:root {
  --bg: #f4f6f5;
  --surface: #ffffff;
  --surface-2: #eef2f0;
  --border: #dfe5e2;
  --text: #1c2422;
  --text-muted: #667169;
  --primary: #0f6e5e;
  --primary-dark: #0b5548;
  --primary-tint: #e3f3ee;
  --danger: #c8452f;
  --danger-tint: #fbe9e6;
  --radius: 14px;
  --radius-sm: 9px;
  --shadow: 0 2px 10px rgba(20, 30, 27, 0.06);
  --shadow-lg: 0 8px 30px rgba(20, 30, 27, 0.14);
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #121815;
    --surface: #1a2320;
    --surface-2: #212b27;
    --border: #2c3733;
    --text: #edf3f0;
    --text-muted: #9caea6;
    --primary: #2bbd9e;
    --primary-dark: #22a189;
    --primary-tint: #16332c;
    --danger: #e5735c;
    --danger-tint: #3a221d;
    --shadow: 0 2px 10px rgba(0, 0, 0, 0.3);
    --shadow-lg: 0 8px 30px rgba(0, 0, 0, 0.45);
  }
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  -webkit-tap-highlight-color: transparent;
}
h1, h2, h3, h4 { margin: 0 0 4px; line-height: 1.25; }
p { margin: 0 0 8px; }
.muted { color: var(--text-muted); font-size: 14px; }
button { font-family: inherit; cursor: pointer; }
input, select, textarea { font-family: inherit; font-size: 16px; }

/* ---------- Login ---------- */
.login-screen {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  background: linear-gradient(160deg, var(--primary-dark), var(--primary) 60%, #16967d);
}
.login-card {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 32px 28px;
  width: 100%;
  max-width: 340px;
  text-align: center;
  box-shadow: var(--shadow-lg);
}
.login-logo { font-size: 48px; margin-bottom: 8px; }
.login-card form { display: flex; flex-direction: column; gap: 10px; margin-top: 20px; }
.login-card input {
  padding: 12px 14px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text);
}
.login-card button {
  padding: 12px 14px;
  border-radius: var(--radius-sm);
  border: none;
  background: var(--primary);
  color: #fff;
  font-weight: 600;
  font-size: 16px;
}
.error-text { color: var(--danger); font-size: 13px; min-height: 18px; margin-top: 8px; }

/* ---------- App shell ---------- */
.app { min-height: 100vh; display: flex; flex-direction: column; padding-bottom: 70px; }
.topbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 18px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}
.topbar-brand { font-weight: 800; font-size: 18px; display: flex; align-items: center; gap: 6px; cursor: pointer; }
.topbar-nav { display: none; gap: 6px; }
@media (min-width: 720px) {
  .topbar-nav { display: flex; }
  .bottombar { display: none !important; }
  .app { padding-bottom: 0; }
}
.nav-btn {
  background: none; border: none; color: var(--text-muted); font-weight: 600;
  padding: 8px 14px; border-radius: 999px; font-size: 14px;
}
.nav-btn.active { background: var(--primary-tint); color: var(--primary-dark); }

.bottombar {
  position: fixed; bottom: 0; left: 0; right: 0; z-index: 20;
  display: flex; background: var(--surface); border-top: 1px solid var(--border);
  padding: 6px 6px calc(6px + env(safe-area-inset-bottom));
}
.bottombar .nav-btn { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 2px; font-size: 12px; padding: 6px; }
.bottombar .nav-btn span { font-size: 20px; }

.view { flex: 1; padding: 16px; max-width: 720px; margin: 0 auto; width: 100%; }

/* ---------- Cards / lists ---------- */
.card {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 16px;
  box-shadow: var(--shadow);
  margin-bottom: 12px;
}
.trip-card { display: block; width: 100%; text-align: left; border: none; background: var(--surface); }
.trip-card-head { display: flex; align-items: center; gap: 10px; }
.trip-card-icon { font-size: 26px; }
.trip-card-title { font-weight: 700; font-size: 16px; }
.trip-card-meta { font-size: 13px; color: var(--text-muted); margin-top: 2px; }
.progress-bar { height: 8px; border-radius: 999px; background: var(--surface-2); margin-top: 12px; overflow: hidden; }
.progress-bar-fill { height: 100%; background: var(--primary); border-radius: 999px; transition: width .25s; }
.progress-label { font-size: 12px; color: var(--text-muted); margin-top: 6px; text-align: right; }

.empty-state { text-align: center; padding: 40px 16px; color: var(--text-muted); }
.empty-state .icon { font-size: 44px; margin-bottom: 10px; }

.fab {
  position: fixed; right: 20px; bottom: 86px; z-index: 15;
  width: 56px; height: 56px; border-radius: 50%;
  background: var(--primary); color: #fff; border: none;
  font-size: 26px; box-shadow: var(--shadow-lg);
  display: flex; align-items: center; justify-content: center;
}
@media (min-width: 720px) { .fab { bottom: 24px; } }

/* ---------- Forms ---------- */
.field { margin-bottom: 16px; }
.field label { display: block; font-weight: 600; font-size: 14px; margin-bottom: 6px; }
.field input[type=text], .field input[type=number], .field input[type=date], .field select, .field textarea {
  width: 100%; padding: 11px 12px; border-radius: var(--radius-sm);
  border: 1px solid var(--border); background: var(--surface); color: var(--text);
}
.chip-group { display: flex; flex-wrap: wrap; gap: 8px; }
.chip {
  padding: 9px 14px; border-radius: 999px; border: 1px solid var(--border);
  background: var(--surface); font-size: 14px; font-weight: 600; color: var(--text-muted);
  display: flex; align-items: center; gap: 6px;
}
.chip.selected { background: var(--primary); border-color: var(--primary); color: #fff; }
.color-chip { width: 30px; height: 30px; border-radius: 50%; border: 2px solid var(--border); padding: 0; }
.color-chip.selected { border-color: var(--primary); box-shadow: 0 0 0 2px var(--primary-tint); }

.btn { padding: 12px 18px; border-radius: var(--radius-sm); border: none; font-weight: 700; font-size: 15px; }
.btn-primary { background: var(--primary); color: #fff; width: 100%; }
.btn-secondary { background: var(--surface-2); color: var(--text); }
.btn-danger { background: var(--danger-tint); color: var(--danger); }
.btn-ghost { background: none; color: var(--primary); font-weight: 600; }
.btn-block { width: 100%; }
.btn-row { display: flex; gap: 10px; margin-top: 18px; }
.btn-row .btn { flex: 1; }
.btn[disabled] { opacity: .5; }

/* ---------- Header w/ back ---------- */
.page-head { display: flex; align-items: center; gap: 10px; margin-bottom: 16px; }
.back-btn { background: var(--surface); border: 1px solid var(--border); border-radius: 50%; width: 36px; height: 36px; font-size: 16px; }

/* ---------- Trip detail ---------- */
.trip-hero { margin-bottom: 14px; }
.trip-hero-meta { display: flex; gap: 14px; flex-wrap: wrap; margin-top: 8px; font-size: 13px; color: var(--text-muted); }
.tabs { display: flex; gap: 6px; overflow-x: auto; padding-bottom: 4px; margin-bottom: 12px; }
.tabs::-webkit-scrollbar { display: none; }
.tab-btn {
  flex: none; padding: 9px 14px; border-radius: 999px; border: 1px solid var(--border);
  background: var(--surface); font-size: 14px; font-weight: 600; white-space: nowrap;
}
.tab-btn.active { background: var(--primary); border-color: var(--primary); color: #fff; }

.category-group { margin-bottom: 18px; }
.category-title { font-size: 12px; font-weight: 700; text-transform: uppercase; letter-spacing: .04em; color: var(--text-muted); margin-bottom: 8px; }

.item-row {
  display: flex; align-items: center; gap: 12px;
  background: var(--surface); border-radius: var(--radius-sm); padding: 10px 12px; margin-bottom: 8px;
  box-shadow: var(--shadow);
}
.item-row.packed { opacity: .55; }
.item-checkbox {
  width: 26px; height: 26px; border-radius: 50%; border: 2px solid var(--border);
  background: var(--surface); flex: none; display: flex; align-items: center; justify-content: center; color: #fff; font-size: 14px;
}
.item-checkbox.checked { background: var(--primary); border-color: var(--primary); }
.item-thumb { width: 38px; height: 38px; border-radius: 8px; object-fit: cover; flex: none; background: var(--surface-2); }
.item-info { flex: 1; min-width: 0; }
.item-name { font-weight: 600; font-size: 14.5px; }
.item-name.packed { text-decoration: line-through; }
.item-sub { font-size: 12px; color: var(--text-muted); }
.qty-stepper { display: flex; align-items: center; gap: 6px; flex: none; }
.qty-stepper button { width: 26px; height: 26px; border-radius: 50%; border: 1px solid var(--border); background: var(--surface-2); font-weight: 700; }
.qty-stepper span { min-width: 18px; text-align: center; font-weight: 600; font-size: 14px; }
.item-delete { background: none; border: none; color: var(--text-muted); font-size: 16px; padding: 4px; flex: none; }

/* ---------- Library ---------- */
.lib-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(110px, 1fr)); gap: 10px; }
.lib-card { background: var(--surface); border-radius: var(--radius-sm); overflow: hidden; box-shadow: var(--shadow); position: relative; }
.lib-card img { width: 100%; aspect-ratio: 1; object-fit: cover; display: block; background: var(--surface-2); }
.lib-card-info { padding: 6px 8px 8px; }
.lib-card-name { font-size: 12.5px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.lib-card-color { display: flex; align-items: center; gap: 5px; font-size: 11px; color: var(--text-muted); margin-top: 2px; }
.dot { width: 10px; height: 10px; border-radius: 50%; border: 1px solid rgba(0,0,0,.15); flex: none; }
.lib-card-del {
  position: absolute; top: 6px; right: 6px; background: rgba(20,20,20,.55); color: #fff;
  border: none; border-radius: 50%; width: 24px; height: 24px; font-size: 13px;
}
.lib-card.selectable { cursor: pointer; border: 2px solid transparent; }
.lib-card.selectable.selected { border-color: var(--primary); }
.lib-card-check {
  position: absolute; top: 6px; left: 6px; width: 22px; height: 22px; border-radius: 50%;
  background: rgba(255,255,255,.85); border: 2px solid var(--border); display: flex; align-items: center; justify-content: center; font-size: 12px;
}
.lib-card.selected .lib-card-check { background: var(--primary); border-color: var(--primary); color: #fff; }

/* ---------- Sheet / modal ---------- */
.sheet-backdrop {
  position: fixed; inset: 0; background: rgba(10, 16, 14, .45); z-index: 40;
  display: flex; align-items: flex-end; justify-content: center;
}
@media (min-width: 720px) { .sheet-backdrop { align-items: center; } }
.sheet {
  background: var(--surface); width: 100%; max-width: 480px; max-height: 88vh; overflow-y: auto;
  border-radius: 18px 18px 0 0; padding: 20px; box-shadow: var(--shadow-lg);
}
@media (min-width: 720px) { .sheet { border-radius: 18px; } }
.sheet-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 14px; }
.sheet-close { background: var(--surface-2); border: none; border-radius: 50%; width: 30px; height: 30px; font-size: 15px; }

/* ---------- Toast ---------- */
.toast {
  position: fixed; bottom: 90px; left: 50%; transform: translateX(-50%) translateY(20px);
  background: #1c2422; color: #fff; padding: 10px 18px; border-radius: 999px; font-size: 13.5px;
  opacity: 0; pointer-events: none; transition: all .25s; z-index: 60; max-width: 90vw; text-align: center;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

/* ---------- Misc ---------- */
.section-title { font-size: 15px; font-weight: 700; margin: 22px 0 10px; }
.section-title:first-child { margin-top: 0; }
.list-row { display: flex; align-items: center; justify-content: space-between; background: var(--surface); border-radius: var(--radius-sm); padding: 12px 14px; margin-bottom: 8px; box-shadow: var(--shadow); }
.list-row-title { font-weight: 600; font-size: 14.5px; }
.icon-btn { background: var(--surface-2); border: none; border-radius: 8px; padding: 6px 10px; font-size: 13px; }
.upload-drop {
  border: 2px dashed var(--border); border-radius: var(--radius-sm); padding: 24px; text-align: center;
  color: var(--text-muted); font-size: 14px; position: relative; overflow: hidden;
}
.upload-drop input[type=file] { position: absolute; inset: 0; opacity: 0; cursor: pointer; }
.upload-preview { width: 100%; max-width: 200px; border-radius: var(--radius-sm); margin: 0 auto 10px; display: block; }
