/* ==========================================================================
   Amino.ph — Visual System (Edition 01) → P&L section design tokens.
   Token values lifted verbatim from the brand Guidebook. Cream canvas, ink
   type, 44px max radius, Helotypo display + JUST Sans everywhere else, one
   category gradient used sparingly as accent.
   ========================================================================== */

@font-face {
  font-family: "JUST Sans";
  src: url("fonts/JUSTSans-400.woff2") format("woff2"),
    url("fonts/JUSTSans-400.woff") format("woff");
  font-weight: 400;
  font-style: normal;
  font-display: swap;
}
@font-face {
  font-family: "JUST Sans";
  src: url("fonts/JUSTSans-800.woff2") format("woff2"),
    url("fonts/JUSTSans-800.woff") format("woff");
  font-weight: 600 800;
  font-style: normal;
  font-display: swap;
}
@font-face {
  font-family: "Helotypo";
  src: url("fonts/Helotypo-400_900.otf") format("opentype");
  font-weight: 400 900;
  font-style: normal;
  font-display: swap;
}

:root {
  /* Neutrals */
  --amino-ink: #0B0B0C;
  --amino-paper: #FFFFFF;
  --amino-cream: #FAF8F3;
  --amino-n-50: #F6F6F4;
  --amino-n-100: #ECECE8;
  --amino-n-200: #DDDDD7;
  --amino-n-300: #C4C4BD;
  --amino-n-400: #9B9B94;
  --amino-n-500: #74746E;
  --amino-n-600: #54544F;
  --amino-n-700: #3A3A37;
  --amino-n-800: #242422;
  --amino-n-900: #131312;

  /* Category gradients (use one, sparingly) + signature spectrum */
  --amino-grad-cosmetic: linear-gradient(120deg, #3D6BF2 0%, #7A4DF5 55%, #F05E82 100%);
  --amino-grad-weight: linear-gradient(120deg, #F1287E 0%, #F8702E 55%, #FBC02D 100%);
  --amino-grad-energy: linear-gradient(120deg, #14936A 0%, #46B84A 55%, #C2F03A 100%);
  --amino-grad-anabolic: linear-gradient(120deg, #F89A1E 0%, #F7591E 55%, #F0309A 100%);
  --amino-grad-spectrum: linear-gradient(110deg, #5B5BF0 0%, #F0307E 38%, #F7591E 68%, #FBC02D 100%);

  /* Semantic */
  --amino-bg: var(--amino-cream);
  --amino-surface: var(--amino-paper);
  --amino-surface-sunk: var(--amino-n-50);
  --amino-border: var(--amino-n-200);
  --amino-text: var(--amino-ink);
  --amino-text-muted: var(--amino-n-500);
  --amino-text-invert: var(--amino-paper);
  --amino-success: #1FA86A;
  --amino-warning: #F8902E;
  --amino-danger: #E5342B;

  /* Type */
  --amino-font-display: "Helotypo", "JUST Sans", system-ui, sans-serif;
  --amino-font-sans: "JUST Sans", system-ui, -apple-system, "Segoe UI", sans-serif;
  --amino-text-sm: 14px;
  --amino-text-base: 16px;
  --amino-text-lg: 18px;
  --amino-text-xl: 22px;
  --amino-text-2xl: 28px;
  --amino-text-3xl: 36px;
  --amino-text-4xl: 48px;
  --amino-text-5xl: 64px;
  --amino-leading-tight: 1.05;
  --amino-leading-snug: 1.2;
  --amino-leading-normal: 1.5;
  --amino-tracking-tight: -0.02em;
  --amino-tracking-wide: 0.08em;

  /* Spacing */
  --amino-space-2: 8px;
  --amino-space-3: 12px;
  --amino-space-4: 16px;
  --amino-space-5: 24px;
  --amino-space-6: 32px;
  --amino-space-7: 48px;
  --amino-space-8: 64px;
  --amino-space-9: 96px;

  /* Radius (brand is very rounded) */
  --amino-radius-sm: 8px;
  --amino-radius-md: 14px;
  --amino-radius-lg: 22px;
  --amino-radius-xl: 32px;
  --amino-radius-2xl: 44px;
  --amino-radius-pill: 999px;

  /* Shadows */
  --amino-shadow-md: 0 4px 14px rgba(11, 11, 12, 0.08);
  --amino-shadow-lg: 0 16px 40px rgba(11, 11, 12, 0.12);
  --amino-shadow-focus: 0 0 0 4px rgba(91, 91, 240, 0.35);
}

* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

html, body {
  background: var(--amino-bg);
  color: var(--amino-text);
  font-family: var(--amino-font-sans);
  font-size: var(--amino-text-base);
  line-height: var(--amino-leading-normal);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

h1, h2, h3 {
  font-weight: 800;
  letter-spacing: var(--amino-tracking-tight);
  line-height: var(--amino-leading-snug);
}

/* Display headline — Helotypo, the one big voice per view */
.amino-display {
  font-family: var(--amino-font-display);
  font-weight: 700;
  letter-spacing: var(--amino-tracking-tight);
  line-height: var(--amino-leading-tight);
}

a { color: inherit; }
button { font-family: inherit; }

/* ---------- Layout shell ---------- */
.app {
  display: grid;
  grid-template-columns: 248px 1fr;
  min-height: 100vh;
}

.sidebar {
  background: var(--amino-cream);
  border-right: 1px solid var(--amino-border);
  padding: var(--amino-space-6) var(--amino-space-5);
  display: flex;
  flex-direction: column;
  gap: var(--amino-space-6);
  position: sticky;
  top: 0;
  height: 100vh;
}

.brand {
  display: flex;
  align-items: center;
  gap: var(--amino-space-3);
}
.brand .brand-mark {
  height: 30px;
  width: auto;
  display: block;
}
.brand .brand-word {
  height: 17px;
  width: auto;
  display: block;
}

.nav { display: flex; flex-direction: column; gap: 2px; }
.nav .group-label {
  font-size: 11px;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: var(--amino-tracking-wide);
  color: var(--amino-n-400);
  padding: var(--amino-space-4) var(--amino-space-3) var(--amino-space-2);
}
.nav button {
  appearance: none;
  border: 0;
  background: transparent;
  text-align: left;
  padding: 10px var(--amino-space-4);
  border-radius: var(--amino-radius-md);
  color: var(--amino-text);
  font-size: var(--amino-text-sm);
  font-weight: 600;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 10px;
  transition: background 0.12s ease;
}
.nav button:hover { background: var(--amino-n-100); }
.nav button.active { background: var(--amino-ink); color: var(--amino-text-invert); }
.nav button .dot {
  width: 8px;
  height: 8px;
  border-radius: var(--amino-radius-pill);
  background: var(--amino-n-300);
}
.nav button.active .dot { background: var(--amino-paper); }

/* ---------- Auth: login screen + account footer ---------- */
.login-wrap {
  min-height: 100vh;
  display: grid;
  place-items: center;
  background: var(--amino-bg);
  padding: var(--amino-space-6);
}
.login-card {
  width: 100%;
  max-width: 380px;
  background: var(--amino-surface);
  border: 1px solid var(--amino-border);
  border-radius: var(--amino-radius-lg);
  padding: var(--amino-space-7);
  box-shadow: 0 12px 40px rgba(11, 11, 12, 0.08);
  display: flex;
  flex-direction: column;
}
.login-card .brand { margin-bottom: var(--amino-space-6); }
.login-title {
  font-family: var(--amino-font-display);
  font-weight: 800;
  font-size: var(--amino-text-xl);
  text-align: center;
}
.login-sub {
  color: var(--amino-text-muted);
  font-size: var(--amino-text-sm);
  text-align: center;
  margin: 6px 0 var(--amino-space-6);
}
.login-label {
  font-size: 12px;
  font-weight: 700;
  color: var(--amino-text-muted);
  margin-bottom: 6px;
}
.login-input {
  padding: 11px var(--amino-space-4);
  border: 1px solid var(--amino-border);
  border-radius: var(--amino-radius-md);
  background: var(--amino-surface);
  font-size: var(--amino-text-sm);
  color: var(--amino-text);
  margin-bottom: var(--amino-space-4);
}
.login-input:focus { outline: none; border-color: var(--amino-ink); }
.login-input:disabled { background: var(--amino-n-50); color: var(--amino-text-muted); }
.login-error {
  background: rgba(224, 49, 49, 0.08);
  border: 1px solid rgba(224, 49, 49, 0.35);
  color: var(--amino-danger);
  border-radius: var(--amino-radius-md);
  padding: 9px var(--amino-space-4);
  font-size: 13px;
  font-weight: 600;
  margin-bottom: var(--amino-space-4);
}
.login-btn { width: 100%; justify-content: center; }
.login-back {
  margin-top: var(--amino-space-3);
  align-self: center;
  background: transparent;
}

.account {
  margin-top: var(--amino-space-5);
  padding-top: var(--amino-space-4);
  border-top: 1px solid var(--amino-border);
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.account-email {
  font-size: 12px;
  font-weight: 600;
  color: var(--amino-text);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.sidebar .foot {
  margin-top: auto;
  font-size: 12px;
  color: var(--amino-text-muted);
  line-height: 1.5;
}

.main {
  padding: var(--amino-space-7) var(--amino-space-8);
  max-width: 1180px;
}

/* ---------- View header ---------- */
.view-head {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: var(--amino-space-5);
  margin-bottom: var(--amino-space-7);
}
.view-head .eyebrow {
  font-size: 12px;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: var(--amino-tracking-wide);
  color: var(--amino-text-muted);
  margin-bottom: var(--amino-space-3);
}
.view-head h1 { font-size: var(--amino-text-4xl); }
.view-head .lede {
  color: var(--amino-text-muted);
  max-width: 52ch;
  margin-top: var(--amino-space-3);
}

/* ---------- Cards ---------- */
.card {
  background: var(--amino-surface);
  border: 1px solid var(--amino-border);
  border-radius: var(--amino-radius-2xl);
  padding: var(--amino-space-6);
  box-shadow: var(--amino-shadow-md);
}
.card.sunk { background: var(--amino-surface-sunk); box-shadow: none; }

.grid { display: grid; gap: var(--amino-space-5); }
.grid.cols-2 { grid-template-columns: repeat(2, 1fr); }
.grid.cols-3 { grid-template-columns: repeat(3, 1fr); }
.grid.cols-4 { grid-template-columns: repeat(4, 1fr); }

/* ---------- Stat (KPI) ---------- */
.stat .label {
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: var(--amino-tracking-wide);
  color: var(--amino-text-muted);
}
.stat .value {
  font-family: var(--amino-font-display);
  font-weight: 700;
  font-size: var(--amino-text-3xl);
  letter-spacing: var(--amino-tracking-tight);
  margin-top: var(--amino-space-3);
  font-variant-numeric: tabular-nums;
}
.stat .sub { font-size: var(--amino-text-sm); color: var(--amino-text-muted); margin-top: 6px; }
.stat .accent-bar {
  height: 8px;
  border-radius: var(--amino-radius-pill);
  margin-bottom: var(--amino-space-5);
  width: 64px;
}

/* ---------- Pills / tags ---------- */
.pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 5px 12px;
  border-radius: var(--amino-radius-pill);
  font-size: 12px;
  font-weight: 700;
  background: var(--amino-n-100);
  color: var(--amino-text);
}
.pill .dot { width: 7px; height: 7px; border-radius: var(--amino-radius-pill); }
.pill.ok { background: rgba(31, 168, 106, 0.12); color: #137a4c; }
.pill.warn { background: rgba(248, 144, 46, 0.15); color: #9a5410; }
.pill.muted { background: var(--amino-n-100); color: var(--amino-text-muted); }

/* ---------- Statement table ---------- */
.statement { width: 100%; border-collapse: collapse; font-variant-numeric: tabular-nums; }
.statement th, .statement td {
  padding: 11px var(--amino-space-4);
  text-align: right;
  white-space: nowrap;
}
.statement th:first-child, .statement td:first-child {
  text-align: left;
  white-space: normal;
}
.statement thead th {
  font-size: 12px;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: var(--amino-tracking-wide);
  color: var(--amino-text-muted);
  border-bottom: 1px solid var(--amino-border);
}
.statement tbody td { font-size: var(--amino-text-sm); border-bottom: 1px solid var(--amino-n-100); }
.statement tbody tr.section td { padding-top: var(--amino-space-5); }
.statement tbody tr.total td {
  font-weight: 800;
  border-top: 1.5px solid var(--amino-ink);
  border-bottom: 1.5px solid var(--amino-ink);
}
.statement tbody tr.grand td {
  font-weight: 800;
  font-size: var(--amino-text-base);
  background: var(--amino-n-50);
}
.statement tbody tr.muted td { color: var(--amino-text-muted); }
.statement td.zero { color: var(--amino-n-300); }
.statement td.neg { color: var(--amino-danger); }
.statement .rowlabel .hint { display: block; font-size: 11px; color: var(--amino-text-muted); font-weight: 400; }

/* ---------- Inputs (tabs) ---------- */
.field { display: flex; flex-direction: column; gap: 6px; }
.field label {
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: var(--amino-tracking-wide);
  color: var(--amino-text-muted);
}
input, select {
  font-family: inherit;
  font-size: var(--amino-text-sm);
  padding: 10px var(--amino-space-4);
  border: 1px solid var(--amino-border);
  border-radius: var(--amino-radius-md);
  background: var(--amino-paper);
  color: var(--amino-text);
  outline: none;
}
input:focus, select:focus { box-shadow: var(--amino-shadow-focus); border-color: var(--amino-n-400); }
input.invalid, select.invalid { border-color: var(--amino-danger); }

.btn {
  appearance: none;
  border: 1px solid var(--amino-ink);
  background: var(--amino-ink);
  color: var(--amino-paper);
  font-weight: 700;
  font-size: var(--amino-text-sm);
  padding: 10px var(--amino-space-5);
  border-radius: var(--amino-radius-pill);
  cursor: pointer;
}
.btn.ghost { background: transparent; color: var(--amino-ink); }
.btn.sm { padding: 6px 14px; font-size: 13px; }
.btn:hover { opacity: 0.9; }

.icon-btn {
  appearance: none;
  border: 1px solid var(--amino-border);
  background: var(--amino-paper);
  width: 32px; height: 32px;
  border-radius: var(--amino-radius-pill);
  cursor: pointer;
  color: var(--amino-text-muted);
  font-size: 15px;
  line-height: 1;
}
.icon-btn:hover { color: var(--amino-danger); border-color: var(--amino-danger); }

.muted { color: var(--amino-text-muted); }
.right { text-align: right; }
.spacer { flex: 1; }
.row { display: flex; align-items: center; gap: var(--amino-space-4); }

/* Audit flag banner */
.flag {
  display: flex;
  align-items: center;
  gap: var(--amino-space-3);
  padding: var(--amino-space-4) var(--amino-space-5);
  border-radius: var(--amino-radius-lg);
  background: rgba(248, 144, 46, 0.12);
  border: 1px solid rgba(248, 144, 46, 0.4);
  font-size: var(--amino-text-sm);
  font-weight: 600;
}
.flag .pesos { font-weight: 800; }
.flag.info { background: var(--amino-n-50); border: 1px solid var(--amino-border); }

/* ---------- Record tables (read-only lists in input tabs) ---------- */
.records { width: 100%; border-collapse: collapse; table-layout: auto; }
.records th,
.records td {
  padding: 12px var(--amino-space-4);
  text-align: left;
  font-size: var(--amino-text-sm);
  border-bottom: 1px solid var(--amino-n-100);
  vertical-align: middle;
}
.records thead th {
  font-size: 12px;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: var(--amino-tracking-wide);
  color: var(--amino-text-muted);
  border-bottom: 1px solid var(--amino-border);
  white-space: nowrap;
}
.records td.num,
.records th.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.records td.vendor { color: var(--amino-text); }
.records td.dim { color: var(--amino-text-muted); white-space: nowrap; }
.records td.actions,
.records th.actions { text-align: right; white-space: nowrap; width: 1%; }
.records tbody tr:hover td { background: var(--amino-n-50); }
.records .empty td {
  text-align: center;
  color: var(--amino-text-muted);
  padding: var(--amino-space-7) var(--amino-space-4);
}
.records td.badcat { color: var(--amino-danger); font-weight: 700; }

.actions-cell { display: inline-flex; gap: 6px; justify-content: flex-end; }

/* ---------- Per-vial COGS reference (COGS tab) ---------- */
.pervial-card { margin-bottom: var(--amino-space-6); }
.pervial {
  display: flex;
  align-items: center;
  gap: var(--amino-space-7);
  flex-wrap: wrap;
}
.pervial-main { flex: 1 1 260px; min-width: 240px; }
.pervial-label {
  font-size: 12px;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: var(--amino-tracking-wide);
  color: var(--amino-text-muted);
  margin-bottom: var(--amino-space-2);
}
.pervial-value {
  font-family: var(--amino-font-display);
  font-weight: 800;
  font-size: 40px;
  line-height: 1;
  letter-spacing: var(--amino-tracking-tight);
  font-variant-numeric: tabular-nums;
}
.pervial-sub {
  margin-top: var(--amino-space-3);
  font-size: 13px;
  color: var(--amino-text-muted);
  max-width: 46ch;
}
.pervial-breakdown {
  display: flex;
  flex-direction: column;
  gap: 2px;
  flex: 1 1 240px;
  min-width: 220px;
}
.pervial-breakdown-head {
  font-size: 11px;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: var(--amino-tracking-wide);
  color: var(--amino-n-400);
  margin-bottom: var(--amino-space-2);
}
.pervial-row {
  display: flex;
  align-items: center;
  gap: var(--amino-space-3);
  padding: 7px 0;
  border-bottom: 1px solid var(--amino-n-100);
  font-size: var(--amino-text-sm);
}
.pervial-row:last-child { border-bottom: 0; }
.pervial-row.toggle { cursor: pointer; }
.pervial-row input[type="checkbox"] {
  width: 15px;
  height: 15px;
  accent-color: var(--amino-ink);
  cursor: pointer;
  margin: 0;
}
.pervial-cat { color: var(--amino-text); font-weight: 600; }
.pervial-rate {
  font-variant-numeric: tabular-nums;
  font-weight: 700;
  white-space: nowrap;
  margin-left: auto;
}
.pervial-row.off .pervial-cat { color: var(--amino-text-muted); }
.pervial-row.off .pervial-rate {
  color: var(--amino-text-muted);
  text-decoration: line-through;
  font-weight: 600;
}

/* ---------- Ledger filter / sort toolbar ---------- */
.ledger-toolbar {
  display: flex;
  align-items: center;
  gap: var(--amino-space-3);
  margin-bottom: var(--amino-space-4);
  flex-wrap: wrap;
}
.ledger-search {
  flex: 1 1 240px;
  min-width: 180px;
  padding: 9px var(--amino-space-4);
  border: 1px solid var(--amino-border);
  border-radius: var(--amino-radius-md);
  background: var(--amino-surface);
  font-size: var(--amino-text-sm);
  color: var(--amino-text);
}
.ledger-search:focus,
.ledger-filter:focus {
  outline: none;
  border-color: var(--amino-ink);
}
.ledger-filter {
  padding: 9px var(--amino-space-4);
  border: 1px solid var(--amino-border);
  border-radius: var(--amino-radius-md);
  background: var(--amino-surface);
  font-size: var(--amino-text-sm);
  color: var(--amino-text);
  cursor: pointer;
}
.ledger-count {
  font-size: 12px;
  white-space: nowrap;
  margin-left: auto;
}

/* Sortable column headers */
.records th.sortable {
  cursor: pointer;
  user-select: none;
  transition: color 0.12s ease;
}
.records th.sortable:hover { color: var(--amino-text); }
.records th.sortable.active { color: var(--amino-text); }
.records th.sortable .sort-caret {
  margin-left: 4px;
  font-size: 10px;
  opacity: 0.35;
}
.records th.sortable.active .sort-caret { opacity: 0.9; }

/* ---------- Modal ---------- */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(11, 11, 12, 0.42);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: var(--amino-space-6);
  z-index: 100;
}
.modal {
  background: var(--amino-surface);
  border-radius: var(--amino-radius-2xl);
  box-shadow: var(--amino-shadow-lg);
  width: 100%;
  max-width: 520px;
  max-height: 90vh;
  overflow: auto;
}
.modal-head { padding: var(--amino-space-6) var(--amino-space-6) 0; }
.modal-head h3 { font-size: var(--amino-text-xl); }
.modal-head .sub { color: var(--amino-text-muted); font-size: var(--amino-text-sm); margin-top: 4px; }
.modal-body { padding: var(--amino-space-5) var(--amino-space-6); }
.modal-foot {
  padding: var(--amino-space-4) var(--amino-space-6);
  display: flex;
  justify-content: flex-end;
  gap: var(--amino-space-3);
  border-top: 1px solid var(--amino-border);
  background: var(--amino-n-50);
  position: sticky;
  bottom: 0;
}
.modal input,
.modal select { width: 100%; }

.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: var(--amino-space-4); }
.form-grid .full { grid-column: 1 / -1; }

/* ---------- Switch ---------- */
.switch { display: inline-flex; align-items: center; gap: 10px; cursor: pointer; font-size: 13px; font-weight: 600; }
.switch input { display: none; }
.switch .track {
  width: 38px;
  height: 22px;
  border-radius: var(--amino-radius-pill);
  background: var(--amino-n-300);
  position: relative;
  transition: background 0.15s ease;
  flex: none;
}
.switch .track::after {
  content: "";
  position: absolute;
  top: 2px;
  left: 2px;
  width: 18px;
  height: 18px;
  border-radius: var(--amino-radius-pill);
  background: #fff;
  transition: transform 0.15s ease;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.2);
}
.switch input:checked + .track { background: var(--amino-ink); }
.switch input:checked + .track::after { transform: translateX(16px); }

.icon-btn.edit:hover { color: var(--amino-ink); border-color: var(--amino-ink); }
.add-row { display: flex; }

.btn.danger {
  background: var(--amino-danger);
  border-color: var(--amino-danger);
  color: #fff;
}

/* ---------- Toasts ---------- */
.toaster {
  position: fixed;
  bottom: 24px;
  right: 24px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  z-index: 200;
}
.toast {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 13px 18px;
  border-radius: var(--amino-radius-lg);
  font-size: var(--amino-text-sm);
  font-weight: 700;
  color: #fff;
  box-shadow: var(--amino-shadow-lg);
  animation: toast-in 0.18s ease;
  max-width: 360px;
}
.toast.success { background: var(--amino-success); }
.toast.error { background: var(--amino-danger); }
.toast span:first-child { font-size: 15px; line-height: 1; }
@keyframes toast-in {
  from { opacity: 0; transform: translateY(10px); }
  to { opacity: 1; transform: none; }
}
