/* 1. Design tokens */
:root {
  color-scheme:light;
  --bg:#f7f9fc;
  --card:#fff;
  --fill:#f3f6fa;
  --sep:#e7ecf3;
  --text:#243247;
  --muted:#778398;
  --blue:#007aff;
  --tint:#edf5ff;
  --income:#25865f;
  --expense:#c45b68;
  --green:#76b89c;
  --red:#e8a2ab;
  --income-glow:transparent;
  --expense-glow:transparent;
  --font:Inter,-apple-system,BlinkMacSystemFont,system-ui,sans-serif;
  --side:232px;
  --button-bg: #007aff;
  --secondary-text: #667994;
  --accent-muted: #7aa7db;
  --field-border: #dfe5ee;
  --button-hover: #006de4;
  --link-hover: #005dbd;
  --balance-surface: #f0f6ff;
  --balance-border: #dfebfc;
  --balance-ink: #3066a7;
  --soft-surface: #fafcff;
  --table-heading: #fafbfd;
  --amount-surface: #fbfcfe;
  --avatar-surface: #eaf3ff;
  --avatar-ink: #568acb;
  --blue-border: #dce9fb;
  --blue-soft: #f2f7ff;
  --blue-soft-hover: #e2edff;
  --blue-soft-ink: #5883b8;
  --track: #f0f4fa;
  --bar: #a8c8f0;
  --success-surface: #f0f8f4;
  --danger-surface: #fdf3f4;
  --danger-hover: #fff0f1;
  --overlay: #22324d55;
}
* {
  box-sizing:border-box;
}
body {
  margin:0;
  background:var(--bg);
  color:var(--text);
  font:400 14px/1.5 var(--font);
  -webkit-font-smoothing:antialiased;
}
button,input,select {
  font:inherit;
}
button {
  cursor:pointer;
  transition:background .15s,color .15s;
}
button:disabled {
  opacity:.45;
  cursor:default;
}
button svg {
  width:18px;
  height:18px;
  flex-shrink:0;
}
input,select {
  width:100%;
  min-height:44px;
  background:var(--card);
  color:var(--text);
  border:1px solid var(--field-border);
  border-radius:8px;
  padding:10px 12px;
}
input::placeholder {
  color:var(--muted);
}
input:focus,select:focus {
  outline:2px solid #b9d7ff;
  border-color:var(--blue);
  outline-offset:1px;
}
:focus-visible {
  outline:3px solid #94c4ff;
  outline-offset:3px;
}
label {
  display:block;
  font-size:12px;
  font-weight:500;
  color:var(--muted);
  margin-bottom:7px;
}
h1,h2,h3,p {
  margin-top:0;
}
h1,h2,h3 {
  font-weight:600;
  letter-spacing:-.5px;
}
h2 {
  font-size:26px;
  margin-bottom:7px;
}
h3 {
  font-size:20px;
}
.num {
  font-variant-numeric:tabular-nums;
}
.hidden {
  display:none!important;
}
.glass {
  background:var(--card);
  border:1px solid var(--sep);
  border-radius:12px;
}
.view {
  display:none;
}
.view.active {
  display:block;
}
.btn,.btn-secondary {
  border:1px solid transparent;
  border-radius:8px;
  padding:10px 16px;
  font-size:13px;
  font-weight:500;
  min-height:42px;
  display:inline-flex;
  align-items:center;
  justify-content:center;
  gap:8px;
}
.btn {
  background:var(--button-bg);
  color:#fff;
}
.btn:hover {
  background:var(--button-hover);
}
.btn-secondary {
  background:var(--card);
  border-color:var(--field-border);
  color:var(--text);
}
.btn-secondary:hover {
  background:var(--fill);
}
.link-btn {
  background:none;
  border:0;
  color:var(--blue);
  padding:4px;
  font-size:12px;
  font-weight:500;
}
.link-btn:hover {
  color:var(--link-hover);
}
/* 2. App shell and navigation */
#appScreen.wrap {
  max-width:none;
  margin-left:var(--side);
  padding:106px 36px 40px;
}
#appScreen>.view {
  max-width:1260px;
  margin:0 auto;
}
.sidebar {
  position:fixed;
  inset:0 auto 0 0;
  width:var(--side);
  background:var(--card);
  border-right:1px solid var(--sep);
  padding:27px 18px;
  display:flex;
  flex-direction:column;
  z-index:35;
}
.sidebar-brand {
  display:flex;
  align-items:center;
  gap:11px;
  text-decoration:none;
  color:var(--text);
  font-weight:600;
  font-size:22px;
  padding:0 10px;
  margin-bottom:38px;
  letter-spacing:-.6px;
}
.sidebar-brand small {
  display:block;
  font-size:11px;
  font-weight:400;
  letter-spacing:0;
  color:var(--muted);
  margin-top:1px;
}
.brand-mark {
  display:inline-flex;
  align-items:center;
  justify-content:center;
  width:36px;
  height:36px;
  border-radius:10px;
  color:var(--blue);
  background:var(--tint);
  font-size:24px;
  font-weight:700;
}
.nav-label {
  font-size:10px;
  color:var(--muted);
  letter-spacing:1.5px;
  margin:0 12px 14px;
  font-weight:600;
}
.tabs {
  display:flex;
  flex-direction:column;
  gap:6px;
}
.tabs button,.sidebar-bottom>button {
  border:0;
  background:none;
  color:var(--secondary-text);
  padding:12px 14px;
  display:flex;
  align-items:center;
  gap:12px;
  border-radius:8px;
  text-align:left;
  font-size:13px;
  font-weight:500;
}
.tabs button.active {
  background:var(--tint);
  color:var(--blue);
}
.tabs button:hover,.sidebar-bottom>button:hover {
  background:var(--fill);
}
.tabs button svg {
  width:19px;
  height:19px;
}
.sidebar-bottom {
  margin-top:auto;
}
.sidebar-bottom>button {
  width:100%;
}
.sidebar-help {
  margin:20px 8px 0;
  padding:18px 12px 0;
  border-top:1px solid var(--sep);
  font-size:11px;
  color:var(--muted);
}
.sidebar-help strong {
  font-weight:500;
  color:var(--secondary-text);
}
.sidebar-help p {
  margin:7px 0 20px;
}
.kbd-hint {
  font-size:10px;
  color:var(--muted);
}
kbd {
  border:1px solid var(--sep);
  border-radius:4px;
  padding:1px 4px;
  font:inherit;
  background:var(--fill);
}
.topbar {
  position:fixed;
  top:0;
  left:var(--side);
  right:0;
  height:74px;
  background:var(--card);
  border-bottom:1px solid var(--sep);
  display:flex;
  align-items:center;
  justify-content:space-between;
  padding:0 36px;
  z-index:30;
}
.topbar-title {
  font-size:14px;
  font-weight:600;
  display:block;
}
.topbar-note {
  font-size:11px;
  color:var(--muted);
}
.topbar-actions {
  display:flex;
  gap:20px;
  align-items:center;
}
.topbar-actions>div {
  position:relative;
}
.avatar {
  width:36px;
  height:36px;
  border:1px solid var(--blue-border);
  background:var(--tint);
  color:var(--blue);
  border-radius:50%;
  font-size:13px;
  font-weight:600;
}
.acct-menu {
  position:absolute;
  right:0;
  top:48px;
  width:240px;
  padding:6px;
  box-shadow:0 10px 40px #263c5a1a;
}
.acct-menu .email {
  font-size:12px;
  color:var(--muted);
  padding:10px;
  word-break:break-all;
  border-bottom:1px solid var(--sep);
}
.acct-menu button {
  width:100%;
  border:0;
  background:none;
  text-align:left;
  padding:11px;
  border-radius:6px;
  color:var(--text);
  font-size:13px;
}
.acct-menu button:hover {
  background:var(--fill);
}
.acct-menu button:last-child {
  color:var(--expense);
}
/* 3. Overview and analytics */
.page-heading {
  display:flex;
  align-items:center;
  justify-content:space-between;
  gap:24px;
  margin-bottom:26px;
}
.overline {
  font-size:10px;
  font-weight:600;
  letter-spacing:1.4px;
  color:var(--muted);
  margin-bottom:7px;
}
.page-sub {
  font-size:13px;
  color:var(--muted);
  margin:0;
}
.period-control {
  flex-shrink:0;
}
.period-control label {
  font-size:11px;
}
.period-control>div {
  display:flex;
  gap:8px;
}
.period-control input {
  width:155px;
  min-height:40px;
  font-size:12px;
}
.period-control button {
  min-height:40px;
  white-space:nowrap;
}
.period-caption {
  color:var(--muted);
  font-size:12px;
  margin-bottom:13px;
}
.summary {
  display:grid;
  grid-template-columns:repeat(4,minmax(0,1fr));
  gap:16px;
  margin-bottom:28px;
}
.card {
  padding:22px;
  position:relative;
  min-height:140px;
}
.card.balance {
  background:var(--balance-surface);
  border-color:var(--balance-border);
}
.metric-icon {
  display:block;
  color:var(--accent-muted);
  margin-bottom:12px;
}
.metric-icon svg {
  width:20px;
  height:20px;
}
.income .metric-icon {
  color:#76ab92;
}
.expense .metric-icon {
  color:#ce939a;
}
.savings .metric-icon {
  color:#a397c9;
}
.eyebrow {
  font-size:12px;
  color:var(--muted);
}
.card .value {
  font-size:clamp(18px,2vw,28px);
  letter-spacing:-.7px;
  font-weight:600;
  margin-top:5px;
  overflow-wrap:anywhere;
}
.card.balance .value {
  color:var(--balance-ink);
}
.card.income .value {
  color:var(--income);
}
.card.expense .value {
  color:var(--expense);
}
.card small {
  font-size:10px;
  color:var(--muted);
}
.analytics-grid {
  display:grid;
  grid-template-columns:1.3fr 1fr;
  gap:22px;
  margin-bottom:24px;
}
.panel {
  background:var(--card);
  border:1px solid var(--sep);
  border-radius:12px;
  overflow:hidden;
}
.sec-head {
  padding:22px 24px 0;
  display:flex;
  align-items:center;
  justify-content:space-between;
  gap:12px;
}
.sec-head h2 {
  font-size:15px;
  letter-spacing:-.2px;
  margin:0 0 4px;
}
.sec-head p {
  font-size:11px;
  color:var(--muted);
  margin:0;
}
.chart-box {
  padding:20px 24px 35px;
}
.legend {
  display:flex;
  gap:18px;
  color:var(--muted);
  font-size:11px;
  margin-bottom:24px;
}
.legend span {
  display:inline-flex;
  align-items:center;
  gap:6px;
}
.dot {
  height:7px;
  width:7px;
  border-radius:2px;
}
.dot.in,.b-in {
  background:var(--green);
}
.dot.out,.b-out {
  background:var(--red);
}
.chart {
  height:185px;
  position:relative;
  margin-left:44px;
}
.gridline {
  position:absolute;
  left:0;
  right:0;
  border-top:1px dashed var(--sep);
}
.gl-label {
  position:absolute;
  left:-44px;
  top:-8px;
  width:36px;
  text-align:right;
  font-size:10px;
  color:var(--muted);
}
.bars-row {
  position:absolute;
  inset:0;
  display:flex;
  gap:12px;
  align-items:flex-end;
}
.bar-col {
  flex:1;
  height:100%;
  display:flex;
  flex-direction:column;
  justify-content:flex-end;
  align-items:center;
}
.bar-pair {
  display:flex;
  align-items:flex-end;
  gap:5px;
  height:100%;
}
.bar-pair div {
  width:13px;
  border-radius:3px 3px 0 0;
}
.bar-label {
  color:var(--muted);
  font-size:10px;
  margin-top:10px;
}
.chart-empty {
  height:185px;
  display:flex;
  align-items:center;
  justify-content:center;
  text-align:center;
  flex-direction:column;
  color:var(--muted);
  font-size:12px;
}
#bars {
  padding:24px;
}
.bar-row {
  display:grid;
  grid-template-columns:1fr auto auto;
  gap:7px 12px;
  margin-bottom:21px;
  font-size:12px;
  align-items:center;
}
.bar-row .name {
  font-weight:500;
  overflow:hidden;
  text-overflow:ellipsis;
  white-space:nowrap;
}
.bar-pct {
  font-size:10px;
  color:var(--muted);
}
.bar-amt {
  font-weight:500;
  text-align:right;
}
.bar-track {
  grid-column:1/-1;
  height:5px;
  border-radius:6px;
  background:var(--track);
  overflow:hidden;
}
.bar-fill {
  height:100%;
  background:var(--bar);
  border-radius:6px;
}
.empty {
  padding:36px 20px;
  text-align:center;
  color:var(--muted);
  font-size:12px;
}
/* 4. Transactions, filtering and paging */
.tx-list {
  background:var(--card);
  border:1px solid var(--sep);
  border-radius:10px;
  overflow:hidden;
}
.recent-panel .tx-list {
  border:0;
  border-radius:0;
  margin-top:20px;
}
.tx {
  display:grid;
  grid-template-columns:minmax(0,1fr) auto auto;
  align-items:center;
  gap:20px;
  padding:16px 24px;
  border:0;
  border-bottom:1px solid var(--sep);
  border-radius:0;
}
.tx:last-child {
  border-bottom:0;
}
.tx-left {
  min-width:0;
}
.tx-cat {
  font-size:13px;
  font-weight:500;
  overflow:hidden;
  text-overflow:ellipsis;
  white-space:nowrap;
}
.tx-meta {
  font-size:11px;
  color:var(--muted);
  margin-top:3px;
}
.tx-amt {
  font-size:13px;
  font-weight:500;
  white-space:nowrap;
}
.tx-actions {
  display:flex;
  gap:4px;
}
.icon-btn {
  border:0;
  background:none;
  color:var(--muted);
  border-radius:6px;
  min-width:32px;
  min-height:32px;
  display:inline-flex;
  justify-content:center;
  align-items:center;
}
.icon-btn svg {
  width:15px;
  height:15px;
}
.icon-btn:hover {
  background:var(--tint);
  color:var(--blue);
}
.icon-btn.danger:hover {
  background:var(--danger-hover);
  color:var(--expense);
}
.filters {
  background:var(--card);
  border:1px solid var(--sep);
  border-radius:10px;
  padding:20px;
  display:grid;
  grid-template-columns:1.6fr 1fr 1fr 1fr 1fr;
  gap:12px;
  margin-bottom:16px;
}
.filter-field {
  min-width:0;
}
.filter-field input,.filter-field select {
  font-size:12px;
}
.heading-actions {
  display:flex;
  align-items:center;
  gap:16px;
}
.tx-table {
  width:100%;
  border-collapse:collapse;
  font-size:12px;
}
.tx-table th {
  text-align:left;
  font-size:11px;
  font-weight:500;
  color:var(--muted);
  background:var(--table-heading);
  padding:15px 20px;
  border-bottom:1px solid var(--sep);
  cursor:pointer;
  white-space:nowrap;
}
.tx-table th:hover {
  color:var(--blue);
}
.tx-table td {
  padding:15px 20px;
  border-bottom:1px solid var(--sep);
}
.tx-table tr:last-child td {
  border-bottom:0;
}
.tx-table tr:hover {
  background:var(--soft-surface);
}
.tx-table .r {
  text-align:right;
  white-space:nowrap;
}
.tx-table .note {
  color:var(--muted);
  max-width:220px;
  overflow:hidden;
  text-overflow:ellipsis;
  white-space:nowrap;
}
.tx-table .acts {
  white-space:nowrap;
  text-align:right;
  width:1%;
}
.pagination {
  display:flex;
  justify-content:space-between;
  align-items:center;
  margin-top:16px;
  font-size:11px;
  color:var(--muted);
  gap:12px;
}
.pagination label {
  display:flex;
  align-items:center;
  gap:8px;
  margin:0;
  font-size:11px;
}
.pagination select {
  width:65px;
  min-height:32px;
  padding:5px;
  font-size:11px;
}
.pagination>div {
  display:flex;
  align-items:center;
  gap:10px;
}
.pagination .btn-secondary {
  min-height:32px;
  padding:6px 12px;
  font-size:11px;
}
/* 5. Dedicated entry page and form controls */
.entry-layout {
  display:grid;
  grid-template-columns:minmax(0,600px) minmax(220px,300px);
  gap:36px;
  align-items:start;
}
.entry-form {
  padding:30px;
  display:grid;
  grid-template-columns:1fr 1fr;
  gap:22px;
}
.full {
  grid-column:1/-1;
}
.toggle,.auth-tabs {
  display:flex;
  gap:4px;
  padding:4px;
  background:var(--fill);
  border-radius:8px;
}
.toggle button,.auth-tabs button {
  flex:1;
  border:0;
  background:none;
  border-radius:6px;
  padding:10px;
  font-size:12px;
  color:var(--muted);
  font-weight:500;
}
.toggle button.active,.auth-tabs button.active {
  background:var(--card);
  color:var(--blue);
  box-shadow:0 1px 4px #23385410;
}
.toggle button.active[data-t="expense"] {
  color:var(--expense);
}
.toggle button.active[data-t="income"] {
  color:var(--income);
}
.amount-field input {
  font-size:32px;
  font-weight:500;
  letter-spacing:-.6px;
  padding:16px;
  min-height:80px;
  background:var(--amount-surface);
}
.entry-actions {
  display:flex;
  justify-content:flex-end;
  gap:10px;
  border-top:1px solid var(--sep);
  padding-top:20px;
}
.entry-guide {
  padding:25px 0;
  color:var(--muted);
  font-size:12px;
}
.guide-icon {
  display:inline-flex;
  background:var(--tint);
  color:var(--accent-muted);
  padding:12px;
  border-radius:10px;
  margin-bottom:20px;
}
.guide-icon svg {
  width:24px;
  height:24px;
}
.entry-guide h3 {
  font-size:18px;
  color:var(--secondary-text);
  margin:0 0 10px;
}
.entry-guide p {
  line-height:1.7;
}
.entry-guide dl {
  margin-top:30px;
}
.entry-guide dt {
  color:var(--secondary-text);
  font-weight:500;
  margin:20px 0 6px;
}
.entry-guide dd {
  margin:0;
  line-height:1.7;
}
/* 6. Authentication, account dialogs and feedback */
#authScreen.wrap {
  padding:24px;
}
.auth-box {
  max-width:420px;
  margin:10vh auto;
  padding:36px;
}
.auth-box h1 {
  display:flex;
  align-items:center;
  justify-content:center;
  gap:10px;
  font-size:28px;
}
.sub {
  font-size:12px;
  color:var(--muted);
  text-align:center;
  margin-bottom:22px;
}
.auth-tabs {
  margin-bottom:22px;
}
.auth-box .btn {
  margin-top:10px;
}
.err,.msg {
  font-size:12px;
  margin-top:10px;
  min-height:16px;
}
.err {
  color:var(--expense);
}
.msg {
  color:var(--income);
}
.modal-overlay {
  position:fixed;
  inset:0;
  background:var(--overlay);
  backdrop-filter:blur(3px);
  display:flex;
  align-items:center;
  justify-content:center;
  padding:20px;
  z-index:50;
  overflow:auto;
}
.modal {
  padding:28px;
  width:100%;
  max-width:440px;
  max-height:90vh;
  overflow:auto;
  box-shadow:0 20px 80px #21324725;
}
.modal-actions {
  display:flex;
  gap:10px;
  margin-top:20px;
}
.modal-actions .btn,.modal-actions .btn-secondary {
  flex:1;
}
.chip {
  display:inline-flex;
  align-items:center;
  gap:6px;
  font-size:11px;
  border-radius:6px;
  padding:6px 10px;
  background:var(--tint);
  color:var(--accent-muted);
}
.chip.default {
  background:var(--fill);
  color:var(--muted);
}
.chip button {
  border:0;
  background:none;
  color:inherit;
}
.app-notice,.toast {
  position:fixed;
  bottom:24px;
  right:24px;
  max-width:calc(100vw - 32px);
  padding:14px 18px;
  border:1px solid var(--sep);
  border-radius:10px;
  background:var(--card);
  box-shadow:0 5px 30px #1a314d18;
  font-size:12px;
  z-index:70;
}
.app-notice {
  color:var(--income);
}
.app-notice.is-error {
  color:var(--expense);
}
.toast {
  bottom:90px;
  display:flex;
  gap:20px;
  align-items:center;
}
.toast button {
  color:var(--blue);
  background:none;
  border:0;
  font-weight:500;
}
/* 7. Responsive layout */
@media(max-width:1200px) {
  #appScreen.wrap {
    padding-left:24px;
    padding-right:24px;
  }
  .summary {
    gap:12px;
  }
  .card {
    padding:18px;
  }
  .filters {
    grid-template-columns:repeat(4,1fr);
  }
  .filters .filter-field:first-child {
    grid-column:1/-1;
  }
  .analytics-grid {
    grid-template-columns:1.1fr 1fr;
  }
  .tx-table td,.tx-table th {
    padding:14px 12px;
  }
}
@media(max-width:999px) {
  :root {
    --side:190px;
  }
  .sidebar {
    padding:24px 12px;
  }
  .sidebar-brand {
    font-size:20px;
    padding:0 6px;
  }
  .topbar {
    padding:0 24px;
  }
  .summary {
    grid-template-columns:repeat(2,minmax(0,1fr));
  }
  .analytics-grid {
    grid-template-columns:1fr;
  }
  .entry-layout {
    grid-template-columns:1fr;
  }
  .entry-guide {
    padding:0;
    max-width:600px;
  }
  .entry-guide dl {
    display:none;
  }
  .page-heading {
    align-items:flex-start;
  }
  .page-heading h2 {
    font-size:23px;
  }
  .page-sub {
    font-size:12px;
  }
  .period-control input {
    width:140px;
  }
}
@media(max-width:760px) {
  #appScreen.wrap {
    margin-left:0;
    padding:94px 16px 100px;
  }
  .sidebar {
    inset:auto 0 0;
    width:100%;
    height:72px;
    padding:8px 12px max(8px,env(safe-area-inset-bottom));
    border-right:0;
    border-top:1px solid var(--sep);
  }
  .sidebar-brand,.nav-label,.sidebar-bottom {
    display:none;
  }
  .tabs {
    flex-direction:row;
    justify-content:space-around;
    gap:8px;
  }
  .tabs button {
    flex:1;
    flex-direction:column;
    justify-content:center;
    gap:3px;
    font-size:10px;
    padding:7px 3px;
    border-radius:8px;
  }
  .tabs button svg {
    height:19px;
    width:19px;
  }
  .topbar {
    left:0;
    padding:0 16px;
    height:70px;
  }
  .topbar-actions {
    gap:12px;
  }
  .topbar-actions .btn {
    font-size:12px;
    padding:9px 12px;
  }
  .page-heading {
    flex-direction:column;
    gap:16px;
  }
  .period-control {
    width:100%;
  }
  .period-control>div {
    width:100%;
  }
  .period-control input {
    flex:1;
    width:0;
  }
  .summary {
    gap:10px;
  }
  .card {
    padding:18px;
    min-height:130px;
  }
  .card .value {
    font-size:22px;
  }
  .metric-icon {
    margin-bottom:10px;
  }
  .analytics-grid {
    gap:18px;
  }
  .sec-head {
    padding:20px 18px 0;
  }
  .chart-box,#bars {
    padding-left:18px;
    padding-right:18px;
  }
  .tx {
    padding:14px 16px;
    gap:8px;
    grid-template-columns:minmax(0,1fr) auto;
  }
  .tx-left {
    grid-row:1/3;
  }
  .tx-actions {
    grid-column:2;
    justify-content:flex-end;
  }
  .tx-amt {
    font-size:12px;
  }
  .filters {
    grid-template-columns:1fr 1fr;
    padding:16px;
    gap:14px;
  }
  .filters .filter-field:first-child {
    grid-column:1/-1;
  }
  .pagination {
    align-items:flex-start;
    flex-direction:column;
  }
  .pagination>div {
    width:100%;
    justify-content:flex-end;
  }
  .pagination #pageInfo {
    margin-right:auto;
  }
  .entry-form {
    padding:22px;
    gap:18px;
  }
  .entry-guide {
    display:none;
  }
  .heading-actions {
    gap:12px;
  }
  .modal-overlay {
    padding:12px;
  }
  .modal {
    padding:24px;
    max-height:90dvh;
  }
  .app-notice {
    bottom:90px;
    right:16px;
  }
  .toast {
    bottom:150px;
    right:16px;
  }
  .auth-box {
    padding:28px 24px;
  }
}
@media(prefers-reduced-motion:reduce) {
  * {
    transition:none!important;
  }
}
/* Transaction type badges */
.type-badge {
  display:inline-block;
  padding:3px 8px;
  border-radius:5px;
  font-size:10px;
  white-space:nowrap;
}
.type-badge.income {
  background:var(--success-surface);
  color:var(--income);
}
.type-badge.expense {
  background:var(--danger-surface);
  color:var(--expense);
}

/* 8. Account menu and spacious profile dialog */
.account-trigger {
  display: flex;
  align-items: center;
  gap: 10px;
  border: 1px solid transparent;
  border-radius: 10px;
  padding: 5px 8px;
  color: var(--text);
  background: none;
}
.account-trigger:hover, .account-trigger[aria-expanded="true"] {
  background: var(--fill);
}
.account-trigger > svg {
  width: 14px;
  height: 14px;
  color: var(--muted);
}
.account-first-name {
  max-width: 130px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 12px;
  font-weight: 500;
}
.account-avatar {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  width: 34px;
  height: 34px;
  border-radius: 10px;
  background: var(--avatar-surface);
  color: var(--avatar-ink);
  font-size: 12px;
  font-weight: 600;
}
.account-avatar svg {
  width: 18px;
  height: 18px;
}
.acct-menu {
  width: 290px;
  padding: 8px;
  top: 54px;
  border-radius: 12px;
  box-shadow: 0 12px 36px #243c5920;
}
.account-menu-header {
  display: flex;
  gap: 12px;
  align-items: center;
  padding: 14px 10px 18px;
  margin-bottom: 6px;
  border-bottom: 1px solid var(--sep);
}
.account-menu-identity {
  min-width: 0;
}
.account-menu-identity strong {
  display: block;
  font-size: 13px;
  font-weight: 600;
  overflow-wrap: anywhere;
}
.acct-menu .email {
  padding: 3px 0 0;
  border: 0;
  font-size: 11px;
}
.acct-menu button {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px;
  font-size: 12px;
}
.acct-menu button svg {
  width: 17px;
  height: 17px;
  color: var(--muted);
}
.acct-menu button:last-child {
  border-top: 1px solid var(--sep);
  border-radius: 0 0 6px 6px;
  margin-top: 5px;
}
.acct-menu button:last-child svg {
  color: var(--expense);
}
.profile-modal {
  max-width: 860px;
  padding: 0;
  border-radius: 16px;
}
.profile-modal-heading {
  padding: 28px 32px;
  border-bottom: 1px solid var(--sep);
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 20px;
}
.profile-modal-heading h3 {
  font-size: 22px;
  margin: 0 0 6px;
}
.profile-modal-heading p {
  margin: 0;
  color: var(--muted);
  font-size: 12px;
}
.profile-content {
  display: grid;
  grid-template-columns: 220px minmax(0,1fr);
}
.profile-identity {
  padding: 32px 24px;
  background: var(--soft-surface);
  border-right: 1px solid var(--sep);
}
.profile-avatar {
  width: 64px;
  height: 64px;
  border-radius: 16px;
  background: var(--avatar-surface);
  color: var(--avatar-ink);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 21px;
  font-weight: 600;
  margin-bottom: 18px;
}
.profile-avatar svg {
  width: 28px;
  height: 28px;
}
.profile-identity h4 {
  font-size: 15px;
  font-weight: 600;
  margin: 0 0 5px;
  overflow-wrap: anywhere;
}
.profile-identity p {
  font-size: 11px;
  color: var(--muted);
  overflow-wrap: anywhere;
  margin: 0 0 28px;
}
.member-label {
  display: block;
  font-size: 10px;
  color: var(--muted);
  margin-bottom: 4px;
}
#profileSince {
  font-size: 11px;
  color: var(--secondary-text);
}
.profile-sections {
  padding: 8px 32px 24px;
  min-width: 0;
}
.profile-section {
  padding: 24px 0;
  border-bottom: 1px solid var(--sep);
}
.profile-section-title {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  margin-bottom: 18px;
}
.profile-section-title > svg {
  width: 18px;
  height: 18px;
  margin-top: 2px;
  color: var(--accent-muted);
  flex-shrink: 0;
}
.profile-section h4 {
  font-size: 13px;
  font-weight: 600;
  margin: 0 0 4px;
}
.profile-section p {
  font-size: 11px;
  color: var(--muted);
  margin: 0;
  line-height: 1.6;
}
.profile-field-row {
  display: flex;
  align-items: center;
  gap: 10px;
}
.profile-field-row input {
  min-width: 0;
  flex: 1;
  font-size: 12px;
}
.profile-field-row button {
  white-space: nowrap;
  font-size: 12px;
  padding: 10px 12px;
}
.profile-modal-footer {
  padding: 18px 32px;
  border-top: 1px solid var(--sep);
  display: flex;
  justify-content: flex-end;
}
@media (max-width: 650px) {
  .profile-content {
    grid-template-columns: 1fr;
  }
  .profile-identity {
    padding: 20px 24px;
    border-right: 0;
    border-bottom: 1px solid var(--sep);
  }
  .profile-avatar {
    width: 44px;
    height: 44px;
    font-size: 16px;
    margin-bottom: 10px;
  }
  .profile-identity p {
    margin-bottom: 12px;
  }
  .profile-modal-heading, .profile-modal-footer {
    padding: 22px 24px;
  }
  .profile-sections {
    padding: 0 24px 20px;
  }
  .profile-field-row {
    flex-wrap: wrap;
  }
  .profile-field-row input {
    flex-basis: 100%;
  }
  .profile-field-row button {
    margin-left: auto;
  }
  .account-first-name {
    max-width: 70px;
  }
  .account-trigger {
    gap: 6px;
    padding: 4px;
  }
  .topbar-actions {
    gap: 6px;
  }
}

/* 9. Currency, export and category preferences */
.preferences-modal {
  max-width: 880px;
  padding: 0;
  border-radius: 16px;
}
.preferences-grid {
  display: grid;
  grid-template-columns: 1fr 1.15fr;
}
.preferences-left {
  background: var(--soft-surface);
  border-right: 1px solid var(--sep);
  padding: 28px 32px;
}
.preference-section h4 {
  font-size: 13px;
  font-weight: 600;
  margin: 0 0 4px;
}
.preference-section .profile-section-title p,
.preference-help,
.category-legend {
  font-size: 11px;
  color: var(--muted);
  line-height: 1.7;
  margin: 0;
}
.preference-help {
  margin-top: 12px;
}
.preference-section select {
  font-size: 13px;
}
.export-section {
  border-top: 1px solid var(--sep);
  margin-top: 28px;
  padding-top: 28px;
}
.export-section .btn-secondary {
  margin-top: 18px;
  width: 100%;
}
.categories-section {
  padding: 28px 32px;
}
.category-legend {
  margin: 14px 0;
}
.category-chips {
  display: flex;
  flex-wrap: wrap;
  align-content: flex-start;
  gap: 8px;
  min-height: 110px;
  max-height: 250px;
  overflow-y: auto;
  margin-bottom: 24px;
  padding: 2px;
}
.category-chips .chip {
  border: 1px solid var(--blue-border);
  background: var(--blue-soft);
  color: var(--blue-soft-ink);
  font-size: 11px;
  border-radius: 7px;
  overflow-wrap: anywhere;
}
.category-chips .chip.default {
  color: var(--muted);
  border-color: var(--sep);
  background: var(--table-heading);
}
.category-chips .chip button {
  min-width: 22px;
  min-height: 22px;
  border-radius: 4px;
}
.category-chips .chip button:hover {
  background: var(--blue-soft-hover);
}
.category-input-row {
  display: flex;
  gap: 10px;
}
.category-input-row input {
  min-width: 0;
  font-size: 12px;
}
#currencyConfirmOverlay {
  z-index: 55;
}
.currency-confirm-modal {
  max-width: 480px;
  padding: 30px;
}
.currency-confirm-icon {
  display: inline-flex;
  padding: 12px;
  color: var(--accent-muted);
  background: var(--tint);
  border-radius: 12px;
  margin-bottom: 20px;
}
.currency-confirm-icon svg {
  width: 26px;
  height: 26px;
}
.currency-confirm-modal h3 {
  margin-bottom: 8px;
}
.currency-choice {
  margin-top: 20px;
}
.currency-choice button {
  width: 100%;
}
.currency-choice p {
  color: var(--muted);
  font-size: 11px;
  line-height: 1.6;
  margin: 8px 2px 0;
}
.currency-confirm-modal > .link-btn {
  display: block;
  margin: 14px auto 0;
}
@media (max-width: 700px) {
  .preferences-grid {
    grid-template-columns: 1fr;
  }
  .preferences-left {
    border-right: 0;
    border-bottom: 1px solid var(--sep);
    padding: 24px;
  }
  .categories-section {
    padding: 24px;
  }
  .category-chips {
    min-height: 0;
    max-height: 180px;
  }
  .currency-confirm-modal {
    padding: 24px;
  }
}

/* 10. Editable category list and reassignment dialog */
.category-list {
  max-height: 280px;
  overflow-y: auto;
  border: 1px solid var(--sep);
  border-radius: 9px;
  margin: 16px 0 24px;
}
.category-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 11px 12px;
  border-bottom: 1px solid var(--sep);
}
.category-row:last-child {
  border-bottom: 0;
}
.category-row-info {
  min-width: 0;
}
.category-row-info strong {
  display: block;
  font-size: 12px;
  font-weight: 500;
  overflow-wrap: anywhere;
}
.category-row-info small {
  display: block;
  color: var(--muted);
  font-size: 10px;
  margin-top: 2px;
}
.category-row-actions {
  display: flex;
  gap: 3px;
  flex-shrink: 0;
}
#categoryActionOverlay {
  z-index: 56;
}
.category-action-modal {
  max-width: 500px;
}
.category-affected {
  font-size: 11px;
  padding: 10px 12px;
  background: var(--tint);
  color: var(--accent-muted);
  border-radius: 7px;
  margin: 16px 0 22px;
}

/* 11. Dark theme: shared semantic tokens cover every screen and dialog. */
:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #111827;
  --card: #1a2434;
  --fill: #263246;
  --sep: #303d50;
  --text: #e3eaf5;
  --muted: #a4b2c8;
  --blue: #83b8ff;
  --button-bg: #3b82f6;
  --tint: #223957;
  --income: #85d5b3;
  --expense: #f0a2ae;
  --green: #70b99a;
  --red: #d68f9c;
  --secondary-text: #b2c0d4;
  --accent-muted: #94b7e3;
  --field-border: #354154;
  --button-hover: #2563eb;
  --link-hover: #a8ccff;
  --balance-surface: #1c2f4b;
  --balance-border: #2d4665;
  --balance-ink: #a2caff;
  --soft-surface: #1b2637;
  --table-heading: #1c2738;
  --amount-surface: #1b2637;
  --avatar-surface: #243c5b;
  --avatar-ink: #9ac3f7;
  --blue-border: #324964;
  --blue-soft: #23374f;
  --blue-soft-hover: #2d4665;
  --blue-soft-ink: #a1c5f1;
  --track: #2b384a;
  --bar: #6e9ed9;
  --success-surface: #1c3930;
  --danger-surface: #3d2832;
  --danger-hover: #4a303c;
  --overlay: #00000099;
}
.account-controls {
  display: flex;
  align-items: center;
  gap: 8px;
}
.theme-toggle {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  padding: 0;
  background: var(--card);
  color: var(--secondary-text);
  border: 1px solid var(--sep);
  border-radius: 9px;
  flex-shrink: 0;
}
.theme-toggle:hover {
  background: var(--fill);
  color: var(--blue);
}
.theme-sun { display: none; }
:root[data-theme="dark"] .theme-moon { display: none; }
:root[data-theme="dark"] .theme-sun { display: block; }
:root[data-theme="dark"] .card.savings .metric-icon { color: #b7a8dc; }
:root[data-theme="dark"] .card.income .metric-icon { color: #91c4aa; }
:root[data-theme="dark"] .card.expense .metric-icon { color: #dba2aa; }
:root[data-theme="dark"] .acct-menu,
:root[data-theme="dark"] .modal,
:root[data-theme="dark"] .app-notice,
:root[data-theme="dark"] .toast { box-shadow: 0 12px 40px #00000040; }
@media (max-width: 480px) {
  .topbar-actions #topAdd span { display: none; }
  .topbar-actions #topAdd { width: 36px; min-height: 36px; padding: 0; }
  .account-controls { gap: 6px; }
  .account-first-name { max-width: 60px; }
}
@media (max-width: 350px) {
  .account-first-name { display: none; }
  .topbar-note { display: none; }
}

/* 12. Compact phone layout with a visible brand and navigation drawer */
.topbar-leading {
  display: flex;
  align-items: center;
  gap: 8px;
}
.mobile-menu-toggle, .mobile-menu-close, .mobile-brand, .nav-backdrop {
  display: none;
}
@media (max-width: 760px) {
  body { font-size: 12px; }
  #appScreen.wrap { padding: 78px 12px 28px; }
  .topbar { height: 58px; padding: 0 12px; }
  .desktop-route-title { display: none; }
  .mobile-menu-toggle {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 32px;
    height: 36px;
    border: 0;
    border-radius: 7px;
    background: none;
    color: var(--secondary-text);
    padding: 0;
  }
  .mobile-menu-toggle:hover { background: var(--fill); }
  .mobile-brand {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    color: var(--text);
    text-decoration: none;
    font-size: 14px;
    font-weight: 600;
    letter-spacing: -.3px;
  }
  .mobile-brand .brand-mark { width: 25px; height: 25px; border-radius: 7px; font-size: 17px; }
  .topbar-actions { gap: 6px; }
  .topbar-actions #topAdd { width: 32px; min-height: 32px; padding: 0; }
  .topbar-actions #topAdd span { display: none; }
  .theme-toggle { width: 32px; height: 32px; border-radius: 7px; }
  .account-avatar { width: 30px; height: 30px; border-radius: 8px; font-size: 10px; }
  .account-first-name { max-width: 52px; font-size: 10px; }
  .account-trigger { padding: 2px; gap: 4px; }
  .account-trigger > svg { width: 11px; height: 11px; }
  .account-controls { gap: 5px; }
  .sidebar {
    inset: 0 auto 0 0;
    width: min(270px, 86vw);
    height: 100dvh;
    padding: 24px 16px;
    border-top: 0;
    border-right: 1px solid var(--sep);
    transform: translateX(-100%);
    visibility: hidden;
    pointer-events: none;
    transition: transform .2s ease, visibility .2s;
    z-index: 45;
  }
  .sidebar.mobile-open { transform: none; visibility: visible; pointer-events: auto; }
  .sidebar-brand { display: flex; margin-bottom: 30px; padding-right: 26px; }
  .nav-label { display: block; }
  .sidebar-bottom { display: block; }
  .sidebar-help { display: none; }
  .tabs { flex-direction: column; gap: 6px; }
  .tabs button {
    flex: initial;
    flex-direction: row;
    justify-content: flex-start;
    gap: 12px;
    font-size: 12px;
    padding: 12px 14px;
    min-height: 42px;
  }
  .mobile-menu-close { display: inline-flex; position: absolute; top: 26px; right: 12px; }
  .nav-backdrop {
    display: block;
    position: fixed;
    inset: 0;
    width: 100%;
    height: 100%;
    background: var(--overlay);
    border: 0;
    padding: 0;
    z-index: 44;
  }
  .page-heading { gap: 12px; margin-bottom: 14px; }
  .page-heading h2 { font-size: 19px; margin-bottom: 4px; }
  .overline { font-size: 8px; letter-spacing: 1px; margin-bottom: 4px; }
  .page-sub { font-size: 11px; }
  .period-control label { font-size: 10px; margin-bottom: 4px; }
  .period-control input, .period-control .btn-secondary { min-height: 34px; padding: 6px 10px; font-size: 11px; }
  .period-caption { font-size: 10px; margin-bottom: 8px; }
  .summary { grid-template-columns: repeat(4,minmax(0,1fr)); gap: 6px; margin-bottom: 16px; }
  .summary .card { padding: 10px 7px; min-height: 78px; border-radius: 8px; }
  .summary .metric-icon { margin-bottom: 4px; line-height: 1; }
  .summary .metric-icon svg { width: 13px; height: 13px; }
  .summary .eyebrow { font-size: 9px; line-height: 1.3; }
  .summary .value { font-size: clamp(10px,2.8vw,17px); line-height: 1.25; letter-spacing: -.3px; margin-top: 4px; overflow-wrap: anywhere; }
  .summary .card small { display: none; }
  .analytics-grid { gap: 14px; margin-bottom: 14px; }
  .panel { border-radius: 9px; }
  .sec-head { padding: 15px 14px 0; gap: 8px; }
  .sec-head h2 { font-size: 13px; }
  .sec-head p { font-size: 10px; }
  .chart-box { padding: 14px 14px 24px; }
  .chart { height: 135px; }
  .chart-empty { height: 135px; font-size: 11px; }
  .legend { margin-bottom: 18px; font-size: 10px; }
  #bars { padding: 16px 14px 6px; }
  .bar-row { font-size: 11px; margin-bottom: 13px; gap: 5px 8px; }
  .bar-pct { font-size: 9px; }
  .bar-track { height: 4px; }
  .recent-panel .tx-list { margin-top: 12px; }
  .tx { padding: 10px 12px; }
  .tx-cat { font-size: 11px; }
  .tx-meta { font-size: 9px; margin-top: 2px; }
  .tx-amt { font-size: 11px; }
  .tx-actions .icon-btn { min-width: 27px; min-height: 27px; }
  .tx-actions .icon-btn svg { width: 13px; height: 13px; }
  .filters { padding: 12px; gap: 10px; margin-bottom: 12px; }
  .filter-field label { font-size: 10px; margin-bottom: 4px; }
  .filter-field input, .filter-field select { min-height: 36px; font-size: 12px; padding: 7px 9px; }
  .heading-actions .btn-secondary { min-height: 34px; font-size: 11px; padding: 7px 12px; }
  .link-btn { font-size: 11px; }
  .entry-form { padding: 16px; gap: 14px; }
  .entry-form label { font-size: 11px; }
  .entry-form .amount-field input { min-height: 60px; font-size: 25px; padding: 12px; }
  .entry-actions { padding-top: 14px; }
  .pagination { font-size: 10px; }
  .empty { padding: 24px 12px; font-size: 11px; }
  .app-notice { bottom: 18px; }
  .toast { bottom: 72px; }
}
@media (max-width: 380px) {
  .account-first-name { display: none; }
  .topbar-leading { gap: 4px; }
  .summary .card { padding: 8px 6px; min-height: 72px; }
  .summary .eyebrow { font-size: 8px; }
}
/* Native touch browsers keep form text large enough to avoid focus zoom. */
@media (max-width: 760px) and (hover: none) {
  input, select, .filter-field input, .filter-field select, .profile-field-row input { font-size: 16px; }
}
