/* =====================================================================
   CRM Data Portal HS — styles
   Mobile-first; the sidebar becomes a drawer under 900px.
   ===================================================================== */

:root {
  --navy: #1e3c72;
  --navy-2: #2a5298;
  --ink: #212529;
  --muted: #6c757d;
  --line: #e0e6ed;
  --bg: #f4f6fa;
  --card: #ffffff;
  --green: #28a745;
  --orange: #fd7e14;
  --red: #dc3545;
  --purple: #6f42c1;
  --amber-bg: #fff3cd;
  --amber-ink: #856404;
  --radius: 12px;
  --shadow: 0 4px 16px rgba(16, 32, 64, .10);
  --nav-w: 232px;
  --top-h: 58px;
}

* { box-sizing: border-box; margin: 0; padding: 0; -webkit-tap-highlight-color: transparent; }

html { -webkit-text-size-adjust: 100%; }

body {
  font-family: 'Segoe UI', system-ui, -apple-system, Roboto, Arial, sans-serif;
  background: var(--bg);
  color: var(--ink);
  font-size: 15px;
  line-height: 1.5;
  min-height: 100vh;
  min-height: 100dvh;
}

/* ---------- shell ---------- */
.topbar {
  position: fixed; inset: 0 0 auto 0; height: var(--top-h); z-index: 40;
  display: flex; align-items: center; gap: 12px; padding: 0 14px;
  background: linear-gradient(120deg, var(--navy), var(--navy-2));
  color: #fff; box-shadow: 0 2px 10px rgba(0,0,0,.18);
  padding-left: max(14px, env(safe-area-inset-left));
  padding-right: max(14px, env(safe-area-inset-right));
}
.topbar .brand { display: flex; align-items: center; gap: 10px; }
.topbar .logo { font-size: 22px; }
.topbar strong { display: block; font-size: 15.5px; line-height: 1.15; }
.topbar small { font-size: 11px; opacity: .8; }
.topbar .spacer { flex: 1; }
.topbar .who { font-size: 13px; opacity: .9; }
.burger {
  display: none; background: rgba(255,255,255,.16); border: 0; color: #fff;
  font-size: 19px; width: 38px; height: 38px; border-radius: 9px; cursor: pointer;
}

.sidenav {
  position: fixed; top: var(--top-h); bottom: 0; left: 0; width: var(--nav-w); z-index: 35;
  background: #fff; border-right: 1px solid var(--line); padding: 14px 10px;
  overflow-y: auto; transition: transform .22s ease;
}
.sidenav a {
  display: flex; align-items: center; gap: 11px; padding: 11px 13px; margin-bottom: 4px;
  border-radius: 9px; color: #40506b; text-decoration: none; font-size: 14.5px; font-weight: 500;
}
.sidenav a:hover { background: #eef3fb; color: var(--navy); }
.sidenav a.on { background: var(--navy); color: #fff; }
.sidenav .ic { width: 20px; text-align: center; font-size: 15px; }

.main {
  margin-left: var(--nav-w); padding: calc(var(--top-h) + 20px) 22px 48px;
  max-width: 1700px;
}
.scrim {
  position: fixed; inset: 0; background: rgba(12,20,40,.45); z-index: 34;
  opacity: 0; pointer-events: none; transition: opacity .2s;
}
.scrim.on { opacity: 1; pointer-events: auto; }

@media (max-width: 900px) {
  .burger { display: block; }
  .sidenav { transform: translateX(-100%); box-shadow: 4px 0 20px rgba(0,0,0,.2); }
  .sidenav.open { transform: none; }
  .main { margin-left: 0; padding: calc(var(--top-h) + 16px) 14px 44px; }
  .topbar .who { display: none; }
}

/* ---------- typography ---------- */
h1 { font-size: 22px; color: var(--navy); margin-bottom: 4px; }
h2 { font-size: 17px; color: var(--navy); margin-bottom: 10px; }
h3 { font-size: 15px; color: var(--navy); }
.sub { color: var(--muted); font-size: 13.5px; margin-bottom: 18px; }

/* ---------- cards ---------- */
.card {
  background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow);
  padding: 18px; margin-bottom: 18px;
}
.card > h2 { margin-bottom: 12px; }

.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(168px, 1fr)); gap: 12px; margin-bottom: 18px; }
.stat {
  background: #fff; border-radius: var(--radius); box-shadow: var(--shadow);
  padding: 14px 16px; border-left: 5px solid var(--navy);
}
.stat .label { font-size: 11px; color: var(--muted); text-transform: uppercase; letter-spacing: .5px; }
.stat .value { font-size: 20px; font-weight: 700; color: var(--navy); margin-top: 5px; word-break: break-word; }
.stat.green { border-left-color: var(--green); }  .stat.green .value { color: var(--green); }
.stat.orange { border-left-color: var(--orange); } .stat.orange .value { color: var(--orange); }
.stat.red { border-left-color: var(--red); }       .stat.red .value { color: var(--red); }
.stat.purple { border-left-color: var(--purple); } .stat.purple .value { color: var(--purple); }

/* ---------- controls ---------- */
.bar { display: flex; flex-wrap: wrap; gap: 14px 18px; align-items: flex-end; }
.field { display: flex; flex-direction: column; gap: 5px; min-width: 150px; }
.field label { font-size: 11.5px; font-weight: 600; color: var(--navy); text-transform: uppercase; letter-spacing: .4px; }
select, input[type=text], input[type=number], input[type=password], textarea {
  padding: 9px 11px; border: 1px solid #cfd8e3; border-radius: 8px; font-size: 14px;
  font-family: inherit; background: #fff; color: var(--ink); outline: none; width: 100%;
}
select:focus, input:focus, textarea:focus { border-color: var(--navy); box-shadow: 0 0 0 3px rgba(30,60,114,.12); }
.check { display: flex; align-items: center; gap: 8px; font-size: 14px; }
.check input { width: 17px; height: 17px; accent-color: var(--navy); }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 7px;
  padding: 10px 16px; border: 0; border-radius: 8px; font-size: 14px; font-weight: 600;
  cursor: pointer; font-family: inherit; text-decoration: none; transition: filter .15s, transform .1s;
  min-height: 42px;
}
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn-primary { background: var(--navy); color: #fff; }
.btn-success { background: var(--green); color: #fff; }
.btn-warn { background: var(--orange); color: #fff; }
.btn-danger { background: var(--red); color: #fff; }
.btn-ghost { background: rgba(255,255,255,.18); color: #fff; }
.btn-light { background: #eef3fb; color: var(--navy); }
.btn:hover:not(:disabled) { filter: brightness(1.08); }
.btn-sm { padding: 6px 11px; min-height: 34px; font-size: 13px; }

/* ---------- upload ---------- */
.drop {
  border: 3px dashed #cfd8e3; border-radius: var(--radius); background: #fff;
  padding: 26px 18px; text-align: center; cursor: pointer; display: block; transition: .2s;
}
.drop.drag { border-color: var(--navy); background: #eef3fb; }
.drop.loaded { border-style: solid; border-color: var(--green); }
.drop .ic { font-size: 36px; }
.drop h3 { margin: 6px 0 3px; }
.drop p { color: var(--muted); font-size: 13px; }
.drop input[type=file] { display: none; }

/* ---------- tables ---------- */
.tablewrap { background: #fff; border-radius: var(--radius); box-shadow: var(--shadow); overflow: hidden; }
.tablehead {
  padding: 13px 16px; background: #f8f9fc; border-bottom: 1px solid var(--line);
  display: flex; justify-content: space-between; align-items: center; gap: 10px; flex-wrap: wrap;
}
.tablescroll { max-height: 68vh; overflow: auto; -webkit-overflow-scrolling: touch; }
table { width: 100%; border-collapse: collapse; font-size: 13px; }
thead th {
  background: var(--navy); color: #fff; padding: 10px 11px; text-align: left;
  font-size: 11px; text-transform: uppercase; letter-spacing: .3px; font-weight: 600;
  position: sticky; top: 0; z-index: 5; white-space: nowrap;
}
thead th.num { text-align: right; }
thead th.a { background: #8a6d1f; }
thead th.b { background: #155a8a; }
tbody td { padding: 8px 11px; border-bottom: 1px solid #eef1f5; white-space: nowrap; }
tbody td.num { text-align: right; font-variant-numeric: tabular-nums; }
tbody tr:hover { background: #f7fbff; }
td.neg { color: var(--red); font-weight: 600; }
td.pos { color: var(--green); font-weight: 600; }
tr.sub td { background: var(--amber-bg) !important; color: var(--amber-ink); font-weight: 700;
  border-top: 2px solid #ffc107; border-bottom: 2px solid #ffc107; }
tr.tot td { background: var(--navy) !important; color: #fff; font-weight: 700; }
tr.tot td.neg, tr.tot td.pos { color: #fff; }

.pill { display: inline-block; padding: 2px 9px; border-radius: 20px; font-size: 11px; font-weight: 700; }
.pill.added { background: #d4edda; color: #155724; }
.pill.dropped { background: #f8d7da; color: #721c24; }
.pill.changed { background: var(--amber-bg); color: var(--amber-ink); }
.pill.same { background: #e9ecef; color: #495057; }
.pill.staging { background: var(--amber-bg); color: var(--amber-ink); }
.pill.stored { background: #d4edda; color: #155724; }

/* ---------- alerts ---------- */
.alert { padding: 12px 16px; border-radius: 9px; margin-bottom: 14px; font-size: 13.5px; display: none; }
.alert.show { display: block; }
.alert.err { background: #f8d7da; color: #721c24; border-left: 4px solid var(--red); }
.alert.ok { background: #d4edda; color: #155724; border-left: 4px solid var(--green); }
.alert.warn { background: var(--amber-bg); color: var(--amber-ink); border-left: 4px solid #ffc107; }
.alert ul { margin: 6px 0 0 18px; }

.empty { padding: 44px 18px; text-align: center; color: var(--muted); }
.empty .ic { font-size: 46px; opacity: .35; display: block; margin-bottom: 8px; }

.spin { display: inline-block; width: 15px; height: 15px; border: 2px solid rgba(255,255,255,.4);
  border-top-color: #fff; border-radius: 50%; animation: sp .7s linear infinite; }
@keyframes sp { to { transform: rotate(360deg); } }

.note { font-size: 12.5px; color: var(--muted); }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
@media (max-width: 780px) { .grid2 { grid-template-columns: 1fr; } }

/* ---------- login ---------- */
.loginwrap {
  min-height: 100vh; min-height: 100dvh; display: flex; align-items: center; justify-content: center;
  background: linear-gradient(135deg, var(--navy) 0%, var(--navy-2) 100%); padding: 20px;
}
.loginbox { background: #fff; border-radius: 16px; box-shadow: 0 18px 44px rgba(0,0,0,.28);
  padding: 32px 28px; width: 100%; max-width: 390px; }
.loginbox h1 { text-align: center; margin-bottom: 4px; }
.loginbox .sub { text-align: center; }
.loginbox .field { margin-bottom: 14px; min-width: 0; }
.loginbox .btn { width: 100%; }

/* ---------- big search box ---------- */
.search-big {
  width: 100%; padding: 15px 18px; font-size: 17px; border: 2px solid #cfd8e3;
  border-radius: 12px; outline: none; font-family: inherit; transition: border .15s, box-shadow .15s;
}
.search-big:focus { border-color: var(--navy); box-shadow: 0 0 0 4px rgba(30,60,114,.12); }
.search-big::placeholder { color: #a6b2c4; }

.searchmeta {
  display: flex; align-items: center; gap: 10px; margin-top: 10px;
  font-size: 12.5px; color: var(--muted);
}
.searchmeta .spacer { flex: 1; }
.searchmeta a { color: var(--navy); text-decoration: none; font-weight: 600; }
.searchmeta a:hover { text-decoration: underline; }

.tipbox {
  margin-top: 14px; padding: 14px 16px; background: #f8f9fc;
  border: 1px solid var(--line); border-radius: 10px; font-size: 13px;
  overflow-x: auto;
}
.tipbox table { width: 100%; border-collapse: collapse; }
.tipbox td { padding: 6px 10px 6px 0; border: 0; vertical-align: top; white-space: normal; }
.tipbox td:first-child { white-space: nowrap; width: 1%; }
.tipbox code {
  background: #e9eef7; color: var(--navy); padding: 2px 7px; border-radius: 5px;
  font-size: 12.5px; font-family: ui-monospace, Menlo, Consolas, monospace;
}

/* ---------- value chips ---------- */
.chipwrap { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 8px; }
.chip {
  display: inline-flex; flex-direction: column; align-items: flex-start; gap: 2px;
  padding: 8px 13px; border: 2px solid #cfd8e3; background: #fff; border-radius: 9px;
  font-size: 13px; font-weight: 600; color: #40506b; cursor: pointer;
  font-family: inherit; transition: all .15s; text-align: left;
}
.chip small { font-weight: 500; font-size: 11.5px; color: var(--muted); }
.chip:hover { border-color: var(--navy); }
.chip.on { border-color: var(--navy); background: var(--navy); color: #fff; }
.chip.on small { color: rgba(255,255,255,.8); }

@media (max-width: 640px) {
  .search-big { font-size: 16px; padding: 13px 15px; }
  .chip { flex: 1 1 100%; }
}
