:root {
  --bg: #f3f5f8;
  --surface: #ffffff;
  --surface-alt: #f8fafc;
  --border: #dde3ec;
  --text: #1e293b;
  --muted: #64748b;
  --primary: #1e5a9e;
  --primary-hover: #17467c;
  --accent: #0f766e;
  --danger: #dc2626;
  --radius: 10px;
  --shadow: 0 2px 10px rgba(15, 23, 42, 0.06);
}

* { box-sizing: border-box; }
body {
  margin: 0;
  font-family: 'Segoe UI', system-ui, -apple-system, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
}

.hidden { display: none !important; }

#app-shell {
  display: flex;
  min-height: 100vh;
}

.sidebar {
  width: 265px;
  background: #0f2744;
  color: #e2e8f0;
  display: flex;
  flex-direction: column;
  padding: 18px 14px;
  flex-shrink: 0;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 6px 8px 18px;
  border-bottom: 1px solid rgba(255,255,255,0.12);
  margin-bottom: 16px;
}

.brand-logo {
  width: 46px;
  height: auto;
  background: #fff;
  padding: 3px;
  border-radius: 6px;
}

.brand-title { font-weight: 700; font-size: 14px; color: #fff; line-height: 1.2; }
.brand-sub { font-size: 11px; color: #94a3b8; margin-top: 2px; }

.nav { display: flex; flex-direction: column; gap: 6px; flex: 1; }
.nav-btn {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 11px 12px;
  border: none;
  background: transparent;
  color: #cbd5e1;
  border-radius: 8px;
  cursor: pointer;
  text-align: left;
  font-size: 13.5px;
  font-weight: 500;
  transition: background 0.15s, color 0.15s;
}
.nav-btn:hover { background: rgba(255,255,255,0.08); color: #fff; }
.nav-btn.active { background: #1e5a9e; color: #fff; font-weight: 600; }

.sidebar-stats {
  border-top: 1px solid rgba(255,255,255,0.12);
  padding-top: 14px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.stat-pill {
  display: flex;
  justify-content: space-between;
  font-size: 12px;
  color: #cbd5e1;
  background: rgba(255,255,255,0.06);
  padding: 6px 10px;
  border-radius: 6px;
}

.main-area {
  flex: 1;
  padding: 24px 28px;
  overflow-x: hidden;
}

.view { display: none; }
.view.active { display: block; }

.view-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 16px;
  margin-bottom: 18px;
}
.view-header h1 { margin: 0; font-size: 22px; font-weight: 700; }
.subtitle { margin: 4px 0 0; color: var(--muted); font-size: 13px; }
.header-actions { display: flex; gap: 8px; flex-wrap: wrap; }

.filter-bar {
  display: flex;
  gap: 10px;
  margin-bottom: 14px;
  flex-wrap: wrap;
}
.flex-1 { flex: 1; min-width: 220px; }

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}
.form-card { padding: 20px; }
.form-card h3 { margin: 0 0 14px; font-size: 16px; }
.grid-2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(340px, 1fr)); gap: 18px; }

.input-ctrl {
  width: 100%;
  padding: 8px 11px;
  border: 1px solid var(--border);
  border-radius: 7px;
  font-size: 13.5px;
  color: var(--text);
  background: #fff;
  outline: none;
}
.input-ctrl:focus { border-color: var(--primary); box-shadow: 0 0 0 2px rgba(30,90,158,0.14); }
select.input-ctrl { width: auto; min-width: 150px; }
.input-sm-num { width: 130px; text-align: right; }

.btn {
  padding: 8px 14px;
  border: 1px solid transparent;
  border-radius: 7px;
  font-size: 13.5px;
  font-weight: 600;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  transition: background 0.15s;
}
.btn-sm { padding: 5px 10px; font-size: 12.5px; }
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-hover); }
.btn-secondary { background: #fff; color: var(--text); border-color: var(--border); }
.btn-secondary:hover { background: var(--surface-alt); }
.btn-accent { background: var(--accent); color: #fff; }
.btn-accent:hover { background: #0d5e58; }
.btn-danger { background: var(--danger); color: #fff; }

.icon-btn {
  border: none;
  background: transparent;
  font-size: 18px;
  cursor: pointer;
  color: var(--muted);
  padding: 4px 8px;
  border-radius: 6px;
}
.icon-btn:hover { background: var(--surface-alt); color: var(--text); }

.table-wrap { overflow-x: auto; }
.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}
.data-table th, .data-table td {
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
  text-align: left;
  vertical-align: middle;
}
.data-table th {
  background: var(--surface-alt);
  font-weight: 600;
  color: var(--muted);
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.03em;
}
.data-table tbody tr:hover { background: #f8fbff; }
.data-table th.sortable {
  cursor: pointer;
  user-select: none;
  white-space: nowrap;
}
.data-table th.sortable:hover { background: #eef2f7; color: var(--primary); }
.data-table th.sortable.sort-asc::after { content: " ▲"; font-size: 10px; color: var(--primary); }
.data-table th.sortable.sort-desc::after { content: " ▼"; font-size: 10px; color: var(--primary); }
.group-header-row td {
  background: #eff6ff !important;
  color: #1e3a8a;
  font-weight: 700;
  font-size: 13px;
  padding: 8px 12px !important;
  border-top: 2px solid #bfdbfe;
  border-bottom: 1px solid #bfdbfe;
}
.group-header-meta {
  font-weight: 500;
  color: #475569;
  font-size: 12px;
  margin-left: 8px;
}

.pagination-bar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 10px;
  padding: 10px 14px;
  border-top: 1px solid var(--border);
  background: var(--surface-alt);
  font-size: 13px;
  color: var(--muted);
}
.pagination-controls {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
}
.pagination-controls select.input-ctrl {
  min-width: 74px;
  padding: 4px 8px;
  font-size: 12.5px;
}
.data-table th.num, .data-table td.num { text-align: right; font-variant-numeric: tabular-nums; }
.actions-col { width: 220px; text-align: right !important; }
.row-actions { display: flex; gap: 5px; justify-content: flex-end; }
.badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 11.5px;
  font-weight: 600;
  background: #e0ecfa;
  color: #1e5a9e;
}
.badge-90 { background: #dcfce7; color: #166534; }

/* Catalog tabs */
.catalog-tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-bottom: 14px;
}
.tab-btn {
  padding: 8px 13px;
  border: 1px solid var(--border);
  background: #fff;
  border-radius: 7px;
  cursor: pointer;
  font-size: 13px;
  font-weight: 500;
}
.tab-btn.active { background: var(--primary); color: #fff; border-color: var(--primary); }
.cat-panel { padding: 16px; }
.cat-toolbar { display: flex; gap: 10px; margin-bottom: 12px; }
.cat-add-box {
  background: var(--surface-alt);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 12px;
  margin-bottom: 12px;
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  align-items: center;
}

.simple-list { list-style: none; padding: 0; margin: 0; }
.simple-list li {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 9px 10px;
  border-bottom: 1px solid var(--border);
}

/* Modals */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.52);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 18px;
  z-index: 1000;
}
.modal {
  background: #fff;
  border-radius: 12px;
  box-shadow: 0 20px 50px rgba(0,0,0,0.22);
  display: flex;
  flex-direction: column;
  max-height: 92vh;
  width: 100%;
}
.modal-md { max-width: 680px; }
.modal-lg { max-width: 960px; }
.modal-xl { max-width: 1080px; }
.modal-preview { max-width: 960px; background: #e2e8f0; }

.modal-header {
  padding: 14px 20px;
  border-bottom: 1px solid var(--border);
  background: #fff;
  border-radius: 12px 12px 0 0;
  display: flex;
  justify-content: space-between;
  align-items: center;
}
.modal-header h2 { margin: 0; font-size: 17px; }
.modal-body { padding: 18px 20px; overflow-y: auto; flex: 1; }
.modal-footer {
  padding: 12px 20px;
  border-top: 1px solid var(--border);
  background: var(--surface-alt);
  border-radius: 0 0 12px 12px;
  display: flex;
  justify-content: flex-end;
  gap: 8px;
}

.form-group { display: flex; flex-direction: column; gap: 4px; margin-bottom: 10px; }
.form-group label { font-size: 12px; font-weight: 600; color: #334155; }
.form-row { display: flex; gap: 10px; }
.form-grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.form-grid-3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 12px; }
.form-grid-4 { display: grid; grid-template-columns: repeat(4, 1fr); gap: 12px; }
.input-with-btn { display: flex; gap: 6px; }

/* Smart Combobox */
.smart-combo { position: relative; width: 100%; }
.smart-combo-input-wrap { position: relative; display: flex; align-items: center; }
.smart-combo-input { padding-right: 30px; }
.smart-combo-toggle {
  position: absolute;
  right: 4px;
  border: none;
  background: transparent;
  cursor: pointer;
  color: var(--muted);
  font-size: 12px;
  padding: 4px 6px;
}
.smart-combo-menu {
  position: absolute;
  top: calc(100% + 2px);
  left: 0;
  right: 0;
  background: #fff;
  border: 1px solid var(--primary);
  border-radius: 7px;
  box-shadow: 0 10px 25px rgba(15,23,42,0.16);
  max-height: 230px;
  overflow-y: auto;
  z-index: 1500;
}
.smart-combo-item {
  padding: 8px 10px;
  cursor: pointer;
  border-bottom: 1px solid #f1f5f9;
  font-size: 13px;
  line-height: 1.3;
}
.smart-combo-item:hover, .smart-combo-item.highlighted { background: #eff6ff; color: var(--primary); }
.smart-combo-group {
  padding: 5px 10px;
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--primary);
  background: #f1f5f9;
  border-bottom: 1px solid #e2e8f0;
}
.smart-combo-add {
  padding: 8px 10px;
  cursor: pointer;
  background: #ecfdf5;
  color: #065f46;
  font-weight: 600;
  font-size: 12.5px;
  border-top: 1px solid #a7f3d0;
}
.smart-combo-add:hover { background: #d1fae5; }

/* Items table */
.items-section {
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 12px;
  background: var(--surface-alt);
  margin-top: 8px;
}
.items-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 10px; }
.items-header h3 { margin: 0; font-size: 14.5px; }
.edit-items-table { width: 100%; border-collapse: collapse; }
.edit-items-table th {
  font-size: 12px;
  text-align: left;
  color: var(--muted);
  padding: 4px 6px 8px;
}
.edit-items-table td { padding: 4px 4px; vertical-align: top; }
.items-total-bar {
  display: flex;
  justify-content: flex-end;
  gap: 12px;
  align-items: center;
  padding-top: 10px;
  margin-top: 8px;
  border-top: 1px solid var(--border);
  font-size: 15px;
}

.liq-totals-grid {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 6px;
  margin-top: 10px;
  padding-top: 10px;
  border-top: 1px solid var(--border);
}
.liq-total-row { display: flex; align-items: center; gap: 12px; font-size: 13.5px; }
.liq-total-row.grand { font-size: 15.5px; color: var(--primary); }

.cheque-upload-box { margin: 8px 0 12px; }
.cheque-dropzone {
  border: 2px dashed #cbd5e1;
  border-radius: 8px;
  padding: 14px;
  text-align: center;
  cursor: pointer;
  background: #f8fafc;
}
.cheque-dropzone:focus, .cheque-dropzone:hover { border-color: var(--primary); background: #eff6ff; outline: none; }
.cheque-preview-wrap { display: flex; flex-direction: column; align-items: center; gap: 8px; }
.cheque-preview-wrap img { max-height: 150px; border: 1px solid var(--border); border-radius: 4px; }
.cheque-placeholder { color: var(--muted); font-size: 13px; }

.checkbox-row {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  color: #334155;
  cursor: pointer;
}

.import-list {
  max-height: 360px;
  overflow-y: auto;
  border: 1px solid var(--border);
  border-radius: 8px;
}
.import-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
  gap: 10px;
}
.import-row:hover { background: #f8fafc; }

.preview-scroll { display: flex; justify-content: center; padding: 20px; }

/* Proyectos y Gastos Dashboard */
.kpi-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 14px;
  margin-bottom: 16px;
}
.kpi-card {
  padding: 16px 18px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.kpi-lbl { font-size: 12px; color: var(--muted); font-weight: 600; text-transform: uppercase; }
.kpi-val { font-size: 22px; font-weight: 700; color: var(--text); font-variant-numeric: tabular-nums; }
.kpi-blue { color: var(--primary); }
.kpi-teal { color: var(--accent); }
.kpi-amber { color: #d97706; }

.charts-grid {
  display: grid;
  grid-template-columns: 1.25fr 1fr;
  gap: 16px;
  margin-bottom: 18px;
}
.chart-card { padding: 16px 18px; }
.chart-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 14px;
  gap: 10px;
}
.chart-head h3 { margin: 0; font-size: 15px; }
.chart-legend { display: flex; gap: 12px; font-size: 12px; color: var(--muted); }
.chart-legend .dot {
  display: inline-block;
  width: 10px;
  height: 10px;
  border-radius: 3px;
  margin-right: 5px;
}
.dot-blue { background: var(--primary); }
.dot-teal { background: var(--accent); }
.dot-amber { background: #d97706; }

.bars-chart { display: flex; flex-direction: column; gap: 10px; max-height: 310px; overflow-y: auto; padding-right: 4px; }
.bar-row { cursor: pointer; padding: 4px 6px; border-radius: 6px; transition: background 0.12s; }
.bar-row:hover { background: #f8fafc; }
.bar-row.selected { background: #eff6ff; outline: 1px solid #bfdbfe; }
.bar-meta { display: flex; justify-content: space-between; font-size: 12.5px; margin-bottom: 4px; gap: 8px; }
.bar-name { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.bar-amt { font-weight: 700; font-variant-numeric: tabular-nums; white-space: nowrap; }
.bar-track {
  height: 12px;
  background: #e2e8f0;
  border-radius: 999px;
  overflow: hidden;
  display: flex;
}
.bar-fill-liq { background: var(--primary); height: 100%; }
.bar-fill-reg { background: #d97706; height: 100%; }
.bar-fill-gd { background: var(--accent); height: 100%; }

.svg-chart-wrap { width: 100%; overflow-x: auto; }
.panel-subhead {
  padding: 14px 16px 8px;
  border-bottom: 1px solid var(--border);
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  flex-wrap: wrap;
  gap: 8px;
}
.panel-subhead h3 { margin: 0; font-size: 15px; }
.clickable-row { cursor: pointer; }
.clickable-row.selected { background: #eff6ff !important; }

.toast {
  position: fixed;
  bottom: 20px;
  right: 20px;
  background: #0f172a;
  color: #fff;
  padding: 11px 16px;
  border-radius: 8px;
  font-size: 13.5px;
  box-shadow: 0 10px 25px rgba(0,0,0,0.2);
  z-index: 2000;
}
.toast.error { background: #b91c1c; }

/* Auth Screen & Sidebar User */
.auth-screen {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(135deg, #0f2744 0%, #1e5a9e 100%);
  padding: 20px;
}
.auth-card {
  width: 100%;
  max-width: 400px;
  padding: 28px 26px;
}
.auth-brand {
  text-align: center;
  margin-bottom: 20px;
}
.auth-logo {
  width: 110px;
  height: auto;
  margin-bottom: 8px;
}
.auth-brand h1 { margin: 0; font-size: 19px; color: var(--text); }
.auth-error {
  background: #fef2f2;
  color: #b91c1c;
  border: 1px solid #fecaca;
  border-radius: 7px;
  padding: 8px 10px;
  font-size: 12.5px;
  margin-bottom: 8px;
}

.sidebar-user {
  border-top: 1px solid rgba(255,255,255,0.12);
  margin-top: 12px;
  padding-top: 12px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.user-info {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 6px;
  font-size: 13px;
  color: #fff;
}
.user-role-badge {
  font-size: 10.5px;
  padding: 2px 7px;
  border-radius: 999px;
  background: rgba(255,255,255,0.15);
  color: #e2e8f0;
  font-weight: 600;
}
.user-actions {
  display: flex;
  gap: 6px;
}
.user-actions .btn { flex: 1; justify-content: center; }

@media (max-width: 900px) {
  #app-shell { flex-direction: column; }
  .sidebar { width: 100%; }
  .form-grid-4, .form-grid-3, .form-grid-2, .kpi-grid, .charts-grid { grid-template-columns: 1fr; }
}
