:root {
  --bg: #f5f7fb;
  --panel: #ffffff;
  --ink: #17202f;
  --muted: #657084;
  --line: #dce2ea;
  --accent: #176b87;
  --accent-2: #2f8f5b;
  --warn: #b56b10;
  --bad: #b33a3a;
  --shadow: 0 12px 35px rgba(28, 39, 60, 0.12);
}

/* Operations dashboard */
:root {
  --bg: #f4f5f7;
  --panel: #ffffff;
  --ink: #151b26;
  --muted: #697386;
  --line: #dfe3e8;
  --accent: #1976d2;
  --accent-2: #2e8b57;
  --warn: #b66a0a;
  --bad: #c2413b;
  --shadow: 0 2px 8px rgba(26, 34, 48, .06);
}

body { background: var(--bg); letter-spacing: 0; }

.topbar {
  background: #111820;
  border-bottom: 1px solid #27313c;
  min-height: 72px;
  padding: 12px clamp(16px, 3vw, 36px);
}

.brand-lockup, .top-actions, .live-indicator { align-items: center; display: flex; }
.brand-lockup { gap: 12px; }
.brand-mark {
  align-items: center;
  background: #f0b429;
  border-radius: 6px;
  color: #111820;
  display: flex;
  font-size: 20px;
  font-weight: 850;
  height: 38px;
  justify-content: center;
  width: 38px;
}
.brand-lockup h1 { font-size: 18px; line-height: 1.1; }
.brand-lockup p { font-size: 12px; margin-top: 3px; }
.top-actions { color: #b9c3cf; font-size: 12px; gap: 14px; }
.live-indicator { color: #d7e9df; gap: 7px; }
.live-indicator i { background: #38a169; border-radius: 50%; height: 7px; width: 7px; }
.icon-button, .logout {
  align-items: center;
  background: transparent;
  border: 1px solid #3a4653;
  border-radius: 6px;
  color: #eef2f6;
  display: inline-flex;
  height: 34px;
  justify-content: center;
  min-width: 34px;
  padding: 0 10px;
  text-decoration: none;
}
.icon-button { font-size: 21px; }

main { margin: 0 auto; max-width: 1920px; padding: 20px clamp(14px, 2.5vw, 36px) 42px; }
.stats {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 7px;
  display: grid;
  gap: 0;
  grid-template-columns: repeat(6, minmax(0, 1fr));
  overflow: hidden;
}
.metric-card {
  background: transparent;
  border: 0;
  border-right: 1px solid var(--line);
  border-radius: 0;
  box-shadow: none;
  min-height: 104px;
  padding: 17px 18px 14px;
}
.metric-card:last-child { border-right: 0; }
.metric-card.metric-alert { background: #fff8f7; }
.metric-label { font-size: 11px; font-weight: 650; text-transform: uppercase; }
.metric-value { font-size: 28px; line-height: 1; margin-top: 10px; }
.metric-detail { border: 0; font-size: 11px; font-weight: 550; margin-top: 8px; padding: 0; }

.section-heading { align-items: end; display: flex; justify-content: space-between; margin: 28px 0 12px; }
.section-heading h2 { font-size: 20px; font-weight: 720; }
.eyebrow { color: #788496; font-size: 10px; font-weight: 750; margin-bottom: 4px; }
.range-control { background: #e7eaee; border-radius: 6px; display: flex; padding: 3px; }
.range-control button { background: transparent; border: 0; border-radius: 4px; color: #5e6978; font-size: 12px; height: 30px; padding: 0 13px; }
.range-control button.active { background: #fff; box-shadow: 0 1px 4px rgba(25, 33, 46, .14); color: #151b26; font-weight: 700; }

.analytics-grid { display: grid; gap: 12px; grid-template-columns: 2fr 1fr 1fr; }
.chart-panel { background: var(--panel); border: 1px solid var(--line); border-radius: 7px; min-width: 0; padding: 16px; }
.chart-header { align-items: start; display: flex; justify-content: space-between; margin-bottom: 13px; }
.chart-header h3 { font-size: 14px; margin: 0; }
.chart-header p { color: var(--muted); font-size: 11px; margin-top: 4px; }
.chart-header > strong { color: #344054; font-size: 14px; white-space: nowrap; }
.chart-frame { height: 230px; min-height: 230px; position: relative; width: 100%; }
.chart-kpis { border-top: 1px solid var(--line); color: var(--muted); display: flex; font-size: 11px; gap: 24px; margin-top: 10px; padding-top: 10px; }
.chart-kpis strong { color: var(--ink); margin-left: 4px; }
.chart-empty { background: #f6f8fa; color: var(--muted); font-size: 11px; margin-top: 8px; padding: 7px 9px; }

.servers { display: grid; gap: 7px; grid-template-columns: 1fr; margin-top: 0; }
.server-row {
  align-items: center;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 6px;
  display: grid;
  gap: 16px;
  grid-template-columns: minmax(250px, 2fr) repeat(4, minmax(88px, .7fr)) minmax(130px, 1fr) auto;
  min-height: 74px;
  padding: 12px 14px;
}
.server-identity { align-items: center; display: flex; gap: 11px; min-width: 0; }
.server-identity h3 { font-size: 14px; margin: 0; }
.server-identity p { color: var(--muted); font-size: 10px; margin-top: 4px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.health-light { background: var(--bad); border-radius: 50%; flex: none; height: 9px; width: 9px; }
.health-light.ok, .health-light.online, .health-light.local { background: var(--accent-2); }
.server-stat span, .quality-cell > span { color: var(--muted); display: block; font-size: 10px; }
.server-stat strong { display: block; font-size: 14px; margin-top: 4px; white-space: nowrap; }
.server-stat small { color: var(--muted); font-size: 11px; font-weight: 600; }
.quality-track { background: #e8ebef; border-radius: 2px; height: 5px; margin-top: 7px; overflow: hidden; }
.quality-track i { background: #2e8b57; display: block; height: 100%; }
.pill { border-radius: 4px; font-size: 10px; font-weight: 700; min-width: 68px; padding: 5px 7px; text-align: center; }

.clients-heading { margin-bottom: 10px; }
.toolbar { background: var(--panel); border: 1px solid var(--line); border-radius: 7px; margin: 0 0 8px; padding: 10px; }
.table-wrap { border: 1px solid var(--line); border-radius: 7px; box-shadow: none; }
th { background: #f7f8fa; color: #677386; font-size: 10px; text-transform: uppercase; }
td { font-size: 12px; }

@media (max-width: 1250px) {
  .stats { grid-template-columns: repeat(3, 1fr); }
  .metric-card:nth-child(3) { border-right: 0; }
  .metric-card:nth-child(-n+3) { border-bottom: 1px solid var(--line); }
  .analytics-grid { grid-template-columns: 1fr 1fr; }
  .chart-wide { grid-column: 1 / -1; }
  .server-row { grid-template-columns: minmax(230px, 2fr) repeat(3, minmax(80px, .8fr)) minmax(120px, 1fr) auto; }
  .server-row .server-stat:nth-of-type(4) { display: none; }
}

@media (max-width: 760px) {
  .topbar { align-items: flex-start; gap: 12px; }
  .top-actions { flex-wrap: wrap; justify-content: flex-end; }
  .live-indicator { display: none; }
  .stats { grid-template-columns: repeat(2, 1fr); }
  .metric-card, .metric-card:nth-child(3) { border-bottom: 1px solid var(--line); border-right: 1px solid var(--line); }
  .metric-card:nth-child(even) { border-right: 0; }
  .metric-card:nth-last-child(-n+2) { border-bottom: 0; }
  .analytics-grid { grid-template-columns: 1fr; }
  .chart-wide { grid-column: auto; }
  .chart-frame { height: 210px; min-height: 210px; }
  .server-row { gap: 10px; grid-template-columns: 1fr 1fr auto; }
  .server-identity { grid-column: 1 / -1; }
  .server-row .server-stat { display: block !important; }
  .server-row .server-stat:nth-of-type(n+3), .quality-cell { display: none !important; }
  .section-heading { align-items: flex-start; gap: 12px; }
  .toolbar { grid-template-columns: 1fr; }
  .toolbar input, .toolbar select, .toolbar button { width: 100%; }
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

.topbar {
  align-items: center;
  background: #152238;
  color: #fff;
  display: flex;
  justify-content: space-between;
  min-height: 86px;
  padding: 18px clamp(16px, 4vw, 42px);
}

h1, h2, p {
  margin: 0;
}

h1 {
  font-size: clamp(24px, 3vw, 34px);
  font-weight: 740;
}

.topbar p {
  color: #b9c5d6;
  margin-top: 6px;
}

.top-actions {
  align-items: center;
  display: flex;
  gap: 10px;
}

main {
  padding: 24px clamp(16px, 4vw, 42px) 42px;
}

.stats, .servers {
  display: grid;
  gap: 14px;
}

.stats {
  grid-template-columns: repeat(auto-fit, minmax(190px, 1fr));
}

.servers {
  grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
  margin-top: 16px;
}

.card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: 0 4px 16px rgba(28, 39, 60, 0.06);
  padding: 16px;
}

.metric-label, .server-meta, .client-meta {
  color: var(--muted);
  font-size: 13px;
}

.metric-value {
  font-size: 30px;
  font-weight: 780;
  margin-top: 6px;
}

.metric-card {
  min-height: 142px;
}

.metric-primary {
  border-top: 3px solid var(--accent);
  padding-top: 14px;
}

.metric-caption {
  color: var(--muted);
  font-size: 12px;
  margin-top: -2px;
}

.metric-detail {
  border-top: 1px solid var(--line);
  color: var(--muted);
  font-size: 12px;
  font-weight: 650;
  margin-top: 10px;
  padding-top: 8px;
}

.metric-good {
  color: var(--accent-2);
}

.metric-bad {
  color: var(--bad);
}

.platform-grid {
  display: grid;
  gap: 9px 12px;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  margin-top: 10px;
}

.platform-grid div {
  min-width: 0;
}

.platform-grid strong,
.platform-grid span {
  display: block;
}

.platform-grid strong {
  font-size: 21px;
}

.platform-grid span {
  color: var(--muted);
  font-size: 11px;
  overflow-wrap: anywhere;
}

@media (min-width: 901px) and (max-width: 1399px) {
  .stats {
    grid-template-columns: repeat(4, minmax(0, 1fr));
  }
}

.server-title {
  align-items: center;
  display: flex;
  gap: 8px;
  justify-content: space-between;
  min-width: 0;
}

.server-title h2 {
  font-size: 17px;
  overflow-wrap: anywhere;
}

.pill {
  border-radius: 999px;
  color: #fff;
  flex: none;
  font-size: 12px;
  padding: 4px 8px;
}

.pill.online, .pill.local, .pill.ok {
  background: var(--accent-2);
}

.pill.offline, .pill.unknown, .pill.stale, .pill.disabled {
  background: var(--bad);
}

.pill.quota-watch {
  background: var(--warn);
}

.pill.quota-warn {
  background: #a55315;
}

.pill.quota-critical {
  background: var(--bad);
}

.server-grid {
  display: grid;
  gap: 10px;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  margin-top: 14px;
}

.server-grid strong {
  display: block;
  font-size: 18px;
  margin-top: 2px;
}

.toolbar {
  align-items: center;
  display: grid;
  gap: 10px;
  grid-template-columns: minmax(220px, 1fr) 210px 170px 180px 210px auto;
  margin: 22px 0 12px;
}

input, select {
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--ink);
  font: inherit;
  min-height: 42px;
  padding: 0 12px;
}

button, .logout {
  align-items: center;
  background: var(--accent);
  border: 1px solid var(--accent);
  border-radius: 8px;
  color: #fff;
  cursor: pointer;
  display: inline-flex;
  font: inherit;
  font-weight: 650;
  justify-content: center;
  min-height: 42px;
  padding: 0 14px;
  text-decoration: none;
  white-space: nowrap;
}

button.ghost, .logout {
  background: transparent;
  border-color: rgba(255, 255, 255, 0.28);
}

main button.ghost {
  border-color: var(--line);
  color: var(--ink);
}

.table-wrap {
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 8px;
  overflow: auto;
  box-shadow: var(--shadow);
}

table {
  border-collapse: collapse;
  min-width: 1440px;
  width: 100%;
}

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

th {
  background: #eef3f8;
  color: #394458;
  font-size: 13px;
  position: sticky;
  top: 0;
  z-index: 1;
}

tbody tr:hover {
  background: #f8fbfd;
}

tbody tr.row-expiring {
  background: #fff8eb;
}

tbody tr.row-expired {
  background: #fff1f1;
}

.client-name {
  font-weight: 700;
  overflow-wrap: anywhere;
}

.client-heading {
  align-items: center;
  display: flex;
  gap: 8px;
}

.expand-client {
  background: transparent;
  border: 0;
  color: var(--accent);
  font-size: 25px;
  min-height: 26px;
  min-width: 26px;
  padding: 0;
  transform: rotate(0deg);
  transition: transform 0.16s ease;
}

.expand-client.open {
  transform: rotate(90deg);
}

.device-pill {
  background: #e6f4ec;
  border-radius: 999px;
  color: #1d6b42;
  display: inline-flex;
  font-size: 12px;
  font-weight: 750;
  margin-bottom: 4px;
  padding: 4px 8px;
}

.device-extra {
  color: var(--accent);
  font-size: 13px;
  font-weight: 700;
  margin-top: 3px;
}

.client-details td {
  background: #f4f8fb;
  padding: 16px;
}

.details-grid {
  display: grid;
  gap: 12px;
  grid-template-columns: repeat(4, minmax(210px, 1fr));
}

.details-card {
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 8px;
  display: grid;
  gap: 7px;
  padding: 13px;
}

.details-card h3 {
  font-size: 14px;
  margin: 0;
}

.details-primary {
  font-size: 18px;
  font-weight: 750;
}

.device-list {
  display: grid;
  gap: 7px;
  margin-top: 4px;
}

.device-entry {
  border-top: 1px solid var(--line);
  display: grid;
  gap: 2px;
  padding-top: 7px;
}

.device-heading {
  align-items: center;
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
}

.device-status {
  align-items: center;
  display: inline-flex;
  font-size: 12px;
  margin-left: auto;
  white-space: nowrap;
}

.device-status.online {
  color: var(--accent-2);
}

.device-status.offline,
.device-status.unavailable {
  color: var(--muted);
}

.device-status .status-dot {
  height: 8px;
  margin-right: 5px;
  width: 8px;
}

.switch-cell {
  text-align: center;
}

.switch-cell input, .row-select {
  height: 18px;
  width: 18px;
}

.inactive {
  color: var(--bad);
  font-weight: 700;
}

.status-dot {
  border-radius: 50%;
  display: inline-block;
  height: 10px;
  margin-right: 8px;
  width: 10px;
}

.online-dot {
  background: var(--accent-2);
}

.offline-dot {
  background: var(--muted);
}

.subscription-pill {
  border-radius: 999px;
  display: inline-flex;
  font-size: 12px;
  font-weight: 700;
  margin-bottom: 4px;
  padding: 4px 8px;
}

.subscription-pill.active {
  background: #e6f4ec;
  color: #1d6b42;
}

.subscription-pill.expiring {
  background: #fff1d6;
  color: #8a5100;
}

.subscription-pill.expired {
  background: #ffe1e1;
  color: #9d2424;
}

.subscription-pill.unlimited {
  background: #e8eef7;
  color: #40506a;
}

.quota-pill {
  border-radius: 999px;
  display: inline-flex;
  font-size: 12px;
  font-weight: 700;
  margin-bottom: 4px;
  padding: 4px 8px;
}

.quota-pill.ok {
  background: #e6f4ec;
  color: #1d6b42;
}

.quota-pill.watch {
  background: #fff7dc;
  color: #806000;
}

.quota-pill.warn {
  background: #fff1d6;
  color: #8a5100;
}

.quota-pill.critical {
  background: #ffe8d8;
  color: #9b3f00;
}

.quota-pill.exceeded,
.quota-pill.missing {
  background: #ffe1e1;
  color: #9d2424;
}

#toast {
  background: #111827;
  border-radius: 8px;
  bottom: 18px;
  color: #fff;
  left: 50%;
  opacity: 0;
  padding: 12px 16px;
  pointer-events: none;
  position: fixed;
  transform: translate(-50%, 18px);
  transition: 0.2s ease;
  z-index: 5;
}

#toast.show {
  opacity: 1;
  transform: translate(-50%, 0);
}

dialog {
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
  max-width: 460px;
  width: calc(100vw - 28px);
}

dialog::backdrop {
  background: rgba(18, 29, 45, 0.42);
}

dialog h2 {
  font-size: 22px;
  margin-bottom: 8px;
}

.checks {
  display: grid;
  gap: 10px;
  margin: 18px 0;
}

.checks label, .login-box label {
  display: grid;
  gap: 6px;
}

.checks label {
  grid-template-columns: 22px 1fr;
}

menu {
  display: flex;
  gap: 10px;
  justify-content: flex-end;
  margin: 0;
  padding: 0;
}

.login-page {
  align-items: center;
  background: #152238;
  display: flex;
  min-height: 100vh;
  padding: 16px;
}

.login-box {
  background: #fff;
  border-radius: 8px;
  box-shadow: var(--shadow);
  margin: auto;
  max-width: 380px;
  padding: 26px;
  width: 100%;
}

.brand {
  font-size: 26px;
  font-weight: 800;
  margin-bottom: 18px;
}

.login-box form {
  display: grid;
  gap: 14px;
}

.error {
  color: var(--bad);
  font-weight: 700;
}

@media (max-width: 900px) {
  .stats, .toolbar {
    grid-template-columns: 1fr 1fr;
  }

  .toolbar input, .toolbar select {
    grid-column: span 2;
  }

  .details-grid {
    grid-template-columns: 1fr 1fr;
  }
}

@media (max-width: 620px) {
  .topbar {
    align-items: flex-start;
    flex-direction: column;
    gap: 14px;
  }

  .stats {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .stats .card {
    min-width: 0;
    padding: 13px;
  }

  .stats .metric-value {
    font-size: 26px;
  }

  .toolbar {
    grid-template-columns: 1fr;
  }

  .toolbar input, .toolbar select {
    grid-column: auto;
  }

  .details-grid {
    grid-template-columns: 1fr;
  }
}
