/*
 * IO-Lab Pro · Design System
 * Dr. César Ortiz Méndez — USACH
 * Paleta: Navy profundo + Azul eléctrico + Ámbar educativo
 */

/* ── Variables globales ──────────────────────────────────────────────────── */
:root {
  --bg:        #0F1117;
  --panel:     #161B27;
  --sidebar:   #12192B;
  --border:    #222D42;
  --blue:      #3B82F6;
  --blue-d:    #2563EB;
  --blue-l:    #93C5FD;
  --green:     #10B981;
  --green-l:   #6EE7B7;
  --amber:     #F59E0B;
  --amber-l:   #FDE68A;
  --red:       #EF4444;
  --purple:    #8B5CF6;
  --cyan:      #06B6D4;
  --txt:       #E2E8F0;
  --muted:     #64748B;
  --muted2:    #94A3B8;
  --mono:      'JetBrains Mono', 'Fira Code', monospace;
  --sans:      'Inter', system-ui, sans-serif;
  --radius:    10px;
  --radius-sm: 6px;
  --shadow:    0 4px 24px rgba(0,0,0,.35);
}

/* ── Reset y base ────────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html { scroll-behavior: smooth; }

body {
  font-family: var(--sans);
  background: var(--bg);
  color: var(--txt);
  min-height: 100vh;
  font-size: 14px;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
}

/* ── Layout principal ────────────────────────────────────────────────────── */
.app-layout {
  display: grid;
  grid-template-columns: 240px 1fr;
  grid-template-rows: auto 1fr;
  min-height: 100vh;
}

@media (max-width: 768px) {
  .app-layout { grid-template-columns: 1fr; }
  .sidebar { display: none; }
  .sidebar.open { display: flex; position: fixed; z-index: 200; top: 0; left: 0; height: 100vh; width: 260px; }
}

/* ── Topbar ──────────────────────────────────────────────────────────────── */
.topbar {
  grid-column: 1 / -1;
  background: var(--panel);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  padding: 0 20px;
  height: 56px;
  gap: 14px;
  position: sticky;
  top: 0;
  z-index: 100;
}

.topbar-logo {
  display: flex;
  align-items: center;
  gap: 10px;
  text-decoration: none;
}

.logo-icon {
  width: 36px; height: 36px;
  background: linear-gradient(135deg, #3B82F6, #8B5CF6);
  border-radius: 9px;
  display: flex; align-items: center; justify-content: center;
  font-size: 18px; flex-shrink: 0;
}

.logo-name { font-size: 16px; font-weight: 700; color: var(--txt); letter-spacing: -.3px; }
.logo-ver  { font-size: 10px; color: var(--muted); margin-top: 1px; }

.topbar-title {
  font-size: 14px;
  color: var(--muted2);
  border-left: 1px solid var(--border);
  padding-left: 14px;
  margin-left: 4px;
}

.topbar-actions { margin-left: auto; display: flex; gap: 8px; align-items: center; }

.hamburger {
  display: none;
  background: none; border: none; color: var(--txt);
  font-size: 22px; cursor: pointer; padding: 4px;
}
@media (max-width: 768px) { .hamburger { display: block; } }

/* ── Sidebar ─────────────────────────────────────────────────────────────── */
.sidebar {
  background: var(--sidebar);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  overflow-y: auto;
  position: sticky;
  top: 56px;
  height: calc(100vh - 56px);
}

.nav-group {
  padding: 14px 12px 4px;
  font-size: 10px;
  font-weight: 600;
  letter-spacing: .1em;
  text-transform: uppercase;
  color: var(--muted);
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 8px 12px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  color: var(--muted2);
  transition: all .13s;
  margin: 1px 8px;
  font-size: 12.5px;
  font-weight: 500;
  text-decoration: none;
}

.nav-item:hover  { background: #1C2740; color: var(--txt); }
.nav-item.active { background: rgba(59,130,246,.15); color: var(--blue); }
.nav-item .ni    { font-size: 15px; width: 18px; text-align: center; flex-shrink: 0; }

.nav-badge {
  margin-left: auto;
  font-size: 9px;
  background: rgba(59,130,246,.18);
  color: var(--blue);
  padding: 1px 5px;
  border-radius: 10px;
  font-family: var(--mono);
}

/* ── Main content ────────────────────────────────────────────────────────── */
.main-content { overflow-y: auto; }
.page-wrapper { max-width: 1200px; margin: 0 auto; padding: 28px 20px; }

/* ── Módulo header ───────────────────────────────────────────────────────── */
.module-header {
  margin-bottom: 24px;
  padding-bottom: 18px;
  border-bottom: 1px solid var(--border);
}

.module-header h1 {
  font-size: 22px;
  font-weight: 700;
  color: var(--txt);
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 6px;
}

.module-header .icon-badge {
  width: 38px; height: 38px;
  border-radius: 9px;
  display: flex; align-items: center; justify-content: center;
  font-size: 20px; flex-shrink: 0;
}

.module-header p { font-size: 13px; color: var(--muted2); line-height: 1.5; max-width: 700px; }

.module-header .breadcrumb {
  font-size: 11px;
  color: var(--muted);
  margin-bottom: 8px;
  display: flex; align-items: center; gap: 5px;
}
.module-header .breadcrumb a { color: var(--muted); text-decoration: none; }
.module-header .breadcrumb a:hover { color: var(--blue); }

/* ── Cards ───────────────────────────────────────────────────────────────── */
.card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  margin-bottom: 16px;
}

.card-title {
  font-size: 11px;
  font-weight: 600;
  color: var(--muted2);
  text-transform: uppercase;
  letter-spacing: .07em;
  margin-bottom: 14px;
  display: flex;
  align-items: center;
  gap: 6px;
}

.card-title .dot {
  width: 6px; height: 6px;
  border-radius: 50%;
  background: var(--blue);
  display: inline-block;
}

/* ── Grid helpers ─────────────────────────────────────────────────────────── */
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.grid-3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 16px; }
.grid-4 { display: grid; grid-template-columns: repeat(4,1fr); gap: 12px; }
@media (max-width: 900px) { .grid-2, .grid-3, .grid-4 { grid-template-columns: 1fr; } }
@media (max-width: 1100px) { .grid-3, .grid-4 { grid-template-columns: 1fr 1fr; } }

/* ── Formularios ─────────────────────────────────────────────────────────── */
.form-label { font-size: 12px; color: var(--muted2); display: block; margin-bottom: 4px; }

.form-control, .form-select {
  background: #0D1117;
  border: 1px solid var(--border);
  color: var(--txt);
  border-radius: var(--radius-sm);
  padding: 7px 10px;
  font-family: var(--sans);
  font-size: 13px;
  outline: none;
  transition: border .13s;
  width: 100%;
}

.form-control:focus, .form-select:focus { border-color: var(--blue); }
.form-select option { background: var(--panel); }

.form-group { margin-bottom: 12px; }

/* ── Botones ─────────────────────────────────────────────────────────────── */
.btn {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 8px 16px; border-radius: var(--radius-sm);
  border: none; cursor: pointer;
  font-size: 13px; font-weight: 500;
  font-family: var(--sans);
  transition: all .13s;
  text-decoration: none;
}

.btn-primary   { background: var(--blue);  color: #fff; }
.btn-primary:hover { background: var(--blue-d); }
.btn-success   { background: rgba(16,185,129,.15); color: var(--green); border: 1px solid rgba(16,185,129,.3); }
.btn-success:hover { background: rgba(16,185,129,.25); }
.btn-warning   { background: rgba(245,158,11,.15); color: var(--amber); border: 1px solid rgba(245,158,11,.3); }
.btn-secondary { background: #1C2740; color: var(--txt); border: 1px solid var(--border); }
.btn-secondary:hover { background: #232D42; }
.btn-sm { padding: 5px 11px; font-size: 12px; }
.btn-lg { padding: 10px 22px; font-size: 14px; }

/* ── Alertas educativas ──────────────────────────────────────────────────── */
.alert {
  padding: 12px 16px;
  border-radius: var(--radius-sm);
  font-size: 13px;
  margin-bottom: 14px;
  line-height: 1.55;
  display: flex; gap: 10px;
}

.alert-info    { background: rgba(59,130,246,.08);  border: 1px solid rgba(59,130,246,.3);  color: var(--blue-l); }
.alert-success { background: rgba(16,185,129,.08);  border: 1px solid rgba(16,185,129,.3);  color: var(--green-l); }
.alert-warning { background: rgba(245,158,11,.08);  border: 1px solid rgba(245,158,11,.3);  color: var(--amber-l); }
.alert-danger  { background: rgba(239,68,68,.08);   border: 1px solid rgba(239,68,68,.3);   color: #FCA5A5; }
.alert-edu     { background: rgba(139,92,246,.08);  border: 1px solid rgba(139,92,246,.3);  color: #C4B5FD; }

.alert-icon { font-size: 16px; flex-shrink: 0; margin-top: 1px; }

/* ── Matrices / Tablas ───────────────────────────────────────────────────── */
.table-wrapper { overflow-x: auto; }

table.matrix { border-collapse: separate; border-spacing: 3px; }
table.matrix th {
  background: #1C2333; padding: 6px 10px;
  font-size: 10.5px; font-weight: 600; color: var(--muted);
  text-align: center; border-radius: 4px; min-width: 46px;
  white-space: nowrap;
}
table.matrix td { padding: 2px; }
table.matrix td input {
  width: 62px; text-align: center;
  font-family: var(--mono); font-size: 12px;
  background: #0D1117; border: 1px solid var(--border);
  color: var(--txt); border-radius: 4px;
  padding: 5px 4px; outline: none;
  transition: border .12s;
}
table.matrix td input:focus { border-color: var(--blue); }
table.matrix td.lc {
  background: #1C2333; padding: 5px 10px;
  border-radius: 4px; font-size: 11.5px; font-weight: 500;
  color: var(--muted2); text-align: center; vertical-align: middle;
  white-space: nowrap;
}
.cell-opt  { border-color: var(--green)!important; background: rgba(16,185,129,.08)!important; color: var(--green)!important; }
.cell-path { border-color: var(--blue)!important;  background: rgba(59,130,246,.08)!important; }

/* Tabla de resultados */
table.result-table { width: 100%; border-collapse: collapse; }
table.result-table th {
  background: #1C2333; padding: 8px 12px;
  font-size: 11px; color: var(--muted); font-weight: 600;
  text-align: left; border-bottom: 1px solid var(--border);
  white-space: nowrap;
}
table.result-table td {
  padding: 7px 12px; border-bottom: 1px solid rgba(34,45,66,.5);
  font-size: 12.5px;
}
table.result-table tr:hover td { background: rgba(59,130,246,.04); }
table.result-table td.critical { color: var(--red); font-weight: 600; }
table.result-table td.optimal  { color: var(--amber); font-weight: 700; }
table.result-table td.success  { color: var(--green); }

/* ── Stats ───────────────────────────────────────────────────────────────── */
.stats-row { display: flex; gap: 10px; flex-wrap: wrap; margin-bottom: 16px; }

.stat-card {
  background: #0D1117;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 12px 16px;
  flex: 1; min-width: 110px;
}
.stat-label { font-size: 10px; color: var(--muted); margin-bottom: 4px; text-transform: uppercase; letter-spacing: .05em; }
.stat-value { font-size: 22px; font-weight: 700; font-family: var(--mono); color: var(--blue); }
.stat-value.green  { color: var(--green); }
.stat-value.amber  { color: var(--amber); }
.stat-value.red    { color: var(--red); }
.stat-value.purple { color: var(--purple); }
.stat-sub   { font-size: 10px; color: var(--muted); margin-top: 2px; }

/* ── Result box (terminal style) ─────────────────────────────────────────── */
.result-box {
  background: #0A0E17;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 16px;
  font-family: var(--mono);
  font-size: 12px;
  color: var(--green);
  white-space: pre-wrap;
  line-height: 1.8;
  max-height: 340px;
  overflow-y: auto;
}

/* ── Canvas ──────────────────────────────────────────────────────────────── */
canvas.iolab-canvas {
  background: #0A0E17;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  display: block;
  width: 100%;
  max-width: 100%;
}

.canvas-hint { font-size: 11px; color: var(--muted); margin-top: 6px; }

/* ── AHP specific ────────────────────────────────────────────────────────── */
.scale-ref { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 12px; }
.scale-chip {
  padding: 3px 9px; border-radius: 20px;
  font-size: 11px; font-family: var(--mono);
  background: rgba(139,92,246,.12);
  border: 1px solid rgba(139,92,246,.3);
  color: #C4B5FD; cursor: pointer;
  transition: all .12s;
}
.scale-chip:hover { background: rgba(139,92,246,.25); }

/* ── TOPSIS steps ────────────────────────────────────────────────────────── */
.topsis-steps { display: flex; gap: 3px; margin-bottom: 14px; }
.tstep {
  flex: 1; padding: 7px 5px; border-radius: 5px;
  background: #0D1117; border: 1px solid var(--border);
  font-size: 10.5px; text-align: center; color: var(--muted);
  transition: all .15s;
}
.tstep.done   { border-color: var(--green); color: var(--green); }
.tstep.active { border-color: var(--blue);  color: var(--blue); }

/* ── Queue diagram ───────────────────────────────────────────────────────── */
.queue-diagram {
  display: flex; align-items: center; gap: 0;
  margin: 14px 0; padding: 12px 16px;
  background: #0D1117; border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  overflow-x: auto;
}
.qd-block {
  padding: 10px 14px; border-radius: 7px;
  font-size: 11px; text-align: center;
  white-space: nowrap;
}
.qd-arr { color: var(--muted); font-size: 22px; padding: 0 8px; }

/* ── Home cards ──────────────────────────────────────────────────────────── */
.module-card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  text-decoration: none;
  display: flex; flex-direction: column; gap: 10px;
  transition: border-color .15s, transform .12s;
  position: relative;
  overflow: hidden;
}
.module-card::before {
  content: '';
  position: absolute; top: 0; left: 0; right: 0; height: 3px;
  background: linear-gradient(90deg, var(--blue), var(--purple));
  opacity: 0; transition: opacity .15s;
}
.module-card:hover { border-color: rgba(59,130,246,.4); transform: translateY(-2px); }
.module-card:hover::before { opacity: 1; }
.module-card .mc-icon { font-size: 26px; }
.module-card .mc-title { font-size: 14px; font-weight: 600; color: var(--txt); }
.module-card .mc-desc  { font-size: 12px; color: var(--muted2); line-height: 1.5; flex: 1; }
.module-card .mc-badge {
  font-size: 10px; padding: 2px 7px; border-radius: 10px;
  background: rgba(59,130,246,.15); color: var(--blue);
  font-family: var(--mono); width: fit-content;
}

/* ── Theory box ──────────────────────────────────────────────────────────── */
.theory-box {
  background: rgba(139,92,246,.06);
  border: 1px solid rgba(139,92,246,.2);
  border-radius: var(--radius-sm);
  padding: 14px 16px;
  margin-bottom: 14px;
}
.theory-box h4 { font-size: 12px; color: #C4B5FD; margin-bottom: 8px; font-weight: 600; }
.theory-box p  { font-size: 12px; color: var(--muted2); line-height: 1.6; }
.theory-box .formula {
  font-family: var(--mono); font-size: 12.5px;
  color: var(--amber-l); margin: 8px 0;
  padding: 6px 10px; background: rgba(0,0,0,.3);
  border-radius: 4px; display: block;
}

/* ── Stepper ─────────────────────────────────────────────────────────────── */
.stepper { display: flex; gap: 0; margin-bottom: 16px; border-radius: var(--radius-sm); overflow: hidden; }
.step {
  flex: 1; padding: 8px; font-size: 11px; text-align: center;
  background: #0D1117; border: 1px solid var(--border);
  color: var(--muted); cursor: pointer; transition: all .13s;
}
.step:not(:last-child) { border-right: none; }
.step.active { background: rgba(59,130,246,.15); border-color: var(--blue); color: var(--blue); font-weight: 600; }
.step.done   { background: rgba(16,185,129,.1); border-color: var(--green); color: var(--green); }

/* ── Scrollbar ───────────────────────────────────────────────────────────── */
::-webkit-scrollbar { width: 5px; height: 5px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }

/* ── Footer ──────────────────────────────────────────────────────────────── */
.site-footer {
  padding: 16px 20px;
  border-top: 1px solid var(--border);
  font-size: 11px; color: var(--muted);
  display: flex; justify-content: space-between; align-items: center;
  flex-wrap: wrap; gap: 8px;
  margin-top: 32px;
}
.site-footer a { color: var(--blue); text-decoration: none; }
.site-footer a:hover { text-decoration: underline; }

/* ── Spinner ─────────────────────────────────────────────────────────────── */
.spinner {
  width: 22px; height: 22px;
  border: 2px solid var(--border);
  border-top-color: var(--blue);
  border-radius: 50%;
  animation: spin .6s linear infinite;
  display: inline-block;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ── Excel I/O widget (compartido por todos los módulos de Logística) ─────── */
.excel-io-bar {
  display: flex; gap: 8px; flex-wrap: wrap; align-items: center;
  padding: 12px 14px; background: rgba(16,185,129,.06);
  border: 1px solid rgba(16,185,129,.25); border-radius: var(--radius-sm);
  margin-bottom: 16px;
}
.excel-io-bar .eio-label { font-size: 11px; color: var(--green-l); font-weight: 600; margin-right: 4px; }
.btn-excel {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 6px 13px; border-radius: var(--radius-sm);
  border: 1px solid rgba(16,185,129,.35); background: rgba(16,185,129,.1);
  color: var(--green-l); cursor: pointer; font-size: 12px; font-weight: 500;
  transition: all .13s; text-decoration: none;
}
.btn-excel:hover { background: rgba(16,185,129,.2); }
.btn-excel input[type=file] { display: none; }
.excel-status { font-size: 11px; color: var(--muted); margin-left: 4px; }
.excel-status.success { color: var(--green); }
.excel-status.error { color: var(--red); }

/* ── Logistics hub cards ─────────────────────────────────────────────────── */
.logi-card { position: relative; }
.logi-badge-new {
  position: absolute; top: 10px; right: 10px;
  font-size: 9px; font-weight: 700; padding: 2px 7px;
  border-radius: 10px; background: var(--amber); color: #1A1300;
  letter-spacing: .04em;
}
.logi-excel-tag {
  font-size: 9px; padding: 1px 6px; border-radius: 8px;
  background: rgba(16,185,129,.15); color: var(--green);
  font-family: var(--mono); width: fit-content; margin-top: 4px;
}

/* ── PWA: tarjeta de instalación ─────────────────────────────────────────── */
.pwa-install-card {
  position: fixed;
  right: 22px;
  bottom: 22px;
  z-index: 300;
  display: grid;
  grid-template-columns: 54px 1fr;
  gap: 14px;
  max-width: 430px;
  padding: 14px;
  background: linear-gradient(180deg, #161B27, #0F1117);
  border: 1px solid var(--border);
  border-left: 3px solid var(--blue);
  border-radius: var(--radius);
  box-shadow: 0 20px 48px rgba(0,0,0,.45), 0 0 18px rgba(59,130,246,.10);
}

.pwa-install-card[hidden] { display: none !important; }

.pwa-install-card__icon {
  width: 54px;
  height: 54px;
  display: grid;
  place-items: center;
  border-radius: 14px;
  background: linear-gradient(135deg, #3B82F6, #8B5CF6);
  color: #fff;
  font-size: 19px;
  font-weight: 800;
  letter-spacing: -.06em;
  box-shadow: 0 10px 26px rgba(59,130,246,.22);
}

.pwa-install-card__title {
  color: var(--txt);
  font-weight: 800;
  font-size: 14px;
  margin-bottom: 2px;
}

.pwa-install-card__text {
  color: var(--muted2);
  font-size: 13px;
  line-height: 1.45;
}

.pwa-install-card__actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  margin-top: 10px;
}

.pwa-install-card__help {
  margin-top: 10px;
  padding: 10px 12px;
  border: 1px dashed var(--border);
  border-radius: var(--radius-sm);
  color: var(--muted2);
  background: #0D1117;
  font-size: 12.5px;
  line-height: 1.45;
}

@media (max-width: 560px) {
  .pwa-install-card {
    left: 12px;
    right: 12px;
    bottom: 12px;
    max-width: none;
    grid-template-columns: 44px 1fr;
    gap: 11px;
    padding: 12px;
  }

  .pwa-install-card__icon {
    width: 44px;
    height: 44px;
    border-radius: 12px;
    font-size: 16px;
  }

  .pwa-install-card__title { font-size: 13px; }
  .pwa-install-card__text { font-size: 12.5px; }
}
