:root {
  --bg: #F7F8F6;
  --card: #FFFFFF;
  --text: #1E242B;
  --muted: #4A5560;
  --accent: #1F5C4D;
  --accent-hover: #17483C;
  --accent-soft: #E6F0ED;
  --border: #E2E6E2;
  --danger: #8B3A3A;
  --danger-hover: #6F2E2E;
  --danger-soft: #F6EAEA;
  --samboer-bg: #F3EEE8;
  --samboer-text: #5C4533;
  --shadow: 0 1px 2px rgba(30, 36, 43, 0.06), 0 10px 28px rgba(30, 36, 43, 0.05);
  --radius: 16px;
  --font: "Segoe UI", "Helvetica Neue", ui-sans-serif, system-ui, -apple-system, sans-serif;
  --space: 20px;
}

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

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

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 1rem;
  line-height: 1.55;
  letter-spacing: 0.01em;
}

[hidden] {
  display: none !important;
}

h1,
h2,
p {
  margin: 0;
}

h1 {
  font-size: 1.5rem;
  font-weight: 650;
  letter-spacing: 0;
  line-height: 1.25;
}

h2 {
  font-size: 1.125rem;
  font-weight: 650;
  line-height: 1.3;
}

button,
input,
textarea {
  font: inherit;
  color: inherit;
}

button {
  cursor: pointer;
}

.amount,
.item-amount,
#sum-ole,
#sum-samboer,
#sum-total,
.settle-sentence {
  font-variant-numeric: tabular-nums;
  font-feature-settings: "tnum" 1;
}

.login-view {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 32px var(--space);
}

.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.card-login {
  width: 100%;
  max-width: 420px;
  padding: 32px 24px 28px;
}

.card-login h1 {
  text-align: center;
}

.lead {
  margin-top: 8px;
  margin-bottom: 28px;
  text-align: center;
  color: var(--muted);
  font-size: 1.0625rem;
}

label,
.field-label {
  display: block;
  margin-bottom: 8px;
  font-weight: 600;
}

label + input,
label + textarea,
.field-label + .payer-choice {
  margin-bottom: 18px;
}

#login-form label {
  margin-top: 0;
}

input,
textarea {
  width: 100%;
  min-height: 48px;
  padding: 12px 14px;
  border: 1.5px solid var(--border);
  border-radius: 12px;
  background: #fff;
}

textarea {
  min-height: 96px;
  resize: vertical;
  line-height: 1.5;
}

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

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 48px;
  padding: 12px 18px;
  border: 1.5px solid transparent;
  border-radius: 12px;
  font-weight: 600;
  text-decoration: none;
  transition: background-color 0.15s ease, border-color 0.15s ease, color 0.15s ease;
}

.btn-block {
  width: 100%;
}

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

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

.btn-ghost {
  background: transparent;
  border-color: var(--border);
  color: var(--text);
}

.btn-ghost:hover,
.btn-ghost:active {
  background: var(--accent-soft);
}

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

.btn-danger:hover,
.btn-danger:active {
  background: var(--danger-hover);
}

.btn-new {
  font-size: 1.0625rem;
  margin: 4px 0 8px;
}

.error {
  margin: 0 0 16px;
  padding: 10px 12px;
  border-radius: 10px;
  background: var(--danger-soft);
  color: var(--danger);
}

.topbar {
  background: var(--bg);
  border-bottom: 1px solid var(--border);
}

.topbar-inner {
  max-width: 840px;
  margin: 0 auto;
  padding: 12px var(--space);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

.topbar h1 {
  font-size: 1.25rem;
}

.topbar-actions {
  display: flex;
  align-items: center;
  gap: 12px;
}

.sync {
  color: var(--muted);
  font-size: 0.9375rem;
  white-space: nowrap;
}

.wrap {
  max-width: 840px;
  margin: 0 auto;
  padding: 20px var(--space) 48px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.card-settle {
  padding: 24px 20px;
  background: var(--accent-soft);
  border-color: color-mix(in srgb, var(--accent) 18%, var(--border));
}

.settle-sentence {
  font-size: 1.375rem;
  font-weight: 700;
  line-height: 1.35;
  letter-spacing: 0;
}

.settle-amount {
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
}

.settle-sub {
  margin-top: 8px;
  color: var(--muted);
  font-size: 1rem;
}

.overview {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
}

.card-stat {
  padding: 12px 10px;
}

.card-stat h2 {
  font-size: 0.875rem;
  font-weight: 600;
  color: var(--muted);
  line-height: 1.3;
}

.card-stat .amount {
  margin-top: 6px;
  font-size: 1.0625rem;
  font-weight: 700;
}

.filters {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
}

.btn-filter {
  min-height: 48px;
  padding: 10px 12px;
  border: 1.5px solid var(--border);
  border-radius: 12px;
  background: var(--card);
  font-weight: 600;
}

.btn-filter.is-active {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}

.btn-filter:not(.is-active):hover {
  background: var(--accent-soft);
}

.list {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.item-card {
  padding: 18px 16px 14px;
}

.item-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
}

.item-name {
  font-size: 1.125rem;
  font-weight: 650;
  line-height: 1.3;
}

.item-amount {
  font-size: 1.125rem;
  font-weight: 700;
  white-space: nowrap;
}

.badge {
  display: inline-flex;
  align-items: center;
  min-height: 28px;
  margin-top: 10px;
  padding: 2px 10px;
  border-radius: 999px;
  font-size: 0.875rem;
  font-weight: 650;
}

.badge-ole {
  background: var(--accent-soft);
  color: var(--accent);
}

.badge-samboer {
  background: var(--samboer-bg);
  color: var(--samboer-text);
}

.item-meta {
  margin-top: 8px;
  color: var(--muted);
}

.item-note {
  margin-top: 6px;
}

.item-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 14px;
}

.item-actions .btn {
  flex: 1 1 96px;
}

.empty {
  padding: 8px 4px 12px;
  color: var(--muted);
}

.ended {
  margin-top: 8px;
  padding-top: 8px;
  border-top: 1px solid var(--border);
}

.ended-toggle {
  width: 100%;
  min-height: 48px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 8px 4px;
  border: 0;
  background: transparent;
  font-weight: 650;
  text-align: left;
}

.caret {
  display: inline-block;
  font-size: 0.85rem;
  line-height: 1;
  transition: transform 0.15s ease;
}

.ended-toggle[aria-expanded="true"] .caret {
  transform: rotate(180deg);
}

.sheet {
  position: fixed;
  inset: 0;
  z-index: 40;
  display: flex;
  align-items: flex-end;
  justify-content: center;
}

.sheet-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(30, 36, 43, 0.35);
}

.sheet-panel {
  position: relative;
  width: 100%;
  max-width: 560px;
  max-height: min(92vh, 900px);
  overflow: auto;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 20px 20px 0 0;
  box-shadow: var(--shadow);
  padding: 24px 20px 28px;
}

.sheet-panel-narrow {
  max-width: 480px;
}

.sheet-panel h2 {
  margin-bottom: 20px;
}

#confirm-text {
  margin-bottom: 24px;
}

.payer-choice {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.btn-payer {
  min-height: 52px;
  border: 1.5px solid var(--border);
  border-radius: 12px;
  background: var(--card);
  font-weight: 650;
}

.btn-payer[aria-pressed="true"][data-payer="ole"] {
  background: var(--accent-soft);
  border-color: var(--accent);
  color: var(--accent);
}

.btn-payer[aria-pressed="true"][data-payer="samboer"] {
  background: var(--samboer-bg);
  border-color: var(--samboer-text);
  color: var(--samboer-text);
}

.sheet-actions {
  display: flex;
  gap: 10px;
  margin-top: 8px;
}

.sheet-actions .btn {
  flex: 1;
}

@media (min-width: 640px) {
  .card-stat {
    padding: 16px;
  }

  .card-stat h2 {
    font-size: 0.9875rem;
  }

  .card-stat .amount {
    font-size: 1.35rem;
  }

  .settle-sentence {
    font-size: 1.75rem;
  }

  .sheet {
    align-items: center;
    padding: 24px;
  }

  .sheet-panel,
  .sheet-panel-narrow {
    border-radius: 20px;
  }
}

@media (prefers-reduced-motion: reduce) {
  .btn,
  .caret {
    transition: none;
  }
}
