:root {
  color-scheme: light;
  --ink: #172536;
  --muted: #67778a;
  --line: #dbe3eb;
  --panel: #ffffff;
  --soft: #f4f7fa;
  --navy: #16324f;
  --blue: #2166a5;
  --blue-soft: #e7f1fa;
  --green: #23805b;
  --red: #ba3d4f;
  --amber: #a66c16;
  --shadow: 0 12px 36px rgba(28, 48, 70, .14);
}

* { box-sizing: border-box; }
html, body, #app { width: 100%; height: 100%; margin: 0; }
body { font-family: Inter, "Segoe UI", Arial, sans-serif; color: var(--ink); background: var(--soft); overflow: hidden; }
button, input, textarea, select { font: inherit; }
button { cursor: pointer; }

.app-shell { display: grid; grid-template-rows: 64px 54px minmax(0, 1fr); }
.topbar { display: flex; align-items: center; gap: 24px; padding: 0 20px; color: #fff; background: linear-gradient(100deg, #112c46, #1d5276); box-shadow: 0 2px 12px rgba(0,0,0,.16); z-index: 1100; }
.brand { display: flex; align-items: center; gap: 10px; min-width: 230px; }
.brand-mark { display: grid; place-items: center; width: 40px; height: 40px; border: 1px solid rgba(255,255,255,.42); border-radius: 11px; font-size: 12px; letter-spacing: .06em; background: rgba(255,255,255,.1); }
.brand strong, .brand small { display: block; }
.brand strong { letter-spacing: .01em; }
.brand small { opacity: .68; margin-top: 2px; font-size: 11px; }
.project-caption { min-width: 0; flex: 1; text-align: center; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; font-weight: 600; }
.user-caption { display: flex; align-items: center; gap: 10px; min-width: 180px; justify-content: flex-end; font-size: 13px; }
.user-caption img { width: 32px; height: 32px; border-radius: 50%; object-fit: cover; }
.user-caption button { border: 0; border-bottom: 1px dotted rgba(255,255,255,.7); padding: 2px 0; color: #fff; background: none; }

.stage-nav { display: grid; grid-template-columns: repeat(7, minmax(105px, 1fr)); background: #fff; border-bottom: 1px solid var(--line); z-index: 1000; overflow-x: auto; }
.stage-nav button { position: relative; display: flex; align-items: center; justify-content: center; gap: 8px; border: 0; border-right: 1px solid var(--line); color: var(--muted); background: #fff; font-size: 13px; font-weight: 600; }
.stage-nav button span { display: grid; place-items: center; width: 24px; height: 24px; border-radius: 50%; background: var(--soft); }
.stage-nav button.active { color: var(--blue); background: #f8fbfe; }
.stage-nav button.active::after { content: ""; position: absolute; inset: auto 18% 0; height: 3px; border-radius: 3px 3px 0 0; background: var(--blue); }
.stage-nav button.done span { color: white; background: var(--green); }
.stage-nav button:disabled { opacity: .45; cursor: not-allowed; }

.workspace { display: grid; grid-template-columns: minmax(360px, 430px) minmax(0, 1fr); min-height: 0; }
.panel { position: relative; z-index: 800; overflow: auto; padding: 22px; background: var(--panel); border-right: 1px solid var(--line); box-shadow: 5px 0 24px rgba(30,55,80,.06); }
.map-wrap, #map { position: relative; width: 100%; height: 100%; min-height: 0; }
.map-status { position: absolute; z-index: 700; left: 12px; bottom: 12px; padding: 7px 11px; border: 1px solid rgba(25,51,77,.12); border-radius: 8px; color: var(--muted); background: rgba(255,255,255,.92); box-shadow: var(--shadow); font-size: 12px; pointer-events: none; }
.basemap-status { position: absolute; z-index: 700; left: 12px; bottom: 54px; max-width: min(430px, calc(100% - 24px)); padding: 7px 11px; border: 1px solid #e4c7a4; border-radius: 8px; color: #8b541e; background: rgba(255,248,235,.96); box-shadow: var(--shadow); font-size: 11px; }
.legend { position: absolute; z-index: 700; right: 12px; bottom: 12px; display: grid; gap: 6px; padding: 9px 11px; border-radius: 9px; background: rgba(255,255,255,.94); box-shadow: var(--shadow); font-size: 11px; }
.legend:empty { display: none; }
.legend-row { display: flex; align-items: center; gap: 7px; }
.legend-swatch { width: 18px; height: 9px; border-radius: 2px; }

h1, h2, h3, p { margin-top: 0; }
h2 { margin-bottom: 7px; font-size: 20px; }
h3 { margin: 22px 0 10px; font-size: 14px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); }
.lead { margin-bottom: 18px; color: var(--muted); line-height: 1.45; font-size: 13px; }
.stack { display: grid; gap: 10px; }
.row { display: flex; gap: 9px; align-items: center; }
.row.wrap { flex-wrap: wrap; }
.row > .grow { flex: 1; min-width: 0; }
.field { display: grid; gap: 6px; }
.field > span { color: var(--muted); font-size: 12px; font-weight: 600; }
.smoothness-label { display: flex; align-items: baseline; justify-content: space-between; font-size: 13px; font-weight: 600; }
.smoothness-label output { font-variant-numeric: tabular-nums; }
#smoothness { min-height: 28px; margin: 0; padding: 0; accent-color: var(--blue); }
#smoothness:focus-visible { outline: 2px solid var(--blue); outline-offset: 2px; }
#smoothness-help { margin: 0; }
input, textarea, select { width: 100%; border: 1px solid #cdd8e3; border-radius: 8px; padding: 9px 10px; color: var(--ink); background: #fff; outline: none; }
textarea { min-height: 78px; resize: vertical; line-height: 1.4; }
input:focus, textarea:focus, select:focus { border-color: #5e96c5; box-shadow: 0 0 0 3px rgba(33,102,165,.1); }

.button { display: inline-flex; align-items: center; justify-content: center; min-height: 38px; border: 1px solid var(--blue); border-radius: 8px; padding: 8px 13px; color: #fff; background: var(--blue); font-weight: 650; font-size: 13px; }
.button:hover { filter: brightness(.96); }
.button.secondary { color: var(--blue); background: #fff; }
.button.ghost { border-color: var(--line); color: var(--muted); background: #fff; }
.button.danger { border-color: #e1b5bc; color: var(--red); background: #fff; }
.button.success { border-color: var(--green); background: var(--green); }
.button:disabled { opacity: .5; cursor: not-allowed; }

.card { border: 1px solid var(--line); border-radius: 11px; padding: 13px; background: #fff; box-shadow: 0 2px 8px rgba(25,50,75,.035); }
.card.active { border-color: #6ba0ca; box-shadow: 0 0 0 3px rgba(33,102,165,.09); }
.card-title { display: flex; align-items: flex-start; justify-content: space-between; gap: 8px; margin-bottom: 5px; font-weight: 700; }
.meta { color: var(--muted); font-size: 12px; line-height: 1.45; }
.badge { display: inline-flex; align-items: center; border-radius: 100px; padding: 3px 7px; background: var(--blue-soft); color: var(--blue); font-size: 11px; font-weight: 700; }
.badge.red { color: var(--red); background: #fae9ec; }
.badge.green { color: var(--green); background: #e6f5ef; }
.callout { border-left: 3px solid var(--blue); border-radius: 7px; padding: 10px 11px; color: #3a526a; background: var(--blue-soft); line-height: 1.45; font-size: 12px; }
.callout.warn { border-color: var(--amber); background: #fff5df; }
.divider { height: 1px; margin: 18px 0; background: var(--line); }
.empty { padding: 28px 12px; text-align: center; color: var(--muted); font-size: 13px; }
.parcel-progress { display: grid; gap: 8px; margin-top: 12px; border: 1px solid #bdd5e8; border-radius: 10px; padding: 11px; background: #f2f8fd; }
.parcel-progress.error { border-color: #e5b3bb; background: #fff2f4; }
.parcel-progress-title { display: flex; align-items: center; justify-content: space-between; gap: 10px; color: var(--blue); font-size: 12px; }
.parcel-progress.error .parcel-progress-title, .parcel-progress-error { color: var(--red); }
.progress-track { height: 9px; overflow: hidden; border-radius: 999px; background: #d9e8f3; }
.progress-track i { display: block; height: 100%; border-radius: inherit; background: linear-gradient(90deg, #2166a5, #4ba6d8); transition: width .35s ease; }
.parcel-progress.error .progress-track i { background: var(--red); }
.parcel-progress-error { font-size: 12px; line-height: 1.4; }
.quarter-list { display: grid; gap: 4px; margin-bottom: 14px; }
.quarter-row { display: flex; align-items: center; justify-content: space-between; gap: 8px; border-bottom: 1px solid #e6ebf0; padding: 6px 2px; font-size: 11px; }
.quarter-row > span { min-width: 0; }
.quarter-row small { display: block; margin-top: 2px; color: var(--muted); font-size: 10px; }
.quarter-refresh { flex: 0 0 28px; width: 28px; height: 28px; min-height: 28px; border: 1px solid var(--line); border-radius: 50%; padding: 0; color: var(--blue); background: #fff; font-size: 19px; line-height: 1; }
.quarter-refresh:disabled { opacity: .42; cursor: not-allowed; }

.project-list, .rumb-list { display: grid; gap: 8px; }
.project-card { cursor: pointer; }
.project-card:hover { border-color: #9ebbd2; }
.rumb-item { display: flex; align-items: center; gap: 9px; border: 1px solid var(--line); border-radius: 8px; padding: 8px 9px; font-size: 12px; }
.rumb-color { width: 12px; height: 26px; border-radius: 4px; }
.rumb-item strong { min-width: 28px; }
.rumb-item span:last-child { margin-left: auto; color: var(--muted); }

.table-wrap { overflow: auto; max-height: 340px; border: 1px solid var(--line); border-radius: 9px; }
table { width: 100%; border-collapse: collapse; font-size: 11px; }
th { position: sticky; top: 0; z-index: 1; padding: 8px 6px; text-align: left; color: var(--muted); background: #f5f8fa; border-bottom: 1px solid var(--line); }
td { padding: 7px 6px; border-bottom: 1px solid #edf1f4; vertical-align: middle; }
tr { cursor: pointer; }
tbody tr:hover, tbody tr.selected { background: #edf6fd; }
td input[type="checkbox"] { width: 16px; height: 16px; padding: 0; }
.parcel-detail { margin-top: 12px; }
.kv { display: grid; grid-template-columns: 110px 1fr; gap: 5px 9px; font-size: 12px; line-height: 1.4; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; overflow-wrap: anywhere; }
details summary { cursor: pointer; color: var(--blue); font-size: 12px; }
pre { max-height: 260px; overflow: auto; border-radius: 7px; padding: 9px; background: #f3f6f8; white-space: pre-wrap; overflow-wrap: anywhere; font: 11px/1.4 Consolas, monospace; }

.login { display: grid; place-items: center; min-height: 75%; text-align: center; }
.login-box { max-width: 310px; }
.login-mark { display: grid; place-items: center; width: 76px; height: 76px; margin: 0 auto 18px; border-radius: 24px; color: #fff; background: linear-gradient(135deg, #16324f, #2d79ad); font-weight: 800; }
#telegram-widget { display: flex; justify-content: center; min-height: 40px; }
.spinner { display: inline-block; width: 16px; height: 16px; border: 2px solid rgba(255,255,255,.45); border-top-color: #fff; border-radius: 50%; animation: spin .7s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.toast { position: fixed; z-index: 3000; right: 18px; bottom: 18px; max-width: 430px; transform: translateY(20px); opacity: 0; pointer-events: none; border-radius: 10px; padding: 11px 14px; color: white; background: #253c52; box-shadow: var(--shadow); transition: .2s; font-size: 13px; }
.toast.show { transform: translateY(0); opacity: 1; }
.toast.error { background: #a93446; }
.mobile-only { display: none; }
.icon-button { border: 0; color: white; background: transparent; font-size: 22px; }

.rumb-handle-inner { filter: hue-rotate(145deg); }
.project-exports { display:flex; align-items:center; gap:12px; margin:0 0 12px; color:var(--muted); font-size:12px; }
.project-exports a { color:#175e94; font-weight:650; padding:4px 0; }
.user-admin-edit { margin: 8px 0; }
.user-admin-edit form { margin-top: 8px; }
.distribution-table table { table-layout: fixed; }
.distribution-table .distribution-measure { width: 64px; }
.distribution-table .distribution-flag { width: 34px; }
.distribution-table .membership-mode { width: 86px; }
.distribution-table select { padding: 5px 1px; font-size: 11px; }
.oks-setting { margin: 12px 0; }
.stage-next { margin-top: 14px; }
.report-inventory { margin-top: 14px; }
.report-inventory ul { margin: 8px 0; padding: 0; list-style: none; }
.report-inventory li { padding: 6px 0; border-bottom: 1px solid var(--line); }
.report-inventory button { padding: 0; border: 0; background: none; color: var(--blue); text-align: left; }
.report-inventory small { display: block; line-height: 1.4; color: var(--muted); }
.distribution-table :is(th, td) { padding-inline: 5px; }
.distribution-table :is(th, td):not(:first-child) { text-align: center; }
.distribution-table :is(th, td):is(:nth-child(2), :nth-child(3)) { font-variant-numeric: tabular-nums; }
.distribution-table td input[type="checkbox"] { margin: 0; vertical-align: middle; }
.distribution-table .cad-select { max-width: 100%; overflow-wrap: anywhere; padding:0; color:#154e79; background:none; border:0; font:inherit; text-align:left; }
.distribution-table .selected td { background:#cfecf6; box-shadow:inset 0 -1px #86bcd6; }
.distribution-table td small { display:block; font-size:10px; color:#40566c; }
.distribution-table .vri-summary { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.distribution-group th { position:static; background:#e2ebf2; color:#243d57; text-align:left; }
.parcel-table-help { margin: 6px 0 0; }
.rumb-handle-outer { filter: hue-rotate(330deg); }

.szz-layers { position: relative; }
.layers-toggle { width: 31px; height: 31px; min-height: 31px; padding: 4px; border: 2px solid rgba(0,0,0,.2); border-radius: 5px; background: #fff; color: #34445b; box-shadow: 0 1px 4px rgba(0,0,0,.13); }
.layers-toggle svg { display: block; pointer-events: none; }
.basemap-menu { position: absolute; top: 37px; right: 0; width: 255px; max-width: calc(100vw - 72px); max-height: min(410px, calc(100vh - 160px)); overflow: auto; padding: 10px; border: 1px solid #ccd5df; border-radius: 7px; color: #172d48; background: #fff; box-shadow: 0 5px 24px rgba(21,47,75,.19); cursor: auto; font: 12px/1.4 system-ui, sans-serif; }
.basemap-heading { margin-bottom: 4px; font-weight: 700; }
.basemap-menu fieldset { margin: 5px 0 9px; padding: 0; border: 0; }
.basemap-menu legend { margin: 0 0 3px; color: #62758b; font-size: 10px; text-transform: uppercase; letter-spacing: .7px; }
.basemap-menu fieldset label { display: flex; align-items: center; gap: 7px; padding: 4px 3px; border-radius: 4px; cursor: pointer; }
.basemap-menu fieldset label:hover { background: #edf4fd; }
.basemap-menu input[type="radio"] { flex-shrink: 0; width: 13px; height: 13px; margin: 0; padding: 0; accent-color: #1369cb; }
.basemap-menu .imagery-opacity { display: block; padding-top: 7px; border-top: 1px solid #e4eaf1; font-size: 11px; }
.imagery-opacity input { display: block; width: 100%; padding: 0; accent-color: #1369cb; cursor: pointer; }
.basemap-menu small { display: block; margin-top: 7px; color: #62758b; font-size: 10px; line-height: 1.4; }
.leaflet-control-attribution { max-width: 90%; font-size: 9px; line-height: 1.25; }

@media (max-width: 900px) {
  .app-shell { grid-template-rows: 56px 50px minmax(0,1fr); }
  .topbar { padding: 0 10px; gap: 10px; }
  .mobile-only { display: inline-flex; }
  .brand { min-width: 0; }
  .brand small, .project-caption { display: none; }
  .user-caption { min-width: 0; margin-left: auto; }
  .user-caption .user-name { display: none; }
  .stage-nav { grid-template-columns: repeat(7, minmax(105px,1fr)); }
  .stage-nav button { font-size: 11px; }
  .workspace { grid-template-columns: 1fr; }
  .panel { position: absolute; inset: 106px auto 0 0; width: min(92vw, 430px); transform: translateX(-102%); transition: transform .2s; box-shadow: var(--shadow); }
  .panel.open { transform: translateX(0); }
}
@media (max-width: 480px) {
  .distribution-table .distribution-measure { width: 54px; }
  .distribution-table .distribution-flag { width: 34px; }
  .distribution-table .membership-mode { width: 72px; }
  .distribution-table :is(th, td) { padding-inline: 4px; }
}
.basemap-drag-surface { position:absolute; inset:0; z-index:850; cursor:move; touch-action:none; }
.szz-layers { display:flex; padding:3px; gap:2px; border:1px solid #bbcad6; border-radius:11px; background:white; box-shadow:0 2px 9px #18304b2b; }
.szz-layers > button { border:0; border-radius:7px; background:transparent; color:#304b61; padding:6px 10px; font:600 13px/19px system-ui,sans-serif; }
.szz-layers > button.chosen { background:#194862; color:white; }
.szz-layers > button[aria-expanded=true] { box-shadow:inset 0 -2px #54a599; }
.szz-layers > button { display:inline-flex; align-items:center; gap:5px; }
.szz-layers > button:hover:not(.chosen) { background:#edf4f7; }
.szz-layers > button::after { content:''; width:5px; height:5px; border:solid currentColor; border-width:0 1.5px 1.5px 0; transform:translateY(-1px) rotate(45deg); margin-left:2px; }
.szz-layers > button[aria-expanded=true]::after { transform:translateY(1px) rotate(225deg); }
.szz-layers > button:last-of-type { border-left:1px solid #d9e2e8; }
.distribution-filter { display:flex; align-items:center; gap:7px; margin:10px 0; }
.distribution-filter input { width:16px; height:16px; margin:0; accent-color:var(--blue); }
.szz-layers .basemap-menu { left:0; right:auto; top:calc(100% + 4px); }
.szz-layers [hidden] { display:none !important; }
.basemap-menu input[type=checkbox] { width:16px; height:16px; accent-color:#227260; }
.basemap-menu input[type=number] { width:80px; margin-left:auto; }
.leaflet-tooltip.quarter-label {
  padding: 2px 5px;
  background: rgba(255, 255, 255, .94);
  color: #006c69;
  border: 0;
  box-shadow: none;
  font-size: 14px;
  font-weight: 700;
  pointer-events: none;
}
