:root {
  color-scheme: light;
  --ink: #3b3322;
  --muted: #7f7358;
  --line: #eadfbd;
  --paper: #fffdf3;
  --app-bg: #fff7d8;
  --accent: #e9bd45;
  --accent-strong: #b98216;
  --income: #2f8f62;
  --expense: #bf5f45;
  --warning: #b68b2f;
  --nav-bg: #6f5521;
  --nav-soft: #fff2bd;
  --shadow: 0 18px 60px rgba(95, 73, 25, 0.13);
  font-family: "Segoe UI", "Noto Sans TC", system-ui, sans-serif;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background:
    linear-gradient(135deg, rgba(255, 223, 119, 0.34), rgba(255, 253, 243, 0.94) 42%, rgba(255, 247, 216, 0) 76%),
    var(--app-bg);
  color: var(--ink);
  line-height: 1.5;
}

.login-screen {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: grid;
  place-items: center;
  padding: 20px;
  background:
    linear-gradient(135deg, rgba(255, 221, 111, 0.32), rgba(255, 247, 210, 0.58)),
    var(--app-bg);
}

.login-screen.hidden {
  display: none;
}

.login-card {
  display: grid;
  gap: 16px;
  width: min(420px, 100%);
  padding: 26px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--paper);
  box-shadow: var(--shadow);
}

.login-brand {
  color: var(--ink);
  margin-bottom: 4px;
}

.login-brand small {
  color: var(--muted);
}

.login-status {
  margin: 0;
  color: var(--muted);
  font-size: 0.92rem;
}

.login-status.error {
  color: var(--expense);
  font-weight: 700;
}

.login-status.success {
  color: var(--accent-strong);
  font-weight: 700;
}

.app-shell.locked {
  display: none;
}

button,
input,
select,
textarea {
  font: inherit;
}

button {
  cursor: pointer;
}

.app-shell {
  display: grid;
  grid-template-columns: 260px minmax(0, 1fr);
  min-height: 100vh;
}

.sidebar {
  background: linear-gradient(180deg, var(--nav-bg), #8a6b2a);
  color: #fff9df;
  padding: 24px 16px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 28px;
}

.brand-mark {
  display: grid;
  place-items: center;
  width: 44px;
  height: 44px;
  border-radius: 8px;
  background: var(--nav-soft);
  color: var(--accent-strong);
  font-weight: 800;
}

.brand strong,
.brand small {
  display: block;
}

.brand small {
  margin-top: 3px;
  color: rgba(255, 249, 223, 0.76);
}

.nav-list {
  display: grid;
  gap: 8px;
}

.nav-item,
.icon-button,
.primary-button,
.secondary-button,
.text-button,
.segment {
  border: 0;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 11px;
  min-height: 46px;
  padding: 0 12px;
  border-radius: 8px;
  background: transparent;
  color: rgba(255, 249, 223, 0.88);
  text-align: left;
}

.nav-item svg,
.primary-button svg,
.secondary-button svg,
.icon-button svg {
  width: 20px;
  height: 20px;
  fill: currentColor;
  flex: 0 0 auto;
}

.nav-item.active,
.nav-item:hover {
  background: rgba(255, 247, 205, 0.18);
  color: #ffffff;
}

.main {
  min-width: 0;
  padding: clamp(18px, 3vw, 32px);
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  margin-bottom: 26px;
}

.eyebrow {
  margin: 0 0 4px;
  color: var(--muted);
  font-size: 0.92rem;
}

.storage-mode {
  margin: 8px 0 0;
  color: var(--muted);
  font-size: 0.9rem;
}

.storage-mode.connected {
  color: var(--accent-strong);
  font-weight: 700;
}

h1,
h2,
p {
  margin-top: 0;
}

h1 {
  margin-bottom: 0;
  font-size: clamp(1.9rem, 3vw, 3rem);
  letter-spacing: 0;
}

h2 {
  margin-bottom: 0;
  font-size: 1.15rem;
}

.topbar-actions,
.toolbar,
.cards-heading,
.panel-header,
.panel-actions,
.dialog-header,
.dialog-actions {
  display: flex;
  align-items: center;
  gap: 12px;
}

.topbar-actions {
  flex-wrap: wrap;
  justify-content: flex-end;
}

.icon-button {
  display: grid;
  place-items: center;
  width: 42px;
  height: 42px;
  border-radius: 8px;
  background: var(--paper);
  color: var(--ink);
  box-shadow: 0 1px 0 var(--line);
}

.icon-button:hover {
  background: #fff3c8;
  color: var(--accent);
}

.icon-button.ghost {
  background: transparent;
  box-shadow: none;
}

.primary-button,
.secondary-button,
.text-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 42px;
  border-radius: 8px;
  padding: 0 16px;
  white-space: nowrap;
}

.primary-button {
  background: var(--accent);
  color: #3b2f16;
}

.primary-button:hover {
  background: var(--accent-strong);
  color: #fff9df;
}

.primary-button.small,
.secondary-button.small {
  min-height: 36px;
  padding: 0 12px;
}

.secondary-button {
  background: #fff2bd;
  color: var(--ink);
}

.secondary-button:hover {
  background: #ffe59a;
}

.text-button {
  background: transparent;
  color: var(--accent);
  padding-inline: 4px;
}

.text-button.compact {
  min-height: auto;
  padding: 4px 0;
  font-weight: 800;
}

.section {
  display: none;
}

.section.active {
  display: block;
}

.summary-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 16px;
  margin-bottom: 18px;
}

@media (min-width: 760px) {
  #overview .summary-grid {
    grid-template-columns: repeat(4, minmax(0, 1fr));
  }
}

.metric,
.panel,
.table-wrap {
  background: rgba(251, 253, 251, 0.97);
  border: 1px solid rgba(207, 225, 211, 0.95);
  border-radius: 8px;
  box-shadow: 0 12px 34px rgba(43, 63, 59, 0.08);
}

.metric {
  position: relative;
  overflow: hidden;
  padding: 20px;
  min-height: 130px;
}

.metric::before {
  content: "";
  position: absolute;
  inset: 0 0 auto;
  height: 4px;
  background: var(--accent);
}

.metric.income::before {
  background: var(--income);
}

.metric.expense::before {
  background: var(--expense);
}

.metric.balance::before {
  background: var(--accent-strong);
}

.metric.card-debt::before {
  background: var(--warning);
}

.metric span,
.metric small {
  display: block;
  color: var(--muted);
}

.metric strong {
  display: block;
  margin: 14px 0 8px;
  font-size: clamp(1.45rem, 2.4vw, 1.8rem);
  overflow-wrap: anywhere;
}

.content-grid,
.category-layout,
.section-stack {
  display: grid;
  gap: 18px;
}

.content-grid,
.category-layout {
  display: grid;
  grid-template-columns: minmax(0, 1.35fr) minmax(320px, 0.85fr);
}

.panel {
  padding: 18px;
}

.panel-header {
  justify-content: space-between;
  margin-bottom: 16px;
}

.panel-actions {
  flex-wrap: wrap;
  justify-content: flex-end;
}

.primary-button:disabled,
.secondary-button:disabled {
  cursor: not-allowed;
  opacity: 0.55;
}

.month-picker {
  grid-auto-flow: column;
  align-items: center;
  gap: 8px;
}

.month-picker input {
  width: 150px;
}

.transaction-list,
.category-bars,
.category-list,
.category-total-list {
  display: grid;
  gap: 10px;
}

.inline-form {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 10px;
  margin-bottom: 14px;
}

.category-pill-row,
.category-total-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--paper);
}

.category-total-row strong {
  color: var(--accent-strong);
}

.category-actions {
  display: inline-flex;
  align-items: center;
  gap: 10px;
}

.category-chart {
  display: grid;
  gap: 10px;
  margin-bottom: 14px;
}

.category-chart-row {
  display: grid;
  grid-template-columns: minmax(76px, 0.35fr) minmax(120px, 1fr) auto;
  align-items: center;
  gap: 10px;
  color: var(--muted);
  font-size: 0.92rem;
}

.category-chart-row strong {
  color: var(--ink);
}

.category-chart-bar {
  overflow: hidden;
  height: 14px;
  border-radius: 999px;
  background: #f5e8bb;
}

.category-chart-fill {
  height: 100%;
  border-radius: inherit;
  background: linear-gradient(90deg, #9fd0aa, #67a87a);
}

.transaction-item {
  display: grid;
  grid-template-columns: 44px minmax(0, 1fr) auto;
  align-items: center;
  gap: 12px;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--paper);
}

.transaction-icon,
.transaction-photo {
  display: grid;
  place-items: center;
  width: 44px;
  height: 44px;
  border-radius: 8px;
  background: #fff2bd;
  color: var(--accent);
  font-weight: 800;
}

.transaction-photo,
.transaction-table-photo {
  background-position: center;
  background-size: cover;
}

.transaction-title-cell {
  display: inline-flex;
  align-items: center;
  gap: 10px;
}

.payment-label {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
  vertical-align: middle;
  font-weight: 700;
}

.payment-label.compact {
  gap: 5px;
}

.payment-thumb {
  width: 28px;
  height: 28px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background-position: center;
  background-size: cover;
  flex: 0 0 auto;
}

.payment-label.compact .payment-thumb {
  width: 18px;
  height: 18px;
  border-radius: 6px;
}

.transaction-table-photo {
  width: 34px;
  height: 34px;
  border-radius: 8px;
  border: 1px solid var(--line);
  flex: 0 0 auto;
}

.image-thumb-button {
  display: inline-flex;
  flex: 0 0 auto;
  padding: 0;
  border: 0;
  border-radius: 8px;
  background: transparent;
  cursor: zoom-in;
}

.image-thumb-button:hover .transaction-table-photo,
.image-thumb-button:focus-visible .transaction-table-photo {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(224, 180, 58, 0.24);
}

.transaction-meta strong,
.transaction-meta small {
  display: block;
}

.transaction-meta small {
  margin-top: 3px;
  color: var(--muted);
}

.amount {
  font-weight: 800;
  text-align: right;
}

.running-balance {
  color: var(--muted);
  font-weight: 700;
}

.transaction-category {
  font-weight: 800;
}

.transaction-category.income {
  color: var(--ink);
}

.transaction-category.expense {
  color: var(--expense);
}

.payment-credit-card {
  font-weight: 800;
}

.amount.income {
  color: var(--income);
}

.amount.expense {
  color: var(--expense);
}

.empty-state {
  display: grid;
  place-items: center;
  min-height: 120px;
  border: 1px dashed #d8bf78;
  border-radius: 8px;
  color: var(--muted);
  text-align: center;
  padding: 24px;
}

.bar-row {
  display: grid;
  gap: 7px;
}

.bar-label {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  color: var(--muted);
  font-size: 0.93rem;
}

.bar-track {
  overflow: hidden;
  height: 10px;
  border-radius: 999px;
  background: #f5e8bb;
}

.bar-fill {
  height: 100%;
  border-radius: inherit;
  background: linear-gradient(90deg, #f8d978, #d99a24);
}

.toolbar {
  justify-content: space-between;
  margin-bottom: 14px;
  flex-wrap: wrap;
}

.segmented {
  display: inline-flex;
  padding: 4px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--paper);
}

.segment {
  min-width: 72px;
  min-height: 34px;
  border-radius: 6px;
  background: transparent;
  color: var(--muted);
}

.segment.active {
  background: #fff0b5;
  color: var(--accent-strong);
  font-weight: 700;
}

.select-label,
.search-label {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--muted);
}

.search-label input {
  width: min(260px, 48vw);
}

select,
input,
textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--paper);
  color: var(--ink);
  min-height: 42px;
  padding: 9px 11px;
  outline: none;
}

select:focus,
input:focus,
textarea:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(233, 189, 69, 0.24);
}

.table-wrap {
  overflow: auto;
  max-width: 100%;
  -webkit-overflow-scrolling: touch;
}

table {
  width: 100%;
  border-collapse: collapse;
  min-width: 760px;
}

#transactions table {
  min-width: 980px;
}

.transaction-table {
  table-layout: fixed;
}

.transaction-table th:nth-child(1),
.transaction-table td:nth-child(1) {
  width: 10%;
}

.transaction-table th:nth-child(2),
.transaction-table td:nth-child(2) {
  width: 22%;
}

.transaction-table th:nth-child(3),
.transaction-table td:nth-child(3) {
  width: 10%;
}

.transaction-table th:nth-child(4),
.transaction-table td:nth-child(4) {
  width: 14%;
}

.transaction-table th:nth-child(5),
.transaction-table td:nth-child(5),
.transaction-table th:nth-child(6),
.transaction-table td:nth-child(6) {
  width: 11%;
}

.transaction-table th:nth-child(7),
.transaction-table td:nth-child(7) {
  width: 16%;
}

.transaction-table th:nth-child(8),
.transaction-table td:nth-child(8) {
  width: 6%;
}

th,
td {
  padding: 14px 16px;
  border-bottom: 1px solid var(--line);
  text-align: left;
  vertical-align: middle;
}

th {
  color: var(--muted);
  font-size: 0.88rem;
  font-weight: 700;
}

.amount-col,
.action-col {
  text-align: right;
}

.row-actions {
  display: inline-flex;
  gap: 6px;
}

.mini-button {
  display: grid;
  place-items: center;
  width: 34px;
  height: 34px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--paper);
  color: var(--muted);
}

.mini-button svg {
  width: 18px;
  height: 18px;
  fill: currentColor;
}

.mini-button:hover {
  color: var(--accent);
  border-color: var(--accent);
}

.cards-heading {
  justify-content: space-between;
  margin-bottom: 18px;
}

.cards-heading p {
  margin-bottom: 0;
  color: var(--muted);
}

.card-summary-strip {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr)) auto;
  align-items: center;
  gap: 12px;
  margin-bottom: 16px;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff7d8;
}

.card-summary-strip article {
  display: grid;
  gap: 5px;
  min-width: 0;
}

.card-summary-strip span,
.card-summary-strip small {
  color: var(--accent-strong);
  font-size: 0.9rem;
  font-weight: 700;
}

.card-summary-strip strong {
  color: var(--ink);
  font-size: 1.35rem;
}

.card-summary-strip .due strong {
  color: var(--expense);
}

.card-record-panel {
  margin-top: 18px;
}

.card-record-summary {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 12px;
  margin-bottom: 14px;
}

.card-record-summary article {
  display: grid;
  gap: 5px;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff7d8;
}

.card-record-summary span,
.card-record-summary small {
  color: var(--muted);
  font-size: 0.9rem;
  font-weight: 700;
}

.card-record-summary strong {
  color: var(--ink);
  font-size: 1.35rem;
}

.card-record-summary-total {
  background: #fff0b5;
  border-color: #e9bd45;
}

.card-record-summary-total strong {
  color: var(--accent-strong);
}

.card-record-panel .select-label select {
  width: 150px;
}

.card-record-table {
  min-width: 900px;
}

.stock-summary-strip {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  align-items: center;
  gap: 12px;
  margin-bottom: 16px;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: linear-gradient(135deg, #fffdf3, #fff3c8);
}

.stock-summary-strip article {
  display: grid;
  gap: 5px;
}

.stock-summary-strip span,
.stock-summary-strip small {
  color: var(--muted);
  font-size: 0.9rem;
  font-weight: 700;
}

.stock-summary-strip strong {
  color: var(--ink);
  font-size: 1.35rem;
}

.stock-summary-strip .stock-up strong,
.stock-summary-strip .stock-up small,
.amount.stock-up {
  color: var(--expense);
}

.stock-summary-strip .stock-down strong,
.stock-summary-strip .stock-down small,
.amount.stock-down {
  color: var(--income);
}

.stock-summary-strip .stock-flat strong,
.stock-summary-strip .stock-flat small,
.amount.stock-flat {
  color: var(--muted);
}

#stockQuoteStatus.success {
  color: var(--income);
  font-weight: 700;
}

#stockQuoteStatus.error {
  color: var(--expense);
  font-weight: 700;
}

.stock-table {
  min-width: 1060px;
}

.stock-trade-panel {
  margin-top: 18px;
}

.stock-trade-table {
  min-width: 980px;
}

.trade-type {
  display: inline-flex;
  align-items: center;
  min-width: 52px;
  justify-content: center;
  border-radius: 8px;
  padding: 5px 8px;
  font-size: 0.85rem;
  font-weight: 800;
}

.trade-type.buy {
  background: #fff2bd;
  color: var(--accent-strong);
}

.trade-type.sell {
  background: #fef2f2;
  color: var(--expense);
}

.table-note {
  display: block;
  margin-top: 3px;
  color: var(--muted);
  font-size: 0.85rem;
  font-weight: 500;
  overflow-wrap: anywhere;
  white-space: normal;
}

.credit-card-grid,
.account-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(290px, 1fr));
  gap: 16px;
}

.account-card {
  min-height: 176px;
  border-radius: 8px;
  padding: 20px;
  background: linear-gradient(135deg, rgba(255, 253, 243, 0.98), rgba(255, 243, 200, 0.9));
  border: 1px solid var(--line);
  box-shadow: 0 10px 34px rgba(95, 73, 25, 0.08);
  position: relative;
  overflow: hidden;
}

.account-card.has-image {
  padding-top: 0;
}

.account-photo {
  height: 132px;
  margin: 0 -20px 18px;
  background-position: center;
  background-size: cover;
  border-bottom: 1px solid var(--line);
}

.account-card::before {
  content: "";
  position: absolute;
  inset: 0 0 auto;
  height: 5px;
  background: var(--account-color);
}

.credit-card {
  min-height: 190px;
  border-radius: 8px;
  padding: 20px;
  color: var(--ink);
  box-shadow: var(--shadow);
  border: 1px solid #eadfbd;
  background: linear-gradient(135deg, #fff6cf, #fffdf3);
}

.credit-card.has-image {
  padding-top: 0;
}

.card-photo {
  height: 132px;
  margin: 0 -20px 18px;
  background-position: center;
  background-size: cover;
  border-bottom: 1px solid #eadfbd;
}

.credit-card-top,
.credit-card-bottom,
.card-progress-label,
.account-card-top,
.account-detail,
.category-total-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.account-card h3,
.credit-card h3 {
  margin: 0;
  font-size: 1.1rem;
}

.account-card small {
  display: block;
  margin-top: 4px;
  color: var(--muted);
}

.account-balance {
  margin: 28px 0 18px;
  font-size: 1.9rem;
  font-weight: 800;
  color: var(--ink);
}

.account-detail {
  color: var(--muted);
  border-top: 1px solid var(--line);
  padding-top: 14px;
}

.account-detail strong {
  color: var(--ink);
}

.account-ledger-panel {
  margin-top: 18px;
}

.account-ledger-table {
  min-width: 980px;
}

.cash-balance-panel {
  margin-bottom: 18px;
}

.cash-balance-row {
  display: grid;
  grid-template-columns: minmax(240px, 340px) minmax(180px, 1fr);
  gap: 16px;
  align-items: end;
}

.currency-input-label {
  display: grid;
  gap: 8px;
  color: var(--muted);
  font-weight: 700;
}

.currency-input {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  align-items: center;
  min-height: 44px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--paper);
  overflow: hidden;
}

.currency-input span {
  padding: 0 12px;
  color: var(--ink);
  font-weight: 900;
}

.currency-input input {
  border: 0;
  border-left: 1px solid var(--line);
  border-radius: 0;
  min-height: 44px;
}

.cash-current-balance {
  display: grid;
  gap: 6px;
}

.cash-current-balance span {
  color: var(--muted);
  font-weight: 700;
}

.cash-current-balance strong {
  color: var(--ink);
  font-size: 1.55rem;
}

.account-ledger-group td {
  padding: 14px 16px;
  background: #fff7d8;
  border-top: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
}

.account-ledger-group td,
.account-ledger-group span {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.account-ledger-group small {
  color: var(--muted);
  font-weight: 700;
}

.image-preview-row {
  display: flex;
  align-items: center;
  gap: 12px;
}

.transaction-image-preview,
.account-image-preview,
.card-image-preview {
  display: grid;
  place-items: center;
  width: 96px;
  height: 64px;
  border: 1px dashed #d8bf78;
  border-radius: 8px;
  background: #fff9df;
  color: var(--muted);
  overflow: hidden;
  background-position: center;
  background-size: cover;
}

.transaction-image-preview.has-image,
.account-image-preview.has-image,
.card-image-preview.has-image {
  color: transparent;
  border-style: solid;
}

.credit-card small {
  color: var(--muted);
}

.card-number {
  margin: 24px 0 20px;
  font-size: 1.4rem;
  letter-spacing: 3px;
}

.card-progress {
  display: grid;
  gap: 8px;
  margin-top: 16px;
}

.statement-cycle {
  margin-top: 12px;
  color: var(--muted);
  font-size: 0.9rem;
  font-weight: 700;
}

.card-settle-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-top: 14px;
}

.settle-button {
  border: 1px solid var(--accent-strong);
  border-radius: 8px;
  background: var(--accent);
  color: #3b2f16;
  min-height: 34px;
  padding: 0 12px;
  font-weight: 800;
}

.settle-button:disabled {
  cursor: not-allowed;
  opacity: 0.48;
}

.settle-summary {
  display: grid;
  gap: 8px;
  margin-bottom: 16px;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff7d8;
  color: var(--muted);
}

.settle-summary strong {
  color: var(--ink);
  font-size: 1.1rem;
}

.card-progress .bar-track {
  background: #f5e8bb;
}

.card-progress .bar-fill {
  background: var(--accent);
}

.summary-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 14px;
  border-radius: 8px;
  background: #fff4c8;
  color: var(--accent-strong);
}

.summary-row strong {
  color: var(--ink);
}

.monthly-category-panel {
  margin-top: 18px;
}

.monthly-table-wrap {
  box-shadow: none;
}

.monthly-category-table {
  min-width: 1160px;
}

.monthly-category-table th:first-child,
.monthly-category-table td:first-child {
  position: sticky;
  left: 0;
  background: var(--paper);
  z-index: 1;
}

dialog {
  width: min(680px, calc(100vw - 28px));
  border: 0;
  border-radius: 8px;
  padding: 0;
  box-shadow: var(--shadow);
}

dialog::backdrop {
  background: rgba(95, 73, 25, 0.32);
}

.dialog-card {
  padding: 22px;
}

.small-dialog {
  width: min(480px, calc(100vw - 28px));
}

.image-dialog {
  width: min(920px, calc(100vw - 24px));
  max-height: calc(100dvh - 24px);
  background: var(--paper);
}

.image-dialog-card {
  padding: 18px;
}

.image-dialog img {
  display: block;
  width: 100%;
  max-height: calc(100dvh - 122px);
  object-fit: contain;
  border-radius: 8px;
  background: #fff8df;
}

.dialog-header {
  justify-content: space-between;
  margin-bottom: 18px;
}

.form-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 14px;
}

label {
  display: grid;
  gap: 7px;
  color: var(--muted);
  font-size: 0.92rem;
}

.balance-preview {
  color: var(--accent-strong);
  font-weight: 700;
}

.balance-preview.warning {
  color: var(--expense);
}

.full {
  grid-column: 1 / -1;
}

textarea {
  resize: vertical;
}

.dialog-actions {
  justify-content: flex-end;
  margin-top: 20px;
}

.swatches {
  display: flex;
  flex-wrap: wrap;
  gap: 9px;
}

.swatch {
  width: 34px;
  height: 34px;
  border: 3px solid var(--paper);
  border-radius: 8px;
  box-shadow: 0 0 0 1px var(--line);
}

.swatch.active {
  box-shadow: 0 0 0 3px var(--accent);
}

@media (max-width: 980px) {
  .app-shell {
    grid-template-columns: 1fr;
  }

  .sidebar {
    position: sticky;
    top: 0;
    z-index: 10;
    padding: 12px;
    box-shadow: 0 8px 24px rgba(31, 47, 45, 0.14);
  }

  .brand {
    margin-bottom: 12px;
  }

  .nav-list {
    grid-template-columns: repeat(7, minmax(0, 1fr));
  }

  .nav-item {
    justify-content: center;
    padding: 0 8px;
    min-width: 0;
  }

  .content-grid,
  .category-layout {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .topbar {
    align-items: flex-start;
  }
}

@media (max-width: 680px) {
  .main {
    padding: 16px 12px 26px;
  }

  .topbar,
  .cards-heading,
  .panel-header {
    align-items: stretch;
    flex-direction: column;
    gap: 10px;
  }

  .card-summary-strip,
  .stock-summary-strip {
    grid-template-columns: 1fr;
  }

  .topbar-actions {
    justify-content: flex-start;
  }

  .topbar-actions,
  .panel-actions,
  .toolbar {
    width: 100%;
  }

  .toolbar,
  .topbar-actions {
    align-items: stretch;
    flex-direction: column;
  }

  .search-label,
  .select-label {
    align-items: stretch;
    flex-direction: column;
    width: 100%;
  }

  .search-label input,
  .select-label select,
  .primary-button,
  .secondary-button {
    width: 100%;
  }

  .icon-button {
    width: 44px;
    min-width: 44px;
  }

  .topbar-actions .icon-button {
    width: 100%;
  }

  .segmented {
    width: 100%;
  }

  .segment {
    flex: 1 1 0;
    min-width: 0;
  }

  .sidebar {
    padding: 10px 8px;
  }

  .sidebar .brand {
    margin-bottom: 8px;
  }

  .nav-list {
    display: flex;
    gap: 6px;
    overflow-x: auto;
    padding-bottom: 2px;
    scrollbar-width: none;
  }

  .nav-list::-webkit-scrollbar {
    display: none;
  }

  .nav-item {
    font-size: 0;
    flex: 0 0 48px;
    min-height: 44px;
  }

  .nav-item svg {
    width: 22px;
    height: 22px;
  }

  .summary-grid,
  .content-grid,
  .category-layout,
  .form-grid {
    grid-template-columns: 1fr;
  }

  .transaction-item {
    grid-template-columns: 40px minmax(0, 1fr);
  }

  .transaction-item .amount {
    grid-column: 2;
    text-align: left;
  }

  .metric,
  .panel,
  .table-wrap {
    border-radius: 8px;
  }

  .metric,
  .panel {
    padding: 16px;
  }

  .stock-summary-strip {
    padding: 12px;
  }

  .cash-balance-row {
    grid-template-columns: 1fr;
  }

  dialog {
    width: calc(100vw - 20px);
    max-height: calc(100dvh - 20px);
  }

  .dialog-card {
    padding: 18px;
  }

  .dialog-actions {
    align-items: stretch;
    flex-direction: column-reverse;
  }

}

@media (max-width: 420px) {
  .brand-mark {
    width: 38px;
    height: 38px;
  }

  .brand strong {
    font-size: 0.95rem;
  }

  .brand small {
    font-size: 0.78rem;
  }

  h1 {
    font-size: 1.7rem;
  }

  th,
  td {
    padding: 12px;
  }
}
