:root {
  --bg: #f3efe6;
  --bg-accent: #e7e0d2;
  --surface: #fffcf7;
  --ink: #1c1915;
  --muted: #6b645a;
  --line: #d9d0c2;
  --accent: #0f6b5c;
  --accent-ink: #fff;
  --danger: #9b2c2c;
  --warn: #9a6b12;
  --ok: #1f7a3f;
  --info: #2a5f8f;
  --shadow: 0 18px 50px rgba(28, 25, 21, 0.08);
  --radius: 14px;
  --font: "Source Sans 3", "Segoe UI", sans-serif;
  --mono: "IBM Plex Mono", ui-monospace, monospace;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  font-family: var(--font);
  color: var(--ink);
  background:
    radial-gradient(1200px 500px at 10% -10%, #dfece7 0%, transparent 55%),
    radial-gradient(900px 400px at 100% 0%, #efe4cf 0%, transparent 50%),
    var(--bg);
}

.hidden { display: none !important; }
.muted { color: var(--muted); }
.eyebrow {
  margin: 0 0 0.35rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  font-size: 0.72rem;
  font-weight: 600;
  color: var(--accent);
}
h1, h2, h3 { margin: 0; font-weight: 700; letter-spacing: -0.02em; }
h1 { font-size: 1.75rem; }
h2 { font-size: 1.15rem; margin-bottom: 0.75rem; }
h3 { font-size: 0.95rem; margin: 1rem 0 0.5rem; }
code, .mono { font-family: var(--mono); font-size: 0.85em; }

.login-view {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 1.5rem;
}
.login-panel {
  width: min(420px, 100%);
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: calc(var(--radius) + 4px);
  box-shadow: var(--shadow);
  padding: 2rem;
}
.login-panel .lede {
  color: var(--muted);
  margin: 0.5rem 0 1.5rem;
  line-height: 1.45;
}
.login-panel label {
  display: grid;
  gap: 0.35rem;
  margin-bottom: 0.9rem;
  font-size: 0.9rem;
  font-weight: 600;
}
.login-panel input, .create-form input {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 0.7rem 0.85rem;
  font: inherit;
  background: #fff;
  color: var(--ink);
}
.login-panel input:focus, .create-form input:focus {
  outline: 2px solid rgba(15, 107, 92, 0.35);
  border-color: var(--accent);
}
.form-error {
  margin: 0.85rem 0 0;
  color: var(--danger);
  font-size: 0.9rem;
}

.app-view {
  width: min(1200px, calc(100% - 2rem));
  margin: 0 auto;
  padding: 1.5rem 0 3rem;
}
.topbar {
  display: flex;
  justify-content: space-between;
  gap: 1rem;
  align-items: flex-start;
  margin-bottom: 1.25rem;
}
.topbar-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  align-items: center;
}

.stats {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 0.75rem;
  margin-bottom: 1rem;
}
.stat {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 1rem 1.1rem;
}
.stat-value {
  display: block;
  font-size: 1.6rem;
  font-weight: 700;
  letter-spacing: -0.03em;
}
.stat-label {
  color: var(--muted);
  font-size: 0.85rem;
}

.toolbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 1rem;
  margin-bottom: 0.85rem;
  flex-wrap: wrap;
}
.create-form {
  display: flex;
  gap: 0.5rem;
  flex-wrap: wrap;
}
.create-form input { width: min(280px, 100%); }
.live.ok { color: var(--ok); font-weight: 600; }

.layout {
  display: grid;
  grid-template-columns: minmax(0, 1.6fr) minmax(280px, 0.9fr);
  gap: 1rem;
  align-items: start;
}
.sessions-panel, .detail-panel {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}
.sessions-panel { overflow: hidden; }
.detail-panel { padding: 1.1rem 1.2rem 1.3rem; min-height: 320px; }

.table-wrap { overflow-x: auto; }
table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.92rem;
}
th, td {
  text-align: left;
  padding: 0.85rem 0.9rem;
  border-bottom: 1px solid var(--line);
  vertical-align: middle;
}
th {
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--muted);
  background: var(--bg-accent);
}
tr.selected { background: #eef6f3; }
tr:hover { background: #f7f3eb; }
.session-id {
  font-family: var(--mono);
  font-size: 0.78rem;
  word-break: break-all;
}

.badge {
  display: inline-flex;
  align-items: center;
  padding: 0.2rem 0.55rem;
  border-radius: 999px;
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.03em;
  border: 1px solid transparent;
}
.badge-CONNECTED { background: #e5f6ea; color: var(--ok); border-color: #b9e2c6; }
.badge-CONNECTING { background: #eef4fa; color: var(--info); border-color: #c5d8ea; }
.badge-QR_REQUIRED { background: #fff5df; color: var(--warn); border-color: #edd39a; }
.badge-PAIRING_REQUIRED { background: #fff5df; color: var(--warn); border-color: #edd39a; }
.badge-DISCONNECTED { background: #f1efe9; color: var(--muted); border-color: var(--line); }
.badge-ERROR { background: #fdecec; color: var(--danger); border-color: #efc0c0; }

.actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
}

.btn {
  appearance: none;
  border: 1px solid var(--line);
  background: #fff;
  color: var(--ink);
  border-radius: 10px;
  padding: 0.55rem 0.9rem;
  font: inherit;
  font-weight: 600;
  cursor: pointer;
}
.btn:hover { background: var(--bg-accent); }
.btn:disabled { opacity: 0.55; cursor: not-allowed; }
.btn-primary {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--accent-ink);
}
.btn-primary:hover { filter: brightness(1.05); background: var(--accent); }
.btn-ghost { background: transparent; }
.btn-tiny {
  padding: 0.2rem 0.45rem;
  font-size: 0.75rem;
  margin-left: 0.35rem;
}
.btn-danger { color: var(--danger); border-color: #e2b4b4; }
.btn-warn { color: var(--warn); border-color: #e5cb8f; }

.detail-meta p { margin: 0.4rem 0; }
.qr-box {
  margin-top: 1rem;
  padding: 0.85rem;
  border: 1px dashed var(--line);
  border-radius: 12px;
  text-align: center;
  background: #fff;
}
.qr-box img {
  width: min(220px, 100%);
  height: auto;
  margin-top: 0.5rem;
}
.error-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  gap: 0.5rem;
  max-height: 280px;
  overflow: auto;
}
.error-list li {
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 0.55rem 0.7rem;
  background: #fff;
  font-size: 0.82rem;
}
.error-list .code {
  font-family: var(--mono);
  font-weight: 600;
  color: var(--danger);
}
.error-list time {
  display: block;
  color: var(--muted);
  font-size: 0.75rem;
  margin-bottom: 0.2rem;
}

.toast {
  position: fixed;
  right: 1rem;
  bottom: 1rem;
  background: var(--ink);
  color: #fff;
  padding: 0.75rem 1rem;
  border-radius: 12px;
  box-shadow: var(--shadow);
  max-width: min(360px, calc(100% - 2rem));
  z-index: 50;
}

@media (max-width: 900px) {
  .stats { grid-template-columns: repeat(2, 1fr); }
  .layout { grid-template-columns: 1fr; }
  .topbar { flex-direction: column; }
}
