:root {
  --bg: #f6f3ee;
  --surface: #ffffff;
  --surface-2: #efeae2;
  --text: #1d2a2f;
  --muted: #66757b;
  --line: #e2dcd2;
  --primary: #0f5c6e;
  --primary-ink: #ffffff;
  --accent: #e0703a;
  --ok: #2f7d4f;
  --ok-bg: #e3f2e8;
  --warn: #a8551c;
  --warn-bg: #fcebdc;
  --shadow: 0 1px 2px rgba(20, 30, 35, .06), 0 4px 14px rgba(20, 30, 35, .06);
  --radius: 14px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #12181b;
    --surface: #1b2428;
    --surface-2: #232e33;
    --text: #e8eef0;
    --muted: #93a3a9;
    --line: #2d393e;
    --primary: #4fb3c8;
    --primary-ink: #0b1a1f;
    --accent: #f08a55;
    --ok: #7fd09c;
    --ok-bg: #1d3427;
    --warn: #f3a46f;
    --warn-bg: #3a2717;
    --shadow: 0 1px 2px rgba(0, 0, 0, .3);
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--text);
  font: 16px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, system-ui, sans-serif;
  padding-bottom: env(safe-area-inset-bottom);
}
body.sheet-open { overflow: hidden; }
a { color: var(--primary); }
h1, h2, h3, h4 { line-height: 1.2; margin: 0; }
h1 { font-size: 1.6rem; letter-spacing: -.01em; }
p { margin: .2rem 0; }
.muted { color: var(--muted); }
.pad { padding: .25rem 0 .75rem; }
.loading { padding: 3rem 1rem; text-align: center; color: var(--muted); }

.topbar {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: center; justify-content: space-between; gap: 1rem;
  padding: calc(.7rem + env(safe-area-inset-top)) 16px .7rem;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: saturate(1.4) blur(10px); -webkit-backdrop-filter: saturate(1.4) blur(10px);
  border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: .45rem; font-weight: 700; text-decoration: none; color: var(--text); font-size: 1.1rem; }
.brand svg { width: 22px; height: 22px; fill: var(--primary); transform: rotate(45deg); }
.who { color: var(--muted); font-size: .8rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 55vw; }

main { max-width: 760px; margin: 0 auto; padding: 1rem 16px 4rem; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: .3rem;
  min-height: 44px; padding: .55rem 1rem; border-radius: 999px;
  border: 1px solid var(--line); background: var(--surface); color: var(--text);
  font: inherit; font-weight: 600; text-decoration: none; cursor: pointer;
}
.btn.primary { background: var(--primary); color: var(--primary-ink); border-color: var(--primary); }
.btn.small { min-height: 36px; padding: .35rem .8rem; font-size: .9rem; }
.btn.wide { width: 100%; margin-top: 1rem; border-style: dashed; color: var(--primary); }
.btn.danger-text { border: 0; background: none; color: #c0392b; padding-left: 0; }
.btn.ghost-light { background: rgba(255, 255, 255, .18); color: #fff; border-color: rgba(255, 255, 255, .35); }
.btn:disabled { opacity: .6; }
.icon-btn {
  display: inline-grid; place-items: center; width: 44px; height: 44px; flex: none;
  border-radius: 50%; border: 1px solid var(--line); background: var(--surface); color: var(--text);
  font-size: 1.3rem; text-decoration: none; cursor: pointer;
}
.icon-btn.small { width: 32px; height: 32px; font-size: .8rem; border: 0; background: none; color: var(--muted); }
.icon-btn.disabled { opacity: .3; }

.page-head { display: flex; align-items: center; justify-content: space-between; gap: 1rem; margin: .5rem 0 1.2rem; }
.section-title { font-size: 1rem; margin: 1.6rem 0 .6rem; color: var(--muted); text-transform: uppercase; letter-spacing: .05em; font-size: .8rem; }
.section-head { display: flex; align-items: center; justify-content: space-between; }
.section-head .section-title { margin-bottom: .6rem; }
.group { margin: 1rem 0 .4rem; font-size: .95rem; }
.empty { text-align: center; padding: 2rem 1rem; background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow); }
.empty .big { font-size: 2.6rem; }
.empty .btn { margin-top: .8rem; }
.back { display: inline-block; margin: .2rem 0 .8rem; text-decoration: none; font-weight: 600; }

/* Trip list */
.trip-grid { display: grid; gap: 1rem; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); }
.trip-grid.past { opacity: .75; }
.trip-card { display: block; background: var(--surface); border-radius: var(--radius); overflow: hidden; box-shadow: var(--shadow); text-decoration: none; color: inherit; }
.trip-card .cover {
  position: relative; height: 120px; background: linear-gradient(135deg, #0f5c6e, #2b8a9e 55%, #e0a46a);
  background-size: cover; background-position: center;
}
.when { position: absolute; left: 10px; bottom: 10px; background: rgba(0, 0, 0, .55); color: #fff; padding: .2rem .6rem; border-radius: 999px; font-size: .8rem; font-weight: 600; }
.trip-card-body { padding: .8rem 1rem 1rem; }
.trip-card h3 { font-size: 1.15rem; }
.row { display: flex; flex-wrap: wrap; gap: .4rem; align-items: center; margin-top: .6rem; }
.total { font-weight: 700; margin-right: .3rem; }
.flag { font-size: .75rem; background: var(--warn-bg); color: var(--warn); padding: .15rem .5rem; border-radius: 999px; font-weight: 600; }

/* Trip header */
.trip-hero {
  display: flex; justify-content: space-between; align-items: flex-end; gap: 1rem; flex-wrap: wrap;
  padding: 1.4rem 1.2rem 1.2rem; border-radius: var(--radius); color: #fff; min-height: 170px;
  background: linear-gradient(to top, rgba(0, 0, 0, .65), rgba(0, 0, 0, .1)), var(--cover, linear-gradient(135deg, #0f5c6e, #2b8a9e 55%, #e0a46a));
  background-size: cover; background-position: center;
}
.trip-hero p { opacity: .92; }
.hero-total { font-size: 1.3rem; font-weight: 700; margin-top: .4rem !important; opacity: 1 !important; }
.hero-total .muted { color: rgba(255, 255, 255, .8); font-size: .9rem; font-weight: 500; }
.hero-actions { display: flex; gap: .4rem; }

.alerts { list-style: none; padding: 0; margin: 1rem 0 0; display: grid; gap: .4rem; }
.alerts a { display: block; padding: .65rem .9rem; border-radius: 10px; background: var(--warn-bg); color: var(--warn); text-decoration: none; font-weight: 600; font-size: .95rem; }
.all-set { margin: 1rem 0 0; padding: .65rem .9rem; border-radius: 10px; background: var(--ok-bg); color: var(--ok); font-weight: 600; }

.tabs {
  display: flex; gap: .3rem; overflow-x: auto; margin: 1.2rem -16px 0; padding: 0 16px .2rem;
  scrollbar-width: none; position: sticky; top: calc(56px + env(safe-area-inset-top)); z-index: 5; background: var(--bg);
}
.tabs::-webkit-scrollbar { display: none; }
.tabs a { flex: none; padding: .55rem .9rem; border-radius: 999px; text-decoration: none; color: var(--muted); font-weight: 600; white-space: nowrap; }
.tabs a.active { background: var(--text); color: var(--bg); }
.count { font-size: .75rem; background: var(--accent); color: #fff; border-radius: 999px; padding: .05rem .4rem; margin-left: .15rem; }
.tab-body { padding-top: .8rem; }

/* Days */
.day-list { display: grid; gap: .6rem; }
.day-card {
  display: flex; gap: .8rem; align-items: stretch; padding: .8rem; background: var(--surface);
  border-radius: var(--radius); box-shadow: var(--shadow); text-decoration: none; color: inherit;
}
.day-card.today { outline: 2px solid var(--accent); }
.day-num { flex: none; width: 46px; display: grid; place-content: center; text-align: center; background: var(--surface-2); border-radius: 10px; font-weight: 800; font-size: 1.3rem; line-height: 1; }
.day-num span { font-size: .65rem; font-weight: 600; color: var(--muted); text-transform: uppercase; margin-bottom: .15rem; }
.day-main { flex: 1; min-width: 0; }
.day-top { display: flex; flex-wrap: wrap; gap: .2rem .6rem; align-items: baseline; }
.place { color: var(--muted); font-size: .85rem; }
.day-line { font-size: .9rem; margin-top: .25rem; overflow: hidden; text-overflow: ellipsis; }
.day-line.warn, .warn { color: var(--warn); }
.day-side { flex: none; display: flex; flex-direction: column; align-items: flex-end; gap: .4rem; }
.day-cost { font-weight: 700; font-size: .9rem; }
.day-pic { width: 54px; height: 54px; object-fit: cover; border-radius: 8px; }

.day-head { display: flex; align-items: center; justify-content: space-between; gap: .6rem; text-align: center; }
.sleep { padding: .2rem 0; }
.sleep-card { display: flex; flex-direction: column; gap: .1rem; padding: .8rem 1rem; background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow); text-decoration: none; color: inherit; }
.sleep-card.warn { background: var(--warn-bg); color: var(--warn); font-weight: 600; box-shadow: none; }

/* Items (travel, lodging, plans) */
.item {
  display: flex; gap: .8rem; padding: .9rem; margin-bottom: .6rem; background: var(--surface);
  border-radius: var(--radius); box-shadow: var(--shadow); cursor: pointer;
}
.item.needed { outline: 2px dashed var(--warn); outline-offset: -2px; }
.item.option { background: color-mix(in srgb, var(--surface) 70%, var(--surface-2)); }
.item-icon { flex: none; font-size: 1.4rem; width: 2rem; text-align: center; }
.item-main { flex: 1; min-width: 0; }
.item-top { display: flex; justify-content: space-between; gap: .6rem; align-items: baseline; }
.cost { font-weight: 700; white-space: nowrap; }
.notes { margin-top: .4rem; font-size: .9rem; white-space: pre-wrap; color: var(--muted); }
.chips { display: flex; flex-wrap: wrap; gap: .35rem; margin-top: .45rem; }
.chips:empty { display: none; }
.chip { font-size: .78rem; font-weight: 600; padding: .2rem .55rem; border-radius: 999px; background: var(--surface-2); color: var(--muted); border: 0; font-family: inherit; }
.chip.ok { background: var(--ok-bg); color: var(--ok); }
.chip.warn { background: var(--warn-bg); color: var(--warn); }
.chip.link { background: none; border: 1px solid var(--line); color: var(--primary); text-decoration: none; }
.chip.action { background: var(--primary); color: var(--primary-ink); cursor: pointer; }

.photos { display: flex; gap: .4rem; overflow-x: auto; margin-top: .6rem; padding-bottom: .2rem; }
.thumb {
  flex: none; width: 72px; height: 72px; border-radius: 10px; overflow: hidden; padding: 0; border: 0;
  background: var(--surface-2); cursor: pointer;
}
.thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }
.add-photo { display: grid; place-content: center; text-align: center; color: var(--muted); border: 1px dashed var(--line); background: none; }
.add-photo span { font-size: 1.2rem; line-height: 1; }
.add-photo small { font-size: .65rem; }

/* Lists */
.quick-add { display: flex; gap: .4rem; margin-bottom: .8rem; }
.quick-add input { flex: 1; min-width: 0; }
.quick-add select { width: auto; flex: none; max-width: 38%; }
.checklist { list-style: none; padding: 0; margin: 0; background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow); }
.checklist li { display: flex; align-items: center; border-bottom: 1px solid var(--line); }
.checklist li:last-child { border-bottom: 0; }
.checklist label { flex: 1; display: flex; align-items: center; gap: .7rem; padding: .7rem .9rem; cursor: pointer; }
.checklist input { width: 22px; height: 22px; accent-color: var(--primary); flex: none; }
.checklist .done span { text-decoration: line-through; color: var(--muted); }
.notes-box { width: 100%; }
.pack-actions { display: flex; flex-wrap: wrap; gap: .5rem; margin-top: 1rem; }
.progress { height: 8px; border-radius: 999px; background: var(--surface-2); overflow: hidden; margin-top: .4rem; }
.progress div { height: 100%; background: var(--ok); border-radius: 999px; }
.progress.over div { background: #c0392b; }

/* Costs */
.cost-total { display: flex; justify-content: space-between; align-items: baseline; padding: 1rem 1.1rem; background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow); }
.cost-total strong { font-size: 1.6rem; }
.cost-table { width: 100%; border-collapse: collapse; margin-top: .8rem; background: var(--surface); border-radius: var(--radius); overflow: hidden; box-shadow: var(--shadow); }
.cost-table td { padding: .65rem .9rem; border-bottom: 1px solid var(--line); }
.cost-table tr:last-child td { border-bottom: 0; }
.cost-table td:last-child { text-align: right; font-weight: 600; white-space: nowrap; }
.cost-table a { text-decoration: none; }

/* Forms */
input, select, textarea {
  width: 100%; font: inherit; font-size: 16px; color: var(--text); background: var(--surface);
  border: 1px solid var(--line); border-radius: 10px; padding: .6rem .7rem; min-height: 44px;
}
textarea { resize: vertical; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--primary); outline-offset: -1px; }

#sheet-root { position: fixed; inset: 0; z-index: 50; pointer-events: none; }
#sheet-root.open { pointer-events: auto; }
.sheet-backdrop { position: absolute; inset: 0; background: rgba(0, 0, 0, .4); opacity: 0; transition: opacity .2s; }
#sheet-root.open .sheet-backdrop { opacity: 1; }
.sheet {
  position: absolute; left: 0; right: 0; bottom: 0; max-height: 92vh; margin: 0 auto; max-width: 600px;
  display: flex; flex-direction: column; background: var(--bg); border-radius: 18px 18px 0 0;
  transform: translateY(100%); transition: transform .22s ease-out;
}
#sheet-root.open .sheet { transform: none; }
@media (min-width: 700px) {
  .sheet { bottom: auto; top: 50%; border-radius: 18px; transform: translateY(-40%); opacity: 0; transition: transform .2s, opacity .2s; }
  #sheet-root.open .sheet { transform: translateY(-50%); opacity: 1; }
}
.sheet-head { display: flex; justify-content: space-between; align-items: center; padding: 1rem 1rem .5rem; }
.sheet-head h2 { font-size: 1.2rem; }
.sheet-body { overflow-y: auto; padding: 0 1rem 1rem; }
.sheet-foot { display: flex; justify-content: space-between; align-items: center; padding: .7rem 1rem calc(.7rem + env(safe-area-inset-bottom)); border-top: 1px solid var(--line); }
.fields { display: flex; flex-wrap: wrap; gap: .8rem; }
.field { flex: 1 1 100%; display: flex; flex-direction: column; gap: .25rem; }
.field.half { flex: 1 1 calc(50% - .4rem); min-width: 130px; }
.field label { font-size: .85rem; font-weight: 600; color: var(--muted); }
.field small { color: var(--muted); font-size: .8rem; }
.money-input { position: relative; }
.money-input span { position: absolute; left: .7rem; top: 50%; transform: translateY(-50%); color: var(--muted); }
.money-input input { padding-left: 1.5rem; }
.check-row { flex: 1 1 100%; display: flex; align-items: center; gap: .6rem; font-weight: 600; min-height: 44px; }
.check-row input { width: 22px; height: 22px; min-height: 0; accent-color: var(--primary); }

.lightbox { position: absolute; inset: 0; background: rgba(0, 0, 0, .92); display: flex; flex-direction: column; align-items: center; justify-content: center; padding: 3.5rem 1rem 1rem; }
.lightbox img { max-width: 100%; max-height: calc(100% - 4rem); object-fit: contain; border-radius: 8px; }
.lb-close { position: absolute; top: calc(.8rem + env(safe-area-inset-top)); right: .8rem; background: rgba(255, 255, 255, .15); color: #fff; border: 0; }
.lb-bar { display: flex; gap: .5rem; margin-top: 1rem; max-width: 100%; }
.lb-bar .btn { max-width: 70vw; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

#toast {
  position: fixed; left: 50%; bottom: calc(1.2rem + env(safe-area-inset-bottom)); z-index: 60;
  transform: translate(-50%, 150%); background: var(--text); color: var(--bg); padding: .7rem 1.1rem;
  border-radius: 999px; font-weight: 600; font-size: .95rem; transition: transform .2s, visibility .2s; max-width: calc(100% - 32px);
  visibility: hidden;
}
#toast.show { transform: translate(-50%, 0); visibility: visible; }
#toast.error { background: #c0392b; color: #fff; }
