:root {
  --bg: #0f1419;
  --card: #1a2332;
  --border: #2d3a4d;
  --text: #e7ecf3;
  --muted: #8b9cb3;
  --accent: #3d8bfd;
  --ok: #3dd68c;
  --warn: #f0b429;
  --err: #f56565;
}

* { box-sizing: border-box; }
html {
  overflow-x: hidden;
  max-width: 100%;
}
body {
  margin: 0;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  font-family: "Segoe UI", system-ui, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.45;
  overflow-x: hidden;
}

header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 1rem 1.5rem;
  border-bottom: 1px solid var(--border);
  background: var(--card);
}
header h1 {
  margin: 0;
  font-size: 1.25rem;
  line-height: 1.2;
}
.header-brand {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  white-space: nowrap;
}
.header-actions {
  display: flex;
  gap: 1rem;
  align-items: center;
  flex-shrink: 0;
}
.header-actions .btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  line-height: 1.2;
  min-height: 2rem;
}
.header-actions #clock {
  line-height: 1.2;
  display: inline-flex;
  align-items: center;
}

.badge {
  font-size: 0.7rem;
  padding: 0.15rem 0.5rem;
  border-radius: 999px;
  background: var(--ok);
  color: #000;
  vertical-align: middle;
  margin-left: 0;
}
.badge.off { background: var(--muted); }

main.grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 1rem;
  padding: 1rem 1.5rem 2rem;
  max-width: 1200px;
  margin: 0 auto;
  /*flex: 1;*/
  width: 100%;
  box-sizing: border-box;
}
@media (max-width: 980px) {
  main.grid {
    grid-template-columns: 1fr;
    max-width: 100%;
    padding: 0.75rem;
    gap: 0.75rem;
  }
  .span2 { grid-column: span 1; }
  .card {
    width: 100%;
    max-width: 100%;
    padding: 0.85rem 0.9rem;
    overflow-x: clip;
  }
  .bar-pair {
    grid-template-columns: 2.4rem 1fr minmax(0, 3.5rem);
  }
  .bar-val {
    font-size: 0.65rem;
    white-space: normal;
    word-break: break-word;
    line-height: 1.2;
  }
  .table-wrap {
    width: 100%;
    max-width: 100%;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    overscroll-behavior-x: contain;
  }
  main.grid .table-wrap:not(.access-table-wrap) table {
    table-layout: fixed;
  }
  main.grid .table-wrap:not(.access-table-wrap) table .mono {
    word-break: break-all;
    overflow-wrap: anywhere;
    font-size: 0.75rem;
  }
  .access-table-wrap {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    overscroll-behavior-x: contain;
  }
  .access-table-wrap table {
    table-layout: auto;
    width: max-content;
    min-width: 42rem;
  }
  .access-table-wrap th,
  .access-table-wrap td {
    white-space: nowrap;
  }
  .access-table-wrap td.mono {
    word-break: normal;
    overflow-wrap: normal;
    font-size: 0.8rem;
  }
  .access-table-wrap .access-comment {
    white-space: normal;
    min-width: 5rem;
    max-width: 12rem;
  }
  .access-table-wrap .access-actions {
    white-space: nowrap;
  }
  .access-table-wrap .access-actions .btn {
    display: inline-block;
    width: auto;
    margin: 0 0.35rem 0 0;
  }
  header {
    flex-wrap: nowrap;
    align-items: center;
    gap: 0.5rem;
    padding: 0.75rem 0.9rem;
  }
  .header-brand {
    white-space: nowrap;
    min-width: 0;
    flex: 1 1 auto;
    align-items: center;
  }
  .header-brand h1 {
    font-size: 1.1rem;
    line-height: 1.2;
  }
  .header-actions {
    flex-wrap: nowrap;
    flex-shrink: 0;
    width: auto;
    justify-content: flex-end;
    align-items: center;
    gap: 0.5rem;
  }
  .status-row {
    width: 100%;
    gap: 0.5rem;
  }
  .status-row .stat {
    flex: 1 1 calc(50% - 0.5rem);
    min-width: 7rem;
  }
  .status-actions .btn.small {
    flex: 1 1 auto;
    min-width: 0;
    white-space: normal;
    text-align: center;
  }
  .tip .tiptext {
    width: min(280px, calc(100vw - 2rem));
    max-width: calc(100vw - 2rem);
  }
  .site-footer {
    flex-direction: column;
    flex-wrap: wrap;
    align-items: center;
    justify-content: center;
    padding: 0.75rem 0.9rem;
    gap: 0.35rem;
    text-align: center;
  }
  .footer-left {
    width: 100%;
    text-align: center;
  }
  .footer-right {
    margin-left: 0;
    white-space: normal;
    width: 100%;
    text-align: center !important;
  }
}

@media (max-width: 980px) {
  main.grid > section.card {
    grid-column: 1 / -1;
    width: 100%;
  }
}
.span2 { grid-column: span 2; }

.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 1rem 1.25rem;
  min-width: 0;
}
.card h2 { margin: 0 0 0.75rem; font-size: 1rem; color: var(--muted); font-weight: 600; }

.muted { color: var(--muted); font-size: 0.875rem; }
.mono { font-family: ui-monospace, monospace; }
.error { color: var(--err); }

.status-row {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem;
  align-items: flex-end;
}
.stat .label { display: block; font-size: 0.75rem; color: var(--muted); }
.stat .value { font-size: 1.1rem; font-weight: 600; }
.stat.ok .value { color: var(--ok); }
.stat.bad .value { color: var(--err); }
.stat.pending .value { color: var(--warn); }
.tip {
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 1rem;
  height: 1rem;
  margin-left: 0.25rem;
  border-radius: 999px;
  border: 1px solid var(--muted);
  color: var(--muted);
  font-size: 0.65rem;
  cursor: help;
  vertical-align: middle;
}
.tip .tiptext {
  visibility: hidden;
  opacity: 0;
  transition: opacity 0.15s ease;
  position: absolute;
  left: 50%;
  transform: translateX(-50%);
  bottom: 125%;
  width: 280px;
  background: #0b1118;
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.5rem 0.6rem;
  z-index: 50;
  font-size: 0.75rem;
  line-height: 1.3;
  pointer-events: none;
}
.tip:hover .tiptext,
.tip:focus .tiptext {
  visibility: visible;
  opacity: 1;
}

.big-num { font-size: 2.5rem; font-weight: 700; color: var(--accent); }

.bars-dual {
  display: flex;
  flex-direction: column;
  gap: 0.85rem;
  font-size: 0.82rem;
}
.metric-block {
  border-bottom: 1px solid var(--border);
  padding-bottom: 0.65rem;
}
.metric-block:last-child {
  border-bottom: none;
  padding-bottom: 0;
}
.metric-title {
  font-weight: 600;
  color: var(--text);
  margin-bottom: 0.4rem;
  font-size: 0.8rem;
}
.bar-pair {
  display: grid;
  grid-template-columns: 3.2rem 1fr 5.5rem;
  gap: 0.4rem;
  align-items: center;
  margin-bottom: 0.3rem;
}
.bar-pair:last-child {
  margin-bottom: 0;
}
.bar-tag {
  color: var(--muted);
  font-size: 0.72rem;
}
.bar {
  height: 8px;
  background: var(--border);
  border-radius: 4px;
  overflow: hidden;
}
.bar-fill {
  height: 100%;
  transition: width 0.4s ease;
}
.bar-fill.bar-server {
  background: linear-gradient(90deg, #3d8bfd, #6ea8fe);
}
.bar-fill.bar-svc {
  background: linear-gradient(90deg, #3dd68c, #7ae7b5);
}
.bar-val {
  text-align: right;
  font-size: 0.72rem;
  color: var(--muted);
  white-space: nowrap;
}
.disk-detail {
  margin: 0.65rem 0 0;
  font-size: 0.75rem;
}

.table-wrap { overflow-x: auto; max-height: 280px; max-width: 100%; }
table { width: 100%; border-collapse: collapse; font-size: 0.85rem; }
th, td { text-align: left; padding: 0.4rem 0.5rem; border-bottom: 1px solid var(--border); }
th { color: var(--muted); font-weight: 500; }
td[data-copy] {
  cursor: copy;
}
td[data-copy]:hover {
  color: var(--accent);
}

.tabs { margin-bottom: 0.5rem; }
.tab {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--muted);
  padding: 0.35rem 0.75rem;
  border-radius: 6px;
  margin-right: 0.35rem;
  cursor: pointer;
}
.tab.active { background: var(--accent); color: #fff; border-color: var(--accent); }

.btn {
  background: var(--accent);
  color: #fff;
  border: none;
  padding: 0.5rem 1rem;
  border-radius: 8px;
  cursor: pointer;
  text-decoration: none;
  font-size: 0.9rem;
}
.btn.ghost { background: transparent; border: 1px solid var(--border); color: var(--text); }
.btn.warn { background: #f0b429; color: #1a2332; border: 1px solid #f0b429; }
.btn.small { padding: 0.35rem 0.65rem; font-size: 0.8rem; }
.status-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  align-items: center;
  margin-top: 0.85rem;
  padding-top: 0.75rem;
  border-top: 1px solid var(--border);
}
.status-actions .btn.small {
  min-height: 2rem;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  line-height: 1;
}
.btn.loading {
  opacity: 0.85;
  cursor: wait;
  position: relative;
}
.btn.loading .btn-label::before {
  content: "";
  display: inline-block;
  width: 0.75rem;
  height: 0.75rem;
  margin-right: 0.35rem;
  border: 2px solid rgba(255, 255, 255, 0.35);
  border-top-color: #fff;
  border-radius: 50%;
  vertical-align: -0.1rem;
  animation: spin 0.7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.doctor-reason {
  margin: 0.5rem 0 0;
  font-size: 0.8rem;
  line-height: 1.35;
}
.doctor-reason.warn { color: var(--warn); }
.doctor-reason.error { color: var(--err); }

.doctor-details {
  margin-top: 0.65rem;
}
.doctor-details summary {
  cursor: pointer;
  color: var(--accent);
  font-size: 0.85rem;
  user-select: none;
}
.doctor-details summary:hover {
  text-decoration: underline;
}
.clients-details {
  margin-top: 0.75rem;
}
.clients-details summary {
  cursor: pointer;
  color: var(--accent);
  font-size: 0.9rem;
  font-weight: 600;
  user-select: none;
  list-style: none;
}
.clients-details summary::-webkit-details-marker {
  display: none;
}
.clients-details summary::before {
  content: "▸ ";
  display: inline-block;
  transition: transform 0.15s ease;
}
.clients-details[open] summary::before {
  transform: rotate(90deg);
}
.clients-details summary:hover {
  text-decoration: underline;
}
.clients-details .table-wrap {
  margin-top: 0.5rem;
}
.proxies-details {
  margin-top: 0.75rem;
}
.proxies-details summary {
  cursor: pointer;
  color: var(--accent);
  font-size: 0.9rem;
  font-weight: 600;
  user-select: none;
  list-style: none;
}
.proxies-details summary::-webkit-details-marker {
  display: none;
}
.proxies-details summary::before {
  content: "▸ ";
  display: inline-block;
  transition: transform 0.15s ease;
}
.proxies-details[open] summary::before {
  transform: rotate(90deg);
}
.proxies-details summary:hover {
  text-decoration: underline;
}
.proxies-details .tabs {
  margin-top: 0.65rem;
}
.proxies-table-wrap {
  max-height: none;
  overflow-y: visible;
  margin-top: 0.5rem;
}
.doctor-snippet {
  margin: 0.5rem 0 0;
  font-size: 0.75rem;
  line-height: 1.35;
  white-space: pre-wrap;
  word-break: break-word;
  overflow: visible;
}

.access-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
}
.access-top-actions {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  flex-wrap: wrap;
}
.access-top h2 {
  margin: 0;
}
#access-msg {
  min-height: 1.3rem;
  margin: 0.35rem 0 0.6rem;
  color: #f0b429;
}
.access-table-wrap {
  max-height: none;
  overflow-x: auto;
  max-width: 100%;
  -webkit-overflow-scrolling: touch;
}
.access-actions {
  white-space: nowrap;
}
.access-actions .btn {
  margin-right: 0.35rem;
}
.access-actions .btn:last-child {
  margin-right: 0;
}
.access-devices-count {
  text-align: center;
  font-variant-numeric: tabular-nums;
}
.access-comment {
  min-width: 8rem;
  max-width: 14rem;
  cursor: text;
}
.access-comment:empty::before {
  content: "—";
  color: var(--muted);
}
.access-comment-input {
  width: 100%;
  box-sizing: border-box;
  background: var(--bg);
  color: var(--text);
  border: 1px solid var(--accent);
  border-radius: 6px;
  padding: 0.25rem 0.4rem;
  font-size: inherit;
}

.site-footer {
  margin-top: auto;
  width: 100%;
  box-sizing: border-box;
  display: flex;
  align-items: center;
  gap: 1rem;
  border-top: 1px solid var(--border);
  background: var(--card);
  padding: 1rem 1.5rem;
  font-size: 0.85rem;
  color: var(--muted);
}
.footer-left {
  flex: 0 1 auto;
  min-width: 0;
}
.footer-left a {
  color: var(--accent);
  text-decoration: none;
}
.footer-left a:hover {
  text-decoration: underline;
}
.footer-right {
  margin-left: auto;
  flex-shrink: 0;
  white-space: nowrap;
  text-align: right;
}

.login-page {
  min-height: 100vh;
}
.login-wrap {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1.5rem;
}
.login-card {
  width: 100%;
  max-width: 360px;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 2rem;
}
.login-card h1 { 
  margin: 0 0 0.25rem; 
  text-align: center;
}
.vpn-form {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  margin-top: 0.5rem;
}
.vpn-hint {
  margin: 0 0 0.25rem;
  font-size: 0.85rem;
}
.vpn-field {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
}
.vpn-field[hidden] {
  display: none !important;
}
.vpn-label {
  font-size: 0.8rem;
  color: var(--muted);
}
.vpn-form input[type="url"] {
  width: 100%;
  padding: 0.55rem 0.65rem;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
  font-family: ui-monospace, monospace;
  font-size: 0.8rem;
}
.vpn-check {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.9rem;
  cursor: pointer;
  user-select: none;
}
.vpn-check input {
  width: 1rem;
  height: 1rem;
  accent-color: var(--accent);
}
.vpn-actions {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  flex-wrap: wrap;
}
.vpn-meta {
  margin: 0;
  font-size: 0.8rem;
}
.vpn-meta strong.ok-text,
.ok-text { color: var(--ok); }
.vpn-meta strong.bad-text,
#vpn-msg.error { color: var(--err); }

.login-card label {
  display: block;
  margin-top: 1rem;
  font-size: 0.85rem;
  color: var(--muted);
}
.login-card input {
  width: 100%;
  margin-top: 0.35rem;
  padding: 0.6rem;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
}
.login-card button { 
  width: 100%; 
  margin-top: 1.25rem; 
  padding: 10px;
  border-radius: 8px;
  font-weight: bold;
  cursor: pointer;
}
p.subhead {
  margin: 0;
  text-align: center;
}
