/* ─── Design Tokens ─────────────────────────────────────────────────────── */
:root {
  /* iOS system colors */
  --bg:            #F2F2F7;
  --bg-2:          #FFFFFF;
  --surface:       #FFFFFF;
  --surface-2:     rgba(118,118,128,.12);
  --primary:       #007AFF;
  --primary-tint:  rgba(0,122,255,.12);
  --destructive:   #FF3B30;
  --text:          #000000;
  --text-2:        rgba(60,60,67,.6);
  --text-3:        rgba(60,60,67,.3);
  --separator:     rgba(60,60,67,.29);
  --separator-thin:rgba(60,60,67,.18);
  --green:         #34C759;
  --orange:        #FF9500;
  --red:           #FF3B30;
  --red-dark:      #C0392B;

  /* Layout */
  --radius-sm:     10px;
  --radius:        13px;
  --radius-lg:     16px;
  --radius-xl:     20px;
  --nav-height:    83px;
  --safe-bottom:   env(safe-area-inset-bottom, 0px);
  --safe-top:      env(safe-area-inset-top, 0px);

  /* Shadows — iOS-style (vertical bias, very soft) */
  --shadow-xs:     0 1px 2px rgba(0,0,0,.06);
  --shadow-sm:     0 1px 8px rgba(0,0,0,.07), 0 0.5px 2px rgba(0,0,0,.05);
  --shadow:        0 4px 20px rgba(0,0,0,.08);
  --shadow-lg:     0 16px 48px rgba(0,0,0,.14), 0 4px 16px rgba(0,0,0,.08);

  --font: -apple-system, BlinkMacSystemFont, 'SF Pro Text', 'SF Pro Display', 'Helvetica Neue', system-ui, sans-serif;
}

/* ─── Reset ──────────────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html { height: 100%; -webkit-text-size-adjust: 100%; }

body {
  height: 100%;
  font-family: var(--font);
  font-size: 17px;
  line-height: 1.47;
  color: var(--text);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
  overscroll-behavior: none;
}

button  { font-family: var(--font); cursor: pointer; border: none; background: none; -webkit-tap-highlight-color: transparent; }
input, textarea, select { font-family: var(--font); font-size: 17px; border: none; outline: none; background: none; }
a { color: var(--primary); text-decoration: none; }
ul { list-style: none; }

/* ─── Icon ───────────────────────────────────────────────────────────────── */
.icon {
  display: inline-block;
  width: 1em; height: 1em;
  flex-shrink: 0;
  fill: currentColor;
  vertical-align: -0.1em;
}

/* ─── App Shell ──────────────────────────────────────────────────────────── */
#app {
  display: flex;
  flex-direction: column;
  height: 100%;
  max-width: 430px;
  margin: 0 auto;
  position: relative;
  overflow: hidden;
  background: var(--bg);
}

#view {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
  -webkit-overflow-scrolling: touch;
  padding-bottom: calc(var(--nav-height) + 12px);
}

/* ─── Loading ────────────────────────────────────────────────────────────── */
.loading-screen {
  position: absolute; inset: 0;
  display: flex; align-items: center; justify-content: center;
  background: var(--surface);
  z-index: 100;
  transition: opacity .3s ease;
}
.loading-logo { animation: pulse 1.2s ease-in-out infinite; }
@keyframes pulse {
  0%,100% { opacity: 1; transform: scale(1); }
  50%      { opacity: .45; transform: scale(.88); }
}

/* ─── iOS Tab Bar ────────────────────────────────────────────────────────── */
#nav {
  position: absolute;
  bottom: 0; left: 0; right: 0;
  height: var(--nav-height);
  padding-bottom: var(--safe-bottom);
  background: rgba(249,249,249,.94);
  -webkit-backdrop-filter: saturate(180%) blur(20px);
  backdrop-filter:         saturate(180%) blur(20px);
  border-top: 0.5px solid var(--separator-thin);
  z-index: 50;
}

.nav-items {
  display: flex;
  height: 49px;
  align-items: stretch;
}

.nav-item {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
  padding: 6px 0 4px;
  color: var(--text-3);
  font-size: 10px;
  font-weight: 500;
  letter-spacing: .01em;
  transition: color .12s;
  -webkit-tap-highlight-color: transparent;
}

.nav-item .icon { width: 24px; height: 24px; flex-shrink: 0; }
.nav-item span  { line-height: 1; }
.nav-item.active { color: var(--primary); }

/* ─── Auth ───────────────────────────────────────────────────────────────── */
.auth-view {
  min-height: 100%;
  display: flex; flex-direction: column;
  align-items: center; justify-content: center;
  padding: 48px 28px 40px;
  background: var(--bg);
}

.auth-logo {
  width: 80px; height: 80px;
  background: var(--primary-tint);
  border-radius: 22px;
  display: flex; align-items: center; justify-content: center;
  margin-bottom: 28px;
  color: var(--primary);
}
.auth-logo .icon { width: 40px; height: 40px; }

.auth-title {
  font-size: 34px; font-weight: 700;
  letter-spacing: -.5px;
  margin-bottom: 6px;
}

.auth-subtitle {
  font-size: 15px; color: var(--text-2);
  text-align: center; margin-bottom: 40px;
}

.auth-notice {
  width: 100%; margin-bottom: 20px;
  padding: 12px 14px;
  border-radius: var(--radius-sm);
  font-size: 14px; line-height: 1.5;
  display: flex; align-items: flex-start; gap: 8px;
}
.auth-notice .icon { flex-shrink: 0; margin-top: 2px; }
.auth-notice--success {
  background: rgba(52,199,89,.12);
  color: #1a7a34;
}
.auth-notice--error {
  background: rgba(255,59,48,.10);
  color: var(--red-dark);
}

.auth-segment {
  display: flex;
  background: var(--surface-2);
  border-radius: 9px;
  padding: 2px;
  width: 100%; margin-bottom: 24px;
}

.auth-seg-btn {
  flex: 1; padding: 7px;
  font-size: 13px; font-weight: 600;
  border-radius: 7px;
  color: var(--text);
  transition: background .15s, box-shadow .15s;
}

.auth-seg-btn.active {
  background: var(--surface);
  box-shadow: var(--shadow-sm);
}

/* ─── Buttons ────────────────────────────────────────────────────────────── */
.btn {
  display: flex; align-items: center; justify-content: center; gap: 8px;
  width: 100%;
  padding: 15px 20px;
  border-radius: var(--radius);
  font-size: 17px; font-weight: 600;
  transition: opacity .12s, transform .1s;
  -webkit-tap-highlight-color: transparent;
}
.btn:active { opacity: .8; transform: scale(.98); }
.btn-primary   { background: var(--primary); color: #fff; }
.btn-secondary { background: var(--surface-2); color: var(--text); }
.btn-danger    { background: var(--destructive); color: #fff; }
.btn-demo {
  background: var(--surface-2);
  color: var(--text-2);
  font-size: 15px;
  padding: 13px 20px;
}

/* ─── Forms ──────────────────────────────────────────────────────────────── */
.form { width: 100%; display: flex; flex-direction: column; gap: 12px; }

.input-group {
  background: var(--surface);
  border-radius: var(--radius-sm);
  padding: 11px 16px;
  border: 1px solid transparent;
  transition: border-color .15s;
}
.input-group:focus-within { border-color: var(--primary); }
.input-group label {
  display: block; font-size: 12px; font-weight: 600;
  text-transform: uppercase; letter-spacing: .07em;
  color: var(--text-2); margin-bottom: 3px;
}
.input-group input::placeholder { color: var(--text-3); }
.input-group input { color: var(--text); width: 100%; font-size: 16px; }

.divider {
  display: flex; align-items: center; gap: 12px;
  color: var(--text-3); font-size: 13px;
}
.divider::before, .divider::after {
  content: ''; flex: 1; height: 0.5px; background: var(--separator);
}

/* ─── View Headers (iOS large title style) ───────────────────────────────── */
.view-header {
  padding: 16px 20px 0;
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
}

.view-title {
  font-size: 34px; font-weight: 700;
  letter-spacing: -.5px;
  line-height: 1.1;
}

.view-header-action {
  display: flex; align-items: center; justify-content: center;
  width: 36px; height: 36px;
  border-radius: 50%;
  background: var(--primary-tint);
  color: var(--primary);
  flex-shrink: 0;
  margin-bottom: 4px;
  transition: background .12s;
  -webkit-tap-highlight-color: transparent;
}
.view-header-action:active { background: rgba(0,122,255,.22); }
.view-header-action .icon { width: 22px; height: 22px; }

/* ─── Budget Summary Card ────────────────────────────────────────────────── */
.budget-summary {
  margin: 16px 20px 0;
  background: var(--primary);
  border-radius: var(--radius-lg);
  padding: 22px 20px 20px;
  color: #fff;
  position: relative;
  overflow: hidden;
}

.budget-summary::before {
  content: '';
  position: absolute;
  top: -30px; right: -20px;
  width: 140px; height: 140px;
  border-radius: 50%;
  background: rgba(255,255,255,.1);
}

.budget-remaining-label {
  font-size: 13px; font-weight: 500; opacity: .82;
  margin-bottom: 4px;
  letter-spacing: .01em;
}

.budget-remaining-amount {
  font-size: 44px; font-weight: 700;
  letter-spacing: -1.5px;
  line-height: 1;
  margin-bottom: 12px;
}

.budget-meta {
  display: flex; justify-content: space-between; align-items: center;
  padding-top: 12px;
  border-top: 1px solid rgba(255,255,255,.2);
}

.budget-meta-item { font-size: 13px; opacity: .8; }
.budget-meta-item strong { font-weight: 600; opacity: 1; }

/* Over budget state */
.budget-summary.over { background: var(--red); }
.budget-summary.warning { background: var(--orange); }

/* ─── Section Header ─────────────────────────────────────────────────────── */
.section-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 20px 20px 10px;
}
.section-title { font-size: 22px; font-weight: 700; letter-spacing: -.3px; }
.section-action { font-size: 15px; color: var(--primary); font-weight: 500; }

/* ─── Category Cards (Dashboard) ─────────────────────────────────────────── */
.category-list {
  display: flex; flex-direction: column;
  gap: 10px;
  padding: 0 20px;
}

.category-card {
  background: var(--surface);
  border-radius: var(--radius);
  overflow: hidden;
  box-shadow: var(--shadow-sm);
  display: flex; align-items: center;
  transition: background .12s;
  -webkit-tap-highlight-color: transparent;
  cursor: pointer;
}

.category-card:active { background: var(--bg); }

.category-accent {
  width: 4px;
  align-self: stretch;
  flex-shrink: 0;
}

.category-icon-wrap {
  width: 36px; height: 36px;
  border-radius: 9px;
  display: flex; align-items: center; justify-content: center;
  margin: 14px 12px 14px 14px;
  flex-shrink: 0;
}
.category-icon-wrap .icon { width: 19px; height: 19px; }

.category-body { flex: 1; min-width: 0; padding: 14px 0; }
.category-name {
  font-size: 15px; font-weight: 600;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  margin-bottom: 1px;
}
.category-spent { font-size: 12px; color: var(--text-2); }

.category-right { padding: 14px 16px 14px 8px; text-align: right; flex-shrink: 0; }
.category-remaining { font-size: 15px; font-weight: 600; }
.category-limit    { font-size: 12px; color: var(--text-3); margin-top: 1px; }

/* ─── Empty State ────────────────────────────────────────────────────────── */
.empty-state {
  text-align: center; padding: 64px 20px;
  color: var(--text-2);
}
.empty-state .icon { width: 48px; height: 48px; opacity: .25; display: block; margin: 0 auto 16px; }
.empty-state h3 { font-size: 17px; font-weight: 600; color: var(--text); margin-bottom: 6px; }
.empty-state p  { font-size: 15px; }

/* ─── Expenses — Category Accordion ─────────────────────────────────────── */
.acc-list {
  display: flex; flex-direction: column;
  gap: 10px;
  padding: 0 20px;
}

.acc-item {
  background: var(--surface);
  border-radius: var(--radius);
  overflow: hidden;
  box-shadow: var(--shadow-sm);
}

.acc-header {
  display: flex; align-items: center;
  overflow: hidden;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  transition: background .12s;
  border: none;
  width: 100%;
  text-align: left;
}
.acc-header:active { background: var(--bg); }

.acc-accent { width: 4px; align-self: stretch; flex-shrink: 0; }

.acc-icon {
  width: 36px; height: 36px;
  border-radius: 9px;
  display: flex; align-items: center; justify-content: center;
  margin: 14px 12px 14px 14px; flex-shrink: 0;
}
.acc-icon .icon { width: 19px; height: 19px; }

.acc-body { flex: 1; min-width: 0; padding: 14px 0; }
.acc-cat-name  { font-size: 15px; font-weight: 600; margin-bottom: 2px; }
.acc-cat-count { font-size: 12px; color: var(--text-2); }

.acc-right {
  padding: 14px 10px 14px 8px;
  text-align: right; flex-shrink: 0;
  display: flex; align-items: center; gap: 8px;
}
.acc-total  { font-size: 15px; font-weight: 600; }
.acc-chevron {
  width: 20px; height: 20px;
  color: var(--text-3);
  transition: transform .2s;
  flex-shrink: 0;
}
.acc-chevron .icon { width: 20px; height: 20px; }
.acc-item.open .acc-chevron { transform: rotate(90deg); }

/* Expanded expense rows */
.acc-expenses {
  border-top: 0.5px solid var(--separator-thin);
  max-height: 0;
  overflow: hidden;
  transition: max-height .28s cubic-bezier(.4,0,.2,1);
}
.acc-item.open .acc-expenses { max-height: 2000px; }

.acc-expense-row {
  display: flex; align-items: center; gap: 12px;
  padding: 11px 16px 11px 18px;
  border-bottom: 0.5px solid var(--separator-thin);
  transition: background .1s;
}
.acc-expense-row:last-child { border-bottom: none; }
.acc-expense-row:active { background: var(--bg); }

.acc-exp-date {
  font-size: 12px; color: var(--text-2); font-variant-numeric: tabular-nums;
  min-width: 52px; flex-shrink: 0;
}
.acc-exp-desc {
  flex: 1; font-size: 14px; font-weight: 500;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.acc-exp-amount { font-size: 15px; font-weight: 600; flex-shrink: 0; }
.acc-exp-delete {
  width: 30px; height: 30px;
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  color: var(--destructive);
  opacity: .7; flex-shrink: 0;
  transition: opacity .12s, background .12s;
  -webkit-tap-highlight-color: transparent;
}
.acc-exp-delete:active { opacity: 1; background: rgba(255,59,48,.1); }
.acc-exp-delete .icon { width: 16px; height: 16px; }

/* Zero-spend category row */
.acc-item.zero-spend .acc-total { color: var(--text-3); font-weight: 400; }

/* ─── Period Navigator ───────────────────────────────────────────────────── */
.period-nav {
  display: flex; align-items: center; justify-content: center;
  gap: 12px; padding: 12px 20px 0;
}
.period-nav-btn {
  width: 30px; height: 30px; border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  color: var(--primary);
  -webkit-tap-highlight-color: transparent;
  transition: background .1s;
}
.period-nav-btn:active { background: var(--primary-tint); }
.period-nav-btn .icon { width: 20px; height: 20px; }
.period-nav-btn:disabled { color: var(--text-3); pointer-events: none; }
.period-nav-label {
  font-size: 15px; font-weight: 600;
  min-width: 170px; text-align: center;
}

/* ─── Categories Management ──────────────────────────────────────────────── */
.page-header {
  display: flex; align-items: center; gap: 12px;
  padding: 12px 20px 8px;
}
.page-header-back {
  width: 34px; height: 34px; border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  color: var(--primary);
}
.page-header-back .icon { width: 22px; height: 22px; }
.page-header h2 { font-size: 20px; font-weight: 700; letter-spacing: -.3px; }

.cat-manage-list { display: flex; flex-direction: column; gap: 0; padding: 0 20px; border-radius: var(--radius); overflow: hidden; box-shadow: var(--shadow-sm); }

.cat-manage-item {
  background: var(--surface);
  display: flex; align-items: center; gap: 14px;
  padding: 12px 16px;
  border-bottom: 0.5px solid var(--separator-thin);
}
.cat-manage-item:last-child { border-bottom: none; }

.cat-manage-icon {
  width: 38px; height: 38px; border-radius: 10px;
  display: flex; align-items: center; justify-content: center; flex-shrink: 0;
}
.cat-manage-icon .icon { width: 20px; height: 20px; }
.cat-manage-body { flex: 1; min-width: 0; }
.cat-manage-name  { font-size: 15px; font-weight: 600; }
.cat-manage-limit { font-size: 12px; color: var(--text-2); margin-top: 1px; }
.cat-manage-actions { display: flex; gap: 2px; }

.icon-btn {
  width: 34px; height: 34px; border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  color: var(--text-3);
  transition: background .1s, color .1s;
  -webkit-tap-highlight-color: transparent;
}
.icon-btn:active  { background: var(--bg); }
.icon-btn .icon   { width: 18px; height: 18px; }
.icon-btn.danger  { color: var(--destructive); }

.add-section { padding: 20px; }
.add-section h3 { font-size: 17px; font-weight: 600; margin-bottom: 14px; }

.icon-picker {
  display: grid; grid-template-columns: repeat(5, 1fr);
  gap: 8px; margin-bottom: 14px;
}
.icon-option {
  aspect-ratio: 1; border-radius: var(--radius-sm);
  display: flex; align-items: center; justify-content: center;
  background: var(--surface-2); color: var(--text-2);
  cursor: pointer; border: 1.5px solid transparent;
  transition: background .1s, color .1s, border-color .1s;
  -webkit-tap-highlight-color: transparent;
}
.icon-option .icon { width: 22px; height: 22px; }
.icon-option.selected {
  background: var(--primary-tint);
  color: var(--primary); border-color: var(--primary);
}

/* ─── Settings ───────────────────────────────────────────────────────────── */
.settings-section { margin: 0 20px 28px; }
.settings-section-title {
  font-size: 13px; font-weight: 600; color: var(--text-2);
  text-transform: uppercase; letter-spacing: .06em;
  padding: 0 4px; margin-bottom: 8px;
}
.settings-card {
  background: var(--surface); border-radius: var(--radius);
  overflow: hidden; box-shadow: var(--shadow-sm);
}
.settings-row {
  display: flex; align-items: center;
  padding: 12px 16px; gap: 14px;
  border-bottom: 0.5px solid var(--separator-thin);
  background: var(--surface);
}
.settings-row:last-child { border-bottom: none; }
.settings-row-icon {
  width: 30px; height: 30px; border-radius: 8px;
  display: flex; align-items: center; justify-content: center; flex-shrink: 0;
  background: var(--primary-tint); color: var(--primary);
}
.settings-row-icon .icon { width: 16px; height: 16px; }
.settings-row-body { flex: 1; }
.settings-row-label { font-size: 15px; font-weight: 500; }
.settings-row-value { font-size: 13px; color: var(--text-2); margin-top: 1px; }
.settings-row-right { color: var(--text-3); }
.settings-row-right .icon { width: 16px; height: 16px; }
.settings-row-control { display: flex; align-items: center; gap: 6px; }
.settings-row-control input,
.settings-row-control select {
  font-size: 15px; color: var(--text-2); text-align: right; max-width: 120px;
}
.settings-row-control select {
  background: var(--surface-2); border-radius: 6px; padding: 4px 8px;
}
.settings-save-btn { margin: 0 20px 16px; }
.danger-btn {
  display: flex; align-items: center; justify-content: center; gap: 8px;
  width: 100%; padding: 14px 20px; border-radius: var(--radius);
  font-size: 17px; font-weight: 600; color: var(--destructive);
  background: rgba(255,59,48,.08);
  transition: background .12s;
  -webkit-tap-highlight-color: transparent;
}
.danger-btn .icon { width: 20px; height: 20px; }
.danger-btn:active { background: rgba(255,59,48,.15); }

/* ─── Quick Add Bottom Sheet ─────────────────────────────────────────────── */
.sheet-overlay {
  position: fixed; inset: 0;
  background: rgba(0,0,0,.4);
  z-index: 200; opacity: 0; pointer-events: none;
  transition: opacity .25s ease;
}
.sheet-overlay.visible { opacity: 1; pointer-events: auto; }

.sheet {
  position: fixed;
  bottom: 0; left: 50%;
  transform: translateX(-50%) translateY(100%);
  width: 100%; max-width: 430px;
  background: var(--surface);
  border-radius: 12px 12px 0 0;
  padding-bottom: calc(16px + var(--safe-bottom));
  z-index: 210;
  transition: transform .32s cubic-bezier(.32,.72,0,1);
  max-height: 92vh;
  overflow-y: auto;
}
.sheet.open { transform: translateX(-50%) translateY(0); }

.sheet-handle {
  width: 36px; height: 5px; border-radius: 3px;
  background: var(--surface-2);
  margin: 10px auto 14px;
}

.sheet-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 0 20px 16px;
}
.sheet-title { font-size: 20px; font-weight: 700; letter-spacing: -.3px; }

.sheet-close {
  width: 28px; height: 28px; border-radius: 50%;
  background: var(--surface-2);
  display: flex; align-items: center; justify-content: center;
  color: var(--text-2);
}
.sheet-close:active { background: var(--separator); }
.sheet-close .icon { width: 16px; height: 16px; }

/* Amount input */
.amount-section {
  padding: 0 20px 20px;
  display: flex; align-items: baseline;
  justify-content: center; gap: 4px;
}
.amount-currency {
  font-size: 32px; font-weight: 300;
  color: var(--text-2);
}
.amount-input {
  font-size: 56px; font-weight: 700; letter-spacing: -2px;
  color: var(--text); text-align: center;
  width: calc(100% - 80px);
  min-width: 80px; max-width: 280px;
  caret-color: var(--primary);
}
.amount-input::placeholder { color: var(--text-3); }

/* Category picker */
.sheet-section { padding: 0 20px 16px; }
.sheet-section-label {
  font-size: 13px; font-weight: 600; color: var(--text-2);
  text-transform: uppercase; letter-spacing: .05em;
  margin-bottom: 10px;
}

.cat-picker {
  display: flex; gap: 8px;
  overflow-x: auto; scrollbar-width: none;
  padding-bottom: 4px;
}
.cat-picker::-webkit-scrollbar { display: none; }

.cat-chip {
  display: flex; flex-direction: column; align-items: center; gap: 5px;
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  background: var(--bg); color: var(--text-2);
  min-width: 64px; font-size: 11px; font-weight: 600; text-align: center;
  border: 1.5px solid transparent; flex-shrink: 0;
  cursor: pointer; transition: background .1s, color .1s, border-color .1s;
  -webkit-tap-highlight-color: transparent;
}
.cat-chip .icon { width: 22px; height: 22px; }
.cat-chip.selected {
  background: var(--primary-tint);
  color: var(--primary); border-color: var(--primary);
}

.sheet-fields { padding: 0 20px; display: flex; flex-direction: column; gap: 10px; }

.field-row {
  display: flex; align-items: center; gap: 10px;
  background: var(--bg); border-radius: var(--radius-sm);
  padding: 12px 14px; border: 1.5px solid transparent;
  transition: border-color .15s;
}
.field-row:focus-within { border-color: var(--primary); }
.field-row .icon { width: 18px; height: 18px; color: var(--text-3); flex-shrink: 0; }
.field-row input { flex: 1; font-size: 15px; color: var(--text); }
.field-row input::placeholder { color: var(--text-3); }

.sheet-submit { margin: 20px 20px 0; }

/* ─── Toast ──────────────────────────────────────────────────────────────── */
#toast-container {
  position: fixed; top: 56px; left: 50%;
  transform: translateX(-50%);
  z-index: 300;
  display: flex; flex-direction: column; gap: 8px;
  pointer-events: none;
  width: min(400px, calc(100vw - 40px));
}
.toast {
  display: flex; align-items: center; gap: 10px;
  padding: 12px 16px; border-radius: var(--radius-sm);
  background: rgba(44,44,46,.95);
  color: #fff; font-size: 14px; font-weight: 500;
  box-shadow: var(--shadow-lg);
  animation: toast-in .25s cubic-bezier(.32,.72,0,1) forwards;
  -webkit-backdrop-filter: blur(20px); backdrop-filter: blur(20px);
}
.toast.removing { animation: toast-out .2s ease forwards; }
.toast .icon    { width: 18px; height: 18px; flex-shrink: 0; }
.toast.success  { background: rgba(52,199,89,.95); }
.toast.error    { background: rgba(255,59,48,.95); }

@keyframes toast-in  { from { opacity:0; transform:translateY(-10px) scale(.96); } to { opacity:1; transform:none; } }
@keyframes toast-out { from { opacity:1; transform:none; } to { opacity:0; transform:translateY(-10px) scale(.96); } }

/* ─── Undo Bar ───────────────────────────────────────────────────────────── */
.undo-bar {
  position: fixed;
  bottom: calc(var(--nav-height) + var(--safe-bottom) + 12px);
  left: 50%;
  transform: translateX(-50%);
  z-index: 150;
  width: min(360px, calc(100vw - 40px));
  background: rgba(44,44,46,.97);
  -webkit-backdrop-filter: blur(24px);
  backdrop-filter: blur(24px);
  border-radius: 14px;
  padding: 13px 6px 13px 16px;
  display: flex;
  align-items: center;
  gap: 8px;
  box-shadow: 0 8px 32px rgba(0,0,0,.22), 0 2px 8px rgba(0,0,0,.12);
  animation: undo-in .3s cubic-bezier(.32,.72,0,1) forwards;
  overflow: hidden;
}

.undo-bar--out {
  animation: undo-out .25s ease forwards;
}

.undo-bar-text {
  flex: 1;
  font-size: 14px;
  font-weight: 500;
  color: rgba(255,255,255,.92);
}

.undo-bar-btn {
  font-size: 15px;
  font-weight: 700;
  color: #FFD60A; /* iOS yellow — stands out on dark bg */
  padding: 6px 10px;
  border-radius: 8px;
  flex-shrink: 0;
  transition: background .12s;
  -webkit-tap-highlight-color: transparent;
}
.undo-bar-btn:active { background: rgba(255,255,255,.1); }

/* Shrinking timer line at the bottom */
.undo-timer {
  position: absolute;
  bottom: 0; left: 0; right: 0;
  height: 2px;
  background: transparent;
}

.undo-timer-fill {
  height: 100%;
  width: 100%;
  background: rgba(255,255,255,.28);
  transform-origin: left center;
  animation: undo-countdown 10s linear forwards;
}

@keyframes undo-in {
  from { opacity: 0; transform: translateX(-50%) translateY(20px) scale(.95); }
  to   { opacity: 1; transform: translateX(-50%) translateY(0)    scale(1);   }
}
@keyframes undo-out {
  from { opacity: 1; transform: translateX(-50%) translateY(0)    scale(1);   }
  to   { opacity: 0; transform: translateX(-50%) translateY(16px) scale(.96); }
}
@keyframes undo-countdown {
  from { transform: scaleX(1); }
  to   { transform: scaleX(0); }
}

/* ─── Modal (Confirm) ────────────────────────────────────────────────────── */
.modal-overlay {
  position: fixed; inset: 0;
  background: rgba(0,0,0,.45);
  z-index: 400;
  display: flex; align-items: center; justify-content: center; padding: 20px;
  opacity: 0; pointer-events: none; transition: opacity .2s;
}
.modal-overlay.visible { opacity: 1; pointer-events: auto; }

.modal {
  background: var(--surface); border-radius: var(--radius-xl);
  padding: 22px 20px 6px; width: 100%; max-width: 300px;
  box-shadow: var(--shadow-lg);
  transform: scale(.95) translateY(8px);
  transition: transform .22s cubic-bezier(.32,.72,0,1);
  text-align: center;
}
.modal-overlay.visible .modal { transform: scale(1) translateY(0); }
.modal h3 { font-size: 17px; font-weight: 700; margin-bottom: 6px; }
.modal p  { font-size: 13px; color: var(--text-2); margin-bottom: 4px; line-height: 1.5; }
.modal-actions {
  display: flex; flex-direction: column;
  border-top: 0.5px solid var(--separator-thin);
  margin-top: 16px;
}
.modal-actions .modal-btn {
  padding: 14px 20px;
  font-size: 17px; font-weight: 400;
  border-bottom: 0.5px solid var(--separator-thin);
  transition: background .1s;
  -webkit-tap-highlight-color: transparent;
  border-radius: 0;
}
.modal-actions .modal-btn:last-child { border-bottom: none; }
.modal-actions .modal-btn:active { background: var(--bg); }
.modal-actions .modal-btn.destructive { color: var(--destructive); font-weight: 600; }
.modal-actions .modal-btn.cancel { color: var(--primary); }

/* ─── Utilities ──────────────────────────────────────────────────────────── */
.mt-4  { margin-top: 4px; }
.mt-8  { margin-top: 8px; }
.mt-12 { margin-top: 12px; }
.mt-16 { margin-top: 16px; }
.mt-20 { margin-top: 20px; }
.hidden { display: none !important; }

#view::-webkit-scrollbar { width: 4px; }
#view::-webkit-scrollbar-track { background: transparent; }
#view::-webkit-scrollbar-thumb { background: var(--separator); border-radius: 2px; }
