:root {
  --bg: #1b1b1b;
  --panel: #242424;
  --panel2: #2c2c2c;
  --line: #3a3a3a;
  --text: #f2ead8;
  --muted: #b9b2a2;
  --red: #e63329;
  --red-dark: #b91f18;
  --gold: #c8a165;
  --green: #4caf7d;
  --radius: 14px;
  --nav-h: 62px;
}
* { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; }
body {
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  overscroll-behavior-y: none;
}
.hidden { display: none !important; }
button { font: inherit; cursor: pointer; }
input, select, textarea {
  font: inherit; color: var(--text); background: var(--panel2);
  border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; width: 100%;
}
label { display: block; font-size: 13px; color: var(--muted); margin-bottom: 12px; }
label input, label select { margin-top: 5px; }
a { color: var(--gold); }

/* ---------- screens (splash / gates) ---------- */
.screen {
  min-height: 100dvh; display: flex; flex-direction: column; align-items: center;
  justify-content: center; padding: 28px 22px; text-align: center;
}
.splash-screen { background: radial-gradient(120% 90% at 50% 0%, #2e2626 0%, var(--bg) 60%); }
.splash-tag-wrap { perspective: 600px; }
.splash-tag {
  width: 148px; height: 148px; border-radius: 28px;
  transform-origin: 50% -30px;
  animation: tagswing 1.6s ease-in-out;
  box-shadow: 0 24px 50px rgba(0,0,0,.55);
}
@keyframes tagswing {
  0% { transform: rotate(24deg) translateY(-16px); opacity: 0; }
  35% { transform: rotate(-13deg); opacity: 1; }
  60% { transform: rotate(7deg); }
  80% { transform: rotate(-3deg); }
  100% { transform: rotate(0deg); }
}
.splash-name { margin-top: 26px; font-size: 34px; font-weight: 800; letter-spacing: 2px; }
.splash-name span, .gate-title span, .topbar-title span { color: var(--red); }
.splash-sub { margin-top: 8px; color: var(--muted); font-size: 14px; letter-spacing: .4px; }

.gate-logo { width: 104px; height: 104px; border-radius: 22px; box-shadow: 0 16px 36px rgba(0,0,0,.5); }
.gate-title { margin-top: 18px; font-size: 28px; font-weight: 800; letter-spacing: 2px; }
.gate-text { margin-top: 14px; color: var(--muted); font-size: 15px; line-height: 1.55; max-width: 430px; }
.gate-text.small { font-size: 13px; }
.screen h1:not(.gate-title) { margin-top: 16px; font-size: 24px; }

/* ---------- auth ---------- */
.auth-tabs { display: flex; gap: 8px; margin: 22px 0 18px; background: var(--panel); padding: 5px; border-radius: 999px; }
.auth-tab { border: 0; background: transparent; color: var(--muted); padding: 8px 22px; border-radius: 999px; font-weight: 600; }
.auth-tab.active { background: var(--red); color: #fff; }
.auth-form { width: 100%; max-width: 380px; text-align: left; }
.auth-note { margin-top: 14px; font-size: 12.5px; color: var(--muted); line-height: 1.5; }
.form-error { background: rgba(230,51,41,.14); border: 1px solid var(--red-dark); color: #ffb3ae; border-radius: 10px; padding: 9px 12px; font-size: 13.5px; margin-bottom: 12px; }

/* ---------- buttons / plans ---------- */
.btn { border: 0; border-radius: 12px; padding: 12px 18px; font-weight: 700; }
.btn-red { background: linear-gradient(180deg, var(--red), var(--red-dark)); color: #fff; }
.btn-ghost { background: transparent; border: 1px solid var(--line); color: var(--muted); margin-top: 18px; }
.btn-block { width: 100%; }
.plans { display: grid; gap: 12px; width: 100%; max-width: 430px; margin-top: 20px; }
.plan-card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; text-align: left; }
.plan-card h3 { font-size: 16px; margin-bottom: 4px; }
.plan-card p { color: var(--muted); font-size: 13px; margin-bottom: 12px; }
.plan-actions { display: flex; gap: 8px; }
.plan-actions a { flex: 1; text-align: center; text-decoration: none; }

/* ---------- app frame ---------- */
#app { min-height: 100dvh; display: flex; flex-direction: column; }
.topbar {
  display: flex; align-items: center; gap: 10px; padding: calc(10px + env(safe-area-inset-top)) 16px 10px;
  background: rgba(27,27,27,.96); position: sticky; top: 0; z-index: 20; border-bottom: 1px solid var(--line);
}
.topbar-logo { width: 34px; height: 34px; border-radius: 8px; }
.topbar-title { font-weight: 800; letter-spacing: 1.5px; font-size: 17px; }
.topbar-user { margin-left: auto; font-size: 12px; color: var(--muted); text-align: right; }
.citybar { display: flex; gap: 8px; padding: 12px 16px 4px; overflow-x: auto; scrollbar-width: none; }
.citybar::-webkit-scrollbar { display: none; }
.city-chip {
  flex: 0 0 auto; border: 1px solid var(--line); background: var(--panel); color: var(--muted);
  border-radius: 999px; padding: 8px 14px; font-weight: 600; font-size: 13.5px;
}
.city-chip.active { background: var(--red); border-color: var(--red); color: #fff; }
.city-chip .n { opacity: .75; font-weight: 500; margin-left: 5px; font-size: 12px; }
main#views { flex: 1; padding: 12px 16px calc(var(--nav-h) + 26px); width: 100%; max-width: 860px; margin: 0 auto; }
.bottomnav {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 30; height: calc(var(--nav-h) + env(safe-area-inset-bottom));
  padding-bottom: env(safe-area-inset-bottom);
  background: rgba(24,24,24,.97); border-top: 1px solid var(--line);
  display: flex; justify-content: space-around; align-items: stretch;
}
.navbtn { background: none; border: 0; color: var(--muted); font-size: 19px; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px; flex: 1; }
.navbtn span { font-size: 10.5px; font-weight: 600; letter-spacing: .3px; }
.navbtn.active { color: var(--red); }

/* ---------- wire ---------- */
.wire-tools { display: grid; gap: 9px; margin-bottom: 14px; }
.wire-row { display: flex; gap: 8px; }
.wire-row select { flex: 1; }
.seg { display: flex; background: var(--panel); border-radius: 10px; padding: 4px; gap: 4px; }
.seg button { flex: 1; border: 0; background: transparent; color: var(--muted); border-radius: 8px; padding: 7px 4px; font-weight: 600; font-size: 13px; }
.seg button.active { background: var(--red); color: #fff; }
.count-line { color: var(--muted); font-size: 13px; margin: 2px 0 12px; }
.lead-card {
  background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 14px; margin-bottom: 10px; text-align: left; width: 100%; color: var(--text); display: block;
}
.lead-card:active { background: var(--panel2); }
.lead-top { display: flex; gap: 8px; align-items: center; margin-bottom: 6px; flex-wrap: wrap; }
.stamp { font-size: 10.5px; font-weight: 800; letter-spacing: .6px; text-transform: uppercase; padding: 3px 8px; border-radius: 6px; background: var(--panel2); border: 1px solid var(--line); color: var(--muted); }
.stamp.issued, .stamp.applied { color: #9fd6ff; border-color: #2c4a63; }
.stamp.violation, .stamp.in_court { color: #ffb3ae; border-color: #63302c; }
.stamp.stalled { color: var(--gold); border-color: #63522c; }
.badge-new { background: var(--red); color: #fff; font-size: 10.5px; font-weight: 800; padding: 3px 7px; border-radius: 6px; letter-spacing: .5px; }
.badge-urgent { color: #ffb3ae; font-size: 12px; font-weight: 700; }
.lead-fav { margin-left: auto; font-size: 17px; color: var(--line); }
.lead-fav.on { color: var(--gold); }
.lead-head { font-size: 15.5px; font-weight: 700; line-height: 1.35; }
.lead-meta { color: var(--muted); font-size: 13px; margin-top: 4px; line-height: 1.5; }
.lead-value { color: var(--green); font-weight: 700; }
.empty { text-align: center; color: var(--muted); padding: 44px 12px; font-size: 14.5px; line-height: 1.6; }

/* ---------- map ---------- */
.map-wrap { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; }
.map-wrap canvas { display: block; width: 100%; }
.map-legend { display: flex; gap: 16px; padding: 10px 14px; font-size: 12.5px; color: var(--muted); border-top: 1px solid var(--line); }
.dot { display: inline-block; width: 9px; height: 9px; border-radius: 50%; margin-right: 5px; }
.dot.permit { background: #9fd6ff; } .dot.violation { background: var(--red); }

/* ---------- digest / working / network / settings ---------- */
.stat-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; margin-bottom: 16px; }
.stat { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 10px; text-align: center; }
.stat .big { font-size: 24px; font-weight: 800; }
.stat .lbl { color: var(--muted); font-size: 11.5px; margin-top: 3px; letter-spacing: .3px; }
.section-title { font-size: 15px; font-weight: 800; margin: 20px 0 10px; letter-spacing: .3px; }
.pipe-group { margin-bottom: 8px; }
.dir-card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; margin-bottom: 10px; }
.dir-card h4 { font-size: 15px; }
.dir-card p { color: var(--muted); font-size: 13px; margin-top: 3px; line-height: 1.5; }
.dir-badge { float: right; font-size: 10.5px; font-weight: 800; letter-spacing: .5px; color: var(--gold); border: 1px solid #63522c; padding: 3px 8px; border-radius: 6px; text-transform: uppercase; }
.settings-block { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; margin-bottom: 14px; }
.settings-block h3 { font-size: 15px; margin-bottom: 12px; }
.trade-grid { display: flex; flex-wrap: wrap; gap: 7px; margin: 4px 0 12px; }
.trade-pill { border: 1px solid var(--line); background: var(--panel2); color: var(--muted); border-radius: 999px; padding: 6px 12px; font-size: 13px; font-weight: 600; }
.trade-pill.on { background: var(--red); border-color: var(--red); color: #fff; }
.saved-msg { color: var(--green); font-size: 13px; margin-top: 8px; }

/* ---------- sheet & modal ---------- */
.sheet-backdrop { position: fixed; inset: 0; background: rgba(0,0,0,.6); z-index: 40; }
.sheet {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 41; max-height: 86dvh; overflow-y: auto;
  background: #222; border-radius: 20px 20px 0 0; border-top: 1px solid var(--line);
  padding: 18px 18px calc(20px + env(safe-area-inset-bottom)); max-width: 860px; margin: 0 auto;
}
.sheet h2 { font-size: 19px; line-height: 1.35; margin: 8px 0 6px; }
.sheet .kv { display: grid; grid-template-columns: 110px 1fr; gap: 5px 12px; font-size: 14px; margin: 14px 0; }
.sheet .kv dt { color: var(--muted); } .sheet .kv dd { font-weight: 600; }
.sheet .desc { color: var(--muted); line-height: 1.6; font-size: 14px; }
.pipe-actions { display: flex; gap: 7px; flex-wrap: wrap; margin-top: 16px; }
.pipe-actions button { border: 1px solid var(--line); background: var(--panel2); color: var(--muted); border-radius: 999px; padding: 8px 14px; font-weight: 700; font-size: 13px; }
.pipe-actions button.on { background: var(--red); border-color: var(--red); color: #fff; }
.sheet-close { position: sticky; top: 0; float: right; background: var(--panel2); border: 1px solid var(--line); color: var(--text); border-radius: 50%; width: 34px; height: 34px; font-size: 16px; }
.modal-backdrop { position: fixed; inset: 0; background: rgba(0,0,0,.72); z-index: 50; display: flex; align-items: center; justify-content: center; padding: 20px; }
.modal { background: #222; border: 1px solid var(--line); border-radius: 20px; padding: 24px; max-width: 440px; width: 100%; max-height: 88dvh; overflow-y: auto; }
.modal-logo { width: 64px; height: 64px; border-radius: 14px; display: block; margin: 0 auto 12px; }
.modal h2 { text-align: center; font-size: 21px; margin-bottom: 14px; }
.welcome-list { list-style: none; display: grid; gap: 12px; margin-bottom: 20px; }
.welcome-list li { color: var(--muted); font-size: 14px; line-height: 1.55; }
.welcome-list strong { color: var(--text); }
@media (min-width: 700px) { .plans { grid-template-columns: 1fr 1fr; max-width: 720px; } }
