:root {
  --cream: #faf6ee;
  --cream-2: #f6e8d4;
  --cocoa: #4a2f22;
  --cocoa-2: #6b4530;
  --berry: #e8842a;
  --berry-2: #c1650f;
  --mint: #2f9e78;
  --amber: #c78a1f;
  --red: #c23b3b;
  --ink: #2a231d;
  --ink-soft: #6d6255;
  --line: #e9d7b8;
  --white: #ffffff;
  --radius: 14px;
  --shadow: 0 8px 24px rgba(74, 47, 34, 0.08);
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --cream: #1c1712;
    --cream-2: #241d16;
    --cocoa: #f0c8a8;
    --cocoa-2: #f6dcc2;
    --ink: #f1e9dc;
    --ink-soft: #c2b6a4;
    --line: #3a2f24;
    --white: #241d16;
    --shadow: 0 8px 24px rgba(0, 0, 0, 0.35);
  }
}
:root[data-theme="dark"] {
  --cream: #1c1712;
  --cream-2: #241d16;
  --cocoa: #f0c8a8;
  --cocoa-2: #f6dcc2;
  --ink: #f1e9dc;
  --ink-soft: #c2b6a4;
  --line: #3a2f24;
  --white: #241d16;
  --shadow: 0 8px 24px rgba(0, 0, 0, 0.35);
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  background: var(--cream);
  color: var(--ink);
  font-family: 'Inter', system-ui, sans-serif;
  font-variant-numeric: tabular-nums;
}
h1, h2, h3 { font-family: 'Manrope', 'Inter', sans-serif; margin: 0; text-wrap: balance; }
button, input, select, textarea { font-family: inherit; font-size: 1rem; }

[hidden] { display: none !important; }

/* ---------- login ---------- */
.view-login {
  min-height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px 16px;
}
.login-card {
  width: 100%;
  max-width: 380px;
  background: var(--white);
  border-radius: 20px;
  box-shadow: var(--shadow);
  padding: 32px 28px;
  border: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: 14px; margin-bottom: 24px; }
.brand-mark {
  width: 44px; height: 44px; border-radius: 12px;
  background: var(--white); border: 1px solid var(--line);
  color: white; display: flex; align-items: center; justify-content: center;
  font-family: 'Manrope', sans-serif; font-weight: 800; font-size: 1.3rem;
  flex: none; overflow: hidden; padding: 4px;
}
.brand-mark img { width: 100%; height: 100%; object-fit: contain; }
.brand-mark.small { width: 34px; height: 34px; border-radius: 9px; font-size: 1rem; padding: 3px; }
.brand h1 { font-size: 1.25rem; color: var(--cocoa); }
.brand-sub { margin: 2px 0 0; font-size: 0.82rem; color: var(--ink-soft); }
.login-hint { margin: 18px 0 0; font-size: 0.82rem; color: var(--ink-soft); text-align: center; }

.form-stack { display: flex; flex-direction: column; gap: 16px; }
.field { display: flex; flex-direction: column; gap: 6px; font-size: 0.85rem; color: var(--ink-soft); font-weight: 600; }
.field input, .field select, .field textarea {
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 11px 12px;
  background: var(--cream);
  color: var(--ink);
}
.field input:focus, .field select:focus, .field textarea:focus {
  outline: 2px solid var(--berry);
  outline-offset: 1px;
}
.field-error { color: var(--red); font-size: 0.85rem; margin: 0; }

.btn {
  border: none; border-radius: 10px; padding: 11px 18px;
  font-weight: 700; cursor: pointer; transition: transform .05s ease, opacity .15s ease;
}
.btn:active { transform: scale(0.98); }
.btn-primary { background: var(--berry); color: white; }
.btn-primary:hover { background: var(--berry-2); }
.btn-block { width: 100%; }
.btn-ghost { background: transparent; color: var(--ink); border: 1px solid var(--line); }
.btn-small { padding: 6px 10px; font-size: 0.82rem; }
.btn-danger { background: var(--red); color: white; }
.btn-success { background: var(--mint); color: white; }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }

/* ---------- shell ---------- */
.app-shell { min-height: 100%; display: flex; flex-direction: column; }
.topbar {
  display: flex; align-items: center; gap: 16px;
  padding: 12px 20px; padding-top: calc(12px + env(safe-area-inset-top, 0px));
  background: var(--white); border-bottom: 1px solid var(--line);
  position: sticky; top: 0; z-index: 5; flex-wrap: wrap;
}
.topbar-left { display: flex; align-items: center; gap: 10px; }
.topbar-sub { font-size: 0.78rem; color: var(--ink-soft); text-transform: capitalize; }
.main-nav { display: flex; gap: 6px; flex: 1; flex-wrap: wrap; }
.main-nav button {
  background: transparent; border: none; padding: 8px 14px; border-radius: 999px;
  font-weight: 600; color: var(--ink-soft); cursor: pointer;
}
.main-nav button.active { background: var(--cream-2); color: var(--cocoa); }
.topbar-right { display: flex; align-items: center; gap: 10px; font-size: 0.85rem; color: var(--ink-soft); }

.app-main { flex: 1; padding: 20px; padding-inline: max(16px, env(safe-area-inset-left, 0px)); max-width: 1080px; width: 100%; margin: 0 auto; }

/* ---------- generic ---------- */
.card {
  background: var(--white); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 18px; margin-bottom: 16px; box-shadow: var(--shadow);
}
.card h2, .card h3 { color: var(--cocoa); }
.section-title { display: flex; align-items: center; justify-content: space-between; margin-bottom: 12px; gap: 10px; flex-wrap: wrap; }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.grid-3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; }
@media (max-width: 640px) { .grid-2, .grid-3 { grid-template-columns: 1fr; } }

.pill {
  display: inline-flex; align-items: center; gap: 5px; padding: 3px 10px; border-radius: 999px;
  font-size: 0.75rem; font-weight: 700;
}
.pill-abierto { background: #e7edf7; color: #3a5a9c; }
.pill-enviado, .pill-pendiente { background: #fbeece; color: var(--amber); }
.pill-validado { background: #e2f4ec; color: var(--mint); }
.pill-rechazado { background: #fbe4e4; color: var(--red); }

.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 0.88rem; }
th, td { padding: 8px 10px; text-align: left; border-bottom: 1px solid var(--line); white-space: nowrap; }
th { color: var(--ink-soft); font-weight: 700; font-size: 0.78rem; text-transform: uppercase; letter-spacing: 0.03em; }

.stat-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 12px; margin-bottom: 16px; }
.stat-tile { background: var(--white); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; box-shadow: var(--shadow); }
.stat-tile .label { font-size: 0.75rem; color: var(--ink-soft); font-weight: 700; text-transform: uppercase; letter-spacing: 0.03em; }
.stat-tile .value { font-family: 'Manrope', sans-serif; font-size: 1.6rem; font-weight: 800; color: var(--cocoa); margin-top: 4px; }
.stat-tile .sub { font-size: 0.78rem; color: var(--ink-soft); margin-top: 2px; }

.tachos-block { border: 1px dashed var(--line); border-radius: 10px; padding: 10px 12px; }
.tachos-header { display: flex; justify-content: space-between; align-items: center; font-size: 0.85rem; font-weight: 600; color: var(--ink-soft); margin-bottom: 8px; }
.tacho-row { display: flex; gap: 8px; align-items: center; margin-bottom: 6px; }
.tacho-row input { flex: 1; }
.tacho-row button { flex: none; }

.empty-state { text-align: center; padding: 30px 10px; color: var(--ink-soft); }

.toast {
  position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%);
  background: var(--cocoa); color: white; padding: 10px 18px; border-radius: 10px;
  font-size: 0.88rem; z-index: 50; box-shadow: var(--shadow);
}
.toast.error { background: var(--red); }
.toast.success { background: var(--mint); }

.lote-header-form { display: flex; flex-direction: column; gap: 12px; }
.lote-auto-code {
  border: 1px solid var(--line); border-radius: 10px; padding: 11px 12px;
  background: var(--cream-2); color: var(--cocoa); font-weight: 800;
  font-family: 'Manrope', sans-serif; letter-spacing: 0.02em;
}
.row-actions { display: flex; gap: 8px; flex-wrap: wrap; }
.muted { color: var(--ink-soft); }

.mantecadora-card {
  background: var(--white); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 20px 16px; box-shadow: var(--shadow); cursor: pointer;
  transition: transform .08s ease, border-color .1s ease; text-align: center;
}
.mantecadora-card:hover { transform: translateY(-2px); border-color: var(--berry); }
.mantecadora-card h3 { color: var(--cocoa); margin-bottom: 6px; }
.mantecadora-card-progreso { border-color: var(--amber); background: #fdf7ea; }
.mantecadora-card-enviado { border-color: var(--mint); background: #eaf7f1; cursor: default; }
.mantecadora-card-enviado:hover { transform: none; }

.lote-sub-card { background: var(--cream-2); box-shadow: none; margin-top: 12px; }

.charts-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); gap: 16px; }
.chart-box { background: var(--white); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; box-shadow: var(--shadow); }
.chart-box h4 { color: var(--cocoa); margin-bottom: 10px; }
.chart-box canvas { max-height: 260px; }

.registro-edit-row { background: var(--cream-2); }
.registro-edit-row td { padding-top: 10px; padding-bottom: 10px; }
.registro-edit-row input, .registro-edit-row select { width: 100%; }

@media print {
  .no-print { display: none !important; }
  body { background: white; }
  .app-main { max-width: none; padding: 0; }
  .printable { box-shadow: none; border: none; }
}
