/* ============ Patmos — Portal de Asesoría Financiera ============ */
:root {
  /* Paleta corporativa: verde oscuro con acentos dorados */
  --navy: #0b2e1f;
  --navy-2: #12452f;
  --navy-3: #1a5c41;
  --gold: #c9a227;
  --gold-light: #e7c65a;
  --bg: #f4f6fa;
  --card: #ffffff;
  --text: #1c2536;
  --muted: #64748b;
  --line: #e2e8f0;
  --green: #16a34a;
  --green-bg: #ecfdf3;
  --red: #dc2626;
  --red-bg: #fef2f2;
  --blue: #2563eb;
  --blue-bg: #eff6ff;
  --amber: #b45309;
  --amber-bg: #fffbeb;
  --radius: 12px;
  --shadow: 0 1px 3px rgba(15, 23, 42, .08), 0 4px 16px rgba(15, 23, 42, .06);
  font-size: 15px;
}

* { margin: 0; padding: 0; box-sizing: border-box; }
html, body { height: 100%; }
body {
  font-family: "Segoe UI", system-ui, -apple-system, sans-serif;
  background: var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
}
.hidden { display: none !important; }
code { background: #eef2f7; padding: 1px 6px; border-radius: 5px; font-size: .85em; }

/* ============ LOGIN ============ */
.login-screen {
  min-height: 100vh;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  background: radial-gradient(1200px 600px at 70% -10%, #2b6e4d 0%, var(--navy) 55%);
  padding: 24px;
}
.login-card {
  background: var(--card); border-radius: 18px; box-shadow: var(--shadow);
  width: 100%; max-width: 400px; padding: 36px;
}
.login-brand { text-align: center; margin-bottom: 26px; }
.login-brand h1 { font-size: 1.7rem; letter-spacing: .5px; margin-top: 10px; color: var(--navy); }
.login-brand p { color: var(--muted); font-size: .9rem; }
.login-logo { width: 210px; max-width: 85%; display: block; margin: 0 auto 4px; }
.sidebar-logo {
  background: #fff; border-radius: 12px; padding: 6px 14px; width: 100%;
  box-shadow: inset 0 0 0 1px rgba(255,255,255,.15);
}
.sidebar-logo img { width: 100%; display: block; }
.brand-logo {
  width: 52px; height: 52px; border-radius: 14px; margin: 0 auto;
  background: linear-gradient(135deg, var(--navy) 0%, var(--navy-3) 100%);
  color: var(--gold-light); font-size: 1.6rem; font-weight: 700;
  display: flex; align-items: center; justify-content: center;
  border: 1px solid var(--gold);
}
.brand-logo.sm { width: 38px; height: 38px; font-size: 1.15rem; margin: 0; border-radius: 10px; }
#login-form label { display: block; font-size: .82rem; font-weight: 600; color: var(--muted); margin: 14px 0 5px; }
#login-form input {
  width: 100%; padding: 11px 13px; border: 1px solid var(--line); border-radius: 9px;
  font-size: .95rem; outline: none; transition: border .15s;
}
#login-form input:focus { border-color: var(--blue); }
#login-form button { margin-top: 20px; }
.login-error { color: var(--red); background: var(--red-bg); border-radius: 8px; padding: 9px 12px; font-size: .85rem; margin-top: 12px; }
.login-demo {
  margin-top: 22px; border-top: 1px dashed var(--line); padding-top: 16px;
  font-size: .8rem; color: var(--muted); line-height: 1.7;
}
.login-footer { color: #94a3b8; font-size: .78rem; margin-top: 18px; }

/* ============ LAYOUT ============ */
.app { display: flex; min-height: 100vh; }
.sidebar {
  width: 248px; flex-shrink: 0; background: var(--navy); color: #cbd5e1;
  display: flex; flex-direction: column; position: sticky; top: 0; height: 100vh;
}
.sidebar-brand {
  display: flex; align-items: center; gap: 11px; padding: 20px 18px 16px;
  border-bottom: 1px solid rgba(255,255,255,.08);
}
.brand-name { color: #fff; font-weight: 700; font-size: 1.05rem; letter-spacing: .4px; }
.brand-sub { font-size: .72rem; color: #93b8a5; }
.nav { flex: 1; padding: 14px 10px; overflow-y: auto; }
.nav-item {
  display: flex; align-items: center; gap: 10px; width: 100%;
  padding: 10px 12px; margin-bottom: 3px; border: none; background: none;
  color: #bad3c6; font-size: .9rem; border-radius: 9px; cursor: pointer; text-align: left;
  transition: background .12s, color .12s;
}
.nav-item:hover { background: rgba(255,255,255,.06); color: #fff; }
.nav-item.active { background: var(--navy-3); color: #fff; font-weight: 600; box-shadow: inset 3px 0 0 var(--gold); }
.nav-section { font-size: .68rem; text-transform: uppercase; letter-spacing: 1px; color: #6f9483; padding: 14px 12px 6px; }
.sidebar-footer { padding: 14px; border-top: 1px solid rgba(255,255,255,.08); }
.user-chip { font-size: .82rem; margin-bottom: 10px; line-height: 1.4; }
.user-chip .u-name { color: #fff; font-weight: 600; }
.user-chip .u-role { color: #93b8a5; font-size: .74rem; }

.main { flex: 1; display: flex; flex-direction: column; min-width: 0; }
.topbar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 16px 28px; background: var(--card); border-bottom: 1px solid var(--line);
  position: sticky; top: 0; z-index: 30;
}
.topbar h2 { font-size: 1.15rem; color: var(--navy); }
.topbar-actions { display: flex; align-items: center; gap: 12px; }
.content { padding: 26px 28px 60px; max-width: 1280px; width: 100%; }

/* ============ COMPONENTES ============ */
.btn {
  display: inline-flex; align-items: center; gap: 7px; border: none; cursor: pointer;
  padding: 9px 16px; border-radius: 9px; font-size: .88rem; font-weight: 600;
  transition: filter .12s, background .12s;
}
.btn:hover { filter: brightness(1.07); }
.btn-primary { background: var(--navy-2); color: #fff; }
.btn-gold { background: var(--gold); color: #241c02; }
.btn-green { background: var(--green); color: #fff; }
.btn-danger { background: var(--red); color: #fff; }
.btn-outline { background: #fff; border: 1px solid var(--line); color: var(--text); }
.btn-ghost { background: rgba(255,255,255,.08); color: #cbd5e1; }
.btn-block { width: 100%; justify-content: center; }
.btn-sm { padding: 5px 10px; font-size: .78rem; border-radius: 7px; }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.icon-btn {
  position: relative; background: none; border: 1px solid var(--line); border-radius: 9px;
  width: 38px; height: 38px; cursor: pointer; font-size: 1rem;
  display: inline-flex; align-items: center; justify-content: center;
}
.icon-btn:hover { background: var(--bg); }
.badge {
  position: absolute; top: -6px; right: -6px; background: var(--red); color: #fff;
  font-size: .66rem; font-weight: 700; border-radius: 999px; padding: 2px 6px; min-width: 18px;
}

.grid { display: grid; gap: 18px; }
.grid-4 { grid-template-columns: repeat(4, 1fr); }
.grid-3 { grid-template-columns: repeat(3, 1fr); }
.grid-2 { grid-template-columns: repeat(2, 1fr); }
.grid-2-1 { grid-template-columns: 2fr 1fr; }
@media (max-width: 1100px) { .grid-4 { grid-template-columns: repeat(2, 1fr); } .grid-3, .grid-2-1 { grid-template-columns: 1fr; } }

.card { background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); padding: 20px; }
.card h3 { font-size: .95rem; color: var(--navy); margin-bottom: 14px; }
.card .card-sub { font-size: .78rem; color: var(--muted); margin-top: -10px; margin-bottom: 14px; }

.kpi { padding: 18px 20px; }
.kpi .kpi-label { font-size: .76rem; text-transform: uppercase; letter-spacing: .6px; color: var(--muted); font-weight: 600; }
.kpi .kpi-value { font-size: 1.55rem; font-weight: 700; color: var(--navy); margin-top: 6px; }
.kpi .kpi-delta { font-size: .8rem; margin-top: 4px; font-weight: 600; }
.pos { color: var(--green); } .neg { color: var(--red); }

.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: .87rem; }
th {
  text-align: left; font-size: .72rem; text-transform: uppercase; letter-spacing: .5px;
  color: var(--muted); padding: 9px 12px; border-bottom: 2px solid var(--line); white-space: nowrap;
}
td { padding: 11px 12px; border-bottom: 1px solid var(--line); vertical-align: middle; }
tr:last-child td { border-bottom: none; }
tbody tr:hover { background: #f8fafc; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
.clickable { cursor: pointer; }

.tag { display: inline-block; padding: 3px 10px; border-radius: 999px; font-size: .72rem; font-weight: 700; }
.tag-green { background: var(--green-bg); color: var(--green); }
.tag-red { background: var(--red-bg); color: var(--red); }
.tag-blue { background: var(--blue-bg); color: var(--blue); }
.tag-amber { background: var(--amber-bg); color: var(--amber); }
.tag-gray { background: #f1f5f9; color: var(--muted); }

.toolbar { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 16px; flex-wrap: wrap; }
.toolbar .left, .toolbar .right { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
input[type=text], input[type=number], input[type=date], input[type=email], input[type=password], select, textarea {
  padding: 9px 12px; border: 1px solid var(--line); border-radius: 9px; font-size: .88rem;
  outline: none; background: #fff; font-family: inherit;
}
input:focus, select:focus, textarea:focus { border-color: var(--blue); }

.tabs { display: flex; gap: 4px; border-bottom: 2px solid var(--line); margin-bottom: 20px; overflow-x: auto; }
.tab {
  padding: 10px 16px; border: none; background: none; cursor: pointer; font-size: .88rem;
  color: var(--muted); font-weight: 600; border-bottom: 2px solid transparent; margin-bottom: -2px; white-space: nowrap;
}
.tab.active { color: var(--navy); border-bottom-color: var(--gold); }

/* Formularios en modal */
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 13px 16px; }
.form-grid .full { grid-column: 1 / -1; }
.field label { display: block; font-size: .78rem; font-weight: 600; color: var(--muted); margin-bottom: 5px; }
.field input, .field select, .field textarea { width: 100%; }
.form-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 20px; }
.form-hint { font-size: .78rem; color: var(--muted); margin-top: 6px; line-height: 1.5; }

/* Modal */
.modal-overlay {
  position: fixed; inset: 0; background: rgba(10, 18, 34, .55); z-index: 100;
  display: flex; align-items: flex-start; justify-content: center; padding: 6vh 16px; overflow-y: auto;
}
.modal { background: #fff; border-radius: 16px; width: 100%; max-width: 620px; box-shadow: 0 24px 64px rgba(0,0,0,.3); }
.modal.wide { max-width: 860px; }
.modal-head { display: flex; align-items: center; justify-content: space-between; padding: 18px 22px; border-bottom: 1px solid var(--line); }
.modal-head h3 { font-size: 1.02rem; color: var(--navy); }
.modal-body { padding: 22px; }

/* Notificaciones */
.notif-panel {
  position: fixed; top: 64px; right: 22px; width: 360px; max-height: 65vh; z-index: 90;
  background: #fff; border-radius: 14px; box-shadow: 0 16px 48px rgba(0,0,0,.22);
  display: flex; flex-direction: column; overflow: hidden;
}
.notif-head { display: flex; justify-content: space-between; align-items: center; padding: 13px 16px; border-bottom: 1px solid var(--line); }
.notif-list { overflow-y: auto; }
.notif-item { padding: 12px 16px; border-bottom: 1px solid var(--line); font-size: .84rem; }
.notif-item.unread { background: var(--blue-bg); }
.notif-item .n-title { font-weight: 600; }
.notif-item .n-date { font-size: .72rem; color: var(--muted); margin-top: 3px; }
.notif-empty { padding: 26px; text-align: center; color: var(--muted); font-size: .85rem; }

/* Toast */
.toast {
  position: fixed; bottom: 26px; left: 50%; transform: translateX(-50%);
  background: var(--navy); color: #fff; padding: 12px 22px; border-radius: 10px;
  font-size: .88rem; z-index: 200; box-shadow: var(--shadow);
}

/* Charts */
.chart-box { display: flex; align-items: center; gap: 20px; flex-wrap: wrap; }
.legend { font-size: .8rem; display: flex; flex-direction: column; gap: 7px; }
.legend-item { display: flex; align-items: center; gap: 8px; }
.legend-dot { width: 11px; height: 11px; border-radius: 3px; flex-shrink: 0; }
.empty-state { text-align: center; color: var(--muted); padding: 40px 20px; font-size: .9rem; }
.empty-state .big { font-size: 2rem; margin-bottom: 8px; }

/* Documentos */
.doc-item {
  display: flex; align-items: center; gap: 13px; padding: 13px 4px; border-bottom: 1px solid var(--line);
}
.doc-icon { font-size: 1.4rem; }
.doc-meta { flex: 1; min-width: 0; }
.doc-name { font-weight: 600; font-size: .88rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.doc-sub { font-size: .76rem; color: var(--muted); }

/* ============ MÓVIL (menú desplegable + refinamiento) ============ */
.menu-btn { display: none; }
.sidebar-backdrop { position: fixed; inset: 0; background: rgba(8, 20, 14, .5); z-index: 115; }

@media (max-width: 860px) {
  /* Barra lateral: cajón deslizante que se abre con ☰ */
  .menu-btn { display: inline-flex; flex-shrink: 0; }
  .sidebar {
    position: fixed; left: 0; top: 0; bottom: 0; z-index: 120; width: 272px; height: 100%;
    transform: translateX(-105%); transition: transform .22s ease;
    box-shadow: 8px 0 32px rgba(0,0,0,.35);
  }
  .sidebar.open { transform: translateX(0); }

  .topbar { padding: 10px 12px; gap: 10px; }
  .topbar h2 { font-size: 1rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .content { padding: 14px 12px 70px; }

  .grid { gap: 10px; }
  .grid-2, .grid-3, .grid-2-1 { grid-template-columns: 1fr; }
  .grid-4 { grid-template-columns: 1fr 1fr; }
  .card { padding: 14px; border-radius: 10px; }
  .kpi { padding: 12px 14px; }
  .kpi .kpi-value { font-size: 1.15rem; }
  .kpi .kpi-label { font-size: .66rem; }
  .kpi .kpi-delta { font-size: .72rem; }

  .toolbar { gap: 8px; }
  .toolbar .left, .toolbar .right { width: 100%; }
  .toolbar .right { justify-content: flex-start; }
  .btn { padding: 9px 13px; font-size: .84rem; }

  table { font-size: .8rem; }
  th, td { padding: 8px 8px; }

  .form-grid { grid-template-columns: 1fr; }
  .modal-overlay { padding: 2vh 8px; }
  .modal { border-radius: 12px; }
  .modal-body { padding: 16px; }

  .notif-panel { left: 8px; right: 8px; width: auto; top: 58px; }
  .chart-box { justify-content: center; }
  .tabs { gap: 0; }
  .tab { padding: 9px 11px; font-size: .8rem; }
}

/* Recibo / impresión */
.print-area { display: none; }
@media print {
  body > *:not(.print-area) { display: none !important; }
  .print-area { display: block !important; padding: 30px; font-size: 13px; }
}
.receipt { font-family: "Segoe UI", sans-serif; color: #111; max-width: 700px; margin: 0 auto; }
.receipt h2 { color: var(--navy); }
.receipt table { margin-top: 14px; }
.receipt .r-head { display: flex; justify-content: space-between; border-bottom: 3px solid var(--navy); padding-bottom: 14px; margin-bottom: 18px; }
.receipt .r-total { font-size: 1.15rem; font-weight: 700; }
.muted { color: var(--muted); font-size: .82rem; }
.small { font-size: .8rem; }
