/* ── Dorcor Combustible ─────────────────────────────────────────────
   Estética: tipografía negra muy grande, tarjetas pastel redondeadas,
   dock flotante oscuro. Todo el radio y el color viven aquí.
   ──────────────────────────────────────────────────────────────────── */

:root {
  --bg:        #eef0f2;
  --card:      #ffffff;
  --ink:       #101318;
  --ink-2:     #4c525b;
  --muted:     #8d939c;
  --line:      #e8eaed;
  --line-soft: #f0f1f3;

  --blue:      #d5e7f8;
  --green:     #d8efdc;
  --yellow:    #fbeec5;
  --purple:    #e6e0f4;
  --plain:     #f4f5f7;

  --danger:    #c8372d;

  --r-card: 28px;
  --r-tile: 24px;
  --r-soft: 16px;

  --sans: -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, Roboto, Helvetica, Arial, sans-serif;
}

* { box-sizing: border-box; }

/* Sin estas dos reglas, los `display:` de más abajo anularían al atributo
   `hidden` y al `display:none` que el navegador da a los diálogos cerrados:
   se verían el previsualizador, el spinner y el visor del ticket al cargar. */
[hidden] { display: none !important; }
dialog:not([open]) { display: none !important; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  font-family: var(--sans);
  font-size: 15px;
  line-height: 1.45;
  color: var(--ink);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
}

h1, h2 { margin: 0; font-weight: 700; letter-spacing: -0.02em; }
p { margin: 0; }
ul { margin: 0; padding: 0; list-style: none; }

.ico {
  width: 22px; height: 22px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.6;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.muted { color: var(--muted); }
.small { font-size: 13px; }

.app { max-width: 620px; margin: 0 auto; padding: 0 16px; }

/* ── Cabecera ────────────────────────────────────────────────────── */

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 18px 2px 8px;
}

.brand { display: flex; align-items: center; gap: 10px; }

.brand-mark {
  display: grid; place-items: center;
  width: 34px; height: 34px;
  background: var(--ink);
  border-radius: 12px;
}
.brand-mark svg { width: 20px; height: 20px; fill: #fff; }

.brand-name { font-weight: 700; letter-spacing: -0.02em; }

.round-btn {
  display: grid; place-items: center;
  width: 40px; height: 40px;
  padding: 0;
  border: 0;
  border-radius: 999px;
  background: var(--plain);
  color: var(--ink);
  cursor: pointer;
}
.round-btn:hover { background: #e6e8ec; }

/* ── Titular ─────────────────────────────────────────────────────── */

.hero {
  margin: 18px 2px 26px;
  font-size: clamp(34px, 10vw, 46px);
  font-weight: 800;
  line-height: 0.96;
  letter-spacing: -0.045em;
}

/* ── Rejilla de acciones ─────────────────────────────────────────── */

.actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  margin-bottom: 12px;
}

.tile {
  display: grid;
  justify-items: center;
  gap: 14px;
  padding: 22px 12px 20px;
  border: 0;
  border-radius: var(--r-tile);
  font: inherit;
  color: var(--ink);
  cursor: pointer;
  transition: transform 0.12s ease;
}
.tile:active { transform: scale(0.975); }

.tile-blue   { background: var(--blue); }
.tile-green  { background: var(--green); }
.tile-yellow { background: var(--yellow); }
.tile-plain  { background: var(--card); box-shadow: inset 0 0 0 1px var(--line); }

.badge {
  display: grid; place-items: center;
  width: 46px; height: 46px;
  background: #fff;
  border-radius: 999px;
}
.tile-plain .badge { background: var(--plain); }

.tile-label { font-size: 17px; font-weight: 700; letter-spacing: -0.02em; }

/* ── Buscador ────────────────────────────────────────────────────── */

.searchbar {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 0 18px;
  height: 54px;
  margin-bottom: 20px;
  background: var(--card);
  border-radius: 999px;
  color: var(--muted);
}
.searchbar input {
  flex: 1;
  min-width: 0;
  border: 0;
  background: none;
  font: inherit;
  color: var(--ink);
  appearance: none;          /* Safari redondea los input[type=search] */
  -webkit-appearance: none;
}
.searchbar input::placeholder { color: var(--muted); }
.searchbar input:focus { outline: 0; }
.searchbar:focus-within { box-shadow: 0 0 0 2px var(--ink); }

/* ── Tarjetas ────────────────────────────────────────────────────── */

.card {
  padding: 22px;
  margin-bottom: 14px;
  background: var(--card);
  border-radius: var(--r-card);
}
.card h2 { font-size: 17px; }
.card > .muted { margin-top: 2px; }

.card-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
}

/* ── Botones ─────────────────────────────────────────────────────── */

.btn {
  padding: 12px 22px;
  border: 0;
  border-radius: 999px;
  background: var(--plain);
  font: inherit;
  font-weight: 600;
  color: var(--ink);
  cursor: pointer;
}
.btn:hover { background: #e6e8ec; }
.btn-dark { background: var(--ink); color: #fff; }
.btn-dark:hover { background: #292d34; }
.btn:disabled { opacity: 0.45; cursor: default; }

.row-btns { display: flex; gap: 8px; margin-top: 18px; flex-wrap: wrap; }
/* Invierte el orden visual sin tocar el del DOM (ver comentario en el diálogo). */
.row-btns.dialog-actions { flex-direction: row-reverse; justify-content: flex-start; }

/* ── Captura ─────────────────────────────────────────────────────── */

.capture-body { display: flex; gap: 18px; align-items: flex-start; }
.capture-body img {
  width: 128px;
  border-radius: var(--r-soft);
  background: var(--plain);
}
.capture-side { flex: 1; min-width: 0; }
.capture-side h2 { margin-bottom: 2px; }

.status {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-top: 18px;
  color: var(--muted);
}
.spinner {
  width: 16px; height: 16px;
  border: 2px solid var(--line);
  border-top-color: var(--ink);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.error {
  padding: 16px 20px;
  margin-bottom: 14px;
  background: #fbe4e1;
  border-radius: var(--r-card);
  color: #8f2018;
}

/* ── Formulario ──────────────────────────────────────────────────── */

.fields {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 14px;
  margin-top: 18px;
}

label {
  display: grid;
  gap: 6px;
  font-size: 13px;
  font-weight: 600;
  color: var(--muted);
}

input[type="date"], input[type="text"], input[type="number"], input[type="password"] {
  padding: 12px 14px;
  border: 0;
  border-radius: var(--r-soft);
  background: var(--plain);
  font: inherit;
  font-weight: 500;
  color: var(--ink);
}
input:focus { outline: 2px solid var(--ink); outline-offset: -2px; }

/* ── Chips de periodo ────────────────────────────────────────────── */

.chips {
  display: flex;
  gap: 8px;
  margin: 22px 0 14px;
  overflow-x: auto;
  scrollbar-width: none;
  padding-bottom: 2px;
}
.chips::-webkit-scrollbar { display: none; }

.chip {
  flex: none;
  padding: 10px 18px;
  border: 0;
  border-radius: 999px;
  background: var(--card);
  font: inherit;
  font-weight: 600;
  color: var(--ink-2);
  cursor: pointer;
}
.chip:hover { background: #e6e8ec; }
.chip.active { background: var(--ink); color: #fff; }

/* ── Lista de cargas ─────────────────────────────────────────────── */

.records li {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 14px 0;
  border-bottom: 1px solid var(--line-soft);
}
.records li:last-child { border-bottom: 0; padding-bottom: 0; }
.records li:first-child { padding-top: 18px; }

.rec-icon {
  display: grid; place-items: center;
  flex: none;
  width: 44px; height: 44px;
  border-radius: 14px;
  color: var(--ink);
}
.rec-icon svg { width: 22px; height: 22px; }

/* Con comprobante, el cuadro pasa a ser la miniatura del ticket. */
.rec-icon-photo { border: 0; padding: 0; overflow: hidden; cursor: zoom-in; }
.rec-icon-photo:hover { box-shadow: 0 0 0 2px var(--ink); }
.rec-photo { width: 100%; height: 100%; object-fit: cover; display: block; }

/* Nombre y detalle se recortan con puntos suspensivos: partirlos en dos
   líneas descuadra la fila y empuja el importe fuera de sitio. */
.rec-main { flex: 1; min-width: 0; }
.rec-title,
.rec-sub { overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
.rec-title { font-weight: 700; letter-spacing: -0.01em; }
.rec-sub { font-size: 13px; color: var(--muted); }

.rec-amount { flex: none; text-align: right; white-space: nowrap; }
.rec-total { font-weight: 700; letter-spacing: -0.02em; }
.rec-unit { font-size: 12px; color: var(--muted); }

.rec-del {
  flex: none;
  display: grid; place-items: center;
  width: 32px; height: 32px;
  padding: 0;
  border: 0;
  border-radius: 999px;
  background: none;
  color: var(--muted);
  cursor: pointer;
}
.rec-del:hover { background: var(--plain); color: var(--danger); }
.rec-del svg { width: 18px; height: 18px; }

.empty { padding: 26px 0 6px; text-align: center; color: var(--muted); }

/* ── Fichas de resumen ───────────────────────────────────────────── */

.stats {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  margin-bottom: 14px;
}

.stat {
  display: grid;
  gap: 6px;
  padding: 20px;
  border-radius: var(--r-tile);
}
.stat-blue   { background: var(--blue); }
.stat-green  { background: var(--green); }
.stat-yellow { background: var(--yellow); }
.stat-purple { background: var(--purple); }

.stat-label { font-size: 13px; font-weight: 600; color: var(--ink-2); }
.stat-value { font-size: clamp(24px, 7vw, 30px); font-weight: 800; letter-spacing: -0.035em; }

/* ── Gráficos ────────────────────────────────────────────────────── */

.chart-wrap { margin-top: 14px; min-height: 220px; }
.chart-wrap svg { display: block; width: 100%; overflow: visible; }

.grid-line  { stroke: var(--line); stroke-width: 1; }
.axis-text  { fill: var(--muted); font-size: 11px; font-weight: 500; font-family: var(--sans); }
.axis-text.y { text-anchor: end; }
.axis-text.x { text-anchor: middle; }
.value-text { fill: var(--ink); font-size: 12px; font-weight: 700; font-family: var(--sans); text-anchor: middle; }

.bar { fill: var(--ink); pointer-events: none; }
.band { fill: var(--blue); opacity: 0; pointer-events: none; }
.band.hot { opacity: 1; }
.bar-hit { fill: transparent; cursor: pointer; }

.area { fill: var(--blue); opacity: 0.55; }
.series-line { fill: none; stroke: var(--ink); stroke-width: 2; stroke-linejoin: round; stroke-linecap: round; }
.series-dot { fill: var(--ink); stroke: var(--card); stroke-width: 2; }
.crosshair { stroke: var(--muted); stroke-width: 1; stroke-dasharray: 3 3; }

/* ── Dock ────────────────────────────────────────────────────────── */

.dock {
  position: fixed;
  left: 0; right: 0;
  bottom: max(16px, env(safe-area-inset-bottom));
  z-index: 30;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  width: min(588px, calc(100% - 32px));
  margin: 0 auto;
  pointer-events: none;
}
.dock > * { pointer-events: auto; }

.dock-pill {
  display: flex;
  gap: 4px;
  padding: 5px;
  background: var(--ink);
  border-radius: 999px;
  box-shadow: 0 6px 22px rgba(16, 19, 24, 0.28);
}

.dock-btn {
  display: grid; place-items: center;
  width: 46px; height: 46px;
  padding: 0;
  border: 0;
  border-radius: 999px;
  background: none;
  color: #8a9099;
  cursor: pointer;
}
.dock-btn.active { background: #2b3038; color: #fff; }

.fab {
  display: grid; place-items: center;
  width: 58px; height: 58px;
  padding: 0;
  border: 0;
  border-radius: 999px;
  background: var(--ink);
  color: #fff;
  cursor: pointer;
  box-shadow: 0 6px 22px rgba(16, 19, 24, 0.28);
}
.fab:active { transform: scale(0.95); }
.fab .ico { width: 26px; height: 26px; stroke-width: 2; }

main { padding-bottom: 110px; }

/* ── Arrastrar y soltar ──────────────────────────────────────────── */

.drop-overlay {
  position: fixed;
  inset: 12px;
  z-index: 40;
  display: grid;
  place-items: center;
  background: rgba(238, 240, 242, 0.92);
  border: 2px dashed var(--ink);
  border-radius: 32px;
  font-size: 20px;
  font-weight: 700;
  letter-spacing: -0.02em;
}

/* ── Tooltip ─────────────────────────────────────────────────────── */

.tooltip {
  position: fixed;
  z-index: 50;
  padding: 9px 13px;
  background: var(--ink);
  color: #fff;
  border-radius: 12px;
  font-size: 12px;
  line-height: 1.45;
  pointer-events: none;
  white-space: nowrap;
}
.tooltip b { font-weight: 700; }

/* ── Diálogo ─────────────────────────────────────────────────────── */

dialog {
  width: min(420px, calc(100vw - 32px));
  padding: 26px;
  border: 0;
  border-radius: var(--r-card);
  background: var(--card);
  color: var(--ink);
}
dialog::backdrop { background: rgba(16, 19, 24, 0.4); }
.photo-dialog { width: min(520px, calc(100vw - 32px)); display: grid; gap: 14px; }
.photo-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
}
.photo-meta h2 { font-size: 19px; }
.photo-dialog img {
  width: 100%;
  max-height: min(62vh, 620px);
  object-fit: contain;
  border-radius: var(--r-soft);
  background: var(--plain);
}
.photo-dialog .btn { justify-self: start; text-decoration: none; }

.settings-form { display: grid; gap: 14px; }
.settings-form h2 { font-size: 20px; }
.settings-form .row-btns { margin-top: 4px; }

/* ── Móvil ───────────────────────────────────────────────────────── */

@media (max-width: 420px) {
  .card { padding: 18px; }
  .capture-body img { width: 96px; }
}
