:root {
  color-scheme: dark;
  --bg: #080808;
  --surface: #111111;
  --surface-raised: #181818;
  --surface-active: #211e16;
  --border: #2a2a2a;
  --border-strong: #4b4024;
  --text: #f4f1e8;
  --muted: #9b978c;
  --gold: #d6ad50;
  --gold-strong: #f0c766;
  --ok: #4ade80;
  --warn: #facc15;
  --danger: #f87171;
  --radius: 6px;
  --sidebar-width: 224px;
  font-family: "SFMono-Regular", "Cascadia Mono", "Roboto Mono", "PingFang SC", monospace;
  font-size: 14px;
}

* {
  box-sizing: border-box;
}

html {
  background: var(--bg);
}

body {
  margin: 0;
  min-width: 320px;
  min-height: 100vh;
  background: var(--bg);
  color: var(--text);
  letter-spacing: 0;
}

button,
input,
select,
textarea {
  font: inherit;
  letter-spacing: 0;
}

button,
input,
select,
textarea,
a {
  outline: none;
}

button:focus-visible,
input:focus-visible,
select:focus-visible,
textarea:focus-visible,
a:focus-visible,
summary:focus-visible {
  outline: 2px solid var(--gold-strong);
  outline-offset: 2px;
}

button {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface-raised);
  color: var(--text);
  cursor: pointer;
}

button:hover {
  border-color: var(--border-strong);
  color: var(--gold-strong);
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.5;
}

input,
select,
textarea {
  width: 100%;
  min-height: 38px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: #0c0c0c;
  color: var(--text);
  padding: 8px 10px;
}

input::placeholder,
textarea::placeholder {
  color: #706d66;
}

input[type="checkbox"],
input[type="radio"] {
  width: 16px;
  min-height: 16px;
  accent-color: var(--gold);
}

textarea {
  resize: vertical;
}

a {
  color: var(--gold-strong);
}

code,
.mono,
.data-table {
  font-variant-numeric: tabular-nums;
}

.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;
}

i[data-lucide] {
  width: 16px;
  height: 16px;
  display: inline-grid;
  flex: 0 0 16px;
  place-items: center;
  overflow: hidden;
  font-size: 14px;
  font-style: normal;
  line-height: 1;
}

i[data-lucide]::before { content: "•"; }
i[data-lucide="activity"]::before { content: "∿"; }
i[data-lucide="arrow-right"]::before { content: "→"; }
i[data-lucide="arrow-up-right"]::before { content: "↗"; }
i[data-lucide="history"]::before { content: "↶"; }
i[data-lucide="key-round"]::before { content: "⚿"; }
i[data-lucide="layout-dashboard"]::before { content: "▦"; }
i[data-lucide="log-out"]::before { content: "↪"; }
i[data-lucide="menu"]::before { content: "☰"; }
i[data-lucide="network"]::before { content: "⌘"; }
i[data-lucide="package-check"]::before { content: "✓"; }
i[data-lucide="plug-zap"]::before { content: "ϟ"; }
i[data-lucide="plus"]::before { content: "+"; }
i[data-lucide="radio-tower"]::before { content: "⌁"; }
i[data-lucide="refresh-cw"]::before { content: "↻"; }
i[data-lucide="scan-line"]::before { content: "◎"; }
i[data-lucide="settings-2"]::before { content: "⚙"; }
i[data-lucide="shield-check"]::before { content: "◆"; }
i[data-lucide="trash-2"]::before { content: "⌫"; }
i[data-lucide="x"]::before { content: "×"; }

.ops-shell {
  display: grid;
  grid-template-columns: 224px minmax(0, 1fr);
  min-height: 100vh;
}

.ops-sidebar {
  position: fixed;
  inset: 0 auto 0 0;
  z-index: 40;
  display: flex;
  width: var(--sidebar-width);
  min-height: 100vh;
  flex-direction: column;
  border-right: 1px solid var(--border);
  background: #0b0b0b;
}

.brand {
  padding: 22px 18px 18px;
  border-bottom: 1px solid var(--border);
}

.brand-mark {
  display: flex;
  align-items: center;
  gap: 10px;
  color: var(--gold-strong);
}

.brand-mark svg {
  width: 16px;
  height: 16px;
}

.brand-title {
  margin: 0;
  font-size: 15px;
  font-weight: 700;
}

.brand-subtitle {
  margin: 6px 0 0 26px;
  color: var(--muted);
  font-size: 11px;
}

.ops-nav {
  display: grid;
  gap: 4px;
  padding: 14px 10px;
}

.nav-button {
  display: flex;
  width: 100%;
  min-height: 42px;
  align-items: center;
  gap: 11px;
  border-color: transparent;
  background: transparent;
  color: var(--muted);
  padding: 0 12px;
  text-align: left;
}

.nav-button svg {
  width: 16px;
  height: 16px;
  flex: 0 0 16px;
}

.nav-button:hover {
  border-color: var(--border);
  background: var(--surface);
}

.nav-button.is-active,
.nav-button[aria-current="page"] {
  border-color: var(--border-strong);
  background: var(--surface-active);
  color: var(--gold-strong);
}

.sidebar-meta {
  display: grid;
  gap: 8px;
  margin-top: auto;
  padding: 16px 18px 20px;
  border-top: 1px solid var(--border);
  color: var(--muted);
  font-size: 11px;
}

.sidebar-meta-row {
  display: flex;
  justify-content: space-between;
  gap: 8px;
}

.sidebar-meta strong {
  color: var(--text);
  font-weight: 500;
}

.sidebar-overlay {
  display: none;
}

.ops-main {
  grid-column: 2;
  min-width: 0;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 30;
  display: flex;
  min-height: 64px;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  border-bottom: 1px solid var(--border);
  background: rgba(8, 8, 8, 0.96);
  padding: 10px 24px;
}

.topbar-title {
  min-width: 0;
}

.topbar-title h1 {
  margin: 0;
  font-size: 17px;
}

.topbar-title p {
  margin: 4px 0 0;
  color: var(--muted);
  font-size: 11px;
}

.topbar-actions,
.toolbar,
.inline-actions,
.form-actions,
.modal-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

.topbar-actions {
  flex-wrap: wrap;
  justify-content: flex-end;
}

.connection-state {
  color: var(--muted);
  font-size: 11px;
  white-space: nowrap;
}

.menu-button {
  display: none;
}

.icon-button {
  width: 36px;
  height: 36px;
  display: inline-grid;
  flex: 0 0 36px;
  place-items: center;
  padding: 0;
}

.icon-button.menu-button {
  display: none;
}

.icon-button svg,
.button svg {
  width: 16px;
  height: 16px;
}

.button {
  display: inline-flex;
  min-height: 36px;
  align-items: center;
  justify-content: center;
  gap: 7px;
  padding: 7px 12px;
  white-space: nowrap;
}

.button-primary {
  border-color: var(--gold);
  background: var(--gold);
  color: #090909;
  font-weight: 700;
}

.button-primary:hover {
  border-color: var(--gold-strong);
  background: var(--gold-strong);
  color: #090909;
}

.button-danger {
  border-color: #6d2929;
  color: var(--danger);
}

.button-danger:hover {
  border-color: var(--danger);
  color: #ffd4d4;
}

.button-small {
  min-height: 30px;
  padding: 5px 9px;
  font-size: 12px;
}

.ops-content {
  width: min(100%, 1600px);
  padding: 22px 24px 40px;
}

.overview-metrics {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 12px;
  margin-bottom: 16px;
}

.metric-card {
  min-width: 0;
  border: 1px solid var(--border);
  border-top-color: var(--gold);
  border-radius: var(--radius);
  background: var(--surface);
  padding: 14px;
}

.metric-label {
  color: var(--muted);
  font-size: 11px;
}

.metric-value {
  margin-top: 8px;
  color: var(--text);
  font-size: 24px;
  font-weight: 700;
  line-height: 1;
}

.metric-meta {
  min-height: 16px;
  margin-top: 8px;
  color: var(--muted);
  font-size: 10px;
  line-height: 1.5;
}

.overview-grid {
  display: grid;
  grid-template-columns: minmax(0, 1.4fr) minmax(260px, 0.6fr);
  gap: 16px;
}

.overview-grid .panel {
  margin: 0;
}

.overview-groups {
  display: grid;
  gap: 8px;
}

.overview-group-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 8px 14px;
  align-items: center;
  border-bottom: 1px solid var(--border);
  padding: 4px 0 12px;
}

.overview-group-row:last-child {
  border-bottom: 0;
  padding-bottom: 0;
}

.overview-group-name {
  min-width: 0;
  overflow-wrap: anywhere;
  font-weight: 700;
}

.overview-group-detail {
  margin-top: 4px;
  color: var(--muted);
  font-size: 11px;
  line-height: 1.5;
}

.overview-group-row .badge {
  justify-self: end;
}

.quick-actions {
  display: grid;
  gap: 8px;
}

.quick-actions .button {
  justify-content: flex-start;
}

.view-panel[hidden] {
  display: none;
}

.view-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 18px;
  margin-bottom: 18px;
}

.view-header h2,
.panel-title,
.modal-title {
  margin: 0;
}

.view-header h2 {
  font-size: 20px;
}

.view-header p,
.section-copy {
  margin: 6px 0 0;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.6;
}

.panel {
  min-width: 0;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
}

.panel + .panel {
  margin-top: 16px;
}

.panel-head {
  display: flex;
  min-height: 50px;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  border-bottom: 1px solid var(--border);
  padding: 10px 14px;
}

.panel-title {
  font-size: 14px;
}

.panel-body {
  padding: 16px;
}

.panel-body.flush {
  padding: 0;
}

.status-strip {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--muted);
  font-size: 12px;
}

.pulse-dot {
  width: 8px;
  height: 8px;
  display: inline-block;
  flex: 0 0 8px;
  border-radius: 50%;
  background: var(--muted);
}

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

.pulse-dot.off {
  background: var(--danger);
}

.warning-box,
.error-box {
  margin-bottom: 16px;
  border: 1px solid #6c5b19;
  border-radius: var(--radius);
  background: #1b180b;
  color: var(--warn);
  padding: 12px 14px;
}

.warning-box ul {
  margin: 8px 0 0;
  padding-left: 18px;
}

.error-box {
  border-color: #6d2929;
  background: #1c0d0d;
  color: var(--danger);
}

.desktop-table {
  display: block;
  overflow-x: auto;
}

.data-table {
  width: 100%;
  min-width: 940px;
  table-layout: fixed;
  border-collapse: collapse;
  font-size: 12px;
}

.data-table th,
.data-table td {
  overflow-wrap: anywhere;
  border-bottom: 1px solid var(--border);
  padding: 11px 12px;
  text-align: left;
  vertical-align: top;
}

.data-table th {
  background: #0d0d0d;
  color: var(--muted);
  font-size: 11px;
  font-weight: 500;
}

.data-table tbody tr:last-child td {
  border-bottom: 0;
}

.data-table tbody tr:hover {
  background: #15140f;
}

.cell-title {
  display: flex;
  min-width: 0;
  align-items: center;
  gap: 7px;
  color: var(--text);
  font-weight: 700;
}

.cell-meta {
  margin-top: 5px;
  color: var(--muted);
  font-size: 11px;
  line-height: 1.45;
}

.action-set {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.badge {
  display: inline-flex;
  min-height: 20px;
  align-items: center;
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 1px 6px;
  color: var(--muted);
  font-size: 10px;
  font-weight: 500;
  white-space: nowrap;
}

.badge-ok,
.text-green-400,
.text-emerald-300,
.text-emerald-400 {
  color: var(--ok) !important;
}

.badge-ok {
  border-color: #235b38;
}

.badge-warn,
.text-yellow-400,
.text-orange-400,
.text-amber-200,
.text-amber-300 {
  color: var(--warn) !important;
}

.badge-warn {
  border-color: #6c5b19;
}

.badge-danger,
.text-red-400,
.text-red-300 {
  color: var(--danger) !important;
}

.badge-danger {
  border-color: #6d2929;
}

.text-slate-300,
.text-slate-400,
.text-slate-500,
.text-slate-600 {
  color: var(--muted) !important;
}

.mobile-groups {
  display: none;
}

.mobile-group {
  border-bottom: 1px solid var(--border);
}

.mobile-group:last-child {
  border-bottom: 0;
}

.mobile-group summary {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 6px 12px;
  cursor: pointer;
  list-style: none;
  padding: 13px 14px;
}

.mobile-group summary::-webkit-details-marker {
  display: none;
}

.mobile-group summary::after {
  grid-column: 2;
  grid-row: 1 / 3;
  align-self: center;
  color: var(--gold);
  content: "+";
  font-size: 18px;
}

.mobile-group[open] summary::after {
  content: "-";
}

.mobile-group-name {
  min-width: 0;
  overflow-wrap: anywhere;
  font-weight: 700;
}

.mobile-group-summary {
  color: var(--muted);
  font-size: 11px;
}

.mobile-group-body {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
  border-top: 1px solid var(--border);
  background: #0d0d0d;
  padding: 14px;
}

.mobile-group-body dl {
  margin: 0;
}

.mobile-group-body dt {
  color: var(--muted);
  font-size: 10px;
}

.mobile-group-body dd {
  margin: 4px 0 0;
  overflow-wrap: anywhere;
  font-size: 12px;
}

.mobile-group-body .action-set,
.mobile-group-detail {
  grid-column: 1 / -1;
}

.status-lower-grid {
  display: grid;
  grid-template-columns: minmax(0, 3fr) minmax(300px, 2fr);
  gap: 16px;
  margin-top: 16px;
}

.status-lower-grid .panel {
  margin: 0;
}

.log-tools {
  display: flex;
  align-items: center;
  gap: 10px;
  color: var(--muted);
  font-size: 11px;
}

.check-label {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

#log-panel {
  height: 360px;
  overflow-y: auto;
  background: #080808;
  padding: 12px;
  color: var(--muted);
  font-size: 11px;
  line-height: 1.65;
  white-space: pre-wrap;
}

#log-panel .empty-state {
  padding: 22px 8px;
}

.log-info { color: #c9c5ba; }
.log-ok { color: var(--ok); }
.log-warn { color: var(--warn); }
.log-error { color: var(--danger); }

.history-list,
.stack-list {
  display: grid;
  gap: 8px;
}

.history-scroll {
  max-height: 360px;
  overflow-y: auto;
  padding: 10px;
}

.list-row {
  min-width: 0;
  border: 1px solid var(--border);
  border-left-color: var(--gold);
  border-radius: var(--radius);
  background: #0d0d0d;
  padding: 10px;
}

.list-row-head {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  color: var(--muted);
  font-size: 10px;
}

.list-row-main {
  margin-top: 6px;
  overflow-wrap: anywhere;
  color: var(--text);
}

.list-row-main svg {
  width: 16px;
  height: 16px;
  vertical-align: -2px;
}

.list-row-meta {
  margin-top: 5px;
  color: var(--muted);
  font-size: 11px;
}

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

.field {
  min-width: 0;
}

.field-wide {
  grid-column: 1 / -1;
}

.field label,
.field-label {
  display: block;
  margin-bottom: 6px;
  color: var(--muted);
  font-size: 11px;
}

.toggle-row {
  display: inline-flex !important;
  align-items: center;
  gap: 8px;
  margin: 0 !important;
  color: var(--text) !important;
  cursor: pointer;
}

.toggle-row input {
  accent-color: var(--gold);
}

.inline-form {
  display: flex;
  align-items: center;
  gap: 8px;
}

.inline-form > input,
.inline-form > select,
.inline-form > textarea {
  min-width: 0;
  flex: 1;
}

.inline-actions input[type="number"] {
  width: 82px;
}

.segmented {
  display: inline-flex;
  gap: 2px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: #0c0c0c;
  padding: 3px;
}

.segmented label {
  margin: 0;
  border-radius: 4px;
  color: var(--muted);
  cursor: pointer;
  padding: 7px 10px;
}

.segmented label:has(input:checked) {
  background: var(--gold);
  color: #090909;
}

.segmented label:has(input:focus-visible) {
  outline: 2px solid var(--gold-strong);
  outline-offset: 2px;
}

.form-actions {
  justify-content: flex-end;
  margin-top: 14px;
}

.form-message {
  min-height: 18px;
  margin-top: 8px;
  color: var(--muted);
  font-size: 11px;
}

.config-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 16px;
}

.config-grid .panel {
  margin: 0;
}

.config-grid .panel-wide {
  grid-column: 1 / -1;
}

.config-summary {
  display: grid;
  gap: 0;
}

.config-summary > div {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  border-bottom: 1px solid var(--border);
  padding: 9px 0;
}

.config-summary > div:last-child {
  border-bottom: 0;
}

.config-summary span:last-child {
  max-width: 60%;
  overflow-wrap: anywhere;
  text-align: right;
}

.server-list,
.records-list {
  display: grid;
  gap: 7px;
}

.captcha-box {
  margin-top: 12px;
  border: 1px solid #6c5b19;
  border-radius: var(--radius);
  background: #171407;
  padding: 12px;
}

.captcha-image-button {
  flex: 0 0 auto;
  padding: 3px;
  background: #fff;
}

.captcha-image-button img {
  display: block;
  width: 130px;
  height: 40px;
  object-fit: contain;
}

.modal {
  position: fixed;
  inset: 0;
  z-index: 60;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(0, 0, 0, 0.78);
  padding: 18px;
}

.modal-dialog {
  width: min(100%, 680px);
  max-height: 90vh;
  overflow-y: auto;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius);
  background: var(--surface-raised);
}

.modal-dialog-small {
  width: min(100%, 480px);
}

.modal-head {
  display: flex;
  min-height: 54px;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  border-bottom: 1px solid var(--border);
  padding: 10px 16px;
}

.modal-body {
  padding: 16px;
}

.modal-actions {
  justify-content: flex-end;
  margin-top: 18px;
}

.spinner {
  width: 14px;
  height: 14px;
  display: inline-block;
  border: 2px solid #5b5547;
  border-top-color: var(--gold-strong);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
  vertical-align: middle;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

.empty-state {
  padding: 28px 16px;
  color: var(--muted);
  text-align: center;
}

.login-page {
  display: grid;
  min-height: 100vh;
  place-items: center;
  padding: 20px;
}

.login-tool {
  width: min(100%, 390px);
  border: 1px solid var(--border);
  border-top-color: var(--gold);
  border-radius: var(--radius);
  background: var(--surface);
}

.login-head {
  border-bottom: 1px solid var(--border);
  padding: 22px 24px 18px;
}

.login-head h1 {
  margin: 0;
  color: var(--gold-strong);
  font-size: 20px;
}

.login-head p {
  margin: 7px 0 0;
  color: var(--muted);
  font-size: 11px;
}

.login-form {
  display: grid;
  gap: 15px;
  padding: 22px 24px 24px;
}

.login-form .button {
  width: 100%;
  min-height: 40px;
}

.login-error {
  color: var(--danger);
  font-size: 12px;
  line-height: 1.5;
  text-align: center;
}

::-webkit-scrollbar {
  width: 8px;
  height: 8px;
}

::-webkit-scrollbar-thumb {
  border-radius: 4px;
  background: #3a372f;
}

::-webkit-scrollbar-track {
  background: transparent;
}

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

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

  .config-grid .panel-wide {
    grid-column: auto;
  }
}

@media (max-width: 760px) {
  .ops-shell {
    grid-template-columns: 1fr;
  }

  .ops-main {
    grid-column: 1;
  }

  .ops-sidebar {
    width: min(82vw, 280px);
    transform: translateX(-100%);
    transition: transform 180ms ease;
  }

  .ops-sidebar.is-open {
    transform: translateX(0);
  }

  .sidebar-overlay {
    position: fixed;
    inset: 0;
    z-index: 35;
    display: block;
    visibility: hidden;
    background: rgba(0, 0, 0, 0.72);
    opacity: 0;
    transition: opacity 180ms ease, visibility 180ms ease;
  }

  .sidebar-overlay.is-open {
    visibility: visible;
    opacity: 1;
  }

  .icon-button.menu-button {
    display: inline-grid;
  }

  .topbar {
    display: grid;
    grid-template-columns: 36px minmax(0, 1fr);
    align-items: center;
    gap: 8px 10px;
    padding: 10px 12px;
  }

  .topbar-title {
    flex: 1;
  }

  .topbar-actions {
    grid-column: 1 / -1;
    width: 100%;
    gap: 6px;
    flex-wrap: nowrap;
    justify-content: flex-start;
  }

  .topbar-actions .status-strip {
    min-width: 0;
    flex: 1;
  }

  .topbar-actions #sched-text {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .topbar-actions #logoutBtn {
    margin-left: auto;
  }

  .topbar-actions .connection-state,
  .topbar-actions #btnRefresh span,
  .topbar-actions #logoutBtn span {
    display: none;
  }

  .ops-content {
    padding: 16px 12px 30px;
  }

  .view-header {
    flex-direction: column;
  }

  .toolbar {
    width: 100%;
    flex-wrap: wrap;
  }

  .desktop-table { display: none; }
  .mobile-groups { display: grid; }

  .status-lower-grid {
    grid-template-columns: 1fr;
  }

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

  #log-panel {
    height: 300px;
  }

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

  .field-wide {
    grid-column: auto;
  }

  .inline-form {
    align-items: stretch;
    flex-wrap: wrap;
  }

  .inline-form > input,
  .inline-form > select,
  .inline-form > textarea {
    flex-basis: 100%;
  }

  .modal {
    align-items: flex-end;
    padding: 0;
  }

  .modal-dialog,
  .modal-dialog-small {
    width: 100%;
    max-height: 94vh;
    border-right: 0;
    border-bottom: 0;
    border-left: 0;
    border-radius: 6px 6px 0 0;
  }
}

@media (max-width: 420px) {
  .overview-metrics {
    grid-template-columns: 1fr;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    scroll-behavior: auto !important;
    transition-duration: 0.01ms !important;
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
  }
}
