.util-toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  margin-bottom: 1rem;
}

.toolbar-left {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.75rem;
}

.toolbar-actions {
  display: flex;
  align-items: center;
  gap: 0.6rem;
}

.period-nav {
  display: flex;
  align-items: center;
  gap: 0.35rem;
}

.period-title {
  margin: 0;
  min-width: 4.5rem;
  text-align: center;
  font-size: 1.1rem;
}

.view-toggle {
  display: inline-flex;
  gap: 0.35rem;
  padding: 0.2rem;
  background: var(--bg-subtle);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
}

.view-btn.active {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--on-accent);
  font-weight: 600;
}

.save-status { font-size: 0.8rem; color: var(--muted); min-width: 4rem; }
.save-status.saved { color: var(--success); }
.save-status.error { color: var(--danger); }

.panel-bar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem 0.75rem;
  margin-bottom: 0.75rem;
}

.panel-bar .addr-tabs {
  margin-bottom: 0;
  flex: 1;
  min-width: 0;
}

.panel-bar-actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.4rem;
}

.col-head-cell {
  min-width: 7.5rem;
  vertical-align: top;
}

.col-head {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.3rem;
}

.col-head-note {
  margin-top: 0.25rem;
  font-size: 0.72rem;
  font-weight: 500;
  color: var(--muted);
  line-height: 1.25;
  max-width: 10rem;
  white-space: normal;
}
.col-head-note-empty {
  font-style: italic;
  opacity: 0.65;
}

.col-head-image {
  display: block;
  margin-top: 0.35rem;
  padding: 0;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--bg-subtle);
  cursor: pointer;
  overflow: hidden;
  max-width: 10rem;
}

.col-head-image img {
  display: block;
  width: 100%;
  max-height: 4.5rem;
  object-fit: cover;
}

.col-head-image:hover {
  border-color: var(--accent);
}

.col-hidden-badge {
  font-size: 0.65rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  color: var(--muted);
  border: 1px solid var(--border);
  border-radius: 3px;
  padding: 0.05rem 0.3rem;
}

.col-is-hidden {
  opacity: 0.55;
  background: color-mix(in srgb, var(--bg-subtle) 70%, transparent);
}

.btn-stats {
  flex-shrink: 0;
  border: 1px solid var(--border);
  background: var(--surface);
  border-radius: 4px;
  padding: 0.2rem 0.35rem;
  font-size: 0.65rem;
  font-weight: 700;
  cursor: pointer;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.02em;
}
.btn-stats:hover {
  color: inherit;
  border-color: var(--accent);
}

.stats-dialog { width: min(28rem, 96vw); }
.stats-body { display: flex; flex-direction: column; gap: 0.75rem; }
.stats-current {
  display: flex;
  flex-direction: column;
  gap: 0.15rem;
  padding: 0.55rem 0.65rem;
  background: var(--bg-subtle);
  border-radius: 6px;
  border: 1px solid var(--border);
}
.stats-label { font-size: 0.75rem; color: var(--muted); text-transform: uppercase; letter-spacing: 0.04em; }
.stats-value { font-size: 1.35rem; font-weight: 800; }
.stats-compare { display: flex; flex-direction: column; gap: 0.45rem; }
.stats-row {
  display: grid;
  grid-template-columns: 1fr auto auto;
  gap: 0.4rem 0.6rem;
  align-items: center;
  font-size: 0.85rem;
}
.stats-subhead { margin: 0.2rem 0 0; font-size: 0.9rem; }
.stats-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.82rem;
}
.stats-table th,
.stats-table td {
  border-bottom: 1px solid var(--border);
  padding: 0.3rem 0.35rem;
  text-align: left;
}
.trend-pill {
  font-size: 0.68rem;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  padding: 0.12rem 0.4rem;
  border-radius: 3px;
  border: 1px solid var(--border);
}
.trend-up { color: #15803d; }
.trend-down { color: var(--danger, #b91c1c); }
.trend-flat { color: var(--muted); }
.trend-pill.trend-up {
  background: #dcfce7;
  border-color: #86efac;
  color: #15803d;
}
.trend-pill.trend-down {
  background: #fee2e2;
  border-color: #fca5a5;
  color: #b91c1c;
}
.trend-pill.trend-flat {
  background: var(--bg-subtle);
}

.addr-tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
  margin-bottom: 0.75rem;
}

.col-edit {
  border: none;
  background: transparent;
  padding: 0;
  margin: 0;
  font: inherit;
  font-weight: 700;
  color: inherit;
  cursor: pointer;
  text-align: left;
  text-decoration: underline dotted color-mix(in srgb, currentColor 35%, transparent);
  text-underline-offset: 0.15em;
}
.col-edit:hover {
  color: var(--accent);
}

.addr-tab {
  border: 1px solid var(--border);
  background: var(--surface);
  border-radius: var(--radius-sm);
  padding: 0.35rem 0.7rem;
  font-size: 0.85rem;
  cursor: pointer;
  color: inherit;
}
.addr-tab.active {
  border-color: var(--accent);
  background: color-mix(in srgb, var(--accent) 12%, var(--surface));
  font-weight: 600;
}

.table-wrap {
  overflow: auto;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
}

.util-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.85rem;
  min-width: 36rem;
}

.util-table th,
.util-table td {
  border-bottom: 1px solid var(--border);
  padding: 0.35rem 0.45rem;
  text-align: left;
  vertical-align: middle;
}

.util-table th {
  background: var(--bg-subtle);
  font-weight: 700;
  position: sticky;
  top: 0;
  z-index: 1;
}

.util-table th.month-col,
.util-table td.month-col {
  position: sticky;
  left: 0;
  background: var(--surface);
  z-index: 2;
  min-width: 5.5rem;
  font-weight: 600;
}

.util-table th.month-col { z-index: 3; background: var(--bg-subtle); }

.util-table td.total-col,
.util-table th.total-col {
  font-weight: 700;
  white-space: nowrap;
}

.util-table tfoot td {
  background: var(--bg-subtle);
  font-weight: 700;
}

.year-select {
  min-width: 5.5rem;
  font-weight: 700;
  font-size: 1.05rem;
  text-align: center;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 0.3rem 0.45rem;
  background: var(--surface);
  color: inherit;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  border: 0;
}

.year-group-row td {
  background: color-mix(in srgb, var(--accent) 10%, var(--bg-subtle));
  font-weight: 800;
  font-size: 0.9rem;
  letter-spacing: 0.02em;
  border-bottom: 1px solid var(--border);
  padding: 0.45rem 0.55rem;
}

.cell-stack {
  display: flex;
  flex-direction: column;
  gap: 0.15rem;
  min-width: 7.5rem;
}

.cell-row {
  display: flex;
  align-items: center;
  gap: 0.25rem;
}

.cell-stack input,
.util-table input.cell-input {
  flex: 1;
  width: 100%;
  min-width: 3.5rem;
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 0.25rem 0.35rem;
  background: var(--surface);
  color: inherit;
  font: inherit;
}

.util-table input.cell-input.is-paid,
.cell-stack.is-paid input.cell-input {
  background: #dcfce7;
  border-color: #86efac;
}

.btn-paid {
  flex-shrink: 0;
  border: 1px solid var(--border);
  background: var(--surface);
  border-radius: 4px;
  padding: 0.2rem 0.35rem;
  font-size: 0.68rem;
  font-weight: 800;
  cursor: pointer;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.02em;
}
.btn-paid.active {
  background: #16a34a;
  border-color: #16a34a;
  color: #fff;
}

.btn-note {
  flex-shrink: 0;
  border: 1px solid var(--border);
  background: var(--surface);
  border-radius: 4px;
  width: 1.7rem;
  height: 1.7rem;
  padding: 0;
  cursor: pointer;
  font-size: 0.85rem;
  line-height: 1;
}
.btn-note.has-note {
  border-color: var(--accent);
  background: color-mix(in srgb, var(--accent) 12%, var(--surface));
}

.cell-diff {
  font-size: 0.72rem;
  color: var(--muted);
}
.cell-diff.has-value { color: inherit; }
.cell-diff.neg { color: var(--danger); }

.note-dialog { width: min(32rem, 96vw); }
.note-dialog textarea {
  width: 100%;
  box-sizing: border-box;
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 0.45rem 0.55rem;
  font: inherit;
  resize: vertical;
  background: var(--surface);
  color: inherit;
}
.note-image-preview-wrap {
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
}
.note-image-preview-wrap img {
  max-width: 100%;
  max-height: 220px;
  object-fit: contain;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--bg-subtle);
}

.addr-section-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  margin: 0.25rem 0 0.5rem;
}
.addr-section-head h3 { margin: 0; font-size: 1.05rem; }
.types-head { margin-top: 1.5rem; }

.addr-manage-table { min-width: 20rem; }
.addr-manage-table .actions {
  display: flex;
  gap: 0.35rem;
  justify-content: flex-end;
}

.util-dialog {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem 1.1rem;
  width: min(26rem, 96vw);
  background: var(--surface);
  color: inherit;
}
.util-dialog::backdrop { background: rgba(0, 0, 0, 0.4); }
.util-dialog form { display: flex; flex-direction: column; gap: 0.55rem; }
.util-dialog h3 { margin: 0; }
.util-dialog label { display: flex; flex-direction: column; gap: 0.2rem; font-size: 0.85rem; }
.util-dialog textarea {
  width: 100%;
  box-sizing: border-box;
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 0.4rem 0.5rem;
  font: inherit;
  resize: vertical;
  background: var(--surface);
  color: inherit;
}
.form-error { margin: 0; color: var(--danger); font-size: 0.82rem; }
.dialog-actions { display: flex; align-items: center; gap: 0.5rem; margin-top: 0.4rem; }
.grow { flex: 1; }
.hint { margin: 0.35rem 0; font-size: 0.82rem; color: var(--muted); }

@media (max-width: 720px) {
  .period-title { min-width: 3.5rem; }
}
