/* ============================================================
   HORNITO — Sistema Panadería
   Design tokens · tema cálido artesanal · claro + oscuro
   ============================================================ */

:root {
  /* accent (tweakable) — azul de acción por defecto */
  --accent-h: 255;
  --accent: oklch(0.585 0.155 var(--accent-h));
  --accent-strong: oklch(0.52 0.165 var(--accent-h));
  --accent-soft: oklch(0.585 0.155 var(--accent-h) / 0.14);
  --accent-ink: oklch(0.985 0.01 var(--accent-h));

  /* semantic */
  --pos: oklch(0.66 0.13 158);          /* ingreso / verde */
  --pos-soft: oklch(0.66 0.13 158 / 0.15);
  --neg: oklch(0.62 0.17 30);           /* egreso / terracota-rojo */
  --neg-soft: oklch(0.62 0.17 30 / 0.15);
  --warn: oklch(0.74 0.14 72);
  --warn-soft: oklch(0.74 0.14 72 / 0.16);

  /* radii / shadow / spacing */
  --r-sm: 7px;
  --r-md: 11px;
  --r-lg: 16px;
  --r-xl: 22px;
  --density: 1;

  --font-ui: "Hanken Grotesk", system-ui, sans-serif;
  --font-mono: "JetBrains Mono", ui-monospace, monospace;
  --font-display: "Newsreader", Georgia, serif;
}

/* ---------- DARK (default) ---------- */
[data-theme="dark"] {
  --bg: oklch(0.175 0.008 64);
  --bg-grad: oklch(0.205 0.012 58);
  --surface-1: oklch(0.215 0.010 62);
  --surface-2: oklch(0.255 0.012 60);
  --surface-3: oklch(0.305 0.014 58);
  --surface-hi: oklch(0.345 0.016 56);
  --border: oklch(0.33 0.012 58);
  --border-soft: oklch(0.275 0.010 60);
  --border-strong: oklch(0.44 0.016 56);
  --text: oklch(0.955 0.008 78);
  --text-muted: oklch(0.74 0.012 70);
  --text-faint: oklch(0.56 0.012 64);
  --brand: oklch(0.74 0.10 62);         /* pan dorado */
  --shadow-1: 0 1px 2px oklch(0 0 0 / 0.4), 0 2px 8px oklch(0 0 0 / 0.28);
  --shadow-2: 0 8px 30px oklch(0 0 0 / 0.45);
  --shadow-pop: 0 18px 60px oklch(0 0 0 / 0.6);
  color-scheme: dark;
}

/* ---------- LIGHT ---------- */
[data-theme="light"] {
  --bg: oklch(0.955 0.013 82);
  --bg-grad: oklch(0.975 0.012 86);
  --surface-1: oklch(0.995 0.005 88);
  --surface-2: oklch(0.945 0.012 80);
  --surface-3: oklch(0.905 0.015 76);
  --surface-hi: oklch(0.875 0.017 74);
  --border: oklch(0.86 0.014 76);
  --border-soft: oklch(0.90 0.012 78);
  --border-strong: oklch(0.76 0.018 70);
  --text: oklch(0.27 0.020 52);
  --text-muted: oklch(0.46 0.018 54);
  --text-faint: oklch(0.62 0.016 58);
  --brand: oklch(0.55 0.11 56);
  --shadow-1: 0 1px 2px oklch(0.3 0.02 60 / 0.10), 0 2px 8px oklch(0.3 0.02 60 / 0.08);
  --shadow-2: 0 10px 34px oklch(0.3 0.03 60 / 0.14);
  --shadow-pop: 0 20px 60px oklch(0.25 0.03 60 / 0.22);
  color-scheme: light;
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }

body {
  font-family: var(--font-ui);
  background: var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  font-feature-settings: "ss01", "cv01";
  overflow: hidden;
}

#root { height: 100vh; }

/* subtle warm grain on the app backdrop */
.app-bg::before {
  content: "";
  position: fixed; inset: 0;
  pointer-events: none;
  background:
    radial-gradient(1200px 600px at 100% -10%, var(--bg-grad), transparent 60%),
    radial-gradient(900px 500px at -10% 110%, var(--bg-grad), transparent 55%);
  opacity: 0.7;
  z-index: 0;
}

/* numbers align nicely */
.tnum { font-variant-numeric: tabular-nums; font-feature-settings: "tnum"; }

::selection { background: var(--accent-soft); }

/* scrollbars */
*::-webkit-scrollbar { width: 11px; height: 11px; }
*::-webkit-scrollbar-thumb {
  background: var(--surface-3);
  border-radius: 99px;
  border: 3px solid transparent;
  background-clip: padding-box;
}
*::-webkit-scrollbar-thumb:hover { background: var(--surface-hi); background-clip: padding-box; }
*::-webkit-scrollbar-track { background: transparent; }

/* ---------- shared primitives ---------- */
.card {
  background: var(--surface-1);
  border: 1px solid var(--border-soft);
  border-radius: var(--r-lg);
  box-shadow: var(--shadow-1);
}

.btn {
  font-family: var(--font-ui);
  font-weight: 600;
  font-size: 14px;
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text);
  border-radius: var(--r-md);
  padding: calc(9px * var(--density)) 14px;
  display: inline-flex; align-items: center; gap: 8px;
  cursor: pointer;
  transition: background .14s, border-color .14s, transform .06s, color .14s;
  white-space: nowrap;
  user-select: none;
}
.btn:hover { background: var(--surface-3); border-color: var(--border-strong); }
.btn:active { transform: translateY(1px); }
.btn.primary {
  background: var(--accent); border-color: transparent; color: var(--accent-ink);
}
.btn.primary:hover { background: var(--accent-strong); }
.btn.ghost { background: transparent; border-color: transparent; }
.btn.ghost:hover { background: var(--surface-2); }
.btn.danger { color: var(--neg); }
.btn.danger:hover { background: var(--neg-soft); border-color: var(--neg); }
.btn.sm { font-size: 12.5px; padding: 6px 10px; border-radius: var(--r-sm); }
.btn.icon { padding: 9px; }
.btn:disabled { opacity: 0.45; cursor: not-allowed; }

.kbd {
  font-family: var(--font-mono);
  font-size: 11px;
  font-weight: 600;
  background: var(--surface-3);
  border: 1px solid var(--border-strong);
  border-bottom-width: 2px;
  border-radius: 6px;
  padding: 2px 6px;
  color: var(--text-muted);
  line-height: 1;
  display: inline-flex; align-items: center; gap: 3px;
}

.chip {
  font-size: 12px; font-weight: 600;
  padding: 4px 10px; border-radius: 99px;
  background: var(--surface-2); color: var(--text-muted);
  border: 1px solid var(--border-soft);
  display: inline-flex; align-items: center; gap: 6px;
}
.chip.on { background: var(--accent-soft); color: var(--accent); border-color: transparent; }

.badge {
  font-size: 11px; font-weight: 700; letter-spacing: .02em;
  padding: 3px 8px; border-radius: 6px;
  display: inline-flex; align-items: center; gap: 5px;
  text-transform: uppercase;
}
.badge.pos { background: var(--pos-soft); color: var(--pos); }
.badge.neg { background: var(--neg-soft); color: var(--neg); }
.badge.warn { background: var(--warn-soft); color: var(--warn); }
.badge.accent { background: var(--accent-soft); color: var(--accent); }
.badge.muted { background: var(--surface-2); color: var(--text-muted); }

.input {
  font-family: var(--font-ui);
  font-size: 14px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: var(--r-md);
  padding: 10px 12px;
  width: 100%;
  outline: none;
  transition: border-color .14s, box-shadow .14s;
}
.input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.input::placeholder { color: var(--text-faint); }
select.input { padding-top: 0; padding-bottom: 0; padding-right: 30px; line-height: normal; }
label.field { display: flex; flex-direction: column; gap: 6px; font-size: 12.5px; font-weight: 600; color: var(--text-muted); }

.divider { height: 1px; background: var(--border-soft); border: 0; margin: 0; }

.purch-row { transition: background .12s; }
.purch-row:hover { background: var(--surface-2); }

.mono { font-family: var(--font-mono); }
.display { font-family: var(--font-display); }

/* generic modal */
.scrim {
  position: fixed; inset: 0; z-index: 100;
  background: oklch(0 0 0 / 0.55);
  backdrop-filter: blur(3px);
  display: flex; align-items: center; justify-content: center;
  padding: 24px;
  animation: fade .16s ease;
}
.modal {
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-radius: var(--r-xl);
  box-shadow: var(--shadow-pop);
  width: 100%;
  max-height: 90vh;
  overflow: auto;
  animation: pop .18s cubic-bezier(.2,.9,.3,1.2);
}
@keyframes fade { from { opacity: 0; } }
@keyframes pop { from { opacity: 0; transform: translateY(8px) scale(.98); } }
@keyframes slideup { from { opacity: 0; transform: translateY(10px); } }

/* entrance animations: base state is always visible; only animate when motion is welcome */
.fade-in, .slide-up { opacity: 1; }
@media (prefers-reduced-motion: no-preference) {
  .fade-in { animation: fade .2s ease; }
  .slide-up { animation: slideup .22s ease both; }
}

/* image placeholder (warm striped) */
.ph {
  background-color: var(--surface-2);
  background-image: repeating-linear-gradient(135deg, var(--border-soft) 0 2px, transparent 2px 11px);
  display: flex; align-items: center; justify-content: center;
  color: var(--text-faint);
  font-family: var(--font-mono); font-size: 11px;
  border-radius: var(--r-md);
}

.muted { color: var(--text-muted); }
.faint { color: var(--text-faint); }

/* ============ responsive utilities ============ */
.kpi-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 14px; }
.kpi-3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 14px; }
.split-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.dash-main { display: grid; grid-template-columns: 1.6fr 1fr; gap: 16px; }
/* auto-packing card layout: cards flow up to fill vertical gaps (masonry) */
.masonry { columns: 2; column-gap: 16px; }
.masonry > * { break-inside: avoid; -webkit-column-break-inside: avoid; margin-bottom: 16px; }
.sup-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 14px; }
/* tables that should scroll sideways instead of squashing */
.table-scroll { width: 100%; overflow-x: auto; -webkit-overflow-scrolling: touch; }
.table-scroll > table { min-width: 680px; }
.ocr-scroll { width: 100%; overflow-x: auto; -webkit-overflow-scrolling: touch; }
.ocr-scroll > .ocr-inner { min-width: 880px; }

@media (max-width: 1024px) {
  .kpi-grid { grid-template-columns: repeat(2, 1fr); }
  .dash-main { grid-template-columns: 1fr; }
}
@media (max-width: 900px) {
  .split-2 { grid-template-columns: 1fr; }
  .masonry { columns: 1; }
  .sup-grid { grid-template-columns: 1fr; }
  .ocr-doc { grid-template-columns: 1fr !important; }
  .ocr-confirm { grid-template-columns: 1fr !important; }
  .cta-row { flex-direction: column !important; align-items: flex-start !important; }
  .cta-row > button { width: 100%; justify-content: center; }
}
@media (max-width: 560px) {
  .kpi-grid, .kpi-3 { grid-template-columns: repeat(2, 1fr); gap: 10px; }
  .scrim { padding: 0; align-items: flex-end; }
  .scrim .modal { max-height: 94vh; border-radius: var(--r-xl) var(--r-xl) 0 0; }
}

/* ====== mobile: render data tables as stacked cards ====== */
@media (max-width: 640px) {
  .table-scroll { overflow-x: visible; padding: 12px 12px 4px; }
  .table-scroll > table { min-width: 0; width: 100%; }
  .table-scroll > table,
  .table-scroll tbody { display: block; width: 100%; }
  .table-scroll thead { display: none; }

  .table-scroll tbody tr {
    display: flex;
    flex-direction: column;
    gap: 8px;
    border: 1px solid var(--border-soft) !important;
    border-radius: var(--r-md);
    background: var(--surface-2);
    padding: 13px 14px;
    margin-bottom: 10px;
  }
  .table-scroll tbody tr:last-child { margin-bottom: 0; }

  .table-scroll tbody td {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 14px;
    padding: 0 !important;
    text-align: right !important;
    font-size: 13.5px;
    border: 0 !important;
  }
  .table-scroll tbody td::before {
    content: attr(data-label);
    flex-shrink: 0;
    font-size: 11px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: .04em;
    color: var(--text-faint);
    text-align: left;
  }

  /* first cell becomes the card header */
  .table-scroll tbody td:first-child {
    flex-direction: column;
    align-items: stretch;
    gap: 2px;
    padding-bottom: 10px !important;
    margin-bottom: 2px;
    border-bottom: 1px solid var(--border-soft) !important;
    text-align: left !important;
  }
  .table-scroll tbody td:first-child::before { display: none; }

  /* action / unlabeled cells: hide label, full-width button */
  .table-scroll tbody td[data-label=""] { padding-top: 2px !important; }
  .table-scroll tbody td[data-label=""]::before { display: none; }
  .table-scroll tbody td[data-label=""] > .btn,
  .table-scroll tbody td[data-label=""] > button { width: 100%; justify-content: center; }
}
