:root {
  --bg: #f8fafc;
  --surface: #ffffff;
  --surface-subtle: #f1f5f9;
  --border: #e2e8f0;
  --text: #0f172a;
  --text-muted: #475569;
  --text-faint: #64748b;
  --accent: #16a34a;
  --accent-hover: #15803d;
  --accent-contrast: #ffffff;
  --secondary-bg: #0f172a;
  --secondary-hover: #1e293b;
  --danger: #dc2626;
  --warning: #d97706;
  --radius-sm: 6px;
  --radius-md: 10px;
  --radius-lg: 12px;
  --font-sans: 'Plus Jakarta Sans', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  --font-mono: 'JetBrains Mono', ui-monospace, SFMono-Regular, Menlo, monospace;
}

html.dark {
  --bg: #0b1120;
  --surface: #111827;
  --surface-subtle: #1e293b;
  --border: #1f2937;
  --text: #f1f5f9;
  --text-muted: #94a3b8;
  --text-faint: #94a3b8;
  --accent: #22c55e;
  --accent-hover: #16a34a;
  --accent-contrast: #052e16;
  --secondary-bg: #e2e8f0;
  --secondary-hover: #ffffff;
  --danger: #f87171;
  --warning: #fbbf24;
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-sans);
  font-size: 14px;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
}

.hidden {
  display: none !important;
}

.mono {
  font-family: var(--font-mono);
  font-variant-numeric: tabular-nums;
}

/* Auth Gate */
.auth-gate {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px 16px;
}

.auth-card {
  width: 100%;
  max-width: 420px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 28px 24px;
}

.auth-brand {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  margin-bottom: 20px;
}

.brand-mark {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 34px;
  height: 34px;
  border-radius: 8px;
  background: var(--accent);
  color: var(--accent-contrast);
  font-weight: 700;
  font-size: 15px;
  flex-shrink: 0;
}

.auth-title {
  margin: 0;
  font-size: 19px;
  font-weight: 700;
  letter-spacing: -0.02em;
  text-wrap: balance;
}

.auth-subtitle {
  margin: 4px 0 0;
  font-size: 13px;
  color: var(--text-muted);
}

/* App Shell */
.app-shell {
  display: flex;
  min-height: 100vh;
}

.sidebar {
  width: 256px;
  flex-shrink: 0;
  background: var(--surface);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  position: sticky;
  top: 0;
  height: 100vh;
}

.sidebar-head {
  height: 60px;
  padding: 0 18px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.sidebar-brand {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}

.brand-name {
  font-weight: 700;
  font-size: 15px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.sidebar-nav {
  padding: 14px 10px;
  display: flex;
  flex-direction: column;
  gap: 4px;
  flex: 1;
}

.nav-item {
  width: 100%;
  text-align: left;
  background: transparent;
  border: 0;
  border-radius: var(--radius-sm);
  padding: 10px 12px;
  font-family: inherit;
  font-size: 13.5px;
  font-weight: 500;
  color: var(--text-muted);
  cursor: pointer;
  white-space: nowrap;
  transition: background-color 150ms ease, color 150ms ease;
}

.nav-item:hover {
  background: var(--surface-subtle);
  color: var(--text);
}

.nav-item.is-active {
  background: var(--surface-subtle);
  color: var(--text);
  font-weight: 700;
}

.sidebar-foot {
  padding: 14px 16px;
  border-top: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.meta-line {
  font-size: 12px;
  color: var(--text-faint);
}

.sidebar-foot-actions {
  display: flex;
  gap: 8px;
}

/* Workspace */
.workspace {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
}

.topbar {
  height: 60px;
  padding: 0 24px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  position: sticky;
  top: 0;
  z-index: 20;
}

.topbar-left {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
}

.breadcrumb {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13.5px;
  color: var(--text-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.breadcrumb strong {
  color: var(--text);
  font-weight: 600;
}

.topbar-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
}

.main-content {
  width: 100%;
  max-width: 1200px;
  margin: 0 auto;
  padding: 24px;
  display: flex;
  flex-direction: column;
  gap: 24px;
}

/* Toast Banner */
.toast-bar {
  margin: 16px 24px 0;
  padding: 11px 14px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--surface);
  font-size: 13px;
  font-weight: 500;
}

.toast-bar.is-error {
  border-color: var(--danger);
  color: var(--danger);
}

.toast-bar.is-ok {
  border-color: var(--accent);
  color: var(--accent-hover);
}

html.dark .toast-bar.is-ok {
  color: var(--accent);
}

/* Metric Strip (flat 1px bordered grid, no nested shadows) */
.metric-strip {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  overflow: hidden;
}

.metric-cell {
  padding: 14px 18px;
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.metric-cell:last-child {
  border-right: 0;
}

.metric-label {
  font-size: 12px;
  color: var(--text-faint);
  font-weight: 500;
}

.metric-value {
  font-size: 18px;
  font-weight: 700;
  color: var(--text);
}

/* Sections & Surfaces */
.section-head {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 16px;
}

.section-title {
  margin: 0;
  font-size: 20px;
  font-weight: 700;
  letter-spacing: -0.02em;
  text-wrap: balance;
}

.section-desc {
  margin: 4px 0 0;
  font-size: 13.5px;
  color: var(--text-muted);
}

.split-layout {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 20px;
  align-items: start;
}

.panel-surface {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 16px;
  min-width: 0;
}

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

.panel-title {
  margin: 0;
  font-size: 15.5px;
  font-weight: 700;
}

.sub-title {
  margin: 0;
  font-size: 14px;
  font-weight: 600;
}

.meta-inline {
  font-size: 12px;
  color: var(--text-faint);
}

.divider {
  height: 1px;
  background: var(--border);
  width: 100%;
}

/* Forms & Controls */
.stack-md {
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.stack-sm {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

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

.field {
  display: flex;
  flex-direction: column;
  gap: 5px;
  min-width: 0;
}

.field label {
  font-size: 12.5px;
  font-weight: 600;
  color: var(--text-muted);
}

input[type="text"],
input[type="password"],
input[type="tel"],
input[type="number"],
input[type="datetime-local"],
select,
textarea {
  width: 100%;
  min-height: 40px;
  padding: 8px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg);
  color: var(--text);
  font-family: inherit;
  font-size: 13.5px;
  outline: none;
  transition: border-color 150ms ease;
}

textarea {
  resize: vertical;
  min-height: 76px;
}

input:focus-visible,
select:focus-visible,
textarea:focus-visible,
button:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.input-copy-row {
  display: flex;
  gap: 8px;
}

.helper-text {
  margin: 0;
  font-size: 12.5px;
  color: var(--text-muted);
}

.form-error {
  margin: 0;
  font-size: 12.5px;
  font-weight: 600;
  color: var(--danger);
}

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-height: 40px;
  padding: 8px 16px;
  border-radius: var(--radius-sm);
  border: 1px solid transparent;
  font-family: inherit;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
  flex-shrink: 0;
  transition: background-color 150ms ease, color 150ms ease, border-color 150ms ease;
}

.btn-sm {
  min-height: 36px;
  padding: 6px 12px;
  font-size: 12.5px;
}

.btn-full {
  width: 100%;
}

.btn-primary {
  background: var(--accent);
  color: var(--accent-contrast);
}

.btn-primary:hover {
  background: var(--accent-hover);
}

.btn-secondary {
  background: var(--secondary-bg);
  color: var(--surface);
}

.btn-secondary:hover {
  background: var(--secondary-hover);
}

.btn-ghost {
  background: transparent;
  border-color: var(--border);
  color: var(--text);
}

.btn-ghost:hover {
  background: var(--surface-subtle);
}

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

.btn-danger-ghost:hover {
  background: var(--surface-subtle);
}

.icon-btn {
  min-width: 40px;
  min-height: 40px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--text);
  font-size: 16px;
  cursor: pointer;
}

/* Segmented Control */
.segmented-control {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 4px;
  padding: 4px;
  background: var(--surface-subtle);
  border-radius: var(--radius-sm);
}

.seg-btn {
  min-height: 36px;
  border: 0;
  border-radius: 4px;
  background: transparent;
  color: var(--text-muted);
  font-family: inherit;
  font-size: 12.5px;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
}

.seg-btn.is-active {
  background: var(--surface);
  color: var(--text);
}

/* Session Rows (Flat hairline separated list, zero nested cards) */
.session-list,
.item-list {
  display: flex;
  flex-direction: column;
}

.list-row {
  padding: 14px 0;
  border-bottom: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.list-row:first-child {
  padding-top: 2px;
}

.list-row:last-child {
  border-bottom: 0;
  padding-bottom: 2px;
}

.row-top {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 10px;
}

.row-title {
  font-size: 14px;
  font-weight: 700;
  color: var(--text);
}

.row-meta {
  font-size: 12px;
  color: var(--text-faint);
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  align-items: center;
}

.row-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 2px;
}

.status-text-ok {
  color: var(--accent-hover);
  font-weight: 700;
  font-size: 12px;
}

html.dark .status-text-ok {
  color: var(--accent);
}

.status-text-warn {
  color: var(--warning);
  font-weight: 700;
  font-size: 12px;
}

.status-text-off {
  color: var(--text-faint);
  font-weight: 600;
  font-size: 12px;
}

/* Dedicated Pairing Output Box */
.pairing-output {
  padding: 18px;
  border: 1px dashed var(--border);
  border-radius: var(--radius-md);
  background: var(--bg);
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  gap: 12px;
}

.pairing-code-display {
  font-family: var(--font-mono);
  font-size: 28px;
  font-weight: 700;
  letter-spacing: 0.14em;
  color: var(--text);
  padding: 10px 18px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface);
}

.qr-image {
  width: 220px;
  height: 220px;
  background: #ffffff;
  padding: 8px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  object-fit: contain;
}

.steps-list {
  margin: 0;
  padding-left: 18px;
  font-size: 12.5px;
  color: var(--text-muted);
  display: flex;
  flex-direction: column;
  gap: 4px;
}

/* Key-Value List & Result Box */
.kv-list {
  margin: 0;
  display: flex;
  flex-direction: column;
}

.kv-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 9px 0;
  border-bottom: 1px solid var(--border);
  font-size: 13px;
}

.kv-row:last-child {
  border-bottom: 0;
}

.kv-row dt {
  color: var(--text-muted);
}

.kv-row dd {
  margin: 0;
  font-weight: 600;
  text-align: right;
}

.result-box {
  padding: 12px 14px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--bg);
  font-size: 13px;
}

/* High-Density Table */
.table-wrap {
  width: 100%;
  overflow-x: auto;
}

.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 12.5px;
}

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

.data-table th {
  color: var(--text-faint);
  font-weight: 600;
}

.data-table th.num,
.data-table td.num {
  text-align: right;
}

/* Mobile Responsive */
.mobile-only {
  display: none;
}

@media (max-width: 960px) {
  .mobile-only {
    display: inline-flex;
    align-items: center;
    justify-content: center;
  }

  .sidebar {
    position: fixed;
    left: 0;
    top: 0;
    bottom: 0;
    z-index: 40;
    transform: translateX(-100%);
    transition: transform 200ms ease;
  }

  .sidebar.is-open {
    transform: translateX(0);
  }

  .sidebar-backdrop {
    position: fixed;
    inset: 0;
    background: rgba(15, 23, 42, 0.45);
    z-index: 30;
  }

  .topbar {
    padding: 0 14px;
    gap: 10px;
  }

  .breadcrumb > span {
    display: none;
  }

  .breadcrumb strong {
    font-size: 14px;
  }

  #refresh-all-btn {
    display: none;
  }

  .main-content {
    padding: 16px 14px 28px;
    gap: 18px;
  }

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

  .metric-cell:nth-child(2) {
    border-right: 0;
  }

  .metric-cell:nth-child(1),
  .metric-cell:nth-child(2) {
    border-bottom: 1px solid var(--border);
  }

  .split-layout,
  .form-grid-2 {
    grid-template-columns: 1fr;
  }

  .toast-bar {
    margin: 12px 14px 0;
  }
}
