:root {
  --bg: #F4F1EA;          /* chalk */
  --surface: #FFFFFF;
  --surface-2: #ECE8DE;
  --ink: #1D1F21;
  --ink-2: #5C5F63;
  --ink-3: #8B8E91;
  --line: #DDD8CC;
  --accent: #D9531E;      /* belay-loop orange */
  --accent-ink: #FFFFFF;
  --ok: #2F7D4F;
  --ok-bg: #E2F1E7;
  --warn: #A56A00;
  --warn-bg: #FBEFD3;
  --bad: #B3261E;
  --bad-bg: #F9DEDC;
  --muted-bg: #ECE8DE;
  --shadow: 0 1px 2px rgba(30, 25, 15, .06), 0 4px 16px rgba(30, 25, 15, .06);
  --radius: 14px;
  --font: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, system-ui, sans-serif;
  --font-display: ui-rounded, "SF Pro Rounded", -apple-system, "Segoe UI", system-ui, sans-serif;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #16181A;
    --surface: #1F2225;
    --surface-2: #2A2E32;
    --ink: #ECEAE5;
    --ink-2: #A9ACAF;
    --ink-3: #7B7F83;
    --line: #33373B;
    --accent: #F06A33;
    --ok: #6CC58F;
    --ok-bg: #1D3226;
    --warn: #E9B44C;
    --warn-bg: #3A2F17;
    --bad: #F2867E;
    --bad-bg: #3D1F1D;
    --muted-bg: #2A2E32;
    --shadow: 0 1px 2px rgba(0,0,0,.3), 0 6px 20px rgba(0,0,0,.25);
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 16px/1.4 var(--font);
  -webkit-font-smoothing: antialiased;
  min-height: 100dvh;
}
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; -webkit-tap-highlight-color: transparent; }
.boot { display: grid; place-items: center; height: 100dvh; color: var(--ink-3); }

/* ───── Layout ───── */
.wrap {
  max-width: 1100px;
  margin: 0 auto;
  padding: calc(env(safe-area-inset-top) + 12px) max(16px, env(safe-area-inset-right)) calc(env(safe-area-inset-bottom) + 96px) max(16px, env(safe-area-inset-left));
}
.topbar { display: flex; align-items: center; gap: 12px; padding: 8px 0 16px; }
.brand { display: flex; align-items: center; gap: 10px; flex: 1; min-width: 0; }
.brand img { width: 36px; height: 36px; border-radius: 9px; }
.brand h1 { font: 700 24px/1.1 var(--font-display); margin: 0; letter-spacing: -.01em; }
.brand small { display: block; color: var(--ink-3); font-size: 13px; font-weight: 500; }

.icon-btn {
  width: 42px; height: 42px; border-radius: 12px; border: 1px solid var(--line);
  background: var(--surface); display: grid; place-items: center; flex: none;
}
.icon-btn svg { width: 22px; height: 22px; }

/* ───── Summary tiles ───── */
.tiles { display: grid; grid-template-columns: repeat(4, 1fr); gap: 10px; margin-bottom: 16px; }
@media (max-width: 640px) { .tiles { grid-template-columns: repeat(2, 1fr); } }
.tile {
  text-align: left; border: 1px solid var(--line); background: var(--surface);
  border-radius: var(--radius); padding: 12px 14px; box-shadow: var(--shadow);
}
.tile b { display: block; font: 700 28px/1.1 var(--font-display); font-variant-numeric: tabular-nums; }
.tile span { color: var(--ink-2); font-size: 13px; font-weight: 500; }
.tile.bad b { color: var(--bad); }
.tile.warn b { color: var(--warn); }
.tile.active { outline: 2px solid var(--accent); outline-offset: -1px; }

/* ───── Toolbar ───── */
.toolbar { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; margin-bottom: 14px; }
.search {
  flex: 1 1 240px; display: flex; align-items: center; gap: 8px; padding: 0 12px;
  background: var(--surface); border: 1px solid var(--line); border-radius: 12px; height: 44px;
}
.search svg { width: 18px; height: 18px; color: var(--ink-3); flex: none; }
.search input { border: 0; outline: 0; background: transparent; flex: 1; min-width: 0; font-size: 16px; }
.chips { display: flex; gap: 6px; overflow-x: auto; scrollbar-width: none; -webkit-overflow-scrolling: touch; max-width: 100%; }
.chips::-webkit-scrollbar { display: none; }
.chip {
  border: 1px solid var(--line); background: var(--surface); border-radius: 999px;
  padding: 8px 14px; font-size: 14px; font-weight: 600; white-space: nowrap; color: var(--ink-2);
}
.chip[aria-pressed="true"] { background: var(--ink); color: var(--bg); border-color: var(--ink); }
.sort { height: 44px; border-radius: 12px; border: 1px solid var(--line); background: var(--surface); padding: 0 10px; font-size: 14px; }

/* ───── Gear list ───── */
.list { display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: 10px; }
.group-h { grid-column: 1 / -1; display: flex; align-items: center; justify-content: space-between; gap: 8px; font: 700 13px/1 var(--font); text-transform: uppercase; letter-spacing: .08em; color: var(--ink-3); margin: 14px 2px 2px; }
.group-add { display: inline-flex; align-items: center; gap: 4px; border: 0; background: none; color: var(--accent); font: 650 14px/1 var(--font); letter-spacing: 0; text-transform: none; padding: 6px 4px; }
.group-add svg { width: 15px; height: 15px; }
.brand-list { list-style: none; margin: 0; padding: 0; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); }
.brand-list li { display: flex; align-items: center; gap: 8px; padding: 10px 12px; border-top: 1px solid var(--line); }
.brand-list li:first-child { border-top: 0; }
.brand-list li > div { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.brand-list li span { font-size: 13px; color: var(--ink-3); }
.brand-list .btn { height: 38px; padding: 0 12px; font-size: 14px; }
.field #f_brand_new { margin-top: 8px; }
.card {
  text-align: left; width: 100%; border: 1px solid var(--line); background: var(--surface);
  border-radius: var(--radius); padding: 14px; box-shadow: var(--shadow);
  display: grid; grid-template-columns: 1fr auto; gap: 4px 10px;
}
.card:active { transform: scale(.995); }
.card .name { font-weight: 650; font-size: 16px; line-height: 1.25; }
.card .meta { color: var(--ink-2); font-size: 13px; grid-column: 1 / -1; display: flex; gap: 6px 10px; flex-wrap: wrap; align-items: center; }
.card .qty { font: 700 15px/1.25 var(--font-display); color: var(--ink-2); font-variant-numeric: tabular-nums; }
.card .status { grid-column: 1 / -1; display: flex; flex-direction: column; gap: 4px; margin-top: 6px; }
.card.retired { opacity: .62; }

.line { display: flex; align-items: center; gap: 8px; font-size: 13.5px; color: var(--ink-2); }
.dot { width: 8px; height: 8px; border-radius: 50%; background: var(--ink-3); flex: none; }
.line.ok .dot { background: var(--ok); }
.line.warn { color: var(--warn); } .line.warn .dot { background: var(--warn); }
.line.bad { color: var(--bad); font-weight: 600; } .line.bad .dot { background: var(--bad); }

.pill { display: inline-block; font-size: 12px; font-weight: 600; padding: 2px 8px; border-radius: 999px; background: var(--muted-bg); color: var(--ink-2); }
.pill.soft { background: #E6EEF7; color: #2C5A8A; }
.pill.hard { background: #ECE6F3; color: #5B3F86; }
@media (prefers-color-scheme: dark) {
  .pill.soft { background: #1E2B3A; color: #9CC3EC; }
  .pill.hard { background: #2A2236; color: #C7B2EA; }
}
.pill.cond-fair, .pill.cond-worn { background: var(--warn-bg); color: var(--warn); }
.pill.cond-retire { background: var(--bad-bg); color: var(--bad); }

.empty { text-align: center; padding: 48px 16px; color: var(--ink-2); grid-column: 1 / -1; }
.empty h2 { color: var(--ink); font: 700 20px var(--font-display); margin: 0 0 6px; }
.empty .row { justify-content: center; margin-top: 16px; }

.fab {
  position: fixed; right: max(18px, env(safe-area-inset-right)); bottom: calc(env(safe-area-inset-bottom) + 18px);
  background: var(--accent); color: var(--accent-ink); border: 0; border-radius: 999px;
  padding: 0 20px 0 16px; height: 54px; display: flex; align-items: center; gap: 6px;
  font-weight: 700; font-size: 16px; box-shadow: 0 6px 20px rgba(217, 83, 30, .35);
}
.fab svg { width: 22px; height: 22px; }

/* ───── Buttons & forms ───── */
.btn {
  border: 1px solid var(--line); background: var(--surface); border-radius: 12px;
  height: 46px; padding: 0 16px; font-weight: 650; display: inline-flex; align-items: center; justify-content: center; gap: 6px;
}
a.btn { text-decoration: none; color: inherit; text-align: center; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.danger { color: var(--bad); }
.btn.ghost { background: transparent; }
.btn.block { width: 100%; }
.btn:disabled { opacity: .5; }
.row { display: flex; gap: 10px; flex-wrap: wrap; }
.row > .btn { flex: 1 1 140px; }

.field { display: flex; flex-direction: column; gap: 6px; margin-bottom: 14px; }
.field label, .lbl { font-size: 13px; font-weight: 600; color: var(--ink-2); }
.field input, .field select, .field textarea {
  border: 1px solid var(--line); background: var(--surface); border-radius: 11px;
  padding: 11px 12px; font-size: 16px; width: 100%; min-height: 46px;
}
.field textarea { min-height: 80px; resize: vertical; }
.field input:focus, .field select:focus, .field textarea:focus { outline: 2px solid var(--accent); outline-offset: -1px; border-color: transparent; }
.field .hint { font-size: 12.5px; color: var(--ink-3); }
.grid2 { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 0 12px; }
.grid2 > .field { min-width: 0; }
.field input[type=date] { min-width: 0; -webkit-appearance: none; appearance: none; }
.inline { display: flex; gap: 8px; align-items: center; }
.inline input { flex: 1; }
.check { display: flex; align-items: center; gap: 10px; font-size: 15px; color: var(--ink); font-weight: 500; }
.field .check input { width: 22px; height: 22px; min-height: 0; flex: none; accent-color: var(--accent); }
.linkish { background: none; border: 0; color: var(--accent); font-weight: 600; padding: 4px 0; font-size: 13px; }

.seg { display: flex; background: var(--surface-2); border-radius: 12px; padding: 3px; gap: 3px; }
.seg button { flex: 1; border: 0; background: transparent; border-radius: 9px; height: 40px; font-weight: 600; color: var(--ink-2); }
.seg button[aria-pressed="true"] { background: var(--surface); color: var(--ink); box-shadow: var(--shadow); }

/* ───── Sheet (dialog) ───── */
.sheet {
  border: 0; padding: 0; background: var(--bg); color: var(--ink);
  width: min(560px, 100vw); max-width: 100vw; max-height: min(92dvh, 900px);
  border-radius: 20px; box-shadow: 0 20px 60px rgba(0,0,0,.3);
}
.sheet::backdrop { background: rgba(10, 10, 10, .45); }
@media (max-width: 640px) {
  .sheet { margin: auto 0 0 0; width: 100vw; border-radius: 20px 20px 0 0; max-height: 94dvh; }
}
.sheet-body { padding: 18px 18px calc(env(safe-area-inset-bottom) + 18px); overflow-y: auto; max-height: inherit; }
.sheet-head { display: flex; align-items: flex-start; gap: 12px; margin-bottom: 16px; }
.sheet-head h2 { font: 700 22px/1.2 var(--font-display); margin: 0; flex: 1; }
.sheet-head .sub { color: var(--ink-2); font-size: 14px; margin-top: 4px; }
.close { width: 36px; height: 36px; border-radius: 50%; border: 0; background: var(--surface-2); display: grid; place-items: center; flex: none; }
.close svg { width: 18px; height: 18px; }

.facts { display: grid; grid-template-columns: 1fr 1fr; gap: 1px; background: var(--line); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; margin-bottom: 14px; }
.facts div { background: var(--surface); padding: 10px 12px; }
.facts dt { font-size: 12px; color: var(--ink-3); font-weight: 600; }
.facts dd { margin: 2px 0 0; font-weight: 600; font-variant-numeric: tabular-nums; }
.box { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px 14px; margin-bottom: 14px; }
.box h3 { margin: 0 0 8px; font-size: 13px; text-transform: uppercase; letter-spacing: .07em; color: var(--ink-3); }
.notes { white-space: pre-wrap; }
.hist { list-style: none; margin: 0; padding: 0; }
.hist li { padding: 8px 0; border-top: 1px solid var(--line); font-size: 14px; }
.hist li:first-child { border-top: 0; }
.hist .when { font-weight: 650; }
.hist .fail { color: var(--bad); font-weight: 650; }

.section-h { font-size: 13px; text-transform: uppercase; letter-spacing: .07em; color: var(--ink-3); margin: 18px 0 8px; font-weight: 700; }
.note { font-size: 14px; color: var(--ink-2); background: var(--surface-2); border-radius: 12px; padding: 10px 12px; margin-bottom: 12px; }
.note.warn { background: var(--warn-bg); color: var(--warn); }
.note.ok { background: var(--ok-bg); color: var(--ok); }

/* ───── Auth ───── */
.auth { max-width: 400px; margin: 0 auto; padding: calc(env(safe-area-inset-top) + 10vh) 20px 40px; }
.auth .logo { width: 72px; height: 72px; border-radius: 18px; margin-bottom: 14px; box-shadow: var(--shadow); }
.auth h1 { font: 800 30px/1.1 var(--font-display); margin: 0 0 6px; }
.auth p { color: var(--ink-2); margin: 0 0 24px; }
.err { color: var(--bad); font-size: 14px; margin: -4px 0 12px; }

/* ───── Toast ───── */
#toast {
  position: fixed; left: 50%; bottom: calc(env(safe-area-inset-bottom) + 86px); transform: translate(-50%, 20px);
  background: var(--ink); color: var(--bg); padding: 10px 16px; border-radius: 12px; font-weight: 600; font-size: 14px;
  opacity: 0; pointer-events: none; transition: .2s; max-width: calc(100vw - 32px); text-align: center; z-index: 10;
}
#toast.show { opacity: 1; transform: translate(-50%, 0); }
