/* rent-split styles. Every color, size and duration comes from tokens.css (a byte copy of the
   design tokens, loaded first); no color literal lives here. The rules are the product CSS of the
   approved mockup (.lavish/design.html) with its `.app` root mapped to the body and its container
   queries written as media queries, plus the self-hosted font and the theme switch. */

@font-face {
  font-family: "Plus Jakarta Sans";
  font-style: normal;
  font-weight: 500;
  font-display: swap;
  src: url(/fonts/plus-jakarta-sans-500-latin.woff2) format("woff2");
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}

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

:root {
  color-scheme: light;
}

[data-theme="dark"] {
  color-scheme: dark;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
  }
}

html {
  background: var(--color-bg);
}

/* The page frame: the mockup's `.app` root. */
body {
  position: relative;
  width: 100%;
  max-width: var(--layout-page);
  margin: 0 auto;
  padding: var(--space-4);
  color: var(--color-text);
  background: var(--color-bg);
  font-family: var(--font-body);
  font-size: var(--text-base);
  font-weight: var(--weight-regular);
  line-height: var(--leading-normal);
  overflow-wrap: break-word;
}

[hidden] {
  display: none !important;
}

/* Skip link: first in the tab order, hidden until focus, then shown at the top of the frame. */
.skip {
  position: absolute;
  left: var(--space-4);
  top: var(--space-2);
  z-index: var(--z-overlay);
  width: 1px;
  height: 1px;
  padding: 0;
  margin: 0;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
  background: var(--color-surface-raised);
  color: var(--color-text);
  border-radius: var(--radius-sm);
}

.skip:focus {
  display: inline-flex;
  align-items: center;
  width: auto;
  height: auto;
  min-height: var(--size-touch);
  padding: var(--space-2) var(--space-3);
  overflow: visible;
  clip: auto;
  white-space: normal;
  box-shadow: var(--shadow-pop);
}

/* Topbar: the wordmark and the lede. The theme switch sits at the right of the wordmark row; it
   is placed out of the flow so it moves neither the receipt nor the form. */
.topbar {
  min-width: 0;
}

.wordmark {
  margin: 0;
  font-size: var(--text-lg);
  font-weight: var(--weight-semibold);
  letter-spacing: var(--tracking-tight);
  line-height: var(--leading-tight);
}

.lede {
  margin: var(--space-2) 0 0;
  max-width: var(--layout-text);
  color: var(--color-text-muted);
  font-size: var(--text-sm);
  line-height: var(--leading-snug);
}

.topbar-tools {
  position: absolute;
  top: var(--space-1);
  right: var(--space-4);
  display: flex;
  align-items: center;
  gap: var(--space-2);
  font-size: var(--text-sm);
  font-weight: var(--weight-medium);
}

.topbar-tools select {
  width: auto;
}

/* Loading: the skeleton stands in for the whole page until the script runs. */
body:has(> #app[aria-busy="true"]) > .topbar,
body:has(> #app[aria-busy="true"]) > .topbar-tools {
  display: none;
}

/* Focus ring: 2 px of the focus color, offset, never removed. */
:focus-visible {
  outline: var(--border-strong) solid var(--color-focus);
  outline-offset: 2px;
}

/* The shell: on a phone the receipt comes first; at 1200 px it is the sticky right column. */
.shell {
  display: flex;
  flex-direction: column;
  gap: var(--space-4);
  margin-top: var(--space-4);
}

.receipt {
  order: -1;
}

/* Banners between the topbar and the shell. */
.banner {
  display: flex;
  gap: var(--space-2);
  align-items: flex-start;
  margin-top: var(--space-4);
  padding: var(--space-3);
  border: var(--border-hair) solid var(--color-border);
  border-radius: var(--radius-md);
  line-height: var(--leading-snug);
}

.banner p {
  margin: 0;
}

.banner-danger {
  background: var(--color-danger-soft);
  color: var(--color-danger-text);
  border-color: var(--color-danger);
}

.banner-info {
  background: var(--color-info-soft);
  color: var(--color-info-text);
  border-color: var(--color-info);
}

/* Cards: the three sections and the receipt. */
.section,
.receipt {
  min-width: 0;
  border: var(--border-hair) solid var(--color-border);
  border-radius: var(--radius-lg);
  background: var(--color-surface);
  box-shadow: var(--shadow-raised);
  padding: var(--space-4);
}

.receipt {
  background: var(--color-surface-raised);
  box-shadow: var(--shadow-pop);
}

.section h2,
.method-title {
  margin: 0 0 var(--space-4);
  font-size: var(--text-lg);
  font-weight: var(--weight-semibold);
  line-height: var(--leading-tight);
}

.method-title {
  margin: var(--space-5) 0 var(--space-3);
  font-size: var(--text-base);
}

/* Fields and rows. */
.fields,
.room-grid,
.person-grid {
  display: grid;
  gap: var(--space-3);
  grid-template-columns: minmax(0, 1fr);
}

.fields > *,
.room-grid > *,
.person-grid > * {
  min-width: 0;
}

/* Every row, the first one too, keeps the hairline and the space under the section heading, as
   the mockup draws it (there the heading, not a row, is the first child of the section). */
.room,
.person {
  min-width: 0;
  padding-top: var(--space-3);
  border-top: var(--border-hair) solid var(--color-border);
}

.room-grid > .btn,
.person-grid > .btn {
  justify-self: start;
  width: auto;
}

label {
  display: block;
  font-size: var(--text-sm);
  font-weight: var(--weight-medium);
}

.field label,
.link-box label {
  margin-bottom: var(--space-1);
}

input[type="text"],
select {
  display: block;
  width: 100%;
  min-width: 0;
  max-width: 100%;
  min-height: var(--size-control);
  padding: 0 var(--space-3);
  font: inherit;
  color: var(--color-text);
  background: var(--color-surface-raised);
  border: var(--border-hair) solid var(--color-border-strong);
  border-radius: var(--radius-sm);
}

.receipt input[type="text"] {
  background: var(--color-bg);
}

input[type="text"]:hover,
select:hover {
  border-color: var(--color-text-muted);
}

input[type="text"]:disabled,
select:disabled {
  color: var(--color-text-muted);
  background: var(--color-surface);
  border-color: var(--color-border);
}

input[aria-invalid="true"],
select[aria-invalid="true"] {
  border: var(--border-strong) solid var(--color-danger);
}

/* One slot under a field holds the hint or the error, so the page does not jump. */
.hint {
  min-height: 1.25rem;
  margin: var(--space-1) 0 0;
  font-size: var(--text-xs);
  line-height: var(--leading-snug);
  color: var(--color-text-muted);
}

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

.hint.is-error:empty {
  display: none;
}

.room > .hint,
.person > .hint {
  margin-top: var(--space-2);
}

/* Checkbox: the label row is the 44 px hit target. */
.check {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  min-height: var(--size-touch);
  min-width: var(--size-touch);
  font-size: var(--text-sm);
  font-weight: var(--weight-medium);
  cursor: pointer;
}

.check input,
input[type="checkbox"] {
  width: 20px;
  height: 20px;
  min-height: 20px;
  padding: 0;
  accent-color: var(--color-accent);
}

.check input:disabled + span {
  color: var(--color-text-muted);
}

.mode {
  margin-top: var(--space-3);
}

.add {
  margin-top: var(--space-3);
}

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-2);
  min-height: var(--size-touch);
  padding: 0 var(--space-4);
  font: inherit;
  font-weight: var(--weight-medium);
  color: var(--color-text);
  background: var(--color-surface-raised);
  border: var(--border-hair) solid var(--color-border-strong);
  border-radius: var(--radius-md);
  cursor: pointer;
  transition: transform var(--duration-fast) var(--ease-out), opacity var(--duration-fast) var(--ease-out);
}

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

.btn:active {
  transform: scale(var(--motion-press));
}

.btn:focus-visible {
  outline: var(--border-strong) solid var(--color-focus);
  outline-offset: 2px;
}

.btn-primary {
  color: var(--color-accent-text);
  background: var(--color-accent);
  border-color: var(--color-accent);
}

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

.btn-secondary,
.btn-ghost {
  color: var(--color-text);
  background: var(--color-surface-raised);
  border-color: var(--color-border-strong);
}

.btn-danger {
  color: var(--color-danger-text);
  background: var(--color-surface-raised);
  border-color: var(--color-danger);
}

.btn-danger:hover {
  background: var(--color-danger-soft);
}

.btn:disabled,
.btn:disabled:hover,
.btn[aria-disabled="true"],
.btn[aria-disabled="true"]:hover {
  color: var(--color-text-muted);
  background: var(--color-surface);
  border-color: var(--color-border);
  cursor: not-allowed;
  transform: none;
  opacity: 1;
}

.actions {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-2);
  margin-top: var(--space-4);
}

.icon {
  width: var(--size-icon);
  height: var(--size-icon);
  flex: none;
}

/* The receipt. */
.eyebrow {
  margin: 0;
  font-size: var(--text-xs);
  font-weight: var(--weight-medium);
  letter-spacing: var(--tracking-wide);
  text-transform: uppercase;
  color: var(--color-text-muted);
}

.bill-total {
  margin: var(--space-2) 0 0;
  font-size: var(--text-xl);
  font-weight: var(--weight-semibold);
  letter-spacing: var(--tracking-tight);
  line-height: var(--leading-tight);
  overflow-wrap: anywhere;
}

.bill-sub,
.empty-copy {
  margin: var(--space-1) 0 0;
  color: var(--color-text-muted);
  font-size: var(--text-sm);
  line-height: var(--leading-snug);
}

.empty-title {
  margin: var(--space-3) 0 0;
  font-size: var(--text-lg);
  font-weight: var(--weight-semibold);
  line-height: var(--leading-tight);
}

.num {
  font-variant-numeric: tabular-nums;
}

.shares {
  list-style: none;
  margin: var(--space-4) 0 0;
  padding: 0;
}

.share {
  display: grid;
  grid-template-columns: var(--size-avatar) minmax(0, 1fr) auto;
  gap: var(--space-1) var(--space-3);
  align-items: center;
  padding: var(--space-3) 0;
  border-top: var(--border-hair) solid var(--color-border);
}

.share-name {
  font-weight: var(--weight-semibold);
  overflow-wrap: anywhere;
}

.share-total {
  font-weight: var(--weight-semibold);
  text-align: right;
}

.share-meta {
  grid-column: 2 / -1;
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-1) var(--space-2);
  align-items: center;
  color: var(--color-text-muted);
  font-size: var(--text-sm);
}

.avatar {
  width: var(--size-avatar);
  height: var(--size-avatar);
  display: grid;
  place-items: center;
  border-radius: var(--radius-full);
  background: var(--color-accent-soft);
  color: var(--color-text);
  font-size: var(--text-sm);
  font-weight: var(--weight-semibold);
}

.badge {
  display: inline-flex;
  align-items: center;
  min-height: 24px;
  padding: 0 var(--space-2);
  border-radius: var(--radius-sm);
  background: var(--color-accent-soft);
  color: var(--color-text);
  font-size: var(--text-xs);
  font-weight: var(--weight-medium);
}

.share-foot {
  display: flex;
  justify-content: space-between;
  gap: var(--space-3);
  margin: 0;
  padding-top: var(--space-3);
  border-top: var(--border-strong) solid var(--color-border-strong);
  font-weight: var(--weight-semibold);
}

.method {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
  max-width: var(--layout-text);
}

.method li {
  padding-left: var(--space-3);
  border-left: var(--border-strong) solid var(--color-accent);
  font-size: var(--text-sm);
  line-height: var(--leading-snug);
  overflow-wrap: anywhere;
}

/* Status slot under the share buttons: a reserved height, so the line never shifts the receipt. */
.status {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  min-height: var(--size-touch);
  margin: var(--space-3) 0 0;
  padding: 0 var(--space-3);
  border-radius: var(--radius-sm);
  font-size: var(--text-sm);
  font-weight: var(--weight-medium);
}

.status.is-success {
  color: var(--color-success-text);
  background: var(--color-success-soft);
}

.status.is-info {
  color: var(--color-info-text);
  background: var(--color-info-soft);
}

.link-box {
  margin-top: var(--space-3);
}

/* Skeleton, shown in the first HTML until the script builds the page. */
.skel {
  background: var(--color-skeleton);
  border-radius: var(--radius-sm);
  animation: pulse var(--duration-slow) var(--ease-out) infinite alternate;
}

.skel-title {
  height: 28px;
  width: 42%;
}

.skel-line {
  height: 14px;
  width: 78%;
  margin-top: var(--space-2);
}

.skel-receipt {
  height: 220px;
  margin-top: var(--space-4);
  border-radius: var(--radius-lg);
}

.skel-card {
  height: 160px;
  margin-top: var(--space-4);
  border-radius: var(--radius-lg);
}

@keyframes pulse {
  from {
    opacity: 1;
  }

  to {
    opacity: 0.5;
  }
}

@media (min-width: 768px) {
  body {
    padding: var(--space-6);
  }

  .topbar-tools {
    right: var(--space-6);
  }

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

  .room-grid {
    grid-template-columns: minmax(0, 1.6fr) minmax(0, 0.8fr) auto auto;
    align-items: end;
  }

  .person-grid {
    grid-template-columns: minmax(0, 1.4fr) minmax(0, 1fr) auto;
    align-items: end;
  }

  .person-grid .field-income {
    grid-column: 1 / -1;
  }

  .bill-total {
    font-size: var(--text-2xl);
  }

  .section,
  .receipt {
    padding: var(--space-5);
  }
}

@media (min-width: 1200px) {
  .shell {
    display: grid;
    grid-template-columns: minmax(0, 1.3fr) minmax(280px, 0.9fr);
    gap: var(--space-8);
    align-items: start;
    margin-top: var(--space-6);
  }

  .form {
    grid-column: 1;
    grid-row: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
    gap: var(--space-4);
  }

  .receipt {
    order: 0;
    grid-column: 2;
    grid-row: 1;
    position: sticky;
    top: var(--space-4);
    z-index: var(--z-sticky);
  }
}

/* Reduced motion: no press scale, no pulse. Color changes on hover stay. */
@media (prefers-reduced-motion: reduce) {
  .btn,
  .skel {
    transition: none;
    animation: none;
  }

  .btn:active {
    transform: none;
  }
}
