/* Panel de administración de DalePuja — tema oscuro, denso, sin adornos. */

:root {
  --bg: #0c0e18;
  --surface: #141727;
  --surface-2: #1b1f33;
  --surface-3: #232843;
  --border: #2a3050;
  --text: #e9ebf7;
  --muted: #8d93b5;
  --accent: #ff3d8b;
  --accent-2: #7b5cff;
  --green: #2ed47a;
  --red: #ff5468;
  --amber: #ffb020;
  --blue: #4aa8ff;
  --violet: #a98bff;
  --radius: 10px;
  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, "Cascadia Mono", Consolas, "Liberation Mono", monospace;
  color-scheme: dark;
}

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

html, body { margin: 0; background: var(--bg); color: var(--text); }
body { font: 14px/1.45 var(--font); -webkit-font-smoothing: antialiased; }

a { color: var(--blue); }
a:hover { color: #8cc8ff; }
code { font-family: var(--mono); color: var(--muted); word-break: break-all; }
h1, h2, h3 { margin: 0; line-height: 1.2; }
h1 { font-size: 22px; display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
p { margin: 0; }

:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.sr-only {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}

.muted { color: var(--muted); }
.small { font-size: 12px; }
.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.pos { color: var(--green); }
.neg { color: var(--red); }
.stack { display: inline-flex; flex-direction: column; gap: 1px; }
.num .stack { align-items: flex-end; }
.stack-gap { display: grid; gap: 12px; }
.view-stack { display: grid; grid-template-columns: minmax(0, 1fr); gap: 14px; }
.view-stack > * { min-width: 0; }

/* --- arranque y login ---------------------------------------------------- */

.boot { min-height: 100vh; display: grid; place-items: center; }
.boot-msg { color: var(--muted); text-align: center; padding: 40px; }

.login-wrap {
  min-height: 100vh; display: grid; place-items: center; padding: 20px;
  background:
    radial-gradient(600px 300px at 20% 0%, rgba(255, 61, 139, 0.14), transparent 70%),
    radial-gradient(600px 300px at 100% 100%, rgba(123, 92, 255, 0.16), transparent 70%),
    var(--bg);
}
.login-card {
  width: 100%; max-width: 380px; background: var(--surface); border: 1px solid var(--border);
  border-radius: 14px; padding: 28px 24px; display: grid; gap: 14px;
}
.login-form { display: grid; gap: 12px; }
.login-msg { border-radius: 8px; padding: 10px 12px; font-size: 13px; }
.login-msg-error { background: rgba(255, 84, 104, 0.12); border: 1px solid rgba(255, 84, 104, 0.45); color: #ffb3bd; }
.login-msg-warn { background: rgba(255, 176, 32, 0.1); border: 1px solid rgba(255, 176, 32, 0.4); color: #ffd58a; }

.brand { display: flex; align-items: center; gap: 10px; font-weight: 700; font-size: 16px; }
.brand-mark {
  display: inline-grid; place-items: center; width: 34px; height: 34px; border-radius: 9px;
  background: linear-gradient(135deg, var(--accent), var(--accent-2)); color: #fff; font-size: 12px; font-weight: 800;
}

/* --- armazón -------------------------------------------------------------- */

.shell { display: grid; grid-template-columns: 228px minmax(0, 1fr); min-height: 100vh; }
.side {
  position: sticky; top: 0; height: 100vh; display: flex; flex-direction: column; gap: 18px;
  padding: 18px 12px; background: var(--surface); border-right: 1px solid var(--border);
}
.side > .brand { padding: 0 8px; }
.nav { display: flex; flex-direction: column; gap: 2px; }
.nav-link {
  display: block; padding: 9px 12px; border-radius: 8px; color: var(--muted); text-decoration: none; font-weight: 600;
  border-left: 3px solid transparent;
}
.nav-link:hover { background: var(--surface-2); color: var(--text); }
.nav-link.is-active { background: var(--surface-3); color: var(--text); border-left-color: var(--accent); }
.side-foot { margin-top: auto; display: grid; gap: 6px; padding: 0 8px; font-size: 12px; }
.side-user { font-weight: 700; font-size: 13px; overflow: hidden; text-overflow: ellipsis; }
.side-mode { color: var(--muted); }
.side-foot .btn { justify-self: start; margin-top: 4px; }

.live-dot { display: inline-flex; align-items: center; gap: 6px; color: var(--green); font-weight: 600; }
.live-dot::before { content: ""; width: 8px; height: 8px; border-radius: 50%; background: currentColor; }
.live-dot.is-off { color: var(--amber); }

.content { min-width: 0; display: flex; flex-direction: column; }
.main { padding: 22px 26px 60px; display: grid; grid-template-columns: minmax(0, 1fr); gap: 16px; align-content: start; outline: none; }
.main > * { min-width: 0; }

.banner { padding: 10px 26px; font-size: 13px; border-bottom: 1px solid; }
.banner-test {
  background: repeating-linear-gradient(-45deg, rgba(255, 176, 32, 0.16) 0 12px, rgba(255, 176, 32, 0.08) 12px 24px);
  border-color: rgba(255, 176, 32, 0.55); color: #ffe0a3;
}
.banner-off { background: rgba(255, 84, 104, 0.12); border-color: rgba(255, 84, 104, 0.5); color: #ffc2ca; }
.banner-inline { border: 1px solid rgba(255, 176, 32, 0.55); border-radius: var(--radius); padding: 12px 14px; }

.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 12px; flex-wrap: wrap; }
.page-head p { margin-top: 4px; }
.section-title { font-size: 13px; text-transform: uppercase; letter-spacing: 0.06em; color: var(--muted); margin-top: 8px; }
.crumbs a { color: var(--muted); text-decoration: none; font-weight: 600; }
.crumbs a:hover { color: var(--text); }

/* --- botones y campos ------------------------------------------------------- */

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px; min-height: 36px;
  padding: 0 14px; border-radius: 8px; border: 1px solid var(--border); background: var(--surface-2);
  color: var(--text); font: inherit; font-weight: 600; cursor: pointer; text-decoration: none; white-space: nowrap;
}
.btn:hover { background: var(--surface-3); }
.btn:disabled, .btn.is-busy { opacity: 0.55; cursor: progress; }
.btn-sm { min-height: 30px; padding: 0 10px; font-size: 13px; }
.btn-block { width: 100%; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn-primary:hover { background: #ff5c9f; }
.btn-danger { background: var(--red); border-color: var(--red); color: #fff; }
.btn-danger:hover { background: #ff6f80; }
.btn-ghost { background: transparent; }
.btn-danger-ghost { background: transparent; color: #ff8e9c; border-color: rgba(255, 84, 104, 0.45); }
.btn-danger-ghost:hover { background: rgba(255, 84, 104, 0.12); }

.field { display: grid; gap: 5px; min-width: 0; }
.field > label, .field-label { font-size: 12px; font-weight: 600; color: var(--muted); }
.hint { color: var(--muted); font-size: 12px; }
.field-check { display: flex; align-items: center; gap: 8px; align-self: end; min-height: 38px; }
.field-check > label { color: var(--text); font-size: 14px; font-weight: 500; }
.field-check input { width: 18px; height: 18px; accent-color: var(--accent); }

input[type="text"], input[type="email"], input[type="password"], input[type="number"], input[type="url"],
input[type="search"], input[type="datetime-local"], select, textarea {
  width: 100%; min-height: 38px; padding: 7px 10px; border-radius: 8px; border: 1px solid var(--border);
  background: var(--bg); color: var(--text); font: inherit;
}
textarea { resize: vertical; min-height: 70px; }
input:focus, select:focus, textarea:focus { border-color: var(--accent-2); outline: none; box-shadow: 0 0 0 3px rgba(123, 92, 255, 0.25); }
input[type="number"] { font-variant-numeric: tabular-nums; }
.select-sm { min-height: 30px; padding: 3px 6px; font-size: 13px; width: auto; }

.toolbar { display: flex; align-items: flex-end; gap: 12px; flex-wrap: wrap; }
.toolbar .field { min-width: 180px; }
.search { flex: 1 1 280px; max-width: 460px; }

.seg { display: flex; flex-wrap: wrap; gap: 6px; }
.seg-btn {
  display: inline-flex; align-items: center; gap: 8px; min-height: 32px; padding: 0 12px; border-radius: 999px;
  border: 1px solid var(--border); background: var(--surface); color: var(--muted); font: inherit; font-weight: 600; cursor: pointer;
}
.seg-btn:hover { color: var(--text); }
.seg-btn.is-on { background: var(--surface-3); border-color: var(--accent); color: var(--text); }
.seg-count { font-size: 12px; padding: 0 6px; border-radius: 999px; background: var(--bg); font-variant-numeric: tabular-nums; }

/* --- tarjetas y números ------------------------------------------------------ */

.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px; }
.card-title { font-size: 16px; margin-bottom: 4px; }

.stats { display: grid; grid-template-columns: repeat(auto-fill, minmax(210px, 1fr)); gap: 10px; }
.stats-tight { grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); }
.stat {
  display: grid; gap: 4px; align-content: start; padding: 14px; border-radius: var(--radius);
  background: var(--surface); border: 1px solid var(--border); border-top: 3px solid var(--border);
  color: var(--text); text-decoration: none;
}
.stat-link:hover { background: var(--surface-2); color: var(--text); }
.stat-label { font-size: 12px; font-weight: 600; color: var(--muted); }
.stat-value { font-size: 22px; font-weight: 750; font-variant-numeric: tabular-nums; }
.stat-big .stat-value { font-size: 28px; }
.stat-note { font-size: 12px; color: var(--muted); }
.stat-words .stat-value { font-size: 16px; text-decoration: none; }
.stat-green { border-top-color: var(--green); }
.stat-green .stat-value { color: var(--green); }
.stat-blue { border-top-color: var(--blue); }
.stat-amber { border-top-color: var(--amber); }
.stat-amber .stat-value { color: var(--amber); }
.stat-red { border-top-color: var(--red); }
.stat-pink { border-top-color: var(--accent); }
.stat-test {
  border-top-color: var(--amber); border-style: dashed; border-top-style: solid;
  background: repeating-linear-gradient(-45deg, rgba(255, 176, 32, 0.06) 0 10px, transparent 10px 20px), var(--surface);
}
.stat-test .stat-value { color: #d9b46a; text-decoration: line-through rgba(255, 176, 32, 0.35); }

.totals { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 16px; }
.total { padding: 6px 10px; border-radius: 8px; border: 1px solid var(--border); background: var(--surface); }
.total b { font-variant-numeric: tabular-nums; }
.total-green b { color: var(--green); }
.total-amber b { color: var(--amber); }
.total-test { border-style: dashed; border-color: rgba(255, 176, 32, 0.55); color: #ffdc9a; }

/* --- chips ----------------------------------------------------------------- */

.chip {
  display: inline-flex; align-items: center; gap: 5px; padding: 2px 8px; border-radius: 999px; font-size: 12px; font-weight: 700;
  border: 1px solid currentColor; white-space: nowrap; line-height: 1.5;
}
.chip::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.chip-xs { font-size: 11px; padding: 0 6px; }
.chip-xs::before { display: none; }
.chip-green { color: var(--green); background: rgba(46, 212, 122, 0.1); }
.chip-blue { color: var(--blue); background: rgba(74, 168, 255, 0.1); }
.chip-gray { color: #aab0cf; background: rgba(170, 176, 207, 0.08); }
.chip-red { color: var(--red); background: rgba(255, 84, 104, 0.1); }
.chip-amber { color: var(--amber); background: rgba(255, 176, 32, 0.1); }
.chip-violet { color: var(--violet); background: rgba(169, 139, 255, 0.12); }
.chip-pink { color: var(--accent); background: rgba(255, 61, 139, 0.1); }
h1 .chip { font-size: 12px; }

/* --- tablas ---------------------------------------------------------------- */

.table-wrap { overflow-x: auto; border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface); -webkit-overflow-scrolling: touch; }
table.grid { width: 100%; border-collapse: collapse; font-size: 13px; }
.grid th {
  position: sticky; top: 0; background: var(--surface-2); color: var(--muted); font-size: 11px; font-weight: 700;
  text-transform: uppercase; letter-spacing: 0.04em; text-align: left; padding: 9px 10px; white-space: nowrap;
  border-bottom: 1px solid var(--border);
}
.grid th.num { text-align: right; }
.grid td { padding: 8px 9px; border-bottom: 1px solid rgba(42, 48, 80, 0.6); vertical-align: middle; }
.grid tbody tr:last-child td { border-bottom: 0; }
.grid tbody tr:hover td { background: rgba(255, 255, 255, 0.02); }
.grid tr.row-test td { background: rgba(255, 176, 32, 0.035); }
.grid tr.flash td { animation: flash 1.2s ease-out; }
@keyframes flash { from { background: rgba(255, 61, 139, 0.18); } to { background: transparent; } }
@media (prefers-reduced-motion: reduce) { .grid tr.flash td { animation: none; } }

.link-strong { color: var(--text); font-weight: 700; text-decoration: none; display: inline-flex; align-items: center; gap: 6px; }
.link-strong:hover { color: var(--accent); }
.link-plain { color: var(--text); text-decoration: none; }
.link-plain:hover { color: var(--blue); }

.col-prod { min-width: 230px; }
.col-clock { min-width: 120px; }
.col-clock .small, .clock { white-space: nowrap; }
.grid .cell-wrap { display: inline-block; white-space: normal; max-width: 130px; text-align: inherit; }
.prod { display: flex; align-items: center; gap: 10px; }
.prod-txt { display: grid; gap: 2px; min-width: 0; }
.prod-title { font-weight: 700; }
.prod-meta { display: flex; flex-wrap: wrap; gap: 4px 6px; align-items: center; }
.thumb { width: 44px; height: 44px; border-radius: 8px; object-fit: cover; background: var(--surface-3); flex: none; }
.img-ph {
  display: grid; place-items: center; background: linear-gradient(135deg, rgba(255, 61, 139, 0.2), rgba(123, 92, 255, 0.2)), var(--surface-3);
  color: var(--muted); font-size: 10px; text-align: center; line-height: 1.1;
}

.clock { font-family: var(--mono); font-weight: 700; font-size: 15px; color: var(--green); font-variant-numeric: tabular-nums; }
.clock.is-urgent { color: var(--red); }
.clock-soft { font-size: 13px; color: var(--blue); }

.delta { font-weight: 700; font-size: 12px; }
.delta-ok { color: var(--green); }
.delta-bad { color: var(--red); }

.row-actions { display: flex; gap: 6px; }
.status-edit { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }

/* --- estados ------------------------------------------------------------------- */

.state { padding: 28px 16px; text-align: center; color: var(--muted); border: 1px dashed var(--border); border-radius: var(--radius); display: grid; gap: 10px; justify-items: center; }
.state-loading { display: flex; justify-content: center; align-items: center; gap: 10px; }
.state-error { color: #ffb3bd; border-color: rgba(255, 84, 104, 0.45); }
.spinner { width: 16px; height: 16px; border-radius: 50%; border: 2px solid var(--border); border-top-color: var(--accent); animation: spin 0.8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

.form-error, .modal-error { padding: 9px 12px; border-radius: 8px; background: rgba(255, 84, 104, 0.12); border: 1px solid rgba(255, 84, 104, 0.45); color: #ffb3bd; font-size: 13px; }
.callout { padding: 10px 12px; border-radius: 8px; font-size: 13px; }
.callout-warn { background: rgba(255, 176, 32, 0.1); border: 1px solid rgba(255, 176, 32, 0.45); color: #ffdc9a; }

/* --- formulario de alta + simulador ---------------------------------------------- */

.form-card { padding: 18px; }
.form-grid { display: grid; grid-template-columns: minmax(0, 1fr) 320px; gap: 20px; align-items: start; }
.form-main { display: grid; gap: 14px; }
.cols-2 { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; align-items: start; }
.cols-2 .field-check { align-self: start; margin-top: 22px; }
.form-actions { display: flex; justify-content: flex-end; gap: 8px; }

.sim {
  position: sticky; top: 16px; border-radius: var(--radius); padding: 14px; display: grid; gap: 10px;
  background: linear-gradient(160deg, rgba(123, 92, 255, 0.14), rgba(255, 61, 139, 0.08)), var(--surface-2);
  border: 1px solid rgba(123, 92, 255, 0.45);
}
.sim-title { font-size: 13px; text-transform: uppercase; letter-spacing: 0.06em; color: var(--violet); }
.sim-body { display: grid; gap: 8px; }
.sim-main { font-size: 14px; }
.sim-n { color: var(--accent); font-size: 18px; }
.sim-warn { color: var(--amber); font-size: 13px; }
.sim-dl { display: grid; grid-template-columns: auto 1fr; gap: 4px 10px; margin: 4px 0 0; font-size: 12px; }
.sim-dl dt { color: var(--muted); }
.sim-dl dd { margin: 0; }

.picker { display: flex; gap: 12px; align-items: flex-start; }
.pick-preview { flex: none; }
.pick-img { width: 96px; height: 96px; border-radius: 10px; object-fit: cover; border: 1px solid var(--border); }
.pick-controls { display: grid; gap: 6px; flex: 1; min-width: 0; }
.pick-row { display: flex; gap: 6px; flex-wrap: wrap; }
.pick-or { font-size: 12px; color: var(--muted); }

.adjust { display: grid; gap: 12px; }
.adjust-row { display: grid; grid-template-columns: 140px 140px minmax(0, 1fr); gap: 12px; }

/* --- modal ------------------------------------------------------------------ */

.modal {
  width: min(460px, calc(100vw - 24px)); max-height: calc(100vh - 32px); padding: 0; border-radius: 14px;
  border: 1px solid var(--border); background: var(--surface); color: var(--text);
}
.modal-wide { width: min(640px, calc(100vw - 24px)); }
.modal::backdrop { background: rgba(5, 6, 12, 0.72); }
.modal-form { display: grid; gap: 14px; padding: 20px; }
.modal-title { font-size: 18px; }
.modal-actions { display: flex; justify-content: flex-end; gap: 8px; flex-wrap: wrap; }

.balance-change { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 12px; border-radius: 10px; background: var(--bg); border: 1px solid var(--border); }
.big-num { font-size: 22px; font-weight: 800; font-variant-numeric: tabular-nums; }

/* --- avisos ------------------------------------------------------------------- */

.toasts { position: fixed; right: 16px; bottom: 16px; z-index: 1000; display: grid; gap: 8px; width: min(380px, calc(100vw - 32px)); }
.toast {
  display: grid; grid-template-columns: auto 1fr auto; gap: 10px; align-items: start; padding: 10px 12px; border-radius: 10px;
  background: var(--surface-2); border: 1px solid var(--border); border-left: 4px solid var(--green); box-shadow: 0 8px 24px rgba(0, 0, 0, 0.4);
}
.toast-error { border-left-color: var(--red); }
.toast-warn { border-left-color: var(--amber); }
.toast-tag { font-size: 11px; font-weight: 800; text-transform: uppercase; color: var(--green); padding-top: 2px; }
.toast-error .toast-tag { color: var(--red); }
.toast-warn .toast-tag { color: var(--amber); }
.toast-msg { font-size: 13px; }
.toast-x { background: none; border: 0; color: var(--muted); font-size: 18px; line-height: 1; cursor: pointer; padding: 0 2px; }

/* --- teléfono ------------------------------------------------------------------- */

@media (max-width: 980px) {
  .form-grid { grid-template-columns: minmax(0, 1fr); }
  .sim { position: static; }
}

@media (max-width: 820px) {
  .shell { grid-template-columns: minmax(0, 1fr); }
  .side {
    position: sticky; top: 0; z-index: 50; height: auto; flex-direction: row; align-items: center; flex-wrap: wrap;
    gap: 8px 12px; padding: 10px 12px; border-right: 0; border-bottom: 1px solid var(--border);
  }
  .side > .brand { padding: 0; }
  .nav { order: 3; flex-direction: row; width: 100%; overflow-x: auto; gap: 4px; padding-bottom: 2px; scrollbar-width: none; }
  .nav-link { white-space: nowrap; border-left: 0; border-bottom: 2px solid transparent; padding: 7px 10px; font-size: 13px; }
  .nav-link.is-active { border-bottom-color: var(--accent); }
  .side-foot { margin: 0 0 0 auto; padding: 0; grid-auto-flow: column; align-items: center; gap: 10px; }
  .side-mode, .side-user { display: none; }
  .side-foot .btn { margin: 0; }
  .main { padding: 16px 12px 60px; }
  .banner { padding: 8px 12px; }
  .cols-2, .adjust-row { grid-template-columns: minmax(0, 1fr); }
  .stats { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .stat-value { font-size: 18px; }
  .stat-big .stat-value { font-size: 20px; }
  .toolbar .field { min-width: 0; flex: 1 1 140px; }
  .picker { flex-direction: column; align-items: stretch; }
  .pick-controls { width: 100%; }
}

@media (max-width: 300px) {
  .stats { grid-template-columns: minmax(0, 1fr); }
}

/* Usuarios sin email (registro rápido) */
.no-email { color: var(--muted); font-style: italic; opacity: 0.8; }

/* Insignia de la cuenta de la casa (postor automático hasta el precio mínimo). */
.chip-house { align-self: flex-start; justify-self: start; width: max-content; font-weight: 800; letter-spacing: 0.08em; color: #0f2a44; background: #d7e6f2; }

/* Demo local (usuarios simulados) */
.demo-card { display: flex; flex-direction: column; gap: 10px; max-width: 640px; }
.demo-card p { margin: 0; }
.demo-card > div { display: flex; flex-direction: column; gap: 12px; }
.demo-row { display: flex; align-items: flex-end; gap: 10px; flex-wrap: wrap; }
.demo-row .field { flex: 1 1 180px; margin: 0; }
.demo-row .btn { margin-bottom: 22px; }
.demo-switch { align-self: flex-start; }
.demo-switch.is-on { color: #0b1a10; background: var(--green); border-color: var(--green); }

/* Ajustes de subastas: precio mínimo promedio y rotación */
.settings-card { margin-bottom: 16px; }
.settings-form { display: grid; gap: 14px; }
.settings-row { display: grid; grid-template-columns: 220px repeat(3, minmax(0, 200px)); gap: 14px; align-items: end; }
.settings-row h2 { margin: 0; font-size: 1rem; align-self: center; }
.settings-row .check { display: flex; align-items: center; gap: 8px; padding-bottom: 8px; }
.settings-form .btn { justify-self: start; }
@media (max-width: 760px) { .settings-row { grid-template-columns: minmax(0, 1fr); } }
