/* ============================================================
   VARIABLES & RESET
   ============================================================ */
:root {
  --primary:       #7C3AED;
  --primary-dark:  #6D28D9;
  --primary-light: #EDE9FE;
  --secondary:     #EC4899;
  --success:       #10B981;
  --warning:       #F59E0B;
  --danger:        #EF4444;
  --info:          #3B82F6;

  --bg:            #F1F5F9;
  --card:          #FFFFFF;
  --text:          #1E293B;
  --text-muted:    #64748B;
  --border:        #E2E8F0;
  --shadow:        0 1px 3px rgba(0,0,0,.08), 0 1px 2px rgba(0,0,0,.05);
  --shadow-md:     0 4px 6px -1px rgba(0,0,0,.1), 0 2px 4px -2px rgba(0,0,0,.1);
  --radius:        12px;
  --radius-sm:     8px;

  --sidebar-w:     240px;
  --header-h:      56px;
  --bnav-h:        64px;
}

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

html { font-size: 16px; -webkit-tap-highlight-color: transparent; }

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
  min-height: 100vh;
}

input, select, button, textarea { font-family: inherit; font-size: inherit; }
button { cursor: pointer; border: none; background: none; }
a { text-decoration: none; color: inherit; }

/* ============================================================
   UTILITIES
   ============================================================ */
.hidden   { display: none !important; }
.mt-8     { margin-top: 8px; }
.mt-16    { margin-top: 16px; }
.fw-600   { font-weight: 600; }
.text-muted { color: var(--text-muted); font-size: .875rem; }
.text-success { color: var(--success); }
.text-danger  { color: var(--danger); }
.text-warning { color: var(--warning); }
.text-primary { color: var(--primary); }

/* ============================================================
   BUTTONS
   ============================================================ */
.btn-primary {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  padding: 10px 20px; border-radius: var(--radius-sm);
  background: var(--primary); color: #fff; font-weight: 600;
  transition: background .15s, transform .1s;
}
.btn-primary:hover  { background: var(--primary-dark); }
.btn-primary:active { transform: scale(.97); }

.btn-outline {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  padding: 10px 20px; border-radius: var(--radius-sm);
  border: 1.5px solid var(--border); color: var(--text); font-weight: 500;
  transition: border-color .15s, background .15s;
}
.btn-outline:hover { border-color: var(--primary); color: var(--primary); background: var(--primary-light); }

.btn-ghost {
  display: inline-flex; align-items: center; justify-content: center;
  padding: 6px 12px; border-radius: var(--radius-sm);
  color: var(--text-muted); font-weight: 500;
  transition: background .15s, color .15s;
}
.btn-ghost:hover { background: var(--bg); color: var(--text); }

.btn-danger {
  display: inline-flex; align-items: center; justify-content: center;
  padding: 10px 20px; border-radius: var(--radius-sm);
  background: var(--danger); color: #fff; font-weight: 600;
  transition: opacity .15s;
}
.btn-danger:hover { opacity: .88; }

.btn-icon {
  display: inline-flex; align-items: center; justify-content: center;
  width: 32px; height: 32px; border-radius: 50%;
  color: var(--text-muted); transition: background .15s, color .15s;
}
.btn-icon:hover { background: var(--bg); color: var(--text); }

.btn-full { width: 100%; }
.btn-sm   { padding: 6px 12px; font-size: .875rem; }
.btn-lg   { padding: 13px 24px; font-size: 1rem; }

/* ============================================================
   LOGIN
   ============================================================ */
#screen-login {
  min-height: 100vh; display: flex; align-items: center; justify-content: center;
  background: linear-gradient(135deg, #7C3AED 0%, #EC4899 100%);
  padding: 20px;
}

.login-wrap {
  background: var(--card); border-radius: 20px; padding: 40px 36px;
  width: 100%; max-width: 380px; box-shadow: var(--shadow-md);
  text-align: center;
}

.login-logo { font-size: 3rem; margin-bottom: 8px; }
.login-title { font-size: 1.5rem; font-weight: 700; color: var(--text); }
.login-sub   { color: var(--text-muted); font-size: .9rem; margin-bottom: 28px; }
.login-form  { text-align: left; }

/* ============================================================
   FORMS / FIELDS
   ============================================================ */
.field { display: flex; flex-direction: column; gap: 6px; margin-bottom: 16px; }
.field label { font-size: .875rem; font-weight: 600; color: var(--text); }

.field input[type="text"],
.field input[type="number"],
.field input[type="date"],
.field input[type="password"],
.field select {
  width: 100%; padding: 10px 14px; border: 1.5px solid var(--border);
  border-radius: var(--radius-sm); background: var(--card); color: var(--text);
  transition: border-color .15s, box-shadow .15s;
  -webkit-appearance: none;
}
.field input:focus, .field select:focus {
  outline: none; border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(124,58,237,.12);
}

.field-row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }

.input-pre {
  display: flex; align-items: center;
  border: 1.5px solid var(--border); border-radius: var(--radius-sm);
  background: var(--card); overflow: hidden;
  transition: border-color .15s, box-shadow .15s;
}
.input-pre:focus-within {
  border-color: var(--primary); box-shadow: 0 0 0 3px rgba(124,58,237,.12);
}
.input-pre span {
  padding: 10px 12px; color: var(--text-muted); font-weight: 500;
  background: var(--bg); border-right: 1.5px solid var(--border); white-space: nowrap;
}
.input-pre input {
  border: none !important; box-shadow: none !important;
  border-radius: 0 !important; flex: 1; padding: 10px 12px;
}

.input-color {
  width: 100%; height: 42px; padding: 4px; border: 1.5px solid var(--border);
  border-radius: var(--radius-sm); cursor: pointer;
}

.error-msg { color: var(--danger); font-size: .85rem; min-height: 20px; margin-bottom: 8px; }

/* Toggle switch */
.toggle-row {
  display: flex; justify-content: space-between; align-items: flex-start;
  cursor: pointer; gap: 12px;
}
.toggle-lbl { font-size: .875rem; font-weight: 600; }
.toggle-hint { font-size: .8rem; color: var(--text-muted); margin-top: 2px; }

.toggle-sw { position: relative; display: inline-block; width: 46px; height: 26px; flex-shrink: 0; }
.toggle-sw input { opacity: 0; width: 0; height: 0; }
.sw-track {
  position: absolute; inset: 0; border-radius: 13px;
  background: var(--border); cursor: pointer;
  transition: background .2s;
}
.sw-track::before {
  content: ''; position: absolute; width: 20px; height: 20px; border-radius: 50%;
  background: #fff; top: 3px; left: 3px;
  transition: transform .2s; box-shadow: 0 1px 3px rgba(0,0,0,.2);
}
.toggle-sw input:checked + .sw-track { background: var(--primary); }
.toggle-sw input:checked + .sw-track::before { transform: translateX(20px); }

/* ============================================================
   APP SHELL
   ============================================================ */
#screen-app {
  display: flex; min-height: 100vh;
}

/* Sidebar */
#sidebar {
  width: var(--sidebar-w); background: var(--card); border-right: 1px solid var(--border);
  display: flex; flex-direction: column; position: fixed; top: 0; left: 0; height: 100vh;
  z-index: 100;
}
.sb-brand {
  display: flex; align-items: center; gap: 10px;
  padding: 20px 20px 16px; border-bottom: 1px solid var(--border);
}
.sb-logo  { font-size: 1.5rem; }
.sb-name  { font-size: 1rem; font-weight: 700; color: var(--text); }
.sb-nav   { flex: 1; padding: 12px 10px; display: flex; flex-direction: column; gap: 2px; }
.nav-item {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 12px; border-radius: var(--radius-sm);
  color: var(--text-muted); font-weight: 500; font-size: .9rem;
  text-align: left; width: 100%;
  transition: background .15s, color .15s;
}
.nav-item span { font-size: 1.1rem; }
.nav-item:hover  { background: var(--bg); color: var(--text); }
.nav-item.active { background: var(--primary-light); color: var(--primary); font-weight: 600; }
.sb-footer {
  padding: 16px 20px; border-top: 1px solid var(--border);
  display: flex; align-items: center; justify-content: space-between;
}
.sb-user-name { font-size: .875rem; font-weight: 600; color: var(--text-muted); }

/* Mobile header */
#mobile-header {
  display: none; position: fixed; top: 0; left: 0; right: 0; height: var(--header-h);
  background: var(--card); border-bottom: 1px solid var(--border);
  align-items: center; justify-content: space-between; padding: 0 16px; z-index: 100;
}
.mh-logo  { font-size: 1.3rem; }
#mh-title { font-size: 1rem; font-weight: 700; }

/* Main content */
#main-content {
  flex: 1; margin-left: var(--sidebar-w);
  padding: 24px; min-height: 100vh;
}

/* Bottom nav */
#bottom-nav {
  display: none; position: fixed; bottom: 0; left: 0; right: 0; height: var(--bnav-h);
  background: var(--card); border-top: 1px solid var(--border);
  align-items: center; justify-content: space-around; z-index: 100;
}
.bnav-item {
  display: flex; flex-direction: column; align-items: center; gap: 2px;
  padding: 6px 12px; border-radius: var(--radius-sm); flex: 1;
  color: var(--text-muted); font-size: 1.2rem;
  transition: color .15s;
}
.bnav-item small { font-size: .65rem; font-weight: 500; }
.bnav-item.active { color: var(--primary); }

/* FAB */
#fab {
  position: fixed; bottom: calc(var(--bnav-h) + 16px); right: 20px;
  width: 56px; height: 56px; border-radius: 50%;
  background: linear-gradient(135deg, var(--primary), var(--secondary));
  color: #fff; font-size: 1.8rem; line-height: 1;
  box-shadow: 0 4px 12px rgba(124,58,237,.4);
  display: flex; align-items: center; justify-content: center;
  z-index: 200; transition: transform .15s, box-shadow .15s;
}
#fab:hover  { transform: scale(1.07); box-shadow: 0 6px 20px rgba(124,58,237,.5); }
#fab:active { transform: scale(.95); }

/* ============================================================
   CARDS
   ============================================================ */
.card {
  background: var(--card); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 20px;
}
.card-sm { padding: 14px 16px; }
.card-title { font-size: .75rem; font-weight: 600; text-transform: uppercase; letter-spacing: .05em; color: var(--text-muted); margin-bottom: 4px; }
.card-value { font-size: 1.6rem; font-weight: 700; }
.card-sub   { font-size: .8rem; color: var(--text-muted); margin-top: 4px; }

/* ============================================================
   SUMMARY GRID
   ============================================================ */
.summary-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 16px; margin-bottom: 20px; }

.summary-card {
  background: var(--card); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 18px 20px;
  border-left: 4px solid transparent;
}
.summary-card.c-primary  { border-color: var(--primary); }
.summary-card.c-info     { border-color: var(--info); }
.summary-card.c-success  { border-color: var(--success); }
.summary-card.c-warning  { border-color: var(--warning); }
.summary-card.c-secondary{ border-color: var(--secondary); }
.summary-card.c-danger   { border-color: var(--danger); }

/* ============================================================
   PAGE HEADER
   ============================================================ */
.page-hd {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 20px; flex-wrap: wrap; gap: 12px;
}
.page-title { font-size: 1.4rem; font-weight: 700; }

.month-nav {
  display: flex; align-items: center; gap: 8px;
  background: var(--card); border-radius: var(--radius-sm);
  box-shadow: var(--shadow); padding: 6px 12px;
}
.month-nav button { color: var(--text-muted); font-size: 1.1rem; padding: 2px 6px; border-radius: 4px; }
.month-nav button:hover { background: var(--bg); color: var(--text); }
.month-label { font-weight: 600; font-size: .9rem; min-width: 110px; text-align: center; }

/* ============================================================
   EXPENSE LIST
   ============================================================ */
.expense-list { display: flex; flex-direction: column; gap: 8px; }

.expense-item {
  display: flex; align-items: center; gap: 12px;
  background: var(--card); border-radius: var(--radius-sm);
  box-shadow: var(--shadow); padding: 12px 16px;
  transition: box-shadow .15s;
}
.expense-item:hover { box-shadow: var(--shadow-md); }

.exp-icon {
  width: 40px; height: 40px; border-radius: 10px;
  display: flex; align-items: center; justify-content: center;
  font-size: 1.2rem; flex-shrink: 0;
}
.exp-info { flex: 1; min-width: 0; }
.exp-desc { font-weight: 600; font-size: .9rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.exp-meta { font-size: .78rem; color: var(--text-muted); display: flex; gap: 8px; align-items: center; margin-top: 2px; }
.exp-date { }
.exp-badge {
  display: inline-flex; align-items: center; gap: 3px;
  padding: 1px 7px; border-radius: 12px; font-size: .7rem; font-weight: 600;
}
.badge-shared { background: #EDE9FE; color: var(--primary); }
.badge-own    { background: #F1F5F9; color: var(--text-muted); }

.exp-right { display: flex; flex-direction: column; align-items: flex-end; gap: 4px; flex-shrink: 0; }
.exp-amount { font-weight: 700; font-size: .95rem; }
.exp-actions { display: flex; gap: 2px; opacity: 0; transition: opacity .15s; }
.expense-item:hover .exp-actions { opacity: 1; }

/* ============================================================
   BALANCE CARD
   ============================================================ */
.balance-card {
  background: linear-gradient(135deg, var(--primary) 0%, var(--secondary) 100%);
  border-radius: var(--radius); padding: 24px; color: #fff; margin-bottom: 20px;
  box-shadow: 0 4px 15px rgba(124,58,237,.3);
}
.balance-card .bc-label { font-size: .8rem; font-weight: 600; opacity: .85; text-transform: uppercase; letter-spacing: .05em; }
.balance-card .bc-amount { font-size: 2.2rem; font-weight: 800; margin: 4px 0; }
.balance-card .bc-desc   { font-size: .9rem; opacity: .9; }
.balance-card.balanced   { background: linear-gradient(135deg, #10B981, #059669); }

/* Daily budget */
.daily-card {
  background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow);
  padding: 20px; margin-bottom: 20px;
}
.daily-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 16px; }
.daily-title  { font-weight: 700; font-size: 1rem; }
.daily-amount { font-size: 2rem; font-weight: 800; color: var(--primary); margin-bottom: 4px; }
.daily-sub    { font-size: .82rem; color: var(--text-muted); }

.progress-bar { height: 8px; background: var(--bg); border-radius: 4px; overflow: hidden; margin-top: 12px; }
.progress-fill { height: 100%; border-radius: 4px; background: var(--primary); transition: width .3s ease; }
.progress-fill.warn { background: var(--warning); }
.progress-fill.danger { background: var(--danger); }

/* ============================================================
   CHARTS
   ============================================================ */
.charts-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 20px; margin-bottom: 20px; }
.chart-card  { background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); padding: 20px; }
.chart-card.full-width { grid-column: 1 / -1; }
.chart-title { font-weight: 700; font-size: 1rem; margin-bottom: 16px; }
.chart-wrap  { position: relative; height: 260px; }

.insights-list { display: flex; flex-direction: column; gap: 10px; margin-top: 8px; }
.insight-item {
  display: flex; align-items: center; gap: 12px;
  padding: 12px 16px; border-radius: var(--radius-sm); border: 1.5px solid var(--border);
}
.insight-icon { font-size: 1.4rem; }
.insight-text { flex: 1; }
.insight-text strong { font-size: .9rem; }
.insight-text span { font-size: .8rem; color: var(--text-muted); display: block; margin-top: 1px; }
.insight-badge {
  padding: 3px 10px; border-radius: 12px; font-size: .75rem; font-weight: 700;
}
.insight-up   { background: #FEE2E2; color: var(--danger); }
.insight-down { background: #D1FAE5; color: var(--success); }
.insight-new  { background: #EDE9FE; color: var(--primary); }

/* ============================================================
   SETTINGS
   ============================================================ */
.settings-section { background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); padding: 24px; margin-bottom: 20px; }
.settings-title   { font-size: 1.1rem; font-weight: 700; margin-bottom: 20px; padding-bottom: 12px; border-bottom: 1px solid var(--border); }

.salary-row { display: flex; align-items: center; gap: 16px; padding: 14px 0; border-bottom: 1px solid var(--border); }
.salary-row:last-child { border-bottom: none; }
.salary-name  { flex: 1; font-weight: 600; }
.salary-ratio { font-size: .8rem; color: var(--text-muted); }
.salary-input-wrap { display: flex; align-items: center; gap: 8px; }

.cat-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); gap: 10px; }
.cat-chip {
  display: flex; align-items: center; gap: 8px;
  padding: 10px 12px; border-radius: var(--radius-sm); border: 1.5px solid var(--border);
  font-weight: 500; font-size: .875rem;
}
.cat-chip-dot { width: 10px; height: 10px; border-radius: 50%; flex-shrink: 0; }
.cat-chip-del { margin-left: auto; color: var(--text-muted); font-size: .8rem; padding: 2px 6px; border-radius: 4px; }
.cat-chip-del:hover { background: #FEE2E2; color: var(--danger); }

/* ============================================================
   RECURRING LIST
   ============================================================ */
.recurring-item {
  display: flex; align-items: center; gap: 12px;
  background: var(--card); border-radius: var(--radius-sm); box-shadow: var(--shadow);
  padding: 14px 16px; margin-bottom: 8px;
}
.rec-icon { font-size: 1.3rem; width: 40px; text-align: center; }
.rec-info  { flex: 1; }
.rec-desc  { font-weight: 600; font-size: .9rem; }
.rec-meta  { font-size: .78rem; color: var(--text-muted); margin-top: 2px; }
.rec-right { display: flex; align-items: center; gap: 10px; flex-shrink: 0; }
.rec-amount { font-weight: 700; font-size: .95rem; }
.rec-inactive { opacity: .45; }

/* ============================================================
   MODALS
   ============================================================ */
.modal-overlay {
  position: fixed; inset: 0; background: rgba(0,0,0,.55);
  display: flex; align-items: flex-end; justify-content: center;
  z-index: 500;
}
@media (min-width: 600px) {
  .modal-overlay { align-items: center; }
}

.modal-sheet {
  background: var(--card); border-radius: 20px 20px 0 0;
  padding: 24px; width: 100%; max-width: 480px;
  max-height: 92vh; overflow-y: auto;
  animation: slideUp .22s ease-out;
}
@media (min-width: 600px) {
  .modal-sheet { border-radius: 20px; }
}
.modal-sm { max-width: 380px; }

@keyframes slideUp {
  from { transform: translateY(30px); opacity: 0; }
  to   { transform: translateY(0);    opacity: 1; }
}

.modal-hd {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 20px;
}
.modal-hd h2 { font-size: 1.1rem; font-weight: 700; }
.modal-x {
  width: 30px; height: 30px; border-radius: 50%;
  background: var(--bg); color: var(--text-muted); font-size: 1rem;
  display: flex; align-items: center; justify-content: center;
  transition: background .15s;
}
.modal-x:hover { background: var(--border); }

.confirm-text { color: var(--text-muted); font-size: .9rem; margin-bottom: 4px; }

/* ============================================================
   TOAST
   ============================================================ */
.toast {
  position: fixed; bottom: calc(var(--bnav-h) + 16px); left: 50%;
  transform: translateX(-50%);
  background: #1E293B; color: #fff;
  padding: 10px 20px; border-radius: 20px;
  font-size: .875rem; font-weight: 500;
  z-index: 9999; box-shadow: var(--shadow-md);
  animation: fadeIn .2s ease;
}
@media (min-width: 768px) {
  .toast { bottom: 24px; }
}
@keyframes fadeIn { from { opacity: 0; transform: translateX(-50%) translateY(8px); } }

/* ============================================================
   SECTION HEADERS / MISC
   ============================================================ */
.sec-hd { display: flex; align-items: center; justify-content: space-between; margin-bottom: 14px; }
.sec-title { font-weight: 700; font-size: 1rem; }

.empty-state {
  text-align: center; padding: 48px 24px; color: var(--text-muted);
}
.empty-state .es-icon { font-size: 3rem; margin-bottom: 12px; }
.empty-state p { font-size: .9rem; }

.tag {
  display: inline-flex; align-items: center; gap: 4px;
  padding: 3px 10px; border-radius: 12px; font-size: .75rem; font-weight: 600;
}

/* ============================================================
   RESPONSIVE
   ============================================================ */
@media (max-width: 1024px) {
  .summary-grid { grid-template-columns: repeat(2, 1fr); }
  .charts-grid  { grid-template-columns: 1fr; }
}

@media (max-width: 768px) {
  #sidebar        { display: none; }
  #mobile-header  { display: flex; }
  #bottom-nav     { display: flex; }
  #main-content   { margin-left: 0; padding: 16px; padding-top: calc(var(--header-h) + 16px); padding-bottom: calc(var(--bnav-h) + 16px); }
  #fab            { bottom: calc(var(--bnav-h) + 16px); }
  .summary-grid   { grid-template-columns: repeat(2, 1fr); gap: 12px; }
  .page-title     { font-size: 1.2rem; }
  .card-value     { font-size: 1.35rem; }
  .balance-card .bc-amount { font-size: 1.8rem; }
  .charts-grid    { grid-template-columns: 1fr; }
  .field-row      { grid-template-columns: 1fr 1fr; }
}

@media (max-width: 400px) {
  .summary-grid { grid-template-columns: 1fr 1fr; gap: 8px; }
  .field-row    { grid-template-columns: 1fr; }
}
