/* ============================================================
   Portal de Gestión — Grupo D&F Consultores
   app.css — Estilos principales
   ============================================================ */

/* Fuentes */
@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700&family=Space+Grotesk:wght@600;700&display=swap');

/* Variables */
:root {
  --df-navy:    #0C2340;
  --df-blue:    #185FA5;
  --df-teal:    #1D9E75;
  --df-amber:   #BA7517;
  --df-red:     #A32D2D;
  --df-border:  #e0e8f0;
  --df-border-soft: #f0f4f8;
  --df-bg:      #f5f7fb;
  --df-card:    #ffffff;
  --df-surface-2:  #f8f9fb;
  --df-hover:      #f0f6ff;
  --df-hover-2:    #e6f1fb;
  --df-row-hover:  #fafbff;
  --df-text:    #1a2232;
  --df-muted:   #6b7a99;
  --df-emphasis: #0C2340;
  --topnav-h:   60px;
  --ticker-h:   30px;
  --sidebar-w:  224px;
  --radius:     8px;
  --radius-lg:  12px;
  --shadow-sm:  0 1px 3px rgba(0,0,0,.06);
  --shadow-md:  0 4px 14px rgba(0,0,0,.08);
}

/* ── MODO OSCURO ─────────────────────────────────────────── */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --df-border:      #263248;
    --df-border-soft: #1c2536;
    --df-bg:          #0d1420;
    --df-card:        #16202f;
    --df-surface-2:   #111a28;
    --df-hover:        rgba(24,95,165,.22);
    --df-hover-2:      rgba(24,95,165,.32);
    --df-row-hover:    rgba(255,255,255,.03);
    --df-text:        #e6ebf5;
    --df-muted:       #8b9bbd;
    --df-emphasis:    #e6ebf5;
    --shadow-sm:  0 1px 3px rgba(0,0,0,.3);
    --shadow-md:  0 4px 14px rgba(0,0,0,.4);
  }
}
:root[data-theme="dark"] {
  --df-border:      #263248;
  --df-border-soft: #1c2536;
  --df-bg:          #0d1420;
  --df-card:        #16202f;
  --df-surface-2:   #111a28;
  --df-hover:        rgba(24,95,165,.22);
  --df-hover-2:      rgba(24,95,165,.32);
  --df-row-hover:    rgba(255,255,255,.03);
  --df-text:        #e6ebf5;
  --df-muted:       #8b9bbd;
  --df-emphasis:    #e6ebf5;
  --shadow-sm:  0 1px 3px rgba(0,0,0,.3);
  --shadow-md:  0 4px 14px rgba(0,0,0,.4);
}

/* Reset */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { font-size: 16px; color-scheme: light; }
@media (prefers-color-scheme: dark) { html:not([data-theme="light"]) { color-scheme: dark; } }
html[data-theme="dark"] { color-scheme: dark; }
body { font-family: 'Inter', system-ui, sans-serif; background: var(--df-bg); color: var(--df-text); line-height: 1.5; }
a    { color: var(--df-blue); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ── TOP NAV ─────────────────────────────────────────────── */
.topnav {
  position: fixed; top: 0; left: 0; right: 0; z-index: 200;
  height: var(--topnav-h);
  background: var(--df-navy);
  display: flex; align-items: center;
  padding: 0 1.25rem; gap: 1rem;
  border-bottom: 1px solid rgba(255,255,255,.08);
}

.topnav-brand { display: flex; align-items: center; gap: 10px; color: white; padding-right: 1.25rem; border-right: 1px solid rgba(255,255,255,.15); flex-shrink: 0; }
.brand-logo { height: 34px; width: auto; display: block; }
.brand-icon { width: 38px; height: 38px; background: var(--df-teal); border-radius: 9px; display: flex; align-items: center; justify-content: center; font-family: 'Space Grotesk', sans-serif; font-weight: 700; font-size: 13px; color: white; flex-shrink: 0; }
.brand-name { font-family: 'Space Grotesk', sans-serif; font-weight: 700; font-size: 15px; color: white; display: block; }
.brand-sub  { font-size: 10px; color: rgba(255,255,255,.5); display: block; }

.topnav-empresa {
  display: flex; align-items: center; gap: 10px;
  background: rgba(255,255,255,.08);
  border: 1px solid rgba(255,255,255,.15);
  border-radius: var(--radius); padding: 6px 12px; color: white;
  cursor: pointer; position: relative; user-select: none;
  transition: background .15s;
}
.topnav-empresa:hover { background: rgba(255,255,255,.14); }
.empresa-nombre { font-size: 13px; font-weight: 500; color: white; }
.empresa-rut    { font-size: 10px; color: rgba(255,255,255,.5); }
.empresa-avatar { width: 28px; height: 28px; background: var(--df-blue); border-radius: 7px; display: flex; align-items: center; justify-content: center; font-size: 11px; font-weight: 700; color: white; }

.topnav-right { margin-left: auto; display: flex; align-items: center; gap: 10px; }

.topnav-sync {
  display: flex; align-items: center; gap: 7px;
  background: rgba(29,158,117,.15); border: 1px solid rgba(29,158,117,.35);
  color: #5DCAA5; border-radius: var(--radius); padding: 5px 12px;
  font-size: 12px; font-weight: 600; cursor: pointer; white-space: nowrap;
  transition: background .15s;
}
.topnav-sync:hover { background: rgba(29,158,117,.25); }
.sync-dot { width: 6px; height: 6px; background: #5DCAA5; border-radius: 50%; animation: pulse 2s infinite; }
@keyframes pulse { 0%,100%{opacity:1} 50%{opacity:.3} }

.topnav-icon-btn { position: relative; width: 36px; height: 36px; border-radius: 50%; display: flex; align-items: center; justify-content: center; color: rgba(255,255,255,.7); cursor: pointer; transition: background .15s; }
.topnav-icon-btn:hover { background: rgba(255,255,255,.1); }

.theme-toggle { border: none; background: none; padding: 0; }
.theme-toggle .icon-moon { display: none; }
:root[data-theme="dark"] .theme-toggle .icon-sun  { display: none; }
:root[data-theme="dark"] .theme-toggle .icon-moon { display: flex; }
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .theme-toggle .icon-sun  { display: none; }
  :root:not([data-theme="light"]) .theme-toggle .icon-moon { display: flex; }
}
.notif-badge { position: absolute; top: 2px; right: 2px; width: 16px; height: 16px; background: var(--df-red); border-radius: 50%; font-size: 9px; font-weight: 700; color: white; display: flex; align-items: center; justify-content: center; }

.topnav-user { display: flex; align-items: center; gap: 8px; cursor: pointer; padding: 4px 8px; border-radius: var(--radius); transition: background .15s; }
.topnav-user:hover { background: rgba(255,255,255,.08); }
.user-avatar { width: 32px; height: 32px; background: var(--df-blue); border-radius: 50%; display: flex; align-items: center; justify-content: center; font-size: 12px; font-weight: 700; color: white; }
.topnav-empresa-logo { display: flex; align-items: center; justify-content: center; height: 36px; padding: 4px 12px; background: #fff; border-radius: 8px; }
.topnav-empresa-logo img { max-height: 28px; max-width: 150px; width: auto; height: auto; display: block; }
.topnav-empresa-logo-fallback { font-size: 13px; font-weight: 700; color: var(--df-navy); white-space: nowrap; }
.user-name  { font-size: 13px; font-weight: 500; color: white; display: block; }
.user-role  { font-size: 10px; color: rgba(255,255,255,.5); display: block; text-transform: capitalize; }

.dropdown {
  position: absolute; top: calc(100% + 6px); right: 0;
  background: var(--df-card); border: 1px solid var(--df-border);
  border-radius: var(--radius-lg); padding: .5rem;
  min-width: 180px; box-shadow: var(--shadow-md);
  display: none; z-index: 300;
}
.dropdown.open { display: block; }
.dropdown a { display: flex; align-items: center; gap: 8px; padding: 8px 10px; border-radius: var(--radius); font-size: 13.5px; color: var(--df-text); }
.dropdown a:hover { background: var(--df-bg); text-decoration: none; }
.dropdown a.danger { color: var(--df-red); }
.dropdown hr { border: none; border-top: 1px solid var(--df-border); margin: .4rem 0; }

/* ── LAYOUT ──────────────────────────────────────────────── */
.app-layout { display: flex; padding-top: calc(var(--topnav-h) + var(--ticker-h)); min-height: 100vh; }

/* ── SIDEBAR ─────────────────────────────────────────────── */
.sidebar {
  width: var(--sidebar-w); background: var(--df-card);
  border-right: 1px solid var(--df-border);
  position: fixed; top: calc(var(--topnav-h) + var(--ticker-h)); bottom: 0; left: 0;
  overflow-y: auto; display: flex; flex-direction: column;
  z-index: 100;
}
.sidebar-nav { flex: 1; padding: 1rem .75rem; }
.sidebar-section { font-size: 10px; font-weight: 700; letter-spacing: .8px; text-transform: uppercase; color: var(--df-muted); padding: .75rem .75rem .25rem; }
.sidebar-item {
  display: flex; align-items: center; gap: 10px;
  padding: 7px 10px; border-radius: var(--radius);
  font-size: 13.5px; font-weight: 500; color: var(--df-text);
  cursor: pointer; transition: all .15s; white-space: nowrap;
  border: none; background: none; width: 100%; text-align: left;
  text-decoration: none;
}
.sidebar-item i { font-size: 17px; width: 20px; flex-shrink: 0; }
.sidebar-item:hover { background: var(--df-hover); color: var(--df-blue); text-decoration: none; }
.sidebar-item.active { background: var(--df-hover-2); color: var(--df-blue); font-weight: 600; }
.sidebar-badge { margin-left: auto; background: var(--df-red); color: white; font-size: 10px; padding: 1px 6px; border-radius: 10px; font-weight: 700; min-width: 18px; text-align: center; }
.sidebar-badge[data-badge="overdue_count"] { background: var(--df-amber); }
.sidebar-badge[data-badge="pending_acuse"] { background: var(--df-amber); }
.sidebar-footer { padding: .75rem; border-top: 1px solid var(--df-border); display: flex; flex-direction: column; gap: 8px; font-size: 11px; color: var(--df-muted); }
.sidebar-empresa-pick { display: flex; flex-direction: column; gap: 2px; padding: 8px 10px; border: 1px solid var(--df-border); border-radius: 8px; background: var(--df-surface-2); }
.sidebar-empresa-pick label { font-size: 10px; color: var(--df-muted); text-transform: uppercase; letter-spacing: .4px; }
.sidebar-empresa-pick select { border: none; background: transparent; font-size: 13px; font-weight: 600; color: var(--df-text); cursor: pointer; outline: none; padding: 0; font-family: inherit; width: 100%; }
.sidebar-user { display: flex; align-items: center; gap: 8px; padding: 8px 10px; border-radius: 8px; text-decoration: none; transition: background .15s; }
.sidebar-user:hover { background: var(--df-hover); text-decoration: none; }
.sidebar-user-avatar-wrap { position: relative; flex-shrink: 0; }
.sidebar-user-avatar-wrap .user-avatar { width: 44px; height: 44px; font-size: 16px; box-shadow: 0 0 0 2px var(--df-card), 0 0 0 4px var(--df-blue); }
.sidebar-user-online { position: absolute; bottom: 0; right: 0; width: 10px; height: 10px; border-radius: 50%; background: #22c55e; border: 2px solid var(--df-card); }
.sidebar-user-info { min-width: 0; }
.sidebar-user-name { display: block; font-size: 13px; font-weight: 600; color: var(--df-text); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.sidebar-user-role { display: block; font-size: 11px; color: var(--df-muted); text-transform: capitalize; }
.sidebar-logout { display: flex; align-items: center; gap: 8px; padding: 8px 10px; border-radius: 8px; font-size: 13px; color: var(--df-red); text-decoration: none; }
.sidebar-logout:hover { background: #fef2f2; text-decoration: none; }
.sidebar-version { font-size: 10px; color: var(--df-muted); text-align: center; }

/* ── MAIN CONTENT ────────────────────────────────────────── */
.main-content { flex: 1; margin-left: var(--sidebar-w); padding: 2rem; min-width: 0; }

/* ── PAGE HEADER ─────────────────────────────────────────── */
.page-header { display: flex; align-items: flex-start; justify-content: space-between; margin-bottom: 1.75rem; gap: 1rem; }
.page-title  { font-family: 'Space Grotesk', sans-serif; font-size: 22px; font-weight: 700; color: var(--df-emphasis); display: flex; align-items: center; gap: 8px; }
.page-title i { font-size: 22px; color: var(--df-blue); }
.page-subtitle{ font-size: 13px; color: var(--df-muted); margin-top: 3px; }
.page-actions { display: flex; gap: 8px; flex-shrink: 0; }

/* ── METRICS GRID ────────────────────────────────────────── */
.metrics-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px,1fr)); gap: 14px; margin-bottom: 1.75rem; }
.metric-card  { background: var(--df-card); border: .5px solid var(--df-border); border-radius: var(--radius-lg); padding: 1.1rem 1.25rem; }
.metric-label { font-size: 12px; color: var(--df-muted); font-weight: 500; margin-bottom: 6px; }
.metric-value { font-size: 26px; font-weight: 700; color: var(--df-emphasis); line-height: 1; }
.metric-value.text-green  { color: #0F6E56; }
.metric-value.text-red    { color: var(--df-red); }
.metric-value.text-amber  { color: var(--df-amber); }
.metric-value.text-blue   { color: var(--df-blue); }
.metric-value.text-purple { color: #7c3aed; }
.metric-value.text-teal   { color: var(--df-teal); }
.metric-value.text-cyan   { color: #0891b2; }
.metric-trend { font-size: 11px; margin-top: 4px; display: flex; align-items: center; gap: 4px; color: var(--df-muted); }
.metric-card--icon { display: flex; align-items: flex-start; justify-content: space-between; gap: .5rem; }
.metric-card-body  { min-width: 0; }
.metric-icon-circle { width: 38px; height: 38px; border-radius: 50%; display: flex; align-items: center; justify-content: center; flex-shrink: 0; }
.metric-icon-circle i { font-size: 18px; }

/* ── KPI CARD (dashboard) ────────────────────────────────── */
.kpi-cards-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px,1fr)); gap: 12px; }
.kpi-card { background: var(--df-card); border: .5px solid var(--df-border); border-radius: var(--radius-lg); padding: 15px 16px; display: flex; flex-direction: column; gap: 9px; }
.kpi-card-top { display: flex; align-items: flex-start; justify-content: space-between; gap: 8px; }
.kpi-card-label { font-size: 12.5px; color: var(--df-muted); font-weight: 500; }
.kpi-card-icon { width: 36px; height: 36px; border-radius: 10px; display: flex; align-items: center; justify-content: center; flex-shrink: 0; }
.kpi-card-icon i { font-size: 17px; }
.kpi-card-value-row { display: flex; align-items: baseline; gap: 8px; flex-wrap: wrap; }
.kpi-card-value { font-size: 22px; font-weight: 700; letter-spacing: -.01em; color: var(--df-emphasis); }
.kpi-card-delta { display: inline-flex; align-items: center; gap: 2px; font-size: 11.5px; font-weight: 700; padding: 1px 7px; border-radius: 6px; }
.kpi-card-delta.up   { color: #15803d; background: #dcfce7; }
.kpi-card-delta.down { color: #dc2626; background: #fee2e2; }
.kpi-card-sub { font-size: 12px; color: var(--df-muted); }

/* ── CARDS ───────────────────────────────────────────────── */
.table-card  { background: var(--df-card); border: .5px solid var(--df-border); border-radius: var(--radius-lg); overflow: hidden; margin-bottom: 1.5rem; }
.table-card-header { padding: .875rem 1.25rem; border-bottom: 1px solid var(--df-border-soft); display: flex; align-items: center; justify-content: space-between; gap: 1rem; }
.table-card-title  { font-size: 14px; font-weight: 600; color: var(--df-emphasis); display: flex; align-items: center; gap: 8px; }
.table-actions { display: flex; gap: 8px; flex-shrink: 0; }

/* ── TABLA ───────────────────────────────────────────────── */
.table-responsive { overflow-x: auto; }
table.table { width: 100%; border-collapse: collapse; }
.table thead th { padding: 10px 16px; text-align: left; font-size: 11px; font-weight: 600; color: var(--df-muted); text-transform: uppercase; letter-spacing: .4px; background: var(--df-surface-2); border-bottom: 1px solid var(--df-border); white-space: nowrap; }
.table tbody td { padding: 11px 16px; font-size: 13px; color: var(--df-text); border-bottom: .5px solid var(--df-border-soft); }
.table tbody tr:last-child td { border-bottom: none; }
.table tbody tr:hover td { background: var(--df-row-hover); }
.table .text-right { text-align: right; }
.table .text-muted  { color: var(--df-muted); }
.table-empty { text-align: center; color: var(--df-muted); padding: 2rem !important; }

/* ── STATUS ──────────────────────────────────────────────── */
.status { display: inline-flex; align-items: center; gap: 4px; font-size: 11px; font-weight: 600; padding: 3px 9px; border-radius: 20px; }
.status-dot { width: 5px; height: 5px; border-radius: 50%; background: currentColor; }
.status-acusado   { background: #EAF3DE; color: #3B6D11; }
.status-pendiente { background: #FAEEDA; color: #854F0B; }
.status-vencido   { background: #FCEBEB; color: var(--df-red); }
.status-pagado    { background: #E1F5EE; color: #0F6E56; }
.status-rechazado { background: #FAECE7; color: #993C1D; }

/* ── BADGES ──────────────────────────────────────────────── */
.badge { display: inline-block; font-size: 11px; font-weight: 600; padding: 2px 8px; border-radius: 20px; }
.badge-warning { background: #FAEEDA; color: #854F0B; }
.badge-danger  { background: #FCEBEB; color: var(--df-red); }
.badge-success { background: #E1F5EE; color: #0F6E56; }

/* ── BOTONES ─────────────────────────────────────────────── */
.btn {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 8px 16px; border-radius: var(--radius); font-size: 13.5px;
  font-weight: 600; font-family: inherit; cursor: pointer; border: none;
  transition: all .15s; line-height: 1;
}
.btn-sm     { padding: 6px 12px; font-size: 12px; }
.btn-full   { width: 100%; justify-content: center; }
.btn-primary{ background: var(--df-navy); color: white; }
.btn-primary:hover { background: var(--df-blue); }
.btn-outline{ background: var(--df-card); border: 1px solid var(--df-border); color: var(--df-text); }
.btn-outline:hover { border-color: var(--df-blue); color: var(--df-blue); background: var(--df-hover); }
.btn-success{ background: var(--df-teal); color: white; }
.btn-success:hover { background: #0F6E56; }
.btn-danger { background: var(--df-red); color: white; }
.btn-danger:hover { background: #791F1F; }
.btn:disabled { opacity: .55; cursor: not-allowed; }
.btn-group  { display: flex; gap: 4px; }

/* ── FILTROS ─────────────────────────────────────────────── */
.filters-bar  { display: flex; gap: 10px; margin-bottom: 1.25rem; flex-wrap: wrap; align-items: center; }
.filter-input { padding: 7px 14px; border: 1px solid var(--df-border); border-radius: var(--radius); font-size: 13px; font-family: inherit; outline: none; background: var(--df-card); width: 220px; }
.filter-input:focus { border-color: var(--df-blue); }
.filter-select{ padding: 7px 12px; border: 1px solid var(--df-border); border-radius: var(--radius); font-size: 13px; font-family: inherit; outline: none; background: var(--df-card); cursor: pointer; }
.filter-select:focus { border-color: var(--df-blue); }

/* ── FORMULARIOS ─────────────────────────────────────────── */
.form-group  { margin-bottom: 1rem; }
.form-label  { display: flex; justify-content: space-between; font-size: 13px; font-weight: 500; color: var(--df-text); margin-bottom: 5px; }
.form-label-link { font-weight: 400; color: var(--df-blue); font-size: 12px; }
.form-help   { display: block; font-size: 13px; color: var(--df-muted); margin-top: .25rem; }
.form-input  { display: block; width: 100%; padding: 9px 14px; border: 1.5px solid var(--df-border); border-radius: var(--radius); font-size: 14px; font-family: inherit; outline: none; transition: border-color .2s; background: var(--df-card); }
.form-input:focus  { border-color: var(--df-blue); }

/* Alias de ".form-control" (nombre usado en varias vistas, nunca definido
   antes — quedaban como <input> sin estilo, blancos fijos en modo oscuro) */
.form-control { display: block; width: 100%; padding: 9px 14px; border: 1.5px solid var(--df-border); border-radius: var(--radius); font-size: 14px; font-family: inherit; outline: none; transition: border-color .2s; background: var(--df-card); color: var(--df-text); }
.form-control:focus { border-color: var(--df-blue); }
select.form-control { cursor: pointer; }
textarea.form-control { resize: vertical; }
.input-icon-wrap   { position: relative; }
.input-icon        { position: absolute; left: 12px; top: 50%; transform: translateY(-50%); color: var(--df-muted); font-size: 17px; pointer-events: none; }
.input-icon-wrap .form-input { padding-left: 38px; }
.input-icon-right  { position: absolute; right: 10px; top: 50%; transform: translateY(-50%); background: none; border: none; color: var(--df-muted); cursor: pointer; padding: 4px; }

/* ── SIDE PANEL ──────────────────────────────────────────── */
.side-panel {
  position: fixed; top: 0; right: -560px; bottom: 0;
  width: 520px; background: var(--df-card);
  border-left: 1px solid var(--df-border);
  z-index: 400; display: flex; flex-direction: column;
  transition: right .3s ease; box-shadow: -8px 0 30px rgba(0,0,0,.1);
}
.side-panel.open { right: 0; }
.side-panel-header { padding: 1.25rem 1.5rem; border-bottom: 1px solid var(--df-border); display: flex; justify-content: space-between; align-items: flex-start; }
.side-panel-header h3 { font-size: 16px; font-weight: 700; color: var(--df-emphasis); }
.side-panel-header small { color: var(--df-muted); font-size: 11px; }
.side-panel-close { background: none; border: none; font-size: 20px; cursor: pointer; color: var(--df-muted); padding: 4px; border-radius: 6px; }
.side-panel-close:hover { background: var(--df-bg); color: var(--df-text); }
.side-panel-body   { flex: 1; overflow-y: auto; padding: 1.5rem; }
.side-panel-footer { padding: 1.25rem 1.5rem; border-top: 1px solid var(--df-border); display: flex; gap: 10px; }

/* ── ALERT CARD (dashboard — tarjetas de color, fijo en ambos temas) ── */
.alerts-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px,1fr)); gap: 12px; }
.alert-card { border-radius: 12px; padding: 13px 14px; display: flex; flex-direction: column; gap: 7px; border: 1px solid; }
.alert-card-head { display: flex; gap: 8px; align-items: flex-start; }
.alert-card-title { font-size: 13px; font-weight: 700; margin: 0; }
.alert-card-body { font-size: 12.5px; color: #57606f; margin: 0; }
.alert-card-link { font-size: 12.5px; font-weight: 700; display: inline-flex; align-items: center; gap: 4px; text-decoration: none; width: fit-content; }
.alert-card.danger  { background: #fef2f2; border-color: #fecaca; }
.alert-card.danger  .ti, .alert-card.danger  .alert-card-title, .alert-card.danger  .alert-card-link { color: #b91c1c; }
.alert-card.warning { background: #fffbeb; border-color: #fde68a; }
.alert-card.warning .ti, .alert-card.warning .alert-card-title, .alert-card.warning .alert-card-link { color: #b45309; }
.alert-card.info    { background: #eff6ff; border-color: #bfdbfe; }
.alert-card.info    .ti, .alert-card.info    .alert-card-title, .alert-card.info    .alert-card-link { color: #1d4ed8; }

/* ── PANEL ACUSE ─────────────────────────────────────────── */
.doc-preview-card { background: var(--df-bg); border: 1px solid var(--df-border); border-radius: 10px; padding: 1.25rem; margin-bottom: 1.25rem; }
.doc-row { display: flex; justify-content: space-between; align-items: center; margin-bottom: 7px; font-size: 13px; }
.doc-row span { color: var(--df-muted); }
.doc-total { padding-top: 10px; margin-top: 10px; border-top: 1px solid var(--df-border); }
.doc-total strong { font-size: 18px; color: var(--df-emphasis); }

.radio-group { display: flex; flex-direction: column; gap: 8px; }
.radio-card  { display: flex; align-items: flex-start; gap: 10px; padding: 10px 12px; border: 1.5px solid var(--df-border); border-radius: var(--radius); cursor: pointer; transition: all .15s; font-size: 13px; }
.radio-card:has(input:checked)  { border-color: var(--df-blue); background: var(--df-hover); }
.radio-card-title { display: block; font-weight: 500; color: var(--df-text); }
.radio-card-desc  { display: block; font-size: 11px; color: var(--df-muted); margin-top: 2px; }
.radio-card input { margin-top: 3px; accent-color: var(--df-blue); flex-shrink: 0; }
.section-label { font-size: 11px; font-weight: 700; letter-spacing: .8px; text-transform: uppercase; color: var(--df-muted); margin-bottom: 8px; }

/* ── OVERLAY ─────────────────────────────────────────────── */
.overlay { display: none; position: fixed; inset: 0; background: rgba(0,0,0,.4); z-index: 350; }
.overlay.open { display: block; }

/* ── MODAL ───────────────────────────────────────────────── */
.modal-overlay { display: none; position: fixed; inset: 0; background: rgba(0,0,0,.5); z-index: 500; align-items: center; justify-content: center; }
.modal-overlay.open { display: flex; }
.modal { background: var(--df-card); border-radius: 14px; width: 460px; overflow: hidden; box-shadow: 0 20px 60px rgba(0,0,0,.2); }
.modal-header { padding: 1.25rem 1.5rem; display: flex; align-items: center; gap: 12px; }
.df-header    { background: var(--df-navy); }
.df-header h3 { color: white; font-size: 16px; font-weight: 700; }
.df-header p  { color: rgba(255,255,255,.6); font-size: 12px; }
.modal-header-icon { width: 36px; height: 36px; background: rgba(29,158,117,.3); border-radius: 8px; display: flex; align-items: center; justify-content: center; color: #5DCAA5; font-size: 18px; }
.modal-close { margin-left: auto; background: none; border: none; color: rgba(255,255,255,.7); cursor: pointer; font-size: 20px; }
.modal-body  { padding: 1.5rem; }
.modal-footer{ padding: 1rem 1.5rem; background: var(--df-bg); display: flex; justify-content: flex-end; gap: 8px; }

/* ── SYNC MODAL ──────────────────────────────────────────── */
.sync-step { display: flex; align-items: center; gap: 12px; padding: 10px 0; border-bottom: .5px solid #f0f0f0; }
.sync-step:last-child { border-bottom: none; }
.sync-step-icon { width: 32px; height: 32px; border-radius: 50%; display: flex; align-items: center; justify-content: center; font-size: 14px; flex-shrink: 0; }
.sync-step-icon.done    { background: #E1F5EE; color: #0F6E56; }
.sync-step-icon.loading { background: #E6F1FB; color: var(--df-blue); animation: spin 1s linear infinite; }
.sync-step-icon.pending { background: var(--df-bg); color: var(--df-muted); }
@keyframes spin { to { transform: rotate(360deg); } }
.sync-step-text { font-size: 13px; font-weight: 500; color: var(--df-text); }
.sync-step-sub  { font-size: 11px; color: var(--df-muted); margin-top: 1px; }

/* ── ALERT ───────────────────────────────────────────────── */
.alert { padding: 10px 16px; border-radius: var(--radius); font-size: 13.5px; margin-bottom: 1rem; display: flex; align-items: center; justify-content: space-between; }
.alert-success { background: #E1F5EE; color: #0F6E56; border-left: 3px solid #0F6E56; }
.alert-error   { background: #FCEBEB; color: var(--df-red); border-left: 3px solid var(--df-red); }
.alert-warning { background: #FAEEDA; color: #854F0B; border-left: 3px solid #854F0B; }
.alert-close   { background: none; border: none; cursor: pointer; font-size: 18px; color: inherit; margin-left: 12px; }

/* ── PAGINACIÓN ──────────────────────────────────────────── */
.pagination { display: flex; gap: 4px; padding: 1rem 1.25rem; justify-content: flex-end; }
.page-link  { display: inline-flex; align-items: center; justify-content: center; width: 32px; height: 32px; border: 1px solid var(--df-border); border-radius: 6px; font-size: 13px; color: var(--df-text); }
.page-link:hover  { border-color: var(--df-blue); color: var(--df-blue); background: var(--df-hover); text-decoration: none; }
.page-link.active { background: var(--df-navy); color: white; border-color: var(--df-navy); }

/* ── TOAST ───────────────────────────────────────────────── */
.toast-container { position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%); z-index: 9999; display: flex; flex-direction: column; gap: 8px; }
.toast { background: var(--df-navy); color: white; padding: 12px 20px; border-radius: 10px; font-size: 13px; font-weight: 500; box-shadow: var(--shadow-md); min-width: 280px; }
.toast.success { background: #0F6E56; }
.toast.error   { background: var(--df-red); }
.toast.warning { background: var(--df-amber); color: #1a1200; }

/* ── DICTADO POR VOZ (botón de micrófono junto a textareas largas) ───────── */
.btn-dictado { position: absolute; right: 6px; bottom: 6px; width: 28px; height: 28px; border-radius: 50%; border: none;
  background: #0C2340; color: #fff; cursor: pointer; display: flex; align-items: center; justify-content: center; padding: 0; }
.btn-dictado.dictando { background: #dc2626; animation: dictando-pulso 1.1s infinite; }
@keyframes dictando-pulso { 0% { box-shadow: 0 0 0 0 rgba(220,38,38,.5); } 70% { box-shadow: 0 0 0 8px rgba(220,38,38,0); } 100% { box-shadow: 0 0 0 0 rgba(220,38,38,0); } }

/* ── UTILS ───────────────────────────────────────────────── */
.text-green  { color: #0F6E56; }
.text-red    { color: var(--df-red); }
.text-amber  { color: var(--df-amber); }
.text-blue   { color: var(--df-blue); }
.text-purple { color: #7c3aed; }
.text-teal   { color: var(--df-teal); }
.text-cyan   { color: #0891b2; }
.text-muted  { color: var(--df-muted); }
.text-center { text-align: center; }
.text-danger { color: var(--df-red); }
.fw-600  { font-weight: 600; }
.fw-bold { font-weight: 700; }
.small   { font-size: .8rem; }
.mt-1 { margin-top: .4rem; }
.mt-2 { margin-top: .75rem; }
.mt-3 { margin-top: 1rem; }
.mt-4 { margin-top: 1.5rem; }
.mb-0 { margin-bottom: 0; }
.d-flex      { display: flex; }
.align-center{ align-items: center; }
.gap-2 { gap: .5rem; }
.topnav-right { position: relative; }

/* ── CARD ────────────────────────────────────────────────── */
.card { background: var(--df-card); border: .5px solid var(--df-border); border-radius: var(--radius-lg); overflow: hidden; margin-bottom: 1rem; }
.card-header { padding: .75rem 1.25rem; border-bottom: 1px solid var(--df-border); display: flex; align-items: center; justify-content: space-between; gap: 1rem; background: var(--df-surface-2); }
.card-title  { font-size: .9rem; font-weight: 700; color: var(--df-emphasis); display: flex; align-items: center; gap: 8px; margin: 0; }
.card-body   { padding: 1.25rem; }
.card-footer { padding: .75rem 1.25rem; border-top: 1px solid var(--df-border); background: var(--df-surface-2); display: flex; gap: 8px; justify-content: flex-end; }

/* ── DATA TABLE ──────────────────────────────────────────── */
.data-table-wrapper { overflow-x: auto; background: var(--df-card); border: .5px solid var(--df-border); border-radius: var(--radius-lg); }
.data-table { width: 100%; border-collapse: collapse; font-size: .85rem; background: var(--df-card); }
.data-table thead th { padding: 9px 14px; text-align: left; font-size: 11px; font-weight: 700; color: var(--df-muted); text-transform: uppercase; letter-spacing: .4px; background: var(--df-surface-2); border-bottom: 1px solid var(--df-border); white-space: nowrap; }
.data-table tbody td { padding: 10px 14px; color: var(--df-text); background: var(--df-card); border-bottom: .5px solid var(--df-border-soft); vertical-align: middle; }
.data-table tbody tr:last-child td { border-bottom: none; }
.data-table tbody tr:hover td { background: var(--df-row-hover); }
.data-table .text-right { text-align: right; }
.data-table .text-muted  { color: var(--df-muted); }
.data-table-empty { text-align: center; color: var(--df-muted); padding: 2rem 14px !important; }

/* ── BADGE COLOURS ───────────────────────────────────────── */
.badge-blue   { background: #dbeafe; color: #1d4ed8; }
.badge-green  { background: #dcfce7; color: #15803d; }
.badge-red    { background: #fee2e2; color: #dc2626; }
.badge-gray   { background: #f1f5f9; color: #64748b; }
.badge-orange { background: #ffedd5; color: #c2410c; }
.badge-teal   { background: #ccfbf1; color: #0f766e; }
.badge-cyan   { background: #cffafe; color: #0e7490; }
.badge-purple { background: #ede9fe; color: #6d28d9; }
.badge-yellow { background: #fef9c3; color: #854d0e; }
.badge-indigo { background: #e0e7ff; color: #3730a3; }
.badge-dark   { background: #1e293b; color: white; }

/* ── FORM EXTRAS ─────────────────────────────────────────── */
.form-select   { display: block; width: 100%; padding: 9px 14px; border: 1.5px solid var(--df-border); border-radius: var(--radius); font-size: 14px; font-family: inherit; outline: none; transition: border-color .2s; background: var(--df-card); cursor: pointer; }
.form-select:focus { border-color: var(--df-blue); }
.form-textarea { display: block; width: 100%; padding: 9px 14px; border: 1.5px solid var(--df-border); border-radius: var(--radius); font-size: 14px; font-family: inherit; outline: none; transition: border-color .2s; background: var(--df-card); resize: vertical; }
.form-textarea:focus { border-color: var(--df-blue); }
.form-row     { display: grid; grid-template-columns: 1fr 1fr; gap: 1rem; }
.form-row-3   { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 1rem; }
.form-actions { display: flex; gap: .5rem; padding-top: .5rem; }

/* ── BUTTON EXTRAS ───────────────────────────────────────── */
.btn-xs      { padding: 3px 8px; font-size: 11px; }
.btn-warning { background: #854d0e; color: white; }
.btn-warning:hover { background: #5a3509; }

/* ── TABS ────────────────────────────────────────────────── */
.tab-list    { display: flex; gap: 4px; border-bottom: 1px solid var(--df-border); margin-bottom: 1.25rem; }
.tab-trigger { padding: 8px 18px; font-size: 13.5px; font-weight: 500; color: var(--df-muted); cursor: pointer; border: none; background: none; border-bottom: 2px solid transparent; margin-bottom: -1px; font-family: inherit; transition: all .15s; border-radius: var(--radius) var(--radius) 0 0; }
.tab-trigger:hover { color: var(--df-blue); background: var(--df-hover); }
.tab-trigger.active { color: var(--df-emphasis); font-weight: 600; border-bottom-color: var(--df-blue); }
.tab-content { display: none; }
.tab-content.active { display: block; }

/* ── TIMELINE ────────────────────────────────────────────── */
.timeline { padding-left: .5rem; }
.timeline-item { display: flex; gap: 12px; padding-bottom: 1.25rem; position: relative; }
.timeline-item:not(:last-child)::before { content: ''; position: absolute; left: 14px; top: 28px; bottom: 0; width: 1px; background: var(--df-border); }
.timeline-dot  { width: 28px; height: 28px; border-radius: 50%; display: flex; align-items: center; justify-content: center; flex-shrink: 0; font-size: 12px; }
.timeline-dot-green  { background: #dcfce7; color: #15803d; }
.timeline-dot-blue   { background: #dbeafe; color: #1d4ed8; }
.timeline-dot-gray   { background: #f1f5f9; color: #64748b; }
.timeline-dot-orange { background: #ffedd5; color: #c2410c; }
.timeline-dot-red    { background: #fee2e2; color: #dc2626; }
.timeline-body  { flex: 1; min-width: 0; }
.timeline-title { font-size: 13px; font-weight: 600; color: var(--df-text); }
.timeline-sub   { font-size: 11.5px; color: var(--df-muted); margin-top: 2px; }
.timeline-meta  { font-size: 11px; color: var(--df-muted); margin-top: 3px; }

/* ── INFO GRID (key/value pairs) ─────────────────────────── */
.info-grid { display: grid; grid-template-columns: auto 1fr; gap: .35rem 1rem; font-size: 13px; }
.info-label{ color: var(--df-muted); font-size: 12px; white-space: nowrap; }
.info-value{ color: var(--df-text); font-weight: 500; }

/* ── TOM SELECT OVERRIDES ────────────────────────────────── */
/* Tom Select CSS loads before app.css, pero su propio tema trae reglas más
   específicas como ".full .ts-control{background-color:#fff}" (el wrapper
   siempre lleva la clase "full") que ganan por especificidad aunque carguen
   antes — el orden de carga no alcanza para tapar eso. Por eso el selector
   de abajo repite ".ts-wrapper.full .ts-control" con la misma especificidad
   que esa regla de la librería, y como carga después, ahí sí gana. */
.ts-wrapper.form-select { padding: 0; border: none; height: auto; min-height: 0; }
.ts-control,
.ts-wrapper.full .ts-control {
  border: 1.5px solid var(--df-border);
  border-radius: var(--radius);
  padding: 0 10px;
  min-height: 40px;
  background: var(--df-card);
  box-shadow: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 4px;
  font-family: 'Inter', system-ui, sans-serif;
}
.ts-wrapper.focus .ts-control,
.ts-wrapper:focus-within .ts-control { border-color: var(--df-blue); box-shadow: 0 0 0 3px rgba(24,95,165,.12); }
.ts-control input,
.ts-control input:focus {
  font-size: 14px;
  font-family: 'Inter', system-ui, sans-serif;
  color: var(--df-text);
  outline: none;
  min-height: 38px;
  caret-color: var(--df-blue);
}
.ts-wrapper.single .ts-control .item {
  font-size: 14px;
  color: var(--df-text);
  padding: 0 4px 0 0;
  line-height: 1;
}
.ts-wrapper.multi .ts-control .item {
  background: var(--df-hover-2);
  color: var(--df-emphasis);
  border-radius: 4px;
  padding: 2px 6px 2px 8px;
  font-size: 12px;
  font-weight: 600;
  display: flex;
  align-items: center;
  gap: 4px;
}
.ts-wrapper.multi .ts-control .item .remove {
  color: var(--df-blue);
  opacity: .7;
  font-weight: 700;
}
.ts-dropdown {
  font-family: 'Inter', system-ui, sans-serif;
  background: var(--df-card);
  border: 1px solid var(--df-border);
  border-radius: var(--radius);
  box-shadow: 0 8px 24px rgba(0,0,0,.1);
  margin-top: 4px;
  z-index: 600;
}
.ts-dropdown-content { max-height: 260px; }
.ts-dropdown .option {
  padding: 9px 14px;
  font-size: 13.5px;
  color: var(--df-text);
  cursor: pointer;
}
.ts-dropdown .option:hover,
.ts-dropdown .option.active { background: var(--df-hover-2); color: var(--df-emphasis); }
.ts-dropdown .option.selected { background: var(--df-navy); color: white; }
.ts-dropdown .no-results { padding: 9px 14px; font-size: 13px; color: var(--df-muted); text-align: center; }
/* ── Buscador predictivo genérico (initBuscadorPredictivo en app.js) ── */
.bp-results {
  background: var(--df-card);
  border: 1px solid var(--df-border);
  border-radius: var(--radius);
  box-shadow: 0 4px 12px rgba(0,0,0,.06);
  margin-top: 6px;
  max-height: 260px;
  overflow-y: auto;
}
.bp-item {
  padding: 9px 14px;
  font-size: 13.5px;
  color: var(--df-text);
  cursor: pointer;
  border-bottom: 1px solid #f5f5f5;
}
.bp-item:last-child { border-bottom: none; }
.bp-item:hover { background: var(--df-hover-2); color: var(--df-emphasis); }
.bp-item small { color: var(--df-muted); margin-left: 6px; }
.bp-empty { padding: 9px 14px; font-size: 13px; color: var(--df-muted); text-align: center; }

/* ── HAMBURGER (oculto en desktop) ───────────────────────── */
.topnav-hamburger {
  display: none;
  align-items: center; justify-content: center;
  width: 36px; height: 36px; border-radius: var(--radius);
  background: none; border: none; color: white;
  cursor: pointer; font-size: 20px; flex-shrink: 0;
  transition: background .15s;
}
.topnav-hamburger:hover { background: rgba(255,255,255,.1); }

/* ── SIDEBAR OVERLAY (solo mobile) ──────────────────────── */
.sidebar-overlay {
  display: none;
  position: fixed; inset: 0;
  background: rgba(0,0,0,.45);
  z-index: 250;
}

/* ── RESPONSIVE ──────────────────────────────────────────── */
@media (max-width: 768px) {

  /* Topnav */
  .topnav { padding: 0 .75rem; gap: .5rem; }
  .topnav-hamburger { display: flex; }
  .brand-text { display: none; }
  .topnav-sync { display: none; }
  .user-info { display: none; }
  .topnav-brand { border-right: none; padding-right: 0; }

  /* Sidebar: oculto por defecto, desliza desde la izquierda */
  .sidebar {
    transform: translateX(-100%);
    transition: transform .25s ease;
    z-index: 300;
    box-shadow: none;
  }
  .sidebar-open .sidebar {
    transform: translateX(0);
    box-shadow: 4px 0 24px rgba(0,0,0,.15);
  }
  .sidebar-open .sidebar-overlay { display: block; }

  /* Contenido principal: ancho completo */
  .main-content {
    margin-left: 0;
    padding: 1rem;
  }

  /* Page header: apilado vertical */
  .page-header {
    flex-direction: column;
    align-items: flex-start;
    gap: .75rem;
    margin-bottom: 1.25rem;
  }
  .page-actions { flex-wrap: wrap; }
  .page-title { font-size: 18px; }

  /* Grids de formulario: una columna */
  .form-row,
  .form-row-3 { grid-template-columns: 1fr; }

  /* Filtros: apilados */
  .filters-bar { flex-direction: column; align-items: stretch; }
  .filter-input { width: 100%; }
  .filter-select { width: 100%; }

  /* Métricas: 2 columnas */
  .metrics-grid { grid-template-columns: repeat(2, 1fr); gap: 10px; }
  .metric-value { font-size: 22px; }

  /* Tabs: scroll horizontal */
  .tab-list {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    flex-wrap: nowrap;
    gap: 0;
    padding-bottom: 0;
  }
  .tab-trigger { white-space: nowrap; padding: 8px 14px; flex-shrink: 0; }

  /* Side panel: pantalla completa */
  .side-panel { width: 100%; right: -100%; }

  /* Modal: pantalla completa con margen */
  .modal { width: calc(100% - 1.5rem); max-height: 90vh; overflow-y: auto; }
  .modal-overlay { align-items: flex-end; padding-bottom: 0; }

  /* Tables: scroll horizontal (ya tienen .table-responsive) */
  .data-table-wrapper { overflow-x: auto; -webkit-overflow-scrolling: touch; }
  .data-table thead th,
  .data-table tbody td { white-space: nowrap; }

  /* Cards */
  .card-header { flex-wrap: wrap; gap: .5rem; }
  .table-card-header { flex-wrap: wrap; gap: .5rem; }
  .table-actions { flex-wrap: wrap; }

  /* Info grid */
  .info-grid { grid-template-columns: auto 1fr; gap: .25rem .75rem; }

  /* Toast: centrado en la parte baja */
  .toast-container { left: 1rem; right: 1rem; transform: none; }
  .toast { min-width: 0; }
}

.link-primary { color: var(--df-blue); text-decoration: none; font-weight: 700; }
.link-primary:hover { text-decoration: underline; }

/* ── Tablet intermedio ────────────────────────────────────── */
@media (max-width: 1024px) and (min-width: 769px) {
  :root { --sidebar-w: 200px; }
  .main-content { padding: 1.5rem; }
  .metrics-grid { grid-template-columns: repeat(3, 1fr); }
}
