:root {
  --primary: #c8622a;
  --primary-light: #e8855a;
  --primary-dark: #9e4a1e;
  --accent: #f5b942;
  --accent-light: #fde68a;
  --bg: #faf7f4;
  --bg-card: #ffffff;
  --bg-sidebar: #1c1917;
  --text: #1c1917;
  --text-muted: #78716c;
  --text-light: #a8a29e;
  --border: #e7e5e4;
  --success: #16a34a;
  --danger: #dc2626;
  --warning: #d97706;
  --info: #2563eb;
  --shadow: 0 1px 3px rgba(0,0,0,.08), 0 4px 16px rgba(0,0,0,.04);
  --shadow-lg: 0 8px 32px rgba(0,0,0,.12);
  --radius: 12px;
  --sidebar-w: 240px;
  --topbar-h: 60px;
  --font-display: 'Playfair Display', serif;
  --font-body: 'DM Sans', sans-serif;
}

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

body {
  font-family: var(--font-body);
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  font-size: 15px;
  line-height: 1.5;
}

/* ========== LOGIN ========== */
.login-screen {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
  overflow: hidden;
  background: linear-gradient(135deg, #1c1917 0%, #292524 60%, #3c2010 100%);
}

.login-bg { position: absolute; inset: 0; }
.login-orb {
  position: absolute;
  border-radius: 50%;
  filter: blur(80px);
  opacity: .35;
}
.login-orb-1 { width: 500px; height: 500px; background: var(--primary); top: -100px; left: -100px; }
.login-orb-2 { width: 300px; height: 300px; background: var(--accent); bottom: -50px; right: 10%; animation: float 8s ease-in-out infinite; }
.login-orb-3 { width: 200px; height: 200px; background: #7c3aed; top: 40%; right: -50px; animation: float 6s ease-in-out infinite reverse; }

@keyframes float {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-30px); }
}

.login-card {
  position: relative;
  z-index: 10;
  background: rgba(255,255,255,.07);
  backdrop-filter: blur(20px);
  border: 1px solid rgba(255,255,255,.12);
  border-radius: 24px;
  padding: 48px 40px;
  width: 380px;
  max-width: 95vw;
  box-shadow: 0 32px 80px rgba(0,0,0,.5);
  animation: slideUp .6s cubic-bezier(.22,.68,0,1.2) both;
}

@keyframes slideUp {
  from { opacity: 0; transform: translateY(40px) scale(.96); }
  to   { opacity: 1; transform: translateY(0) scale(1); }
}

.login-logo { text-align: center; margin-bottom: 36px; }
.login-icon { font-size: 48px; display: block; margin-bottom: 12px; }
.login-title {
  font-family: var(--font-display);
  font-size: 28px;
  color: #fff;
  line-height: 1.15;
  margin-bottom: 6px;
}
.login-title span { color: var(--accent); }
.login-sub { color: rgba(255,255,255,.5); font-size: 13px; letter-spacing: .08em; text-transform: uppercase; }

.field-group { margin-bottom: 16px; }
.field-group label { display: block; color: rgba(255,255,255,.6); font-size: 12px; letter-spacing: .06em; text-transform: uppercase; margin-bottom: 6px; }
.field-group input {
  width: 100%; padding: 12px 16px;
  background: rgba(255,255,255,.1);
  border: 1px solid rgba(255,255,255,.15);
  border-radius: 10px;
  color: #fff;
  font-family: var(--font-body);
  font-size: 15px;
  outline: none;
  transition: all .2s;
}
.field-group input::placeholder { color: rgba(255,255,255,.3); }
.field-group input:focus { border-color: var(--accent); background: rgba(255,255,255,.15); }

.btn-login {
  width: 100%; padding: 14px;
  background: linear-gradient(135deg, var(--primary), var(--primary-light));
  color: #fff;
  border: none; border-radius: 10px;
  font-family: var(--font-body);
  font-size: 15px; font-weight: 600;
  cursor: pointer;
  margin-top: 8px;
  transition: all .2s;
  letter-spacing: .03em;
}
.btn-login:hover { transform: translateY(-1px); box-shadow: 0 8px 24px rgba(200,98,42,.4); }
.btn-login:active { transform: translateY(0); }

.login-error { color: #fca5a5; font-size: 13px; text-align: center; margin-top: 12px; }

/* ========== APP LAYOUT ========== */
.app { display: flex; min-height: 100vh; }

.sidebar {
  width: var(--sidebar-w);
  background: var(--bg-sidebar);
  display: flex;
  flex-direction: column;
  position: fixed;
  left: 0; top: 0; bottom: 0;
  z-index: 100;
  transition: transform .3s cubic-bezier(.4,0,.2,1);
  overflow-y: auto;
}

.sidebar-header {
  padding: 20px 16px;
  display: flex; align-items: center; gap: 10px;
  border-bottom: 1px solid rgba(255,255,255,.08);
}
.sidebar-icon { font-size: 28px; }
.sidebar-title { flex: 1; }
.sidebar-name { display: block; font-family: var(--font-display); color: #fff; font-size: 16px; }
.sidebar-sub { display: block; color: rgba(255,255,255,.4); font-size: 11px; }
.sidebar-close { display: none; background: none; border: none; color: rgba(255,255,255,.4); cursor: pointer; font-size: 18px; }

.sidebar-user {
  padding: 16px;
  border-bottom: 1px solid rgba(255,255,255,.06);
}

.sidebar-nav { list-style: none; padding: 12px 8px; flex: 1; }
.sidebar-nav li a {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 12px;
  color: rgba(255,255,255,.55);
  text-decoration: none;
  border-radius: 8px;
  font-size: 14px;
  font-weight: 500;
  transition: all .15s;
}
.sidebar-nav li a:hover { color: #fff; background: rgba(255,255,255,.06); }
.sidebar-nav li a.active { color: #fff; background: var(--primary); }
.sidebar-nav li a span { font-size: 16px; }

.sidebar-footer { padding: 16px; border-top: 1px solid rgba(255,255,255,.08); }
.btn-logout {
  width: 100%; padding: 10px;
  background: rgba(255,255,255,.06);
  border: 1px solid rgba(255,255,255,.1);
  border-radius: 8px;
  color: rgba(255,255,255,.6);
  font-family: var(--font-body);
  font-size: 13px; cursor: pointer;
  transition: all .2s;
}
.btn-logout:hover { background: rgba(220,38,38,.2); color: #fca5a5; border-color: rgba(220,38,38,.3); }

/* TOPBAR */
.topbar {
  position: fixed;
  left: var(--sidebar-w); right: 0; top: 0;
  height: var(--topbar-h);
  background: rgba(250,247,244,.9);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border);
  display: flex; align-items: center;
  padding: 0 24px;
  gap: 16px;
  z-index: 50;
  transition: left .3s;
}
.menu-btn { display: none; background: none; border: none; font-size: 22px; cursor: pointer; color: var(--text); }
.topbar-title { flex: 1; font-family: var(--font-display); font-size: 20px; color: var(--text); }
.topbar-user { font-size: 13px; color: var(--text-muted); text-align: right; }

/* MAIN CONTENT */
.main-content {
  margin-left: var(--sidebar-w);
  margin-top: var(--topbar-h);
  padding: 28px;
  min-height: calc(100vh - var(--topbar-h));
  flex: 1;
}

/* PAGES */
.page { display: none; }
.page.active { display: block; animation: fadeIn .3s ease; }
@keyframes fadeIn { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: translateY(0); } }

/* ========== COMPONENTS ========== */
.card {
  background: var(--bg-card);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 24px;
  border: 1px solid var(--border);
}

.card-title {
  font-family: var(--font-display);
  font-size: 17px;
  color: var(--text);
  margin-bottom: 16px;
  display: flex; align-items: center; gap: 8px;
}

.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 20px; }
.grid-3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 20px; }
.grid-4 { display: grid; grid-template-columns: repeat(4, 1fr); gap: 20px; }
.grid-auto { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 20px; }

/* STAT CARDS */
.stat-card {
  background: var(--bg-card);
  border-radius: var(--radius);
  padding: 20px 24px;
  box-shadow: var(--shadow);
  border: 1px solid var(--border);
  display: flex; flex-direction: column; gap: 6px;
  position: relative; overflow: hidden;
}
.stat-card::before {
  content: '';
  position: absolute; left: 0; top: 0; bottom: 0;
  width: 4px;
}
.stat-card.green::before { background: var(--success); }
.stat-card.red::before { background: var(--danger); }
.stat-card.amber::before { background: var(--accent); }
.stat-card.blue::before { background: var(--info); }
.stat-card.orange::before { background: var(--primary); }

.stat-label { font-size: 12px; color: var(--text-muted); text-transform: uppercase; letter-spacing: .06em; font-weight: 500; }
.stat-value { font-size: 28px; font-weight: 600; color: var(--text); letter-spacing: -.02em; }
.stat-sub { font-size: 12px; color: var(--text-light); }
.stat-icon { position: absolute; right: 16px; top: 50%; transform: translateY(-50%); font-size: 36px; opacity: .15; }

/* BUTTONS */
.btn {
  padding: 9px 18px;
  border-radius: 8px;
  font-family: var(--font-body);
  font-size: 14px; font-weight: 500;
  cursor: pointer; border: none;
  transition: all .15s;
  display: inline-flex; align-items: center; gap: 6px;
}
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-dark); transform: translateY(-1px); }
.btn-secondary { background: var(--border); color: var(--text); }
.btn-secondary:hover { background: #d6d3d1; }
.btn-success { background: var(--success); color: #fff; }
.btn-danger { background: var(--danger); color: #fff; }
.btn-ghost { background: transparent; color: var(--text-muted); border: 1px solid var(--border); }
.btn-ghost:hover { background: var(--border); }
.btn-sm { padding: 6px 12px; font-size: 13px; }
.btn-icon { padding: 7px; border-radius: 7px; font-size: 16px; }

/* FORMS */
.form-group { margin-bottom: 16px; }
.form-group label { display: block; font-size: 12px; font-weight: 500; color: var(--text-muted); text-transform: uppercase; letter-spacing: .05em; margin-bottom: 6px; }
.form-group input, .form-group select, .form-group textarea {
  width: 100%; padding: 10px 14px;
  border: 1.5px solid var(--border);
  border-radius: 8px;
  font-family: var(--font-body); font-size: 14px;
  color: var(--text); background: var(--bg);
  outline: none; transition: border-color .15s;
}
.form-group input:focus, .form-group select:focus, .form-group textarea:focus {
  border-color: var(--primary);
}
.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }

/* TABLES */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 14px; }
th { text-align: left; padding: 10px 14px; font-size: 11px; text-transform: uppercase; letter-spacing: .06em; color: var(--text-muted); border-bottom: 2px solid var(--border); font-weight: 600; }
td { padding: 12px 14px; border-bottom: 1px solid var(--border); vertical-align: middle; }
tr:last-child td { border-bottom: none; }
tr:hover td { background: rgba(200,98,42,.03); }

/* BADGES */
.badge {
  display: inline-flex; align-items: center; gap: 4px;
  padding: 3px 10px; border-radius: 20px;
  font-size: 11px; font-weight: 600; letter-spacing: .04em;
}
.badge-green { background: #dcfce7; color: #166534; }
.badge-red { background: #fee2e2; color: #991b1b; }
.badge-amber { background: #fef3c7; color: #92400e; }
.badge-blue { background: #dbeafe; color: #1e40af; }
.badge-gray { background: #f5f5f4; color: #57534e; }
.badge-orange { background: #fed7aa; color: #9a3412; }

/* CALENDAR */
.cal-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 20px; }
.cal-nav { display: flex; gap: 8px; align-items: center; }
.cal-month { font-family: var(--font-display); font-size: 20px; }
.cal-grid { display: grid; grid-template-columns: repeat(7, 1fr); gap: 2px; }
.cal-day-name { text-align: center; font-size: 11px; font-weight: 600; color: var(--text-muted); padding: 8px 0; text-transform: uppercase; letter-spacing: .05em; }
.cal-day {
  min-height: 90px; padding: 6px;
  border-radius: 8px;
  border: 1px solid transparent;
  cursor: pointer;
  transition: all .15s;
  background: var(--bg-card);
  position: relative;
}
.cal-day:hover { border-color: var(--primary); background: #fff7f4; }
.cal-day.today { border-color: var(--primary); background: #fff7f4; }
.cal-day.today .cal-day-num { background: var(--primary); color: #fff; border-radius: 50%; width: 24px; height: 24px; display: flex; align-items: center; justify-content: center; }
.cal-day.other-month { opacity: .35; }
.cal-day-num { font-size: 13px; font-weight: 500; color: var(--text); margin-bottom: 4px; display: block; }
.cal-event { font-size: 11px; padding: 2px 6px; border-radius: 4px; margin-bottom: 2px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.cal-event.salud { background: #fce7f3; color: #9d174d; }
.cal-event.escolar { background: #ede9fe; color: #4c1d95; }
.cal-event.familiar { background: #dcfce7; color: #166534; }
.cal-event.social { background: #dbeafe; color: #1e40af; }
.cal-event.trabajo { background: #fef3c7; color: #92400e; }
.cal-event.otro { background: #f5f5f4; color: #57534e; }

/* TASK ITEMS */
.task-item {
  display: flex; align-items: flex-start; gap: 12px;
  padding: 14px 0;
  border-bottom: 1px solid var(--border);
}
.task-item:last-child { border-bottom: none; }
.task-check { width: 20px; height: 20px; border-radius: 50%; border: 2px solid var(--border); flex-shrink: 0; cursor: pointer; margin-top: 2px; display: flex; align-items: center; justify-content: center; transition: all .15s; }
.task-check.done { background: var(--success); border-color: var(--success); color: #fff; }
.task-check:hover:not(.done) { border-color: var(--primary); }
.task-content { flex: 1; }
.task-title { font-size: 14px; font-weight: 500; color: var(--text); }
.task-title.done { text-decoration: line-through; color: var(--text-light); }
.task-meta { font-size: 12px; color: var(--text-muted); margin-top: 3px; display: flex; gap: 10px; flex-wrap: wrap; }
.task-actions { display: flex; gap: 4px; opacity: 0; transition: opacity .15s; }
.task-item:hover .task-actions { opacity: 1; }

/* TRANSACTION ITEMS */
.tx-item {
  display: flex; align-items: center; gap: 12px;
  padding: 12px 0;
  border-bottom: 1px solid var(--border);
}
.tx-item:last-child { border-bottom: none; }
.tx-icon { width: 40px; height: 40px; border-radius: 10px; display: flex; align-items: center; justify-content: center; font-size: 18px; flex-shrink: 0; }
.tx-info { flex: 1; }
.tx-desc { font-size: 14px; font-weight: 500; }
.tx-meta { font-size: 12px; color: var(--text-muted); }
.tx-amount { font-size: 15px; font-weight: 600; }
.tx-amount.ingreso { color: var(--success); }
.tx-amount.gasto { color: var(--danger); }

/* USER AVATAR */
.user-chip {
  display: flex; align-items: center; gap: 8px;
  padding: 8px 12px;
  border-radius: 10px;
  background: rgba(255,255,255,.07);
}
.user-chip .avatar { font-size: 22px; }
.user-chip .name { color: #fff; font-size: 13px; font-weight: 500; }
.user-chip .role-badge { font-size: 10px; color: rgba(255,255,255,.4); text-transform: uppercase; letter-spacing: .06em; }

/* DONUT CHART (CSS) */
.donut-wrap { display: flex; align-items: center; gap: 24px; }
.donut-chart { position: relative; width: 140px; height: 140px; flex-shrink: 0; }
.donut-chart svg { transform: rotate(-90deg); }
.donut-center { position: absolute; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; }
.donut-center .val { font-size: 18px; font-weight: 700; color: var(--text); }
.donut-center .lbl { font-size: 10px; color: var(--text-muted); }
.legend { display: flex; flex-direction: column; gap: 8px; flex: 1; min-width: 0; }
.legend-item { display: flex; align-items: center; gap: 8px; font-size: 12px; }
.legend-dot { width: 10px; height: 10px; border-radius: 50%; flex-shrink: 0; }
.legend-name { flex: 1; color: var(--text-muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.legend-val { font-weight: 600; color: var(--text); }

/* BAR CHART */
.bar-chart { display: flex; flex-direction: column; gap: 10px; }
.bar-row { display: flex; align-items: center; gap: 12px; }
.bar-label { width: 90px; font-size: 12px; color: var(--text-muted); text-align: right; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.bar-track { flex: 1; height: 10px; background: var(--border); border-radius: 5px; overflow: hidden; }
.bar-fill { height: 100%; border-radius: 5px; transition: width .8s cubic-bezier(.22,.68,0,1.2); }
.bar-val { font-size: 12px; font-weight: 600; color: var(--text); width: 90px; }

/* PAGE HEADER */
.page-header { margin-bottom: 24px; display: flex; align-items: flex-start; justify-content: space-between; flex-wrap: wrap; gap: 12px; }
.page-header h2 { font-family: var(--font-display); font-size: 26px; color: var(--text); }
.page-header p { font-size: 14px; color: var(--text-muted); margin-top: 2px; }

/* MODAL */
.modal-overlay {
  position: fixed; inset: 0; z-index: 1000;
  background: rgba(0,0,0,.5);
  backdrop-filter: blur(4px);
  display: flex; align-items: center; justify-content: center;
  padding: 20px;
}
.modal-box {
  background: var(--bg-card);
  border-radius: 16px;
  box-shadow: var(--shadow-lg);
  width: 100%; max-width: 520px;
  max-height: 90vh;
  overflow-y: auto;
  animation: modalIn .25s cubic-bezier(.22,.68,0,1.2) both;
}
@keyframes modalIn {
  from { opacity: 0; transform: scale(.95) translateY(20px); }
  to   { opacity: 1; transform: scale(1) translateY(0); }
}
.modal-header {
  padding: 20px 24px 0;
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 20px;
}
.modal-header h3 { font-family: var(--font-display); font-size: 18px; }
.modal-header button { background: none; border: none; color: var(--text-muted); cursor: pointer; font-size: 18px; }
#modal-body { padding: 0 24px 24px; }

/* TOAST */
.toast {
  position: fixed; bottom: 24px; right: 24px; z-index: 2000;
  background: var(--bg-sidebar);
  color: #fff;
  padding: 12px 20px;
  border-radius: 10px;
  font-size: 14px;
  box-shadow: var(--shadow-lg);
  animation: toastIn .3s ease;
  max-width: 320px;
}
.toast.success { border-left: 4px solid var(--success); }
.toast.error { border-left: 4px solid var(--danger); }
.toast.info { border-left: 4px solid var(--info); }
@keyframes toastIn { from { opacity: 0; transform: translateY(20px); } to { opacity: 1; transform: translateY(0); } }

/* EMPTY STATE */
.empty-state { text-align: center; padding: 48px 24px; color: var(--text-muted); }
.empty-state .icon { font-size: 48px; margin-bottom: 12px; display: block; opacity: .5; }
.empty-state p { font-size: 14px; }

/* UTILITIES */
.hidden { display: none !important; }
.flex { display: flex; }
.flex-col { flex-direction: column; }
.items-center { align-items: center; }
.justify-between { justify-content: space-between; }
.gap-2 { gap: 8px; }
.gap-3 { gap: 12px; }
.gap-4 { gap: 16px; }
.mt-1 { margin-top: 4px; }
.mt-2 { margin-top: 8px; }
.mt-3 { margin-top: 12px; }
.mt-4 { margin-top: 16px; }
.mb-4 { margin-bottom: 16px; }
.mb-6 { margin-bottom: 24px; }
.text-sm { font-size: 13px; }
.text-muted { color: var(--text-muted); }
.text-right { text-align: right; }
.font-bold { font-weight: 700; }
.divider { border: none; border-top: 1px solid var(--border); margin: 20px 0; }
.clp::before { content: '$'; }
.scroll-x { overflow-x: auto; }

/* FILTER BAR */
.filter-bar { display: flex; gap: 10px; flex-wrap: wrap; margin-bottom: 20px; align-items: center; }
.filter-bar select, .filter-bar input { padding: 8px 12px; border: 1.5px solid var(--border); border-radius: 8px; font-family: var(--font-body); font-size: 13px; background: var(--bg-card); color: var(--text); outline: none; }
.filter-bar select:focus, .filter-bar input:focus { border-color: var(--primary); }

/* TABS */
.tab-bar { display: flex; gap: 4px; border-bottom: 2px solid var(--border); margin-bottom: 24px; }
.tab-btn { padding: 10px 20px; background: none; border: none; font-family: var(--font-body); font-size: 14px; font-weight: 500; color: var(--text-muted); cursor: pointer; border-bottom: 2px solid transparent; margin-bottom: -2px; transition: all .15s; }
.tab-btn.active { color: var(--primary); border-bottom-color: var(--primary); }

/* RESPONSIVE */
@media (max-width: 900px) {
  .sidebar { transform: translateX(-100%); }
  .sidebar.open { transform: translateX(0); }
  .sidebar-close { display: block; }
  .topbar { left: 0; }
  .main-content { margin-left: 0; }
  .menu-btn { display: block; }
  .grid-4 { grid-template-columns: 1fr 1fr; }
  .grid-3 { grid-template-columns: 1fr 1fr; }
}
@media (max-width: 600px) {
  .main-content { padding: 16px; }
  .grid-2, .grid-3, .grid-4 { grid-template-columns: 1fr; }
  .form-row { grid-template-columns: 1fr; }
  .cal-day { min-height: 60px; }
  .topbar { padding: 0 16px; }
}
