/* Samarth IVF status dashboard — dark theme.
   Layout: side menu + main column; one card per topic; colour only where it means something. */
:root {
  color-scheme: dark;
  --bg: #0a0a0c; --panel: #131316; --panel-2: #1a1a1f; --hover: #202027; --line: #26262d; --line-2: #33333c;
  --ink: #f0eff4; --muted: #9a98a6; --faint: #6b6976;
  --brand: #b18ae0; --brand-ink: #0a0a0c; --brand-soft: rgba(177, 138, 224, .14);
  /* chart series (validated for this surface: CVD ΔE 9.4, contrast ≥ 3:1) */
  --s1: #3987e5; --s2: #d95926; --s3: #199e70;
  /* status — always shown with an icon or label, never colour alone */
  --good: #0ca30c; --good-ink: #5fd36f; --good-bg: rgba(12, 163, 12, .14);
  --warn: #fab219; --warn-ink: #fac552; --warn-bg: rgba(250, 178, 25, .13);
  --bad: #d03b3b; --bad-ink: #f07c7c; --bad-bg: rgba(208, 59, 59, .16);
  --nodata: #2c2c33;
  --sans: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  --radius: 12px;
}
* { box-sizing: border-box; }
html, body { height: 100%; }
body { margin: 0; background: var(--bg); color: var(--ink); font: 14px/1.5 var(--sans); -webkit-font-smoothing: antialiased; }
a { color: var(--brand); }
button { font: inherit; cursor: pointer; }
:focus-visible { outline: 2px solid var(--brand); outline-offset: 2px; }
code, .mono { font-family: var(--mono); font-size: 12.5px; }
.muted { color: var(--muted); }
.faint { color: var(--faint); }
.small { font-size: 12.5px; }
[hidden] { display: none !important; }

/* ---------- sign-in and setup pages ---------- */
.narrow { max-width: 420px; margin: 10vh auto; padding: 0 16px; }
.panel { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 22px 24px; }
.title { font-size: 20px; margin: 0 0 4px; }
.sub { margin: 0; }
.hint { margin: 8px 0 4px; }
.tight { margin: 4px 0; }
.mt12 { margin-top: 12px; }
form { display: grid; gap: 14px; }
label { display: grid; gap: 6px; font-size: 13px; font-weight: 600; color: var(--muted); }
input { font: inherit; color: var(--ink); background: var(--panel-2); border: 1px solid var(--line-2); border-radius: 8px; padding: 10px 12px; }
input:focus { border-color: var(--brand); outline: none; }
.btn, form button, #b-passkey { background: var(--brand); color: var(--brand-ink); border: 0; border-radius: 8px; padding: 10px 16px; font-weight: 600; }
.btn:disabled, form button:disabled, #b-passkey:disabled { opacity: .55; cursor: default; }
.btn.ghost { background: transparent; color: var(--ink); border: 1px solid var(--line-2); }
.btn.ghost:hover { background: var(--hover); }
.error { color: var(--bad-ink); min-height: 1.3em; margin: 10px 0 0; font-size: 13px; }
.error.ok { color: var(--good-ink); }
.form-col { max-width: 420px; }
.steps { display: flex; gap: 6px; margin: 14px 0 18px; }
.steps span { flex: 1; height: 4px; border-radius: 2px; background: var(--line-2); }
.steps span.on { background: var(--brand); }
.qr { display: block; width: 220px; max-width: 100%; margin: 8px auto; border-radius: 8px; background: #fff; padding: 6px; }

/* ---------- desktop shell: menu bar, desktop with windows, dock ---------- */
body.os { display: grid; grid-template-rows: auto minmax(0, 1fr); height: 100vh; overflow: hidden;
  background: radial-gradient(1200px 700px at 15% 0%, #1d1430 0%, transparent 60%), radial-gradient(900px 600px at 100% 100%, #0f2236 0%, transparent 55%), var(--bg); }
.icon { width: 18px; height: 18px; flex: none; }
.menubar { display: flex; align-items: center; gap: 14px; height: 40px; padding: 0 14px; background: rgba(14, 14, 18, .82); border-bottom: 1px solid var(--line);
  backdrop-filter: blur(14px); -webkit-backdrop-filter: blur(14px); z-index: 1000; font-size: 13px; white-space: nowrap; }
.mb-brand { display: inline-flex; align-items: center; gap: 8px; font-weight: 700; }
.mark { width: 22px; height: 22px; border-radius: 6px; background: var(--brand); color: var(--brand-ink); display: grid; place-items: center; font-weight: 800; font-size: 12px; }
.mb-app { font-weight: 600; color: var(--muted); }
.menubar .spacer { flex: 1; }
.mb-clock { color: var(--muted); font-variant-numeric: tabular-nums; }
.mb-user { display: inline-flex; align-items: center; gap: 8px; color: var(--muted); }
.status-pill { display: inline-flex; align-items: center; gap: 8px; padding: 3px 10px; border-radius: 999px; font-weight: 600; font-size: 12.5px; }
.status-pill.ok { background: var(--good-bg); color: var(--good-ink); }
.status-pill.warn { background: var(--warn-bg); color: var(--warn-ink); }
.status-pill.bad { background: var(--bad-bg); color: var(--bad-ink); }
.dot { width: 8px; height: 8px; border-radius: 50%; background: currentColor; flex: none; }
.live { display: inline-flex; align-items: center; gap: 8px; color: var(--muted); font-size: 12.5px; }
.live .pulse { width: 8px; height: 8px; border-radius: 50%; background: var(--good); box-shadow: 0 0 0 0 rgba(12, 163, 12, .6); animation: pulse 2s infinite; }
@keyframes pulse { 70% { box-shadow: 0 0 0 7px rgba(12, 163, 12, 0); } 100% { box-shadow: 0 0 0 0 rgba(12, 163, 12, 0); } }
.iconbtn { display: inline-grid; place-items: center; width: 28px; height: 28px; border-radius: 7px; background: transparent; color: var(--muted); border: 1px solid var(--line-2); }
.iconbtn:hover { color: var(--ink); background: var(--hover); }
.iconbtn .icon { width: 16px; height: 16px; }
.iconbtn.spin svg { animation: spin .8s linear; }
@keyframes spin { to { transform: rotate(360deg); } }

.desktop { position: relative; overflow: hidden; }
.toast { position: absolute; left: 50%; top: 12px; transform: translateX(-50%); z-index: 900; margin: 0; max-width: min(640px, 90%);
  padding: 8px 14px; border-radius: 10px; background: var(--bad-bg); color: var(--bad-ink); border: 1px solid rgba(208, 59, 59, .4); font-size: 13px; backdrop-filter: blur(10px); }
.toast:empty { display: none; }

/* windows */
.win { position: absolute; display: grid; grid-template-rows: auto minmax(0, 1fr); background: rgba(16, 16, 20, .96); border: 1px solid var(--line-2);
  border-radius: 12px; box-shadow: 0 24px 60px rgba(0, 0, 0, .55), 0 0 0 .5px rgba(255, 255, 255, .04) inset; overflow: hidden; }
.win.focused { border-color: #44444f; box-shadow: 0 30px 80px rgba(0, 0, 0, .7); }
.win.max { inset: 0 !important; width: auto !important; height: auto !important; border-radius: 0; border-width: 0 0 1px; }
.win.moving { user-select: none; }
.win-bar { display: flex; align-items: center; gap: 12px; height: 38px; padding: 0 12px; background: #17171c; border-bottom: 1px solid var(--line); cursor: default; touch-action: none; user-select: none; }
.win-title { display: inline-flex; align-items: center; gap: 8px; margin: 0 auto; padding-right: 54px; font-weight: 600; font-size: 13px; color: var(--muted); }
.win.focused .win-title { color: var(--ink); }
.win-title .icon { width: 15px; height: 15px; }
.lights { display: inline-flex; gap: 8px; }
.light { width: 13px; height: 13px; border-radius: 50%; border: 0; padding: 0; background: #3a3a44; }
.win.focused .light.close, .lights:hover .light.close { background: #ff5f57; }
.win.focused .light.min, .lights:hover .light.min { background: #febc2e; }
.win.focused .light.zoom, .lights:hover .light.zoom { background: #28c840; }
.light:focus-visible { outline-offset: 1px; }
.win-body { overflow: auto; padding: 16px; container-type: inline-size; }
.win-grip { position: absolute; right: 0; bottom: 0; width: 18px; height: 18px; cursor: nwse-resize; touch-action: none;
  background: linear-gradient(135deg, transparent 55%, var(--line-2) 55%, var(--line-2) 62%, transparent 62%, transparent 72%, var(--line-2) 72%, var(--line-2) 79%, transparent 79%); }
.win.max .win-grip { display: none; }

/* dock */
.dock { position: fixed; left: 50%; bottom: 10px; transform: translateX(-50%); z-index: 1000; display: flex; gap: 6px; padding: 7px;
  background: rgba(24, 24, 30, .72); border: 1px solid rgba(255, 255, 255, .08); border-radius: 18px; backdrop-filter: blur(18px); -webkit-backdrop-filter: blur(18px); max-width: calc(100vw - 20px); overflow-x: auto; }
.dock-app { position: relative; display: grid; place-items: center; width: 48px; height: 48px; border-radius: 12px; border: 0; color: var(--ink);
  background: linear-gradient(160deg, #2b2b35, #1b1b22); transition: transform .12s ease; flex: none; }
.dock-app:hover { transform: translateY(-4px); }
.dock-app .icon { width: 22px; height: 22px; }
.dock-app[aria-pressed="true"] { background: linear-gradient(160deg, #3a2d52, #231b33); color: #d9c4f5; }
.dock-app.running::after { content: ""; position: absolute; bottom: -5px; width: 4px; height: 4px; border-radius: 50%; background: var(--muted); }
.dock-badge { position: absolute; top: -4px; right: -4px; min-width: 18px; height: 18px; padding: 0 5px; border-radius: 999px; background: var(--bad); color: #fff; font-size: 11px; font-weight: 700; display: grid; place-items: center; }
.dock-tip { position: absolute; bottom: 60px; left: 50%; transform: translateX(-50%); padding: 3px 8px; border-radius: 6px; background: #26262e; color: var(--ink); font-size: 12px; white-space: nowrap; pointer-events: none; opacity: 0; transition: opacity .12s; }
.dock-app:hover .dock-tip, .dock-app:focus-visible .dock-tip { opacity: 1; }
.dock { overflow: visible; }

/* forms and buttons inside apps */
select { font: inherit; color: var(--ink); background: var(--panel-2); border: 1px solid var(--line-2); border-radius: 8px; padding: 7px 10px; }
.btn.small, .small.btn { padding: 5px 11px; font-size: 12.5px; }
.btn.danger { background: transparent; color: var(--bad-ink); border: 1px solid rgba(208, 59, 59, .45); }
.btn.danger:hover { background: var(--bad-bg); }
.row-btns { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }
.inline-form { display: flex; flex-wrap: wrap; gap: 12px; align-items: end; padding: 12px; margin-bottom: 12px; background: var(--panel-2); border-radius: 10px; }
.filters { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 12px; }
.filters input { padding: 7px 10px; font-size: 13px; min-width: 220px; }
.more { padding-top: 10px; text-align: center; }
dialog { background: var(--panel); color: var(--ink); border: 1px solid var(--line-2); border-radius: 14px; padding: 22px 24px; width: min(520px, calc(100vw - 32px)); box-shadow: 0 30px 80px rgba(0, 0, 0, .7); }
dialog::backdrop { background: rgba(0, 0, 0, .55); backdrop-filter: blur(3px); }
dialog h2 { margin: 0 0 10px; font-size: 17px; }
#cf-result { display: grid; gap: 10px; margin: 6px 0; justify-items: start; }
.linkrow { display: flex; gap: 8px; width: 100%; }
.linkbox { flex: 1; min-width: 0; font-size: 12px; }

/* ---------- cards, grids ---------- */
.page { display: grid; gap: 16px; }
.grid { display: grid; gap: 16px; }
.cols-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.cols-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.cols-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.span-2 { grid-column: span 2; }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px 20px; min-width: 0; }
.card-head { display: flex; align-items: center; gap: 10px; margin-bottom: 14px; }
.card-head h2 { font-size: 14px; font-weight: 600; margin: 0; }
.card-head .sub { color: var(--muted); font-size: 12.5px; }
.card-head .right { margin-left: auto; display: flex; gap: 6px; align-items: center; }
.seg { display: inline-flex; background: var(--panel-2); border: 1px solid var(--line); border-radius: 8px; padding: 2px; }
.seg button { background: transparent; border: 0; color: var(--muted); padding: 4px 10px; border-radius: 6px; font-size: 12.5px; font-weight: 600; }
.seg button[aria-pressed="true"] { background: var(--hover); color: var(--ink); }

/* KPI tiles */
.kpi .label { color: var(--muted); font-size: 12.5px; display: flex; align-items: center; gap: 8px; }
.kpi .value { font-size: 28px; font-weight: 700; letter-spacing: -.02em; margin: 6px 0 2px; font-variant-numeric: tabular-nums; }
.kpi .value small { font-size: 14px; color: var(--muted); font-weight: 500; margin-left: 4px; }
.kpi .note { color: var(--muted); font-size: 12.5px; }
.kpi .spark { height: 36px; margin-top: 8px; }
.meter { height: 8px; border-radius: 4px; background: var(--panel-2); overflow: hidden; margin-top: 10px; }
.meter > span { display: block; height: 100%; border-radius: 4px; background: var(--s1); }

/* badges */
.badge { display: inline-flex; align-items: center; gap: 6px; padding: 2px 9px; border-radius: 999px; font-size: 12px; font-weight: 600; white-space: nowrap; }
.badge.ok { background: var(--good-bg); color: var(--good-ink); }
.badge.warn { background: var(--warn-bg); color: var(--warn-ink); }
.badge.bad { background: var(--bad-bg); color: var(--bad-ink); }
.badge.neutral { background: var(--panel-2); color: var(--muted); }

/* tables */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-variant-numeric: tabular-nums; }
th, td { text-align: left; padding: 9px 10px; border-bottom: 1px solid var(--line); vertical-align: middle; }
th { font-size: 11.5px; text-transform: uppercase; letter-spacing: .05em; color: var(--faint); font-weight: 600; }
tbody tr:last-child td { border-bottom: 0; }
td code { white-space: nowrap; }
.nowrap { white-space: nowrap; }

/* attention list */
.alist { display: grid; gap: 8px; }
.aitem { display: flex; gap: 10px; align-items: flex-start; padding: 10px 12px; border-radius: 10px; background: var(--panel-2); }
.aitem .t { font-weight: 600; }
.aitem .d { color: var(--muted); font-size: 12.5px; }
.allclear { display: flex; gap: 10px; align-items: center; color: var(--good-ink); font-weight: 600; padding: 10px 0; }

#backup .alist { grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); }

/* app cards */
.apps { display: grid; grid-template-columns: repeat(auto-fill, minmax(250px, 1fr)); gap: 12px; }
.app { background: var(--panel-2); border: 1px solid var(--line); border-radius: 10px; padding: 14px; display: grid; gap: 8px; }
.app .top { display: flex; align-items: center; gap: 8px; }
.app .name { font-weight: 600; }
.app .domain { color: var(--muted); font-size: 12.5px; overflow-wrap: anywhere; }
.app .meta { display: flex; justify-content: space-between; color: var(--muted); font-size: 12px; }
.strip { display: flex; gap: 1px; height: 18px; }
.strip i { flex: 1; border-radius: 1px; background: var(--nodata); }
.strip i.up { background: var(--good); }
.strip i.part { background: var(--warn); }
.strip i.down { background: var(--bad); }

/* charts */
.chart { position: relative; height: 240px; }
.chart.short { height: 180px; }
.chart svg { display: block; width: 100%; height: 100%; overflow: visible; }
.chart .grid-line { stroke: var(--line); stroke-width: 1; }
.chart .axis-text { fill: var(--faint); font-size: 11px; font-family: var(--sans); }
.chart .ref-line { stroke: var(--warn); stroke-width: 1; stroke-dasharray: 4 4; }
.chart .ref-text { fill: var(--warn-ink); font-size: 11px; }
.chart .cross { stroke: var(--line-2); stroke-width: 1; }
.chart .empty { fill: var(--faint); font-size: 13px; }
.tip { position: absolute; pointer-events: none; z-index: 5; min-width: 150px; background: #1f1f26; border: 1px solid var(--line-2); border-radius: 8px; padding: 8px 10px; font-size: 12px; box-shadow: 0 8px 24px rgba(0, 0, 0, .45); }
.tip .when { color: var(--muted); margin-bottom: 4px; }
.tip .row { display: flex; justify-content: space-between; gap: 14px; }
.tip .row b { font-variant-numeric: tabular-nums; }
.hbar { display: grid; grid-template-columns: 170px minmax(0, 1fr) 70px; gap: 10px; align-items: center; padding: 6px 0; }
.hbar .track { height: 10px; background: var(--panel-2); border-radius: 5px; overflow: hidden; }
.hbar .fill { height: 100%; border-radius: 0 5px 5px 0; background: var(--s1); }
.hbar .fill.warn { background: var(--warn); }
.hbar .val { text-align: right; font-variant-numeric: tabular-nums; color: var(--muted); }

/* ---------- file manager ---------- */
.fm { display: grid; grid-template-columns: 260px minmax(0, 1fr); min-height: 560px; padding: 0; overflow: hidden; }
.fm-tree { border-right: 1px solid var(--line); padding: 12px 8px; overflow: auto; max-height: 75vh; background: #101013; }
.fm-tree .tn { display: flex; align-items: center; gap: 6px; width: 100%; background: transparent; border: 0; color: var(--muted); padding: 5px 8px; border-radius: 6px; text-align: left; font-size: 13px; white-space: nowrap; }
.fm-tree .tn:hover { background: var(--hover); color: var(--ink); }
.fm-tree .tn[aria-current="true"] { background: var(--brand-soft); color: var(--ink); }
.fm-tree .caret { width: 12px; display: inline-block; color: var(--faint); transition: transform .15s; }
.fm-tree .caret.open { transform: rotate(90deg); }
.fm-tree .kids { margin-left: 14px; }
.fm-tree .root-label { color: var(--faint); font-size: 11px; text-transform: uppercase; letter-spacing: .05em; padding: 10px 8px 4px; }
.fm-main { display: grid; grid-template-rows: auto auto minmax(0, 1fr) auto; min-width: 0; }
.fm-bar { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; padding: 12px 16px; border-bottom: 1px solid var(--line); }
.crumbs { display: flex; flex-wrap: wrap; align-items: center; gap: 2px; font-family: var(--mono); font-size: 12.5px; min-width: 0; }
.crumbs button { background: transparent; border: 0; color: var(--muted); padding: 3px 5px; border-radius: 5px; font-family: var(--mono); }
.crumbs button:hover { background: var(--hover); color: var(--ink); }
.crumbs button:last-child { color: var(--ink); font-weight: 600; }
.crumbs .sep { color: var(--faint); }
.fm-search { margin-left: auto; position: relative; }
.fm-search input { width: 220px; padding: 7px 10px 7px 30px; font-size: 13px; }
.fm-search svg { position: absolute; left: 9px; top: 9px; color: var(--faint); width: 14px; height: 14px; }
.fm-summary { display: flex; gap: 18px; padding: 10px 16px; color: var(--muted); font-size: 12.5px; border-bottom: 1px solid var(--line); }
.fm-list { overflow: auto; max-height: 60vh; }
.fm-list table th { position: sticky; top: 0; background: var(--panel); z-index: 1; }
.fm-list th button { background: transparent; border: 0; color: inherit; font: inherit; text-transform: inherit; letter-spacing: inherit; padding: 0; }
.fm-list th button:hover { color: var(--ink); }
.fm-list tbody tr { cursor: pointer; }
.fm-list tbody tr:hover { background: var(--hover); }
.fm-list tbody tr[aria-selected="true"] { background: var(--brand-soft); }
.fm-name { display: flex; align-items: center; gap: 8px; min-width: 0; }
.fm-name span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 380px; }
.fm-name .icon { width: 16px; height: 16px; }
.ic-dir { color: #e2b04a; }
.ic-file { color: var(--muted); }
.ic-lock { color: var(--warn); }
.ic-link { color: var(--s1); }
.sizecell { display: flex; align-items: center; gap: 8px; min-width: 120px; }
.sizecell .bar { flex: 1; height: 6px; background: var(--panel-2); border-radius: 3px; overflow: hidden; }
.sizecell .bar i { display: block; height: 100%; background: var(--s1); border-radius: 0 3px 3px 0; }
.sizecell b { font-weight: 500; min-width: 64px; text-align: right; color: var(--muted); }
.perm { font-family: var(--mono); font-size: 12px; color: var(--muted); letter-spacing: .02em; }
.fm-detail { border-top: 1px solid var(--line); padding: 14px 16px; background: #101013; display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 10px 18px; }
.fm-detail .k { color: var(--faint); font-size: 11px; text-transform: uppercase; letter-spacing: .05em; }
.fm-detail .v { overflow-wrap: anywhere; }
.fm-detail .wide { grid-column: 1 / -1; }
.warnbox { display: flex; gap: 8px; align-items: center; color: var(--warn-ink); background: var(--warn-bg); border-radius: 8px; padding: 8px 10px; font-size: 13px; }

/* skeleton while loading */
.skeleton { background: linear-gradient(90deg, var(--panel-2), var(--hover), var(--panel-2)); background-size: 200% 100%; animation: shimmer 1.2s infinite; border-radius: 6px; min-height: 14px; }
@keyframes shimmer { to { background-position: -200% 0; } }

/* ---------- narrow windows and phones (keep last) ---------- */
/* Layout follows the window's width, not the screen's: a window can be narrow on a wide screen. */
.page { padding-bottom: 72px; } /* room above the dock */
@container (max-width: 1000px) { .cols-4 { grid-template-columns: repeat(2, minmax(0, 1fr)); } .cols-3 { grid-template-columns: minmax(0, 1fr); } .span-2 { grid-column: auto; } }
@container (max-width: 700px) {
  .cols-2, .cols-4 { grid-template-columns: minmax(0, 1fr); }
  .fm { grid-template-columns: minmax(0, 1fr); }
  .fm-tree { max-height: 220px; border-right: 0; border-bottom: 1px solid var(--line); }
  .fm-search input { width: 100%; } .fm-search { margin-left: 0; width: 100%; }
  .hbar { grid-template-columns: 110px minmax(0, 1fr) 56px; }
}
@media (max-width: 760px) {
  .menubar { gap: 10px; padding: 0 10px; }
  .live, .mb-clock, #who, .mb-app { display: none; }
  .win-body { padding: 12px; }
  .win-grip { display: none; }
  .dock { left: 0; right: 0; bottom: 0; transform: none; border-radius: 16px 16px 0 0; justify-content: flex-start; overflow-x: auto; max-width: none; }
  .dock-tip { display: none; }
  .dock-app { width: 44px; height: 44px; }
  .filters input { min-width: 0; flex: 1; }
}
@media (prefers-reduced-motion: reduce) { *, *::before, *::after { animation: none !important; transition: none !important; } }
