:root {
  --c-bg: #f4f4f7;
  --c-surface: #ffffff;
  --c-text: #1a1a1f;
  --c-text-muted: #6b6b78;
  --c-border: #e5e5ec;
  --c-primary: #2563eb;
  --c-primary-hover: #1d4ed8;
  --c-primary-soft: #dbeafe;
  --c-danger: #dc2626;
  --c-danger-hover: #b91c1c;
  --c-success: #16a34a;
  --radius: 12px;
  --radius-sm: 8px;
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.04), 0 4px 12px rgba(0, 0, 0, 0.05);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

@media (prefers-color-scheme: dark) {
  :root {
    --c-bg: #0f1115;
    --c-surface: #1a1d23;
    --c-text: #f2f2f5;
    --c-text-muted: #9ca3af;
    --c-border: #2a2e36;
    --c-primary: #3b82f6;
    --c-primary-hover: #60a5fa;
    --c-primary-soft: #1e3a8a;
    --shadow: 0 1px 2px rgba(0, 0, 0, 0.3), 0 4px 12px rgba(0, 0, 0, 0.4);
  }
}

* {
  box-sizing: border-box;
}

html, body {
  margin: 0;
  padding: 0;
  background: var(--c-bg);
  color: var(--c-text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  font-size: 16px;
  line-height: 1.5;
  -webkit-text-size-adjust: 100%;
  -webkit-font-smoothing: antialiased;
}

button,
input,
select,
textarea {
  font-family: inherit;
  color: inherit;
}

.app {
  max-width: 560px;
  margin: 0 auto;
  min-height: 100vh;
  padding-bottom: calc(24px + var(--safe-bottom));
}

.app-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 16px;
  background: var(--c-surface);
  border-bottom: 1px solid var(--c-border);
  position: sticky;
  top: 0;
  z-index: 10;
}

.app-header h1 {
  margin: 0;
  font-size: 1.25rem;
  font-weight: 600;
}

.icon-btn {
  background: transparent;
  border: 1px solid var(--c-border);
  color: var(--c-text-muted);
  width: 36px;
  height: 36px;
  border-radius: 50%;
  font-size: 1.1rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.15s ease;
}

.icon-btn:hover {
  background: var(--c-bg);
  color: var(--c-danger);
  border-color: var(--c-danger);
}

.icon-btn-add {
  color: var(--c-primary);
  border-color: var(--c-primary);
  font-size: 1.3rem;
  font-weight: 600;
  flex-shrink: 0;
}

.icon-btn-add:hover {
  background: var(--c-primary);
  color: white;
  border-color: var(--c-primary);
}

.receipt-bar {
  display: flex;
  gap: 8px;
  align-items: center;
  padding: 10px 16px;
  background: var(--c-surface);
  border-bottom: 1px solid var(--c-border);
}

.receipt-switcher-btn {
  flex: 1;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 12px;
  background: var(--c-bg);
  border: 1px solid var(--c-border);
  border-radius: var(--radius-sm);
  color: var(--c-text);
  font-family: inherit;
  font-size: 0.9375rem;
  cursor: pointer;
  text-align: left;
  min-height: 40px;
  transition: all 0.15s ease;
}

.receipt-switcher-btn:hover {
  border-color: var(--c-primary);
}

.receipt-switcher-label {
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--c-text-muted);
  font-weight: 500;
  flex-shrink: 0;
}

.receipt-switcher-name {
  flex: 1;
  font-weight: 500;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.receipt-switcher-arrow {
  color: var(--c-text-muted);
  font-size: 0.875rem;
  flex-shrink: 0;
}

.tabs {
  display: flex;
  background: var(--c-surface);
  border-bottom: 1px solid var(--c-border);
  position: sticky;
  top: 65px;
  z-index: 9;
}

.tab {
  flex: 1;
  background: transparent;
  border: none;
  border-bottom: 2px solid transparent;
  color: var(--c-text-muted);
  padding: 12px 8px;
  font-size: 0.875rem;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.15s ease;
  font-family: inherit;
}

.tab.active {
  color: var(--c-primary);
  border-bottom-color: var(--c-primary);
}

.panel {
  display: none;
  padding: 16px;
}

.panel.active {
  display: block;
}

.card {
  background: var(--c-surface);
  border-radius: var(--radius);
  padding: 16px;
  margin-bottom: 16px;
  box-shadow: var(--shadow);
}

.card-title {
  font-size: 0.875rem;
  font-weight: 600;
  color: var(--c-text-muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-bottom: 12px;
}

.field {
  display: block;
  margin-bottom: 12px;
}

.field:last-child {
  margin-bottom: 0;
}

.field-label {
  display: block;
  font-size: 0.875rem;
  font-weight: 500;
  color: var(--c-text-muted);
  margin-bottom: 6px;
}

input[type="text"],
input[type="number"] {
  width: 100%;
  padding: 12px;
  font-size: 1rem;
  border: 1px solid var(--c-border);
  border-radius: var(--radius-sm);
  background: var(--c-surface);
  color: var(--c-text);
  font-family: inherit;
  -webkit-appearance: none;
  appearance: none;
}

input[type="text"]:focus,
input[type="number"]:focus {
  outline: none;
  border-color: var(--c-primary);
  box-shadow: 0 0 0 3px var(--c-primary-soft);
}

.inline-form {
  display: flex;
  gap: 8px;
  margin-bottom: 12px;
}

.inline-form input {
  flex: 1;
}

.btn-primary,
.btn-secondary,
.btn-danger {
  padding: 12px 16px;
  font-size: 1rem;
  font-weight: 500;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: all 0.15s ease;
  font-family: inherit;
  border: 1px solid transparent;
  min-height: 44px;
}

.btn-primary {
  background: var(--c-primary);
  color: white;
}

.btn-primary:hover {
  background: var(--c-primary-hover);
}

.btn-primary:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

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

.btn-secondary:hover {
  background: var(--c-bg);
}

.btn-danger {
  background: var(--c-danger);
  color: white;
}

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

.btn-block {
  display: block;
  width: 100%;
  margin-top: 8px;
}

.btn-grow {
  flex: 1;
}

.btn-link {
  background: transparent;
  border: none;
  color: var(--c-primary);
  cursor: pointer;
  padding: 4px 0;
  font-size: 0.875rem;
  font-family: inherit;
}

.btn-link:hover {
  text-decoration: underline;
}

.form-actions {
  display: flex;
  gap: 8px;
  margin-top: 12px;
}

.chip-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 12px;
  background: var(--c-bg);
  border: 1px solid var(--c-border);
  border-radius: 999px;
  color: var(--c-text);
  font-size: 0.9375rem;
  font-family: inherit;
  user-select: none;
}

.chip-remove {
  background: transparent;
  border: none;
  color: var(--c-text-muted);
  cursor: pointer;
  padding: 0;
  font-size: 1.1rem;
  line-height: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 18px;
  height: 18px;
  border-radius: 50%;
}

.chip-remove:hover {
  background: var(--c-danger);
  color: white;
}

.chip-list.selectable .chip {
  cursor: pointer;
  transition: all 0.15s ease;
  min-height: 40px;
  padding: 8px 14px;
}

.chip-list.selectable .chip.selected {
  background: var(--c-primary);
  color: white;
  border-color: var(--c-primary);
}

.assignee-actions {
  display: flex;
  gap: 12px;
  margin-top: 8px;
}

.empty-state {
  color: var(--c-text-muted);
  font-size: 0.9375rem;
  font-style: italic;
  margin: 8px 0 0;
}

.empty-state.hidden,
.hidden {
  display: none !important;
}

.sticky-total {
  text-align: center;
  background: linear-gradient(135deg, var(--c-primary), var(--c-primary-hover));
  color: white;
}

.sticky-total .total-label {
  font-size: 0.8125rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  opacity: 0.85;
}

.sticky-total .total-amount {
  font-size: 1.75rem;
  font-weight: 700;
  margin-top: 4px;
}

.entries-list {
  list-style: none;
  margin: 0;
  padding: 0;
}

.entry-item {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 12px;
  padding: 12px 0;
  border-bottom: 1px solid var(--c-border);
}

.entry-item:last-child {
  border-bottom: none;
}

.entry-info {
  flex: 1;
  min-width: 0;
}

.entry-name {
  font-weight: 500;
  margin-bottom: 2px;
  word-break: break-word;
}

.entry-meta {
  font-size: 0.8125rem;
  color: var(--c-text-muted);
  word-break: break-word;
}

.entry-price-block {
  text-align: right;
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 6px;
}

.entry-price {
  font-weight: 600;
  white-space: nowrap;
}

.entry-actions {
  display: flex;
  gap: 4px;
}

.entry-action-btn {
  background: transparent;
  border: 1px solid var(--c-border);
  border-radius: var(--radius-sm);
  width: 32px;
  height: 32px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--c-text-muted);
  font-size: 0.875rem;
  transition: all 0.15s ease;
}

.entry-action-btn:hover {
  background: var(--c-bg);
  color: var(--c-text);
}

.entry-action-btn.delete:hover {
  background: var(--c-danger);
  color: white;
  border-color: var(--c-danger);
}

.summary-rows {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-top: 12px;
}

.summary-row {
  display: flex;
  justify-content: space-between;
  font-size: 0.9375rem;
  color: var(--c-text-muted);
}

.summary-row.total {
  font-size: 1.125rem;
  font-weight: 700;
  color: var(--c-text);
  padding-top: 8px;
  border-top: 1px solid var(--c-border);
  margin-top: 4px;
}

.per-person-list {
  list-style: none;
  margin: 0 0 16px;
  padding: 0;
}

.person-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 14px 0;
  border-bottom: 1px solid var(--c-border);
}

.person-row:last-child {
  border-bottom: none;
}

.person-name {
  font-weight: 500;
}

.person-amount {
  font-weight: 600;
  font-size: 1.0625rem;
  color: var(--c-primary);
}

.copy-feedback {
  text-align: center;
  color: var(--c-success);
  font-weight: 500;
  margin: 8px 0 0;
  font-size: 0.9375rem;
}

.modal {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.5);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  z-index: 100;
}

.modal-content {
  background: var(--c-surface);
  border-radius: var(--radius);
  padding: 20px;
  max-width: 360px;
  width: 100%;
  box-shadow: var(--shadow);
}

.modal-content p {
  margin: 0 0 16px;
}

.modal-content-wide {
  max-width: 480px;
}

.modal-title {
  margin: 0 0 16px;
  font-size: 1.125rem;
  font-weight: 600;
}

.modal-actions {
  display: flex;
  gap: 8px;
  justify-content: flex-end;
}

.modal-actions.vertical {
  flex-direction: column;
}

.receipts-list {
  list-style: none;
  margin: 0 0 16px;
  padding: 0;
  max-height: 50vh;
  overflow-y: auto;
}

.receipt-item {
  display: flex;
  align-items: stretch;
  gap: 6px;
  padding: 6px 0;
  border-bottom: 1px solid var(--c-border);
}

.receipt-item:last-child {
  border-bottom: none;
}

.receipt-item-info {
  flex: 1;
  display: block;
  text-align: left;
  background: transparent;
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  padding: 10px 12px;
  cursor: pointer;
  color: var(--c-text);
  font-family: inherit;
  min-width: 0;
  transition: all 0.15s ease;
}

.receipt-item-info:hover {
  background: var(--c-bg);
}

.receipt-item.active .receipt-item-info {
  background: var(--c-primary-soft);
  border-color: var(--c-primary);
}

.receipt-item-name {
  font-weight: 500;
  margin-bottom: 2px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.receipt-item-meta {
  font-size: 0.8125rem;
  color: var(--c-text-muted);
}

.receipts-empty {
  color: var(--c-text-muted);
  font-style: italic;
  font-size: 0.9375rem;
  text-align: center;
  margin: 16px 0;
}

.receipt-item-delete {
  background: transparent;
  border: 1px solid var(--c-border);
  border-radius: var(--radius-sm);
  width: 40px;
  cursor: pointer;
  color: var(--c-text-muted);
  font-size: 1rem;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: all 0.15s ease;
}

.receipt-item-delete:hover {
  background: var(--c-danger);
  color: white;
  border-color: var(--c-danger);
}
