:root {
  color-scheme: light;
  --bg: #f4f8fa;
  --surface: #ffffff;
  --surface-muted: #eaf5f7;
  --ink: #061b3b;
  --muted: #607083;
  --line: #d9e6eb;
  --primary: #082b5f;
  --primary-strong: #051f48;
  --accent: #13b9b0;
  --income: #168457;
  --expense: #c44f4b;
  --warning: #b17617;
  --blue: #0b79a8;
  --shadow: 0 18px 42px rgba(6, 27, 59, 0.1);
  --radius: 8px;
  --content-max: 1180px;
  --page-gutter: 16px;
  --shell-top: 22px;
  --shell-bottom: 32px;
  --section-gap: 18px;
  --panel-pad: 16px;
  --field-pad-x: 12px;
  --touch-target: 44px;
  --h1-size: 2rem;
  --h2-size: 1.55rem;
  --h3-size: 1rem;
  --metric-size: 1.55rem;
  --tab-label-size: 0.88rem;
}

* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

html {
  min-height: 100%;
  background: var(--bg);
}

body {
  min-height: 100%;
  margin: 0;
  background:
    linear-gradient(180deg, #e8f6f8 0%, rgba(244, 248, 250, 0) 360px),
    var(--bg);
  color: var(--ink);
  font-family:
    Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI",
    sans-serif;
  font-size: 16px;
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
}

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

button {
  cursor: pointer;
}

.app-shell {
  width: min(var(--content-max), calc(100% - (var(--page-gutter) * 2)));
  margin: 0 auto;
  padding: calc(var(--shell-top) + env(safe-area-inset-top)) 0 var(--shell-bottom);
}

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

.brand-row {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
}

.brand-mark {
  width: var(--touch-target);
  height: var(--touch-target);
  border-radius: var(--radius);
  box-shadow: 0 8px 18px rgba(6, 27, 59, 0.12);
  flex: 0 0 auto;
}

.menu-button {
  display: grid;
  place-items: center;
  gap: 4px;
  width: var(--touch-target);
  min-width: var(--touch-target);
  height: var(--touch-target);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: 0 8px 18px rgba(6, 27, 59, 0.08);
}

.menu-button:focus-visible {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(19, 185, 176, 0.2);
  outline: none;
}

.menu-bar {
  width: 20px;
  height: 2px;
  border-radius: 999px;
  background: var(--accent);
}

h1,
h2,
h3,
h4,
p {
  margin: 0;
}

h1 {
  font-size: var(--h1-size);
  line-height: 1.08;
  letter-spacing: 0;
}

h2 {
  font-size: var(--h2-size);
  line-height: 1.15;
  letter-spacing: 0;
}

h3 {
  font-size: var(--h3-size);
  line-height: 1.25;
  letter-spacing: 0;
}

h4 {
  font-size: 0.96rem;
  line-height: 1.25;
  letter-spacing: 0;
}

.eyebrow {
  margin-bottom: 4px;
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.month-control {
  display: grid;
  gap: 6px;
  min-width: 164px;
}

.month-control label,
label {
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 700;
  letter-spacing: 0;
}

input,
select,
textarea {
  width: 100%;
  min-height: var(--touch-target);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--ink);
  padding: 10px var(--field-pad-x);
  outline: none;
}

input:focus,
select:focus,
textarea:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(20, 92, 74, 0.14);
}

textarea {
  min-height: 128px;
  resize: vertical;
  line-height: 1.45;
}

.tabs {
  position: fixed;
  inset: 0 auto 0 0;
  z-index: 40;
  display: flex;
  flex-direction: column;
  gap: 8px;
  width: min(318px, calc(100% - 56px));
  padding: calc(20px + env(safe-area-inset-top)) 14px calc(20px + env(safe-area-inset-bottom));
  border-right: 1px solid rgba(220, 229, 223, 0.88);
  background: rgba(255, 255, 255, 0.96);
  backdrop-filter: blur(14px);
  box-shadow: 24px 0 46px rgba(21, 42, 34, 0.16);
  transform: translateX(calc(-100% - 16px));
  transition: transform 180ms ease;
}

body.menu-open {
  overflow: hidden;
}

body.menu-open .tabs {
  transform: translateX(0);
}

.drawer-scrim {
  position: fixed;
  inset: 0;
  z-index: 35;
  background: rgba(23, 33, 29, 0.32);
  opacity: 0;
  pointer-events: none;
  transition: opacity 180ms ease;
}

body.menu-open .drawer-scrim {
  opacity: 1;
  pointer-events: auto;
}

.drawer-heading {
  display: grid;
  gap: 2px;
  padding: 2px 4px 10px;
}

.drawer-heading strong {
  font-size: 1.15rem;
  line-height: 1.2;
}

.tab {
  display: flex;
  align-items: center;
  justify-content: flex-start;
  gap: 10px;
  min-height: 48px;
  border: 0;
  border-radius: var(--radius);
  background: transparent;
  color: var(--muted);
  font-size: var(--tab-label-size);
  font-weight: 700;
  overflow: hidden;
  padding: 0 12px;
}

.tab.active {
  background: var(--primary);
  color: #fff;
}

.tab-icon {
  display: grid;
  place-items: center;
  width: 22px;
  height: 22px;
  font-size: 1rem;
  line-height: 1;
  flex: 0 0 auto;
}

.tab span:last-child {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.view {
  display: none;
}

.active-view {
  display: block;
}

#dashboardView.active-view {
  display: flex;
  flex-direction: column;
}

.section-heading,
.panel-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
}

.section-heading {
  margin-bottom: 16px;
  order: 1;
}

.metric-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
  order: 3;
}

.metric-card,
.panel {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: var(--shadow);
}

.metric-card {
  display: grid;
  gap: 8px;
  align-content: space-between;
  aspect-ratio: 1 / 1;
  min-height: auto;
  padding: calc(var(--panel-pad) + 2px);
  border-top: 4px solid var(--primary);
}

.metric-card strong {
  font-size: var(--metric-size);
  line-height: 1.1;
  letter-spacing: 0;
  word-break: break-word;
}

.metric-card small,
.metric-label,
.item-meta,
.privacy-note {
  color: var(--muted);
}

.metric-label {
  font-size: 0.82rem;
  font-weight: 800;
  text-transform: uppercase;
}

.metric-card.income {
  border-top-color: var(--income);
}

.metric-card.receivable {
  border-top-color: var(--blue);
}

.metric-card.expense {
  border-top-color: var(--expense);
}

.metric-card.due {
  border-top-color: var(--warning);
}

.dashboard-grid,
.workspace-grid,
.single-panel,
.settings-grid,
.reports-grid {
  display: grid;
  gap: var(--section-gap);
  margin-top: var(--section-gap);
}

.dashboard-grid {
  grid-template-columns: repeat(auto-fit, minmax(min(100%, 340px), 1fr));
  order: 4;
}

.workspace-grid {
  grid-template-columns: minmax(min(100%, 310px), 0.72fr) minmax(0, 1.28fr);
}

.settings-grid {
  grid-template-columns: minmax(0, 1fr) minmax(min(100%, 300px), 0.48fr);
}

.reports-grid {
  grid-template-columns: repeat(3, minmax(0, 1fr));
}

.report-period-control {
  display: grid;
  gap: 6px;
  min-width: min(100%, 190px);
}

.report-summary-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(min(100%, 170px), 1fr));
  gap: 10px;
  margin-top: var(--section-gap);
}

.report-stat {
  display: grid;
  gap: 8px;
  min-height: 116px;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: 0 12px 28px rgba(6, 27, 59, 0.08);
}

.report-stat span {
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 900;
  text-transform: uppercase;
}

.report-stat strong {
  color: var(--ink);
  font-size: 1.2rem;
  line-height: 1.12;
}

.report-stat small {
  color: var(--muted);
  font-weight: 700;
}

.report-stat.income {
  border-top: 4px solid var(--income);
}

.report-stat.expense {
  border-top: 4px solid var(--expense);
}

.report-stat.warning {
  border-top: 4px solid var(--warning);
}

.report-stat.neutral {
  border-top: 4px solid var(--blue);
}

.report-wide {
  grid-column: 1 / -1;
}

.bar-list,
.insight-list {
  display: grid;
  gap: 10px;
  margin-top: 14px;
}

.trend-item,
.rank-item {
  display: grid;
  gap: 10px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #fbfcfb;
}

.trend-head,
.rank-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.trend-bars {
  display: grid;
  gap: 8px;
}

.bar-row {
  display: grid;
  grid-template-columns: 82px minmax(0, 1fr) 104px;
  align-items: center;
  gap: 10px;
  color: var(--muted);
  font-size: 0.82rem;
  font-weight: 800;
}

.bar-row strong {
  color: var(--ink);
  text-align: right;
}

.bar-track {
  height: 9px;
  overflow: hidden;
  border-radius: 999px;
  background: var(--surface-muted);
}

.bar-fill {
  display: block;
  height: 100%;
  border-radius: inherit;
  background: var(--blue);
}

.bar-fill.income {
  background: var(--income);
}

.bar-fill.expense {
  background: var(--expense);
}

.bar-fill.warning {
  background: var(--warning);
}

.bar-fill.neutral {
  background: var(--blue);
}

.panel {
  padding: var(--panel-pad);
  container-type: inline-size;
}

.form-panel {
  display: grid;
  align-content: start;
  gap: 14px;
}

.quick-panel {
  margin-top: var(--section-gap);
  order: 2;
}

.quick-panel .panel-heading {
  align-items: center;
}

.quick-actions {
  display: grid;
  grid-template-columns: repeat(2, minmax(120px, 1fr));
  gap: 8px;
}

.quick-income-button {
  background: var(--income);
}

.quick-expense-button {
  background: var(--expense);
}

.quick-form {
  display: grid;
  gap: 12px;
  margin-top: 0;
}

.quick-kind {
  display: none;
}

.toggle-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.toggle-chip {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-height: 40px;
  padding: 8px 11px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #fbfcfb;
  color: var(--ink);
  font-size: 0.84rem;
  font-weight: 800;
}

.toggle-chip input {
  width: 18px;
  min-height: 18px;
  accent-color: var(--primary);
}

.toggle-chip:has(input:checked) {
  border-color: rgba(20, 92, 74, 0.34);
  background: #e9f5ef;
  color: var(--primary);
}

.form-spacer {
  min-height: var(--touch-target);
}

.two-columns,
.three-columns,
.action-row,
.inline-form {
  display: grid;
  gap: 10px;
}

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

.three-columns {
  grid-template-columns: repeat(3, minmax(0, 1fr));
}

.action-row {
  grid-template-columns: repeat(2, minmax(0, 1fr));
  margin-top: 12px;
}

.compact-heading {
  align-items: flex-start;
}

.sync-box {
  display: grid;
  gap: 12px;
  margin-bottom: 14px;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface-muted);
}

.sync-form {
  display: grid;
  gap: 10px;
}

.sync-form input,
.sync-form select {
  background: var(--surface);
}

.sync-actions {
  margin-top: 0;
}

.inline-form {
  grid-template-columns: minmax(0, 1fr) 138px 44px;
  margin: 14px 0;
}

.segmented {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 6px;
  padding: 6px;
  border-radius: var(--radius);
  background: var(--surface-muted);
}

.segment {
  min-height: var(--touch-target);
  border: 0;
  border-radius: 6px;
  background: transparent;
  color: var(--muted);
  font-weight: 800;
}

.segment.active {
  background: var(--surface);
  color: var(--primary);
  box-shadow: 0 4px 12px rgba(21, 42, 34, 0.08);
}

.compact-segmented {
  max-width: 420px;
  margin-top: 14px;
}

.primary-button,
.secondary-button,
.danger-button,
.icon-button {
  min-height: var(--touch-target);
  border-radius: var(--radius);
  border: 1px solid transparent;
  font-weight: 800;
}

.primary-button {
  background: var(--primary);
  color: #fff;
}

.primary-button:hover {
  background: var(--primary-strong);
}

.secondary-button {
  display: grid;
  place-items: center;
  border-color: var(--line);
  background: var(--surface);
  color: var(--ink);
}

.compact-button {
  min-width: 150px;
  padding: 0 12px;
}

.panel-note {
  margin-top: 4px;
  color: var(--muted);
  font-size: 0.82rem;
  line-height: 1.35;
}

.wide-button {
  width: 100%;
  margin-top: 10px;
}

.danger-button {
  width: 100%;
  margin-top: 10px;
  border-color: rgba(187, 62, 55, 0.28);
  background: #fff4f2;
  color: var(--expense);
}

.icon-button {
  display: grid;
  place-items: center;
  width: var(--touch-target);
  min-width: var(--touch-target);
  padding: 0;
  background: var(--primary);
  color: #fff;
  font-size: 1.25rem;
  line-height: 1;
}

.file-button {
  position: relative;
  overflow: hidden;
}

.file-button input {
  position: absolute;
  inset: 0;
  opacity: 0;
}

.item-list {
  display: grid;
  gap: 10px;
  margin-top: 14px;
}

.list-item {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 12px;
  align-items: center;
  min-height: 72px;
  padding: max(12px, calc(var(--panel-pad) - 4px));
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #fbfcfb;
}

.list-item.state-positive {
  border-color: rgba(29, 122, 85, 0.22);
  background: #f0faf4;
}

.list-item.state-negative {
  border-color: rgba(187, 62, 55, 0.22);
  background: #fff5f3;
}

.list-item.state-warning {
  border-color: rgba(165, 106, 25, 0.24);
  background: #fff9ed;
}

.list-item.is-clickable {
  cursor: pointer;
}

.list-item.is-clickable:hover,
.list-item.is-clickable:focus-visible {
  border-color: rgba(20, 92, 74, 0.42);
  box-shadow: 0 0 0 3px rgba(20, 92, 74, 0.1);
  outline: none;
}

.item-main {
  min-width: 0;
}

.item-title {
  overflow: hidden;
  color: var(--ink);
  font-weight: 800;
  text-overflow: ellipsis;
  white-space: nowrap;
  overflow-wrap: anywhere;
}

.item-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 6px 10px;
  margin-top: 5px;
  font-size: 0.82rem;
}

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

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

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

.amount-neutral {
  color: var(--blue);
}

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

.item-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 8px;
}

.mini-button {
  min-height: 36px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--surface);
  color: var(--ink);
  font-size: 0.82rem;
  font-weight: 800;
}

.mini-button.danger {
  color: var(--expense);
}

.mini-button.status-positive {
  border-color: rgba(29, 122, 85, 0.28);
  background: #edf8f2;
  color: var(--income);
}

.mini-button.status-warning {
  border-color: rgba(165, 106, 25, 0.26);
  background: #fff8eb;
  color: var(--warning);
}

.mini-button.status-negative {
  border-color: rgba(187, 62, 55, 0.28);
  background: #fff4f2;
  color: var(--expense);
}

.empty-state {
  min-height: 92px;
  padding: 18px;
  border: 1px dashed var(--line);
  border-radius: var(--radius);
  background: #fbfcfb;
  color: var(--muted);
}

.status-badge,
.subtle-pill,
.tag {
  display: inline-flex;
  align-items: center;
  min-height: 30px;
  border-radius: 999px;
  padding: 4px 10px;
  font-size: 0.78rem;
  font-weight: 800;
}

.status-badge {
  background: var(--surface-muted);
  color: var(--muted);
}

.status-badge.good {
  background: #e4f4eb;
  color: var(--income);
}

.status-badge.warn {
  background: #fff3df;
  color: var(--warning);
}

.status-badge.bad {
  background: #fff1ef;
  color: var(--expense);
}

.subtle-pill,
.tag {
  background: var(--surface-muted);
  color: var(--muted);
}

.tag-list {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.tag {
  gap: 8px;
}

.tag button {
  display: grid;
  place-items: center;
  width: 22px;
  height: 22px;
  border: 0;
  border-radius: 999px;
  background: rgba(100, 115, 109, 0.16);
  color: var(--ink);
  font-weight: 900;
}

.category-list {
  display: grid;
  gap: 8px;
  margin-top: 14px;
}

.category-board {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
  margin-top: 14px;
}

.category-group {
  display: grid;
  align-content: start;
  gap: 10px;
  min-height: 180px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #fbfcfb;
}

.category-group.state-positive {
  border-color: rgba(29, 122, 85, 0.2);
  background: #f5fcf8;
}

.category-group.state-negative {
  border-color: rgba(187, 62, 55, 0.2);
  background: #fff8f7;
}

.category-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  min-height: 58px;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #fbfcfb;
}

.category-item.state-positive {
  border-color: rgba(29, 122, 85, 0.22);
  background: #f0faf4;
}

.category-item.state-negative {
  border-color: rgba(187, 62, 55, 0.22);
  background: #fff5f3;
}

.category-main {
  display: grid;
  gap: 2px;
  min-width: 0;
}

.category-main strong {
  overflow: hidden;
  color: var(--ink);
  text-overflow: ellipsis;
  white-space: nowrap;
}

.category-main span {
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 800;
}

.category-actions {
  display: flex;
  flex: 0 0 auto;
  gap: 6px;
}

.support-description {
  margin-top: 8px;
  color: var(--ink);
  font-size: 0.92rem;
  line-height: 1.45;
  overflow-wrap: anywhere;
}

.privacy-note {
  margin-top: 12px;
  font-size: 0.88rem;
  line-height: 1.45;
}

.about-panel {
  grid-column: 1 / -1;
}

.about-content {
  display: grid;
  gap: 8px;
  margin-top: 14px;
  color: var(--muted);
  font-size: 0.92rem;
  line-height: 1.5;
}

.about-content strong {
  color: var(--ink);
}

.toast {
  position: fixed;
  right: max(18px, env(safe-area-inset-right));
  bottom: max(18px, env(safe-area-inset-bottom));
  z-index: 30;
  max-width: min(420px, calc(100% - 36px));
  padding: 12px 14px;
  border-radius: var(--radius);
  background: var(--ink);
  color: #fff;
  font-weight: 800;
  opacity: 0;
  pointer-events: none;
  transform: translateY(10px);
  transition: opacity 160ms ease, transform 160ms ease;
}

.toast.show {
  opacity: 1;
  transform: translateY(0);
}

.modal-layer {
  position: fixed;
  inset: 0;
  z-index: 40;
  display: grid;
  place-items: center;
  padding: max(16px, env(safe-area-inset-top)) max(14px, env(safe-area-inset-right)) max(16px, env(safe-area-inset-bottom))
    max(14px, env(safe-area-inset-left));
}

.modal-layer[hidden] {
  display: none !important;
}

.modal-scrim {
  position: absolute;
  inset: 0;
  border: 0;
  background: rgba(6, 27, 59, 0.42);
}

.modal-panel {
  position: relative;
  z-index: 1;
  display: grid;
  gap: 16px;
  width: min(680px, 100%);
  max-height: min(760px, calc(100vh - 32px));
  overflow: auto;
  padding: var(--panel-pad);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: 0 24px 80px rgba(6, 27, 59, 0.22);
}

.quick-dialog-panel {
  width: min(780px, 100%);
}

.modal-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
}

.modal-close {
  flex: 0 0 auto;
}

.edit-form {
  display: grid;
  gap: 12px;
}

.edit-actions {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
  margin-top: 4px;
}

@container (max-width: 360px) {
  .panel-heading,
  .section-heading {
    align-items: flex-start;
    flex-direction: column;
  }

  .item-actions {
    justify-content: stretch;
  }

  .mini-button {
    flex: 1 1 0;
  }
}

@media (min-width: 700px) {
  :root {
    --page-gutter: 24px;
    --shell-top: 24px;
    --section-gap: 18px;
    --panel-pad: 18px;
    --h1-size: 2.25rem;
    --metric-size: 1.72rem;
  }

  .metric-card {
    aspect-ratio: 1 / 1;
  }
}

@media (min-width: 1100px) {
  :root {
    --page-gutter: 32px;
    --shell-top: 30px;
    --section-gap: 20px;
    --panel-pad: 20px;
    --h1-size: 2.5rem;
    --h2-size: 1.65rem;
    --metric-size: 1.95rem;
  }

  body {
    background:
      linear-gradient(90deg, rgba(8, 43, 95, 0.04) 0 1px, transparent 1px) 0 0 / 32px 32px,
      linear-gradient(180deg, #e8f6f8 0%, rgba(244, 248, 250, 0) 420px),
      var(--bg);
  }

  .app-shell {
    min-height: 100vh;
    padding-inline: 20px;
    border-inline: 1px solid rgba(217, 230, 235, 0.72);
    background: rgba(255, 255, 255, 0.38);
  }

  .metric-grid {
    grid-template-columns: repeat(4, minmax(0, 1fr));
  }
}

@media (max-width: 880px) {
  :root {
    --content-max: 720px;
    --page-gutter: 11px;
    --shell-top: 14px;
    --shell-bottom: 32px;
    --section-gap: 12px;
    --panel-pad: 14px;
    --h1-size: 1.8rem;
    --h2-size: 1.38rem;
    --metric-size: 1.48rem;
    --tab-label-size: 0.72rem;
  }

  .app-shell {
    width: min(var(--content-max), calc(100% - (var(--page-gutter) * 2)));
  }

  .topbar {
    align-items: stretch;
    flex-direction: column;
    gap: 12px;
  }

  .brand-row {
    align-items: flex-start;
  }

  .tabs {
    width: min(304px, calc(100% - 46px));
  }

  .tab {
    min-height: 50px;
    gap: 10px;
  }

  .tab-icon {
    width: 18px;
    height: 18px;
  }

  .dashboard-grid,
  .workspace-grid,
  .settings-grid,
  .reports-grid,
  .category-board {
    grid-template-columns: 1fr;
  }

  .metric-grid {
    gap: 10px;
  }

  .metric-card {
    min-height: 116px;
  }
}

@media (max-width: 520px) {
  :root {
    --page-gutter: 10px;
    --panel-pad: 12px;
    --h1-size: 1.58rem;
    --h2-size: 1.28rem;
    --metric-size: 1.36rem;
  }

  .section-heading,
  .panel-heading {
    align-items: flex-start;
  }

  .two-columns,
  .three-columns,
  .action-row,
  .inline-form {
    grid-template-columns: 1fr;
  }

  .inline-form .icon-button {
    width: 100%;
  }

  .report-period-control {
    width: 100%;
  }

  .report-stat {
    min-height: 104px;
  }

  .bar-row {
    grid-template-columns: minmax(0, 1fr) 92px;
    grid-template-areas:
      "label amount"
      "track track";
  }

  .bar-row > span:first-child {
    grid-area: label;
  }

  .bar-row > .bar-track {
    grid-area: track;
  }

  .bar-row > strong {
    grid-area: amount;
  }

  .list-item {
    grid-template-columns: 1fr;
  }

  .item-amount {
    text-align: left;
  }

  .category-item,
  .category-actions {
    align-items: stretch;
    flex-direction: column;
  }
}

@media (max-width: 360px) {
  :root {
    --page-gutter: 8px;
    --panel-pad: 10px;
    --field-pad-x: 10px;
    --h1-size: 1.42rem;
    --h2-size: 1.18rem;
    --metric-size: 1.22rem;
    --tab-label-size: 0.66rem;
  }

  .tabs {
    width: min(292px, calc(100% - 38px));
    padding-inline: 10px;
  }

  .tab span:last-child {
    max-width: none;
  }

  .item-meta {
    gap: 5px 8px;
  }
}
