:root {
  color-scheme: light;
  font-family: "IBM Plex Sans", "Segoe UI", sans-serif;
  background: #edf3fb;
  color: #122035;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background: radial-gradient(circle at 5% 10%, #f7fbff, #e7effa 45%, #dbe6f3 100%);
}

.topbar {
  display: grid;
  grid-template-columns: auto minmax(680px, 1fr) auto;
  align-items: center;
  gap: 14px;
  padding: 8px 14px;
  border-bottom: 1px solid #c9d8ea;
  background: #ffffffcc;
  backdrop-filter: blur(4px);
  position: sticky;
  top: 0;
  z-index: 20;
}

.topbar h1 {
  margin: 0;
  font-size: 21px;
  letter-spacing: 0.4px;
  white-space: nowrap;
}
.topbar h1 span { color: #58708b; font-size: 13px; font-weight: 600; }

.topbar-block,
.project-save-bar {
  border: 1px solid #d5e1ef;
  border-radius: 11px;
  background: #f8fbff;
  box-shadow: 0 2px 8px rgba(20, 53, 89, 0.06);
}

.topbar-brand {
  display: flex;
  align-items: center;
  min-height: 50px;
  padding: 7px 12px;
}

.top-actions {
  display: flex;
  gap: 8px;
  align-items: center;
  justify-content: flex-end;
  white-space: nowrap;
  min-height: 50px;
  padding: 7px;
}

.project-save-bar {
  display: grid;
  grid-template-columns: minmax(150px, 240px) auto minmax(150px, 1fr) auto auto;
  gap: 7px;
  align-items: stretch;
  min-width: 0;
  padding: 4px;
}

.current-project-box, .clock-box {
  display: grid;
  align-content: center;
  min-height: 42px;
  padding: 3px 9px;
  border: 1px solid #c8d9ed;
  border-radius: 8px;
  background: #fff;
}
.current-project-box span, .clock-box span, .clock-box small { color: #526b86; font-size: 11px; }
.current-project-box strong { font-size: 15px; }
.project-save-bar > button { min-height: 42px; padding-top: 4px; padding-bottom: 4px; }
.project-save-summary { align-self: center; color: #526b86; font-size: 14px; font-weight: 650; line-height: 1.3; }
.project-save-summary.pending { color: #b42323; }
.project-save-summary.saved { color: #24713c; }
.project-save-bar > button { position: relative; }
.project-save-bar > button.has-unsaved::after {
  content: "!";
  position: absolute;
  top: -8px;
  right: -8px;
  display: grid;
  place-items: center;
  width: 22px;
  height: 22px;
  border: 2px solid #fff;
  border-radius: 50%;
  background: #d32626;
  color: #fff;
  font-size: 14px;
  font-weight: 800;
  box-shadow: 0 2px 7px rgba(130, 15, 15, 0.35);
}
.clock-box { gap: 1px; min-width: 145px; }
.clock-box strong { font-variant-numeric: tabular-nums; font-size: 15px; line-height: 1.05; }

input, select, button, textarea, .button {
  font: inherit;
  border-radius: 8px;
  border: 1px solid #b8cbe2;
  padding: 7px 10px;
  background: #fff;
  color: #10233b;
}

textarea {
  resize: vertical;
  min-height: 56px;
  font-family: ui-monospace, "SF Mono", Menlo, monospace;
  font-size: 12px;
}

button, .button {
  cursor: pointer;
  background: #173b68;
  color: #fff;
  border-color: #173b68;
  text-decoration: none;
}

button:hover, .button:hover {
  background: #214f88;
}

button:disabled, select:disabled {
  cursor: wait;
  opacity: 0.58;
}

button.danger {
  background: #922b2b;
  border-color: #922b2b;
}

.layout {
  display: grid;
  grid-template-columns: 1fr 390px;
  gap: 14px;
  padding: 14px;
}

.panel {
  border-radius: 12px;
  background: #ffffff;
  border: 1px solid #c8d9ed;
  box-shadow: 0 8px 20px rgba(15, 42, 72, 0.09);
}

.map-panel {
  display: grid;
  grid-template-rows: 1fr auto;
  min-height: calc(100vh - 90px);
  position: relative;
}

#map-canvas {
  width: 100%;
  height: 100%;
  min-width: 0;
  min-height: 0;
  display: block;
  border-radius: 12px 12px 0 0;
  border-bottom: 1px solid #d2deec;
}

.status {
  padding: 8px 12px;
  font-size: 13px;
  color: #344c66;
}

.status.error {
  color: #8f2424;
}

.tag-popover {
  position: absolute;
  min-width: 240px;
  max-width: 300px;
  background: #ffffff;
  border: 1px solid #b8cbe2;
  border-radius: 10px;
  box-shadow: 0 10px 22px rgba(15, 42, 72, 0.22);
  padding: 10px;
  z-index: 30;
}

.tag-popover.hidden {
  display: none;
}

.controls-panel {
  padding: 10px;
  max-height: calc(100vh - 90px);
  overflow: auto;
}

@media (max-width: 1450px) {
  .topbar { grid-template-columns: auto minmax(540px, 1fr) auto; }
  .project-save-summary { display: none; }
  .project-save-bar { grid-template-columns: minmax(140px, 1fr) auto auto auto; }
}

@media (max-width: 1100px) {
  .topbar { grid-template-columns: auto 1fr; }
  .project-save-bar { grid-column: 1 / -1; grid-row: 2; }
  .top-actions { grid-column: 2; grid-row: 1; }
}

.subpanel {
  border: 1px solid #dbe6f3;
  border-radius: 10px;
  padding: 10px;
  margin-bottom: 10px;
  background: #fbfdff;
}

.subpanel h2 {
  margin: 0 0 8px;
  font-size: 15px;
}

.form-grid {
  display: grid;
  gap: 8px;
}

.form-grid label {
  display: grid;
  gap: 4px;
  font-size: 12px;
}

.checkbox {
  display: flex !important;
  align-items: center;
  gap: 8px;
}

.button-row {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.table-wrap {
  margin-top: 8px;
  overflow: auto;
  max-height: 220px;
}

table {
  border-collapse: collapse;
  width: 100%;
  font-size: 12px;
}

th, td {
  border: 1px solid #d8e5f4;
  padding: 4px 6px;
  text-align: left;
}

.target-list {
  display: grid;
  gap: 6px;
}

.target-row {
  border: 1px solid #d8e5f4;
  border-radius: 8px;
  padding: 6px;
  background: #fff;
}

.target-row .name {
  font-weight: 600;
  font-size: 13px;
}

.target-row .meta {
  font-size: 12px;
  color: #4c6078;
}

.session-list {
  display: grid;
  gap: 6px;
}

.session-row {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr auto;
  gap: 6px;
  align-items: center;
  border: 1px solid #d8e5f4;
  border-radius: 8px;
  padding: 6px;
  font-size: 12px;
}

.muted {
  color: #687f98;
  font-size: 13px;
}

.preset-panel select option[data-active="true"] {
  font-weight: 700;
}

.project-devices {
  grid-column: 1 / -1;
  margin-top: 8px;
  padding-top: 10px;
  border-top: 1px solid var(--border, #d7dce3);
}

.project-devices h3 { margin: 0 0 6px; font-size: 14px; }

.project-device-list {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(230px, 1fr));
  gap: 6px;
  max-height: 280px;
  overflow: auto;
  margin-top: 8px;
}

.project-device-row {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  padding: 8px;
  border: 1px solid var(--border, #d7dce3);
  border-radius: 6px;
  background: rgba(255, 255, 255, 0.55);
}

.project-device-row small { display: block; margin-top: 2px; color: #687180; }

.history-devices {
  display: grid;
  gap: 6px;
  padding: 8px;
  border: 1px solid var(--border, #d7dce3);
  border-radius: 8px;
  background: #f8fbff;
}

.history-devices > b { font-size: 12px; }
.history-devices .project-device-list { max-height: 170px; margin-top: 0; }
.compact-buttons button { padding: 5px 9px; font-size: 12px; }

#map-preset-meta {
  min-height: 34px;
  padding: 7px 9px;
  border-radius: 8px;
  background: #edf4fc;
  border: 1px solid #d4e2f1;
}

@media (max-width: 1200px) {
  .layout {
    grid-template-columns: 1fr;
  }
  .controls-panel {
    max-height: none;
  }
  .map-panel {
    min-height: 65vh;
  }
}

/* ---- Anchor Calibration ---- */
.calib-hint {
  margin: 0 0 8px;
  font-size: 12px;
  color: #4c6078;
  line-height: 1.5;
}

#calib-result {
  margin-top: 10px;
}

#calib-result.calib-hidden {
  display: none;
}

.calib-msg {
  margin: 4px 0;
  font-size: 13px;
  padding: 4px 0;
}

.calib-ok  { color: #1a6b2a; }
.calib-error { color: #8f2424; }

.calib-table {
  width: 100%;
  font-size: 11px;
  border-collapse: collapse;
}

.calib-table th,
.calib-table td {
  border: 1px solid #d8e5f4;
  padding: 3px 5px;
  white-space: nowrap;
}

.calib-improved td { background: #f0fff4; }
.calib-neutral  td { background: #fff; }
.calib-skip     td { color: #999; font-style: italic; }
.calib-skip-label { font-size: 11px; color: #aaa; }

.calib-better { color: #1a6b2a; font-weight: 600; }
.calib-delta  { font-weight: 600; color: #2255a4; }

.calib-actions {
  margin-top: 8px;
  align-items: center;
}

.calib-all-chk {
  font-size: 12px;
  color: #4c6078;
  margin-left: 4px;
}

.btn-outline {
  background: #fff;
  color: #173b68;
  border: 1px solid #173b68;
}

.btn-outline:hover {
  background: #eef4fb;
}

/* ---- Analysis panel ---- */
.an-result {
  margin-top: 4px;
  padding: 8px 10px;
  border-radius: 8px;
  background: #f2f7fd;
  border: 1px solid #dbe6f3;
  font-size: 12px;
  line-height: 1.55;
  word-break: break-word;
}
/* Конвейер LOCUS: этапы в порядке обработки, каждый сворачивается. */
.locus-stage {
  border: 1px solid #dbe6f3;
  border-radius: 8px;
  padding: 6px 10px;
  margin-bottom: 6px;
  background: #fbfdff;
}
.locus-stage > summary {
  cursor: pointer;
  font-weight: 600;
  font-size: 13px;
  padding: 2px 0;
}
.locus-stage-desc {
  font-size: 11px;
  color: #5b6b7d;
  line-height: 1.45;
  margin: 4px 0 8px;
}
.locus-field {
  display: flex;
  flex-direction: column;
  gap: 2px;
  font-size: 12px;
}

/* Диагностика LOCUS — таблица по анкерам, переносы значимы. */
#locus-diag-result {
  white-space: pre-wrap;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
}
.an-sep {
  border: none;
  border-top: 1px dashed #cbd9ea;
  margin: 4px 0;
}
.an-ok { color: #1a6b2a; font-weight: 600; }
.an-warn { color: #a8560a; font-weight: 600; }
.an-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 11px;
  margin-top: 2px;
}
.an-table th, .an-table td {
  border: 1px solid #d8e5f4;
  padding: 3px 5px;
  text-align: right;
  white-space: nowrap;
}
.an-table th:first-child, .an-table td:first-child { text-align: left; }
