/* ===== Reset & Base ===== */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg: #0f1117;
  --bg2: #1a1d27;
  --bg3: #22263a;
  --border: #2e3352;
  --accent: #6c63ff;
  --accent2: #4ecdc4;
  --income: #2ecc71;
  --expense: #e74c3c;
  --text: #e8eaf0;
  --text2: #8b93b8;
  --sidebar-w: 240px;
  --radius: 12px;
  --shadow: 0 4px 24px rgba(0,0,0,0.4);
}

body {
  font-family: 'Segoe UI', 'Hiragino Sans', 'Yu Gothic', sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  line-height: 1.6;
}

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ===== Auth Pages ===== */
.auth-page {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  background: var(--bg);
}

.auth-card {
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 40px 36px;
  width: 100%;
  max-width: 400px;
  box-shadow: var(--shadow);
}

.auth-logo { font-size: 40px; text-align: center; display: block; margin-bottom: 8px; }
.auth-title { font-size: 24px; font-weight: 700; text-align: center; }
.auth-subtitle { color: var(--text2); text-align: center; margin-bottom: 28px; }
.auth-link { text-align: center; margin-top: 20px; color: var(--text2); }

.error-banner {
  background: rgba(231,76,60,0.15);
  border: 1px solid rgba(231,76,60,0.4);
  color: #ff6b6b;
  border-radius: 8px;
  padding: 10px 14px;
  margin-bottom: 16px;
  font-size: 13px;
}

/* ===== Form ===== */
.form-group { margin-bottom: 16px; }
.form-group label { display: block; font-size: 12px; color: var(--text2); margin-bottom: 6px; font-weight: 500; text-transform: uppercase; letter-spacing: 0.05em; }

input[type=text], input[type=email], input[type=password],
input[type=number], input[type=date], select, textarea {
  width: 100%;
  background: var(--bg3);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px 12px;
  color: var(--text);
  font-size: 14px;
  transition: border-color 0.2s;
  font-family: inherit;
}

input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--accent);
}

select option { background: var(--bg3); }
textarea { resize: vertical; min-height: 80px; }

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

/* ===== Buttons ===== */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 9px 18px;
  border-radius: 8px;
  border: none;
  cursor: pointer;
  font-size: 14px;
  font-weight: 500;
  transition: opacity 0.15s, transform 0.1s;
  font-family: inherit;
}
.btn:hover { opacity: 0.85; }
.btn:active { transform: scale(0.97); }
.btn-primary { background: var(--accent); color: #fff; }
.btn-success { background: var(--income); color: #fff; }
.btn-danger { background: var(--expense); color: #fff; }
.btn-ghost { background: var(--bg3); color: var(--text); border: 1px solid var(--border); }
.btn-full { width: 100%; justify-content: center; padding: 12px; font-size: 15px; }
.btn-sm { padding: 5px 12px; font-size: 12px; }
.btn-icon {
  background: var(--bg3);
  border: 1px solid var(--border);
  color: var(--text);
  width: 32px; height: 32px;
  border-radius: 8px;
  cursor: pointer;
  font-size: 18px;
  display: flex; align-items: center; justify-content: center;
  transition: background 0.2s;
  flex-shrink: 0;
}
.btn-icon:hover { background: var(--border); }

/* ===== Layout ===== */
.sidebar {
  position: fixed;
  top: 0; left: 0;
  width: var(--sidebar-w);
  height: 100vh;
  background: var(--bg2);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  z-index: 100;
  transition: transform 0.25s ease;
}

.sidebar-header {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 20px 16px 16px;
  border-bottom: 1px solid var(--border);
}
.sidebar-logo { font-size: 24px; }
.sidebar-title { font-size: 18px; font-weight: 700; flex: 1; }
.sidebar-close { display: none; background: none; border: none; color: var(--text2); font-size: 18px; cursor: pointer; }

.household-selector {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
}
.household-selector select { flex: 1; padding: 7px 10px; font-size: 13px; }

.sidebar-nav { flex: 1; padding: 12px 8px; overflow-y: auto; }
.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border-radius: 8px;
  color: var(--text2);
  font-size: 14px;
  transition: background 0.15s, color 0.15s;
  margin-bottom: 2px;
}
.nav-item:hover { background: var(--bg3); color: var(--text); text-decoration: none; }
.nav-item.active { background: rgba(108,99,255,0.15); color: var(--accent); font-weight: 600; }

.sidebar-footer {
  padding: 14px 16px;
  border-top: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 13px;
  color: var(--text2);
}
.logout-link { color: var(--text2); font-size: 12px; }
.logout-link:hover { color: var(--expense); }

.overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.5);
  z-index: 99;
}

.main-wrapper {
  margin-left: var(--sidebar-w);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

.topbar {
  position: sticky;
  top: 0;
  background: var(--bg2);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 14px 24px;
  z-index: 50;
}
.menu-btn {
  display: none;
  background: none;
  border: none;
  color: var(--text);
  font-size: 20px;
  cursor: pointer;
}
.page-title { font-size: 18px; font-weight: 700; flex: 1; }
.topbar-actions { display: flex; gap: 8px; }

.content { padding: 24px; flex: 1; }

/* ===== Cards & Grid ===== */
.card {
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
}

.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.grid-3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 16px; }
.grid-4 { display: grid; grid-template-columns: repeat(4,1fr); gap: 16px; }

/* ===== Dashboard ===== */
.summary-cards { display: grid; grid-template-columns: repeat(3, 1fr); gap: 16px; margin-bottom: 24px; }

.summary-card {
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px 24px;
}
.summary-card .label { font-size: 12px; color: var(--text2); text-transform: uppercase; letter-spacing: 0.05em; margin-bottom: 8px; }
.summary-card .amount { font-size: 26px; font-weight: 700; }
.summary-card.income .amount { color: var(--income); }
.summary-card.expense .amount { color: var(--expense); }
.summary-card.balance .amount { color: var(--accent); }

.charts-row { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; margin-bottom: 24px; }
.chart-card { background: var(--bg2); border: 1px solid var(--border); border-radius: var(--radius); padding: 20px; }
.chart-card h3 { font-size: 14px; color: var(--text2); margin-bottom: 16px; }
.chart-wrap { position: relative; height: 220px; }

.month-nav {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 20px;
}
.month-nav .month-label { font-size: 18px; font-weight: 700; flex: 1; }

/* ===== Transactions ===== */
.tx-filters {
  display: flex;
  gap: 10px;
  margin-bottom: 16px;
  flex-wrap: wrap;
  align-items: flex-end;
}
.tx-filters select, .tx-filters input { width: auto; }

.tx-table-wrap { background: var(--bg2); border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; }
.tx-table { width: 100%; border-collapse: collapse; }
.tx-table th {
  background: var(--bg3);
  padding: 10px 14px;
  text-align: left;
  font-size: 12px;
  color: var(--text2);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  border-bottom: 1px solid var(--border);
}
.tx-table td {
  padding: 12px 14px;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}
.tx-table tr:last-child td { border-bottom: none; }
.tx-table tr:hover td { background: var(--bg3); }

.tx-amount { font-weight: 600; font-size: 15px; }
.tx-amount.income { color: var(--income); }
.tx-amount.expense { color: var(--expense); }

.category-badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 2px 8px;
  border-radius: 20px;
  font-size: 12px;
  font-weight: 500;
}

.tx-actions { display: flex; gap: 6px; opacity: 0; transition: opacity 0.15s; }
.tx-table tr:hover .tx-actions { opacity: 1; }

/* ===== Accounts ===== */
.accounts-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 16px; }
.account-card {
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  border-left: 4px solid var(--accent);
  position: relative;
}
.account-card .acc-label { font-size: 11px; color: var(--text2); text-transform: uppercase; margin-bottom: 6px; }
.account-card .acc-name { font-size: 15px; font-weight: 600; margin-bottom: 12px; }
.account-card .acc-balance { font-size: 22px; font-weight: 700; }
.account-card .acc-balance.positive { color: var(--income); }
.account-card .acc-balance.negative { color: var(--expense); }
.account-card .acc-actions { position: absolute; top: 12px; right: 12px; display: flex; gap: 6px; opacity: 0; transition: opacity 0.15s; }
.account-card:hover .acc-actions { opacity: 1; }
.acc-tag {
  display: inline-block;
  font-size: 11px;
  padding: 2px 8px;
  border-radius: 20px;
  background: var(--bg3);
  color: var(--text2);
  margin-top: 8px;
}

/* ===== Budgets ===== */
.budget-list { display: flex; flex-direction: column; gap: 12px; }
.budget-item {
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px 20px;
}
.budget-item .budget-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 10px; }
.budget-item .budget-name { font-weight: 600; font-size: 15px; }
.budget-item .budget-amounts { font-size: 13px; color: var(--text2); }
.budget-item .budget-amounts span { color: var(--text); font-weight: 600; }
.progress-bar { height: 8px; background: var(--bg3); border-radius: 4px; overflow: hidden; }
.progress-fill { height: 100%; border-radius: 4px; transition: width 0.4s ease; }
.progress-fill.ok { background: var(--accent2); }
.progress-fill.warn { background: #f39c12; }
.progress-fill.over { background: var(--expense); }

/* ===== Recurring ===== */
.recurring-list { display: flex; flex-direction: column; gap: 10px; }
.recurring-item {
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 18px;
  display: flex;
  align-items: center;
  gap: 14px;
}
.recurring-item.inactive { opacity: 0.5; }
.recurring-item .rec-icon { font-size: 24px; }
.recurring-item .rec-info { flex: 1; }
.recurring-item .rec-name { font-weight: 600; }
.recurring-item .rec-meta { font-size: 12px; color: var(--text2); }
.recurring-item .rec-amount { font-size: 16px; font-weight: 700; }
.recurring-item .rec-amount.expense { color: var(--expense); }
.recurring-item .rec-amount.income { color: var(--income); }

/* ===== Reports ===== */
.report-year-nav { display: flex; align-items: center; gap: 12px; margin-bottom: 20px; }
.report-year-nav .year-label { font-size: 20px; font-weight: 700; }

.yearly-table { width: 100%; border-collapse: collapse; }
.yearly-table th, .yearly-table td {
  padding: 10px 12px;
  text-align: right;
  border-bottom: 1px solid var(--border);
  font-size: 13px;
}
.yearly-table th:first-child, .yearly-table td:first-child { text-align: left; }
.yearly-table th { background: var(--bg3); color: var(--text2); font-size: 12px; }
.yearly-table tfoot td { font-weight: 700; background: var(--bg3); }

/* ===== Settings ===== */
.settings-section { margin-bottom: 32px; }
.settings-section h3 { font-size: 15px; font-weight: 700; margin-bottom: 16px; padding-bottom: 8px; border-bottom: 1px solid var(--border); }
.member-list { display: flex; flex-direction: column; gap: 8px; }
.member-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 14px;
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: 8px;
}
.member-avatar {
  width: 36px; height: 36px;
  border-radius: 50%;
  background: var(--accent);
  display: flex; align-items: center; justify-content: center;
  font-weight: 700;
  font-size: 14px;
}
.member-item .member-info { flex: 1; }
.member-item .member-name { font-weight: 600; }
.member-item .member-role { font-size: 12px; color: var(--text2); }

.cat-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(160px,1fr)); gap: 10px; }
.cat-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 12px;
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 13px;
}
.cat-item .cat-dot { width: 10px; height: 10px; border-radius: 50%; flex-shrink: 0; }
.cat-item .cat-name { flex: 1; }
.cat-item .cat-del { background: none; border: none; color: var(--text2); cursor: pointer; font-size: 16px; opacity: 0; transition: opacity 0.15s; }
.cat-item:hover .cat-del { opacity: 1; }

/* ===== Modal ===== */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.6);
  z-index: 200;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}
.modal {
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  width: 100%;
  max-width: 480px;
  max-height: 90vh;
  overflow-y: auto;
  box-shadow: var(--shadow);
}
.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 18px 20px;
  border-bottom: 1px solid var(--border);
}
.modal-header h3 { font-size: 16px; font-weight: 700; }
.modal-close { background: none; border: none; color: var(--text2); font-size: 20px; cursor: pointer; }
.modal-body { padding: 20px; }
.modal-footer { display: flex; gap: 10px; justify-content: flex-end; padding-top: 16px; border-top: 1px solid var(--border); margin-top: 16px; }

/* ===== Type toggle ===== */
.type-toggle { display: flex; gap: 0; border-radius: 8px; overflow: hidden; border: 1px solid var(--border); }
.type-toggle button {
  flex: 1;
  padding: 9px;
  background: var(--bg3);
  border: none;
  color: var(--text2);
  cursor: pointer;
  font-size: 14px;
  font-family: inherit;
  transition: background 0.15s, color 0.15s;
}
.type-toggle button.active-income { background: rgba(46,204,113,0.2); color: var(--income); font-weight: 600; }
.type-toggle button.active-expense { background: rgba(231,76,60,0.2); color: var(--expense); font-weight: 600; }

/* ===== Misc ===== */
.loading { color: var(--text2); text-align: center; padding: 60px; }
.empty-state { text-align: center; padding: 60px; color: var(--text2); }
.empty-state .empty-icon { font-size: 48px; margin-bottom: 12px; }
.tag-shared { background: rgba(78,205,196,0.15); color: var(--accent2); }
.tag-income { background: rgba(46,204,113,0.15); color: var(--income); }
.tag-expense { background: rgba(231,76,60,0.15); color: var(--expense); }

.toast {
  position: fixed;
  bottom: 24px;
  right: 24px;
  background: var(--bg3);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 12px 18px;
  box-shadow: var(--shadow);
  z-index: 500;
  font-size: 14px;
  animation: slideIn 0.2s ease;
}
.toast.success { border-left: 3px solid var(--income); }
.toast.error { border-left: 3px solid var(--expense); }
@keyframes slideIn { from { transform: translateY(20px); opacity: 0; } to { transform: translateY(0); opacity: 1; } }

/* ===== OCR Zone ===== */
.ocr-zone { margin-bottom: 4px; }
.ocr-zone .btn-full {
  border: 2px dashed var(--border);
  background: transparent;
  color: var(--text2);
  transition: border-color 0.2s, color 0.2s;
}
.ocr-zone .btn-full:hover {
  border-color: var(--accent);
  color: var(--accent);
  background: rgba(108,99,255,0.06);
}

/* ===== Responsive ===== */
@media (max-width: 900px) {
  .sidebar { transform: translateX(-100%); }
  .sidebar.open { transform: translateX(0); }
  .sidebar-close { display: block; }
  .overlay.show { display: block; }
  .main-wrapper { margin-left: 0; }
  .menu-btn { display: block; }
  .summary-cards { grid-template-columns: 1fr 1fr; }
  .charts-row { grid-template-columns: 1fr; }
  .grid-2, .grid-3, .grid-4 { grid-template-columns: 1fr; }
}

@media (max-width: 600px) {
  .content { padding: 16px; }
  .summary-cards { grid-template-columns: 1fr; }
  .tx-table th:nth-child(3), .tx-table td:nth-child(3) { display: none; }
  .tx-table th:nth-child(5), .tx-table td:nth-child(5) { display: none; }
  .form-row, .form-row-3 { grid-template-columns: 1fr; }
}
