/* E-Code MED interface.
   Tokens first; every component below reads them, so light and dark differ only here. */

:root {
  color-scheme: light;
  --bg: #f4f4f2;
  --surface: #ffffff;
  --surface-2: #fafaf9;
  --surface-hover: #f3f3f1;
  --border: #e4e3de;
  --border-strong: #d3d2cc;
  --text: #1c1c1a;
  --text-2: #55544f;
  --muted: #6d6c66; /* >= 4.7:1 on every light surface (WCAG AA for small text) */
  --accent: #2563eb;
  --accent-hover: #1d4ed8;
  --accent-soft: #eff6ff;
  --accent-text: #1d4ed8;
  --logo-ink: #1e293b;
  --logo-blue: #2563eb;
  --signin-bg: #f5f8fe;
  --signin-glow-1: rgba(37, 99, 235, 0.11);
  --signin-glow-2: rgba(79, 70, 229, 0.09);
  --signin-shadow: 0 24px 64px rgba(15, 23, 42, 0.08), 0 2px 6px rgba(15, 23, 42, 0.04);
  --brand-gradient: linear-gradient(90deg, #2563eb, #4f46e5);
  --brand-text-gradient: linear-gradient(90deg, #2563eb, #4f46e5);
  --on-accent: #ffffff;
  --positive: #0f6b1a;
  --positive-soft: #e7f3e8;
  --negative: #b42318;
  --negative-soft: #fcebe9;
  --warning: #8a5a00;
  --warning-soft: #fdf3dc;
  --focus: 0 0 0 3px rgba(37, 99, 235, 0.28);
  --shadow-pop: 0 12px 32px rgba(17, 17, 15, 0.14), 0 2px 6px rgba(17, 17, 15, 0.06);
  --series-1: #2a78d6;
  --series-2: #eb6834;
  --grid: #e1e0d9;
  --axis: #6d6c66;

  --radius: 8px;
  --radius-sm: 6px;
  --sidebar-w: 248px;
  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

@media (prefers-color-scheme: dark) {
  :root:where(:not([data-theme="light"])) {
    color-scheme: dark;
    --bg: #111110;
    --surface: #1a1a19;
    --surface-2: #1f1f1d;
    --surface-hover: #252523;
    --border: #2c2c2a;
    --border-strong: #3a3a37;
    --text: #f0efec;
    --text-2: #c3c2b7;
    --muted: #8f8e88;
    --accent: #2563eb;
    --accent-hover: #1d4ed8;
    --accent-soft: rgba(59, 130, 246, 0.16);
    --accent-text: #60a5fa;
    --logo-ink: #f1f5f9;
    --logo-blue: #3b82f6;
    --signin-bg: var(--bg);
    --signin-glow-1: rgba(59, 130, 246, 0.16);
    --signin-glow-2: rgba(99, 102, 241, 0.13);
    --signin-shadow: 0 24px 64px rgba(0, 0, 0, 0.45);
    --brand-gradient: linear-gradient(90deg, #2563eb, #4f46e5);
    --brand-text-gradient: linear-gradient(90deg, #60a5fa, #818cf8);
    --positive: #3fb950;
    --positive-soft: rgba(12, 163, 12, 0.14);
    --negative: #f07070;
    --negative-soft: rgba(208, 59, 59, 0.16);
    --warning: #e3a33a;
    --warning-soft: rgba(250, 178, 25, 0.14);
    --focus: 0 0 0 3px rgba(57, 135, 229, 0.4);
    --shadow-pop: 0 16px 40px rgba(0, 0, 0, 0.5);
    --series-1: #3987e5;
    --series-2: #d95926;
    --grid: #2c2c2a;
    --axis: #898781;
  }
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #111110;
  --surface: #1a1a19;
  --surface-2: #1f1f1d;
  --surface-hover: #252523;
  --border: #2c2c2a;
  --border-strong: #3a3a37;
  --text: #f0efec;
  --text-2: #c3c2b7;
  --muted: #8f8e88;
  --accent: #2563eb;
  --accent-hover: #1d4ed8;
  --accent-soft: rgba(59, 130, 246, 0.16);
  --accent-text: #60a5fa;
  --logo-ink: #f1f5f9;
  --logo-blue: #3b82f6;
  --signin-bg: var(--bg);
  --signin-glow-1: rgba(59, 130, 246, 0.16);
  --signin-glow-2: rgba(99, 102, 241, 0.13);
  --signin-shadow: 0 24px 64px rgba(0, 0, 0, 0.45);
  --brand-gradient: linear-gradient(90deg, #2563eb, #4f46e5);
  --brand-text-gradient: linear-gradient(90deg, #60a5fa, #818cf8);
  --positive: #3fb950;
  --positive-soft: rgba(12, 163, 12, 0.14);
  --negative: #f07070;
  --negative-soft: rgba(208, 59, 59, 0.16);
  --warning: #e3a33a;
  --warning-soft: rgba(250, 178, 25, 0.14);
  --focus: 0 0 0 3px rgba(57, 135, 229, 0.4);
  --shadow-pop: 0 16px 40px rgba(0, 0, 0, 0.5);
  --series-1: #3987e5;
  --series-2: #d95926;
  --grid: #2c2c2a;
  --axis: #898781;
}

/* ---------- Base ---------- */

*, *::before, *::after { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 14px/1.5 var(--font);
  -webkit-font-smoothing: antialiased;
}

a { color: var(--accent-text); text-decoration: none; }
a:hover { text-decoration: underline; text-underline-offset: 2px; }

h1, h2, h3 { margin: 0; font-weight: 600; letter-spacing: -0.01em; }
h1 { font-size: 20px; line-height: 28px; }
h2 { font-size: 15px; line-height: 22px; }
h3 { font-size: 14px; line-height: 20px; }
p { margin: 0; }

:focus-visible { outline: none; box-shadow: var(--focus); border-radius: var(--radius-sm); }

.sr-only {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0;
}

.muted { color: var(--muted); }
.text-2 { color: var(--text-2); }
.num { font-variant-numeric: tabular-nums; white-space: nowrap; }
.nowrap { white-space: nowrap; }
.pos { color: var(--positive); }
.neg { color: var(--negative); }

/* ---------- App shell ---------- */

.app { display: flex; min-height: 100vh; }

.sidebar {
  position: sticky;
  top: 0;
  flex: 0 0 var(--sidebar-w);
  width: var(--sidebar-w);
  height: 100vh;
  display: flex;
  flex-direction: column;
  background: var(--surface);
  border-right: 1px solid var(--border);
  z-index: 30;
}

.brand {
  display: flex;
  align-items: center;
  gap: 8px;
  height: 64px;
  padding: 0 16px;
  border-bottom: 1px solid var(--border);
  color: var(--text);
}
.brand:hover { text-decoration: none; }
.brand-name { margin-top: 0.16em; font-weight: 700; font-size: 20px; line-height: 1; letter-spacing: 0.025em; color: var(--text); white-space: nowrap; }

.nav { flex: 1; overflow-y: auto; padding: 12px 10px 16px; }
.nav-group + .nav-group { margin-top: 18px; }
.nav-label {
  padding: 0 10px 6px;
  font-size: 11.5px;
  font-weight: 600;
  color: var(--muted);
}
.nav-link {
  display: flex;
  align-items: center;
  gap: 10px;
  height: 34px;
  padding: 0 10px;
  border-radius: var(--radius-sm);
  color: var(--text-2);
  font-weight: 500;
}
.nav-link i { width: 16px; text-align: center; font-size: 13px; color: var(--muted); }
.nav-link:hover { background: var(--surface-hover); color: var(--text); text-decoration: none; }
.nav-link.is-active { background: var(--accent-soft); color: var(--accent-text); }
.nav-link.is-active i { color: var(--accent-text); }
.nav-link span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.sidebar-foot { border-top: 1px solid var(--border); padding: 12px; }
.user-chip { display: flex; align-items: center; gap: 10px; min-width: 0; }
.user-chip .avatar { flex: none; }
.user-meta { min-width: 0; flex: 1; }
.user-name { font-weight: 600; font-size: 13px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.user-role { font-size: 12px; color: var(--muted); }
.foot-actions { display: flex; gap: 6px; margin-top: 10px; }
.foot-actions form { display: contents; }

.avatar {
  display: inline-grid;
  place-items: center;
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: var(--accent-soft);
  color: var(--accent-text);
  font-size: 12px;
  font-weight: 600;
  overflow: hidden;
}
.avatar img { width: 100%; height: 100%; object-fit: cover; }
.avatar-lg { width: 64px; height: 64px; font-size: 20px; }

.main { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.recent { display: grid; grid-template-columns: 1fr auto; gap: 6px 16px; margin-top: 18px; padding-top: 14px; border-top: 1px solid var(--border); font-size: 13px; }
.recent dt { color: var(--text-2); }
.recent dd { margin: 0; text-align: right; font-variant-numeric: tabular-nums; }

.topbar {
  display: none;
  align-items: center;
  gap: 12px;
  height: 56px;
  padding: 0 16px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 20;
}

.content { padding: 24px 28px 40px; max-width: 1480px; width: 100%; }

.page-head {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  justify-content: space-between;
  gap: 12px 24px;
  margin-bottom: 18px;
}
.page-title { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.eyebrow { font-size: 12.5px; color: var(--muted); }
.eyebrow a { color: var(--muted); }
.page-sub { color: var(--text-2); font-size: 13px; }
.page-actions { display: flex; flex-wrap: wrap; gap: 8px; }

.tabs {
  display: flex;
  gap: 4px;
  margin: -4px 0 18px;
  border-bottom: 1px solid var(--border);
  overflow-x: auto;
  scrollbar-width: none;
}
.tab {
  padding: 9px 12px;
  margin-bottom: -1px;
  border-bottom: 2px solid transparent;
  color: var(--text-2);
  font-weight: 500;
  white-space: nowrap;
}
.tab:hover { color: var(--text); text-decoration: none; }
.tab.is-active { color: var(--accent-text); border-bottom-color: var(--accent); }

.backdrop {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(10, 10, 9, 0.4);
  z-index: 25;
}

@media (max-width: 1024px) {
  .sidebar {
    position: fixed;
    left: 0;
    transform: translateX(-100%);
    transition: transform 0.2s ease;
    box-shadow: var(--shadow-pop);
  }
  body.nav-open .sidebar { transform: none; }
  body.nav-open .backdrop { display: block; }
  .topbar { display: flex; }
  .content { padding: 18px 16px 32px; }
}

/* ---------- Buttons ---------- */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  height: 36px;
  padding: 0 14px;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--text);
  font: inherit;
  font-weight: 500;
  line-height: 1;
  white-space: nowrap;
  cursor: pointer;
  transition: background-color 0.12s, border-color 0.12s, color 0.12s;
}
.btn:hover { background: var(--surface-hover); text-decoration: none; }
.btn i { font-size: 13px; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: var(--on-accent); }
.btn-primary:hover { background: var(--accent-hover); border-color: var(--accent-hover); }
.btn-danger { color: var(--negative); }
.btn-danger:hover { background: var(--negative-soft); border-color: var(--negative); }
.btn-ghost { border-color: transparent; background: transparent; color: var(--text-2); }
.btn-ghost:hover { background: var(--surface-hover); color: var(--text); }
.btn-sm { height: 30px; padding: 0 10px; font-size: 13px; }
.btn-block { width: 100%; }
.btn[disabled], .btn.is-busy { opacity: 0.6; pointer-events: none; }

.icon-btn {
  display: inline-grid;
  place-items: center;
  width: 30px;
  height: 30px;
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--muted);
  cursor: pointer;
}
.icon-btn:hover { background: var(--surface-hover); color: var(--text); text-decoration: none; }
.icon-btn i { font-size: 13px; }
.row-actions { display: flex; justify-content: flex-end; gap: 2px; }

/* ---------- Cards ---------- */

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  min-width: 0;
}
.card-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  min-height: 52px;
  padding: 12px 18px;
  border-bottom: 1px solid var(--border);
}
.card-head p { color: var(--muted); font-size: 12.5px; }
.card-body { padding: 18px; }
.card-foot { padding: 12px 18px; border-top: 1px solid var(--border); }

.grid { display: grid; gap: 16px; }
.content > .stats, .content > .grid, .content > .card, .content > .stack { margin-bottom: 16px; }
.stack { display: flex; flex-direction: column; gap: 16px; }
.content > :last-child { margin-bottom: 0; }
.grid-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.grid-main { grid-template-columns: minmax(0, 2fr) minmax(0, 1fr); }
@media (max-width: 1180px) { .grid-3 { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
@media (max-width: 900px) { .grid-2, .grid-3, .grid-main { grid-template-columns: minmax(0, 1fr); } }

/* ---------- Stat tiles ---------- */

.stats {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}
.stat { padding: 16px 18px; min-width: 0; }
.stat + .stat { border-left: 1px solid var(--border); }
.stat-label { font-size: 12.5px; color: var(--text-2); }
.stat-value { margin-top: 4px; font-size: clamp(18px, 4.6vw, 22px); line-height: 30px; font-weight: 600; letter-spacing: -0.01em; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.stat-meta { margin-top: 2px; font-size: 12.5px; color: var(--muted); }
@media (max-width: 900px) {
  .stats { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .stat:nth-child(3) { border-left: 0; }
  .stat:nth-child(n + 3) { border-top: 1px solid var(--border); }
}
@media (max-width: 340px) {
  .stats { grid-template-columns: minmax(0, 1fr); }
  .stat + .stat { border-left: 0; border-top: 1px solid var(--border); }
}

.hero-figure { font-size: 34px; line-height: 42px; font-weight: 600; letter-spacing: -0.02em; }
.split { display: grid; grid-template-columns: 1fr 1fr; gap: 1px; background: var(--border); border-top: 1px solid var(--border); }
.split > div { background: var(--surface); padding: 14px 18px; }
.key { display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-right: 6px; vertical-align: -1px; }
.key-1 { background: var(--series-1); }
.key-2 { background: var(--series-2); }

/* ---------- Forms ---------- */

.field { display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.field > label, .field-label { font-size: 12.5px; font-weight: 500; color: var(--text-2); }
.field .hint { font-size: 12px; color: var(--muted); }
.field .errorlist { margin: 0; padding: 0; list-style: none; color: var(--negative); font-size: 12.5px; }
.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px 18px; }
.form-grid .span-2 { grid-column: 1 / -1; }
@media (max-width: 640px) { .form-grid { grid-template-columns: minmax(0, 1fr); } .form-grid .span-2 { grid-column: auto; } }

.input,
.field > input:not([type="checkbox"]):not([type="radio"]):not([type="file"]),
.field > select,
.field > textarea,
.search > input,
.filters input,
.filters select {
  width: 100%;
  height: 36px;
  padding: 0 10px;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--text);
  font: inherit;
  transition: border-color 0.12s, box-shadow 0.12s;
}
.field > textarea { height: auto; min-height: 76px; padding: 8px 10px; resize: vertical; }
.field > input[type="file"] { font: inherit; font-size: 13px; color: var(--text-2); }
.input:focus, .field > input:focus, .field > select:focus, .field > textarea:focus, .search > input:focus, .filters input:focus, .filters select:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: var(--focus);
}
.field > input[readonly], .field > textarea[readonly], .input[readonly] { background: var(--surface-2); color: var(--text-2); }
::placeholder { color: var(--muted); opacity: 1; }

.search { position: relative; }
.search i { position: absolute; left: 11px; top: 50%; transform: translateY(-50%); color: var(--muted); font-size: 12px; pointer-events: none; }
.search input { padding-left: 32px !important; }

.segmented {
  display: inline-flex;
  padding: 3px;
  gap: 3px;
  border-radius: 8px;
  background: var(--surface-2);
  border: 1px solid var(--border);
}
.segmented label, .segmented button {
  position: relative;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  height: 30px;
  padding: 0 12px;
  border: 0;
  border-radius: 6px;
  background: transparent;
  color: var(--text-2);
  font: inherit;
  font-weight: 500;
  cursor: pointer;
}
.segmented label, .segmented button { white-space: nowrap; }
.segmented input { position: absolute; opacity: 0; pointer-events: none; }
@media (max-width: 560px) { .segmented label, .segmented button { padding: 0 9px; } }
.segmented label:has(input:checked), .segmented button.is-active {
  background: var(--surface);
  color: var(--text);
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.08), 0 0 0 1px var(--border);
}
.segmented label:has(input:focus-visible) { box-shadow: var(--focus); }
.segmented.is-block { display: flex; }
.segmented.is-block label { flex: 1; justify-content: center; }

.form-error {
  display: none;
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  background: var(--negative-soft);
  color: var(--negative);
  font-size: 13px;
}
.form-error.is-visible { display: block; }

/* ---------- Filters ---------- */

.filters {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  padding: 12px 14px;
  border-bottom: 1px solid var(--border);
}
.filters .search { flex: 1 1 220px; max-width: 320px; }
.filters select { width: auto; min-width: 84px; }
.filters .dates { display: flex; align-items: center; gap: 6px; }
.filters .dates input { width: 148px; }
.filters .spacer { flex: 1; }
@media (max-width: 640px) {
  .filters .search { max-width: none; flex-basis: 100%; }
  .filters .dates { flex-basis: 100%; }
  .filters .dates input { flex: 1; width: auto; min-width: 0; }
  .filters select { flex: 1; }
}

/* ---------- Tables ---------- */

.table-wrap { overflow-x: auto; }
.table { width: 100%; border-collapse: collapse; font-size: 13.5px; }
.table th, .table td { padding: 10px 14px; text-align: left; vertical-align: middle; }
.table thead th {
  position: sticky;
  top: 0;
  background: var(--surface-2);
  border-bottom: 1px solid var(--border);
  color: var(--text-2);
  font-size: 12.5px;
  font-weight: 600;
  white-space: nowrap;
  z-index: 1;
}
.table tbody td { border-bottom: 1px solid var(--border); }
.table tbody tr:last-child td { border-bottom: 0; }
.table tbody tr:hover td { background: var(--surface-2); }
.table tfoot td { border-top: 1px solid var(--border-strong); background: var(--surface-2); font-weight: 600; }
.table .r { text-align: right; }
.table .c { text-align: center; }
.table td.r, .table td.num { font-variant-numeric: tabular-nums; }
.table .actions { width: 1%; white-space: nowrap; }
.table .strong { font-weight: 500; color: var(--text); }
.table .sub { display: block; font-size: 12px; color: var(--muted); }
.table-compact th, .table-compact td { padding: 8px 14px; }
.cell-link { color: var(--text); }
.cell-link.strong, .table .cell-link.strong { font-weight: 500; }
.cell-link:hover { color: var(--accent-text); }

.empty {
  padding: 48px 20px;
  text-align: center;
  color: var(--muted);
}
.empty i { display: block; margin-bottom: 10px; font-size: 22px; color: var(--border-strong); }
.empty strong { display: block; color: var(--text-2); font-weight: 600; margin-bottom: 2px; }

/* ---------- Badges ---------- */

.badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  height: 22px;
  padding: 0 8px;
  border-radius: 11px;
  background: var(--surface-hover);
  color: var(--text-2);
  font-size: 12px;
  font-weight: 500;
  white-space: nowrap;
}
.badge i { font-size: 10px; }
.badge-in { background: var(--positive-soft); color: var(--positive); }
.badge-out { background: var(--warning-soft); color: var(--warning); }
.badge-accent { background: var(--accent-soft); color: var(--accent-text); }
.badge-neg { background: var(--negative-soft); color: var(--negative); }

/* ---------- Pagination ---------- */

.pager {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 12px 14px;
  border-top: 1px solid var(--border);
  font-size: 13px;
  color: var(--text-2);
}
.pages { display: flex; gap: 2px; }
.pages a, .pages span {
  display: inline-grid;
  place-items: center;
  min-width: 30px;
  height: 30px;
  padding: 0 6px;
  border-radius: var(--radius-sm);
  color: var(--text-2);
  font-variant-numeric: tabular-nums;
}
.pages a:hover { background: var(--surface-hover); color: var(--text); text-decoration: none; }
.pages .is-current { background: var(--accent-soft); color: var(--accent-text); font-weight: 600; }

/* ---------- Lists ---------- */

.list { margin: 0; padding: 0; list-style: none; }
.list > li { display: flex; gap: 12px; padding: 12px 18px; border-bottom: 1px solid var(--border); }
.list > li:last-child { border-bottom: 0; }
.list .grow { flex: 1; min-width: 0; }
.list .title { font-weight: 500; }
.list .meta { font-size: 12.5px; color: var(--muted); }
.list .note { margin-top: 4px; color: var(--text-2); font-size: 13px; }
.list .aside { text-align: right; white-space: nowrap; }

.dl { display: grid; grid-template-columns: minmax(140px, 220px) minmax(0, 1fr); margin: 0; }
.dl dt, .dl dd { margin: 0; padding: 11px 18px; border-bottom: 1px solid var(--border); }
.dl dt { color: var(--text-2); font-size: 13px; }
.dl dd { min-width: 0; overflow-wrap: anywhere; }
.dl > :nth-last-child(-n + 2) { border-bottom: 0; }
@media (max-width: 560px) {
  .dl { grid-template-columns: minmax(0, 1fr); }
  .dl dt { border-bottom: 0; padding-bottom: 0; }
}

.profile { display: flex; align-items: center; gap: 14px; }

/* ---------- Dialog ---------- */

dialog.modal {
  width: min(560px, calc(100vw - 24px));
  max-height: calc(100vh - 48px);
  padding: 0;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--surface);
  color: var(--text);
  box-shadow: var(--shadow-pop);
}
dialog.modal.modal-wide { width: min(880px, calc(100vw - 24px)); }
dialog.modal::backdrop { background: rgba(10, 10, 9, 0.45); }
dialog.modal[open] { display: flex; flex-direction: column; }
.modal form { display: flex; flex-direction: column; min-height: 0; flex: 1; }
.modal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
}
.modal-body { padding: 18px 20px; overflow-y: auto; display: flex; flex-direction: column; gap: 16px; }
.modal-foot {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 8px;
  padding: 14px 20px;
  border-top: 1px solid var(--border);
  background: var(--surface-2);
  border-radius: 0 0 12px 12px;
}
.modal-foot .total { margin-right: auto; }
.total-label { font-size: 12px; color: var(--muted); }
.total-value { font-size: 18px; font-weight: 600; font-variant-numeric: tabular-nums; }

details.more > summary {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  color: var(--accent-text);
  font-weight: 500;
  cursor: pointer;
  list-style: none;
}
details.more > summary::-webkit-details-marker { display: none; }
details.more > summary i { font-size: 11px; transition: transform 0.15s; }
details.more[open] > summary i { transform: rotate(90deg); }
details.more > .form-grid { margin-top: 14px; }

.suggest { position: relative; }
.suggest-list {
  position: absolute;
  left: 0;
  right: 0;
  top: calc(100% + 4px);
  max-height: 240px;
  overflow-y: auto;
  margin: 0;
  padding: 4px;
  list-style: none;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow-pop);
  z-index: 5;
}
.suggest-list[hidden] { display: none; }
.suggest-list li { padding: 8px 10px; border-radius: 4px; cursor: pointer; }
.suggest-list li .meta { font-size: 12px; color: var(--muted); }
.suggest-list li:hover, .suggest-list li.is-active { background: var(--surface-hover); }

.chip-note {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 8px 12px;
  border-radius: var(--radius-sm);
  background: var(--accent-soft);
  color: var(--accent-text);
  font-size: 13px;
}
.chip-note[hidden] { display: none; }

.picker { border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; }
.picker-head { padding: 10px; border-bottom: 1px solid var(--border); background: var(--surface-2); }
.picker-list { max-height: 300px; overflow-y: auto; }
.picker-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto 112px auto;
  align-items: center;
  gap: 10px;
  padding: 8px 10px;
  border-bottom: 1px solid var(--border);
}
.picker-row:last-child { border-bottom: 0; }
.picker-row.is-picked { background: var(--accent-soft); }
.picker-row.is-locked .picker-name { color: var(--muted); }
.picker-name { min-width: 0; }
.picker-name strong { display: block; font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.picker-name span { font-size: 12px; color: var(--muted); }
.stepper { display: inline-flex; align-items: center; border: 1px solid var(--border-strong); border-radius: var(--radius-sm); background: var(--surface); }
.stepper button { width: 28px; height: 30px; border: 0; background: transparent; color: var(--text-2); cursor: pointer; }
.stepper button:hover { color: var(--text); background: var(--surface-hover); }
.stepper button:disabled { opacity: 0.4; cursor: not-allowed; }
.stepper input { width: 52px; height: 30px; border: 0; background: transparent; color: var(--text); text-align: center; font: inherit; font-variant-numeric: tabular-nums; }
.stepper input:focus, .stepper input:focus-visible { outline: none; box-shadow: none; }
/* Money positions (cash desk): the quantity is the sum itself, so it needs room for six or more digits. */
.stepper.is-money input { width: 104px; }
/* The frame shows focus, so the number field inside does not draw a second ring. */
.stepper:focus-within { border-color: var(--accent); box-shadow: var(--focus); }
.picker-row .price { height: 32px; padding: 0 8px; border: 1px solid var(--border-strong); border-radius: var(--radius-sm); background: var(--surface); color: var(--text); font: inherit; text-align: right; font-variant-numeric: tabular-nums; width: 100%; }
.picker-row .price[readonly] { background: var(--surface-2); color: var(--text-2); }
.file-btn { position: relative; }
.file-btn input { position: absolute; inset: 0; opacity: 0; cursor: pointer; }
.file-btn.has-file { color: var(--accent-text); }
.picker-empty { padding: 20px; text-align: center; color: var(--muted); }
@media (max-width: 560px) {
  .picker-row { grid-template-columns: minmax(0, 1fr) auto; }
  .picker-row .price { grid-column: 1; }
}

.icon-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(40px, 1fr)); gap: 4px; max-height: 200px; overflow-y: auto; padding: 6px; border: 1px solid var(--border); border-radius: var(--radius-sm); }
.icon-grid label { display: grid; place-items: center; height: 38px; border-radius: 6px; color: var(--text-2); cursor: pointer; }
.icon-grid label:hover { background: var(--surface-hover); }
.icon-grid input { position: absolute; opacity: 0; pointer-events: none; }
.icon-grid label:has(input:checked) { background: var(--accent-soft); color: var(--accent-text); box-shadow: inset 0 0 0 1px var(--accent); }

/* ---------- Toast ---------- */

.toasts { position: fixed; right: 20px; bottom: 20px; display: flex; flex-direction: column; gap: 8px; z-index: 100; }
.toast {
  display: flex;
  align-items: center;
  gap: 10px;
  max-width: 360px;
  padding: 11px 14px;
  border-radius: var(--radius);
  background: var(--text);
  color: var(--bg);
  box-shadow: var(--shadow-pop);
  font-size: 13.5px;
  animation: toast-in 0.18s ease-out;
}
.toast.is-error { background: var(--negative); color: #fff; }
@keyframes toast-in { from { transform: translateY(8px); opacity: 0; } }

/* ---------- Charts ---------- */

.chart-box { position: relative; height: 300px; }
.legend { display: flex; flex-wrap: wrap; gap: 16px; font-size: 12.5px; color: var(--text-2); }
.scroll-y { max-height: 360px; overflow-y: auto; }

/* ---------- Sign-in page (same layout as E-Code ERP) ----------
   Every size is a multiple of --u, which follows the window height, so the page fits without scrolling:
   1px from ~800px of height up, proportionally smaller below. Narrow screens show only the sign-in card. */

.signin {
  --u: clamp(0.58px, 0.125vh, 1px);
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  background:
    radial-gradient(1100px 620px at 8% -12%, var(--signin-glow-1), transparent 62%),
    radial-gradient(900px 640px at 105% 108%, var(--signin-glow-2), transparent 60%),
    var(--signin-bg);
}
.signin-top, .signin-main { width: 100%; max-width: 1480px; margin: 0 auto; }
.signin-top { display: flex; align-items: center; justify-content: space-between; gap: 16px; padding: calc(24 * var(--u)) 40px 0; }
.signin-brand { display: flex; align-items: center; gap: calc(8 * var(--u)); color: var(--text); }
.signin-brand .brand-mark { width: calc(42 * var(--u)); height: calc(42 * var(--u)); }
.signin-brand .brand-name { font-size: calc(26 * var(--u)); }

.lang-pills {
  display: inline-flex;
  gap: 2px;
  padding: calc(4 * var(--u));
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--surface);
  box-shadow: 0 1px 2px rgba(15, 23, 42, 0.05);
}
.lang-pills button {
  min-width: calc(44 * var(--u));
  height: calc(32 * var(--u));
  padding: 0 calc(12 * var(--u));
  border: 0;
  border-radius: 999px;
  background: transparent;
  color: var(--text-2);
  font: inherit;
  font-size: calc(13 * var(--u));
  font-weight: 700;
  cursor: pointer;
}
.lang-pills button:hover { color: var(--text); }
.lang-pills button.is-active { background: var(--accent); color: var(--on-accent); }
.lang-pills button:focus-visible { outline: none; box-shadow: var(--focus); }

.signin-main {
  flex: 1;
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  align-items: center;
  gap: 64px;
  padding: calc(24 * var(--u)) 40px;
}
.signin-hero { max-width: 700px; padding-left: 40px; }
.signin-badge {
  display: inline-flex;
  align-items: center;
  gap: calc(8 * var(--u));
  padding: calc(7 * var(--u)) calc(16 * var(--u));
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--surface);
  color: var(--accent-text);
  font-size: calc(14 * var(--u));
  font-weight: 700;
}
.signin-title {
  margin: calc(26 * var(--u)) 0 0;
  font-size: min(calc(52 * var(--u)), 3.4vw);
  font-weight: 800;
  line-height: 1.1;
  letter-spacing: -0.025em;
  color: var(--text);
}
.signin-title .accent {
  background: var(--brand-text-gradient);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}
.signin-lead { margin: calc(20 * var(--u)) 0 0; max-width: 610px; font-size: calc(18 * var(--u)); line-height: 1.6; color: var(--text-2); }
.signin-stats { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: calc(20 * var(--u)); max-width: 616px; margin-top: calc(36 * var(--u)); }
.signin-stat {
  padding: calc(20 * var(--u)) calc(22 * var(--u)) calc(18 * var(--u));
  border: 1px solid var(--border);
  border-radius: calc(18 * var(--u));
  background: var(--surface);
  box-shadow: 0 1px 2px rgba(15, 23, 42, 0.04), 0 10px 28px rgba(15, 23, 42, 0.04);
}
.signin-stat-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  font-size: calc(13 * var(--u));
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--text-2);
}
.signin-stat-icon {
  display: grid;
  place-items: center;
  flex: none;
  width: calc(34 * var(--u));
  height: calc(34 * var(--u));
  border-radius: 50%;
  background: var(--accent-soft);
  color: var(--accent);
  font-size: calc(13 * var(--u));
}
.signin-stat-value { margin-top: calc(14 * var(--u)); font-size: calc(32 * var(--u)); font-weight: 800; letter-spacing: -0.01em; color: var(--text); }
.signin-stat-meta { margin-top: calc(4 * var(--u)); font-size: calc(13.5 * var(--u)); font-weight: 600; color: var(--accent-text); }
.signin-stat.is-green .signin-stat-icon { background: var(--positive-soft); color: var(--positive); }
.signin-stat.is-green .signin-stat-meta { color: var(--positive); }
.signin-checks {
  display: flex;
  flex-wrap: wrap;
  gap: calc(12 * var(--u)) calc(30 * var(--u));
  margin: calc(36 * var(--u)) 0 0;
  padding: 0;
  list-style: none;
  font-size: calc(15 * var(--u));
  font-weight: 600;
  color: var(--text-2);
}
.signin-checks i { margin-right: calc(8 * var(--u)); color: var(--accent); }

.signin-card {
  justify-self: center;
  width: min(calc(536 * var(--u)), 100%);
  padding: calc(42 * var(--u)) calc(46 * var(--u)) calc(30 * var(--u));
  border: 1px solid var(--border);
  border-radius: calc(26 * var(--u));
  background: var(--surface);
  box-shadow: var(--signin-shadow);
}
.signin-card-head { display: flex; flex-direction: column; align-items: center; text-align: center; }
.signin-card-head .brand-mark { width: calc(52 * var(--u)); height: calc(52 * var(--u)); }
.signin-card-head h2 { margin: calc(16 * var(--u)) 0 0; font-size: calc(30 * var(--u)); font-weight: 800; line-height: 1.2; letter-spacing: -0.01em; }
.signin-card-head p { margin: calc(4 * var(--u)) 0 0; font-size: calc(16.5 * var(--u)); color: var(--text-2); }
.signin-form { display: flex; flex-direction: column; gap: calc(20 * var(--u)); margin-top: calc(30 * var(--u)); }
.signin-field { display: flex; flex-direction: column; gap: calc(9 * var(--u)); }
.signin-label-row { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; }
.signin-label { font-size: calc(13.5 * var(--u)); font-weight: 700; letter-spacing: 0.06em; text-transform: uppercase; color: var(--text); }
.signin-link { padding: 0; border: 0; background: none; color: var(--accent-text); font: inherit; font-size: calc(14 * var(--u)); font-weight: 600; cursor: pointer; }
.signin-link:hover { text-decoration: underline; }
.signin-input {
  display: flex;
  align-items: center;
  gap: calc(12 * var(--u));
  height: calc(56 * var(--u));
  padding: 0 calc(14 * var(--u)) 0 calc(18 * var(--u));
  border: 1px solid var(--border-strong);
  border-radius: calc(16 * var(--u));
  background: var(--surface);
  transition: border-color 0.15s, box-shadow 0.15s;
}
.signin-input:focus-within { border-color: var(--accent); box-shadow: var(--focus); }
.signin-input input {
  flex: 1;
  min-width: 0;
  height: 100%;
  padding: 0;
  border: 0;
  outline: 0;
  background: transparent;
  color: var(--text);
  font: inherit;
  font-size: max(16px, calc(17 * var(--u)));
  font-weight: 600;
}
/* The frame shows focus; the bare input inside must not draw a second ring. */
.signin-input input:focus, .signin-input input:focus-visible { outline: none; box-shadow: none; }
.signin-prefix { font-size: calc(14 * var(--u)); font-weight: 600; color: var(--muted); }
.signin-input > .fas { font-size: calc(15 * var(--u)); color: var(--muted); }
.signin-eye {
  display: grid;
  place-items: center;
  flex: none;
  width: calc(34 * var(--u));
  height: calc(34 * var(--u));
  padding: 0;
  border: 0;
  border-radius: 10px;
  background: none;
  color: var(--muted);
  font-size: calc(15 * var(--u));
  cursor: pointer;
}
.signin-eye:hover { color: var(--text); }
.signin-eye:focus-visible { outline: none; box-shadow: var(--focus); }
.signin-hint { margin: 0; padding: calc(9 * var(--u)) 14px; border-radius: 12px; background: var(--accent-soft); color: var(--accent-text); font-size: calc(13.5 * var(--u)); line-height: 1.5; }
.signin-error { padding: calc(11 * var(--u)) 14px; border-radius: 12px; background: var(--negative-soft); color: var(--negative); font-size: calc(14 * var(--u)); font-weight: 600; }
.signin-submit {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  height: calc(58 * var(--u));
  margin-top: calc(4 * var(--u));
  border: 0;
  border-radius: calc(16 * var(--u));
  background: var(--brand-gradient);
  color: #fff;
  font: inherit;
  font-size: calc(17 * var(--u));
  font-weight: 700;
  cursor: pointer;
  box-shadow: 0 12px 28px rgba(37, 99, 235, 0.3);
  transition: filter 0.15s, transform 0.15s;
}
.signin-submit:hover { filter: brightness(1.07); }
.signin-submit:active { transform: translateY(1px); }
.signin-submit:focus-visible { outline: none; box-shadow: var(--focus), 0 12px 28px rgba(37, 99, 235, 0.3); }
.signin-card-foot {
  margin: calc(24 * var(--u)) 0 0;
  padding-top: calc(20 * var(--u));
  border-top: 1px solid var(--border);
  text-align: center;
  font-size: calc(15 * var(--u));
  line-height: 1.55;
  color: var(--text-2);
}
.signin-card-foot a { font-weight: 700; color: var(--accent-text); white-space: nowrap; }
.signin-foot { padding: 0 24px calc(14 * var(--u)); text-align: center; font-size: calc(13.5 * var(--u)); color: var(--muted); }

@media (max-width: 1100px) {
  .signin-main { grid-template-columns: minmax(0, 1fr); max-width: 600px; }
  .signin-hero { display: none; }
}
@media (max-width: 560px) {
  .signin-top { padding: 16px 16px 0; }
  .signin-brand .brand-name { font-size: 20px; }
  .lang-pills button { min-width: 38px; padding: 0 9px; }
  .signin-main { padding: calc(16 * var(--u)) 16px; }
  .signin-card { padding: calc(30 * var(--u)) 20px calc(22 * var(--u)); border-radius: 22px; }
}

/* ---------- Error pages ---------- */

.error-page { min-height: 100vh; display: grid; place-items: center; padding: 24px; text-align: center; }
.error-brand { display: inline-flex; align-items: center; gap: 8px; margin-bottom: 28px; color: var(--text); }
.error-brand:hover { text-decoration: none; }
.error-brand .brand-name { font-size: 22px; }
.error-code { font-size: 13px; font-weight: 600; color: var(--accent-text); margin-bottom: 8px; }
.error-page h1 { margin-bottom: 8px; }
.error-page p { color: var(--text-2); margin-bottom: 20px; }

@media print {
  .sidebar, .topbar, .page-actions, .filters, .pager, .row-actions, .tabs { display: none !important; }
  .content { padding: 0; max-width: none; }
  .card { border: 0; }
  body { background: #fff; }
}

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; animation: none !important; }
}

fieldset.bare { border: 0; padding: 0; margin: 0; min-width: 0; }
fieldset.bare:disabled { opacity: 0.7; }
.brand-mark { display: block; flex: none; overflow: visible; }

/* E-Code logo: same mark and wave as E-Code ERP */
.logo-bar1 { stroke: var(--logo-ink); }
.logo-bar2, .logo-bar3 { stroke: var(--logo-blue); }
.logo-bar { animation: logoWave 1.6s ease-in-out infinite; }
.logo-bar2 { animation-delay: 250ms; }
.logo-bar3 { animation-delay: 500ms; }
@keyframes logoWave {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-4px); }
}
.brand-inline { display: flex; align-items: center; gap: 8px; color: var(--text); }
.brand-inline .brand-name { font-size: 18px; }
.brand-inline:hover { text-decoration: none; }
.card-head .legend { margin-top: 4px; }
.stat-value-sm { font-size: 18px; line-height: 26px; }
.cell-icon { width: 18px; margin-right: 6px; text-align: center; color: var(--muted); }
.eyebrow { display: block; }
.eyebrow::first-letter { text-transform: uppercase; }
.form-error[data-top] { margin-bottom: 16px; }
.form-actions { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.form-actions .spacer { flex: 1; }
.field .profile { margin-bottom: 4px; }
.field input[type="checkbox"] { width: 16px; height: 16px; vertical-align: -3px; margin: 0 6px 0 0; accent-color: var(--accent); }
.card-fill { display: flex; flex-direction: column; }
.card-fill > .card-body { flex: 1; }

/* ---------- Language switcher ---------- */

.lang-switch { position: relative; display: flex; align-items: center; margin-top: 10px; }
.lang-switch > i { position: absolute; left: 10px; font-size: 12px; color: var(--muted); pointer-events: none; }
.lang-switch select {
  width: 100%;
  height: 30px;
  padding: 0 8px 0 28px;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--text);
  font: inherit;
  font-size: 13px;
  cursor: pointer;
}
.lang-switch select:focus { outline: none; border-color: var(--accent); box-shadow: var(--focus); }

/* ---------- Notices (messages, subscription state) ---------- */

.notice {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 16px;
  padding: 10px 14px;
  border: 1px solid transparent;
  border-radius: var(--radius);
  background: var(--accent-soft);
  color: var(--accent-text);
  font-size: 13.5px;
}
.notice > span { flex: 1; min-width: 0; }
.notice .btn { flex: none; }
.notice-success { background: var(--positive-soft); color: var(--positive); }
.notice-warning { background: var(--warning-soft); color: var(--warning); }
.notice-danger { background: var(--negative-soft); color: var(--negative); }

.nav-clinic { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--text-2); }

/* ---------- Platform panel and subscription ---------- */

/* Label and figure side by side even on phones (status counts on the platform overview). */
.dl.dl-inline { grid-template-columns: minmax(0, 1fr) auto; }
@media (max-width: 560px) {
  .dl.dl-inline dt { border-bottom: 1px solid var(--border); padding-bottom: 11px; }
  .dl.dl-inline > :nth-last-child(-n + 2) { border-bottom: 0; }
}

.meter { display: flex; flex-direction: column; gap: 6px; }
.meter-track { height: 6px; border-radius: 3px; background: var(--surface-hover); overflow: hidden; }
.meter-fill { height: 100%; border-radius: 3px; background: var(--accent); }
.meter-fill.is-full { background: var(--warning); }

.bars { display: grid; grid-template-columns: repeat(12, minmax(0, 1fr)); gap: 8px; align-items: end; height: 180px; }
.bar { display: flex; flex-direction: column; justify-content: flex-end; align-items: center; gap: 6px; height: 100%; min-width: 0; }
.bar-fill { width: 100%; max-width: 34px; min-height: 2px; border-radius: 4px 4px 0 0; background: var(--series-1); }
.bar-label { font-size: 11px; color: var(--muted); white-space: nowrap; }

.plans { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 12px; }
.plan { position: relative; display: flex; flex-direction: column; gap: 6px; padding: 14px; border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface); cursor: pointer; }
.plan:hover { border-color: var(--border-strong); }
.plan input { position: absolute; opacity: 0; pointer-events: none; }
.plan:has(input:checked) { border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent); }
.plan:has(input:focus-visible) { box-shadow: var(--focus); }
.plan:has(input:disabled) { opacity: 0.55; cursor: not-allowed; }
.plan-name { font-weight: 600; }
.plan-price { font-size: 20px; font-weight: 600; }
.plan-meta { font-size: 12.5px; color: var(--text-2); }

.plans + .field { margin-top: 18px; max-width: 260px; }
.pay-actions { display: flex; flex-wrap: wrap; gap: 8px; }
.inline-form { display: inline; }
.urls { margin: 0; padding: 0; list-style: none; font-family: ui-monospace, SFMono-Regular, Consolas, monospace; font-size: 12.5px; overflow-wrap: anywhere; }
@media (max-width: 560px) {
  .bars { gap: 4px; }
  .bar-label { font-size: 10px; }
}
