:root {
  --bg: #f7f5f2;
  --surface: #ffffff;
  --surface-alt: #faf8f5;
  --border: #e5e0d8;
  --text: #1a1814;
  --muted: #6b6358;
  --accent: #b83a5c;
  --accent-soft: #fce8ee;
  --success: #16a34a;
  --shadow-sm: 0 1px 2px rgba(26,24,20,0.04), 0 1px 1px rgba(26,24,20,0.03);
  --shadow: 0 2px 6px rgba(26,24,20,0.06), 0 1px 2px rgba(26,24,20,0.04);
  --radius: 14px;
  --radius-sm: 8px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #141210;
    --surface: #1f1d1a;
    --surface-alt: #252320;
    --border: #35322d;
    --text: #ece8e0;
    --muted: #9a928a;
    --accent: #e8809c;
    --accent-soft: #3a1f29;
    --shadow-sm: 0 1px 2px rgba(0,0,0,0.3);
    --shadow: 0 2px 6px rgba(0,0,0,0.35);
  }
}

* { box-sizing: border-box; }

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

body {
  min-height: 100vh;
  padding-bottom: 48px;
}

h1, h2, h3, h4 { margin: 0; font-weight: 600; letter-spacing: -0.01em; }
p { margin: 0 0 12px; }
small { color: var(--muted); }

#topbar {
  position: sticky;
  top: 0;
  z-index: 30;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 20px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  backdrop-filter: blur(8px);
}
#topbar .brand h1 {
  font-size: 17px;
  letter-spacing: -0.02em;
}
#topbar .brand small {
  font-size: 12px;
  display: block;
  margin-top: 2px;
}
#topbar .stats {
  font-size: 13px;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}
#topbar .stats b { color: var(--accent); font-weight: 600; }

#nav {
  position: sticky;
  top: 57px;
  z-index: 20;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
}
#nav::-webkit-scrollbar { display: none; }
#nav .tabs {
  display: flex;
  gap: 2px;
  padding: 8px 12px;
  min-width: max-content;
}
#nav button {
  appearance: none;
  border: 0;
  background: transparent;
  color: var(--muted);
  font-size: 14px;
  font-weight: 500;
  padding: 8px 14px;
  border-radius: 999px;
  cursor: pointer;
  white-space: nowrap;
  transition: background 0.15s, color 0.15s;
  font-family: inherit;
}
#nav button:hover { background: var(--surface-alt); color: var(--text); }
#nav button[aria-current="page"] {
  background: var(--text);
  color: var(--bg);
}

#view {
  max-width: 820px;
  margin: 0 auto;
  padding: 24px 18px 48px;
}

.page-header {
  margin-bottom: 24px;
}
.page-header h2 {
  font-size: 26px;
  margin-bottom: 4px;
}
.page-header .meta {
  color: var(--muted);
  font-size: 14px;
}

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px 20px;
  margin-bottom: 14px;
  box-shadow: var(--shadow-sm);
}
.card h3 {
  font-size: 15px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--muted);
  margin-bottom: 14px;
}
.card > p:last-child { margin-bottom: 0; }

.info-card {
  background: var(--accent-soft);
  border-color: transparent;
  color: var(--text);
}
.info-card h3 { color: var(--accent); }

.note-card {
  border-left: 3px solid var(--accent);
  padding-left: 16px;
  background: var(--surface-alt);
  font-size: 14px;
  border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
  padding-top: 10px;
  padding-bottom: 10px;
  margin-bottom: 14px;
}

/* Checklist */
.checklist { list-style: none; padding: 0; margin: 0; }
.check-item {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  padding: 12px 0;
  border-top: 1px solid var(--border);
  cursor: pointer;
}
.check-item:first-child { border-top: 0; }
.check-item input[type="checkbox"] {
  appearance: none;
  width: 22px;
  height: 22px;
  border: 2px solid var(--border);
  border-radius: 6px;
  background: var(--surface);
  cursor: pointer;
  flex-shrink: 0;
  margin: 1px 0 0;
  position: relative;
  transition: background 0.15s, border-color 0.15s;
}
.check-item input[type="checkbox"]:checked {
  background: var(--success);
  border-color: var(--success);
}
.check-item input[type="checkbox"]:checked::after {
  content: "";
  position: absolute;
  left: 6px;
  top: 2px;
  width: 5px;
  height: 10px;
  border: solid white;
  border-width: 0 2px 2px 0;
  transform: rotate(45deg);
}
.check-item .body {
  flex: 1;
  min-width: 0;
}
.check-item .label {
  font-size: 15px;
  line-height: 1.35;
}
.check-item.done .label {
  text-decoration: line-through;
  color: var(--muted);
}
.check-item .sub {
  font-size: 13px;
  color: var(--muted);
  margin-top: 3px;
}
.check-item.secret {
  background: linear-gradient(90deg, var(--accent-soft), transparent);
  border-radius: var(--radius-sm);
  padding-left: 10px;
  padding-right: 10px;
  margin: 6px -10px;
}
.check-item .note-btn {
  appearance: none;
  border: 1px solid var(--border);
  background: var(--surface);
  border-radius: 6px;
  width: 30px;
  height: 30px;
  cursor: pointer;
  color: var(--muted);
  font-size: 14px;
  font-family: inherit;
  display: grid;
  place-items: center;
  flex-shrink: 0;
  transition: border-color 0.15s, color 0.15s;
}
.check-item .note-btn.has-note {
  color: var(--accent);
  border-color: var(--accent);
}
.check-item textarea {
  width: 100%;
  margin-top: 8px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 8px 10px;
  background: var(--surface-alt);
  color: var(--text);
  font-family: inherit;
  font-size: 14px;
  resize: vertical;
  min-height: 60px;
  display: none;
}
.check-item.note-open textarea { display: block; }

/* Timeline day */
.day-head {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 18px;
}
.day-head .pill {
  display: inline-block;
  padding: 4px 10px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.04em;
  background: var(--day, var(--accent));
  color: white;
  text-transform: uppercase;
}

.timeline { position: relative; padding-left: 22px; margin: 0; list-style: none; }
.timeline::before {
  content: "";
  position: absolute;
  left: 6px;
  top: 8px;
  bottom: 8px;
  width: 2px;
  background: var(--border);
}
.tl-item {
  position: relative;
  padding: 0 0 20px 10px;
}
.tl-item::before {
  content: "";
  position: absolute;
  left: -22px;
  top: 6px;
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: var(--day, var(--accent));
  border: 3px solid var(--bg);
  box-shadow: 0 0 0 1px var(--day, var(--accent));
}
.tl-item .time {
  font-size: 13px;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
  font-weight: 600;
  margin-bottom: 2px;
}
.tl-item .title {
  font-size: 16px;
  font-weight: 600;
  line-height: 1.35;
}
.tl-item .detail {
  font-size: 14px;
  color: var(--muted);
  margin-top: 4px;
  line-height: 1.45;
}
.tl-item.surprise {
  background: linear-gradient(100deg, var(--accent-soft), transparent 70%);
  border-radius: var(--radius-sm);
  padding: 10px 10px 14px 14px;
  margin: 0 -10px 20px -10px;
  padding-left: 24px;
}
.tl-item.surprise::before {
  left: -12px;
  background: var(--accent);
  box-shadow: 0 0 0 1px var(--accent), 0 0 0 3px var(--accent-soft);
}
.tl-item.surprise .title::before { content: "✨ "; }

/* Expandable logistics + smart notes (his-only) */
.tl-expand {
  appearance: none;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--muted);
  border-radius: 999px;
  padding: 4px 12px;
  font-size: 12px;
  font-family: inherit;
  font-weight: 500;
  cursor: pointer;
  margin-top: 8px;
  display: inline-flex;
  align-items: center;
  gap: 4px;
  transition: border-color 0.15s, color 0.15s;
}
.tl-expand:hover { border-color: var(--accent); color: var(--accent); }
.tl-expand-arrow {
  display: inline-block;
  transition: transform 0.2s;
  font-size: 11px;
}
.tl-item.open .tl-expand-arrow { transform: rotate(180deg); }
.tl-extra {
  display: none;
  margin-top: 10px;
  padding: 10px 12px;
  background: var(--surface-alt);
  border-left: 2px solid var(--accent);
  border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
  font-size: 13px;
}
.tl-item.open .tl-extra { display: block; }
.tl-extra-row { display: flex; gap: 8px; margin-bottom: 6px; }
.tl-extra-row:last-child { margin-bottom: 0; }
.tl-extra-label {
  flex-shrink: 0;
  font-weight: 600;
  color: var(--accent);
  min-width: 62px;
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  padding-top: 1px;
}
.tl-extra-text {
  flex: 1;
  color: var(--text);
  line-height: 1.45;
}

/* Addresses list */
.addr-list dt {
  color: var(--muted);
  font-size: 13px;
  font-weight: 500;
  margin-top: 10px;
}
.addr-list dt:first-child { margin-top: 0; }
.addr-list dd {
  margin: 2px 0 0;
  font-size: 14px;
  line-height: 1.4;
}
.addr-map {
  color: var(--accent);
  text-decoration: none;
  font-weight: 500;
  white-space: nowrap;
}
.addr-map:hover { text-decoration: underline; }

/* Logistics table */
.log-table { margin: 0; }
.log-row {
  display: flex;
  gap: 12px;
  padding: 8px 0;
  border-top: 1px solid var(--border);
  font-size: 14px;
  line-height: 1.4;
}
.log-row:first-child { border-top: 0; }
.log-when {
  flex-shrink: 0;
  width: 140px;
  font-variant-numeric: tabular-nums;
  font-weight: 600;
  color: var(--muted);
  font-size: 13px;
}
@media (max-width: 560px) {
  .log-row { flex-direction: column; gap: 2px; }
  .log-when { width: auto; font-size: 12px; }
}

/* Contact/Budget tables */
.kv { display: grid; grid-template-columns: max-content 1fr; gap: 8px 18px; font-size: 14px; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; }

.budget-row {
  display: flex;
  justify-content: space-between;
  padding: 8px 0;
  border-top: 1px solid var(--border);
  font-size: 14px;
}
.budget-row:first-child { border-top: 0; }
.budget-row .num {
  font-variant-numeric: tabular-nums;
  font-weight: 600;
}
.budget-total {
  border-top: 2px solid var(--text) !important;
  margin-top: 6px;
  padding-top: 12px !important;
  font-weight: 600;
}

.mode-banner {
  background: var(--accent-soft);
  color: var(--accent);
  text-align: center;
  font-size: 12px;
  padding: 6px;
  font-weight: 500;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

#view > *:first-child { margin-top: 0; }

@media (max-width: 560px) {
  #topbar { padding: 10px 14px; }
  #topbar .brand h1 { font-size: 15px; }
  #topbar .brand small { font-size: 11px; }
  #topbar .stats { font-size: 11px; }
  #nav { top: 53px; }
  #nav button { font-size: 13px; padding: 7px 12px; }
  #view { padding: 16px 12px 40px; }
  .page-header h2 { font-size: 22px; }
  .card { padding: 14px 14px; }
  .timeline { padding-left: 20px; }
  .tl-item { padding-bottom: 16px; }
}

@media print {
  #topbar, #nav, .note-btn { display: none; }
  #view { max-width: none; padding: 0; }
  .card { break-inside: avoid; box-shadow: none; border: 1px solid #ccc; }
}

/* sync indicator */
.sync-indicator { display: inline-block; margin-left: 10px; font-size: .8rem; padding: 2px 8px; border-radius: 10px; background: rgba(255,255,255,.15); color: rgba(255,255,255,.85); }
.sync-indicator[data-state="ok"] { background: rgba(80,200,120,.25); color: #d4f5e0; }
.sync-indicator[data-state="pending"] { background: rgba(255,200,80,.25); color: #ffe9b0; }
.sync-indicator[data-state="offline"] { background: rgba(255,80,80,.25); color: #ffd4d4; }

/* today-deadline banner */
.banner-card { background: linear-gradient(135deg, #ffe9b0, #ffcfa8); border-left: 5px solid #d97706; padding: 16px 18px; border-radius: 10px; margin: 12px 0 18px; box-shadow: 0 4px 14px rgba(0,0,0,.06); }
.banner-card h3 { margin: 0 0 8px; color: #92400e; }
.banner-card .banner-list { margin: 0; padding-left: 22px; color: #5a3a0c; }
.banner-card .banner-list li { margin: 4px 0; }

/* receipts */
.receipts-card .receipt-row { padding: 10px 0; border-bottom: 1px solid #eee; }
.receipts-card .receipt-row:last-child { border-bottom: 0; }
.receipts-card .receipt-label { font-weight: 600; }
.receipts-card .receipt-meta { color: #666; font-size: .9rem; margin: 4px 0 6px; }
.receipts-card textarea { width: 100%; min-height: 50px; padding: 8px; border: 1px solid #ddd; border-radius: 6px; font-family: inherit; font-size: .9rem; box-sizing: border-box; resize: vertical; }

.logout-btn { display: inline-block; margin-left: 8px; padding: 4px 10px; border: 1px solid rgba(255,255,255,0.4); background: transparent; color: rgba(255,255,255,0.85); border-radius: 8px; cursor: pointer; font-size: .9rem; }
.logout-btn:hover { background: rgba(255,255,255,0.15); }
