:root {
  color-scheme: dark;
  --bg-main: #080b12;
  --bg-top: #0b101a;
  --surface: rgba(14, 20, 34, 0.9);
  --surface-strong: rgba(18, 25, 42, 0.96);
  --border: rgba(143, 166, 213, 0.24);
  --text: #e7eefc;
  --muted: #9aaccc;
  --ok: #18b37f;
  --bad: #f06464;
  --action: #4f8cff;
  --action-hover: #74a2ff;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: "Segoe UI", "Inter", sans-serif;
  color: var(--text);
  background: linear-gradient(160deg, var(--bg-top) 0%, var(--bg-main) 100%);
  min-height: 100vh;
}

.page {
  max-width: 1240px;
  margin: 0 auto;
  padding: 28px 24px;
}

.topbar {
  display: flex;
  justify-content: space-between;
  align-items: end;
  gap: 24px;
  margin-bottom: 20px;
}

.topbar h1 {
  margin: 0;
  font-size: 1.92rem;
  letter-spacing: 0.01em;
}

.topbar p {
  margin: 7px 0 0;
  color: var(--muted);
}

.auth {
  min-width: 320px;
  padding: 12px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: rgba(10, 15, 26, 0.82);
  backdrop-filter: blur(8px);
}

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

.auth-row {
  margin-top: 8px;
  display: flex;
  gap: 8px;
}

.auth-row input {
  flex: 1;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: rgba(14, 20, 36, 0.95);
  color: var(--text);
  padding: 10px 12px;
}

.auth-row input:focus {
  outline: 2px solid rgba(79, 140, 255, 0.5);
  outline-offset: 1px;
}

.auth-row button {
  border: 1px solid transparent;
  border-radius: 8px;
  padding: 10px 14px;
  background: var(--action);
  color: #fff;
  cursor: pointer;
  transition: background-color 0.16s ease;
}

.auth-row button:hover {
  background: var(--action-hover);
}

.auth-actions {
  margin-top: 10px;
  display: flex;
  justify-content: flex-end;
}

.button-ghost {
  border: 1px solid var(--border);
  border-radius: 8px;
  background: rgba(17, 24, 42, 0.95);
  color: var(--text);
  padding: 6px 10px;
  font-size: 0.8rem;
  cursor: pointer;
  transition: border-color 0.14s ease, background-color 0.14s ease;
}

.button-ghost:hover {
  border-color: rgba(162, 186, 236, 0.48);
  background: rgba(26, 35, 62, 0.95);
}

.button-ghost:disabled,
.button-danger:disabled {
  cursor: not-allowed;
  opacity: 0.55;
}

.button-danger {
  border: 1px solid rgba(240, 100, 100, 0.42);
  border-radius: 8px;
  background: rgba(62, 18, 26, 0.62);
  color: #ffb4b4;
  padding: 6px 10px;
  font-size: 0.8rem;
  cursor: pointer;
  transition: background-color 0.14s ease;
}

.button-danger:hover {
  background: rgba(95, 24, 38, 0.72);
}

.button-group {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.meta {
  margin-bottom: 13px;
  color: var(--muted);
}

.table-wrapper {
  border: 1px solid var(--border);
  border-radius: 14px;
  overflow-x: auto;
  overflow-y: auto;
  background: var(--surface);
  backdrop-filter: blur(6px);
  box-shadow:
    0 12px 28px rgba(0, 0, 0, 0.34),
    inset 0 1px 0 rgba(199, 219, 255, 0.025);
}

table {
  width: max(100%, 1240px);
  border-collapse: collapse;
  min-width: 1240px;
  table-layout: auto;
}

th,
td {
  text-align: left;
  padding: 12px 10px;
  border-bottom: 1px solid rgba(122, 145, 194, 0.16);
  font-size: 0.92rem;
  vertical-align: middle;
}

thead th {
  font-size: 0.76rem;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  color: #94abd9;
  background: rgba(15, 21, 37, 0.92);
  position: sticky;
  top: 0;
}

tbody tr:hover {
  background: rgba(47, 65, 104, 0.25);
}

.cell-subdomain strong {
  display: inline-block;
  max-width: 240px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.cell-subdomain .muted {
  max-width: 240px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.cell-agent .agent-line {
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 30px;
}

.cell-agent .agent-name {
  font-weight: 600;
  max-width: 110px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.cell-agent .agent-connection {
  max-width: 120px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 0.8rem;
  padding: 1px 0;
}

.cell-agent .agent-replicas {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 30px;
  height: 22px;
  padding: 0 8px;
  border-radius: 999px;
  font-size: 0.74rem;
  font-weight: 700;
  color: #e7eefc;
  background: rgba(79, 140, 255, 0.2);
  border: 1px solid rgba(79, 140, 255, 0.4);
}

.cell-local,
.cell-last-seen {
  white-space: nowrap;
}

.cell-cors code {
  display: inline-block;
  max-width: 240px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  vertical-align: top;
}

.cell-actions {
  min-width: 210px;
}

.button-group-actions {
  flex-wrap: nowrap;
}

td.cell-actions .button-ghost,
td.cell-actions .button-danger {
  white-space: nowrap;
  padding: 6px 10px;
}

.pill {
  display: inline-flex;
  align-items: center;
  border-radius: 999px;
  padding: 4px 10px;
  font-size: 0.77rem;
  font-weight: 700;
}

.pill.ok {
  color: #e9fff7;
  background: linear-gradient(140deg, #12906b, #19bc85);
}

.pill.bad {
  color: #ffeaea;
  background: linear-gradient(140deg, #b3394f, #f06464);
}

.muted {
  color: var(--muted);
}

.mono {
  font-family: "Consolas", "Cascadia Code", monospace;
  font-size: 0.83rem;
  color: #d6e2ff;
}

.modal.hidden {
  display: none;
}

.modal {
  position: fixed;
  inset: 0;
  z-index: 60;
}

.modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(2, 5, 10, 0.72);
  backdrop-filter: blur(3px);
}

.modal-card {
  position: relative;
  z-index: 1;
  width: min(680px, calc(100% - 28px));
  margin: 9vh auto 0;
  border: 1px solid var(--border);
  border-radius: 14px;
  background: var(--surface-strong);
  padding: 18px;
  box-shadow: 0 24px 52px rgba(0, 0, 0, 0.48);
}

.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
}

.modal-header h2 {
  margin: 0;
  font-size: 1.12rem;
}

.modal-token-box {
  margin-top: 10px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: rgba(10, 14, 24, 0.86);
  padding: 12px;
  line-height: 1.55;
  word-break: break-all;
}

.modal-actions {
  margin-top: 14px;
  display: flex;
  justify-content: flex-end;
  gap: 8px;
}

.modal-textarea {
  margin-top: 10px;
  width: 100%;
  min-height: 170px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: rgba(10, 14, 24, 0.86);
  color: #d6e2ff;
  font-family: "Consolas", "Cascadia Code", monospace;
  font-size: 0.82rem;
  line-height: 1.45;
  padding: 12px;
  resize: vertical;
}

.modal-instructions {
  margin-top: 10px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: rgba(10, 14, 24, 0.86);
  color: #d6e2ff;
  font-family: "Consolas", "Cascadia Code", monospace;
  font-size: 0.82rem;
  line-height: 1.52;
  padding: 12px;
  white-space: pre-wrap;
}

@media (max-width: 860px) {
  .topbar {
    flex-direction: column;
    align-items: stretch;
  }

  .auth {
    min-width: 100%;
  }
}

@media (max-width: 1080px) {
  .page {
    padding: 18px 12px;
  }
}
