:root {
  --bg: #f4f1ea;
  --bg-elev: #ffffff;
  --text: #23291f;
  --text-muted: #6b7263;
  --border: #e2ddce;
  --accent: #2f6f4f;
  --accent-dark: #234f39;
  --accent-contrast: #ffffff;
  --danger: #b5423c;
  --pink: #a3406f;
  --cyan: #2c8090;
  --radius: 14px;
  --shadow: 0 1px 3px rgba(30, 30, 20, 0.08), 0 1px 2px rgba(30, 30, 20, 0.06);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #171b15;
    --bg-elev: #20251d;
    --text: #eceee6;
    --text-muted: #9aa294;
    --border: #333a2c;
    --accent: #52a878;
    --accent-dark: #6fc492;
    --accent-contrast: #0d130e;
    --danger: #e08079;
    --pink: #d989b3;
    --cyan: #7fd3e0;
    --shadow: 0 1px 3px rgba(0, 0, 0, 0.4), 0 1px 2px rgba(0, 0, 0, 0.3);
  }
}

* { box-sizing: border-box; }
/* Author rules like .btn/.modal/.grid2 set their own `display`, which otherwise beats the
   browser's default `[hidden]{display:none}` (author styles always outrank UA styles). */
[hidden] { display: none !important; }
html, body { margin: 0; padding: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  font-size: 15px;
  line-height: 1.4;
  -webkit-tap-highlight-color: transparent;
}
h1, h2, h3 { margin: 0 0 4px; }
p { margin: 0 0 8px; }
a { color: var(--accent-dark); }

.inp {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--bg-elev);
  color: var(--text);
  font-size: 15px;
  font-family: inherit;
}
.inp:focus { outline: 2px solid var(--accent); outline-offset: 1px; }
label { display: block; font-size: 13px; color: var(--text-muted); margin-bottom: 10px; }
label > .inp, label > select { margin-top: 4px; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 0 12px; }
.chk { display: flex; align-items: center; gap: 8px; font-size: 14px; }
.chk input { width: 18px; height: 18px; }
.hint { font-size: 12px; color: var(--text-muted); }

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  border: none;
  border-radius: 10px;
  padding: 10px 16px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  text-decoration: none;
  white-space: nowrap;
}
.btn-primary { background: var(--accent); color: var(--accent-contrast); }
.btn-primary:active { background: var(--accent-dark); }
.btn-secondary { background: var(--bg-elev); color: var(--text); border: 1px solid var(--border); }
.btn-danger { background: transparent; color: var(--danger); border: 1px solid var(--danger); }
.btn-ghost { background: transparent; color: var(--text); border: 1px solid var(--border); }
.btn-block { width: 100%; }
.btn-small { padding: 6px 10px; font-size: 12px; }

/* Top bar (desktop) */
.topbar {
  display: flex;
  align-items: center;
  gap: 20px;
  padding: 10px 20px;
  border-bottom: 1px solid var(--border);
  background: var(--bg-elev);
  position: sticky;
  top: 0;
  z-index: 20;
}
.brand { font-weight: 800; font-size: 17px; }
.tabs { display: none; gap: 4px; flex: 1; }
.tab {
  border: none; background: transparent; color: var(--text-muted);
  padding: 8px 14px; border-radius: 999px; font-size: 14px; font-weight: 600; cursor: pointer;
}
.tab.is-active { background: var(--accent); color: var(--accent-contrast); }
.user-menu { display: flex; align-items: center; gap: 10px; margin-left: auto; }
.user-name { font-size: 13px; color: var(--text-muted); }

/* Bottom nav (mobile) */
.bottomnav {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 20;
  display: flex; background: var(--bg-elev); border-top: 1px solid var(--border);
  padding-bottom: var(--safe-bottom);
}
.bn-item {
  flex: 1; border: none; background: transparent; color: var(--text-muted);
  display: flex; flex-direction: column; align-items: center; gap: 2px;
  padding: 8px 0 6px; font-size: 11px; cursor: pointer;
}
.bn-item span { font-size: 20px; }
.bn-item.is-active { color: var(--accent); }

@media (min-width: 760px) {
  .tabs { display: flex; }
  .bottomnav { display: none; }
  .content { padding-bottom: 24px !important; }
}

.content { max-width: 760px; margin: 0 auto; padding: 14px 14px calc(74px + var(--safe-bottom)); }

.toolbar { display: flex; gap: 8px; margin-bottom: 14px; flex-wrap: wrap; }
.searchbox { flex: 1; min-width: 140px; }

.empty { color: var(--text-muted); text-align: center; padding: 30px 10px; }

.cat-heading {
  font-size: 12px; font-weight: 700; text-transform: uppercase; letter-spacing: .04em;
  color: var(--text-muted); margin: 18px 2px 8px;
}
.cat-heading:first-child { margin-top: 4px; }

.cardlist { display: flex; flex-direction: column; gap: 8px; }
.card {
  display: flex; align-items: center; gap: 10px;
  background: var(--bg-elev); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 10px 12px; box-shadow: var(--shadow);
}
.thumb {
  width: 44px; height: 44px; flex: none; border-radius: 10px; object-fit: cover;
  background: #f2f0e8; border: 1px solid var(--border);
}
.thumb-placeholder { display: flex; align-items: center; justify-content: center; font-size: 20px; }
@media (prefers-color-scheme: dark) { .thumb { background: #2a3023; } }
.thumb-btn { padding: 0; border: none; background: none; cursor: pointer; flex: none; }

.seg { display: flex; gap: 4px; background: var(--bg); border-radius: 10px; padding: 3px; margin-bottom: 14px; }
.seg-btn {
  flex: 1; border: none; background: transparent; color: var(--text-muted);
  padding: 8px 6px; border-radius: 8px; font-size: 13px; font-weight: 600; cursor: pointer;
}
.seg-btn.is-active { background: var(--bg-elev); color: var(--text); box-shadow: var(--shadow); }

.icon-picker {
  display: flex; flex-wrap: wrap; gap: 6px; max-height: 130px; overflow-y: auto;
  padding: 8px; border: 1px solid var(--border); border-radius: 10px; background: var(--bg); margin-top: 4px;
}
.icon-chip {
  width: 34px; height: 34px; border-radius: 8px; border: 1px solid transparent; background: var(--bg-elev);
  font-size: 16px; cursor: pointer; display: flex; align-items: center; justify-content: center;
}
.icon-chip.is-active { border-color: var(--accent); background: color-mix(in srgb, var(--accent) 18%, var(--bg-elev)); }
.icon-chip[data-icon=""] { width: auto; padding: 0 10px; font-size: 12px; font-weight: 600; }
.card-main { flex: 1; min-width: 0; cursor: pointer; }
.card-title { font-weight: 600; display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.card-sub { font-size: 12px; color: var(--text-muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.card-meta { font-size: 12px; color: var(--text-muted); margin-top: 2px; }
.card-side { display: flex; flex-direction: column; align-items: flex-end; gap: 4px; }
.card-weight { font-variant-numeric: tabular-nums; font-weight: 700; font-size: 13px; }
.card-price { font-size: 11px; color: var(--text-muted); }
.mini-link { font-size: 12px; color: var(--accent-dark); text-decoration: none; background: none; border: none; cursor: pointer; padding: 0; }
.mini-danger { color: var(--danger); }

.badge {
  font-size: 10px; padding: 2px 6px; border-radius: 999px; font-weight: 700;
}
.badge-pink { background: color-mix(in srgb, var(--pink) 20%, transparent); color: var(--pink); }
.badge-cyan { background: color-mix(in srgb, var(--cyan) 20%, transparent); color: var(--cyan); }

.trip-card { cursor: pointer; }
.trip-actions { display: flex; gap: 8px; }

/* weight bar */
.weightbar { margin-bottom: 16px; background: var(--bg-elev); border: 1px solid var(--border); border-radius: var(--radius); padding: 12px; box-shadow: var(--shadow); }
.weightbar-empty { color: var(--text-muted); font-size: 13px; margin-bottom: 12px; }
.wtrack { display: flex; height: 14px; border-radius: 999px; overflow: hidden; background: var(--border); }
.wseg { height: 100%; }
.wlegend { display: flex; flex-wrap: wrap; gap: 8px 14px; margin-top: 10px; font-size: 12px; }
.wleg { display: flex; align-items: center; gap: 5px; color: var(--text-muted); }
.wdot { width: 8px; height: 8px; border-radius: 50%; display: inline-block; }
.wtotal { margin-top: 10px; font-size: 13px; text-align: right; }
.wpacked-row { display: flex; align-items: center; gap: 10px; margin-top: 10px; }
.wpacked-track { flex: 1; height: 8px; background: var(--border); border-radius: 999px; overflow: hidden; }
.wpacked-fill { height: 100%; background: var(--accent); transition: width .2s ease; }
.wpacked-label { font-size: 11px; color: var(--text-muted); white-space: nowrap; }

/* trip detail */
.trip-header { margin-bottom: 14px; }
.trip-header .btn-ghost { margin-bottom: 8px; }
.pack-row.is-packed { opacity: .55; }
.pack-row.is-packed .card-title { text-decoration: line-through; }
.pack-check { position: relative; display: inline-flex; }
.pack-check input { position: absolute; opacity: 0; width: 28px; height: 28px; margin: 0; cursor: pointer; }
.pack-check span {
  display: block; width: 28px; height: 28px; border-radius: 8px; border: 2px solid var(--border);
  background: var(--bg); transition: all .15s ease;
}
.pack-check input:checked + span { background: var(--accent); border-color: var(--accent); }
.pack-check input:checked + span::after {
  content: "✓"; display: block; text-align: center; line-height: 24px; color: var(--accent-contrast); font-weight: 900;
}

.add-gear-panel { margin-top: 18px; }
.addpanel-body { margin-top: 10px; }
.addpanel-body .searchbox { margin-bottom: 10px; }

/* modal */
.modal {
  position: fixed; inset: 0; background: rgba(0,0,0,.45); z-index: 50;
  display: flex; align-items: flex-end; justify-content: center;
}
@media (min-width: 600px) { .modal { align-items: center; } }
.modal-card {
  background: var(--bg-elev); width: 100%; max-width: 480px; max-height: 90vh; overflow-y: auto;
  border-radius: 18px 18px 0 0; padding: 18px; padding-bottom: calc(18px + var(--safe-bottom));
}
@media (min-width: 600px) { .modal-card { border-radius: 18px; } }
.modal-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 14px; }
.modal-close { border: none; background: var(--bg); width: 32px; height: 32px; border-radius: 50%; font-size: 15px; cursor: pointer; color: var(--text); }
.modal-actions { display: flex; justify-content: space-between; gap: 10px; margin-top: 16px; }

.toast {
  position: fixed; top: 12px; left: 50%; transform: translateX(-50%);
  background: var(--accent-dark); color: #fff; padding: 8px 16px; border-radius: 999px;
  font-size: 13px; z-index: 100; box-shadow: var(--shadow);
}
.alert { background: color-mix(in srgb, var(--danger) 15%, transparent); color: var(--danger); padding: 10px 12px; border-radius: 10px; font-size: 13px; margin-bottom: 12px; }

/* auth page */
.auth-body { display: flex; align-items: center; justify-content: center; min-height: 100vh; padding: 20px; }
.auth-card { width: 100%; max-width: 340px; background: var(--bg-elev); border: 1px solid var(--border); border-radius: var(--radius); padding: 26px; box-shadow: var(--shadow); text-align: center; }
.auth-logo { font-size: 40px; }
.auth-sub { color: var(--text-muted); font-size: 13px; margin-bottom: 16px; }
.auth-card label { text-align: left; }
.auth-note { font-size: 11px; color: var(--text-muted); margin-top: 14px; }
