:root {
  --ink: #172129;
  --muted: #6c787f;
  --line: #dce2e2;
  --paper: #f5f4ef;
  --white: #fff;
  --jf: #d78b37;
  --jk: #9f263d;
  --sf: #177880;
  --outside: #7c858a;
  --clark: #94c83d;
  --shadow: 0 18px 54px rgba(8, 24, 33, .18);
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body { font-family: Inter, ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif; color: var(--ink); background: #111a20; overflow: hidden; }
button, input, textarea { font: inherit; }
button { color: inherit; }

.app-shell { display: grid; grid-template-columns: 390px 1fr; grid-template-rows: 72px 1fr; width: 100%; height: 100%; }
.topbar { grid-column: 1 / -1; display: flex; align-items: center; justify-content: space-between; padding: 0 22px; background: #111a20; color: #fff; border-bottom: 1px solid rgba(255,255,255,.09); z-index: 1002; }
.brand { display: flex; align-items: center; gap: 13px; }
.brand-mark { width: 37px; height: 37px; display: grid; grid-template-columns: repeat(3, 1fr); gap: 3px; transform: skew(-7deg); }
.brand-mark span { background: #e4a343; border-radius: 2px; }
.brand-mark span:nth-child(2) { background: #f5f4ef; transform: translateY(6px); }
.brand-mark span:nth-child(3) { background: #9f263d; transform: translateY(12px); }
.brand-copy { display: grid; gap: 2px; line-height: 1.05; }
.brand-copy strong { font-size: 15px; letter-spacing: .015em; }
.brand-copy small { text-transform: uppercase; letter-spacing: .18em; font-size: 9px; color: #9dacb4; font-weight: 700; }
.topbar-actions { display: flex; align-items: center; gap: 12px; }
.status-pill { display: flex; align-items: center; gap: 7px; padding: 8px 11px; font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: .09em; color: #bbc6ca; border: 1px solid rgba(255,255,255,.12); border-radius: 999px; }
.status-pill i { width: 7px; height: 7px; border-radius: 50%; background: #80b442; box-shadow: 0 0 0 3px rgba(128,180,66,.14); }
.icon-button { border: 0; background: transparent; padding: 8px; color: white; }
.icon-button svg { width: 22px; stroke: currentColor; stroke-width: 2; fill: none; }
.mobile-panel-button { display: none; }

.sidebar { grid-row: 2; background: var(--paper); overflow: auto; overscroll-behavior: contain; z-index: 1001; border-right: 1px solid #cfd6d6; }
.sidebar section { padding: 24px 24px 22px; border-bottom: 1px solid var(--line); }
.section-kicker { color: #8c6325; font-size: 10px; font-weight: 800; letter-spacing: .16em; text-transform: uppercase; margin-bottom: 7px; }
h1, h2 { margin: 0; letter-spacing: -.025em; }
h1 { font-family: Georgia, "Times New Roman", serif; font-size: 29px; line-height: 1.08; font-weight: 500; max-width: 300px; }
h2 { font-size: 16px; font-weight: 760; }
.search-box { margin-top: 18px; display: grid; grid-template-columns: 20px 1fr auto; align-items: center; gap: 8px; padding: 6px 6px 6px 13px; background: #fff; border: 1px solid #cfd7d7; border-radius: 8px; box-shadow: 0 4px 15px rgba(18,33,40,.05); }
.search-box:focus-within { border-color: #7d919a; box-shadow: 0 0 0 3px rgba(23,120,128,.12); }
.search-box svg { width: 18px; fill: none; stroke: #77868d; stroke-width: 1.9; }
.search-box input { min-width: 0; border: 0; outline: 0; padding: 9px 2px; color: var(--ink); background: transparent; font-size: 13px; }
.search-box button { border: 0; border-radius: 6px; padding: 9px 12px; color: #fff; background: #24333a; font-size: 11px; font-weight: 800; letter-spacing: .03em; cursor: pointer; }
.search-feedback { min-height: 0; margin-top: 8px; color: var(--muted); font-size: 11px; }
.search-feedback:not(:empty) { min-height: 16px; }
.search-results { display: grid; gap: 5px; max-height: 230px; overflow: auto; }
.search-result { width: 100%; text-align: left; display: grid; grid-template-columns: 30px 1fr; gap: 9px; padding: 9px; border: 1px solid #d9dfdf; border-radius: 7px; background: rgba(255,255,255,.7); cursor: pointer; }
.search-result:hover { border-color: #aebbbb; background: #fff; }
.search-result > span:first-child { display: grid; place-items: center; width: 30px; height: 30px; border-radius: 6px; background: #e7eceb; color: #425159; font-weight: 800; }
.search-result strong { display: block; font-size: 12px; line-height: 1.35; }
.search-result small { display: block; margin-top: 2px; color: var(--muted); font-size: 10px; line-height: 1.35; }
.section-heading { display: flex; justify-content: space-between; align-items: center; gap: 15px; }
.text-button { border: 0; background: transparent; padding: 4px; color: #42616a; font-size: 11px; text-decoration: underline; text-underline-offset: 3px; cursor: pointer; }
.legend-grid { margin-top: 15px; display: grid; grid-template-columns: 1fr 1fr; gap: 7px; }
.legend-item { display: grid; grid-template-columns: 8px 1fr; gap: 9px; align-items: center; padding: 9px 10px; text-align: left; border: 1px solid #d9dfde; border-radius: 7px; background: rgba(255,255,255,.55); cursor: pointer; }
.legend-item:hover, .legend-item.active { background: #fff; border-color: #b8c2c2; }
.swatch { width: 8px; height: 34px; border-radius: 3px; }
.swatch.jf { background: var(--jf); } .swatch.jk { background: var(--jk); } .swatch.sf { background: var(--sf); } .swatch.out { background: repeating-linear-gradient(45deg,#99a2a5,#99a2a5 3px,#d4d9da 3px,#d4d9da 6px); }
.legend-item strong, .legend-item small { display: block; }
.legend-item strong { font-size: 12px; }
.legend-item small { margin-top: 2px; color: var(--muted); font-size: 10px; }
.clark-note { display: flex; gap: 10px; align-items: center; margin-top: 12px; padding: 10px 11px; background: rgba(148,200,61,.08); border: 1px solid rgba(112,156,42,.2); border-radius: 7px; }
.clark-hatch { width: 32px; height: 30px; flex: 0 0 auto; border-radius: 5px; background-color: rgba(148,200,61,.2); background-image: repeating-linear-gradient(135deg, rgba(83,122,29,.25) 0, rgba(83,122,29,.25) 1px, transparent 1px, transparent 6px); }
.clark-note strong, .clark-note small { display: block; }
.clark-note strong { font-size: 11px; }
.clark-note small { color: #667465; font-size: 9.5px; line-height: 1.35; margin-top: 2px; }
.count-badge { display: inline-grid; place-items: center; min-width: 19px; height: 19px; padding: 0 5px; margin-left: 4px; border-radius: 10px; color: #fff; background: #66767d; font-size: 10px; vertical-align: 2px; }
.switch-label { display: flex; align-items: center; gap: 7px; color: var(--muted); font-size: 10px; cursor: pointer; }
.switch-label input { position: absolute; opacity: 0; }
.switch { position: relative; width: 32px; height: 18px; border-radius: 20px; background: #b7c1c2; transition: .2s; }
.switch::after { content: ""; position: absolute; width: 14px; height: 14px; left: 2px; top: 2px; background: #fff; border-radius: 50%; box-shadow: 0 1px 3px rgba(0,0,0,.2); transition: .2s; }
.switch-label input:checked + .switch { background: var(--sf); }
.switch-label input:checked + .switch::after { transform: translateX(14px); }
.empty-state { padding: 25px 12px 10px; text-align: center; color: var(--muted); }
.empty-pin { display: grid; place-items: center; width: 36px; height: 36px; margin: 0 auto 9px; border-radius: 50% 50% 50% 8px; transform: rotate(-45deg); background: #e3e7e5; font-size: 20px; color: #65747a; }
.empty-pin::first-letter { transform: rotate(45deg); }
.empty-state strong { display: block; color: #59666b; font-size: 11px; }
.empty-state p { max-width: 260px; margin: 5px auto 0; font-size: 10px; line-height: 1.45; }
.pin-list { display: grid; gap: 7px; margin-top: 14px; }
.pin-card { display: grid; grid-template-columns: 30px 1fr auto; align-items: center; gap: 9px; padding: 9px; border: 1px solid #d6dddd; border-radius: 8px; background: rgba(255,255,255,.65); }
.pin-card:hover { background: #fff; }
.pin-territory { display: grid; place-items: center; width: 30px; height: 30px; color: #fff; border-radius: 50% 50% 50% 8px; transform: rotate(-45deg); font-size: 9px; font-weight: 900; }
.pin-territory span { transform: rotate(45deg); }
.pin-card .pin-copy { min-width: 0; border: 0; background: transparent; text-align: left; padding: 0; cursor: pointer; }
.pin-copy strong { display: block; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; font-size: 11px; }
.pin-copy small { display: block; margin-top: 2px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; color: var(--muted); font-size: 9px; }
.pin-visibility { width: 28px; height: 28px; border: 0; border-radius: 5px; background: transparent; cursor: pointer; color: #637279; }
.pin-visibility.off { opacity: .35; }
.pin-actions { display: flex; justify-content: space-between; margin-top: 12px; }
.pin-actions button { border: 0; background: transparent; padding: 4px; color: #53666d; font-size: 10px; text-decoration: underline; text-underline-offset: 3px; cursor: pointer; }
.pin-actions .danger-text { color: #9f263d; }
.sidebar-footer { min-height: 54px; display: flex; justify-content: space-between; align-items: center; padding: 15px 24px; color: #7a878c; font-size: 9px; }
.sidebar-footer button { border: 0; background: none; color: #53666d; text-decoration: underline; text-underline-offset: 3px; cursor: pointer; }

.map-stage { grid-column: 2; grid-row: 2; position: relative; min-width: 0; min-height: 0; background: #172129; }
#map { width: 100%; height: 100%; }
.map-title-card { position: absolute; z-index: 700; top: 18px; left: 18px; padding: 11px 14px; min-width: 190px; color: #fff; background: rgba(17,26,32,.86); backdrop-filter: blur(10px); border: 1px solid rgba(255,255,255,.12); border-radius: 8px; box-shadow: 0 10px 35px rgba(0,0,0,.22); pointer-events: none; }
.map-title-card span, .map-title-card strong { display: block; }
.map-title-card span { color: #9fadb4; text-transform: uppercase; font-size: 8px; letter-spacing: .15em; font-weight: 800; }
.map-title-card strong { margin-top: 3px; font-family: Georgia, serif; font-size: 16px; font-weight: 500; }
.map-legend-mini { position: absolute; z-index: 700; left: 18px; bottom: 28px; display: flex; gap: 6px; }
.map-legend-mini button { display: flex; align-items: center; gap: 7px; border: 1px solid rgba(255,255,255,.14); border-radius: 7px; padding: 9px 11px; color: #dbe2e3; background: rgba(17,26,32,.82); backdrop-filter: blur(8px); font-size: 10px; font-weight: 700; cursor: pointer; }
.map-legend-mini button:not(.active) { opacity: .55; }
.layer-icon { width: 14px; height: 11px; border: 1px solid #fff; opacity: .8; }
.territory-icon { width: 14px; height: 11px; background: linear-gradient(90deg,var(--jf) 0 33%,var(--jk) 33% 66%,var(--sf) 66%); opacity: .9; }
.leaflet-control-zoom a { color: #24333a !important; }
.leaflet-control-layers { border: 0 !important; border-radius: 8px !important; box-shadow: var(--shadow) !important; }
.county-label { color: rgba(255,255,255,.92); font-size: 9px; font-weight: 800; letter-spacing: .03em; text-shadow: 0 1px 3px #000, 0 0 5px #000; white-space: nowrap; }
.territory-badge { display: grid; place-items: center; width: 34px !important; height: 34px !important; margin: -17px 0 0 -17px !important; border-radius: 50%; color: #fff; font-weight: 900; font-size: 12px; border: 2px solid rgba(255,255,255,.85); box-shadow: 0 3px 14px rgba(0,0,0,.35); }
.territory-badge.jf { background: var(--jf); } .territory-badge.jk { background: var(--jk); } .territory-badge.sf { background: var(--sf); }
.custom-pin { position: relative; width: 34px; height: 42px; }
.custom-pin .pin-head { display: grid; place-items: center; width: 31px; height: 31px; transform: rotate(-45deg); border-radius: 50% 50% 50% 7px; border: 2px solid #fff; box-shadow: 0 4px 14px rgba(0,0,0,.4); }
.custom-pin .pin-head span { transform: rotate(45deg); color: #fff; font-size: 8px; font-weight: 900; }
.custom-pin::after { content: ""; position: absolute; left: 10px; bottom: 0; width: 11px; height: 4px; border-radius: 50%; background: rgba(0,0,0,.35); filter: blur(2px); }
.leaflet-tooltip.territory-tooltip { padding: 10px 12px; border: 0; border-radius: 7px; background: rgba(17,26,32,.92); color: #fff; box-shadow: var(--shadow); }
.territory-tooltip::before { display: none; }
.tooltip-title { font-size: 12px; font-weight: 800; }.tooltip-meta { display: block; margin-top: 3px; color: #c0cbce; font-size: 9px; }

dialog { border: 0; padding: 0; background: transparent; max-width: min(92vw, 470px); width: 100%; }
dialog::backdrop { background: rgba(6,14,18,.56); backdrop-filter: blur(3px); }
.dialog-card { position: relative; width: 100%; margin: 0; padding: 28px; border-radius: 12px; background: var(--paper); box-shadow: 0 24px 80px rgba(0,0,0,.34); }
.dialog-close { position: absolute; right: 16px; top: 13px; border: 0; background: transparent; font-size: 24px; color: #758188; cursor: pointer; }
.dialog-card h2 { font-family: Georgia, serif; font-size: 26px; font-weight: 500; padding-right: 24px; }
.dialog-address { margin: 6px 0 12px; color: var(--muted); font-size: 11px; line-height: 1.4; }
.territory-readout { display: inline-flex; align-items: center; gap: 7px; margin-bottom: 18px; padding: 7px 9px; border-radius: 6px; background: #e8ecea; color: #47575e; font-size: 10px; font-weight: 800; }
.territory-readout i { width: 8px; height: 8px; border-radius: 50%; }
.field-label { display: block; margin-bottom: 6px; color: #57676e; font-size: 10px; font-weight: 800; text-transform: uppercase; letter-spacing: .08em; }
.dialog-card textarea { width: 100%; resize: vertical; border: 1px solid #cdd5d4; border-radius: 7px; padding: 11px; color: var(--ink); background: #fff; outline: none; font-size: 12px; line-height: 1.5; }
.dialog-card textarea:focus { border-color: var(--sf); box-shadow: 0 0 0 3px rgba(23,120,128,.11); }
.dialog-actions { display: flex; justify-content: space-between; gap: 10px; margin-top: 16px; }
.dialog-actions button, .save-button { border: 0; border-radius: 7px; padding: 10px 14px; font-size: 11px; font-weight: 800; cursor: pointer; }
.delete-button { color: #9f263d; background: transparent; }
.save-button { color: #fff; background: #24333a; }
.save-button.full { width: 100%; margin-top: 18px; }
.info-card ul { margin: 16px 0 0; padding-left: 19px; color: #5d6a70; font-size: 11px; line-height: 1.55; }
.info-card li + li { margin-top: 7px; }

@media (max-width: 850px) {
  .app-shell { grid-template-columns: 1fr; }
  .mobile-panel-button { display: block; }
  .status-pill { display: none; }
  .sidebar { position: fixed; top: 72px; bottom: 0; left: 0; width: min(390px, 92vw); transform: translateX(-105%); transition: transform .25s ease; box-shadow: 18px 0 50px rgba(0,0,0,.28); }
  .sidebar.open { transform: translateX(0); }
  .map-stage { grid-column: 1; }
}

@media (max-width: 520px) {
  .topbar { height: 64px; padding: 0 14px; }
  .app-shell { grid-template-rows: 64px 1fr; }
  .sidebar { top: 64px; }
  .brand-copy strong { font-size: 13px; }
  .brand-mark { width: 31px; height: 31px; }
  .map-title-card { left: 12px; top: 12px; }
  .map-legend-mini { left: 12px; bottom: 22px; }
}
