/* ==========================================================================
   Ternah Pharmacy — Product UI theme
   Per the Ternah design kit: Hanken Grotesk (400/500/600), warm off-white
   canvas, white surfaces, one filled brand colour, amber as the only
   attention colour. Light theme only. Ternah Pharmacy's own brand colour
   is burgundy (the kit's --nav slot); other Ternah products keep navy.
   ========================================================================== */

@font-face {
  font-family: 'Hanken Grotesk';
  font-style: normal;
  font-weight: 400 600;
  font-display: swap;
  src: url('../fonts/HankenGrotesk-latin.woff2') format('woff2');
}

:root {
  color-scheme: light;

  /* ---- Ternah kit tokens ---- */
  --font: 'Hanken Grotesk', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;

  --bg: #F6F3F2;
  --surface: #FFFFFF;
  --border: #E7DFE0;
  --border-hover: #D8CDCF;
  --ink: #241A1E;
  --muted: #665A5F;
  --nav: #4A1D2E;
  --nav-active: #682B41;
  --nav-text: #E9D3DA;
  --icon-bg: #F5EBEE;
  --warn: #8A4A0E;
  --warn-bg: #FBF0E2;

  /* Not in the kit (it defines no error colour yet — an open item with
     Ternah). Reserved for genuinely blocking states only: expired stock,
     a locked subscription, form errors. Everything merely needing
     attention uses --warn. */
  --error: #9B2C2C;
  --error-bg: #F8E9E7;

  --sp-2: 8px;  --sp-3: 12px; --sp-4: 16px; --sp-5: 20px;
  --sp-6: 24px; --sp-7: 28px; --sp-10: 40px; --sp-12: 48px;

  --r-tile: 20px; --r-card: 20px; --r-photo: 24px;
  --r-input: 12px; --r-btn: 12px; --r-pill: 999px;

  --shadow-lift: 0 12px 28px rgba(36,26,30,.10);
  --shadow-frame: 0 24px 60px rgba(36,26,30,.14), 0 2px 6px rgba(36,26,30,.06);
  --focus-ring: 0 0 0 3px rgba(36,26,30,.08);

  --tui-nav-w: 256px;
  --tui-header-h: 72px;
  --ease: cubic-bezier(.22,.61,.36,1);

  --text-greeting: 600 36px/1.2 var(--font);
  --text-tile-number-lg: 600 44px/1.1 var(--font);
  --text-tile-number-sm: 600 36px/1.1 var(--font);
  --text-tile-title: 600 17px/1.3 var(--font);
  --text-body: 400 15px/1.5 var(--font);
  --text-pill: 500 14px/1 var(--font);

  /* ---- Legacy names, aliased to the kit so existing templates follow ---- */
  --card: var(--surface);
  --card-border: var(--border);
  --card-glow: transparent;
  --accent: var(--nav);
  --accent-strong: var(--nav);
  --deep-navy: var(--nav);
  --indigo: var(--nav);
  --indigo-2: var(--nav-active);
  --sidebar-bg: var(--nav);
  --sidebar-text: var(--nav-text);
  --sidebar-text-active: #FFFFFF;
  --sidebar-hover-bg: rgba(255,255,255,.06);
  --sidebar-active-bg: var(--nav-active);
  --sidebar-border: rgba(255,255,255,.08);
  --text: var(--ink);
  --text-secondary: var(--muted);
  --text-on-light: var(--ink);
  --success: var(--nav);
  --danger: var(--error);
  --warning: var(--warn);
  --expiring: var(--warn);
  --pale-indigo: var(--icon-bg);
  --space: 8px;
  --radius-lg: var(--r-card);
  --radius-md: var(--r-card);
  --radius-sm: var(--r-input);
  --motion: 200ms var(--ease);
  --input-bg: var(--surface);
}

* { box-sizing: border-box; }

html, body {
  height: 100%;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-weight: 400;
  font-size: 15px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

a { color: var(--accent); text-decoration: none; transition: color var(--motion); }
a:hover { color: var(--nav-active); }
h1, h2, h3, h4 { font-weight: 600; }
b, strong, th { font-weight: 600; }

/* ---------- Layout shell ---------- */
.app-shell {
  display: flex;
  min-height: 100vh;
}

.sidebar {
  width: var(--tui-nav-w);
  flex-shrink: 0;
  height: 100vh;
  position: sticky;
  top: 0;
  background: var(--sidebar-bg);
  border-right: 1px solid var(--sidebar-border);
  padding: calc(var(--space) * 3) calc(var(--space) * 2.5);
  display: flex;
  flex-direction: column;
  gap: calc(var(--space) * 3);
  color: var(--sidebar-text);
}
.sidebar nav {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
}
.sidebar-footer {
  border-top: 1px solid var(--sidebar-border);
  padding-top: calc(var(--space) * 2);
  flex-shrink: 0;
}
.sidebar-logout {
  width: 100%;
  background: transparent;
  border: none;
  cursor: pointer;
  font-family: inherit;
  text-align: left;
}
.sidebar-logout:hover { background: var(--sidebar-hover-bg); color: #FFFFFF; }

.sidebar-brand {
  display: flex;
  align-items: center;
  gap: 10px;
  font-weight: 600;
  font-size: 15px;
  letter-spacing: 0.01em;
  color: var(--sidebar-text-active);
}
.sidebar-brand .mark {
  width: 32px; height: 32px;
  background: rgba(255,255,255,.08);
  border-radius: 10px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 4px;
  flex-shrink: 0;
  color: white;
  font-weight: 600;
}
.sidebar-brand .mark img {
  width: 100%; height: 100%;
  object-fit: contain;
}
.sidebar-brand span {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.nav-section-label {
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--sidebar-text);
  opacity: 0.7;
  font-weight: 500;
  margin: calc(var(--space) * 2) 0 var(--space) 0;
}

.nav-link {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 14px;
  border-radius: var(--radius-sm);
  color: var(--sidebar-text);
  font-weight: 500;
  font-size: 14px;
  transition: background var(--motion), color var(--motion);
}
.nav-link:hover { background: var(--sidebar-hover-bg); color: var(--sidebar-text-active); }
.nav-link.active { background: var(--sidebar-active-bg); color: var(--sidebar-text-active); }
.nav-link svg { width: 18px; height: 18px; }

.nav-group summary {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 14px;
  border-radius: var(--radius-sm);
  color: var(--sidebar-text);
  font-weight: 500;
  font-size: 14px;
  cursor: pointer;
  list-style: none;
  transition: background var(--motion), color var(--motion);
}
.nav-group summary::-webkit-details-marker { display: none; }
.nav-group summary:hover { background: var(--sidebar-hover-bg); color: var(--sidebar-text-active); }
.nav-group summary svg { width: 18px; height: 18px; }
.nav-group summary .chevron { margin-left: auto; width: 14px; height: 14px; transition: transform var(--motion); }
.nav-group[open] summary .chevron { transform: rotate(90deg); }
.nav-group .nav-link { padding-left: 34px; }

/* ---------- Sidebar user card ---------- */
.sidebar-user-card {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: background var(--motion);
}
.sidebar-user-card:hover { background: var(--sidebar-hover-bg); }
.sidebar-user-card .avatar {
  width: 34px; height: 34px;
  flex-shrink: 0;
  border-radius: 50%;
  background: var(--nav-active);
  color: #FFFFFF;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 600;
  font-size: 14px;
}
.sidebar-user-info { flex: 1; min-width: 0; }
.sidebar-user-name {
  font-size: 14px;
  font-weight: 500;
  color: var(--sidebar-text-active);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.sidebar-user-email {
  font-size: 11px;
  color: var(--sidebar-text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.sidebar-user-card svg { width: 16px; height: 16px; color: var(--sidebar-text); flex-shrink: 0; }
.sidebar-user-menu {
  margin-top: 6px;
  border-top: 1px solid var(--sidebar-border);
  padding-top: 6px;
}
.sidebar-user-menu[hidden] { display: none; }

/* ---------- Predictive search (typeahead) ---------- */
.typeahead-wrap { position: relative; }
.typeahead-results {
  display: none;
  position: absolute;
  top: calc(100% + 4px);
  left: 0;
  right: 0;
  z-index: 20;
  background: var(--card);
  border: 1px solid var(--card-border);
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow-lift);
  max-height: 280px;
  overflow-y: auto;
}
.typeahead-item {
  padding: 10px 14px;
  font-size: 14px;
  cursor: pointer;
  border-bottom: 1px solid var(--card-border);
}
.typeahead-item:last-child { border-bottom: none; }
.typeahead-item:hover { background: var(--bg); }
.typeahead-empty {
  padding: 10px 14px;
  font-size: 13px;
  color: var(--text-secondary);
}

.main-area {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-height: var(--tui-header-h);
  padding: 0 var(--sp-10);
  border-bottom: 1px solid var(--border);
  background: rgba(246,243,242,.85);
  backdrop-filter: saturate(1.4) blur(8px);
  position: sticky;
  top: 0;
  z-index: 40;
}

.topbar-title { font-size: 20px; font-weight: 600; letter-spacing: -0.01em; }

.user-chip {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 14px;
  color: var(--text-secondary);
}
.user-chip .avatar {
  width: 32px; height: 32px; border-radius: 50%;
  background: var(--nav);
  display: flex; align-items: center; justify-content: center;
  color: white; font-weight: 600; font-size: 13px;
}

.content { padding: var(--sp-7) var(--sp-10) var(--sp-12); flex: 1; width: 100%; max-width: 1440px; }

/* ---------- Cards ---------- */
.card {
  background: var(--card);
  border: 1px solid var(--card-border);
  border-radius: var(--r-card);
  padding: var(--sp-6);
}

.card + .card { margin-top: calc(var(--space) * 2); }

/* ---------- Stat cards (Accountant Dashboard) ---------- */
.stat-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: calc(var(--space) * 2);
}
.stat-card {
  background: var(--card);
  border: 1px solid var(--card-border);
  border-radius: var(--r-tile);
  padding: var(--sp-5) var(--sp-6);
}
.stat-card-warning, .stat-card-expiring { background: var(--warn-bg); border-color: transparent; }
.stat-card-warning .stat-card-value, .stat-card-expiring .stat-card-value { color: var(--warn); }
.stat-card-danger { background: var(--error-bg); border-color: transparent; }
.stat-card-danger .stat-card-value { color: var(--error); }
.stat-card-label {
  font-size: 14px;
  color: var(--muted);
  font-weight: 500;
}
.stat-card-value { font-size: 28px; font-weight: 600; line-height: 1.15; margin: 8px 0 4px; letter-spacing: -0.01em; font-variant-numeric: tabular-nums; }
.stat-card-sub { font-size: 13px; color: var(--text-secondary); }

/* ---------- Home page module tiles ---------- */
.module-tile-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: calc(var(--space) * 2);
  margin-top: calc(var(--space) * 2);
}
.module-tile {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 10px;
  background: var(--card);
  border: 1px solid var(--card-border);
  border-radius: var(--r-tile);
  padding: var(--sp-6);
  color: var(--ink);
  transition: box-shadow var(--motion), border-color var(--motion);
}
.module-tile:hover { box-shadow: var(--shadow-lift); border-color: var(--border-hover); color: var(--ink); }
.module-tile-icon {
  width: 40px; height: 40px;
  border-radius: var(--r-pill);
  background: var(--icon-bg);
  color: var(--nav);
  display: flex; align-items: center; justify-content: center;
}
.module-tile-icon svg { width: 20px; height: 20px; }
.module-tile-title { font: var(--text-tile-title); }
.module-tile-desc { font-size: 14px; color: var(--muted); }

/* ---------- Home: greeting + figure tiles (Ternah kit dashboard tile) ---------- */
.home-greeting { margin: var(--sp-2) 0 var(--sp-7); }
.home-greeting h1 { font: var(--text-greeting); letter-spacing: -0.015em; margin: 0 0 6px; color: var(--ink); }
.home-greeting p { margin: 0; color: var(--muted); font-size: 15px; }
.home-attention { color: var(--warn); font-weight: 500; }
.home-section-label { font-size: 14px; font-weight: 500; color: var(--muted); margin: var(--sp-10) 0 0; }

.figure-tile-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: var(--sp-4);
}
.figure-tile {
  display: flex;
  flex-direction: column;
  min-height: 196px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-tile);
  padding: var(--sp-6);
  color: var(--ink);
  transition: box-shadow var(--motion), border-color var(--motion);
}
a.figure-tile:hover { box-shadow: var(--shadow-lift); border-color: var(--border-hover); color: var(--ink); }
.figure-tile-head { display: flex; align-items: center; gap: var(--sp-3); }
.figure-tile-icon {
  width: 40px; height: 40px; flex-shrink: 0;
  border-radius: var(--r-pill);
  background: var(--icon-bg);
  color: var(--nav);
  display: flex; align-items: center; justify-content: center;
}
.figure-tile-icon svg { width: 20px; height: 20px; }
.figure-tile-title { font: var(--text-tile-title); }
.figure-tile-figure {
  margin-top: auto;
  padding-top: var(--sp-6);
  color: var(--ink);
  letter-spacing: -0.02em;
  font-variant-numeric: tabular-nums;
}
.figure-tile-figure.figure-lg { font: var(--text-tile-number-lg); }
.figure-tile-figure.figure-sm { font: var(--text-tile-number-sm); }
.figure-tile-unit { margin-top: 6px; font-size: 14px; color: var(--muted); }
/* Attention: figure and icon go amber; the tile is "raised" with the soft shadow. */
.figure-tile.is-attention { box-shadow: 0 8px 22px rgba(36,26,30,.10); border-color: transparent; }
.figure-tile.is-attention .figure-tile-figure { color: var(--warn); }
.figure-tile.is-attention .figure-tile-icon { background: var(--warn-bg); color: var(--warn); }

/* Templates lay out button rows and filter rows with inline flex and no
   wrap; with kit-size controls they can outgrow the card, so let them wrap. */
div[style*="display:flex"]:has(> .btn),
div[style*="display: flex"]:has(> .btn),
form[style*="display:flex"],
div[style*="display:flex; gap:12px; align-items:end"] { flex-wrap: wrap; }
.topbar > div { flex-wrap: nowrap !important; } /* the menu button + title row never wraps */

/* Navy-friendly scrollbar for the sidebar's own scroll area */
.sidebar nav { scrollbar-width: thin; scrollbar-color: rgba(255,255,255,.18) transparent; }
.sidebar nav::-webkit-scrollbar { width: 6px; }
.sidebar nav::-webkit-scrollbar-thumb { background: rgba(255,255,255,.18); border-radius: 999px; }
.sidebar nav::-webkit-scrollbar-track { background: transparent; }

/* ---------- Home: first-run setup checklist ---------- */
.setup-card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--r-card);
  padding: var(--sp-7); margin-bottom: var(--sp-7);
}
.setup-card h2 { font-size: 22px; margin: 0 0 4px; }
.setup-card > p { margin: 0 0 var(--sp-5); color: var(--muted); }
.setup-steps { list-style: none; margin: 0; padding: 0; }
.setup-step { display: flex; align-items: center; gap: var(--sp-4); padding: var(--sp-4) 0; border-top: 1px solid var(--border); flex-wrap: wrap; }
.setup-step-mark {
  width: 32px; height: 32px; flex-shrink: 0; border-radius: var(--r-pill);
  display: flex; align-items: center; justify-content: center;
  background: var(--icon-bg); color: var(--nav); font-weight: 600;
}
.setup-step-mark svg { width: 16px; height: 16px; }
.setup-step.is-done .setup-step-mark { background: var(--nav); color: #FFFFFF; }
.setup-step.is-done .setup-step-title { color: var(--muted); text-decoration: line-through; }
.setup-step.is-locked { opacity: .55; }
.setup-step-text { flex: 1; min-width: 200px; display: flex; flex-direction: column; }
.setup-step-title { font-weight: 600; }
.setup-step-desc { font-size: 14px; color: var(--muted); }

/* ---------- Notices (banners) ---------- */
.notice {
  display: flex; align-items: flex-start; gap: var(--sp-3);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-card);
  padding: var(--sp-4) var(--sp-5);
  margin-bottom: var(--sp-4);
  color: var(--ink);
}
.notice svg { flex-shrink: 0; width: 20px; height: 20px; color: var(--nav); margin-top: 1px; }
.notice-warn { background: var(--warn-bg); border-color: transparent; color: var(--warn); }
.notice-warn svg { color: var(--warn); }
.notice-error { background: var(--error-bg); border-color: transparent; color: var(--error); }
.notice-error svg { color: var(--error); }

@media (max-width: 600px) {
  .home-greeting h1 { font-size: 28px; }
}

.two-col {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: calc(var(--space) * 2);
}
@media (max-width: 900px) {
  .two-col { grid-template-columns: 1fr; }
}

.bar-row { margin-bottom: calc(var(--space) * 1.5); }
.bar-row-label { display:flex; justify-content:space-between; font-size: 14px; margin-bottom: 4px; }
.bar-track { background: var(--bg); border-radius: 999px; height: 8px; overflow: hidden; }
.bar-fill { background: var(--nav); height: 100%; border-radius: 999px; }

.card-title {
  font: var(--text-tile-title);
  font-size: 18px;
  margin-bottom: var(--space);
}

/* A section within a form that needs more than a bare label — a bold
   title plus one line explaining what belongs in it, so a long form
   reads as a sequence of small decisions rather than one wall of
   inputs. Pair .card-desc right after .card-title; the fields follow
   in a .form-grid below. */
.card-desc {
  font-size: 14px;
  color: var(--muted);
  margin-top: -4px;
  margin-bottom: calc(var(--space) * 2);
}
.form-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: calc(var(--space) * 2) calc(var(--space) * 2.5);
}
.form-field label { margin-bottom: 6px; }
.form-field-error { color: var(--danger); font-size: 12px; margin-top: 4px; }
.form-field-help { color: var(--text-secondary); font-size: 12px; margin-top: 4px; display: block; }

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  justify-content: center;
  min-height: 44px;
  padding: 0 20px;
  border-radius: var(--r-btn);
  font-family: var(--font);
  font-weight: 500;
  font-size: 15px;
  line-height: 1;
  border: 1px solid transparent;
  cursor: pointer;
  white-space: nowrap;
  transition: background var(--motion), border-color var(--motion), color var(--motion);
}
.btn svg { width: 18px; height: 18px; }
.btn:focus-visible { outline: none; box-shadow: var(--focus-ring); }
.btn-primary, .btn-success { background: var(--nav); color: #FFFFFF; }
.btn-primary:hover, .btn-success:hover { background: var(--nav-active); color: #FFFFFF; }
.btn-outline { background: var(--surface); border-color: var(--border); color: var(--ink); }
.btn-outline:hover { border-color: var(--border-hover); color: var(--ink); }
.btn-danger { background: var(--surface); border-color: var(--border); color: var(--error); }
.btn-danger:hover { border-color: var(--error); color: var(--error); }
.btn-lg { min-height: 56px; padding: 0 30px; font-size: 17px; }

/* ---------- Badges ---------- */
.badge { display: inline-flex; align-items: center; padding: 6px 12px; border-radius: var(--r-pill); font: var(--text-pill); font-size: 13px; white-space: nowrap; }
.badge-success { background: var(--icon-bg); color: var(--nav); }
.badge-accent { background: var(--nav); color: #FFFFFF; }
.badge-warning, .badge-expiring { background: var(--warn-bg); color: var(--warn); }
.badge-danger { background: var(--error-bg); color: var(--error); }
.badge-neutral { background: transparent; color: var(--muted); box-shadow: inset 0 0 0 1px var(--border); }

/* ---------- Modals ---------- */
dialog.modal {
  background: var(--card);
  color: var(--text);
  border: 1px solid var(--card-border);
  border-radius: var(--r-card);
  padding: var(--sp-7);
  width: min(520px, 92vw);
  box-shadow: var(--shadow-frame);
}
dialog.modal::backdrop { background: rgba(36,26,30,.5); }
dialog.modal .card-title { margin-bottom: calc(var(--space) * 2); }
dialog.modal details { margin: 10px 0; }
dialog.modal summary { cursor: pointer; color: var(--accent); font-size: 13px; margin-bottom: 8px; }

/* ---------- Forms ---------- */
.form-control, input[type="text"], input[type="password"], input[type="email"],
input[type="number"], input[type="date"], select, textarea {
  background: var(--input-bg);
  border: 1px solid var(--card-border);
  color: var(--text);
  border-radius: var(--r-input);
  min-height: 44px;
  padding: 10px 14px;
  font-family: var(--font);
  font-size: 15px;
  width: 100%;
  transition: border-color var(--motion), box-shadow var(--motion);
}
textarea { min-height: 96px; }
.form-control:hover, input:hover, select:hover, textarea:hover { border-color: var(--border-hover); }
.form-control:focus, input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--border-hover);
  box-shadow: var(--focus-ring);
}
label { font-size: 14px; font-weight: 500; color: var(--ink); margin-bottom: 6px; display: block; }

/* ---------- Tables ---------- */
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 14px 12px; border-bottom: 1px solid var(--border); font-size: 15px; }
th { color: var(--muted); font-weight: 500; font-size: 14px; }
td { font-variant-numeric: tabular-nums; }
tbody tr:last-child td { border-bottom: none; }

/* ---------- Auth page (login) ---------- */
.auth-wrapper {
  min-height: 100vh;
  display: flex;
}
.auth-panel-brand {
  flex: 1;
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: var(--sp-7);
  background: var(--nav);
  color: var(--nav-text);
  padding: var(--sp-12);
}
.auth-brand-row { display: flex; align-items: center; gap: var(--sp-3); }
.auth-brand-name { color: #FFFFFF; font-weight: 600; font-size: 17px; }
.auth-panel-brand .mark {
  width: 40px; height: 40px;
  background: rgba(255,255,255,.08);
  border-radius: var(--r-input);
  display: inline-flex; align-items: center; justify-content: center;
  padding: 8px;
}
.auth-panel-brand .mark img { width: 100%; height: 100%; object-fit: contain; }
.auth-panel-brand h1 { font-size: 44px; font-weight: 600; margin: 0 0 var(--sp-3); line-height: 1.1; letter-spacing: -0.02em; color: #FFFFFF; max-width: 520px; }
.auth-panel-brand p { font-size: 17px; color: var(--nav-text); max-width: 480px; margin: 0; line-height: 1.5; }

.tour-person code, .auth-subtitle code { font-family: inherit; font-weight: 500; background: var(--icon-bg); color: var(--ink); padding: 2px 8px; border-radius: 8px; }

/* ---------- Demo copy: the bar on every page ---------- */
.demo-bar {
  display: flex; align-items: center; justify-content: center; gap: var(--sp-4);
  min-height: 36px; padding: 6px 16px;
  background: var(--warn-bg); color: var(--warn);
  font-size: 14px; text-align: center;
  position: relative; z-index: 60;
}
.demo-bar strong { font-weight: 600; }
.demo-bar a { color: var(--warn); font-weight: 500; text-decoration: underline; text-underline-offset: 3px; }
.demo-bar ~ .app-shell .sidebar { height: calc(100vh - 36px); top: 36px; }
.demo-bar ~ .app-shell .topbar { top: 0; }
@media (max-width: 480px) {
  .demo-bar { font-size: 13px; gap: 10px; padding: 6px 12px; white-space: nowrap; }
}

/* ---------- Demo copy: tour pages ---------- */
.tour-body { min-height: 100vh; }
.tour-header {
  display: flex; align-items: center; justify-content: space-between; gap: var(--sp-4);
  min-height: var(--tui-header-h); padding: 0 var(--sp-10);
  background: var(--nav); color: var(--nav-text);
}
.tour-brand { display: flex; align-items: center; gap: var(--sp-3); color: #FFFFFF; font-weight: 600; font-size: 16px; }
.tour-brand:hover { color: #FFFFFF; }
.tour-brand .mark { width: 32px; height: 32px; padding: 6px; border-radius: 10px; background: rgba(255,255,255,.08); display: inline-flex; }
.tour-brand .mark img { width: 100%; height: 100%; object-fit: contain; }
.tour-nav { display: flex; gap: var(--sp-2); flex-wrap: wrap; }
.tour-nav a { color: var(--nav-text); font-weight: 500; font-size: 15px; padding: 8px 14px; border-radius: var(--r-pill); }
.tour-nav a:hover { color: #FFFFFF; background: rgba(255,255,255,.06); }
.tour-nav a.is-active { color: #FFFFFF; background: var(--nav-active); }
.tour-main { max-width: 1200px; margin: 0 auto; padding: var(--sp-12) var(--sp-10) 80px; }

.tour-hero { max-width: 720px; margin-bottom: var(--sp-10); }
.tour-hero h1 { font-size: 48px; line-height: 1.1; letter-spacing: -0.02em; margin: 0 0 var(--sp-4); }
.tour-hero p, .tour-lead { font-size: 17px; color: var(--muted); margin: 0; }
.tour-eyebrow {
  display: inline-flex; padding: 6px 12px; margin-bottom: var(--sp-4);
  border-radius: var(--r-pill); background: var(--icon-bg); color: var(--nav); font: var(--text-pill);
}

.tour-role-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(320px, 1fr)); gap: var(--sp-4); }
.tour-role-card {
  display: flex; flex-direction: column; gap: var(--sp-2);
  padding: var(--sp-6); background: var(--surface); color: var(--ink);
  border: 1px solid var(--border); border-radius: var(--r-card);
  transition: box-shadow var(--motion), border-color var(--motion);
}
.tour-role-card:hover { box-shadow: var(--shadow-lift); border-color: var(--border-hover); color: var(--ink); }
.tour-role-card .figure-tile-icon { margin-bottom: var(--sp-3); }
.tour-role-label { font: var(--text-tile-title); font-size: 20px; }
.tour-role-summary { color: var(--muted); }
.tour-role-people { margin-top: auto; padding-top: var(--sp-4); font-size: 14px; color: var(--muted); border-top: 1px solid var(--border); }

.tour-flows-teaser {
  display: flex; justify-content: space-between; gap: var(--sp-6); flex-wrap: wrap;
  margin-top: var(--sp-10); padding: var(--sp-7); border-radius: var(--r-card);
  background: var(--nav); color: var(--nav-text);
}
.tour-flows-teaser h2 { color: #FFFFFF; font-size: 24px; margin: 0 0 6px; }
.tour-flows-teaser p { margin: 0; max-width: 420px; }
.tour-flows-teaser ul { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: var(--sp-2); }
.tour-flows-teaser a { color: #FFFFFF; font-weight: 500; }
.tour-flows-teaser a::after { content: " →"; }

.tour-back { display: inline-flex; align-items: center; gap: 6px; color: var(--muted); font-weight: 500; margin-bottom: var(--sp-6); }
.tour-back svg { width: 16px; height: 16px; }
.tour-role-layout { display: grid; grid-template-columns: minmax(0, 1fr) 400px; gap: var(--sp-10); align-items: start; }
.tour-role-layout h1 { font-size: 40px; letter-spacing: -0.02em; margin: var(--sp-4) 0 var(--sp-2); }
.tour-subhead { font-size: 15px; font-weight: 600; margin: var(--sp-7) 0 var(--sp-3); }
.tour-people { display: flex; flex-direction: column; gap: var(--sp-2); }
.tour-person {
  display: flex; align-items: center; gap: var(--sp-3); flex-wrap: wrap;
  padding: var(--sp-3) var(--sp-4); background: var(--surface);
  border: 1px solid var(--border); border-radius: var(--r-card);
}
.demo-avatar {
  width: 36px; height: 36px; flex-shrink: 0; border-radius: var(--r-pill);
  background: var(--icon-bg); color: var(--nav);
  display: flex; align-items: center; justify-content: center; font-weight: 600;
}
.tour-person-text { display: flex; flex-direction: column; min-width: 160px; flex: 1; }
.tour-person-name { font-weight: 600; }
.tour-person-meta { font-size: 14px; color: var(--muted); }
.tour-person-actions { display: flex; gap: var(--sp-2); flex-wrap: wrap; }
.tour-person-actions form { margin: 0; }
.tour-try { margin: 0; padding-left: 20px; color: var(--muted); }
.tour-try li { margin-bottom: 6px; }
.tour-signin {
  position: sticky; top: var(--sp-6);
  padding: var(--sp-7); background: var(--surface);
  border: 1px solid var(--border); border-radius: var(--r-card); box-shadow: var(--shadow-frame);
}
.tour-signin h2 { font-size: 28px; margin: 0 0 6px; }

.tour-flow { margin-top: var(--sp-10); padding: var(--sp-7); background: var(--surface); border: 1px solid var(--border); border-radius: var(--r-card); }
.tour-flow h2 { font-size: 24px; margin: 0 0 6px; }
.tour-steps { list-style: none; margin: var(--sp-6) 0 0; padding: 0; display: flex; flex-direction: column; gap: var(--sp-3); }
.tour-step { display: flex; align-items: center; gap: var(--sp-4); flex-wrap: wrap; padding: var(--sp-4) 0; border-top: 1px solid var(--border); }
.tour-step form { margin: 0 0 0 auto; }
.tour-step-num {
  width: 32px; height: 32px; flex-shrink: 0; border-radius: var(--r-pill);
  background: var(--nav); color: #FFFFFF; display: flex; align-items: center; justify-content: center; font-weight: 600;
}
.tour-step-text { flex: 1; min-width: 220px; }
.tour-contact { display: flex; flex-direction: column; gap: var(--sp-3); }

@media (max-width: 900px) {
  .tour-header { padding: 12px 16px; flex-wrap: wrap; }
  .tour-main { padding: var(--sp-7) 16px 48px; }
  .tour-hero h1 { font-size: 32px; }
  .tour-role-grid { grid-template-columns: 1fr; }
  .tour-role-layout { grid-template-columns: 1fr; }
  .tour-signin { position: static; }
  .tour-step form { margin-left: 0; }
  .demo-bar ~ .app-shell .sidebar { height: auto; top: 0; }
}

.auth-panel-form {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg);
  padding: var(--sp-10);
}
.auth-card { width: min(400px, 92vw); }
.auth-card h2 { font: var(--text-greeting); margin: 0 0 8px; letter-spacing: -0.01em; }
.auth-card .auth-subtitle { color: var(--muted); font-size: 15px; margin: 0 0 28px; }
.auth-card .btn-primary { min-height: 48px; }
.auth-footnote { text-align: center; font-size: 14px; color: var(--muted); margin-top: 20px; }

@media (max-width: 900px) {
  .auth-wrapper { flex-direction: column; }
  .auth-panel-brand { flex: none; padding: var(--sp-7) 16px; }
  .auth-panel-brand h1 { font-size: 28px; }
  .auth-panel-form { padding: var(--sp-7) 16px; }
}

/* ---------- Mobile ---------- */
.sidebar-toggle { display: none; }
.sidebar-overlay { display: none; }

@media (max-width: 900px) {
  .app-shell { display: block; } /* sidebar becomes fixed/off-canvas, no longer part of the flex row */

  .sidebar {
    position: fixed;
    top: 0; left: 0; bottom: 0;
    width: min(var(--tui-nav-w), 82vw);
    z-index: 110;
    transform: translateX(-100%);
    transition: transform var(--motion);
    box-shadow: none; /* only once open — closed, it would bleed onto the page edge */
    overflow-y: auto;
  }
  .sidebar.open { transform: translateX(0); box-shadow: 0 0 40px rgba(36,26,30,.35); }

  .sidebar-overlay {
    display: block;
    position: fixed;
    inset: 0;
    background: rgba(36,26,30,.5);
    z-index: 105;
    opacity: 0;
    pointer-events: none;
    transition: opacity var(--motion);
  }
  .sidebar-overlay.open { opacity: 1; pointer-events: auto; }

  .sidebar-toggle { display: inline-flex; }

  .main-area { min-height: 100vh; }
  .topbar { min-height: 60px; padding: 0 16px; gap: 10px; flex-wrap: nowrap; }
  .topbar > div:first-child { flex: 1; min-width: 0; }
  .topbar-title { font-size: 17px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; min-width: 0; }
  /* Square icon buttons in the bar (menu, bell) instead of full-width pills. */
  .topbar .btn { min-height: 40px; width: 40px; padding: 0 !important; flex-shrink: 0; }
  .user-chip { gap: 8px; flex-shrink: 0; }
  .user-chip span:not(.avatar) { display: none; } /* keep the avatar + buttons, drop the printed name to save space */
  .content { padding: 16px 16px 32px; }

  .card { padding: var(--sp-5) var(--sp-4); }

  /* Filter/search rows are plain flex with no explicit wrap across the
     app — none declare flex-wrap inline, so this applies cleanly. */
  .card form { flex-wrap: wrap; }

  /* A data table wider than the screen scrolls on its own axis instead
     of breaking the page layout — the standard mobile-table pattern. */
  table { display: block; overflow-x: auto; white-space: nowrap; }
}

/* ---------- Phones: tables become stacked cards ----------
   static/js/main.js copies each column's header onto its cells
   (data-label) and marks the table .is-stackable; key-value tables
   without a header row are left as they are. */
@media screen and (max-width: 640px) {
  table.is-stackable { display: block; overflow: visible; white-space: normal; }
  table.is-stackable thead { display: none; }
  table.is-stackable tbody, table.is-stackable tfoot { display: block; }
  table.is-stackable tr {
    display: block; margin-bottom: 10px; padding: 6px 14px;
    background: var(--surface); border: 1px solid var(--border); border-radius: 16px;
  }
  .card table.is-stackable tr { background: var(--bg); border-color: transparent; }
  table.is-stackable td, table.is-stackable tbody th {
    display: flex; justify-content: space-between; align-items: center; gap: 16px;
    padding: 8px 0; border: none; text-align: right; font-size: 15px;
  }
  table.is-stackable td + td { border-top: 1px solid var(--border); }
  table.is-stackable td::before {
    content: attr(data-label); flex-shrink: 0; max-width: 45%;
    color: var(--muted); font-size: 13px; font-weight: 500; text-align: left;
  }
  table.is-stackable td[data-label=""]::before { content: none; }
  table.is-stackable td[data-label=""] { justify-content: flex-end; flex-wrap: wrap; }
  table.is-stackable td > form, table.is-stackable td .btn { margin: 0; }
  table.is-stackable td[colspan] { justify-content: center; text-align: center; }

  /* Home: two compact figure tiles per row instead of one screen each. */
  .figure-tile-grid { grid-template-columns: 1fr 1fr; gap: 10px; }
  .figure-tile { min-height: 0; padding: 14px; border-radius: 16px; }
  .figure-tile-head { gap: 8px; align-items: flex-start; }
  .figure-tile-icon { width: 32px; height: 32px; }
  .figure-tile-icon svg { width: 16px; height: 16px; }
  .figure-tile-title { font-size: 14px; line-height: 1.25; }
  .figure-tile-figure { padding-top: 14px; }
  .figure-tile-figure.figure-lg { font-size: 34px; }
  .figure-tile-figure.figure-sm { font-size: 22px; }
  .figure-tile-unit { font-size: 12px; line-height: 1.35; }
  .module-tile-grid { grid-template-columns: 1fr 1fr; gap: 10px; }
  .module-tile { padding: 14px; border-radius: 16px; }
  .module-tile-desc { display: none; }
  .home-greeting { margin-bottom: 20px; }
}


/* ---------- Print letterhead ---------- */
.print-letterhead { margin-bottom: calc(var(--space) * 2); }
.print-letterhead-name { font-size: 20px; font-weight: 600; }
.print-letterhead-line { font-size: 13px; color: var(--text-secondary); margin-top: 2px; }
.print-letterhead-small { font-size: 11px; }

/* Repeats at the bottom of every printed page (Chrome/Firefox/Edge all
   render position:fixed content once per page when printing) — hidden
   everywhere else. Populated once in base.html, not per-template. */
.print-footer { display: none; }

/* ---------- Print (bills, receipts) ----------
   A real printed document, not "the webpage with the sidebar hidden":
   page margins, a compact letterhead instead of the on-screen size, a
   small repeating footer, tighter table type, and print-safe badges
   (a border as well as color, in case background graphics are off). */
@media print {
  @page {
    margin: 14mm 12mm 16mm 12mm;
  }
  .sidebar, .topbar, .no-print { display: none !important; }
  body { background: #FFFFFF !important; font-size: 12px; }
  .main-area, .content { padding: 0; margin: 0; }
  .card, .card * { color: #1B1E3A !important; }
  .card {
    background: #FFFFFF !important;
    border: none;
    box-shadow: none;
    padding: 0;
  }
  .card + .card { margin-top: calc(var(--space) * 2); }

  .print-letterhead {
    margin-bottom: calc(var(--space) * 1.5);
    padding-bottom: calc(var(--space) * 1);
    border-bottom: 1px solid #C9CEEA;
  }
  .print-letterhead-name { font-size: 14px; font-weight: 600; }
  .print-letterhead-line { font-size: 9px; margin-top: 1px; }
  .print-letterhead-small { font-size: 8px; }

  table { font-size: 11px; }
  th, td { padding: 5px 7px; }
  .card-title { font-size: 13px; }

  .badge {
    border: 1px solid currentColor;
    background: transparent !important;
    padding: 1px 8px;
  }

  .print-footer {
    display: block;
    position: fixed;
    bottom: 0; left: 0; right: 0;
    font-size: 8px;
    color: #5B6270;
    text-align: center;
    border-top: 1px solid #C9CEEA;
    padding-top: 3px;
  }
}

/* ---------- 80mm thermal receipt printing ----------
   receipt.html renders a second, stacked-layout card (#receipt-80mm)
   alongside the normal one and toggles which one prints via a
   `print-80mm` body class set by JS right before window.print(). A
   multi-column table can't stay legible at 80mm, so this is a
   fundamentally different layout, not the A4 receipt shrunk down.
   @page can't be scoped by a class selector, so its size override is
   injected as an inline <style> by that same JS rather than living
   here — this block only handles which card is visible and how it's
   styled once printing starts. */
.receipt-80mm { display: none; }

@media print {
  body.print-80mm #receipt-normal { display: none !important; }
  body.print-80mm .receipt-80mm { display: block !important; }
  body.print-80mm { font-size: 13px; }

  body.print-80mm .print-letterhead { text-align: center; }
  body.print-80mm .print-letterhead-name { font-size: 15px; }
  body.print-80mm .print-letterhead-line { font-size: 10px; }

  body.print-80mm .receipt-80mm-meta {
    margin: 8px 0;
    padding-bottom: 6px;
    border-bottom: 1px dashed #1B1E3A;
    font-size: 12px;
  }

  body.print-80mm .receipt-80mm-item {
    padding: 5px 0;
    border-bottom: 1px dashed #C9CEEA;
  }
  body.print-80mm .receipt-80mm-item:last-child { border-bottom: none; }
  body.print-80mm .receipt-80mm-item-void { text-decoration: line-through; color: #5B6270; }
  body.print-80mm .receipt-80mm-item-name { font-weight: 600; font-size: 13px; }
  body.print-80mm .receipt-80mm-item-sub { font-size: 10px; color: #5B6270; }
  body.print-80mm .receipt-80mm-item-line,
  body.print-80mm .receipt-80mm-totals-line {
    display: flex;
    justify-content: space-between;
    gap: 8px;
    font-size: 12px;
  }

  body.print-80mm .receipt-80mm-totals {
    margin-top: 8px;
    padding-top: 6px;
    border-top: 1px dashed #1B1E3A;
  }
  body.print-80mm .receipt-80mm-totals-grand { font-weight: 600; font-size: 14px; }

  body.print-80mm .print-footer { font-size: 9px; }
}

/* ---------- Implication notice ----------
   A callout used on every page that's about to trigger a sensitive,
   hard-to-reverse action (approve a refund/swap, close a branch, settle
   a claim/bill) — states in plain language what actually happens, not
   just "are you sure?". */
.implication-notice {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  background: var(--pale-indigo);
  border: 1px solid var(--card-border);
  border-radius: var(--radius-sm);
  padding: 12px 14px;
  font-size: 13px;
  color: var(--text-secondary);
  margin-bottom: 4px;
}
.implication-notice i { flex-shrink: 0; color: var(--nav); margin-top: 1px; }
.implication-notice strong { color: var(--text); }

/* ---------- Notification bell ----------
   A live badge in the topbar, not a stored log — it reflects whatever
   ReversalRequest rows actually need this user's action right now, so
   it can never drift out of sync with reality and needs no "mark as
   read" bookkeeping: it clears the moment the underlying item is
   approved/rejected/performed. */
.notif-bell-wrap { position: relative; }
.notif-bell-badge {
  position: absolute;
  top: -4px;
  right: -4px;
  background: var(--warn);
  color: #fff;
  border-radius: 999px;
  font-size: 10px;
  font-weight: 600;
  line-height: 1;
  padding: 3px 5px;
  min-width: 16px;
  text-align: center;
}
.notif-dropdown {
  position: absolute;
  top: calc(100% + 8px);
  right: 0;
  width: 340px;
  max-width: 90vw;
  max-height: 420px;
  overflow-y: auto;
  background: var(--card);
  border: 1px solid var(--card-border);
  border-radius: var(--r-card);
  box-shadow: var(--shadow-frame);
  z-index: 50;
}
.notif-dropdown-title {
  font-weight: 600;
  font-size: 13px;
  padding: 12px 14px 8px;
  color: var(--text);
}
.notif-item {
  display: block;
  padding: 10px 14px;
  border-top: 1px solid var(--card-border);
  font-size: 13px;
  color: var(--text);
}
.notif-item:hover { background: var(--pale-indigo); }
.notif-item-meta { color: var(--text-secondary); font-size: 11px; margin-top: 2px; }
.notif-empty { padding: 16px 14px; color: var(--text-secondary); font-size: 13px; }

/* ---------- Dispensing: batch picker ----------
   One row per sellable batch of the chosen drug (earliest expiry first),
   each with its own price — batches from different sources can differ. */
.batch-picker { display: flex; flex-direction: column; gap: 8px; }
.batch-option {
  display: grid; grid-template-columns: auto minmax(0, 1fr) auto auto; align-items: center; gap: 14px;
  padding: 12px 14px; margin: 0; cursor: pointer;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--r-input);
  color: var(--ink); font-size: 15px; transition: border-color var(--motion), box-shadow var(--motion);
}
.batch-option:hover { border-color: var(--border-hover); }
.batch-option:has(input:checked) { border-color: var(--nav); box-shadow: var(--focus-ring); }
.batch-option input { width: 18px; height: 18px; min-height: 0; margin: 0; accent-color: var(--nav); }
.batch-option.is-unavailable { opacity: .5; cursor: not-allowed; }
.batch-main { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.batch-name { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.batch-meta { font-size: 13px; color: var(--muted); }
.batch-qty { font-size: 14px; color: var(--muted); white-space: nowrap; }
.batch-price { font-weight: 600; font-variant-numeric: tabular-nums; white-space: nowrap; }
.batch-empty { color: var(--muted); }
@media (max-width: 640px) {
  .batch-option { grid-template-columns: auto minmax(0, 1fr) auto; }
  .batch-qty { grid-column: 2; }
}
