/* =============================================================
   CashVue — Design System
   ============================================================= */

:root {
  --primary: #1F7537;
  --primary-light: #4FAE48;
  --primary-dark: #175C2B;
  --text: #283C40;
  --text-secondary: #5B6B6E;
  --text-muted: #8A9699;
  --blue: #034776;
  --teal: #068B9C;
  --gold: #E89305;
  --yellow: #FDDA1B;
  --danger: #DC2626;
  --danger-bg: #FDEDEC;
  --bg: #F7FAF8;
  --card-bg: #FFFFFF;
  --border: #E5EBE6;
  --radius: 14px;
  --radius-sm: 10px;
  --radius-lg: 18px;
  --sidebar-w: 240px;
  --shadow: 0 1px 2px rgba(40,60,64,.06), 0 2px 8px rgba(40,60,64,.05);
  --shadow-md: 0 4px 16px rgba(40,60,64,.08);
  --font-heading: 'Manrope', 'Inter', -apple-system, sans-serif;
  --font-body: 'Inter', 'Manrope', -apple-system, sans-serif;
}

* { box-sizing: border-box; }
html, body { overflow-x: hidden; max-width: 100%; }
body {
  margin: 0;
  font-family: var(--font-body);
  color: var(--text);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
}
h1, h2, h3, h4 { font-family: var(--font-heading); font-weight: 700; margin: 0; color: var(--text); }
a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }
p { margin: 0; }
button { font-family: var(--font-body); }
input, select, textarea { font-family: var(--font-body); }

/* ── App shell ────────────────────────────────────────────── */

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

.app-loading { display: flex; align-items: center; justify-content: center; height: 100dvh; width: 100%; }
.spinner {
  width: 32px; height: 32px; border-radius: 50%;
  border: 3px solid var(--border); border-top-color: var(--primary);
  animation: spin .7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.sidebar {
  width: var(--sidebar-w); background: var(--primary-dark); color: #EAF3EB;
  height: 100vh; height: 100dvh; display: flex; flex-direction: column; flex-shrink: 0;
  position: fixed; top: 0; left: 0; bottom: 0; z-index: 100; overflow: hidden;
}
.sidebar-logo { display: flex; align-items: center; gap: .625rem; padding: 1.25rem 1.125rem; border-bottom: 1px solid rgba(255,255,255,.12); flex-shrink: 0; }
.sidebar-logo img { width: 30px; height: 30px; flex-shrink: 0; }
.sidebar-logo span { font-family: var(--font-heading); font-weight: 700; font-size: 1.0625rem; color: #fff; }
.sidebar-nav { flex: 1; min-height: 0; overflow-y: auto; padding: .75rem .625rem; -webkit-overflow-scrolling: touch; }
.nav-link {
  display: flex; align-items: center; gap: .75rem; padding: .625rem .75rem; border-radius: var(--radius-sm);
  color: rgba(234,243,235,.78); font-size: .875rem; font-weight: 500; cursor: pointer; margin-bottom: .125rem;
  transition: background .15s, color .15s;
}
.nav-link svg, .nav-link .nav-icon { width: 18px; height: 18px; flex-shrink: 0; font-size: 1.05rem; line-height: 1; }
.nav-link:hover { background: rgba(255,255,255,.08); color: #fff; }
.nav-link.active { background: var(--primary-light); color: #fff; font-weight: 600; }
.sidebar-footer { padding: .875rem 1rem; border-top: 1px solid rgba(255,255,255,.12); flex-shrink: 0; }
.sidebar-user { display: flex; align-items: center; gap: .625rem; font-size: .8125rem; }
.sidebar-user-avatar {
  width: 32px; height: 32px; border-radius: 50%; background: var(--primary-light); color: #fff;
  display: flex; align-items: center; justify-content: center; font-weight: 700; font-size: .8125rem; flex-shrink: 0;
}
.sidebar-user-info { flex: 1; min-width: 0; }
.sidebar-user-name { font-weight: 600; color: #fff; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.sidebar-user-role { font-size: .75rem; color: rgba(234,243,235,.6); text-transform: capitalize; }
.btn-logout { background: none; border: none; cursor: pointer; color: rgba(234,243,235,.7); padding: .25rem; display: flex; border-radius: 6px; }
.btn-logout:hover { background: rgba(255,255,255,.1); color: #fff; }

.mobile-topbar {
  display: none; align-items: center; gap: .75rem; padding: .75rem 1rem; background: var(--primary-dark);
  color: #fff; position: sticky; top: 0; z-index: 90; flex-shrink: 0;
}
.mobile-topbar img { width: 26px; height: 26px; }
.mobile-topbar span { font-family: var(--font-heading); font-weight: 700; font-size: 1rem; }
.btn-hamburger { background: none; border: none; cursor: pointer; padding: .25rem; display: flex; color: #fff; border-radius: 4px; }
.btn-hamburger:hover { background: rgba(255,255,255,.1); }
.btn-sidebar-close { display: none; background: none; border: none; cursor: pointer; color: rgba(234,243,235,.8); padding: .25rem; margin-left: auto; border-radius: 4px; }
.btn-sidebar-close:hover { color: #fff; background: rgba(255,255,255,.1); }
.sidebar-backdrop { display: none; position: fixed; inset: 0; background: rgba(0,0,0,.5); z-index: 150; }
.sidebar-backdrop.open { display: block; }

.main { margin-left: var(--sidebar-w); flex: 1; min-width: 0; display: flex; flex-direction: column; min-height: 100vh; min-height: 100dvh; }
.content { flex: 1; min-width: 0; padding: 1.75rem 2rem; max-width: 1280px; width: 100%; }

/* ── Page header ──────────────────────────────────────────── */

.page-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 1.5rem; gap: 1rem; flex-wrap: wrap; }
.page-title { font-size: 1.5rem; }
.page-subtitle { color: var(--text-secondary); font-size: .875rem; margin-top: .25rem; }

/* ── Buttons ──────────────────────────────────────────────── */

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: .4rem;
  padding: .5625rem 1.125rem; border-radius: var(--radius-sm); border: 1px solid transparent;
  font-size: .875rem; font-weight: 600; cursor: pointer; transition: background .15s, border-color .15s, color .15s;
  white-space: nowrap;
}
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-dark); }
.btn-secondary { background: #fff; color: var(--text); border-color: var(--border); }
.btn-secondary:hover { background: #F1F5F2; }
.btn-danger { background: var(--danger-bg); color: var(--danger); }
.btn-danger:hover { background: #FADBD8; }
.btn-ghost { background: none; color: var(--text-secondary); }
.btn-ghost:hover { background: #F1F5F2; }
.btn-sm { padding: .3125rem .625rem; font-size: .8125rem; }
.btn-full { width: 100%; }
.btn:disabled { opacity: .55; cursor: not-allowed; }

/* ── Cards ────────────────────────────────────────────────── */

.card { background: var(--card-bg); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); overflow: hidden; }
.card-body { padding: 1.25rem; }
.card-header { display: flex; justify-content: space-between; align-items: center; padding: 1rem 1.25rem; border-bottom: 1px solid var(--border); flex-wrap: wrap; gap: .5rem; }
.card-title { font-family: var(--font-heading); font-weight: 700; font-size: 1rem; }

.stats-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 1rem; margin-bottom: 1.5rem; }
.stat-card { background: var(--card-bg); border: 1px solid var(--border); border-radius: var(--radius); padding: 1.125rem 1.25rem; box-shadow: var(--shadow); }
.stat-label { font-size: .8125rem; color: var(--text-secondary); font-weight: 500; margin-bottom: .375rem; }
.stat-value { font-family: var(--font-heading); font-size: 1.5rem; font-weight: 700; letter-spacing: -.01em; }
.stat-value.positive { color: var(--primary); }
.stat-value.negative { color: var(--danger); }
.stat-sub { font-size: .75rem; color: var(--text-muted); margin-top: .25rem; }

/* ── Forms ────────────────────────────────────────────────── */

.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 1rem; }
.form-group { margin-bottom: 1rem; }
.form-group label { display: block; font-size: .8125rem; font-weight: 600; margin-bottom: .375rem; color: var(--text); }
.label-required::after { content: ' *'; color: var(--danger); }
.form-group input, .form-group select, .form-group textarea {
  width: 100%; padding: .625rem .75rem; border: 1px solid var(--border); border-radius: var(--radius-sm);
  font-size: .875rem; color: var(--text); background: #fff; transition: border-color .15s, box-shadow .15s;
}
.form-group input:focus, .form-group select:focus, .form-group textarea:focus {
  outline: none; border-color: var(--primary-light); box-shadow: 0 0 0 3px rgba(79,174,72,.15);
}
.form-group input:disabled { background: #F5F7F5; color: var(--text-muted); }
.form-group textarea { min-height: 80px; resize: vertical; }
.form-hint { font-size: .75rem; color: var(--text-muted); margin-top: .375rem; }
.form-section-title { font-family: var(--font-heading); font-weight: 700; font-size: .9375rem; }
.color-swatch-row { display: flex; gap: .5rem; flex-wrap: wrap; }
.color-swatch { width: 28px; height: 28px; border-radius: 50%; cursor: pointer; border: 2px solid transparent; }
.color-swatch.selected { border-color: var(--text); box-shadow: 0 0 0 2px #fff inset; }
.icon-picker { display: flex; gap: .375rem; flex-wrap: wrap; max-height: 120px; overflow-y: auto; }
.icon-option { width: 34px; height: 34px; display: flex; align-items: center; justify-content: center; font-size: 1.15rem; border-radius: var(--radius-sm); border: 1px solid var(--border); background: #fff; cursor: pointer; }
.icon-option.selected { border-color: var(--primary); background: #EAF6EB; }

/* ── Tables ───────────────────────────────────────────────── */

.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: .875rem; }
thead th { text-align: left; font-size: .75rem; font-weight: 600; text-transform: uppercase; letter-spacing: .03em; color: var(--text-muted); padding: .75rem 1.25rem; border-bottom: 1px solid var(--border); white-space: nowrap; }
tbody td { padding: .8125rem 1.25rem; border-bottom: 1px solid var(--border); vertical-align: middle; }
tbody tr:last-child td { border-bottom: none; }
tbody tr:hover { background: #FAFCFA; }
th.sortable { cursor: pointer; user-select: none; }
th.sortable:hover { color: var(--text); }
.td-actions { display: flex; gap: .375rem; white-space: nowrap; }
.empty-state { text-align: center; padding: 2.5rem 1rem; color: var(--text-muted); }
.empty-state-icon { font-size: 2rem; margin-bottom: .5rem; }

.toolbar { display: flex; gap: .75rem; padding: 1rem 1.25rem; border-bottom: 1px solid var(--border); flex-wrap: wrap; align-items: center; }
.toolbar-search { flex: 1; min-width: 180px; max-width: 320px; }
.toolbar-search input { width: 100%; padding: .5625rem .75rem; border: 1px solid var(--border); border-radius: var(--radius-sm); font-size: .875rem; }
.toolbar select { padding: .5625rem .75rem; border: 1px solid var(--border); border-radius: var(--radius-sm); font-size: .875rem; background: #fff; }

/* ── Badges ───────────────────────────────────────────────── */

.badge { display: inline-flex; align-items: center; padding: .1875rem .625rem; border-radius: 999px; font-size: .75rem; font-weight: 600; }
.badge-green { background: #E6F4E8; color: var(--primary); }
.badge-red { background: var(--danger-bg); color: var(--danger); }
.badge-gold { background: #FDF1DC; color: #A56604; }
.badge-blue { background: #E4EEF6; color: var(--blue); }
.badge-teal { background: #E1F0F2; color: var(--teal); }
.badge-gray { background: #EEF1EF; color: var(--text-secondary); }

.amount { font-family: var(--font-heading); font-weight: 700; }
.amount.credit { color: var(--primary); }
.amount.debit { color: var(--danger); }

/* ── Category chip ───────────────────────────────────────── */

.category-chip { display: inline-flex; align-items: center; gap: .375rem; padding: .25rem .625rem .25rem .375rem; border-radius: 999px; font-size: .8125rem; font-weight: 600; }
.category-chip .cat-dot { width: 8px; height: 8px; border-radius: 50%; flex-shrink: 0; }

/* ── Modal ────────────────────────────────────────────────── */

.modal-overlay { position: fixed; inset: 0; background: rgba(40,60,64,.5); z-index: 300; display: flex; align-items: center; justify-content: center; padding: 1rem; }
.modal-box { background: #fff; border-radius: var(--radius-lg); max-width: 560px; width: 100%; max-height: 88vh; display: flex; flex-direction: column; box-shadow: var(--shadow-md); }
.modal-box.modal-lg { max-width: 760px; }
.modal-header { display: flex; justify-content: space-between; align-items: center; padding: 1.25rem 1.5rem; border-bottom: 1px solid var(--border); flex-shrink: 0; }
.modal-title { font-family: var(--font-heading); font-size: 1.125rem; font-weight: 700; }
.modal-close { background: none; border: none; font-size: 1.5rem; line-height: 1; cursor: pointer; color: var(--text-muted); padding: 0 .25rem; }
.modal-close:hover { color: var(--text); }
.modal-body { padding: 1.5rem; overflow-y: auto; flex: 1; min-height: 0; }
.modal-footer { display: flex; justify-content: flex-end; gap: .625rem; padding: 1.25rem 1.5rem; border-top: 1px solid var(--border); flex-shrink: 0; }

/* ── Toast ────────────────────────────────────────────────── */

.toast-container { position: fixed; bottom: 1.5rem; right: 1.5rem; z-index: 400; display: flex; flex-direction: column; gap: .5rem; }
.toast { background: var(--text); color: #fff; padding: .75rem 1.125rem; border-radius: var(--radius-sm); font-size: .875rem; box-shadow: var(--shadow-md); min-width: 220px; animation: toast-in .2s ease; }
.toast.error { background: var(--danger); }
.toast.success { background: var(--primary); }
@keyframes toast-in { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: translateY(0); } }

/* ── Tabs ─────────────────────────────────────────────────── */

.tabs { display: flex; border-bottom: 1px solid var(--border); margin-bottom: 1.25rem; gap: 1.5rem; overflow-x: auto; }
.tab-btn { background: none; border: none; padding: .625rem .125rem; font-size: .875rem; font-weight: 600; color: var(--text-secondary); cursor: pointer; border-bottom: 2px solid transparent; white-space: nowrap; }
.tab-btn.active { color: var(--primary); border-bottom-color: var(--primary); }
.tab-panel { display: none; }
.tab-panel.active { display: block; }

/* ── Charts ───────────────────────────────────────────────── */

.chart-wrap { padding: 1.25rem; }
.bar-row { display: flex; align-items: center; gap: .75rem; margin-bottom: .75rem; }
.bar-label { width: 110px; flex-shrink: 0; font-size: .8125rem; font-weight: 600; display: flex; align-items: center; gap: .375rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.bar-track { flex: 1; background: #F1F5F2; border-radius: 999px; height: 10px; overflow: hidden; min-width: 0; }
.bar-fill { height: 100%; border-radius: 999px; transition: width .4s ease; }
.bar-value { width: 90px; flex-shrink: 0; text-align: right; font-size: .8125rem; font-weight: 600; font-family: var(--font-heading); }

.trend-chart { display: flex; align-items: flex-end; gap: .625rem; height: 160px; padding: 0 .5rem; }
.trend-col { flex: 1; display: flex; flex-direction: column; align-items: center; gap: .375rem; height: 100%; justify-content: flex-end; min-width: 0; }
.trend-bars { display: flex; gap: 3px; align-items: flex-end; height: 100%; width: 100%; justify-content: center; }
.trend-bar { width: 40%; border-radius: 4px 4px 0 0; min-height: 2px; }
.trend-month { font-size: .6875rem; color: var(--text-muted); font-weight: 600; white-space: nowrap; }

.compare-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 1rem; margin-bottom: 1.25rem; }
.compare-card { background: #fff; border: 1px solid var(--border); border-radius: var(--radius); padding: 1.125rem; }
.compare-card .stat-label { display: flex; justify-content: space-between; align-items: center; }
.change-pill { font-size: .75rem; font-weight: 700; padding: .125rem .5rem; border-radius: 999px; }
.change-pill.up { background: #E6F4E8; color: var(--primary); }
.change-pill.down { background: var(--danger-bg); color: var(--danger); }
.change-pill.flat { background: #EEF1EF; color: var(--text-secondary); }

.progress-track { background: #F1F5F2; border-radius: 999px; height: 8px; overflow: hidden; margin-top: .5rem; }
.progress-fill { height: 100%; border-radius: 999px; }

/* ── Breadcrumb / misc ────────────────────────────────────── */

.breadcrumb { font-size: .8125rem; color: var(--text-muted); margin-bottom: .75rem; display: flex; align-items: center; gap: .375rem; }
.breadcrumb-sep { color: var(--text-muted); }
.text-muted { color: var(--text-muted); }
.alert { padding: .75rem 1rem; border-radius: var(--radius-sm); font-size: .875rem; margin-bottom: 1rem; }
.alert-error { background: var(--danger-bg); color: var(--danger); }
.alert-success { background: #E6F4E8; color: var(--primary-dark); }
.alert-warning { background: #FDF1DC; color: #8A5A00; }

/* ── Auth pages ───────────────────────────────────────────── */

.login-body { background: var(--bg); min-height: 100vh; min-height: 100dvh; display: flex; }
.login-wrap { flex: 1; display: flex; align-items: center; justify-content: center; padding: 1.5rem; }
.login-card { background: #fff; border-radius: var(--radius-lg); box-shadow: var(--shadow-md); padding: 2.25rem; max-width: 400px; width: 100%; }
.login-logo { display: flex; align-items: center; gap: .625rem; }
.login-logo img { width: 96px; }
.login-card h1 { font-size: 1.375rem; text-align: center; margin-bottom: .375rem; }
.login-tagline { text-align: center; color: var(--text-secondary); font-size: .875rem; margin-bottom: 1.5rem; }
.login-hint { text-align: center; font-size: .8125rem; color: var(--text-secondary); margin-top: 1.25rem; }
.login-error { background: var(--danger-bg); color: var(--danger); padding: .625rem .875rem; border-radius: var(--radius-sm); font-size: .8125rem; margin-bottom: 1rem; display: none; }
.login-error.show { display: block; }

/* ── Responsive ───────────────────────────────────────────── */

@media (max-width: 900px) {
  .stats-grid { grid-template-columns: repeat(2, 1fr); }
  .compare-grid { grid-template-columns: 1fr; }
}

@media (max-width: 768px) {
  .mobile-topbar { display: flex; }
  .btn-sidebar-close { display: flex; }

  .sidebar {
    position: fixed !important;
    top: 0; left: 0;
    width: 260px !important;
    height: 100vh;
    height: 100dvh;
    transform: translateX(-100%);
    transition: transform .25s ease;
    z-index: 200;
  }
  .sidebar.open { transform: translateX(0); }

  .main { margin-left: 0; flex-direction: column; }
  .content { padding: 1rem; }

  .form-row { grid-template-columns: 1fr; }
  .stats-grid { grid-template-columns: repeat(2, 1fr); gap: .625rem; }

  .page-header { flex-direction: column; align-items: flex-start; gap: .5rem; }

  .toolbar { gap: .5rem; padding: .75rem 1rem; }
  .toolbar-search { max-width: 100%; min-width: 0; flex: 1 1 140px; }

  .modal-overlay { padding: 0; align-items: flex-end; }
  .modal-box { max-width: 100% !important; max-height: 92vh; border-radius: var(--radius) var(--radius) 0 0; }
  .modal-body { padding: 1rem; }
  .modal-header { padding: 1rem; }
  .modal-footer { padding: .875rem 1rem; }

  .toast-container { right: .75rem; left: .75rem; bottom: .75rem; }
  .toast { max-width: 100%; min-width: auto; }

  .card-header { flex-wrap: wrap; gap: .5rem; }
  .btn-sm { padding: .2rem .5rem; font-size: .75rem; }
  .tabs { overflow-x: auto; -webkit-overflow-scrolling: touch; }
  .login-wrap { padding: .75rem; }
  .bar-label { width: 80px; }
  .bar-value { width: 70px; }
}

@media (max-width: 480px) {
  .stats-grid { grid-template-columns: 1fr; }
  .login-card { padding: 1.5rem; }
}
