/* ==========================================================================
   Dashboard stylesheet (MQTT GPS Tracking — Ingestion Console).

   Loaded by frontend/index.html and served by GET /dashboard.css.
   Dark theme by default; `html[data-theme="light"]` overrides the
   variables. Rule order is significant — keep new rules close to the
   section they belong to.
   ========================================================================== */


/* ========================================
   CSS VARIABLES
   ======================================== */

:root {
  --bg: #0c1113;
  --panel: #12191c;
  --panel-2: #182124;
  --panel-3: #1e292d;
  --border: #263135;
  --border-soft: #1c2528;
  --text: #e8edee;
  --text-dim: #8fa0a5;
  --text-faint: #5c6d72;
  --accent: #2fd6c4;
  --accent-dim: rgba(47, 214, 196, .12);
  --accent-dim2: rgba(47, 214, 196, .22);
  --accent-ink: #04211d;
  --amber: #e6ab3f;
  --amber-dim: rgba(230, 171, 63, .12);
  --red: #ee5f57;
  --red-dim: rgba(238, 95, 87, .12);
  --blue: #6fa9dc;
  --blue-dim: rgba(111, 169, 220, .12);
  --radius: 8px;
  --radius-sm: 5px;
  --topbar-bg: rgba(18, 25, 28, .92);
  --console-bg: #0a0f11;
  --console-line: rgba(255, 255, 255, .03);
  --auth-hero-bg: radial-gradient(circle at 78% 50%, #132123 0%, #0e1517 55%, #0c1113 100%);

  font-size: 15px;
  color-scheme: dark;
}

/* ---------- light theme (toggled via the theme buttons) ---------- */

html[data-theme="light"] {
  --bg: #eef3f2;
  --panel: #ffffff;
  --panel-2: #f0f5f4;
  --panel-3: #e3ebe9;
  --border: #d5dedc;
  --border-soft: #e4eae9;
  --text: #13211f;
  --text-dim: #41605a;
  --text-faint: #7e9590;
  --accent: #0d8d7f;
  --accent-dim: rgba(13, 141, 127, .10);
  --accent-dim2: rgba(13, 141, 127, .28);
  --accent-ink: #ffffff;
  --amber: #96690f;
  --amber-dim: rgba(150, 105, 15, .12);
  --red: #c2433a;
  --red-dim: rgba(194, 67, 58, .10);
  --blue: #2e6da4;
  --blue-dim: rgba(46, 109, 164, .12);
  --topbar-bg: rgba(255, 255, 255, .92);
  --console-bg: #f7faf9;
  --console-line: rgba(19, 33, 31, .07);
  --auth-hero-bg: radial-gradient(circle at 78% 50%, #d9eae7 0%, #eef3f2 60%, #e2ebe9 100%);

  color-scheme: light;
}


/* ========================================
   RESET / BASE
   ======================================== */

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

html,
body {
  height: 100%;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: 'IBM Plex Sans', system-ui, sans-serif;
  -webkit-font-smoothing: antialiased;
}

code,
.mono,
.mono * {
  font-family: 'IBM Plex Mono', ui-monospace, monospace;
}

*:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
  border-radius: 3px;
}

@media (prefers-reduced-motion: reduce) {
  * {
    animation-duration: .001ms !important;
    transition-duration: .001ms !important;
  }
}


/* ========================================
   LAYOUT SHELL (sidebar + connection list)
   ======================================== */

.app {
  display: grid;
  grid-template-columns: 264px 1fr;
  min-height: 100vh;
}

.sidebar {
  background: var(--panel);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  padding: 18px 14px 14px;
  position: sticky;
  top: 0;
  height: 100vh;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 2px 4px 18px;
  border-bottom: 1px solid var(--border-soft);
  margin-bottom: 16px;
}

.brand-mark {
  width: 34px;
  height: 34px;
  border-radius: 9px;
  flex: none;
  background: radial-gradient(circle at 30% 30%, var(--accent), #17847a 75%);
  position: relative;
  display: grid;
  place-items: center;
}

.brand-mark::after {
  content: '';
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--accent-ink);
  box-shadow: 0 0 0 2px rgba(4, 33, 29, .35);
}

.brand-text h1 {
  font-size: 14.5px;
  margin: 0;
  font-weight: 600;
  letter-spacing: .1px;
}

.brand-text p {
  margin: 1px 0 0;
  font-size: 11.5px;
  color: var(--text-faint);
}

.side-block {
  margin-bottom: 20px;
}

.side-label {
  font-size: 11.5px;
  color: var(--text-faint);
  font-weight: 500;
  margin: 0 4px 8px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.search-input {
  width: 100%;
  background: var(--panel-2);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: var(--radius-sm);
  padding: 8px 10px;
  font-size: 13px;
  font-family: inherit;
}

.search-input::placeholder {
  color: var(--text-faint);
}

.conn-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-top: 8px;
}

.conn-item {
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 9px 10px;
  border-radius: var(--radius-sm);
  border: 1px solid transparent;
  cursor: pointer;
}

.conn-item:hover {
  background: var(--panel-2);
}

.conn-item.active {
  background: var(--accent-dim);
  border-color: var(--accent-dim2);
}

/* Per-broker connect/disconnect action inside a connection row. */
.conn-act {
  flex: none;
  margin-left: auto;
  font-size: 11px;
  font-weight: 600;
  padding: 4px 10px;
  border-radius: 5px;
  cursor: pointer;
  font-family: inherit;
  white-space: nowrap;
  border: 1px solid var(--accent-dim2);
  background: var(--accent-dim);
  color: var(--accent);
}

.conn-act:hover {
  filter: brightness(1.12);
}

.conn-act.disconnect {
  border-color: rgba(238, 95, 87, .25);
  background: var(--red-dim);
  color: var(--red);
}

.conn-act:disabled {
  opacity: .45;
  cursor: wait;
}

/* Compact 3-dot actions menu per connection row. */
.conn-menu-btn {
  flex: none;
  width: 26px;
  height: 26px;
  border-radius: 6px;
  cursor: pointer;
  border: 1px solid transparent;
  background: none;
  color: var(--text-dim);
  font-size: 15px;
  line-height: 1;
  letter-spacing: 1px;
  font-family: inherit;
  padding: 0;
}

.conn-menu-btn:hover {
  background: var(--panel-2);
  color: var(--text);
}

.conn-menu-btn.open {
  background: var(--panel-2);
  color: var(--text);
  border-color: var(--border-soft);
}

.conn-menu {
  position: fixed;
  z-index: 1200;
  min-width: 140px;
  padding: 4px;
  background: var(--panel);
  border: 1px solid var(--border-soft);
  border-radius: 8px;
  box-shadow: 0 10px 30px rgba(0, 0, 0, .35);
  display: flex;
  flex-direction: column;
  gap: 1px;
}

.conn-menu-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 7px 10px;
  border-radius: 5px;
  background: none;
  border: none;
  color: var(--text);
  font-size: 13px;
  font-family: inherit;
  cursor: pointer;
  text-align: left;
  width: 100%;
}

.conn-menu-item:hover {
  background: var(--panel-2);
}

.conn-menu-item.del {
  color: var(--red);
}

.conn-menu-item.del:hover {
  background: var(--red-dim);
}

/* Full-page boot loader: hidden only by real initialization state. */
.boot-spinner {
  width: 26px;
  height: 26px;
  border-radius: 50%;
  border: 2.5px solid var(--border-soft);
  border-top-color: var(--accent);
  animation: bootSpin .8s linear infinite;
}

@keyframes bootSpin {
  to {
    transform: rotate(360deg);
  }
}

#bootLoader.done {
  opacity: 0;
  transition: opacity .25s ease;
  pointer-events: none;
}

.dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  flex: none;
  background: var(--text-faint);
}

.dot.on {
  background: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-dim);
}

.conn-meta {
  min-width: 0;
}

.conn-meta .name {
  font-size: 13.5px;
  font-weight: 500;
  line-height: 1.3;
}

.conn-item.active .name {
  color: var(--accent);
}

.conn-meta .host {
  font-size: 11px;
  color: var(--text-faint);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  font-family: 'IBM Plex Mono', monospace;
}


/* ========================================
   NAVIGATION (sidebar tabs)
   ======================================== */

.nav {
  display: flex;
  flex-direction: column;
  gap: 2px;
  margin-top: auto;
  padding-top: 10px;
  border-top: 1px solid var(--border-soft);
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 10px;
  border-radius: var(--radius-sm);
  color: var(--text-dim);
  font-size: 13.5px;
  font-weight: 500;
  cursor: pointer;
  border: 1px solid transparent;
  background: none;
  text-align: left;
  width: 100%;
  font-family: inherit;
}

.nav-item svg {
  flex: none;
  opacity: .8;
}

.nav-item:hover {
  background: var(--panel-2);
  color: var(--text);
}

.nav-item.active {
  background: var(--panel-3);
  color: var(--text);
  border-color: var(--border);
}

.nav-item.active svg {
  color: var(--accent);
  opacity: 1;
}

.nav-count {
  margin-left: auto;
  font-size: 11px;
  color: var(--text-faint);
  font-family: 'IBM Plex Mono', monospace;
}

.btn-add {
  margin-top: 14px;
  width: 100%;
  padding: 10px;
  border-radius: var(--radius-sm);
  background: transparent;
  border: 1px dashed var(--border);
  color: var(--text-dim);
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  font-family: inherit;
}

.btn-add:hover {
  border-color: var(--accent-dim2);
  color: var(--accent);
  background: var(--accent-dim);
}


/* ========================================
   TOPBAR (main column header + status pills)
   ======================================== */

.main {
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  background: var(--topbar-bg);
  backdrop-filter: blur(6px);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: 14px;
  flex-wrap: wrap;
  row-gap: 10px;
  padding: 14px 26px;
}

.menu-btn {
  display: none;
  background: none;
  border: 1px solid var(--border);
  color: var(--text-dim);
  border-radius: var(--radius-sm);
  width: 34px;
  height: 34px;
  align-items: center;
  justify-content: center;
  cursor: pointer;
}

.topbar h2 {
  font-size: 15.5px;
  margin: 0;
  font-weight: 600;
}

.topbar .sub {
  font-size: 11.5px;
  color: var(--text-faint);
  margin-top: 1px;
}

.pills {
  display: flex;
  gap: 8px;
  margin-left: auto;
  align-items: center;
  flex-wrap: wrap;
}

.pill {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 5px 10px 5px 8px;
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-radius: 999px;
  font-size: 11.5px;
  color: var(--text-dim);
  font-family: 'IBM Plex Mono', monospace;
}

.pill .dot {
  width: 6px;
  height: 6px;
}

/* Theme toggle: same pill footprint as the status indicators. One instance
   lives in the topbar, another on the login/register screens. */
.theme-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  border-radius: 999px;
  flex: none;
  background: var(--panel-2);
  border: 1px solid var(--border);
  color: var(--text-dim);
  cursor: pointer;
  font-family: inherit;
}

.theme-btn:hover {
  color: var(--accent);
  border-color: var(--accent-dim2);
}

.theme-btn svg {
  display: block;
}

.theme-btn .icon-sun {
  display: none;
}

html[data-theme="light"] .theme-btn .icon-sun {
  display: block;
}

html[data-theme="light"] .theme-btn .icon-moon {
  display: none;
}

/* Floating instance for the login/register overlay. */
.auth-theme-btn {
  position: fixed;
  top: 16px;
  right: 16px;
  z-index: 210;
}

/* Search-match highlight: visual only, the payload text is untouched. */
.console-line mark.hl,
.live-card mark.hl {
  background: var(--amber-dim);
  color: var(--amber);
  border-radius: 3px;
  padding: 0 2px;
}

html[data-theme="light"] .console-line mark.hl,
html[data-theme="light"] .live-card mark.hl {
  color: #96690f;
}


/* ========================================
   LIVE MESSAGE CARDS (Live Log)
   ======================================== */

.live-card {
  background: var(--console-bg);
  border: 1px solid var(--border-soft);
  border-radius: var(--radius-sm);
  padding: 10px 14px;
  margin-bottom: 10px;
  width: 100%;
  max-width: 100%;
  box-sizing: border-box;
  overflow: hidden;
}

.live-card-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  flex-wrap: wrap;
  font-size: 12px;
  margin-bottom: 8px;
}

.live-topic {
  color: var(--text-dim);
}

.live-topic b {
  color: var(--blue);
  font-weight: 600;
  font-family: 'IBM Plex Mono', monospace;
}

.live-qos {
  color: var(--text-faint);
  font-family: 'IBM Plex Mono', monospace;
  font-size: 11.5px;
}

.live-json {
  margin: 0;
  font-size: 12px;
  line-height: 1.65;
  white-space: pre-wrap;
  overflow-wrap: break-word;
  word-break: normal;
}

.live-card-foot {
  margin-top: 8px;
  font-size: 11.5px;
  color: var(--text-faint);
  font-family: 'IBM Plex Mono', monospace;
}

/* CBOR dual-form blocks inside a live card: one for the encoded hex,
   one for the decoded JSON. Same monospace look as the Live Log. */
.cbor-block {
  margin-top: 8px;
}

.cbor-label {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 11px;
  color: var(--text-faint);
  margin-bottom: 4px;
  text-transform: uppercase;
  letter-spacing: .4px;
}

.cbor-copy {
  background: none;
  border: 1px solid var(--border);
  border-radius: 4px;
  color: var(--text-dim);
  font-size: 10.5px;
  padding: 1px 8px;
  cursor: pointer;
  font-family: inherit;
  text-transform: none;
  letter-spacing: 0;
}

.cbor-copy:hover {
  color: var(--accent);
  border-color: var(--accent-dim2);
}

.live-card.fresh {
  animation: highlight 1.4s ease;
}

/* Signed-in identity chip + logout in the topbar. */
.user-chip {
  display: flex;
  align-items: center;
  gap: 8px;
  padding-left: 8px;
  border-left: 1px solid var(--border);
  margin-left: 4px;
}

.avatar {
  width: 26px;
  height: 26px;
  border-radius: 50%;
  background: var(--panel-3);
  border: 1px solid var(--border);
  display: grid;
  place-items: center;
  font-size: 11px;
  font-weight: 600;
  color: var(--text-dim);
}

.logout {
  font-size: 12.5px;
  color: var(--red);
  cursor: pointer;
  background: none;
  border: none;
  font-family: inherit;
}


/* ========================================
   CONTENT / TABS / PANELS
   ======================================== */

.content {
  padding: 24px 26px 60px;
  max-width: 1240px;
  width: 100%;
  margin: 0 auto;
}

.tab {
  display: none;
}

.tab.active {
  display: block;
  animation: fade .25s ease;
}

@keyframes fade {
  from {
    opacity: 0;
    transform: translateY(4px);
  }

  to {
    opacity: 1;
    transform: none;
  }
}

h3.section-title {
  font-size: 15px;
  font-weight: 600;
  margin: 0 0 3px;
}

p.section-desc {
  font-size: 12.5px;
  color: var(--text-faint);
  margin: 0 0 16px;
}

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

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


/* ========================================
   BUTTONS
   ======================================== */

.btn {
  font-family: inherit;
  font-size: 12.5px;
  font-weight: 600;
  padding: 8px 14px;
  border-radius: var(--radius-sm);
  border: 1px solid transparent;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  white-space: nowrap;
}

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

.btn-primary:hover {
  background: #4fe2d2;
}

.btn-ghost {
  background: var(--panel-2);
  border-color: var(--border);
  color: var(--text-dim);
}

.btn-ghost:hover {
  color: var(--text);
  border-color: #3a464b;
}

.btn-amber {
  background: var(--amber-dim);
  color: var(--amber);
  border-color: rgba(230, 171, 63, .25);
}

.btn-amber:hover {
  background: rgba(230, 171, 63, .2);
}

.btn-red {
  background: var(--red-dim);
  color: var(--red);
  border-color: rgba(238, 95, 87, .25);
}

.btn-red:hover {
  background: rgba(238, 95, 87, .2);
}

.btn-sm {
  padding: 6px 10px;
  font-size: 11.5px;
}

.btn:disabled {
  opacity: .45;
  cursor: not-allowed;
}


/* ========================================
   FORMS
   ======================================== */

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

.field {
  min-width: 0;
}

.input,
select.input,
textarea.input {
  width: 100%;
  background: var(--panel-2);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: var(--radius-sm);
  padding: 9px 11px;
  font-size: 13px;
  font-family: inherit;
}

textarea.input {
  font-family: 'IBM Plex Mono', monospace;
  font-size: 12.5px;
  resize: vertical;
  line-height: 1.6;
}

.input::placeholder {
  color: var(--text-faint);
}

.input:focus,
textarea.input:focus,
select.input:focus {
  border-color: var(--accent-dim2);
}

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

.row-4 {
  grid-template-columns: repeat(4, 1fr);
}

.row-3 {
  grid-template-columns: 2fr 1fr 1fr;
}

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

/* Search-payload row: side-by-side on wide screens, stacked on phones
   (moved out of an inline style so media queries can reach it). */
.search-row {
  grid-template-columns: 1fr auto auto;
  align-items: end;
}

@media (max-width: 640px) {
  .search-row {
    grid-template-columns: 1fr;
  }

  .search-row .btn {
    width: 100%;
    justify-content: center;
  }
}


/* ========================================
   CHIPS (subscription chips)
   ======================================== */

.chip {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 5px 6px 5px 11px;
  background: var(--accent-dim);
  color: var(--accent);
  border: 1px solid var(--accent-dim2);
  border-radius: 999px;
  font-size: 12px;
  font-family: 'IBM Plex Mono', monospace;
}

.chip button {
  background: none;
  border: none;
  color: inherit;
  opacity: .65;
  cursor: pointer;
  display: grid;
  place-items: center;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  font-size: 13px;
}

.chip button:hover {
  opacity: 1;
  background: rgba(0, 0, 0, .15);
}

/* An unsubscribed chip fades out over 2s, then is removed from the DOM. */
.chip.chip-fading {
  animation: chipFadeOut 2s ease forwards;
  pointer-events: none;
}

@keyframes chipFadeOut {
  from {
    opacity: 1;
  }

  to {
    opacity: 0;
  }
}

.chip-row {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  margin-top: 12px;
}


/* ========================================
   TABLES
   ======================================== */

.table-wrap {
  overflow-x: auto;
  border: 1px solid var(--border-soft);
  border-radius: var(--radius-sm);
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}

thead th {
  text-align: left;
  font-size: 11.5px;
  font-weight: 500;
  color: var(--text-faint);
  padding: 10px 14px;
  border-bottom: 1px solid var(--border);
  background: var(--panel-2);
  white-space: nowrap;
}

tbody td {
  padding: 11px 14px;
  border-bottom: 1px solid var(--border-soft);
  vertical-align: middle;
}

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

tbody tr:hover {
  background: var(--panel-2);
}

.topic-tag {
  font-family: 'IBM Plex Mono', monospace;
  font-size: 12px;
  color: var(--blue);
  background: var(--blue-dim);
  padding: 3px 8px;
  border-radius: 5px;
}

/* Long topic names (e.g. multi-level MQTT topics) must not push neighbouring
   columns — ellipsis inside record rows on every viewport. */
.record-head .topic-tag {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  max-width: 100%;
}

.status-live {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 12.5px;
  color: var(--accent);
  font-weight: 500;
}

.status-live .dot {
  background: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-dim);
}


/* ========================================
   KPI CARDS
   ======================================== */

.kpi-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 14px;
  margin-bottom: 20px;
}

.kpi {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px 18px;
  border-top: 2px solid var(--kpi-c, var(--accent));
}

.kpi .label {
  font-size: 12px;
  color: var(--text-faint);
  margin-bottom: 8px;
}

.kpi .value {
  font-family: 'IBM Plex Mono', monospace;
  font-size: 26px;
  font-weight: 600;
  letter-spacing: -.5px;
}

.kpi .value small {
  font-size: 13px;
  color: var(--text-faint);
  font-weight: 500;
  margin-left: 3px;
}

.kpi .delta {
  font-size: 11.5px;
  margin-top: 6px;
  color: var(--text-faint);
}


/* ========================================
   RECORD ROWS (historical records + JSON colors)
   ======================================== */

.record {
  border: 1px solid var(--border-soft);
  border-radius: var(--radius-sm);
  margin-bottom: 10px;
  overflow: hidden;
}

.record-head {
  display: grid;
  grid-template-columns: 70px 90px 1fr 130px 90px 34px;
  gap: 14px;
  align-items: center;
  padding: 11px 14px;
  cursor: pointer;
  font-size: 13px;
}

.record-head:hover {
  background: var(--panel-2);
}

.record-head .id {
  color: var(--text-faint);
  font-family: 'IBM Plex Mono', monospace;
  font-size: 12px;
}

.record-head > * {
  min-width: 0;
}

.record-summary {
  display: flex;
  gap: 14px;
  flex-wrap: wrap;
  font-family: 'IBM Plex Mono', monospace;
  font-size: 12px;
  color: var(--text-dim);
}

.record-summary b {
  color: var(--text);
  font-weight: 600;
}

.record-time {
  color: var(--text-faint);
  font-size: 12px;
  font-family: 'IBM Plex Mono', monospace;
}

.caret {
  transition: transform .15s ease;
  color: var(--text-faint);
}

.record.open .caret {
  transform: rotate(90deg);
  color: var(--accent);
}

.record-body {
  display: none;
  border-top: 1px solid var(--border-soft);
  background: var(--panel-2);
}

.record.open .record-body {
  display: block;
}

.record-body pre {
  margin: 0;
  padding: 16px 18px;
  font-size: 12px;
  line-height: 1.7;
  overflow-x: auto;
  max-height: 340px;
  overflow-y: auto;
}

/* JSON syntax colors inside expanded record payloads. */
.jk {
  color: var(--blue);
}

.js {
  color: var(--accent);
}

.jn {
  color: var(--amber);
}

.jb {
  color: #c792ea;
}

.jl {
  color: var(--text-faint);
}

/* Light theme: deepen syntax colors so highlighted JSON stays readable. */
html[data-theme="light"] .jk {
  color: #2e6da4;
}

html[data-theme="light"] .js {
  color: #0d8d7f;
}

html[data-theme="light"] .jn {
  color: #96690f;
}

html[data-theme="light"] .jb {
  color: #7a4fb5;
}


/* ========================================
   CONSOLE (live log stream)
   ======================================== */

.console {
  background: var(--console-bg);
  border: 1px solid var(--border-soft);
  border-radius: var(--radius-sm);
  height: 420px;
  overflow-y: auto;
  padding: 6px 0;
}

.console-line {
  padding: 9px 18px;
  border-bottom: 1px solid var(--console-line);
  font-size: 12px;
  display: flex;
  gap: 12px;
}

.console-line .ts {
  color: var(--text-faint);
  flex: none;
  font-family: 'IBM Plex Mono', monospace;
}

.console-line .badge {
  flex: none;
  font-family: 'IBM Plex Mono', monospace;
  color: var(--blue);
  background: var(--blue-dim);
  padding: 1px 6px;
  border-radius: 4px;
  height: fit-content;
}

.console-line pre {
  margin: 0;
  white-space: pre-wrap;
  word-break: break-word;
  font-size: 12px;
  line-height: 1.6;
}

.console-line.fresh {
  animation: highlight 1.4s ease;
}

@keyframes highlight {
  from {
    background: rgba(47, 214, 196, .09);
  }

  to {
    background: transparent;
  }
}


/* ========================================
   TOAST / EMPTY STATE
   ======================================== */

.toast {
  position: fixed;
  bottom: 22px;
  right: 22px;
  background: var(--panel-3);
  border: 1px solid var(--accent-dim2);
  color: var(--text);
  padding: 12px 16px;
  border-radius: var(--radius-sm);
  font-size: 13px;
  display: flex;
  align-items: center;
  gap: 10px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, .35);
  transform: translateY(12px);
  opacity: 0;
  pointer-events: none;
  transition: all .25s ease;
  z-index: 100;
}

.toast.show {
  transform: none;
  opacity: 1;
}

.empty {
  padding: 30px;
  text-align: center;
  color: var(--text-faint);
  font-size: 13px;
}


/* ========================================
   TOPIC COMBOBOX (custom dropdown)
   ======================================== */

.topic-combo {
  position: relative;
}

.combo-trigger {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  cursor: pointer;
  text-align: left;
}

.combo-caret {
  color: var(--text-faint);
  flex: none;
  transition: transform .15s ease;
}

.combo-trigger[aria-expanded="true"] .combo-caret {
  transform: rotate(180deg);
}

.combo-trigger:focus-visible,
.combo-trigger[aria-expanded="true"] {
  border-color: var(--accent-dim2);
}

.combo-panel {
  position: absolute;
  top: calc(100% + 6px);
  left: 0;
  right: 0;
  z-index: 40;
  background: var(--panel-3);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 6px;
  box-shadow: 0 12px 28px rgba(0, 0, 0, .4);
  display: none;
  max-height: 320px;
  overflow-y: auto;
}

.combo-panel.open {
  display: block;
}

.combo-option {
  padding: 8px 10px;
  border-radius: 5px;
  font-size: 13px;
  color: var(--text-dim);
  cursor: pointer;
}

.combo-option:hover {
  background: var(--panel-2);
  color: var(--text);
}

.combo-option.selected {
  background: var(--accent-dim);
  color: var(--accent);
  font-weight: 500;
}

.combo-divider {
  height: 1px;
  background: var(--border-soft);
  margin: 6px 4px;
}

.combo-actions-label {
  padding: 6px 10px 4px;
  font-size: 11px;
  color: var(--text-faint);
  font-weight: 500;
}

.combo-action {
  width: 100%;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 10px;
  border-radius: 5px;
  background: none;
  border: none;
  color: var(--red);
  font-size: 12.5px;
  font-weight: 500;
  text-align: left;
  cursor: pointer;
  font-family: inherit;
}

.combo-action:hover {
  background: var(--red-dim);
}

.combo-action:disabled {
  opacity: .4;
  cursor: not-allowed;
  background: none;
}

.combo-action svg {
  flex: none;
  opacity: .85;
}


/* ========================================
   BACKDROP (shared dimming layer)
   ======================================== */

.backdrop {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, .5);
  z-index: 30;
}


/* ========================================
   AUTH (login / register overlay)
   ======================================== */

.auth-view {
  position: fixed;
  inset: 0;
  z-index: 200;
  background: var(--bg);
  display: none;
}

/* Centered two-column composition: capped columns + justify-content keep
   branding and form balanced in the viewport instead of stretched apart. */
.auth-view.active {
  display: grid;
  grid-template-columns: minmax(0, 520px) minmax(0, 440px);
  justify-content: center;
}

.auth-hero {
  position: relative;
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 48px;
  background: var(--auth-hero-bg);
  border-right: 1px solid var(--border);
}

.auth-hero-content {
  max-width: 420px;
  position: relative;
  z-index: 2;
}

.auth-hero-content h2 {
  font-size: 27px;
  margin: 26px 0 12px;
  font-weight: 600;
  line-height: 1.3;
}

.auth-hero-content p.lead {
  color: var(--text-dim);
  font-size: 14px;
  line-height: 1.65;
  margin: 0 0 30px;
}

.auth-feature-list {
  display: flex;
  flex-direction: column;
  gap: 15px;
}

.auth-feature {
  display: flex;
  gap: 10px;
  align-items: flex-start;
  font-size: 13px;
  color: var(--text-dim);
  line-height: 1.5;
}

.auth-feature svg {
  color: var(--accent);
  flex: none;
  margin-top: 2px;
}

.auth-panel {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 40px 44px;
  overflow-y: auto;
}

.auth-card {
  width: 100%;
  max-width: 340px;
}

.auth-card .brand {
  border: none;
  padding: 0;
  margin-bottom: 30px;
}

.auth-form {
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.auth-form h3 {
  font-size: 19px;
  margin: 0 0 2px;
  font-weight: 600;
}

.auth-form p.hint {
  margin: 0 0 4px;
  font-size: 12.5px;
  color: var(--text-faint);
}

.checkbox-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 12.5px;
  color: var(--text-dim);
  margin-top: -2px;
}

.checkbox-row label {
  display: flex;
  align-items: center;
  gap: 7px;
  cursor: pointer;
}

.checkbox-row input[type=checkbox] {
  accent-color: var(--accent);
}

.checkbox-row a {
  color: var(--accent);
  text-decoration: none;
}

.checkbox-row a:hover {
  text-decoration: underline;
}

.auth-switch {
  margin-top: 20px;
  text-align: center;
  font-size: 12.5px;
  color: var(--text-faint);
}

.auth-switch button {
  background: none;
  border: none;
  color: var(--accent);
  font-weight: 600;
  cursor: pointer;
  font-family: inherit;
  font-size: inherit;
  padding: 0;
}

.auth-error {
  display: none;
  font-size: 12px;
  color: var(--red);
  background: var(--red-dim);
  border: 1px solid rgba(238, 95, 87, .25);
  padding: 9px 11px;
  border-radius: 6px;
  line-height: 1.5;
}

.auth-error.show {
  display: block;
}


/* ========================================
   MODALS (connection create/edit + delete confirm)
   ======================================== */

.modal-label {
  display: block;
  margin-bottom: 6px;
  font-size: 13px;
  color: var(--text-dim);
}

.modal-input {
  width: 100%;
  padding: 10px 12px;
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text);
  font-size: 14px;
  box-sizing: border-box;
}


/* ========================================
   RESPONSIVE
   ======================================== */

@media (max-width: 860px) {
  .auth-view.active {
    grid-template-columns: minmax(0, 420px);
    justify-content: center;
  }

  .auth-hero {
    display: none;
  }

  #mobileBrand {
    display: flex !important;
  }
}

@media (max-width: 960px) {
  .app {
    grid-template-columns: 1fr;
  }

  .sidebar {
    position: fixed;
    left: 0;
    top: 0;
    z-index: 40;
    width: 264px;
    max-width: 85vw;
    transform: translateX(-100%);
    transition: transform .2s ease;
  }

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

  .menu-btn {
    display: inline-flex;
  }

  .backdrop.open {
    display: block;
  }

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

  .row-4 {
    grid-template-columns: repeat(2, 1fr);
  }

  .row-3 {
    grid-template-columns: 1fr;
  }

  .record-head {
    grid-template-columns: 50px 1fr 34px;
  }

  .record-head .record-time,
  .record-head .id {
    display: none;
  }
}

@media (max-width: 560px) {
  .kpi-grid {
    grid-template-columns: 1fr;
  }

  .pills .pill span.txt {
    display: none;
  }

  /* Phones: tighter chrome, single-column forms, shorter console. */
  .topbar {
    padding: 12px 14px;
    gap: 10px;
  }

  .content {
    padding: 16px 14px 48px;
  }

  .panel {
    padding: 16px;
  }

  .row-4 {
    grid-template-columns: 1fr;
  }

  .record-head {
    grid-template-columns: 44px 1fr 30px;
    gap: 10px;
    padding: 10px 12px;
  }

  .record-summary {
    gap: 8px;
    font-size: 11.5px;
  }

  .console {
    height: 320px;
  }

  .toast {
    left: 12px;
    right: 12px;
    bottom: 14px;
  }

  .user-chip {
    padding-left: 0;
    border-left: none;
    margin-left: 0;
  }

  .auth-panel {
    padding: 24px 16px;
  }
}
