/* ===== Design tokens ===== */
:root {
  /* iOS system colours (dark): black background, grouped cells on it, one tint for everything that can be tapped */
  --bg: #000000;
  --surface: #1c1c1e;
  --surface-inset: #2c2c2e;
  --border: #38383a;
  --text: #ffffff;
  --muted: #98989f;
  --seg-thumb: #636366;

  --primary: #0a84ff;
  --primary-hover: #409cff;
  --accent: #0a84ff;
  --accent-hover: #409cff;
  --success: #30d158;
  --danger: #ff453a;

  /* Colours of the bills table, the app bar and the like */
  --bar-bg: rgba(22, 22, 24, 0.78);
  --line-soft: rgba(84, 84, 88, 0.6);
  --shadow: rgba(0, 0, 0, 0.4);
  --year-bg: rgba(48, 209, 88, 0.12);
  --year-border: transparent;
  --year-accent: #30d158;
  --year-sub-bg: rgba(255, 255, 255, 0.04);
  --year-sub-fg: #d1f5dc;
  --year-caret: #30d158;
  --month-bg: rgba(10, 132, 255, 0.16);
  --month-fg: #ffffff;
  --month-accent: #0a84ff;
  --link: #0a84ff;

  --radius: 12px;
  --radius-sm: 10px;
  --gap: 1rem;
  --content-width: 70rem;

  color-scheme: dark;
}

/* The light theme only changes the tokens; the theme is chosen in the settings (see js/ui/theme.js). */
:root[data-theme='light'] {
  --bg: #f2f2f7;
  --surface: #ffffff;
  --surface-inset: #eeeef0;
  --border: #c6c6c8;
  --text: #000000;
  --muted: #6c6c70;
  --seg-thumb: #ffffff;

  --primary: #007aff;
  --primary-hover: #0062cc;
  --accent: #007aff;
  --accent-hover: #0062cc;
  --success: #248a3d;
  --danger: #d70015;

  --bar-bg: rgba(249, 249, 249, 0.8);
  --line-soft: rgba(60, 60, 67, 0.29);
  --shadow: rgba(15, 23, 42, 0.18);
  --year-bg: rgba(52, 199, 89, 0.12);
  --year-border: transparent;
  --year-accent: #248a3d;
  --year-sub-bg: rgba(255, 255, 255, 0.7);
  --year-sub-fg: #1d6b31;
  --year-caret: #248a3d;
  --month-bg: rgba(0, 122, 255, 0.1);
  --month-fg: #003e80;
  --month-accent: #007aff;
  --link: #007aff;

  color-scheme: light;
}

/* ===== Base ===== */
*,
*::before,
*::after {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

html {
  -webkit-text-size-adjust: 100%;
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.4 -apple-system, BlinkMacSystemFont, 'SF Pro Text', system-ui, 'Segoe UI', Roboto, sans-serif;
  letter-spacing: -0.01em;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
}

h1,
h2 {
  margin: 0 0 0.75rem;
  font-size: 1.1rem;
  font-weight: 600;
}

h1 {
  font-size: 1.5rem;
}

p {
  margin: 0 0 0.5rem;
}

.muted {
  color: var(--muted);
}

.small {
  font-size: 0.8125rem;
}

.error,
.text-danger {
  color: var(--danger);
}

.text-success {
  color: var(--success);
}

.text-primary {
  color: var(--primary-hover);
}

.text-accent {
  color: var(--accent-hover);
}

/* ===== Form controls ===== */
/* 16px font prevents iOS Safari from zooming into focused inputs. */
input,
select,
textarea,
button {
  font: inherit;
}

input,
select,
textarea {
  width: 100%;
  min-height: 44px;
  padding: 0.6rem 0.75rem;
  background: var(--surface-inset);
  color: var(--text);
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
}

input:focus-visible,
select:focus-visible,
button:focus-visible {
  outline: 2px solid var(--primary);
  outline-offset: 1px;
}

/* Date and month fields: the browser's own date control is taller than a text field and, on iPhone and iPad, centres
   its value and may ignore the width. These rules make them look and size like the other fields. */
input[type='date'],
input[type='month'] {
  -webkit-appearance: none;
  appearance: none;
  display: block;
  min-width: 0;
  max-width: 100%;
  padding-block: 0.35rem;
  line-height: 1.5;
  text-align: left;
}

input[type='date']::-webkit-date-and-time-value,
input[type='month']::-webkit-date-and-time-value {
  min-height: 1.5em;
  margin: 0;
  text-align: left;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
  min-width: 0;
}

.field > span {
  font-size: 0.8125rem;
  color: var(--muted);
}

.field-narrow {
  width: 7.5rem;
}

.grow {
  flex: 1 1 10rem;
}

.form {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.inline-form {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  gap: 0.5rem;
}

.form-divider {
  margin-top: 1rem;
  padding-top: 1rem;
  border-top: 1px solid var(--border);
}

.select-sm,
.input-sm {
  width: auto;
  min-height: 38px;
  padding: 0.35rem 0.6rem;
}

.input-sm {
  width: 6.5rem;
}

/* ===== Buttons ===== */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.4rem;
  min-height: 44px;
  padding: 0.55rem 1rem;
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  background: var(--surface-inset);
  color: var(--primary);
  font-weight: 600;
  cursor: pointer;
  transition: background-color 0.15s, opacity 0.15s;
}

.btn:active {
  opacity: 0.6;
}

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

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

.btn-accent {
  background: var(--accent);
  color: #fff;
}

.btn-accent:hover {
  background: var(--accent-hover);
}

.btn-ghost {
  background: var(--surface-inset);
  color: var(--primary);
  font-weight: 500;
}

.btn-ghost:hover {
  background: var(--border);
}

.btn-sm {
  min-height: 38px;
  padding: 0.3rem 0.7rem;
  font-size: 0.875rem;
}

.btn-icon {
  min-width: 44px;
  padding: 0.4rem;
}

.btn-block {
  width: 100%;
}

/* ===== Layout ===== */
.card {
  padding: 1rem;
  background: var(--surface);
  border-radius: var(--radius);
  min-width: 0;
}

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

.card-header h2 {
  margin: 0;
}

.range-picker {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.4rem;
}

.range-custom {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
}

.range-custom input {
  width: 9.5rem;
  min-height: 36px;
}

.app {
  padding-bottom: calc(2rem + env(safe-area-inset-bottom));
}

.app-bar {
  position: sticky;
  top: 0;
  z-index: 10;
  background: var(--bar-bg);
  -webkit-backdrop-filter: saturate(180%) blur(20px);
  backdrop-filter: saturate(180%) blur(20px);
  border-bottom: 0.5px solid transparent;
  padding-top: env(safe-area-inset-top);
  transition: border-color 0.2s;
}

/* The hairline under the bar appears once the large title has scrolled under it, as on iOS */
.app-bar.is-condensed {
  border-bottom-color: var(--line-soft);
}

.app-header,
.content {
  max-width: var(--content-width);
  margin-inline: auto;
}

.app-header {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto minmax(0, 1fr);
  align-items: center;
  gap: 0.5rem;
  min-height: 44px;
  padding: 0 1rem;
}

.app-header > .header-actions {
  justify-self: end;
}

.bar-title {
  overflow: hidden;
  max-width: 50vw;
  font-size: 1.0625rem;
  font-weight: 600;
  text-overflow: ellipsis;
  white-space: nowrap;
  opacity: 0;
  transition: opacity 0.2s;
}

.app-bar.is-condensed .bar-title {
  opacity: 1;
}

.icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 44px;
  height: 44px;
  margin-right: -0.6rem;
  color: var(--primary);
}

.icon-btn svg {
  width: 1.5rem;
  height: 1.5rem;
}

/* The large title of a page (iOS): bold, left-aligned, above the content; it shrinks into the bar on scroll */
.large-title {
  margin: 0.25rem 0 0;
  font-size: 2.125rem;
  font-weight: 700;
  line-height: 1.2;
  letter-spacing: 0.01em;
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.brand {
  justify-self: start;
  overflow: hidden;
  max-width: 100%;
  margin-left: -0.35rem;
  font-size: 1.0625rem;
  color: var(--primary);
  text-decoration: none;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* The way back to the landing page, like the back button of iOS; on the landing page the title is the home itself */
.brand::before {
  content: '‹';
  display: inline-block;
  margin-right: 0.3rem;
  font-size: 1.6rem;
  font-weight: 400;
  line-height: 1;
  vertical-align: -0.12rem;
}

[data-page='landing'] .brand {
  visibility: hidden;
}

/* ----- Landing page: two big buttons ----- */
.landing {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: var(--gap);
}

.landing-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.35rem;
  min-height: 11rem;
  padding: 1.5rem 1rem;
  background: var(--surface);
  border: 1px solid transparent;
  border-radius: var(--radius);
  color: var(--text);
  text-align: center;
  text-decoration: none;
}

.landing-card:hover,
.landing-card:focus-visible {
  border-color: var(--primary);
  background: var(--surface-inset);
}

.landing-icon {
  font-size: 3rem;
  line-height: 1;
}

.landing-title {
  font-size: 1.6rem;
  font-weight: 700;
}

@media (min-width: 720px) {
  .landing {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .landing-card {
    min-height: 16rem;
  }
}

/* The bottom bar (iOS style): one column per visible section, an icon over a label, the open one in colour. Modules
   switched off in the settings drop out. It sits on the bottom edge above the home indicator of a phone. */
:root {
  --nav-height: 3.6rem;
}

.tabs {
  position: fixed;
  right: 0;
  bottom: 0;
  left: 0;
  z-index: 12;
  display: grid;
  grid-auto-columns: minmax(0, 1fr);
  grid-auto-flow: column;
  min-height: var(--nav-height);
  padding: 0.25rem max(0.25rem, env(safe-area-inset-right)) env(safe-area-inset-bottom) max(0.25rem, env(safe-area-inset-left));
  background: var(--bar-bg);
  -webkit-backdrop-filter: saturate(180%) blur(16px);
  backdrop-filter: saturate(180%) blur(16px);
  border-top: 0.5px solid var(--line-soft);
}

.tabs[hidden] {
  display: none;
}

.tab {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.15rem;
  min-width: 0;
  padding: 0.25rem 0.1rem;
  background: none;
  border: 0;
  border-radius: var(--radius-sm);
  color: var(--muted);
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}

.tab-icon {
  width: 1.5rem;
  height: 1.5rem;
}

.tab-label {
  max-width: 100%;
  font-size: 0.6875rem;
  font-weight: 500;
  line-height: 1.1;
  text-align: center;
  overflow-wrap: anywhere;
}

.tab.is-active {
  color: var(--primary);
}

.tab.is-active .tab-label {
  font-weight: 700;
}

.tab.is-active .tab-icon {
  stroke-width: 2.2;
}

/* On a wide screen the bar is a floating capsule in the middle, not an edge-to-edge strip */
@media (min-width: 720px) {
  .tabs {
    right: auto;
    bottom: 0.75rem;
    left: 50%;
    width: min(34rem, calc(100% - 2rem));
    padding-bottom: 0.25rem;
    transform: translateX(-50%);
    border: 1px solid var(--border);
    border-radius: 1.4rem;
    box-shadow: 0 8px 24px var(--shadow);
  }
}

/* Room for the bar under the content while it is shown */
.has-nav .app {
  padding-bottom: calc(var(--nav-height) + 2rem + env(safe-area-inset-bottom));
}

.has-nav .toast-region {
  bottom: calc(var(--nav-height) + 0.75rem + env(safe-area-inset-bottom));
}

.content {
  padding: 1rem;
  padding-inline: max(1rem, env(safe-area-inset-left)) max(1rem, env(safe-area-inset-right));
}

.view {
  display: flex;
  flex-direction: column;
  gap: var(--gap);
}

@media (min-width: 720px) {
  .content {
    padding: 1.5rem;
  }
}

.auth-screen {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  padding: 1.5rem;
  text-align: center;
}

.auth-card {
  width: 100%;
  max-width: 24rem;
  padding: 2rem;
}

.month-switcher {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.6rem;
}

.month-switcher input {
  flex: 1;
  min-width: 0;
  text-align: center;
}

.month-switcher input::-webkit-date-and-time-value {
  text-align: center;
}

/* On a phone in portrait the arrows, the month and "Today" do not fit in one row: Today gets its own. */
@media (max-width: 540px) {
  .month-switcher {
    display: grid;
    grid-template-columns: auto minmax(0, 1fr) auto;
  }

  .month-switcher > .btn:not(.btn-icon) {
    grid-column: 1 / -1;
  }
}

/* ===== Stats ===== */
.stats {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0.75rem;
  margin-top: 1rem;
}

.stats-cards {
  grid-template-columns: minmax(0, 1fr);
  margin-top: 0;
}

.stats-cards .stat {
  min-height: 5.5rem;
  padding: 1.1rem 1.1rem 1rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-left: 4px solid var(--currency-color, var(--border));
  border-radius: var(--radius);
}

.stats-cards .stat-value {
  margin-top: 0.15rem;
  font-size: 1.5rem;
}

/* Each currency keeps its colour everywhere on the savings page (set from JS; the same as in the chart). */
.currency-text {
  color: var(--currency-text);
}

/* The text tints are light, for the dark theme; the light theme gets darker ones. */
:root[data-theme='light'] .currency-text {
  color: var(--currency-text-light, var(--currency-text));
}

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

@media (min-width: 720px) {
  .stats-cards {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }
}

.stat-label {
  font-size: 0.8125rem;
  color: var(--muted);
}

.stat-value {
  font-size: 1.15rem;
  font-weight: 700;
  overflow-wrap: break-word;
}

/* Several short values (e.g. one per currency) that wrap instead of forcing a tall box. */
.stat-lines {
  display: flex;
  flex-wrap: wrap;
  gap: 0.15rem 0.9rem;
  font-size: 0.9375rem;
  font-weight: 600;
}

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

.stats-wide .stat-value {
  font-size: 1.9rem;
}

@media (min-width: 720px) {
  .stat-value {
    font-size: 1.35rem;
  }
}

.progress {
  height: 8px;
  margin: 0.5rem 0;
  background: var(--line-soft);
  border-radius: 999px;
  overflow: hidden;
}

.progress-fill {
  height: 100%;
  background: var(--primary);
  border-radius: inherit;
  transition: width 0.3s;
}

.progress-over .progress-fill {
  background: var(--danger);
}

/* ===== Lists ===== */
.list {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.list-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  padding: 0.65rem 0.75rem;
  background: var(--surface-inset);
  border: 0;
  border-radius: var(--radius-sm);
}

.list-item-main {
  flex: 1;
  min-width: 0;
}

.list-item-title {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.4rem;
  font-weight: 500;
  overflow-wrap: anywhere;
}

.list-item-side {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  white-space: nowrap;
}

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

.category.is-closed {
  opacity: 0.65;
}

.category-controls {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: flex-end;
  gap: 0.4rem;
}

.category-group {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.category-children {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  margin-left: 1.25rem;
  padding-left: 0.75rem;
  border-left: 2px solid var(--border);
}

.left-field {
  display: flex;
  align-items: center;
  gap: 0.4rem;
}

/* Expenses: the plan and "left" amounts of one line and the ✓ / − toggles. */
.row-fields {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  gap: 0.4rem;
}

.mini-field {
  display: flex;
  flex-direction: column;
  gap: 0.15rem;
  font-size: 0.75rem;
  color: var(--muted);
}

.mini-field .input-sm {
  width: 6rem;
}

.icon-toggle {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 44px;
  height: 44px;
  background: transparent;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--muted);
  font-size: 1.25rem;
  font-weight: 700;
  line-height: 1;
  cursor: pointer;
}

.icon-toggle[aria-pressed='true'].toggle-done {
  background: rgba(16, 185, 129, 0.2);
  border-color: var(--success);
  color: var(--success);
}

.icon-toggle.toggle-exclude:hover,
.icon-toggle[aria-pressed='true'].toggle-exclude {
  border-color: var(--danger);
  color: var(--danger);
}

.is-excluded {
  opacity: 0.5;
}

.badge-custom {
  background: rgba(59, 130, 246, 0.25);
  color: var(--primary-hover);
}

.person-filter {
  margin-bottom: 0.9rem;
}

/* Renamable item names in the budget template. */
.name-input {
  font-weight: 500;
}

.move-select {
  flex: 1 1 8rem;
  min-width: 0;
  width: auto;
}

.person-input {
  flex: 1 1 7rem;
  width: auto;
  min-width: 0;
  min-height: 38px;
  padding: 0.35rem 0.6rem;
}

.btn-toggle {
  min-width: 2rem;
  padding-inline: 0.4rem;
}

a.btn {
  text-decoration: none;
}

@media (min-width: 720px) {
  .category {
    flex-direction: row;
    align-items: center;
  }
}

/*
 * Template rows: the name must stay the biggest thing in the row. On a phone in landscape and on a tablet in
 * portrait there is not enough room for the name beside the person, category and amount fields, so those go on a
 * line of their own under the name; side by side only when the screen is really wide.
 */
@media (min-width: 720px) and (max-width: 959px) {
  .tpl-item {
    flex-direction: column;
    align-items: stretch;
  }
}

@media (min-width: 960px) {
  .tpl-item {
    display: grid;
    grid-template-columns: minmax(14rem, 1fr) auto;
    gap: 0.75rem;
  }

  .tpl-item .category-controls {
    flex-wrap: nowrap;
  }

  .tpl-item .person-input {
    flex: 0 0 8rem;
    width: 8rem;
  }

  .tpl-item .move-select {
    flex: 0 0 9rem;
    width: 9rem;
  }

  .tpl-item .input-sm {
    flex: 0 0 6rem;
  }
}

.badge {
  padding: 0.05rem 0.5rem;
  background: var(--border);
  border-radius: 999px;
  color: var(--muted);
  font-size: 0.75rem;
  font-weight: 500;
}

/* ===== Charts ===== */
.chart-box {
  position: relative;
  height: 18rem;
  width: 100%;
}

.chart-box-short {
  height: 14rem;
}

.chart-box[data-empty] {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 8rem;
}

.chart-box[data-empty] canvas {
  display: none;
}

.chart-box[data-empty]::after {
  content: attr(data-empty);
  color: var(--muted);
  font-size: 0.875rem;
}

/* ===== Utility comparison ===== */
.compare {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 0.5rem;
}

.compare-row {
  padding: 0.75rem;
  background: var(--surface-inset);
  border-radius: var(--radius-sm);
}

.chips {
  display: flex;
  flex-wrap: wrap;
  gap: 0.25rem 0.75rem;
  margin-top: 0.25rem;
}

.chip {
  font-size: 0.8125rem;
}

/* A card whose content is folded away until its heading is tapped (e.g. the history). */
.collapsible > summary {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  min-height: 44px;
  list-style: none;
  cursor: pointer;
}

.collapsible > summary::-webkit-details-marker {
  display: none;
}

/* The "+" mark: everything that can be opened shows a boxed "+" (and a "−" once it is open). */
.collapsible > summary::before,
.bills-compact summary > span:first-child::before,
.hb-purchase > summary::before,
.stock-group > summary::before,
.caret,
.link-btn[aria-expanded]::before {
  content: '+';
  display: inline-grid;
  flex: none;
  place-items: center;
  width: 1.3rem;
  height: 1.3rem;
  margin-right: 0.5rem;
  border: 1.5px solid currentColor;
  border-radius: 6px;
  font-size: 1rem;
  font-weight: 700;
  line-height: 1;
  vertical-align: middle;
}

.collapsible > summary::before,
.bills-compact summary > span:first-child::before,
.hb-purchase > summary::before,
.stock-group > summary::before {
  color: var(--accent);
}

.collapsible[open] > summary::before,
.bills-compact details[open] > summary > span:first-child::before,
.hb-purchase[open] > summary::before,
.stock-group[open] > summary::before,
.link-btn[aria-expanded='true']::before {
  content: '−';
}

.collapsible > summary h2 {
  margin: 0;
}

.collapsible-body {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  margin-top: 0.75rem;
}

@media (min-width: 720px) {
  .compare {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }
}

/* ===== Bills ===== */
.check {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  color: var(--muted);
  font-size: 0.875rem;
  cursor: pointer;
}

.check input {
  width: 1.1rem;
  min-height: 0;
  height: 1.1rem;
}

.table-scroll {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
}

.bills-table {
  width: max-content;
  min-width: 100%;
  border-collapse: separate;
  border-spacing: 0;
  font-size: 0.8125rem;
  font-variant-numeric: tabular-nums;
}

.bills-table th,
.bills-table td {
  padding: 0.3rem 0.3rem;
  border-right: 1px solid var(--line-soft);
  border-bottom: 1px solid var(--border);
  text-align: right;
  white-space: nowrap;
}

/* Rotated headings keep every column narrow, so the whole table fits on a wide screen.
   The minimum width matters in Safari: a column with no figures yet would otherwise collapse to its
   padding and the rotated text would spill into the neighbouring columns. */
.bills-table th.vertical {
  min-width: 2rem;
  padding: 0.5rem 0.25rem;
  vertical-align: bottom;
}

.bills-table th.vertical span {
  display: inline-block;
  transform: rotate(180deg);
  white-space: nowrap;
  writing-mode: vertical-rl;
}

/* The narrow-screen list and the wide table: CSS shows the one that fits. */
.wide-only,
.bills-wide {
  display: none;
}

.bills-compact {
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

@media (min-width: 1024px) {
  .bills-wide {
    display: block;
  }

  .check.wide-only {
    display: inline-flex;
  }

  .bills-compact {
    display: none;
  }

  /* Set from JS when the table has too many columns to be shrunk to fit. */
  .is-too-wide .bills-wide {
    display: none;
  }

  .is-too-wide .bills-compact {
    display: flex;
  }
}

.bills-year {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.bills-compact details {
  background: var(--surface-inset);
  border: 1px solid var(--line-soft);
  border-radius: var(--radius-sm);
}

.bills-compact details.year-details {
  background: var(--year-bg);
  border-color: var(--year-border);
}

.bills-compact details.year-details > summary {
  font-size: 1.0625rem;
  font-weight: 700;
  letter-spacing: 0.03em;
}

.year-body {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  padding: 0 0.6rem 0.6rem;
}

/* The yearly figures per bill: lighter than the year heading and the months under it. */
.bills-compact details.year-breakdown {
  background: var(--year-sub-bg);
  border-style: dashed;
}

.bills-compact details.year-breakdown > summary {
  color: var(--year-sub-fg);
  font-size: 0.875rem;
}

/* Months are blue, so they read differently from the bills listed under them. */
.bills-compact details.month-details {
  border-left: 4px solid var(--month-accent);
}

.bills-compact details.month-details summary {
  background: var(--month-bg);
  border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
  color: var(--month-fg);
  font-weight: 700;
}

.bills-compact summary {
  display: flex;
  justify-content: space-between;
  gap: 0.75rem;
  padding: 0.7rem 0.85rem;
  list-style: none;
  cursor: pointer;
}

.bills-compact summary::-webkit-details-marker {
  display: none;
}

.table-tools {
  display: flex;
  justify-content: flex-end;
  margin-bottom: 0.5rem;
}

.year-toggle {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  min-height: 32px;
  padding: 0;
  background: none;
  border: 0;
  color: inherit;
  font: inherit;
  letter-spacing: inherit;
  cursor: pointer;
}

.year-toggle .caret {
  margin-right: 0;
  color: var(--year-caret);
}

.link-btn[aria-expanded]::before {
  color: var(--accent);
}

/* A card that asks for something to be done (e.g. moving old salary rows). */
.notice {
  border-left: 4px solid var(--accent);
}

.notice .btn {
  margin-top: 0.5rem;
}

/* ----- Salary ----- */
.bills-compact summary {
  align-items: center;
}

.sum-pair {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  text-align: right;
}

.sum-pair small {
  font-weight: 400;
  opacity: 0.85;
}

.note-line {
  display: block;
}

.bill-line.total-line {
  border-bottom: 0;
  padding-top: 0.3rem;
}

/* A payment, the total and the rate share three columns, so every amount ends at the same place (the third column is
   the width of the delete button, empty in the total). */
.bill-line.salary-line {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto 44px;
  align-items: center;
}

.salary-line .bill-line-values {
  font-variant-numeric: tabular-nums;
}

.bill-line.salary-line.total-line {
  align-items: start;
}

.rate-editor {
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
  padding-top: 0.5rem;
  border-top: 1px solid var(--border);
}

.rate-editor .input-sm {
  width: 6.5rem;
}

/* A comment on a figure shows as an orange corner, like a note in the spreadsheet. */
.salary-table td.has-note {
  position: relative;
  cursor: help;
}

.salary-table td.has-note::after {
  content: '';
  position: absolute;
  top: 0;
  right: 0;
  border-style: solid;
  border-width: 0 9px 9px 0;
  border-color: transparent #f97316 transparent transparent;
}

.salary-table td.estimate {
  font-style: italic;
}

.salary-detail td {
  padding: 0.6rem 0.85rem;
  background: var(--surface-inset);
  text-align: left;
  white-space: normal;
}

.salary-detail .bill-lines {
  max-width: 42rem;
  padding: 0;
}

.bill-lines {
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
  padding: 0 0.85rem 0.85rem;
}

.bill-line {
  display: flex;
  justify-content: space-between;
  gap: 0.75rem;
  padding-bottom: 0.3rem;
  border-bottom: 1px dashed var(--border);
  font-size: 0.9rem;
}

.bill-line-values {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  text-align: right;
}

.bills-table thead th {
  background: var(--surface-inset);
  font-weight: 600;
  text-align: center;
}

.bills-table th.sub {
  color: var(--muted);
  font-size: 0.75rem;
  font-weight: 500;
}

/* The month column stays visible while the table scrolls sideways. */
.bills-table th.sticky {
  position: sticky;
  left: 0;
  z-index: 1;
  background: var(--surface);
  text-align: left;
}

.bills-table thead th.sticky {
  background: var(--surface-inset);
}

.bills-table td.reading {
  color: var(--muted);
}

.bills-table td.total {
  background: var(--surface-inset);
  font-weight: 700;
}

/* Years and months stand out from the figures: months are blue, years are green and larger. */
.bills-table tbody tr:not(.year-row) th.sticky {
  background: var(--month-bg);
  border-right: 3px solid var(--month-accent);
  color: var(--month-fg);
  font-weight: 700;
}

.bills-table tr.year-row th,
.bills-table tr.year-row td {
  background: var(--year-bg);
  color: var(--text);
  font-size: 0.9375rem;
  font-weight: 700;
}

.bills-table tr.year-row th.sticky {
  border-right: 3px solid var(--year-accent);
  letter-spacing: 0.04em;
}

.link-btn {
  min-height: 32px;
  padding: 0;
  background: none;
  border: 0;
  color: var(--link);
  font: inherit;
  font-weight: 700;
  cursor: pointer;
}

.month-switcher + form {
  margin-top: 0.75rem;
}

.bill-fields {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 0.75rem;
}

.bill-field {
  min-width: 0;
  margin: 0;
  padding: 0.5rem 0.75rem 0.75rem;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
}

.bill-field legend {
  padding: 0 0.35rem;
  font-weight: 600;
}

.bill-field-inputs {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(7rem, 1fr));
  gap: 0.5rem;
}

@media (min-width: 720px) {
  .bill-fields {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

.category-group.is-hidden {
  opacity: 0.65;
}

.type-editor {
  margin-top: 0.5rem;
  padding: 0.75rem;
  border: 1px dashed var(--border);
  border-radius: var(--radius-sm);
}

.meter-list {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.meter-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 7rem auto;
  align-items: center;
  gap: 0.4rem;
}

.meter-rate {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  grid-column: 1 / -1;
  gap: 0.4rem;
  color: var(--muted);
  font-size: 0.8125rem;
}

.meter-rate .input-sm {
  width: 5rem;
}

.new-type summary {
  display: inline-flex;
  list-style: none;
  cursor: pointer;
}

.new-type summary::-webkit-details-marker {
  display: none;
}

.new-type[open] summary {
  margin-bottom: 0.75rem;
}

/* ===== Settings ===== */
.toolbar-title {
  flex: 1;
  margin: 0;
}

.switch-list {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.module-row {
  display: flex;
  align-items: center;
  gap: 0.4rem;
}

.group-title {
  margin: 0.5rem 0 0;
  color: var(--muted);
  font-size: 0.8125rem;
  font-weight: 600;
  letter-spacing: 0.05em;
  text-transform: uppercase;
}

.group-title:first-child {
  margin-top: 0;
}

.module-row .switch {
  flex: 1;
  min-width: 0;
}

.module-move {
  display: flex;
  gap: 0.25rem;
}

.module-move .btn:disabled {
  opacity: 0.35;
}

/* Currencies: two columns on a phone, more on wider screens. */
.switch-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

@media (min-width: 720px) {
  .switch-grid {
    grid-template-columns: repeat(4, minmax(0, 1fr));
  }
}

.switch {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  min-height: 48px;
  padding: 0.5rem 0.75rem;
  background: var(--surface-inset);
  border: 1px solid var(--line-soft);
  border-radius: var(--radius-sm);
  cursor: pointer;
}

.switch input {
  width: 1.4rem;
  min-height: 0;
  height: 1.4rem;
  accent-color: var(--primary);
}

.switch-hint {
  color: var(--muted);
  font-size: 0.8125rem;
}

.transfer-fields {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0.75rem;
}

/* ===== Toasts ===== */
.toast-region {
  position: fixed;
  left: 0;
  right: 0;
  bottom: calc(1rem + env(safe-area-inset-bottom));
  z-index: 20;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.5rem;
  padding-inline: 1rem;
  pointer-events: none;
}

.toast {
  max-width: 28rem;
  padding: 0.7rem 1rem;
  border-radius: var(--radius-sm);
  background: var(--surface);
  border: 1px solid var(--border);
  box-shadow: 0 8px 24px var(--shadow);
  font-size: 0.9rem;
}

.toast-error {
  border-color: var(--danger);
}

.toast {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  pointer-events: auto;
}

.toast-action {
  min-height: 36px;
  padding: 0.2rem 0.6rem;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--link);
  font-weight: 600;
  cursor: pointer;
}

/* ===== Lamps ===== */
.btn-danger {
  color: var(--danger);
}

.lamps-summary {
  border-color: var(--primary);
}

.lamps-summary-head {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
}

.lamps-summary-actions {
  display: flex;
  gap: 0.5rem;
}

.lamps-total {
  font-size: 1.9rem;
  font-weight: 700;
  line-height: 1.1;
}

.lamps-lines {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  margin: 0.9rem 0 0;
  padding: 0;
  list-style: none;
}

.lamps-line {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.65rem 0.75rem;
  background: var(--surface-inset);
  border: 1px solid var(--line-soft);
  border-radius: var(--radius-sm);
}

.lamps-qty {
  flex: none;
  min-width: 3.2rem;
  padding: 0.35rem 0.5rem;
  border-radius: 999px;
  background: var(--primary);
  color: #fff;
  font-size: 1.15rem;
  font-weight: 700;
  text-align: center;
}

.lamps-line-main {
  flex: 1;
  min-width: 0;
}

.lamps-line-title {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.4rem;
  font-weight: 600;
}

.tone {
  padding: 0.05rem 0.5rem;
  border-radius: 999px;
  font-size: 0.75rem;
  font-weight: 600;
}

.tone-warm {
  background: #fde68a;
  color: #78350f;
}

.tone-bright {
  background: #bfdbfe;
  color: #1e3a8a;
}

.lamps-ok {
  display: flex;
  align-items: center;
  gap: 0.9rem;
}

.lamps-ok h2 {
  margin: 0;
}

.lamps-ok-mark {
  display: grid;
  flex: none;
  place-items: center;
  width: 2.6rem;
  height: 2.6rem;
  border-radius: 50%;
  background: var(--success);
  color: #fff;
  font-size: 1.4rem;
  font-weight: 700;
}

.lamps-empty {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.6rem;
  text-align: center;
}

.lamps-empty h2,
.lamps-empty p {
  margin: 0;
}

.lamps-empty-icon {
  font-size: 2.4rem;
}

.lamps-group-title {
  margin: 1.25rem 0 0.5rem;
  color: var(--muted);
  font-size: 0.8125rem;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.lamps-group:first-child .lamps-group-title {
  margin-top: 0;
}

.lamps-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 0.75rem;
}

@media (min-width: 600px) {
  .lamps-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@media (min-width: 1000px) {
  .lamps-grid {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }
}

.lamp-tile {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  padding: 0.9rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}

.lamp-tile-out {
  border-color: var(--danger);
}

.lamp-tile-empty {
  opacity: 0.65;
}

.lamp-tile-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
}

.lamp-tile-head h3 {
  margin: 0;
  font-size: 1.05rem;
  overflow-wrap: anywhere;
}

.lamp-spec {
  display: flex;
  flex-wrap: wrap;
  gap: 0.3rem;
}

.spec-chip {
  padding: 0.1rem 0.5rem;
  border-radius: 999px;
  background: var(--surface-inset);
  border: 1px solid var(--line-soft);
  color: var(--muted);
  font-size: 0.8125rem;
}

.bulbs {
  display: flex;
  flex-wrap: wrap;
  gap: 0.25rem;
}

/* A tap target of 44px even though the bulb itself is smaller */
.bulb {
  display: grid;
  place-items: center;
  width: 44px;
  height: 44px;
  padding: 0;
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  background: transparent;
  font-size: 1.6rem;
  line-height: 1;
  cursor: pointer;
}

.bulb-dead {
  background: color-mix(in srgb, var(--danger) 14%, transparent);
  border-color: var(--danger);
  filter: grayscale(1) brightness(0.8);
}

.lamp-stepper {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.lamp-stepper .btn-icon {
  font-size: 1.4rem;
}

.lamp-stepper-value {
  min-width: 4.5rem;
  font-size: 1.15rem;
  font-weight: 600;
  text-align: center;
}

.lamp-status {
  color: var(--success);
  font-size: 0.875rem;
  font-weight: 600;
}

.lamp-status-out {
  color: var(--danger);
}

.lamps-fab {
  position: fixed;
  right: 1rem;
  bottom: calc(var(--nav-height) + 1rem + env(safe-area-inset-bottom));
  z-index: 15;
  min-height: 48px;
  padding: 0.6rem 1.1rem;
  border: 0;
  border-radius: 999px;
  background: var(--primary);
  box-shadow: 0 8px 24px var(--shadow);
  color: #fff;
  font-weight: 700;
  cursor: pointer;
}

.lamps-fab[hidden] {
  display: none;
}

.lamps-edit-list {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  margin: 0.75rem 0;
}

.lamps-edit-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  padding: 0.5rem 0.75rem;
  background: var(--surface-inset);
  border: 1px solid var(--line-soft);
  border-radius: var(--radius-sm);
}

.lamps-form {
  padding: 0.9rem;
  background: var(--surface-inset);
  border: 1px solid var(--primary);
  border-radius: var(--radius-sm);
}

.lamps-form-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  align-items: end;
  gap: 0.75rem;
}

@media (min-width: 720px) {
  .lamps-form-grid {
    grid-template-columns: repeat(4, minmax(0, 1fr));
  }
}

.lamps-form-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
}

@media (prefers-reduced-motion: reduce) {
  * {
    transition: none !important;
  }
}

.year-tools {
  display: flex;
  justify-content: flex-end;
  padding: 0.25rem 0;
}

/* Lamps: stock */
.toolbar-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin-left: auto;
}

.count-badge {
  display: inline-block;
  min-width: 1.4rem;
  padding: 0 0.4rem;
  border-radius: 999px;
  background: var(--success);
  color: #fff;
  font-size: 0.8125rem;
  text-align: center;
}

.count-badge[hidden] {
  display: none;
}

.lamps-from-stock {
  color: var(--success);
  font-weight: 600;
}

.lamps-total-ok {
  color: var(--success);
}

.lamps-qty-stock {
  background: var(--success);
}

.stock-qty {
  min-width: 2rem;
  font-size: 1.15rem;
  font-weight: 700;
  text-align: center;
}

/* Forms with two fields side by side */
.form-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  align-items: end; /* the fields of a row line up even when one label wraps */
  gap: 0.75rem;
}

/* ===== Home health ===== */
.health-head {
  display: flex;
  align-items: center;
  gap: 0.9rem;
}

.health-head h2,
.health-head p {
  margin: 0;
}

.health-icon {
  font-size: 2rem;
  line-height: 1;
}

.health-good h2 {
  color: var(--success);
}

.health-attention h2 {
  color: #d97706;
}

.health-urgent h2 {
  color: var(--danger);
}

.health-numbers {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0.75rem;
  margin-top: 1rem;
}

@media (min-width: 720px) {
  .health-numbers {
    grid-template-columns: repeat(4, minmax(0, 1fr));
  }
}

.health-groups {
  display: flex;
  flex-direction: column;
  gap: var(--gap);
}

.health-group-overdue {
  border-color: var(--danger);
}

.health-item {
  align-items: flex-start;
}

.health-check {
  display: grid;
  flex: none;
  place-items: center;
  width: 44px;
  height: 44px;
  padding: 0;
  background: transparent;
  border: 0;
  cursor: pointer;
}

.health-check::before {
  content: '';
  display: grid;
  place-items: center;
  width: 1.6rem;
  height: 1.6rem;
  border: 2px solid var(--muted);
  border-radius: 50%;
  color: #fff;
  font-weight: 700;
}

.health-check:hover::before {
  border-color: var(--success);
}

.health-check-done::before {
  content: '✓';
  background: var(--success);
  border-color: var(--success);
}

.health-title-done {
  color: var(--muted);
  text-decoration: line-through;
}

.priority-critical {
  border-color: var(--danger);
  color: var(--danger);
}

.priority-important {
  border-color: #d97706;
  color: #d97706;
}

/* ===== Home budget ===== */
.hb-found {
  margin-top: 0.75rem;
}

.hb-found p {
  margin: 0;
}

.hb-filters {
  margin-top: 0.75rem;
}

/* The summary of the whole house */
.hb-total {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 0.25rem 1rem;
}

.hb-total .stat-label {
  flex-basis: 100%;
}

.hb-total-uah {
  font-size: 1.9rem;
  font-weight: 700;
  line-height: 1.1;
}

.hb-total-usd {
  color: var(--muted);
  font-size: 1.25rem;
  font-weight: 600;
}

.hb-sections {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 0.5rem;
  margin-top: 1rem;
}

@media (min-width: 720px) {
  .hb-sections {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

/* Every part has its colour: the same on the summary and on the purchases that belong to it */

.hb-section {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
  gap: 0.3rem 0.75rem;
  min-height: 44px;
  padding: 0.6rem 0.75rem;
  background: var(--surface-inset);
  border: 1px solid var(--line-soft);
  border-left: 5px solid var(--section);
  border-radius: var(--radius-sm);
  background: color-mix(in srgb, var(--section) 14%, var(--surface-inset));
  color: inherit;
  text-align: left;
}

.hb-section-name {
  font-weight: 600;
}

.hb-section-sum,
.hb-payment-sum,
.hb-purchase-cost {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  text-align: right;
  font-variant-numeric: tabular-nums;
}

.hb-share {
  grid-column: 1 / -1;
  height: 4px;
  border-radius: 2px;
  background: var(--border);
  overflow: hidden;
}

.hb-share-fill {
  display: block;
  height: 100%;
  background: var(--section);
}

/* The purchases */
.hb-list {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.hb-purchase {
  background: var(--surface);
  border: 1px solid var(--border);
  border-left: 5px solid var(--section);
  border-radius: var(--radius-sm);
}

.hb-purchase > summary {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  min-height: 48px;
  padding: 0.6rem 0.75rem;
  list-style: none;
  cursor: pointer;
}

.hb-purchase > summary::-webkit-details-marker {
  display: none;
}

.hb-purchase > summary::before {
  margin-right: 0;
}

.hb-purchase-main {
  display: flex;
  flex: 1;
  flex-direction: column;
  min-width: 0;
}

.hb-purchase-title {
  overflow-wrap: anywhere;
}

.hb-purchase-body {
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
  padding: 0 0.75rem 0.75rem;
}

.hb-purchase-body .btn {
  align-self: flex-start;
}

.hb-payment {
  display: flex;
  justify-content: space-between;
  gap: 0.75rem;
  padding-bottom: 0.3rem;
  border-bottom: 1px dashed var(--border);
  font-size: 0.9rem;
}

/* The form: a payment is a small card of its own */
.hb-form-subtitle {
  margin: 0.5rem 0 0;
}

.hb-payments {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.hb-payment-form {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  padding: 0.75rem;
  background: var(--surface-inset);
  border: 1px solid var(--line-soft);
  border-radius: var(--radius-sm);
}

.hb-payment-top {
  display: flex;
  gap: 0.5rem;
}

.hb-payment-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  align-items: end;
  gap: 0.5rem;
}

/* Two fields a row on a phone, four from a tablet up */
/* The rate is the last of five fields: it takes a row of its own on a phone */
.hb-payment-grid > :last-child {
  grid-column: 1 / -1;
}

@media (min-width: 720px) {
  .hb-payment-grid {
    grid-template-columns: 1.2fr 0.8fr 1fr 0.8fr 1fr;
  }

  .hb-payment-grid > :last-child {
    grid-column: auto;
  }
}

.hb-rate-hint {
  min-height: 1em;
}

textarea {
  min-height: 7rem;
  padding: 0.6rem 0.75rem;
  resize: vertical;
}

.hb-sold-block {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.hb-sold-block p {
  margin: 0;
}

.hb-sold .hb-purchase-title {
  color: var(--muted);
}

.hb-payment-sold strong {
  color: var(--success);
}

.hb-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin-top: 1rem;
}

.hb-actions[hidden],
.hb-actions .btn[hidden] {
  display: none;
}

.hb-expand {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
}

/* The table of years: a row with the sum and a bar */
.hb-year {
  display: grid;
  grid-template-columns: 4.5rem minmax(0, 1fr) auto;
  align-items: center;
  gap: 0.75rem;
  padding: 0.4rem 0;
  border-bottom: 1px dashed var(--border);
  font-variant-numeric: tabular-nums;
}

.hb-year-total {
  border-bottom: 0;
  font-weight: 700;
}

.hb-year-bar {
  height: 8px;
  border-radius: 4px;
  background: var(--border);
  overflow: hidden;
}

.hb-year-bar > span {
  display: block;
  height: 100%;
  background: var(--primary);
}

/* A button with the text of what it does hides when it is not needed (e.g. "Today" in the current month) */
.btn[hidden] {
  display: none;
}

/* "All spent" of an expense: a labelled button under the figures, away from the amount fields */
.done-chip {
  align-self: flex-start;
  min-height: 40px;
  margin-top: 0.4rem;
  padding: 0.3rem 0.9rem;
  background: transparent;
  border: 1px solid var(--border);
  border-radius: 999px;
  color: var(--muted);
  font-size: 0.875rem;
  font-weight: 600;
  cursor: pointer;
}

.done-chip[aria-pressed='true'] {
  background: rgba(16, 185, 129, 0.2);
  border-color: var(--success);
  color: var(--success);
}

/* Lamps: which rooms lack lamps in stock */
.count-badge-bad {
  background: var(--danger);
}

.gaps {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.gaps-head {
  display: flex;
  flex-direction: column;
  gap: 0.2rem;
  padding: 0.75rem;
  background: var(--surface-inset);
  border: 1px solid var(--success);
  border-radius: var(--radius-sm);
}

.gaps-head-bad {
  border-color: var(--danger);
}

.gaps-row-bad {
  border-color: var(--danger);
}

.gaps-match {
  color: var(--success);
}

.gaps-qty {
  min-width: 2.4rem;
  padding: 0.3rem 0.5rem;
  border-radius: 999px;
  background: var(--success);
  color: #fff;
  font-weight: 700;
  text-align: center;
}

.gaps-qty-bad {
  background: var(--danger);
}

.gaps-group {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  padding: 0.75rem;
  background: var(--surface-inset);
  border: 1px solid var(--danger);
  border-radius: var(--radius-sm);
}

.gaps-group-title {
  font-size: 1.05rem;
  font-weight: 700;
}

.gaps-qty {
  white-space: nowrap;
}

/* ===== Settings: groups of links ===== */
.settings-group h2 {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin: 0 0 0.5rem;
}

.settings-links {
  display: flex;
  flex-direction: column;
}

.settings-link {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  min-height: 56px;
  padding: 0.6rem 0.25rem;
  border-top: 1px solid var(--line-soft);
  color: inherit;
  text-decoration: none;
}

.settings-link:first-child {
  border-top: 0;
}

a.settings-link:hover {
  background: var(--surface-inset);
}

.settings-link[hidden],
.settings-group[hidden] {
  display: none;
}

.settings-link-text {
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.settings-link-text small {
  font-size: 0.8125rem;
}

.settings-link-side {
  display: flex;
  flex: none;
  align-items: center;
  gap: 0.5rem;
}

.settings-chevron {
  color: var(--muted);
  font-size: 1.6rem;
  line-height: 1;
}

.settings-field select {
  flex: none;
  width: auto;
  min-width: 9rem;
}

/* ===== Lamps: the stock by socket, watts and variation ===== */
#lamps-stock-list {
  gap: 0.75rem;
}

.stock-group {
  background: var(--surface-inset);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
}

.stock-group > summary {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  min-height: 52px;
  padding: 0.5rem 0.75rem;
  list-style: none;
  cursor: pointer;
}

.stock-group > summary::-webkit-details-marker {
  display: none;
}

.stock-group > summary::before {
  margin-right: 0;
}

.stock-group-title {
  display: flex;
  flex: 1;
  flex-direction: column;
  min-width: 0;
}

.stock-group-title strong {
  font-size: 1.1rem;
}

.stock-total {
  padding: 0.2rem 0.65rem;
  border-radius: 999px;
  background: var(--success);
  color: #fff;
  font-weight: 700;
  white-space: nowrap;
}

.stock-total-zero {
  background: var(--muted);
}

.stock-group-body {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  padding: 0 0.75rem 0.75rem;
}

.stock-group-body > .btn {
  align-self: flex-start;
}

.stock-watts {
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
}

.stock-watts-head {
  display: flex;
  align-items: baseline;
  gap: 0.6rem;
  padding-bottom: 0.25rem;
  border-bottom: 1px solid var(--border);
}

.stock-watts-head strong {
  font-size: 1rem;
}

.stock-add {
  margin-left: auto;
}

.stock-variations {
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
}

.stock-variation {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.4rem 0.5rem;
  background: var(--surface);
  border: 1px solid var(--line-soft);
  border-radius: var(--radius-sm);
}

.stock-variation-zero {
  opacity: 0.65;
}

.stock-variation-main {
  flex: 1;
  min-width: 0;
}

.stock-variation-name {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.4rem;
  font-size: 0.9rem;
}

.stock-stepper {
  display: flex;
  flex: none;
  align-items: center;
  gap: 0.25rem;
}

.stock-stepper .btn-icon {
  min-width: 40px;
  height: 40px;
  font-size: 1.3rem;
}

.stock-qty-input {
  width: 3.2rem;
  min-height: 40px;
  padding: 0.2rem;
  font-size: 1.1rem;
  font-weight: 700;
  text-align: center;
}

.tab[hidden] {
  display: none;
}

/* ===== Subscriptions ===== */
.sub-totals {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0.75rem;
}

.sub-total {
  min-width: 0;
}

.sub-total-value {
  font-size: clamp(1.15rem, 5.4vw, 1.7rem);
  overflow-wrap: anywhere;
  font-weight: 700;
  line-height: 1.15;
  font-variant-numeric: tabular-nums;
}

.chart-box-pie {
  height: 15rem;
}

.sub-share {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  align-items: center;
  gap: 0.15rem 0.6rem;
}

.sub-row-name {
  min-width: 0;
  font-weight: 500;
  overflow-wrap: anywhere;
}

.sub-row-details {
  grid-column: 2;
  min-width: 0;
}

.sub-row-actions {
  display: flex;
  grid-column: 3;
  align-items: center;
  justify-content: flex-end;
  gap: 0.25rem;
}

/* A little more air between the pie chart and the first service */
.chart-box-pie {
  margin-bottom: 1.25rem;
}

.sub-swatch {
  flex: none;
  width: 0.9rem;
  height: 0.9rem;
  border-radius: 50%;
}

.sub-inactive {
  opacity: 0.65;
}

.sub-toggle {
  flex: none;
  width: 1.4rem;
  min-height: 0;
  height: 1.4rem;
  margin: 0 0.25rem;
  accent-color: var(--success);
  cursor: pointer;
}

.sub-share-cost {
  white-space: nowrap;
}

/* A dropdown and a button side by side in a card header are exactly the same height, whatever the browser draws for a
   select, and the button's label stays on one line (a wrapped label would make it taller). */
.inline-form > .select-sm,
.inline-form > .btn-sm {
  box-sizing: border-box;
  height: 38px;
  min-height: 38px;
}

.inline-form > .btn-sm {
  padding-block: 0;
  line-height: 1.1;
  white-space: nowrap;
}

/* ===== Homes, invitations and members ===== */
.auth-card > * + * {
  margin-top: 0.75rem;
}

.onboard {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  text-align: left;
}

#view-settings-access .group-title {
  margin: 1.25rem 0 0.5rem;
}

#settings-access .list:empty {
  display: none;
}

.list-item-actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 0.25rem;
}

.list-item-sub {
  font-size: 0.8125rem;
  color: var(--muted);
  overflow-wrap: anywhere;
}

.badge-owner {
  background: var(--primary);
  color: var(--on-primary, #fff);
}

.badge-expired {
  border: 1px solid var(--danger);
  background: transparent;
  color: var(--danger);
}

.account-facts {
  display: grid;
  grid-template-columns: max-content 1fr;
  gap: 0.4rem 1rem;
  margin: 0 0 1rem;
}

.account-facts dt {
  color: var(--muted);
}

.account-facts dd {
  margin: 0;
  overflow-wrap: anywhere;
}

@media (max-width: 480px) {
  #settings-access .list-item {
    flex-direction: column;
    align-items: stretch;
  }

  .list-item-actions {
    justify-content: flex-start;
  }
}

/* ----- First-time setup of a home ----- */
.onboard-section {
  margin: 0 0 0.5rem;
  padding: 0.5rem 0.75rem;
  border: 1px solid var(--border);
  border-radius: 0.5rem;
}

.onboard-module {
  padding-left: 1.5rem;
}

.onboard-theme {
  display: flex;
  gap: 1rem;
}

/* ===== Car ===== */
.landing {
  grid-template-columns: repeat(auto-fit, minmax(min(100%, 15rem), 1fr));
}

.car-tile {
  position: relative;
  display: flex;
  flex-direction: column;
}

.car-tile .landing-card {
  flex: 1;
}

.car-edit {
  position: absolute;
  top: 0.5rem;
  right: 0.5rem;
}

.car-picture {
  display: block;
  width: 7.5rem;
  height: auto;
}

.car-bar {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.5rem 0.75rem;
}

.car-bar-picture .car-picture {
  width: 3rem;
}

.car-bar-text {
  display: flex;
  flex: 1;
  flex-direction: column;
  min-width: 0;
}

.stack {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.form-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
}

.car-optional {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  margin: 0;
  padding: 0.75rem;
  border: 1px dashed var(--border);
  border-radius: var(--radius);
}

.car-optional legend {
  padding: 0 0.4rem;
  color: var(--muted);
  font-size: 0.8125rem;
}

.car-price {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.car-entry {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  padding: 0.75rem 1rem;
  margin-bottom: 0.5rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  text-decoration: none;
}

.car-entry:hover,
.car-entry:focus-visible {
  border-color: var(--primary);
}

.car-entry-main,
.car-entry-cost {
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.car-entry-cost {
  align-items: flex-end;
  text-align: right;
  font-variant-numeric: tabular-nums;
}

.car-kind {
  grid-template-columns: 8.5rem minmax(0, 1fr) auto;
}

.car-table-wrap {
  overflow-x: auto;
}

.car-table {
  width: 100%;
  border-collapse: collapse;
  font-variant-numeric: tabular-nums;
  font-size: 0.82rem;
}

.car-table th,
.car-table td {
  padding: 0.4rem 0.35rem;
  border-bottom: 1px dashed var(--border);
  text-align: left;
  white-space: nowrap;
}

.car-table th[scope='row'] {
  white-space: normal;
}

.car-table th.num,
.car-table td.num {
  text-align: right;
}

.car-table thead th {
  color: var(--muted);
  font-size: 0.8125rem;
  font-weight: 600;
}

.car-now {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
}

.car-table-total th,
.car-table-total td {
  border-bottom: 0;
  font-weight: 700;
}

/* ===== Expenses: categories told apart by colour, compact sub-categories ===== */
.filter-checks {
  display: flex;
  flex-wrap: wrap;
  gap: 0.1rem 0.9rem;
  margin-bottom: 0.5rem;
}

.filter-checks .check-chip[hidden] {
  display: none;
}

.check-chip {
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
  min-height: 28px;
  color: var(--muted);
  font-size: 0.78rem;
  cursor: pointer;
}

.check-chip input {
  width: 15px;
  height: 15px;
  margin: 0;
}

#category-list .category-group {
  gap: 0.4rem;
  padding: 0.3rem 0.3rem 0.3rem 0.25rem;
  border-left: 4px solid var(--cat);
  border-radius: var(--radius-sm);
  background: color-mix(in srgb, var(--cat) 9%, transparent);
}

#category-list .category-head {
  background: color-mix(in srgb, var(--cat) 16%, var(--surface-inset));
  border-color: color-mix(in srgb, var(--cat) 35%, var(--line-soft));
}

#category-list .category-children {
  gap: 0.4rem;
  margin-left: 0;
  padding-left: 0.35rem;
  border-left: 2px solid color-mix(in srgb, var(--cat) 55%, transparent);
}

#category-list .cat-leaf {
  gap: 0.35rem;
  padding: 0.4rem 0.5rem;
}

.leaf-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 0.5rem;
}

.leaf-head .list-item-title {
  flex: 1;
  min-width: 0;
  padding-top: 0.2rem;
}

.leaf-head .icon-toggle {
  flex: none;
  width: 32px;
  height: 32px;
  margin: -0.1rem -0.25rem 0 0;
  font-size: 1rem;
}

.leaf-row {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  justify-content: space-between;
  gap: 0.4rem;
}

#category-list .cat-leaf .done-chip {
  min-height: 36px;
  margin: 0;
  padding: 0.2rem 0.5rem;
  font-size: 0.75rem;
  white-space: nowrap;
}

#category-list .cat-leaf .mini-field .input-sm {
  width: 4.4rem;
}

#category-list .cat-leaf .row-fields {
  flex-wrap: nowrap;
  gap: 0.3rem;
}

#category-list .cat-leaf .progress {
  height: 4px;
  margin: 0;
}

/* The switch of a main module (Home, Money, Car) above its modules in the settings. */
.section-switch {
  margin-top: 0.75rem;
  padding-bottom: 0.25rem;
  border-bottom: 1px solid var(--border);
  font-weight: 700;
}

.section-switch:first-child {
  margin-top: 0;
}

/* Budget template: the sum of a category's sub-categories, and the quiet "add sub-category" button. */
.tpl-sum {
  display: inline-flex;
  flex-direction: column;
  align-items: flex-end;
  line-height: 1.2;
}

.tpl-add-sub {
  align-self: flex-start;
}

/* First-time setup: the theme choice is two boxes as wide as the sections above it. */
.onboard-theme {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0.5rem;
}

.onboard-theme .switch {
  justify-content: center;
  margin: 0;
  padding: 0.6rem 0.75rem;
  border: 1px solid var(--border);
  border-radius: 0.5rem;
}

.onboard-theme .switch:has(input:checked) {
  border-color: var(--primary);
  background: color-mix(in srgb, var(--primary) 14%, transparent);
}

/* Car totals: period buttons, and the cars of the whole home */
.period-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
  margin-bottom: 0.9rem;
}

.period-chip {
  min-height: 34px;
  padding: 0.2rem 0.8rem;
  background: transparent;
  border: 1px solid var(--border);
  border-radius: 999px;
  color: var(--muted);
  font-size: 0.8125rem;
  font-weight: 600;
  cursor: pointer;
}

.period-chip[aria-pressed='true'] {
  background: color-mix(in srgb, var(--primary) 18%, transparent);
  border-color: var(--primary);
  color: var(--text);
}

.fleet-row {
  display: grid;
  grid-template-columns: 8.5rem minmax(0, 1fr) auto;
  align-items: center;
  gap: 0.75rem;
  padding: 0.4rem 0;
  border-bottom: 1px dashed var(--border);
  font-variant-numeric: tabular-nums;
}

.fleet-car {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  min-width: 0;
  overflow-wrap: anywhere;
}

.fleet-car .car-picture {
  width: 1.8rem;
  flex: none;
}

/* ===== Alignment fixes ===== */

/* Expenses: the three list buttons are one size, side by side (wrapping into equal columns on a narrow screen). */
.card-header:has(.exp-actions) h2,
.exp-actions {
  flex: 1 1 100%;
}

.exp-actions {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(8.5rem, 1fr));
  gap: 0.4rem;
}

.exp-actions .btn {
  width: 100%;
  height: 40px;
  min-height: 40px;
  padding-block: 0.2rem;
  justify-content: center;
  text-align: center;
  white-space: normal;
}

.exp-actions .btn[hidden] {
  display: none;
}

/* Template: Who, the other box (the category of a sub-category) and the amount are boxes of one size, in a row. */
.tpl-item .person-input,
.tpl-item .move-select,
.tpl-item .input-sm {
  box-sizing: border-box;
  height: 40px;
  min-height: 40px;
}

@media (max-width: 959px) {
  .tpl-sub-controls,
  .tpl-cat-controls {
    display: grid;
    align-items: center;
    gap: 0.4rem;
  }

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

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

  /* The remove button sits in the top right corner, beside the name, like on the expenses page. */
  .tpl-item {
    position: relative;
  }

  .tpl-item .list-item-main .name-input {
    padding-right: 3rem;
  }

  .tpl-item .category-controls > .btn-icon {
    position: absolute;
    top: 0.65rem;
    right: 0.75rem;
    width: 34px;
    height: 34px;
    min-height: 34px;
    padding: 0;
  }

  .tpl-item .person-input,
  .tpl-item .move-select,
  .tpl-item .input-sm {
    width: 100%;
    flex: none;
  }

  .tpl-cat-controls .tpl-sum {
    align-items: center;
  }
}

/* Expenses: "all spent", the plan and the left amount of a sub-category always sit in one row of boxes of one height. */
#category-list .cat-leaf .leaf-row {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  align-items: end;
  gap: 0.4rem;
}

#category-list .cat-leaf .row-fields {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0.3rem;
}

#category-list .cat-leaf .mini-field {
  min-width: 0;
}

#category-list .cat-leaf .mini-field .input-sm {
  width: 100%;
  height: 38px;
  min-height: 38px;
}

#category-list .cat-leaf .done-chip {
  height: 38px;
  min-height: 38px;
  align-self: end;
}

/* Settings lists: purchase categories and cars */
.hbc-list {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.hbc-list .list-item {
  align-items: center;
}

/* ===== iOS look: settings as inset grouped lists, segmented controls ===== */
.large-title + .view,
.large-title[hidden] + .view {
  margin-top: 0;
}

.large-title:not([hidden]) {
  margin-bottom: 0.75rem;
}

.settings-group > h2 {
  margin: 0 0 0.4rem 1rem;
  color: var(--muted);
  font-size: 0.8125rem;
  font-weight: 400;
  letter-spacing: 0.02em;
  text-transform: uppercase;
}

.card.settings-links {
  padding: 0;
  overflow: hidden;
}

.card.settings-links .settings-link {
  position: relative;
  justify-content: flex-start;
  min-height: 44px;
  padding: 0.5rem 1rem;
  border-top: 0;
}

.card.settings-links .settings-link-text {
  flex: 1 1 auto;
}

.card.settings-links .settings-link-text strong {
  font-weight: 400;
}

/* Separators between the rows start after the icon, as in iOS */
.card.settings-links .settings-link:not([hidden]) ~ .settings-link::before {
  content: '';
  position: absolute;
  top: 0;
  right: 0;
  left: 3.6rem;
  border-top: 0.5px solid var(--line-soft);
}

.card.settings-links .settings-link:not(:has(.row-icon))::before {
  left: 1rem;
}

.card.settings-links a.settings-link:hover {
  background: none;
}

.card.settings-links a.settings-link:active {
  background: var(--surface-inset);
}

.row-icon {
  display: inline-flex;
  flex: none;
  align-items: center;
  justify-content: center;
  width: 29px;
  height: 29px;
  border-radius: 7px;
  background: var(--tint);
  color: #fff;
}

.row-icon svg {
  width: 18px;
  height: 18px;
}

.settings-signout {
  justify-content: center !important;
  width: 100%;
  background: none;
  border: 0;
  color: var(--danger);
  font: inherit;
  cursor: pointer;
}

.segmented {
  display: inline-grid;
  flex: none;
  grid-auto-columns: minmax(0, 1fr);
  grid-auto-flow: column;
  padding: 2px;
  background: var(--surface-inset);
  border-radius: 9px;
}

.segmented button {
  min-height: 30px;
  padding: 0.25rem 0.75rem;
  background: none;
  border: 0;
  border-radius: 7px;
  color: var(--text);
  font-size: 0.8125rem;
  font-weight: 500;
  cursor: pointer;
}

.segmented button[aria-checked='true'] {
  background: var(--seg-thumb);
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.15);
  font-weight: 600;
}

/* Expenses list, iOS look: a thin colour stripe per category, a softly tinted header, no boxes inside boxes */
#category-list .category-group {
  gap: 0.35rem;
  padding: 0 0 0 0.5rem;
  border-left: 3px solid var(--cat);
  border-radius: 0;
  background: none;
}

#category-list .category-head {
  background: color-mix(in srgb, var(--cat) 16%, var(--surface-inset));
  border: 0;
}

#category-list .category-children {
  padding-left: 0;
  border-left: 0;
}

.done-chip {
  border: 0;
  background: var(--surface);
  color: var(--primary);
}

.segmented + *,
.settings-field .settings-link-text strong {
  white-space: nowrap;
}

/* ===== iOS look, step 2: the rest of the modules ===== */
.stats-cards .stat,
.table-scroll,
.bills-compact details,
.bill-field,
.lamps-line,
.lamp-tile,
.lamps-edit-row,
.hb-section,
.hb-purchase,
.hb-payment-form,
.stock-group,
.stock-variation,
.onboard-section,
.car-entry {
  border-color: transparent;
}

.icon-toggle,
.spec-chip,
.period-chip {
  border-color: transparent;
  background: var(--surface-inset);
}

/* Page headers that became the large title and the back button of the bar */
.is-nav-header,
.toolbar-title,
.is-in-bar,
.card.is-nav-only {
  display: none !important;
}

.bar-back.is-cancel::before {
  content: none;
}

.header-actions {
  gap: 0;
}

.header-actions .icon-btn + .icon-btn {
  margin-left: 0.25rem;
}

/* Pages slide in from the right; a form of something new rises from the bottom, like an iOS sheet */
@keyframes view-in {
  from { opacity: 0; transform: translateX(24px); }
  to { opacity: 1; transform: none; }
}

@keyframes view-up {
  from { opacity: 0; transform: translateY(32px); }
  to { opacity: 1; transform: none; }
}

.view-enter {
  animation: view-in 0.28s cubic-bezier(0.2, 0.8, 0.2, 1);
}

.view-enter-up {
  animation: view-up 0.32s cubic-bezier(0.2, 0.8, 0.2, 1);
}

@media (prefers-reduced-motion: reduce) {
  .view-enter,
  .view-enter-up {
    animation: none;
  }
}

/* Segmented controls made from dropdowns fill their row */
.segmented-select {
  display: grid;
  width: 100%;
}

.segmented-select button {
  min-height: 34px;
}

/* Swipe a row to the left to delete it: the row slides over a red "Видалити" */
.card {
  overflow-x: clip;
}

.list-item {
  position: relative;
  touch-action: pan-y;
}

.list-item.is-swiping {
  transform: translateX(var(--swipe));
}

.list-item.is-swiping::after {
  content: 'Видалити';
  position: absolute;
  top: 0;
  bottom: 0;
  left: 100%;
  display: flex;
  align-items: center;
  width: 140px;
  margin-left: 6px;
  padding-left: 1rem;
  background: var(--danger);
  border-radius: var(--radius-sm);
  color: #fff;
  font-weight: 600;
  opacity: 0.7;
}

.list-item.is-swiped-far::after {
  opacity: 1;
}

.list-item:not(.is-swiping) {
  transition: transform 0.2s;
}

/* Action sheets (instead of the browser's confirm and prompt) */
.sheet-overlay {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  padding: 0 0.5rem calc(0.5rem + env(safe-area-inset-bottom));
  background: rgba(0, 0, 0, 0);
  transition: background 0.22s;
}

.sheet-overlay.is-open {
  background: rgba(0, 0, 0, 0.4);
}

.sheet {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  width: min(100%, 28rem);
  transform: translateY(110%);
  transition: transform 0.26s cubic-bezier(0.2, 0.8, 0.2, 1);
}

.sheet-overlay.is-open .sheet {
  transform: none;
}

.sheet-group {
  display: flex;
  flex-direction: column;
  overflow: hidden;
  background: var(--sheet-bg, var(--surface));
  border-radius: 14px;
}

.sheet-message {
  margin: 0;
  padding: 0.9rem 1rem;
  color: var(--muted);
  font-size: 0.8125rem;
  text-align: center;
}

.sheet-input {
  width: auto;
  margin: 0 1rem 0.9rem;
}

.sheet-action,
.sheet-cancel {
  min-height: 56px;
  background: var(--sheet-bg, var(--surface));
  border: 0;
  color: var(--primary);
  font-size: 1.0625rem;
  cursor: pointer;
}

.sheet-action {
  border-top: 0.5px solid var(--line-soft);
}

.sheet-action.is-destructive {
  color: var(--danger);
}

.sheet-cancel {
  border-radius: 14px;
  font-weight: 600;
}

:root:not([data-theme='light']) {
  --sheet-bg: #2c2c2e;
}

:root:not([data-theme='light']) .sheet-input {
  background: #3a3a3c;
}

/* ===== Landing: one big card per section (Home, Money, Car) ===== */
.home-sections .section-card {
  position: relative;
  align-items: flex-start;
  justify-content: flex-end;
  gap: 0.2rem;
  min-height: 9.5rem;
  padding: 1.1rem 1.25rem;
  border: 0;
  text-align: left;
}

.home-sections .section-card::after {
  content: '›';
  position: absolute;
  top: 50%;
  right: 1.1rem;
  color: var(--muted);
  font-size: 1.8rem;
  line-height: 1;
  transform: translateY(-50%);
}

.home-sections .section-card:hover,
.home-sections .section-card:focus-visible {
  background: var(--surface);
  border-color: transparent;
}

.home-sections .section-card:active {
  opacity: 0.6;
}

.section-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 3rem;
  height: 3rem;
  margin-bottom: auto;
  border-radius: 0.8rem;
  background: var(--tint);
  color: #fff;
}

.section-icon svg {
  width: 1.75rem;
  height: 1.75rem;
}

.home-sections .landing-title {
  margin-top: 0.75rem;
  font-size: 1.5rem;
  font-weight: 700;
}

.home-sections .landing-hint {
  padding-right: 1.5rem;
  color: var(--muted);
  font-size: 0.875rem;
}

/* The "+" and other icon buttons of the bar have no box */
button.icon-btn {
  padding: 0;
  background: none;
  border: 0;
  cursor: pointer;
}

/* Before scrolling the bar has no title, so a long back label gets the room */
.bar-title {
  max-width: 0;
}

.app-bar.is-condensed .bar-title {
  max-width: 50vw;
}

/* Toolbars of buttons sit on the page, not in a box of their own */
.card.toolbar {
  padding: 0;
  background: none;
}

/* Savings: the balances as one group of rows, each with its currency's colour as a dot */
.stats-cards {
  gap: 0;
  overflow: hidden;
  background: var(--surface);
  border-radius: var(--radius);
}

.stats-cards .stat {
  min-height: 0;
  padding: 0.75rem 1rem;
  background: none;
  border: 0;
  border-radius: 0;
}

.stats-cards .stat + .stat {
  border-top: 0.5px solid var(--line-soft);
}

.stats-cards .stat-value {
  font-size: 1.375rem;
}

/* Fields inside a grey row or block stand out from it */
.list-item input,
.list-item select,
.hb-payment-form input,
.hb-payment-form select,
.stock-group input,
.stock-group select,
.lamps-edit-row input,
.lamps-edit-row select {
  background: var(--surface);
}

/* ===== Car pages: the currency (₴ / $ / €) and the period above the totals ===== */
.car-controls {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  margin-bottom: 0.75rem;
}

.car-period {
  display: flex;
  flex: 1 1 auto;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.5rem;
  min-width: 0;
}

/* The two dates share the width of the card, so they fit a phone */
.car-period-dates {
  display: flex;
  flex: 1 1 100%;
  align-items: center;
  gap: 0.375rem;
  min-width: 0;
}

.car-period-dates input {
  flex: 1 1 0;
  width: auto;
  min-width: 0;
}

.hb-summary > div > .car-currency {
  margin-bottom: 0.75rem;
}

/*
 * The top bar, as on iOS: at rest it is the colour of the page (no frosted band over the large title, which in the
 * home-screen app also covers the status bar and looked like a pane of glass); it turns translucent once the content
 * scrolls under it.
 */
.app-bar:not(.is-condensed) {
  background: var(--bg);
  -webkit-backdrop-filter: none;
  backdrop-filter: none;
}
