/* ============================================================
   ORION — Sistema de diseño unificado
   Consola de inteligencia · oscuro profundo + dorado institucional
   Tipografía: Rajdhani (display) · IBM Plex Sans (texto) · IBM Plex Mono (datos)
   Reemplaza a premium.css y a los <style> duplicados de cada template.
   Regla de la casa: acá NO se usa !important. Los estilos específicos
   de página viven en {% block styles %} y ganan por orden de carga.
   ============================================================ */

/* ---------- 1. Variables (incluye alias legados de los templates) ---------- */
:root {
  /* fondo y superficies */
  --bg: #07090e;
  --bg-raise: #0e1420;
  --card: #111722;
  --card-bg: #111722;
  --card-2: #17202d;
  --card2: #17202d;
  --card-bg-soft: #17202d;
  --soft: #17202d;

  /* bordes */
  --border: #2a3548;
  --b: #2a3548;
  --border-soft: rgba(159, 183, 201, .16);

  /* identidad dorada */
  --gold: #d7b46a;
  --gold2: #e4c77f;
  --gold-soft: #e9cf8b;
  --gold-deep: #b98f3f;
  --accent: #d7b46a;
  --accent-2: #9fb7c9;

  /* texto */
  --ink: #eef3f8;
  --text: #eef3f8;
  --text-main: #eef3f8;
  --t: #eef3f8;
  --muted: #a9b6c4;
  --text-muted: #a9b6c4;
  --m: #a9b6c4;

  /* estados */
  --danger: #ef7d7d;
  --red: #ef7d7d;
  --success: #73c89b;
  --green: #73c89b;

  /* detalles */
  --bar: linear-gradient(180deg, #f0d99a, #b98f3f);
  --bar-strong: linear-gradient(180deg, #ffe9b0, #a87f33);
  --shadow: 0 18px 46px rgba(0, 0, 0, .32);
  --shadow-soft: 0 10px 26px rgba(0, 0, 0, .22);
  --radius: 10px;

  --font-body: "IBM Plex Sans", ui-sans-serif, system-ui, "Segoe UI", sans-serif;
  --font-display: "Rajdhani", "IBM Plex Sans", ui-sans-serif, sans-serif;
  --font-mono: "IBM Plex Mono", ui-monospace, "Cascadia Mono", monospace;

  /* sidebar */
  --sb-w: 232px;
  --sb-w-min: 64px;
}

/* ---------- 2. Base ---------- */
* { box-sizing: border-box; }

html { background: var(--bg); }

body {
  margin: 0;
  padding: 0;
  min-height: 100vh;
  color: var(--text);
  font-family: var(--font-body);
  font-size: 14.5px;
  line-height: 1.5;
  background:
    radial-gradient(1100px 500px at 18% -8%, rgba(215, 180, 106, .07), transparent 60%),
    radial-gradient(900px 420px at 92% -6%, rgba(159, 183, 201, .06), transparent 55%),
    linear-gradient(180deg, #101826 0%, var(--bg) 300px);
}

/* trama sutil de fondo: rejilla de consola, casi imperceptible */
body::before {
  content: "";
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: -1;
  background-image:
    linear-gradient(rgba(159, 183, 201, .025) 1px, transparent 1px),
    linear-gradient(90deg, rgba(159, 183, 201, .025) 1px, transparent 1px);
  background-size: 44px 44px;
  mask-image: linear-gradient(180deg, rgba(0,0,0,.9), transparent 70%);
}

/* hilo dorado en el borde superior de la pantalla */
body::after {
  content: "";
  position: fixed;
  top: 0; left: 0; right: 0;
  height: 2px;
  z-index: 50;
  background: linear-gradient(90deg, transparent, var(--gold) 18%, var(--gold2) 50%, var(--gold) 82%, transparent);
  opacity: .65;
  pointer-events: none;
}

::selection { background: rgba(215, 180, 106, .32); color: #fff7e3; }

a { color: var(--gold-soft); text-decoration-thickness: 1px; text-underline-offset: 3px; }
a:hover { color: #f6e3ab; }

h1, h2, h3 {
  font-family: var(--font-display);
  font-weight: 600;
  letter-spacing: .02em;
  color: #f3d58f;
  margin: 0 0 10px;
}
h1 { font-size: 26px; }
h2 { font-size: 20px; }
h3 { font-size: 17px; }

.container { width: min(100%, 1220px); margin: 0 auto; }

.muted, .text-muted { color: var(--muted); }
.small { font-size: 12.5px; }
.nowrap { white-space: nowrap; }

/* ---------- 2b. Layout con sidebar ---------- */
.layout {
  display: grid;
  grid-template-columns: var(--sb-w) minmax(0, 1fr);
  min-height: 100vh;
  transition: grid-template-columns .18s ease;
}
.layout.no-sb { grid-template-columns: minmax(0, 1fr); }
html.sb-collapsed .layout { grid-template-columns: var(--sb-w-min) minmax(0, 1fr); }

.main { min-width: 0; padding: 20px; }

/* --- sidebar --- */
.sidebar {
  position: sticky;
  top: 0;
  height: 100vh;
  display: flex;
  flex-direction: column;
  overflow-y: auto;
  overflow-x: hidden;
  background: linear-gradient(180deg, rgba(13, 19, 28, .98), rgba(9, 13, 20, .99));
  border-right: 1px solid var(--border-soft);
  box-shadow: var(--shadow-soft);
}

.sb-brand {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 14px 14px 12px;
  border-bottom: 1px solid var(--border-soft);
  text-decoration: none;
  color: inherit;
}
.sb-logo { width: 40px; height: 40px; flex: 0 0 40px; object-fit: contain; filter: drop-shadow(0 8px 14px rgba(0, 0, 0, .3)); }
.sb-brand-text { display: flex; flex-direction: column; min-width: 0; }
.sb-brand-main {
  font-family: var(--font-display);
  font-size: 19px;
  font-weight: 700;
  letter-spacing: .1em;
  color: #f7fafc;
  line-height: 1.1;
}
.sb-brand-sub {
  font-family: var(--font-mono);
  font-size: 10px;
  letter-spacing: .14em;
  text-transform: uppercase;
  color: var(--gold);
  white-space: nowrap;
}

.sb-nav { flex: 1 1 auto; padding: 10px 8px; display: flex; flex-direction: column; gap: 2px; }

.sb-link {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  padding: 8px 10px;
  font: inherit;
  font-size: 13.5px;
  font-weight: 500;
  text-align: left;
  color: #cdd8e4;
  background: none;
  border: 1px solid transparent;
  border-radius: 8px;
  box-shadow: none;
  min-height: 0;
  cursor: pointer;
  text-decoration: none;
  transition: background-color .14s ease, color .14s ease, border-color .14s ease;
}
.sb-link:hover {
  background: rgba(159, 183, 201, .09);
  color: #f0f5fa;
  border-color: transparent;
  transform: none;
  box-shadow: none;
  text-decoration: none;
}
.sb-link.active {
  background: rgba(215, 180, 106, .12);
  border-color: rgba(215, 180, 106, .35);
  color: #f0d99a;
}
.sb-ico { flex: 0 0 22px; width: 22px; text-align: center; font-size: 15px; line-height: 1; }
.sb-text { flex: 1 1 auto; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sb-caret { flex: 0 0 auto; font-size: 11px; color: var(--muted); transition: transform .14s ease; }
.sb-group.open .sb-caret { transform: rotate(180deg); }

.sb-sub { display: none; flex-direction: column; gap: 1px; padding: 2px 0 4px 30px; }
.sb-group.open .sb-sub { display: flex; }
.sb-sublink {
  display: block;
  padding: 5px 10px;
  font-size: 12.8px;
  color: var(--muted);
  border-left: 1px solid rgba(159, 183, 201, .18);
  border-radius: 0 7px 7px 0;
  text-decoration: none;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.sb-sublink:hover { color: #f0f5fa; background: rgba(159, 183, 201, .08); }
.sb-sublink.active { color: var(--gold-soft); border-left-color: var(--gold); background: rgba(215, 180, 106, .08); }

.sb-foot { flex: 0 0 auto; padding: 8px; border-top: 1px solid var(--border-soft); display: flex; flex-direction: column; gap: 2px; }
.sb-user {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 6px 10px 8px;
  font-size: 12.5px;
  font-weight: 600;
  color: var(--text);
}
.sb-user .sb-text { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* colapsada a iconos (escritorio) */
html.sb-collapsed .sb-text,
html.sb-collapsed .sb-caret,
html.sb-collapsed .sb-brand-text,
html.sb-collapsed .sb-sub { display: none; }
html.sb-collapsed .sb-brand { justify-content: center; padding-left: 8px; padding-right: 8px; }
html.sb-collapsed .sb-link { justify-content: center; padding-left: 6px; padding-right: 6px; }
html.sb-collapsed .sb-user { justify-content: center; padding-left: 6px; padding-right: 6px; }
html.sb-collapsed .sb-caret-collapse { transform: rotate(180deg); }

.sb-overlay { display: none; }

.hamburger {
  display: none;
  flex: 0 0 auto;
  min-height: 0;
  padding: 6px 10px;
  font-size: 18px;
  color: var(--gold);
  background: rgba(215, 180, 106, .07);
  border: 1px solid rgba(215, 180, 106, .4);
  border-radius: 8px;
  box-shadow: none;
}
.hamburger:hover { background: rgba(215, 180, 106, .14); color: var(--gold2); transform: none; box-shadow: none; }

/* off-canvas en pantallas chicas */
@media (max-width: 768px) {
  .layout, html.sb-collapsed .layout { display: block; }
  .sidebar {
    position: fixed;
    z-index: 90;
    top: 0; left: 0; bottom: 0;
    width: min(82vw, var(--sb-w));
    height: 100dvh;
    transform: translateX(-105%);
    transition: transform .2s ease;
  }
  body.sb-open .sidebar { transform: translateX(0); }
  /* en móvil la barra siempre muestra textos, aunque esté "colapsada" en escritorio */
  html.sb-collapsed .sb-text,
  html.sb-collapsed .sb-caret,
  html.sb-collapsed .sb-brand-text { display: initial; }
  html.sb-collapsed .sb-group.open .sb-sub { display: flex; }
  html.sb-collapsed .sb-link { justify-content: flex-start; padding: 8px 10px; }
  body.sb-open .sb-overlay {
    display: block;
    position: fixed;
    inset: 0;
    z-index: 80;
    background: rgba(4, 6, 10, .62);
    backdrop-filter: blur(2px);
  }
  .hamburger { display: inline-flex; }
}

/* ---------- 3. Encabezado ---------- */
.top, .top-bar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 18px;
  flex-wrap: wrap;
  margin: 0 auto 12px;
  padding: 12px 16px;
  border: 1px solid var(--border-soft);
  border-radius: 14px;
  background: rgba(12, 17, 25, .74);
  backdrop-filter: blur(12px);
  box-shadow: var(--shadow-soft);
}

.brand { display: flex; gap: 12px; align-items: center; min-width: 0; }
.brand a { display: flex; align-items: center; gap: 12px; color: inherit; text-decoration: none; }
.brand img, .brand-logo {
  width: 58px; height: 58px;
  object-fit: contain;
  filter: drop-shadow(0 10px 16px rgba(0, 0, 0, .3));
}
.brand .t, .brand-text-main {
  font-family: var(--font-display);
  font-size: 20px;
  font-weight: 700;
  letter-spacing: .06em;
  color: #f7fafc;
  line-height: 1.15;
}
.brand .s, .brand-text-sub {
  font-family: var(--font-mono);
  font-size: 11px;
  letter-spacing: .14em;
  text-transform: uppercase;
  color: var(--gold);
}

.page-title-block { text-align: left; flex: 1 1 240px; min-width: 0; }
.page-title-block h1, .page-title { margin: 0; font-size: 23px; }
.subtitle-main, .subtitle { margin: 2px 0 0; color: var(--muted); font-size: 12.5px; }
.page-kicker {
  font-family: var(--font-mono);
  font-size: 10.5px;
  letter-spacing: .16em;
  text-transform: uppercase;
  color: var(--gold);
}
.page-actions {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 12px;
  flex-wrap: wrap;
  color: var(--muted);
  font-size: 12.5px;
  line-height: 1.7;
}
.page-actions a { color: var(--gold); text-decoration: none; }
.page-actions a:hover { color: var(--gold2); text-decoration: underline; }
.page-actions:empty { display: none; }

.user {
  text-align: right;
  color: var(--muted);
  font-size: 12.5px;
  line-height: 1.7;
}
.user b { color: var(--text); font-weight: 600; }
.user a { color: var(--gold); text-decoration: none; }
.user a:hover { color: var(--gold2); text-decoration: underline; }

/* franja secundaria de sesión (patrón mini-header legado) */
.mini-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
  margin: 0 auto 12px;
  padding: 8px 14px;
  border: 1px solid var(--border-soft);
  border-radius: 10px;
  background: rgba(14, 20, 29, .6);
  color: var(--muted);
  font-size: 12.5px;
}
.mini-header b, .mini-header .left b { color: var(--text); font-weight: 600; }
.mini-header .right { display: flex; gap: 14px; flex-wrap: wrap; }
.mini-header a, .mini-header .right a { color: var(--gold); text-decoration: none; }
.mini-header a:hover, .mini-header .right a:hover { color: var(--gold2); text-decoration: underline; }

.back-link { margin: 0 0 12px; font-size: 13px; }
.back-link a { color: var(--gold); text-decoration: none; }
.back-link a:hover { text-decoration: underline; }

/* ---------- 4. Tarjetas y paneles ---------- */
.card, .wide-card, .item-card, .panel, section.card {
  background: linear-gradient(180deg, rgba(20, 28, 40, .96), rgba(14, 20, 29, .98));
  border: 1px solid var(--border-soft);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 18px;
  margin-bottom: 14px;
  animation: orion-rise .35s ease both;
}
@keyframes orion-rise {
  from { opacity: 0; transform: translateY(6px); }
  to   { opacity: 1; transform: none; }
}
@media (prefers-reduced-motion: reduce) {
  .card, .wide-card, .item-card, .panel, section.card { animation: none; }
}

.card h2, .card-title, .wide-title h2 { margin: 0 0 6px; font-size: 18px; }
.card p { margin: 0 0 12px; color: var(--muted); font-size: 13px; }

.card-header, .wide-title { display: flex; align-items: center; gap: 10px; margin: 0 0 12px; }
.card-header .card-title, .card-header h2 { margin: 0; }
.card-header-bar, .wide-bar, .bar {
  width: 4px; height: 20px;
  flex: 0 0 4px;
  border-radius: 3px;
  background: var(--bar);
  box-shadow: 0 0 0 3px rgba(215, 180, 106, .11);
}

.wide-wrap { width: min(100%, 1220px); margin: 14px auto 0; }

.item-card { padding: 12px 14px; margin-bottom: 10px; }

.section-footer { margin-top: 14px; color: var(--muted); font-size: 12.5px; }

/* ---------- 5. Formularios ---------- */
label { display: block; color: var(--muted); font-size: 13px; margin: 0 0 4px; }

input, select, textarea {
  width: 100%;
  padding: 8px 10px;
  font: inherit;
  color: var(--text);
  background: #0d131c;
  border: 1px solid rgba(159, 183, 201, .24);
  border-radius: 8px;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, .03);
  transition: border-color .15s ease, box-shadow .15s ease;
}
input[type="checkbox"], input[type="radio"] {
  width: auto;
  accent-color: var(--gold);
}
input::placeholder, textarea::placeholder { color: #718195; }
input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: rgba(215, 180, 106, .85);
  box-shadow: 0 0 0 3px rgba(215, 180, 106, .16);
}
input[readonly], input:disabled, select:disabled, textarea:disabled {
  opacity: .75;
  cursor: not-allowed;
}
textarea { resize: vertical; min-height: 90px; }

.field-row { margin-bottom: 10px; }
.col { flex: 1 1 250px; min-width: 0; }
.btnrow, .actions, .inline-actions {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  align-items: center;
  margin-top: 12px;
}
.actions a { color: var(--gold); text-decoration: none; }
.actions a:hover { text-decoration: underline; }

/* ---------- 6. Botones ---------- */
button, .btn, input[type="submit"] {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  width: auto;
  min-height: 34px;
  padding: 7px 16px;
  font: inherit;
  font-weight: 600;
  letter-spacing: .01em;
  color: #161208;
  background: linear-gradient(180deg, #e3c57b, #bd9345);
  border: 1px solid rgba(215, 180, 106, .9);
  border-radius: 8px;
  text-decoration: none;
  cursor: pointer;
  box-shadow: 0 10px 22px rgba(0, 0, 0, .22), inset 0 1px 0 rgba(255, 255, 255, .28);
  transition: background-color .16s ease, border-color .16s ease, transform .16s ease, box-shadow .16s ease;
}
button:hover, .btn:hover, input[type="submit"]:hover {
  transform: translateY(-1px);
  background: linear-gradient(180deg, #efd89d, #cba254);
  border-color: #efd89d;
  color: #161208;
  box-shadow: 0 14px 26px rgba(0, 0, 0, .28), inset 0 1px 0 rgba(255, 255, 255, .35);
  text-decoration: none;
}
button:active, .btn:active, input[type="submit"]:active { transform: translateY(0); }
:where(button, .btn, a, input, select, textarea):focus-visible {
  outline: 2px solid var(--gold);
  outline-offset: 2px;
}

.btn2, .btn-secondary, .btn.secondary, button.secondary, .btn-copy, .btn-wa {
  background: rgba(215, 180, 106, .07);
  color: #f0d99a;
  border-color: rgba(215, 180, 106, .48);
  box-shadow: none;
}
.btn2:hover, .btn-secondary:hover, .btn.secondary:hover, button.secondary:hover, .btn-copy:hover, .btn-wa:hover {
  background: rgba(215, 180, 106, .14);
  color: #ffe5a4;
  border-color: rgba(215, 180, 106, .76);
}

.btn-danger, button.danger {
  background: rgba(239, 125, 125, .14);
  border-color: rgba(239, 125, 125, .68);
  color: #ffd8d8;
  box-shadow: none;
}
.btn-danger:hover, button.danger:hover {
  background: rgba(239, 125, 125, .22);
  border-color: var(--danger);
  color: #ffe3e3;
}

/* botón que parece enlace (p. ej. "Borrar" en tablas) */
.btn-link-plain {
  background: none;
  border: none;
  box-shadow: none;
  min-height: 0;
  padding: 0;
  font: inherit;
  color: var(--gold);
  cursor: pointer;
  text-decoration: underline;
  text-underline-offset: 3px;
}
.btn-link-plain:hover { background: none; border: none; box-shadow: none; color: var(--gold2); transform: none; }

/* ---------- 7. Tablas ---------- */
.table-wrapper, .table-wrap {
  overflow-x: auto;
  background: #0d131c;
  border: 1px solid var(--border-soft);
  border-radius: var(--radius);
  box-shadow: 0 14px 34px rgba(0, 0, 0, .2);
}

table { width: 100%; border-collapse: separate; border-spacing: 0; }
th, td {
  padding: 8px 10px;
  font-size: 12.8px;
  text-align: left;
  border-bottom: 1px solid rgba(159, 183, 201, .14);
  border-right: 1px solid rgba(159, 183, 201, .08);
}
th:last-child, td:last-child { border-right: none; }
th {
  font-family: var(--font-display);
  font-size: 13px;
  font-weight: 600;
  letter-spacing: .06em;
  text-transform: uppercase;
  color: #d9e3ee;
  background: #17202d;
  position: sticky;
  top: 0;
}
td { background: rgba(14, 20, 29, .92); color: #e8eef5; }
tr:nth-child(even) td { background: rgba(18, 26, 37, .92); }
tr:hover td { background: rgba(36, 49, 66, .92); }

/* ---------- 8. Avisos y chips ---------- */
.msg, .flash {
  margin: 0 0 12px;
  padding: 10px 14px;
  border: 1px solid rgba(215, 180, 106, .35);
  border-left: 3px solid var(--gold);
  border-radius: 8px;
  background: rgba(215, 180, 106, .12);
  color: #f8df9f;
  font-size: 13.5px;
  animation: orion-rise .3s ease both;
}

.chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 2px 10px;
  font-family: var(--font-mono);
  font-size: 11.5px;
  letter-spacing: .04em;
  border-radius: 999px;
  border: 1px solid rgba(159, 183, 201, .22);
  background: rgba(159, 183, 201, .08);
  color: #c8d3df;
}
.chip.gold { border-color: rgba(215, 180, 106, .48); background: rgba(215, 180, 106, .11); color: #f0d99a; }
.chip.green { border-color: rgba(115, 200, 155, .45); background: rgba(115, 200, 155, .1); color: #9adfba; }
.chip.red { border-color: rgba(239, 125, 125, .45); background: rgba(239, 125, 125, .1); color: #ffc9c9; }

.dropzone, .doc-row {
  background: rgba(13, 19, 28, .84);
  border-color: rgba(159, 183, 201, .24);
}

/* ---------- 9. Scrollbar ---------- */
::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-track { background: #0a0f17; }
::-webkit-scrollbar-thumb {
  background: #2a3548;
  border-radius: 6px;
  border: 2px solid #0a0f17;
}
::-webkit-scrollbar-thumb:hover { background: #3b4a63; }

/* ---------- 10. Responsive ---------- */
@media (max-width: 768px) {
  .main { padding: 12px; }
  .top, .top-bar { padding: 10px 12px; }
  .brand img, .brand-logo { width: 44px; height: 44px; }
  .page-title-block { text-align: left; }
  .user { text-align: left; }
  .card, .wide-card { padding: 14px; border-radius: var(--radius); }
  button, .btn, input[type="submit"] { min-height: 40px; }
  th, td { padding: 9px 10px; }
}

@media print {
  body { background: #fff; color: #000; padding: 0; }
  .layout { display: block; }
  body::before, body::after, .top, .top-bar, .mini-header, .btnrow, .actions,
  .sidebar, .sb-overlay, .hamburger { display: none; }
  .card, .wide-card { box-shadow: none; border: 1px solid #999; animation: none; }
}
