:root {
  --bg: #f4f6f9;
  --surface: #ffffff;
  --surface-2: #f8fafc;
  --border: #e3e8ef;
  --text: #17212f;
  --muted: #64748b;
  /* Synex Pharma brand: teal blue + leaf green from the logo */
  --primary: #13658a;
  --primary-2: #0e5070;
  --primary-soft: #e4f0f5;
  --on-primary: #ffffff;
  --accent: #7fb83a;
  --accent-soft: #eef6e3;
  --brand-gradient: linear-gradient(90deg, #13658a 0%, #4b8f7d 55%, #8cc63f 100%);
  --good: #15803d;
  --good-soft: #e7f6ec;
  --bad: #b91c1c;
  --bad-soft: #fdecec;
  --warn: #b45309;
  --warn-soft: #fdf3e2;
  --info: #1d4ed8;
  --info-soft: #e8efff;
  --side: #0c2e3e;
  --side-text: #c3d6df;
  --side-active: #15455b;
  --shadow: 0 1px 2px rgba(16, 24, 40, 0.05), 0 1px 3px rgba(16, 24, 40, 0.06);
  --radius: 10px;
  --c1: #13658a; --c2: #7fb83a; --c3: #d97706; --c4: #7c3aed; --c5: #db2777; --c6: #0891b2; --c7: #4b8f7d; --c8: #64748b;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0d141c; --surface: #151f2a; --surface-2: #1a2633; --border: #263545; --text: #e5edf5; --muted: #8fa1b5;
    --primary: #4fb3db; --primary-2: #7fcbe8; --primary-soft: #12303d; --on-primary: #04202c; --accent: #9fd35a; --accent-soft: #233417;
    --good: #4ade80; --good-soft: #12301d; --bad: #f87171; --bad-soft: #3a1717; --warn: #fbbf24; --warn-soft: #3a2a0d;
    --info: #93b4ff; --info-soft: #18264a; --side: #081e29; --side-text: #9fb7c3; --side-active: #123444;
    --shadow: 0 1px 2px rgba(0, 0, 0, 0.4);
    --c1: #4fb3db; --c2: #9fd35a; --c3: #fbbf24; --c4: #a78bfa; --c5: #f472b6; --c6: #22d3ee; --c7: #6fbfa8; --c8: #94a3b8;
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #0d141c; --surface: #151f2a; --surface-2: #1a2633; --border: #263545; --text: #e5edf5; --muted: #8fa1b5;
  --primary: #4fb3db; --primary-2: #7fcbe8; --primary-soft: #12303d; --on-primary: #04202c; --accent: #9fd35a; --accent-soft: #233417;
  --good: #4ade80; --good-soft: #12301d; --bad: #f87171; --bad-soft: #3a1717; --warn: #fbbf24; --warn-soft: #3a2a0d;
  --info: #93b4ff; --info-soft: #18264a; --side: #081e29; --side-text: #9fb7c3; --side-active: #123444;
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.4);
  --c1: #4fb3db; --c2: #9fd35a; --c3: #fbbf24; --c4: #a78bfa; --c5: #f472b6; --c6: #22d3ee; --c7: #6fbfa8; --c8: #94a3b8;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: 14px/1.45 "Inter", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
}
a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3 { margin: 0; line-height: 1.25; }
h1 { font-size: 22px; font-weight: 700; }
h2 { font-size: 15px; font-weight: 600; }
h3 { font-size: 13px; font-weight: 600; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.r { text-align: right; }
.nowrap { white-space: nowrap; }
.num { font-variant-numeric: tabular-nums; }
.hidden { display: none !important; }
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.spacer { flex: 1; }
.stack > * + * { margin-top: 16px; }

/* ---------- buttons & inputs ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  border: 1px solid var(--border); background: var(--surface); color: var(--text);
  padding: 8px 14px; border-radius: 8px; font: inherit; font-weight: 500; cursor: pointer; white-space: nowrap;
}
.btn:hover { background: var(--surface-2); text-decoration: none; }
.btn.primary { background: var(--primary); border-color: var(--primary); color: var(--on-primary); }
.btn.primary:hover { background: var(--primary-2); }
.btn.danger { color: var(--bad); }
.btn.good { color: var(--good); }
.btn.sm { padding: 4px 9px; font-size: 12px; border-radius: 6px; }
.btn.block { width: 100%; padding: 12px; font-size: 15px; }
.btn:disabled { opacity: 0.55; cursor: default; }
input, select, textarea {
  font: inherit; color: var(--text); background: var(--surface);
  border: 1px solid var(--border); border-radius: 8px; padding: 8px 10px; min-width: 0;
}
input:focus, select:focus, textarea:focus { outline: 2px solid var(--primary); outline-offset: -1px; border-color: transparent; }
textarea { resize: vertical; min-height: 70px; }
label.field { display: flex; flex-direction: column; gap: 5px; font-size: 12px; font-weight: 600; color: var(--muted); }
label.field > input, label.field > select, label.field > textarea { font-weight: 400; font-size: 14px; }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px 14px; }
.form-grid .full { grid-column: 1 / -1; }
.form-error { color: var(--bad); background: var(--bad-soft); padding: 8px 10px; border-radius: 8px; margin-bottom: 12px; }
.check { display: flex; gap: 8px; align-items: center; font-size: 13px; font-weight: 500; color: var(--text); }

/* ---------- cards / KPIs ---------- */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); }
.card-head { display: flex; align-items: center; gap: 10px; padding: 14px 16px 0; flex-wrap: wrap; }
.card-body { padding: 14px 16px 16px; }
.card-body.flush { padding: 8px 0 0; }
.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(230px, 1fr)); gap: 12px; }
.kpi { padding: 14px 16px; }
.kpi .k-label { font-size: 12px; color: var(--muted); font-weight: 500; }
.kpi .k-value { font-size: 22px; font-weight: 700; margin-top: 4px; font-variant-numeric: tabular-nums; letter-spacing: -0.01em; }
.kpi .k-sub { font-size: 12px; color: var(--muted); margin-top: 2px; }
.kpi.accent { border-top: 3px solid var(--primary); }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.grid-3 { display: grid; grid-template-columns: 2fr 1fr; gap: 16px; }
.chart-box { position: relative; height: 270px; }
.chart-box.tall { height: 340px; }
.map { height: 360px; border-radius: 0 0 var(--radius) var(--radius); z-index: 0; }
.map.short { height: 260px; }

/* ---------- tables ---------- */
.table-wrap { overflow-x: auto; }
table.t { width: 100%; border-collapse: collapse; }
table.t th, table.t td { padding: 9px 12px; border-bottom: 1px solid var(--border); text-align: left; vertical-align: middle; }
table.t th { font-size: 11px; text-transform: uppercase; letter-spacing: 0.04em; color: var(--muted); font-weight: 600; background: var(--surface-2); position: sticky; top: 0; }
table.t td.r, table.t th.r { text-align: right; }
table.t td.num { white-space: nowrap; }
table.t tbody tr.click { cursor: pointer; }
table.t tbody tr.click:hover { background: var(--surface-2); }
table.t tfoot td { font-weight: 700; background: var(--surface-2); }
.empty { padding: 28px; text-align: center; color: var(--muted); }

.badge { display: inline-block; padding: 2px 8px; border-radius: 99px; font-size: 11px; font-weight: 600; background: var(--surface-2); color: var(--muted); white-space: nowrap; }
.badge.approved, .badge.good { background: var(--good-soft); color: var(--good); }
.badge.pending, .badge.warn { background: var(--warn-soft); color: var(--warn); }
.badge.rejected, .badge.bad { background: var(--bad-soft); color: var(--bad); }
.badge.info { background: var(--info-soft); color: var(--info); }
.pos { color: var(--good); font-weight: 600; }
.neg { color: var(--bad); font-weight: 600; }
.bar { height: 6px; background: var(--surface-2); border-radius: 99px; overflow: hidden; min-width: 70px; }
.bar > span { display: block; height: 100%; background: var(--primary); border-radius: 99px; }

.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--border); flex-wrap: wrap; }
.tabs button { background: none; border: 0; padding: 9px 14px; font: inherit; font-weight: 500; color: var(--muted); cursor: pointer; border-bottom: 2px solid transparent; margin-bottom: -1px; }
.tabs button.on { color: var(--primary); border-bottom-color: var(--primary); }
.seg { display: inline-flex; border: 1px solid var(--border); border-radius: 8px; overflow: hidden; flex-wrap: wrap; }
.seg button { background: var(--surface); border: 0; border-right: 1px solid var(--border); padding: 7px 12px; font: inherit; cursor: pointer; color: var(--muted); }
.seg button:last-child { border-right: 0; }
.seg button.on { background: var(--primary-soft); color: var(--primary); font-weight: 600; }

/* ---------- modal / toast ---------- */
.modal-back { position: fixed; inset: 0; background: rgba(8, 15, 25, 0.5); display: flex; align-items: flex-start; justify-content: center; padding: 6vh 16px; z-index: 1000; overflow-y: auto; }
.modal { background: var(--surface); border-radius: 12px; width: 100%; max-width: 560px; box-shadow: 0 20px 50px rgba(0, 0, 0, 0.25); }
.modal.wide { max-width: 820px; }
.modal-head { display: flex; align-items: center; padding: 16px 18px; border-bottom: 1px solid var(--border); }
.modal-head h2 { font-size: 16px; flex: 1; }
.modal-close { background: none; border: 0; font-size: 22px; line-height: 1; color: var(--muted); cursor: pointer; }
.modal-body { padding: 18px; }
.modal-foot { display: flex; justify-content: flex-end; gap: 8px; padding: 12px 18px; border-top: 1px solid var(--border); }
#toasts { position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%); z-index: 2000; display: flex; flex-direction: column; gap: 8px; align-items: center; pointer-events: none; }
.toast { background: var(--text); color: var(--bg); padding: 10px 16px; border-radius: 8px; box-shadow: var(--shadow); font-weight: 500; max-width: 90vw; }
.toast.err { background: var(--bad); color: #fff; }
.spinner { width: 22px; height: 22px; border: 3px solid var(--border); border-top-color: var(--primary); border-radius: 50%; animation: spin 0.8s linear infinite; margin: 40px auto; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- login ---------- */
.login-wrap { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.login-card { width: 100%; max-width: 380px; padding: 28px; }
.brand { display: flex; align-items: center; gap: 10px; font-weight: 700; font-size: 16px; }
.brand-mark { width: 34px; height: 34px; border-radius: 9px; background: var(--primary); color: var(--on-primary); display: grid; place-items: center; font-weight: 800; }

/* Leaflet popups follow the theme */
.leaflet-popup-content-wrapper, .leaflet-popup-tip { background: var(--surface); color: var(--text); }
.leaflet-container { background: var(--surface-2); font: inherit; }

@media (max-width: 1000px) {
  .grid-2, .grid-3 { grid-template-columns: 1fr; }
}
@media (max-width: 560px) {
  .form-grid { grid-template-columns: 1fr; }
  .kpis { grid-template-columns: 1fr 1fr; gap: 10px; }
  .kpi { padding: 12px; }
  .kpi .k-value { font-size: 18px; }
}

/* ---------- brand ---------- */
.brand-logo { width: 34px; height: 34px; object-fit: contain; flex-shrink: 0; }
.brand-name { font-weight: 800; letter-spacing: -0.01em; }
.brand-name b { color: var(--accent); font-weight: 800; }
.brand-bar { height: 4px; background: var(--brand-gradient); }
.kpi.accent { border-top: 3px solid transparent; border-image: var(--brand-gradient) 1; }
.login-logo { display: block; width: 100%; max-width: 260px; margin: 0 auto 6px; }
.new-brick { display: flex; flex-direction: column; gap: 10px; padding: 12px; border: 1px dashed var(--primary); border-radius: 8px; background: var(--primary-soft); }
.role-badge { display: inline-block; padding: 1px 7px; border-radius: 99px; font-size: 11px; font-weight: 700; background: var(--primary-soft); color: var(--primary); }
.role-badge.tm { background: var(--accent-soft); color: #4d7a1d; }
.role-badge.admin { background: var(--surface-2); color: var(--muted); }
.alert { display: flex; gap: 12px; align-items: flex-start; padding: 12px 16px; border-radius: var(--radius); background: var(--warn-soft); color: var(--warn); border: 1px solid transparent; margin-bottom: 16px; }
.alert b { color: inherit; }
.alert.ok { background: var(--good-soft); color: var(--good); }

/* ---------- splash ---------- */
.splash { position: fixed; inset: 0; z-index: 3000; background: #f3f6f7; display: grid; place-items: center; transition: opacity 0.35s; padding: 16px; }
.splash.out { opacity: 0; pointer-events: none; }
.splash-stage { position: relative; width: min(92vw, 440px); aspect-ratio: 9 / 16; max-height: 92vh; display: grid; place-items: center; }
.splash-video { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; border-radius: 18px; transition: opacity 0.5s; box-shadow: 0 20px 60px rgba(12, 46, 62, 0.18); }
.splash-video.done { opacity: 0; }
.splash-info { position: relative; text-align: center; color: #1d3c4a; opacity: 0; transform: translateY(10px); transition: opacity 0.5s 0.1s, transform 0.5s 0.1s; padding: 0 12px; pointer-events: none; }
.splash-info.show { opacity: 1; transform: none; pointer-events: auto; }
.splash-logo { width: min(80vw, 340px); height: auto; }
.splash-about { margin-top: 18px; font-size: 15px; font-weight: 600; color: #13658a; }
.splash-contact { margin-top: 8px; font-size: 13px; color: #4d6470; line-height: 1.7; }
.splash-contact .dotsep { margin: 0 8px; color: #8cc63f; }
.splash-go { margin-top: 22px; padding: 11px 28px; font-size: 15px; }
.splash-skip { position: absolute; top: 16px; right: 16px; background: rgba(255, 255, 255, 0.85); border: 1px solid #d6e2e7; border-radius: 99px; padding: 6px 14px; font: inherit; font-size: 13px; color: #1d3c4a; cursor: pointer; }
.restore-box { margin-top: 6px; padding-top: 14px; border-top: 1px solid var(--border); }

/* developer credit (NanoSoft AI Solutions) */
.dev-credit { margin: 10px 0 0; text-align: center; font-size: 12px; color: var(--muted); }
.dev-credit a, .splash-dev a, .side-dev a, #pin-lock .pl-foot a { color: inherit; }
.splash-dev { margin-top: 14px; font-size: 12px; opacity: .8; line-height: 1.5; }
