/* ============================================================
   Meshtastic Web — main stylesheet
   Colors taken from the Python original (app/theme.py):
     base       #0F1115
     surface    #1A1E27 / #222732
     brand      #67EA94
     text       #E8ECF1
     muted      #7C8696
     warning    #F5B946
     danger     #F0584B
   Plus a light theme variant.
   ============================================================ */

/* ---------- design tokens ---------- */
:root {
  --bg:           #0F1115;
  --bg-elev:      #161A22;
  --surface:      #1A1E27;
  --surface-2:    #222732;
  --surface-3:    #2A303D;
  --border:       #2A303D;
  --border-soft:  #232833;
  --text:         #E8ECF1;
  --text-soft:    #B8C0CC;
  --muted:        #7C8696;
  --brand:        #67EA94;
  --brand-dim:    #4FB678;
  --brand-bg:     rgba(103, 234, 148, 0.12);
  --accent:       #5BA4F2;
  --warning:      #F5B946;
  --warn-bg:      rgba(245, 185, 70, 0.14);
  --danger:       #F0584B;
  --danger-bg:    rgba(240, 88, 75, 0.14);
  --info-bg:      rgba(91, 164, 242, 0.12);
  --bubble-me:    #2E5F44;
  --bubble-them:  #222732;
  --shadow:       0 4px 20px rgba(0,0,0,.30);
  --radius:       10px;
  --radius-sm:    6px;
  --radius-lg:    14px;
  --gap:          14px;
  --gap-sm:       8px;
  --gap-lg:       22px;
  --font-mono:    ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, monospace;
  --font-sans:    system-ui, -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

[data-theme="light"] {
  --bg:           #F5F6F8;
  --bg-elev:      #FFFFFF;
  --surface:      #FFFFFF;
  --surface-2:    #F0F2F5;
  --surface-3:    #E2E6EB;
  --border:       #D8DEE6;
  --border-soft:  #E2E6EB;
  --text:         #1B1F24;
  --text-soft:    #43505E;
  --muted:        #6B7785;
  --brand:        #1F9C5A;
  --brand-dim:    #1A7C48;
  --brand-bg:     rgba(31, 156, 90, 0.10);
  --accent:       #2266CC;
  --warning:      #B5832B;
  --warn-bg:      rgba(245, 185, 70, 0.16);
  --danger:       #C13B30;
  --danger-bg:    rgba(240, 88, 75, 0.10);
  --info-bg:      rgba(91, 164, 242, 0.16);
  --bubble-me:    #B7E7C7;
  --bubble-them:  #ECEFF3;
  --shadow:       0 4px 14px rgba(0,0,0,.07);
}

/* Auto theme follows OS preference. We rely on the data-theme attribute set
   by JS based on saved preference; the CSS rules just need a sensible
   fallback for when JS hasn't loaded yet. */
@media (prefers-color-scheme: light) {
  [data-theme="auto"] {
    --bg:           #F5F6F8;
    --bg-elev:      #FFFFFF;
    --surface:      #FFFFFF;
    --surface-2:    #F0F2F5;
    --surface-3:    #E2E6EB;
    --border:       #D8DEE6;
    --border-soft:  #E2E6EB;
    --text:         #1B1F24;
    --text-soft:    #43505E;
    --muted:        #6B7785;
    --brand:        #1F9C5A;
    --brand-dim:    #1A7C48;
    --brand-bg:     rgba(31, 156, 90, 0.10);
    --accent:       #2266CC;
    --bubble-me:    #B7E7C7;
    --bubble-them:  #ECEFF3;
    --shadow:       0 4px 14px rgba(0,0,0,.07);
  }
}

/* ---------- reset ---------- */
*, *::before, *::after { box-sizing: border-box; }
html, body { margin: 0; padding: 0; height: 100%; }
body {
  font-family: var(--font-sans);
  font-size: 14px;
  line-height: 1.45;
  background: var(--bg);
  color: var(--text);
  display: grid;
  grid-template-rows: auto auto 1fr auto;
  min-height: 100vh;
}
body.boot { opacity: 0; transition: opacity .2s; }
body.ready { opacity: 1; }
code, pre, .mono { font-family: var(--font-mono); font-size: 0.92em; }
button, input, select, textarea { font: inherit; color: inherit; }
button { background: none; border: 0; cursor: pointer; }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
hr { border: 0; border-top: 1px solid var(--border-soft); margin: 12px 0; }

/* ---------- scrollbars (subtle) ---------- */
* {
  scrollbar-width: thin;
  scrollbar-color: var(--surface-3) transparent;
}
*::-webkit-scrollbar { width: 8px; height: 8px; }
*::-webkit-scrollbar-thumb { background: var(--surface-3); border-radius: 4px; }
*::-webkit-scrollbar-track { background: transparent; }

/* ============================================================
   TOP BAR
   ============================================================ */
#appbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--gap);
  padding: 10px 16px;
  background: var(--bg-elev);
  border-bottom: 1px solid var(--border);
  box-shadow: var(--shadow);
  z-index: 5;
}
.brand { display: flex; align-items: center; gap: 10px; min-width: 0; }
.logo { color: var(--brand); display: inline-flex; }
.brand-text { display: flex; flex-direction: column; line-height: 1.1; }
.brand-title { font-weight: 700; font-size: 15px; }
.brand-subtitle { color: var(--muted); font-size: 11px; }

.conn-form {
  display: flex;
  align-items: center;
  gap: 10px;
  flex: 1;
  flex-wrap: wrap;
  justify-content: center;
}
.conn-type-label {
  color: var(--brand);
  font-weight: 600;
  font-size: 12px;
  letter-spacing: 0.4px;
  text-transform: uppercase;
  background: var(--brand-bg);
  padding: 4px 10px;
  border-radius: 999px;
  border: 1px solid var(--brand-dim);
}
.conn-inputs { display: flex; gap: 6px; }
.conn-inputs input {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 7px 10px;
  color: var(--text);
  font-size: 13px;
}
#conn-host { width: 200px; }
#conn-port { width: 90px; text-align: center; }
.conn-inputs input:focus { outline: 2px solid var(--brand); outline-offset: -1px; border-color: var(--brand-dim); }

.conn-actions { display: flex; align-items: center; gap: 8px; }
.btn-icon {
  background: var(--surface);
  border: 1px solid var(--border-soft);
  border-radius: var(--radius-sm);
  padding: 6px 10px;
  font-size: 14px;
  color: var(--text);
  transition: background .15s, border-color .15s;
}
.btn-icon:hover { background: var(--surface-2); border-color: var(--border); }
.btn-icon.muted { color: var(--muted); }

.status-pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 5px 12px;
  border-radius: 999px;
  background: var(--surface);
  border: 1px solid var(--border-soft);
  font-size: 12px;
  font-weight: 500;
}
.dot {
  display: inline-block;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--muted);
  flex-shrink: 0;
}
.dot.ok      { background: var(--brand); box-shadow: 0 0 6px var(--brand); }
.dot.warn    { background: var(--warning); box-shadow: 0 0 6px var(--warning); }
.dot.danger  { background: var(--danger); box-shadow: 0 0 6px var(--danger); }
.dot.pulse   { animation: dotPulse 1.4s infinite ease-in-out; }
@keyframes dotPulse {
  0%, 100% { opacity: 1; transform: scale(1); }
  50%      { opacity: .5; transform: scale(1.25); }
}

/* ============================================================
   BUTTONS
   ============================================================ */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 7px 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface-2);
  color: var(--text);
  font-weight: 500;
  font-size: 13px;
  transition: background .15s, border-color .15s, transform .05s;
}
.btn:hover:not(:disabled) { background: var(--surface-3); }
.btn:active:not(:disabled) { transform: translateY(1px); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }

.btn-primary {
  background: var(--brand);
  color: #0a0d10;
  border-color: var(--brand-dim);
  font-weight: 600;
}
.btn-primary:hover:not(:disabled) { background: var(--brand-dim); }
.btn-danger {
  background: var(--danger);
  color: #fff;
  border-color: var(--danger);
}
.btn-danger:hover:not(:disabled) { filter: brightness(0.9); }
.btn-warn  {
  background: var(--warning);
  color: #1a1306;
  border-color: var(--warning);
}
.btn-ghost {
  background: transparent;
  border-color: transparent;
  color: var(--text-soft);
}
.btn-ghost:hover { background: var(--surface-2); }
.btn-small { padding: 4px 10px; font-size: 12px; }
.btn-block { width: 100%; justify-content: center; }
.btn-row { display: flex; gap: 8px; flex-wrap: wrap; }

/* ============================================================
   TABS
   ============================================================ */
#tabs {
  display: flex;
  overflow-x: auto;
  background: var(--bg);
  border-bottom: 1px solid var(--border);
  padding: 0 8px;
  scrollbar-width: none;
}
#tabs::-webkit-scrollbar { display: none; }
.tab {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 11px 16px;
  border-bottom: 2px solid transparent;
  color: var(--text-soft);
  font-size: 13px;
  font-weight: 500;
  white-space: nowrap;
  transition: color .15s, border-color .15s, background .15s;
  border-radius: 0;
}
.tab:hover { color: var(--text); background: var(--surface); }
.tab[aria-selected="true"] {
  color: var(--brand);
  border-bottom-color: var(--brand);
}
.tab .tab-emoji { font-size: 14px; line-height: 1; }

/* ============================================================
   MAIN PAGE AREA
   ============================================================ */
#page-root {
  overflow: auto;
  position: relative;
  background: var(--bg);
}
.page {
  padding: var(--gap-lg);
  max-width: 1400px;
  margin: 0 auto;
}
.page[hidden] { display: none !important; }

h1, h2, h3 { color: var(--text); margin: 0 0 12px; }
h1 { font-size: 22px; }
h2 { font-size: 18px; }
h3 { font-size: 15px; }
.subtitle { color: var(--muted); font-size: 13px; margin-bottom: 16px; }

/* ============================================================
   CARDS
   ============================================================ */
.card {
  background: var(--surface);
  border: 1px solid var(--border-soft);
  border-radius: var(--radius);
  padding: 16px;
  box-shadow: var(--shadow);
}
.card + .card { margin-top: var(--gap); }
.card-title {
  font-size: 13px;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  font-weight: 600;
  margin-bottom: 8px;
}
.card-row { display: flex; justify-content: space-between; align-items: center; gap: 8px; padding: 6px 0; }
.card-row + .card-row { border-top: 1px solid var(--border-soft); }
.card-row .label { color: var(--muted); }
.card-row .value { font-weight: 500; }

.grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: var(--gap);
}
.grid-2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(360px, 1fr)); gap: var(--gap); }
.grid-3 { display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: var(--gap); }

/* Big metric card (Info page) */
.metric-card {
  background: var(--surface);
  border: 1px solid var(--border-soft);
  border-radius: var(--radius);
  padding: 18px;
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.metric-label {
  color: var(--muted);
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  font-weight: 600;
}
.metric-value {
  font-size: 28px;
  font-weight: 700;
  color: var(--text);
}
.metric-status {
  font-size: 12px;
  color: var(--text-soft);
}
.metric-card.ok       { border-left: 4px solid var(--brand); }
.metric-card.warn     { border-left: 4px solid var(--warning); }
.metric-card.danger   { border-left: 4px solid var(--danger); }
.metric-card.info     { border-left: 4px solid var(--accent); }

.metric-bar {
  height: 6px;
  background: var(--surface-3);
  border-radius: 3px;
  overflow: hidden;
}
.metric-bar > span {
  display: block;
  height: 100%;
  background: var(--brand);
  border-radius: 3px;
  transition: width .3s;
}
.metric-bar.warn > span   { background: var(--warning); }
.metric-bar.danger > span { background: var(--danger); }

/* ============================================================
   FORM ELEMENTS
   ============================================================ */
.form-group { display: flex; flex-direction: column; gap: 4px; margin-bottom: 12px; }
.form-group > label { color: var(--text-soft); font-size: 12px; font-weight: 500; }
input[type=text], input[type=number], input[type=search],
input[type=password], select, textarea {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 8px 10px;
  color: var(--text);
  font-size: 13px;
  width: 100%;
  font-family: inherit;
}
input:focus, select:focus, textarea:focus {
  outline: 2px solid var(--brand);
  outline-offset: -1px;
  border-color: var(--brand);
}
textarea { resize: vertical; min-height: 60px; font-family: var(--font-sans); }
.checkbox-row {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 8px 0;
  cursor: pointer;
}
.checkbox-row input[type=checkbox] {
  width: 16px;
  height: 16px;
  accent-color: var(--brand);
  cursor: pointer;
}
.form-hint { color: var(--muted); font-size: 12px; margin-top: 6px; }

/* ============================================================
   MESSAGES PAGE
   ============================================================ */
.msg-layout {
  display: grid;
  grid-template-columns: 280px 1fr;
  gap: var(--gap);
  height: calc(100vh - 240px);
  min-height: 480px;
}
@media (max-width: 720px) {
  .msg-layout { grid-template-columns: 1fr; height: auto; }
  .msg-layout.show-thread .convo-list { display: none; }
  .msg-layout:not(.show-thread) .msg-thread { display: none; }
}
.convo-list {
  background: var(--surface);
  border: 1px solid var(--border-soft);
  border-radius: var(--radius);
  overflow-y: auto;
  display: flex;
  flex-direction: column;
}
.convo-list-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 12px;
  border-bottom: 1px solid var(--border-soft);
}
.convo-list-header h3 { margin: 0; font-size: 13px; color: var(--muted); text-transform: uppercase; letter-spacing: 0.5px; }
.convo-section-title {
  padding: 10px 12px 4px;
  font-size: 11px;
  font-weight: 600;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.4px;
}
.convo-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  cursor: pointer;
  border-bottom: 1px solid var(--border-soft);
  transition: background .15s;
}
.convo-item:hover { background: var(--surface-2); }
.convo-item.active { background: var(--brand-bg); border-left: 3px solid var(--brand); padding-left: 9px; }
.convo-avatar {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: var(--surface-3);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 12px;
  font-weight: 600;
  color: var(--brand);
  flex-shrink: 0;
}
.convo-avatar.channel { background: var(--brand); color: #0a0d10; }
.convo-info { flex: 1; min-width: 0; }
.convo-name { font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.convo-preview { font-size: 11px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.convo-badge {
  background: var(--brand);
  color: #0a0d10;
  font-size: 10px;
  font-weight: 600;
  padding: 2px 6px;
  border-radius: 999px;
  flex-shrink: 0;
}

.msg-thread {
  background: var(--surface);
  border: 1px solid var(--border-soft);
  border-radius: var(--radius);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
.msg-thread-header {
  padding: 12px;
  border-bottom: 1px solid var(--border-soft);
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px;
}
.msg-thread-title { font-weight: 600; font-size: 14px; }
.msg-thread-subtitle { font-size: 11px; color: var(--muted); }
.msg-list {
  flex: 1;
  overflow-y: auto;
  padding: 12px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  background: var(--bg);
}
.bubble {
  max-width: 75%;
  padding: 8px 12px;
  border-radius: 14px;
  background: var(--bubble-them);
  align-self: flex-start;
  word-wrap: break-word;
  overflow-wrap: break-word;
}
.bubble.me {
  background: var(--bubble-me);
  align-self: flex-end;
}
.bubble-meta {
  font-size: 10.5px;
  color: var(--muted);
  margin-bottom: 2px;
  display: flex;
  gap: 8px;
}
.bubble-text { font-size: 13.5px; line-height: 1.4; white-space: pre-wrap; }
.bubble-sender { font-weight: 600; color: var(--brand); }
.bubble.me .bubble-sender { color: #c4ecd4; }
.msg-empty {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  height: 100%;
  color: var(--muted);
  text-align: center;
  padding: 40px 20px;
}
.msg-empty-icon { font-size: 36px; margin-bottom: 8px; opacity: 0.5; }

.msg-composer {
  padding: 10px 12px;
  border-top: 1px solid var(--border-soft);
  display: flex;
  gap: 8px;
  background: var(--surface-2);
}
.msg-composer textarea {
  flex: 1;
  min-height: 38px;
  max-height: 120px;
  resize: none;
  background: var(--surface);
  font-size: 14px;
}
.msg-composer .send-btn {
  padding: 7px 14px;
  background: var(--brand);
  color: #0a0d10;
  border: 0;
  border-radius: var(--radius-sm);
  font-weight: 600;
  cursor: pointer;
}
.msg-actions-bar {
  padding: 8px 12px;
  border-bottom: 1px solid var(--border-soft);
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}

/* ============================================================
   NODES PAGE
   ============================================================ */
.nodes-toolbar {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  margin-bottom: 12px;
  align-items: center;
}
.nodes-toolbar input[type=search] { flex: 1; max-width: 400px; }
.nodes-toolbar .count { color: var(--muted); font-size: 12px; }

.node-card {
  background: var(--surface);
  border: 1px solid var(--border-soft);
  border-radius: var(--radius);
  padding: 14px;
  cursor: pointer;
  transition: border-color .15s, background .15s;
  position: relative;
}
.node-card:hover { border-color: var(--brand-dim); background: var(--surface-2); }
.node-card.me { border-color: var(--brand); }
.node-card.fav::before {
  content: '★';
  position: absolute;
  top: 8px;
  right: 10px;
  color: var(--warning);
}
.node-head { display: flex; align-items: center; gap: 10px; margin-bottom: 10px; }
.node-avatar {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: var(--surface-3);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 14px;
  color: var(--brand);
  flex-shrink: 0;
}
.node-name { font-weight: 600; }
.node-id { font-size: 11px; color: var(--muted); font-family: var(--font-mono); }
.node-meta { font-size: 12px; color: var(--muted); }
.node-meters { display: grid; grid-template-columns: 1fr 1fr; gap: 6px 12px; font-size: 12px; }
.node-meter > .label { color: var(--muted); font-size: 11px; }
.node-meter > .value { font-weight: 600; }

/* ============================================================
   CHANNELS PAGE
   ============================================================ */
.channel-list { display: flex; flex-direction: column; gap: 8px; }
.channel-row {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px;
  background: var(--surface);
  border: 1px solid var(--border-soft);
  border-radius: var(--radius);
}
.channel-index {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: var(--surface-3);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
}
.channel-row.primary .channel-index { background: var(--brand); color: #0a0d10; }
.channel-name { font-weight: 600; flex: 1; }
.channel-role-badge {
  font-size: 11px;
  padding: 2px 8px;
  border-radius: 999px;
  background: var(--surface-3);
  color: var(--text-soft);
}
.channel-row.primary .channel-role-badge { background: var(--brand-bg); color: var(--brand); }

.url-bar {
  display: flex;
  gap: 8px;
  align-items: stretch;
  margin-top: 12px;
}
.url-bar input { flex: 1; font-family: var(--font-mono); font-size: 11px; }

/* ============================================================
   STATS PAGE
   ============================================================ */
.stat-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: var(--gap);
  margin-bottom: var(--gap);
}
.bar-chart { display: flex; flex-direction: column; gap: 6px; padding: 4px 0; }
.bar-row { display: grid; grid-template-columns: 130px 1fr 60px; gap: 8px; align-items: center; font-size: 12px; }
.bar-row .name { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.bar-row .bar { height: 12px; background: var(--surface-3); border-radius: 6px; overflow: hidden; }
.bar-row .bar > span { display: block; height: 100%; background: var(--brand); border-radius: 6px; }
.bar-row .num { text-align: right; font-variant-numeric: tabular-nums; color: var(--text-soft); }

.hour-chart { display: flex; align-items: flex-end; gap: 2px; height: 120px; padding: 8px 0; }
.hour-chart .hbar {
  flex: 1;
  background: var(--brand);
  border-radius: 2px 2px 0 0;
  min-height: 1px;
  transition: height .25s;
}
.hour-chart .hbar.zero { background: var(--surface-3); }

/* ============================================================
   CONSOLE PAGE
   ============================================================ */
.console-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: var(--gap);
}
@media (max-width: 800px) {
  .console-grid { grid-template-columns: 1fr; }
}
.feed {
  background: var(--surface);
  border: 1px solid var(--border-soft);
  border-radius: var(--radius);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  min-height: 320px;
}
.feed-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 10px 12px;
  border-bottom: 1px solid var(--border-soft);
  background: var(--surface-2);
}
.feed-head h3 { margin: 0; font-size: 13px; text-transform: uppercase; color: var(--muted); letter-spacing: 0.5px; }
.feed-list {
  flex: 1;
  overflow-y: auto;
  padding: 8px 12px;
  font-family: var(--font-mono);
  font-size: 11.5px;
  line-height: 1.5;
}
.feed-list .row { padding: 1px 0; white-space: pre-wrap; word-break: break-all; }
.feed-list .ts   { color: var(--muted); }
.feed-list .L-DEBUG   { color: var(--muted); }
.feed-list .L-INFO    { color: var(--text-soft); }
.feed-list .L-WARNING { color: var(--warning); }
.feed-list .L-ERROR   { color: var(--danger); }

.console-cmd {
  display: flex;
  gap: 8px;
  margin-bottom: var(--gap);
}
.console-cmd input {
  flex: 1;
  font-family: var(--font-mono);
}
.console-cmd-output {
  background: var(--surface);
  border: 1px solid var(--border-soft);
  border-radius: var(--radius);
  padding: 12px;
  font-family: var(--font-mono);
  font-size: 12px;
  white-space: pre-wrap;
  word-break: break-word;
  max-height: 250px;
  overflow-y: auto;
  margin-bottom: var(--gap);
}

/* ============================================================
   SETTINGS PAGE
   ============================================================ */
.settings-section { margin-bottom: var(--gap-lg); }
.settings-section .form-hint { margin-bottom: 12px; }
.settings-actions { display: flex; gap: 8px; flex-wrap: wrap; }

/* ============================================================
   MAP
   ============================================================ */
#map-canvas {
  height: 70vh;
  min-height: 400px;
  border-radius: var(--radius);
  background: var(--surface-2);
}
.map-legend {
  background: var(--surface);
  border: 1px solid var(--border-soft);
  border-radius: var(--radius);
  padding: 10px 14px;
  display: inline-flex;
  gap: 16px;
  margin-top: 8px;
  font-size: 12px;
}
.map-legend .swatch {
  width: 12px;
  height: 12px;
  border-radius: 50%;
  display: inline-block;
  margin-right: 6px;
}

/* ============================================================
   STATUS BAR (FOOTER)
   ============================================================ */
#statusbar {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 14px;
  background: var(--bg-elev);
  border-top: 1px solid var(--border);
  color: var(--text-soft);
  font-size: 12px;
  flex-wrap: wrap;
}
.sb-item { display: inline-flex; align-items: center; gap: 6px; }
.sb-sep  { color: var(--muted); }
.sb-spacer { flex: 1; }
.sb-muted { color: var(--muted); }
@media (max-width: 600px) {
  .sb-sep { display: none; }
  #statusbar { font-size: 11px; }
}

/* ============================================================
   POPOVERS + TOAST
   ============================================================ */
.popover {
  position: fixed;
  z-index: 100;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 6px;
  box-shadow: var(--shadow);
  min-width: 160px;
}
.popover-item {
  display: block;
  width: 100%;
  text-align: left;
  padding: 8px 12px;
  border-radius: var(--radius-sm);
  font-size: 13px;
  color: var(--text);
}
.popover-item:hover { background: var(--surface-2); }
.popover-item.danger { color: var(--danger); }
.popover-divider { height: 1px; background: var(--border-soft); margin: 4px 0; }

#toast-region {
  position: fixed;
  bottom: 50px;
  right: 20px;
  z-index: 200;
  display: flex;
  flex-direction: column;
  gap: 8px;
  pointer-events: none;
}
.toast {
  background: var(--surface);
  color: var(--text);
  padding: 10px 14px;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  box-shadow: var(--shadow);
  font-size: 13px;
  min-width: 200px;
  max-width: 360px;
  border-left: 4px solid var(--brand);
  animation: toastIn .25s;
  pointer-events: auto;
}
.toast.danger  { border-left-color: var(--danger); }
.toast.warning { border-left-color: var(--warning); }
.toast.info    { border-left-color: var(--accent); }
@keyframes toastIn {
  from { transform: translateX(20px); opacity: 0; }
  to   { transform: translateX(0); opacity: 1; }
}

/* ============================================================
   UTILITY CLASSES
   ============================================================ */
.text-muted   { color: var(--muted); }
.text-soft    { color: var(--text-soft); }
.text-brand   { color: var(--brand); }
.text-warn    { color: var(--warning); }
.text-danger  { color: var(--danger); }
.text-small   { font-size: 12px; }
.text-mono    { font-family: var(--font-mono); }
.text-center  { text-align: center; }
.text-right   { text-align: right; }
.fw-600       { font-weight: 600; }
.fw-700       { font-weight: 700; }
.mt-8  { margin-top: 8px; }
.mt-12 { margin-top: 12px; }
.mt-16 { margin-top: 16px; }
.mb-8  { margin-bottom: 8px; }
.mb-12 { margin-bottom: 12px; }
.gap-8 { gap: 8px; }
.flex-row { display: flex; align-items: center; gap: 8px; }
.flex-col { display: flex; flex-direction: column; gap: 8px; }
.row-between { display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.hidden { display: none !important; }

/* badges */
.badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 11px;
  background: var(--surface-3);
  color: var(--text-soft);
}
.badge.brand  { background: var(--brand-bg); color: var(--brand); }
.badge.warn   { background: var(--warn-bg);  color: var(--warning); }
.badge.danger { background: var(--danger-bg); color: var(--danger); }

/* ============================================================
   MOBILE TWEAKS
   ============================================================ */
@media (max-width: 720px) {
  #appbar {
    padding: 8px 10px;
    gap: 8px;
  }
  .brand-subtitle { display: none; }
  .conn-inputs { width: 100%; }
  #conn-host { flex: 1; }
  #conn-port { width: 70px; }
  .conn-form { order: 3; width: 100%; justify-content: stretch; }
  .conn-form > * { flex: 1; }
  .conn-actions { order: 2; }
  .page { padding: 14px; }
  h1 { font-size: 18px; }
  .grid { grid-template-columns: 1fr; }
  .bar-row { grid-template-columns: 100px 1fr 40px; font-size: 11px; }
}

@media (max-width: 480px) {
  #tabs .tab { padding: 9px 10px; font-size: 12px; }
  #tabs .tab span:not(.tab-emoji) { display: none; }
  #statusbar #sb-firmware,
  #statusbar #sb-uptime { display: none; }
}

/* Loader */
.loader {
  display: inline-block;
  width: 14px;
  height: 14px;
  border: 2px solid var(--surface-3);
  border-top-color: var(--brand);
  border-radius: 50%;
  animation: spin .8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
