:root {
  /* surfaces */
  --bg: #f2f7f6;
  --panel: #ffffff;
  --panel-2: #f7fbfa;
  --sidebar: #ffffff;
  --ink: #132b2e;
  --muted: #64807f;
  --muted-2: #9fb5b4;
  --line: #e2edeb;
  --line-2: #ecf4f2;
  /* brand — deep teal with warm amber support */
  --brand: #0d9488;
  --brand-d: #0f766e;
  --brand-soft: #d9f3ef;
  --brand-soft-2: #bfe9e2;
  /* accents */
  --ev: #16a34a;
  --ice: #ea580c;
  --warn: #e11d48;
  --ok: #16a34a;
  --sky: #38bdf8;
  --amber: #f59e0b;
  --shadow: 0 1px 2px rgba(10, 45, 48, .04), 0 6px 18px rgba(10, 45, 48, .05);
  --shadow-lg: 0 10px 40px rgba(10, 45, 48, .12);
  --radius: 16px;
  --radius-sm: 11px;
  --ease: cubic-bezier(.22, .61, .36, 1);
  /* chart palette */
  --c1: #0d9488; --c2: #16a34a; --c3: #ea580c; --c4: #7c3aed;
  --c5: #0891b2; --c6: #f59e0b; --c7: #db2777; --c8: #475569;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  color: var(--ink);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
}
.hidden { display: none !important; }
button { cursor: pointer; font: inherit; }
code { background: var(--brand-soft); color: var(--brand-d); padding: 1px 5px; border-radius: 4px; font-size: .85em; }

/* ============================ animations ============================ */
@keyframes fadeUp {
  from { opacity: 0; transform: translateY(10px); }
  to   { opacity: 1; transform: translateY(0); }
}
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
@keyframes popIn {
  from { opacity: 0; transform: translateY(8px) scale(.97); }
  to   { opacity: 1; transform: translateY(0) scale(1); }
}
@keyframes slideInRight {
  from { opacity: 0; transform: translateX(24px); }
  to   { opacity: 1; transform: translateX(0); }
}
@keyframes spin { to { transform: rotate(360deg); } }
@keyframes shimmer { 100% { background-position: -200% 0; } }

/* ---------- Login ---------- */
.login-wrap {
  min-height: 100vh; display: grid; place-items: center;
  background: radial-gradient(1100px 560px at 50% -8%, #2dd4bf, #0d9488 42%, #0b3236 100%);
  padding: 20px;
}
.login-card {
  width: 100%; max-width: 388px; background: var(--panel);
  border-radius: 22px; padding: 34px; box-shadow: 0 30px 70px rgba(7, 40, 44, .45);
  display: flex; flex-direction: column; gap: 14px;
  animation: popIn .5s var(--ease) both;
}
.brand { display: flex; align-items: center; gap: 12px; margin-bottom: 8px; }
.brand h1 { margin: 0; font-size: 22px; letter-spacing: -.01em; }
.brand p { margin: 0; color: var(--muted); font-size: 13px; }
.logo {
  display: grid; place-items: center; width: 44px; height: 44px;
  background: linear-gradient(135deg, #2dd4bf, #0f766e); color: #fff;
  border-radius: 13px; font-weight: 800; font-size: 22px;
  box-shadow: 0 6px 16px rgba(13, 148, 136, .4);
}
.login-card label { display: flex; flex-direction: column; gap: 6px; font-size: 13px; color: var(--muted); }
.login-card input, .form input, .form select, .form textarea {
  padding: 11px 13px; border: 1px solid var(--line); border-radius: var(--radius-sm);
  font-size: 14px; color: var(--ink); background: var(--panel-2); transition: border-color .15s, box-shadow .15s;
}
.login-card input:focus, .form input:focus, .form select:focus, .form textarea:focus {
  outline: none; border-color: var(--brand); box-shadow: 0 0 0 3px var(--brand-soft);
}
.login-card button[type=submit], .form button[type=submit] {
  margin-top: 6px; padding: 12px; border: 0; border-radius: var(--radius-sm);
  background: var(--brand); color: #fff; font-weight: 600; transition: background .15s, transform .1s;
}
.login-card button[type=submit]:hover, .form button[type=submit]:hover { background: var(--brand-d); }
.login-card button[type=submit]:active { transform: scale(.98); }
.hint { font-size: 12px; color: var(--muted); margin: 4px 0 0; }
.error { color: var(--warn); font-size: 13px; min-height: 18px; margin: 0; }

/* ============================ App shell ============================ */
.app { display: grid; grid-template-columns: 248px 1fr; min-height: 100vh; }
.sidebar {
  background: var(--sidebar); color: var(--muted); display: flex; flex-direction: column;
  padding: 18px 14px; border-right: 1px solid var(--line); position: sticky; top: 0; height: 100vh;
}
.brand.small { color: var(--ink); padding: 6px 8px 4px; gap: 11px; align-items: center; }
.brand.small .logo { width: 36px; height: 36px; font-size: 18px; border-radius: 11px; }
.brand-text { display: flex; flex-direction: column; line-height: 1.15; }
.brand-name { font-weight: 800; letter-spacing: -.01em; font-size: 17px; }
.brand-tagline { font-size: 10.5px; color: var(--muted); font-weight: 500; letter-spacing: .01em; margin-top: 1px; }

#nav { display: flex; flex-direction: column; gap: 1px; margin-top: 14px; flex: 1; overflow-y: auto; }
.nav-group-label {
  font-size: 10.5px; text-transform: uppercase; letter-spacing: .09em; color: var(--muted-2);
  font-weight: 700; padding: 14px 12px 6px;
}
#nav button {
  display: flex; align-items: center; gap: 11px; text-align: left; background: transparent;
  color: #5c5c72; border: 0; padding: 10px 12px; border-radius: var(--radius-sm);
  font-size: 14px; font-weight: 500; position: relative; transition: background .16s, color .16s, transform .12s;
}
#nav button .nav-ico { width: 19px; text-align: center; font-size: 15px; opacity: .85; flex: none; }
#nav button:hover { background: var(--line-2); color: var(--ink); }
#nav button.active { background: var(--brand-soft); color: var(--brand-d); font-weight: 600; }
#nav button.active::before {
  content: ''; position: absolute; left: -14px; top: 9px; bottom: 9px; width: 3px;
  border-radius: 0 3px 3px 0; background: var(--brand);
}

/* Collapsible EV / ICE parent groups */
.nav-parent { display: flex; flex-direction: column; }
.nav-parent-btn { width: 100%; }
.nav-parent-btn .caret { margin-left: auto; font-size: 11px; opacity: .65; transition: transform .16s; }
.nav-parent.expanded > .nav-parent-btn .caret { transform: rotate(90deg); }
.nav-parent.expanded > .nav-parent-btn { color: var(--ink); }
.nav-sub { display: none; flex-direction: column; gap: 1px; }
.nav-parent.expanded > .nav-sub { display: flex; }
.nav-sub button { padding-left: 42px; font-size: 13.5px; }

.sidebar-footer {
  display: flex; align-items: center; gap: 10px; padding: 12px 8px 4px; margin-top: 6px;
  border-top: 1px solid var(--line); font-size: 13px;
}
.sidebar-footer .avatar { width: 32px; height: 32px; font-size: 12px; }
.sidebar-footer .who { display: flex; flex-direction: column; line-height: 1.25; min-width: 0; }
.sidebar-footer .who b { font-size: 13px; color: var(--ink); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.sidebar-footer .who span { font-size: 11px; color: var(--muted); text-transform: capitalize; }
.link { background: none; border: 0; color: var(--muted); border-radius: 8px; padding: 6px; transition: color .15s, background .15s; }
.link:hover { color: var(--warn); background: #fff1f3; }

.content { display: flex; flex-direction: column; min-width: 0; }
.topbar {
  display: flex; align-items: center; gap: 14px;
  padding: 14px 26px; background: rgba(245, 246, 252, .8); backdrop-filter: saturate(1.4) blur(8px);
  border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 5;
}
.topbar h2 { margin: 0; font-size: 19px; letter-spacing: -.01em; }
.topbar-actions { display: flex; gap: 10px; align-items: center; margin-left: auto; }
.search { position: relative; display: flex; align-items: center; }
.search::before { content: '🔍'; position: absolute; left: 12px; font-size: 12px; opacity: .5; }
.topbar input {
  width: 210px; padding: 9px 12px 9px 32px; border: 1px solid var(--line); border-radius: 999px;
  font-size: 13.5px; background: var(--panel); color: var(--ink); transition: border-color .15s, box-shadow .15s, width .2s;
}
.topbar input:focus { outline: none; border-color: var(--brand); box-shadow: 0 0 0 3px var(--brand-soft); width: 240px; }
.icon-btn {
  display: grid; place-items: center; width: 38px; height: 38px; border-radius: 11px;
  border: 1px solid var(--line); background: var(--panel); font-size: 15px; transition: background .15s, transform .1s, border-color .15s;
}
.icon-btn:hover { background: var(--brand-soft); border-color: var(--brand-soft-2); }
.icon-btn:active { transform: scale(.94); }
#sync-btn {
  display: flex; align-items: center; gap: 7px; padding: 9px 15px; border: 1px solid var(--line);
  background: var(--panel); border-radius: 11px; font-weight: 500; font-size: 13.5px; transition: background .15s, border-color .15s;
}
#sync-btn:hover { background: var(--brand-soft); border-color: var(--brand-soft-2); }
#sync-btn .sync-ico { display: inline-block; }
#sync-btn.syncing { pointer-events: none; opacity: .7; }
#sync-btn.syncing .sync-ico { animation: spin .8s linear infinite; }
.avatar {
  display: grid; place-items: center; width: 38px; height: 38px; border-radius: 50%;
  background: linear-gradient(135deg, #2dd4bf, #0f766e); color: #fff; font-weight: 700; font-size: 14px;
  flex: none; box-shadow: 0 3px 10px rgba(13, 148, 136, .35); text-transform: uppercase;
}
#view-root { padding: 24px 26px 40px; }

/* ============================ KPI cards ============================ */
.kpi-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: 15px; }
.kpi {
  background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 18px; box-shadow: var(--shadow); transition: transform .18s var(--ease), box-shadow .18s;
  animation: fadeUp .45s var(--ease) both;
}
.kpi:hover { transform: translateY(-3px); box-shadow: var(--shadow-lg); }
.kpi-grid .kpi:nth-child(2) { animation-delay: .04s; }
.kpi-grid .kpi:nth-child(3) { animation-delay: .08s; }
.kpi-grid .kpi:nth-child(4) { animation-delay: .12s; }
.kpi-grid .kpi:nth-child(5) { animation-delay: .16s; }
.kpi-grid .kpi:nth-child(6) { animation-delay: .20s; }
.kpi-grid .kpi:nth-child(7) { animation-delay: .24s; }
.kpi-grid .kpi:nth-child(8) { animation-delay: .28s; }
.kpi .label { color: var(--muted); font-size: 11.5px; text-transform: uppercase; letter-spacing: .05em; font-weight: 600; }
.kpi .value { font-size: 30px; font-weight: 800; margin-top: 8px; letter-spacing: -.02em; line-height: 1; }
.kpi .sub { color: var(--muted); font-size: 12px; margin-top: 7px; }
.kpi.warn .value { color: var(--warn); }
.kpi.ok .value { color: var(--ok); }
.kpi .trend {
  display: inline-flex; align-items: center; gap: 3px; margin-top: 9px; padding: 2px 8px;
  border-radius: 999px; font-size: 11.5px; font-weight: 700;
}
.kpi .trend.up { background: #dcfce7; color: #15803d; }
.kpi .trend.down { background: #ffe4e6; color: #be123c; }

.section-title {
  margin: 30px 0 13px; font-size: 12px; text-transform: uppercase; letter-spacing: .06em;
  color: var(--muted); font-weight: 700; animation: fadeIn .4s ease both;
}

/* ============================ Tables / cards ============================ */
.card {
  background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius);
  box-shadow: var(--shadow); overflow: hidden; animation: fadeUp .42s var(--ease) both;
}
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 13.5px; }
th, td { text-align: left; padding: 12px 16px; border-bottom: 1px solid var(--line-2); white-space: nowrap; }
tbody tr:last-child td { border-bottom: 0; }
th { background: var(--panel-2); color: var(--muted); font-weight: 600; font-size: 11.5px; text-transform: uppercase; letter-spacing: .03em; }
tbody tr { transition: background .12s; }
tbody tr:hover { background: var(--brand-soft); }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
td a { color: var(--brand-d); text-decoration: none; font-weight: 600; }
td a:hover { text-decoration: underline; }
.empty { padding: 30px; text-align: center; color: var(--muted); }

/* ---- expandable rows (inline full-record detail) ---- */
.expand-col { width: 36px; }
.expand-cell { width: 36px; padding-right: 4px !important; }
.row-toggle {
  border: 0; background: transparent; color: var(--muted); font-size: 11px;
  width: 24px; height: 24px; border-radius: 7px; line-height: 1; display: grid; place-items: center;
  transition: transform .18s var(--ease), background .15s, color .15s;
}
.row-toggle:hover { background: var(--brand-soft); color: var(--brand-d); }
.row-toggle.open { transform: rotate(90deg); color: var(--brand-d); }
.exp-row { cursor: pointer; }
.exp-row:hover .row-toggle { color: var(--brand-d); }
.exp-row.open { background: var(--brand-soft) !important; }
.exp-row.open > td { border-bottom-color: transparent; }
.detail-row > td { padding: 0 !important; background: var(--panel-2); white-space: normal; }
.detail-panel { padding: 16px 20px 20px; animation: fadeIn .2s ease both; }
.detail-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 13px 24px; }
.dcell { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.dcell .dt { font-size: 10.5px; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); font-weight: 700; }
.dcell .dd { font-size: 13.5px; color: var(--ink); word-break: break-word; }
.dcell .dd a { color: var(--brand-d); font-weight: 600; text-decoration: none; }
.dcell .dd a:hover { text-decoration: underline; }

/* inline follow-up queue inside an expanded insurance row */
.detail-sub { margin-top: 18px; padding-top: 14px; border-top: 1px dashed var(--line); }
.detail-sub .section-title { margin: 0 0 10px; }
.fu-list { display: flex; flex-direction: column; gap: 7px; margin-bottom: 12px; }
.fu-item { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; font-size: 13px; }
.fu-item .dt { color: var(--muted); font-variant-numeric: tabular-nums; min-width: 84px; }
.fu-item .dd { flex: 1; min-width: 120px; }
.fu-add { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.fu-add input {
  padding: 8px 11px; border: 1px solid var(--line); border-radius: 9px; font-size: 13px;
  background: var(--panel); color: var(--ink);
}
.fu-add input:focus { outline: none; border-color: var(--brand); box-shadow: 0 0 0 3px var(--brand-soft); }
.fu-add input[name="note"] { flex: 1; min-width: 180px; }

/* price history inside an expanded stock-unit row */
.price-hist .ph-head { font-size: 13px; font-weight: 700; color: var(--ink); margin-bottom: 10px; }
.price-hist .ph-title {
  margin: 16px 0 8px; padding-top: 12px; border-top: 1px dashed var(--line);
  font-size: 10.5px; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); font-weight: 700;
}
.ph-table { width: 100%; border-collapse: collapse; font-size: 12.5px; }
.ph-table th {
  text-align: left; padding: 6px 10px; font-size: 10.5px; text-transform: uppercase;
  letter-spacing: .04em; color: var(--muted); font-weight: 700; border-bottom: 1px solid var(--line);
}
.ph-table td { padding: 6px 10px; border-bottom: 1px solid var(--line); color: var(--ink); white-space: nowrap; }
.ph-table th.num, .ph-table td.num { text-align: right; font-variant-numeric: tabular-nums; }
.ph-table tr:last-child td { border-bottom: none; }
.ph-table tr.ph-current { background: var(--brand-soft); }

/* ---- per-unit editor (inward) + unit picker (transfer) ---- */
.unit-editor { display: flex; flex-direction: column; gap: 8px; }
.units-head { display: flex; align-items: baseline; justify-content: space-between; gap: 10px; font-size: 12px; color: var(--muted); font-weight: 600; }
#unit-rows { display: flex; flex-direction: column; gap: 8px; }
.unit-row { display: flex; gap: 8px; align-items: center; }
.unit-row .u-f {
  flex: 1; min-width: 0; padding: 9px 11px; border: 1px solid var(--line); border-radius: var(--radius-sm);
  font-size: 13px; background: var(--panel); color: var(--ink); transition: border-color .15s, box-shadow .15s;
}
.unit-row .u-f:focus { outline: none; border-color: var(--brand); box-shadow: 0 0 0 3px var(--brand-soft); }
.unit-row .u-chassis { flex: 1.4; font-variant-numeric: tabular-nums; }
.unit-row .u-color { flex: .8; }
.u-del {
  flex: none; width: 30px; height: 30px; border-radius: 8px; border: 1px solid var(--line);
  background: var(--panel); color: var(--muted); font-size: 13px; transition: background .15s, color .15s, border-color .15s;
}
.u-del:hover { background: #fff1f3; color: var(--warn); border-color: #fecdd3; }
#add-unit { align-self: flex-start; }

/* transfer unit picker */
.unit-search {
  width: 100%; padding: 9px 12px; margin-bottom: 8px; border: 1px solid var(--line);
  border-radius: var(--radius-sm); font-size: 13px; background: var(--panel); color: var(--ink);
  transition: border-color .15s, box-shadow .15s;
}
.unit-search:focus { outline: none; border-color: var(--brand); box-shadow: 0 0 0 3px var(--brand-soft); }
.unit-search-empty { padding: 10px 2px; }
.unit-pick-list { display: flex; flex-direction: column; gap: 6px; max-height: 300px; overflow-y: auto; padding: 2px; }
.unit-pick-item {
  display: grid; grid-template-columns: auto 1.3fr 1.4fr 1.3fr; gap: 10px; align-items: center;
  padding: 9px 12px; border: 1px solid var(--line); border-radius: var(--radius-sm);
  background: var(--panel); font-size: 13px; cursor: pointer; transition: border-color .15s, background .15s;
}
.unit-pick-item:hover { border-color: var(--brand-soft-2); background: var(--brand-soft); }
.unit-pick-item:has(input:checked) { border-color: var(--brand); background: var(--brand-soft); }
.unit-pick-item.disabled { opacity: .45; cursor: not-allowed; }
.unit-pick-item .upi-chassis { font-weight: 600; font-variant-numeric: tabular-nums; }
.unit-pick-item .upi-veh { color: var(--ink); }
.unit-pick-item .upi-extra { color: var(--muted); font-size: 12px; }
.unit-pick-item input { width: 16px; height: 16px; accent-color: var(--brand); }

/* ============================ Badges ============================ */
.badge { display: inline-block; padding: 3px 10px; border-radius: 999px; font-size: 11.5px; font-weight: 600; }
.badge.green { background: #dcfce7; color: #166534; }
.badge.amber { background: #fef3c7; color: #92400e; }
.badge.red { background: #ffe4e6; color: #9f1239; }
.badge.blue { background: #e0f2fe; color: #075985; }
.badge.gray { background: #eef0f6; color: #4b5563; }
.pill-ev { color: var(--ev); font-weight: 700; }
.pill-ice { color: var(--ice); font-weight: 700; }

/* ============================ Toolbar / buttons ============================ */
.toolbar { display: flex; gap: 10px; align-items: center; margin-bottom: 16px; flex-wrap: wrap; animation: fadeIn .35s ease both; }
.toolbar select, .toolbar input {
  padding: 9px 12px; border: 1px solid var(--line); border-radius: var(--radius-sm);
  font-size: 13px; background: var(--panel); color: var(--ink); transition: border-color .15s, box-shadow .15s;
}
.toolbar select:focus, .toolbar input:focus { outline: none; border-color: var(--brand); box-shadow: 0 0 0 3px var(--brand-soft); }
.toolbar label.fin-date { display: inline-flex; align-items: center; gap: 6px; font-size: 12px; color: var(--muted); }
.btn {
  padding: 9px 15px; border-radius: var(--radius-sm); border: 1px solid var(--line); background: var(--panel);
  font-size: 13px; font-weight: 500; color: var(--ink); transition: background .15s, border-color .15s, transform .1s, box-shadow .15s;
}
.btn:hover { background: var(--panel-2); border-color: var(--muted-2); }
.btn:active { transform: scale(.97); }
.btn.primary { background: var(--brand); color: #fff; border-color: var(--brand); box-shadow: 0 4px 12px rgba(13, 148, 136, .28); }
.btn.primary:hover { background: var(--brand-d); border-color: var(--brand-d); }
.btn.danger { color: var(--warn); border-color: #fecdd3; background: #fff5f6; }
.btn.danger:hover { background: #ffe4e6; }
.btn.sm { padding: 6px 11px; font-size: 12.5px; }
.spacer { flex: 1; }
.count-note { color: var(--muted); font-size: 13px; }

/* ============================ Reports grid ============================ */
.report-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(min(420px, 100%), 1fr)); gap: 18px; }
.report-card h3 { margin: 0; padding: 15px 17px; border-bottom: 1px solid var(--line-2); font-size: 14px; }
.report-grid .card:nth-child(2n) { animation-delay: .05s; }
.report-grid .card:nth-child(3n) { animation-delay: .1s; }

/* ============================ Modal ============================ */
.modal-backdrop {
  position: fixed; inset: 0; background: rgba(7, 40, 44, .42); backdrop-filter: blur(3px);
  display: grid; place-items: center; z-index: 50; padding: 20px; animation: fadeIn .2s ease both;
}
.modal {
  background: var(--panel); border-radius: 20px; width: 100%; max-width: min(920px, 94vw); max-height: 90vh;
  overflow: auto; box-shadow: var(--shadow-lg); animation: popIn .26s var(--ease) both;
}
.modal header { display: flex; align-items: center; justify-content: space-between; padding: 18px 22px; border-bottom: 1px solid var(--line); position: sticky; top: 0; background: var(--panel); }
.modal header h3 { margin: 0; font-size: 16px; }
.modal .x { border: 0; background: none; font-size: 22px; color: var(--muted); border-radius: 8px; width: 32px; height: 32px; transition: background .15s, color .15s; }
.modal .x:hover { background: var(--line-2); color: var(--ink); }
/* Auto-fit columns so a wide (desktop) modal fills horizontally with 3+
   columns, while a narrow one falls back to 2 then 1. */
.form { padding: 20px 24px; display: grid; grid-template-columns: repeat(auto-fit, minmax(230px, 1fr)); gap: 14px 18px; }
.form label { display: flex; flex-direction: column; gap: 6px; font-size: 12px; color: var(--muted); font-weight: 500; }
.form label.full { grid-column: 1 / -1; }
.form .actions { grid-column: 1 / -1; display: flex; justify-content: flex-end; gap: 10px; margin-top: 8px; }
.form label > .btn.sm { align-self: flex-start; }
.lookup-info { min-height: 18px; }

/* ============================ Toast ============================ */
.toast {
  position: fixed; bottom: 24px; right: 24px; background: var(--ink); color: #fff;
  padding: 13px 19px; border-radius: 13px; box-shadow: var(--shadow-lg); z-index: 60; font-size: 14px; font-weight: 500;
  animation: slideInRight .3s var(--ease) both;
}
.toast.err { background: var(--warn); }
.toast.ok { background: var(--ok); }

/* ============================ Settings page ============================ */
.tabs { display: flex; gap: 4px; padding: 5px; background: var(--panel); border: 1px solid var(--line); border-radius: 13px; margin-bottom: 22px; width: fit-content; box-shadow: var(--shadow); animation: fadeIn .35s ease both; }
.tab {
  border: 0; background: transparent; color: var(--muted); padding: 9px 17px; border-radius: 9px;
  font-size: 13.5px; font-weight: 600; transition: background .15s, color .15s;
}
.tab:hover { color: var(--ink); }
.tab.active { background: var(--brand-soft); color: var(--brand-d); }

.settings-head { display: flex; align-items: flex-start; gap: 12px; margin-bottom: 16px; }
.settings-head .spacer { flex: 1; }
.settings-head h3 { margin: 0 0 3px; font-size: 16px; }
.settings-head p { margin: 0; color: var(--muted); font-size: 13px; max-width: 540px; }

/* role chips */
.role-chip { display: inline-flex; align-items: center; gap: 5px; padding: 3px 10px; border-radius: 999px; font-size: 11.5px; font-weight: 700; text-transform: capitalize; }
.role-chip.admin { background: #ccfbf1; color: #0f766e; }
.role-chip.manager { background: #e0f2fe; color: #0369a1; }
.role-chip.staff { background: #f1f5f9; color: #475569; }
.dot-active { display: inline-block; width: 8px; height: 8px; border-radius: 50%; background: var(--ok); margin-right: 6px; }
.dot-inactive { display: inline-block; width: 8px; height: 8px; border-radius: 50%; background: var(--muted-2); margin-right: 6px; }

/* permission matrix */
.perm-table th, .perm-table td { white-space: normal; }
.perm-table td.center, .perm-table th.center { text-align: center; }
.perm-key { font-weight: 600; color: var(--ink); }
.perm-key small { display: block; font-weight: 400; color: var(--muted); font-size: 11.5px; margin-top: 2px; max-width: 360px; white-space: normal; }
.perm-group-row td { background: var(--panel-2); font-size: 11px; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); font-weight: 700; }

/* toggle switch */
.switch { position: relative; display: inline-block; width: 42px; height: 24px; cursor: pointer; vertical-align: middle; }
.switch input { opacity: 0; width: 0; height: 0; position: absolute; }
.switch .slider {
  position: absolute; inset: 0; background: #d7d9e6; border-radius: 999px; transition: background .2s;
}
.switch .slider::before {
  content: ''; position: absolute; height: 18px; width: 18px; left: 3px; top: 3px;
  background: #fff; border-radius: 50%; transition: transform .2s var(--ease); box-shadow: 0 1px 3px rgba(0,0,0,.25);
}
.switch input:checked + .slider { background: var(--brand); }
.switch input:checked + .slider::before { transform: translateX(18px); }
.switch input:disabled + .slider { opacity: .5; cursor: not-allowed; }
.switch.sm { width: 36px; height: 21px; }
.switch.sm .slider::before { height: 15px; width: 15px; }
.switch.sm input:checked + .slider::before { transform: translateX(15px); }

/* alert checkbox cells in mail control unit */
.chk-cell { display: grid; place-items: center; }

/* skeleton shimmer for loading states */
.skeleton {
  background: linear-gradient(90deg, var(--line-2) 25%, var(--line) 37%, var(--line-2) 63%);
  background-size: 200% 100%; animation: shimmer 1.3s infinite linear; border-radius: 8px;
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .001ms !important; animation-delay: 0ms !important; transition-duration: .001ms !important; }
}

/* Mobile layout rules live at the end of this file so they override the
   glassmorphism skin below. */

/* ============================================================
   Glassmorphism skin — frosted translucent panels floating over an
   animated pastel gradient. Layered last so it re-skins the surfaces
   defined above without touching their layout. Falls back to solid
   panels where backdrop-filter is unsupported.
   ============================================================ */
:root {
  --glass-bg: rgba(255, 255, 255, .55);
  --glass-bg-strong: rgba(255, 255, 255, .74);
  --glass-border: rgba(255, 255, 255, .55);
  --glass-blur: blur(18px) saturate(1.5);
  --glass-shadow: 0 8px 32px rgba(8, 54, 58, .12), inset 0 1px 0 rgba(255, 255, 255, .6);
}

/* Animated pastel mesh backdrop. */
body {
  background: linear-gradient(120deg, #e0f4f0 0%, #e9faf4 26%, #e2f2fb 50%, #fdf4e6 74%, #e3f2ef 100%);
  background-size: 300% 300%;
  background-attachment: fixed;
  animation: meshShift 26s ease infinite;
}
@keyframes meshShift {
  0%   { background-position: 0% 50%; }
  50%  { background-position: 100% 50%; }
  100% { background-position: 0% 50%; }
}
/* Slow-drifting colour blobs sitting behind every glass panel. */
body::before {
  content: ''; position: fixed; inset: -20vmax; z-index: -1; pointer-events: none;
  background:
    radial-gradient(40vmax 40vmax at 12% 18%, rgba(20, 184, 166, .28), transparent 60%),
    radial-gradient(38vmax 38vmax at 88% 20%, rgba(56, 189, 248, .22), transparent 60%),
    radial-gradient(42vmax 42vmax at 72% 92%, rgba(251, 191, 36, .20), transparent 62%);
  filter: blur(8px);
  animation: blobFloat 30s ease-in-out infinite alternate;
}
@keyframes blobFloat {
  from { transform: translate3d(0, 0, 0) scale(1); }
  to   { transform: translate3d(0, -3%, 0) scale(1.06); }
}
.app { background: transparent; }

/* Frosted surfaces. */
.sidebar, .topbar, .card, .kpi, .modal, .tabs, .login-card, .report-card {
  background: var(--glass-bg);
  -webkit-backdrop-filter: var(--glass-blur);
  backdrop-filter: var(--glass-blur);
  border: 1px solid var(--glass-border);
}
.sidebar { border-width: 0 1px 0 0; box-shadow: var(--glass-shadow); }
.topbar { box-shadow: 0 4px 24px rgba(8, 54, 58, .06); }
.card, .kpi, .report-card { box-shadow: var(--glass-shadow); }
.kpi:hover { box-shadow: 0 14px 44px rgba(8, 54, 58, .20); }
.modal { background: var(--glass-bg-strong); box-shadow: 0 30px 80px rgba(7, 40, 44, .35); }
.modal header { background: transparent; border-bottom-color: rgba(255, 255, 255, .5); }
.login-card { background: var(--glass-bg-strong); }

/* Tables: translucent header + airy hover so the glass reads through. */
th { background: rgba(255, 255, 255, .38); }
tbody tr:hover { background: rgba(13, 148, 136, .10); }
.report-card h3 { border-bottom-color: rgba(255, 255, 255, .5); }
.perm-group-row td { background: rgba(255, 255, 255, .4); }

/* Nav pills + topbar controls. */
#nav button:hover { background: rgba(255, 255, 255, .55); }
#nav button.active { background: rgba(13, 148, 136, .16); }
.topbar input, #sync-btn, .icon-btn, .branch-select {
  background: rgba(255, 255, 255, .5);
  -webkit-backdrop-filter: blur(6px); backdrop-filter: blur(6px);
}
.branch-select {
  padding: 9px 12px; border: 1px solid var(--glass-border); border-radius: 11px;
  font-size: 13.5px; color: var(--ink); max-width: 170px; transition: border-color .15s, box-shadow .15s;
}
.branch-select:focus { outline: none; border-color: var(--brand); box-shadow: 0 0 0 3px var(--brand-soft); }
.branch-select:disabled { opacity: .85; cursor: default; }
.pref-input { padding: 7px 10px; border: 1px solid var(--line); border-radius: 9px; font-size: 13px; background: rgba(255, 255, 255, .7); }

/* Translucent form fields. */
.form input, .form select, .form textarea,
.toolbar input, .toolbar select { background: rgba(255, 255, 255, .62); }

/* No backdrop-filter (older browsers) → solid panels for legibility. */
@supports not ((backdrop-filter: blur(1px)) or (-webkit-backdrop-filter: blur(1px))) {
  .sidebar, .topbar, .card, .kpi, .modal, .tabs, .login-card, .report-card { background: rgba(255, 255, 255, .96); }
  body::before { display: none; }
}

@media (prefers-reduced-motion: reduce) {
  body, body::before { animation: none; }
}

/* ============================================================
   Mobile — off-canvas drawer nav, bottom-sheet modals, touch
   sizing. Placed last so it overrides the glass skin above.
   ============================================================ */
.menu-btn { display: none; }
.sidebar-backdrop {
  position: fixed; inset: 0; background: rgba(7, 40, 44, .55); z-index: 39;
  opacity: 0; pointer-events: none; transition: opacity .22s ease;
}

@media (max-width: 860px) {
  body { -webkit-tap-highlight-color: transparent; }
  .app { display: block; }

  /* Off-canvas drawer */
  .sidebar {
    position: fixed; top: 0; left: 0; bottom: 0; height: 100dvh;
    width: min(82vw, 300px); z-index: 40; overflow-y: auto;
    transform: translateX(-105%); transition: transform .28s var(--ease);
    padding: calc(16px + env(safe-area-inset-top)) 14px calc(14px + env(safe-area-inset-bottom));
    /* Solid, opaque drawer so the menu reads clearly — the frosted-glass panel
       let the dimmed page bleed through and washed out the nav items. */
    background: #ffffff;
    -webkit-backdrop-filter: none; backdrop-filter: none;
    border-right: 1px solid var(--line); box-shadow: none;
  }
  body.nav-open .sidebar { transform: translateX(0); box-shadow: 0 24px 60px rgba(7, 40, 44, .4); }
  body.nav-open .sidebar-backdrop { opacity: 1; pointer-events: auto; }
  body.nav-open { overflow: hidden; }
  #nav { overflow-y: visible; }
  #nav button { padding: 12px; font-size: 15px; color: #3f3f56; }
  #nav button:hover { background: var(--line-2); }
  .nav-group-label { color: var(--muted); }
  .nav-sub button { padding-left: 44px; font-size: 14px; }

  .menu-btn { display: grid; flex: none; }

  /* Topbar */
  .topbar {
    flex-wrap: wrap; gap: 8px; padding: 10px 14px;
    padding-top: calc(10px + env(safe-area-inset-top));
  }
  .topbar h2 { font-size: 17px; flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .topbar-actions { flex-wrap: wrap; gap: 8px; margin-left: 0; justify-content: flex-end; }
  .branch-select { max-width: 124px; }
  .topbar input { width: 128px; }
  .topbar input:focus { width: 150px; }

  #view-root { padding: 14px 14px calc(28px + env(safe-area-inset-bottom)); }

  /* KPI cards: two columns, tighter */
  .kpi-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
  .kpi { padding: 14px; }
  .kpi .value { font-size: 24px; }
  .kpi:hover { transform: none; }
  .section-title { margin: 22px 0 10px; }

  .report-grid { grid-template-columns: 1fr; gap: 12px; }

  /* Tables: momentum scroll, tighter cells */
  .table-wrap { -webkit-overflow-scrolling: touch; }
  th, td { padding: 10px 12px; }

  /* Expanded detail panels: keep them readable on a phone, and pinned to the
     viewport width even though the table itself scrolls horizontally. */
  .detail-row > td { position: sticky; left: 0; }
  .detail-panel { width: 92vw; padding: 14px 14px 16px; }
  .detail-grid { grid-template-columns: 1fr 1fr; gap: 11px 16px; }
  .fu-add input[name="note"] { min-width: 120px; }

  /* Toolbar controls stretch to fill rows */
  .toolbar { gap: 8px; }
  .toolbar select, .toolbar input { flex: 1 1 130px; min-width: 0; }

  .tabs { width: 100%; overflow-x: auto; }
  .tab { white-space: nowrap; flex: none; }

  /* Modal becomes a bottom sheet */
  .modal-backdrop { padding: 0; align-items: end; }
  .modal {
    max-width: none; max-height: 92dvh; border-radius: 20px 20px 0 0;
    padding-bottom: env(safe-area-inset-bottom);
  }
  .form { grid-template-columns: 1fr; padding: 16px; }
  .form .actions .btn { flex: 1; padding: 12px; }

  /* 16px inputs stop iOS Safari from zooming on focus */
  .login-card input, .form input, .form select, .form textarea,
  .toolbar input, .toolbar select, .topbar input, .branch-select, .pref-input,
  .unit-row .u-f, .fu-add input { font-size: 16px; }

  /* Unit editor / picker stack on a phone */
  .unit-row {
    flex-wrap: wrap; padding: 10px; border: 1px solid var(--line);
    border-radius: var(--radius-sm); background: var(--panel-2);
  }
  .unit-row .u-f { flex: 1 1 100%; }
  .unit-row .u-del { margin-left: auto; }
  .unit-pick-item { grid-template-columns: auto 1fr; gap: 4px 10px; }
  .unit-pick-item .upi-extra { grid-column: 2; }

  .toast {
    left: 14px; right: 14px; bottom: calc(14px + env(safe-area-inset-bottom));
    text-align: center;
  }

  /* Cheaper glass on mobile GPUs */
  :root { --glass-blur: blur(10px) saturate(1.4); }
  body::before { animation: none; }
}

@media (max-width: 480px) {
  /* Search drops to its own full-width row */
  .search { flex: 1 1 100%; order: 9; }
  .topbar input, .topbar input:focus { width: 100%; }
  .login-card { padding: 26px 22px; }
  .detail-grid { grid-template-columns: 1fr; }
}

/* ============================================================
   UI refinements (2026): tidy selects, modern dashboard charts,
   table export + column filters.
   (The sidebar menu is intentionally left as the original design.)
   Kept last so these win over the base + glass layers.
   ============================================================ */

/* ---- Native <select> dropdowns: consistent, well-padded, custom caret ---- */
select, .branch-select, .form select, .toolbar select {
  -webkit-appearance: none; -moz-appearance: none; appearance: none;
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%2364748b' stroke-width='3' stroke-linecap='round' stroke-linejoin='round'><polyline points='6 9 12 15 18 9'/></svg>");
  background-repeat: no-repeat; background-position: right 11px center;
  padding-right: 30px !important; text-overflow: ellipsis;
}
.form select { width: 100%; }
.branch-select { min-width: 128px; }

/* ============================ dashboard (modern) ============================ */
.dash-head { display: flex; align-items: center; gap: 12px; margin-bottom: 14px; flex-wrap: wrap; }
.dash-head h3 { margin: 0; font-size: 15px; font-weight: 700; letter-spacing: -.01em; }
.dash-head .sub { color: var(--muted); font-size: 12.5px; }
.dash-head .spacer { flex: 1; }

/* KPI cards become clickable tiles with an accent stripe + hover lift. */
.kpi-grid { grid-template-columns: repeat(auto-fill, minmax(184px, 1fr)); }
.kpi { position: relative; overflow: hidden; cursor: default; }
.kpi.clickable { cursor: pointer; }
.kpi.clickable:hover { transform: translateY(-3px); }
.kpi::after {
  content: ''; position: absolute; left: 0; top: 0; bottom: 0; width: 4px;
  background: var(--brand); opacity: .9;
}
.kpi.ok::after { background: var(--ok); }
.kpi.warn::after { background: var(--warn); }
.kpi.info::after { background: var(--sky); }
.kpi .label { display: flex; align-items: center; gap: 7px; }
.kpi .kpi-ico { font-size: 15px; opacity: .85; }
.kpi .trend { font-size: 11.5px; font-weight: 600; padding: 1px 6px; border-radius: 20px; }
.kpi .trend.up { color: #15803d; background: #dcfce7; }
.kpi .trend.down { color: #b91c1c; background: #fee2e2; }

/* Chart grid + cards */
.chart-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; margin: 6px 0 20px; }
.chart-card {
  background: var(--glass-bg); border: 1px solid var(--glass-border); border-radius: var(--radius);
  box-shadow: var(--glass-shadow); padding: 16px 16px 12px; display: flex; flex-direction: column; min-height: 0;
}
.chart-card.wide { grid-column: 1 / -1; }
.chart-card h4 { margin: 0 0 4px; font-size: 13.5px; font-weight: 700; }
.chart-card .chart-sub { margin: 0 0 10px; font-size: 12px; color: var(--muted); }
.chart-holder { position: relative; height: 260px; }
.chart-holder.tall { height: 300px; }
.chart-card canvas { cursor: pointer; }
@media (max-width: 860px) { .chart-grid { grid-template-columns: 1fr; } .chart-holder { height: 240px; } }

/* ============================ table tools: export + filters ============================ */
.table-tools {
  display: flex; align-items: center; gap: 8px; padding: 10px 12px;
  border-bottom: 1px solid var(--line); flex-wrap: wrap;
}
.table-tools .tt-title { font-weight: 700; font-size: 13px; }
.table-tools .tt-count { color: var(--muted); font-size: 12px; }
.table-tools .spacer { flex: 1; }
.btn.tt {
  padding: 6px 11px; font-size: 12.5px; font-weight: 600; border-radius: 9px;
  display: inline-flex; align-items: center; gap: 6px;
}
.btn.tt.xlsx { color: #166534; border-color: #bbf7d0; background: #f0fdf4; }
.btn.tt.xlsx:hover { background: #dcfce7; }
.btn.tt.pdf { color: #b91c1c; border-color: #fecaca; background: #fef2f2; }
.btn.tt.pdf:hover { background: #fee2e2; }
.btn.tt.filter { color: var(--brand-d); border-color: var(--brand-soft-2); background: var(--brand-soft); }

tr.filter-row th { padding: 6px 8px; background: rgba(255,255,255,.5); }
.col-filter {
  width: 100%; min-width: 70px; padding: 5px 8px; font-size: 12px;
  border: 1px solid var(--line); border-radius: 7px; background: #fff; color: var(--ink);
}
.col-filter:focus { outline: none; border-color: var(--brand); box-shadow: 0 0 0 2px var(--brand-soft); }
tr.no-match { display: none; }

/* ============================ settings: backup + whatsapp ============================ */
.kv-form { display: grid; grid-template-columns: 220px 1fr; gap: 12px 16px; align-items: center; max-width: 760px; margin-top: 6px; }
.kv-form label { font-size: 13px; color: var(--muted); font-weight: 600; }
.kv-form input, .kv-form select, .kv-form textarea {
  padding: 10px 12px; border: 1px solid var(--line); border-radius: var(--radius-sm);
  font-size: 14px; background: rgba(255,255,255,.7); color: var(--ink); width: 100%;
}
.kv-form .full { grid-column: 1 / -1; }
@media (max-width: 640px) { .kv-form { grid-template-columns: 1fr; gap: 6px 0; } .kv-form label { margin-top: 8px; } }

.status-line { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; margin: 4px 0 14px; font-size: 13px; }
.status-line .pill { padding: 3px 10px; border-radius: 20px; font-weight: 600; font-size: 12px; }
.status-line .pill.ok { background: #dcfce7; color: #166534; }
.status-line .pill.warn { background: #fef9c3; color: #854d0e; }
.status-line .pill.err { background: #fee2e2; color: #b91c1c; }
.status-line .pill.off { background: #e2e8f0; color: #475569; }

/* WhatsApp template preview bubble */
.wa-preview {
  margin-top: 10px; max-width: 380px; background: #d9fdd3; color: #111b21;
  border-radius: 12px 12px 12px 4px; padding: 10px 12px; font-size: 13.5px; line-height: 1.5;
  box-shadow: 0 1px 2px rgba(0,0,0,.12); white-space: pre-wrap; position: relative;
}
.wa-preview .wa-meta { display: block; margin-top: 6px; font-size: 10.5px; color: #667781; text-align: right; }
.wa-phone {
  background: #e5ddd5;
  background-image: linear-gradient(rgba(229,221,213,.9), rgba(229,221,213,.9));
  border-radius: 16px; padding: 16px; border: 1px solid var(--line); max-width: 420px;
}
.wa-var-row { display: flex; gap: 8px; align-items: center; margin: 6px 0; }
.wa-var-row label { min-width: 60px; font-size: 12px; color: var(--muted); }
.tmpl-list { margin-top: 12px; }
.tmpl-card {
  border: 1px solid var(--line); border-radius: var(--radius-sm); padding: 12px 14px;
  margin-bottom: 10px; background: rgba(255,255,255,.6);
}
.tmpl-card .tc-head { display: flex; align-items: center; gap: 10px; }
.tmpl-card .tc-head strong { font-size: 14px; }
.tmpl-card .tc-sid { font-family: ui-monospace, monospace; font-size: 11.5px; color: var(--muted); }
.event-chip { font-size: 11px; font-weight: 600; padding: 2px 8px; border-radius: 20px; background: var(--brand-soft); color: var(--brand-d); }
