:root {
  --bg: #f4f6f8;
  --surface: #ffffff;
  --border: #e0e4e9;
  --text: #1f2937;
  --text-muted: #6b7280;
  --primary: #2563eb;
  --primary-dark: #1d4ed8;
  --danger: #dc2626;
  --danger-dark: #b91c1c;
  --success: #16a34a;
  --radius: 8px;
  --shadow: 0 1px 3px rgba(0, 0, 0, 0.08), 0 1px 2px rgba(0, 0, 0, 0.06);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
}

a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }

/* Topbar */
.topbar {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 10;
}
.topbar-inner {
  max-width: 1200px;
  margin: 0 auto;
  padding: 0 24px;
  display: flex;
  align-items: center;
  gap: 32px;
  height: 56px;
}
.brand {
  font-weight: 700;
  font-size: 1.1rem;
  color: var(--text);
  text-decoration: none;
  letter-spacing: 0.5px;
}
.nav { display: flex; align-items: center; gap: 20px; height: 100%; }
.nav-user { margin-left: auto; }
.nav a, .nav-dropdown-btn {
  color: var(--text-muted);
  text-decoration: none;
  font-size: 0.92rem;
  font-weight: 500;
  padding: 8px 0;
  border-bottom: 2px solid transparent;
  background: none;
  border-top: none; border-left: none; border-right: none;
  cursor: pointer;
  font-family: inherit;
}
.nav a:hover, .nav-dropdown-btn:hover { color: var(--text); text-decoration: none; }
.nav a.active, .nav-dropdown-btn.active { color: var(--primary); border-bottom-color: var(--primary); }

.nav-dropdown { position: relative; height: 100%; display: flex; align-items: center; }

@media (max-width: 640px) {
  .topbar-inner { flex-wrap: wrap; height: auto; padding: 10px 16px; row-gap: 8px; }
  .nav { flex-wrap: wrap; height: auto; row-gap: 8px; }
  .nav-dropdown { height: auto; }
}
.nav-dropdown-menu {
  display: none;
  position: absolute;
  top: 100%;
  left: 0;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  min-width: 200px;
  padding: 6px;
  margin-top: 4px;
}
.nav-dropdown.open .nav-dropdown-menu { display: block; }
.nav-dropdown-menu a {
  display: block;
  padding: 8px 10px;
  border-radius: 6px;
  color: var(--text);
  font-weight: 400;
}
.nav-dropdown-menu a:hover { background: var(--bg); text-decoration: none; }
.nav-dropdown-menu-btn {
  display: block;
  width: 100%;
  text-align: left;
  padding: 8px 10px;
  border-radius: 6px;
  color: var(--text);
  font-weight: 400;
  font-size: 0.92rem;
  background: none;
  border: none;
  cursor: pointer;
  font-family: inherit;
}
.nav-dropdown-menu-btn:hover { background: var(--bg); }

/* Layout */
.container {
  max-width: 1200px;
  margin: 0 auto;
  padding: 28px 24px 64px;
}
.page-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 20px;
  flex-wrap: wrap;
  gap: 12px;
}
.page-header h1 { font-size: 1.4rem; margin: 0; }
.page-header p.subtitle { color: var(--text-muted); margin: 4px 0 0; font-size: 0.9rem; }

/* Card / surface */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 20px;
}

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 14px;
  border-radius: 6px;
  border: 1px solid transparent;
  background: var(--primary);
  color: #fff;
  font-size: 0.88rem;
  font-weight: 600;
  cursor: pointer;
  text-decoration: none;
}
.btn:hover { background: var(--primary-dark); text-decoration: none; }
.btn-secondary { background: var(--surface); color: var(--text); border-color: var(--border); }
.btn-secondary:hover { background: var(--bg); }
.btn-danger { background: var(--danger); }
.btn-danger:hover { background: var(--danger-dark); }
.btn-sm { padding: 4px 10px; font-size: 0.8rem; }
.btn:disabled { opacity: 0.55; cursor: not-allowed; }

/* Table */
table { width: 100%; border-collapse: collapse; }
thead th {
  text-align: left;
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-muted);
  border-bottom: 1px solid var(--border);
  padding: 10px 12px;
}
tbody td {
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
  font-size: 0.9rem;
  vertical-align: middle;
}
tbody tr:last-child td { border-bottom: none; }
tbody tr:hover { background: #fafbfc; }
.text-right { text-align: right; }
.text-center { text-align: center; }
.text-muted { color: var(--text-muted); }

/* Forms */
label { display: block; font-size: 0.82rem; font-weight: 600; margin-bottom: 4px; color: var(--text); }
input[type=text], input[type=date], input[type=number], input[type=password], input[type=email], select, textarea {
  width: 100%;
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 0.9rem;
  font-family: inherit;
  background: var(--surface);
  color: var(--text);
}
input:focus, select:focus, textarea:focus { outline: 2px solid #bfdbfe; border-color: var(--primary); }
.field { margin-bottom: 14px; }
.field-row { display: flex; gap: 16px; flex-wrap: wrap; }
.field-row .field { flex: 1; min-width: 200px; }

/* Badges */
.badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 0.72rem;
  font-weight: 600;
}
.badge-success { background: #dcfce7; color: #15803d; }
.badge-muted { background: #f1f5f9; color: #64748b; }

/* KPI grid */
.kpi-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 14px;
  margin-bottom: 24px;
}
.kpi-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px 18px;
  box-shadow: var(--shadow);
}
.kpi-card .kpi-label { font-size: 0.78rem; color: var(--text-muted); font-weight: 600; text-transform: uppercase; letter-spacing: 0.03em; }
.kpi-card .kpi-value { font-size: 1.7rem; font-weight: 700; margin-top: 4px; color: var(--text); }

/* Chart grid */
.chart-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(420px, 1fr));
  gap: 16px;
  margin-bottom: 16px;
}
.chart-card h3 { margin: 0 0 12px; font-size: 0.95rem; }
.chart-card canvas { max-height: 320px; }

/* Filters bar */
.filters-bar {
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
  align-items: flex-end;
  margin-bottom: 20px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 16px;
}
.filters-bar .field { margin-bottom: 0; min-width: 160px; }

/* Capture sheet */
.captura-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 20px;
}
@media (max-width: 900px) {
  .captura-grid { grid-template-columns: 1fr; }
}
.captura-grid table input[type=number] { width: 80px; text-align: right; }
.captura-grid h2 { font-size: 1rem; margin: 0 0 12px; }

.empty-state {
  text-align: center;
  padding: 40px 20px;
  color: var(--text-muted);
}

.toast {
  position: fixed;
  bottom: 20px;
  right: 20px;
  padding: 12px 18px;
  border-radius: 8px;
  background: var(--text);
  color: #fff;
  font-size: 0.88rem;
  box-shadow: var(--shadow);
  opacity: 0;
  transform: translateY(8px);
  transition: opacity 0.2s, transform 0.2s;
  pointer-events: none;
  z-index: 100;
}
.toast.show { opacity: 1; transform: translateY(0); }
.toast.error { background: var(--danger); }
.toast.success { background: var(--success); }

.actions-cell { display: flex; gap: 8px; }

/* Excel-like tabs + spreadsheet view */
.excel-tabs {
  display: flex;
  gap: 4px;
  overflow-x: auto;
  border-bottom: 1px solid var(--border);
  margin-bottom: 20px;
  padding-bottom: 0;
}
.excel-tab {
  flex-shrink: 0;
  padding: 8px 16px;
  border: 1px solid var(--border);
  border-bottom: none;
  border-radius: 6px 6px 0 0;
  background: var(--bg);
  color: var(--text-muted);
  font-size: 0.85rem;
  font-weight: 500;
  cursor: pointer;
  margin-bottom: -1px;
}
.excel-tab:hover { color: var(--text); }
.excel-tab.active {
  background: var(--surface);
  color: var(--primary);
  border-color: var(--border);
  border-bottom: 1px solid var(--surface);
  font-weight: 600;
}

.resumen-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 20px;
  align-items: start;
}
@media (max-width: 1100px) {
  .resumen-grid { grid-template-columns: 1fr; }
}

.excel-card { margin-bottom: 20px; overflow: hidden; }
.excel-card h2 { font-size: 0.95rem; margin: 0 0 12px; }
.excel-scroll { overflow-x: auto; }

.excel-table { border-collapse: collapse; white-space: nowrap; font-size: 0.82rem; }
.excel-table th, .excel-table td {
  border: 1px solid var(--border);
  padding: 6px 10px;
  text-align: right;
}
.excel-table th:first-child, .excel-table td:first-child {
  text-align: left;
  position: sticky;
  left: 0;
  background: var(--surface);
  font-weight: 500;
  z-index: 1;
  min-width: 220px;
}
.excel-table thead th {
  background: var(--bg);
  color: var(--text-muted);
  font-size: 0.72rem;
  text-transform: none;
  letter-spacing: 0;
  position: sticky;
  top: 0;
  z-index: 2;
}
.excel-table thead th:first-child { z-index: 3; }
.excel-table tbody tr:nth-child(even) td { background: #fafbfc; }
.excel-table tbody tr:nth-child(even) td:first-child { background: #f5f6f8; }
.excel-table td.cero { color: #c7ccd4; }
.excel-table td.total, .excel-table th.total {
  font-weight: 700;
  background: #eef2ff !important;
}
.excel-table tfoot td {
  font-weight: 700;
  background: #f1f5f9;
}
