/* =========================================================
   TDS Panel — тёмная тема
   ========================================================= */
:root {
  --bg:        #0d1117;
  --bg2:       #131a22;
  --card:      #161d27;
  --card2:     #1b242f;
  --line:      #232d3a;
  --line2:     #2c3949;
  --txt:       #dbe3ee;
  --muted:     #7d8ca1;
  --muted2:    #5a677a;
  --accent:    #4da3ff;
  --accent-d:  #1c6fd1;
  --ok:        #3fb96c;
  --ok-d:      #1d6b43;
  --warn:      #e8a33d;
  --warn-d:    #7a5316;
  --err:       #ef6262;
  --err-d:     #7e2b2b;

  --t1: #3fb96c;
  --t2: #4da3ff;
  --t3: #e8a33d;
  --t4: #8b96a8;

  --r: 10px;
  --mono: "SFMono-Regular", "Cascadia Code", Consolas, "Liberation Mono", monospace;
  --sans: -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--txt);
  font-family: var(--sans);
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}
h1, h2, h3 { margin: 0; font-weight: 600; }
h1 { font-size: 20px; }
h2 { font-size: 15px; }
h3 { font-size: 15px; }
p { margin: 0; }
a { color: var(--accent); }
.muted { color: var(--muted); }
.muted.thin { font-weight: 400; font-size: 12px; color: var(--muted2); margin-left: 6px; }
.hidden { display: none !important; }
.spacer { flex: 1; }

/* ---------------- layout ---------------- */
.app { display: flex; min-height: 100vh; }
.sidebar {
  width: 212px;
  flex: none;
  background: var(--bg2);
  border-right: 1px solid var(--line);
  display: flex;
  flex-direction: column;
  padding: 18px 12px;
}
.brand {
  font-size: 18px;
  font-weight: 700;
  letter-spacing: .5px;
  padding: 0 8px 18px;
  color: var(--txt);
}
.brand span { color: var(--accent); }
.sidebar nav { display: flex; flex-direction: column; gap: 4px; flex: 1; }
.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 10px;
  border-radius: 8px;
  color: var(--muted);
  text-decoration: none;
  font-size: 14px;
  border: 1px solid transparent;
}
.nav-item:hover { color: var(--txt); background: var(--card); }
.nav-item.active {
  color: var(--txt);
  background: var(--card2);
  border-color: var(--line2);
}
.nav-ic { width: 18px; text-align: center; opacity: .85; }
.sidebar-foot {
  padding: 12px 10px 0;
  border-top: 1px solid var(--line);
  margin-top: 10px;
  color: var(--muted);
  font-size: 12px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.link { color: var(--muted); text-decoration: none; }
.link:hover { color: var(--err); }

.main { flex: 1; padding: 22px 26px 60px; overflow-x: auto; }

/* ---------------- page head ---------------- */
.page-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 18px;
}
.head-actions { display: flex; gap: 8px; }

/* ---------------- cards ---------------- */
.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--r);
  margin-bottom: 18px;
  overflow: hidden;
}
.card-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  padding: 12px 16px;
  border-bottom: 1px solid var(--line);
  background: var(--card2);
  flex-wrap: wrap;
}
.card-body { padding: 16px; }

/* ---------------- buttons ---------------- */
.btn {
  font: inherit;
  font-size: 13px;
  color: var(--txt);
  background: var(--bg2);
  border: 1px solid var(--line2);
  border-radius: 8px;
  padding: 7px 13px;
  cursor: pointer;
  transition: background .13s, border-color .13s, opacity .13s;
}
.btn:hover { background: var(--card2); border-color: #3b4c61; }
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: .45; cursor: not-allowed; }
.btn-primary { background: var(--accent-d); border-color: var(--accent-d); color: #fff; }
.btn-primary:hover { background: #2a84ec; border-color: #2a84ec; }
.btn-on { background: var(--ok-d); border-color: var(--ok-d); color: #eafff3; }
.btn-on:hover { background: #268251; border-color: #268251; }
.btn-off { background: var(--err-d); border-color: var(--err-d); color: #ffe9e9; }
.btn-off:hover { background: #993939; border-color: #993939; }
.btn-block { width: 100%; }
.btn-sm { padding: 4px 9px; font-size: 12px; }

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

/* ---------------- tables ---------------- */
.tbl {
  width: 100%;
  border-collapse: collapse;
  font-size: 13.5px;
}
.tbl th {
  text-align: left;
  color: var(--muted);
  font-weight: 600;
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: .5px;
  padding: 8px 10px;
  border-bottom: 1px solid var(--line);
}
.tbl td {
  padding: 9px 10px;
  border-bottom: 1px solid var(--line);
  vertical-align: middle;
}
.tbl tbody tr:last-child td { border-bottom: none; }
.tbl tbody tr:hover { background: var(--card2); }
.row-loading td { color: var(--muted); text-align: center; padding: 18px; }
.tablewrap { overflow-x: auto; max-height: 420px; overflow-y: auto; border: 1px solid var(--line); border-radius: 8px; }
.tbl-grid td, .tbl-grid th { text-align: center; }

/* ---------------- badges ---------------- */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  font-size: 11.5px;
  font-weight: 600;
  padding: 3px 8px;
  border-radius: 999px;
  background: var(--bg2);
  border: 1px solid var(--line2);
  color: var(--muted);
  white-space: nowrap;
}
.badge-ok { background: rgba(63,185,108,.14); border-color: rgba(63,185,108,.4); color: #7fe0a5; }
.badge-warn { background: rgba(232,163,61,.14); border-color: rgba(232,163,61,.4); color: #f2c679; }
.badge-err { background: rgba(239,98,98,.14); border-color: rgba(239,98,98,.4); color: #f8a2a2; }
.tag { font-size: 10px; padding: 2px 7px; border-radius: 999px; background: var(--bg); border: 1px solid var(--line2); color: var(--muted); }
.tag-soon { margin-left: auto; }

.dot { width: 9px; height: 9px; border-radius: 50%; display: inline-block; }
.dot-on { background: var(--ok); box-shadow: 0 0 8px rgba(63,185,108,.7); }
.dot-off { background: var(--err); box-shadow: 0 0 8px rgba(239,98,98,.5); }
.dot-unk { background: var(--muted2); }

.pill-on  { color: #7fe0a5; font-weight: 700; }
.pill-off { color: #f8a2a2; font-weight: 700; }

/* tier colors */
.t1 { --tc: var(--t1); }
.t2 { --tc: var(--t2); }
.t3 { --tc: var(--t3); }
.t4 { --tc: var(--t4); }

/* ---------------- traffic row ---------------- */
.sw {
  position: relative;
  width: 44px;
  height: 24px;
  border-radius: 999px;
  background: var(--err-d);
  border: 1px solid var(--line2);
  cursor: pointer;
  appearance: none;
  -webkit-appearance: none;
  transition: background .15s;
  flex: none;
}
.sw::after {
  content: "";
  position: absolute;
  top: 2px; left: 2px;
  width: 18px; height: 18px;
  border-radius: 50%;
  background: #fff;
  transition: left .15s;
}
.sw:checked { background: var(--ok-d); }
.sw:checked::after { left: 22px; }
.sw:disabled { opacity: .4; cursor: wait; }

.row-site { font-weight: 600; }
.row-host { font-size: 11.5px; color: var(--muted2); font-family: var(--mono); }

/* ---------------- tabs ---------------- */
.tabs { display: flex; gap: 4px; flex-wrap: wrap; }
.tab {
  font: inherit;
  font-size: 13px;
  font-weight: 600;
  padding: 6px 14px;
  border-radius: 999px;
  border: 1px solid var(--line2);
  background: var(--bg2);
  color: var(--muted);
  cursor: pointer;
}
.tab:hover { color: var(--txt); }
.tab.active {
  color: #fff;
  background: color-mix(in srgb, var(--tc) 24%, transparent);
  border-color: var(--tc);
}

/* ---------------- editor ---------------- */
.editor-wrap { display: flex; flex-direction: column; gap: 10px; }
.editor {
  width: 100%;
  min-height: 240px;
  resize: vertical;
  font-family: var(--mono);
  font-size: 12.5px;
  line-height: 1.6;
  background: var(--bg);
  color: #d7e0ec;
  border: 1px solid var(--line2);
  border-radius: 8px;
  padding: 12px 14px;
  outline: none;
  tab-size: 2;
}
.editor:focus { border-color: var(--accent); }
.editor-foot {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

/* ---------------- map: toolbar ---------------- */
.map-toolbar {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  margin-bottom: 14px;
}
.inp {
  font: inherit;
  font-size: 13px;
  color: var(--txt);
  background: var(--bg);
  border: 1px solid var(--line2);
  border-radius: 8px;
  padding: 7px 11px;
  outline: none;
}
.inp:focus { border-color: var(--accent); }
.fld-inline { display: flex; align-items: center; gap: 7px; color: var(--muted); font-size: 12.5px; }
.fld-inline select { width: 64px; padding: 6px 8px; }

/* ---------------- kanban ---------------- */
.board { display: grid; grid-template-columns: repeat(4, 1fr); gap: 12px; }
.board-col {
  background: var(--bg2);
  border: 1px solid var(--line);
  border-top: 3px solid var(--tc);
  border-radius: var(--r);
  display: flex;
  flex-direction: column;
  min-height: 280px;
}
.board-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 9px 12px;
  font-weight: 700;
  border-bottom: 1px solid var(--line);
  color: var(--tc);
}
.board-count {
  font-family: var(--mono);
  font-size: 12px;
  background: var(--card2);
  border: 1px solid var(--line2);
  border-radius: 999px;
  padding: 1px 8px;
  color: var(--txt);
}
.board-body {
  padding: 8px;
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
  align-content: flex-start;
  flex: 1;
  overflow-y: auto;
  max-height: 340px;
}
.board-body.drag-over {
  background: color-mix(in srgb, var(--tc) 12%, transparent);
  box-shadow: inset 0 0 0 1px var(--tc);
}
.chip {
  font-family: var(--mono);
  font-size: 11.5px;
  font-weight: 600;
  padding: 3px 7px;
  border-radius: 6px;
  background: var(--card2);
  border: 1px solid var(--line2);
  cursor: grab;
  user-select: none;
  color: var(--txt);
}
.chip:hover { border-color: var(--tc); }
.chip:active { cursor: grabbing; }
.chip.dragging { opacity: .35; }
.chip.sel { outline: 2px solid var(--accent); }

/* активная кнопка переключения вида/тира */
.btn.active {
  color: #fff;
  background: color-mix(in srgb, var(--accent) 22%, transparent);
  border-color: var(--accent);
}
.btn.active.t1 { background: color-mix(in srgb, var(--t1) 24%, transparent); border-color: var(--t1); color: #dffff0; }
.btn.active.t2 { background: color-mix(in srgb, var(--t2) 24%, transparent); border-color: var(--t2); color: #e2f1ff; }
.btn.active.t3 { background: color-mix(in srgb, var(--t3) 24%, transparent); border-color: var(--t3); color: #fff3de; }

/* map table select */
.sel-tier {
  font: inherit;
  font-size: 12px;
  padding: 3px 6px;
  color: var(--txt);
  background: var(--bg);
  border: 1px solid var(--line2);
  border-radius: 6px;
}
.tbl tbody tr.flash { background: color-mix(in srgb, var(--accent) 22%, transparent); }

/* ---------------- map: поиск с выпадающим списком ---------------- */
.search-wrap { position: relative; }
.search-drop {
  position: absolute;
  top: calc(100% + 4px);
  left: 0;
  z-index: 40;
  min-width: 210px;
  background: var(--card2);
  border: 1px solid var(--line2);
  border-radius: 8px;
  box-shadow: 0 14px 32px rgba(0,0,0,.55);
  max-height: 320px;
  overflow-y: auto;
  padding: 4px;
}
.drop-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 6px 9px;
  border-radius: 6px;
  cursor: pointer;
  font-size: 13px;
}
.drop-item:hover,
.drop-item.active { background: color-mix(in srgb, var(--accent) 18%, transparent); }

/* ---------------- map: вид "Назначение" ---------------- */
.assign-head {
  display: flex;
  align-items: center;
  gap: 14px;
  flex-wrap: wrap;
  margin-bottom: 12px;
}
.assign-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(116px, 1fr));
  gap: 4px;
  max-height: 440px;
  overflow-y: auto;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px;
  background: var(--bg2);
}
.as-item {
  display: flex;
  align-items: center;
  gap: 7px;
  padding: 5px 8px;
  border-radius: 6px;
  border: 1px solid transparent;
  cursor: pointer;
  font-size: 12.5px;
  user-select: none;
}
.as-item:hover { background: var(--card2); }
.as-item .as-code { font-family: var(--mono); font-weight: 600; }
.as-item input { accent-color: var(--tc); width: 14px; height: 14px; margin: 0; cursor: pointer; flex: none; }
.as-item.as-cur {
  border-color: color-mix(in srgb, var(--tc) 55%, transparent);
  background: color-mix(in srgb, var(--tc) 10%, transparent);
}
.as-item.as-cur .as-code { color: var(--tc); }
.as-item.as-other { opacity: .7; }
.as-item.as-other input { cursor: not-allowed; }
.as-badge {
  margin-left: auto;
  font-size: 10px;
  font-weight: 700;
  padding: 1px 6px;
  border-radius: 999px;
  border: 1px solid var(--tc);
  color: var(--tc);
  cursor: pointer;
  white-space: nowrap;
}
.as-badge.as-free-b { border-color: var(--muted2); color: var(--muted); cursor: default; }

/* ---------------- op log ---------------- */
.op-log {
  font-family: var(--mono);
  font-size: 12px;
  max-height: 300px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.op-line {
  padding: 6px 10px;
  border-radius: 6px;
  background: var(--bg2);
  border-left: 3px solid var(--line2);
  display: flex;
  gap: 10px;
  align-items: baseline;
  flex-wrap: wrap;
}
.op-line.ok { border-left-color: var(--ok); }
.op-line.fail { border-left-color: var(--err); }
.op-line .t { color: var(--muted2); }
.op-line .site { font-weight: 700; }
.op-line .ver { color: var(--ok); }
.op-line .why { color: #f8a2a2; }

/* ---------------- login ---------------- */
body.login-page { background: var(--bg); }
.login-wrap-outer { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 20px; }
.login-wrap {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg);
  padding: 20px;
}
.login-card {
  width: 100%;
  max-width: 340px;
  background: var(--card);
  border: 1px solid var(--line2);
  border-radius: 14px;
  padding: 26px 24px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}
.login-logo { font-size: 24px; font-weight: 800; text-align: center; }
.login-logo span { color: var(--accent); }
.login-sub { text-align: center; color: var(--muted); font-size: 13px; margin-top: -6px; }
.fld { display: flex; flex-direction: column; gap: 5px; font-size: 12px; color: var(--muted); }
.fld input {
  font: inherit;
  font-size: 14px;
  color: var(--txt);
  background: var(--bg);
  border: 1px solid var(--line2);
  border-radius: 8px;
  padding: 9px 12px;
  outline: none;
}
.fld input:focus { border-color: var(--accent); }
.login-hint { text-align: center; font-size: 11.5px; color: var(--muted2); }

/* ---------------- alerts ---------------- */
.alert {
  border-radius: 8px;
  padding: 9px 12px;
  font-size: 13px;
  border: 1px solid;
}
.alert-err { background: rgba(239,98,98,.12); border-color: rgba(239,98,98,.4); color: #f8a2a2; }

/* ---------------- stub ---------------- */
.stub { text-align: center; padding: 46px 20px; }
.stub-ic { font-size: 38px; color: var(--muted2); margin-bottom: 8px; }
.stub h3 { margin-bottom: 8px; }

/* ---------------- toast ---------------- */
#toasts {
  position: fixed;
  right: 18px;
  bottom: 18px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  z-index: 50;
}
.toast {
  min-width: 260px;
  max-width: 380px;
  background: var(--card2);
  border: 1px solid var(--line2);
  border-left: 3px solid var(--accent);
  border-radius: 8px;
  padding: 10px 14px;
  font-size: 13px;
  box-shadow: 0 10px 28px rgba(0,0,0,.5);
  animation: tin .18s ease-out;
}
.toast.ok { border-left-color: var(--ok); }
.toast.fail { border-left-color: var(--err); }
.toast .tt { font-weight: 700; margin-bottom: 2px; }
.toast .td { color: var(--muted); font-size: 12px; }
@keyframes tin { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }

/* ---------------- modal ---------------- */
.modal-back {
  position: fixed;
  inset: 0;
  background: rgba(4,8,14,.72);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 60;
  padding: 24px;
}
.modal {
  width: 100%;
  max-width: 820px;
  max-height: 84vh;
  background: var(--card);
  border: 1px solid var(--line2);
  border-radius: 12px;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
.modal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px;
  border-bottom: 1px solid var(--line);
  background: var(--card2);
}
.modal-body { padding: 14px 16px; overflow-y: auto; }
.modal pre {
  font-family: var(--mono);
  font-size: 12px;
  line-height: 1.6;
  color: #cfe0f5;
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
  margin: 0;
  white-space: pre-wrap;
  max-height: 58vh;
  overflow-y: auto;
}

/* ---------------- stats ---------------- */
.freshness { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; margin-bottom: 16px; }

.stat-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 12px;
}
.stat-card {
  background: var(--bg2);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 14px 16px;
}
.stat-card.sc-main { border-color: color-mix(in srgb, var(--accent) 45%, transparent); }
.stat-card .sc-label {
  color: var(--muted);
  font-size: 11.5px;
  text-transform: uppercase;
  letter-spacing: .5px;
  font-weight: 600;
}
.stat-card .sc-val {
  font-size: 26px;
  font-weight: 700;
  font-family: var(--mono);
  margin-top: 4px;
}
.stat-card .sc-sub { color: var(--muted2); font-size: 11.5px; margin-top: 3px; }

.tier-row {
  display: grid;
  grid-template-columns: 64px 1fr 110px 46px;
  gap: 14px;
  align-items: center;
  padding: 8px 0;
}
.tier-row + .tier-row { border-top: 1px solid var(--line); }
.tier-row .tr-name { font-weight: 700; color: var(--tc); }
.tier-row .tr-bar {
  height: 14px;
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 999px;
  overflow: hidden;
}
.tier-row .tr-fill {
  display: block;
  height: 100%;
  background: var(--tc);
  border-radius: 999px;
  min-width: 2px;
}
.tier-row .tr-n { font-family: var(--mono); text-align: right; }
.tier-row .tr-p { color: var(--muted); font-size: 12px; text-align: right; }

/* ---------------- responsive ---------------- */
@media (max-width: 1100px) {
  .board { grid-template-columns: repeat(2, 1fr); }
}
@media (max-width: 760px) {
  .app { flex-direction: column; }
  .sidebar { width: 100%; flex-direction: row; align-items: center; padding: 10px; }
  .sidebar nav { flex-direction: row; }
  .sidebar-foot { border-top: none; padding: 0 8px; margin: 0; }
  .board { grid-template-columns: 1fr; }
  .main { padding: 16px; }
}
