:root {
  --navy: #001C7F;
  --navy-dark: #00145c;
  --navy-light: #1a3aa8;
  --gold: #c9a227;
  --gold-light: #e6c86a;
  --gold-soft: #f4e9c8;
  --bg: #f5f6fa;
  --surface: #ffffff;
  --text: #1a1f36;
  --text-muted: #6b7280;
  --border: #e6e8f0;
  --success: #1f9d55;
  --danger: #d64545;
  --warning: #d97706;
  --info: #2563eb;
  --radius: 12px;
  --radius-sm: 8px;
  --shadow-sm: 0 1px 3px rgba(0, 28, 127, 0.05);
  --shadow: 0 4px 16px rgba(0, 28, 127, 0.08);
  --shadow-lg: 0 16px 40px rgba(0, 9, 40, 0.14);
  --font-serif: 'Cormorant Garamond', Georgia, serif;
  --font-sans: 'Inter', -apple-system, system-ui, sans-serif;
}

* { margin: 0; padding: 0; box-sizing: border-box; }

body {
  font-family: var(--font-sans);
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

a { color: var(--navy); text-decoration: none; }
::selection { background: var(--gold-soft); color: var(--navy-dark); }

/* ---------- Login ---------- */
.login-view {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background:
    radial-gradient(1200px 600px at 85% -10%, rgba(201,162,39,0.22), transparent 55%),
    radial-gradient(900px 700px at -10% 110%, rgba(26,58,168,0.35), transparent 55%),
    linear-gradient(135deg, #00145c 0%, #001C7F 48%, #0a1e6e 100%);
  position: relative;
  overflow: hidden;
  padding: 24px;
}
.login-view::after {
  content: "";
  position: absolute;
  inset: 0;
  background-image:
    radial-gradient(rgba(255,255,255,0.05) 1px, transparent 1px);
  background-size: 28px 28px;
  pointer-events: none;
}
.login-card {
  position: relative;
  z-index: 1;
  background: var(--surface);
  padding: 44px 42px 38px;
  border-radius: 20px;
  box-shadow: 0 30px 80px rgba(0, 9, 40, 0.45);
  width: 100%;
  max-width: 410px;
  animation: card-in 0.5s cubic-bezier(0.16, 1, 0.3, 1);
}
@keyframes card-in { from { opacity: 0; transform: translateY(14px); } to { opacity: 1; transform: none; } }

.login-logo { text-align: center; margin-bottom: 8px; }
.login-logo img {
  height: 88px;
  width: auto;
  filter: drop-shadow(0 6px 16px rgba(0, 28, 127, 0.18));
}
.login-title {
  font-family: var(--font-serif);
  font-size: 34px;
  font-weight: 700;
  color: var(--navy);
  text-align: center;
  letter-spacing: 1.5px;
  line-height: 0.95;
  margin-top: 6px;
}
.login-title span {
  display: block;
  font-size: 13px;
  letter-spacing: 6px;
  color: var(--gold);
  font-weight: 600;
  margin-top: 6px;
  text-transform: uppercase;
}
.login-rule {
  width: 48px; height: 2px;
  background: linear-gradient(90deg, var(--gold), transparent);
  margin: 16px auto 14px;
}
.login-sub {
  text-align: center;
  color: var(--text-muted);
  font-size: 13px;
  margin-bottom: 28px;
}
.login-error {
  background: #fde8e8;
  color: var(--danger);
  padding: 10px 14px;
  border-radius: 8px;
  font-size: 13px;
  margin-bottom: 14px;
  border-left: 3px solid var(--danger);
}

/* ---------- Layout app ---------- */
.app-view { display: flex; min-height: 100vh; }

.sidebar {
  width: 248px;
  background: linear-gradient(180deg, #00145c 0%, #001C7F 100%);
  color: #fff;
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
  position: sticky;
  top: 0;
  height: 100vh;
}
.sidebar-brand {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 24px 20px 22px;
  border-bottom: 1px solid rgba(255,255,255,0.1);
}
.sidebar-brand img {
  height: 52px;
  width: auto;
  background: #fff;
  border-radius: 50%;
  padding: 4px;
  box-shadow: 0 4px 14px rgba(0,0,0,0.28);
}
.sidebar-brand-text { display: flex; flex-direction: column; line-height: 1; }
.brand-cosmo { font-family: var(--font-serif); font-size: 21px; font-weight: 700; letter-spacing: 1.5px; }
.brand-inversiones { font-size: 8.5px; letter-spacing: 3.5px; opacity: 0.7; margin-top: 5px; color: var(--gold-light); }

.sidebar-nav { flex: 1; padding: 18px 14px; }
.nav-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 11px 14px;
  border-radius: 9px;
  color: rgba(255,255,255,0.72);
  font-weight: 500;
  font-size: 14px;
  margin-bottom: 5px;
  transition: 0.18s;
  border-left: 3px solid transparent;
}
.nav-item:hover { background: rgba(255,255,255,0.07); color: #fff; }
.nav-item.active {
  background: rgba(255,255,255,0.12);
  color: #fff;
  border-left-color: var(--gold);
}
.nav-icon { width: 20px; text-align: center; opacity: 0.9; font-size: 15px; }

.sidebar-footer { padding: 16px; border-top: 1px solid rgba(255,255,255,0.1); }
.user-box { display: flex; align-items: center; gap: 11px; margin-bottom: 14px; }
.user-avatar {
  width: 38px; height: 38px; border-radius: 50%;
  background: linear-gradient(135deg, var(--gold), var(--gold-light));
  color: var(--navy-dark);
  display: flex; align-items: center; justify-content: center;
  font-weight: 700; font-size: 17px;
  box-shadow: 0 3px 10px rgba(201,162,39,0.4);
}
.user-info { display: flex; flex-direction: column; line-height: 1.25; }
.user-name { font-size: 13px; font-weight: 600; }
.user-rol { font-size: 11px; opacity: 0.65; text-transform: capitalize; }
.btn-logout {
  width: 100%;
  padding: 10px;
  background: rgba(255,255,255,0.08);
  color: #fff;
  border: 1px solid rgba(255,255,255,0.18);
  border-radius: 9px;
  cursor: pointer;
  font-family: var(--font-sans);
  font-size: 13px;
  font-weight: 500;
  transition: 0.18s;
}
.btn-logout:hover { background: rgba(255,255,255,0.18); }

/* ---------- Content ---------- */
.content { flex: 1; padding: 32px 38px; overflow-x: hidden; }
.view { display: none; }
.view.active { display: block; animation: fade 0.35s ease; }
@keyframes fade { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }

.page-header {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  margin-bottom: 28px;
  flex-wrap: wrap;
  gap: 14px;
}
.page-eyebrow {
  font-size: 11px;
  letter-spacing: 2.5px;
  text-transform: uppercase;
  color: var(--gold);
  font-weight: 600;
  margin-bottom: 4px;
}
.page-title {
  font-family: var(--font-serif);
  font-size: 32px;
  font-weight: 700;
  color: var(--navy);
  letter-spacing: 0.5px;
  line-height: 1.05;
}
.page-sub { color: var(--text-muted); font-size: 14px; margin-top: 5px; }

/* ---------- Botones ---------- */
.btn {
  font-family: var(--font-sans);
  font-size: 14px;
  font-weight: 600;
  padding: 11px 20px;
  border-radius: 9px;
  border: none;
  cursor: pointer;
  transition: 0.18s;
  letter-spacing: 0.2px;
}
.btn-primary {
  background: var(--navy);
  color: #fff;
  box-shadow: 0 4px 14px rgba(0, 28, 127, 0.28);
}
.btn-primary:hover { background: var(--navy-light); transform: translateY(-1px); box-shadow: 0 6px 18px rgba(0, 28, 127, 0.36); }
.btn-ghost { background: transparent; color: var(--navy); border: 1px solid var(--border); }
.btn-ghost:hover { background: #eef0f8; border-color: var(--navy); }
.btn-block { width: 100%; }
.btn-sm { padding: 6px 13px; font-size: 12px; }
.btn-success { background: var(--success); color: #fff; }
.btn-success:hover { filter: brightness(1.07); }
.btn-gold { background: var(--gold); color: var(--navy-dark); }
.btn-gold:hover { background: var(--gold-light); }

/* ---------- Stats ---------- */
.stat-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(190px, 1fr));
  gap: 16px;
  margin-bottom: 26px;
}
.stat-card {
  background: var(--surface);
  padding: 22px;
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  border: 1px solid var(--border);
  position: relative;
  overflow: hidden;
  transition: 0.18s;
}
.stat-card:hover { box-shadow: var(--shadow-lg); transform: translateY(-2px); }
.stat-card::before {
  content: "";
  position: absolute;
  left: 0; top: 0; bottom: 0;
  width: 4px;
  background: var(--navy);
}
.stat-card.gold::before { background: var(--gold); }
.stat-value {
  font-family: var(--font-serif);
  font-size: 32px;
  font-weight: 700;
  color: var(--navy);
  line-height: 1;
}
.stat-label { color: var(--text-muted); font-size: 13px; margin-top: 8px; }

.dashboard-grid {
  display: grid;
  grid-template-columns: 1.4fr 1fr;
  gap: 16px;
}
@media (max-width: 900px) { .dashboard-grid { grid-template-columns: 1fr; } }

.panel {
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  border: 1px solid var(--border);
  padding: 24px;
}
.panel-title {
  font-family: var(--font-serif);
  font-size: 19px;
  font-weight: 700;
  color: var(--navy);
  margin-bottom: 18px;
}

/* Etapa barras */
.etapa-barras { display: flex; flex-direction: column; gap: 14px; }
.etapa-row { display: flex; align-items: center; gap: 12px; }
.etapa-nombre { width: 122px; font-size: 13px; color: var(--text-muted); flex-shrink: 0; }
.etapa-track { flex: 1; height: 24px; background: var(--bg); border-radius: 7px; overflow: hidden; }
.etapa-fill {
  height: 100%;
  background: linear-gradient(90deg, var(--navy), var(--navy-light));
  border-radius: 7px;
  transition: width 0.5s cubic-bezier(0.16, 1, 0.3, 1);
  min-width: 3px;
}
.etapa-count { width: 30px; text-align: right; font-weight: 700; color: var(--navy); }

/* Casa lista */
.casa-lista { display: flex; flex-direction: column; gap: 10px; }
.casa-row {
  display: flex; align-items: center; justify-content: space-between;
  padding: 13px 16px;
  background: var(--bg);
  border-radius: 9px;
  border: 1px solid var(--border);
}
.casa-nombre { font-weight: 600; display: flex; align-items: center; gap: 8px; }
.casa-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--gold); }
.casa-total { color: var(--navy); font-weight: 700; font-family: var(--font-serif); font-size: 18px; }

/* ---------- Kanban ---------- */
.kanban {
  display: flex;
  gap: 16px;
  overflow-x: auto;
  padding-bottom: 12px;
  align-items: flex-start;
}
.kanban-col {
  background: #e9ebf6;
  border-radius: var(--radius);
  padding: 12px;
  min-width: 240px;
  width: 240px;
  flex-shrink: 0;
  border-top: 3px solid var(--navy);
}
.kanban-col-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 13px;
  padding: 0 4px;
}
.kanban-col-title { font-weight: 700; font-size: 13px; color: var(--navy); display: flex; align-items: center; gap: 8px; letter-spacing: 0.3px; }
.kanban-count {
  background: var(--navy);
  color: #fff;
  font-size: 11px;
  border-radius: 12px;
  padding: 2px 9px;
  font-weight: 600;
}
.kanban-cards { display: flex; flex-direction: column; gap: 10px; min-height: 40px; }

.deudor-card {
  background: var(--surface);
  border-radius: 10px;
  padding: 14px;
  box-shadow: var(--shadow-sm);
  border: 1px solid var(--border);
  cursor: pointer;
  transition: 0.16s;
  border-left: 4px solid var(--navy-light);
}
.deudor-card:hover { box-shadow: var(--shadow); transform: translateY(-2px); border-left-color: var(--gold); }
.deudor-card-nombre { font-weight: 600; font-size: 14px; color: var(--text); margin-bottom: 5px; }
.deudor-card-meta { font-size: 12px; color: var(--text-muted); display: flex; align-items: center; gap: 6px; }
.score-pill {
  display: inline-block;
  font-size: 11px;
  font-weight: 700;
  padding: 2px 9px;
  border-radius: 10px;
  color: #fff;
  background: var(--text-muted);
}
.score-high { background: var(--success); }
.score-mid { background: var(--warning); }
.score-low { background: var(--danger); }

/* ---------- Tablas ---------- */
.table-wrap { overflow-x: auto; border-radius: var(--radius); border: 1px solid var(--border); background: var(--surface); }
.table { width: 100%; border-collapse: collapse; }
.table th {
  text-align: left;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 1px;
  color: var(--text-muted);
  padding: 13px 16px;
  background: #fafbfe;
  border-bottom: 2px solid var(--border);
  font-weight: 700;
}
.table td {
  padding: 15px 16px;
  border-bottom: 1px solid var(--border);
  font-size: 14px;
}
.table tr:last-child td { border-bottom: none; }
.table tr:hover td { background: #f8f9fe; }

.badge {
  display: inline-block;
  font-size: 11px;
  font-weight: 600;
  padding: 4px 11px;
  border-radius: 12px;
}
.badge-activo { background: #e6f7ee; color: var(--success); }
.badge-pagado { background: #e0e7ff; color: var(--navy); }
.badge-mora { background: #fde8e8; color: var(--danger); }
.badge-castigado { background: #f3f4f6; color: var(--text-muted); }

/* ---------- Formularios ---------- */
.field-label {
  display: block;
  font-size: 12px;
  font-weight: 600;
  color: var(--text-muted);
  margin-bottom: 6px;
  margin-top: 14px;
  letter-spacing: 0.3px;
}
.field-label:first-child { margin-top: 0; }
.field-input {
  width: 100%;
  padding: 11px 13px;
  border: 1px solid var(--border);
  border-radius: 9px;
  font-family: var(--font-sans);
  font-size: 14px;
  color: var(--text);
  background: #fff;
  transition: 0.18s;
}
.field-input:focus { outline: none; border-color: var(--navy); box-shadow: 0 0 0 3px rgba(0,28,127,0.12); }
textarea.field-input { resize: vertical; }
select.field-input { cursor: pointer; }

.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 4px 20px; }
@media (max-width: 600px) { .form-grid { grid-template-columns: 1fr; } }

.score-display { text-align: center; color: var(--navy); font-weight: 700; font-size: 14px; margin-top: -4px; }

/* ---------- Modales ---------- */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 9, 40, 0.6);
  backdrop-filter: blur(3px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  padding: 20px;
  animation: fade 0.2s ease;
}
.modal {
  background: var(--surface);
  border-radius: 16px;
  width: 100%;
  max-width: 560px;
  max-height: 90vh;
  overflow-y: auto;
  box-shadow: 0 30px 80px rgba(0,9,40,0.4);
  animation: card-in 0.3s cubic-bezier(0.16, 1, 0.3, 1);
}
.modal-wide { max-width: 940px; }
.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 22px 26px;
  border-bottom: 1px solid var(--border);
  background: linear-gradient(180deg, #fafbfe, #fff);
  border-radius: 16px 16px 0 0;
}
.modal-title { font-family: var(--font-serif); font-size: 24px; font-weight: 700; color: var(--navy); }
.modal-close {
  background: none; border: none;
  font-size: 28px; color: var(--text-muted);
  cursor: pointer; line-height: 1;
  width: 34px; height: 34px; border-radius: 50%;
  transition: 0.15s;
}
.modal-close:hover { color: var(--text); background: var(--bg); }
.modal-body { padding: 24px 26px; }
.modal-footer {
  padding: 18px 26px;
  border-top: 1px solid var(--border);
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  background: #fafbfe;
  border-radius: 0 0 16px 16px;
}

/* Ficha */
.ficha-grid { display: grid; grid-template-columns: 1.3fr 1fr; gap: 26px; }
@media (max-width: 700px) { .ficha-grid { grid-template-columns: 1fr; } }
.ficha-datos { margin-bottom: 18px; }
.dato-row { display: flex; justify-content: space-between; padding: 9px 0; border-bottom: 1px solid var(--border); font-size: 14px; }
.dato-label { color: var(--text-muted); }
.dato-valor { font-weight: 600; text-align: right; color: var(--text); }

.score-block { margin-bottom: 22px; }
.score-label { font-size: 13px; color: var(--text-muted); display: block; margin-bottom: 9px; }
.score-bar { height: 12px; background: var(--bg); border-radius: 6px; overflow: hidden; margin-bottom: 7px; }
.score-fill { height: 100%; background: linear-gradient(90deg, var(--danger), var(--gold), var(--success)); border-radius: 6px; transition: width 0.4s; }
.score-num { font-family: var(--font-serif); font-size: 24px; font-weight: 700; color: var(--navy); }

.notas-block h3, .etapa-selector h3, .simulador h3 { font-size: 15px; font-weight: 700; color: var(--navy); margin-bottom: 12px; }
.notas-lista { display: flex; flex-direction: column; gap: 8px; margin-bottom: 12px; max-height: 180px; overflow-y: auto; }
.nota-item { background: var(--bg); padding: 11px 13px; border-radius: 9px; font-size: 13px; border-left: 3px solid var(--gold); }
.nota-item small { color: var(--text-muted); display: block; margin-top: 4px; }
.nota-form { display: flex; gap: 8px; }
.nota-form .field-input { flex: 1; }

.etapa-selector { margin-bottom: 20px; }

.simulador { background: #f0f2fa; padding: 18px; border-radius: 12px; margin-bottom: 18px; border: 1px solid var(--border); }
.sim-resultado {
  background: linear-gradient(135deg, var(--navy-dark), var(--navy));
  color: #fff;
  padding: 16px;
  border-radius: 10px;
  margin: 16px 0;
  text-align: center;
  box-shadow: var(--shadow);
}
.sim-resultado .sim-cuota { font-family: var(--font-serif); font-size: 28px; font-weight: 700; color: var(--gold-light); display: block; }
.sim-resultado .sim-detalle { font-size: 12px; opacity: 0.85; margin-top: 5px; }

.creditos-deudor { margin-top: 8px; }
.credito-mini { background: var(--bg); padding: 12px 14px; border-radius: 9px; margin-bottom: 8px; font-size: 13px; border-left: 3px solid var(--navy-light); }

/* ---------- Toast ---------- */
.toast {
  position: fixed;
  bottom: 26px;
  right: 26px;
  background: var(--navy);
  color: #fff;
  padding: 14px 22px;
  border-radius: 11px;
  font-weight: 500;
  box-shadow: 0 10px 30px rgba(0,9,40,0.32);
  z-index: 200;
  opacity: 0;
  transform: translateY(12px);
  transition: 0.28s cubic-bezier(0.16, 1, 0.3, 1);
  pointer-events: none;
  border-left: 4px solid var(--gold);
}
.toast.show { opacity: 1; transform: translateY(0); }
.toast.error { background: var(--danger); border-left-color: #fff; }

.hidden { display: none !important; }
