:root {
  color-scheme: light;
  --surface-1: #ffffff;
  --page: #f4f6f1;
  --text-primary: #10130c;
  --text-secondary: #55594c;
  --text-muted: #8a8f7d;
  --gridline: #e6e9de;
  --border: rgba(16, 19, 12, 0.10);

  /* Paleta de marca María Paula, C.A. — tomada del isotipo (hoja + fondo oliva) */
  --brand-dark: #182410;      /* insignia circular oscura del logo */
  --brand-wash: #7e9143;      /* verde oliva del fondo del logo */
  --brand-leaf-light: #d7e88f; /* punta clara de la hoja (gradiente) */

  --brand-military: #4b5a2e;
  --brand-military-dark: #384322;
  --brand-apple: #7cb342;
  --brand-apple-dark: #5d8c2e;

  --series-1: #4b5a2e; /* BARITANQUE — verde militar */
  --series-2: #7cb342; /* TAMBOR — verde manzana */
  --series-3: #23261c; /* SACO — negro verdoso */
  --series-4: #9db67f; /* CARBOYA — verde salvia claro */
  --series-5: #6b7a4a; /* OTRO — verde oliva medio */
  --series-6: #a3a696; /* SIN_ESPECIFICAR — gris neutro */

  --status-good: #3f7d1f;
  --status-warning: #8a6d1a;
  --status-critical: #a6362b;
}

@media (prefers-color-scheme: dark) {
  :root:where(:not([data-theme="light"])) {
    color-scheme: dark;
    --surface-1: #14170f;
    --page: #0b0d08;
    --text-primary: #f6f7f2;
    --text-secondary: #c2c7b3;
    --text-muted: #8a8f7d;
    --gridline: #2a2f20;
    --border: rgba(255, 255, 255, 0.10);

    --brand-dark: #0d1409;
    --brand-wash: #6d7e39;
    --brand-leaf-light: #e2f0a4;

    --brand-military: #8ba05c;
    --brand-military-dark: #6f8348;
    --brand-apple: #9ccc65;
    --brand-apple-dark: #7cb342;

    --series-1: #8ba05c;
    --series-2: #9ccc65;
    --series-3: #d7dbc9;
    --series-4: #5e6b48;
    --series-5: #7f9459;
    --series-6: #7a7d6d;

    --status-good: #9ccc65;
    --status-warning: #d3ab3a;
    --status-critical: #e0847a;
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --surface-1: #14170f;
  --page: #0b0d08;
  --text-primary: #f6f7f2;
  --text-secondary: #c2c7b3;
  --text-muted: #8a8f7d;
  --gridline: #2a2f20;
  --border: rgba(255, 255, 255, 0.10);

  --brand-dark: #0d1409;
  --brand-wash: #6d7e39;
  --brand-leaf-light: #e2f0a4;

  --brand-military: #8ba05c;
  --brand-military-dark: #6f8348;
  --brand-apple: #9ccc65;
  --brand-apple-dark: #7cb342;

  --series-1: #8ba05c;
  --series-2: #9ccc65;
  --series-3: #d7dbc9;
  --series-4: #5e6b48;
  --series-5: #7f9459;
  --series-6: #7a7d6d;

  --status-good: #9ccc65;
  --status-warning: #d3ab3a;
  --status-critical: #e0847a;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: system-ui, -apple-system, "Segoe UI", sans-serif;
  background: var(--page);
  color: var(--text-primary);
}

.app-shell {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

header.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 1rem 1.25rem;
  background: var(--surface-1);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 10;
}

header.topbar .user-info {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  color: var(--text-secondary);
  font-size: 0.9rem;
}

/* Marca María Paula, C.A. */
.brand-lockup {
  display: flex;
  align-items: center;
  gap: 0.65rem;
}

.brand-badge {
  flex-shrink: 0;
  border-radius: 50%;
  filter: drop-shadow(0 1px 2px rgba(0, 0, 0, 0.15));
}

.brand-text h1 {
  font-size: 1.05rem;
  margin: 0;
  color: var(--brand-military);
  font-weight: 700;
  letter-spacing: -0.01em;
  line-height: 1.2;
}

.brand-text .brand-subtitle {
  font-size: 0.7rem;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  font-weight: 600;
}

button, .btn {
  font-family: inherit;
  border: 1px solid var(--border);
  background: var(--surface-1);
  color: var(--text-primary);
  border-radius: 8px;
  padding: 0.55rem 1rem;
  font-size: 0.9rem;
  cursor: pointer;
}

button.primary {
  background: var(--brand-military);
  border-color: var(--brand-military);
  color: #ffffff;
  font-weight: 600;
}

button:hover { filter: brightness(0.96); }
button:disabled { opacity: 0.5; cursor: not-allowed; }

main {
  flex: 1;
  padding: 1.25rem;
  max-width: 1200px;
  width: 100%;
  margin: 0 auto;
}

/* KPI stat tiles */
.kpi-row {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 0.75rem;
  margin-bottom: 1.5rem;
}

.stat-tile {
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-top: 2px solid var(--brand-apple);
  border-radius: 12px;
  padding: 1rem 1.1rem;
}

.stat-tile .label {
  color: var(--text-secondary);
  font-size: 0.8rem;
  margin-bottom: 0.35rem;
}

.stat-tile .value {
  font-size: 1.75rem;
  font-weight: 600;
  font-variant-numeric: proportional-nums;
}

/* Section cards */
.card {
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 1.1rem;
  margin-bottom: 1.5rem;
  overflow-x: auto;
}

.card h2 {
  font-size: 1rem;
  margin: 0 0 0.9rem 0;
}

/* Empaque meter (horizontal bar list) */
.meter-row {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  margin-bottom: 0.55rem;
  font-size: 0.85rem;
}

.meter-row .swatch {
  width: 10px;
  height: 10px;
  border-radius: 3px;
  flex-shrink: 0;
}

.meter-row .name {
  width: 130px;
  color: var(--text-secondary);
  flex-shrink: 0;
}

.meter-track {
  flex: 1;
  height: 8px;
  background: var(--gridline);
  border-radius: 4px;
  overflow: hidden;
}

.meter-fill {
  height: 100%;
  border-radius: 4px;
}

.meter-row .amount {
  width: 90px;
  text-align: right;
  font-variant-numeric: tabular-nums;
  color: var(--text-primary);
}

/* Filters */
.filters {
  display: flex;
  flex-wrap: wrap;
  gap: 0.6rem;
  margin-bottom: 1rem;
}

.periodo-presets {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
  margin-bottom: 0.6rem;
}

.periodo-btn {
  font-size: 0.8rem;
  padding: 0.4rem 0.75rem;
  border-radius: 999px;
}

.periodo-btn.active {
  background: var(--brand-military);
  border-color: var(--brand-military);
  color: #fff;
}

.rango-label {
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
  font-size: 0.8rem;
  color: var(--text-secondary);
}

.kardex-toolbar {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 0.75rem;
  margin-bottom: 0.8rem;
}

#kardex-eliminar-btn {
  background: var(--status-critical);
  border-color: var(--status-critical);
  color: #fff;
}

#kardex-eliminar-btn:disabled {
  background: var(--surface-1);
  border-color: var(--border);
  color: var(--text-muted);
  opacity: 1;
}

.kardex-hint { padding: 0; text-align: left; }

.inv-confirmar-btn {
  font-size: 0.78rem;
  padding: 0.35rem 0.7rem;
  background: var(--brand-apple);
  border-color: var(--brand-apple);
  color: #fff;
  white-space: nowrap;
}

.inv-confirmar-btn:disabled {
  background: var(--surface-1);
  border-color: var(--border);
  color: var(--text-muted);
  opacity: 1;
}

.filters select, .filters input {
  font-family: inherit;
  padding: 0.5rem 0.6rem;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--surface-1);
  color: var(--text-primary);
  font-size: 0.9rem;
}

/* Tables */
table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.85rem;
  min-width: 640px;
}

thead th {
  text-align: left;
  color: var(--text-muted);
  font-weight: 500;
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.02em;
  padding: 0.5rem 0.6rem;
  border-bottom: 1px solid var(--gridline);
}

tbody td {
  padding: 0.55rem 0.6rem;
  border-bottom: 1px solid var(--gridline);
  font-variant-numeric: tabular-nums;
}

tbody tr:last-child td { border-bottom: none; }

.pill {
  display: inline-block;
  padding: 0.15rem 0.5rem;
  border-radius: 999px;
  font-size: 0.72rem;
  font-weight: 600;
  background: var(--gridline);
  color: var(--text-secondary);
}

.amount-positive { color: var(--status-good); }
.amount-negative { color: var(--status-critical); }

.inv-empaque-edit,
.inv-empaques-edit {
  font-family: inherit;
  padding: 0.35rem 0.5rem;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: var(--page);
  color: var(--text-primary);
  font-size: 0.82rem;
}

.inv-empaques-edit { width: 80px; }

.inv-empaque-edit:focus,
.inv-empaques-edit:focus {
  outline: none;
  border-color: var(--brand-apple);
}

/* Movimiento form */
#mov-form label {
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
  font-size: 0.8rem;
  color: var(--text-secondary);
}

#mov-form select,
#mov-form input {
  font-family: inherit;
  padding: 0.5rem 0.6rem;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--page);
  color: var(--text-primary);
  font-size: 0.9rem;
}

.mov-header-row {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem;
  align-items: end;
  margin-bottom: 0.9rem;
}

.mov-header-row > label:first-child { flex: 1; min-width: 200px; }

/* La línea de producto: una sola fila en escritorio, apila en móvil */
.mov-line {
  display: grid;
  grid-template-columns: 2fr 1fr 0.7fr 0.8fr;
  gap: 0.6rem;
  align-items: end;
  margin-bottom: 0.9rem;
}

.mov-totales {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 0.6rem;
  margin-bottom: 0.9rem;
}

.mov-totales .stat-tile { padding: 0.75rem 1rem; }
.mov-totales .value { font-size: 1.3rem; }

#mov-form > label { margin-bottom: 0.9rem; }

@media (max-width: 780px) {
  .mov-line { grid-template-columns: 1fr 1fr; }
  .mov-line-producto { grid-column: 1 / -1; }
}

.direccion-toggle {
  display: flex;
  gap: 0.4rem;
}

.direccion-toggle button {
  flex: 1;
}

.direccion-toggle button.active[data-dir="ENTRADA"] {
  background: var(--status-good);
  border-color: var(--status-good);
  color: #fff;
}

.direccion-toggle button.active[data-dir="SALIDA"] {
  background: var(--status-critical);
  border-color: var(--status-critical);
  color: #fff;
}

.banner {
  padding: 0.7rem 0.9rem;
  border-radius: 8px;
  font-size: 0.85rem;
  margin-bottom: 1rem;
  display: none;
}

.banner.show { display: block; }
.banner.success { background: rgba(63, 125, 31, 0.12); color: var(--status-good); }
.banner.error { background: rgba(166, 54, 43, 0.12); color: var(--status-critical); }

.empty-state {
  color: var(--text-muted);
  font-size: 0.85rem;
  padding: 1rem 0;
  text-align: center;
}

/* Login page */
.login-shell {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: radial-gradient(circle at 50% -10%, var(--brand-wash) 0%, transparent 55%), var(--page);
  padding: 1rem;
}

.login-card {
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 2rem;
  width: 100%;
  max-width: 360px;
}

.login-brand {
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  gap: 0.6rem;
  margin-bottom: 1.5rem;
}

.login-brand .brand-badge { width: 56px; height: 56px; }

.login-card h1 {
  font-size: 1.2rem;
  margin: 0;
  color: var(--brand-military);
  font-weight: 700;
}

.login-brand .brand-subtitle {
  font-size: 0.75rem;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  font-weight: 600;
}

.login-card label {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  font-size: 0.85rem;
  color: var(--text-secondary);
  margin-bottom: 1rem;
}

.login-card input {
  font-family: inherit;
  padding: 0.6rem 0.7rem;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--page);
  color: var(--text-primary);
  font-size: 0.95rem;
}

.login-card button {
  width: 100%;
  margin-top: 0.5rem;
}

@media (max-width: 640px) {
  .kpi-row { grid-template-columns: repeat(2, 1fr); }
  main { padding: 0.9rem; }
  .meter-row .name { width: 90px; }
}
