:root {
  /* ---- Paleta oficial Natura / 3C — valores exactos, no derivados ---- */
  --natura-naranja-dia: #ee7230;   /* color icono principal de la marca */
  --natura-rojo-dia: #e55415;
  --natura-amarillo-tarde: #f6a038;
  --natura-verde-dia: #667b53;
  --natura-azul-dia: #86c8d9;
  --natura-rosa-tarde: #ec786a;
  --natura-crema: #fbf2ea;         /* 2do valor "Rosa Tarde" del brief: es un crema, no rosa */
  --natura-lavanda-light: #f7f1f8;
  --natura-naranja-light: #fde0ca;
  --natura-verde-light: #ebf1d7;
  --natura-rosa-light: #f5e2e1;
  --natura-celeste-light: #cae7ee;

  --surface-1: #fcfcfb;
  --page: #f9f9f7;
  --text-primary: #0b0b0b;
  --text-secondary: #52514e;
  --text-muted: #898781;
  --hairline: #e1e0d9;
  --baseline: #c3c2b7;
  --border: rgba(11, 11, 11, 0.1);

  /* ---- Roles de UI, mapeados a la paleta de marca ---- */
  --series-1: var(--natura-azul-dia);   /* Grupo 1 */
  --series-2: var(--natura-verde-dia);  /* Grupo 2 */

  --status-good: var(--natura-verde-dia);
  --status-good-bg: var(--natura-verde-light);
  --status-muted-bg: rgba(137, 135, 129, 0.14);

  --accent-bg: var(--natura-naranja-light);
  --accent-border: var(--natura-naranja-dia);
  --accent-text-on: #ffffff;

  --radius: 10px;
  --shadow: 0 1px 2px rgba(11, 11, 11, 0.06), 0 1px 1px rgba(11, 11, 11, 0.04);
}

@media (prefers-color-scheme: dark) {
  :root {
    --surface-1: #1a1a19;
    --page: #0d0d0d;
    --text-primary: #ffffff;
    --text-secondary: #c3c2b7;
    --text-muted: #898781;
    --hairline: #2c2c2a;
    --baseline: #383835;
    --border: rgba(255, 255, 255, 0.1);

    /* Los tonos de marca se mantienen exactos; solo el fondo/tinte cambia
       de opacidad para legibilidad sobre superficie oscura. */
    --series-1: var(--natura-azul-dia);
    --series-2: var(--natura-verde-dia);

    --status-good: var(--natura-verde-dia);
    --status-good-bg: rgba(102, 123, 83, 0.22);
    --status-muted-bg: rgba(137, 135, 129, 0.18);

    --accent-bg: rgba(238, 114, 48, 0.18);
    --accent-border: var(--natura-naranja-dia);
    --accent-text-on: #ffffff;
  }
}

* {
  box-sizing: border-box;
}

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

.hidden {
  display: none !important;
}

/* ---------- Login screen ---------- */

.login-screen {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}

.login-card {
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 40px 36px;
  width: 100%;
  max-width: 380px;
  text-align: center;
}

.login-card h1 {
  font-size: 20px;
  margin: 0 0 4px;
}

.login-card .subtitle {
  color: var(--text-secondary);
  font-size: 14px;
  margin: 0 0 28px;
}

.ms-login-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  width: 100%;
  padding: 11px 16px;
  background: #2f2f2f;
  color: #fff;
  border: none;
  border-radius: 6px;
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  text-decoration: none;
}

.ms-login-btn:hover {
  background: #1f1f1f;
}

.ms-logo {
  width: 18px;
  height: 18px;
  flex-shrink: 0;
}

.login-hint {
  margin-top: 18px;
  font-size: 12px;
  color: var(--text-muted);
}

.login-error {
  margin-top: 16px;
  font-size: 13px;
  color: var(--status-good);
  border-radius: 6px;
  padding: 10px 12px;
  background: var(--status-good-bg);
}

.login-error.is-error {
  color: #d03b3b;
  background: rgba(208, 59, 59, 0.1);
}

/* ---------- App shell (sidebar + topbar) ---------- */

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

.brand-logo {
  height: 22px;
  width: auto;
  display: block;
}

.brand-logo-lg {
  height: 42px;
  width: auto;
  margin: 0 auto 14px;
}

.muted {
  color: var(--text-muted);
}

.sidebar {
  width: 240px;
  flex-shrink: 0;
  background: var(--surface-1);
  border-right: 1px solid var(--hairline);
  display: flex;
  flex-direction: column;
  position: sticky;
  top: 0;
  height: 100vh;
}

.sidebar-brand {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 18px 20px;
  font-size: 14px;
  font-weight: 600;
  border-bottom: 1px solid var(--hairline);
}

.sidebar-nav {
  display: flex;
  flex-direction: column;
  padding: 12px;
  gap: 2px;
  flex: 1;
  overflow-y: auto;
}

.nav-btn {
  text-align: left;
  background: transparent;
  border: none;
  border-radius: 8px;
  padding: 10px 12px;
  font-size: 14px;
  color: var(--text-secondary);
  cursor: pointer;
}

.nav-btn:hover {
  background: var(--page);
  color: var(--text-primary);
}

.nav-btn.active {
  background: var(--accent-bg);
  color: var(--text-primary);
  font-weight: 600;
  box-shadow: inset 3px 0 0 var(--accent-border);
}

.sidebar-footer {
  padding: 14px 16px;
  border-top: 1px solid var(--hairline);
}

.user-name {
  font-size: 13px;
  line-height: 1.3;
  margin-bottom: 10px;
}

.user-name .role {
  display: block;
  color: var(--text-muted);
  font-size: 12px;
}

.logout-btn {
  width: 100%;
  border: 1px solid var(--border);
  background: transparent;
  color: var(--text-secondary);
  border-radius: 6px;
  padding: 7px 12px;
  font-size: 13px;
  cursor: pointer;
}

.logout-btn:hover {
  background: var(--accent-bg);
}

.app-main {
  flex: 1;
  min-width: 0;
}

.topbar {
  display: none;
  align-items: center;
  gap: 12px;
  padding: 12px 16px;
  background: var(--surface-1);
  border-bottom: 1px solid var(--hairline);
  position: sticky;
  top: 0;
  z-index: 5;
}

.topbar-title {
  font-size: 15px;
  font-weight: 600;
}

.hamburger-btn {
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 4px;
  width: 34px;
  height: 34px;
  padding: 8px;
  background: transparent;
  border: 1px solid var(--border);
  border-radius: 6px;
  cursor: pointer;
}

.hamburger-btn span {
  display: block;
  height: 2px;
  border-radius: 1px;
  background: var(--text-primary);
}

.sidebar-backdrop {
  display: none;
}

main {
  max-width: 1080px;
  margin: 0 auto;
  padding: 24px 28px 64px;
}

.tab-panel {
  animation: fade-in 0.12s ease-out;
}

@keyframes fade-in {
  from {
    opacity: 0;
  }
  to {
    opacity: 1;
  }
}

/* ---------- Stat tiles ---------- */

.stat-row {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 12px;
  margin-bottom: 24px;
}

.stat-tile {
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px 18px;
  box-shadow: var(--shadow);
}

.stat-tile .stat-label {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  color: var(--text-muted);
  margin-bottom: 6px;
}

.stat-tile .stat-value {
  font-size: 22px;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}

.stat-tile .stat-delta {
  font-size: 12px;
  color: var(--text-secondary);
  margin-top: 2px;
}

/* ---------- Group dot ---------- */

.group-dot {
  display: inline-block;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  margin-right: 6px;
  flex-shrink: 0;
}

.group-dot.g1 {
  background: var(--series-1);
}

.group-dot.g2 {
  background: var(--series-2);
}

.group-label {
  display: inline-flex;
  align-items: center;
  font-size: 13px;
}

/* ---------- Tables ---------- */

.table-card {
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13.5px;
}

thead th {
  text-align: left;
  font-size: 12px;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.02em;
  padding: 10px 16px;
  border-bottom: 1px solid var(--hairline);
  background: var(--page);
}

tbody td {
  padding: 11px 16px;
  border-bottom: 1px solid var(--hairline);
  color: var(--text-primary);
  vertical-align: middle;
}

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

td.num,
th.num {
  font-variant-numeric: tabular-nums;
  text-align: right;
}

.pill {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-size: 11px;
  font-weight: 600;
  padding: 3px 8px;
  border-radius: 999px;
  letter-spacing: 0.02em;
  white-space: nowrap;
}

.pill.pill-actual {
  background: var(--accent-border);
  color: var(--accent-text-on);
}

.pill.pill-pendiente {
  background: var(--status-muted-bg);
  color: var(--text-secondary);
}

.pill.pill-finalizado {
  background: transparent;
  color: var(--text-muted);
  border: 1px solid var(--hairline);
}

.pill.pill-active {
  background: var(--status-good-bg);
  color: var(--status-good);
}

.pill.pill-inactive {
  background: var(--status-muted-bg);
  color: var(--text-muted);
}

.pill.pill-error {
  background: rgba(208, 59, 59, 0.12);
  color: #d03b3b;
}

.table-card.table-scroll {
  overflow-x: auto;
}

.sub-tabs {
  display: flex;
  gap: 4px;
  border-bottom: 1px solid var(--hairline);
  margin-bottom: 20px;
  flex-wrap: wrap;
}

.sub-tab-btn {
  background: transparent;
  border: none;
  padding: 8px 14px;
  font-size: 13px;
  color: var(--text-secondary);
  cursor: pointer;
  border-bottom: 2px solid transparent;
  margin-bottom: -1px;
}

.sub-tab-btn:hover {
  color: var(--text-primary);
}

.sub-tab-btn.active {
  color: var(--text-primary);
  border-bottom-color: var(--accent-border);
  font-weight: 600;
}

.inline-checkbox {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 13px;
  cursor: pointer;
}

.table-card select,
.table-card input[type='text'] {
  font-family: inherit;
  font-size: 13px;
  color: var(--text-primary);
  background: var(--page);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 6px 8px;
  width: 100%;
  max-width: 220px;
}

code {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 12px;
  background: var(--page);
  padding: 2px 5px;
  border-radius: 4px;
}

.run-now-controls {
  display: flex;
  gap: 8px;
  align-items: center;
  flex-wrap: wrap;
}

.run-now-controls select {
  font-family: inherit;
  font-size: 13px;
  color: var(--text-primary);
  background: var(--page);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 8px 10px;
  max-width: 260px;
}

.run-detail-toolbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.pagination-bar {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 16px;
  margin-top: 16px;
  font-size: 13px;
}

.pagination-bar button:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

/* ---------- Ciclo row: una fila por ciclo, ramificada por grupo ---------- */

.ciclo-cell {
  font-weight: 600;
  white-space: nowrap;
  vertical-align: top;
}

.group-cell {
  vertical-align: top;
}

.group-cell-head {
  display: flex;
  align-items: center;
  font-size: 12.5px;
  color: var(--text-secondary);
  margin-bottom: 4px;
}

.group-cell-dates {
  font-size: 13px;
  margin-bottom: 6px;
  font-variant-numeric: tabular-nums;
}

.group-cell-dates .arrow {
  color: var(--text-muted);
  margin: 0 4px;
}

.group-cell.is-actual {
  background: var(--accent-bg);
  box-shadow: inset 3px 0 0 var(--accent-border);
}

tr.is-current {
  background: var(--accent-bg);
  box-shadow: inset 3px 0 0 var(--accent-border);
}

.order-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: var(--page);
  border: 1px solid var(--hairline);
  font-size: 11px;
  font-weight: 700;
  color: var(--text-secondary);
  margin-right: 8px;
}

.muted {
  color: var(--text-muted);
}

/* ---------- Structures cards ---------- */

.structures-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
  gap: 16px;
}

.structure-card {
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 18px 20px;
}

.structure-card .card-title {
  display: flex;
  align-items: center;
  font-size: 14px;
  font-weight: 600;
  margin-bottom: 12px;
}

.structure-card ul {
  list-style: none;
  margin: 0;
  padding: 0;
}

.structure-card li {
  display: flex;
  justify-content: space-between;
  padding: 9px 0;
  border-bottom: 1px solid var(--hairline);
  font-size: 13.5px;
}

.structure-card li:last-child {
  border-bottom: none;
}

.structure-card li .codigo {
  color: var(--text-muted);
  font-variant-numeric: tabular-nums;
  font-size: 12.5px;
}

.empty-state {
  padding: 32px 16px;
  text-align: center;
  color: var(--text-muted);
  font-size: 13px;
}

.loading {
  padding: 24px;
  text-align: center;
  color: var(--text-muted);
  font-size: 13px;
}

/* ---------- Configuracion (integracion GERA) ---------- */

.config-intro h2 {
  font-size: 16px;
  margin: 0 0 4px;
}

.config-intro p {
  font-size: 13px;
  margin: 0 0 20px;
}

.env-switch-banner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 16px 20px;
  margin-bottom: 20px;
  flex-wrap: wrap;
}

.env-switch-current {
  font-size: 14px;
  margin-bottom: 2px;
}

.toggle-switch {
  position: relative;
  display: inline-block;
  width: 52px;
  height: 28px;
  flex-shrink: 0;
  cursor: pointer;
}

.toggle-switch input {
  position: absolute;
  opacity: 0;
  inset: 0;
  margin: 0;
  cursor: pointer;
  z-index: 1;
}

.toggle-track {
  display: block;
  width: 52px;
  height: 28px;
  border-radius: 999px;
  background: var(--status-muted-bg);
  border: 1px solid var(--border);
  position: relative;
  transition: background 0.15s ease;
}

.toggle-thumb {
  position: absolute;
  top: 2px;
  left: 2px;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: #ffffff;
  box-shadow: 0 1px 2px rgba(11, 11, 11, 0.3);
  transition: transform 0.15s ease;
}

.toggle-switch input:checked ~ .toggle-track {
  background: var(--accent-border);
}

.toggle-switch input:checked ~ .toggle-track .toggle-thumb {
  transform: translateX(24px);
}

.toggle-switch input:disabled ~ .toggle-track {
  opacity: 0.6;
  cursor: not-allowed;
}

.config-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(320px, 1fr));
  gap: 16px;
}

.config-card {
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 18px 20px;
}

.config-card.is-active-env {
  box-shadow: var(--shadow), inset 3px 0 0 var(--accent-border);
}

.config-card-head {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 16px;
}

.config-card-subtitle {
  font-size: 13px;
  color: var(--text-secondary);
  flex: 1;
}

.pill.pill-hml {
  background: var(--natura-celeste-light);
  color: var(--text-primary);
}

.pill.pill-pdr {
  background: var(--natura-rosa-light);
  color: var(--text-primary);
}

.config-form {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.config-form label {
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-size: 12.5px;
  color: var(--text-secondary);
}

.config-form input {
  font-family: inherit;
  font-size: 13.5px;
  color: var(--text-primary);
  background: var(--page);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 8px 10px;
}

.config-form input:focus {
  outline: 2px solid var(--accent-border);
  outline-offset: -1px;
}

.config-form-actions {
  display: flex;
  gap: 8px;
  margin-top: 4px;
}

.btn-primary,
.btn-secondary {
  border-radius: 6px;
  padding: 8px 14px;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  border: 1px solid transparent;
}

.btn-primary {
  background: var(--accent-border);
  color: var(--accent-text-on);
}

.btn-primary:hover {
  opacity: 0.92;
}

.btn-secondary {
  background: transparent;
  border-color: var(--border);
  color: var(--text-secondary);
}

.btn-secondary:hover {
  background: var(--page);
}

.config-result {
  font-size: 12.5px;
  min-height: 16px;
}

.config-result.is-success {
  color: var(--status-good);
}

.config-result.is-error {
  color: #d03b3b;
}

/* ---------- Responsive: sidebar pasa a menu hamburguesa off-canvas ---------- */

@media (max-width: 900px) {
  .sidebar {
    position: fixed;
    left: 0;
    top: 0;
    z-index: 20;
    transform: translateX(-100%);
    transition: transform 0.18s ease-out;
    box-shadow: 2px 0 12px rgba(11, 11, 11, 0.15);
  }

  .app-shell.sidebar-open .sidebar {
    transform: translateX(0);
  }

  .app-shell.sidebar-open .sidebar-backdrop {
    display: block;
    position: fixed;
    inset: 0;
    background: rgba(11, 11, 11, 0.4);
    z-index: 15;
  }

  .topbar {
    display: flex;
  }

  main {
    padding: 18px 16px 48px;
  }

  .login-card {
    padding: 32px 24px;
  }

  .stat-row {
    grid-template-columns: 1fr;
  }
}

/* ---------- Responsive: tablas se apilan como tarjetas ---------- */

@media (max-width: 640px) {
  .table-card table,
  .table-card thead,
  .table-card tbody,
  .table-card tr,
  .table-card td {
    display: block;
    width: 100%;
  }

  .table-card thead {
    display: none;
  }

  .table-card tbody tr {
    padding: 12px 16px;
    border-bottom: 1px solid var(--hairline);
  }

  .table-card td {
    border-bottom: none;
    padding: 4px 0;
  }

  .table-card td.num {
    text-align: left;
  }

  .table-card td[data-label]::before {
    content: attr(data-label);
    display: block;
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.02em;
    color: var(--text-muted);
    margin-bottom: 2px;
  }

  .group-cell.is-actual {
    box-shadow: none;
    background: var(--accent-bg);
    border-radius: 8px;
    padding: 8px;
    margin: 4px 0;
  }
}
