:root {
  --bg: #f5f5f7;
  --surface: #ffffff;
  --surface-soft: #f2f2f7;
  --line: rgba(60, 60, 67, 0.12);
  --text: #1c1c1e;
  --muted: #6c6c70;
  --accent: #007aff;
  --accent-ink: #ffffff;
  --positive: #34c759;
  --warning: #ff9500;
  --negative: #ff3b30;
  --purple: #af52de;
  --font: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, sans-serif;
  --move-fast: 160ms;
  --move: 220ms;
  --move-slow: 320ms;
  --ease: cubic-bezier(0.22, 1, 0.36, 1);
  color-scheme: light;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  min-height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 16px;
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
}

body { padding-top: calc(3.5rem + env(safe-area-inset-top)); }

button, input, select { font: inherit; }
button { cursor: pointer; }
h1, h2, h3, p { margin: 0; }
h1 { font-size: 1.75rem; line-height: 1.15; font-weight: 700; letter-spacing: -0.025em; }
h2 { font-size: 1.125rem; font-weight: 650; }
a { color: var(--accent); text-decoration: none; }

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

.topbar {
  position: fixed;
  z-index: 50;
  top: 0;
  left: 0;
  right: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  height: calc(3.5rem + env(safe-area-inset-top));
  padding: env(safe-area-inset-top) 16px 0;
  background: rgba(245, 245, 247, 0.92);
  backdrop-filter: blur(18px);
  border-bottom: 1px solid var(--line);
}

.wordmark {
  position: absolute;
  left: 16px;
  color: var(--text);
  font-weight: 700;
}

.topbar__section {
  max-width: 48vw;
  overflow: hidden;
  color: var(--muted);
  font-size: 0.9375rem;
  font-weight: 600;
  text-overflow: ellipsis;
  white-space: nowrap;
}

main {
  padding: 16px 16px calc(6.5rem + env(safe-area-inset-bottom));
}

.page {
  display: grid;
  gap: 16px;
  width: min(100%, 30rem);
  margin-inline: auto;
  animation: enter var(--move) var(--ease);
}

@keyframes enter {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: none; }
}

.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 20px;
  padding: 16px;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.025);
}

.hero {
  display: grid;
  gap: 4px;
  padding: 22px 18px;
}

.hero h2 {
  font-size: 2rem;
  font-weight: 700;
  letter-spacing: -0.035em;
  font-variant-numeric: tabular-nums lining-nums;
}

.eyebrow {
  color: var(--accent);
  font-size: 0.8125rem;
  font-weight: 700;
  letter-spacing: 0.01em;
}

.muted { color: var(--muted); }
.compact { font-size: 0.875rem; }
.positive { color: var(--positive); }
.negative { color: var(--negative); }
.note {
  color: var(--muted);
  font-size: 0.8125rem;
  line-height: 1.4;
}

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

.metric {
  display: grid;
  gap: 4px;
  min-height: 88px;
}

.metric span {
  color: var(--muted);
  font-size: 0.8125rem;
  font-weight: 500;
}

.metric strong {
  align-self: end;
  font-size: 1.0625rem;
  font-variant-numeric: tabular-nums lining-nums;
  line-height: 1.2;
  overflow-wrap: anywhere;
}

.quick-actions {
  display: grid;
  grid-template-columns: 1fr;
  gap: 10px;
}

.button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 48px;
  padding: 0 18px;
  border: 0;
  border-radius: 14px;
  background: var(--accent);
  color: var(--accent-ink);
  font-weight: 650;
  text-align: center;
  text-decoration: none;
  transition: opacity var(--move-fast) var(--ease), transform var(--move-fast) var(--ease), background var(--move-fast) var(--ease);
}

.button:active { opacity: 0.82; transform: scale(0.985); }
.button--secondary {
  background: var(--surface-soft);
  color: var(--accent);
}
.button--danger {
  background: color-mix(in srgb, var(--negative) 10%, white);
  color: var(--negative);
}
.button--small {
  min-height: 38px;
  padding-inline: 14px;
  border-radius: 12px;
  font-size: 0.875rem;
}

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

.page-heading { margin-top: 4px; }
.section-heading a { font-size: 0.875rem; font-weight: 600; }

.empty {
  display: grid;
  gap: 12px;
  justify-items: start;
  color: var(--muted);
}

.mini-list, .payment-list, .delivery-list, .installment-list {
  display: grid;
}

.mini-list { margin-top: 12px; }

.mini-row, .payment-row {
  display: flex;
  align-items: center;
  gap: 12px;
  min-height: 58px;
  padding: 8px 0;
  color: var(--text);
  border-top: 1px solid var(--line);
}

.mini-row:first-child, .payment-row:first-child { border-top: 0; }

.mini-row__main, .payment-row__main {
  display: grid;
  flex: 1;
  min-width: 0;
}

.mini-row strong, .payment-row strong {
  overflow: hidden;
  font-size: 0.9375rem;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.mini-row small, .payment-row small, .mutualist-card small {
  color: var(--muted);
  font-size: 0.8125rem;
}

.number-badge {
  display: inline-grid;
  place-items: center;
  flex: 0 0 auto;
  width: 34px;
  height: 34px;
  border-radius: 11px;
  background: color-mix(in srgb, var(--accent) 12%, white);
  color: var(--accent);
  font-size: 0.9375rem;
  font-weight: 750;
  font-variant-numeric: tabular-nums;
}

.number-badge--large {
  width: 46px;
  height: 46px;
  border-radius: 15px;
  font-size: 1.25rem;
}

.progress-ring {
  color: var(--muted);
  font-size: 0.75rem;
  font-weight: 650;
  font-variant-numeric: tabular-nums;
}

.mutualist-card { display: grid; gap: 12px; }

.mutualist-card__header {
  display: flex;
  align-items: center;
  gap: 12px;
  color: var(--text);
}

.mutualist-card__header > span:nth-child(2) {
  display: grid;
  flex: 1;
  min-width: 0;
}

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

progress.progress {
  width: 100%;
  height: 8px;
  overflow: hidden;
  border: 0;
  border-radius: 999px;
  background: var(--surface-soft);
  appearance: none;
}

progress.progress::-webkit-progress-bar {
  border-radius: 999px;
  background: var(--surface-soft);
}

progress.progress::-webkit-progress-value {
  border-radius: 999px;
  background: var(--positive);
  transition: width var(--move-slow) var(--ease);
}

progress.progress::-moz-progress-bar {
  border-radius: 999px;
  background: var(--positive);
  transition: width var(--move-slow) var(--ease);
}

.installment-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(29px, 1fr));
  gap: 5px;
}

.installment {
  display: inline-grid;
  place-items: center;
  min-width: 29px;
  height: 29px;
  padding-inline: 3px;
  border-radius: 8px;
  background: var(--surface-soft);
  color: var(--muted);
  font-size: 0.6875rem;
  font-weight: 650;
  font-variant-numeric: tabular-nums;
}

.installment--paid {
  background: color-mix(in srgb, var(--positive) 18%, white);
  color: #187a36;
}

.installment--overdue {
  background: color-mix(in srgb, var(--negative) 14%, white);
  color: var(--negative);
}

.fields {
  display: grid;
  gap: 16px;
}

.fields label {
  display: grid;
  gap: 7px;
  color: var(--muted);
  font-size: 0.8125rem;
  font-weight: 600;
}

.fields input, .fields select, .delivery-assign select {
  width: 100%;
  min-height: 48px;
  padding: 0 13px;
  border: 1px solid transparent;
  border-radius: 14px;
  background: var(--surface-soft);
  color: var(--text);
  font-size: 1rem;
}

.fields input:focus, .fields select:focus, .delivery-assign select:focus {
  border-color: var(--accent);
  outline: none;
  box-shadow: 0 0 0 2px color-mix(in srgb, var(--accent) 18%, transparent);
}

.segmented-field {
  display: grid;
  gap: 7px;
  margin: 0;
  padding: 0;
  border: 0;
}

.segmented-field legend {
  margin-bottom: 7px;
  color: var(--muted);
  font-size: 0.8125rem;
  font-weight: 600;
}

.segmented {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 3px;
  padding: 3px;
  border-radius: 14px;
  background: var(--surface-soft);
}

.segmented label { display: contents; }
.segmented input {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}

.segmented span {
  display: grid;
  place-items: center;
  min-height: 42px;
  padding: 0 8px;
  border-radius: 11px;
  color: var(--muted);
  font-size: 0.875rem;
  font-weight: 600;
  text-align: center;
}

.segmented input:checked + span {
  background: var(--surface);
  color: var(--text);
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.12);
}

.detail-card { display: grid; gap: 18px; }
.detail-hero {
  display: flex;
  align-items: center;
  gap: 12px;
}

.facts {
  display: grid;
  gap: 0;
  margin: 0;
}

.facts div {
  display: flex;
  justify-content: space-between;
  gap: 14px;
  padding: 10px 0;
  border-top: 1px solid var(--line);
}

.facts dt {
  color: var(--muted);
  font-size: 0.875rem;
}

.facts dd {
  margin: 0;
  font-size: 0.875rem;
  font-weight: 650;
  text-align: right;
  font-variant-numeric: tabular-nums;
}

.installment-list { margin-top: 12px; }

.installment-row {
  display: grid;
  grid-template-columns: 34px 1fr auto;
  gap: 8px 10px;
  align-items: center;
  padding: 10px 0;
  border-top: 1px solid var(--line);
}

.installment-row:first-child { border-top: 0; }
.installment-row span:nth-child(2) { font-size: 0.875rem; }
.installment-row strong {
  font-size: 0.8125rem;
  font-variant-numeric: tabular-nums;
}
.installment-row em {
  grid-column: 2 / 4;
  color: var(--muted);
  font-size: 0.75rem;
  font-style: normal;
}
.installment-row--paid em { color: #187a36; }
.installment-row--overdue em { color: var(--negative); }

.delivery-list { margin-top: 14px; }

.delivery-row {
  display: grid;
  gap: 12px;
  padding: 14px 0;
  border-top: 1px solid var(--line);
}

.delivery-row:first-child { border-top: 0; }
.delivery-row__date {
  display: grid;
  gap: 2px;
}
.delivery-row__date strong { text-transform: capitalize; }
.delivery-row__date span {
  color: var(--muted);
  font-size: 0.8125rem;
}

.delivery-row__assigned {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px;
  border-radius: 14px;
  background: var(--surface-soft);
}

.delivery-row__assigned div { display: grid; }
.delivery-row__assigned small { color: var(--muted); }

.delivery-assign {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 8px;
}

.pill {
  display: inline-flex;
  align-items: center;
  width: fit-content;
  min-height: 26px;
  padding-inline: 10px;
  border-radius: 999px;
  background: var(--surface-soft);
  color: var(--muted);
  font-size: 0.75rem;
  font-weight: 650;
}

.payment-row form { margin: 0; }

.settings-card {
  display: grid;
  gap: 16px;
}

.settings-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-height: 52px;
  color: var(--text);
  border-bottom: 1px solid var(--line);
  font-weight: 600;
}

.alert {
  padding: 12px 14px;
  border-radius: 14px;
  font-size: 0.875rem;
  font-weight: 600;
}

.alert--danger {
  background: color-mix(in srgb, var(--negative) 10%, white);
  color: var(--negative);
}

.alert--ok {
  background: color-mix(in srgb, var(--positive) 12%, white);
  color: #187a36;
}

.tabbar {
  position: fixed;
  z-index: 50;
  right: 0;
  bottom: 0;
  left: 0;
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  min-height: calc(4.25rem + env(safe-area-inset-bottom));
  padding: 5px 6px calc(5px + env(safe-area-inset-bottom));
  background: rgba(255, 255, 255, 0.94);
  backdrop-filter: blur(18px);
  border-top: 1px solid var(--line);
}

.tabbar a {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  min-height: 54px;
  border-radius: 14px;
  color: var(--muted);
  font-size: 0.625rem;
  font-weight: 600;
  text-decoration: none;
}

.tabbar a[aria-current="page"] {
  background: color-mix(in srgb, var(--accent) 11%, white);
  color: var(--accent);
}

.tabbar__icon {
  display: grid;
  place-items: center;
  height: 24px;
}

.tabbar svg { display: block; }

@media (hover: hover) and (pointer: fine) {
  .button:hover { opacity: 0.92; }
  .mini-row:hover, .settings-row:hover { color: var(--accent); }
}

@media (min-width: 30rem) {
  .quick-actions { grid-template-columns: repeat(3, 1fr); }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.001ms !important;
    scroll-behavior: auto !important;
    transition-duration: 0.001ms !important;
  }
}

form.rodauth {
  display: grid;
  gap: 16px;
  padding: 16px;
  border: 1px solid var(--line);
  border-radius: 20px;
  background: var(--surface);
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.025);
}

form.rodauth .form-group {
  display: grid;
  gap: 7px;
  margin: 0;
}

form.rodauth label {
  color: var(--muted);
  font-size: 0.8125rem;
  font-weight: 600;
}

.page input:not([type="hidden"]):not([type="radio"]):not([type="checkbox"]):not([type="submit"]),
.page select {
  width: 100%;
  min-height: 48px;
  padding: 0 13px;
  border: 1px solid transparent;
  border-radius: 14px;
  background: var(--surface-soft);
  color: var(--text);
  font-size: 1rem;
}

.page input:focus, .page select:focus {
  border-color: var(--accent);
  outline: none;
  box-shadow: 0 0 0 2px color-mix(in srgb, var(--accent) 18%, transparent);
}

.page input[type="submit"], .page button[type="submit"]:not(.button) {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  min-height: 48px;
  padding: 0 18px;
  border: 0;
  border-radius: 14px;
  background: var(--accent);
  color: var(--accent-ink);
  font-weight: 650;
}

.rodauth-login-form-footer-links-heading {
  margin: 0;
  font-size: 1rem;
}

.rodauth-links {
  display: grid;
  gap: 8px;
  margin: 0;
  padding: 0 0 0 1.2rem;
  color: var(--muted);
}

.installment { position: relative; }

.installment--paid::after {
  content: "✓";
  position: absolute;
  top: 0;
  right: 2px;
  color: #187a36;
  font-size: 0.5rem;
  font-weight: 800;
  line-height: 1;
}

.grid-legend {
  display: flex;
  flex-wrap: wrap;
  gap: 8px 14px;
  color: var(--muted);
  font-size: 0.75rem;
}

.grid-legend span {
  display: inline-flex;
  align-items: center;
  gap: 5px;
}

.legend-dot {
  width: 10px;
  height: 10px;
  border-radius: 3px;
  background: var(--surface-soft);
}

.legend-dot--paid { background: color-mix(in srgb, var(--positive) 35%, white); }
.legend-dot--overdue { background: color-mix(in srgb, var(--negative) 30%, white); }

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

.detail-actions .button {
  min-width: 0;
  padding-inline: 10px;
  font-size: 0.875rem;
  white-space: nowrap;
}
