: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(5, minmax(120px, 1fr)); background: #fff; border-bottom: 1px solid var(--line); z-index: 1000; }
.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; }
.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; }
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; }

.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); }
.rumb-handle-outer { filter: hue-rotate(330deg); }

@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 { overflow-x: auto; grid-template-columns: repeat(5, 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); }
}
