/* ===== Design tokens ===== */
:root {
  --surface-1: #fcfcfb;
  --surface-2: #ffffff;
  --page-plane: #f2f3f1;
  --text-primary: #0b0b0b;
  --text-secondary: #52514e;
  --text-muted: #898781;
  --gridline: #e1e0d9;
  --baseline: #c3c2b7;
  --border: rgba(11, 11, 11, 0.10);
  --border-strong: rgba(11, 11, 11, 0.16);

  --series-1: #2a78d6; /* blue */
  --series-2: #1baf7a; /* aqua */
  --series-3: #eda100; /* yellow */
  --series-4: #008300; /* green */
  --series-5: #4a3aa7; /* violet */
  --series-6: #e34948; /* red */
  --series-7: #e87ba4; /* magenta */
  --series-8: #eb6834; /* orange */

  --status-good: #0ca30c;
  --status-warning: #fab219;
  --status-serious: #ec835a;
  --status-critical: #d03b3b;

  --brand: #1baf7a;
  --brand-ink: #0a5c3e;
  --brand-wash: #e8f7f1;

  --sidebar-bg: #0f2f26;
  --sidebar-bg-active: #16473a;
  --sidebar-text: #d7ece4;
  --sidebar-text-muted: #8fb3a6;
  --sidebar-accent: #35d69b;

  --radius-sm: 6px;
  --radius-md: 10px;
  --radius-lg: 14px;
  --shadow-sm: 0 1px 2px rgba(11,11,11,0.06);
  --shadow-md: 0 4px 16px rgba(11,11,11,0.08);
  --shadow-lg: 0 12px 32px rgba(11,11,11,0.14);
}

:root[data-theme="dark"] {
  --surface-1: #1a1a19;
  --surface-2: #212120;
  --page-plane: #0d0d0d;
  --text-primary: #ffffff;
  --text-secondary: #c3c2b7;
  --text-muted: #898781;
  --gridline: #2c2c2a;
  --baseline: #383835;
  --border: rgba(255, 255, 255, 0.10);
  --border-strong: rgba(255, 255, 255, 0.18);

  --series-1: #3987e5;
  --series-2: #199e70;
  --series-3: #c98500;
  --series-4: #2fb52f;
  --series-5: #9085e9;
  --series-6: #e66767;
  --series-7: #d55181;
  --series-8: #d95926;

  --status-good: #0ca30c;
  --status-warning: #fab219;
  --status-serious: #ec835a;
  --status-critical: #d03b3b;

  --brand: #199e70;
  --brand-ink: #6fe0b8;
  --brand-wash: #10291f;

  --sidebar-bg: #0a1a15;
  --sidebar-bg-active: #14332a;
  --sidebar-text: #cfe6dc;
  --sidebar-text-muted: #6f9384;
  --sidebar-accent: #35d69b;

  --shadow-sm: 0 1px 2px rgba(0,0,0,0.3);
  --shadow-md: 0 4px 16px rgba(0,0,0,0.4);
  --shadow-lg: 0 12px 32px rgba(0,0,0,0.5);
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --surface-1: #1a1a19;
    --surface-2: #212120;
    --page-plane: #0d0d0d;
    --text-primary: #ffffff;
    --text-secondary: #c3c2b7;
    --text-muted: #898781;
    --gridline: #2c2c2a;
    --baseline: #383835;
    --border: rgba(255, 255, 255, 0.10);
    --border-strong: rgba(255, 255, 255, 0.18);
    --series-1: #3987e5; --series-2: #199e70; --series-3: #c98500; --series-4: #2fb52f;
    --series-5: #9085e9; --series-6: #e66767; --series-7: #d55181; --series-8: #d95926;
    --brand: #199e70; --brand-ink: #6fe0b8; --brand-wash: #10291f;
    --sidebar-bg: #0a1a15; --sidebar-bg-active: #14332a; --sidebar-text: #cfe6dc; --sidebar-text-muted: #6f9384;
  }
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  font-family: system-ui, -apple-system, "Segoe UI", sans-serif;
  background: var(--page-plane);
  color: var(--text-primary);
  -webkit-font-smoothing: antialiased;
}
#root { height: 100%; }
button, input, select, textarea { font-family: inherit; font-size: inherit; }
table { font-variant-numeric: tabular-nums; }

/* ===== App shell ===== */
.app-shell { display: flex; min-height: 100vh; }

.sidebar {
  width: 240px;
  flex-shrink: 0;
  background: var(--sidebar-bg);
  color: var(--sidebar-text);
  display: flex;
  flex-direction: column;
  position: sticky;
  top: 0;
  height: 100vh;
}
.sidebar-brand {
  padding: 20px 18px 12px;
  display: flex;
  align-items: center;
  gap: 10px;
  border-bottom: 1px solid rgba(255,255,255,0.08);
}
.sidebar-brand-mark {
  width: 34px; height: 34px; border-radius: 9px;
  background: var(--sidebar-accent);
  color: #06231b;
  display: flex; align-items: center; justify-content: center;
  font-weight: 800; font-size: 15px;
}
.sidebar-brand-name { font-weight: 700; font-size: 14.5px; line-height: 1.25; }
.sidebar-brand-sub { font-size: 11px; color: var(--sidebar-text-muted); }

.sidebar-nav { flex: 1; overflow-y: auto; padding: 14px 10px; display: flex; flex-direction: column; gap: 2px; }
.sidebar-link {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 12px; border-radius: var(--radius-sm);
  color: var(--sidebar-text-muted);
  text-decoration: none;
  cursor: pointer;
  font-size: 13.5px; font-weight: 600;
  border: none; background: transparent; width: 100%; text-align: left;
}
.sidebar-link:hover { background: rgba(255,255,255,0.06); color: var(--sidebar-text); }
.sidebar-link.active { background: var(--sidebar-bg-active); color: #ffffff; }
.sidebar-link .icon { font-size: 16px; width: 18px; text-align: center; }

.sidebar-foot { padding: 12px; border-top: 1px solid rgba(255,255,255,0.08); }
.sidebar-user { display: flex; align-items: center; gap: 10px; padding: 8px; border-radius: var(--radius-sm); }
.sidebar-user:hover { background: rgba(255,255,255,0.06); cursor: pointer; }
.avatar {
  width: 32px; height: 32px; border-radius: 50%;
  background: var(--sidebar-accent); color: #06231b;
  display: flex; align-items: center; justify-content: center;
  font-weight: 700; font-size: 12.5px; flex-shrink: 0;
}
.sidebar-user-name { font-size: 12.5px; font-weight: 700; color: #fff; }
.sidebar-user-role { font-size: 11px; color: var(--sidebar-text-muted); }

.main-area { flex: 1; min-width: 0; display: flex; flex-direction: column; }

.topbar {
  height: 60px; flex-shrink: 0;
  display: flex; align-items: center; justify-content: space-between;
  padding: 0 22px;
  background: var(--surface-2);
  border-bottom: 1px solid var(--border);
  position: sticky; top: 0; z-index: 20;
}
.topbar-title { font-size: 17px; font-weight: 700; }
.topbar-actions { display: flex; align-items: center; gap: 10px; }
#mobile-menu-btn { display: none; }

.content { padding: 22px; flex: 1; min-width: 0; }

.sidebar-backdrop { display: none; }

/* ===== Buttons ===== */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  padding: 8px 14px; border-radius: var(--radius-sm);
  border: 1px solid var(--border-strong);
  background: var(--surface-2); color: var(--text-primary);
  font-weight: 600; font-size: 13px; cursor: pointer;
  transition: background 0.12s, border-color 0.12s;
  white-space: nowrap;
}
.btn:hover { background: var(--page-plane); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn-primary { background: var(--brand); border-color: var(--brand); color: #fff; }
.btn-primary:hover { filter: brightness(0.95); }
.btn-danger { background: var(--status-critical); border-color: var(--status-critical); color: #fff; }
.btn-danger:hover { filter: brightness(0.95); }
.btn-ghost { background: transparent; border-color: transparent; }
.btn-ghost:hover { background: var(--page-plane); }
.btn-sm { padding: 5px 10px; font-size: 12px; }
.btn-icon { width: 34px; height: 34px; padding: 0; border-radius: var(--radius-sm); }

/* ===== Cards ===== */
.card {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
}
.card-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 16px 18px; border-bottom: 1px solid var(--border);
}
.card-title { font-size: 14.5px; font-weight: 700; }
.card-subtitle { font-size: 12px; color: var(--text-muted); margin-top: 2px; }
.card-body { padding: 18px; }

/* ===== KPI tiles ===== */
.kpi-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 16px; margin-bottom: 20px; }
.kpi-tile { background: var(--surface-2); border: 1px solid var(--border); border-radius: var(--radius-lg); padding: 16px 18px; box-shadow: var(--shadow-sm); }
.kpi-tile-top { display: flex; align-items: center; justify-content: space-between; margin-bottom: 10px; }
.kpi-label { font-size: 12px; color: var(--text-muted); font-weight: 600; text-transform: uppercase; letter-spacing: 0.03em; }
.kpi-icon { width: 30px; height: 30px; border-radius: 8px; display: flex; align-items: center; justify-content: center; font-size: 15px; }
.kpi-value { font-size: 26px; font-weight: 800; letter-spacing: -0.02em; }
.kpi-delta { font-size: 12px; margin-top: 6px; color: var(--text-muted); }
.kpi-delta.up { color: var(--status-good); }
.kpi-delta.down { color: var(--status-critical); }

/* ===== Grid helpers ===== */
.grid-2 { display: grid; grid-template-columns: 1.3fr 1fr; gap: 16px; }
.grid-3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 16px; }
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.spacer { flex: 1; }

/* ===== Forms ===== */
.field { display: flex; flex-direction: column; gap: 5px; margin-bottom: 14px; }
.field label { font-size: 12.5px; font-weight: 700; color: var(--text-secondary); }
.field .hint { font-size: 11px; color: var(--text-muted); font-weight: 400; }
.input, select.input, textarea.input {
  padding: 9px 11px; border-radius: var(--radius-sm);
  border: 1px solid var(--border-strong);
  background: var(--surface-1); color: var(--text-primary);
  outline: none; width: 100%;
}
.input:focus { border-color: var(--brand); box-shadow: 0 0 0 3px var(--brand-wash); }
textarea.input { resize: vertical; min-height: 70px; }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 0 16px; }
.form-grid .field.full { grid-column: 1 / -1; }
.field-error { border-color: var(--status-critical) !important; }
.error-text { font-size: 11.5px; color: var(--status-critical); }
.char-count { font-size: 11px; color: var(--text-muted); text-align: right; }

/* ===== Tables ===== */
.table-wrap { overflow-x: auto; border-radius: var(--radius-md); border: 1px solid var(--border); }
table.data-table { width: 100%; border-collapse: collapse; font-size: 13px; background: var(--surface-2); }
table.data-table th {
  text-align: left; padding: 10px 12px; font-weight: 700; font-size: 11.5px;
  text-transform: uppercase; letter-spacing: 0.02em; color: var(--text-muted);
  background: var(--page-plane); border-bottom: 1px solid var(--border);
  white-space: nowrap; cursor: pointer; user-select: none;
  position: sticky; top: 0;
}
table.data-table th:hover { color: var(--text-primary); }
table.data-table td { padding: 10px 12px; border-bottom: 1px solid var(--gridline); vertical-align: middle; }
table.data-table tbody tr:hover { background: var(--page-plane); }
table.data-table tbody tr:last-child td { border-bottom: none; }
.sort-arrow { margin-left: 4px; opacity: 0.6; }
.cell-muted { color: var(--text-muted); }
.cell-num { text-align: right; font-variant-numeric: tabular-nums; }
.table-empty { padding: 40px 20px; text-align: center; color: var(--text-muted); }

/* ===== Botones de ícono circulares (acciones compactas en tablas de celular) ===== */
.icon-btn {
  display: inline-flex; align-items: center; justify-content: center;
  width: 28px; height: 28px; border-radius: 50%; border: none; cursor: pointer;
  flex-shrink: 0; transition: filter 0.12s;
}
.icon-btn:active { filter: brightness(0.9); }
.icon-btn svg { width: 15px; height: 15px; }
.icon-btn-neutral { background: var(--page-plane); color: var(--text-secondary); }
.icon-btn-good { background: rgba(12,163,12,0.12); color: var(--status-good); }
.icon-btn-critical { background: rgba(208,59,59,0.12); color: var(--status-critical); }

/* ===== Botón flotante (FAB) — acción principal siempre visible en celular ===== */
.fab {
  position: fixed; right: 18px; bottom: 22px; z-index: 60;
  width: 54px; height: 54px; border-radius: 50%; border: none; cursor: pointer;
  background: var(--brand); color: #fff;
  display: flex; align-items: center; justify-content: center;
  box-shadow: var(--shadow-md);
}
.fab:active { filter: brightness(0.92); }

.chevron-toggle {
  display: inline-flex; align-items: center; justify-content: center;
  width: 24px; height: 24px; border-radius: 50%; background: var(--page-plane);
  color: var(--text-secondary); font-size: 13px; transition: transform 0.15s;
  flex-shrink: 0;
}

/* ===== Paired panels (e.g. gráfico + resumen) with a uniform, scrollable height ===== */
.panel-scroll { height: 420px; overflow-y: auto; }
.panel-scroll .table-wrap { border: none; border-radius: 0; }

/* ===== Badges ===== */
.badge {
  display: inline-flex; align-items: center; gap: 5px;
  padding: 3px 9px; border-radius: 999px; font-size: 11.5px; font-weight: 700;
  white-space: nowrap;
}
.badge-dot { width: 7px; height: 7px; border-radius: 50%; flex-shrink: 0; }
.badge-good { background: rgba(12,163,12,0.12); color: var(--status-good); }
.badge-good .badge-dot { background: var(--status-good); }
.badge-warning { background: rgba(250,178,25,0.16); color: #8a5a00; }
.badge-warning .badge-dot { background: var(--status-warning); }
.badge-serious { background: rgba(236,131,90,0.16); color: #a1441c; }
.badge-serious .badge-dot { background: var(--status-serious); }
.badge-critical { background: rgba(208,59,59,0.12); color: var(--status-critical); }
.badge-critical .badge-dot { background: var(--status-critical); }
.badge-neutral { background: var(--page-plane); color: var(--text-secondary); }
.badge-neutral .badge-dot { background: var(--text-muted); }
:root[data-theme="dark"] .badge-warning { color: #fab219; }
:root[data-theme="dark"] .badge-serious { color: #ec835a; }
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .badge-warning { color: #fab219; }
  :root:not([data-theme="light"]) .badge-serious { color: #ec835a; }
}

/* ===== Modal ===== */
.modal-overlay {
  position: fixed; inset: 0; background: rgba(11,11,11,0.45);
  display: flex; align-items: center; justify-content: center; z-index: 100;
  padding: 24px;
}
.modal {
  background: var(--surface-2); border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg); width: 100%; max-width: 640px;
  max-height: 88vh; display: flex; flex-direction: column;
  border: 1px solid var(--border);
}
.modal.modal-lg { max-width: 860px; }
.modal-header { padding: 16px 20px; border-bottom: 1px solid var(--border); display: flex; align-items: center; justify-content: space-between; }
.modal-title { font-size: 15.5px; font-weight: 700; }
.modal-body { padding: 20px; overflow-y: auto; }
.modal-footer { padding: 14px 20px; border-top: 1px solid var(--border); display: flex; justify-content: flex-end; gap: 10px; }

/* ===== Toasts ===== */
.toast-stack { position: fixed; top: 18px; right: 18px; z-index: 200; display: flex; flex-direction: column; gap: 8px; }
.toast {
  min-width: 260px; max-width: 360px; padding: 12px 14px; border-radius: var(--radius-md);
  background: var(--surface-2); border: 1px solid var(--border); box-shadow: var(--shadow-md);
  font-size: 13px; display: flex; align-items: flex-start; gap: 10px;
  animation: toast-in 0.18s ease-out;
}
@keyframes toast-in { from { opacity: 0; transform: translateY(-6px); } to { opacity: 1; transform: translateY(0); } }
.toast-icon { font-size: 15px; margin-top: 1px; }
.toast-success { border-left: 3px solid var(--status-good); }
.toast-error { border-left: 3px solid var(--status-critical); }
.toast-info { border-left: 3px solid var(--series-1); }

/* ===== Login ===== */
.login-screen {
  min-height: 100vh; display: flex; align-items: center; justify-content: center;
  background: radial-gradient(circle at 20% 20%, var(--brand-wash), var(--page-plane) 60%);
  padding: 20px;
}
.login-card { width: 100%; max-width: 400px; background: var(--surface-2); border: 1px solid var(--border); border-radius: var(--radius-lg); box-shadow: var(--shadow-lg); padding: 30px 28px; }
.login-brand { display: flex; align-items: center; gap: 10px; margin-bottom: 22px; }
.login-title { font-size: 18px; font-weight: 800; }
.login-sub { font-size: 12.5px; color: var(--text-muted); margin-top: 2px; }
.login-demo { margin-top: 18px; border-top: 1px solid var(--border); padding-top: 14px; }
.login-demo summary { cursor: pointer; font-size: 12px; font-weight: 700; color: var(--text-secondary); }
.demo-user-row { display: flex; justify-content: space-between; align-items: center; padding: 6px 0; font-size: 12px; }
.demo-user-row button { font-size: 11px; }

/* ===== Misc ===== */
.tag-list { display: flex; flex-wrap: wrap; gap: 6px; }
.chip {
  padding: 4px 10px; border-radius: 999px; font-size: 12px; font-weight: 600;
  background: var(--page-plane); border: 1px solid var(--border); cursor: pointer; color: var(--text-secondary);
}
.chip.active { background: var(--brand); border-color: var(--brand); color: #fff; }
.progress-track { width: 100%; height: 6px; border-radius: 999px; background: var(--gridline); overflow: hidden; }
.progress-fill { height: 100%; border-radius: 999px; }
.empty-state { padding: 50px 20px; text-align: center; color: var(--text-muted); }
.empty-state .icon { font-size: 34px; margin-bottom: 10px; }
.divider { height: 1px; background: var(--border); margin: 16px 0; }
.text-muted { color: var(--text-muted); }
.text-secondary { color: var(--text-secondary); }
.mono { font-variant-numeric: tabular-nums; }
.skeleton { background: linear-gradient(90deg, var(--gridline) 25%, var(--page-plane) 37%, var(--gridline) 63%); background-size: 400% 100%; animation: skeleton-loading 1.4s ease infinite; border-radius: 6px; }
@keyframes skeleton-loading { 0% { background-position: 100% 50%; } 100% { background-position: 0 50%; } }

.chart-legend { display: flex; flex-wrap: wrap; gap: 12px; margin-top: 10px; font-size: 12px; color: var(--text-secondary); }
.chart-legend-item { display: flex; align-items: center; gap: 6px; }
.chart-legend-dot { width: 9px; height: 9px; border-radius: 3px; }
.chart-canvas-wrap { position: relative; }

.pill-select { position: relative; }
.checkbox-row { display: flex; align-items: center; gap: 8px; font-size: 13px; white-space: nowrap; }

/* ===== Filter bar (uniform filter cards across Inventario / Movimientos / Reportes) ===== */
.filter-card-header {
  display: flex; align-items: center; justify-content: space-between; flex-wrap: wrap; gap: 6px;
  padding: 12px 18px; border-bottom: 1px solid var(--border);
}
.filter-card-title {
  display: flex; align-items: center; gap: 7px;
  font-size: 12px; font-weight: 700; color: var(--text-secondary);
  text-transform: uppercase; letter-spacing: 0.04em;
}
.filter-card-meta { font-size: 12px; color: var(--text-muted); white-space: nowrap; }
.filter-card-body { padding: 16px 18px; display: flex; flex-direction: column; gap: 14px; }
.filter-row { display: flex; flex-wrap: wrap; gap: 12px 14px; align-items: flex-end; }
.filter-row + .filter-row { padding-top: 14px; border-top: 1px dashed var(--gridline); }
.filter-field { display: flex; flex-direction: column; gap: 5px; flex: 1 1 150px; min-width: 130px; max-width: 220px; }
.filter-field .input { width: 100%; }
.filter-field-grow { flex: 2 1 220px; max-width: 320px; }
.filter-field-auto { flex: 0 0 auto; min-width: 0; max-width: none; }
.filter-field-label {
  font-size: 10.5px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.045em;
  color: var(--text-muted); white-space: nowrap;
}
.filter-actions {
  display: flex; flex-wrap: wrap; align-items: center; gap: 8px;
  padding-top: 14px; border-top: 1px solid var(--border);
}

/* Grouped sub-sections within a filter card (e.g. Periodo / Modalidad / Ubicación) */
.filter-section { display: flex; flex-direction: column; gap: 10px; }
.filter-section + .filter-section { padding-top: 16px; border-top: 1px solid var(--border); }
.filter-section-title {
  display: flex; align-items: baseline; gap: 8px;
  font-size: 12.5px; font-weight: 700; color: var(--text-primary);
}
.filter-section-hint { font-size: 11px; font-weight: 400; color: var(--text-muted); }
.filter-chain-arrow { color: var(--text-muted); font-size: 13px; align-self: center; margin-bottom: 9px; user-select: none; }

/* ===== Multi-select dropdown (estilo filtro de Excel: checkboxes dentro de un desplegable) ===== */
.msdd { position: relative; }
.msdd-trigger {
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
  cursor: pointer; text-align: left; color: var(--text-primary);
}
.msdd-trigger-label { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.msdd-caret { color: var(--text-muted); font-size: 10px; flex-shrink: 0; }
.msdd-panel {
  position: absolute; top: calc(100% + 4px); left: 0; z-index: 30;
  min-width: 100%; width: max-content; max-width: 260px;
  background: var(--surface-2); border: 1px solid var(--border-strong); border-radius: var(--radius-sm);
  box-shadow: var(--shadow-md); padding: 6px; max-height: 260px; overflow-y: auto;
}
.msdd-item {
  display: flex; align-items: center; gap: 8px;
  padding: 6px 8px; border-radius: 6px; font-size: 13px; cursor: pointer; white-space: nowrap;
}
.msdd-item:hover { background: var(--page-plane); }
.msdd-item input { flex-shrink: 0; }
.msdd-all { font-weight: 700; }
.msdd-divider { height: 1px; background: var(--border); margin: 4px 2px; }

@media (max-width: 1180px) {
  .kpi-grid { grid-template-columns: repeat(2, 1fr); }
  .grid-2, .grid-3 { grid-template-columns: 1fr; }
  .form-grid { grid-template-columns: 1fr; }
}
@media (max-width: 860px) {
  .sidebar { position: fixed; z-index: 90; transform: translateX(-100%); transition: transform 0.2s; }
  .sidebar.open { transform: translateX(0); }
  .kpi-grid { grid-template-columns: 1fr; }
  #mobile-menu-btn { display: inline-flex; }
  .content { padding: 12px; }
  .topbar { padding: 0 14px; }
  .sidebar-backdrop.open {
    display: block; position: fixed; inset: 0;
    background: rgba(11,11,11,0.45); z-index: 80;
  }
  table.data-table { font-size: 12.5px; }
  table.data-table th, table.data-table td { padding: 8px 6px; }
  .card-body { padding: 14px; }
  .card-header { flex-direction: column; align-items: flex-start; gap: 10px; }
  .card-header > .row { width: 100%; }
  .panel-scroll { height: auto; overflow-y: visible; }
}
