:root {
  --bg: #f4f5f7;
  --card: #ffffff;
  --text: #1c1e21;
  --muted: #6b7280;
  --border: #e5e7eb;
  --accent: #2563eb;
  --accent-contrast: #ffffff;
  --danger: #dc2626;
  --positive: #16a34a;
  --negative: #dc2626;
  --radius: 12px;
  --avatar-colors: #2563eb, #d97706, #16a34a, #db2777, #7c3aed, #0891b2;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
}

.page {
  max-width: 480px;
  margin: 0 auto;
  padding: 16px;
  padding-bottom: 80px;
}

.centered-page {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
}

.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  margin-bottom: 12px;
}

h1 {
  font-size: 1.4rem;
  margin: 0 0 4px;
}

h2 {
  font-size: 1.1rem;
  margin: 0 0 8px;
}

p.subtitle {
  color: var(--muted);
  margin: 0 0 20px;
  font-size: 0.9rem;
}

label {
  display: block;
  font-size: 0.85rem;
  color: var(--muted);
  margin-bottom: 4px;
}

input[type="text"],
input[type="number"],
input[type="password"],
input[type="month"],
select {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 1rem;
  background: white;
  color: var(--text);
}

button {
  cursor: pointer;
  font-size: 0.95rem;
  border-radius: 8px;
  border: none;
  padding: 10px 14px;
  font-weight: 600;
}

.btn-primary {
  background: var(--accent);
  color: var(--accent-contrast);
  width: 100%;
}

.btn-secondary {
  background: #eef1f5;
  color: var(--text);
}

.btn-danger {
  background: transparent;
  color: var(--danger);
  font-weight: 500;
  padding: 4px 8px;
}

.btn-link {
  background: transparent;
  color: var(--accent);
  padding: 4px 8px;
}

.error-text {
  color: var(--danger);
  font-size: 0.85rem;
  min-height: 1.2em;
  margin-top: 8px;
}

.top-bar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 16px;
}

.action-row {
  display: flex;
  gap: 8px;
  margin-bottom: 16px;
}

.action-row button {
  flex: 1;
}

.hidden {
  display: none !important;
}

.bill-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  margin-bottom: 10px;
}

.bill-meta {
  font-size: 0.85rem;
  color: var(--muted);
}

.bill-summary {
  display: flex;
  justify-content: space-between;
  align-items: center;
  cursor: pointer;
  gap: 12px;
}

.item-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  padding: 10px 0;
  border-top: 1px solid var(--border);
}

.item-row:first-of-type {
  border-top: none;
}

.item-name {
  flex: 1 1 140px;
  min-width: 100px;
}

.item-price {
  width: 80px;
}

.item-translation {
  width: 100%;
  font-size: 0.85rem;
  font-style: italic;
  color: var(--muted);
  border-color: transparent;
  background: transparent;
  padding: 2px 0;
}

.item-translation:focus {
  border-color: var(--border);
  background: white;
  padding: 10px 12px;
}

.item-row.needs-review {
  background: #fff7ed;
  border-radius: 8px;
  margin: 4px 0;
  padding-left: 10px;
  padding-right: 10px;
}

.review-badge {
  width: 100%;
  text-align: left;
  background: #fdba74;
  color: #7c2d12;
  font-size: 0.78rem;
  font-weight: 700;
  padding: 6px 10px;
  border-radius: 6px;
}

.assignees {
  display: flex;
  gap: 6px;
  width: 100%;
}

.avatar-btn {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  border: 2px solid var(--border);
  background: white;
  color: var(--text);
  font-size: 0.8rem;
  font-weight: 700;
  padding: 0;
  display: flex;
  align-items: center;
  justify-content: center;
}

.avatar-btn.selected {
  border-color: transparent;
  color: white;
}

.split-note {
  font-size: 0.78rem;
  color: var(--muted);
  width: 100%;
}

.new-item-row {
  display: flex;
  gap: 8px;
  padding-top: 10px;
}

.new-item-row input {
  flex: 1;
}

.setup-list {
  list-style: none;
  padding: 0;
  margin: 12px 0;
}

.setup-list li {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 8px 0;
  border-bottom: 1px solid var(--border);
}

.add-person-row {
  display: flex;
  gap: 8px;
  margin-bottom: 12px;
}

.add-person-row input {
  flex: 1;
}

.balance-row {
  display: flex;
  justify-content: space-between;
  padding: 8px 0;
  border-top: 1px solid var(--border);
}

.balance-row:first-of-type {
  border-top: none;
}

.balance-net.positive {
  color: var(--positive);
  font-weight: 700;
}

.balance-net.negative {
  color: var(--negative);
  font-weight: 700;
}

.transaction-line {
  padding: 8px 0;
  border-top: 1px solid var(--border);
  font-size: 0.92rem;
}

.transaction-line:first-of-type {
  border-top: none;
}

.warning-banner {
  background: #fff7ed;
  border: 1px solid #fdba74;
  color: #9a3412;
  padding: 10px 12px;
  border-radius: 8px;
  font-size: 0.85rem;
  margin-bottom: 12px;
}

.spinner-overlay {
  position: fixed;
  inset: 0;
  background: rgba(255, 255, 255, 0.75);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-direction: column;
  gap: 12px;
  z-index: 50;
}

.spinner {
  width: 32px;
  height: 32px;
  border: 3px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

.receipt-thumb {
  width: 100%;
  max-height: 220px;
  object-fit: cover;
  border-radius: 8px;
  margin-bottom: 10px;
  display: block;
}

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

.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.4);
  display: flex;
  align-items: flex-end;
  justify-content: center;
  z-index: 40;
}

.modal-sheet {
  background: var(--card);
  border-radius: 16px 16px 0 0;
  padding: 20px 16px 24px;
  width: 100%;
  max-width: 480px;
  max-height: 85vh;
  overflow-y: auto;
}

.modal-sheet .close-row {
  display: flex;
  justify-content: flex-end;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #17181a;
    --card: #212327;
    --text: #f1f2f4;
    --muted: #9ca3af;
    --border: #33353a;
  }
  input[type="text"],
  input[type="number"],
  input[type="password"],
  input[type="month"],
  select {
    background: #1a1c1f;
    color: var(--text);
  }
  .avatar-btn {
    background: #1a1c1f;
  }
  .btn-secondary {
    background: #2a2d32;
    color: var(--text);
  }
  .warning-banner {
    background: #2a1c0f;
    border-color: #7c4a1e;
    color: #fdba74;
  }
  .spinner-overlay {
    background: rgba(23, 24, 26, 0.85);
  }
  .item-translation:focus {
    background: #1a1c1f;
  }
  .item-row.needs-review {
    background: #2a1c0f;
  }
  .review-badge {
    background: #7c4a1e;
    color: #fed7aa;
  }
}
