/* ============================================================
   ZYLINK CORP — ENTERPRISE ID & WORKFORCE SYSTEM
   Design system: dark premium, dense, data-first
   ============================================================ */

/* ============ TOKENS ============ */
:root{
  --void:#070910;
  --surface:#0F1219;
  --surface-2:#161A24;
  --surface-3:#1E2330;
  --border:#232938;
  --border-2:#2E3548;
  --text:#EDF1F5;
  --text-2:#C4CAD4;
  --muted:#7C8598;
  --muted-2:#5B6376;

  --teal:#00E5B0;
  --teal-2:#1FF0C0;
  --teal-dim:#0B9E78;
  --teal-soft:rgba(0,229,176,.12);
  --danger:#FF4D6D;
  --danger-soft:rgba(255,77,109,.12);
  --amber:#FFB020;
  --amber-soft:rgba(255,176,32,.14);
  --blue:#38BDF8;
  --blue-soft:rgba(56,189,248,.14);
  --violet:#7C5CFF;
  --violet-soft:rgba(124,92,255,.14);

  --div-ai:#7C5CFF;
  --div-fintech:#00E5B0;
  --div-cyber:#FF4D6D;
  --div-blockchain:#FFB020;
  --div-ecom:#38BDF8;
  --div-cloud:#34D399;
  --div-media:#F472B6;
  --div-hq:#94A3B8;
  --div-ops:#FB7185;
  --div-legal:#A78BFA;

  --font-display:'Space Grotesk', sans-serif;
  --font-body:'Inter', sans-serif;
  --font-mono:'JetBrains Mono', monospace;

  --radius:14px;
  --radius-sm:9px;
  --radius-lg:18px;
  --shadow:0 18px 40px -18px rgba(0,0,0,.6);
  --shadow-2:0 8px 24px -10px rgba(0,0,0,.5);
}

*{box-sizing:border-box; margin:0; padding:0;}
html,body{height:100%;}
body{
  background:var(--void);
  color:var(--text);
  font-family:var(--font-body);
  font-size:14px;
  line-height:1.5;
  -webkit-font-smoothing:antialiased;
  overflow-x:hidden;
}
button, input, select, textarea{font-family:inherit; color:inherit; font-size:inherit;}
::selection{background:var(--teal); color:#04120E;}
:focus-visible{outline:2px solid var(--teal); outline-offset:2px;}
::-webkit-scrollbar{width:10px; height:10px;}
::-webkit-scrollbar-track{background:var(--void);}
::-webkit-scrollbar-thumb{background:var(--border); border-radius:6px; border:2px solid var(--void);}
::-webkit-scrollbar-thumb:hover{background:var(--border-2);}
a{color:var(--teal); text-decoration:none;}
a:hover{text-decoration:underline;}

/* ============ APP LAYOUT ============ */
.app{display:flex; min-height:100vh;}

/* SIDEBAR */
.sidebar{
  width:248px; flex-shrink:0;
  background:var(--surface);
  border-right:1px solid var(--border);
  display:flex; flex-direction:column;
  padding:20px 14px;
  position:sticky; top:0; height:100vh; z-index:20;
}
.brand{display:flex; align-items:center; gap:11px; padding:0 8px 22px;}
.brand-mark{
  width:38px; height:38px; border-radius:10px;
  background:linear-gradient(135deg, var(--teal), var(--teal-dim));
  color:#04120E; font-family:var(--font-display); font-weight:700; font-size:19px;
  display:flex; align-items:center; justify-content:center; flex-shrink:0;
  box-shadow:0 6px 18px -6px var(--teal);
}
.brand-text{display:flex; flex-direction:column; line-height:1.15;}
.brand-name{font-family:var(--font-display); font-weight:700; font-size:15px;}
.brand-sub{font-size:10.5px; color:var(--muted); letter-spacing:.06em; text-transform:uppercase;}

.nav-section{margin:14px 0 6px; padding:0 10px;}
.nav-section-label{
  font-size:10px; color:var(--muted-2); letter-spacing:.1em; text-transform:uppercase;
  font-weight:600; margin-bottom:6px;
}
.nav-links{display:flex; flex-direction:column; gap:2px;}
.nav-link{
  display:flex; align-items:center; gap:11px;
  background:none; border:none; text-align:left;
  padding:9px 11px; border-radius:8px;
  font-size:13px; font-weight:500; color:var(--text-2);
  cursor:pointer; transition:background .15s, color .15s;
  width:100%; position:relative;
}
.nav-link svg{flex-shrink:0; opacity:.7;}
.nav-link:hover{background:var(--surface-2); color:var(--text);}
.nav-link.active{background:var(--surface-3); color:var(--teal);}
.nav-link.active svg{opacity:1;}
.nav-link .badge-count{
  margin-left:auto; background:var(--surface-3); color:var(--muted);
  font-size:10.5px; padding:1px 7px; border-radius:100px; font-weight:600;
}
.nav-link.active .badge-count{background:var(--teal-soft); color:var(--teal);}

.sidebar-footer{
  margin-top:auto;
  display:flex; flex-direction:column; gap:10px;
  padding-top:14px; border-top:1px solid var(--border);
}
.user-pill{
  display:flex; align-items:center; gap:10px;
  padding:8px 10px; border-radius:9px; background:var(--surface-2);
  cursor:pointer; transition:background .15s;
}
.user-pill:hover{background:var(--surface-3);}
.user-avatar{
  width:32px; height:32px; border-radius:8px; flex-shrink:0;
  background:linear-gradient(135deg, var(--violet), var(--div-cyber));
  color:#fff; font-family:var(--font-display); font-weight:700; font-size:13px;
  display:flex; align-items:center; justify-content:center;
}
.user-info{display:flex; flex-direction:column; line-height:1.2; min-width:0;}
.user-name{font-size:12.5px; font-weight:600; white-space:nowrap; overflow:hidden; text-overflow:ellipsis;}
.user-role{font-size:10.5px; color:var(--muted); white-space:nowrap; overflow:hidden; text-overflow:ellipsis;}
.conn-status{
  display:flex; align-items:center; gap:8px;
  font-size:11px; color:var(--muted);
  padding:0 4px;
}
.conn-dot{width:7px; height:7px; border-radius:50%; background:var(--muted); flex-shrink:0;}
.conn-dot.ok{background:var(--teal); box-shadow:0 0 8px var(--teal);}
.conn-dot.bad{background:var(--danger);}
.conn-dot.local{background:var(--amber); box-shadow:0 0 6px var(--amber);}

/* MAIN */
.main{flex:1; padding:28px 36px 80px; min-width:0; max-width:1480px;}

.topbar{
  display:flex; align-items:center; gap:14px; margin-bottom:24px;
}
.topbar h1{font-family:var(--font-display); font-size:23px; font-weight:600;}
.topbar .crumb{color:var(--muted); font-size:12.5px; margin-left:2px;}
.topbar-actions{margin-left:auto; display:flex; gap:8px; align-items:center;}

.view{display:none;}
.view.active{display:block; animation:fadeIn .25s ease;}
@keyframes fadeIn{from{opacity:0; transform:translateY(4px);} to{opacity:1; transform:translateY(0);}}

.view-header{margin-bottom:22px;}
.view-header h1{font-family:var(--font-display); font-size:24px; font-weight:600;}
.view-sub{color:var(--muted); font-size:13px; margin-top:3px;}

/* ============ STATS ============ */
.stat-grid{display:grid; grid-template-columns:repeat(4, 1fr); gap:14px; margin-bottom:22px;}
.stat-card{
  background:var(--surface); border:1px solid var(--border); border-radius:var(--radius);
  padding:16px 18px; display:flex; flex-direction:column; gap:8px;
  position:relative; overflow:hidden;
}
.stat-card::before{
  content:''; position:absolute; right:-12px; top:-12px; width:60px; height:60px;
  border-radius:50%; opacity:.08; background:var(--stat-c, var(--teal));
}
.stat-icon{
  width:30px; height:30px; border-radius:8px;
  background:var(--stat-soft, var(--teal-soft));
  color:var(--stat-c, var(--teal));
  display:flex; align-items:center; justify-content:center;
}
.stat-label{font-size:11.5px; color:var(--muted); text-transform:uppercase; letter-spacing:.05em; font-weight:500;}
.stat-value{font-family:var(--font-display); font-size:26px; font-weight:700; line-height:1.1;}
.stat-foot{font-size:11.5px; color:var(--muted); display:flex; align-items:center; gap:5px;}
.stat-foot .up{color:var(--teal);}
.stat-foot .down{color:var(--danger);}

/* ============ PANELS / TABLES ============ */
.panel{
  background:var(--surface); border:1px solid var(--border); border-radius:var(--radius);
  margin-bottom:18px;
}
.panel-head{
  display:flex; align-items:center; justify-content:space-between; gap:12px;
  padding:14px 18px; border-bottom:1px solid var(--border); flex-wrap:wrap;
}
.panel-head h2{font-family:var(--font-display); font-size:15px; font-weight:600;}
.panel-head .panel-sub{font-size:12px; color:var(--muted); margin-top:2px;}
.panel-head .actions{display:flex; gap:8px; align-items:center; flex-wrap:wrap;}
.panel-body{padding:16px 18px;}
.panel-body.no-pad{padding:0;}

.table-wrap{overflow-x:auto;}
.data-table{width:100%; border-collapse:collapse; font-size:13px;}
.data-table th{
  text-align:left; padding:11px 12px; color:var(--muted); font-weight:500;
  font-size:11px; text-transform:uppercase; letter-spacing:.04em;
  border-bottom:1px solid var(--border);
  white-space:nowrap; position:sticky; top:0; background:var(--surface);
}
.data-table td{padding:11px 12px; border-bottom:1px solid var(--border); vertical-align:middle;}
.data-table tr:last-child td{border-bottom:none;}
.data-table tbody tr{transition:background .12s;}
.data-table tbody tr:hover td{background:var(--surface-2);}
.data-table tbody tr.selected td{background:rgba(0,229,176,.06);}
.data-table .th-check, .data-table .td-check{width:36px;}
.data-table .row-photo{width:30px; height:30px; border-radius:7px; object-fit:cover; background:var(--surface-3);}
.data-table .placeholder-photo{
  width:30px; height:30px; border-radius:7px; display:flex; align-items:center; justify-content:center;
  font-size:11px; font-weight:600; color:#fff; flex-shrink:0;
}
.mono{font-family:var(--font-mono); font-size:12px;}
.text-muted{color:var(--muted);}
.text-tiny{font-size:11px;}

.badge{
  display:inline-flex; align-items:center; gap:5px;
  padding:3px 9px; border-radius:100px; font-size:11px; font-weight:600;
  white-space:nowrap;
}
.badge.active{background:var(--teal-soft); color:var(--teal);}
.badge.revoked{background:var(--danger-soft); color:var(--danger);}
.badge.expired{background:var(--amber-soft); color:var(--amber);}
.badge.pending{background:var(--blue-soft); color:var(--blue);}
.badge.neutral{background:var(--surface-3); color:var(--muted);}

.division-chip{
  display:inline-flex; align-items:center; gap:6px;
  font-size:11.5px; font-weight:500;
}
.division-chip::before{
  content:''; width:7px; height:7px; border-radius:2px; background:var(--chip-c, var(--muted));
}

/* ============ IN-PAGE SHEET (editable grid) ============ */
.sheet{
  background:var(--surface); border:1px solid var(--border); border-radius:var(--radius);
  overflow:hidden;
}
.sheet-toolbar{
  display:flex; align-items:center; gap:8px; padding:10px 14px;
  border-bottom:1px solid var(--border); flex-wrap:wrap;
}
.sheet-toolbar h3{font-size:13.5px; font-weight:600;}
.sheet-toolbar .spacer{flex:1;}
.sheet-grid-wrap{overflow:auto; max-height:480px;}
.sheet-grid{
  width:100%; border-collapse:separate; border-spacing:0; font-size:12.5px;
}
.sheet-grid th{
  position:sticky; top:0; z-index:5;
  background:var(--surface-2); color:var(--muted); font-weight:500;
  font-size:10.5px; text-transform:uppercase; letter-spacing:.04em;
  padding:8px 10px; border-bottom:1px solid var(--border);
  white-space:nowrap; text-align:left;
  cursor:pointer; user-select:none;
}
.sheet-grid th:hover{color:var(--text);}
.sheet-grid th .sort-arrow{opacity:.5; margin-left:3px;}
.sheet-grid th.sorted .sort-arrow{opacity:1; color:var(--teal);}
.sheet-grid td{
  padding:7px 10px; border-bottom:1px solid var(--border);
  vertical-align:middle;
}
.sheet-grid tbody tr:hover td{background:var(--surface-2);}
.sheet-grid td.editing{padding:0;}
.sheet-grid input.cell-edit,
.sheet-grid select.cell-edit{
  width:100%; background:var(--void); border:1px solid var(--teal); border-radius:0;
  padding:7px 10px; font-size:12.5px;
}
.sheet-grid input.cell-edit:focus, .sheet-grid select.cell-edit:focus{outline:none;}

.sheet-add-row{
  display:flex; align-items:center; justify-content:center; gap:8px;
  padding:10px; color:var(--muted); cursor:pointer; font-size:12px;
  border-top:1px dashed var(--border);
}
.sheet-add-row:hover{color:var(--teal); background:var(--surface-2);}

/* ============ BUTTONS ============ */
.btn{
  border:none; border-radius:9px; padding:9px 16px; font-size:13px; font-weight:600;
  cursor:pointer; transition:all .15s; font-family:var(--font-body);
  display:inline-flex; align-items:center; gap:6px; white-space:nowrap;
}
.btn svg{flex-shrink:0;}
.btn-primary{background:var(--teal); color:#04120E;}
.btn-primary:hover{background:var(--teal-2);}
.btn-primary:disabled{opacity:.5; cursor:not-allowed;}
.btn-outline{background:none; border:1px solid var(--border-2); color:var(--text);}
.btn-outline:hover{border-color:var(--teal); color:var(--teal);}
.btn-ghost{background:none; border:1px solid var(--border); color:var(--muted);}
.btn-ghost:hover{color:var(--text); border-color:var(--muted);}
.btn-danger{background:none; border:1px solid var(--danger); color:var(--danger);}
.btn-danger:hover{background:var(--danger-soft);}
.btn-danger-solid{background:var(--danger); color:#fff;}
.btn-danger-solid:hover{background:#E6395A;}
.btn-sm{padding:6px 11px; font-size:12px;}
.btn-xs{padding:4px 9px; font-size:11px;}

.icon-btn{
  background:none; border:1px solid var(--border); color:var(--muted);
  border-radius:7px; padding:5px 9px; font-size:12px; cursor:pointer;
  transition:all .15s; display:inline-flex; align-items:center; gap:5px;
}
.icon-btn:hover{border-color:var(--teal); color:var(--teal);}
.icon-btn.danger:hover{border-color:var(--danger); color:var(--danger);}
.icon-btn.only-icon{padding:6px;}
.icon-btn.only-icon svg{width:14px; height:14px;}

/* ============ FORMS ============ */
.field-row{display:grid; grid-template-columns:1fr 1fr; gap:14px; margin-bottom:14px;}
.field-row.three{grid-template-columns:repeat(3,1fr);}
.field{display:flex; flex-direction:column; gap:6px; margin-bottom:14px;}
.field label{font-size:11.5px; color:var(--muted); font-weight:500; letter-spacing:.02em;}
.field label .muted{font-weight:400; opacity:.8;}
.field input, .field select, .field textarea{
  background:var(--void); border:1px solid var(--border); border-radius:9px;
  padding:10px 12px; font-size:13.5px; transition:border-color .15s;
}
.field input:focus, .field select:focus, .field textarea:focus{border-color:var(--teal);}
.field .hint{font-size:11px; color:var(--muted-2);}
.field textarea{resize:vertical; min-height:80px; font-family:inherit;}
.form-actions{display:flex; justify-content:flex-end; gap:10px; margin-top:6px; flex-wrap:wrap;}
.muted{color:var(--muted);}
.small{font-size:12px;}

.search-input{
  background:var(--void); border:1px solid var(--border); border-radius:9px;
  padding:9px 12px 9px 34px; font-size:13px; min-width:240px; width:100%;
  transition:border-color .15s;
}
.search-input:focus{border-color:var(--teal); outline:none;}
.search-input::placeholder{color:var(--muted-2);}
.search-wrap{position:relative;}
.search-wrap svg{position:absolute; left:11px; top:50%; transform:translateY(-50%); color:var(--muted-2);}

.photo-upload{
  border:1.5px dashed var(--border); border-radius:9px; padding:18px;
  text-align:center; font-size:12.5px; color:var(--muted); cursor:pointer;
  transition:border-color .15s, background .15s;
  position:relative;
}
.photo-upload:hover{border-color:var(--teal); background:var(--surface-2);}
.photo-upload.has-photo{border-style:solid; color:var(--teal);}
.photo-upload .preview{
  width:54px; height:54px; border-radius:8px; object-fit:cover; margin:0 auto 6px; display:block;
}

/* ============ ISSUE LAYOUT ============ */
.issue-grid{display:grid; grid-template-columns:1.05fr .95fr; gap:18px; align-items:start;}
.form-panel{padding:20px;}
.preview-panel{
  position:sticky; top:24px; display:flex; flex-direction:column; align-items:center; gap:14px;
  padding:20px; background:var(--surface); border:1px solid var(--border); border-radius:var(--radius);
}
.preview-label{font-size:11px; color:var(--muted); text-transform:uppercase; letter-spacing:.06em; align-self:flex-start;}

/* ============ ID CARD ============ */
.card-stage{display:flex; flex-direction:column; gap:16px; align-items:center;}
.id-card{
  --acc: var(--div-ai);
  width:342.4px; height:216px;
  border-radius:16px;
  position:relative; overflow:hidden;
  background:
    radial-gradient(120% 140% at 100% 0%, rgba(255,255,255,.06), transparent 55%),
    linear-gradient(155deg, #171A22 0%, #0E1015 65%, #0A0C10 100%);
  border:1px solid var(--border);
  box-shadow:0 18px 40px -18px rgba(0,0,0,.6);
  font-family:var(--font-body);
  color:var(--text);
  display:flex; flex-direction:column; justify-content:space-between;
  padding:16px 18px 14px 26px;
}
.card-trace{
  position:absolute; left:0; top:0; bottom:0; width:8px;
  background:
    repeating-linear-gradient(180deg,
      var(--acc) 0px, var(--acc) 3px,
      transparent 3px, transparent 14px);
  box-shadow:0 0 10px 0 var(--acc);
  opacity:.85;
}
.card-watermark{
  position:absolute; right:8px; bottom:8px; opacity:.04;
  font-family:var(--font-display); font-weight:700; font-size:80px; line-height:1; color:#fff;
  pointer-events:none;
}
.card-top{display:flex; align-items:center; justify-content:space-between;}
.card-brand{font-family:var(--font-display); font-size:12.5px; letter-spacing:.06em; color:var(--muted);}
.card-brand b{color:var(--text);}
.card-division{
  font-size:9.5px; font-weight:700; letter-spacing:.06em; text-transform:uppercase;
  /* html2canvas does NOT support color-mix() — use a simple solid border + accent color */
  color:var(--acc);
  background:transparent;
  border:1px solid var(--acc);
  padding:3px 8px; border-radius:100px;
  /* give it a subtle tinted background via rgba (html2canvas-safe) */
  background-color:rgba(255,255,255,.04);
}
.card-body{display:flex; align-items:center; gap:14px; margin:6px 0;}
.card-photo{
  width:64px; height:64px; border-radius:10px; flex-shrink:0;
  background:var(--surface-3); border:1px solid var(--border-2);
  display:flex; align-items:center; justify-content:center;
  font-family:var(--font-display); font-size:22px; color:var(--muted);
  overflow:hidden;
}
.card-photo img{width:100%; height:100%; object-fit:cover;}
.card-info{display:flex; flex-direction:column; gap:3px; min-width:0;}
.card-name{font-family:var(--font-display); font-size:16px; font-weight:600; line-height:1.15;
  white-space:nowrap; overflow:hidden; text-overflow:ellipsis; max-width:200px;}
.card-role{font-size:11.5px; color:var(--muted); white-space:nowrap; overflow:hidden; text-overflow:ellipsis; max-width:200px;}
.card-id{font-family:var(--font-mono); font-size:11px; color:var(--acc); margin-top:2px;}
.card-bottom{display:flex; justify-content:space-between; font-family:var(--font-mono); font-size:9.5px; color:var(--muted);}

/* BACK OF CARD */
.card-back{justify-content:flex-start; align-items:center; gap:10px; padding:16px 18px 14px 26px;}
.back-qr{width:76px; height:76px; background:#fff; border-radius:8px; padding:6px; margin-top:2px;}
.back-qr img, .back-qr canvas{width:100%; height:100%;}
.back-meta{width:100%; display:flex; flex-direction:column; gap:4px; font-size:10.5px;}
.back-row{display:flex; justify-content:space-between; gap:8px; color:var(--muted);}
.back-row b{color:var(--text); font-weight:600; text-align:right;}
.back-terms{font-size:8.3px; line-height:1.4; color:var(--muted); text-align:center; padding:0 6px;}
.back-sign{
  width:100%; text-align:center; font-size:8.5px; color:var(--muted);
  border-top:1px dashed var(--border); padding-top:5px; letter-spacing:.04em;
}

/* ============ MODAL ============ */
.modal{
  position:fixed; inset:0; background:rgba(4,5,8,.75); backdrop-filter:blur(6px);
  display:none; align-items:center; justify-content:center; z-index:100; padding:20px;
}
.modal.open{display:flex; animation:fadeIn .2s ease;}
.modal-content{
  background:var(--surface); border:1px solid var(--border); border-radius:var(--radius-lg);
  padding:24px; max-width:520px; width:100%; position:relative;
  max-height:90vh; overflow-y:auto;
  display:flex; flex-direction:column; gap:18px;
}
.modal-content.wide{max-width:780px;}
.modal-close{
  position:absolute; top:14px; right:16px; background:none; border:none;
  color:var(--muted); font-size:22px; cursor:pointer; line-height:1; z-index:2;
}
.modal-close:hover{color:var(--text);}
.modal-title{font-family:var(--font-display); font-size:18px; font-weight:600; padding-right:24px;}
.modal-stage{width:100%;}
.modal-stage .card-stage{flex-direction:row; flex-wrap:wrap; justify-content:center;}

/* ============ DRAWER (right slide-in) ============ */
.drawer-overlay{
  position:fixed; inset:0; background:rgba(4,5,8,.5); backdrop-filter:blur(2px);
  opacity:0; pointer-events:none; transition:opacity .25s; z-index:90;
}
.drawer-overlay.open{opacity:1; pointer-events:auto;}
.drawer{
  position:fixed; top:0; right:0; bottom:0; width:420px; max-width:90vw;
  background:var(--surface); border-left:1px solid var(--border);
  transform:translateX(100%); transition:transform .3s cubic-bezier(.4,0,.2,1);
  z-index:95; display:flex; flex-direction:column;
}
.drawer.open{transform:translateX(0);}
.drawer-head{
  display:flex; align-items:center; justify-content:space-between;
  padding:18px 20px; border-bottom:1px solid var(--border);
}
.drawer-head h3{font-family:var(--font-display); font-size:16px; font-weight:600;}
.drawer-body{flex:1; overflow-y:auto; padding:18px 20px;}
.drawer-foot{padding:14px 20px; border-top:1px solid var(--border); display:flex; gap:8px; justify-content:flex-end;}

/* ============ TOAST ============ */
.toast-stack{
  position:fixed; bottom:22px; right:22px; z-index:300;
  display:flex; flex-direction:column; gap:8px; max-width:340px;
}
.toast{
  background:var(--surface-3); border:1px solid var(--border-2); color:var(--text);
  padding:11px 16px; border-radius:10px; font-size:13px;
  display:flex; align-items:flex-start; gap:10px;
  box-shadow:var(--shadow-2);
  transform:translateX(120%); opacity:0;
  transition:transform .25s ease, opacity .25s;
}
.toast.show{transform:translateX(0); opacity:1;}
.toast.error{border-color:var(--danger);}
.toast.error .toast-icon{color:var(--danger);}
.toast.success .toast-icon{color:var(--teal);}
.toast-icon{flex-shrink:0; margin-top:1px;}
.toast-msg{flex:1; line-height:1.4;}

/* ============ TABS ============ */
.tabs{display:flex; gap:2px; border-bottom:1px solid var(--border); margin-bottom:18px;}
.tab{
  background:none; border:none; color:var(--muted);
  padding:9px 14px; font-size:13px; font-weight:500; cursor:pointer;
  border-bottom:2px solid transparent; transition:color .15s, border-color .15s;
  margin-bottom:-1px;
}
.tab:hover{color:var(--text);}
.tab.active{color:var(--teal); border-bottom-color:var(--teal);}

/* ============ CHIPS / FILTERS ============ */
.chip-row{display:flex; gap:6px; flex-wrap:wrap;}
.chip{
  background:var(--surface-2); border:1px solid var(--border); color:var(--muted);
  padding:5px 11px; border-radius:100px; font-size:11.5px; cursor:pointer; transition:all .15s;
  font-weight:500;
}
.chip:hover{border-color:var(--border-2); color:var(--text);}
.chip.active{background:var(--teal-soft); border-color:var(--teal); color:var(--teal);}

/* ============ CHART ============ */
.chart-wrap{position:relative; height:220px;}
.chart-wrap.tall{height:280px;}
.chart-wrap canvas{max-width:100%;}

/* ============ KPI TILE ============ */
.kpi-grid{display:grid; grid-template-columns:repeat(auto-fit, minmax(180px,1fr)); gap:12px; margin-bottom:18px;}
.kpi-tile{
  background:var(--surface); border:1px solid var(--border); border-radius:var(--radius);
  padding:14px 16px; display:flex; flex-direction:column; gap:4px;
}
.kpi-tile .label{font-size:11px; color:var(--muted); text-transform:uppercase; letter-spacing:.05em;}
.kpi-tile .value{font-family:var(--font-display); font-size:22px; font-weight:700;}
.kpi-tile .delta{font-size:11px; color:var(--muted);}
.kpi-tile .delta.up{color:var(--teal);}
.kpi-tile .delta.down{color:var(--danger);}

/* ============ TIMELINE / ACTIVITY ============ */
.timeline{display:flex; flex-direction:column; gap:0; padding:6px 0;}
.timeline-item{
  display:flex; gap:12px; padding:10px 18px; border-bottom:1px solid var(--border);
}
.timeline-item:last-child{border-bottom:none;}
.timeline-dot{
  width:8px; height:8px; border-radius:50%; margin-top:6px; flex-shrink:0;
  background:var(--teal); box-shadow:0 0 6px var(--teal);
}
.timeline-item.type-create .timeline-dot{background:var(--teal); box-shadow:0 0 6px var(--teal);}
.timeline-item.type-update .timeline-dot{background:var(--blue); box-shadow:0 0 6px var(--blue);}
.timeline-item.type-revoke .timeline-dot{background:var(--danger); box-shadow:0 0 6px var(--danger);}
.timeline-item.type-reinstate .timeline-dot{background:var(--amber); box-shadow:0 0 6px var(--amber);}
.timeline-item.type-login .timeline-dot{background:var(--violet); box-shadow:0 0 6px var(--violet);}
.timeline-item.type-import .timeline-dot{background:var(--div-media); box-shadow:0 0 6px var(--div-media);}
.timeline-body{flex:1; min-width:0;}
.timeline-text{font-size:12.5px;}
.timeline-text b{font-weight:600;}
.timeline-meta{font-size:11px; color:var(--muted); margin-top:2px;}

/* ============ LOGIN ============ */
.login-screen{
  position:fixed; inset:0; background:var(--void); z-index:500;
  display:flex; align-items:center; justify-content:center; padding:20px;
}
.login-card{
  width:100%; max-width:400px; background:var(--surface); border:1px solid var(--border);
  border-radius:var(--radius-lg); padding:36px 30px;
  box-shadow:var(--shadow);
}
.login-logo{
  display:flex; align-items:center; gap:11px; margin-bottom:24px; justify-content:center;
}
.login-logo .brand-mark{width:42px; height:42px; font-size:20px;}
.login-logo .brand-text{text-align:left;}
.login-logo .brand-name{font-size:16px;}
.login-card h2{
  font-family:var(--font-display); text-align:center; font-size:18px; margin-bottom:6px;
}
.login-card .sub{color:var(--muted); font-size:12.5px; text-align:center; margin-bottom:22px;}
.login-form .field{margin-bottom:14px;}
.login-actions{margin-top:8px;}
.login-card .hint{
  text-align:center; margin-top:18px; font-size:11px; color:var(--muted-2);
  padding-top:18px; border-top:1px solid var(--border);
}

/* ============ MISC ============ */
.empty-state{
  padding:48px 20px; text-align:center; color:var(--muted);
}
.empty-state svg{opacity:.4; margin-bottom:10px;}
.empty-state .title{font-family:var(--font-display); font-size:15px; color:var(--text-2); margin-bottom:4px;}

.divider{height:1px; background:var(--border); margin:18px 0;}
.flex{display:flex;}
.flex-1{flex:1;}
.gap-2{gap:8px;}
.gap-3{gap:12px;}
.items-center{align-items:center;}
.justify-between{justify-content:space-between;}
.text-center{text-align:center;}
.nowrap{white-space:nowrap;}
.hide-mobile{}
.row-gap-2{row-gap:8px;}

.spinner{
  width:14px; height:14px; border:2px solid var(--border-2); border-top-color:var(--teal);
  border-radius:50%; animation:spin 1s linear infinite; display:inline-block;
}
@keyframes spin{to{transform:rotate(360deg);}}

/* ============ SWITCH ============ */
.switch{position:relative; display:inline-block; width:38px; height:22px;}
.switch input{opacity:0; width:0; height:0;}
.switch .slider{
  position:absolute; cursor:pointer; inset:0;
  background:var(--surface-3); border:1px solid var(--border-2); border-radius:22px;
  transition:.2s;
}
.switch .slider::before{
  content:''; position:absolute; height:16px; width:16px; left:2px; bottom:2px;
  background:var(--muted); border-radius:50%; transition:.2s;
}
.switch input:checked + .slider{background:var(--teal-soft); border-color:var(--teal);}
.switch input:checked + .slider::before{transform:translateX(16px); background:var(--teal);}

/* ============ PROGRESS ============ */
.progress{height:6px; background:var(--surface-3); border-radius:100px; overflow:hidden;}
.progress-bar{height:100%; background:var(--teal); border-radius:100px; transition:width .3s ease;}

/* ============ RESPONSIVE ============ */

/* Tablet and small desktop */
@media (max-width:1100px){
  .stat-grid{grid-template-columns:repeat(2,1fr);}
  .dash-row{display:grid !important; grid-template-columns:1fr !important; gap:14px !important; margin-bottom:14px !important;}
  .main{padding:24px 24px 100px;}
  .sidebar{width:220px;}
}

@media (max-width:980px){
  .issue-grid{grid-template-columns:1fr;}
  .preview-panel{position:static;}
  .field-row.three{grid-template-columns:1fr;}
  .main{padding:20px 16px 100px;}
}

/* ============ MOBILE (<=760px) ============ */
@media (max-width:760px){
  :root{--radius:12px;}

  body{padding-bottom:env(safe-area-inset-bottom, 0);}

  /* App becomes a single column. Sidebar becomes a bottom tab bar. */
  .app{flex-direction:column; min-height:100vh; padding-bottom:64px;}

  /* TOP APP BAR — replaces sidebar header on mobile */
  .mobile-appbar{
    display:flex !important;
    align-items:center; justify-content:space-between;
    padding:12px 16px; gap:10px;
    background:var(--surface); border-bottom:1px solid var(--border);
    position:sticky; top:0; z-index:30;
    padding-top:max(12px, env(safe-area-inset-top, 12px));
  }
  .mobile-appbar .brand{padding:0;}
  .mobile-appbar .brand-mark{width:32px; height:32px; font-size:17px; border-radius:8px;}
  .mobile-appbar .brand-name{font-size:14px;}
  .mobile-appbar .brand-sub{font-size:9.5px;}
  .mobile-appbar .conn-status{
    margin:0; padding:0; font-size:10.5px;
  }
  .mobile-appbar .conn-dot{width:6px; height:6px;}

  /* Hide desktop sidebar completely on mobile */
  .sidebar{display:none !important;}

  /* Show desktop-only nav-section labels only on desktop */
  .nav-section{display:none;}

  /* MAIN content padding — leave room for bottom tab bar */
  .main{
    padding:14px 14px 90px;
    max-width:100%;
  }

  /* Topbar — compact */
  .topbar{
    flex-wrap:wrap; gap:8px; margin-bottom:16px;
  }
  .topbar h1{font-size:20px; line-height:1.15;}
  .topbar .crumb{font-size:11.5px; display:block; margin-top:2px;}
  .topbar-actions{width:100%; justify-content:flex-start; flex-wrap:wrap;}
  .topbar-actions .btn{padding:8px 12px; font-size:12.5px;}
  .topbar-actions .btn span:not(.hide-mobile){display:inline;}

  /* View headers */
  .view-header h1{font-size:21px;}
  .view-sub{font-size:12.5px;}

  /* Stats: 2x2 grid on phones */
  .stat-grid{
    grid-template-columns:repeat(2,1fr);
    gap:10px; margin-bottom:16px;
  }
  .stat-card{padding:14px 14px;}
  .stat-value{font-size:22px;}
  .stat-label{font-size:10.5px;}
  .stat-icon{width:26px; height:26px;}

  /* Panels: tighter padding */
  .panel{margin-bottom:14px;}
  .panel-head{padding:12px 14px; flex-wrap:wrap; gap:8px;}
  .panel-head h2{font-size:14px;}
  .panel-head .panel-sub{font-size:11.5px;}
  .panel-body{padding:12px 14px;}

  /* Search inputs full width */
  .search-input{min-width:0; width:100%;}
  .panel-head .search-wrap{flex:1 1 100%; max-width:100%;}
  .panel-head .actions{width:100%; flex-wrap:wrap;}
  .panel-head .actions .search-input{max-width:100%;}

  /* DATA TABLES → CARD LIST on mobile */
  .data-table thead{display:none;}
  .data-table, .data-table tbody, .data-table tr, .data-table td{display:block; width:100%;}
  .data-table tbody tr{
    background:var(--surface-2);
    border:1px solid var(--border);
    border-radius:11px;
    padding:10px 12px;
    margin-bottom:8px;
    display:grid;
    grid-template-columns:auto 1fr auto;
    gap:6px 10px;
    align-items:center;
  }
  .data-table tbody tr td{
    padding:0; border-bottom:none;
    font-size:12.5px;
  }
  /* For the directory table — arrange as: photo | (name+id stacked) | (actions) */
  /* Mark cells that should be hidden on mobile with .mobile-hide */
  .data-table .mobile-hide{display:none !important;}
  .data-table td.mt-main{grid-column:2; min-width:0;}
  .data-table td.mt-photo{grid-column:1; grid-row:1 / span 2;}
  .data-table td.mt-actions{grid-column:3; grid-row:1 / span 2; display:flex; flex-direction:column; gap:6px;}
  .data-table td.mt-actions .icon-btn{margin:0; width:100%; justify-content:center; font-size:11.5px;}
  /* Default: stack remaining cells across row 2 */
  .data-table tbody tr td:not(.mt-photo):not(.mt-main):not(.mt-actions):not(.mobile-hide){
    grid-column:1 / -1; padding-top:4px; border-top:1px solid var(--border); margin-top:4px;
  }
  .data-table .row-photo, .data-table .placeholder-photo{width:42px; height:42px;}
  .data-table .badge{font-size:10.5px;}

  /* Recent table (dashboard) — simpler 2-row layout */
  #recentTable tbody tr, #expiryTable tbody tr{
    display:grid; grid-template-columns:1fr auto;
    gap:4px 10px; padding:10px 12px;
  }
  #recentTable tbody tr td:nth-child(1), #expiryTable tbody tr td:nth-child(1){
    grid-column:1; font-weight:600;
  }
  #recentTable tbody tr td:nth-child(3){
    grid-column:2; text-align:right;
  }
  #recentTable tbody tr td:nth-child(2){
    grid-column:1 / -1; font-size:13px;
  }

  /* Field rows: single column on mobile */
  .field-row{grid-template-columns:1fr; gap:10px;}
  .field{margin-bottom:12px;}

  /* Issue grid: form first, preview last (already single column at 980px) */
  .issue-grid{gap:14px;}
  .form-panel{padding:16px 16px 110px;} /* extra bottom padding so save button clears tab bar */
  .preview-panel{padding:16px 16px 110px; position:static;}
  .id-card{width:min(342.4px, 90vw); height:auto; aspect-ratio:342.4/216;}
  .preview-label{font-size:11px;}

  /* Charts: stack vertically with reasonable height */
  .chart-wrap{height:180px;}
  .chart-wrap.tall{height:220px;}

  /* Modals: take full width minus margins */
  .modal{padding:12px;}
  .modal-content{padding:18px 16px; max-width:100%; border-radius:14px;}
  .modal-content.wide{max-width:100%;}
  .modal-title{font-size:16px;}
  .modal-stage .card-stage{gap:14px;}
  .form-actions{flex-wrap:wrap;}
  .form-actions .btn{flex:1; min-width:120px; justify-content:center;}

  /* Toast stack: full width on mobile */
  .toast-stack{left:12px; right:12px; bottom:78px; max-width:100%;}

  /* Tabs (settings) — horizontally scrollable */
  .tabs{overflow-x:auto; gap:0; white-space:nowrap;}
  .tab{padding:9px 12px; font-size:12.5px; flex-shrink:0;}

  /* KPI grid: 2 cols on mobile */
  .kpi-grid{grid-template-columns:repeat(2,1fr);}

  /* Timeline: smaller padding */
  .timeline-item{padding:9px 14px; gap:10px;}
  .timeline-text{font-size:12.5px;}

  /* Sheet (divisions, assets) — horizontal scroll preserved but tighter */
  .sheet-grid-wrap{max-height:480px;}
  .sheet-grid th, .sheet-grid td{padding:8px 10px; font-size:11.5px;}

  /* Filter chips wrap properly */
  .chip-row{gap:5px;}
  .chip{padding:5px 10px; font-size:11px;}

  /* Bottom tab bar — replaces the sidebar nav on mobile */
  .mobile-tabbar{
    display:flex !important;
    position:fixed; bottom:0; left:0; right:0; z-index:50;
    background:rgba(15,18,25,.96);
    backdrop-filter:blur(14px);
    -webkit-backdrop-filter:blur(14px);
    border-top:1px solid var(--border);
    padding:6px 4px max(6px, env(safe-area-inset-bottom, 6px));
    justify-content:space-around;
    align-items:stretch;
  }
  .mobile-tabbar .mtab{
    flex:1;
    background:none; border:none;
    display:flex; flex-direction:column; align-items:center; justify-content:center;
    gap:3px; padding:6px 4px; border-radius:9px;
    color:var(--muted); font-size:10px; font-weight:500;
    cursor:pointer; transition:color .15s, background .15s;
    min-width:0;
  }
  .mobile-tabbar .mtab svg{width:18px; height:18px;}
  .mobile-tabbar .mtab .mtab-label{font-size:9.5px; white-space:nowrap; overflow:hidden; text-overflow:ellipsis; max-width:100%;}
  .mobile-tabbar .mtab.active{color:var(--teal);}
  .mobile-tabbar .mtab:active{background:var(--surface-2);}
  .mobile-tabbar .mtab .mtab-badge{
    position:absolute; top:2px; right:50%; transform:translateX(20px);
    background:var(--teal); color:#04120E;
    font-size:9px; font-weight:700;
    padding:1px 5px; border-radius:100px; min-width:14px; text-align:center;
  }
  .mobile-tabbar .mtab{position:relative;}

  /* Floating action button (FAB) for "New Card" / "Add Visitor" etc. — replaces topbar primary action */
  .mobile-fab{
    display:none; /* shown per-view via JS */
  }

  /* Login screen: tighter */
  .login-card{padding:28px 22px;}
  .login-logo{margin-bottom:18px;}

  /* Buttons: bigger touch targets */
  .btn{padding:11px 16px; font-size:13.5px;}
  .btn-sm{padding:9px 13px;}
  .icon-btn{padding:8px 11px; font-size:12px;}

  /* Photo upload */
  .photo-upload{padding:14px;}

  /* "More" modal on mobile — bottom sheet style */
  #moreModal[style*="display: flex"]{display:flex !important;}
  #moreModal{align-items:flex-end;}
  #moreModal .modal-content{
    max-width:100%; width:100%;
    border-radius:18px 18px 0 0;
    padding-bottom:max(20px, env(safe-area-inset-bottom, 20px));
  }
}

/* Very small phones (<=380px) */
@media (max-width:380px){
  .stat-grid{grid-template-columns:1fr;}
  .kpi-grid{grid-template-columns:1fr;}
  .mobile-tabbar .mtab .mtab-label{display:none;}
  .mobile-tabbar .mtab svg{width:20px; height:20px;}
}

/* Landscape orientation on phones — give a bit more height to charts */
@media (max-width:900px) and (orientation:landscape){
  .chart-wrap{height:160px;}
  .stat-grid{grid-template-columns:repeat(4,1fr);}
  .stat-value{font-size:20px;}
}

/* Desktop-only: hide mobile app bar + bottom tab bar */
@media (min-width:761px){
  .mobile-appbar{display:none !important;}
  .mobile-tabbar{display:none !important;}
}

/* ============ PRINT ============ */
@media print{
  .sidebar, .topbar-actions, .panel-head .actions, .form-actions{display:none !important;}
  body{background:#fff; color:#000;}
  .main{padding:0;}
  .panel{box-shadow:none; border-color:#ccc;}
}

/* ============ LOGIN SCREEN HIDDEN WHEN AUTHED ============ */
body.authed .login-screen{display:none;}
