/* eprescription design system — ported from the asset-register dashboard (same tokens, type, shell and components).
   Fonts: Schibsted Grotesk (UI) + Bricolage Grotesque (numbers / headings). */

:root {
  --bg: #eef1f6;
  --panel: #ffffff;
  --ink: #161b26;
  --ink-2: #485164;
  --mute: #677084;
  --line: #e9ecf2;
  --soft: #f3f5f9;
  --track: #e8ecf2;
  /* brand: taken from the mfamasia logo (green word mark, blue lines/water, lime swoosh) */
  --brand: #0b7a35;
  --brand-d: #07612a;
  --brand-s: #e7f5ec;
  --brand-rgb: 11, 122, 53;
  --on-brand: #ffffff;
  --lime: #8cbf26;
  --sky: #0062d6;
  /* warnings keep amber so they still read as warnings */
  --warn: #b86e00;
  --warn-s: #fff3e2;
  --dark: #161b26;
  --dark-2: #232a38;
  --green: #1d8a5f;
  --green-s: #e8f6ef;
  --red: #c9442f;
  --red-s: #fdecea;
  --blue: #1f5fbf;
  --blue-s: #e8f0fc;
  --amber-s: #fff6dc;
  --r: 22px;
  --num: "Bricolage Grotesque", system-ui, sans-serif;
  --ui: "Schibsted Grotesk", system-ui, sans-serif;
  --ease: cubic-bezier(.22, 1, .36, 1);
  --shadow: 0 1px 0 rgba(22,27,38,.04), 0 12px 32px -18px rgba(22,27,38,.18);
  --pop: 0 24px 60px -20px rgba(22,27,38,.35), 0 0 0 1px var(--line);
}

* { box-sizing: border-box; }
html { overflow-y: scroll; }
html, body { margin: 0; }
body { background: var(--bg); color: var(--ink); font: 14px/1.45 var(--ui); -webkit-font-smoothing: antialiased; }
button { font: inherit; color: inherit; background: none; border: 0; cursor: pointer; }
a { color: var(--brand-d); }
svg.i { width: 20px; height: 20px; flex: none; }
h1, h2, h3, h4, p { margin: 0; }
img { max-width: 100%; }
.muted { color: var(--mute); font-size: 13px; }
.num { font-family: var(--num); }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
[hidden] { display: none !important; }

/* ---------- Shell ---------- */
.app { display: grid; grid-template-columns: 244px minmax(0, 1fr); gap: 16px; padding: 16px; min-height: 100vh; max-width: 1680px; margin: 0 auto; }
.panel { background: var(--panel); border-radius: var(--r); box-shadow: var(--shadow); }
.main { display: grid; grid-template-columns: minmax(0, 1fr); gap: 16px; align-content: start; min-width: 0; }

/* Sidebar */
.side { position: sticky; top: 16px; height: calc(100vh - 32px); display: flex; flex-direction: column; padding: 22px 16px 16px; box-shadow: 0 1px 0 rgba(22,27,38,.04), -12px 16px 32px -24px rgba(22,27,38,.2); overflow: hidden; }
.brand { display: flex; align-items: center; gap: 10px; padding: 0 8px 18px; border-bottom: 1px solid var(--line); text-decoration: none; color: var(--ink); }
.brand img { height: auto; width: 168px; max-width: 100%; display: block; }
.nav { display: grid; gap: 4px; padding: 16px 0; position: relative; overflow-y: auto; overflow-x: hidden; margin-right: -16px; padding-right: 16px; scrollbar-width: none; }
.nav::-webkit-scrollbar { display: none; }
.nav-h { font-size: 11px; font-weight: 600; letter-spacing: .1em; text-transform: uppercase; color: var(--mute); padding: 12px 14px 4px; }
.nav a { position: relative; z-index: 1; display: flex; align-items: center; gap: 12px; padding: 11px 14px; margin-right: -16px; padding-right: 30px; color: var(--ink-2); text-decoration: none; font-weight: 500; transition: color .3s; border-radius: 16px 0 0 16px; }
.nav a svg { transition: color .3s, transform .3s; }
.nav a:hover { color: var(--ink); }
.nav a:hover svg { transform: translateX(2px); }
.nav a.on { color: var(--ink); font-weight: 600; background: var(--bg); }
.nav a.on svg { color: var(--brand); }
.nav a.on::before, .nav a.on::after { content: ""; position: absolute; right: 0; width: 18px; height: 18px; pointer-events: none; }
.nav a.on::before { top: -18px; background: radial-gradient(circle at 0 0, transparent 17.5px, var(--bg) 18px); }
.nav a.on::after { bottom: -18px; background: radial-gradient(circle at 0 100%, transparent 17.5px, var(--bg) 18px); }
.nav em { margin-left: auto; font-style: normal; font-size: 12px; }
.side-foot { margin-top: auto; display: flex; gap: 10px; align-items: flex-start; padding: 14px 12px; border-radius: 16px; background: var(--soft); font-size: 12px; color: var(--mute); line-height: 1.4; }
.side-foot svg { width: 16px; height: 16px; color: var(--brand-d); margin-top: 1px; }
.side-foot.warn { background: var(--red-s); color: var(--red); }
.side-foot.warn svg { color: var(--red); }

/* Top bar */
.top { display: flex; align-items: center; gap: 16px; padding: 12px 12px 12px 14px; position: relative; z-index: 1000; }
.m-brand { display: none; }
.m-brand img { height: 36px; display: block; }
.search { flex: 1; max-width: 560px; display: flex; align-items: center; gap: 10px; background: var(--soft); border-radius: 14px; padding: 0 12px; height: 46px; position: relative; }
.search svg { color: var(--mute); }
.search input { flex: 1; border: 0; background: none; outline: none; font: inherit; font-size: 14.5px; color: var(--ink); min-width: 0; }
.search input::placeholder { color: var(--mute); }
.search:focus-within { box-shadow: 0 0 0 2px var(--brand); background: var(--panel); }
.date { margin-left: auto; color: var(--ink-2); font-weight: 500; white-space: nowrap; display: grid; justify-items: end; line-height: 1.25; }
.date small { font-size: 11.5px; color: var(--mute); }

.me { position: relative; }
.me-btn { display: flex; align-items: center; gap: 10px; padding: 4px 10px 4px 4px; border-radius: 999px; transition: background .2s; }
.me-btn:hover { background: var(--soft); }
.me-t { display: grid; text-align: left; line-height: 1.2; }
.me-t b { font-size: 13px; font-weight: 600; max-width: 180px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.me-t small { font-size: 11.5px; color: var(--mute); text-transform: capitalize; }
.me .chev { width: 16px; height: 16px; color: var(--mute); }
.me-menu { position: absolute; right: 0; top: 52px; width: 260px; padding: 8px; z-index: 1200; box-shadow: var(--pop); animation: menuIn .2s var(--ease); }
@keyframes menuIn { from { opacity: 0; transform: translateY(-6px); } }
.me-head { display: flex; gap: 10px; align-items: center; padding: 8px 8px 12px; margin-bottom: 4px; border-bottom: 1px solid var(--line); min-width: 0; }
.me-head div { min-width: 0; }
.me-head b { display: block; font-size: 13.5px; }
.me-head small { color: var(--mute); font-size: 12px; display: block; overflow: hidden; text-overflow: ellipsis; }
.me-menu a, .me-menu button.lnk { display: flex; width: 100%; align-items: center; gap: 10px; padding: 10px; border-radius: 12px; color: var(--ink-2); text-decoration: none; font-weight: 500; font-size: 13.5px; text-align: left; }
.me-menu a:hover, .me-menu button.lnk:hover { background: var(--soft); color: var(--ink); }
.me-menu svg { width: 17px; height: 17px; }
.me-menu .out { color: var(--red) !important; }
.me-row { display: flex; align-items: center; gap: 10px; padding: 8px 10px; font-size: 13.5px; color: var(--ink-2); }
.me-row .seg { margin-left: auto; }
.avatar { width: 38px; height: 38px; border-radius: 50%; background: var(--brand); color: var(--on-brand); display: grid; place-items: center; font: 600 13px var(--num); flex: none; overflow: hidden; }
.avatar img { width: 100%; height: 100%; object-fit: cover; }
.avatar.big { width: 72px; height: 72px; font-size: 24px; }
.avatar.sm { width: 32px; height: 32px; font-size: 11.5px; }

/* Phone bottom bar */
.tabs { display: none; }

/* ---------- Page heading ---------- */
.phead { display: flex; align-items: end; justify-content: space-between; gap: 16px; padding: 6px 6px 0; flex-wrap: wrap; }
.phead h1 { font: 600 30px/1.1 var(--num); letter-spacing: -.01em; }
.phead p { color: var(--mute); margin-top: 4px; font-size: 15px; max-width: 46em; }
.phead .crumb { display: inline-flex; align-items: center; gap: 6px; font-size: 13px; font-weight: 600; color: var(--mute); text-decoration: none; margin-bottom: 8px; }
.phead .crumb:hover { color: var(--brand-d); }
.phead .crumb svg { width: 15px; height: 15px; }
.pact { display: flex; gap: 8px; flex-wrap: wrap; }
.hello h1 { font: 600 30px/1.1 var(--num); letter-spacing: -.01em; }
.hello p { color: var(--mute); margin-top: 6px; font-size: 15.5px; }

/* ---------- Buttons ---------- */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 8px; padding: 10px 16px; border-radius: 13px; font-weight: 600; font-size: 13.5px; text-decoration: none; white-space: nowrap; transition: transform .2s var(--ease), box-shadow .2s, background .2s, opacity .2s; cursor: pointer; line-height: 1.2; }
.btn svg { width: 17px; height: 17px; }
.btn:active { transform: scale(.97); }
.btn:disabled, .btn.is-busy { opacity: .6; pointer-events: none; }
.btn-o { background: var(--brand); color: var(--on-brand); box-shadow: 0 8px 18px -10px rgba(var(--brand-rgb), .9); }
.btn-o:hover { background: var(--brand-d); }
.btn-d { background: var(--ink); color: #fff; }
.btn-d:hover { background: var(--dark-2); }
.btn-l { background: var(--panel); color: var(--ink); box-shadow: 0 1px 2px rgba(22,27,38,.08), 0 0 0 1px var(--line); }
.btn-l:hover { background: var(--soft); }
.btn-s { background: var(--soft); color: var(--ink-2); }
.btn-s:hover { background: var(--track); color: var(--ink); }
.btn-r { background: var(--red-s); color: var(--red); }
.btn-r:hover { background: var(--red); color: #fff; }
.btn-g { background: var(--green-s); color: var(--green); }
.btn-g:hover { background: var(--green); color: #fff; }
.btn-sm { padding: 7px 11px; font-size: 12.5px; border-radius: 10px; }
.btn-sm svg { width: 15px; height: 15px; }
.btn-block { width: 100%; padding: 13px; font-size: 15px; }
.btn.is-busy::after { content: ""; width: 14px; height: 14px; border: 2px solid currentColor; border-right-color: transparent; border-radius: 50%; animation: spin .7s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.ib { width: 34px; height: 34px; border-radius: 10px; display: inline-grid; place-items: center; color: var(--ink-2); text-decoration: none; transition: background .2s, color .2s; }
.ib svg { width: 18px; height: 18px; }
.ib:hover { background: var(--panel); color: var(--brand-d); box-shadow: 0 1px 3px rgba(22,27,38,.14); }
.ib.del:hover { color: var(--red); }
.acts { display: inline-flex; gap: 2px; align-items: center; justify-content: flex-end; }
.acts form { display: inline; margin: 0; }

/* Segmented control + chips */
.seg { display: inline-flex; background: var(--track); border-radius: 12px; padding: 3px; gap: 2px; }
.seg button, .seg a { padding: 7px 12px; border-radius: 9px; font-weight: 600; font-size: 13px; color: var(--mute); display: inline-flex; align-items: center; justify-content: center; gap: 6px; transition: background .2s, color .2s; text-decoration: none; }
.seg svg { width: 16px; height: 16px; }
.seg .on { background: var(--panel); color: var(--ink); box-shadow: 0 1px 3px rgba(22,27,38,.14); }
.chips { display: flex; gap: 8px; flex-wrap: wrap; }
.chip { display: inline-flex; align-items: center; gap: 8px; padding: 8px 12px; border-radius: 12px; background: var(--soft); font-weight: 600; font-size: 13px; color: var(--ink-2); text-decoration: none; transition: background .2s, color .2s; white-space: nowrap; }
.chip em { font-style: normal; font-weight: 500; color: var(--mute); font-size: 12px; }
.chip:hover { background: var(--track); color: var(--ink); }
.chip.on { background: var(--brand); color: #fff; box-shadow: 0 6px 14px -8px rgba(var(--brand-rgb), .8); }
.chip.on em { color: rgba(255,255,255,.85); }

/* Status pills */
.pill { display: inline-flex; align-items: center; gap: 6px; font-size: 12px; font-weight: 600; padding: 4px 10px; border-radius: 999px; white-space: nowrap; background: var(--soft); color: var(--ink-2); text-transform: capitalize; }
.pill::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.pill.ok { background: var(--green-s); color: var(--green); }
.pill.bad { background: var(--red-s); color: var(--red); }
.pill.warn { background: var(--warn-s); color: var(--warn); }
.pill.info { background: var(--blue-s); color: var(--blue); }
.badge { background: var(--brand); color: #fff; border-radius: 999px; min-width: 22px; height: 22px; padding: 0 6px; display: inline-grid; place-items: center; font-size: 12px; font-weight: 600; line-height: 1; }

/* ---------- KPIs ---------- */
.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 16px; }
.kpis > * { min-width: 0; }
.kpi { padding: 20px 22px 18px; display: grid; gap: 2px; position: relative; overflow: hidden; text-decoration: none; color: inherit; transition: transform .3s var(--ease), box-shadow .3s; }
a.kpi:hover { transform: translateY(-2px); box-shadow: 0 1px 0 rgba(22,27,38,.04), 0 24px 40px -22px rgba(22,27,38,.35); }
.kpi p { color: var(--ink-2); font-weight: 500; margin-top: 14px; }
.kpi .v { font: 600 34px/1.1 var(--num); letter-spacing: -.02em; margin-top: 2px; }
.kpi .v .u { font-size: .5em; font-weight: 500; color: var(--mute); margin-left: 4px; letter-spacing: 0; }
.kpi small { color: var(--mute); font-size: 12.5px; }
.k-ic { width: 42px; height: 42px; border-radius: 14px; background: var(--soft); display: grid; place-items: center; }
.k-ic.o { background: var(--brand-s); color: var(--brand-d); box-shadow: inset 0 0 0 2px var(--brand); }
.k-ic.b { background: var(--blue-s); color: var(--blue); }
.k-ic.r { background: var(--red-s); color: var(--red); }
.k-ic.g { background: var(--green-s); color: var(--green); }
.k-ic.a { background: var(--amber-s); color: var(--warn); }

/* ---------- Panels, rows ---------- */
.pbody { display: grid; gap: 16px; grid-template-columns: minmax(0, 1fr); }
.row2 { display: grid; gap: 16px; grid-template-columns: minmax(0, 1.6fr) minmax(0, 1fr); align-items: start; }
.row2.even { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.row3 { display: grid; gap: 16px; grid-template-columns: repeat(3, minmax(0, 1fr)); }
.box { padding: 20px 22px 22px; min-width: 0; }
.ph { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 16px; flex-wrap: wrap; }
.ph h3 { font: 600 17px var(--num); }
.ph .muted { display: block; margin-top: 2px; }
.dark-box { background: var(--dark); color: #fff; }
.dark-box .ph h3 { color: #fff; }
.dark-box .muted { color: rgba(255,255,255,.6); }

/* Toolbar (filters above tables) */
.toolbar { display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap; margin-bottom: 14px; }
.tools { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.find { display: flex; align-items: center; gap: 8px; background: var(--soft); border-radius: 12px; padding: 0 10px; height: 40px; }
.find svg { width: 16px; height: 16px; color: var(--mute); }
.find input { border: 0; background: none; outline: none; font: inherit; font-size: 13.5px; width: 220px; color: var(--ink); }
.find:focus-within { box-shadow: 0 0 0 2px var(--brand); background: var(--panel); }
.toolbar .f { margin-top: 0; flex: 0 1 auto; min-width: 160px; }
.toolbar .f > label { display: none; }
.sel select, .sel input { font: inherit; font-size: 13px; font-weight: 600; color: var(--ink-2); background: var(--soft); border: 0; border-radius: 12px; padding: 0 12px; height: 40px; cursor: pointer; max-width: 220px; }

/* ---------- Tables ---------- */
.tw { overflow-x: auto; margin: 0 -6px; padding: 0 6px; }
.dt { width: 100%; border-collapse: separate; border-spacing: 0; font-size: 13.5px; }
.dt th { text-align: left; color: var(--mute); font-size: 12px; font-weight: 500; padding: 8px 10px; border-bottom: 1px solid var(--line); white-space: nowrap; }
.dt td { padding: 11px 10px; border-bottom: 1px solid var(--line); vertical-align: middle; }
.dt tbody tr { transition: background .2s; }
.dt tbody tr:hover td { background: var(--soft); }
.dt tbody tr:hover td:first-child { border-radius: 14px 0 0 14px; }
.dt tbody tr:hover td:last-child { border-radius: 0 14px 14px 0; }
.dt tbody tr:last-child td { border-bottom: 0; }
.dt .r, .dt th.r { text-align: right; }
.dt .c { text-align: center; }
.dt .v { font: 600 14px var(--num); white-space: nowrap; }
.dt .nw { white-space: nowrap; }
.dt tr.row-link { cursor: pointer; }
.dt tfoot td { font-weight: 700; border-top: 1px solid var(--line); border-bottom: 0; }
.cell { display: flex; align-items: center; gap: 12px; min-width: 0; }
.cell b { display: block; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; color: var(--ink); }
.cell small { display: block; color: var(--mute); font-size: 12px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.cell > div { min-width: 0; }
a.cell { text-decoration: none; color: inherit; }
a.cell:hover b { color: var(--brand-d); }
.thumb { width: 44px; height: 44px; border-radius: 12px; background: var(--soft) center/cover; flex: none; display: grid; place-items: center; color: var(--ink-2); overflow: hidden; font: 600 13px var(--num); }
.thumb img { width: 100%; height: 100%; object-fit: cover; }
.thumb svg { width: 20px; height: 20px; }
.code { font: 600 12.5px ui-monospace, SFMono-Regular, Consolas, monospace; background: var(--soft); padding: 3px 7px; border-radius: 7px; color: var(--ink-2); white-space: nowrap; }

.empty { padding: 44px 10px; text-align: center; color: var(--mute); }
.empty svg { width: 34px; height: 34px; color: var(--brand); margin-bottom: 8px; }
.empty b { display: block; color: var(--ink); font: 600 16px var(--num); margin-bottom: 4px; }

/* Pagination */
.pager { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; margin-top: 16px; padding-top: 14px; border-top: 1px solid var(--line); }
.pager .muted b { color: var(--ink); font-weight: 600; }
.pages { display: flex; gap: 4px; flex-wrap: wrap; }
.pages a, .pages span { min-width: 36px; height: 36px; padding: 0 10px; border-radius: 11px; display: inline-grid; place-items: center; font: 600 13px var(--num); color: var(--ink-2); text-decoration: none; background: var(--soft); }
.pages a:hover { background: var(--brand-s); color: var(--ink); }
.pages .on { background: var(--ink); color: #fff; }
.pages .off { opacity: .4; }
.pages svg { width: 16px; height: 16px; }

/* Definition list (detail pages) */
.dl { display: grid; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: 16px 20px; }
.dl div { min-width: 0; }
.dl dt { color: var(--mute); font-size: 12px; margin-bottom: 3px; }
.dl dd { margin: 0; font-weight: 600; overflow-wrap: anywhere; }
.sum { display: grid; gap: 2px; }
.sum div { display: flex; justify-content: space-between; gap: 12px; padding: 9px 0; border-bottom: 1px solid var(--line); }
.sum div span { color: var(--ink-2); }
.sum div b { font: 600 14px var(--num); }
.sum div.tot { border-bottom: 0; padding-top: 12px; }
.sum div.tot span { color: var(--ink); font-weight: 600; }
.sum div.tot b { font-size: 20px; }

/* ---------- Forms ---------- */
.form { display: flex; flex-wrap: wrap; gap: 0 14px; align-content: flex-start; }
.fh { flex: 0 0 100%; font: 600 12.5px var(--ui); text-transform: uppercase; letter-spacing: .06em; color: var(--mute); margin: 22px 0 0; padding-top: 16px; border-top: 1px solid var(--line); }
.form > .fh:first-child, .form > input[type=hidden] + .fh, .form > input[type=hidden] + input[type=hidden] + .fh, .form > .fh:first-of-type { border-top: 0; padding-top: 0; margin-top: 4px; }
.f { flex: 1 1 100%; min-width: 0; display: flex; flex-direction: column; gap: 6px; margin-top: 14px; }
.f.half { flex: 1 1 calc(50% - 14px); }
.f.third { flex: 1 1 calc(33.33% - 14px); }
.f.quarter { flex: 1 1 calc(25% - 14px); }
.f > label, .f .lbl { font-weight: 600; font-size: 13px; color: var(--ink-2); }
.f .req { color: var(--red); font-style: normal; }
.inp, .f input:not([type=checkbox]):not([type=radio]):not([type=file]), .f select, .f textarea { width: 100%; font: inherit; font-size: 14px; color: var(--ink); background: var(--soft); border: 1px solid transparent; border-radius: 11px; padding: 10px 12px; min-height: 42px; transition: border-color .2s, background .2s; }
.f textarea { resize: vertical; min-height: 88px; }
.inp:focus, .f input:focus, .f select:focus, .f textarea:focus { outline: none; border-color: var(--brand); background: var(--panel); }
.f input[type=file] { font: inherit; font-size: 13px; padding: 9px; background: var(--soft); border-radius: 11px; width: 100%; color: var(--ink-2); }
.f input[type=file]::file-selector-button { font: 600 12.5px var(--ui); border: 0; border-radius: 9px; padding: 7px 12px; margin-right: 10px; background: var(--panel); color: var(--ink); box-shadow: 0 0 0 1px var(--line); cursor: pointer; }
.f .help { color: var(--mute); font-size: 12px; }
.f .err { color: var(--red); font-size: 12px; font-style: normal; }
.f.bad input:not([type=checkbox]):not([type=radio]), .f.bad select, .f.bad textarea, .f.bad .ts-control { border-color: var(--red) !important; background: var(--red-s) !important; }
.f select { appearance: none; background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23677084' stroke-width='2' stroke-linecap='round'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E"); background-repeat: no-repeat; background-position: right 10px center; background-size: 16px; padding-right: 34px; }
.unit { display: flex; align-items: center; background: var(--soft); border-radius: 11px; border: 1px solid transparent; }
.unit:focus-within { border-color: var(--brand); background: var(--panel); }
.unit em { font-style: normal; font-size: 12px; font-weight: 600; color: var(--mute); padding: 0 12px; white-space: nowrap; }
.unit input { background: transparent !important; border: 0 !important; }
.check { display: inline-flex; align-items: center; gap: 9px; font-weight: 500; font-size: 14px; color: var(--ink); cursor: pointer; }
.check input { width: 18px; height: 18px; accent-color: var(--brand); margin: 0; }
.radios { display: flex; gap: 8px; flex-wrap: wrap; }
.radios label { flex: 1; min-width: 120px; display: flex; align-items: center; gap: 10px; padding: 12px 14px; border-radius: 13px; background: var(--soft); border: 1px solid transparent; cursor: pointer; font-weight: 600; transition: border-color .2s, background .2s; }
.radios label:has(input:checked) { border-color: var(--brand); background: var(--brand-s); }
.radios input { accent-color: var(--brand); }
.form-foot { flex: 0 0 100%; display: flex; gap: 8px; justify-content: flex-end; align-items: center; margin-top: 22px; padding-top: 16px; border-top: 1px solid var(--line); flex-wrap: wrap; }
.form-foot .sp { flex: 1; }
.preview { display: flex; align-items: center; gap: 12px; margin-top: 6px; }
.preview img { width: 64px; height: 64px; border-radius: 14px; object-fit: cover; box-shadow: 0 0 0 1px var(--line); }

/* Alerts (inline) */
.alert { display: flex; gap: 10px; align-items: flex-start; padding: 12px 14px; border-radius: 14px; font-size: 13.5px; background: var(--blue-s); color: var(--blue); }
.alert svg { width: 18px; height: 18px; margin-top: 1px; }
.alert.bad { background: var(--red-s); color: var(--red); }
.alert.ok { background: var(--green-s); color: var(--green); }
.alert.warn { background: var(--warn-s); color: var(--warn); }
.alert b { font-weight: 600; }
.alert ul { margin: 4px 0 0; padding-left: 18px; }

/* Tom Select (searchable selects) skinned to match */
.ts-wrapper { width: 100%; }
.ts-wrapper .ts-control { background: var(--soft) !important; border: 1px solid transparent !important; border-radius: 11px !important; padding: 9px 34px 9px 12px !important; min-height: 42px; font: inherit !important; font-size: 14px !important; color: var(--ink) !important; box-shadow: none !important; }
.ts-wrapper.focus .ts-control { border-color: var(--brand) !important; background: var(--panel) !important; }
.ts-wrapper .ts-control input { font: inherit !important; color: var(--ink) !important; }
.ts-wrapper.multi .ts-control > div { background: var(--brand-s) !important; color: var(--brand-d) !important; border-radius: 8px !important; border: 0 !important; font-weight: 600; font-size: 12.5px; padding: 3px 8px !important; }
.ts-dropdown { border: 0 !important; border-radius: 14px !important; box-shadow: var(--pop) !important; padding: 6px !important; margin-top: 6px !important; background: var(--panel) !important; color: var(--ink) !important; font: 14px var(--ui) !important; z-index: 1600 !important; }
.ts-dropdown .option { border-radius: 10px; padding: 8px 10px !important; }
.ts-dropdown .active { background: var(--soft) !important; color: var(--ink) !important; }
.ts-dropdown .no-results { padding: 10px !important; color: var(--mute); }
.ts-wrapper.single .ts-control::after { border-color: var(--mute) transparent transparent !important; right: 14px !important; }

/* ---------- Modal ---------- */
.modal { position: fixed; inset: 0; z-index: 1500; background: rgba(22,27,38,.55); display: grid; place-items: center; padding: 20px 16px; animation: fadeIn .2s; }
@keyframes fadeIn { from { opacity: 0; } }
.modal-box { width: min(560px, 100%); max-height: min(92vh, 1000px); display: grid; grid-template-rows: auto minmax(0, 1fr) auto; padding: 0; overflow: hidden; animation: menuIn .25s var(--ease); }
.modal-box.wide { width: min(860px, 100%); }
.modal-box.small { width: min(420px, 100%); }
.modal-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 16px 16px 14px 22px; border-bottom: 1px solid var(--line); }
.modal-head b { font: 600 18px var(--num); display: block; }
.modal-head small { color: var(--mute); font-size: 13px; }
.modal-body { overflow-y: auto; padding: 6px 22px 20px; overscroll-behavior: contain; }
.modal-body.pad { padding: 22px; }
.modal-foot { display: flex; align-items: center; gap: 8px; justify-content: flex-end; padding: 14px 22px; border-top: 1px solid var(--line); }
.modal-q { font: 600 17px var(--num); display: block; }
.modal-body p { color: var(--ink-2); margin-top: 6px; font-size: 14px; }
body.modal-open { overflow: hidden; }

/* ---------- Toasts ---------- */
.toasts { position: fixed; left: 50%; bottom: 28px; transform: translateX(-50%); display: grid; gap: 8px; z-index: 2000; width: max-content; max-width: calc(100vw - 32px); pointer-events: none; }
.toast { display: flex; align-items: center; gap: 10px; background: var(--dark); color: #fff; padding: 12px 16px 12px 14px; border-radius: 14px; font-weight: 500; font-size: 13.5px; box-shadow: 0 16px 40px -12px rgba(22,27,38,.5); animation: toastIn .35s var(--ease); pointer-events: auto; }
.toast svg { width: 18px; height: 18px; flex: none; }
.toast.ok svg { color: #6fd6a4; }
.toast.bad svg { color: #ff8a73; }
.toast.warn svg { color: #ffb347; }
.toast.info svg { color: #7fb2ff; }
.toast.out { opacity: 0; transform: translateY(10px); transition: opacity .3s, transform .3s; }
@keyframes toastIn { from { opacity: 0; transform: translateY(16px); } }

/* ---------- Entrance ---------- */
.rise { animation: rise .6s var(--ease) both; }
.main > .rise:nth-child(2) { animation-delay: .04s; } .main > .rise:nth-child(3) { animation-delay: .1s; } .main > .rise:nth-child(4) { animation-delay: .16s; } .main > .rise:nth-child(5) { animation-delay: .22s; } .main > .rise:nth-child(6) { animation-delay: .28s; }
.kpis > .rise:nth-child(2) { animation-delay: .06s; } .kpis > .rise:nth-child(3) { animation-delay: .12s; } .kpis > .rise:nth-child(4) { animation-delay: .18s; }
@keyframes rise { from { opacity: 0; transform: translateY(14px); } }
.main.leaving > *:not(.top) { opacity: 0; transition: opacity .2s; }

/* ---------- Guest (auth) pages ---------- */
.guest { min-height: 100vh; display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1.1fr); gap: 16px; padding: 16px; max-width: 1680px; margin: 0 auto; }
.g-art { background: var(--dark); color: #fff; border-radius: var(--r); padding: 40px; display: flex; flex-direction: column; justify-content: space-between; position: relative; overflow: hidden; min-height: calc(100vh - 32px); }
.g-art::before { content: ""; position: absolute; width: 520px; height: 520px; right: -160px; bottom: -180px; border-radius: 50%; background: radial-gradient(circle, rgba(140,191,38,.45), rgba(140,191,38,0) 65%); }
.g-art::after { content: ""; position: absolute; width: 380px; height: 380px; left: -140px; top: -120px; border-radius: 50%; background: radial-gradient(circle, rgba(0,98,214,.5), rgba(0,98,214,0) 65%); }
.g-art > * { position: relative; z-index: 1; }
.g-art img { height: 56px; width: auto; max-width: 240px; align-self: flex-start; object-fit: contain; object-position: left center; filter: brightness(0) invert(1); }
.g-art h2 { font: 600 40px/1.08 var(--num); letter-spacing: -.02em; max-width: 13em; }
.g-art h2 em { font-style: normal; color: var(--lime); }
.g-art p { color: rgba(255,255,255,.7); font-size: 16px; margin-top: 14px; max-width: 30em; }
.g-pts { display: grid; gap: 10px; margin-top: 28px; }
.g-pts span { display: flex; align-items: center; gap: 10px; color: rgba(255,255,255,.85); font-weight: 500; }
.g-pts svg { width: 18px; height: 18px; color: var(--lime); }
.g-art small { color: rgba(255,255,255,.5); font-size: 12px; }
.g-main { display: grid; place-items: center; padding: 24px 8px; }
.g-card { width: 100%; max-width: 440px; padding: 34px 30px; }
.g-card.wide { max-width: 680px; }
.g-card .m-logo { display: none; height: 40px; width: auto; max-width: 180px; object-fit: contain; object-position: left center; margin-bottom: 20px; }
.g-card h1 { font: 700 28px/1.15 var(--num); margin: 0 0 4px; letter-spacing: -.01em; }
.g-card .sub { margin: 0 0 18px; color: var(--mute); font-size: 15px; }
.g-card .f input:not([type=checkbox]):not([type=radio]):not([type=file]) { background: #f7f8fb; border-color: var(--line); padding: 12px 14px; }
.g-card .f input:focus { background: var(--panel); border-color: var(--brand); }
.g-alt { text-align: center; color: var(--mute); margin-top: 20px; font-size: 14px; }
.g-alt a, .lnk-o { color: var(--brand-d); font-weight: 600; text-decoration: none; }
.g-alt a:hover, .lnk-o:hover { text-decoration: underline; }
.pw { position: relative; }
.pw input { padding-right: 46px !important; }
.pw button { position: absolute; right: 6px; top: 50%; transform: translateY(-50%); width: 34px; height: 34px; border-radius: 9px; display: grid; place-items: center; color: var(--mute); }
.pw button:hover { color: var(--ink); background: var(--soft); }
.pw svg { width: 18px; height: 18px; }

/* ---------- Responsive ---------- */
@media (max-width: 1320px) {
  .row3 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (max-width: 1100px) {
  .row2, .row2.even { grid-template-columns: minmax(0, 1fr); }
  .guest { grid-template-columns: minmax(0, 1fr); }
  .g-art { display: none; }
  .g-card .m-logo { display: block; }
}
@media (max-width: 860px) {
  .app { grid-template-columns: minmax(0, 1fr); padding: 0 12px 112px; gap: 12px; }
  .side { display: none; }
  .main { gap: 12px; }
  .top { position: sticky; top: 0; margin: 0 -12px; border-radius: 0; padding: calc(10px + env(safe-area-inset-top)) 16px 10px; box-shadow: 0 1px 0 var(--line); gap: 10px; }
  .m-brand { display: block; }
  .top .search, .top .date { display: none; }
  .me { margin-left: auto; }
  .me-t, .me .chev { display: none; }
  .me-btn { padding: 2px; }
  .me .avatar { width: 34px; height: 34px; }
  .me-menu { position: fixed; left: 12px; right: 12px; top: 64px; width: auto; border-radius: 22px; padding: 10px; max-height: calc(100vh - 170px); overflow-y: auto; }
  .phead h1, .hello h1 { font-size: 24px; }
  .phead p, .hello p { font-size: 14px; }
  .pact { width: 100%; }
  .pact .btn { flex: 1; }
  .kpis { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
  .kpi { padding: 14px; border-radius: 18px; }
  .kpi .k-ic { width: 34px; height: 34px; border-radius: 11px; }
  .kpi .k-ic svg { width: 17px; height: 17px; }
  .kpi p { margin-top: 10px; font-size: 13px; }
  .kpi .v { font-size: 24px; }
  .row3 { grid-template-columns: minmax(0, 1fr); }
  .dl { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px 14px; }
  .box { padding: 16px; }
  .tools, .find { width: 100%; }
  .find input { width: 100%; }
  .sel { flex: 1; }
  .sel select { max-width: none; width: 100%; }
  .f.half, .f.third, .f.quarter { flex: 1 1 100%; }
  .form-foot .btn { flex: 1; }
  /* tables become stacked cards */
  .dt.stack thead { display: none; }
  .dt.stack, .dt.stack tbody { display: block; width: 100%; }
  .dt.stack tr { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px 14px; padding: 12px 2px; border-bottom: 1px solid var(--line); }
  .dt.stack tbody tr:last-child { border-bottom: 0; }
  .dt.stack td { display: block; border: 0; padding: 0; text-align: left; min-width: 0; }
  .dt.stack td::before { content: attr(data-label); display: block; color: var(--mute); font-size: 11.5px; font-weight: 500; margin-bottom: 1px; }
  .dt.stack td.r { text-align: left; }
  .dt.stack td.lead, .dt.stack td.wide { grid-column: 1 / -1; }
  .dt.stack td.lead::before, .dt.stack td:not([data-label])::before { display: none; }
  .dt.stack td.hide-sm { display: none; }
  .dt.stack tbody tr:hover td { background: none; }
  .dt.stack td.acts-cell { grid-column: 1 / -1; }
  .dt.stack td.acts-cell .acts { justify-content: flex-start; margin-left: -8px; }
  .tabs { display: grid; grid-auto-flow: column; grid-auto-columns: 1fr; align-items: center; position: fixed; left: 14px; right: 14px; bottom: calc(14px + env(safe-area-inset-bottom) * .5); height: 70px; padding: 0 8px; border-radius: 999px; background: var(--panel); z-index: 1100; box-shadow: 0 14px 34px -8px rgba(22,27,38,.22), 0 2px 6px rgba(22,27,38,.05); }
  .tabs a { display: grid; justify-items: center; gap: 4px; padding: 6px 2px; font-size: 11px; font-weight: 500; color: #8a92a3; text-decoration: none; text-align: center; }
  .tabs a svg { width: 24px; height: 24px; color: #8a92a3; }
  .tabs a.on { color: var(--ink); font-weight: 600; }
  .tabs a.on svg { color: var(--brand); }
  .tabs a.plus { justify-self: center; width: 56px; height: 56px; border-radius: 50%; background: var(--brand); place-items: center; box-shadow: 0 10px 22px -8px rgba(var(--brand-rgb), .8); padding: 0; }
  .tabs a.plus svg { width: 25px; height: 25px; color: #fff; }
  .modal { padding: 0; place-items: end stretch; }
  .modal-box, .modal-box.wide, .modal-box.small { width: 100%; max-height: 94vh; border-radius: 22px 22px 0 0; }
  .toasts { bottom: 100px; }
  .guest { padding: 12px; }
  .g-main { padding: 12px 0; align-items: start; }
  .g-card { padding: 26px 20px; }
}

/* ---------- Dark theme ---------- */
body[data-theme="dark"] {
  --bg: #0e1219; --panel: #171c26; --ink: #e9ecf2; --ink-2: #b9c0cd; --mute: #8b94a6; --line: #262d3a; --soft: #1f2531; --track: #222937;
  --brand: #1f9d4f; --brand-d: #6bd394; --brand-s: #12301e; --brand-rgb: 31, 157, 79; --warn: #ffb347; --warn-s: #302611; --green: #3fbf88; --green-s: #13291f; --red: #ef6a55; --red-s: #35191a; --blue: #7fa2d6; --blue-s: #18233a; --amber-s: #302611;
  --dark: #0a0d13; --dark-2: #1b212c;
  color-scheme: dark;
}
body[data-theme="dark"] .brand img, body[data-theme="dark"] .m-brand img { filter: brightness(0) invert(1); }
body[data-theme="dark"] .btn-d { background: #e9ecf2; color: #161b26; }
body[data-theme="dark"] .pages .on { background: var(--brand); color: var(--on-brand); }
body[data-theme="dark"] .g-card .f input:not([type=checkbox]):not([type=radio]):not([type=file]) { background: var(--soft); }

/* ---------- Print ---------- */
@media print {
  body { background: #fff; }
  .side, .top, .tabs, .pact, .toasts, .no-print { display: none !important; }
  .app { display: block; padding: 0; }
  .panel { box-shadow: none; border: 1px solid #ddd; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}
