/* ============================================================
   CasoTransfer · tema base (verde/negro, Montserrat local)
   ============================================================ */
@font-face {
  font-family: 'Montserrat';
  font-style: normal;
  font-weight: 100 900;
  font-display: swap;
  src: url('/fonts/montserrat-latin.woff2') format('woff2');
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329,
    U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}
@font-face {
  font-family: 'Montserrat';
  font-style: normal;
  font-weight: 100 900;
  font-display: swap;
  src: url('/fonts/montserrat-latin-ext.woff2') format('woff2');
  unicode-range: U+0100-02BA, U+02BD-02C5, U+02C7-02CC, U+02CE-02D7, U+02DD-02FF, U+0304, U+0308, U+0329,
    U+1D00-1DBF, U+1E00-1E9F, U+1EF2-1EFF, U+2020, U+20A0-20AB, U+20AD-20C0, U+2113, U+2C60-2C7F, U+A720-A7FF;
}

:root {
  /* Verde bosque profundo sobre negro: elegante, sin neón. */
  --green: #1f9d6b;
  --green-bright: #45d6a0;
  --green-dark: #0b5a41;
  --green-soft: rgba(31, 157, 107, 0.13);
  --green-line: rgba(69, 214, 160, 0.26);
  --bg: #040706;
  --bg-soft: #070d0a;
  --surface: #0a1210;
  --surface-2: #0e1815;
  --surface-3: #14211c;
  --line: #1b2b25;
  --line-soft: #14201b;
  --text: #eef4f1;
  --text-dim: #aebfb7;
  --muted: #7e938a;
  --danger: #ef7d7d;
  --danger-soft: rgba(239, 125, 125, 0.12);
  --warning: #e8b455;
  --warning-soft: rgba(232, 180, 85, 0.12);
  --radius: 14px;
  --radius-sm: 10px;
  --radius-lg: 20px;
  /* Color del texto sobre el color de acento (se ajusta por tema). */
  --on-accent: #04120a;
  --shadow: 0 22px 50px rgba(0, 0, 0, 0.55);
  --shadow-soft: 0 10px 28px rgba(0, 0, 0, 0.35);
  --header-h: 64px;
  --tabbar-h: 66px;
  color-scheme: dark;
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

/*
 * `hidden` tiene que ganar siempre.
 * Sin esto, cualquier bloque con `display: grid` o `flex` en su clase (por ejemplo
 * .boot, .auth-wrap o un modal) sigue viéndose aunque el JS le ponga `hidden`:
 * el panel pintaba la pantalla de carga y el login a la vez, uno debajo del otro.
 */
[hidden] {
  display: none !important;
}

html {
  -webkit-text-size-adjust: 100%;
}

body {
  margin: 0;
  min-height: 100vh;
  background:
    radial-gradient(1100px 620px at 12% -10%, rgba(31, 157, 107, 0.14), transparent 62%),
    radial-gradient(900px 520px at 100% 0%, rgba(31, 157, 107, 0.07), transparent 58%),
    var(--bg);
  color: var(--text);
  font-family: 'Montserrat', system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
  font-size: 15px;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
  overflow-wrap: anywhere;
}

h1,
h2,
h3,
h4 {
  margin: 0 0 0.4em;
  font-weight: 700;
  letter-spacing: -0.02em;
  line-height: 1.2;
}
h1 { font-size: clamp(1.6rem, 4.4vw, 2.3rem); }
h2 { font-size: clamp(1.25rem, 3vw, 1.6rem); }
h3 { font-size: 1.05rem; }
p { margin: 0 0 1em; color: var(--text-dim); }
a { color: var(--green-bright); text-decoration: none; }
a:hover { color: #fff; }
img { max-width: 100%; }
small { font-size: 0.78rem; }
code {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 0.85em;
  background: var(--surface-3);
  padding: 0.15em 0.45em;
  border-radius: 6px;
  color: var(--green-bright);
}
::selection { background: var(--green); color: #04110a; }

:focus-visible {
  outline: 2px solid var(--green);
  outline-offset: 2px;
}

.muted { color: var(--muted); }
.dim { color: var(--text-dim); }
.tiny { font-size: 0.75rem; }
.mono { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; }
.center { text-align: center; }
.nowrap { white-space: nowrap; }
.hidden { display: none !important; }
.grow { flex: 1 1 auto; min-width: 0; }
.truncate { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.row { display: flex; align-items: center; gap: 12px; }
.row.wrap { flex-wrap: wrap; }
.col { display: flex; flex-direction: column; gap: 12px; }
.grid-2 { display: grid; gap: 16px; grid-template-columns: 1fr; }
.grid-3 { display: grid; gap: 16px; grid-template-columns: 1fr; }
@media (min-width: 680px) {
  .grid-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .grid-3 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (min-width: 1024px) {
  .grid-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
}

/* ---------- Botones ---------- */
.btn {
  --btn-bg: var(--surface-3);
  --btn-fg: var(--text);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 11px 18px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--btn-bg);
  color: var(--btn-fg);
  font-family: inherit;
  font-size: 0.88rem;
  font-weight: 600;
  cursor: pointer;
  transition: transform 0.12s ease, background 0.18s ease, border-color 0.18s ease, opacity 0.18s ease;
  text-align: center;
  line-height: 1.2;
  -webkit-tap-highlight-color: transparent;
}
.btn:hover { border-color: var(--green-line); color: #fff; }
.btn:active { transform: translateY(1px) scale(0.995); }
.btn[disabled],
.btn.is-busy { opacity: 0.55; pointer-events: none; }
.btn-primary {
  --btn-bg: var(--green);
  --btn-fg: var(--on-accent);
  border-color: transparent;
  box-shadow: 0 10px 26px rgba(31, 157, 107, 0.18);
}
.btn-primary:hover { color: var(--on-accent); filter: brightness(1.08); }
.btn-ghost { --btn-bg: transparent; }
.btn-danger { --btn-bg: var(--danger-soft); --btn-fg: #fca5a5; border-color: rgba(248, 113, 113, 0.3); }
.btn-danger:hover { color: #fff; border-color: var(--danger); }
.btn-sm { padding: 7px 13px; font-size: 0.78rem; }
.btn-block { width: 100%; }
.btn-icon {
  width: 38px;
  height: 38px;
  padding: 0;
  border-radius: 12px;
  font-size: 1rem;
}

/* ---------- Formularios ---------- */
.form {
  display: flex;
  flex-direction: column;
  gap: 16px;
}
.field {
  display: flex;
  flex-direction: column;
  gap: 7px;
  min-width: 0;
}
.field > label,
.label {
  font-size: 0.78rem;
  font-weight: 600;
  letter-spacing: 0.02em;
  color: var(--text-dim);
  text-transform: uppercase;
}
.field .hint {
  font-size: 0.76rem;
  color: var(--muted);
  line-height: 1.45;
}
input[type='text'],
input[type='email'],
input[type='password'],
input[type='number'],
input[type='search'],
input[type='url'],
input[type='time'],
select,
textarea {
  width: 100%;
  padding: 12px 14px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--bg-soft);
  color: var(--text);
  font-family: inherit;
  font-size: 0.92rem;
  transition: border-color 0.18s ease, background 0.18s ease;
}
textarea { min-height: 92px; resize: vertical; }
input:hover,
select:hover,
textarea:hover { border-color: #2b3a33; }
input:focus,
select:focus,
textarea:focus {
  outline: none;
  border-color: var(--green);
  background: #08130d;
  box-shadow: 0 0 0 3px rgba(31, 157, 107, 0.14);
}
input::placeholder,
textarea::placeholder { color: #5e6d66; }
select {
  appearance: none;
  background-image: linear-gradient(45deg, transparent 50%, var(--muted) 50%),
    linear-gradient(135deg, var(--muted) 50%, transparent 50%);
  background-position: calc(100% - 20px) 55%, calc(100% - 15px) 55%;
  background-size: 5px 5px, 5px 5px;
  background-repeat: no-repeat;
  padding-right: 38px;
}
.field-row {
  display: grid;
  gap: 16px;
  grid-template-columns: 1fr;
}
.field-row.three { grid-template-columns: 1fr; }
@media (min-width: 620px) {
  .field-row { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .field-row.three { grid-template-columns: repeat(3, minmax(0, 1fr)); }
}
.check {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  padding: 12px 14px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--bg-soft);
  cursor: pointer;
  font-size: 0.86rem;
  color: var(--text-dim);
}
.check input {
  width: 18px;
  height: 18px;
  margin: 2px 0 0;
  accent-color: var(--green);
  flex: none;
}
.check b { color: var(--text); font-weight: 600; }
.check span small { display: block; color: var(--muted); font-size: 0.76rem; }

/* ---------- Superficies ---------- */
.card {
  background: linear-gradient(180deg, var(--surface) 0%, #08100c 100%);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 18px;
  box-shadow: var(--shadow-soft);
}
.card.pad-lg { padding: 24px; }
.card-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 14px;
  flex-wrap: wrap;
}
.card-head h2,
.card-head h3 { margin: 0; }
.card-head .sub { font-size: 0.8rem; color: var(--muted); }
.card-foot {
  margin-top: 16px;
  padding-top: 14px;
  border-top: 1px solid var(--line-soft);
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
}
.panel {
  background: var(--bg-soft);
  border: 1px solid var(--line-soft);
  border-radius: var(--radius-sm);
  padding: 14px;
}

/* ---------- Badges ---------- */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 10px;
  border-radius: 999px;
  font-size: 0.72rem;
  font-weight: 600;
  letter-spacing: 0.02em;
  border: 1px solid transparent;
  white-space: nowrap;
}
.badge-green { background: var(--green-soft); color: var(--green-bright); border-color: var(--green-line); }
.badge-gray { background: rgba(255, 255, 255, 0.05); color: var(--muted); border-color: var(--line); }
.badge-amber { background: var(--warning-soft); color: #fcd34d; border-color: rgba(251, 191, 36, 0.3); }
.badge-red { background: var(--danger-soft); color: #fca5a5; border-color: rgba(248, 113, 113, 0.3); }
/* Archivo permanente: mismo peso visual que «Caducado», en verde apagado. */
.badge-archive { background: rgba(69, 214, 160, 0.07); color: #9fd9c0; border-color: var(--line); }
.dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: currentColor;
  box-shadow: 0 0 0 3px rgba(31, 157, 107, 0.16);
  flex: none;
}
.dot.pulse { animation: pulse 2.2s ease-in-out infinite; }
@keyframes pulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(31, 157, 107, 0.5); }
  50% { box-shadow: 0 0 0 6px rgba(31, 157, 107, 0); }
}

/* ---------- Estadísticas ---------- */
.stat {
  padding: 16px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: linear-gradient(160deg, var(--surface-2), #08100c);
}
.stat .k {
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--muted);
  font-weight: 600;
}
.stat .v {
  font-size: clamp(1.4rem, 4vw, 1.85rem);
  font-weight: 700;
  letter-spacing: -0.03em;
  margin-top: 4px;
}
.stat .m { font-size: 0.75rem; color: var(--muted); }

/* ---------- Tablas ---------- */
.table-wrap {
  overflow-x: auto;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: var(--bg-soft);
  -webkit-overflow-scrolling: touch;
}
table.data {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.84rem;
  min-width: 540px;
}
table.data th {
  text-align: left;
  padding: 11px 14px;
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--muted);
  background: rgba(255, 255, 255, 0.02);
  border-bottom: 1px solid var(--line);
  white-space: nowrap;
  font-weight: 600;
}
table.data td {
  padding: 12px 14px;
  border-bottom: 1px solid var(--line-soft);
  vertical-align: middle;
}
table.data tr:last-child td { border-bottom: none; }
table.data tbody tr:hover { background: rgba(31, 157, 107, 0.04); }
table.data .actions { display: flex; gap: 6px; flex-wrap: wrap; justify-content: flex-end; }

/* ---------- Tabs ---------- */
.tabs {
  display: flex;
  gap: 6px;
  overflow-x: auto;
  padding-bottom: 2px;
  scrollbar-width: none;
}
.tabs::-webkit-scrollbar { display: none; }
.tab {
  padding: 8px 14px;
  border-radius: 999px;
  border: 1px solid transparent;
  background: transparent;
  color: var(--muted);
  font-family: inherit;
  font-size: 0.82rem;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
}
.tab:hover { color: var(--text); background: rgba(255, 255, 255, 0.04); }
.tab[aria-selected='true'] {
  background: var(--green-soft);
  border-color: var(--green-line);
  color: var(--green-bright);
}

/* ---------- Modales ---------- */
dialog.modal {
  width: min(720px, calc(100vw - 24px));
  max-height: calc(100dvh - 40px);
  padding: 0;
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  background: var(--surface);
  color: var(--text);
  box-shadow: var(--shadow);
  overflow: hidden;
}
dialog.modal::backdrop {
  background: rgba(2, 6, 4, 0.72);
  backdrop-filter: blur(4px);
}
dialog.modal .modal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 16px 20px;
  border-bottom: 1px solid var(--line-soft);
}
dialog.modal .modal-head h3 { margin: 0; }
dialog.modal .modal-body {
  padding: 20px;
  overflow-y: auto;
  max-height: calc(100dvh - 190px);
}
dialog.modal .modal-foot {
  display: flex;
  gap: 10px;
  justify-content: flex-end;
  padding: 14px 20px;
  border-top: 1px solid var(--line-soft);
  background: var(--bg-soft);
  flex-wrap: wrap;
}

/* ---------- Toasts ---------- */
.toast-host {
  position: fixed;
  left: 50%;
  bottom: calc(18px + env(safe-area-inset-bottom, 0px));
  transform: translateX(-50%);
  display: flex;
  flex-direction: column;
  gap: 8px;
  z-index: 90;
  width: min(440px, calc(100vw - 24px));
  pointer-events: none;
}
.toast {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  padding: 12px 16px;
  border-radius: 14px;
  background: #0f1a13;
  border: 1px solid var(--green-line);
  color: var(--text);
  font-size: 0.85rem;
  box-shadow: var(--shadow);
  animation: toast-in 0.22s ease-out;
}
.toast.error { border-color: rgba(248, 113, 113, 0.4); background: #1a1010; }
.toast.warn { border-color: rgba(251, 191, 36, 0.4); background: #1a1710; }
.toast .ico { flex: none; font-size: 1rem; line-height: 1.3; }
.toast.out { animation: toast-out 0.2s ease-in forwards; }
@keyframes toast-in {
  from { opacity: 0; transform: translateY(10px) scale(0.98); }
  to { opacity: 1; transform: none; }
}
@keyframes toast-out {
  to { opacity: 0; transform: translateY(8px) scale(0.98); }
}

/* ---------- Carga / vacío ---------- */
.spinner {
  width: 22px;
  height: 22px;
  border-radius: 50%;
  border: 2px solid rgba(255, 255, 255, 0.12);
  border-top-color: var(--green);
  animation: spin 0.8s linear infinite;
  flex: none;
}
.spinner.lg { width: 34px; height: 34px; border-width: 3px; }
@keyframes spin { to { transform: rotate(360deg); } }
.boot {
  min-height: 100dvh;
  display: grid;
  place-items: center;
  gap: 14px;
  text-align: center;
  color: var(--muted);
}
.progress {
  height: 8px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.07);
  overflow: hidden;
}
.progress > i {
  display: block;
  height: 100%;
  width: 0;
  border-radius: inherit;
  background: linear-gradient(90deg, var(--green-dark), var(--green-bright));
  transition: width 0.22s ease;
}
.empty {
  text-align: center;
  padding: 34px 18px;
  border: 1px dashed var(--line);
  border-radius: var(--radius);
  color: var(--muted);
  background: rgba(255, 255, 255, 0.015);
}
.empty .big { font-size: 1.8rem; margin-bottom: 6px; }
