* { box-sizing: border-box; }

:root {
  --primary: #0b5394;
  --primary-light: #1c7ed6;
  --primary-50: #eff6ff;
  --primary-100: #dbeafe;
  --warn: #f59f00;
  --warn-dark: #b85c00;
  --warn-50: #fff7ed;
  --danger: #dc2626;
  --danger-50: #fef2f2;
  --ok: #10b981;
  --ok-50: #dcfce7;
  --ok-dark: #166534;
  --bg: #f6f8fb;
  --surface: #ffffff;
  --text: #0f172a;
  --text-2: #334155;
  --muted: #64748b;
  --border: #e2e8f0;
  --border-strong: #cbd5e1;
  --radius: 10px;
  --radius-sm: 6px;
  --shadow-sm: 0 1px 2px rgba(15,23,42,.04);
  --shadow-md: 0 4px 12px rgba(15,23,42,.06), 0 1px 3px rgba(15,23,42,.04);
  --shadow-lg: 0 10px 24px rgba(15,23,42,.08), 0 2px 6px rgba(15,23,42,.06);
}

body {
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  margin: 0;
  background: var(--bg);
  background-image:
    radial-gradient(at 0% 0%, rgba(28, 126, 214, 0.04) 0%, transparent 50%),
    radial-gradient(at 100% 0%, rgba(245, 159, 0, 0.03) 0%, transparent 50%);
  background-attachment: fixed;
  color: var(--text);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  font-feature-settings: 'cv02', 'cv03', 'cv04', 'cv11';
}

a { color: var(--primary); }

.wrap { max-width: 1400px; margin: 0 auto; padding: 0 24px; }

/* ============ Navbar ============ */
.navbar {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 50;
  backdrop-filter: saturate(1.2) blur(6px);
}
.navbar .wrap {
  display: flex;
  align-items: center;
  gap: 28px;
  padding: 12px 24px;
  min-height: 60px;
}
.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  text-decoration: none;
  color: var(--primary);
  flex-shrink: 0;
}
.brand-mark {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  background: linear-gradient(135deg, var(--primary), var(--primary-light));
  color: #fff;
  font-weight: 700;
  border-radius: 8px;
  font-size: 13px;
  letter-spacing: .5px;
  box-shadow: var(--shadow-md);
}
.brand-title { font-weight: 700; font-size: 15px; line-height: 1.1; }
.brand-sub { font-size: 11px; color: var(--muted); line-height: 1.1; display: block; margin-top: 2px; }

.navbar nav {
  display: flex;
  gap: 2px;
  flex: 1;
  align-items: center;
}
.navbar nav a {
  color: var(--text-2);
  text-decoration: none;
  font-size: 14px;
  padding: 8px 14px;
  border-radius: var(--radius-sm);
  font-weight: 500;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  transition: background .12s, color .12s;
  white-space: nowrap;
}
.navbar nav > a:hover,
.nav-drop > a:hover { background: #f1f5f9; color: var(--text); }
.navbar nav > a.active,
.nav-drop > a.active { background: var(--primary-50); color: var(--primary); }

.user {
  font-size: 13px;
  color: var(--text-2);
  display: flex;
  align-items: center;
  gap: 12px;
  flex-shrink: 0;
}
.user .logout {
  color: var(--muted);
  font-size: 11px;
  text-decoration: none;
  padding: 4px 8px;
  border-radius: 4px;
  border: 1px solid var(--border);
}
.user .logout:hover { color: var(--danger); border-color: var(--danger); }

/* Nav dropdown */
[x-cloak] { display: none !important; }
.nav-drop { position: relative; }
.nav-drop > a .caret {
  font-size: 9px;
  color: var(--muted);
  margin-left: 4px;
  transition: transform .15s;
}
.nav-drop:hover > a .caret { transform: rotate(180deg); color: var(--text-2); }
.nav-drop-menu {
  position: absolute;
  top: calc(100% + 6px);
  left: 0;
  background: var(--surface);
  min-width: 220px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-lg);
  padding: 8px;
  z-index: 100;
}
.nav-drop-menu::before {
  content: '';
  position: absolute;
  top: -5px;
  left: 24px;
  width: 10px;
  height: 10px;
  background: var(--surface);
  border-top: 1px solid var(--border);
  border-left: 1px solid var(--border);
  transform: rotate(45deg);
}
.nav-drop-menu a {
  display: block;
  padding: 10px 14px;
  font-size: 14px;
  color: var(--text-2);
  text-decoration: none;
  border-radius: var(--radius-sm);
  font-weight: 500;
  transition: background .12s;
  position: relative;
}
.nav-drop-menu a:hover { background: #f1f5f9; color: var(--text); }
.nav-drop-menu a.active { background: var(--primary-50); color: var(--primary); }

/* ============ Main ============ */
main.wrap { padding-top: 28px; padding-bottom: 80px; }

/* ============ Hero ============ */
.hero {
  margin-bottom: 24px;
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 20px;
}
.hero-main { flex: 1; min-width: 0; }
.hero h1 {
  margin: 0 0 8px;
  font-size: 28px;
  font-weight: 700;
  color: var(--text);
  letter-spacing: -.02em;
  line-height: 1.15;
}
.hero h1 .hero-sub { color: var(--muted); font-weight: 500; font-size: 18px; }
.hero p.meta { margin: 0; color: var(--muted); font-size: 13px; }
.hero p.meta strong { color: var(--text); font-weight: 600; }
.hero-actions { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }

/* ============ KPIs ============ */
.kpis {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
  gap: 16px;
  margin-bottom: 24px;
}
.kpi {
  background: var(--surface);
  padding: 22px 24px;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  box-shadow: var(--shadow-sm);
  position: relative;
  overflow: hidden;
  transition: box-shadow .15s, transform .08s;
}
.kpi:hover { box-shadow: var(--shadow-md); }
.kpi::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  width: 4px;
  height: 100%;
  background: var(--primary);
}
.kpi.warn::before { background: var(--warn); }
.kpi.ok::before { background: var(--ok); }
.kpi .label {
  font-size: 11px;
  text-transform: uppercase;
  color: var(--muted);
  letter-spacing: .6px;
  font-weight: 600;
}
.kpi .value {
  font-size: 30px;
  font-weight: 700;
  color: var(--text);
  margin-top: 10px;
  letter-spacing: -.02em;
  line-height: 1.05;
}
.kpi .value.small { font-size: 16px; font-weight: 500; color: var(--text-2); }
.kpi.warn .value { color: var(--warn-dark); }
.kpi .hint { font-size: 11px; color: var(--muted); margin-top: 8px; line-height: 1.4; }

/* ============ Cards ============ */
section.card {
  background: var(--surface);
  border-radius: var(--radius);
  border: 1px solid var(--border);
  box-shadow: var(--shadow-sm);
  padding: 24px 28px;
  margin-bottom: 20px;
}
section.card h2 {
  margin: 0 0 18px;
  color: var(--text);
  font-size: 16px;
  font-weight: 600;
  letter-spacing: -.01em;
}
section.card.alert { background: var(--danger-50); border-color: #fecaca; }
section.card.alert h2 { color: #7f1d1d; }

.grid-charts {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(380px, 1fr));
  gap: 18px;
  margin-bottom: 20px;
}
.grid-charts .card { margin-bottom: 0; padding: 22px 24px; }
.grid-charts .card h2 { font-size: 14px; margin-bottom: 16px; text-transform: uppercase; letter-spacing: .5px; color: var(--muted); font-weight: 600; }
.grid-charts canvas { max-height: 280px !important; }

/* Bottom grid: 2 columns for better breathing room */
.bottom-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(420px, 1fr));
  gap: 18px;
  margin-bottom: 20px;
}
.bottom-grid .card { margin-bottom: 0; padding: 22px 24px; }
.bottom-grid .card h2 { font-size: 14px; text-transform: uppercase; letter-spacing: .5px; color: var(--muted); font-weight: 600; }

/* Action card (sync) */
.actions-card { padding: 22px 28px; }
.actions-card h2 { margin-bottom: 16px; }
.action-buttons {
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
  align-items: center;
}
.action-buttons form { margin: 0; }
.hint-msg {
  font-size: 13px;
  color: var(--muted);
  font-style: italic;
}

/* ============ Filters ============ */
.filters {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  align-items: flex-end;
  margin-bottom: 18px;
  background: var(--surface);
  padding: 14px 16px;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  box-shadow: var(--shadow-sm);
}
.filters label {
  display: flex;
  flex-direction: column;
  font-size: 11px;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: .5px;
  gap: 4px;
  font-weight: 600;
}
.filters input, .filters select {
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 7px 10px;
  font-size: 13px;
  min-width: 150px;
  background: var(--surface);
  color: var(--text);
  font-family: inherit;
  transition: border-color .12s, box-shadow .12s;
}
.filters input:focus, .filters select:focus {
  outline: none;
  border-color: var(--primary-light);
  box-shadow: 0 0 0 3px var(--primary-100);
}

/* ============ Buttons ============ */
.filters button, .btn, a.btn {
  background: var(--primary);
  color: #fff;
  border: 1px solid var(--primary);
  padding: 9px 18px;
  border-radius: var(--radius-sm);
  font-size: 13px;
  cursor: pointer;
  font-weight: 600;
  font-family: inherit;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  transition: background .12s, border-color .12s, box-shadow .12s, transform .06s;
  box-shadow: var(--shadow-sm);
}
.filters button:hover, .btn:hover, a.btn:hover {
  background: var(--primary-light);
  border-color: var(--primary-light);
  color: #fff;
  box-shadow: var(--shadow-md);
}
.filters button:active, .btn:active { transform: translateY(1px); }
.filters button:disabled, .btn:disabled { opacity: .5; cursor: not-allowed; box-shadow: none; }
.btn.is-loading { opacity: .7; cursor: wait; pointer-events: none; }
.btn-link {
  color: var(--muted);
  font-size: 13px;
  text-decoration: none;
  padding: 9px 12px;
  font-weight: 500;
}
.btn-link:hover { color: var(--primary); text-decoration: underline; }
.btn-secondary {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 9px 16px;
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--primary);
  font-size: 13px;
  font-weight: 600;
  text-decoration: none;
  border: 1px solid var(--primary-100);
  transition: all .12s;
  box-shadow: var(--shadow-sm);
}
.btn-secondary:hover {
  background: var(--primary);
  color: #fff;
  border-color: var(--primary);
  box-shadow: var(--shadow-md);
}
.btn-ok, .btn.btn-ok {
  background: var(--ok);
  border-color: var(--ok);
  color: #fff;
}
.btn-ok:hover, .btn.btn-ok:hover {
  background: #059669;
  border-color: #059669;
}

/* ============ Tables ============ */
.table-wrap { overflow-x: auto; border-radius: var(--radius-sm); }
table.data { width: 100%; border-collapse: collapse; font-size: 13px; }
table.data th {
  background: #f8fafc;
  padding: 10px 12px;
  text-align: left;
  border-bottom: 1px solid var(--border-strong);
  font-weight: 600;
  color: var(--text-2);
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: .4px;
  white-space: nowrap;
}
table.data td {
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
  vertical-align: top;
}
table.data.compact td, table.data.compact th { padding: 7px 10px; font-size: 12px; }
table.data tbody tr:hover { background: #f8fafc; }
table.data tbody tr:last-child td { border-bottom: none; }
table.data .num { text-align: right; font-variant-numeric: tabular-nums; }
table.data .num.est { color: var(--warn-dark); font-weight: 600; }
table.data .small { font-size: 11px; color: var(--muted); }
table.data .nowrap { white-space: nowrap; }
table.data .mono { font-family: SFMono-Regular, Consolas, monospace; font-size: 11px; color: var(--text-2); }
table.data .empty { text-align: center; color: var(--muted); font-style: italic; padding: 28px; }
table.data a { color: var(--primary); text-decoration: none; font-weight: 500; }
table.data a:hover { text-decoration: underline; }

/* ============ Badges ============ */
.badges { display: flex; flex-wrap: wrap; gap: 8px; padding: 0; list-style: none; margin: 0; }
.badge {
  display: inline-flex;
  align-items: center;
  background: #e2e8f0;
  color: var(--text-2);
  padding: 3px 10px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 500;
  white-space: nowrap;
}
.badge-pagado, .badge-ok { background: var(--ok-50); color: var(--ok-dark); }
.badge-anulada, .badge-fallo { background: #fee2e2; color: #991b1b; }
.badge-pendiente { background: #fef3c7; color: #92400e; }

/* ============ Prestaciones list ============ */
.presta-list { list-style: none; padding: 0; margin: 0; }
.presta-list li { font-size: 11px; padding: 1px 0; color: var(--text-2); }
.presta-list .cod { font-family: monospace; background: #f1f5f9; padding: 1px 6px; border-radius: 3px; margin-right: 4px; color: var(--text); }
.presta-list .cant { color: var(--muted); font-size: 10px; }

/* ============ Footer ============ */
footer {
  border-top: 1px solid var(--border);
  padding: 18px 0;
  color: var(--muted);
  font-size: 12px;
  background: var(--surface);
  margin-top: 40px;
}
footer .wrap { display: flex; justify-content: space-between; flex-wrap: wrap; gap: 10px; }
footer a { color: var(--primary); text-decoration: none; }
footer a:hover { text-decoration: underline; }

.empty { text-align: center; color: var(--muted); font-style: italic; padding: 28px; }

@media (max-width: 900px) {
  .navbar .wrap { flex-wrap: wrap; gap: 12px; padding: 10px 16px; }
  .navbar nav { overflow-x: auto; width: 100%; order: 3; }
  .kpis { grid-template-columns: repeat(2, 1fr); }
  .hero { flex-direction: column; }
  .wrap { padding: 0 16px; }
  .filters { padding: 12px; }
  .filters input, .filters select { min-width: 120px; }
}
