/* =============================================================================
   Teik Fishery Employee Management System — shared styles (premium theme)
   Navy + teal maritime palette, Inter typography. Mobile-first responsive.
   ============================================================================= */

:root {
  /* palette */
  --bg: #f7f1ef;
  --surface: rgba(255, 255, 255, 0.9);
  --border: #ead9df;
  --border-strong: #d9c2cb;
  --text: #2b2228;
  --muted: #8a7580;
  --navy-900: #321420;
  --navy-800: #5e1b31;
  --navy-700: #7a2440;
  --primary: #7a2440;          /* harbor maroon (Hua Hong logo banner) */
  --primary-dark: #5e1b31;
  --primary-soft: #f9e8ed;
  --gold: #e3b7c4;             /* blush accent */
  --blue: #3e5c94;             /* logo wave blue */
  --blue-soft: #e9f0fa;
  --input-bg: #ffffff;
  --danger: #c0392b;
  --danger-soft: #fdeae7;
  --ok: #1e7d3c;
  --ok-soft: #e6f4ea;
  --warn: #b07a06;
  --warn-soft: #fdf3dd;
  --warn-border: #e3b341;

  /* shape & depth */
  --radius: 14px;
  --radius-sm: 9px;
  --shadow: 0 1px 2px rgba(10,28,44,.05), 0 8px 24px rgba(10,28,44,.06);
  --shadow-lift: 0 2px 4px rgba(10,28,44,.07), 0 14px 34px rgba(10,28,44,.12);
  --maxw: 1140px;
  --font: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

* { box-sizing: border-box; }

html, body {
  margin: 0; padding: 0;
  background: linear-gradient(160deg, #fbf6f2 0%, #f7edee 38%, #eff0f7 100%) fixed var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 15.5px;
  line-height: 1.55;
  -webkit-text-size-adjust: 100%;
  -webkit-font-smoothing: antialiased;
  /* Guard: no element may widen the page sideways. "clip" (modern browsers)
     does this WITHOUT breaking position:sticky (the split-view side panel);
     "hidden" stays as fallback for old browsers. */
  overflow-x: hidden;
  overflow-x: clip;
}

a { color: var(--blue); text-decoration: none; }
a:hover { text-decoration: none; }

h1,h2,h3,h4 { letter-spacing: -0.015em; }

/* ---- Top bar / navigation -------------------------------------------------- */
.topbar {
  background: linear-gradient(135deg, var(--navy-900) 0%, var(--navy-800) 60%, #8c3552 100%);
  color: #fff;
  position: sticky; top: 0; z-index: 50;
  box-shadow: 0 2px 14px rgba(50,20,32,.25);
}
.topbar-inner {
  max-width: var(--maxw);
  margin: 0 auto;
  padding: 0 18px;
  display: flex; align-items: center; gap: 22px;
  min-height: 62px;
}
.brand {
  display: flex; align-items: center; gap: 11px;
  color: #fff; text-decoration: none; flex: 0 0 auto;
}
.brand-mark {
  width: 36px; height: 36px; border-radius: 10px;
  background: linear-gradient(140deg, var(--primary) 0%, #a04464 100%);
  display: flex; align-items: center; justify-content: center;
  box-shadow: 0 3px 10px rgba(122,36,64,.45);
}
.brand-mark svg { width: 20px; height: 20px; fill: #fff; }
.brand-mark.logo { background: #fff; padding: 3px; }
.brand-mark.logo img { width: 100%; height: 100%; object-fit: contain; border-radius: 8px; display: block; }
.brand strong { display: block; font-size: .98rem; font-weight: 700; line-height: 1.15; }
.brand small { display: block; font-size: .68rem; font-weight: 500; color: #d8aebc; letter-spacing: .02em; }

.topnav {
  display: flex; gap: 4px; flex: 1 1 auto;
  overflow-x: auto; scrollbar-width: none;
}
.topnav::-webkit-scrollbar { display: none; }
.nav-link {
  color: #ddb9c7; font-size: .9rem; font-weight: 600;
  padding: 8px 13px; border-radius: 9px; white-space: nowrap;
  transition: background .15s ease, color .15s ease;
}
.nav-link:hover { color: #fff; background: rgba(255,255,255,.08); }
.nav-link.active { color: #fff; background: rgba(255,255,255,.13); box-shadow: inset 0 -2px 0 var(--gold); }

.topbar .user { display: flex; align-items: center; gap: 10px; flex: 0 0 auto; }
.user-chip {
  font-size: .78rem; color: #e0c2ce; background: rgba(255,255,255,.08);
  border: 1px solid rgba(255,255,255,.12);
  padding: 6px 12px; border-radius: 999px; max-width: 200px;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.btn-ghost {
  background: transparent; color: #e0c2ce;
  border: 1px solid rgba(255,255,255,.25);
  padding: 7px 14px; border-radius: 9px; font-size: .82rem; font-weight: 600;
  cursor: pointer; transition: all .15s ease; font-family: inherit;
}
.btn-ghost:hover { background: rgba(255,255,255,.12); color: #fff; }

/* ---- Desktop sidebar (≥900px replaces the top bar; phones/tablets keep
   their current bars — pure CSS switch, no extra payload) ------------------- */
.sidebar { display: none; }
@media (min-width: 900px) {
  .topbar { display: none; }
  .sidebar {
    display: flex; flex-direction: column; gap: 0;
    position: fixed; left: 0; top: 0; bottom: 0; width: 232px; z-index: 50;
    background: linear-gradient(170deg, var(--navy-900) 0%, var(--navy-800) 62%, #8c3552 100%);
    padding: 20px 14px 16px;
    box-shadow: 2px 0 14px rgba(50,20,32,.22);
    overflow-y: auto;
  }
  .sidebar .brand { padding: 0 6px 16px; border-bottom: 1px solid rgba(255,255,255,.14); }
  .sidenav { display: flex; flex-direction: column; gap: 4px; margin-top: 14px; }
  .snav-link {
    display: flex; align-items: center; gap: 11px;
    color: #ddb9c7; font-size: .92rem; font-weight: 600;
    padding: 10px 12px; border-radius: 10px;
    transition: background .15s ease, color .15s ease;
  }
  .snav-link svg { width: 19px; height: 19px; flex: 0 0 auto; }
  .snav-link:hover { color: #fff; background: rgba(255,255,255,.08); }
  .snav-link.active { color: #fff; background: rgba(255,255,255,.15); box-shadow: inset 3px 0 0 var(--gold); }
  /* Sub-item (Renewals nested under PLKS Files): indented, smaller, with a connector tick. */
  .snav-sub { margin-left: 18px; padding-top: 7px; padding-bottom: 7px; font-size: .85rem; color: #c9a3b3; position: relative; }
  .snav-sub::before { content: ""; position: absolute; left: -8px; top: 50%; width: 8px; height: 1px; background: rgba(255,255,255,.22); }
  .snav-sub svg { width: 16px; height: 16px; }
  /* Group header (e.g. LHDN): same size as a main item, but not clickable. */
  .snav-head { cursor: default; margin-top: 4px; }
  .snav-head:hover { background: transparent; color: #ddb9c7; }
  .side-foot { display: flex; flex-direction: column; gap: 9px; padding-top: 14px; border-top: 1px solid rgba(255,255,255,.14); }
  .side-foot .user-chip { max-width: none; text-align: center; }
}
html[data-theme="dark"] .sidebar { background: linear-gradient(170deg, #120a0e 0%, #3a1424 62%, #5e2038 100%); }

/* ---- Layout ----------------------------------------------------------------- */
.container { max-width: var(--maxw); margin: 0 auto; padding: 26px 18px 70px; }
@media (min-width: 900px) {
  /* content sits beside the fixed sidebar and may grow wider */
  .container { margin: 0 auto 0 232px; max-width: 1240px; padding: 28px 32px 70px; }
}

.page-title { font-size: 1.45rem; font-weight: 800; margin: 4px 0 20px; color: var(--navy-900); }
.page-sub { color: var(--muted); font-size: .9rem; margin: -14px 0 20px; }

/* ---- Cards ------------------------------------------------------------------ */
.grid { display: grid; gap: 16px; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); }

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 22px;
}

.nav-card {
  display: flex; gap: 14px; align-items: flex-start;
  transition: transform .14s ease, box-shadow .18s ease, border-color .18s ease;
}
.nav-card:hover { transform: translateY(-3px); box-shadow: var(--shadow-lift); border-color: var(--primary); }
.nav-card .icon {
  flex: 0 0 auto; width: 42px; height: 42px; border-radius: 11px;
  background: var(--primary-soft); color: var(--primary);
  display: flex; align-items: center; justify-content: center;
}
.nav-card .icon svg { width: 22px; height: 22px; }
.nav-card h3 { margin: 2px 0 4px; color: var(--navy-900); font-size: 1.02rem; }
.nav-card p { margin: 0; color: var(--muted); font-size: .85rem; line-height: 1.45; }

/* ---- Stat cards --------------------------------------------------------------- */
.stats { display: grid; gap: 16px; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); margin-bottom: 26px; }
.stat {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); box-shadow: var(--shadow);
  padding: 18px 20px; display: flex; align-items: center; gap: 14px;
}
.stat .stat-icon {
  width: 44px; height: 44px; border-radius: 12px; flex: 0 0 auto;
  display: flex; align-items: center; justify-content: center;
}
.stat .stat-icon svg { width: 22px; height: 22px; }
.stat-num { font-size: 1.55rem; font-weight: 800; color: var(--navy-900); line-height: 1.1; }
.stat-label { font-size: .78rem; font-weight: 600; color: var(--muted); letter-spacing: .02em; }
.stat.warn { border-color: var(--warn-border); background: linear-gradient(0deg, var(--warn-soft), #fff 70%); }

/* ---- Forms -------------------------------------------------------------------- */
.field { margin-bottom: 15px; }
.field label {
  display: block; font-size: .78rem; color: var(--muted);
  margin-bottom: 6px; font-weight: 700; letter-spacing: .02em;
}
.field input, .field select, .field textarea {
  width: 100%; padding: 11px 13px;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  font-size: .95rem; font-family: inherit;
  background: var(--input-bg); color: var(--text);
  transition: border-color .15s ease, box-shadow .15s ease;
}
.field input:focus, .field select:focus, .field textarea:focus {
  outline: none; border-color: var(--primary);
  box-shadow: 0 0 0 3.5px rgba(122,36,64,.14);
}
/* iOS Safari: date inputs have an intrinsic width + centered text that
   overflows grid columns — normalise them. */
.field input, .field select, .field textarea { min-width: 0; max-width: 100%; }
.field input[type="date"] {
  -webkit-appearance: none;
  appearance: none;
  display: block;
  width: 100%;
  min-height: 44px;
  text-align: left;
}
input[type="date"]::-webkit-date-and-time-value { text-align: left; }

button, .btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  padding: 11px 20px; border: none; border-radius: 999px;
  background: linear-gradient(135deg, var(--primary) 0%, var(--primary-dark) 100%);
  color: #fff; font-size: .93rem; font-family: inherit; font-weight: 700;
  cursor: pointer; transition: filter .15s ease, transform .12s ease, box-shadow .15s ease;
  box-shadow: 0 2px 8px rgba(122,36,64,.28);
}
button:hover, .btn:hover { filter: brightness(1.08); transform: translateY(-2px); box-shadow: 0 4px 14px rgba(122,36,64,.35); }
button:active, .btn:active { transform: translateY(1px); }
button:disabled { opacity: .55; cursor: not-allowed; }

/* User decision 2026-06-07: ALL buttons share the solid maroon pill style
   (Option B). .btn-secondary intentionally no longer overrides it. */
.btn-danger { background: linear-gradient(135deg, #c0392b, #a93226); box-shadow: 0 2px 8px rgba(192,57,43,.3); }

/* ---- Messages ------------------------------------------------------------------ */
.msg { padding: 12px 15px; border-radius: var(--radius-sm); font-size: .9rem; font-weight: 500; margin-bottom: 16px; }
.msg-error { background: var(--danger-soft); color: var(--danger); border: 1px solid #f0c2bb; }
.msg-ok { background: var(--ok-soft); color: var(--ok); border: 1px solid #bfe0c8; }

/* ---- Tables --------------------------------------------------------------------- */
.table-wrap {
  overflow-x: auto; background: var(--surface);
  border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: var(--shadow);
}
table { width: 100%; border-collapse: collapse; font-size: .9rem; }
th, td { text-align: left; padding: 13px 16px; border-bottom: 1px solid var(--border); white-space: nowrap; }
tbody tr:last-child td { border-bottom: none; }
th {
  background: #f6edf0; color: var(--muted);
  font-weight: 700; font-size: .72rem; text-transform: uppercase; letter-spacing: .06em;
  position: sticky; top: 0;
}
tbody tr { transition: background .12s ease; }
tbody tr:hover { background: #fbf4f6; }
tr.expiring { background: var(--warn-soft); }
tr.expiring:hover { background: #fbedcc; }
tr.expiring td:first-child { box-shadow: inset 3px 0 0 var(--warn-border); }

.badge {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 3px 10px; border-radius: 999px; font-size: .73rem; font-weight: 700;
}
.badge::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.badge-warn { background: var(--warn-soft); color: var(--warn); border: 1px solid var(--warn-border); }
.badge-ok { background: var(--ok-soft); color: var(--ok); border: 1px solid #bfe0c8; }
.badge-muted { background: #eef1f4; color: var(--muted); border: 1px solid var(--border-strong); }
.badge-danger { background: var(--danger-soft); color: var(--danger); border: 1px solid var(--danger); }
.msg-warn { background: var(--warn-soft); color: var(--warn); border: 1px solid var(--warn-border); }

/* ---- Login ------------------------------------------------------------------------ */
.auth-wrap {
  min-height: 100vh; display: flex; align-items: center; justify-content: center;
  padding: 20px;
  background:
    radial-gradient(1100px 500px at 85% -10%, rgba(62,92,148,.30), transparent 60%),
    radial-gradient(900px 500px at -10% 110%, rgba(227,183,196,.18), transparent 55%),
    linear-gradient(150deg, #260b15 0%, var(--navy-800) 55%, #3f2640 100%);
}
.auth-card { width: 100%; max-width: 400px; padding: 34px 32px; border: none; }
.auth-logo {
  width: 52px; height: 52px; border-radius: 14px; margin-bottom: 18px;
  background: linear-gradient(140deg, var(--primary) 0%, #a04464 100%);
  display: flex; align-items: center; justify-content: center;
  box-shadow: 0 6px 18px rgba(122,36,64,.4);
}
.auth-logo svg { width: 28px; height: 28px; fill: #fff; }
.auth-card h1 { font-size: 1.32rem; font-weight: 800; margin: 0 0 4px; color: var(--navy-900); }
.auth-card .sub { color: var(--muted); font-size: .88rem; margin: 0 0 24px; }
.auth-card button { width: 100%; padding: 13px; }

/* ---- Scan box (shared look for scan-or-manual) ------------------------------------- */
.scan-box {
  border: 2px dashed var(--border-strong); border-radius: var(--radius);
  padding: 18px; background: var(--surface); margin-bottom: 20px;
  transition: border-color .15s ease;
}
.scan-box:hover { border-color: var(--primary); }
.scan-box.haspreview { border-style: solid; border-color: var(--primary); }
.scan-preview { max-width: 100%; max-height: 240px; border-radius: 10px; margin-top: 12px; display: block; box-shadow: var(--shadow); }

/* ---- Utilities ----------------------------------------------------------------------- */
.row { display: flex; gap: 12px; flex-wrap: wrap; align-items: center; }
.row > * { flex: 1 1 auto; }
.spacer { flex: 1; }
.muted { color: var(--muted); }
.last-edit { margin-top: 8px; font-size: .7rem; color: var(--muted); letter-spacing: .01em; }
.plist-kv + .plist-kv { margin-top: 14px; padding-top: 14px; border-top: 1px dashed var(--border-strong); }
.field-bad {
  border-color: var(--danger) !important;
  box-shadow: 0 0 0 3px var(--danger-soft) !important;
  animation: fieldShake .25s ease 1;
}
@keyframes fieldShake { 25% { transform: translateX(-3px); } 75% { transform: translateX(3px); } }

/* ---- Generated documents card --------------------------------------------------- */
.gen-sec {
  font-size: .78rem; font-weight: 800; color: var(--primary);
  background: var(--primary-soft); border-left: 3px solid var(--primary);
  padding: 6px 10px; border-radius: 0 7px 7px 0;
  letter-spacing: .03em; margin: 12px 0 4px;
}
.gen-row {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 0; border-top: 1px solid var(--border);
}
.gen-main { flex: 1; min-width: 0; }
.gen-opt {
  display: block; width: 100%; text-align: left;
  background: var(--input-bg); color: var(--text);
  border: 1px solid var(--border-strong); border-radius: var(--radius-sm);
  padding: 10px 12px; box-shadow: none;
}
.gen-opt:hover { border-color: var(--primary); background: var(--primary-soft); filter: none; transform: none; box-shadow: none; }
.gen-opt.sel { border-color: var(--primary); background: var(--primary-soft); box-shadow: 0 0 0 2px var(--primary-soft); }

/* ---- Alerts: error card, success pill, confirm sheet --------------------------- */
.tk-toast {
  position: fixed; z-index: 300; top: 74px; right: 18px;
  max-width: 360px; display: flex; gap: 10px; align-items: flex-start;
  background: var(--surface); border: 1px solid var(--border);
  border-left: 4px solid var(--danger); border-radius: 0 var(--radius) var(--radius) 0;
  padding: 12px 12px 12px 14px; box-shadow: var(--shadow-lift);
  font-size: .86rem; color: var(--text); animation: tkIn .22s ease;
}
.tk-toast .tk-t-ic { color: var(--danger); flex: 0 0 auto; margin-top: 1px; display: flex; }
.tk-toast .tk-t-msg { flex: 1; min-width: 0; line-height: 1.45; font-weight: 500; }
.tk-toast .tk-t-x { color: var(--muted); cursor: pointer; flex: 0 0 auto; padding: 2px; display: flex; }
.tk-toast .tk-t-x:hover { color: var(--text); }
.tk-pill {
  position: fixed; z-index: 300; left: 50%; transform: translateX(-50%); bottom: 26px;
  background: var(--primary-dark); color: #fff; border-radius: 999px;
  padding: 10px 18px; font-size: .87rem; font-weight: 600;
  display: flex; align-items: center; gap: 8px; max-width: calc(100% - 32px);
  box-shadow: 0 6px 18px rgba(50,20,32,.35); animation: tkUp .22s ease;
}
.tk-pill .tk-p-ic { color: #7fd49a; display: flex; flex: 0 0 auto; }
.tk-sheet-wrap {
  position: fixed; inset: 0; z-index: 400; background: rgba(50,20,32,.45);
  display: flex; align-items: center; justify-content: center; padding: 20px;
  animation: tkFade .18s ease;
}
.tk-sheet {
  background: var(--surface); border-radius: var(--radius); padding: 22px 20px;
  max-width: 340px; width: 100%; text-align: center;
  box-shadow: var(--shadow-lift); animation: tkPop .2s ease;
}
.tk-sheet-ic {
  width: 46px; height: 46px; border-radius: 50%;
  background: var(--primary-soft); color: var(--primary);
  display: flex; align-items: center; justify-content: center; margin: 0 auto 12px;
}
.tk-sheet-ic.danger { background: var(--danger-soft); color: var(--danger); }
.tk-sheet-title { font-weight: 700; font-size: 1rem; }
.tk-sheet-sub { font-size: .82rem; color: var(--muted); margin-top: 6px; line-height: 1.5; white-space: pre-line; }
.tk-sheet-btns { display: flex; gap: 10px; margin-top: 18px; }
.tk-sheet-btns button { flex: 1; padding: 10px; }
.tk-sheet .tk-cancel { background: var(--input-bg); color: var(--muted); border: 1.5px solid var(--border-strong); box-shadow: none; }
.tk-sheet .tk-cancel:hover { filter: none; transform: none; box-shadow: none; border-color: var(--primary); color: var(--primary); }
.tk-sheet .tk-ok.danger { background: linear-gradient(135deg, #c0392b, #a93226); box-shadow: 0 2px 8px rgba(192,57,43,.3); }
@keyframes tkIn { from { opacity: 0; transform: translateY(-8px); } }
@keyframes tkUp { from { opacity: 0; transform: translate(-50%, 8px); } }
@keyframes tkFade { from { opacity: 0; } }
@keyframes tkPop { from { opacity: 0; transform: scale(.94); } }
@media (max-width: 640px) {
  .tk-toast { left: 12px; right: 12px; top: 66px; max-width: none; }
  .tk-pill { bottom: 96px; white-space: normal; text-align: center; }   /* clears the bottom tab bar */
  .tk-sheet-wrap { align-items: flex-end; padding: 0; }
  .tk-sheet { max-width: none; border-radius: 18px 18px 0 0; padding-bottom: 26px; animation: tkSlide .22s ease; }
}
@keyframes tkSlide { from { transform: translateY(40px); opacity: 0; } }
.center { text-align: center; }
.hidden { display: none !important; }
/* Sticky search/filter toolbar — stays reachable when a long list is scrolled.
   Frosted so rows scroll cleanly underneath. */
.search-bar {
  margin-bottom: 18px;
  position: sticky; top: 0; z-index: 20;
  padding: 10px 0; margin-bottom: 12px;
  background: rgba(251, 246, 242, .82);
  -webkit-backdrop-filter: blur(8px); backdrop-filter: blur(8px);
}
@supports not (backdrop-filter: blur(1px)) { .search-bar { background: var(--bg); } }
html[data-theme="dark"] .search-bar { background: rgba(26, 14, 20, .85); }
@media (max-width: 899px) {
  /* sit just below the sticky mobile top bar */
  .search-bar { top: 56px; }
}
.search-bar input {
  max-width: 440px; width: 100%;
  padding: 11px 14px;
  border: 1px solid var(--border-strong); border-radius: 999px;
  font-size: .93rem; font-family: inherit; background: var(--input-bg); color: var(--text);
  transition: border-color .15s ease, box-shadow .15s ease;
}
.search-bar input:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 3.5px rgba(122,36,64,.14); }

.avatar { width: 34px; height: 34px; border-radius: 50%; object-fit: cover; background: #e2ebf2; vertical-align: middle; display: inline-block; }
.avatar-sq { border-radius: 9px; }   /* square-ish frame for buildings & boats */

/* ---- Profile views (employee / vessel / fishery detail) ----------------------- */
.profile-head { text-align: center; padding: 6px 0 14px; }
.profile-avatar {
  width: 84px; height: 84px; border-radius: 50%; object-fit: cover;
  background: #fff; border: 3px solid var(--gold); display: inline-block;
}
.profile-avatar.sq { border-radius: 20px; }
.profile-name { margin: 10px 0 0; font-size: 1.25rem; font-weight: 800; color: var(--navy-900); }
.profile-sub { margin: 2px 0 10px; font-size: .88rem; color: var(--muted); }
.stat-strip {
  display: flex; background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); box-shadow: var(--shadow);
  padding: 12px 0; margin-bottom: 16px;
}
.stat-strip > div { flex: 1; text-align: center; min-width: 0; }
.stat-strip > div + div { border-left: 1px solid var(--border); }
.stat-strip .n { font-size: 1.05rem; font-weight: 800; color: var(--navy-900); }
.stat-strip .n.warn-n { color: var(--primary); }
.stat-strip .l { font-size: .68rem; font-weight: 600; color: var(--muted); }
details.psec {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); box-shadow: var(--shadow); margin-bottom: 10px;
}
details.psec summary {
  list-style: none; cursor: pointer; display: flex; align-items: center; gap: 10px;
  padding: 14px 18px; font-weight: 700; font-size: .95rem; color: var(--text);
}
details.psec summary::-webkit-details-marker { display: none; }
details.psec summary .chev { margin-left: auto; transition: transform .15s ease; color: var(--border-strong); }
details.psec[open] summary .chev { transform: rotate(90deg); }
details.psec summary .cnt {
  background: var(--primary-soft); color: var(--primary);
  font-size: .72rem; font-weight: 700; border-radius: 999px; padding: 1px 9px;
}
details.psec .psec-body { padding: 2px 18px 16px; }
.kv { display: grid; grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); gap: 12px 16px; }
.kv .k { font-size: .68rem; font-weight: 700; color: var(--muted); letter-spacing: .03em; text-transform: uppercase; }
.kv .v { font-size: .92rem; font-weight: 600; word-break: break-word; }
.kv .v.empty { color: var(--border-strong); font-weight: 400; }
.profile-actions { display: flex; gap: 10px; margin: 4px 0 16px; }
.profile-actions > * { flex: 1; }
.plist-row { display: flex; align-items: center; gap: 10px; padding: 9px 0; border-top: 1px solid var(--border); font-size: .9rem; }
.plist-row:first-child { border-top: none; }

/* Desktop: profile spreads into two columns */
@media (min-width: 900px) {
  .profile-grid { display: flex; gap: 16px; align-items: flex-start; }
  .profile-grid .pcol-main { flex: 1.6; min-width: 0; }
  .profile-grid .pcol-side { flex: 1; min-width: 0; }
}

/* ---- Wizard (new/edit employee) ------------------------------------------------ */
.wiz-chips { display: flex; align-items: center; gap: 6px; margin: 0 0 16px; flex-wrap: wrap; }
.wiz-chip {
  border-radius: 999px; padding: 5px 13px; font-size: .78rem; font-weight: 700;
  background: var(--input-bg); border: 1px solid var(--border-strong); color: var(--muted);
}
.wiz-chip.active { background: var(--primary); border-color: var(--primary); color: #f6e3ea; }
.wiz-chip.done { background: var(--primary-soft); border-color: var(--gold); color: var(--primary); }
.wiz-line { flex: 1; height: 2px; background: var(--border); min-width: 12px; }
.wiz-nav {
  display: flex; gap: 10px; margin-top: 20px;
  position: sticky; bottom: 12px; z-index: 5;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); box-shadow: var(--shadow-lift); padding: 12px;
}
@media (max-width: 640px) { .wiz-nav { bottom: 92px; } }
/* Never let the sticky button bars overflow, at any window width. */
.wiz-nav button, .form-actions button { min-width: 0; white-space: nowrap; }
@media (max-width: 820px) {
  .wiz-nav, .form-actions { gap: 8px; }
  .wiz-nav button, .form-actions button {
    flex: 1 1 auto !important; padding: 10px 8px; font-size: .85rem;
  }
  .wiz-nav .spacer, .form-actions .spacer { display: none; }
}
.scan-ok { border-color: var(--ok) !important; background: var(--ok-soft) !important; }
.review-row { display: flex; gap: 12px; padding: 7px 0; border-bottom: 1px solid var(--border); font-size: .9rem; }
.review-row .rk { flex: 0 0 46%; color: var(--muted); font-size: .8rem; font-weight: 600; }
.review-row .rv { flex: 1; font-weight: 600; word-break: break-word; }

/* ---- Night mode 夜间 ------------------------------------------------------------ */
html[data-theme="dark"] {
  --bg: #1a0e14;
  --surface: rgba(43, 25, 33, 0.92);
  --border: #4a2a38;
  --border-strong: #5e3a4a;
  --text: #f4e7ec;
  --muted: #c39aab;
  --navy-900: #f4e7ec;
  --navy-800: #3a1424;
  --primary: #a04464;
  --primary-dark: #7a2440;
  --primary-soft: #3a1b28;
  --gold: #e3b7c4;
  --blue: #8fa8d8;
  --blue-soft: #243450;
  --input-bg: #2b1620;
  --ok: #7fd49a;
  --ok-soft: #1c3a28;
  --warn: #fac775;
  --warn-soft: #3a2c12;
  --warn-border: #8a6a2a;
  --danger: #ff9d92;
  --danger-soft: #3a1b1b;
  --shadow: 0 1px 2px rgba(0,0,0,.3), 0 8px 24px rgba(0,0,0,.25);
  --shadow-lift: 0 2px 4px rgba(0,0,0,.35), 0 14px 34px rgba(0,0,0,.4);
}
html[data-theme="dark"], html[data-theme="dark"] body {
  background: linear-gradient(160deg, #170c11 0%, #1f1018 45%, #141220 100%) fixed;
}
html[data-theme="dark"] .topbar { background: linear-gradient(135deg, #120a0e 0%, #3a1424 60%, #5e2038 100%); }
html[data-theme="dark"] th { background: #321a24; }
html[data-theme="dark"] tbody tr:hover { background: #33202a; }
html[data-theme="dark"] tr.expiring { background: #3a2c12; }
html[data-theme="dark"] tr.expiring:hover { background: #46361a; }
html[data-theme="dark"] .stat.warn { background: var(--warn-soft); }
html[data-theme="dark"] .bottombar { background: rgba(23,12,17,.97); }
html[data-theme="dark"] .bb-plus { border-color: #1a0e14; }
html[data-theme="dark"] .badge-muted { background: #322631; color: var(--muted); border-color: var(--border-strong); }
html[data-theme="dark"] .msg-ok { background: var(--ok-soft); border-color: #2c5a3c; }
html[data-theme="dark"] .msg-error { background: var(--danger-soft); color: #f0a8a0; border-color: #5e2a2a; }
html[data-theme="dark"] .msg-warn { background: var(--warn-soft); border-color: var(--warn-border); }
html[data-theme="dark"] .badge-ok { background: var(--ok-soft); border-color: #2c5a3c; }
html[data-theme="dark"] .badge-warn { background: var(--warn-soft); border-color: var(--warn-border); }
html[data-theme="dark"] .profile-avatar { background: #2b1620; }

/* ---- Document rows (no horizontal scroll, actions always visible) -------------- */
.doc-row {
  display: flex; align-items: center; gap: 8px;
  padding: 9px 0; border-top: 1px solid var(--border);
}
.doc-row:first-child { border-top: none; }
.doc-main { min-width: 0; flex: 1; }
.doc-main a {
  font-weight: 600; font-size: .88rem; word-break: break-all;
}
.doc-meta { font-size: .72rem; color: var(--muted); margin-top: 1px; }
.doc-ic {
  flex: 0 0 auto; width: 34px; height: 34px; padding: 0;
  display: inline-flex; align-items: center; justify-content: center;
  background: var(--input-bg); color: var(--text);
  border: 1px solid var(--border-strong); border-radius: 9px; box-shadow: none;
}
.doc-ic:hover { border-color: var(--primary); color: var(--primary); background: var(--input-bg); filter: none; box-shadow: none; }
.doc-ic.danger { color: var(--danger); }
.doc-ic.danger:hover { border-color: var(--danger); background: var(--danger-soft); color: var(--danger); }
.doc-row .dsel { width: 16px; height: 16px; accent-color: var(--primary); flex: 0 0 auto; cursor: pointer; }
.doc-multibar {
  display: flex; align-items: center; gap: 10px;
  padding: 0 0 9px; font-size: .8rem; border-bottom: 1px solid var(--border);
}
.doc-multibar label { display: flex; align-items: center; gap: 6px; font-weight: 700; color: var(--muted); cursor: pointer; }
.doc-multibar input { width: 16px; height: 16px; accent-color: var(--primary); cursor: pointer; }
.doc-multibar .dm-count { font-size: .74rem; }

/* ---- List redesign: expiry chips, status toggle, mobile cards ------------------ */
.xchip {
  display: inline-flex; flex-direction: column; align-items: center;
  border-radius: 9px; padding: 3px 9px; line-height: 1.35;
  font-size: .68rem; font-weight: 700; text-align: center;
}
.xchip i { font-style: normal; font-size: .72rem; font-weight: 600; }
.xchip.okc { background: var(--ok-soft); color: var(--ok); }
.xchip.warnc { background: var(--warn-soft); color: var(--warn); }
.xchip.urgc { background: var(--primary); color: #f6e3ea; }
.xchip.mutedc { background: var(--primary-soft); color: var(--muted); }

.switch { position: relative; display: inline-block; width: 40px; height: 22px; flex: 0 0 auto; cursor: pointer; }
.switch input { opacity: 0; width: 0; height: 0; position: absolute; }
.switch .knob { position: absolute; inset: 0; border-radius: 999px; background: var(--border-strong); transition: background .15s ease; }
.switch .knob::after {
  content: ""; position: absolute; top: 2px; left: 2px;
  width: 18px; height: 18px; border-radius: 50%; background: #fff;
  transition: transform .15s ease;
}
.switch input:checked + .knob { background: var(--ok); }
.switch input:checked + .knob::after { transform: translateX(18px); }
.tgl-wrap { text-align: center; flex: 0 0 auto; }
.tgl-l { font-size: .58rem; font-weight: 700; margin-top: 2px; color: var(--muted); }
.tgl-l.on { color: var(--ok); }

.mob-cards { display: none; }
.mcard {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 16px; box-shadow: var(--shadow);
  padding: 12px; margin-bottom: 10px; cursor: pointer;
}
.mcard.urgent { border-color: var(--warn-border); }
.mcard.urgent.expired { border-color: var(--primary); }
.mcard.inactive { opacity: .7; }
/* Top alert strip — clearly flags an expiring/expired document. */
.mc-alert {
  display: flex; align-items: center; gap: 5px;
  font-size: .72rem; font-weight: 700;
  padding: 6px 12px; margin: -12px -12px 10px;
  border-radius: 15px 15px 0 0;
}
.mc-alert.warn { background: var(--warn-soft); color: var(--warn); border-bottom: 1px solid var(--warn-border); }
.mc-alert.exp  { background: var(--primary); color: #f6e3ea; }
/* Global files (shared library: Settings manages, others view/download) */
.gfile-row { display: flex; align-items: center; gap: 8px; padding: 7px 0; border-bottom: 1px solid var(--border); }
.gfile-row:last-child { border-bottom: none; }
.gfile-ic { flex: 0 0 auto; color: #A32D2D; display: flex; }
.gfile-nm { flex: 1 1 auto; min-width: 0; font-size: .82rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.gfile-sz { flex: 0 0 auto; font-size: .68rem; color: var(--muted); }
.gfile-ib { flex: 0 0 auto; width: 30px; height: 30px; padding: 0; border-radius: 8px; border: 1px solid var(--border-strong); background: var(--surface); color: var(--muted); display: inline-flex; align-items: center; justify-content: center; cursor: pointer; }
.gfile-ib:hover { background: var(--input-bg); }
.gfile-ib.gfile-del { color: #A32D2D; border-color: #F09595; }
.gen-global-wrap { border-bottom: 1px dashed var(--border-strong); margin: 0 0 10px; padding: 0 0 8px; }
.gen-global-lbl { font-size: .72rem; font-weight: 700; color: var(--muted); margin: 0 0 2px; }
.mc-top { display: flex; align-items: center; gap: 10px; }
.mc-main { min-width: 0; flex: 1; }
.mc-name { font-size: .92rem; font-weight: 700; }
.mc-id { font-size: 1.02rem; font-weight: 700; color: var(--primary); letter-spacing: .05em; }
.mc-sub { font-size: .7rem; color: var(--muted); }
.mc-chips { display: flex; gap: 6px; margin-top: 9px; }
.mc-chips .xchip { flex: 1; }
.mc-pill {
  background: var(--blue-soft); color: var(--blue);
  font-size: .7rem; font-weight: 700; border-radius: 999px; padding: 3px 10px;
  flex: 0 0 auto; white-space: nowrap;
}
@media (max-width: 640px) {
  .mob-cards { display: block; }
  .list-desktop { display: none !important; }
  .form-actions {
    position: sticky; bottom: 92px; z-index: 5;
    background: var(--surface); border: 1px solid var(--border);
    border-radius: var(--radius); box-shadow: var(--shadow-lift); padding: 12px;
  }
}

/* ---- Pager + mobile-only helpers ---------------------------------------------- */
.bottombar { display: none; }   /* shown only on mobile (media query below) */
.pager { display: flex; gap: 12px; align-items: center; justify-content: center; margin: 18px 0 0; flex-wrap: wrap; }
.mobile-only { display: none !important; }
@media (max-width: 640px) {
  .mobile-only { display: inline-flex !important; }
}

/* ---- Split view (desktop list + live side panel, all list pages) ------------- */
#spPanel { display: none; }
@media (min-width: 900px) {
  .split-wrap { display: flex; gap: 16px; align-items: flex-start; }
  .split-list { flex: 1.55; min-width: 0; }
  #spPanel { display: block; flex: 1; min-width: 280px; max-width: 380px; position: sticky; top: 20px; }
  tr.sel-row td { background: var(--primary-soft); }
  tr.sel-row td:first-child { box-shadow: inset 3px 0 0 var(--primary); }
}
.sp-kv { display: grid; grid-template-columns: 1fr 1fr; gap: 9px 12px; text-align: left;
         border-top: 1px solid var(--border); padding-top: 12px; margin-top: 12px; }
.sp-kv .k { font-size: .62rem; font-weight: 700; color: var(--muted); letter-spacing: .04em; text-transform: uppercase; }
.sp-kv .v { font-size: .86rem; font-weight: 600; word-break: break-word; }
.sp-btns { display: flex; gap: 8px; margin-top: 14px; flex-wrap: wrap; }
.sp-btns button { flex: 1 1 120px; padding: 9px 10px; font-size: .85rem; white-space: nowrap; }

/* Glass panel (desktop): pure CSS backdrop blur — zero network, GPU-painted.
   Browsers without backdrop-filter quietly keep the solid card. */
@media (min-width: 900px) {
  #spPanel .card {
    background: rgba(255, 255, 255, .55);
    -webkit-backdrop-filter: blur(14px);
    backdrop-filter: blur(14px);
    border: 1px solid rgba(255, 255, 255, .75);
    box-shadow: 0 8px 28px rgba(122, 36, 64, .10);
  }
  html[data-theme="dark"] #spPanel .card {
    background: rgba(43, 25, 33, .55);
    border-color: rgba(255, 255, 255, .10);
  }
  @supports not (backdrop-filter: blur(1px)) {
    #spPanel .card { background: var(--surface); border: 1px solid var(--border); }
  }
}

/* Status pill (panel + lists) */
.st-pill {
  display: inline-flex; align-items: center; gap: 5px; cursor: pointer;
  border-radius: 999px; padding: 4px 12px; font-size: .76rem; font-weight: 700;
  border: 1px solid transparent; background: var(--ok-soft); color: var(--ok); box-shadow: none;
}
.st-pill .dot { width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.st-pill.off { background: #eef1f4; color: var(--muted); }
.st-pill:hover { border-color: currentColor; filter: none; transform: none; box-shadow: none; }
html[data-theme="dark"] .st-pill.off { background: #322631; }

/* Two-line bilingual table headers (keeps columns narrow) */
th .th-cn { display: block; font-size: .62rem; font-weight: 600; text-transform: none; letter-spacing: .02em; margin-top: 1px; }

/* ---- Active deep-link filter chip (e.g. ?nat= from the dashboard) ------------ */
.flt-chip {
  display: inline-flex; align-items: center; gap: 7px; cursor: pointer;
  background: var(--primary-soft); color: var(--primary); border: 1px solid var(--gold);
  border-radius: 999px; padding: 6px 13px; font-size: .8rem; font-weight: 700; margin: 0 0 12px;
}
.flt-chip:hover { border-color: var(--primary); filter: none; transform: none; box-shadow: none; }
.flt-chip b { font-weight: 800; }
.flt-chip.flt-all { background: var(--input-bg); color: var(--muted); border-color: var(--border-strong); }
.flt-chip.flt-all:hover { color: var(--primary); border-color: var(--primary); }

/* ---- Multi-select relationship chips (family contact) ------------------------ */
.rel-chips { display: flex; flex-wrap: wrap; gap: 6px; }
.rel-chip {
  background: var(--input-bg); color: var(--muted);
  border: 1.5px solid var(--border-strong); border-radius: 999px;
  padding: 5px 12px; font-size: .8rem; font-weight: 600; cursor: pointer;
  box-shadow: none;
}
.rel-chip:hover { border-color: var(--primary); color: var(--primary); filter: none; transform: none; box-shadow: none; }
.rel-chip.sel { background: var(--primary-soft); border-color: var(--primary); color: var(--primary); }
.rel-chip.sel::before { content: "✓ "; }

/* ---- Count pill (record totals next to list titles) -------------------------- */
.count-pill {
  display: inline-block; background: var(--primary-soft); color: var(--primary);
  font-size: .78rem; font-weight: 800; border-radius: 999px;
  padding: 3px 12px; vertical-align: 3px; margin-left: 8px; white-space: nowrap;
}

/* ---- A–Z filter bar ---------------------------------------------------------- */
.alpha-bar { display: flex; gap: 4px; flex-wrap: wrap; margin: 0 0 16px; }
.alpha-chip {
  padding: 5px 9px; border-radius: 7px;
  border: 1px solid var(--border); background: var(--input-bg); color: var(--muted);
  font-size: .76rem; font-weight: 700; cursor: pointer;
  box-shadow: none; min-width: 30px;
}
.alpha-chip:hover { border-color: var(--primary); color: var(--primary); background: var(--input-bg); filter: none; box-shadow: none; transform: none; }
.alpha-chip.active { background: var(--primary); color: #fff; border-color: var(--primary); }

@media (max-width: 640px) {
  .brand small { display: none; }
  .user-chip { display: none; }
  .page-title { font-size: 1.25rem; }
  .container { padding: 18px 14px 148px; }   /* room for the tab bar + floating + button */
  .card { padding: 17px; }

  /* Topbar: brand + sign-out only; navigation moves to the bottom tab bar */
  .topbar-inner { gap: 8px 12px; padding: 10px 12px; min-height: 0; }
  .brand { flex: 1 1 auto; }
  .topbar .user { flex: 0 0 auto; }
  .topnav { display: none; }

  /* Bottom tab bar (app style) */
  .bottombar {
    display: flex; position: fixed; bottom: 0; left: 0; right: 0; z-index: 60;
    align-items: center; justify-content: space-around;
    background: rgba(255,255,255,.97);
    border-top: 1px solid var(--border);
    padding: 6px 8px calc(8px + env(safe-area-inset-bottom));
  }
  .bb-item {
    display: flex; flex-direction: column; align-items: center; gap: 3px;
    font-size: .72rem; font-weight: 600; color: var(--muted); text-decoration: none;
    flex: 1; min-width: 0;   /* 5 tabs share the width evenly */
  }
  .bb-item svg { width: 23px; height: 23px; }
  .bb-item.active { color: var(--primary); }
  /* + is a floating action button above the bar, bottom-right (Option A). */
  .bb-plus {
    position: fixed; right: 16px; bottom: calc(74px + env(safe-area-inset-bottom));
    width: 52px; height: 52px; border-radius: 50%; z-index: 61;
    background: linear-gradient(135deg, var(--primary), var(--primary-dark));
    display: flex; align-items: center; justify-content: center;
    box-shadow: 0 5px 14px rgba(122,36,64,.4);
  }
  .bb-plus svg { width: 24px; height: 24px; }

  /* Tighter stat cards (2-up) */
  .stats { grid-template-columns: 1fr 1fr; gap: 10px; margin-bottom: 18px; }
  .stat { padding: 12px 14px; gap: 10px; }
  .stat .stat-icon { width: 36px; height: 36px; border-radius: 10px; }
  .stat .stat-icon svg { width: 18px; height: 18px; }
  .stat-num { font-size: 1.25rem; }
  .stat-label { font-size: .68rem; }

  /* Lists: turn tables into stacked cards (uses td[data-label]) */
  .table-wrap { border: none; background: transparent; box-shadow: none; overflow: visible; }
  .table-wrap thead { display: none; }
  .table-wrap table, .table-wrap tbody, .table-wrap tr, .table-wrap td { display: block; width: 100%; }
  .table-wrap tr {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    margin-bottom: 12px;
    padding: 8px 0;
  }
  .table-wrap td {
    border-bottom: none;
    padding: 6px 16px;
    white-space: normal;
    display: flex; justify-content: space-between; align-items: center; gap: 12px;
    text-align: right;
    word-break: break-word;
  }
  .table-wrap td::before {
    content: attr(data-label);
    color: var(--muted); font-size: .7rem; font-weight: 700;
    text-transform: uppercase; letter-spacing: .05em;
    text-align: left; flex: 0 0 auto;
  }
  .table-wrap td:not([data-label])::before { content: none; }
  .table-wrap td.cell-avatar { justify-content: flex-start; padding-bottom: 0; }
  .table-wrap td.cell-action { padding-top: 10px; }
  .table-wrap td.cell-action button { flex: 1; }
  tr.expiring td:first-child { box-shadow: none; }
  .table-wrap tr.expiring { border-left: 4px solid var(--warn-border); }
}

/* Toggle switch + AI settings rows (Settings → AI) */
.sw { position:relative; display:inline-block; width:46px; height:26px; flex:none; }
.sw input { opacity:0; width:0; height:0; }
.sw span { position:absolute; inset:0; background:var(--border-strong); border-radius:20px; transition:.15s; cursor:pointer; }
.sw span::before { content:""; position:absolute; width:20px; height:20px; left:3px; top:3px; background:#fff; border-radius:50%; transition:.15s; }
.sw input:checked + span { background:var(--primary); }
.sw input:checked + span::before { transform:translateX(20px); }
.sw input:disabled + span { opacity:.55; cursor:default; }
.ai-row { display:flex; align-items:center; gap:12px; padding:13px 0; border-top:1px solid var(--border); }
.ai-row:first-child { border-top:none; }
.ai-row .ai-l { flex:1; min-width:0; }
.ai-row .ai-l b { font-weight:700; font-size:.9rem; }
.ai-row .ai-l div { font-size:.74rem; color:var(--muted); margin-top:2px; }
.ai-row.sub { padding-left:18px; }
