/*
 * Sistema de diseño «Cafe»: tonos cálidos, Poppins, superficies limpias.
 * Día: paleta Cafe tal cual. Noche: espresso con el dorado del ícono como color principal.
 * Espaciado: 2 / 4 / 8 / 12 / 16 / 24 / 32 / 48.  Radios: 4 / 8.
 */
:root {
  --bg: #F9F7F5; --card: #FFFFFF; --ink: #3E2B1E; --muted: #75604F; --line: #E9E3DD;
  --brand: #5D4432; --brand-hover: #4A3527; --brand-ink: #FFFFFF; --soft: #E9E3DD;
  --accent: #C98A12;
  --good: #15803D; --bad: #C81E1E; --warn: #A8530A; --warn-bg: #FBEFD9;
  --chart-1: #5D4432; --chart-2: #D4950F; --chart-3: #A8703F; --chart-4: #7F9168; --chart-5: #C2613F; --chart-6: #D9B98C;
  --r-sm: 4px; --r-md: 8px;
  --shadow: 0 1px 2px rgba(62, 43, 30, .05), 0 4px 16px rgba(62, 43, 30, .05);
  --font: "Poppins", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --mono: "JetBrains Mono", ui-monospace, Menlo, Consolas, monospace;
}
:root[data-theme="dark"] {
  --bg: #15100C; --card: #1F1812; --ink: #F4ECE4; --muted: #B7A698; --line: #35291F;
  --brand: #EBAA24; --brand-hover: #F5BC45; --brand-ink: #231505; --soft: #32261A;
  --accent: #EBAA24;
  --good: #4ADE80; --bad: #F87171; --warn: #FBBF24; --warn-bg: #3A2A0C;
  --chart-1: #EBAA24; --chart-2: #B98A5E; --chart-3: #F0D9A8; --chart-4: #8FA37A; --chart-5: #D9764F; --chart-6: #7A6657;
  --shadow: none;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #15100C; --card: #1F1812; --ink: #F4ECE4; --muted: #B7A698; --line: #35291F;
    --brand: #EBAA24; --brand-hover: #F5BC45; --brand-ink: #231505; --soft: #32261A;
    --accent: #EBAA24;
    --good: #4ADE80; --bad: #F87171; --warn: #FBBF24; --warn-bg: #3A2A0C;
    --chart-1: #EBAA24; --chart-2: #B98A5E; --chart-3: #F0D9A8; --chart-4: #8FA37A; --chart-5: #D9764F; --chart-6: #7A6657;
    --shadow: none;
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; background: var(--bg); color: var(--ink); font: 400 15px/1.55 var(--font); -webkit-font-smoothing: antialiased; }
a { color: var(--brand); text-decoration: none; }
a:hover { text-decoration: underline; text-underline-offset: 3px; }
h1 { font-size: 1.75rem; font-weight: 600; margin: 0; letter-spacing: -.02em; line-height: 1.2; }
h2 { font-size: 1rem; font-weight: 600; margin: 0 0 12px; }
small, .muted { color: var(--muted); }
small { font-size: .8rem; }
.num { font-variant-numeric: tabular-nums; white-space: nowrap; }
.good { color: var(--good); } .bad { color: var(--bad); }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: var(--r-sm); }

/* Estructura */
body.app { display: grid; grid-template-columns: 232px 1fr; min-height: 100vh; }
.side { position: sticky; top: 0; height: 100vh; padding: 24px 16px; border-right: 1px solid var(--line); background: var(--card); display: flex; flex-direction: column; gap: 24px; }
.brand { display: flex; gap: 12px; align-items: center; font-weight: 600; line-height: 1.2; }
.brand small { font-weight: 400; }
.logo { width: 40px; height: 40px; border-radius: var(--r-md); background: var(--brand); color: var(--brand-ink); display: grid; place-items: center; font-size: 1.2rem; }
.side nav { display: flex; flex-direction: column; gap: 4px; flex: 1; }
.side nav a { display: flex; align-items: center; gap: 12px; padding: 10px 12px; border-radius: var(--r-md); color: var(--muted); font-weight: 500; text-decoration: none; transition: background .15s, color .15s; }
.side nav a svg { width: 20px; height: 20px; flex: none; }
.side nav a:hover { background: var(--soft); color: var(--ink); }
.side nav a.on { background: var(--brand); color: var(--brand-ink); }
.who { font-size: .8rem; color: var(--muted); }
main { padding: 32px clamp(16px, 3vw, 48px) 48px; max-width: 1200px; width: 100%; min-width: 0; }
.fab { position: fixed; right: 24px; bottom: 24px; width: 56px; height: 56px; border-radius: 50%; background: var(--brand); color: var(--brand-ink); font-size: 2rem; font-weight: 300; line-height: 54px; text-align: center; text-decoration: none; box-shadow: 0 8px 24px rgba(62, 43, 30, .28); z-index: 20; transition: background .15s, transform .15s; }
.fab:hover { background: var(--brand-hover); text-decoration: none; transform: translateY(-2px); }

@media (max-width: 800px) {
  body.app { display: block; padding-bottom: 76px; }
  .side { position: fixed; inset: auto 0 0 0; height: auto; flex-direction: row; padding: 8px 4px calc(8px + env(safe-area-inset-bottom)); border-right: 0; border-top: 1px solid var(--line); z-index: 30; }
  .brand, .who { display: none; }
  .side nav { flex-direction: row; justify-content: space-around; width: 100%; gap: 2px; }
  .side nav a { flex-direction: column; gap: 2px; padding: 8px 2px; font-size: .66rem; flex: 1; min-width: 0; }
  .side nav a.on { background: var(--soft); color: var(--brand); }
  .fab { bottom: calc(88px + env(safe-area-inset-bottom)); right: 16px; }
  main { padding-top: 24px; }
  h1 { font-size: 1.5rem; }
}

/* Piezas */
.head { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 24px; }
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--r-md); padding: 24px; box-shadow: var(--shadow); min-width: 0; }
.grid { display: grid; gap: 16px; }
.kpis { grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); margin-bottom: 16px; }
.kpi .label { color: var(--muted); font: 500 .72rem var(--mono); text-transform: uppercase; letter-spacing: .06em; margin-bottom: 4px; }
.kpi .value { font-size: 1.6rem; font-weight: 600; letter-spacing: -.02em; line-height: 1.25; }
.two { grid-template-columns: repeat(auto-fit, minmax(min(100%, 340px), 1fr)); margin-bottom: 16px; }
.flash { background: var(--soft); color: var(--ink); border-left: 4px solid var(--accent); border-radius: var(--r-md); padding: 12px 16px; margin-bottom: 16px; font-weight: 500; }
.alert { background: var(--warn-bg); color: var(--warn); border-radius: var(--r-md); padding: 12px 16px; margin-bottom: 16px; display: block; font-weight: 500; }
.seg { display: inline-flex; background: var(--soft); border-radius: var(--r-md); padding: 4px; gap: 2px; }
.seg a, .seg button { padding: 8px 12px; border-radius: var(--r-sm); color: var(--muted); font-weight: 500; font-size: .88rem; border: 0; background: none; cursor: pointer; text-decoration: none; }
.seg a:hover, .seg button:hover { color: var(--ink); text-decoration: none; }
.seg a.on, .seg button.on { background: var(--brand); color: var(--brand-ink); }
.monthnav { display: inline-flex; align-items: center; gap: 8px; font-weight: 500; }
.monthnav a { width: 32px; height: 32px; display: grid; place-items: center; border: 1px solid var(--line); border-radius: var(--r-md); background: var(--card); text-decoration: none; }
.monthnav a:hover { background: var(--soft); }
.bar { height: 12px; background: var(--soft); border-radius: 99px; overflow: hidden; }
.bar > i { display: block; height: 100%; background: var(--accent); border-radius: 99px; }
.rows { list-style: none; margin: 0; padding: 0; }
.rows li { display: flex; justify-content: space-between; gap: 12px; padding: 12px 0; border-bottom: 1px solid var(--line); align-items: center; }
.rows li:last-child { border-bottom: 0; padding-bottom: 0; }
.rows .t { min-width: 0; text-decoration: none; }
.rows .t b { display: block; font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.rows .t small { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.rows b.num { font-weight: 600; }
.tag { display: inline-block; font: 500 .68rem var(--mono); text-transform: uppercase; letter-spacing: .04em; padding: 2px 8px; border-radius: 99px; background: var(--soft); color: var(--ink); }
.tag.warn { background: var(--warn-bg); color: var(--warn); }
.chart { position: relative; height: 240px; }
.empty { color: var(--muted); text-align: center; padding: 24px 12px; }

/* Tablas */
.tablewrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 12px; border-bottom: 1px solid var(--line); vertical-align: middle; }
th { font: 500 .72rem var(--mono); color: var(--muted); text-transform: uppercase; letter-spacing: .06em; }
td.r, th.r { text-align: right; }
tr:last-child td { border-bottom: 0; }

/* Formularios */
form.stack { display: grid; gap: 16px; }
.fields { display: grid; gap: 12px; grid-template-columns: repeat(auto-fit, minmax(min(100%, 200px), 1fr)); }
label { display: grid; gap: 4px; font-size: .82rem; color: var(--muted); font-weight: 500; }
input, select, button { font: inherit; }
input[type=text], input[type=email], input[type=password], input[type=date], input[type=search], select {
  width: 100%; padding: 8px 12px; border: 1px solid var(--line); border-radius: var(--r-md); background: var(--card); color: var(--ink); min-height: 44px;
  transition: border-color .15s, box-shadow .15s;
}
input[type=file] { color: var(--muted); font-size: .85rem; max-width: 100%; }
input:hover, select:hover { border-color: var(--muted); }
input:focus, select:focus { outline: none; border-color: var(--brand); box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 35%, transparent); }
::placeholder { color: var(--muted); opacity: .7; }
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 8px; padding: 8px 16px; border-radius: var(--r-md); border: 1px solid var(--line); background: var(--card); color: var(--ink); font-weight: 500; cursor: pointer; min-height: 44px; text-decoration: none; transition: background .15s, border-color .15s; }
.btn:hover { background: var(--soft); text-decoration: none; }
.btn:active { transform: translateY(1px); }
.btn.primary { background: var(--brand); color: var(--brand-ink); border-color: var(--brand); }
.btn.primary:hover { background: var(--brand-hover); border-color: var(--brand-hover); }
.btn.danger { color: var(--bad); }
.btn.sm { padding: 4px 12px; min-height: 32px; font-size: .82rem; }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.actions { display: flex; gap: 12px; flex-wrap: wrap; }
.filters { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 16px; }
.filters select, .filters input { width: auto; flex: 1 1 130px; }
.typepick { display: grid; grid-template-columns: repeat(4, 1fr); gap: 4px; background: var(--soft); border-radius: var(--r-md); padding: 4px; }
.typepick label { display: block; }
.typepick input { position: absolute; opacity: 0; }
.typepick span { display: grid; place-items: center; min-height: 40px; text-align: center; padding: 4px; border-radius: var(--r-sm); font-weight: 500; color: var(--muted); cursor: pointer; font-size: .82rem; line-height: 1.2; }
.typepick input:checked + span { background: var(--brand); color: var(--brand-ink); }
.typepick input:focus-visible + span { outline: 2px solid var(--accent); outline-offset: 2px; }
[hidden] { display: none !important; }

/* Invitado */
body.guest { display: grid; place-items: center; min-height: 100vh; padding: 16px; }
body.guest main { max-width: 420px; padding: 0; }
body.guest .brand { margin-bottom: 24px; }
.code { font: 600 1.5rem var(--mono); letter-spacing: .1em; background: var(--soft); color: var(--ink); padding: 12px 16px; border-radius: var(--r-md); display: inline-block; }

/* Captura rápida e ícono */
.capture { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.capture .btn { min-height: 56px; font-size: 1rem; }
.capture .rec { background: var(--bad); color: #fff; border-color: var(--bad); }
img.logo { object-fit: cover; background: none; }
img.iconprev { width: 72px; height: 72px; border-radius: 16px; border: 1px solid var(--line); object-fit: cover; }

/* Selector de estilo */
.presets { display: flex; flex-wrap: wrap; gap: 8px; }
.preset { display: inline-flex; align-items: center; gap: 8px; padding: 8px 12px 8px 8px; min-height: 44px; border: 1px solid var(--line); border-radius: var(--r-md); background: var(--card); color: var(--ink); font-weight: 500; font-size: .85rem; cursor: pointer; }
.preset:hover { background: var(--soft); }
.preset.on { border-color: var(--brand); box-shadow: 0 0 0 2px var(--brand); }
.preset .sw { display: inline-flex; gap: 2px; padding: 4px; border-radius: var(--r-sm); border: 1px solid rgba(62, 43, 30, .15); }
.preset .sw i { width: 14px; height: 20px; border-radius: 2px; display: block; }
.colors { grid-template-columns: repeat(3, 1fr); }
input[type=color] { width: 100%; height: 44px; padding: 4px; border: 1px solid var(--line); border-radius: var(--r-md); background: var(--card); cursor: pointer; }
