:root {
  color-scheme: dark;
  --bg: #0b0e12;
  --panel: #11151b;
  --panel-2: #151a21;
  --panel-3: #0e1217;
  --line: #29313a;
  --line-soft: #202730;
  --text: #edf2f7;
  --muted: #93a0ad;
  --green: #50d890;
  --green-bg: rgba(80, 216, 144, .11);
  --yellow: #f2c45d;
  --yellow-bg: rgba(242, 196, 93, .12);
  --red: #ff7474;
  --red-bg: rgba(255, 116, 116, .12);
  --blue: #6da9ff;
  --radius: 10px;
  --shadow: 0 14px 40px rgba(0, 0, 0, .32);
}

* { box-sizing: border-box; }
html { min-width: 320px; scroll-behavior: smooth; background: var(--bg); }
body {
  min-height: 100vh;
  margin: 0;
  overflow-x: hidden;
  color: var(--text);
  background: var(--bg);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  font-size: 14px;
  -webkit-font-smoothing: antialiased;
}

button, input, select { font: inherit; }
button { color: inherit; }
a { color: var(--blue); text-decoration: none; }
a:hover { text-decoration: underline; }
.is-hidden { display: none !important; }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0; }

h1, h2, h3, p { margin-top: 0; }
h1 { margin-bottom: 5px; font-size: clamp(21px, 2vw, 28px); line-height: 1.2; }
h2 { margin-bottom: 4px; font-size: 18px; line-height: 1.25; }
h3 { margin-bottom: 5px; font-size: 14px; }
.eyebrow { margin: 0 0 5px; color: var(--green); font-size: 10px; font-weight: 700; letter-spacing: .12em; text-transform: uppercase; }

.button {
  min-height: 36px;
  padding: 7px 13px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: var(--panel-2);
  color: var(--text);
  cursor: pointer;
  font-weight: 650;
  line-height: 1.2;
}
.button:hover:not(:disabled) { border-color: #44505c; background: #1b222b; }
.button:disabled { cursor: not-allowed; opacity: .48; }
.button-primary { border-color: #3ead72; background: #3ead72; color: #07110b; }
.button-primary:hover:not(:disabled) { border-color: var(--green); background: var(--green); }
.button-secondary { background: transparent; }
.button-ghost { border-color: transparent; background: transparent; color: var(--muted); }
.button-danger { color: var(--red); }
.button-small { min-height: 30px; padding: 5px 9px; font-size: 12px; }
.button-wide { width: 100%; }
.icon-button {
  display: inline-grid;
  width: 34px;
  height: 34px;
  padding: 0;
  place-items: center;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  font-size: 18px;
}
.icon-button:hover { border-color: #45515e; color: var(--text); }
.danger-button { color: var(--red); }

input, select {
  width: 100%;
  min-width: 0;
  min-height: 36px;
  padding: 7px 9px;
  border: 1px solid var(--line);
  border-radius: 7px;
  outline: none;
  background: #0d1116;
  color: var(--text);
}
input::placeholder { color: #687480; }
input:focus, select:focus, button:focus-visible { border-color: var(--green); box-shadow: 0 0 0 2px rgba(80, 216, 144, .15); }
label > span, legend { display: block; margin-bottom: 4px; color: var(--muted); font-size: 11px; font-weight: 650; }
label small { display: block; margin-top: 4px; color: var(--muted); font-size: 11px; }

.login-shell { display: grid; min-height: 100vh; padding: 20px; place-items: center; }
.login-card { width: min(100%, 380px); padding: 28px; border: 1px solid var(--line); border-radius: var(--radius); background: var(--panel); box-shadow: var(--shadow); }
.login-card h1 { font-size: 24px; }
.login-lead, .modal-lead { margin-bottom: 20px; color: var(--muted); line-height: 1.5; }
.form-stack { display: grid; gap: 14px; }
.form-error { min-height: 18px; margin: 7px 0 0; color: var(--red); font-size: 12px; line-height: 1.45; }

.app-shell { min-height: 100vh; }
.topbar {
  position: sticky;
  z-index: 20;
  top: 0;
  display: flex;
  min-height: 48px;
  padding: 7px clamp(12px, 2vw, 26px);
  align-items: center;
  justify-content: space-between;
  border-bottom: 1px solid var(--line-soft);
  background: rgba(11, 14, 18, .96);
  backdrop-filter: blur(10px);
}
.topbar-status, .topbar-actions { display: flex; align-items: center; gap: 10px; }
.topbar-status > strong { font-size: 14px; letter-spacing: .02em; }
.system-state { display: inline-flex; align-items: center; gap: 6px; color: var(--green); font-size: 12px; }
.system-state i { width: 7px; height: 7px; border-radius: 50%; background: currentColor; box-shadow: 0 0 0 3px var(--green-bg); }
.system-state.is-offline { color: var(--red); }

.dashboard { display: grid; width: min(100%, 1680px); margin: 0 auto; padding: 14px clamp(10px, 1.8vw, 24px) 42px; gap: 14px; }
.overview-strip {
  display: grid;
  grid-template-columns: repeat(4, minmax(130px, 1fr)) minmax(190px, 1.2fr);
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--panel);
}
.stat-card, .history-select { min-width: 0; padding: 11px 14px; border-right: 1px solid var(--line-soft); }
.stat-card > span, .history-select > span { display: block; margin-bottom: 2px; color: var(--muted); font-size: 10px; font-weight: 700; letter-spacing: .04em; text-transform: uppercase; }
.stat-card strong { margin-right: 8px; font-size: 19px; line-height: 1.2; }
.stat-card small { color: var(--muted); font-size: 10px; }
.history-select { display: grid; align-content: center; border-right: 0; }
.history-select select { min-height: 31px; font-size: 12px; }

.section-block, .panel { min-width: 0; border: 1px solid var(--line); border-radius: var(--radius); background: var(--panel); }
.section-block { padding: 15px; }
.section-heading, .panel-heading { display: flex; min-width: 0; margin-bottom: 12px; align-items: flex-start; justify-content: space-between; gap: 14px; }
.section-heading p, .panel-heading p { margin: 0; color: var(--muted); font-size: 12px; }
.compact-heading { align-items: center; }
.heading-actions { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: 7px; }
.section-counter { min-width: 40px; padding: 5px 8px; border-radius: 6px; background: var(--red-bg); color: var(--red); text-align: center; font-size: 17px; }

.filter-bar { display: grid; margin-bottom: 10px; gap: 7px; align-items: end; }
.incident-filters { grid-template-columns: minmax(190px, 1.5fr) repeat(6, minmax(115px, .8fr)) auto; }
.device-filters { grid-template-columns: minmax(220px, 1.5fr) repeat(3, minmax(130px, .7fr)) auto; }
.filter-search input { min-height: 36px; }
.filter-count { padding: 9px 2px; color: var(--muted); font-size: 12px; white-space: nowrap; }
.inline-error { margin: 8px 0; padding: 8px 10px; border: 1px solid rgba(242, 196, 93, .3); border-radius: 6px; background: var(--yellow-bg); color: var(--yellow); font-size: 12px; }

.ops-table { min-width: 0; overflow: hidden; border: 1px solid var(--line-soft); border-radius: 7px; background: var(--panel-3); }
.incident-table { display: flex; flex-direction: column; }
.ops-row {
  display: grid;
  grid-template-columns: minmax(130px, 1.05fr) minmax(100px, .8fr) minmax(100px, .8fr) minmax(150px, 1.25fr) minmax(68px, .5fr) minmax(140px, 1.1fr) minmax(115px, .85fr) minmax(105px, .7fr);
  min-width: 0;
  border-bottom: 1px solid var(--line-soft);
}
.ops-row:last-child { border-bottom: 0; }
.ops-row > * { min-width: 0; padding: 9px 8px; overflow-wrap: anywhere; }
.ops-head { position: static !important; z-index: auto; align-items: center; background: #171c23; color: var(--muted); font-size: 10px; font-weight: 750; letter-spacing: .03em; text-transform: uppercase; transform: none; }
.incident-row { font-size: 12px; }
.incident-row:hover { background: rgba(255, 255, 255, .025); }
.incident-row.is-offline { box-shadow: inset 3px 0 var(--red); }
.incident-row.is-unreachable { box-shadow: inset 3px 0 var(--yellow); }
.table-cell { display: flex; flex-direction: column; justify-content: center; gap: 2px; }
.table-cell strong { color: var(--text); font-size: 12px; font-weight: 650; }
.table-cell small { color: var(--muted); font-size: 10px; line-height: 1.35; }
.cell-reason strong { color: var(--red); }
.cell-server strong, .mono { font-family: ui-monospace, SFMono-Regular, Consolas, monospace; }
.empty-state { padding: 24px; color: var(--muted); text-align: center; font-size: 12px; }
.incident-table-footer { display: flex; padding-top: 9px; align-items: center; justify-content: flex-end; gap: 10px; }
.incident-table-footer span { color: var(--muted); font-size: 11px; }

@media (min-width: 1101px) {
  .ops-row > * + * { border-left: 1px solid rgba(255, 255, 255, .035); }
}

.device-table { min-width: 0; overflow: hidden; border: 1px solid var(--line-soft); border-radius: 7px; background: var(--panel-3); }
.device-row, .device-row-head {
  display: grid;
  grid-template-columns: minmax(170px, 1.15fr) minmax(150px, 1fr) minmax(150px, 1fr) minmax(140px, .85fr) minmax(190px, auto);
  min-width: 0;
  align-items: center;
  border-bottom: 1px solid var(--line-soft);
}
.device-row:last-child { border-bottom: 0; }
.device-row:hover { background: rgba(255, 255, 255, .025); }
.device-row-head { background: #171c23; color: var(--muted); font-size: 10px; font-weight: 750; letter-spacing: .03em; text-transform: uppercase; }
.device-row > *, .device-row-head > * { min-width: 0; padding: 9px 10px; }
.device-identity, .device-cell { display: flex; min-width: 0; flex-direction: column; gap: 2px; }
.device-identity { position: relative; padding-left: 29px !important; }
.device-identity .device-dot { position: absolute; top: 14px; left: 11px; }
.device-identity strong, .device-cell strong { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 12px; }
.device-identity small, .device-cell span { overflow: hidden; color: var(--muted); font-size: 10px; text-overflow: ellipsis; white-space: nowrap; }
.device-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--red); }
.device-dot.online { background: var(--green); }
.device-actions { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: 6px; }
.device-actions .button { white-space: nowrap; }
.ota-badge { color: var(--blue); }
.location-admin { padding: 7px 10px; border-bottom: 1px solid var(--line-soft); background: #12171d; }
.location-admin summary { color: var(--muted); cursor: pointer; font-size: 11px; }
.location-toolbar { display: flex; padding-top: 7px; flex-wrap: wrap; gap: 5px; }
.location-toolbar button { padding: 4px 7px; border: 1px solid var(--line); border-radius: 5px; background: transparent; color: var(--muted); cursor: pointer; font-size: 10px; }

.control-grid { display: grid; grid-template-columns: minmax(0, 1.2fr) minmax(340px, .8fr); gap: 14px; }
.panel { padding: 15px; }
.source-grid { display: grid; grid-template-columns: 1.4fr 1fr .6fr; gap: 8px; }
.manual-target { display: grid; grid-template-columns: 1fr 100px; margin-top: 8px; gap: 8px; }
.scope-heading { display: flex; margin: 14px 0 8px; align-items: center; justify-content: space-between; gap: 12px; }
.scope-heading h3 { margin: 0; }
.scope-heading p, .run-actions p { margin: 2px 0 0; color: var(--muted); font-size: 11px; }
.switch { display: inline-flex; align-items: center; gap: 6px; }
.switch input { width: 16px; min-height: auto; accent-color: var(--green); }
.switch span { margin: 0; white-space: nowrap; }
.scope-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.scope-grid.is-disabled { opacity: .42; }
fieldset { min-width: 0; margin: 0; padding: 8px; border: 1px solid var(--line-soft); border-radius: 7px; }
.choice-list { display: flex; max-height: 115px; overflow: auto; flex-wrap: wrap; gap: 5px; }
.choice-item { display: inline-flex; align-items: center; gap: 5px; padding: 4px 7px; border: 1px solid var(--line); border-radius: 5px; background: var(--panel-3); }
.choice-item input { width: 13px; min-height: auto; accent-color: var(--green); }
.choice-item span { margin: 0; color: var(--text); font-size: 10px; }
.empty-copy { margin: 0; color: var(--muted); font-size: 11px; }
.run-actions { display: flex; margin-top: 9px; align-items: center; justify-content: space-between; gap: 10px; }
.run-empty { display: grid; min-height: 230px; place-content: center; text-align: center; }
.run-empty p { margin: 0; color: var(--muted); font-size: 12px; }
.run-heading-actions { display: flex; align-items: center; justify-content: flex-end; gap: 7px; }
.progress-track { height: 6px; overflow: hidden; border-radius: 20px; background: #242b34; }
.progress-track span { display: block; width: 0; height: 100%; border-radius: inherit; background: var(--green); transition: width .25s ease; }
.progress-copy { margin: 6px 0 10px; color: var(--muted); font-size: 10px; text-align: right; }
.result-stats { display: grid; grid-template-columns: 1fr 1fr; gap: 7px; }
.result-stats > div { padding: 9px; border: 1px solid var(--line-soft); border-radius: 7px; background: var(--panel-3); }
.result-stats span { display: block; margin-bottom: 2px; color: var(--muted); font-size: 10px; }
.result-stats strong { font-size: 20px; }
.result-stats > div:last-child { grid-column: 1 / -1; }
.run-meta { max-width: 520px; }

.queue-panel { grid-column: 1 / -1; }
.queue-heading { margin-bottom: 9px; }
.queue-list { display: grid; gap: 7px; }
.compact-empty { min-height: 46px; padding: 12px; }
.queue-item { overflow: hidden; border: 1px solid var(--line-soft); border-radius: 7px; background: var(--panel-3); }
.queue-item-head { display: flex; min-width: 0; padding: 9px 10px; align-items: center; justify-content: space-between; gap: 12px; }
.queue-item-head > div:first-child { display: flex; min-width: 0; flex-direction: column; gap: 2px; }
.queue-item-head strong, .queue-item-head span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.queue-item-head > div:first-child span { color: var(--muted); font-size: 10px; }
.queue-counters { display: flex; flex: 0 0 auto; align-items: center; justify-content: flex-end; flex-wrap: wrap; gap: 5px; }
.queue-tasks { border-top: 1px solid var(--line-soft); }
.queue-tasks summary { padding: 7px 10px; color: var(--muted); cursor: pointer; font-size: 10px; }
.queue-task { display: grid; grid-template-columns: minmax(0, 1fr) auto; padding: 6px 10px; align-items: center; gap: 10px; border-top: 1px solid rgba(255, 255, 255, .035); font-size: 10px; }
.queue-task span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.queue-task small { color: var(--muted); }
.queue-task small.is-active { color: var(--yellow); }

.status-pill { display: inline-flex; width: fit-content; align-items: center; gap: 5px; padding: 3px 7px; border-radius: 20px; font-size: 10px; font-weight: 700; white-space: nowrap; }
.status-pill i { width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.status-available { background: var(--green-bg); color: var(--green); }
.status-partial, .status-pending { background: var(--yellow-bg); color: var(--yellow); }
.status-unavailable { background: var(--red-bg); color: var(--red); }
.status-unknown { background: rgba(147, 160, 173, .1); color: var(--muted); }

.view-switch { display: inline-flex; padding: 2px; border: 1px solid var(--line); border-radius: 7px; background: var(--panel-3); }
.view-switch button { padding: 5px 9px; border: 0; border-radius: 5px; background: transparent; color: var(--muted); cursor: pointer; font-size: 11px; }
.view-switch button.is-active { background: #29323c; color: var(--text); }
.results-view { display: grid; grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); gap: 8px; }
.location-result { min-width: 0; padding: 11px; border: 1px solid var(--line-soft); border-radius: 7px; background: var(--panel-3); }
.location-result-head { display: flex; margin-bottom: 8px; align-items: flex-start; justify-content: space-between; gap: 10px; }
.location-result-head h3 { margin: 0; }
.location-result-head p { margin: 2px 0 0; color: var(--muted); font-size: 10px; }
.provider-rows { display: grid; }
.provider-rows > div { display: grid; grid-template-columns: 1fr auto auto; padding: 6px 0; align-items: center; gap: 8px; border-top: 1px solid var(--line-soft); font-size: 11px; }
.provider-rows span { color: var(--muted); }
.server-table { grid-column: 1 / -1; overflow: hidden; border: 1px solid var(--line-soft); border-radius: 7px; }
.server-row { display: grid; grid-template-columns: minmax(180px, 1fr) 90px 100px 110px; padding: 8px 10px; align-items: center; gap: 8px; border-bottom: 1px solid var(--line-soft); font-size: 11px; }
.server-row:last-child { border-bottom: 0; }
.server-row > div { display: flex; min-width: 0; flex-direction: column; }
.server-row small { overflow: hidden; color: var(--muted); text-overflow: ellipsis; white-space: nowrap; }
.server-row-head { background: #171c23; color: var(--muted); font-size: 10px; font-weight: 700; text-transform: uppercase; }

.map-section { padding: 0; overflow: hidden; }
.map-section summary { display: flex; padding: 13px 15px; align-items: center; justify-content: space-between; cursor: pointer; list-style: none; }
.map-section summary::-webkit-details-marker { display: none; }
.map-section summary span:first-child { display: flex; align-items: baseline; gap: 10px; }
.map-section summary small, .map-section summary > span:last-child { color: var(--muted); font-size: 11px; }
.map-shell { position: relative; min-height: 300px; border-top: 1px solid var(--line); background: #0d1116; }
#world-map { display: block; width: 100%; min-height: 300px; }
.countries path { fill: #222a33; stroke: #343e49; stroke-width: .5; }
.markers circle:first-child { stroke: #0b0e12; stroke-width: 2; }
.marker-available { fill: var(--green); }.marker-partial { fill: var(--yellow); }.marker-unavailable { fill: var(--red); }.marker-unknown { fill: var(--muted); }.marker-core { fill: #fff; }
.map-controls { position: absolute; top: 10px; right: 10px; display: flex; overflow: hidden; border: 1px solid var(--line); border-radius: 6px; background: var(--panel); }
.map-controls button { min-width: 32px; min-height: 30px; border: 0; border-right: 1px solid var(--line); background: transparent; color: var(--text); cursor: pointer; }
.map-controls button:last-child { border-right: 0; padding: 0 8px; font-size: 10px; }
.map-legend { position: absolute; right: 10px; bottom: 10px; display: flex; padding: 6px 8px; flex-wrap: wrap; gap: 8px; border: 1px solid var(--line); border-radius: 6px; background: rgba(17, 21, 27, .9); color: var(--muted); font-size: 9px; }
.map-legend span { display: flex; align-items: center; gap: 4px; }.map-legend i { width: 6px; height: 6px; border-radius: 50%; }.map-legend .available { background: var(--green); }.map-legend .partial { background: var(--yellow); }.map-legend .unavailable { background: var(--red); }.map-legend .unknown { background: var(--muted); }
.map-empty { position: absolute; inset: 0; display: grid; margin: 0; place-items: center; color: var(--muted); }

.modal { width: min(94vw, 620px); max-height: 90vh; margin: auto; padding: 0; overflow: auto; border: 1px solid var(--line); border-radius: var(--radius); background: var(--panel); color: var(--text); box-shadow: var(--shadow); }
.modal::backdrop { background: rgba(3, 5, 8, .72); backdrop-filter: blur(3px); }
.modal > form { padding: 18px; }
.modal-head { display: flex; margin-bottom: 15px; align-items: flex-start; justify-content: space-between; gap: 12px; }
.modal-head h2 { margin: 0; }
.modal-divider { height: 1px; margin: 16px 0; background: var(--line); }
.modal-actions { display: flex; margin-top: 15px; justify-content: flex-end; gap: 8px; }
.compact-form { gap: 10px; }
.coordinate-grid, .builder-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.builder-modal { width: min(94vw, 760px); }
.builder-subtitle { margin-top: 15px; }
.form-check { display: inline-flex; margin-top: 8px; align-items: center; gap: 7px; }
.form-check input { width: 15px; min-height: auto; }
.form-check span { margin: 0; }
.secret-note, .warning-note { margin: 10px 0 0; padding: 9px 10px; border: 1px solid var(--line); border-radius: 6px; background: var(--panel-3); color: var(--muted); font-size: 11px; line-height: 1.45; }
.warning-note { border-color: rgba(242, 196, 93, .3); background: var(--yellow-bg); color: #e8cf92; }
.firmware-flash-links { display: flex; margin: 12px 0 0; flex-wrap: wrap; align-items: baseline; gap: 7px; color: var(--muted); font-size: 11px; }
.firmware-flash-links small { flex-basis: 100%; }
.builder-status { margin: 10px 0 0; color: var(--muted); font-size: 11px; }
.subscription-list { display: grid; gap: 7px; }
.subscription-row { display: flex; padding: 9px; align-items: center; justify-content: space-between; gap: 10px; border: 1px solid var(--line-soft); border-radius: 6px; background: var(--panel-3); }
.subscription-row > div:first-child { display: flex; min-width: 0; flex-direction: column; gap: 2px; }
.subscription-row span { overflow: hidden; color: var(--muted); font-size: 10px; text-overflow: ellipsis; white-space: nowrap; }
.subscription-row > div:last-child { display: flex; gap: 5px; }
.ota-state { margin: 12px 0; padding: 12px; border: 1px solid var(--line); border-radius: 7px; background: var(--panel-3); }
.ota-state-head { display: flex; margin-bottom: 8px; justify-content: space-between; gap: 10px; }
.ota-state p { margin: 9px 0 0; color: var(--muted); font-size: 11px; line-height: 1.45; }

.toast { position: fixed; z-index: 100; right: 18px; bottom: 18px; max-width: min(420px, calc(100vw - 24px)); padding: 10px 13px; border: 1px solid #3a4652; border-radius: 7px; background: #1a2028; color: var(--text); box-shadow: var(--shadow); font-size: 12px; }

@media (max-width: 1280px) {
  .incident-filters { grid-template-columns: minmax(210px, 1.5fr) repeat(3, minmax(120px, 1fr)); }
  .incident-filters > :nth-last-child(-n+3) { grid-row: 2; }
  .device-filters { grid-template-columns: minmax(210px, 1.3fr) repeat(3, minmax(120px, .8fr)); }
  .filter-count { grid-column: 1 / -1; padding: 0; }
}

@media (max-width: 1100px) {
  .overview-strip { grid-template-columns: repeat(4, 1fr); }
  .history-select { grid-column: 1 / -1; border-top: 1px solid var(--line-soft); }
  .ops-head { display: none; }
  .ops-table { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; padding: 8px; border: 0; background: transparent; }
  .ops-row { display: grid; grid-template-columns: 1fr 1fr; padding: 8px; border: 1px solid var(--line-soft); border-radius: 7px; background: var(--panel-3); }
  .ops-row.ops-head { display: none; }
  .ops-row > * { padding: 5px 7px; }
  .ops-row > *::before { content: attr(data-label); display: block; margin-bottom: 2px; color: var(--muted); font-size: 9px; font-weight: 700; text-transform: uppercase; }
  .incident-row.is-offline, .incident-row.is-unreachable { box-shadow: none; border-left: 3px solid var(--red); }
  .incident-row.is-unreachable { border-left-color: var(--yellow); }
  .ops-table > .empty-state { grid-column: 1 / -1; }
  .device-row, .device-row-head { grid-template-columns: minmax(160px, 1fr) minmax(135px, 1fr) minmax(135px, 1fr) minmax(130px, .8fr) minmax(160px, auto); }
}

@media (max-width: 850px) {
  .dashboard { padding-inline: 8px; }
  .overview-strip { grid-template-columns: 1fr 1fr; }
  .stat-card:nth-child(even) { border-right: 0; }
  .stat-card:nth-child(n+3) { border-top: 1px solid var(--line-soft); }
  .history-select { grid-column: 1 / -1; }
  .incident-filters, .device-filters { grid-template-columns: 1fr 1fr; }
  .filter-search { grid-column: 1 / -1; }
  .incident-filters > :nth-last-child(-n+3) { grid-row: auto; }
  .filter-count { grid-column: 1 / -1; }
  .control-grid { grid-template-columns: 1fr; }
  .device-row-head { display: none; }
  .device-table { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; padding: 8px; border: 0; background: transparent; }
  .location-admin { grid-column: 1 / -1; border: 1px solid var(--line-soft); border-radius: 7px; }
  .device-row { display: grid; grid-template-columns: 1fr 1fr; padding: 7px; border: 1px solid var(--line-soft); border-radius: 7px; background: var(--panel-3); }
  .device-row > * { padding: 5px 7px; }
  .device-row > *::before { content: attr(data-label); display: block; margin-bottom: 2px; color: var(--muted); font-size: 9px; font-weight: 700; text-transform: uppercase; }
  .device-identity { padding-left: 23px !important; }
  .device-identity .device-dot { top: 9px; left: 6px; }
  .device-actions { grid-column: 1 / -1; justify-content: stretch; }
  .device-actions .button { flex: 1; }
  .device-table > .empty-state { grid-column: 1 / -1; }
}

@media (max-width: 600px) {
  body { font-size: 13px; }
  .topbar { padding-inline: 10px; }
  .topbar-status > strong { display: none; }
  .dashboard { padding-top: 8px; gap: 8px; }
  .section-block, .panel { padding: 11px; border-radius: 8px; }
  .section-heading, .panel-heading { align-items: flex-start; flex-direction: column; }
  .compact-heading { align-items: stretch; }
  .heading-actions { justify-content: stretch; }
  .heading-actions .button { flex: 1; }
  .incident-table-footer { align-items: stretch; flex-direction: column; }
  .incident-table-footer .button { width: 100%; }
  .incident-filters, .device-filters { grid-template-columns: 1fr; }
  .filter-search, .filter-count { grid-column: auto; }
  .ops-table, .device-table { grid-template-columns: 1fr; padding: 0; }
  .ops-row, .device-row { grid-template-columns: 1fr 1fr; }
  .source-grid { grid-template-columns: 1fr 1fr; }
  .source-grid label:first-child { grid-column: 1 / -1; }
  .scope-grid, .manual-target, .coordinate-grid, .builder-grid { grid-template-columns: 1fr; }
  .run-actions { align-items: stretch; flex-direction: column; }
  .run-heading-actions { width: 100%; justify-content: space-between; }
  .queue-item-head { align-items: stretch; flex-direction: column; }
  .queue-counters { justify-content: flex-start; }
  .queue-counters .button { flex: 1; }
  .run-actions .button { width: 100%; }
  .provider-rows > div { grid-template-columns: 1fr auto; }
  .provider-rows .status-pill { grid-column: 1 / -1; }
  .server-row { grid-template-columns: 1fr auto; }
  .server-row > :nth-child(3), .server-row > :nth-child(4) { text-align: right; }
  .server-row-head { display: none; }
  .map-section summary span:first-child { align-items: flex-start; flex-direction: column; gap: 2px; }
  .modal { width: calc(100vw - 12px); max-height: calc(100vh - 12px); }
  .modal > form { padding: 14px; }
  .subscription-row { align-items: stretch; flex-direction: column; }
  .subscription-row > div:last-child { justify-content: flex-end; }
  .toast { right: 12px; bottom: 12px; }
}

@media (max-width: 390px) {
  .overview-strip { grid-template-columns: 1fr; }
  .stat-card { border-right: 0; border-top: 1px solid var(--line-soft); }
  .stat-card:first-child { border-top: 0; }
  .ops-row, .device-row { grid-template-columns: 1fr; }
  .device-actions { grid-column: auto; }
  .result-stats { grid-template-columns: 1fr; }
}

/* Operational summary */
.dashboard { padding-bottom: 86px; }
.availability-section { display: grid; scroll-margin-top: 56px; gap: 10px; }
.availability-section > .section-heading { margin-bottom: 2px; }
.summary-panel { min-width: 0; overflow: hidden; border: 1px solid var(--line-soft); border-radius: 8px; background: var(--panel-3); }
.summary-panel-heading {
  display: flex;
  min-width: 0;
  padding: 10px 12px;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  border-bottom: 1px solid var(--line-soft);
  background: #151a21;
}
.summary-panel-heading h2 { margin: 0; font-size: 15px; }
.summary-panel-heading p { margin: 2px 0 0; color: var(--muted); font-size: 10px; }
.server-summary-tools { display: flex; min-width: 0; align-items: flex-end; justify-content: flex-end; gap: 7px; }
.server-probe-filter { display: grid; min-width: min(290px, 34vw); gap: 2px; }
.server-probe-filter span { color: var(--muted); font-size: 9px; font-weight: 700; letter-spacing: .04em; text-transform: uppercase; }
.server-probe-filter select { min-height: 30px; padding-block: 4px; font-size: 11px; }
.summary-total { color: var(--muted); font-size: 11px; white-space: nowrap; }
.server-summary { display: grid; gap: 6px; padding: 8px; }
.server-summary-row {
  display: grid;
  grid-template-columns: minmax(180px, .8fr) 92px minmax(300px, 1.7fr);
  min-width: 0;
  padding: 9px 10px;
  align-items: center;
  gap: 12px;
  border: 1px solid var(--line-soft);
  border-left-width: 3px;
  border-radius: 7px;
  background: #10151b;
}
.server-summary-row.is-unavailable { border-left-color: var(--red); background: linear-gradient(90deg, var(--red-bg), transparent 26%), #10151b; }
.server-summary-row.is-partial, .server-summary-row.is-pending { border-left-color: var(--yellow); }
.server-summary-row.is-available { border-left-color: var(--green); }
.server-summary-identity { display: flex; min-width: 0; flex-direction: column; gap: 2px; }
.server-summary-identity strong { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 12px; }
.server-summary-identity small { overflow: hidden; color: var(--muted); font: 10px/1.35 ui-monospace, SFMono-Regular, Consolas, monospace; text-overflow: ellipsis; white-space: nowrap; }
.server-answer-count { display: flex; flex-direction: column; }
.server-answer-count strong { font: 750 18px/1 ui-monospace, SFMono-Regular, Consolas, monospace; }
.server-answer-count small { margin-top: 3px; color: var(--muted); font-size: 9px; }
.server-problems { display: flex; min-width: 0; flex-wrap: wrap; gap: 5px; }
.probe-issue { min-width: min(100%, 255px); border: 1px solid rgba(255, 116, 116, .24); border-radius: 6px; background: rgba(255, 116, 116, .06); }
.probe-issue summary { display: grid; grid-template-columns: auto auto minmax(90px, 1fr); padding: 5px 7px; align-items: center; gap: 6px; cursor: pointer; list-style: none; font-size: 10px; }
.probe-issue summary::-webkit-details-marker { display: none; }
.probe-issue summary span, .probe-issue summary strong, .probe-issue summary em { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.probe-issue summary span { color: var(--text); }
.probe-issue summary strong { color: #ccd5de; }
.probe-issue summary em { color: var(--red); font-style: normal; text-align: right; }
.probe-issue-detail { padding: 6px 7px; border-top: 1px solid rgba(255, 116, 116, .18); color: var(--muted); font-size: 9px; line-height: 1.45; }
.probe-pending { border-color: rgba(242, 196, 93, .3); background: rgba(242, 196, 93, .07); }
.probe-pending summary { grid-template-columns: minmax(74px, auto) minmax(120px, 1fr) auto; }
.probe-pending summary strong { color: var(--text); }
.probe-pending summary span { color: var(--muted); }
.probe-pending summary em { color: var(--yellow); }
.probe-pending .probe-issue-detail { border-top-color: rgba(242, 196, 93, .22); }
.probe-result summary { grid-template-columns: minmax(74px, auto) minmax(120px, 1fr) minmax(90px, auto); }
.probe-result.is-success { border-color: rgba(80, 216, 144, .3); background: rgba(80, 216, 144, .07); }
.probe-result.is-success summary em { color: var(--green); }
.probe-result.is-success .probe-issue-detail { border-top-color: rgba(80, 216, 144, .22); }
.probe-result.is-pending { border-color: rgba(242, 196, 93, .3); background: rgba(242, 196, 93, .07); }
.probe-result.is-pending summary em { color: var(--yellow); }
.probe-result.is-pending .probe-issue-detail { border-top-color: rgba(242, 196, 93, .22); }
.probe-result.is-cancelled { border-color: var(--line); background: rgba(154, 164, 175, .06); }
.probe-result.is-cancelled summary em { color: var(--muted); }
.probe-result.is-cancelled .probe-issue-detail { border-top-color: var(--line-soft); }
.server-state-copy { padding: 4px 7px; border-radius: 5px; font-size: 10px; }
.server-state-copy.is-available { background: var(--green-bg); color: var(--green); }
.server-state-copy.is-partial, .server-state-copy.is-pending { background: var(--yellow-bg); color: var(--yellow); }
.server-state-copy.is-unavailable { background: var(--red-bg); color: var(--red); }
.healthy-server-group { overflow: hidden; border: 1px solid rgba(80, 216, 144, .18); border-radius: 7px; }
.healthy-server-group > summary {
  display: grid;
  grid-template-columns: 1fr auto auto;
  padding: 8px 10px;
  align-items: center;
  gap: 10px;
  cursor: pointer;
  list-style: none;
  background: var(--green-bg);
  color: var(--green);
  font-size: 11px;
}
.healthy-server-group > summary::-webkit-details-marker { display: none; }
.healthy-server-group > summary small { color: var(--muted); }
.healthy-server-group[open] > summary small { font-size: 0; }
.healthy-server-group[open] > summary small::after { content: "Скрыть"; font-size: 10px; }
.healthy-server-list { display: grid; gap: 6px; padding: 6px; }

.location-results { padding: 8px; }
.location-counts { display: grid; grid-template-columns: repeat(3, 1fr); margin-bottom: 8px; gap: 5px; }
.location-counts > span { padding: 6px 7px; border-radius: 6px; background: #151b22; }
.location-counts small { display: block; margin-bottom: 1px; color: var(--muted); font-size: 9px; }
.location-counts strong { font: 750 16px/1.1 ui-monospace, SFMono-Regular, Consolas, monospace; }
.location-counts .count-success strong { color: var(--green); }
.location-counts .count-failed strong { color: var(--red); }
.location-counts .count-pending strong { color: var(--yellow); }
.provider-rows > div { grid-template-columns: minmax(100px, 1fr) minmax(170px, auto) 70px auto; }
.provider-rows > div.is-filtered { margin-inline: -6px; padding-inline: 6px; background: rgba(80, 216, 144, .07); }
.provider-filter-button {
  width: fit-content;
  min-width: 0;
  padding: 2px 0;
  border: 0;
  background: transparent;
  color: var(--text);
  font-weight: 700;
  text-align: left;
  cursor: pointer;
  text-decoration: underline;
  text-decoration-color: #43505c;
  text-underline-offset: 3px;
}
.provider-filter-button:hover, .provider-filter-button[aria-pressed="true"] { color: var(--green); text-decoration-color: currentColor; }
.provider-filter-button:focus-visible { border-radius: 3px; outline: 2px solid var(--green); outline-offset: 2px; }
.provider-counts { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: 7px; }
.provider-counts b { font-size: 10px; font-weight: 650; }
.provider-counts .is-success { color: var(--green); }
.provider-counts .is-failed { color: var(--red); }
.provider-latency { text-align: right; }

/* Raw incidents stay available without dominating the page. */
.incident-section { padding: 0; }
.incident-log-details > summary { list-style: none; }
.incident-log-details > summary::-webkit-details-marker { display: none; }
.incident-log-summary {
  display: flex;
  min-width: 0;
  padding: 12px 14px;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  cursor: pointer;
}
.incident-log-summary > span:first-child { display: flex; min-width: 0; flex-direction: column; gap: 2px; }
.incident-log-summary > span:first-child > strong { font-size: 15px; }
.incident-log-summary small { color: var(--muted); font-size: 10px; }
.incident-log-meta { display: flex; flex: 0 0 auto; align-items: center; gap: 9px; }
.incident-log-meta i { color: var(--muted); font-size: 10px; font-style: normal; }
.incident-log-body { padding: 0 12px 12px; border-top: 1px solid var(--line-soft); }
.incident-log-body .filter-bar { margin-top: 10px; }

/* Device inventory can be collapsed; the fixed status remains visible. */
.devices-section { padding: 0; scroll-margin-top: 62px; }
.device-disclosure-summary {
  display: flex;
  min-width: 0;
  padding: 12px 14px;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  cursor: pointer;
  list-style: none;
}
.device-disclosure-summary::-webkit-details-marker { display: none; }
.device-disclosure-summary > span { display: flex; min-width: 0; flex-direction: column; gap: 2px; }
.device-disclosure-summary > span:last-child { flex: 0 0 auto; align-items: flex-end; }
.device-disclosure-summary strong { font-size: 14px; }
.device-disclosure-summary small, .device-disclosure-summary i { color: var(--muted); font-size: 10px; font-style: normal; }
.device-section-body { padding: 12px; border-top: 1px solid var(--line-soft); }
.device-dock {
  position: fixed;
  z-index: 18;
  right: 18px;
  bottom: 16px;
  display: inline-flex;
  min-height: 38px;
  padding: 7px 11px;
  align-items: center;
  gap: 7px;
  border: 1px solid #394550;
  border-radius: 8px;
  background: rgba(17, 21, 27, .96);
  color: var(--text);
  box-shadow: 0 10px 30px rgba(3, 6, 9, .42);
  cursor: pointer;
}
.device-dock strong { font-size: 11px; }
.device-dock:active { transform: translateY(1px); }

.location-search { display: grid; gap: 5px; }
.search-control { display: grid; grid-template-columns: 1fr auto; gap: 6px; }
.search-control .button { white-space: nowrap; }
.location-search-results { display: grid; max-height: 180px; overflow: auto; gap: 4px; }
.location-search-results button {
  display: flex;
  min-width: 0;
  padding: 7px 8px;
  align-items: flex-start;
  flex-direction: column;
  gap: 2px;
  border: 1px solid var(--line-soft);
  border-radius: 6px;
  background: var(--panel-3);
  color: var(--text);
  cursor: pointer;
  text-align: left;
}
.location-search-results button:hover { border-color: #45515e; background: #171d24; }
.location-search-results strong, .location-search-results span { width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.location-search-results strong { font-size: 11px; }
.location-search-results span, .location-attribution { color: var(--muted); font-size: 9px; }

@media (max-width: 900px) {
  .server-summary-row { grid-template-columns: minmax(150px, 1fr) 80px minmax(240px, 1.5fr); }
  .provider-rows > div { grid-template-columns: 1fr auto; }
  .provider-counts { justify-content: flex-start; }
  .provider-latency { text-align: right; }
  .provider-rows .status-pill { grid-column: 1 / -1; }
}

@media (max-width: 680px) {
  .availability-section { padding: 10px; }
  .summary-panel-heading { align-items: flex-start; flex-wrap: wrap; }
  .server-summary-tools { width: 100%; align-items: flex-end; justify-content: flex-start; flex-wrap: wrap; }
  .server-probe-filter { min-width: 0; flex: 1 1 220px; }
  .server-summary-tools .summary-total { margin-left: auto; align-self: center; }
  .server-summary-row { grid-template-columns: 1fr auto; gap: 8px; }
  .server-problems { grid-column: 1 / -1; }
  .probe-issue { width: 100%; min-width: 0; }
  .probe-issue summary { grid-template-columns: minmax(80px, auto) minmax(70px, auto) 1fr; }
  .location-results { grid-template-columns: 1fr; padding: 6px; }
  .location-counts { grid-template-columns: repeat(3, 1fr); }
  .incident-log-summary, .device-disclosure-summary { align-items: flex-start; }
  .incident-log-meta { align-items: flex-end; flex-direction: column; gap: 4px; }
  .device-dock { right: 8px; bottom: 8px; }
  .search-control { grid-template-columns: 1fr; }
}

@media (max-width: 390px) {
  .location-counts { grid-template-columns: 1fr 1fr; }
  .location-counts .count-pending { grid-column: 1 / -1; }
  .device-dock { left: 8px; justify-content: center; }
}
