/* Expenses: plain CSS, no build step. A "statement" look: warm paper, ink, Inter for words,
   IBM Plex Mono for labels and figures. Tokens first, then layout, components, and pages. */

:root {
  --bg: #ebebe6;
  --surface: #ffffff;
  --surface-muted: #f4f4ef;
  --border: #e2e2db;
  --border-strong: #c9c9c1;
  --rule: #1a1a1a;
  --ink: #141414;
  --text-muted: #5f5f5a;
  --text-faint: #8c8c86;
  --accent-soft: #eef1f7;
  --focus: #6b8fd6;
  --danger: #b4233a;
  --danger-soft: #fbe9ec;
  --warning: #7a5600;
  --warning-soft: #fcf3d9;
  --success: #2f6b3a;
  --success-soft: #e6f2e4;

  --radius-lg: 10px;
  --radius-md: 8px;
  --radius-sm: 6px;
  --shadow: 0 1px 2px rgb(20 20 20 / 0.04);

  --font: "Inter", ui-sans-serif, system-ui, -apple-system, "Segoe UI", sans-serif;
  --mono: "IBM Plex Mono", ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  --gutter: clamp(16px, 4vw, 40px);
  --page-width: 1120px;
  --panel-pad: clamp(20px, 4vw, 40px);
}

/* Base ------------------------------------------------------------------- */

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

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

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font);
  font-size: 15px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

a { color: var(--ink); text-decoration: underline; text-decoration-color: var(--border-strong); text-underline-offset: 3px; }
a:hover { text-decoration-color: var(--ink); }

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

[hidden] { display: none !important; }

img { max-width: 100%; display: block; }

:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }

.visually-hidden {
  position: absolute !important;
  width: 1px; height: 1px;
  padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0 0 0 0);
  white-space: nowrap; border: 0;
}

/* Small uppercase mono labels: eyebrows, card names, column headers. */
.eyebrow {
  font-family: var(--mono);
  font-size: 12px;
  font-weight: 500;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--text-muted);
  margin-bottom: 6px;
}
.eyebrow a { color: inherit; text-decoration: none; }

/* App shell -------------------------------------------------------------- */

.app-header {
  max-width: calc(var(--page-width) + 2 * var(--gutter));
  margin: 0 auto;
  padding: 18px var(--gutter) 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.app-header__brand {
  font-weight: 800;
  font-size: 18px;
  letter-spacing: -0.03em;
  color: var(--ink);
  text-decoration: none;
}

.app-header__nav { display: flex; align-items: center; gap: 16px; font-size: 14px; }
.app-header__link { color: var(--text-muted); font-weight: 600; text-decoration: none; }
.app-header__link:hover { color: var(--ink); }
.app-header__user { color: var(--text-faint); }
.app-header__nav form { margin: 0; }

.page {
  max-width: calc(var(--page-width) + 2 * var(--gutter));
  margin: 0 auto;
  padding: 20px var(--gutter) 64px;
  display: flex;
  flex-direction: column;
  gap: 24px;
}

.flash {
  border-radius: var(--radius-sm);
  padding: 12px 16px;
  font-weight: 500;
  background: var(--success-soft);
  color: var(--success);
}
.flash--alert { background: var(--danger-soft); color: var(--danger); }

/* Panels ----------------------------------------------------------------- */

.panel {
  background: var(--surface);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow);
  padding: var(--panel-pad);
  min-width: 0;
}

.panel--narrow { max-width: 560px; width: 100%; margin-inline: auto; }

.panel__header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 24px;
  flex-wrap: wrap;
}

.panel__title {
  font-size: clamp(24px, 4vw, 32px);
  font-weight: 800;
  letter-spacing: -0.035em;
  line-height: 1.15;
  display: flex;
  align-items: center;
  gap: 12px;
}
.panel__title--small { font-size: 20px; letter-spacing: -0.02em; }

.hint { color: var(--text-muted); font-size: 14px; }

.empty-state { color: var(--text-muted); text-align: center; padding: 40px 16px; }

/* Buttons and inputs ----------------------------------------------------- */

.button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-height: 40px;
  padding: 0 16px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-strong);
  background: var(--surface);
  color: var(--ink);
  font: inherit;
  font-weight: 600;
  font-size: 14px;
  cursor: pointer;
  white-space: nowrap;
  text-decoration: none;
  transition: background 0.15s, border-color 0.15s;
}
.button:hover { background: var(--surface-muted); }

.button--primary { background: var(--ink); border-color: var(--ink); color: #fff; }
.button--primary:hover { background: #333; border-color: #333; }

.button--ghost { background: transparent; border-color: transparent; }
.button--danger { color: var(--danger); }
.button--danger:hover { background: var(--danger-soft); }

.button--small { min-height: 32px; padding: 0 12px; font-size: 13px; }

.button-row { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; }
.button-row form { margin: 0; }

.link-button {
  background: none;
  border: 0;
  padding: 0;
  font: inherit;
  color: var(--text-muted);
  font-weight: 600;
  cursor: pointer;
}
.link-button:hover { color: var(--ink); }

.icon-button {
  display: inline-grid;
  place-items: center;
  width: 34px;
  height: 34px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text-muted);
  cursor: pointer;
  flex: none;
  text-decoration: none;
}
.icon-button:hover { background: var(--surface-muted); color: var(--ink); }

.input {
  width: 100%;
  min-height: 44px;
  padding: 0 12px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-strong);
  background: var(--surface);
  color: var(--ink);
  font: inherit;
  font-size: 16px; /* 16px keeps iOS from zooming on focus */
}
.input:focus { outline: none; border-color: var(--ink); box-shadow: 0 0 0 3px var(--accent-soft); }
.input:disabled { background: var(--surface-muted); color: var(--text-muted); }
select.input { padding-right: 32px; }
.input--compact { min-height: 34px; width: auto; font-size: 14px; padding: 0 10px; }
.input--money { text-align: right; font-family: var(--mono); }
input[type="date"].input { font-family: var(--mono); }

.form { display: flex; flex-direction: column; gap: 18px; }
.form__actions { display: flex; gap: 10px; justify-content: flex-end; flex-wrap: wrap; }

.field { display: flex; flex-direction: column; gap: 6px; min-width: 0; flex: 1; }
.field label { font-weight: 600; font-size: 14px; }
.field-row { display: flex; gap: 16px; flex-wrap: wrap; }
.field-row .field { min-width: 180px; }

.checkbox { display: flex; gap: 10px; align-items: center; font-weight: 600; }
.checkbox input { width: 18px; height: 18px; accent-color: var(--ink); }

.inline-form { display: flex; gap: 8px; align-items: center; margin: 0; }

.form-errors {
  border-radius: var(--radius-sm);
  background: var(--danger-soft);
  color: var(--danger);
  padding: 12px 16px;
  font-size: 14px;
}
.form-errors ul { margin: 6px 0 0; padding-left: 18px; }

.notice { border-radius: var(--radius-sm); padding: 14px 16px; display: flex; flex-direction: column; gap: 10px; }
.notice--warning { background: var(--warning-soft); color: var(--warning); }

.spinner {
  width: 18px;
  height: 18px;
  border-radius: 50%;
  border: 2px solid var(--border);
  border-top-color: var(--ink);
  animation: spin 0.8s linear infinite;
  display: inline-block;
  flex: none;
}
@keyframes spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) { .spinner { animation-duration: 2.4s; } }

.status { font-family: var(--mono); font-size: 12px; font-weight: 500; padding: 3px 8px; border-radius: 999px; }
.status--ok { background: var(--success-soft); color: var(--success); }
.status--muted { background: var(--surface-muted); color: var(--text-muted); }

/* Categories -------------------------------------------------------------- */

.category-dot {
  width: 9px;
  height: 9px;
  border-radius: 2px;
  background: var(--dot);
  display: inline-block;
  flex: none;
}

/* Tinted pill: category color at low opacity, solid dot, label in ink for contrast. */
.category-chip {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 3px 10px 3px 8px;
  border-radius: 999px;
  background: color-mix(in srgb, var(--chip) 30%, white);
  color: var(--ink);
  font-size: 13px;
  font-weight: 600;
  white-space: nowrap;
  justify-self: start;
}
.category-chip .category-dot { border-radius: 50%; width: 7px; height: 7px; }

/* Dashboard + table: one "statement" with a scalloped tear between them ------- */

.statement { display: flex; flex-direction: column; }
.statement > .dashboard { border-radius: var(--radius-lg) var(--radius-lg) 0 0; }
.statement > .expenses {
  position: relative;
  border-radius: 0 0 var(--radius-lg) var(--radius-lg);
  margin-top: 10px;
}
.statement > .expenses::before {
  content: "";
  position: absolute;
  left: 0;
  right: 0;
  top: -10px;
  height: 10px;
  background: radial-gradient(circle at 6px 10px, var(--surface) 5.5px, transparent 6px) 0 0 / 12px 10px repeat-x;
}

.dashboard__meta { display: flex; justify-content: space-between; gap: 12px; flex-wrap: wrap; }

.dashboard__top {
  display: flex;
  justify-content: space-between;
  align-items: flex-end;
  gap: 8px 16px;
  flex-wrap: wrap;
  padding-bottom: 18px;
  border-bottom: 2px solid var(--rule);
}

.dashboard__title {
  font-size: clamp(34px, 6vw, 48px);
  font-weight: 800;
  letter-spacing: -0.045em;
  line-height: 1;
}

.dashboard__total { display: flex; align-items: baseline; gap: 12px; }
.dashboard__total-label { font-family: var(--mono); font-size: 12px; letter-spacing: 0.08em; text-transform: uppercase; color: var(--text-muted); }
.dashboard__total-amount {
  font-family: var(--mono);
  font-size: clamp(34px, 6.5vw, 56px);
  font-weight: 700;
  letter-spacing: -0.03em;
  line-height: 1;
}

.range-controls {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px 14px;
  margin: 18px 0;
}
.range-controls__month { display: flex; gap: 6px; }
.range-controls__presets { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }
.range-controls__person { margin: 0 0 0 auto; }

.range-pill {
  display: inline-flex;
  align-items: center;
  min-height: 32px;
  padding: 0 12px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text-muted);
  font-family: var(--mono);
  font-size: 12.5px;
  font-weight: 500;
  cursor: pointer;
  list-style: none;
  user-select: none;
  text-decoration: none;
}
.range-pill::-webkit-details-marker { display: none; }
.range-pill:hover { color: var(--ink); border-color: var(--border-strong); }
.range-pill--selected, .range-pill--selected:hover { background: var(--ink); border-color: var(--ink); color: #fff; }

.custom-range { position: relative; }
.custom-range__form {
  position: absolute;
  z-index: 10;
  top: calc(100% + 8px);
  left: 0;
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  gap: 10px;
  padding: 14px;
  border-radius: var(--radius-md);
  background: var(--surface);
  border: 1px solid var(--border);
  box-shadow: 0 12px 32px -12px rgb(20 20 20 / 0.25);
  width: max-content;
  max-width: calc(100vw - 2 * var(--gutter));
}
.custom-range__form label { display: flex; flex-direction: column; gap: 4px; font-family: var(--mono); font-size: 12px; color: var(--text-muted); }

.stacked-bar {
  display: flex;
  gap: 2px;
  height: 32px;
  background: var(--surface-muted);
}
.stacked-bar__segment { flex: var(--share) 1 0; min-width: 3px; background: var(--color); }

.category-cards {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 10px;
  margin-top: 20px;
}

/* Cards are buttons: clicking one filters the table to that category. */
.category-card {
  appearance: none;
  border: 1px solid transparent;
  font: inherit;
  color: inherit;
  text-align: left;
  cursor: pointer;
  background: var(--surface-muted);
  border-radius: var(--radius-sm);
  padding: 12px 14px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  min-width: 0;
  transition: border-color 0.15s, background 0.15s;
}
.category-card:hover { border-color: var(--border-strong); }
.category-card[aria-pressed="true"] {
  background: color-mix(in srgb, var(--color) 22%, white);
  border-color: var(--ink);
  box-shadow: inset 0 0 0 1px var(--ink);
}
.category-card__header { display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.category-card__name {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-family: var(--mono);
  font-size: 11.5px;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}
.category-card__share { font-family: var(--mono); font-size: 11.5px; color: var(--text-muted); }
.category-card__amount { font-family: var(--mono); font-size: clamp(16px, 1.8vw, 19px); font-weight: 700; letter-spacing: -0.02em; }
.category-card__count { font-family: var(--mono); font-size: 11.5px; color: var(--text-muted); }

.meter { display: block; height: 4px; background: var(--border); overflow: hidden; }
.meter__fill { display: block; height: 100%; width: calc(var(--share) * 1%); background: var(--color); }

/* Awaiting review strip */

.awaiting {
  background: var(--surface);
  border-radius: var(--radius-md);
  border-left: 4px solid var(--ink);
  padding: 12px 18px;
  display: flex;
  align-items: center;
  gap: 10px 18px;
  flex-wrap: wrap;
}
.awaiting__title { display: flex; align-items: center; gap: 10px; font-weight: 600; }
.awaiting__badge {
  display: inline-grid;
  place-items: center;
  min-width: 24px;
  height: 24px;
  padding: 0 7px;
  border-radius: 999px;
  background: var(--ink);
  color: #fff;
  font-family: var(--mono);
  font-size: 12px;
}
.awaiting__list { display: flex; flex-wrap: wrap; gap: 8px; margin: 0; padding: 0; list-style: none; }
.awaiting__item {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 5px 12px;
  border-radius: 999px;
  background: var(--surface-muted);
  color: var(--ink);
  font-size: 13.5px;
  font-weight: 600;
  text-decoration: none;
}
.awaiting__status { font-family: var(--mono); font-size: 12px; color: var(--text-muted); font-weight: 500; }
.awaiting__item--failed .awaiting__status { color: var(--danger); }

/* Expense table ------------------------------------------------------------ */

.expenses { padding: 0; }

.expenses__header {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 12px 20px;
  flex-wrap: wrap;
  padding: var(--panel-pad) var(--panel-pad) 20px;
}
.expenses__heading { display: flex; align-items: baseline; gap: 12px; flex-wrap: wrap; }
.expenses__title { font-size: 24px; font-weight: 800; letter-spacing: -0.03em; }
.expenses__count { font-family: var(--mono); font-size: 13px; color: var(--text-muted); }

.search { position: relative; flex: 0 1 360px; min-width: 0; }
.search__icon { position: absolute; left: 0; top: 50%; translate: 0 -50%; color: var(--ink); }
.search__input {
  width: 100%;
  min-height: 42px;
  padding: 0 4px 0 28px;
  border: 0;
  border-bottom: 2px solid var(--ink);
  border-radius: 0;
  font-family: var(--mono);
  font-size: 16px;
  background: transparent;
  color: var(--ink);
}
.search__input::placeholder { color: var(--text-faint); }
.search__input:focus { outline: none; border-bottom-color: var(--focus); }

.expense-table { width: 100%; border-collapse: collapse; }

.expense-table thead th {
  padding: 12px 16px;
  border-bottom: 1.5px solid var(--rule);
  text-align: left;
  font-family: var(--mono);
  font-size: 11.5px;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--text-muted);
}
.expense-table thead th:first-child { padding-left: var(--panel-pad); }
.expense-table thead th:last-child { padding-right: var(--panel-pad); }
.expense-table th.expense-table__amount, .expense__amount { text-align: right; }

.sort-link { color: inherit; display: inline-flex; gap: 4px; align-items: center; text-decoration: none; }
.sort-link:hover, .sort-link--active { color: var(--ink); }
.sort-link__arrow { font-size: 9px; }

.expense td { padding: 14px 16px; border-bottom: 1px dashed var(--border-strong); vertical-align: middle; }
.expense td:first-child { padding-left: var(--panel-pad); }
.expense td:last-child { padding-right: var(--panel-pad); }
.expense:last-of-type td { border-bottom: 0; }
.expense--open .expense__summary td { border-bottom-color: transparent; }

/* The caret sits inside the cell's padding, with room before it. */
.expense__toggle {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  padding: 0;
  border: 0;
  background: none;
  font: inherit;
  font-weight: 600;
  color: var(--ink);
  cursor: pointer;
  text-align: left;
}
.expense__chevron { color: var(--text-faint); transition: transform 0.15s; flex: none; margin-left: 2px; }
.expense__toggle[aria-expanded="true"] .expense__chevron { transform: rotate(90deg); }
.expense__number { display: block; font-family: var(--mono); font-size: 12px; color: var(--text-muted); padding-left: 26px; }
.expense__person, .expense__items-count { color: var(--text-muted); font-size: 14px; }
.expense__date { white-space: nowrap; font-family: var(--mono); font-size: 13.5px; }
.expense__amount { font-family: var(--mono); font-weight: 700; white-space: nowrap; }

.expense__details td { background: var(--surface-muted); padding-top: 6px; padding-bottom: 16px; }
.expense__details td:first-child { padding-left: calc(var(--panel-pad) + 16px); }

.expense__links { display: flex; flex-wrap: wrap; gap: 6px 18px; margin-top: 10px; padding-left: 10px; font-size: 13.5px; font-weight: 600; }

/* Line item lists (dashboard rows and receipt summary) */

.item-list { list-style: none; margin: 0; padding: 0; }
.item-list__row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 140px 100px;
  gap: 12px;
  align-items: center;
  padding: 9px 10px;
  border-bottom: 1px dashed var(--border);
  border-radius: var(--radius-sm);
}
.item-list__row:last-child { border-bottom: 0; }
/* Highlighted rows keep the same padding as every other row; only the background changes. */
.item-list__row--match { background: color-mix(in srgb, var(--focus) 14%, white); border-bottom-color: transparent; }
.item-list__amount { text-align: right; font-family: var(--mono); font-weight: 600; }
.item-list--compact .item-list__row { font-size: 14px; }

/* Receipt viewer modal --------------------------------------------------------- */

.viewer {
  padding: 0;
  border: 0;
  border-radius: var(--radius-lg);
  width: min(720px, calc(100vw - 2 * var(--gutter)));
  max-height: calc(100dvh - 2 * var(--gutter));
  background: var(--surface);
  color: var(--ink);
  box-shadow: 0 24px 64px -16px rgb(0 0 0 / 0.4);
}
.viewer::backdrop { background: rgb(20 20 20 / 0.55); }
.viewer__panel { display: flex; flex-direction: column; max-height: inherit; }
.viewer__header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 12px 12px 20px;
  border-bottom: 1px solid var(--border);
}
.viewer__title { font-family: var(--mono); font-size: 13px; font-weight: 600; letter-spacing: 0.04em; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.viewer__actions { display: flex; align-items: center; gap: 12px; flex: none; }
.viewer__full { font-size: 13.5px; font-weight: 600; }
.viewer__body { overflow: auto; background: var(--surface-muted); display: grid; place-items: center; min-height: 200px; }
.viewer__image { max-width: 100%; max-height: calc(100dvh - 2 * var(--gutter) - 60px); object-fit: contain; }
.viewer__pdf { width: 100%; height: calc(100dvh - 2 * var(--gutter) - 60px); border: 0; background: #fff; }

/* Receipt pages -------------------------------------------------------------- */

.capture__options { display: grid; grid-template-columns: 1fr; gap: 12px; }
.capture__option {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 170px;
  padding: 24px 16px;
  border: 1.5px dashed var(--border-strong);
  border-radius: var(--radius-md);
  background: var(--surface-muted);
  text-align: center;
  cursor: pointer;
  transition: border-color 0.15s, background 0.15s;
}
.capture__option:hover, .capture__option:focus-within { border-color: var(--ink); background: var(--surface); }
.capture__icon { color: var(--ink); }
.capture__label { font-weight: 700; font-size: 17px; }
.capture__hint { font-family: var(--mono); font-size: 12px; color: var(--text-muted); }

/* Only touch screens get a camera button. Desktops, and headless browsers with no
   pointer at all, just choose a file. */
.capture__option--camera { display: none; }
@media (pointer: coarse) {
  .capture__option--camera { display: flex; }
  .capture__options { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

.capture__progress { display: flex; flex-direction: column; align-items: center; gap: 16px; padding: 12px 0; }
.capture__preview { max-height: 320px; border-radius: var(--radius-sm); border: 1px solid var(--border); }
.capture__file { display: flex; align-items: center; gap: 10px; font-family: var(--mono); font-size: 14px; padding: 14px 18px; border: 1px solid var(--border); border-radius: var(--radius-sm); max-width: 100%; overflow-wrap: anywhere; }
.capture__status { display: flex; align-items: center; gap: 10px; font-weight: 600; }

.receipt-status { display: flex; flex-direction: column; gap: 16px; }

/* Shared receipt file display (image or PDF). */
.receipt-file { display: flex; flex-direction: column; gap: 8px; min-width: 0; }
.receipt-file__frame {
  display: block;
  border-radius: var(--radius-md);
  overflow: hidden;
  border: 1px solid var(--border);
  background: var(--surface-muted);
}
.receipt-file__frame img { width: 100%; max-height: 70vh; object-fit: contain; }
.receipt-file__pdf { width: 100%; height: 70vh; border: 0; display: block; background: #fff; }
.receipt-file__link { font-size: 13.5px; font-weight: 600; }
.receipt-status .receipt-file { max-width: 360px; }
.receipt-status .receipt-file__frame img { max-height: 360px; }
.receipt-status .receipt-file__pdf { height: 420px; }

.receipt-layout {
  display: grid;
  grid-template-columns: minmax(220px, 340px) minmax(0, 1fr);
  gap: 32px;
  align-items: start;
}
.receipt-layout__image { position: sticky; top: 20px; }
.receipt-layout__body { display: flex; flex-direction: column; gap: 20px; min-width: 0; }

.receipt-summary__total { font-family: var(--mono); font-size: clamp(26px, 5vw, 38px); font-weight: 700; letter-spacing: -0.03em; }

.line-items-editor { border: 0; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 10px; min-width: 0; }
.line-items-editor legend { font-weight: 700; font-size: 16px; margin-bottom: 10px; padding: 0; }

.line-items-editor__head,
.line-item-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 150px 120px 34px;
  gap: 8px;
  align-items: center;
}
.line-items-editor__head { font-family: var(--mono); font-size: 11.5px; font-weight: 600; letter-spacing: 0.08em; text-transform: uppercase; color: var(--text-muted); }
.line-items-editor__head span:nth-child(3) { text-align: right; }
.line-items-editor [data-line-items-target="list"] { display: flex; flex-direction: column; gap: 8px; }
.line-item-row__field { min-width: 0; }
.line-item-row__error { grid-column: 1 / -1; color: var(--danger); font-size: 13px; }
.line-item-row .icon-button { border-color: transparent; }
.line-item-row .icon-button:hover { color: var(--danger); background: var(--danger-soft); }
.line-items-editor > .button { align-self: flex-start; }

.receipt-editor__total {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  padding: 14px 0;
  border-top: 2px solid var(--rule);
  font-weight: 700;
}
.receipt-editor__total output { font-family: var(--mono); font-size: 24px; letter-spacing: -0.02em; }
.receipt-editor__danger { margin-top: 20px; padding-top: 16px; border-top: 1px solid var(--border); display: flex; justify-content: flex-end; }

/* Admin tables -------------------------------------------------------------- */

.table-wrap { overflow-x: auto; margin-inline: -8px; }
.data-table { width: 100%; border-collapse: collapse; }
.data-table th {
  text-align: left;
  font-family: var(--mono);
  font-size: 11.5px;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--text-muted);
  padding: 10px 8px;
  border-bottom: 1.5px solid var(--rule);
}
.data-table td { padding: 14px 8px; border-bottom: 1px dashed var(--border-strong); vertical-align: middle; }
.data-table tr:last-child td { border-bottom: 0; }
.data-table__actions { text-align: right; white-space: nowrap; }
.data-table__actions .button-row { justify-content: flex-end; }
.cell-primary { font-weight: 600; }
.cell-secondary { font-family: var(--mono); font-size: 12px; color: var(--text-muted); }

/* Auth pages */

.auth { display: flex; flex-direction: column; gap: 18px; }
.auth__links { font-size: 14px; }

/* Responsive ----------------------------------------------------------------- */

@media (max-width: 1040px) {
  .category-cards { grid-template-columns: repeat(3, minmax(0, 1fr)); }
}

@media (max-width: 760px) {
  .app-header__user { display: none; }
  .category-cards { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .receipt-layout { grid-template-columns: 1fr; gap: 20px; }
  .receipt-layout__image { position: static; }
  .receipt-file__frame img { max-height: 320px; }
  .receipt-file__pdf { height: 420px; }
  .range-controls__person { margin-left: 0; }
}

@media (max-width: 640px) {
  body { font-size: 14.5px; }
  .page { gap: 18px; }
  .dashboard__total { width: 100%; justify-content: space-between; }

  .search { flex-basis: 100%; }

  /* Each receipt becomes a stacked card instead of a wide row. */
  .expense-table thead { display: none; }
  .expense-table, .expense-table tbody, .expense__summary, .expense__details, .expense__details td { display: block; width: 100%; }
  .expense { border-bottom: 1px dashed var(--border-strong); }
  .expense:last-of-type { border-bottom: 0; }
  .expense__summary {
    display: flex;
    flex-wrap: wrap;
    align-items: baseline;
    padding: 14px var(--panel-pad);
  }
  .expense td, .expense td:first-child, .expense td:last-child { border: 0; padding: 0; }
  /* Merchant and amount fill the first line exactly, so the details always wrap below. */
  .expense .expense__receipt { flex: 1 1 calc(100% - 120px); min-width: 0; }
  .expense .expense__amount { flex: 0 0 120px; padding-left: 12px; order: 1; }
  .expense__person, .expense__items-count, .expense__date { order: 2; font-size: 12.5px; color: var(--text-muted); margin-top: 2px; }
  .expense .expense__person, .expense .expense__items-count { padding-left: 26px; }
  .expense .expense__person + .expense__items-count { padding-left: 0; }
  .expense__person + .expense__items-count::before,
  .expense__date::before { content: "·"; margin: 0 6px; }
  .expense__details td, .expense__details td:first-child { padding: 4px var(--panel-pad) 14px; }
  .item-list__row { grid-template-columns: minmax(0, 1fr) auto; }
  .item-list__row .category-chip { grid-row: 2; }
  .item-list__amount { grid-row: 1 / span 2; grid-column: 2; }
  .expense__links { padding-left: 10px; }

  .line-items-editor__head { display: none; }
  .line-item-row {
    grid-template-columns: minmax(0, 1fr) 110px 34px;
    padding: 10px;
    border-radius: var(--radius-sm);
    background: var(--surface-muted);
  }
  .line-item-row__description { grid-column: 1 / span 2; }
  .line-item-row .icon-button { grid-column: 3; grid-row: 1; }
  .line-item-row__category { grid-column: 1; }
  .line-item-row__amount { grid-column: 2 / span 2; }

  .capture__options { grid-template-columns: 1fr; }
  .capture__option { min-height: 130px; }
}

@media (max-width: 420px) {
  .category-cards { grid-template-columns: 1fr; }
  .app-header__add { padding: 0 10px; }
}
