/* ============ Tokens ============ */
:root {
  --bg: #F6F5FB;
  --surface: #FFFFFF;
  --surface-2: #FBFAFE;
  --border: #E4E1F0;
  --ink: #1B1730;
  --ink-soft: #4A4560;
  --muted: #7A7490;
  --accent: #5B21B6;
  --accent-ink: #FFFFFF;
  --accent-soft: #EFE9FE;

  --danger: #DC2626;
  --danger-soft: #FDE8E8;
  --danger-ink: #7F1D1D;

  --success: #15803D;
  --success-soft: #E3F7EA;
  --success-ink: #14532D;

  --warning: #C2650A;
  --warning-soft: #FDEDD3;
  --warning-ink: #7C3E05;

  --info: #1D4ED8;
  --info-soft: #E4ECFE;
  --info-ink: #1E3A8A;

  --shadow: 0 1px 2px rgba(27,23,48,.06), 0 8px 24px -12px rgba(27,23,48,.22);
  --radius: 14px;
  --radius-sm: 9px;

  --font-display: 'Sora', system-ui, sans-serif;
  --font-body: 'IBM Plex Sans', system-ui, sans-serif;
  --font-mono: 'IBM Plex Mono', ui-monospace, monospace;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #14121F;
    --surface: #1D1A2E;
    --surface-2: #221E37;
    --border: #322C4B;
    --ink: #F1EFFB;
    --ink-soft: #C9C4E0;
    --muted: #948FB0;
    --accent: #B39DFB;
    --accent-ink: #1B1730;
    --accent-soft: #2C2650;

    --danger: #F87171;
    --danger-soft: #3A1E22;
    --danger-ink: #FCA5A5;

    --success: #4ADE80;
    --success-soft: #16301F;
    --success-ink: #86EFAC;

    --warning: #FBBF24;
    --warning-soft: #3A2A0E;
    --warning-ink: #FCD34D;

    --info: #60A5FA;
    --info-soft: #182A4A;
    --info-ink: #93C5FD;

    --shadow: 0 1px 2px rgba(0,0,0,.5), 0 8px 24px -12px rgba(0,0,0,.6);
  }
}

* { box-sizing: border-box; }

/* El atributo hidden siempre gana, sin importar qué display defina cada clase */
[hidden] { display: none !important; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font-body);
  -webkit-font-smoothing: antialiased;
}

body { min-height: 100vh; }

h1, h2, h3 { font-family: var(--font-display); margin: 0; text-wrap: balance; }

button { font-family: inherit; }

a { color: var(--accent); }

.mono { font-family: var(--font-mono); font-variant-numeric: tabular-nums; }

/* ============ Botones ============ */
.primary-btn {
  background: var(--accent);
  color: var(--accent-ink);
  border: none;
  padding: .7em 1.2em;
  border-radius: var(--radius-sm);
  font-weight: 600;
  font-size: .95rem;
  cursor: pointer;
  white-space: nowrap;
}
.primary-btn:hover { filter: brightness(1.08); }
.primary-btn.full { width: 100%; }

.ghost-btn {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--ink-soft);
  padding: .65em 1.1em;
  border-radius: var(--radius-sm);
  font-weight: 600;
  font-size: .9rem;
  cursor: pointer;
}
.ghost-btn:hover { background: var(--surface-2); }

.chip-btn {
  background: var(--accent-soft);
  color: var(--accent);
  border: none;
  padding: .5em 1em;
  border-radius: 999px;
  font-weight: 600;
  font-size: .85rem;
  cursor: pointer;
}

.icon-btn {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--muted);
  width: 2.1em;
  height: 2.1em;
  border-radius: var(--radius-sm);
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}
.icon-btn.danger:hover { color: var(--danger); border-color: var(--danger); }

.action-btn {
  background: var(--surface-2);
  border: 1px solid var(--border);
  color: var(--ink-soft);
  padding: .55em .9em;
  border-radius: var(--radius-sm);
  font-weight: 600;
  font-size: .85rem;
  cursor: pointer;
  white-space: nowrap;
}
.action-btn:hover { background: var(--accent-soft); color: var(--accent); }

/* ============ Login ============ */
.login-screen {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background:
    radial-gradient(circle at 15% 10%, var(--accent-soft), transparent 55%),
    var(--bg);
}
.login-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 2.2em 2em;
  width: 100%;
  max-width: 360px;
  text-align: center;
}
.login-mark { font-size: 2.4rem; }
.login-card h1 { font-size: 1.5rem; margin-top: .3em; }
.login-sub { color: var(--muted); margin: .2em 0 1.4em; font-weight: 600; }
#login-form { display: flex; flex-direction: column; gap: .6em; text-align: left; }
#login-form label { font-size: .82rem; font-weight: 600; color: var(--ink-soft); }
.login-error { color: var(--danger); font-size: .85rem; margin: .2em 0 0; }

/* ============ Inputs ============ */
input[type="text"], input[type="password"], input[type="number"],
input[type="url"], select, textarea {
  width: 100%;
  padding: .65em .8em;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--ink);
  font-family: inherit;
  font-size: .95rem;
}
textarea { resize: vertical; }
input:focus, select:focus, textarea:focus, button:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}

/* ============ App shell ============ */
.app { max-width: 1080px; margin: 0 auto; padding: 20px 20px 60px; }

.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1em;
  padding: 6px 0 18px;
  flex-wrap: wrap;
}
.brand { display: flex; align-items: center; gap: .7em; }
.brand-mark { font-size: 1.9rem; }
.brand h1 { font-size: 1.15rem; }
.brand p { margin: 0; color: var(--muted); font-size: .8rem; font-weight: 600; }
.header-actions { display: flex; align-items: center; gap: .6em; }

/* ============ Stats ============ */
.stats-row {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 12px;
  margin-bottom: 18px;
}
.stat-tile {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 16px;
  box-shadow: var(--shadow);
}
.stat-tile .stat-num { font-family: var(--font-display); font-size: 1.7rem; font-weight: 700; font-variant-numeric: tabular-nums; }
.stat-tile .stat-label { font-size: .78rem; color: var(--muted); font-weight: 600; margin-top: 2px; }
.stat-tile.stat-danger .stat-num { color: var(--danger); }
.stat-tile.stat-warning .stat-num { color: var(--warning); }
.stat-tile.stat-success .stat-num { color: var(--success); }
.stat-tile.stat-info .stat-num { color: var(--info); }

/* ============ Toolbar ============ */
.toolbar {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
  margin-bottom: 16px;
}
.tabs { display: flex; gap: 4px; background: var(--surface-2); padding: 4px; border-radius: 999px; border: 1px solid var(--border); }
.tab {
  border: none; background: transparent; color: var(--muted);
  padding: .5em 1.1em; border-radius: 999px; font-weight: 600; font-size: .85rem; cursor: pointer;
}
.tab.active { background: var(--surface); color: var(--accent); box-shadow: var(--shadow); }
.filters { display: flex; gap: 8px; flex-wrap: wrap; }
.filters select { width: auto; padding: .5em .7em; font-size: .85rem; }
.toolbar .primary-btn { margin-left: auto; }

/* ============ Lista de pedidos ============ */
.pedidos-list { display: flex; flex-direction: column; gap: 10px; }

.pedido-card {
  display: flex;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
}
.status-stripe { width: 6px; flex-shrink: 0; background: var(--border); }
.pedido-card.status-no_pedido .status-stripe { background: var(--danger); }
.pedido-card.status-atrasado .status-stripe { background: var(--warning); }
.pedido-card.status-pedido .status-stripe { background: var(--success); }
.pedido-card.status-para_entregar .status-stripe { background: var(--info); }
.pedido-card.status-entregado .status-stripe { background: var(--muted); }

.card-main { padding: 14px 16px; flex: 1; min-width: 0; }
.card-side {
  padding: 14px 16px;
  border-left: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  gap: 8px;
  justify-content: center;
  min-width: 230px;
}

.card-top { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; margin-bottom: 6px; }
.badge {
  display: inline-flex; align-items: center; gap: 4px;
  font-size: .74rem; font-weight: 700; padding: .3em .6em; border-radius: 999px;
  background: var(--surface-2); color: var(--ink-soft); border: 1px solid var(--border);
  white-space: nowrap;
}
.badge-status-no_pedido { background: var(--danger-soft); color: var(--danger-ink); border-color: transparent; }
.badge-status-atrasado { background: var(--warning-soft); color: var(--warning-ink); border-color: transparent; }
.badge-status-pedido { background: var(--success-soft); color: var(--success-ink); border-color: transparent; }
.badge-status-para_entregar { background: var(--info-soft); color: var(--info-ink); border-color: transparent; }
.badge-status-entregado { background: var(--surface-2); color: var(--muted); }
.badge-sena { background: var(--accent-soft); color: var(--accent); border-color: transparent; }

.producto { font-size: 1.02rem; margin-bottom: 3px; }
.producto .cantidad { color: var(--muted); font-weight: 500; font-size: .85em; }
.cliente { margin: 0 0 2px; font-size: .88rem; color: var(--ink-soft); }
.meta { margin: 0; font-size: .78rem; color: var(--muted); }
.meta a { font-weight: 600; }
.notas-line {
  margin-top: 8px; font-size: .83rem; color: var(--ink-soft);
  background: var(--surface-2); border: 1px dashed var(--border);
  border-radius: var(--radius-sm); padding: .5em .7em;
  display: flex; align-items: flex-start; justify-content: space-between; gap: 8px;
}
.notas-line button { flex-shrink: 0; }
.notas-empty { color: var(--muted); font-style: italic; }

/* Semáforo */
.semaforo-toggle {
  display: flex; align-items: center; gap: 8px;
  border: 1px solid var(--border); background: var(--surface-2);
  padding: .5em .7em; border-radius: 999px; cursor: pointer; font-weight: 700; font-size: .85rem;
  color: var(--ink-soft);
}
.semaforo-toggle .dot { width: 12px; height: 12px; border-radius: 50%; flex-shrink: 0; }
.semaforo-toggle.is-red .dot { background: var(--danger); box-shadow: 0 0 0 3px var(--danger-soft); }
.semaforo-toggle.is-green .dot { background: var(--success); box-shadow: 0 0 0 3px var(--success-soft); }
.semaforo-toggle.urgente { animation: pulse 1.6s infinite; }
@keyframes pulse {
  0%, 100% { box-shadow: 0 0 0 0 var(--danger-soft); }
  50% { box-shadow: 0 0 0 5px var(--danger-soft); }
}

.side-actions { display: flex; flex-direction: column; gap: 6px; }
.side-actions .action-btn { width: 100%; text-align: left; }
.side-row { display: flex; gap: 6px; }

.warning-line {
  font-size: .78rem; font-weight: 700; color: var(--warning-ink);
  background: var(--warning-soft); border-radius: var(--radius-sm);
  padding: .35em .6em; margin-top: 6px; display: inline-block;
}

/* ============ Empty state ============ */
.empty-state {
  text-align: center; color: var(--muted); padding: 3em 1em; font-size: .95rem;
  border: 1px dashed var(--border); border-radius: var(--radius); background: var(--surface-2);
}

/* ============ Modales ============ */
dialog.modal {
  border: none; border-radius: var(--radius); padding: 0;
  box-shadow: var(--shadow); max-width: 480px; width: 92vw;
  background: var(--surface); color: var(--ink);
}
dialog.modal::backdrop { background: rgba(20, 18, 31, .55); }
dialog.modal-small { max-width: 380px; }
dialog.modal form { padding: 1.4em 1.4em 1.2em; display: flex; flex-direction: column; gap: .8em; }
dialog.modal h2 { font-size: 1.1rem; }
.modal-sub { margin: -.4em 0 0; color: var(--muted); font-size: .85rem; }
.field { display: flex; flex-direction: column; gap: .35em; }
.field label { font-size: .8rem; font-weight: 600; color: var(--ink-soft); }
.field-row { display: flex; gap: 10px; }
.field-row .field { flex: 1; }
.checkbox-field { justify-content: center; }
.checkbox-field label { display: flex; align-items: center; gap: .5em; font-size: .9rem; color: var(--ink); }
.checkbox-field input { width: auto; }
.modal-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: .4em; }

/* ============ Toast ============ */
.toast {
  position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%);
  background: var(--ink); color: var(--surface); padding: .7em 1.2em;
  border-radius: 999px; font-size: .88rem; font-weight: 600; box-shadow: var(--shadow);
  z-index: 50;
}

/* ============ Responsive ============ */
@media (max-width: 720px) {
  .stats-row { grid-template-columns: repeat(2, 1fr); }
  .pedido-card { flex-direction: column; }
  .status-stripe { width: 100%; height: 5px; }
  .card-side { border-left: none; border-top: 1px solid var(--border); min-width: 0; }
  .toolbar .primary-btn { margin-left: 0; width: 100%; }
  .toolbar { flex-direction: column; align-items: stretch; }
  .filters { width: 100%; }
  .filters select { flex: 1; }
}

@media (max-width: 420px) {
  .stats-row { grid-template-columns: 1fr 1fr; }
  .app { padding: 14px 12px 50px; }
}
