:root {
  --bg: #f5f7fb;
  --surface: #ffffff;
  --surface-2: #f0f3f8;
  --text: #182230;
  --muted: #748094;
  --border: #e5e9f0;
  --accent: #3b63f3;
  --accent-dark: #2f50cc;
  --success: #15966d;
  --danger: #d94b58;
  --shadow: 0 12px 35px rgba(22, 35, 61, .07);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background: var(--bg);
  color: var(--text);
}

button, input, select { font: inherit; }

.sidebar {
  position: fixed;
  inset: 0 auto 0 0;
  width: 240px;
  background: #101827;
  color: #fff;
  padding: 26px 16px;
  display: flex;
  flex-direction: column;
}

.brand { display: flex; gap: 12px; align-items: center; padding: 0 10px 34px; }
.brand-icon {
  width: 38px; height: 38px; border-radius: 12px;
  display: grid; place-items: center; background: #fff; color: #101827; font-weight: 800;
}
.brand strong, .brand span { display: block; }
.brand span { color: #8d99ac; font-size: 12px; margin-top: 3px; }

nav { display: grid; gap: 7px; }
.nav-item {
  border: 0; background: transparent; color: #aab4c5; text-align: left;
  padding: 12px 14px; border-radius: 10px; cursor: pointer;
}
.nav-item:hover, .nav-item.active { background: #1d2a40; color: #fff; }

.sidebar-footer { margin-top: auto; padding: 10px; color: #9ba7b8; }
.sidebar-footer small { display: block; margin-top: 5px; color: #67758b; }

.main { margin-left: 240px; padding: 34px 42px 60px; max-width: 1600px; }
.topbar { display: flex; align-items: end; justify-content: space-between; margin-bottom: 28px; }
.eyebrow { margin: 0 0 6px; color: var(--muted); font-size: 13px; }
h1, h2, p { margin-top: 0; }
h1 { margin-bottom: 0; font-size: 30px; }
h2 { margin-bottom: 4px; font-size: 17px; }
.panel-head p, .card small { color: var(--muted); font-size: 12px; margin-bottom: 0; }

.cards { display: grid; grid-template-columns: repeat(4, 1fr); gap: 18px; margin-bottom: 18px; }
.card, .panel {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 16px; box-shadow: var(--shadow);
}
.card { padding: 22px; }
.card span { display: block; color: var(--muted); font-size: 13px; margin-bottom: 13px; }
.card strong { display: block; font-size: 26px; margin-bottom: 12px; font-variant-numeric: tabular-nums; }
.metric-card { min-width: 0; }
.metric-footer { display: grid; gap: 5px; min-height: 35px; }
.metric-change { font-weight: 650; }
.metric-change.positive { color: var(--success); }
.metric-change.negative { color: var(--danger); }
.metric-change.neutral { color: var(--muted); }

.grid { display: grid; gap: 18px; margin-bottom: 18px; }
.grid.two { grid-template-columns: 1.35fr 1fr; }
.panel { padding: 22px; }
.panel-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 18px; }
.chart-panel canvas { max-height: 310px; }
.actions { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; justify-content: flex-end; }
.compact-select { width: auto; min-width: 120px; }

button {
  border: 0; border-radius: 9px; padding: 10px 14px; cursor: pointer;
}
.primary { background: var(--accent); color: #fff; font-weight: 650; }
.primary:hover { background: var(--accent-dark); }
.ghost { background: var(--surface-2); color: var(--text); }
.row-actions { display: flex; gap: 6px; justify-content: flex-end; }
.row-actions .ghost { padding: 7px 9px; }
.primary:disabled { cursor: not-allowed; opacity: .55; }
.wide { width: 100%; margin-top: 8px; }

.filters {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 10px;
  margin-bottom: 18px;
}
.filters button { min-height: 42px; }
input, select {
  width: 100%; border: 1px solid var(--border); border-radius: 9px;
  padding: 10px 11px; background: #fff; color: var(--text); outline: none;
}
input:focus, select:focus { border-color: var(--accent); }

.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th, td { padding: 13px 10px; border-bottom: 1px solid var(--border); text-align: left; font-size: 13px; }
th { color: var(--muted); font-size: 11px; text-transform: uppercase; letter-spacing: .05em; }
td.amount { font-weight: 700; text-align: right; }
.income { color: var(--success); }
.expense { color: var(--danger); }

.transaction-list { display: grid; gap: 4px; }
.transaction-row {
  display: grid; grid-template-columns: 1fr auto; gap: 15px;
  padding: 12px 0; border-bottom: 1px solid var(--border);
}
.transaction-row:last-child { border-bottom: 0; }
.transaction-main strong { display: block; font-size: 13px; }
.transaction-main small { color: var(--muted); }
.transaction-amount { font-weight: 700; }
td.amount, .transaction-amount, .account-card > strong { font-variant-numeric: tabular-nums; }

.budget-item { margin-bottom: 17px; }
.budget-item:last-child { margin-bottom: 0; }
.budget-top { display: flex; justify-content: space-between; font-size: 13px; margin-bottom: 8px; }
.progress { display: block; width: 100%; height: 8px; border: 0; border-radius: 99px; appearance: none; background: var(--surface-2); overflow: hidden; }
.progress::-webkit-progress-bar { border-radius: inherit; background: var(--surface-2); }
.progress::-webkit-progress-value { border-radius: inherit; background: var(--accent); }
.progress::-moz-progress-bar { border-radius: inherit; background: var(--accent); }
.progress.warn::-webkit-progress-value { background: #e7a62b; }
.progress.warn::-moz-progress-bar { background: #e7a62b; }
.progress.danger::-webkit-progress-value { background: var(--danger); }
.progress.danger::-moz-progress-bar { background: var(--danger); }

.budget-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 15px; }
.budget-card { border: 1px solid var(--border); border-radius: 13px; padding: 18px; }
.budget-card strong { font-size: 20px; }

.hidden { display: none !important; }

.modal {
  position: fixed; inset: 0; background: rgba(11, 18, 31, .55);
  display: grid; grid-template-columns: minmax(0, 1fr); place-items: center; padding: 20px; z-index: 10;
}
.modal-card {
  width: min(480px, 100%); min-width: 0; max-height: calc(100dvh - 40px);
  overflow-y: auto; background: var(--surface);
  border-radius: 16px; padding: 24px; box-shadow: 0 30px 80px rgba(0,0,0,.25);
}
.modal-card.wide-modal { width: min(980px, 100%); }
.preview-summary { display: flex; gap: 22px; margin-bottom: 16px; color: var(--muted); font-size: 13px; }
.preview-summary strong { color: var(--text); }
.preview-table { max-height: min(52vh, 520px); }
.status { display: inline-block; padding: 4px 7px; border-radius: 6px; font-size: 11px; font-weight: 700; text-transform: capitalize; }
.status.valid { color: #087451; background: #e5f6ef; }
.status.invalid { color: #a82e3a; background: #fdebed; }
.status.duplicate { color: #8a5c00; background: #fff3d7; }
.row-invalid td, .row-duplicate td { color: var(--muted); }
.modal-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 18px; }
.modal-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 20px; }
.close { background: var(--surface-2); font-size: 20px; width: 36px; height: 36px; padding: 0; }
form { display: grid; gap: 13px; }
label { font-size: 12px; color: var(--muted); }
label input, label select { margin-top: 6px; }

.toast {
  position: fixed; right: 25px; bottom: 25px; background: #101827;
  color: white; padding: 12px 16px; border-radius: 10px; box-shadow: var(--shadow);
}

@media (max-width: 1000px) {
  .sidebar { width: 190px; }
  .main { margin-left: 190px; padding: 25px; }
  .cards { grid-template-columns: repeat(2, 1fr); }
  .grid.two { grid-template-columns: 1fr; }
}

@media (min-width: 1001px) and (max-width: 1250px) {
  .cards { grid-template-columns: repeat(2, 1fr); }
}

@media (max-width: 700px) {
  .sidebar {
    position: sticky; inset: 0 0 auto; z-index: 5; width: auto; padding: 13px 14px;
  }
  .brand { padding: 0 4px 12px; }
  .brand-icon { width: 34px; height: 34px; border-radius: 8px; }
  nav { display: flex; gap: 5px; overflow-x: auto; scrollbar-width: none; }
  nav::-webkit-scrollbar { display: none; }
  .nav-item { flex: 0 0 auto; white-space: nowrap; padding: 9px 12px; }
  .sidebar-footer { display: none; }
  .main { margin-left: 0; padding: 18px; }
  .topbar { align-items: center; }
  .cards { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }
  .card { padding: 16px; }
  .metric-card strong { font-size: 21px; overflow-wrap: anywhere; }
  .metric-footer { min-height: 48px; }
  .filters { grid-template-columns: 1fr; }
  .panel-head { align-items: flex-start; gap: 14px; flex-direction: column; }
  .actions { justify-content: flex-start; }
  .compact-select { width: 100%; }
  .budget-grid { grid-template-columns: 1fr; }
  .preview-summary { gap: 10px; justify-content: space-between; }
}

.account-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }
.account-card {
  border: 1px solid var(--border); border-radius: 13px; padding: 15px 16px;
  display: flex; align-items: center; justify-content: space-between; gap: 15px;
  background: var(--surface);
}
.account-card strong { display: block; font-size: 14px; }
.account-card small { display: block; color: var(--muted); margin-top: 4px; text-transform: capitalize; }
@media (max-width: 700px) { .account-grid { grid-template-columns: 1fr; } }

.toast { z-index: 20; max-width: calc(100vw - 50px); }
#transaction-history-list { list-style: none; padding: 0; margin: 0; }
.history-event { padding: 16px 0; border-bottom: 1px solid var(--border); }
.history-event h3 { font-size: 15px; text-transform: capitalize; margin: 0 0 8px; }
.history-event time { display: block; color: var(--muted); font-size: 12px; font-weight: 400; margin-top: 4px; }
.history-event td { overflow-wrap: anywhere; }

#deleted-transactions-modal, #transaction-history-modal { padding-bottom: 90px; }
#deleted-transactions-modal .modal-card,
#transaction-history-modal .modal-card { max-height: calc(100dvh - 110px); }
.history-event td:first-child { white-space: nowrap; }
#deleted-table td { overflow-wrap: anywhere; }
#deleted-table td:first-child { white-space: nowrap; }
.modal-actions button:disabled { opacity: .45; cursor: default; }

#deleted-table button { white-space: nowrap; flex-shrink: 0; }
@media (max-width: 700px) {
  #deleted-transactions-modal thead { display: none; }
  #deleted-table tr {
    display: grid; grid-template-columns: minmax(0, 1fr) auto;
    padding: 12px 0; border-bottom: 1px solid var(--border);
  }
  #deleted-table td { border: 0; padding: 6px 0; }
  #deleted-table td:nth-child(1) { grid-column: 1; grid-row: 1; }
  #deleted-table td:nth-child(2) { grid-column: 1 / -1; grid-row: 2; }
  #deleted-table td:nth-child(3) { grid-column: 2; grid-row: 1; }
  #deleted-table td:nth-child(4) { grid-column: 1 / -1; grid-row: 3; }
}

.statement-setup {
  display: grid; grid-template-columns: minmax(150px, 1fr) minmax(150px, 1fr) auto;
  gap: 16px; align-items: end; padding: 20px 0; border-bottom: 1px solid var(--border);
}
.statement-detail, .statement-history { padding: 24px 0; }
.statement-totals { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 16px; margin: 20px 0; }
.statement-totals dt { font-size: 12px; color: var(--muted); }
.statement-totals dd { margin: 6px 0 0; font-size: 20px; font-weight: 650; overflow-wrap: anywhere; }
#reconciliation-entries input { width: 20px; height: 20px; accent-color: var(--accent); cursor: pointer; }
#reconciliation-entries td { overflow-wrap: anywhere; }
#reconciliation-entries td:nth-child(2), #reconciliation-entries .amount { white-space: nowrap; }
#reconciliation-entry-count { font-size: 13px; color: var(--muted); }
#reconciliation-history button { white-space: nowrap; }
#reconciliation-view button:disabled { opacity: .5; cursor: default; }
@media (max-width: 700px) {
  .statement-setup { grid-template-columns: minmax(0, 1fr); }
  .statement-totals { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  #reconciliation-heading { overflow-wrap: anywhere; }
  #reconciliation-view > .panel-head label { width: 100%; }
}

@media (max-width: 700px) {
  .main:has(#reconciliation-view:not(.hidden)) .topbar { flex-wrap: wrap; gap: 12px; }
  #reconciliation-view button, #reconciliation-view input { scroll-margin-top: 150px; }
}

.login-page { min-height: 100dvh; display: grid; place-items: center; padding: 24px; }
.login-main { width: min(100%, 360px); }
.login-main h1 { font-size: 28px; margin-bottom: 28px; }
.login-main form { display: grid; gap: 10px; }
.login-main input { width: 100%; min-width: 0; margin-bottom: 10px; }
.login-error { color: var(--danger); min-height: 24px; overflow-wrap: anywhere; margin: 0; }
.login-main button { min-height: 44px; border-radius: 6px; }
.topbar { flex-wrap: wrap; gap: 12px; }

.reconciliation-pagination { align-items: center; flex-wrap: wrap; }
.reconciliation-pagination p { margin-right: auto; }
