:root {
  color-scheme: light;
  --surface-1: #fcfcfb;
  --page: #f9f9f7;
  --text-primary: #0b0b0b;
  --text-secondary: #52514e;
  --text-muted: #898781;
  --gridline: #e1e0d9;
  --border: rgba(11, 11, 11, 0.1);
  --series-1: #2a78d6;

  --status-good: #0ca30c;
  --status-warning: #fab219;
  --status-serious: #ec835a;
  --status-critical: #d03b3b;
}

@media (prefers-color-scheme: dark) {
  :root:where(:not([data-theme='light'])) {
    color-scheme: dark;
    --surface-1: #1a1a19;
    --page: #0d0d0d;
    --text-primary: #ffffff;
    --text-secondary: #c3c2b7;
    --text-muted: #898781;
    --gridline: #2c2c2a;
    --border: rgba(255, 255, 255, 0.1);
    --series-1: #3987e5;

    --status-good: #0ca30c;
    --status-warning: #fab219;
    --status-serious: #ec835a;
    --status-critical: #e66767;
  }
}

:root[data-theme='dark'] {
  color-scheme: dark;
  --surface-1: #1a1a19;
  --page: #0d0d0d;
  --text-primary: #ffffff;
  --text-secondary: #c3c2b7;
  --text-muted: #898781;
  --gridline: #2c2c2a;
  --border: rgba(255, 255, 255, 0.1);
  --series-1: #3987e5;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--page);
  color: var(--text-primary);
  font-family: system-ui, -apple-system, 'Segoe UI', sans-serif;
  -webkit-font-smoothing: antialiased;
}

[hidden] {
  display: none !important;
}

.wrap {
  max-width: 860px;
  margin: 0 auto;
  padding: 24px 16px 64px;
}

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

.topbar h1 {
  font-size: 18px;
  font-weight: 600;
  margin: 0;
}

.btn {
  appearance: none;
  border: 1px solid var(--border);
  background: var(--surface-1);
  color: var(--text-primary);
  border-radius: 8px;
  padding: 9px 14px;
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
}

.btn:hover {
  border-color: var(--text-muted);
}

.btn-primary {
  background: var(--series-1);
  border-color: var(--series-1);
  color: #ffffff;
}

.btn-danger {
  background: transparent;
  border-color: var(--status-critical);
  color: var(--status-critical);
}

.btn:disabled {
  opacity: 0.5;
  cursor: default;
}

.card {
  background: var(--surface-1);
  border: 1px solid var(--gridline);
  border-radius: 12px;
  padding: 20px;
  margin-bottom: 16px;
}

.card h2 {
  font-size: 14px;
  font-weight: 600;
  margin: 0 0 14px;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

.status-row {
  display: flex;
  align-items: center;
  gap: 10px;
}

.status-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  flex-shrink: 0;
}

.status-dot.open {
  background: var(--status-good);
}
.status-dot.qr {
  background: var(--status-warning);
}
.status-dot.close,
.status-dot.connecting {
  background: var(--status-critical);
}

.status-label {
  font-size: 15px;
  font-weight: 600;
}

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

.stat-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 12px;
  margin-top: 16px;
}

.stat-tile {
  background: var(--page);
  border: 1px solid var(--gridline);
  border-radius: 10px;
  padding: 12px 14px;
}

.stat-tile .value {
  font-size: 24px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}

.stat-tile .label {
  font-size: 12px;
  color: var(--text-muted);
  margin-top: 2px;
}

.qr-box {
  margin-top: 16px;
  text-align: center;
}

.qr-box img {
  width: 220px;
  height: 220px;
  border-radius: 8px;
  border: 1px solid var(--gridline);
  background: #fff;
  padding: 8px;
}

.qr-box p {
  font-size: 13px;
  color: var(--text-secondary);
  margin-top: 10px;
}

.field {
  margin-bottom: 14px;
}

.field label {
  display: block;
  font-size: 13px;
  font-weight: 500;
  margin-bottom: 6px;
  color: var(--text-secondary);
}

.field input[type='text'],
.field input[type='password'],
.field select {
  width: 100%;
  padding: 9px 10px;
  border-radius: 8px;
  border: 1px solid var(--gridline);
  background: var(--page);
  color: var(--text-primary);
  font-size: 14px;
}

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

.toggle-row .desc {
  font-size: 12px;
  color: var(--text-muted);
  margin-top: 2px;
}

.switch {
  position: relative;
  width: 42px;
  height: 24px;
  flex-shrink: 0;
}

.switch input {
  opacity: 0;
  width: 0;
  height: 0;
}

.switch .track {
  position: absolute;
  inset: 0;
  background: var(--gridline);
  border-radius: 999px;
  transition: background 0.15s;
  cursor: pointer;
}

.switch .track::before {
  content: '';
  position: absolute;
  width: 18px;
  height: 18px;
  left: 3px;
  top: 3px;
  background: #fff;
  border-radius: 50%;
  transition: transform 0.15s;
}

.switch input:checked + .track {
  background: var(--series-1);
}

.switch input:checked + .track::before {
  transform: translateX(18px);
}

.form-actions {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-top: 4px;
}

.msg {
  font-size: 13px;
  margin-top: 8px;
}

.msg.error {
  color: var(--status-critical);
}

.msg.success {
  color: var(--status-good);
}

.event-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
  max-height: 320px;
  overflow-y: auto;
}

.event-item {
  display: flex;
  gap: 10px;
  padding: 8px 0;
  border-bottom: 1px solid var(--gridline);
  font-size: 13px;
}

.event-item:last-child {
  border-bottom: none;
}

.event-badge {
  flex-shrink: 0;
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  padding: 2px 6px;
  border-radius: 4px;
  height: fit-content;
  white-space: nowrap;
}

.event-badge.transcription {
  color: var(--status-good);
  background: color-mix(in srgb, var(--status-good) 15%, transparent);
}
.event-badge.error {
  color: var(--status-critical);
  background: color-mix(in srgb, var(--status-critical) 15%, transparent);
}
.event-badge.connection {
  color: var(--series-1);
  background: color-mix(in srgb, var(--series-1) 15%, transparent);
}
.event-badge.settings {
  color: var(--text-secondary);
  background: var(--page);
}

.event-text {
  flex: 1;
  min-width: 0;
  word-break: break-word;
}

.event-time {
  color: var(--text-muted);
  font-size: 11px;
  margin-top: 2px;
}

.empty {
  color: var(--text-muted);
  font-size: 13px;
}

/* Login */
.login-wrap {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
}

.login-card {
  width: 100%;
  max-width: 360px;
  background: var(--surface-1);
  border: 1px solid var(--gridline);
  border-radius: 14px;
  padding: 28px 24px;
}

.login-card h1 {
  font-size: 18px;
  margin: 0 0 4px;
}

.login-card .subtitle {
  font-size: 13px;
  color: var(--text-muted);
  margin: 0 0 20px;
}

.login-card .btn-primary {
  width: 100%;
}
