/* ==========================================================================
   CreditFlow — hoja de estilos principal
   Tema oscuro, futurista, con acentos de neón y superficies "glass".
   ========================================================================== */

:root {
  --bg-0: #06070f;
  --bg-1: #0a0e1c;
  --bg-2: #0f1428;
  --surface: rgba(255, 255, 255, 0.045);
  --surface-strong: rgba(255, 255, 255, 0.08);
  --border: rgba(255, 255, 255, 0.09);
  --border-strong: rgba(255, 255, 255, 0.16);

  --cyan: #22d3ee;
  --cyan-glow: #22d3ee66;
  --purple: #a855f7;
  --purple-glow: #a855f766;
  --blue: #6366f1;
  --pink: #f472b6;
  --green: #34d399;
  --amber: #fbbf24;
  --red: #f87171;

  --text-0: #f4f6fb;
  --text-1: #b7bfd6;
  --text-2: #7c85a3;

  --grad-primary: linear-gradient(135deg, var(--cyan), var(--blue) 55%, var(--purple));
  --grad-warm: linear-gradient(135deg, var(--pink), var(--purple));
  --grad-success: linear-gradient(135deg, #34d399, #22d3ee);

  --radius-sm: 10px;
  --radius-md: 16px;
  --radius-lg: 22px;
  --shadow-glow: 0 8px 30px -8px rgba(99, 102, 241, 0.45);
  --font-display: "Space Grotesk", "Inter", system-ui, sans-serif;
  --font-body: "Inter", system-ui, sans-serif;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  background: var(--bg-0);
  color: var(--text-0);
  font-family: var(--font-body);
  font-size: 15px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  overflow-x: hidden;
}
h1, h2, h3, h4 { font-family: var(--font-display); margin: 0; letter-spacing: -0.01em; }
p { margin: 0 0 .6em; }
a { color: var(--cyan); text-decoration: none; }
button, input, select, textarea { font-family: inherit; color: inherit; }
::selection { background: var(--purple-glow); }

::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border-strong); border-radius: 8px; }
::-webkit-scrollbar-thumb:hover { background: var(--cyan-glow); }

/* ---------------------------------------------------------------------- */
/* Fondo animado                                                          */
/* ---------------------------------------------------------------------- */
#bg-fx {
  position: fixed;
  inset: 0;
  z-index: 0;
  overflow: hidden;
  background: radial-gradient(ellipse at top, var(--bg-1), var(--bg-0) 60%);
}
.blob {
  position: absolute;
  border-radius: 50%;
  filter: blur(90px);
  opacity: 0.35;
  will-change: transform;
}
.blob-a { width: 46vw; height: 46vw; top: -12vw; left: -10vw; background: var(--purple); animation: float-a 26s ease-in-out infinite; }
.blob-b { width: 38vw; height: 38vw; bottom: -14vw; right: -8vw; background: var(--cyan); animation: float-b 32s ease-in-out infinite; }
.blob-c { width: 30vw; height: 30vw; top: 40%; left: 55%; background: var(--pink); opacity: 0.2; animation: float-c 22s ease-in-out infinite; }
.grid-overlay {
  position: absolute; inset: 0;
  background-image: linear-gradient(rgba(255,255,255,0.025) 1px, transparent 1px), linear-gradient(90deg, rgba(255,255,255,0.025) 1px, transparent 1px);
  background-size: 44px 44px;
  mask-image: radial-gradient(ellipse at 50% 0%, black, transparent 75%);
}
@keyframes float-a { 0%,100% { transform: translate(0,0) scale(1);} 50% { transform: translate(6vw, 8vw) scale(1.1);} }
@keyframes float-b { 0%,100% { transform: translate(0,0) scale(1);} 50% { transform: translate(-5vw, -6vw) scale(1.15);} }
@keyframes float-c { 0%,100% { transform: translate(0,0);} 50% { transform: translate(-4vw, 5vw);} }

@media (prefers-reduced-motion: reduce) {
  .blob { animation: none !important; }
}

#root { position: relative; z-index: 1; min-height: 100vh; }

/* ---------------------------------------------------------------------- */
/* Boot loader                                                            */
/* ---------------------------------------------------------------------- */
.boot-loader { min-height: 100vh; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 18px; }
.boot-mark { font-family: var(--font-display); font-size: 26px; font-weight: 700; background: var(--grad-primary); -webkit-background-clip: text; background-clip: text; color: transparent; }
.boot-bar { width: 220px; height: 4px; border-radius: 4px; background: var(--surface); overflow: hidden; }
.boot-bar span { display: block; height: 100%; width: 40%; background: var(--grad-primary); border-radius: 4px; animation: boot-sweep 1.1s ease-in-out infinite; }
@keyframes boot-sweep { 0% { transform: translateX(-100%);} 100% { transform: translateX(340%);} }

/* ---------------------------------------------------------------------- */
/* Pantallas de acceso (login / setup)                                    */
/* ---------------------------------------------------------------------- */
.auth-screen {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}
.auth-card {
  width: 100%;
  max-width: 420px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 36px 32px;
  backdrop-filter: blur(20px);
  box-shadow: var(--shadow-glow);
  animation: rise .5s ease;
}
.auth-brand { display: flex; align-items: center; gap: 10px; margin-bottom: 6px; }
.auth-brand .mark { font-size: 26px; }
.auth-brand .name { font-family: var(--font-display); font-size: 22px; font-weight: 700; background: var(--grad-primary); -webkit-background-clip: text; background-clip: text; color: transparent; }
.auth-sub { color: var(--text-1); font-size: 13.5px; margin-bottom: 26px; }
.auth-card .field { margin-bottom: 16px; }
.auth-card .btn-primary { width: 100%; margin-top: 6px; }
.auth-error { background: rgba(248,113,113,0.12); border: 1px solid rgba(248,113,113,0.35); color: #ffb4b4; padding: 10px 14px; border-radius: var(--radius-sm); font-size: 13px; margin-bottom: 16px; }
.auth-foot { text-align: center; margin-top: 20px; font-size: 12.5px; color: var(--text-2); }
@keyframes rise { from { opacity: 0; transform: translateY(14px);} to { opacity: 1; transform: translateY(0);} }

/* ---------------------------------------------------------------------- */
/* App shell                                                              */
/* ---------------------------------------------------------------------- */
.app-shell { display: grid; grid-template-columns: 250px 1fr; min-height: 100vh; }

.sidebar {
  border-right: 1px solid var(--border);
  background: linear-gradient(180deg, rgba(255,255,255,0.035), rgba(255,255,255,0.015));
  backdrop-filter: blur(16px);
  padding: 22px 16px;
  display: flex;
  flex-direction: column;
  position: sticky;
  top: 0;
  height: 100vh;
}
.sidebar-brand { display: flex; align-items: center; gap: 10px; padding: 4px 8px 22px; }
.sidebar-brand .mark { font-size: 22px; filter: drop-shadow(0 0 8px var(--cyan-glow)); }
.sidebar-brand .name { font-family: var(--font-display); font-weight: 700; font-size: 18px; background: var(--grad-primary); -webkit-background-clip: text; background-clip: text; color: transparent; }

.nav-group { margin-bottom: 18px; }
.nav-label { font-size: 10.5px; text-transform: uppercase; letter-spacing: .09em; color: var(--text-2); padding: 0 12px; margin-bottom: 8px; }
.nav-link {
  display: flex; align-items: center; gap: 11px;
  padding: 10px 12px; border-radius: var(--radius-sm);
  color: var(--text-1); font-size: 14px; font-weight: 500;
  cursor: pointer; margin-bottom: 3px; border: 1px solid transparent;
  transition: background .15s, color .15s, border-color .15s, transform .15s;
}
.nav-link svg { width: 18px; height: 18px; flex-shrink: 0; opacity: .85; }
.nav-link:hover { background: var(--surface); color: var(--text-0); transform: translateX(2px); }
.nav-link.active {
  color: #fff;
  background: linear-gradient(90deg, rgba(34,211,238,0.16), rgba(168,85,247,0.14));
  border-color: rgba(34,211,238,0.28);
  box-shadow: inset 0 0 0 1px rgba(255,255,255,0.03), 0 0 18px -6px var(--cyan-glow);
}
.nav-link .count {
  margin-left: auto; font-size: 11px; padding: 1px 7px; border-radius: 20px;
  background: var(--surface-strong); color: var(--text-1);
}

.sidebar-foot { margin-top: auto; padding-top: 14px; border-top: 1px solid var(--border); }
.user-chip { display: flex; align-items: center; gap: 10px; padding: 8px; border-radius: var(--radius-sm); }
.user-avatar {
  width: 34px; height: 34px; border-radius: 50%; flex-shrink: 0;
  background: var(--grad-primary); display: flex; align-items: center; justify-content: center;
  font-weight: 700; font-size: 13px; color: #06070f;
}
.user-meta { min-width: 0; }
.user-meta .u-name { font-size: 13px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.user-meta .u-role { font-size: 11px; color: var(--text-2); text-transform: capitalize; }
.logout-btn { margin-left: auto; background: none; border: none; color: var(--text-2); cursor: pointer; padding: 6px; border-radius: 8px; }
.logout-btn:hover { color: var(--red); background: rgba(248,113,113,0.1); }

.main-area { min-width: 0; display: flex; flex-direction: column; }
.topbar {
  position: sticky; top: 0; z-index: 5;
  display: flex; align-items: center; gap: 14px;
  padding: 16px 28px; border-bottom: 1px solid var(--border);
  background: rgba(7,9,18,0.55); backdrop-filter: blur(14px);
}
.topbar h1 { font-size: 19px; }
.topbar .sub { color: var(--text-2); font-size: 12.5px; margin-top: 2px; }
.topbar-actions { margin-left: auto; display: flex; gap: 10px; align-items: center; }
.hamburger { display: none; background: var(--surface); border: 1px solid var(--border); border-radius: 10px; padding: 8px; cursor: pointer; }

.content { padding: 26px 28px 60px; flex: 1; }
.view-fade { animation: view-in .28s ease; }
@keyframes view-in { from { opacity: 0; transform: translateY(6px);} to { opacity: 1; transform: translateY(0);} }

/* ---------------------------------------------------------------------- */
/* Componentes genéricos                                                  */
/* ---------------------------------------------------------------------- */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 20px;
  backdrop-filter: blur(10px);
}
.card-hover { transition: transform .18s ease, border-color .18s ease, box-shadow .18s ease; }
.card-hover:hover { transform: translateY(-2px); border-color: var(--border-strong); box-shadow: 0 14px 34px -18px rgba(99,102,241,.55); }

.section-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; margin-bottom: 20px; flex-wrap: wrap; }
.section-head h2 { font-size: 21px; }
.section-head .sub { color: var(--text-2); font-size: 13px; margin-top: 4px; }

.grid { display: grid; gap: 18px; }
.grid-kpi { grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); }
.grid-2 { grid-template-columns: repeat(auto-fit, minmax(340px, 1fr)); }

.kpi-card { position: relative; overflow: hidden; }
.kpi-card .kpi-label { font-size: 12.5px; color: var(--text-2); text-transform: uppercase; letter-spacing: .06em; }
.kpi-card .kpi-value { font-family: var(--font-display); font-size: 32px; font-weight: 700; margin-top: 6px; }
.kpi-card .kpi-icon { position: absolute; right: 14px; top: 14px; width: 36px; height: 36px; border-radius: 12px; display: flex; align-items: center; justify-content: center; opacity: .9; }
.kpi-card .kpi-icon svg { width: 18px; height: 18px; }
.kpi-c1 .kpi-icon { background: rgba(34,211,238,.15); color: var(--cyan); }
.kpi-c2 .kpi-icon { background: rgba(168,85,247,.15); color: var(--purple); }
.kpi-c3 .kpi-icon { background: rgba(52,211,153,.15); color: var(--green); }
.kpi-c4 .kpi-icon { background: rgba(251,191,36,.15); color: var(--amber); }
.kpi-bar { margin-top: 14px; height: 5px; border-radius: 6px; background: rgba(255,255,255,.06); overflow: hidden; }
.kpi-bar span { display: block; height: 100%; border-radius: 6px; background: var(--grad-primary); transition: width .6s ease; }

/* Botones */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  border-radius: var(--radius-sm); border: 1px solid transparent;
  padding: 10px 16px; font-size: 13.5px; font-weight: 600; cursor: pointer;
  transition: transform .12s ease, box-shadow .12s ease, filter .12s ease, background .12s ease;
  white-space: nowrap;
}
.btn svg { width: 15px; height: 15px; }
.btn:active { transform: scale(.97); }
.btn:disabled { opacity: .5; cursor: not-allowed; transform: none !important; }
.btn-primary { background: var(--grad-primary); color: #06070f; box-shadow: 0 8px 22px -8px var(--cyan-glow); }
.btn-primary:hover:not(:disabled) { filter: brightness(1.08); box-shadow: 0 10px 26px -6px var(--cyan-glow); }
.btn-ghost { background: var(--surface); border-color: var(--border); color: var(--text-0); }
.btn-ghost:hover:not(:disabled) { background: var(--surface-strong); border-color: var(--border-strong); }
.btn-danger { background: rgba(248,113,113,.14); color: #ffb4b4; border-color: rgba(248,113,113,.35); }
.btn-danger:hover:not(:disabled) { background: rgba(248,113,113,.22); }
.btn-sm { padding: 7px 12px; font-size: 12.5px; }
.btn-icon { padding: 8px; border-radius: 10px; }
.btn-block { width: 100%; }

/* Formularios */
.field { display: flex; flex-direction: column; gap: 6px; }
.field label { font-size: 12.5px; color: var(--text-1); font-weight: 600; }
.field .hint { font-size: 11.5px; color: var(--text-2); }
input[type="text"], input[type="email"], input[type="password"], input[type="date"], input[type="number"], input[type="search"], select, textarea {
  background: rgba(255,255,255,.04);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 10px 13px;
  font-size: 13.5px;
  color: var(--text-0);
  outline: none;
  transition: border-color .15s, box-shadow .15s, background .15s;
  width: 100%;
}
textarea { resize: vertical; min-height: 90px; font-family: "JetBrains Mono", "SFMono-Regular", Menlo, monospace; line-height: 1.55; }
input:focus, select:focus, textarea:focus { border-color: var(--cyan); box-shadow: 0 0 0 3px rgba(34,211,238,.14); background: rgba(255,255,255,.055); }
select option { background: #12172b; color: var(--text-0); }
.form-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px,1fr)); gap: 14px; }
.form-actions { display: flex; gap: 10px; justify-content: flex-end; margin-top: 22px; }

/* Tablas */
.table-wrap { overflow-x: auto; border: 1px solid var(--border); border-radius: var(--radius-md); background: var(--surface); }
table { width: 100%; border-collapse: collapse; min-width: 560px; }
thead th { text-align: left; font-size: 11px; text-transform: uppercase; letter-spacing: .06em; color: var(--text-2); padding: 13px 16px; border-bottom: 1px solid var(--border); white-space: nowrap; }
tbody td { padding: 13px 16px; border-bottom: 1px solid rgba(255,255,255,.05); font-size: 13.5px; vertical-align: middle; }
tbody tr:last-child td { border-bottom: none; }
tbody tr { transition: background .12s; cursor: pointer; }
tbody tr:hover { background: rgba(255,255,255,.03); }
.row-name { font-weight: 600; color: var(--text-0); }
.row-sub { font-size: 12px; color: var(--text-2); }
.cell-actions { display: flex; gap: 6px; justify-content: flex-end; }

/* Badges de estado */
.badge { display: inline-flex; align-items: center; gap: 6px; padding: 4px 10px; border-radius: 20px; font-size: 11.5px; font-weight: 700; text-transform: uppercase; letter-spacing: .03em; white-space: nowrap; }
.badge::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; box-shadow: 0 0 8px currentColor; }
.badge-borrador { background: rgba(124,133,163,.16); color: #b7bfd6; }
.badge-lista { background: rgba(99,102,241,.16); color: #a5b4fc; }
.badge-enviada { background: rgba(34,211,238,.16); color: var(--cyan); }
.badge-en_transito { background: rgba(251,191,36,.16); color: var(--amber); }
.badge-entregada { background: rgba(52,211,153,.16); color: var(--green); }
.badge-devuelta { background: rgba(248,113,113,.16); color: var(--red); }
.badge-respondida { background: rgba(244,114,182,.16); color: var(--pink); }
.badge-completada { background: rgba(52,211,153,.22); color: #6ee7c4; }
.badge-activo { background: rgba(52,211,153,.16); color: var(--green); }
.badge-pausado { background: rgba(251,191,36,.16); color: var(--amber); }

/* Empty state */
.empty { text-align: center; padding: 60px 20px; color: var(--text-2); }
.empty .mark { font-size: 34px; margin-bottom: 10px; }
.empty h3 { color: var(--text-1); font-size: 15px; margin-bottom: 6px; }

/* Toasts */
.toast-stack { position: fixed; top: 18px; right: 18px; z-index: 200; display: flex; flex-direction: column; gap: 10px; }
.toast {
  background: rgba(15,20,40,.92); border: 1px solid var(--border-strong); border-radius: 12px;
  padding: 12px 16px; min-width: 240px; max-width: 340px; font-size: 13px;
  backdrop-filter: blur(10px); box-shadow: 0 12px 30px -12px rgba(0,0,0,.6);
  animation: toast-in .25s ease;
  border-left: 3px solid var(--cyan);
}
.toast.err { border-left-color: var(--red); }
.toast.ok { border-left-color: var(--green); }
@keyframes toast-in { from { opacity: 0; transform: translateX(30px);} to { opacity: 1; transform: translateX(0);} }

/* Modal */
.modal-overlay { position: fixed; inset: 0; background: rgba(4,6,14,.62); backdrop-filter: blur(4px); z-index: 100; display: flex; align-items: center; justify-content: center; padding: 20px; animation: fade-in .15s ease; }
@keyframes fade-in { from { opacity: 0;} to { opacity: 1;} }
.modal {
  width: 100%; max-width: 560px; max-height: 88vh; overflow-y: auto;
  background: var(--bg-2); border: 1px solid var(--border-strong); border-radius: var(--radius-lg);
  padding: 26px; box-shadow: 0 30px 80px -20px rgba(0,0,0,.7);
  animation: rise .22s ease;
}
.modal.modal-wide { max-width: 780px; }
.modal-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 18px; }
.modal-head h3 { font-size: 17px; }
.modal-close { background: var(--surface); border: 1px solid var(--border); border-radius: 8px; width: 30px; height: 30px; display: flex; align-items: center; justify-content: center; cursor: pointer; color: var(--text-1); }

/* Timeline / actividad */
.timeline { display: flex; flex-direction: column; gap: 0; }
.timeline-item { display: flex; gap: 12px; padding: 10px 0; border-left: 2px solid var(--border); margin-left: 6px; padding-left: 18px; position: relative; }
.timeline-item::before { content: ""; position: absolute; left: -6px; top: 15px; width: 10px; height: 10px; border-radius: 50%; background: var(--cyan); box-shadow: 0 0 10px var(--cyan-glow); }
.timeline-item:last-child { border-left-color: transparent; }
.timeline-body .t-action { font-size: 13px; font-weight: 600; }
.timeline-body .t-detail { font-size: 12.5px; color: var(--text-1); margin-top: 1px; }
.timeline-body .t-time { font-size: 11px; color: var(--text-2); margin-top: 2px; }

/* Stepper de proceso de la carta */
.stepper { display: flex; align-items: center; gap: 4px; flex-wrap: wrap; margin: 6px 0 22px; }
.step { display: flex; align-items: center; gap: 8px; padding: 8px 14px; border-radius: 30px; background: var(--surface); border: 1px solid var(--border); font-size: 12px; font-weight: 600; color: var(--text-2); }
.step.done { color: #06070f; background: var(--grad-success); border-color: transparent; }
.step.current { color: #fff; background: var(--grad-primary); border-color: transparent; box-shadow: 0 0 16px -4px var(--cyan-glow); }
.step-sep { width: 20px; height: 2px; background: var(--border); }
.step-sep.done { background: linear-gradient(90deg, var(--green), var(--cyan)); }

/* Carta: editor y vista de impresión */
.letter-preview {
  background: #fff; color: #111; border-radius: var(--radius-md);
  padding: 44px; font-family: Georgia, "Times New Roman", serif; font-size: 14px; line-height: 1.7;
  white-space: pre-wrap; box-shadow: 0 20px 50px -20px rgba(0,0,0,.6);
}
.placeholder-chip {
  display: inline-block; background: rgba(34,211,238,.14); color: var(--cyan); border: 1px solid rgba(34,211,238,.3);
  padding: 3px 9px; border-radius: 8px; font-size: 11.5px; font-family: monospace; cursor: pointer; margin: 3px 4px 0 0;
}
.placeholder-chip:hover { background: rgba(34,211,238,.24); }

/* Utilidades */
.text-muted { color: var(--text-2); }
.text-sm { font-size: 12.5px; }
.mt-0 { margin-top: 0; }
.flex { display: flex; }
.flex-between { display: flex; align-items: center; justify-content: space-between; }
.gap-8 { gap: 8px; }
.gap-12 { gap: 12px; }
.w-full { width: 100%; }
.tag-row { display: flex; gap: 8px; flex-wrap: wrap; }
.pill-filter {
  padding: 7px 14px; border-radius: 30px; font-size: 12.5px; font-weight: 600;
  background: var(--surface); border: 1px solid var(--border); color: var(--text-1); cursor: pointer;
}
.pill-filter.active { background: var(--grad-primary); color: #06070f; border-color: transparent; }
.search-box { position: relative; }
.search-box svg { position: absolute; left: 12px; top: 50%; transform: translateY(-50%); width: 15px; height: 15px; color: var(--text-2); }
.search-box input { padding-left: 34px; }

/* Responsive */
@media (max-width: 980px) {
  .app-shell { grid-template-columns: 1fr; }
  .sidebar {
    position: fixed; z-index: 50; left: 0; top: 0; height: 100vh; width: 250px;
    transform: translateX(-104%); transition: transform .22s ease;
  }
  .sidebar.open { transform: translateX(0); box-shadow: 30px 0 60px rgba(0,0,0,.5); }
  .hamburger { display: flex; }
  .content { padding: 20px 16px 50px; }
  .topbar { padding: 14px 16px; }
}

/* Impresión de cartas: limpio, sin la interfaz de la app */
@media print {
  #bg-fx, .sidebar, .topbar, .no-print { display: none !important; }
  body, #root, .app-shell, .main-area, .content { background: #fff !important; margin: 0; padding: 0; }
  .letter-preview { box-shadow: none; padding: 0; }
}
