:root {
  --primary: #1b2a4a;
  --primary-dark: #121f38;
  --secondary: #f2a900;
  --accent: #d32f2f;
  --bg: #e9eef4;
  --panel: #ffffff;
  --ink: #16202f;
  --muted: #7b8798;
  --metal: #aeb6c2;
  --metal-dark: #6b7383;
  --steel: #59616f;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --tb-h: calc(62px + var(--safe-bottom));
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; padding: 0; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--ink);
  min-height: 100vh;
}

.app { padding: calc(20px + var(--safe-top)) 16px calc(var(--tb-h) + 24px); max-width: 560px; margin: 0 auto; }

/* ---------- Screens ---------- */
.screen { display: none; animation: fade .25s ease; }
.screen.active { display: block; }
@keyframes fade { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }

.app-head { margin-bottom: 18px; }
.app-head.small { margin-bottom: 12px; }
.brand-mark { position: relative; width: 30px; height: 30px; margin-bottom: 6px; }
.brand-mark .ring { position: absolute; inset: 0; border: 3px solid var(--secondary); border-radius: 50%; }
.brand-mark .ring-a { transform: rotate(20deg); }
.brand-mark .ring-b { border-color: var(--accent); transform: rotate(-15deg) scale(.6); }
.app-head h1, .app-head h2 { margin: 0; font-size: 26px; letter-spacing: -.5px; color: var(--primary); }
.app-head.small h2 { font-size: 20px; }
.app-sub { margin: 2px 0 0; font-size: 12px; text-transform: uppercase; letter-spacing: 1.5px; color: var(--muted); font-weight: 600; }

/* ---------- Dashboard rail + key tag counters ---------- */
.rail { position: relative; background: linear-gradient(180deg, #6b7383, #3a414e 18%, #7d8493 38%, #2c323c); border-radius: 6px; padding: 16px 10px 26px; box-shadow: 0 3px 8px rgba(0,0,0,.25); }
.rail::before { content: ""; position: absolute; left: 0; right: 0; top: 8px; height: 4px; background: repeating-linear-gradient(90deg, rgba(255,255,255,.28) 0 8px, transparent 8px 14px); }
.dash-rail { display: flex; justify-content: space-around; align-items: flex-start; }
.dash-counter { width: 92px; text-align: center; }
.split { height: 18px; position: relative; }
.split .ringi { position: absolute; left: 50%; top: 0; width: 16px; height: 16px; transform: translateX(-50%); border: 2.5px solid #d7dde6; border-radius: 50%; background: transparent; }
.dash-counter .tag {
  position: relative; background: linear-gradient(180deg, #eef1f5, #c9cfd9); border-radius: 6px; padding: 10px 6px 8px; color: #2b3140; box-shadow: inset 0 1px 0 #fff, 0 2px 3px rgba(0,0,0,.4); border: 1px solid #8f97a6;
}
.dash-counter .hole { position: absolute; top: 6px; left: 50%; transform: translateX(-50%); width: 12px; height: 12px; border-radius: 50%; background: var(--metal-dark); box-shadow: inset 0 1px 3px rgba(0,0,0,.6); }
.dash-counter .glyph { width: 26px; height: 26px; margin: 14px auto 4px; opacity: .85; }
.dash-counter .num { font-size: 30px; font-weight: 800; letter-spacing: -.5px; text-shadow: 0 1px 0 rgba(255,255,255,.5); }
.dash-counter.danger .tag { background: linear-gradient(180deg, #f4d4d4, #e0a9a9); border-color: #b56a6a; }
.dash-counter.danger .glyph { color: var(--accent); }
.dash-counter.danger .num { color: var(--accent); }

/* engraved glyphs */
.glyph.clipboard::before { content: "▣"; font-size: 22px; color: #5a6273; }
.glyph.shield::before { content: "⬢"; font-size: 22px; color: #4a8f6b; }
.glyph.warn::before { content: "▲"; font-size: 22px; color: var(--accent); }

/* recent hooks */
.recent-block { margin-top: 24px; }
.rail-label { display: flex; justify-content: space-between; font-size: 11px; text-transform: uppercase; letter-spacing: 1px; color: var(--muted); font-weight: 700; margin-bottom: 10px; }
.hook-rail { position: relative; padding-top: 6px; }
.hook-rail::before { content: ""; position: absolute; top: 0; left: 6px; right: 6px; height: 5px; border-radius: 3px; background: linear-gradient(180deg, #8f97a6, #5b6270); box-shadow: 0 2px 3px rgba(0,0,0,.25); }
.recent-list { display: flex; flex-direction: column; gap: 12px; padding-top: 4px; }

/* ---------- Tag cards ---------- */
.tag-list { display: flex; flex-direction: column; gap: 12px; }
.tag-card {
  position: relative; overflow: hidden; border-radius: 8px; background: linear-gradient(180deg, #ffe27a, #f2c925); border: 2px solid var(--accent); border-top-width: 3px; box-shadow: 0 2px 6px rgba(0,0,0,.18); padding: 10px 14px 12px; color: #3a2f00;
}
.tag-card .zip {
  position: absolute; top: 0; left: 50%; transform: translateX(-50%) translateY(-50%); width: 8px; height: 14px; border-radius: 3px;
}
.zip.pending { background: repeating-linear-gradient(45deg,#f2a900,#f2a900 3px,#ffd24d 3px,#ffd24d 6px); }
.zip.progress { background: repeating-linear-gradient(45deg,#2f7fd3,#2f7fd3 3px,#6ba7e8 3px,#6ba7e8 6px); }
.zip.passed { background: repeating-linear-gradient(45deg,#3c9b5f,#3c9b5f 3px,#7fc79a 3px,#7fc79a 6px); }
.zip.failed { background: repeating-linear-gradient(45deg,#c92f2f,#c92f2f 3px,#ef7d7d 3px,#ef7d7d 6px); }

.tag-card .shook { position: absolute; top: -2px; left: -2px; width: 12px; height: 12px; border: 2px solid var(--accent); border-top: none; border-left: none; border-radius: 0 0 4px 0; transform: rotate(-30deg); }
.tag-card .tagtop { display: flex; align-items: baseline; justify-content: space-between; gap: 8px; }
.tag-card .address { font-size: 15px; font-weight: 800; color: #2c2500; margin: 0; }
.tag-card .address i { font-style: normal; }
.tag-card .stamp { font-family: "Courier New", monospace; font-size: 11px; font-weight: 700; letter-spacing: .5px; color: #6b5c00; border: 1px dashed #a58d00; border-radius: 3px; padding: 2px 5px; background: rgba(255,255,255,.4); text-transform: uppercase; }
.tag-card .meta { display: flex; justify-content: space-between; align-items: center; margin-top: 6px; }
.tag-card .inspector { font-size: 12px; color: #6b5f14; font-weight: 600; }
.tag-card .status-lbl { font-size: 10px; font-weight: 800; text-transform: uppercase; letter-spacing: .5px; padding: 2px 7px; border-radius: 3px; color: #fff; }
.status-lbl.Pending { background: var(--secondary); color: #2c2500; }
.status-lbl.In\ Progress { background: #2f7fd3; }
.status-lbl.Passed { background: #3c9b5f; }
.status-lbl.Failed { background: var(--accent); }

/* swipe delete */
.swipe-wrap { position: relative; border-radius: 8px; overflow: hidden; }
.swipe-delete { position: absolute; top: 0; right: 0; bottom: 0; width: 72px; background: var(--accent); display: flex; align-items: center; justify-content: center; color: #fff; transform: translateX(100%); }
.swipe-delete svg { width: 26px; height: 26px; }
.tag-card { transition: transform .2s ease; touch-action: pan-y; }

/* ---------- Completed (faded) ---------- */
.completed-list .tag-card { background: linear-gradient(180deg, #d9dee6, #c2cad5); border-color: #9aa3b1; color: #6b7383; box-shadow: none; filter: saturate(.6); opacity: .85; }
.completed-list .tag-card.passed { background: linear-gradient(180deg, #eef6f0, #cfe7d7); border-color: #8fb89c; }
.completed-list .tag-card.passed::after { content: ""; position: absolute; inset: 0; background: linear-gradient(135deg, rgba(255,255,255,.5), transparent 55%); pointer-events: none; }
.completed-list .stamp, .completed-list .inspector, .completed-list .address { color: #6b7383; border-color: #9aa3b1; }
.date-group-label { font-size: 11px; text-transform: uppercase; letter-spacing: 1px; color: var(--muted); font-weight: 700; margin: 18px 4px 8px; }
.date-group-label:first-child { margin-top: 0; }

/* ---------- Search & chips ---------- */
.search-wrap { margin-bottom: 10px; }
.search-wrap input {
  width: 100%; padding: 13px 14px; border: 1px solid #ccd3de; border-radius: 10px; font-size: 16px; background: var(--panel); color: var(--ink); box-shadow: inset 0 1px 3px rgba(0,0,0,.05);
}
.chips { display: flex; gap: 8px; overflow-x: auto; padding-bottom: 4px; margin-bottom: 14px; scrollbar-width: none; }
.chips::-webkit-scrollbar { display: none; }
.chip { flex: 0 0 auto; padding: 9px 14px; border-radius: 999px; border: 1px solid #ccd3de; background: var(--panel); color: var(--steel); font-size: 13px; font-weight: 600; }
.chip.active { background: var(--primary); border-color: var(--primary); color: #fff; }

/* ---------- Ghost rail empty state ---------- */
.ghost-rail { margin-top: 30px; padding: 26px 16px; border-radius: 10px; border: 2px dashed #ccd3de; text-align: center; }
.ghost-rail::before { content: ""; display: block; width: 70%; height: 4px; margin: 0 auto 20px; border-radius: 3px; background: linear-gradient(180deg, #ccd3de, #aeb6c2); opacity: .7; }
.ghost-tag { width: 34px; height: 42px; margin: 0 auto; background: linear-gradient(180deg,#e6eaf0,#c9cfd9); border-radius: 5px; border: 1px solid #b7bfcc; position: relative; transform: rotate(-6deg); }
.ghost-tag .hole { position: absolute; top: 6px; left: 50%; transform: translateX(-50%); width: 8px; height: 8px; border-radius: 50%; background: #b7bfcc; }
.ghost-copy { margin: 16px 0 0; color: var(--muted); font-size: 14px; }

/* ---------- Form ---------- */
.form { display: flex; flex-direction: column; gap: 16px; }
.field { display: flex; flex-direction: column; gap: 6px; }
.field span, .status-field legend { font-size: 13px; font-weight: 700; color: var(--primary); }
.field input {
  padding: 13px 14px; border: 1px solid #ccd3de; border-radius: 10px; font-size: 16px; background: var(--panel); color: var(--ink);
}
.field input:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px rgba(27,42,74,.15); }
.status-field { border: 1px solid #ccd3de; border-radius: 10px; padding: 10px 12px 14px; background: var(--panel); }
.status-field legend { padding: 0 6px; }
.status-picker { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.status-opt { display: flex; align-items: center; gap: 7px; padding: 12px 10px; border-radius: 8px; border: 1px solid #ccd3de; background: #f4f6fa; font-size: 13px; font-weight: 700; color: var(--steel); }
.status-opt.active { border-color: var(--primary); background: var(--primary); color: #fff; }
.dot { width: 10px; height: 10px; border-radius: 50%; flex: 0 0 auto; }
.dot-pending { background: var(--secondary); }
.dot-progress { background: #2f7fd3; }
.dot-passed { background: #3c9b5f; }
.dot-failed { background: var(--accent); }
.form-msg { margin: 0; font-size: 13px; color: var(--accent); font-weight: 600; }
.submit-btn { padding: 15px; border: none; border-radius: 12px; background: var(--primary); color: #fff; font-size: 16px; font-weight: 700; letter-spacing: .3px; box-shadow: 0 2px 0 var(--primary-dark); }
.submit-btn:active { transform: translateY(1px); box-shadow: 0 1px 0 var(--primary-dark); }
.cancel-btn { padding: 14px; border-radius: 12px; border: 1px solid #ccd3de; background: var(--panel); color: var(--steel); font-size: 15px; font-weight: 700; }

/* ---------- Edit sheet ---------- */
.sheet { position: fixed; inset: 0; z-index: 50; }
.sheet-backdrop { position: absolute; inset: 0; background: rgba(18,25,40,.5); }
.sheet-panel {
  position: absolute; left: 0; right: 0; bottom: 0; background: var(--bg); border-radius: 18px 18px 0 0; padding: 10px 18px calc(20px + var(--safe-bottom)); box-shadow: 0 -4px 20px rgba(0,0,0,.3); animation: rise .28s ease; max-height: 88vh; overflow-y: auto;
}
@keyframes rise { from { transform: translateY(100%); } to { transform: none; } }
.sheet-grip { width: 44px; height: 5px; border-radius: 3px; background: #ccd3de; margin: 0 auto 12px; }
.sheet-panel h3 { margin: 0 0 16px; font-size: 19px; color: var(--primary); }
.sheet-actions { display: flex; gap: 10px; }
.sheet-actions .submit-btn { flex: 1; }
.sheet-actions .cancel-btn { flex: 1; }

/* ---------- Bottom tab bar ---------- */
.tabbar { position: fixed; left: 0; right: 0; bottom: 0; z-index: 40; background: var(--primary); padding: 8px 6px var(--safe-bottom); box-shadow: 0 -3px 12px rgba(0,0,0,.25); }
.wire { position: absolute; top: 0; left: 0; right: 0; height: 3px; background: repeating-linear-gradient(90deg,#0c1422 0 6px,#3a465e 6px 12px); }
.tabbar { display: flex; }
.tab { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 5px; background: none; border: none; color: #8b95a8; padding: 6px 0 8px; }
.tab.active { color: var(--secondary); }
.tab-label { font-size: 10px; font-weight: 700; letter-spacing: .3px; text-transform: uppercase; }

.carabiner { position: relative; width: 26px; height: 34px; display: block; transition: transform .2s ease, color .2s ease; }
/* closed carabiner: matte black D-ring */
.carabiner::before {
  content: ""; position: absolute; inset: 0 3px; border: 4px solid #232a36; border-top-width: 5px; border-radius: 50% 50% 46% 46% / 46% 46% 60% 60%; background: transparent;
}
.carabiner::after {
  content: ""; position: absolute; left: 13px; top: 2px; width: 5px; height: 22px; background: #232a36; transform: rotate(6deg); border-radius: 2px;
}
.carabiner.active-biner { transform: rotate(16deg) translateY(-2px); }
.carabiner.active-biner::before { border-color: #9fb0cc; background: linear-gradient(160deg,#eaf0fa,#9fb0cc); box-shadow: 0 0 8px rgba(210,225,250,.6); }
.carabiner.active-biner::after { background: #c6d4ea; height: 30px; top: -2px; transform: rotate(-6deg); border-radius: 3px; }
.tab.active .carabiner { filter: drop-shadow(0 0 6px rgba(242,169,0,.4)); }