:root {
  color-scheme: light;
  --bg: #f7f8f6;
  --panel: #ffffff;
  --panel-soft: #fbfcfa;
  --ink: #18211f;
  --muted: #68716d;
  --subtle: #8b958f;
  --line: #dce3de;
  --line-strong: #c9d3cd;
  --brand: #2f7465;
  --brand-dark: #23584d;
  --brand-soft: #e7f1ed;
  --warning: #946200;
  --warning-soft: #fff5da;
  --danger: #b42318;
  --danger-soft: #fff1f0;
  --success: #067647;
  --success-soft: #ecfdf3;
  --shadow: 0 18px 45px rgba(20, 31, 28, 0.08);
  --radius: 8px;
}

* {
  box-sizing: border-box;
}

html {
  min-height: 100%;
}

body {
  margin: 0;
  min-height: 100dvh;
  background:
    linear-gradient(180deg, rgba(231, 241, 237, 0.55), rgba(247, 248, 246, 0) 280px),
    var(--bg);
  color: var(--ink);
  font-family:
    ui-sans-serif,
    system-ui,
    -apple-system,
    BlinkMacSystemFont,
    "Segoe UI",
    sans-serif;
  letter-spacing: 0;
}

a {
  color: inherit;
}

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

.shell {
  width: min(1280px, calc(100% - 32px));
  margin: 0 auto;
  padding: 28px 0 44px;
}

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

.panel.narrow {
  width: min(560px, 100%);
  margin: 52px auto;
}

.auth-panel {
  width: min(520px, 100%);
  margin: 0;
}

.login-panel {
  margin: 0;
}

.stack {
  display: grid;
  gap: 8px;
}

h1,
h2,
p {
  margin: 0;
}

h1 {
  font-size: clamp(28px, 4vw, 46px);
  line-height: 1.05;
  font-weight: 760;
  letter-spacing: 0;
}

h2 {
  font-size: 18px;
  line-height: 1.25;
  font-weight: 740;
  letter-spacing: 0;
}

.eyebrow {
  color: var(--brand);
  font-size: 12px;
  font-weight: 760;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.muted {
  color: var(--muted);
  line-height: 1.6;
}

.auth-page {
  min-height: calc(100dvh - 72px);
  display: grid;
  grid-template-columns: minmax(0, 0.95fr) minmax(360px, 520px);
  align-items: center;
  gap: 48px;
}

.admin-login-page {
  grid-template-columns: minmax(0, 0.9fr) minmax(340px, 480px);
}

.auth-copy {
  display: grid;
  gap: 16px;
  align-content: center;
}

.auth-copy .muted {
  max-width: 58ch;
  font-size: 16px;
}

.auth-summary,
.stats-grid,
.client-meta-grid {
  display: grid;
  gap: 12px;
}

.auth-summary {
  grid-template-columns: repeat(2, minmax(0, 1fr));
  margin-top: 10px;
  max-width: 560px;
}

.auth-summary div,
.stat,
.client-meta-grid div {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: rgba(255, 255, 255, 0.74);
  padding: 14px;
}

.auth-summary span,
.stat span,
.client-meta-grid span {
  display: block;
  color: var(--muted);
  font-size: 12px;
  font-weight: 720;
  margin-bottom: 6px;
}

.auth-summary strong,
.client-meta-grid strong {
  display: block;
  font-size: 14px;
  line-height: 1.35;
  overflow-wrap: anywhere;
}

.form {
  display: grid;
  gap: 15px;
  margin-top: 18px;
}

.auth-form {
  margin-top: 0;
}

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

.compact-form {
  margin-top: 0;
}

.full-span {
  grid-column: 1 / -1;
}

label {
  display: grid;
  gap: 7px;
  color: var(--ink);
  font-size: 14px;
  font-weight: 680;
}

.hint,
.form-note {
  color: var(--muted);
  font-size: 13px;
  line-height: 1.45;
}

input,
textarea {
  width: 100%;
  border: 1px solid var(--line-strong);
  border-radius: 7px;
  color: var(--ink);
  background: #fff;
  font: inherit;
  font-weight: 520;
  padding: 11px 12px;
  outline: none;
}

input[readonly] {
  background: var(--panel-soft);
  color: var(--muted);
}

textarea {
  resize: vertical;
  min-height: 112px;
  line-height: 1.45;
}

input:focus,
textarea:focus,
button:focus-visible,
a.button:focus-visible {
  outline: 2px solid var(--brand);
  outline-offset: 2px;
}

.email-combo {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: stretch;
  border: 1px solid var(--line-strong);
  border-radius: 7px;
  background: #fff;
  overflow: hidden;
}

.email-combo input {
  border: 0;
  border-radius: 0;
}

.email-combo input:focus {
  outline: 0;
}

.email-combo:focus-within {
  outline: 2px solid var(--brand);
  outline-offset: 0;
  border-color: var(--brand);
}

.email-combo > span {
  display: flex;
  align-items: center;
  border-left: 1px solid var(--line-strong);
  background: var(--panel-soft);
  color: var(--muted);
  font-weight: 720;
  padding: 0 12px;
  white-space: nowrap;
}

.button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 40px;
  border: 1px solid transparent;
  border-radius: 7px;
  padding: 0 15px;
  font: inherit;
  font-size: 14px;
  font-weight: 760;
  text-decoration: none;
  cursor: pointer;
  white-space: nowrap;
  transition:
    transform 150ms ease,
    background-color 150ms ease,
    border-color 150ms ease,
    color 150ms ease;
}

.button:active {
  transform: scale(0.98);
}

.button.primary {
  background: var(--brand);
  color: #fff;
}

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

.button.secondary {
  background: #fff;
  color: var(--brand-dark);
  border-color: var(--line-strong);
}

.button.secondary:hover {
  border-color: var(--brand);
  background: var(--brand-soft);
}

.button.danger {
  background: #fff;
  color: var(--danger);
  border-color: #f6b5af;
}

.button.danger:hover {
  background: var(--danger-soft);
}

.button.tiny {
  min-height: 30px;
  padding: 0 10px;
  font-size: 12px;
}

.segmented {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  border: 1px solid var(--line);
  border-radius: 9px;
  padding: 3px;
  gap: 3px;
  background: #eef3f0;
}

.segmented label {
  display: block;
}

.segmented input {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}

.segmented span {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 38px;
  border-radius: 7px;
  color: var(--muted);
  cursor: pointer;
  font-weight: 740;
  transition:
    transform 150ms ease,
    background-color 150ms ease,
    color 150ms ease;
}

.segmented input:focus-visible + span {
  outline: 2px solid var(--brand);
  outline-offset: 2px;
}

.segmented input:checked + span {
  background: #fff;
  color: var(--ink);
  box-shadow: 0 1px 3px rgba(16, 24, 40, 0.12);
}

.segmented span:active {
  transform: scale(0.98);
}

.known {
  margin-top: 18px;
  border-top: 1px solid var(--line);
  padding-top: 16px;
}

.hidden {
  display: none;
}

.section-label,
.label {
  color: var(--muted);
  font-size: 12px;
  font-weight: 760;
  margin-bottom: 10px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

.known-list {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.email-chip {
  border: 1px solid var(--line-strong);
  border-radius: 999px;
  background: #fff;
  color: var(--ink);
  padding: 7px 11px;
  font: inherit;
  font-size: 13px;
  cursor: pointer;
  max-width: 100%;
  overflow-wrap: anywhere;
}

.email-chip:hover {
  border-color: var(--brand);
  background: var(--brand-soft);
}

.notice {
  border-radius: var(--radius);
  padding: 12px 14px;
  margin-bottom: 16px;
  line-height: 1.5;
  font-size: 14px;
  border: 1px solid var(--line);
}

.notice.error {
  color: var(--danger);
  background: var(--danger-soft);
  border-color: #ffcdc8;
}

.notice.success {
  color: var(--success);
  background: var(--success-soft);
  border-color: #abefc6;
}

.notice.code {
  background: var(--warning-soft);
  border-color: #fedf89;
}

.secret-box {
  margin: 20px 0;
  border: 1px solid #fedf89;
  border-radius: var(--radius);
  background: var(--warning-soft);
  padding: 18px;
  overflow-wrap: anywhere;
}

code {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 0.95em;
}

.secret-box code {
  display: block;
  font-size: 20px;
  font-weight: 780;
  letter-spacing: 0;
}

.warning {
  color: #93370d;
  line-height: 1.5;
  margin-bottom: 20px;
}

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

.admin-header > div {
  display: grid;
  gap: 7px;
}

.admin-header h1 {
  font-size: clamp(28px, 3vw, 38px);
}

.stats-grid {
  grid-template-columns: repeat(4, minmax(0, 1fr));
  margin-bottom: 18px;
}

.stat {
  box-shadow: none;
}

.stat strong {
  display: block;
  min-height: 30px;
  font-size: 25px;
  line-height: 1.1;
  font-weight: 780;
  overflow-wrap: anywhere;
}

.stat small {
  display: block;
  margin-top: 8px;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.35;
}

.workbench-grid {
  display: grid;
  grid-template-columns: minmax(0, 1.6fr) minmax(280px, 0.9fr);
  gap: 18px;
  align-items: stretch;
}

.workbench-grid .panel {
  margin-bottom: 18px;
}

.quick-reference {
  box-shadow: none;
}

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

.section-heading > div {
  display: grid;
  gap: 5px;
}

.section-heading .muted {
  font-size: 14px;
}

.table-wrap {
  overflow-x: auto;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #fff;
}

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

.data-table {
  min-width: 850px;
}

.invite-table {
  min-width: 700px;
}

.log-table {
  min-width: 900px;
}

th,
td {
  border-bottom: 1px solid var(--line);
  padding: 12px 14px;
  text-align: left;
  vertical-align: middle;
  font-size: 14px;
}

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

th {
  background: var(--panel-soft);
  color: var(--muted);
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  font-weight: 780;
  white-space: nowrap;
}

td {
  line-height: 1.4;
}

.col-id {
  width: 68px;
  color: var(--muted);
  font-weight: 720;
  white-space: nowrap;
}

.cell-title {
  font-weight: 760;
  color: var(--ink);
  overflow-wrap: anywhere;
}

.cell-meta {
  margin-top: 4px;
  color: var(--muted);
  font-size: 12px;
  overflow-wrap: anywhere;
}

.code-pill,
.event-code {
  display: inline-flex;
  max-width: 280px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--panel-soft);
  color: #27332f;
  padding: 5px 8px;
  overflow-wrap: anywhere;
  white-space: normal;
}

.event-code {
  max-width: 220px;
}

.meter-label {
  display: flex;
  align-items: baseline;
  gap: 4px;
  margin-bottom: 7px;
  white-space: nowrap;
}

.meter-label strong {
  font-size: 15px;
}

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

.meter {
  width: 112px;
  height: 7px;
  border-radius: 999px;
  background: #e9eeeb;
  overflow: hidden;
}

.meter span {
  display: block;
  height: 100%;
  border-radius: inherit;
  background: var(--brand);
}

.status {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 26px;
  border-radius: 999px;
  padding: 0 9px;
  font-size: 12px;
  font-weight: 760;
  white-space: nowrap;
}

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

.status.warning {
  color: var(--warning);
  background: var(--warning-soft);
}

.status.muted {
  color: var(--muted);
  background: #eff2f0;
}

.inline-form {
  display: inline-flex;
  margin: 0 6px 6px 0;
}

.actions {
  min-width: 174px;
  white-space: nowrap;
}

.actions.compact {
  min-width: 82px;
}

.subpanel {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--panel-soft);
  padding: 16px;
  margin-top: 12px;
}

.client-editor {
  display: grid;
  gap: 16px;
}

.subpanel-head,
.form-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
}

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

.client-meta-grid div {
  background: #fff;
  padding: 12px;
}

.client-fields {
  margin-top: 0;
}

.checkline {
  display: inline-flex;
  align-items: center;
  gap: 9px;
  min-height: 40px;
  color: var(--ink);
}

.checkline input {
  width: 16px;
  height: 16px;
  accent-color: var(--brand);
}

.kv {
  display: grid;
  grid-template-columns: 92px minmax(0, 1fr);
  gap: 10px 12px;
  margin-top: 20px;
}

.compact-kv {
  margin-top: 0;
}

.kv dt {
  color: var(--muted);
  font-weight: 740;
}

.kv dd {
  margin: 0;
  overflow-wrap: anywhere;
}

.detail-cell {
  max-width: 360px;
  overflow-wrap: anywhere;
}

.extra-log-row {
  display: none;
}

.extra-log-row.show {
  display: table-row;
}

#toggle-logs[hidden] {
  display: none;
}

.empty-row td {
  color: var(--muted);
  text-align: center;
  padding: 28px 14px;
}

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

@media (max-width: 980px) {
  .auth-page,
  .admin-login-page,
  .workbench-grid {
    grid-template-columns: 1fr;
  }

  .auth-page {
    align-items: start;
    gap: 22px;
    min-height: auto;
  }

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

@media (max-width: 720px) {
  .shell {
    width: min(100% - 20px, 1280px);
    padding: 16px 0 28px;
  }

  .panel {
    padding: 16px;
  }

  .panel.narrow {
    margin: 18px auto;
  }

  h1 {
    font-size: 28px;
  }

  .auth-summary,
  .stats-grid,
  .client-meta-grid,
  .grid-form {
    grid-template-columns: 1fr;
  }

  .admin-header,
  .section-heading,
  .subpanel-head,
  .form-footer {
    align-items: stretch;
    flex-direction: column;
  }

  .admin-header .button,
  .form-footer .button,
  .compact-form .button {
    width: 100%;
  }

  .secret-box code {
    font-size: 17px;
  }

  .email-combo {
    grid-template-columns: 1fr;
  }

  .email-combo > span {
    min-height: 40px;
    border-left: 0;
    border-top: 1px solid var(--line-strong);
  }

  th,
  td {
    padding: 11px 12px;
  }

  .data-table {
    min-width: 760px;
  }

  .log-table {
    min-width: 820px;
  }
}
