:root {
  color-scheme: light;
  --bg: #edf3f6;
  --panel: #ffffff;
  --panel-soft: #f6fafc;
  --ink: #17212b;
  --muted: #637282;
  --line: #d8e2e8;
  --ok: #15835a;
  --ok-bg: #e8f6ef;
  --bad: #c8372e;
  --bad-bg: #fdeceb;
  --warn: #b7791f;
  --accent: #1769aa;
  --accent-dark: #0f4f82;
  --cyan: #22a6b8;
  --cyan-bg: #e8f8fb;
  --shadow: 0 18px 42px rgba(24, 38, 50, 0.08);
  font-family: "Segoe UI", Arial, sans-serif;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background:
    linear-gradient(180deg, #dce9ef 0, #edf3f6 390px),
    var(--bg);
  color: var(--ink);
}

button,
input {
  font: inherit;
}

.shell {
  width: min(1320px, calc(100% - 32px));
  margin: 0 auto;
  padding: 28px 0;
}

.topbar,
.section-head,
.actions,
.module-head {
  display: flex;
  align-items: center;
}

.topbar {
  justify-content: space-between;
  gap: 22px;
  padding: 18px 0 8px;
}

.section-head,
.module-head {
  justify-content: space-between;
  gap: 14px;
}

.section-head {
  margin-bottom: 16px;
}

.module-head {
  margin-bottom: 14px;
}

.module-head > span {
  color: var(--muted);
  font-weight: 700;
}

.eyebrow {
  margin: 0 0 7px;
  color: var(--accent-dark);
  font-weight: 800;
  text-transform: uppercase;
  font-size: 0.76rem;
}

h1,
h2,
h3,
p {
  margin: 0;
  letter-spacing: 0;
}

h1 {
  font-size: clamp(2rem, 4vw, 3.35rem);
  line-height: 1.05;
}

h2 {
  font-size: 1.22rem;
}

h3 {
  font-size: 1.02rem;
}

.subtitle {
  max-width: 760px;
  margin-top: 9px;
  color: var(--muted);
  font-size: 0.98rem;
}

.actions {
  gap: 10px;
}

.icon-button,
.primary,
.small,
.text-button {
  border: 0;
  cursor: pointer;
}

.icon-button {
  width: 42px;
  height: 42px;
  border-radius: 8px;
  background: var(--panel);
  border: 1px solid var(--line);
  box-shadow: var(--shadow);
  color: var(--accent-dark);
  font-weight: 900;
}

.toggle {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-height: 42px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 9px 12px;
  color: var(--muted);
  box-shadow: var(--shadow);
}

.stats,
.charts,
.workspace,
.internet-grid,
.link-cards {
  display: grid;
  gap: 16px;
}

.stats {
  grid-template-columns: repeat(4, minmax(0, 1fr));
  margin: 24px 0 18px;
}

.module {
  margin-bottom: 18px;
  padding: 18px;
  border: 1px solid #d3e0e7;
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.52);
}

.stat,
.panel,
.link-card {
  background: rgba(255, 255, 255, 0.97);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.stat {
  position: relative;
  overflow: hidden;
  padding: 18px;
}

.stat::before {
  content: "";
  position: absolute;
  inset: 0 auto 0 0;
  width: 4px;
  background: var(--accent);
}

.stat.ok::before {
  background: var(--ok);
}

.stat.bad::before {
  background: var(--bad);
}

.stat span,
.stat small,
.section-head span {
  color: var(--muted);
}

.stat span {
  display: block;
  font-size: 0.86rem;
  font-weight: 800;
  text-transform: uppercase;
}

.stat strong {
  display: block;
  margin-top: 8px;
  font-size: 2rem;
  line-height: 1;
}

.stat small {
  display: block;
  margin-top: 9px;
  font-size: 0.82rem;
}

.stat.ok strong {
  color: var(--ok);
}

.stat.bad strong {
  color: var(--bad);
}

.internet-grid {
  grid-template-columns: 420px minmax(0, 1fr);
  align-items: stretch;
}

.link-cards {
  grid-template-columns: 1fr;
}

.link-history-panel {
  margin-top: 16px;
}

.link-card {
  position: relative;
  overflow: hidden;
  padding: 18px;
  min-height: 122px;
}

.link-card::before {
  content: "";
  position: absolute;
  inset: 0 auto 0 0;
  width: 5px;
  background: var(--cyan);
}

.link-card.offline::before {
  background: var(--bad);
}

.link-card.muted::before {
  background: var(--warn);
}

.link-top,
.link-bottom {
  display: flex;
  justify-content: space-between;
  gap: 12px;
}

.link-top {
  align-items: flex-start;
}

.link-bottom {
  align-items: end;
  margin-top: 18px;
}

.link-name {
  font-weight: 900;
  font-size: 1.1rem;
}

.link-ip,
.link-site {
  color: var(--muted);
  font-size: 0.88rem;
}

.link-latency {
  color: var(--accent-dark);
  font-weight: 900;
  font-size: 1.8rem;
  line-height: 1;
}

.link-latency small {
  color: var(--muted);
  font-size: 0.8rem;
  font-weight: 700;
}

.charts {
  grid-template-columns: 330px minmax(0, 1fr) 310px;
  align-items: stretch;
}

.panel {
  padding: 18px;
}

.chart-card canvas {
  display: block;
  width: 100%;
  max-width: 100%;
}

.availability-card canvas {
  height: 220px;
}

.latency-card canvas {
  height: 260px;
}

#internetLatencyChart {
  height: 220px;
}

.donut-layout {
  display: grid;
  align-items: center;
  gap: 12px;
}

.legend,
.alert-list,
.history-list {
  display: grid;
  gap: 9px;
}

.legend span {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--muted);
  font-size: 0.9rem;
}

.dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
}

.ok-dot {
  background: var(--ok);
}

.bad-dot {
  background: var(--bad);
}

.warn-dot {
  background: #f2c94c;
}

.link-timeline {
  display: grid;
  gap: 16px;
}

.timeline-row {
  display: grid;
  grid-template-columns: 210px 1fr;
  gap: 16px;
  align-items: center;
}

.timeline-label strong {
  display: block;
  font-size: 0.94rem;
}

.timeline-label span {
  color: var(--muted);
  font-size: 0.82rem;
}

.timeline-bars {
  display: grid;
  grid-template-columns: repeat(var(--count), minmax(2px, 1fr));
  gap: 1px;
  min-height: 44px;
  padding: 3px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #f3f7f9;
}

.timeline-segment {
  min-height: 36px;
  border-radius: 2px;
  background: var(--ok);
}

.timeline-segment.warn {
  background: #f2c94c;
}

.timeline-segment.bad {
  background: var(--bad);
}

.timeline-segment.muted {
  background: #d8dde2;
}

.timeline-legend {
  display: flex;
  flex-wrap: wrap;
  gap: 16px;
  margin-top: 14px;
  color: var(--muted);
  font-size: 0.88rem;
}

.timeline-legend span {
  display: inline-flex;
  align-items: center;
  gap: 7px;
}

.alert-item {
  display: grid;
  gap: 4px;
  padding: 11px 12px;
  border-radius: 8px;
  background: var(--bad-bg);
  border: 1px solid #f5c8c4;
}

.alert-item strong {
  font-size: 0.94rem;
}

.alert-item span {
  color: var(--muted);
  font-size: 0.84rem;
}

.alert-ok {
  padding: 14px;
  border-radius: 8px;
  color: var(--ok);
  background: var(--ok-bg);
  border: 1px solid #c8ead8;
  font-weight: 800;
}

.workspace {
  grid-template-columns: 280px 280px 1fr;
  align-items: start;
  margin-bottom: 16px;
}

form {
  display: grid;
  gap: 14px;
  margin-top: 18px;
}

.settings-form {
  grid-template-columns: 180px repeat(3, minmax(0, 1fr)) 150px;
  align-items: end;
  margin-top: 0;
}

.setting-toggle {
  min-height: 43px;
  box-shadow: none;
}

label {
  display: grid;
  gap: 7px;
  color: var(--muted);
  font-size: 0.9rem;
}

input[type="text"],
input:not([type]) {
  width: 100%;
}

input {
  border: 1px solid var(--line);
  border-radius: 7px;
  padding: 11px 12px;
  color: var(--ink);
  background: #fff;
}

input:focus {
  outline: 3px solid rgba(23, 105, 170, 0.15);
  border-color: var(--accent);
}

.primary {
  border-radius: 7px;
  padding: 12px 14px;
  color: #fff;
  background: var(--accent);
  font-weight: 900;
}

.primary:hover {
  background: var(--accent-dark);
}

.main-panel {
  min-width: 0;
}

.section-head span {
  font-size: 0.88rem;
}

.table-wrap {
  overflow-x: auto;
  border: 1px solid var(--line);
  border-radius: 8px;
}

table {
  width: 100%;
  border-collapse: collapse;
  min-width: 790px;
  background: #fff;
}

th,
td {
  padding: 12px 11px;
  border-bottom: 1px solid var(--line);
  text-align: left;
  vertical-align: middle;
}

th {
  color: var(--muted);
  background: var(--panel-soft);
  font-size: 0.78rem;
  font-weight: 900;
  text-transform: uppercase;
}

td {
  font-size: 0.92rem;
}

tbody tr:hover {
  background: #f7fbfd;
}

.badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 110px;
  min-height: 30px;
  border-radius: 999px;
  padding: 6px 10px;
  font-weight: 900;
  font-size: 0.8rem;
}

.badge.online {
  color: var(--ok);
  background: var(--ok-bg);
}

.badge.offline {
  color: var(--bad);
  background: var(--bad-bg);
}

.badge.muted {
  color: var(--warn);
  background: #fff6df;
}

.type-pill {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 78px;
  min-height: 28px;
  border-radius: 999px;
  padding: 5px 9px;
  background: #eef6fb;
  color: var(--accent-dark);
  font-size: 0.78rem;
  font-weight: 900;
}

.type-pill.internet {
  background: var(--cyan-bg);
  color: #107787;
}

.empty {
  color: var(--muted);
  text-align: center;
}

.row-actions {
  text-align: right;
  white-space: nowrap;
}

.small {
  min-width: 74px;
  border-radius: 7px;
  padding: 8px 10px;
  background: #eef3f6;
  color: var(--muted);
}

.small.mute {
  color: var(--accent-dark);
  background: #e6f1f8;
}

.small.mute.active {
  color: var(--warn);
  background: #fff6df;
}

.small.danger:hover {
  color: #fff;
  background: var(--bad);
}

.text-button {
  background: transparent;
  color: var(--accent);
  font-weight: 900;
}

.history-item {
  display: grid;
  grid-template-columns: 120px 1fr 150px;
  gap: 12px;
  padding: 11px 0;
  border-bottom: 1px solid var(--line);
  color: var(--muted);
}

.history-item strong {
  color: var(--ink);
}

@media (max-width: 1180px) {
  .internet-grid,
  .workspace,
  .settings-form {
    grid-template-columns: 1fr 1fr;
  }

  .main-panel,
  .settings-form .primary {
    grid-column: 1 / -1;
  }
}

@media (max-width: 1100px) {
  .charts {
    grid-template-columns: 1fr 1fr;
  }

  .latency-card {
    grid-column: 1 / -1;
  }
}

@media (max-width: 860px) {
  .stats,
  .charts,
  .internet-grid,
  .workspace,
  .settings-form {
    grid-template-columns: 1fr;
  }

  .topbar,
  .module-head {
    align-items: flex-start;
  }

  .history-item {
    grid-template-columns: 1fr;
    gap: 4px;
  }

  .timeline-row {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 560px) {
  .shell {
    width: min(100% - 20px, 1320px);
    padding: 18px 0;
  }

  .topbar,
  .module-head {
    flex-direction: column;
  }

  .actions {
    width: 100%;
    justify-content: space-between;
  }
}
