/* ===== Sistema de diseño — Abastecimiento Inteligente (Grupo Safed) ===== */
:root {
  --radius: 10px;
  --radius-sm: 7px;
  --gap: 16px;
  --maxw: 1780px;
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  --mono: ui-monospace, "SF Mono", "Cascadia Code", Consolas, monospace;
  --shadow: 0 1px 2px rgba(0,0,0,.06), 0 8px 24px rgba(0,0,0,.06);
  --t: .16s ease;
}

/* ---- Tema oscuro (por defecto) ---- */
:root, :root[data-theme="dark"] {
  --bg: #0b0e14;
  --bg-elev: #111722;
  --card: #141b28;
  --card-2: #0f1420;
  --line: #222c3d;
  --line-soft: #1a2230;
  --txt: #e8ecf3;
  --txt-2: #aeb9cc;
  --muted: #7c889d;
  --accent: #4f8cff;
  --accent-ink: #ffffff;
  --accent-soft: rgba(79,140,255,.14);
  --eco: #34d399;
  --eco-soft: rgba(52,211,153,.14);
  --prem: #fbbf24;
  --prem-soft: rgba(251,191,36,.14);
  --danger: #f87171;
  --danger-soft: rgba(248,113,113,.14);
  --ok: #34d399;
}
/* ---- Tema claro ---- */
:root[data-theme="light"] {
  --bg: #f4f6fb;
  --bg-elev: #ffffff;
  --card: #ffffff;
  --card-2: #f7f9fc;
  --line: #e2e7f0;
  --line-soft: #eef1f7;
  --txt: #16202e;
  --txt-2: #45536b;
  --muted: #8592a6;
  --accent: #2f6bef;
  --accent-ink: #ffffff;
  --accent-soft: rgba(47,107,239,.10);
  --eco: #0f9d6b;
  --eco-soft: rgba(15,157,107,.12);
  --prem: #b7791f;
  --prem-soft: rgba(183,121,31,.14);
  --danger: #dc2626;
  --danger-soft: rgba(220,38,38,.10);
  --ok: #0f9d6b;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--txt);
  font: 14px/1.55 var(--font); -webkit-font-smoothing: antialiased;
}

/* ---------- Barra superior ---------- */
.topbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; gap: 24px;
  padding: 0 24px; height: 60px;
  background: color-mix(in srgb, var(--bg-elev) 88%, transparent);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: 12px; min-width: 0; }
.brand-mark {
  width: 36px; height: 36px; border-radius: 9px; flex: none;
  display: grid; place-items: center; font-weight: 800; letter-spacing: .5px;
  color: var(--accent-ink); background: linear-gradient(135deg, var(--accent), #7aa8ff);
}
.brand-text { display: flex; flex-direction: column; line-height: 1.25; min-width: 0; }
.brand-text strong { font-size: 15px; }
.brand-text span { font-size: 11.5px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.tabs { display: flex; gap: 4px; margin-left: 8px; }
.tab {
  appearance: none; border: 0; background: transparent; cursor: pointer;
  color: var(--txt-2); font: inherit; font-weight: 500; padding: 8px 14px;
  border-radius: var(--radius-sm); position: relative; transition: var(--t);
}
.tab:hover { color: var(--txt); background: var(--card-2); }
.tab.is-active { color: var(--accent); }
.tab.is-active::after {
  content: ""; position: absolute; left: 14px; right: 14px; bottom: -11px; height: 2px;
  background: var(--accent); border-radius: 2px;
}
.topbar-actions { margin-left: auto; display: flex; gap: 8px; align-items: center; }

/* ---------- Layout ---------- */
main { max-width: var(--maxw); margin: 0 auto; padding: 22px clamp(16px, 3vw, 40px) 64px; }
.view { display: none; animation: fade .18s ease; }
.view.is-active { display: block; }
@keyframes fade { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: none; } }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: var(--gap); align-items: start; }
@media (max-width: 980px) { .grid-2 { grid-template-columns: 1fr; } }
.stack { display: flex; flex-direction: column; gap: var(--gap); }
.stack > .card { margin-bottom: 0; }

/* ---------- KPIs ---------- */
.kpis { display: grid; grid-template-columns: repeat(4, 1fr); gap: var(--gap); margin-bottom: var(--gap); }
@media (max-width: 900px) { .kpis { grid-template-columns: repeat(2, 1fr); } }
.kpi {
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 16px 18px; display: flex; flex-direction: column; gap: 2px;
}
.kpi-label { font-size: 12px; color: var(--muted); text-transform: uppercase; letter-spacing: .5px; }
.kpi-value { font-size: 30px; font-weight: 700; letter-spacing: -.5px; font-variant-numeric: tabular-nums; }
.kpi-sub { font-size: 12px; color: var(--txt-2); }
.kpi.warn .kpi-value { color: var(--prem); }

/* ---------- Cards ---------- */
.card {
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 18px 20px; margin-bottom: var(--gap); box-shadow: var(--shadow);
}
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 14px; }
.card-head h2 { margin: 0; font-size: 15px; font-weight: 650; display: flex; align-items: center; gap: 10px; }
.card-actions { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.card-actions.end { justify-content: flex-end; margin-top: 16px; }
.hint { color: var(--muted); font-size: 12.5px; margin: 8px 0 0; }
.pill { font-size: 12px; font-weight: 600; color: var(--accent); background: var(--accent-soft); padding: 2px 9px; border-radius: 999px; }

/* ---------- Formularios ---------- */
.field-row { display: flex; gap: 12px; flex-wrap: wrap; align-items: flex-end; margin-bottom: 12px; }
.field { display: flex; flex-direction: column; gap: 5px; min-width: 90px; }
.field.grow { flex: 1 1 200px; }
.field > span { font-size: 12px; color: var(--txt-2); font-weight: 500; }
input, select, textarea {
  background: var(--card-2); border: 1px solid var(--line); color: var(--txt);
  padding: 9px 11px; border-radius: var(--radius-sm); font: inherit; width: 100%;
  transition: var(--t);
}
input:focus, select:focus, textarea:focus {
  outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft);
}
input::placeholder, textarea::placeholder { color: var(--muted); }
textarea { resize: vertical; font-family: var(--mono); font-size: 13px; margin: 10px 0; }
.field.grow input, .field input, .field select { min-width: 0; }
.end { align-self: flex-end; }
details summary { cursor: pointer; color: var(--txt-2); font-size: 13px; margin-top: 6px; user-select: none; }
details[open] summary { margin-bottom: 4px; }

/* ---------- Botones ---------- */
.btn {
  appearance: none; cursor: pointer; font: inherit; font-weight: 550;
  border: 1px solid var(--line); background: var(--card-2); color: var(--txt);
  padding: 9px 15px; border-radius: var(--radius-sm); transition: var(--t); white-space: nowrap;
}
.btn:hover { border-color: color-mix(in srgb, var(--accent) 40%, var(--line)); }
.btn:active { transform: translateY(1px); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.primary:hover { filter: brightness(1.08); }
.btn.secondary { background: var(--accent-soft); border-color: transparent; color: var(--accent); }
.btn.ghost { background: transparent; }
.btn.sm { padding: 7px 12px; font-size: 13px; }
.btn.icon { padding: 7px 10px; }
.btn:disabled { opacity: .5; cursor: not-allowed; transform: none; filter: none; }
a.btn { text-decoration: none; display: inline-flex; align-items: center; }

/* ---------- Tablas ---------- */
.table-wrap { overflow: auto; border: 1px solid var(--line); border-radius: var(--radius); }
.table-wrap.short { max-height: 320px; }
table.data { width: 100%; border-collapse: collapse; font-size: 13px; }
table.data th, table.data td { text-align: left; padding: 9px 12px; white-space: nowrap; border-bottom: 1px solid var(--line-soft); }
table.data thead th {
  position: sticky; top: 0; z-index: 1; background: var(--card-2);
  color: var(--muted); font-weight: 600; font-size: 11.5px; text-transform: uppercase; letter-spacing: .4px;
  cursor: pointer; user-select: none;
}
table.data thead th.sortable::after { content: " ⇅"; color: var(--muted); opacity: .5; font-size: 10px; }
table.data thead th.sort-asc::after { content: " ↑"; color: var(--accent); opacity: 1; }
table.data thead th.sort-desc::after { content: " ↓"; color: var(--accent); opacity: 1; }
table.data tbody tr { transition: background var(--t); }
table.data tbody tr:hover { background: var(--card-2); }
table.data tbody tr:last-child td { border-bottom: 0; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
/* especificidad: debe ganar a `table.data td { white-space: nowrap }`, si no el texto
   largo se derrama fuera de la celda y se encima al vecino. */
table.data td.wrap { white-space: normal; max-width: 360px; min-width: 240px; }
table.data td.trunc { max-width: 190px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
/* título de producto: máx. 2 líneas + "…" (el completo está en el detalle al hacer clic) */
.clamp2 {
  display: -webkit-box; -webkit-line-clamp: 2; line-clamp: 2; -webkit-box-orient: vertical;
  overflow: hidden; word-break: break-word;
}
td.strong { font-weight: 700; }
.muted { color: var(--muted); }
.empty { padding: 28px; text-align: center; color: var(--muted); }
.compare td.cost { color: var(--txt); font-weight: 700; }
td.vol { color: var(--eco); }
.vol-ex { color: var(--eco); }
.ahorro { font-size: 10.5px; font-weight: 700; opacity: .85; }
.uv { font-size: 10.5px; color: var(--muted); }
.incog { color: var(--prem); font-weight: 700; cursor: help; }
.desde {
  font-size: 9.5px; font-weight: 700; text-transform: uppercase; letter-spacing: .3px;
  color: var(--prem); background: var(--prem-soft); padding: 1px 5px; border-radius: 4px; cursor: help;
}

/* ---------- Badges ---------- */
.badge { display: inline-block; padding: 2px 9px; border-radius: 999px; font-size: 11px; font-weight: 650; letter-spacing: .2px; }
.badge.economico, .badge.hecho { background: var(--eco-soft); color: var(--eco); }
.badge.premium { background: var(--prem-soft); color: var(--prem); }
.badge.pendiente { background: var(--line); color: var(--txt-2); }
.badge.procesando { background: var(--accent-soft); color: var(--accent); }
.badge.error { background: var(--danger-soft); color: var(--danger); }
.badge.cat { background: var(--accent-soft); color: var(--accent); font-weight: 600; }
.badge.riesgo-bajo { background: var(--line); color: var(--muted); }
.badge.riesgo-medio { background: var(--prem-soft); color: var(--prem); cursor: help; }
.badge.riesgo-alto { background: var(--danger-soft); color: var(--danger); cursor: help; }
.legend { color: var(--muted); font-size: 12px; margin: 12px 2px 0; display: flex; gap: 10px; flex-wrap: wrap; align-items: center; }
.search { max-width: 240px; }
.check { display: inline-flex; align-items: center; gap: 6px; font-size: 13px; color: var(--txt-2); white-space: nowrap; }
.check input { width: auto; }

/* ---------- Ajustes ---------- */
.settings { display: flex; flex-direction: column; gap: 0; }
.set-item {
  display: flex; align-items: center; justify-content: space-between; gap: 20px;
  padding: 14px 0; border-bottom: 1px solid var(--line-soft);
}
.set-item:last-child { border-bottom: 0; }
.set-text { min-width: 0; }
.set-label { font-weight: 550; }
.set-help { color: var(--muted); font-size: 12px; margin-top: 2px; }
.set-input { flex: none; display: flex; align-items: center; gap: 7px; }
.set-input input, .set-input select { width: 120px; }
.set-input input.wide { width: 260px; font-family: var(--mono); font-size: 12.5px; }
.set-input .unit { color: var(--muted); font-size: 13px; }
.set-default { font-size: 11px; color: var(--muted); white-space: nowrap; }

/* ---------- Flow list ---------- */
.flow { margin: 0; padding-left: 20px; color: var(--txt-2); font-size: 13px; line-height: 1.9; }
.flow b { color: var(--txt); }

/* ---------- Log ---------- */
.log {
  background: var(--card-2); border: 1px solid var(--line); border-radius: var(--radius-sm);
  padding: 12px; margin: 12px 0 0; max-height: 200px; overflow: auto;
  font: 12px/1.6 var(--mono); color: var(--txt-2); white-space: pre-wrap;
}

/* ---------- Drawer de detalle ---------- */
.drawer { position: fixed; inset: 0; z-index: 40; }
.drawer[hidden] { display: none; }
.drawer-backdrop { position: absolute; inset: 0; background: rgba(0,0,0,.5); animation: fade .15s ease; }
.drawer-panel {
  position: absolute; top: 0; right: 0; height: 100%; width: min(560px, 94vw);
  background: var(--bg-elev); border-left: 1px solid var(--line);
  box-shadow: -12px 0 40px rgba(0,0,0,.28); display: flex; flex-direction: column;
  animation: slideIn .22s ease;
}
@keyframes slideIn { from { transform: translateX(20px); opacity: .6; } to { transform: none; opacity: 1; } }
.drawer-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 16px 20px; border-bottom: 1px solid var(--line); }
.drawer-head h3 { margin: 0; font-size: 15px; }
.drawer-body { padding: 18px 20px; overflow: auto; }
.d-section { margin-bottom: 20px; }
.d-section h4 { margin: 0 0 8px; font-size: 12px; text-transform: uppercase; letter-spacing: .5px; color: var(--muted); }
.kv { display: grid; grid-template-columns: 130px 1fr; gap: 6px 12px; font-size: 13px; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; word-break: break-word; }
.cost-line { display: flex; justify-content: space-between; padding: 6px 0; border-bottom: 1px dashed var(--line-soft); font-size: 13px; }
.cost-line.total { border-bottom: 0; border-top: 2px solid var(--line); margin-top: 4px; padding-top: 10px; font-weight: 700; font-size: 15px; }
.cost-line .v { font-variant-numeric: tabular-nums; }
.cost-line.total .v { color: var(--accent); }
.total-box {
  margin-top: 14px; padding: 14px 16px; border-radius: var(--radius);
  background: var(--accent-soft); border: 1px solid color-mix(in srgb, var(--accent) 35%, transparent);
}
.tb-row { display: flex; justify-content: space-between; align-items: baseline; gap: 12px; font-size: 13px; }
.tb-row + .tb-row { margin-top: 8px; padding-top: 8px; border-top: 1px dashed color-mix(in srgb, var(--accent) 30%, transparent); }
.tb-big { font-size: 22px; font-weight: 800; color: var(--accent); font-variant-numeric: tabular-nums; }
.aviso {
  background: var(--danger-soft); color: var(--danger); border-radius: var(--radius-sm);
  padding: 9px 12px; margin-bottom: 10px; font-size: 12.5px; font-weight: 500;
}
/* Bloque de verificación en el registro oficial de China (GSXT) */
.gsxt {
  margin-top: 12px; padding: 12px 14px; border-radius: var(--radius-sm);
  background: var(--card-2); border: 1px solid var(--line);
}
.gsxt-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.gsxt-title { font-weight: 650; font-size: 13px; color: var(--eco); }
.gsxt-help { margin: 8px 0 0; font-size: 12px; color: var(--txt-2); line-height: 1.5; }
.gsxt-nota { margin: 8px 0 0; font-size: 11.5px; color: var(--muted); line-height: 1.5; }
.gsxt-copy { display: flex; align-items: center; gap: 8px; margin-top: 10px; flex-wrap: wrap; }
.gsxt-copy span { font-size: 12px; color: var(--muted); }
.gsxt-copy code {
  font-family: var(--mono); font-size: 12px; background: var(--bg-elev);
  border: 1px solid var(--line); border-radius: 5px; padding: 3px 8px; color: var(--txt);
  max-width: 320px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}

.star { cursor: pointer; color: var(--muted); font-size: 16px; background: none; border: 0; }
.star.on { color: var(--prem); }
.mini-row { display: flex; gap: 8px; align-items: flex-end; flex-wrap: wrap; }
.mini-row .field { min-width: 84px; }

/* ---------- Login ---------- */
.login-body { display: grid; place-items: center; min-height: 100vh; padding: 24px; }
.login-wrap { width: 100%; max-width: 400px; }
.login-card {
  background: var(--card); border: 1px solid var(--line); border-radius: 14px;
  padding: 30px 28px; box-shadow: var(--shadow);
}
.login-brand { display: flex; align-items: center; gap: 12px; margin-bottom: 24px; }
.login-brand strong { display: block; font-size: 14px; line-height: 1.3; }
.login-brand span { font-size: 11.5px; color: var(--muted); }
.login-card h1 { margin: 0 0 6px; font-size: 20px; letter-spacing: -.3px; }
.login-hint { margin: 0 0 20px; font-size: 13px; color: var(--muted); }
.login-card .field { margin-bottom: 14px; }
.login-btn { width: 100%; margin-top: 6px; padding: 11px; font-size: 14px; }
.login-error {
  background: var(--danger-soft); color: var(--danger); border-radius: var(--radius-sm);
  padding: 10px 13px; margin-bottom: 16px; font-size: 13px; font-weight: 500;
}
.login-pie { margin: 18px 0 0; font-size: 11.5px; color: var(--muted); text-align: center; }
.topbar-user { font-size: 12px; color: var(--muted); display: flex; align-items: center; gap: 8px; }

/* ---------- Toasts ---------- */
.toasts { position: fixed; top: 72px; right: 20px; z-index: 50; display: flex; flex-direction: column; gap: 10px; }
.toast {
  background: var(--card); border: 1px solid var(--line); border-left: 3px solid var(--accent);
  border-radius: var(--radius-sm); padding: 11px 15px; box-shadow: var(--shadow);
  font-size: 13px; min-width: 240px; max-width: 360px; animation: slide .2s ease;
}
.toast.ok { border-left-color: var(--ok); }
.toast.err { border-left-color: var(--danger); }
@keyframes slide { from { opacity: 0; transform: translateX(16px); } to { opacity: 1; transform: none; } }
