/* ─── Variables ─────────────────────────────────────────────────────────── */
:root {
  --bg:      #f8fafc;
  --card:    #ffffff;
  --border:  #e2e8f0;
  --text:    #1e293b;
  --muted:   #64748b;
  --primary: #1a3c6d;
  --primary-hover: #0f2a5c;
  --radius:  10px;

  --bajo:    #166534;  --bajo-bg:    #dcfce7;
  --mod:     #854d0e;  --mod-bg:     #fef9c3;
  --alto:    #9a3412;  --alto-bg:    #ffedd5;
  --crit:    #991b1b;  --crit-bg:    #fee2e2;
}

/* ─── Reset / base ──────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
body {
  font-family: system-ui, -apple-system, Segoe UI, Roboto, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 15px;
  line-height: 1.5;
}

/* ─── Nav ───────────────────────────────────────────────────────────────── */
nav {
  background: var(--primary);
  padding: 10px 20px;
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  align-items: center;
}
nav a {
  color: #fff;
  text-decoration: none;
  padding: 6px 14px;
  border-radius: 6px;
  font-size: 0.9em;
  transition: background 0.2s;
}
nav a:hover { background: rgba(255,255,255,0.15); }

/* ─── Layout ────────────────────────────────────────────────────────────── */
.container {
  max-width: 1300px;
  margin: 0 auto;
  padding: 30px 20px 60px;
}
h1 {
  color: var(--primary);
  font-size: 1.9rem;
  margin-bottom: 4px;
}
.subtitle {
  color: var(--muted);
  margin-bottom: 28px;
  font-size: 0.95em;
}

/* ─── Card ──────────────────────────────────────────────────────────────── */
.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 24px;
  margin-bottom: 20px;
  box-shadow: 0 1px 4px rgba(0,0,0,0.06);
}

/* ─── Form grid ─────────────────────────────────────────────────────────── */
.form-row {
  display: flex;
  gap: 16px;
  flex-wrap: wrap;
  margin-bottom: 16px;
}
.field {
  display: flex;
  flex-direction: column;
  gap: 5px;
  flex: 1;
  min-width: 180px;
}
.field label {
  font-size: 0.82em;
  font-weight: 600;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}
.field input,
.field select,
.field textarea {
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 0.95em;
  font-family: inherit;
  color: var(--text);
  background: #fff;
  transition: border-color 0.2s;
}
.field input:focus,
.field select:focus,
.field textarea:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(26,60,109,0.08);
}
.field select:disabled { background: #f1f5f9; color: var(--muted); cursor: not-allowed; }
.field textarea { resize: vertical; min-height: 60px; }
.field-empresa { max-width: 340px; }

/* ─── Sliders ───────────────────────────────────────────────────────────── */
.sliders-row {
  align-items: flex-end;
  gap: 20px;
}
.slider-group {
  flex: 1;
  min-width: 160px;
}
.slider-group label {
  font-size: 0.82em;
  font-weight: 600;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  display: flex;
  justify-content: space-between;
  margin-bottom: 4px;
}
.slider-group label .val-badge {
  background: var(--primary);
  color: #fff;
  padding: 1px 7px;
  border-radius: 10px;
  font-size: 0.9em;
  font-weight: 700;
}
.slider-group .slider-hint {
  font-size: 0.78em;
  color: var(--muted);
  margin-top: 2px;
}
input[type="range"] {
  width: 100%;
  accent-color: var(--primary);
  cursor: pointer;
}

/* ─── IR display ────────────────────────────────────────────────────────── */
.ir-box {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-width: 110px;
  padding: 10px 16px;
  border-radius: var(--radius);
  border: 2px solid var(--border);
  background: #f8fafc;
  transition: all 0.25s;
}
.ir-box .ir-num {
  font-size: 2rem;
  font-weight: 800;
  line-height: 1;
  color: var(--text);
}
.ir-box .nivel-label {
  font-size: 0.8em;
  font-weight: 700;
  padding: 2px 10px;
  border-radius: 20px;
  letter-spacing: 0.03em;
}

/* nivel colors */
.nivel-bajo   { color: var(--bajo);  background: var(--bajo-bg); }
.nivel-mod    { color: var(--mod);   background: var(--mod-bg); }
.nivel-alto   { color: var(--alto);  background: var(--alto-bg); }
.nivel-crit   { color: var(--crit);  background: var(--crit-bg); }

.ir-box.ir-bajo  { border-color: #86efac; background: #f0fdf4; }
.ir-box.ir-mod   { border-color: #fcd34d; background: #fffbeb; }
.ir-box.ir-alto  { border-color: #fb923c; background: #fff7ed; }
.ir-box.ir-crit  { border-color: #f87171; background: #fef2f2; }

/* ─── Buttons ───────────────────────────────────────────────────────────── */
.form-footer {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  margin-top: 4px;
}
.btn {
  padding: 9px 20px;
  border: none;
  border-radius: 6px;
  font-size: 0.92em;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  gap: 6px;
}
.btn-primary  { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-hover); transform: translateY(-1px); }
.btn-export   { background: #0f766e; color: #fff; }
.btn-export:hover { background: #0d6460; }
.btn-print    { background: #6366f1; color: #fff; }
.btn-print:hover { background: #4f46e5; }
.btn-danger   { background: #fee2e2; color: #991b1b; }
.btn-danger:hover { background: #fecaca; }
.btn-sm { padding: 4px 10px; font-size: 0.82em; }

/* ─── Table actions bar ─────────────────────────────────────────────────── */
.table-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 10px;
  margin-bottom: 12px;
}
.table-bar h2 { font-size: 1.05em; color: var(--primary); }
.table-bar .actions { display: flex; gap: 8px; flex-wrap: wrap; }

/* ─── Table ─────────────────────────────────────────────────────────────── */
.table-wrap {
  overflow-x: auto;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  box-shadow: 0 1px 4px rgba(0,0,0,0.04);
}
table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.875em;
  min-width: 1000px;
}
thead tr {
  background: var(--primary);
  color: #fff;
}
thead th {
  padding: 10px 12px;
  text-align: left;
  font-weight: 600;
  white-space: nowrap;
}
tbody tr { border-bottom: 1px solid var(--border); transition: background 0.15s; }
tbody tr:hover { background: #f8fafc; }
tbody tr:last-child { border-bottom: none; }
tbody td { padding: 9px 12px; vertical-align: top; }
td.num { text-align: center; font-weight: 700; }

/* nivel pill en tabla */
.pill {
  display: inline-block;
  padding: 2px 9px;
  border-radius: 12px;
  font-size: 0.8em;
  font-weight: 700;
  white-space: nowrap;
}

/* ─── Empty state ───────────────────────────────────────────────────────── */
.empty-row td {
  text-align: center;
  padding: 40px;
  color: var(--muted);
  font-style: italic;
}

/* ─── Spinner / feedback ─────────────────────────────────────────────────── */
.toast {
  position: fixed;
  bottom: 24px;
  right: 24px;
  background: #1e293b;
  color: #fff;
  padding: 10px 18px;
  border-radius: 8px;
  font-size: 0.9em;
  opacity: 0;
  transform: translateY(10px);
  transition: all 0.3s;
  pointer-events: none;
  z-index: 9999;
}
.toast.show { opacity: 1; transform: translateY(0); }

/* ─── Print view (matriz.php) ───────────────────────────────────────────── */
@media print {
  nav, .form-card, .table-bar .actions, .btn-del { display: none !important; }
  body { background: #fff; font-size: 11pt; }
  table { font-size: 9pt; min-width: 0; }
  .table-wrap { overflow: visible; border: none; box-shadow: none; }
}

/* ─── Responsive ────────────────────────────────────────────────────────── */
@media (max-width: 640px) {
  h1 { font-size: 1.4rem; }
  .card { padding: 16px; }
  .field { min-width: 100%; }
  .sliders-row { flex-direction: column; }
}
