:root {
  color-scheme: dark;
  --bg: #08090a;
  --panel: #14171b;
  --panel-strong: #1b2026;
  --line: #2b323b;
  --muted: #9198a5;
  --text: #f4f1e8;
  --accent: #d9ff5a;
  --accent-strong: #c6ef35;
  --warn: #f0b44c;
  --danger: #f06f78;
  --focus: #d9ff5a;
}

* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

body {
  margin: 0;
  min-height: 100vh;
  background:
    radial-gradient(circle at 50% -20%, rgba(217, 255, 90, 0.08), transparent 34rem),
    linear-gradient(180deg, #090a0b 0%, var(--bg) 45%);
  color: var(--text);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

button,
input,
textarea,
select {
  font: inherit;
}

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

.sidebar {
  border-right: 1px solid var(--line);
  background: #0d1013;
  padding: 24px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 14px;
  margin-bottom: 28px;
}

.brand-mark {
  display: grid;
  place-items: center;
  width: 44px;
  height: 44px;
  border-radius: 8px;
  background: var(--accent);
  color: #08090a;
  font-size: 26px;
  font-weight: 800;
}

h1,
h2,
h3,
p {
  margin: 0;
}

h1 {
  font-size: 22px;
  line-height: 1.1;
}

.brand p,
.topbar p {
  color: var(--muted);
  margin-top: 4px;
}

.status-card {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px;
  border: 1px solid var(--line);
  background: var(--panel);
  border-radius: 8px;
}

.status-card strong,
.status-card span {
  display: block;
}

.status-card span {
  color: var(--muted);
  font-size: 13px;
  margin-top: 2px;
}

.status-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--warn);
}

.status-dot.ok {
  background: var(--accent);
  box-shadow: 0 0 18px rgba(217, 255, 90, 0.38);
}

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

.nav {
  display: grid;
  gap: 8px;
  margin-top: 28px;
}

.nav a {
  color: var(--muted);
  text-decoration: none;
  padding: 11px 12px;
  border-radius: 8px;
}

.nav a.active,
.nav a:hover {
  color: var(--text);
  background: var(--panel-strong);
}

.logged-out .workspace {
  max-width: 680px;
  margin: 0 auto;
}

.logged-out .topbar {
  margin-top: 32px;
}

.logged-out.shell,
.logged-out .shell {
  display: block;
}

.logged-out .sidebar {
  display: none !important;
}

.workspace {
  padding: 28px;
  max-width: 980px;
  width: 100%;
}

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

.topbar h2 {
  font-size: 28px;
  line-height: 1.15;
}

.panel {
  border: 1px solid var(--line);
  background: var(--panel);
  border-radius: 8px;
  padding: 18px;
  margin-bottom: 16px;
}

.panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 16px;
}

.panel-head h3 {
  font-size: 18px;
}

.panel-actions,
.metric-row {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.pill {
  color: var(--muted);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 5px 10px;
  font-size: 13px;
  white-space: nowrap;
}

.pill.ok {
  color: var(--accent);
  border-color: rgba(217, 255, 90, 0.42);
}

.pill.warn {
  color: var(--warn);
  border-color: rgba(240, 180, 76, 0.45);
}

.pill.danger {
  color: var(--danger);
  border-color: rgba(239, 107, 115, 0.5);
}

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

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

.single-action {
  display: grid;
}

.field {
  display: grid;
  gap: 7px;
}

.toggle-field {
  display: flex;
  align-items: center;
  gap: 10px;
  color: var(--text);
  padding-top: 24px;
}

.toggle-field input {
  width: 18px;
  min-height: 18px;
  accent-color: var(--accent);
}

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

.field span {
  color: var(--muted);
  font-size: 13px;
}

input,
textarea,
select {
  width: 100%;
  color: var(--text);
  background: #0b0e11;
  border: 1px solid var(--line);
  border-radius: 8px;
  outline: none;
}

input {
  min-height: 42px;
  padding: 9px 11px;
}

select {
  min-height: 42px;
  padding: 9px 11px;
}

input:focus,
textarea:focus,
select:focus {
  border-color: var(--focus);
}

button {
  min-height: 40px;
  border: 0;
  border-radius: 8px;
  padding: 9px 14px;
  cursor: pointer;
}

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

.primary {
  background: var(--accent);
  color: #08090a;
  font-weight: 700;
}

.primary:hover:not(:disabled) {
  background: var(--accent-strong);
}

.secondary {
  background: var(--panel-strong);
  color: var(--text);
  border: 1px solid var(--line);
}

.ghost {
  color: var(--muted);
  background: transparent;
  border: 1px solid var(--line);
}

.ghost:hover:not(:disabled),
.secondary:hover:not(:disabled) {
  border-color: var(--focus);
  color: var(--text);
}

.danger-action {
  color: var(--danger);
}

.compact {
  min-height: 32px;
  padding: 5px 10px;
}

.summary-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 10px;
  margin-bottom: 14px;
}

.summary-grid div {
  border: 1px solid var(--line);
  background: #0e1115;
  border-radius: 8px;
  padding: 12px;
  min-width: 0;
}

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

.summary-grid span {
  color: var(--muted);
  font-size: 12px;
  margin-bottom: 5px;
}

.summary-grid strong {
  overflow-wrap: anywhere;
  font-size: 13px;
}

.config-tools {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-bottom: 12px;
}

.config-box {
  min-height: 220px;
  resize: vertical;
  padding: 13px;
  line-height: 1.45;
  font-family: "SFMono-Regular", Consolas, "Liberation Mono", monospace;
  font-size: 13px;
}

.config-box.small {
  min-height: 96px;
  margin-top: 10px;
}

.config-box.link-box {
  min-height: 74px;
}

.user-groups {
  display: grid;
  gap: 12px;
}

.user-group {
  border: 1px solid var(--line);
  background: #0e1115;
  border-radius: 8px;
  overflow: hidden;
}

.user-group-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 14px;
  padding: 14px;
  border-bottom: 1px solid var(--line);
}

.compact-user .user-group-head {
  border-bottom: 0;
}

.user-group-head strong,
.user-group-head span {
  display: block;
}

.user-group-head span {
  color: var(--muted);
  font-size: 13px;
  margin-top: 3px;
}

.id-chip {
  display: inline-flex !important;
  width: fit-content;
  max-width: 100%;
  align-items: center;
  border-color: rgba(217, 255, 90, 0.24);
  color: #cdd4de !important;
  overflow-wrap: anywhere;
}

.full-id,
.identity-block {
  font-family: "SFMono-Regular", Consolas, "Liberation Mono", monospace;
  font-size: 12px;
  line-height: 1.35;
  overflow-wrap: anywhere;
  white-space: normal;
}

.client-table-wrap {
  overflow-x: auto;
}

.client-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}

.client-table th,
.client-table td {
  padding: 9px 8px;
  border-bottom: 1px solid var(--line);
  text-align: left;
}

.client-table th {
  color: var(--muted);
  font-weight: 600;
}

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

.table-actions {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.config-cell {
  display: grid;
  gap: 6px;
  min-width: 190px;
}

.config-cell strong {
  font-size: 14px;
  line-height: 1.25;
}

.config-cell span {
  color: var(--muted);
  font-size: 12px;
}

.ip-badge {
  display: inline-flex;
  width: fit-content;
  margin-left: 0;
  padding: 3px 7px;
}

.config-meta-row {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
}

.pager {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 10px;
  margin-top: 14px;
  color: var(--muted);
}

.empty-state {
  color: var(--muted);
  border: 1px dashed var(--line);
  border-radius: 8px;
  padding: 18px;
}

.client-page {
  min-height: 100vh;
  padding: 24px 16px;
}

.client-shell {
  width: min(760px, 100%);
  margin: 0 auto;
}

.client-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 16px;
}

.compact-brand {
  margin-bottom: 0;
}

.header-meta {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  justify-content: flex-end;
  max-width: min(480px, 100%);
}

.identity-block {
  max-width: min(390px, 100%);
  color: #cdd4de;
  border: 1px solid rgba(217, 255, 90, 0.28);
  border-radius: 8px;
  background: rgba(14, 17, 21, 0.72);
  padding: 6px 9px;
}

.blocked-state {
  display: grid;
  gap: 14px;
  border: 1px solid rgba(240, 111, 120, 0.34);
  background: linear-gradient(180deg, rgba(240, 111, 120, 0.08), rgba(20, 23, 27, 0.96));
  border-radius: 8px;
  padding: 16px;
  margin-bottom: 16px;
}

.blocked-state h2 {
  margin-top: 10px;
  font-size: 22px;
  line-height: 1.1;
}

.blocked-state p {
  max-width: 680px;
  margin-top: 8px;
  color: var(--muted);
  line-height: 1.5;
}

.compact-summary {
  grid-template-columns: minmax(0, 2fr) minmax(160px, 0.6fr);
  margin-bottom: 0;
}

.qr-layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 280px;
  gap: 14px;
  align-items: stretch;
}

.qr-card {
  position: relative;
  display: grid;
  place-items: center;
  width: min(280px, 100%);
  min-height: 280px;
  margin: 0 auto;
  border: 1px solid var(--line);
  background: #f8fafc;
  border-radius: 8px;
  padding: 16px;
}

.qr-card.empty {
  background: #0e1115;
  color: var(--muted);
}

.qr-card.empty img {
  display: none;
}

.qr-card:not(.empty)::after {
  content: "L";
  position: absolute;
  display: grid;
  place-items: center;
  width: 50px;
  height: 50px;
  border-radius: 8px;
  background: rgba(217, 255, 90, 0.94);
  color: #08090a;
  font-size: 30px;
  font-weight: 800;
  box-shadow: 0 0 0 8px rgba(248, 250, 252, 0.92);
  pointer-events: none;
}

.qr-card:not(.empty) span {
  display: none;
}

.qr-card img {
  width: 100%;
  max-width: 236px;
  aspect-ratio: 1;
  object-fit: contain;
}

.log-panel ol {
  margin: 0;
  padding-left: 20px;
  color: var(--muted);
}

.log-panel li {
  margin: 8px 0;
}

.toast {
  position: fixed;
  right: 24px;
  bottom: 24px;
  z-index: 20;
  max-width: min(420px, calc(100vw - 48px));
  padding: 12px 14px;
  border: 1px solid rgba(217, 255, 90, 0.5);
  border-radius: 8px;
  background: #171d0d;
  color: var(--text);
  box-shadow: 0 16px 40px rgba(0, 0, 0, 0.3);
}

.toast.danger {
  border-color: rgba(239, 107, 115, 0.5);
  background: #261419;
}

.modal {
  width: min(820px, calc(100vw - 32px));
  color: var(--text);
  background: transparent;
  border: 0;
  padding: 0;
}

.client-config-modal {
  width: min(600px, calc(100vw - 32px));
}

.create-config-modal {
  width: min(460px, calc(100vw - 32px));
}

.confirm-modal {
  width: min(560px, calc(100vw - 32px));
}

.modal::backdrop {
  background: rgba(4, 7, 12, 0.72);
}

.modal-panel {
  border: 1px solid var(--line);
  background: var(--panel);
  border-radius: 8px;
  padding: 16px;
}

.client-config-modal .modal-panel {
  padding: 14px;
}

.modal-panel p {
  margin-top: 4px;
  color: var(--muted);
}

.modal-panel p:empty {
  display: none;
}

.modal-actions {
  justify-content: flex-end;
  margin-bottom: 12px;
}

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

.modal-toolbar .config-tools {
  margin-bottom: 0;
}

.segmented {
  display: inline-flex;
  gap: 6px;
  margin-bottom: 0;
}

.segmented .active {
  border-color: var(--focus);
  color: var(--text);
}

.tab-panel {
  min-height: 0;
}

.client-config-modal .tab-panel {
  display: grid;
  place-items: center;
  width: 100%;
}

.client-config-modal .config-box {
  min-height: 260px;
  max-height: min(48vh, 340px);
}

.message-mode .segmented,
.message-mode .config-tools {
  display: none;
}

.message-panel {
  min-height: auto;
  display: block;
  padding: 2px 0 0;
}

.message-panel p {
  max-width: 520px;
  color: var(--text);
  font-size: 15px;
  line-height: 1.5;
}

.compact-form {
  margin-bottom: 14px;
}

.confirm-copy {
  color: var(--muted);
  line-height: 1.45;
  margin-bottom: 18px;
}

.confirm-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
}

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

  .sidebar {
    border-right: 0;
    border-bottom: 1px solid var(--line);
  }

  .workspace {
    padding: 16px;
  }

  .topbar,
  .panel-head {
    align-items: stretch;
    flex-direction: column;
  }

  .form-grid,
  .summary-grid,
  .qr-layout {
    grid-template-columns: 1fr;
  }

  .user-group-head,
  .client-header {
    flex-direction: column;
  }

  .header-meta,
  .modal-toolbar,
  .confirm-actions {
    align-items: stretch;
    flex-direction: column;
  }

  .identity-block {
    max-width: 100%;
  }

  .table-actions {
    flex-direction: column;
  }
}
