:root {
  --accent: #0F806B;
  --bg: #f5f6f7; --surface: #ffffff; --ink: #1b2124; --muted: #5d6970; --line: #dfe3e6; --soft: #eef1f2;
  --ok: #1d7a4a; --warn: #a15c00; --bad: #b3261e;
  --radius: 10px;
  font-family: system-ui, -apple-system, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root { --bg: #14181a; --surface: #1d2225; --ink: #e8ecee; --muted: #9aa6ad; --line: #2c3338; --soft: #262c30; --ok: #5ccb8d; --warn: #f0b155; --bad: #ff8a80; }
}
* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); color: var(--ink); font-size: 15px; line-height: 1.45; }
h1, h2, h3 { line-height: 1.2; margin: 0 0 .6em; }
h1 { font-size: 1.5rem; } h2 { font-size: 1.2rem; } h3 { font-size: 1.05rem; }
a { color: var(--accent); }
.hidden { display: none !important; }
:focus-visible { outline: 3px solid color-mix(in srgb, var(--accent) 55%, transparent); outline-offset: 2px; }

button, .btn { font: inherit; cursor: pointer; border: 1px solid var(--line); background: var(--surface); color: var(--ink); padding: .55rem .95rem; border-radius: 8px; text-decoration: none; display: inline-flex; align-items: center; gap: .4rem; }
button:hover:not(:disabled), .btn:hover { border-color: var(--accent); }
button:disabled { opacity: .55; cursor: not-allowed; }
.primary { background: var(--accent); border-color: var(--accent); color: #fff; font-weight: 600; }
.primary:hover:not(:disabled) { filter: brightness(1.08); }
.danger { color: var(--bad); border-color: color-mix(in srgb, var(--bad) 45%, var(--line)); }
.link-btn { border: 0; background: none; color: var(--accent); padding: .2rem; text-decoration: underline; }
.icon-btn { padding: .1rem .55rem; font-size: 1.3rem; line-height: 1.2; border: 0; background: none; }

input, select, textarea { font: inherit; color: var(--ink); background: var(--surface); border: 1px solid var(--line); border-radius: 8px; padding: .55rem .7rem; width: 100%; }
input[type=checkbox] { width: auto; }
input[type=color] { width: 3.2rem; height: 2.4rem; padding: .2rem; cursor: pointer; }
label.row { flex-wrap: nowrap; align-items: flex-start; }
textarea { min-height: 5rem; resize: vertical; }
.field { display: grid; gap: .3rem; margin-bottom: .9rem; }
.field label { font-weight: 600; font-size: .9rem; }
small, .muted { color: var(--muted); }
.row { display: flex; gap: .6rem; align-items: center; flex-wrap: wrap; }
.grow { flex: 1 1 14rem; }
.spacer { flex: 1; }

.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 1rem 1.1rem; }
.pill { display: inline-block; padding: .1rem .55rem; border-radius: 99px; font-size: .78rem; font-weight: 600; background: var(--soft); color: var(--muted); white-space: nowrap; }
.st-nuevo { background: color-mix(in srgb, var(--accent) 16%, transparent); color: var(--accent); }
.st-confirmado { background: color-mix(in srgb, #2b6cd0 16%, transparent); color: #2b6cd0; }
.st-preparado { background: color-mix(in srgb, var(--warn) 18%, transparent); color: var(--warn); }
.st-entregado { background: color-mix(in srgb, var(--ok) 18%, transparent); color: var(--ok); }
.st-cancelado { background: color-mix(in srgb, var(--bad) 14%, transparent); color: var(--bad); }
.ok { color: var(--ok); } .warn { color: var(--warn); } .bad { color: var(--bad); }

.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; background: var(--surface); }
th, td { text-align: left; padding: .6rem .7rem; border-bottom: 1px solid var(--line); vertical-align: middle; }
th { font-size: .78rem; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); white-space: nowrap; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
tbody tr.click { cursor: pointer; } tbody tr.click:hover { background: var(--soft); }

.brand { display: flex; align-items: center; gap: .6rem; font-weight: 700; font-size: 1.05rem; }
.brand-logo { border-radius: 8px; object-fit: contain; }

dialog.modal { border: 1px solid var(--line); border-radius: 12px; padding: 0; width: min(36rem, calc(100vw - 2rem)); background: var(--surface); color: var(--ink); }
dialog.modal::backdrop { background: rgba(0, 0, 0, .45); }
.modal-head { display: flex; justify-content: space-between; align-items: center; padding: .8rem 1rem; border-bottom: 1px solid var(--line); }
.modal-head h3 { margin: 0; }
.modal-body { padding: 1rem; max-height: 70vh; overflow: auto; }
.modal-actions { padding: .8rem 1rem; border-top: 1px solid var(--line); display: flex; gap: .6rem; justify-content: flex-end; }

#toast { position: fixed; left: 50%; bottom: 1.2rem; transform: translate(-50%, 140%); background: #222; color: #fff; padding: .7rem 1.1rem; border-radius: 8px; max-width: min(32rem, calc(100vw - 2rem)); transition: transform .2s; z-index: 50; }
#toast.show { transform: translate(-50%, 0); }
#toast.err { background: #b3261e; color: #fff; }
@media (prefers-reduced-motion: reduce) { * { transition: none !important; } }

/* Comprobantes electrónicos: siempre en "papel" claro, también en modo oscuro y al imprimir */
.invoice { background: #fff; color: #111; border: 1px solid #cfd4d7; border-radius: 6px; padding: 1.2rem; max-width: 52rem; margin: 0 auto 1rem; }
.invoice table { background: #fff; } .invoice th, .invoice td { border-bottom-color: #dcdfe1; color: #111; } .invoice th { color: #555; }
.invoice small { color: #555; }
.inv-banner { background: #fff3cd; color: #664d03; border: 1px solid #e6c860; padding: .5rem .7rem; border-radius: 6px; font-weight: 600; margin-bottom: .8rem; }
.inv-head { display: grid; grid-template-columns: 1fr auto 1fr; gap: 1rem; border-bottom: 2px solid #111; padding-bottom: .8rem; margin-bottom: .8rem; }
.inv-head h2 { margin: 0 0 .3rem; }
.inv-letter { border: 2px solid #111; width: 4.2rem; height: 4.8rem; display: grid; place-content: center; text-align: center; } .inv-letter b { font-size: 2.2rem; line-height: 1; }
.inv-receptor { display: grid; grid-template-columns: repeat(auto-fit, minmax(14rem, 1fr)); gap: .3rem 1rem; padding-bottom: .6rem; }
.inv-kv { display: flex; gap: .4rem; flex-wrap: wrap; } .inv-kv span { color: #555; }
.inv-total { display: flex; justify-content: flex-end; gap: 1rem; align-items: baseline; font-size: 1.2rem; padding: .7rem 0; border-top: 2px solid #111; }
.inv-foot { display: flex; gap: 1rem; align-items: center; flex-wrap: wrap; }
.inv-note { font-weight: 600; }
@media (max-width: 40rem) { .inv-head { grid-template-columns: 1fr; } .inv-letter { justify-self: start; } }
@media print {
  body * { visibility: hidden; }
  .invoice, .invoice * { visibility: visible; }
  .invoice { position: absolute; left: 0; top: 0; width: 100%; max-width: none; border: 0; }
}
