:root {
  color-scheme: light;
  --bg: #f3f6fb;
  --surface: #ffffff;
  --surface-soft: #f8fafc;
  --ink: #142033;
  --muted: #647386;
  --line: #d7deea;
  --primary: #204ac0;
  --primary-dark: #17398f;
  --accent: #00a887;
  --success-bg: #eaf7ef;
  --success: #167243;
  --error-bg: #fff0f0;
  --error: #b42318;
  --warning-bg: #fff7df;
  --warning: #946200;
  --shadow: 0 18px 45px rgb(20 32 51 / 10%);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--ink);
}

:focus-visible {
  outline: 3px solid rgb(32 74 192 / 35%);
  outline-offset: 3px;
}

button,
input,
select {
  font: inherit;
}

code {
  font-family: "SFMono-Regular", Consolas, "Liberation Mono", monospace;
  font-size: 0.92em;
}

.topnav {
  position: sticky;
  top: 0;
  z-index: 20;
  min-height: 64px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  padding: 14px clamp(18px, 4vw, 42px);
  background: var(--surface);
  border-bottom: 1px solid var(--line);
}

.brand,
.nav-actions,
.nav-actions form {
  display: inline-flex;
  align-items: center;
}

.brand {
  gap: 12px;
}

.nav-actions,
.nav-actions form {
  gap: 8px;
}

.brand {
  color: inherit;
  text-decoration: none;
}

.brand:hover {
  color: var(--primary);
}

.topnav .brand-mark {
  width: 34px;
  height: 34px;
  display: block;
  border-radius: 8px;
  object-fit: contain;
}

.brand-text {
  display: grid;
  gap: 1px;
}

.brand-name {
  font-size: 15px;
  font-weight: 800;
  line-height: 1.2;
}

.brand-subtitle {
  color: var(--muted);
  font-size: 12px;
  line-height: 1.2;
}

.nav-actions a,
.nav-actions button {
  min-height: 42px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  border: 1px solid var(--line);
  border-radius: 7px;
  padding: 0 13px;
  background: #fff;
  color: inherit;
  text-decoration: none;
  cursor: pointer;
  min-width: 0;
}

.nav-actions a:hover,
.nav-actions button:hover {
  border-color: #b8c3d4;
  background: #f8fafc;
}

.nav-actions a[aria-disabled="true"] {
  color: var(--muted);
}

.shell {
  width: min(1600px, calc(100vw - 32px));
  margin: 0 auto;
  padding: 28px 0 48px;
}

.login-page {
  min-height: 100vh;
  min-height: 100dvh;
  display: grid;
  place-items: center;
  padding: 24px;
  background:
    linear-gradient(135deg, rgb(32 74 192 / 12%), transparent 38%),
    linear-gradient(315deg, rgb(0 168 135 / 14%), transparent 42%),
    var(--bg);
}

.login-panel {
  width: min(430px, 100%);
  padding: 30px;
  background: rgb(255 255 255 / 94%);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.login-logo {
  margin-bottom: 24px;
}

.login-logo .brand-mark {
  width: 34px;
  height: 34px;
  border-radius: 8px;
  display: block;
  object-fit: contain;
}

.login-title {
  margin: 0;
  font-size: clamp(26px, 4vw, 38px);
  line-height: 1.12;
  letter-spacing: 0;
}

.login-copy {
  margin: 10px 0 0;
  color: var(--muted);
  line-height: 1.55;
}

.login-form {
  margin-top: 24px;
  display: grid;
  gap: 14px;
}

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

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

.field input {
  width: 100%;
  min-height: 44px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: #ffffff;
  color: var(--ink);
  padding: 0 12px;
}

.status-line {
  min-height: 20px;
  margin: 0;
  color: var(--error);
  font-size: 13px;
}

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

.page-actions {
  display: inline-flex;
  align-items: center;
  gap: 12px;
  padding-top: 2px;
}

.eyebrow {
  margin: 0 0 6px;
  color: var(--primary);
  font-size: 12px;
  text-transform: uppercase;
  font-weight: 800;
  letter-spacing: 0.08em;
}

h1,
h2,
p {
  margin-top: 0;
}

h1 {
  margin-bottom: 6px;
  font-size: 30px;
  line-height: 1.15;
  letter-spacing: 0;
}

h2 {
  margin-bottom: 16px;
  font-size: 17px;
  line-height: 1.25;
  letter-spacing: 0;
}

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

.stat {
  min-width: 112px;
  padding: 14px 16px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  text-align: right;
}

.stat span {
  display: block;
  font-size: 28px;
  font-weight: 800;
  line-height: 1;
}

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

.layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 340px;
  gap: 18px;
  align-items: start;
}

.layout.single {
  grid-template-columns: 1fr;
}

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

.panel-head {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  align-items: baseline;
}

.panel-head.compact h2 {
  margin-bottom: 0;
}

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

table {
  width: 100%;
  border-collapse: collapse;
  table-layout: auto;
}

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

td:first-child {
  min-width: 170px;
}

th {
  color: var(--muted);
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

.acl-list {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.acl,
.status,
.scope {
  display: inline-flex;
  align-items: center;
  min-height: 28px;
  border-radius: 999px;
  padding: 0 10px;
  font-size: 13px;
  white-space: nowrap;
}

.acl {
  gap: 6px;
  border: 1px solid var(--line);
  background: var(--surface-soft);
}

.status.ok,
.scope.narrow {
  background: var(--success-bg);
  color: var(--success);
}

.scope.wide {
  background: var(--warning-bg);
  color: var(--warning);
}

.form {
  display: grid;
  gap: 14px;
}

.password-actions {
  display: grid;
  grid-template-columns: minmax(120px, 1fr) repeat(3, 36px);
  gap: 8px;
  align-items: center;
  max-width: 310px;
}

.secret-display {
  min-width: 0;
  line-height: 1.35;
}

.password-value {
  display: inline-block;
  max-width: 150px;
  overflow-wrap: anywhere;
  color: var(--ink);
  font-family: "SFMono-Regular", Consolas, "Liberation Mono", monospace;
  font-size: 12px;
}

label {
  display: grid;
  gap: 6px;
  font-size: 13px;
  font-weight: 700;
}

input,
select {
  width: 100%;
  min-height: 42px;
  border: 1px solid var(--line);
  border-radius: 7px;
  padding: 0 11px;
  background: #fff;
  color: var(--ink);
}

.primary,
.primary-button,
.secondary {
  min-height: 44px;
  border-radius: 7px;
  padding: 0 14px;
  font-weight: 750;
  cursor: pointer;
}

.action-button {
  min-width: 154px;
}

.primary,
.primary-button {
  border: 0;
  background: var(--primary);
  color: white;
}

.secondary {
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--ink);
}

.primary:hover,
.primary-button:hover {
  background: var(--primary-dark);
}

.secondary:hover {
  border-color: var(--primary);
  color: var(--primary);
}

.icon-button {
  width: 36px;
  height: 36px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: var(--surface);
  color: var(--ink);
  font-size: 22px;
  line-height: 1;
  cursor: pointer;
}

.icon-button:disabled {
  cursor: not-allowed;
  opacity: 0.45;
}

.icon-button:hover {
  border-color: var(--primary);
  color: var(--primary);
}

.icon-button.copied {
  border-color: var(--success);
  color: var(--success);
}

.modal {
  width: min(420px, calc(100vw - 32px));
  padding: 0;
  border: 0;
  border-radius: 8px;
  background: transparent;
}

.modal::backdrop {
  background: rgb(20 32 51 / 42%);
}

.modal-card {
  padding: 20px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: var(--shadow);
}

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

.modal-head h2 {
  margin: 0;
}

.modal-copy {
  margin-bottom: 2px;
}

.match-status {
  min-height: 20px;
  margin: -2px 0 0;
  color: var(--muted);
  font-size: 13px;
}

.match-status.ok {
  color: var(--success);
}

.match-status.error-text {
  color: var(--error);
}

.alert {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  border-radius: 7px;
  padding: 12px 14px;
  margin-bottom: 16px;
}

.alert.success {
  background: var(--success-bg);
  color: var(--success);
}

.alert.error {
  background: var(--error-bg);
  color: var(--error);
}

.alert-close {
  width: 28px;
  height: 28px;
  border: 0;
  border-radius: 7px;
  background: rgb(255 255 255 / 72%);
  color: inherit;
  font-size: 20px;
  line-height: 1;
  cursor: pointer;
}

.alert-close:hover {
  background: #ffffff;
}

.messages-layout {
  display: grid;
  grid-template-columns: 320px minmax(0, 1fr);
  gap: 18px;
  align-items: stretch;
}

.subscriber-list,
.message-viewer {
  min-height: calc(100vh - 190px);
}

.subscriber-users {
  display: grid;
  gap: 8px;
}

.subscriber-user {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
  background: #ffffff;
  color: var(--ink);
  text-align: left;
  cursor: pointer;
}

.subscriber-user:hover,
.subscriber-user.is-active {
  border-color: var(--primary);
  background: #f5f8ff;
}

.subscriber-user.is-disabled {
  cursor: not-allowed;
  opacity: 0.55;
}

.subscriber-user strong,
.subscriber-user small {
  display: block;
}

.subscriber-user small {
  margin-top: 4px;
  color: var(--muted);
  font-family: "SFMono-Regular", Consolas, "Liberation Mono", monospace;
  font-size: 12px;
  overflow-wrap: anywhere;
}

.subscriber-state {
  flex: 0 0 auto;
  border-radius: 999px;
  padding: 5px 8px;
  background: var(--surface-soft);
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

.subscriber-user.is-active .subscriber-state {
  background: var(--primary);
  color: #ffffff;
}

.message-viewer {
  display: grid;
  grid-template-rows: auto auto minmax(0, 1fr);
  gap: 12px;
}

.message-viewer-head {
  display: flex;
  align-items: start;
  justify-content: space-between;
  gap: 16px;
}

.message-viewer-head h2 {
  margin-bottom: 4px;
}

.stream-status {
  border: 1px solid var(--line);
  border-radius: 7px;
  padding: 10px 12px;
  background: var(--surface-soft);
  color: var(--muted);
  font-size: 13px;
}

.message-list {
  min-height: 360px;
  max-height: calc(100vh - 330px);
  overflow: auto;
  display: grid;
  align-content: start;
  gap: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
  background: #f7f9fc;
}

.empty-state {
  display: grid;
  min-height: 160px;
  place-items: center;
  color: var(--muted);
  text-align: center;
}

.message-item {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
  background: #ffffff;
}

.message-meta {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 8px;
  color: var(--muted);
  font-size: 12px;
}

.message-meta code {
  overflow-wrap: anywhere;
}

.message-item pre {
  margin: 0;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  font-family: "SFMono-Regular", Consolas, "Liberation Mono", monospace;
  font-size: 12px;
  line-height: 1.5;
}

@media (max-width: 860px) {
  .topnav,
  .page-head,
  .panel-head {
    align-items: stretch;
    flex-direction: column;
  }

  .page-actions {
    align-items: stretch;
    flex-direction: column-reverse;
  }

  .nav-actions {
    flex-wrap: wrap;
  }

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

  .messages-layout {
    grid-template-columns: 1fr;
  }

  .subscriber-list,
  .message-viewer {
    min-height: auto;
  }

  .message-list {
    max-height: none;
  }

  .message-viewer-head {
    flex-direction: column;
  }

  .stat {
    text-align: left;
  }
}
