/* Apple iOS–inspired theme */
:root {
  --ios-bg: #f2f2f7;
  --ios-bg-secondary: #ffffff;
  --ios-separator: rgba(60, 60, 67, 0.12);
  --ios-separator-strong: rgba(60, 60, 67, 0.29);
  --ios-blue: #007aff;
  --ios-blue-pressed: #0051d5;
  --ios-red: #ff3b30;
  --ios-green: #34c759;
  --ios-orange: #ff9500;
  --ios-label: #000000;
  --ios-label-secondary: rgba(60, 60, 67, 0.6);
  --ios-label-tertiary: rgba(60, 60, 67, 0.4);
  --ios-fill: rgba(120, 120, 128, 0.2);
  --ios-fill-secondary: rgba(120, 120, 128, 0.16);
  --ios-radius: 12px;
  --ios-radius-sm: 10px;
  --ios-nav-height: 44px;
  --ios-safe-top: env(safe-area-inset-top, 0);
  --ios-safe-bottom: env(safe-area-inset-bottom, 0);
}

/* Dark mode */
body.dark-mode {
  --ios-bg: #1c1c1e;
  --ios-bg-secondary: #2c2c2e;
  --ios-separator: rgba(84, 84, 88, 0.5);
  --ios-separator-strong: rgba(84, 84, 88, 0.65);
  --ios-label: #ffffff;
  --ios-label-secondary: rgba(235, 235, 245, 0.6);
  --ios-label-tertiary: rgba(235, 235, 245, 0.4);
  --ios-fill: rgba(120, 120, 128, 0.32);
  --ios-fill-secondary: rgba(120, 120, 128, 0.24);
}

body.dark-mode .nav-segmented-btn.is-active {
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.3);
}

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

body {
  margin: 0;
  min-height: 100vh;
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", "SF Pro Display", "Helvetica Neue", sans-serif;
  font-size: 17px;
  color: var(--ios-label);
  background: var(--ios-bg);
  -webkit-font-smoothing: antialiased;
}

/* Nav — iOS large-title–style bar */
.nav {
  background: var(--ios-bg-secondary);
  padding: 0.75rem 1rem;
  padding-top: calc(0.75rem + var(--ios-safe-top));
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 0.75rem;
  border-bottom: 1px solid var(--ios-separator);
  position: sticky;
  top: 0;
  z-index: 100;
}

.nav-brand {
  font-weight: 600;
  font-size: 1.25rem;
  color: var(--ios-label);
  text-decoration: none;
}

.nav-segmented {
  display: flex;
  align-items: center;
  gap: 0;
  padding: 0.25rem;
  background: var(--ios-fill);
  border-radius: var(--ios-radius-sm);
  flex-wrap: wrap;
}

.nav-segmented-btn {
  color: var(--ios-label-secondary);
  text-decoration: none;
  font-size: 0.875rem;
  font-weight: 500;
  padding: 0.45rem 0.75rem;
  border-radius: 6px;
  transition: background 0.2s ease, color 0.2s ease, box-shadow 0.2s ease;
}

.nav-segmented-btn:hover {
  color: var(--ios-label);
}

.nav-segmented-btn.is-active {
  background: var(--ios-bg-secondary);
  color: var(--ios-label);
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.06);
}

/* Hamburger — visible only on mobile */
.nav-hamburger {
  display: none;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 5px;
  width: 44px;
  height: 44px;
  padding: 0;
  border: none;
  background: transparent;
  color: var(--ios-label);
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  border-radius: var(--ios-radius-sm);
}

.nav-hamburger:hover {
  background: var(--ios-fill);
}

.nav-hamburger-bar {
  display: block;
  width: 22px;
  height: 2px;
  border-radius: 1px;
  background: currentColor;
  transition: transform 0.2s ease, opacity 0.2s ease;
}

@media (max-width: 767px) {
  .nav-hamburger {
    display: flex;
    margin-left: auto;
  }
  .nav-segmented {
    display: none;
  }
}

@media (min-width: 768px) {
  .nav-drawer,
  .nav-drawer-backdrop {
    display: none !important;
  }
}

/* Side drawer — mobile only */
.nav-drawer-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.35);
  z-index: 199;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease;
}

body.nav-drawer-open .nav-drawer-backdrop {
  opacity: 1;
  pointer-events: auto;
}

.nav-drawer {
  position: fixed;
  top: 0;
  left: 0;
  width: 260px;
  max-width: 82vw;
  height: 100%;
  height: 100dvh;
  background: var(--ios-bg-secondary);
  z-index: 200;
  transform: translateX(-100%);
  transition: transform 0.25s ease-out;
  display: flex;
  flex-direction: column;
  padding-top: calc(0.75rem + var(--ios-safe-top));
  box-shadow: 8px 0 32px rgba(0, 0, 0, 0.12);
}

body.nav-drawer-open .nav-drawer {
  transform: translateX(0);
}

.nav-drawer-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.75rem 1rem 1rem;
  border-bottom: 1px solid var(--ios-separator);
}

.nav-drawer-title {
  font-size: 0.9375rem;
  font-weight: 600;
  color: var(--ios-label-secondary);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.nav-drawer-close {
  padding: 0.5rem 0.5rem 0.5rem 0.75rem;
  min-height: 36px;
  min-width: 36px;
  border: none;
  background: transparent;
  color: var(--ios-blue);
  font-size: 0.9375rem;
  font-weight: 500;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  border-radius: 8px;
}

.nav-drawer-close:hover {
  background: var(--ios-fill);
}

.nav-drawer-links {
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: 0.75rem 0.75rem 1.5rem;
}

.nav-drawer-link {
  display: block;
  padding: 0.875rem 1rem;
  font-size: 1rem;
  font-weight: 500;
  color: var(--ios-label);
  text-decoration: none;
  border-radius: 10px;
  transition: background 0.15s ease, color 0.15s ease;
  -webkit-tap-highlight-color: transparent;
}

.nav-drawer-link:hover {
  background: var(--ios-fill);
  color: var(--ios-label);
}

.nav-drawer-link:active {
  background: var(--ios-fill-secondary);
}

.nav-drawer-link.is-active {
  background: rgba(0, 122, 255, 0.12);
  color: var(--ios-blue);
}

.nav-user {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
}

.nav-avatar,
.nav-avatar-placeholder {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  object-fit: cover;
}

.nav-avatar-placeholder {
  background: var(--ios-fill);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--ios-label-secondary);
}

.nav-logout button {
  background: transparent;
  border: none;
  color: var(--ios-blue);
  padding: 0.35rem 0.75rem;
  border-radius: var(--ios-radius-sm);
  cursor: pointer;
  font-size: 0.9rem;
}

.nav-logout button:hover {
  background: var(--ios-fill);
}

/* Main content */
.container {
  max-width: 680px;
  margin: 0 auto;
  padding: 1rem 1rem calc(1rem + var(--ios-safe-bottom));
}

.site-footer {
  text-align: center;
  padding: 1.5rem 1rem calc(1.5rem + var(--ios-safe-bottom));
}

.site-footer-text {
  margin: 0;
  font-size: 0.8125rem;
  color: var(--ios-label-tertiary);
}

.page-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 1rem;
  margin-bottom: 1.25rem;
}

.page-header h1 {
  margin: 0;
  font-size: 1.75rem;
  font-weight: 700;
  letter-spacing: -0.02em;
}

.page-header-actions {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  flex-wrap: wrap;
}

@media (max-width: 767px) {
  .page-header-actions {
    width: 100%;
  }
  .add-expense-btn {
    flex: 1;
    min-width: 0;
    padding: 0.75rem 1.5rem;
    font-size: 1rem;
  }
}

.page-filters-wrap {
  margin-bottom: 1rem;
}

.page-filters-wrap.is-hidden {
  display: none;
}

.filter-toggle-btn {
  flex-shrink: 0;
}

/* Cards — iOS grouped list */
.card {
  background: var(--ios-bg-secondary);
  border-radius: var(--ios-radius);
  margin-bottom: 1.5rem;
  overflow: visible;
  border: none;
  box-shadow: none;
  padding: 0;
}

.card h2 {
  margin: 0;
  padding: 1rem 1.25rem 0.5rem;
  font-size: 1.125rem;
  font-weight: 600;
  color: var(--ios-label);
}

.card .form-card,
.card .dashboard-filter,
.card .avatar-form,
.card.owing-new-form {
  padding: 0;
}

.card .form-card .field:last-child,
.card .form-card button {
  margin-bottom: 0;
}

/* New owing form — clean card layout, full width */
.owing-new-form .owing-new-form-inner {
  padding: 1.5rem 1.25rem;
  width: 100%;
  max-width: 100%;
  box-sizing: border-box;
}

.owing-new-form .field {
  margin-bottom: 1.5rem;
}

.owing-new-form .field:last-of-type {
  margin-bottom: 1.25rem;
}

.owing-new-form .field-who-owes .field-hint-block {
  margin: 0.25rem 0 0.75rem;
  font-size: 0.8125rem;
  color: var(--ios-label-secondary);
  line-height: 1.35;
}

.owing-new-form .multi-select-row {
  display: flex;
  align-items: stretch;
  gap: 0.5rem;
  flex-wrap: wrap;
  width: 100%;
}

.owing-new-form .multi-select-row select {
  flex: 1 1 auto;
  min-width: 0;
  width: 100%;
  max-width: 100%;
}

.owing-new-form .multi-select-row .btn-add,
.owing-new-form .multi-select-row .btn-add-all,
.owing-new-form .multi-select-row .dropdown-dots,
.owing-new-form .multi-select-row .dropdown-more-options {
  flex-shrink: 0;
  align-self: center;
}

.owing-new-form .multi-select-row .btn-add-all:disabled {
  opacity: 0.6;
  cursor: not-allowed;
}

.owing-new-form .chips-wrap {
  margin-top: 0.75rem;
  min-height: 44px;
  width: 100%;
}

.owing-new-form .chips-box {
  border: 1px solid var(--ios-separator);
  border-radius: var(--ios-radius-sm);
  background: var(--ios-fill);
  padding: 0.75rem 1rem;
  min-height: 52px;
  width: 100%;
  box-sizing: border-box;
}

.owing-new-form .chips {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  align-items: center;
  min-height: 2rem;
}

.owing-new-form .input-with-suffix {
  display: flex;
  align-items: center;
  border: 1px solid var(--ios-separator-strong);
  border-radius: var(--ios-radius-sm);
  background: var(--ios-bg-secondary);
  overflow: hidden;
}

.owing-new-form .input-with-suffix:focus-within {
  border-color: var(--ios-blue);
  box-shadow: 0 0 0 3px rgba(0, 122, 255, 0.2);
}

.owing-new-form .input-suffix {
  padding: 0 1rem;
  font-size: 1rem;
  color: var(--ios-label-secondary);
  flex-shrink: 0;
}

.owing-new-form .input-with-suffix input {
  flex: 1;
  min-width: 0;
  border: none;
  box-shadow: none;
  padding: 0.75rem 1rem 0.75rem 0.5rem;
  background: transparent;
}

.owing-new-form .input-with-suffix input:focus {
  box-shadow: none;
  outline: none;
}

.owing-new-form .label-optional {
  font-weight: 400;
  color: var(--ios-label-tertiary);
}

.owing-new-form .form-actions {
  margin-top: 1.5rem;
  padding-top: 0.25rem;
}

/* Add from receipt */
.receipt-card {
  padding: 1.5rem;
}

.receipt-card .receipt-card-title {
  margin: 0 0 0.5rem;
  padding: 0 0 0.5rem 0;
  font-size: 1.125rem;
  font-weight: 600;
  color: var(--ios-label);
}

.receipt-intro {
  margin: 0 0 1.5rem;
  font-size: 0.9375rem;
  line-height: 1.45;
  color: var(--ios-label-secondary);
}

.receipt-upload-form .receipt-field {
  margin-bottom: 0;
}

.receipt-file-label {
  display: block;
  margin-bottom: 0.5rem;
  cursor: pointer;
}

.receipt-file-label-text {
  display: block;
  font-size: 0.9375rem;
  font-weight: 500;
  color: var(--ios-label);
}

.receipt-file-hint {
  display: block;
  margin-top: 0.2rem;
  font-size: 0.8125rem;
  color: var(--ios-label-tertiary);
}

.receipt-file-input {
  display: block;
  width: 100%;
  min-height: 44px;
  margin-top: 0.5rem;
  padding: 0.75rem;
  font-size: 1rem;
  color: var(--ios-label);
  background: var(--ios-bg-secondary);
  border: 1px solid var(--ios-separator-strong);
  border-radius: var(--ios-radius-sm);
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}

.receipt-file-input::file-selector-button {
  margin-right: 0.75rem;
  padding: 0.5rem 0.75rem;
  min-height: 36px;
  font-size: 0.9375rem;
  font-weight: 500;
  color: var(--ios-blue);
  background: var(--ios-fill);
  border: none;
  border-radius: 6px;
  cursor: pointer;
}

@media (max-width: 480px) {
  .receipt-file-input {
    min-height: 48px;
    padding: 0.875rem 1rem;
    font-size: 16px; /* prevents iOS zoom on focus */
  }
  .receipt-file-input::file-selector-button {
    min-height: 44px;
    padding: 0.6rem 1rem;
    font-size: 1rem;
  }
}

.receipt-form-actions {
  margin-top: 1.5rem;
  padding-top: 1rem;
  border-top: 1px solid var(--ios-separator);
}

.receipt-fallback {
  margin: 1.25rem 0 0;
  padding-top: 1rem;
  font-size: 0.875rem;
  color: var(--ios-label-tertiary);
  border-top: 1px solid var(--ios-separator);
}

.receipt-fallback a {
  color: var(--ios-blue);
  text-decoration: none;
}

.receipt-fallback a:hover {
  text-decoration: underline;
}

.owing-new-form .btn-block {
  width: 100%;
  padding: 0.75rem 1.25rem;
  font-size: 1rem;
}

/* New owing step 2 — set amounts */
.owing-amount-receipt-preview {
  padding: 1.25rem 1.5rem;
  margin-bottom: 1rem;
}
.owing-amount-receipt-preview .owing-amount-receipt-preview-title {
  margin: 0 0 0.75rem;
  padding: 0;
  font-size: 0.9375rem;
  font-weight: 600;
  color: var(--ios-label);
}
.owing-amount-receipt-preview-trigger {
  display: block;
  padding: 0;
  margin: 0;
  border: none;
  background: none;
  cursor: pointer;
  width: 100%;
  text-align: left;
  -webkit-tap-highlight-color: transparent;
}
.owing-amount-receipt-preview-trigger:focus {
  outline: 2px solid var(--ios-blue);
  outline-offset: 2px;
  border-radius: var(--ios-radius-sm);
}
.owing-amount-receipt-preview-img {
  display: block;
  max-width: 100%;
  width: auto;
  max-height: 200px;
  height: auto;
  border-radius: var(--ios-radius-sm);
  border: 1px solid var(--ios-separator-strong);
  background: var(--ios-bg-secondary);
  pointer-events: none;
}
.owing-amount-receipt-preview-hint {
  margin: 0.5rem 0 0;
  font-size: 0.8125rem;
  color: var(--ios-label-tertiary);
}
.owing-amount-receipt-preview-change {
  margin: 0.75rem 0 0;
  font-size: 0.875rem;
}
.owing-amount-receipt-preview-change a {
  color: var(--ios-blue);
  text-decoration: none;
}
.owing-amount-receipt-preview-change a:hover {
  text-decoration: underline;
}

/* Receipt lightbox — full-size view */
.receipt-lightbox {
  position: fixed;
  inset: 0;
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
  box-sizing: border-box;
}
.receipt-lightbox[hidden] {
  display: none;
}
.receipt-lightbox-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.85);
  cursor: pointer;
}
.receipt-lightbox-close {
  position: absolute;
  top: 1rem;
  right: 1rem;
  z-index: 1002;
  width: 2.5rem;
  height: 2.5rem;
  padding: 0;
  border: none;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.2);
  color: #fff;
  font-size: 1.5rem;
  line-height: 1;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  -webkit-tap-highlight-color: transparent;
}
.receipt-lightbox-close:hover {
  background: rgba(255, 255, 255, 0.3);
}
.receipt-lightbox-close:focus {
  outline: 2px solid #fff;
  outline-offset: 2px;
}
.receipt-lightbox-img {
  position: relative;
  z-index: 1001;
  max-width: 100%;
  max-height: calc(100vh - 2rem);
  width: auto;
  height: auto;
  border-radius: var(--ios-radius-sm);
  box-shadow: 0 4px 24px rgba(0, 0, 0, 0.5);
  object-fit: contain;
}

.owing-amount-form .owing-amount-inner {
  padding: 1.5rem 1.25rem;
  max-width: 420px;
}

.owing-amount-summary {
  margin: 0 0 1.25rem;
  font-size: 0.9375rem;
  color: var(--ios-label-secondary);
}

.owing-amount-tabs {
  display: flex;
  gap: 0;
  margin-bottom: 1.25rem;
  padding: 0.25rem;
  background: var(--ios-fill);
  border-radius: var(--ios-radius-sm);
  width: fit-content;
}

.owing-amount-tab {
  padding: 0.5rem 1rem;
  font-size: 0.9375rem;
  font-weight: 500;
  border: none;
  border-radius: 6px;
  background: transparent;
  color: var(--ios-label-secondary);
  cursor: pointer;
  font-family: inherit;
  transition: background 0.2s ease, color 0.2s ease, box-shadow 0.2s ease;
}

.owing-amount-tab:hover {
  color: var(--ios-label);
}

.owing-amount-tab.is-active {
  background: var(--ios-bg-secondary);
  color: var(--ios-label);
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.06);
}

.owing-amount-panel {
  display: none;
  margin-bottom: 1rem;
}

.owing-amount-panel.is-active {
  display: block;
}

.owing-amount-form .field {
  margin-bottom: 1.25rem;
}

.owing-amount-form .input-with-suffix {
  display: flex;
  align-items: center;
  border: 1px solid var(--ios-separator-strong);
  border-radius: var(--ios-radius-sm);
  background: var(--ios-bg-secondary);
  overflow: hidden;
}

.owing-amount-form .input-with-suffix:focus-within {
  border-color: var(--ios-blue);
  box-shadow: 0 0 0 3px rgba(0, 122, 255, 0.2);
}

.owing-amount-form .input-suffix {
  padding: 0 1rem;
  font-size: 1rem;
  color: var(--ios-label-secondary);
}

.owing-amount-form .input-with-suffix input {
  flex: 1;
  min-width: 0;
  border: none;
  padding: 0.75rem 1rem 0.75rem 0.5rem;
  background: transparent;
}

.owing-amount-form .input-with-suffix input:focus {
  outline: none;
  box-shadow: none;
}

.custom-equal-row {
  display: flex;
  align-items: flex-end;
  gap: 0.75rem;
  margin-bottom: 1.25rem;
  flex-wrap: wrap;
}

.custom-equal-input-wrap {
  flex: 1;
  min-width: 140px;
}

.custom-equal-input-wrap label {
  display: block;
  font-size: 0.9rem;
  font-weight: 500;
  margin-bottom: 0.35rem;
}

.custom-equal-row .btn {
  flex-shrink: 0;
  margin-bottom: 0;
}

.owing-amount-per-person {
  margin-bottom: 1rem;
}

.owing-amount-form .form-actions {
  margin-top: 1.5rem;
}

.owing-amount-form .btn-block {
  width: 100%;
  padding: 0.75rem 1.25rem;
  font-size: 1rem;
}

.card > .empty {
  padding: 1.25rem;
}

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0.5rem 1.25rem;
  border-radius: var(--ios-radius-sm);
  font-size: 0.9375rem;
  font-weight: 600;
  cursor: pointer;
  border: none;
  text-decoration: none;
  text-align: center;
  -webkit-tap-highlight-color: transparent;
}

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

.btn-primary:hover {
  background: var(--ios-blue-pressed);
  color: #fff;
}

.btn-secondary {
  background: var(--ios-fill);
  color: var(--ios-blue);
}

.btn-secondary:hover {
  background: var(--ios-fill-secondary);
  color: var(--ios-blue-pressed);
}

.btn-sm {
  padding: 0.35rem 0.75rem;
  font-size: 0.875rem;
  font-weight: 500;
}

/* Loading state for buttons (instant feedback on submit) */
.btn.is-loading,
button.is-loading {
  pointer-events: none;
  cursor: wait;
  opacity: 0.85;
}

.btn.is-loading .btn-spinner,
button.is-loading .btn-spinner {
  display: inline-block;
  width: 1em;
  height: 1em;
  margin-right: 0.4em;
  vertical-align: -0.15em;
  border: 2px solid currentColor;
  border-right-color: transparent;
  border-radius: 50%;
  animation: btn-spin 0.6s linear infinite;
}

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

/* Forms */
.field {
  margin-bottom: 1.25rem;
}

.field label {
  display: block;
  font-weight: 400;
  margin-bottom: 0.35rem;
  font-size: 0.9375rem;
  color: var(--ios-label);
}

.field input[type="text"],
.field input[type="number"],
.field input[type="password"],
.field select {
  width: 100%;
  max-width: 100%;
  padding: 0.75rem 1rem;
  border: 1px solid var(--ios-separator-strong);
  border-radius: var(--ios-radius-sm);
  font-size: 1rem;
  font-family: inherit;
  background: var(--ios-bg-secondary);
  color: var(--ios-label);
}

.field input:focus,
.field select:focus {
  outline: none;
  border-color: var(--ios-blue);
  box-shadow: 0 0 0 3px rgba(0, 122, 255, 0.2);
}

.field small,
.field-hint {
  display: block;
  margin-top: 0.25rem;
  font-size: 0.8125rem;
  color: var(--ios-label-secondary);
}

.field-hint {
  font-weight: 400;
  display: inline;
  margin-top: 0;
  margin-left: 0.25rem;
}

.multi-select-wrap {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  flex-wrap: wrap;
}

.multi-select-wrap select {
  flex: 1;
  min-width: 160px;
  max-width: 240px;
}

.btn-add {
  flex-shrink: 0;
}

.chips {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin-top: 0.5rem;
  min-height: 2rem;
}

.chip {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  padding: 0.35rem 0.5rem 0.35rem 0.35rem;
  background: var(--ios-fill);
  border-radius: var(--ios-radius-sm);
  font-size: 0.9375rem;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}

.chip:hover {
  background: var(--ios-fill-secondary);
}

.chip-avatar-wrap {
  display: inline-flex;
  flex-shrink: 0;
}

.chip-avatar,
.chip-avatar-placeholder {
  width: 24px;
  height: 24px;
  border-radius: 50%;
  object-fit: cover;
  display: block;
}

.chip-avatar-placeholder {
  background: var(--ios-fill-secondary);
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--ios-label-secondary);
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.chip-remove {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 22px;
  height: 22px;
  padding: 0;
  border: none;
  background: var(--ios-fill-secondary);
  border-radius: 6px;
  font-size: 1.1rem;
  line-height: 1;
  cursor: pointer;
  color: var(--ios-label-secondary);
}

.chip-remove:hover {
  background: var(--ios-separator);
  color: var(--ios-label);
}

.form-card .btn,
.form-card button[type="submit"] {
  margin-top: 0.5rem;
}

/* Alerts — iOS style */
.alert {
  padding: 1rem 1.25rem;
  border-radius: var(--ios-radius-sm);
  margin-bottom: 1rem;
  font-size: 0.9375rem;
}

.alert-error {
  background: rgba(255, 59, 48, 0.12);
  color: #c62828;
}

.alert-success {
  background: rgba(52, 199, 89, 0.15);
  color: #248a3d;
}

.alert-warning {
  background: rgba(255, 149, 0, 0.15);
  color: #c93400;
}

/* Dashboard */
.dashboard-filter {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  flex-wrap: wrap;
}

.dashboard-filter .filter-label {
  margin: 0;
  font-weight: 400;
  font-size: 0.9375rem;
  color: var(--ios-label-secondary);
}

.dashboard-filter .person-filter-select {
  max-width: 200px;
  padding: 0.5rem 0.75rem;
  border: 1px solid var(--ios-separator-strong);
  border-radius: var(--ios-radius-sm);
  font-size: 0.9375rem;
  background: var(--ios-bg-secondary);
}

/* Card that is only the filter (no list) */
.card.dashboard-filter {
  padding: 1rem 1.25rem;
}

.dashboard-filter-row {
  flex-wrap: wrap;
  gap: 1rem 0.75rem;
}

.dashboard-filter-group {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  flex-wrap: wrap;
}

.dashboard-search-form {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  flex-wrap: wrap;
  flex: 1 1 auto;
  min-width: 0;
}

.dashboard-search-form .filter-search-input {
  min-width: 140px;
  max-width: 220px;
  padding: 0.5rem 0.75rem;
  border: 1px solid var(--ios-separator-strong);
  border-radius: var(--ios-radius-sm);
  font-size: 0.9375rem;
  background: var(--ios-bg-secondary);
  color: var(--ios-label);
}

.dashboard-search-form .filter-search-input::placeholder {
  color: var(--ios-label-tertiary);
}

/* Dashboard toolbar — segment (All / Owed to me / Owing) + sort */
.dashboard-toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 1rem 1.25rem;
  padding: 1rem 1.25rem;
}

.dashboard-segment-wrap {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  flex-wrap: wrap;
}

.dashboard-segment-label,
.dashboard-sort-label {
  margin: 0;
  font-size: 0.9375rem;
  font-weight: 400;
  color: var(--ios-label-secondary);
}

.dashboard-segment {
  display: flex;
  align-items: center;
  padding: 0.25rem;
  background: var(--ios-fill);
  border-radius: var(--ios-radius-sm);
}

.dashboard-segment-btn {
  color: var(--ios-label-secondary);
  text-decoration: none;
  font-size: 0.8125rem;
  font-weight: 500;
  padding: 0.4rem 0.65rem;
  border-radius: 6px;
  transition: background 0.2s ease, color 0.2s ease, box-shadow 0.2s ease;
}

.dashboard-segment-btn:hover {
  color: var(--ios-label);
}

.dashboard-segment-btn.is-active {
  background: var(--ios-bg-secondary);
  color: var(--ios-label);
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.06);
}

.dashboard-sort-wrap {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.dashboard-sort-select {
  padding: 0.4rem 0.65rem;
  font-size: 0.875rem;
  border: 1px solid var(--ios-separator-strong);
  border-radius: var(--ios-radius-sm);
  background: var(--ios-bg-secondary);
  color: var(--ios-label);
}

/* Owing list — iOS grouped rows */
.owing-list {
  list-style: none;
  padding: 0;
  margin: 0;
}

.owing-item {
  padding: 0.875rem 1.25rem;
  border-bottom: 1px solid var(--ios-separator);
}

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

.owing-item.settled {
  opacity: 0.7;
}

.owing-item-content {
  display: flex;
  align-items: flex-start;
  gap: 0.75rem;
  width: 100%;
  min-width: 0;
}

@media (max-width: 767px) {
  .owing-item {
    padding: 1rem 1rem;
  }

  .owing-item-content {
    flex-direction: column;
    align-items: stretch;
    gap: 0.75rem;
  }

  .owing-item-link {
    min-width: 0;
  }

  .owing-actions-row {
    flex-direction: row;
    align-items: center;
    width: 100%;
    justify-content: flex-start;
    margin-top: 0.25rem;
    padding-top: 0.5rem;
    border-top: 1px solid var(--ios-separator);
  }

  .owing-actions-row .dropdown-actions {
    display: inline-block;
  }

  .owing-actions-row .dropdown-actions summary,
  .owing-actions-row .btn-actions-trigger {
    width: auto;
  }
}

.owing-item-link {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
  text-decoration: none;
  color: inherit;
  cursor: pointer;
}

.owing-item-link:hover {
  color: inherit;
}

.owing-item-row {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  min-width: 0;
}

.owing-who {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  min-width: 0;
  flex: 1;
}

.owing-who-text {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.owing-avatars {
  display: flex;
  align-items: center;
  flex-shrink: 0;
}

.owing-avatars .avatar,
.owing-avatars .avatar-placeholder {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  object-fit: cover;
  display: block;
}

.owing-avatars .avatar-placeholder {
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.875rem;
  font-weight: 600;
  background: var(--ios-fill);
  color: var(--ios-label-secondary);
}

.owing-avatars .avatar:last-child,
.owing-avatars .avatar-placeholder:last-child {
  margin-left: -8px;
}

.owing-amount {
  font-weight: 600;
  font-size: 1.375rem;
  color: var(--ios-label);
  flex-shrink: 0;
}

.owing-desc {
  font-size: 0.8125rem;
  color: var(--ios-label-secondary);
  margin: 0;
  line-height: 1.35;
}

.owing-meta {
  font-size: 0.8125rem;
  color: var(--ios-label-secondary);
  margin: 0;
}

.owing-settle {
  margin: 0;
}

.owing-actions-row {
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: 0.5rem;
  margin: 0;
  flex-shrink: 0;
  min-width: 0;
}

.owing-actions-row .dropdown-actions {
  display: block;
}

.owing-actions-row .dropdown-actions summary,
.owing-actions-row .btn-actions-trigger {
  width: 100%;
  justify-content: center;
  box-sizing: border-box;
}

.owing-actions-wrap {
  margin: 0;
}

.dropdown-actions {
  position: relative;
  display: inline-block;
}

.dropdown-actions summary {
  list-style: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.35rem;
}

.dropdown-actions summary::-webkit-details-marker {
  display: none;
}

.dropdown-actions summary::after {
  content: '';
  width: 0;
  height: 0;
  border-left: 5px solid transparent;
  border-right: 5px solid transparent;
  border-top: 5px solid currentColor;
  margin-left: 0.25rem;
  flex-shrink: 0;
}

.dropdown-actions[open] summary::after {
  transform: rotate(180deg);
}

.btn-actions-trigger {
  background: var(--ios-fill);
  color: var(--ios-blue);
}

.btn-actions-trigger:hover {
  background: var(--ios-fill-secondary);
}

.dropdown-dots summary::after {
  display: none;
}

.owing-new-form .btn-dots {
  min-width: 2.25rem;
  padding: 0.4rem 0.5rem;
  font-size: 1.1rem;
  line-height: 1;
  background: var(--ios-fill);
  color: var(--ios-label-secondary);
  border: none;
  border-radius: var(--ios-radius-sm);
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}

.owing-new-form .btn-dots:hover {
  background: var(--ios-fill-secondary);
  color: var(--ios-label);
}

.dropdown-actions .dropdown-menu {
  position: absolute;
  top: 100%;
  left: 0;
  margin-top: 0.25rem;
  min-width: 180px;
  background: var(--ios-bg-secondary);
  border: 1px solid var(--ios-separator);
  border-radius: var(--ios-radius-sm);
  box-shadow: 0 4px 24px rgba(0, 0, 0, 0.12);
  padding: 0.25rem 0;
  z-index: 1000;
}

/* Settings people list: menu overhangs to the left */
.people-list-card .dropdown-actions .dropdown-menu {
  left: auto;
  right: 0;
}

.dropdown-item,
.dropdown-form .dropdown-item {
  display: block;
  width: 100%;
  padding: 0.625rem 1rem;
  text-align: left;
  background: none;
  border: none;
  border-radius: 0;
  font-size: 0.9375rem;
  cursor: pointer;
  color: var(--ios-blue);
  text-decoration: none;
}

.dropdown-item:hover,
.dropdown-form .dropdown-item:hover {
  background: var(--ios-fill);
}

.dropdown-item:disabled {
  opacity: 0.5;
  cursor: not-allowed;
  color: var(--ios-label-tertiary);
}

.dropdown-item-danger {
  color: var(--ios-red);
}

.dropdown-item-danger:hover {
  background: rgba(255, 59, 48, 0.1);
}

.dropdown-form {
  margin: 0;
}

.dropdown-form .dropdown-item {
  font-family: inherit;
}

.owing-meta {
  font-size: 0.8125rem;
  color: var(--ios-label-secondary);
}

/* Owing edit page */
.owing-edit-card {
  padding: 1.5rem 1.25rem;
}

.owing-edit-summary-wrap {
  padding-bottom: 1.25rem;
  margin-bottom: 1.25rem;
  border-bottom: 1px solid var(--ios-separator);
}

.owing-edit-summary {
  margin: 0;
  font-size: 1.0625rem;
  color: var(--ios-label);
  line-height: 1.4;
}

.owing-edit-form .field {
  margin-bottom: 1.25rem;
}

.owing-edit-form .field:last-of-type {
  margin-bottom: 0;
}

.owing-edit-actions {
  margin-top: 1.5rem;
  padding-top: 1.25rem;
  border-top: 1px solid var(--ios-separator);
}

.owing-edit-actions .btn {
  min-width: 140px;
}

/* Owing detail view */
.owing-detail-card {
  padding: 1.5rem 1.25rem;
}

.owing-detail-main {
  margin-bottom: 1.25rem;
}

.owing-detail-avatars {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin-bottom: 0.875rem;
}

.owing-detail-avatars .avatar,
.owing-detail-avatars .avatar-placeholder {
  width: 48px;
  height: 48px;
  border-radius: 50%;
  object-fit: cover;
}

.owing-detail-avatars .avatar-placeholder {
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.25rem;
  font-weight: 600;
  background: var(--ios-fill);
  color: var(--ios-label-secondary);
}

.owing-detail-who {
  margin: 0 0 0.25rem;
  font-size: 1.125rem;
}

.owing-detail-amount {
  margin: 0 0 0.25rem;
  font-size: 1.5rem;
  font-weight: 600;
  color: var(--ios-label);
}

.owing-detail-desc {
  margin: 0.5rem 0 0.25rem;
  font-size: 0.9375rem;
  color: var(--ios-label-secondary);
}

.owing-detail-meta,
.owing-detail-status {
  margin: 0.25rem 0 0;
  font-size: 0.8125rem;
  color: var(--ios-label-secondary);
}

.owing-detail-status-settled { color: var(--ios-green, #34c759); }
.owing-detail-status-deleted { color: var(--ios-label-tertiary); }
.owing-detail-status-outstanding { color: var(--ios-blue); }

.owing-detail-receipt-wrap {
  margin-top: 1rem;
  padding-top: 1rem;
  border-top: 1px solid var(--ios-separator);
}
.owing-detail-receipt-label {
  margin: 0 0 0.5rem;
  font-size: 0.8125rem;
  font-weight: 600;
  color: var(--ios-label-secondary);
}
.owing-detail-receipt-img {
  display: block;
  max-width: 100%;
  height: auto;
  max-height: 60vh;
  border-radius: var(--ios-radius-sm);
  border: 1px solid var(--ios-separator-strong);
  background: var(--ios-bg-secondary);
}

.owing-detail-actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.5rem;
  padding-top: 1.25rem;
  margin-top: 0;
  border-top: 1px solid var(--ios-separator);
}

.owing-detail-delete-form,
.owing-detail-inline-form {
  margin: 0;
  display: inline;
}

/* Activity section — timeline */
.owing-activity-card {
  padding: 0;
  overflow: hidden;
}

.owing-activity-title {
  margin: 0;
  padding: 1rem 1.25rem 0.75rem;
  font-size: 1.125rem;
  font-weight: 600;
  color: var(--ios-label);
}

.owing-history-list {
  list-style: none;
  padding: 0 1.25rem 1rem;
  margin: 0;
}

.owing-history-item {
  position: relative;
  padding: 0 0 1.25rem 1.5rem;
  font-size: 0.9375rem;
}

.owing-history-item:last-child {
  padding-bottom: 0.5rem;
}

.owing-history-item:last-child .owing-history-dot::after {
  display: none;
}

.owing-history-dot {
  position: absolute;
  left: 0;
  top: 0.4em;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--ios-blue);
}

.owing-history-dot::after {
  content: '';
  position: absolute;
  left: 3px;
  top: 12px;
  bottom: -1.25rem;
  width: 2px;
  background: var(--ios-separator);
}

.owing-history-content {
  margin: 0;
}

.owing-history-text {
  margin: 0 0 0.35rem;
  color: var(--ios-label);
  line-height: 1.45;
}

.owing-history-time {
  display: block;
  font-size: 0.8125rem;
  color: var(--ios-label-secondary);
}

.avatar,
.avatar-placeholder {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  object-fit: cover;
  flex-shrink: 0;
}

.avatar-placeholder {
  background: var(--ios-fill);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 1rem;
  font-weight: 600;
  color: var(--ios-label-secondary);
}

.badge {
  font-size: 0.75rem;
  padding: 0.2rem 0.5rem;
  border-radius: 6px;
  font-weight: 500;
}

.badge-success {
  background: rgba(52, 199, 89, 0.2);
  color: #248a3d;
}

.badge-pending {
  background: rgba(255, 149, 0, 0.2);
  color: #c93400;
}

.badge-receipt {
  background: rgba(0, 122, 255, 0.15);
  color: var(--ios-blue);
}

.empty {
  color: var(--ios-label-secondary);
  margin: 0;
  padding: 1rem;
  font-size: 0.9375rem;
}

.empty a {
  color: var(--ios-blue);
  text-decoration: none;
}

.empty a:hover {
  text-decoration: underline;
}

/* People list */
.people-list {
  list-style: none;
  padding: 0;
  margin: 0;
}

.people-list li {
  padding: 0.5rem 0;
  border-bottom: 1px solid var(--ios-separator);
}

.people-list li:last-child {
  border-bottom: none;
}

.people-list-rows {
  padding: 0;
}

.people-list-rows .people-row {
  display: flex;
  align-items: center;
  gap: 1rem;
  padding: 0.75rem 1.25rem;
  border-bottom: 1px solid var(--ios-separator);
  min-height: 56px;
}

.people-list-rows .people-row:last-child {
  border-bottom: none;
}

.people-list-card > .empty {
  padding: 1.25rem 1.25rem 1rem;
  margin: 0;
}

.people-row-avatar {
  flex-shrink: 0;
}

.people-row-avatar .avatar,
.people-row-avatar .avatar-placeholder {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  object-fit: cover;
}

.people-row-avatar .avatar-placeholder {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 1.125rem;
  font-weight: 600;
  background: var(--ios-fill);
  color: var(--ios-label-secondary);
}

.people-row-name {
  flex: 1;
  font-weight: 500;
  font-size: 1rem;
}

.people-row-actions {
  margin-left: auto;
  flex-shrink: 0;
}

/* People page — layout and add form */
.people-page {
  max-width: 560px;
}

.people-add-card .people-add-inner {
  padding: 0 1.25rem 1.25rem;
}

.people-add-form {
  margin: 0;
}

.people-add-row {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.people-add-input {
  flex: 1;
  min-width: 0;
  padding: 0.75rem 1rem;
  border: 1px solid var(--ios-separator-strong);
  border-radius: var(--ios-radius-sm);
  font-size: 1rem;
  font-family: inherit;
  background: var(--ios-bg-secondary);
  color: var(--ios-label);
}

.people-add-input::placeholder {
  color: var(--ios-label-tertiary);
}

.people-add-input:focus {
  outline: none;
  border-color: var(--ios-blue);
  box-shadow: 0 0 0 3px rgba(0, 122, 255, 0.2);
}

.people-add-row .btn {
  flex-shrink: 0;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

/* History list */
.history-list {
  list-style: none;
  padding: 0;
  margin: 0;
}

.history-item {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 0.75rem;
  padding: 0.875rem 1.25rem;
  border-bottom: 1px solid var(--ios-separator);
  min-height: 56px;
}

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

.history-direction {
  font-size: 0.875rem;
  color: var(--ios-label-secondary);
  min-width: 100px;
}

.history-who {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.history-amount {
  font-weight: 600;
  font-size: 1rem;
}

.history-desc {
  font-size: 0.875rem;
  color: var(--ios-label-secondary);
}

.history-date {
  font-size: 0.8125rem;
  color: var(--ios-label-secondary);
  margin-left: auto;
}

/* History tabs */
.history-tabs {
  margin-bottom: 0;
}

.history-tab-list {
  display: flex;
  gap: 0;
  margin-bottom: 1rem;
  padding: 0.25rem;
  background: var(--ios-fill);
  border-radius: var(--ios-radius-sm);
  width: fit-content;
}

.history-tab-btn {
  padding: 0.5rem 1.25rem;
  font-size: 0.9375rem;
  font-weight: 500;
  border: none;
  border-radius: 6px;
  background: transparent;
  color: var(--ios-label-secondary);
  cursor: pointer;
  font-family: inherit;
}

.history-tab-btn:hover {
  color: var(--ios-label);
}

.history-tab-btn.is-active {
  background: var(--ios-bg-secondary);
  color: var(--ios-label);
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.06);
}

.history-tab-panel {
  display: none;
}

.history-tab-panel.is-active {
  display: block;
}

.history-item-deleted .owing-meta-deleted {
  color: var(--ios-label-tertiary);
  font-size: 0.8125rem;
}

/* People edit name */
.people-edit-card .people-edit-inner {
  padding: 1.5rem 1.25rem;
  max-width: 400px;
}

.people-edit-form .field {
  margin-bottom: 1.25rem;
}

.people-edit-input {
  width: 100%;
  padding: 0.75rem 1rem;
  border: 1px solid var(--ios-separator-strong);
  border-radius: var(--ios-radius-sm);
  font-size: 1rem;
  font-family: inherit;
}

.people-edit-form .form-actions {
  margin-top: 1.25rem;
}

.people-edit-form .btn-block {
  width: 100%;
  padding: 0.75rem;
}

/* Profile / People photo */
.people-photo-card .people-photo-inner {
  padding: 1.25rem 1.25rem 1.5rem;
  max-width: 480px;
}

.people-photo-current {
  display: flex;
  align-items: center;
  gap: 1rem;
  margin-bottom: 1.5rem;
}

.people-photo-current .profile-avatar,
.people-photo-current .profile-avatar-placeholder {
  width: 64px;
  height: 64px;
  font-size: 1.5rem;
}

.people-photo-choose-wrap {
  margin-bottom: 1rem;
}

.people-photo-choose-wrap input[type="file"] {
  display: none;
}

.people-photo-crop-wrap {
  display: none;
  margin: 1rem 0;
  border-radius: var(--ios-radius-sm);
  overflow: hidden;
  background: var(--ios-bg);
}

.people-photo-crop-wrap.is-visible {
  display: block;
}

.people-photo-crop-hint {
  margin: 0 0 0.75rem;
  font-size: 0.875rem;
  color: var(--ios-label-secondary);
}

.people-photo-current-label {
  font-size: 0.9375rem;
  color: var(--ios-label-secondary);
}

.people-photo-crop-wrap .img-container {
  width: 100%;
  height: 320px;
  background: #000;
}

.people-photo-crop-wrap .img-container img {
  max-width: 100%;
  max-height: 100%;
  display: block;
}

.people-photo-crop-actions {
  display: flex;
  gap: 0.5rem;
  margin-top: 1rem;
  flex-wrap: wrap;
}

.people-photo-crop-actions .btn {
  flex: 1;
  min-width: 120px;
}

.profile-avatar-section {
  display: flex;
  align-items: center;
  gap: 1.5rem;
  flex-wrap: wrap;
}

.profile-avatar,
.profile-avatar-placeholder {
  width: 88px;
  height: 88px;
  border-radius: 50%;
  object-fit: cover;
}

.profile-avatar-placeholder {
  background: var(--ios-fill);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 2.25rem;
  font-weight: 600;
  color: var(--ios-label-secondary);
}

.avatar-form input[type="file"] {
  margin-right: 0.5rem;
  font-size: 0.9375rem;
}

.profile-note {
  font-size: 0.875rem;
  color: var(--ios-label-secondary);
  margin: 0.5rem 0 0;
}

/* Settings page */
.settings-card h2 {
  padding-bottom: 0.25rem;
}

.settings-list {
  list-style: none;
  padding: 0.25rem 1.25rem 0.75rem;
  margin: 0;
}

.settings-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.75rem 0;
  border-bottom: 1px solid var(--ios-separator);
  gap: 1rem;
  min-height: 44px;
}

.settings-row:last-child {
  border-bottom: none;
  padding-bottom: 0;
}

.settings-logout-form {
  margin: 0;
}

.settings-logout-form .btn-logout {
  color: var(--ios-red);
}

.settings-logout-form .btn-logout:hover {
  color: var(--ios-red);
  opacity: 0.9;
}

.settings-dev-card {
  padding: 1.25rem 1.5rem;
  border-left: 3px solid var(--ios-orange);
}
.settings-dev-card h2 {
  margin: 0 0 0.5rem;
  padding: 0 0 0.5rem 0;
  font-size: 1.125rem;
  font-weight: 600;
  color: var(--ios-label);
}
.settings-dev-intro {
  margin: 0 0 1rem;
  font-size: 0.9375rem;
  color: var(--ios-label-secondary);
}

.dev-tools-card {
  padding: 1.25rem 1.5rem;
  margin-bottom: 1.5rem;
}
.dev-tools-card h2 {
  margin: 0 0 0.5rem;
  padding: 0 0 0.5rem 0;
  font-size: 1.125rem;
  font-weight: 600;
  color: var(--ios-label);
}
.dev-tools-desc {
  margin: 0 0 1rem;
  font-size: 0.875rem;
  color: var(--ios-label-secondary);
  line-height: 1.4;
}
.dev-tools-form {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.75rem;
}
.dev-tools-form label {
  font-size: 0.9375rem;
  color: var(--ios-label);
}
.dev-tools-form select {
  padding: 0.5rem 0.75rem;
  font-size: 0.9375rem;
  border: 1px solid var(--ios-separator-strong);
  border-radius: var(--ios-radius-sm);
  background: var(--ios-bg-secondary);
  min-width: 180px;
}
.dev-btn-danger {
  color: var(--ios-red);
}
.dev-btn-danger:hover {
  opacity: 0.9;
}

.audit-log-wrap {
  max-height: 400px;
  overflow-y: auto;
  font-size: 0.8125rem;
}
.audit-log-list {
  list-style: none;
  padding: 0;
  margin: 0;
}
.audit-log-item {
  padding: 0.5rem 0;
  border-bottom: 1px solid var(--ios-separator);
  display: grid;
  grid-template-columns: auto 1fr auto;
  gap: 0.75rem;
  align-items: baseline;
  line-height: 1.35;
}
.audit-log-item:last-child {
  border-bottom: none;
}
.audit-log-action {
  font-weight: 600;
  color: var(--ios-label);
}
.audit-log-who {
  color: var(--ios-label-secondary);
}
.audit-log-time {
  color: var(--ios-label-tertiary);
  white-space: nowrap;
}
.audit-log-details {
  grid-column: 1 / -1;
  font-family: ui-monospace, monospace;
  font-size: 0.75rem;
  color: var(--ios-label-tertiary);
  word-break: break-all;
}

.settings-label {
  font-size: 0.9375rem;
  color: var(--ios-label);
  font-weight: 400;
}

.settings-toggle {
  flex-shrink: 0;
  padding: 0;
  border: none;
  background: none;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}

.settings-toggle-track {
  display: flex;
  width: 51px;
  height: 31px;
  border-radius: 31px;
  background: var(--ios-fill);
  align-items: center;
  padding: 2px;
  transition: background 0.2s ease;
}

.settings-toggle.is-on .settings-toggle-track {
  background: var(--ios-blue);
}

.settings-toggle-thumb {
  width: 27px;
  height: 27px;
  border-radius: 50%;
  background: var(--ios-bg-secondary);
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);
  transition: transform 0.2s ease;
}

.settings-toggle.is-on .settings-toggle-thumb {
  transform: translateX(20px);
}

/* Tutorial page */
.tutorial-card {
  padding: 0 0 1.5rem 0;
  max-width: 42rem;
}

.tutorial-card .tutorial-card-title {
  margin: 0;
  padding: 1.25rem 1.5rem 0.5rem;
  font-size: 1.125rem;
  font-weight: 600;
  color: var(--ios-label);
}

.tutorial-intro {
  margin: 0 1.5rem 1.25rem;
  font-size: 0.9375rem;
  line-height: 1.55;
  color: var(--ios-label-secondary);
}

.tutorial-tip {
  margin: 1.25rem 1.5rem 2rem;
  padding: 0.875rem 1rem;
  font-size: 0.875rem;
  line-height: 1.5;
  background: rgba(0, 122, 255, 0.08);
  border-radius: var(--ios-radius-sm);
  color: var(--ios-label);
}

.tutorial-steps {
  margin: 0;
  padding: 0 1.5rem 1.5rem;
  list-style: none;
  counter-reset: tutorial-step;
}

.tutorial-step {
  counter-increment: tutorial-step;
  padding: 1rem 0 1rem 3.25rem;
  position: relative;
  border-bottom: 1px solid var(--ios-separator);
  min-height: 2.5rem;
}

.tutorial-step:last-child {
  border-bottom: none;
  padding-bottom: 0;
}

.tutorial-step:first-child {
  padding-top: 0.5rem;
}

.tutorial-step::before {
  content: counter(tutorial-step);
  position: absolute;
  left: 0;
  top: 1rem;
  width: 1.75rem;
  height: 1.75rem;
  border-radius: 50%;
  background: var(--ios-blue);
  color: #fff;
  font-size: 0.8125rem;
  font-weight: 600;
  text-align: center;
  line-height: 1.75rem;
  flex-shrink: 0;
}

.tutorial-step-title {
  display: block;
  font-weight: 600;
  font-size: 1rem;
  color: var(--ios-label);
  margin-bottom: 0.25rem;
}

.tutorial-step-desc {
  margin: 0;
  font-size: 0.9375rem;
  line-height: 1.55;
  color: var(--ios-label-secondary);
}

.tutorial-step-desc a {
  color: var(--ios-blue);
  text-decoration: none;
}

.tutorial-step-desc a:hover {
  text-decoration: underline;
}

/* Tutorial popup (first-time users on dashboard) */
.tutorial-popup-overlay {
  position: fixed;
  inset: 0;
  z-index: 300;
  background: rgba(0, 0, 0, 0.45);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.25s ease, visibility 0.25s ease;
}

.tutorial-popup-overlay.is-visible {
  opacity: 1;
  visibility: visible;
}

.tutorial-popup {
  background: var(--ios-bg-secondary);
  border-radius: var(--ios-radius);
  max-width: 24rem;
  width: 100%;
  max-height: 90vh;
  display: flex;
  flex-direction: column;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.2);
  overflow: hidden;
}

.tutorial-popup-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 0.5rem;
  padding: 1.25rem 1.25rem 0.5rem;
  flex-shrink: 0;
}

.tutorial-popup-title {
  margin: 0;
  font-size: 1.25rem;
  font-weight: 700;
  color: var(--ios-label);
}

.tutorial-popup-close {
  flex-shrink: 0;
  width: 2rem;
  height: 2rem;
  padding: 0;
  border: none;
  background: var(--ios-fill);
  color: var(--ios-label);
  font-size: 1.5rem;
  line-height: 1;
  border-radius: var(--ios-radius-sm);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  -webkit-tap-highlight-color: transparent;
}

.tutorial-popup-close:hover {
  background: var(--ios-fill-secondary);
}

.tutorial-popup-intro {
  margin: 0 1.25rem 0.75rem;
  font-size: 0.8125rem;
  color: var(--ios-label-tertiary);
}

.tutorial-popup-nav-wrap {
  display: flex;
  align-items: stretch;
  flex: 1;
  min-height: 0;
}

.tutorial-popup-arrow {
  display: none;
  flex-shrink: 0;
  width: 2.5rem;
  padding: 0;
  border: none;
  background: var(--ios-fill);
  color: var(--ios-label);
  font-size: 1.5rem;
  line-height: 1;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  transition: background 0.2s ease;
}

.tutorial-popup-arrow:hover {
  background: var(--ios-fill-secondary);
}

@media (min-width: 768px) {
  .tutorial-popup-arrow {
    display: flex;
    align-items: center;
    justify-content: center;
  }
}

.tutorial-popup-track {
  flex: 1;
  min-width: 0;
  display: flex;
  overflow-x: auto;
  overflow-y: hidden;
  scroll-snap-type: x mandatory;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
}

.tutorial-popup-track::-webkit-scrollbar {
  display: none;
}

.tutorial-popup-slide {
  flex: 0 0 100%;
  scroll-snap-align: start;
  scroll-snap-stop: always;
  padding: 0 1.25rem 1rem;
  min-height: 8rem;
  overflow-y: auto;
}

.tutorial-popup-slide-title {
  margin: 0 0 0.5rem;
  font-size: 1rem;
  font-weight: 600;
  color: var(--ios-label);
}

.tutorial-popup-slide-desc {
  margin: 0;
  font-size: 0.9375rem;
  line-height: 1.5;
  color: var(--ios-label-secondary);
}

.tutorial-popup-slide-desc a {
  color: var(--ios-blue);
  text-decoration: none;
}

.tutorial-popup-slide-desc a:hover {
  text-decoration: underline;
}

.tutorial-popup-footer {
  padding: 1rem 1.25rem 1.25rem;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1rem;
  flex-shrink: 0;
  border-top: 1px solid var(--ios-separator);
}

.tutorial-popup-dots {
  display: flex;
  gap: 0.5rem;
  align-items: center;
  justify-content: center;
}

.tutorial-popup-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--ios-fill);
  transition: background 0.2s ease, transform 0.2s ease;
}

.tutorial-popup-dot.is-active {
  background: var(--ios-blue);
  transform: scale(1.2);
}

.tutorial-popup-gotit {
  width: 100%;
  max-width: 12rem;
}

/* Auth pages */
.auth-page {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 2rem;
  background: var(--ios-bg);
}

.auth-page h1 {
  margin: 0 0 0.25rem;
  font-size: 1.75rem;
  font-weight: 700;
}

.auth-tagline {
  margin: 0 0 1.5rem;
  color: var(--ios-label-secondary);
  font-size: 0.9375rem;
}

.auth-form {
  width: 100%;
  max-width: 320px;
  margin-bottom: 1rem;
}

.auth-form h2 {
  margin: 0 0 1rem;
  font-size: 1.1rem;
  font-weight: 600;
}

.auth-switch {
  margin: 0;
  font-size: 0.9375rem;
  color: var(--ios-label-secondary);
}

.auth-switch a {
  color: var(--ios-blue);
  font-weight: 500;
  text-decoration: none;
}

/* Error page */
body:has(.error-page) {
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--ios-bg);
}

main.error-page {
  text-align: center;
  padding: 2rem;
}

.error-page h1 {
  margin: 0 0 0.5rem;
  font-weight: 700;
}

.error-page p {
  margin: 0;
  color: var(--ios-label-secondary);
}

.error-page a {
  display: inline-block;
  margin-top: 1rem;
  color: var(--ios-blue);
  text-decoration: none;
  font-weight: 500;
}

.error-page a:hover {
  text-decoration: underline;
}

/* Login overlay when not logged in */
.main-blurred {
  filter: blur(6px);
  pointer-events: none;
  user-select: none;
}

.login-overlay {
  position: fixed;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 1.5rem;
  padding: 2rem;
  z-index: 90;
  background: rgba(242, 242, 247, 0.85);
}

body.dark-mode .login-overlay {
  background: rgba(28, 28, 30, 0.9);
}

.login-overlay-message {
  margin: 0;
  font-size: 1.25rem;
  font-weight: 500;
  color: var(--ios-label);
  text-align: center;
}

/* Login / Register — person list & PIN pad */
.login-person-list {
  list-style: none;
  padding: 0;
  margin: 0 0 1rem;
}

.login-person-list li {
  margin: 0;
  border-bottom: 1px solid var(--ios-separator);
}

.login-person-list li:last-child {
  border-bottom: none;
}

.login-person-link {
  display: flex;
  align-items: center;
  gap: 1rem;
  padding: 0.875rem 1rem;
  color: var(--ios-label);
  text-decoration: none;
  transition: background 0.15s ease;
  -webkit-tap-highlight-color: transparent;
}

.login-person-link:hover {
  background: var(--ios-fill);
}

.login-person-name {
  flex: 1;
  font-size: 1.0625rem;
  font-weight: 500;
}

.login-person-chevron {
  font-size: 1.25rem;
  color: var(--ios-label-tertiary);
}

.login-register-prompt {
  margin: 0;
  padding: 1rem 1.25rem 1.25rem;
  border-top: 1px solid var(--ios-separator);
  font-size: 0.9375rem;
  color: var(--ios-label-secondary);
  text-align: center;
}

.login-register-prompt a {
  display: inline-block;
  margin-top: 0.5rem;
  padding: 0.625rem 1.25rem;
  color: var(--ios-blue);
  text-decoration: none;
  font-weight: 500;
  border-radius: var(--ios-radius-sm);
  background: var(--ios-fill);
  transition: background 0.15s ease;
}

.login-register-prompt a:hover {
  background: var(--ios-fill-secondary);
}

/* PIN / Create account cards — lock-screen style */
.pin-card {
  max-width: 360px;
  margin: 0 auto 2rem;
  padding: 0 0 1.5rem;
}

.pin-card-person {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.5rem;
  padding: 1.5rem 1.25rem 0.5rem;
}

.pin-card-avatar {
  width: 64px;
  height: 64px;
  border-radius: 50%;
  object-fit: cover;
}

.pin-card-avatar-placeholder {
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--ios-fill);
  font-size: 1.5rem;
  font-weight: 600;
  color: var(--ios-label-secondary);
}

.pin-card-person-name {
  font-size: 1.125rem;
  font-weight: 600;
  color: var(--ios-label);
}

.pin-card h2 {
  margin: 0;
  padding: 1.25rem 1.25rem 0.25rem;
  font-size: 1.25rem;
  font-weight: 600;
  color: var(--ios-label);
  text-align: center;
}

.pin-section-divider {
  height: 1px;
  background: var(--ios-separator);
  margin: 1rem 0 0.5rem;
}

.pin-hint {
  margin: 0 0 1.5rem;
  padding: 0 1.25rem;
  font-size: 0.9375rem;
  color: var(--ios-label-secondary);
  text-align: center;
  line-height: 1.4;
}

.pin-form,
.register-form {
  padding: 0 1.25rem;
}

.register-form .field {
  margin-bottom: 1.5rem;
}

.register-form .field label {
  font-size: 0.9375rem;
  color: var(--ios-label-secondary);
}

.register-form .field input[type="text"] {
  padding: 0.875rem 1rem;
  font-size: 1.0625rem;
  border-radius: var(--ios-radius-sm);
  border: 1px solid var(--ios-separator-strong);
}

.register-form .field input[type="text"]:focus {
  border-color: var(--ios-blue);
  outline: none;
  box-shadow: 0 0 0 3px rgba(0, 122, 255, 0.2);
}

.pin-dots-wrap {
  margin: 1.5rem 0 1rem;
  padding: 1rem 0;
}

.pin-dots-label {
  display: block;
  margin-bottom: 0.75rem;
  font-size: 0.9375rem;
  font-weight: 500;
  color: var(--ios-label-secondary);
  text-align: center;
}

.pin-dots {
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 1rem;
  margin-bottom: 1.5rem;
}

.pin-dot {
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: var(--ios-separator);
  transition: background 0.2s ease, transform 0.15s ease;
}

.pin-dot[data-filled="1"] {
  background: var(--ios-label);
  transform: scale(1.1);
}

body.dark-mode .pin-dot[data-filled="1"] {
  background: var(--ios-label);
}

.pin-numpad {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 1rem;
  max-width: 280px;
  margin: 0 auto 1.75rem;
  justify-items: center;
}

.pin-key {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 64px;
  height: 64px;
  min-width: 64px;
  min-height: 64px;
  border: none;
  border-radius: 50%;
  background: var(--ios-fill);
  color: var(--ios-label);
  font-size: 1.625rem;
  font-weight: 400;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  transition: background 0.15s ease, transform 0.08s ease;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.06);
}

body.dark-mode .pin-key {
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.2);
}

.pin-key:hover {
  background: var(--ios-fill-secondary);
}

.pin-key:active {
  transform: scale(0.94);
}

.pin-key-empty {
  background: transparent;
  cursor: default;
  pointer-events: none;
  box-shadow: none;
}

.pin-key-delete {
  font-size: 1.375rem;
  font-weight: 500;
}

.pin-loading {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.75rem;
  margin-top: 1.25rem;
  padding: 0.75rem 0;
}

.pin-loading-spinner {
  width: 24px;
  height: 24px;
  border: 2px solid var(--ios-fill);
  border-top-color: var(--ios-blue);
  border-radius: 50%;
  animation: pin-spin 0.7s linear infinite;
}

.pin-loading-text {
  font-size: 0.9375rem;
  font-weight: 500;
  color: var(--ios-label-secondary);
}

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

.pin-form .pin-submit,
.register-form .pin-submit {
  margin-top: 0.25rem;
  padding: 0.875rem 1.25rem;
  font-size: 1.0625rem;
  font-weight: 600;
  border-radius: var(--ios-radius-sm);
}

.nav-drawer-logout {
  margin: 0;
  padding: 0;
}

.nav-drawer-link-logout {
  background: none;
  border: none;
  width: 100%;
  text-align: left;
  font-family: inherit;
  font-size: 1rem;
  font-weight: 500;
  cursor: pointer;
  color: var(--ios-label);
  border-radius: 10px;
}

.nav-drawer-link-logout:hover {
  background: rgba(255, 59, 48, 0.1);
  color: var(--ios-red);
}
