/*───────────────────────────────────────────────────────────────────────────
  PharmaBI — application shell
  Sidebar, context bar, command palette, skeletons, dark mode.

  Loaded AFTER app.css. It overrides a few tokens and adds the shell; every
  existing component class in app.css keeps working untouched, so a page can
  adopt the shell without being rewritten.
───────────────────────────────────────────────────────────────────────────*/

:root{
  /* --muted-2 was #94a3b8 on white: about 2.8:1, below the 4.5:1 minimum for
     small text. Darkened so hints and secondary labels are actually legible
     in a bright pharmacy. */
  --muted-2:#6b7a90;

  --sidebar-w:218px;
  --sidebar-w-min:62px;
  --shell-bg:#f6f7fb;
  --sb-bg:#ffffff;
  --sb-hover:#f1f5f9;
  --ring:0 0 0 3px var(--primary-tint);
}

/*───────────────────────────── dark mode ─────────────────────────────────*/
html[data-theme="dark"]{
  --bg:#0b1220; --surface:#131c2e; --surface-2:#1b2740;
  --border:#263349; --border-strong:#36455f;
  --text:#e6ecf5; --muted:#9babc2; --muted-2:#8294ad;
  --primary:#818cf8; --primary-600:#a5b4fc; --primary-tint:#1e2a4a;
  --green:#4ade80; --green-tint:#14321f; --red:#f87171; --red-tint:#3a1b1b;
  --amber:#fbbf24; --amber-tint:#3a2d0c;
  --sh:0 1px 2px rgba(0,0,0,.4), 0 2px 6px rgba(0,0,0,.3);
  --sh-md:0 6px 20px rgba(0,0,0,.45);
  --shell-bg:#0b1220; --sb-bg:#101829; --sb-hover:#1b2740;
  color-scheme:dark;
}
html[data-theme="dark"] body{ background:var(--shell-bg); }
html[data-theme="dark"] .nav{ background:rgba(16,24,41,.85); }

/* A browser draws a <select>'s option list itself, so CSS cannot reach it -
   that is why it stayed white-on-white in dark mode. color-scheme is the one
   property it does honour, and it makes the native popup dark. */
html[data-theme="dark"] select,
html[data-theme="dark"] input[type=date],
html[data-theme="dark"] input[type=text],
html[data-theme="dark"] input[type=number]{ color-scheme:dark; }

/* on-page filter bar, for pages that prefer their own controls to the
   context chips in the top bar */
.filterbar{ display:flex; gap:16px; align-items:flex-end; flex-wrap:wrap;
  background:var(--surface); border:1px solid var(--border); border-radius:var(--r);
  box-shadow:var(--sh); padding:14px 16px; margin-bottom:18px; }
.filterbar label{ display:block; font-size:.66rem; font-weight:650; text-transform:uppercase;
  letter-spacing:.06em; color:var(--muted); margin-bottom:6px; }
.filterbar select,.filterbar input[type=date]{ padding:8px 11px; border:1px solid var(--border-strong);
  border-radius:var(--r-sm); background:var(--surface); color:var(--text); font-size:.88rem; outline:none; }
.filterbar select{ min-width:210px; }
.filterbar select:focus,.filterbar input:focus{ border-color:var(--primary); box-shadow:var(--ring); }
.filterbar .note{ font-size:.8rem; color:var(--muted); align-self:center; }

/*──────────────────────── no flash of the old page ───────────────────────
  This file is in <head>, so these rules apply before the first paint. The
  old top bar never shows, and the page body stays invisible until shell.js
  has built the new frame (html.shell-ready). If shell.js ever failed to
  load, the body still appears after 2.5 s rather than staying blank.     */
html:not(.shell-ready) body > .nav{ display:none; }
html:not(.shell-ready) body > .wrap{ visibility:hidden; animation:pbiReveal 0s 2.5s forwards; }
@keyframes pbiReveal{ to{ visibility:visible; } }
html.sb-noanim .sb, html.sb-noanim .main{ transition:none !important; }

/*──────────────────────────── shell layout ───────────────────────────────*/
body.shell{ background:var(--shell-bg); }
.shell-wrap{ display:flex; min-height:100vh; }

/* ── sidebar ─────────────────────────────────────────────────────────── */
.sb{ width:var(--sidebar-w); flex:0 0 auto; background:var(--sb-bg);
  border-right:1px solid var(--border); display:flex; flex-direction:column;
  position:fixed; left:0; top:0; height:100vh; overflow-x:hidden; z-index:45;
  transition:width .22s cubic-bezier(.4,0,.2,1), box-shadow .22s ease; }
.sb.min{ width:var(--sidebar-w-min); }
/* hidden: page gets the full screen width */
.sb.off{ width:0; border-right:0; }
body.sb-off .page{ max-width:none; }

/* The menu is fixed, so the page reserves its width with a margin. Hover
   ("peek") widens only the menu - the margin stays, so nothing jumps. */
.main{ margin-left:var(--sidebar-w); transition:margin-left .22s cubic-bezier(.4,0,.2,1); }
body.sb-min .main{ margin-left:var(--sidebar-w-min); }
body.sb-off .main{ margin-left:0; }
.sb.peek{ width:var(--sidebar-w); box-shadow:8px 0 28px rgba(15,23,42,.16); border-right:1px solid var(--border); }
html[data-theme="dark"] .sb.peek{ box-shadow:8px 0 28px rgba(0,0,0,.5); }
.sb.peek .sb-a span,.sb.peek .sb-grp,.sb.peek .sb-name{ animation:sbFade .2s ease both; }
@keyframes sbFade{ from{ opacity:0; transform:translateX(-4px); } to{ opacity:1; transform:none; } }

/* invisible strip on the left edge that opens a hidden menu on hover */
.sb-edge{ display:none; position:fixed; left:0; top:0; width:10px; height:100vh; z-index:46; }
body.sb-off .sb-edge{ display:block; }
.sb.min .sb-foot{ flex-direction:column; }
.sb.min .sb-top{ justify-content:center; padding:16px 0 12px; }

.sb-top{ display:flex; align-items:center; gap:9px; padding:16px 14px 12px; }
.sb-logo{ width:28px; height:28px; border-radius:8px; flex:0 0 auto;
  background:linear-gradient(135deg,var(--primary),#7c3aed); color:#fff;
  display:flex; align-items:center; justify-content:center; font-weight:800; font-size:.82rem; }
.sb-name{ font-weight:750; letter-spacing:-.02em; font-size:1rem; white-space:nowrap; }
.sb.min .sb-name,.sb.min .sb-grp,.sb.min .sb-a span,.sb.min .sb-foot-txt{ display:none; }
.sb.min .sb-a{ justify-content:center; padding:9px 0; }

.sb-scroll{ flex:1; overflow-y:auto; padding:4px 10px 12px; }
.sb-scroll::-webkit-scrollbar{ width:6px; }
.sb-scroll::-webkit-scrollbar-thumb{ background:var(--border-strong); border-radius:3px; }

.sb-grp{ font-size:.63rem; font-weight:700; text-transform:uppercase; letter-spacing:.09em;
  color:var(--muted-2); padding:14px 10px 5px; }
.sb-a{ display:flex; align-items:center; gap:10px; padding:8px 10px; border-radius:9px;
  color:var(--muted); text-decoration:none; font-size:.875rem; font-weight:500;
  transition:background .12s,color .12s; white-space:nowrap; }
.sb-a:hover{ background:var(--sb-hover); color:var(--text); }
.sb-a.on{ background:var(--primary-tint); color:var(--primary-600); font-weight:650; }
.sb-a svg{ width:17px; height:17px; flex:0 0 auto; stroke-width:1.8; }

.sb-foot{ border-top:1px solid var(--border); padding:10px; display:flex; align-items:center; gap:8px; }
.sb-foot button{ background:transparent; color:var(--muted); border:0; padding:7px;
  border-radius:8px; cursor:pointer; display:flex; }
.sb-foot button:hover{ background:var(--sb-hover); color:var(--text); }
.sb-foot-txt{ font-size:.76rem; color:var(--muted-2); overflow:hidden; text-overflow:ellipsis; white-space:nowrap; }

/* ── main column ─────────────────────────────────────────────────────── */
.main{ flex:1; min-width:0; display:flex; flex-direction:column; }

/* ── context bar ─────────────────────────────────────────────────────── */
.ctx{ position:sticky; top:0; z-index:40; display:flex; align-items:center; gap:10px;
  flex-wrap:wrap; padding:11px 22px; background:rgba(255,255,255,.88);
  backdrop-filter:saturate(180%) blur(10px); border-bottom:1px solid var(--border); }
html[data-theme="dark"] .ctx{ background:rgba(19,28,46,.88); }

.ctx-chip{ display:inline-flex; align-items:center; gap:7px; padding:6px 11px;
  border:1px solid var(--border-strong); border-radius:var(--r-pill); background:var(--surface);
  font-size:.82rem; font-weight:550; color:var(--text); cursor:pointer; transition:.14s; }
.ctx-chip:hover{ border-color:var(--primary); color:var(--primary-600); }
.ctx-chip svg{ width:15px; height:15px; stroke-width:1.9; opacity:.75; }
.ctx-chip select,.ctx-chip input{ border:0; background:transparent; padding:0; font-size:.82rem;
  font-weight:550; color:inherit; outline:none; cursor:pointer; }
.ctx-chip .caret{ width:13px; height:13px; opacity:.55; margin-left:1px; }

/* Branch picker — a native <select> cannot be themed (the browser draws the
   option list itself, white-on-white in dark mode), so this replaces it. */
.bp{ position:fixed; z-index:60; width:320px; max-width:94vw; background:var(--surface);
  border:1px solid var(--border); border-radius:var(--r); box-shadow:var(--sh-md); overflow:hidden; }
.bp input{ width:100%; border:0; border-bottom:1px solid var(--border); padding:11px 14px;
  font-size:.9rem; background:transparent; color:var(--text); outline:none; }
.bp input::placeholder{ color:var(--muted-2); }
.bp .list{ max-height:min(60vh,380px); overflow:auto; padding:5px; }
.bp .list::-webkit-scrollbar{ width:7px; }
.bp .list::-webkit-scrollbar-thumb{ background:var(--border-strong); border-radius:4px; }
.bp .it{ display:flex; align-items:center; gap:9px; padding:8px 11px; border-radius:8px;
  font-size:.86rem; color:var(--text); cursor:pointer; }
.bp .it:hover,.bp .it.sel{ background:var(--surface-2); }
.bp .it.on{ color:var(--primary-600); font-weight:650; }
.bp .it .tick{ width:14px; height:14px; flex:0 0 auto; opacity:0; }
.bp .it.on .tick{ opacity:1; }
.bp .it .co{ margin-left:auto; font-size:.72rem; color:var(--muted-2); }
.bp .sep{ height:1px; background:var(--border); margin:5px 7px; }
.bp .none{ padding:16px; text-align:center; color:var(--muted); font-size:.85rem; }
.ctx-note{ font-size:.74rem; color:var(--muted-2); }

/* Page name + what is currently being shown. On a page with its own filter
   bar these fill the space the hidden chips leave behind, and they stay
   visible once the filter bar scrolls away. */
.ctx-title{ font-size:.92rem; font-weight:700; letter-spacing:-.01em; color:var(--text);
  white-space:nowrap; }
.ctx-title:empty{ display:none; }
.ctx-sum{ font-size:.8rem; color:var(--muted); white-space:nowrap; overflow:hidden;
  text-overflow:ellipsis; padding-left:12px; margin-left:2px; border-left:1px solid var(--border); }
.ctx-sum:empty{ display:none; }
.ctx-upd{ font-size:.74rem; color:var(--muted-2); white-space:nowrap; }
@media(max-width:900px){ .ctx-sum,.ctx-upd{ display:none; } }

/* icon-only control (theme), sized to match the search box beside it */
.ctx-icon{ margin-left:auto; background:var(--surface); color:var(--muted);
  border:1px solid var(--border-strong); border-radius:var(--r-pill);
  width:34px; height:34px; padding:0; display:inline-flex; align-items:center;
  justify-content:center; cursor:pointer; transition:.14s; flex:0 0 auto; }
.ctx-icon + .ctx-search,.ctx-icon + .ctx-icon{ margin-left:0; }
/* menu toggle sits at the far left, before the page title */
.ctx-icon.ctx-sbt{ margin-left:0; border-color:transparent; background:transparent; }
.ctx-icon.ctx-sbt:hover{ border-color:var(--primary); }
.ctx-icon:hover{ color:var(--primary-600); border-color:var(--primary); background:var(--primary-tint); }
.ctx-icon svg{ width:16px; height:16px; stroke-width:1.9; }

/* search reads as a field, not a button - people expect to type into it */
.ctx-search{ display:inline-flex; align-items:center; gap:9px; height:34px; padding:0 10px 0 12px;
  min-width:258px; border:1px solid var(--border-strong); border-radius:var(--r-pill);
  background:var(--surface); color:var(--muted); font-size:.83rem; font-weight:450;
  cursor:text; transition:.14s; flex:0 0 auto; }
.ctx-search:hover{ border-color:var(--primary); background:var(--primary-tint); color:var(--text); }
.ctx-search svg{ width:15px; height:15px; opacity:.7; flex:0 0 auto; }
.ctx-search span{ flex:1; text-align:left; white-space:nowrap; overflow:hidden; text-overflow:ellipsis; }
.ctx-search kbd{ font:inherit; font-size:.7rem; padding:2px 7px; border-radius:6px; color:var(--muted-2);
  background:var(--surface-2); border:1px solid var(--border); flex:0 0 auto; }
@media(max-width:760px){
  .ctx-search{ min-width:0; width:34px; padding:0; justify-content:center; }
  .ctx-search span,.ctx-search kbd{ display:none; }
}

/* date popover — fixed, so scrolling the page cannot leave it stranded */
.pop{ position:fixed; z-index:60; background:var(--surface); border:1px solid var(--border);
  border-radius:var(--r); box-shadow:var(--sh-md); padding:0; width:420px; max-width:94vw;
  display:flex; overflow:hidden; }
.pop .col-l{ width:168px; flex:0 0 auto; border-right:1px solid var(--border); padding:7px; }
.pop .col-r{ flex:1; padding:12px 14px; min-width:0; }
.pop b{ display:block; font-size:.63rem; text-transform:uppercase; letter-spacing:.08em;
  color:var(--muted-2); padding:6px 9px 5px; }
.pop a{ display:block; padding:7px 9px; border-radius:8px; font-size:.84rem;
  color:var(--text); text-decoration:none; cursor:pointer; }
.pop a:hover{ background:var(--surface-2); }
.pop a.on{ background:var(--primary-tint); color:var(--primary-600); font-weight:600; }
.pop .fld{ margin-bottom:10px; }
.pop .fld label{ display:block; font-size:.66rem; font-weight:650; text-transform:uppercase;
  letter-spacing:.06em; color:var(--muted); margin-bottom:5px; }
.pop .fld input{ width:100%; padding:8px 10px; border:1px solid var(--border-strong);
  border-radius:var(--r-sm); background:var(--surface); color:var(--text); font-size:.86rem; outline:none; }
.pop .fld input:focus{ border-color:var(--primary); box-shadow:var(--ring); }
.pop .days{ font-size:.78rem; color:var(--muted); margin:2px 0 10px; }
.pop .err{ font-size:.78rem; color:var(--red); margin:-6px 0 9px; display:none; }
.pop .go{ display:flex; gap:8px; }
.pop .go button{ flex:1; padding:8px; font-size:.84rem; }

/* step the whole period back / forward, keeping its length */
.ctx-step{ display:inline-flex; align-items:center; border:1px solid var(--border-strong);
  border-radius:var(--r-pill); overflow:hidden; background:var(--surface); }
.ctx-step button{ background:transparent; color:var(--muted); border:0; padding:6px 9px;
  cursor:pointer; display:flex; }
.ctx-step button:hover{ background:var(--surface-2); color:var(--primary-600); }
.ctx-step button:disabled{ opacity:.35; cursor:not-allowed; }

/* ── page head ───────────────────────────────────────────────────────── */
.page{ padding:22px 22px 60px; max-width:1560px; width:100%; margin:0 auto; }
.ph{ display:flex; align-items:flex-end; gap:14px; flex-wrap:wrap; margin-bottom:18px; }
.ph h1{ margin:0; font-size:1.45rem; }
.ph .sub{ font-size:.84rem; color:var(--muted); margin-top:3px; }
.ph .acts{ margin-left:auto; display:flex; gap:8px; }

/* ── metric tiles ────────────────────────────────────────────────────── */
.tiles{ display:grid; grid-template-columns:repeat(auto-fit,minmax(170px,1fr)); gap:13px; margin-bottom:18px; }
.tile{ background:var(--surface); border:1px solid var(--border); border-radius:var(--r);
  padding:15px 17px; box-shadow:var(--sh); position:relative; overflow:hidden; }
.tile .lbl{ font-size:.67rem; font-weight:650; text-transform:uppercase; letter-spacing:.07em; color:var(--muted); }
.tile .val{ font-size:1.6rem; font-weight:760; letter-spacing:-.025em; margin-top:5px;
  font-variant-numeric:tabular-nums; }
.tile .dl{ font-size:.76rem; font-weight:650; margin-top:3px; display:flex; align-items:center; gap:4px; }
.tile .spark{ position:absolute; right:0; bottom:0; opacity:.16; }
.up{ color:var(--green); } .down{ color:var(--red); } .flat{ color:var(--muted-2); }

/* ── attention list ──────────────────────────────────────────────────── */
.att{ display:flex; gap:11px; padding:11px 0; border-bottom:1px solid var(--border); }
.att:last-child{ border-bottom:0; }
.att .ico{ width:30px; height:30px; border-radius:9px; flex:0 0 auto; display:flex;
  align-items:center; justify-content:center; }
.att .ico svg{ width:16px; height:16px; stroke-width:2; }
.att.red  .ico{ background:var(--red-tint);   color:var(--red); }
.att.amb  .ico{ background:var(--amber-tint); color:var(--amber); }
.att.blue .ico{ background:var(--primary-tint); color:var(--primary-600); }
.att .t{ font-size:.87rem; font-weight:650; }
.att .s{ font-size:.78rem; color:var(--muted); margin-top:1px; }
.att .go{ margin-left:auto; align-self:center; font-size:.78rem; color:var(--primary-600);
  text-decoration:none; font-weight:600; white-space:nowrap; }

/* ── skeletons ───────────────────────────────────────────────────────── */
.sk{ background:linear-gradient(90deg,var(--surface-2) 25%,var(--border) 37%,var(--surface-2) 63%);
  background-size:400% 100%; animation:shm 1.3s ease infinite; border-radius:7px; }
@keyframes shm{ 0%{background-position:100% 50%} 100%{background-position:0 50%} }
.sk-l{ height:12px; margin:8px 0; } .sk-v{ height:26px; width:70%; margin:7px 0; }

/* ── empty state ─────────────────────────────────────────────────────── */
.empty{ text-align:center; padding:34px 18px; color:var(--muted); }
.empty svg{ width:34px; height:34px; opacity:.4; margin-bottom:9px; stroke-width:1.5; }
.empty .t{ font-weight:650; color:var(--text); font-size:.92rem; }
.empty .s{ font-size:.82rem; margin-top:3px; }

/* ── command palette ─────────────────────────────────────────────────── */
.cmd-bg{ position:fixed; inset:0; background:rgba(15,23,42,.42); backdrop-filter:blur(3px);
  z-index:90; display:flex; align-items:flex-start; justify-content:center; padding-top:11vh; }
.cmd{ width:min(600px,92vw); background:var(--surface); border:1px solid var(--border);
  border-radius:var(--r); box-shadow:var(--sh-md); overflow:hidden; }
.cmd-top{ display:flex; align-items:center; gap:11px; padding:0 16px;
  border-bottom:1px solid var(--border); }
.cmd-top svg{ width:17px; height:17px; color:var(--muted-2); flex:0 0 auto; }
.cmd-top kbd{ font:inherit; font-size:.68rem; padding:2px 7px; border-radius:6px; color:var(--muted-2);
  background:var(--surface-2); border:1px solid var(--border); flex:0 0 auto; }
.cmd input{ flex:1; width:100%; border:0; padding:15px 0; font-size:.98rem;
  background:transparent; color:var(--text); outline:none; }
.cmd input::placeholder{ color:var(--muted-2); }
.cmd-foot{ display:flex; gap:16px; padding:9px 16px; border-top:1px solid var(--border);
  background:var(--surface-2); font-size:.72rem; color:var(--muted-2); }
.cmd-foot kbd{ font:inherit; font-size:.68rem; padding:1px 5px; border-radius:4px;
  background:var(--surface); border:1px solid var(--border); margin-right:3px; }
.cmd-list{ max-height:min(56vh,420px); overflow:auto; padding:6px; }
.cmd-i{ display:flex; align-items:center; gap:11px; padding:9px 12px; border-radius:9px;
  cursor:pointer; font-size:.9rem; }
.cmd-i:hover,.cmd-i.sel{ background:var(--surface-2); }
.cmd-i.sel{ box-shadow:inset 2px 0 0 var(--primary); }
.cmd-i svg{ width:16px; height:16px; color:var(--muted); flex:0 0 auto; }
.cmd-i .k{ margin-left:auto; font-size:.7rem; color:var(--muted-2); }
.cmd-grp{ font-size:.63rem; font-weight:700; text-transform:uppercase; letter-spacing:.08em;
  color:var(--muted-2); padding:10px 12px 4px; }

/* ── mobile ──────────────────────────────────────────────────────────── */
/* The menu button. The SVG had no size of its own, and iPhone Safari
   collapses a size-less SVG inside a flex button to zero width - which is
   why the button was invisible on the phone. Sized explicitly now. */
.sb-burger{ display:none; align-items:center; justify-content:center; width:38px; height:38px;
  padding:0; flex:0 0 auto; background:var(--surface); color:var(--text);
  border:1px solid var(--border-strong); border-radius:10px; cursor:pointer; }
.sb-burger svg{ width:20px; height:20px; stroke-width:2; }
.sb-burger:active{ background:var(--primary-tint); color:var(--primary-600); }
@media(max-width:900px){
  .sb{ position:fixed; left:0; top:0; width:min(280px,84vw) !important; transform:translateX(-100%);
       box-shadow:var(--sh-md); transition:transform .24s cubic-bezier(.4,0,.2,1); }
  .sb.open{ transform:none; }
  .sb-burger{ display:inline-flex; }
  /* on a phone the menu is always the full menu when opened, whatever the
     desktop setting (icons-only / hidden) was */
  .sb.min .sb-name,.sb.off .sb-name{ display:block; }
  .sb.min .sb-grp,.sb.off .sb-grp{ display:block; }
  .sb.min .sb-a span,.sb.off .sb-a span{ display:inline; }
  .sb.min .sb-foot-txt{ display:inline; }
  .sb.min .sb-a{ justify-content:flex-start; padding:10px 10px; }
  .sb.min .sb-foot{ flex-direction:row; }
  .sb.min .sb-top{ justify-content:flex-start; padding:16px 14px 12px; }
  .sb-a{ padding:10px 10px; font-size:.92rem; }      /* bigger tap targets */
  .ctx-sbt{ display:none !important; }
  .main, body.sb-min .main{ margin-left:0; }
  .sb-edge{ display:none !important; }
  .sb.off{ width:var(--sidebar-w); border-right:1px solid var(--border); }
  .page{ padding:16px 14px 50px; }
  .ctx{ padding:10px 14px; }
  .sb-scrim{ position:fixed; inset:0; background:rgba(15,23,42,.4); z-index:44; }
}

@media print{
  .sb,.sb-edge,.ctx,.cmd-bg,.sb-scrim,.no-print{ display:none !important; }
  .main{ margin-left:0 !important; }
  /* paper is always white: printing from dark mode must not give light grey
     text on a white page */
  html[data-theme="dark"]{
    --bg:#fff; --surface:#fff; --surface-2:#f1f5f9; --border:#e5e7eb; --border-strong:#cbd5e1;
    --text:#0f172a; --muted:#64748b; --muted-2:#6b7a90; --primary-tint:#eef2ff;
    --shell-bg:#fff; color-scheme:light;
  }
  html[data-theme="dark"] body{ background:#fff; color:#0f172a; }
  .page{ padding:0; max-width:none; }
}
