:root {
  --bg: #f1f5f9;
  --card: #ffffff;
  --text: #0f172a;
  --muted: #64748b;
  --border: #e2e8f0;
  --sidebar: #0f172a;
  --sidebar-text: #cbd5e1;
  --accent: #7c3aed;
  --accent-2: #8b5cf6;
  --green: #10b981;
  --red: #ef4444;
  --shadow: 0 1px 3px rgba(15, 23, 42, .08), 0 8px 24px rgba(15, 23, 42, .04);
  --radius: 14px;
  --font: "Segoe UI", system-ui, -apple-system, Roboto, Ubuntu, sans-serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  line-height: 1.45;
}

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
.muted { color: var(--muted); }
.ta-r { text-align: right; }
.nowrap { white-space: nowrap; }
.amt-red { color: var(--red); font-weight: 600; }
.amt-green { color: var(--green); font-weight: 600; }

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

.sidebar {
  width: 250px;
  background: var(--sidebar);
  color: var(--sidebar-text);
  display: flex;
  flex-direction: column;
  padding: 20px 16px;
  position: sticky;
  top: 0;
  height: 100vh;
  flex-shrink: 0;
}

.brand {
  display: flex;
  gap: 12px;
  align-items: center;
  margin-bottom: 28px;
  padding: 0 8px;
}
.brand strong { display: block; color: #fff; font-size: 15px; }
.brand small { color: #94a3b8; font-size: 12px; }
.brand-mark {
  width: 40px; height: 40px; border-radius: 12px;
  background: linear-gradient(135deg, var(--accent), #06b6d4);
  color: #fff; font-weight: 800; display: grid; place-items: center;
  font-size: 14px; flex-shrink: 0;
}

.nav { display: flex; flex-direction: column; gap: 4px; flex: 1; }
.nav-link {
  color: var(--sidebar-text);
  padding: 11px 14px;
  border-radius: 10px;
  text-decoration: none;
  font-weight: 500;
  font-size: 14px;
}
.nav-link:hover { background: rgba(255,255,255,.06); text-decoration: none; color: #fff; }
.nav-link.is-active {
  background: rgba(124, 58, 237, .22);
  color: #fff;
  box-shadow: inset 3px 0 0 var(--accent-2);
}

.sidebar-foot {
  border-top: 1px solid rgba(255,255,255,.08);
  padding-top: 14px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
  font-size: 13px;
}
.user-name { color: #e2e8f0; font-weight: 600; overflow: hidden; text-overflow: ellipsis; }
.logout-link { color: #94a3b8; }
.logout-link:hover { color: #fff; }

.main {
  flex: 1;
  padding: 28px 32px 48px;
  min-width: 0;
}

.page-head {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 16px;
  margin-bottom: 22px;
  flex-wrap: wrap;
}
.page-head h1 { margin: 0 0 4px; font-size: 26px; letter-spacing: -.02em; }
.page-sub { margin: 0; color: var(--muted); font-size: 14px; }

.filters, .filters-bar {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
}

.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 18px 20px;
  margin-bottom: 18px;
}
.card h3 { margin: 0 0 14px; font-size: 16px; }
.card-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  margin-bottom: 12px;
}
.card-head h3 { margin: 0; }
.link-muted { color: var(--muted); font-size: 13px; font-weight: 600; }

.kpis {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 14px;
  margin-bottom: 18px;
}
.kpi {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 16px 18px;
}
.kpi-label { display: block; color: var(--muted); font-size: 12px; font-weight: 600; text-transform: uppercase; letter-spacing: .04em; }
.kpi-value { display: block; font-size: 24px; font-weight: 800; margin: 6px 0 4px; letter-spacing: -.02em; }
.kpi-sub { display: block; color: var(--muted); font-size: 12px; }
.kpi-red { color: var(--red); }
.kpi-green { color: var(--green); }

.grid-2 {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 18px;
}
.chart-box { position: relative; height: 300px; }

.btn {
  appearance: none;
  border: none;
  background: linear-gradient(135deg, var(--accent), #6d28d9);
  color: #fff;
  font-weight: 700;
  font-size: 14px;
  padding: 10px 16px;
  border-radius: 10px;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  text-decoration: none;
  line-height: 1.2;
}
.btn:hover { filter: brightness(1.06); text-decoration: none; }
.btn-block { width: 100%; }
.btn-sm { padding: 8px 12px; font-size: 13px; }
.btn-xs { padding: 5px 8px; font-size: 12px; border-radius: 8px; }
.btn-ghost {
  background: #fff;
  color: var(--text);
  border: 1px solid var(--border);
  font-weight: 600;
}
.btn-ghost:hover { background: #f8fafc; filter: none; }
.btn-danger {
  background: #fff;
  color: var(--red);
  border: 1px solid #fecaca;
  font-weight: 600;
}
.btn-danger:hover { background: #fef2f2; filter: none; }

label {
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-size: 13px;
  font-weight: 600;
  color: #334155;
}
input[type="text"], input[type="password"], input[type="date"], input[type="search"],
input[type="number"], input[type="file"], select, textarea, .field-inline {
  width: 100%;
  border: 1px solid var(--border);
  background: #fff;
  border-radius: 10px;
  padding: 10px 12px;
  font: inherit;
  font-size: 14px;
  font-weight: 500;
  color: var(--text);
}
textarea { resize: vertical; min-height: 70px; }
input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: #a78bfa;
  box-shadow: 0 0 0 3px rgba(124, 58, 237, .15);
}
.field-inline { width: auto; min-width: 160px; }

.form-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 14px;
}
.form-grid .span-2 { grid-column: 1 / -1; }
.form-actions {
  display: flex;
  gap: 10px;
  margin-top: 16px;
  flex-wrap: wrap;
}
.file-note { margin-top: 6px; color: var(--muted); font-weight: 500; }
.stack-form { display: flex; flex-direction: column; gap: 12px; }

.filters-bar {
  padding: 14px 16px;
}
.filters-bar > * { min-width: 0; }
.filters-bar select,
.filters-bar input[type="date"],
.filters-bar input[type="search"] {
  width: auto;
  min-width: 140px;
  flex: 1 1 140px;
}

.table-wrap { overflow-x: auto; }
.table {
  width: 100%;
  border-collapse: collapse;
  font-size: 14px;
}
.table th {
  text-align: left;
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: .04em;
  color: var(--muted);
  border-bottom: 1px solid var(--border);
  padding: 10px 8px;
  white-space: nowrap;
}
.table td {
  padding: 12px 8px;
  border-bottom: 1px solid #f1f5f9;
  vertical-align: middle;
}
.table tbody tr:hover { background: #f8fafc; }
.table-compact td, .table-compact th { padding: 8px 6px; }
.desc-cell { max-width: 280px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.actions { display: flex; gap: 6px; justify-content: flex-end; align-items: center; }
.inline-form { display: inline; margin: 0; }

.proj-dot {
  width: 9px; height: 9px; border-radius: 50%;
  display: inline-block; margin-right: 7px; vertical-align: middle;
}

.badge {
  display: inline-block;
  font-size: 11px;
  font-weight: 700;
  padding: 2px 7px;
  border-radius: 999px;
  margin-right: 6px;
  vertical-align: middle;
}
.badge-gasto { background: #fef2f2; color: #b91c1c; }
.badge-ingreso { background: #ecfdf5; color: #047857; }

.flash {
  border-radius: 12px;
  padding: 12px 14px;
  margin-bottom: 16px;
  font-size: 14px;
  font-weight: 600;
}
.flash-ok { background: #ecfdf5; color: #065f46; border: 1px solid #a7f3d0; }
.flash-error { background: #fef2f2; color: #991b1b; border: 1px solid #fecaca; }

.empty { color: var(--muted); margin: 8px 0; }
.pagination {
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 16px;
  padding-top: 14px;
  font-size: 14px;
  color: var(--muted);
}

.cat-col h4 {
  margin: 0 0 12px;
  font-size: 14px;
  text-transform: uppercase;
  letter-spacing: .04em;
  color: var(--muted);
}
.cat-tree { list-style: none; margin: 0 0 14px; padding: 0; }
.cat-tree > li { margin-bottom: 8px; }
.cat-tree-sub { margin: 6px 0 0 18px; padding-left: 10px; border-left: 2px solid var(--border); }
.cat-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
  padding: 8px;
  border-radius: 10px;
  background: #f8fafc;
}
.cat-rename { display: flex; gap: 6px; align-items: center; flex: 1; min-width: 180px; }
.cat-rename input[type="text"] { padding: 7px 10px; }
.cat-stats { color: var(--muted); font-size: 12px; white-space: nowrap; }
.add-cat-form {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 8px;
}
.add-cat-form select, .add-cat-form input[type="text"] { flex: 1 1 140px; min-width: 120px; }

.info-list { list-style: none; margin: 0 0 16px; padding: 0; }
.info-list li {
  display: flex;
  justify-content: space-between;
  padding: 10px 0;
  border-bottom: 1px solid var(--border);
  font-size: 14px;
}
.info-list span { color: var(--muted); }

/* Login */
.login-body {
  min-height: 100vh;
  display: grid;
  place-items: center;
  background:
    radial-gradient(1000px 500px at 10% 10%, rgba(124,58,237,.35), transparent 60%),
    radial-gradient(800px 400px at 90% 80%, rgba(14,165,233,.28), transparent 55%),
    #0f172a;
  padding: 24px;
}
.login-wrap { width: 100%; max-width: 420px; }
.login-card {
  background: #fff;
  border-radius: 18px;
  padding: 28px 26px 30px;
  box-shadow: 0 20px 60px rgba(0,0,0,.35);
}
.login-brand { text-align: center; margin-bottom: 22px; }
.login-brand .brand-mark { margin: 0 auto 12px; width: 48px; height: 48px; font-size: 16px; }
.login-brand h1 { margin: 0 0 4px; font-size: 22px; }
.login-brand p { margin: 0; color: var(--muted); font-size: 14px; }
.login-form { display: flex; flex-direction: column; gap: 14px; }

@media (max-width: 1100px) {
  .kpis { grid-template-columns: repeat(2, 1fr); }
}
@media (max-width: 900px) {
  .app { flex-direction: column; }
  .sidebar {
    width: 100%;
    height: auto;
    position: relative;
    padding: 14px;
  }
  .brand { margin-bottom: 12px; }
  .nav { flex-direction: row; overflow-x: auto; gap: 6px; }
  .nav-link { white-space: nowrap; }
  .nav-link.is-active { box-shadow: none; }
  .sidebar-foot { margin-top: 10px; }
  .main { padding: 18px 14px 36px; }
  .grid-2 { grid-template-columns: 1fr; }
  .form-grid { grid-template-columns: 1fr; }
  .form-grid .span-2 { grid-column: auto; }
  .kpis { grid-template-columns: 1fr 1fr; }
}
@media (max-width: 560px) {
  .kpis { grid-template-columns: 1fr; }
  .page-head h1 { font-size: 22px; }
}

/* ===== Expert dashboard extras ===== */
.nav-section {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: .08em;
  color: #64748b;
  margin: 14px 8px 6px;
  font-weight: 700;
}
.nav-project { display: flex; align-items: center; gap: 2px; }
.sidebar { overflow-y: auto; }

.project-pills {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-bottom: 18px;
}
.pill {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  background: #fff;
  border: 1px solid var(--border);
  border-left: 4px solid var(--pill, var(--accent));
  border-radius: 12px;
  padding: 12px 14px;
  color: var(--text);
  font-weight: 700;
  text-decoration: none;
  box-shadow: var(--shadow);
  min-width: 160px;
}
.pill:hover { text-decoration: none; transform: translateY(-1px); }
.pill-go { margin-left: auto; color: var(--muted); font-size: 12px; font-weight: 600; }

.project-title { display: flex; align-items: center; gap: 10px; }
.project-title h1 { margin: 0; }
.proj-dot.lg { width: 14px; height: 14px; }

.kpis { grid-template-columns: repeat(3, 1fr); }
.kpis-5 { grid-template-columns: repeat(5, 1fr); }
@media (min-width: 1200px) {
  .kpis { grid-template-columns: repeat(6, 1fr); }
}

.insights {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-bottom: 16px;
}
.insight {
  border-radius: 12px;
  padding: 10px 14px;
  font-size: 13px;
  font-weight: 600;
  border: 1px solid var(--border);
  background: #fff;
}
.insight-ok { background: #ecfdf5; border-color: #a7f3d0; color: #065f46; }
.insight-warn { background: #fff7ed; border-color: #fed7aa; color: #9a3412; }
.insight-info { background: #f5f3ff; border-color: #ddd6fe; color: #5b21b6; }

.chart-card .card-head { margin-bottom: 8px; flex-wrap: wrap; }
.chart-tools { display: flex; flex-wrap: wrap; gap: 6px; }
.chip {
  appearance: none;
  border: 1px solid var(--border);
  background: #fff;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
  padding: 5px 10px;
  border-radius: 999px;
  cursor: pointer;
}
.chip:hover { border-color: #c4b5fd; color: var(--text); }
.chip.is-on {
  background: #ede9fe;
  border-color: #c4b5fd;
  color: #5b21b6;
}

.chart-box.tall { height: 380px; }
.filters-advanced { max-width: 100%; }

.mini-bar {
  height: 5px;
  background: #e2e8f0;
  border-radius: 999px;
  margin-top: 4px;
  overflow: hidden;
  min-width: 70px;
}
.mini-bar span { display: block; height: 100%; border-radius: 999px; }

.quick-cats { margin-top: 18px; padding-top: 14px; border-top: 1px solid var(--border); }
.quick-cats h4 { margin: 0 0 10px; font-size: 13px; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; }
.tag-cloud { display: flex; flex-wrap: wrap; gap: 6px; }
.tag {
  background: #f1f5f9;
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 4px 10px;
  font-size: 12px;
  font-weight: 600;
}
.tag small { color: var(--muted); }
.small { font-size: 12px; }

@media (max-width: 1200px) {
  .kpis-5 { grid-template-columns: repeat(3, 1fr); }
}
@media (max-width: 900px) {
  .kpis, .kpis-5 { grid-template-columns: repeat(2, 1fr); }
  .chart-box.tall { height: 300px; }
  .nav-section { display: none; }
}
@media (max-width: 560px) {
  .kpis, .kpis-5 { grid-template-columns: 1fr; }
}
