:root {
  --primary: #1e40af;
  --primary-light: #3b82f6;
  --surface: #ffffff;
  --bg: #f1f5f9;
  --border: #e2e8f0;
  --text: #1e293b;
  --text-muted: #64748b;
  --positive: #059669;
  --positive-bg: #ecfdf5;
  --negative: #dc2626;
  --negative-bg: #fef2f2;
  --warning: #d97706;
  --warning-bg: #fffbeb;
  --warning-border: #fbbf24;
  --radius: 10px;
  --shadow: 0 1px 4px rgba(0,0,0,0.08);
}

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

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
}

/* NAVBAR */
.navbar {
  display: flex;
  align-items: center;
  gap: 16px;
  background: var(--primary);
  color: white;
  padding: 0 24px;
  height: 56px;
  position: sticky;
  top: 0;
  z-index: 100;
  box-shadow: 0 2px 8px rgba(0,0,0,0.15);
}

.navbar-brand {
  display: flex;
  align-items: center;
  gap: 8px;
  font-weight: 700;
  font-size: 16px;
  white-space: nowrap;
  margin-right: 8px;
}

.navbar-tabs {
  display: flex;
  gap: 4px;
  flex: 1;
}

.tab-btn {
  background: none;
  border: none;
  color: rgba(255,255,255,0.75);
  padding: 6px 16px;
  border-radius: 6px;
  cursor: pointer;
  font-size: 14px;
  font-weight: 500;
  transition: background 0.15s, color 0.15s;
}

.tab-btn:hover { background: rgba(255,255,255,0.12); color: white; }
.tab-btn.active { background: rgba(255,255,255,0.2); color: white; }

.empresa-select {
  background: rgba(255,255,255,0.15);
  border: 1px solid rgba(255,255,255,0.3);
  color: white;
  padding: 5px 10px;
  border-radius: 6px;
  font-size: 13px;
  cursor: pointer;
  min-width: 200px;
}

.empresa-select option { background: var(--primary); color: white; }

/* MAIN */
.main-content { padding: 24px; max-width: 1400px; margin: 0 auto; }

.tab-content { display: none; }
.tab-content.active { display: block; }

/* KPIs */
.kpi-row {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 16px;
  margin-bottom: 24px;
}

.kpi-card {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 20px;
  box-shadow: var(--shadow);
  border-left: 4px solid var(--primary-light);
}

.kpi-card.positive { border-left-color: var(--positive); }
.kpi-card.negative { border-left-color: var(--negative); }
.kpi-card.neutral  { border-left-color: #94a3b8; }
.kpi-card.warning  { border-left-color: var(--warning); background: var(--warning-bg); }

.kpi-label { font-size: 12px; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.05em; margin-bottom: 8px; }
.kpi-value { font-size: 22px; font-weight: 700; }
.kpi-sub   { font-size: 12px; color: var(--text-muted); margin-top: 4px; }

/* CARDS */
.card {
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
}

.card.mt { margin-top: 20px; }

.card-header {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 14px 20px;
  font-weight: 600;
  font-size: 14px;
  border-bottom: 1px solid var(--border);
  background: #f8fafc;
}

.card-header--warning {
  background: var(--warning-bg);
  border-bottom-color: var(--warning-border);
  color: #92400e;
}

.badge--warning {
  background: var(--warning);
}

.dias-vencido {
  display: inline-block;
  padding: 1px 7px;
  border-radius: 10px;
  font-size: 11px;
  font-weight: 700;
}
.dias-vencido.leve  { background: #fef9c3; color: #854d0e; }
.dias-vencido.medio { background: #fed7aa; color: #9a3412; }
.dias-vencido.grave { background: #fee2e2; color: #991b1b; }

.card-header-actions {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: 12px;
}

/* LAYOUT */
.row-two-col {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 20px;
}

@media (max-width: 900px) {
  .row-two-col { grid-template-columns: 1fr; }
}

.mt { margin-top: 20px; }

/* CHARTS */
.chart-wrap    { padding: 20px; height: 260px; }
.chart-wrap-sm { padding: 16px; height: 300px; }
.chart-wrap-lg { padding: 20px; height: 320px; }

/* TABLES */
.table-wrap {
  overflow: auto;
  max-height: 420px;
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}

thead th {
  background: #f8fafc;
  padding: 10px 12px;
  text-align: left;
  font-weight: 600;
  color: var(--text-muted);
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 1;
}

tbody tr { border-bottom: 1px solid var(--border); transition: background 0.1s; }
tbody tr:hover { background: #f8fafc; }
tbody td { padding: 10px 12px; }
tbody tr:last-child { border-bottom: none; }

.amount-positive { color: var(--positive); font-weight: 600; }
.amount-negative { color: var(--negative); font-weight: 600; }
.amount-neutral  { font-weight: 600; }

.badge {
  background: var(--primary-light);
  color: white;
  padding: 2px 8px;
  border-radius: 12px;
  font-size: 11px;
  font-weight: 600;
}

/* FILTER BAR */
.filter-bar {
  display: flex;
  align-items: center;
  gap: 16px;
  margin-bottom: 20px;
  background: var(--surface);
  padding: 12px 20px;
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.filter-bar label { font-size: 13px; color: var(--text-muted); display: flex; align-items: center; gap: 6px; }
.filter-bar select { padding: 4px 8px; border: 1px solid var(--border); border-radius: 6px; font-size: 13px; }

.btn-primary {
  background: var(--primary);
  color: white;
  border: none;
  padding: 7px 16px;
  border-radius: 6px;
  cursor: pointer;
  font-size: 13px;
  font-weight: 500;
}

.btn-primary:hover { background: var(--primary-light); }

.btn-link {
  background: none;
  border: none;
  color: var(--primary-light);
  cursor: pointer;
  font-size: 12px;
  text-decoration: underline;
}

.btn-close {
  background: none;
  border: none;
  cursor: pointer;
  font-size: 16px;
  color: var(--text-muted);
  padding: 2px 6px;
}

.btn-secondary {
  background: #f1f5f9;
  color: var(--text);
  border: 1px solid var(--border);
  padding: 7px 16px;
  border-radius: 6px;
  cursor: pointer;
  font-size: 13px;
  font-weight: 500;
}

.btn-secondary:hover { background: var(--border); }

.btn-danger {
  background: none;
  color: var(--negative);
  border: none;
  cursor: pointer;
  font-size: 12px;
  text-decoration: underline;
  padding: 0 4px;
}

.btn-admin {
  display: flex;
  align-items: center;
  gap: 6px;
  background: rgba(255,255,255,0.15);
  border: 1px solid rgba(255,255,255,0.3);
  color: white;
  padding: 5px 12px;
  border-radius: 6px;
  cursor: pointer;
  font-size: 13px;
  font-weight: 500;
}

.btn-admin:hover { background: rgba(255,255,255,0.25); }

/* USER INFO NAVBAR */
.navbar-right { display: flex; align-items: center; gap: 10px; }

.user-info {
  display: flex;
  align-items: center;
  gap: 8px;
  background: rgba(255,255,255,0.1);
  border-radius: 8px;
  padding: 4px 10px;
  color: rgba(255,255,255,0.9);
  font-size: 13px;
}

.btn-logout {
  background: none;
  border: none;
  cursor: pointer;
  color: rgba(255,255,255,0.75);
  display: flex;
  align-items: center;
  padding: 2px;
}

.btn-logout:hover { color: white; }

/* MODALS */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.45);
  z-index: 200;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}

.modal {
  background: white;
  border-radius: var(--radius);
  box-shadow: 0 20px 60px rgba(0,0,0,0.3);
  width: 100%;
  max-width: 680px;
  max-height: 90vh;
  display: flex;
  flex-direction: column;
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 20px;
  font-weight: 600;
  font-size: 15px;
  border-bottom: 1px solid var(--border);
  background: #f8fafc;
  border-radius: var(--radius) var(--radius) 0 0;
}

.modal-body { padding: 20px; overflow-y: auto; }

/* FORMS */
.form-group { margin-bottom: 16px; }
.form-group label { display: block; font-size: 13px; font-weight: 500; color: #374151; margin-bottom: 6px; }
.form-group input[type="text"],
.form-group input[type="password"],
.form-group select {
  width: 100%;
  padding: 8px 12px;
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 13px;
  outline: none;
}
.form-group input:focus,
.form-group select:focus {
  border-color: var(--primary-light);
  box-shadow: 0 0 0 3px rgba(59,130,246,0.12);
}

.checkbox-list {
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 8px 12px;
  max-height: 160px;
  overflow-y: auto;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px;
}

.checkbox-list label {
  display: flex;
  align-items: center;
  gap: 6px;
  font-weight: normal;
  margin: 0;
  cursor: pointer;
  font-size: 13px;
}

.role-badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 12px;
  font-size: 11px;
  font-weight: 600;
}
.role-badge.admin { background: #dbeafe; color: #1e40af; }
.role-badge.user  { background: #f0fdf4; color: #15803d; }

/* LOADING / ERROR */
.loading-overlay {
  position: fixed;
  inset: 0;
  background: rgba(255,255,255,0.7);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 999;
  font-size: 16px;
  color: var(--primary);
  gap: 12px;
}

.spinner {
  width: 24px;
  height: 24px;
  border: 3px solid var(--border);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

@keyframes spin { to { transform: rotate(360deg); } }

.error-banner {
  background: var(--negative-bg);
  border: 1px solid #fca5a5;
  color: var(--negative);
  padding: 12px 20px;
  border-radius: var(--radius);
  margin-bottom: 16px;
  font-size: 13px;
}

.text-muted { color: var(--text-muted); }
.text-center { text-align: center; }

/* MONTHLY TREASURY FORECAST */
.forecast-model-toolbar { flex-wrap: wrap; }
.forecast-model-toolbar strong { margin-right: 8px; }
.forecast-model-toolbar input[type="month"] {
  padding: 4px 8px; border: 1px solid var(--border); border-radius: 6px; font-size: 13px;
}
.forecast-company { margin-left: auto; color: var(--primary); font-weight: 700; }
.export-selection { padding: 9px 10px; border: 1px solid var(--border); border-radius: 6px; background: #f8fafc; font-weight: 600; }
.empty-model { padding: 34px 20px; text-align: center; color: var(--text-muted); }
.forecast-grid-wrap { max-height: 620px; }
.forecast-grid { min-width: 760px; }
.forecast-grid th:not(:first-child), .forecast-grid td:not(:first-child) { text-align: right; white-space: nowrap; }
.forecast-grid .forecast-concept-col { min-width: 210px; text-align: left; }
.forecast-grid .forecast-origin-col { min-width: 110px; text-align: left; }
.forecast-grid td.forecast-origin { text-align: left; color: var(--text-muted); font-size: 11px; }
.forecast-section td {
  background: #e2e8f0; color: #334155; font-weight: 700; text-transform: uppercase;
  letter-spacing: .04em; font-size: 11px; padding-top: 8px; padding-bottom: 8px;
}
.forecast-specific td:first-child { background: #dcfce7; color: #166534; }
.specific-dot { display: inline-block; width: 7px; height: 7px; margin-left: 7px; border-radius: 50%; background: #22c55e; }
.forecast-subtotal td { background: #f8fafc; border-top: 2px solid var(--border); font-weight: 700; }
.forecast-balance-row td { background: #eff6ff; font-weight: 700; }
.forecast-accumulated td { background: #dbeafe; color: #1e3a8a; font-weight: 800; }
.forecast-final td { background: #1e40af; color: white; font-weight: 800; }
.forecast-final .amount-positive, .forecast-final .amount-negative, .forecast-final .amount-neutral { color: white; }
.section-caption { margin: 28px 0 10px; color: var(--text-muted); font-size: 12px; font-weight: 700; text-transform: uppercase; letter-spacing: .06em; }

.modal-wide { max-width: 1040px; }
.config-forecast-layout { display: grid; grid-template-columns: 360px 1fr; gap: 20px; }
.forecast-form-panel { border-right: 1px solid var(--border); padding-right: 20px; }
.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.form-row .form-group input, .form-row .form-group select,
.forecast-form-panel input[type="text"], .forecast-form-panel input[type="number"],
.forecast-form-panel select, .manual-entry-form input, .manual-entry-form select {
  width: 100%; padding: 8px 10px; border: 1px solid var(--border); border-radius: 6px;
}
.compact-row { align-items: center; margin-bottom: 16px; }
.compact-row label { font-size: 13px; display: flex; align-items: center; gap: 7px; }
.compact-row input[type="number"] { width: 80px; }
.modal-actions { display: flex; justify-content: flex-end; gap: 8px; }
.account-finder { display: flex; gap: 6px; margin-top: 8px; }
.account-finder input { flex: 1; }
.account-results { max-height: 130px; overflow-y: auto; border: 1px solid var(--border); border-radius: 6px; margin-top: 6px; }
.account-results:empty { display: none; }
.account-results button { display: block; width: 100%; border: 0; border-bottom: 1px solid var(--border); background: white; padding: 6px 8px; text-align: left; font-size: 12px; cursor: pointer; }
.account-results button:hover { background: #eff6ff; }
.concept-list-wrap { max-height: 590px; border: 1px solid var(--border); border-radius: 6px; }
.manual-entry-form { display: grid; grid-template-columns: 1.4fr 1fr 1fr 1fr 1fr 1fr; gap: 10px; align-items: end; }
.manual-entry-form .form-group { margin-bottom: 0; }
.manual-entry-form .manual-note { grid-column: span 4; }
.manual-list-wrap { margin-top: 20px; max-height: 360px; border: 1px solid var(--border); border-radius: 6px; }

@media (max-width: 800px) {
  .config-forecast-layout { grid-template-columns: 1fr; }
  .forecast-form-panel { border-right: 0; border-bottom: 1px solid var(--border); padding: 0 0 20px; }
  .manual-entry-form { grid-template-columns: 1fr 1fr; }
  .manual-entry-form .manual-note { grid-column: span 2; }
}
