/* Modo oscuro siempre, independientemente de la configuración del dispositivo. */
:root {
  --bg: #151514;
  --surface: #1e1e1c;
  --surface-2: #262624;
  --text: #ecebe6;
  --muted: #a09f98;
  --border: #34332f;
  --accent: #ecebe6;
  --accent-text: #151514;
  --pos: #5cc98a;
  --neg: #ff8a80;
  --warn: #e3b341;
  --info: #7fa8ff;
  --radius: 10px;
  --shadow: none;
  color-scheme: dark;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

.wrap { max-width: 1180px; margin: 0 auto; padding: 0 16px; }
main.wrap { padding-top: 24px; padding-bottom: 64px; }

h1 { font-size: 1.6rem; margin: 0; letter-spacing: -.01em; }
h2 { font-size: 1.05rem; margin: 0 0 12px; }
a { color: inherit; }
code { background: var(--surface-2); padding: 1px 5px; border-radius: 4px; }

.muted { color: var(--muted); }
.small { font-size: .85rem; }
.nowrap { white-space: nowrap; }
.pos { color: var(--pos); }
.neg { color: var(--neg); }

/* ---------- Cabecera */
.top { background: var(--surface); border-bottom: 1px solid var(--border); position: sticky; top: 0; z-index: 10; }
.top-in { display: flex; align-items: center; gap: 24px; min-height: 58px; flex-wrap: wrap; }
.brand { font-weight: 800; letter-spacing: .02em; text-decoration: none; font-size: 1.1rem; }
.brand span { font-weight: 400; color: var(--muted); margin-left: 4px; }
.brand-lg { font-size: 1.4rem; margin: 0 0 8px; }
.nav { display: flex; gap: 4px; flex-wrap: wrap; flex: 1; }
.nav a, .user a { text-decoration: none; padding: 6px 12px; border-radius: 999px; color: var(--muted); }
.nav a:hover, .user a:hover { color: var(--text); background: var(--surface-2); }
.nav a.on, .user a.on { color: var(--text); background: var(--surface-2); font-weight: 600; }
.user { display: flex; align-items: center; gap: 4px; }
.user form { margin: 0; }

/* ---------- Botones */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  padding: 8px 16px; border-radius: 8px; border: 1px solid var(--border);
  background: var(--surface); color: var(--text); font: inherit; font-weight: 500;
  text-decoration: none; cursor: pointer; white-space: nowrap;
}
.btn:hover { background: var(--surface-2); }
.btn-primary { background: var(--accent); color: var(--accent-text); border-color: var(--accent); }
.btn-primary:hover { background: var(--accent); opacity: .88; }
.btn-danger { color: var(--neg); border-color: currentColor; background: transparent; }
.btn-danger:hover { background: var(--neg); color: #fff; border-color: var(--neg); }
.btn-sm { padding: 5px 12px; font-size: .9rem; }
.btn-icon {
  width: 36px; height: 36px; border-radius: 8px; border: 1px solid var(--border);
  background: transparent; color: var(--muted); font-size: 1.3rem; line-height: 1; cursor: pointer; align-self: end;
}
.btn-icon:hover { color: var(--neg); border-color: var(--neg); }
button.link { background: none; border: 0; padding: 6px 12px; font: inherit; color: var(--muted); cursor: pointer; }
button.link:hover { color: var(--text); }
a.link { color: var(--info); text-decoration: none; }
a.link:hover { text-decoration: underline; }
.btn:focus-visible, a:focus-visible, button:focus-visible, input:focus-visible, select:focus-visible, textarea:focus-visible, summary:focus-visible {
  outline: 2px solid var(--info); outline-offset: 2px;
}

/* ---------- Formularios */
label { display: flex; flex-direction: column; gap: 4px; font-size: .85rem; color: var(--muted); font-weight: 500; }
input, select, textarea {
  font: inherit; font-size: .95rem; color: var(--text); background: var(--surface);
  border: 1px solid var(--border); border-radius: 8px; padding: 8px 10px; min-width: 0; width: 100%;
}
textarea { resize: vertical; }
input::placeholder, textarea::placeholder { color: var(--muted); opacity: .7; }
.check { flex-direction: row; align-items: center; gap: 8px; color: var(--text); font-weight: 400; font-size: .95rem; margin: 12px 0; }
.check input { width: auto; }
fieldset { border: 1px solid var(--border); border-radius: var(--radius); margin: 0; padding: 16px; }
legend { font-weight: 600; padding: 0 6px; }

.stack { display: flex; flex-direction: column; gap: 16px; }
.grid-3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px 16px; }
.span-2 { grid-column: span 2; }
.form-actions { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.form-actions .push { margin-left: auto; }

.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 20px; box-shadow: var(--shadow); }
.card.flush { padding: 0; overflow: hidden; }
.narrow { max-width: 480px; }
.stack > .card, main > .card, main > section.card { margin-bottom: 16px; }
.stack > .card { margin-bottom: 0; }

.page-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; margin-bottom: 20px; }
.actions { display: flex; gap: 8px; flex-wrap: wrap; }

.flash { padding: 10px 14px; border-radius: 8px; margin-bottom: 16px; border: 1px solid; font-size: .95rem; }
.flash ul { margin: 0; padding-left: 18px; }
.flash-ok { color: var(--pos); border-color: currentColor; background: color-mix(in srgb, var(--pos) 8%, transparent); }
.flash-error { color: var(--neg); border-color: currentColor; background: color-mix(in srgb, var(--neg) 8%, transparent); }
.flash-info { color: var(--info); border-color: currentColor; background: color-mix(in srgb, var(--info) 8%, transparent); }

/* ---------- Login */
.auth { min-height: 70vh; display: grid; place-items: center; }
.auth-card { width: 100%; max-width: 380px; background: var(--surface); border: 1px solid var(--border); border-radius: 14px; padding: 32px; box-shadow: var(--shadow); }
.auth-card h1 { font-size: 1.25rem; margin-bottom: 20px; }
.auth-wide { max-width: 760px; }

/* ---------- Filtros y resumen */
.filters { display: flex; gap: 12px; flex-wrap: wrap; align-items: end; margin-bottom: 16px; }
.filters label { min-width: 130px; }
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 12px; margin-bottom: 16px; }
.stat { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px 16px; }
.stat span { display: block; font-size: .8rem; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; }
.stat strong { font-size: 1.35rem; font-variant-numeric: tabular-nums; }
.tallas-resumen { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 16px; }
.tallas-resumen span { background: var(--surface); border: 1px solid var(--border); border-radius: 999px; padding: 3px 12px; font-size: .9rem; font-variant-numeric: tabular-nums; }
.tallas-resumen b { color: var(--muted); font-weight: 600; margin-right: 2px; }
.empty { text-align: center; padding: 40px 20px; color: var(--muted); }

/* ---------- Tablas */
.table-wrap { overflow-x: auto; }
.tbl { width: 100%; border-collapse: collapse; font-size: .92rem; }
.tbl th, .tbl td { padding: 9px 12px; text-align: left; border-bottom: 1px solid var(--border); vertical-align: top; }
.tbl th { font-size: .78rem; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); font-weight: 600; background: var(--surface-2); }
.tbl tbody tr:last-child td { border-bottom: 0; }
.tbl tfoot td { border-top: 1px solid var(--border); border-bottom: 0; background: var(--surface-2); }
.tbl tfoot tr.total td { font-weight: 700; }
.num { text-align: right !important; font-variant-numeric: tabular-nums; white-space: nowrap; }
.dim { color: var(--muted); opacity: .5; }

/* ---------- Pedidos (lista desplegable) */
.pedidos { display: flex; flex-direction: column; gap: 8px; }
.pedido-head, .pedido > summary {
  display: grid; grid-template-columns: 100px minmax(0, 1fr) 120px 80px 120px 110px; gap: 12px; align-items: center;
}
.pedido-head { padding: 0 44px 0 16px; font-size: .78rem; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); font-weight: 600; }
.pedido { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); }
.pedido > summary { list-style: none; cursor: pointer; padding: 14px 44px 14px 16px; position: relative; }
.pedido > summary::-webkit-details-marker { display: none; }
.pedido > summary::after {
  content: ""; position: absolute; right: 18px; top: 50%; width: 8px; height: 8px;
  border-right: 2px solid var(--muted); border-bottom: 2px solid var(--muted);
  transform: translateY(-70%) rotate(45deg); transition: transform .15s;
}
.pedido[open] > summary::after { transform: translateY(-30%) rotate(-135deg); }
.pedido > summary:hover { background: var(--surface-2); border-radius: var(--radius); }
.pedido[open] > summary { border-bottom: 1px solid var(--border); border-radius: var(--radius) var(--radius) 0 0; }
.p-prov { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.p-prov small { font-weight: 400; color: var(--muted); }
.p-total { font-weight: 700; }
.p-uds small { color: var(--muted); }
.pedido-body { padding: 16px; }
.pedido-body .table-wrap { border: 1px solid var(--border); border-radius: 8px; }
.pedido-actions { display: flex; gap: 8px; align-items: center; justify-content: flex-end; margin-top: 12px; flex-wrap: wrap; }
.pedido-actions .muted { margin-right: auto; }
.notas { background: var(--surface-2); border-radius: 8px; padding: 10px 12px; margin: 12px 0 0; font-size: .92rem; }

.badge { display: inline-block; padding: 2px 10px; border-radius: 999px; font-size: .8rem; font-weight: 600; border: 1px solid currentColor; }
.estado-pedido { color: var(--info); }
.estado-en_camino { color: var(--warn); }
.estado-recibido { color: var(--pos); }
.estado-incidencia { color: var(--neg); }

/* ---------- Formulario de pedido */
.linea { border: 1px solid var(--border); border-radius: 8px; padding: 14px; margin-bottom: 12px; background: var(--bg); }
.linea-top { display: grid; grid-template-columns: minmax(0, 2fr) minmax(0, 1fr) 150px 36px; gap: 12px; }
.tallas { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 12px; align-items: end; }
.talla { width: 64px; text-align: center; }
.talla span { font-weight: 700; color: var(--text); }
.talla input { text-align: center; padding: 8px 4px; }
.linea-res { margin-left: auto; display: flex; flex-direction: column; align-items: flex-end; font-variant-numeric: tabular-nums; }
.linea-res span { color: var(--muted); font-size: .85rem; }
.totales { display: flex; gap: 24px; flex-wrap: wrap; justify-content: flex-end; margin: 16px 0 0; padding-top: 16px; border-top: 1px solid var(--border); }
.totales div { text-align: right; }
.totales dt { font-size: .8rem; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; }
.totales dd { margin: 0; font-size: 1.15rem; font-weight: 600; font-variant-numeric: tabular-nums; }
.totales .grand dd { font-size: 1.5rem; font-weight: 800; }

.tipo-toggle { display: inline-flex; border: 1px solid var(--border); border-radius: 8px; overflow: hidden; align-self: flex-start; }
.tipo-toggle label { flex-direction: row; margin: 0; }
.tipo-toggle input { position: absolute; opacity: 0; width: 1px; height: 1px; }
.tipo-toggle span { padding: 8px 20px; cursor: pointer; font-size: .95rem; color: var(--muted); }
.tipo-toggle input:checked + span { background: var(--accent); color: var(--accent-text); }
.tipo-toggle input:focus-visible + span { outline: 2px solid var(--info); outline-offset: -2px; }

/* ---------- Móvil */
@media (max-width: 860px) {
  .grid-3 { grid-template-columns: 1fr 1fr; }
  .pedido-head { display: none; }
  .pedido > summary { grid-template-columns: 1fr auto; gap: 4px 12px; }
  .p-fecha { order: 1; color: var(--muted); font-size: .85rem; }
  .p-total { order: 2; }
  .p-prov { order: 3; }
  .p-uds { order: 4; }
  .pedido > summary > span:nth-child(3) { order: 5; }
  .p-quien { order: 6; text-align: right; color: var(--muted); font-size: .85rem; }
}
@media (max-width: 600px) {
  h1 { font-size: 1.35rem; }
  .grid-3 { grid-template-columns: 1fr; }
  .span-2 { grid-column: auto; }
  .linea-top { grid-template-columns: 1fr 1fr; }
  .linea-top label:first-child { grid-column: 1 / -1; }
  .btn-icon { grid-column: 2; justify-self: end; }
  .top-in { gap: 8px; padding-top: 8px; padding-bottom: 8px; }
  .nav { order: 3; flex-basis: 100%; overflow-x: auto; flex-wrap: nowrap; }
  .nav a { white-space: nowrap; }
  .user { margin-left: auto; }
  .filters label { min-width: calc(50% - 6px); flex: 1; }
  .form-actions .push { margin-left: 0; }
  .auth-card { padding: 24px; }
}
