/* ── Meshtastic × Tabler — Custom Overrides ────────────────────────────────── */

/* 1. Brand color variables */
:root {
  --tblr-primary: #3FB86D;
  --tblr-primary-rgb: 63, 184, 109;
  --tblr-primary-darken: #2D8F52;
  --meshtastic-accent: #67EA94;

  /* Neutral palette (Meshtastic design standards) */
  --mesh-950: #0F1017;
  --mesh-900: #1A1B26;
  --mesh-800: #2C2D3C;
  --mesh-700: #3D3E50;
  --mesh-600: #555668;
  --mesh-500: #6E7082;
  --mesh-400: #9496A6;
  --mesh-300: #B8BAC8;
}

/* 2. Dark theme surface overrides */
[data-bs-theme="dark"] {
  --tblr-body-bg: #1A1B26;
  --tblr-body-color: #d0d0d8;
  --tblr-card-bg: #2C2D3C;
  --tblr-border-color: #3D3E50;
  --tblr-secondary-color: #9496A6;
}

/* 3. Tabler Icons — local font delivery */
@font-face {
  font-family: "tabler-icons";
  src: url("/static/fonts/tabler-icons.woff2") format("woff2"),
       url("/static/fonts/tabler-icons.woff") format("woff"),
       url("/static/fonts/tabler-icons.ttf") format("truetype");
  font-weight: 400;
  font-style: normal;
  font-display: block;
}

/* ── Connection status indicator ────────────────────────────────────────────── */
.conn-dot {
  display: inline-block;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  margin-right: 4px;
  vertical-align: middle;
  flex-shrink: 0;
}
.conn-dot.connected    { background: #3FB86D; box-shadow: 0 0 0 3px rgba(63,184,109,.2); }
.conn-dot.disconnected { background: #d63939; }
.conn-dot.connecting   { background: #f59f00; animation: blink 1s ease-in-out infinite; }

@keyframes blink {
  0%, 100% { opacity: 1; }
  50%       { opacity: .35; }
}

/* ── Node avatar circle ──────────────────────────────────────────────────────── */
.mesh-avatar {
  background: linear-gradient(135deg, #3FB86D 0%, #2D8F52 100%);
  color: #fff;
  font-weight: 700;
  letter-spacing: .03em;
  user-select: none;
}

.node-avatar {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 34px;
  height: 34px;
  flex-shrink: 0;
  aspect-ratio: 1;
  border-radius: 50%;
  font-size: 11px;
  font-weight: 700;
  color: #fff;
  background: var(--mesh-600);
}

/* ── Hop count badge colors ──────────────────────────────────────────────────── */
.hop-badge { font-size: .7rem; font-weight: 600; }
.hop-0 { background: #2fb344 !important; color: #fff !important; }
.hop-1 { background: #63e6be !important; color: #0a0a0a !important; }
.hop-2 { background: #4299e1 !important; color: #fff !important; }
.hop-3 { background: #6574cd !important; color: #fff !important; }
.hop-4 { background: #206bc4 !important; color: #fff !important; }
.hop-5 { background: #f59f00 !important; color: #fff !important; }
.hop-6 { background: #f76707 !important; color: #fff !important; }
.hop-7 { background: #d63939 !important; color: #fff !important; }
.hop-unknown { background: #546E7A !important; color: #fff !important; }

/* ── Signal quality helpers ──────────────────────────────────────────────────── */
.signal-excellent { color: #2fb344; }
.signal-good      { color: #63e6be; }
.signal-fair      { color: #f59f00; }
.signal-poor      { color: #d63939; }

/* ── Map node markers ────────────────────────────────────────────────────────── */
.node-marker {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 2px solid rgba(255,255,255,.35);
  box-shadow: 0 2px 8px rgba(0,0,0,.45);
  cursor: pointer;
  transition: transform .15s ease, box-shadow .15s ease;
}
.node-marker:hover {
  transform: scale(1.18);
  box-shadow: 0 4px 14px rgba(0,0,0,.6);
}
.node-marker i { font-size: 16px; color: #fff; line-height: 1; }

/* ── Leaflet popup dark theme ───────────────────────────────────────────────── */
.leaflet-popup-content-wrapper {
  background: var(--mesh-800) !important;
  border: 1px solid var(--mesh-700) !important;
  border-radius: 10px !important;
  box-shadow: 0 8px 28px rgba(0,0,0,.5) !important;
  color: #d0d0d8 !important;
  padding: 0 !important;
}
.leaflet-popup-content { margin: 0 !important; }
.leaflet-popup-tip     { background: var(--mesh-800) !important; }
.leaflet-popup-close-button {
  color: var(--mesh-400) !important;
  font-size: 18px !important;
  top: 6px !important;
  right: 8px !important;
}

.node-popup {
  padding: 14px 16px;
  min-width: 190px;
}
.node-popup-name  { font-weight: 700; color: #3FB86D; font-size: .95rem; margin: 0 0 4px; }
.node-popup-uid   { font-family: monospace; font-size: .78rem; color: var(--mesh-400); margin: 0 0 10px; }
.node-popup-row   { display: flex; justify-content: space-between; gap: 12px; font-size: .82rem; margin: 3px 0; }
.node-popup-label { color: var(--mesh-400); }
.node-popup-value { color: #e0e0e0; font-weight: 500; }

/* ── Map legend ──────────────────────────────────────────────────────────────── */
.map-legend {
  background: rgba(44,45,60,.95);
  border: 1px solid var(--mesh-700);
  border-radius: 8px;
  padding: 10px 14px;
  min-width: 130px;
  font-size: .78rem;
  backdrop-filter: blur(4px);
  color: #d0d0d8;
}
.map-legend-title {
  font-size: .7rem;
  text-transform: uppercase;
  letter-spacing: .06em;
  color: var(--mesh-400);
  margin: 0 0 8px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  cursor: pointer;
}
.legend-item { display: flex; align-items: center; gap: 8px; margin: 4px 0; }
.legend-dot {
  width: 12px;
  height: 12px;
  border-radius: 50%;
  flex-shrink: 0;
  border: 1.5px solid rgba(255,255,255,.2);
}

/* ── Leaflet controls dark ───────────────────────────────────────────────────── */
.leaflet-control-layers,
.leaflet-control-layers-expanded {
  background: rgba(44,45,60,.95) !important;
  border: 1px solid var(--mesh-700) !important;
  border-radius: 8px !important;
  color: #d0d0d8 !important;
}
.leaflet-control-layers label { color: #d0d0d8 !important; }
.leaflet-control-layers-separator { border-color: var(--mesh-700) !important; }
.leaflet-control-zoom a {
  background: rgba(44,45,60,.92) !important;
  color: #d0d0d8 !important;
  border-color: var(--mesh-700) !important;
}
.leaflet-control-zoom a:hover { background: var(--mesh-700) !important; }

/* ── Messages UI ─────────────────────────────────────────────────────────────── */
.chat-container {
  display: flex;
  flex-direction: column;
  height: calc(100vh - 220px);
  min-height: 400px;
}

.msg-thread {
  flex: 1;
  overflow-y: auto;
  min-height: 0;
  padding: 16px 12px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.msg-row {
  display: flex;
  align-items: flex-end;
  gap: 10px;
}
.msg-row.outbound {
  flex-direction: row-reverse;
}

/* Constrain message width on the wrapper so msg-body can be 100% inside it */
.msg-row > div {
  max-width: 70%;
}

.msg-body {
  padding: 8px 13px;
  border-radius: 14px;
  font-size: .9rem;
  line-height: 1.45;
  word-break: break-word;
  background: var(--mesh-800);
  color: #d0d0d8;
}
.msg-row.outbound .msg-body {
  background: #206bc4;
  color: #fff;
  border-bottom-right-radius: 4px;
}
.msg-row:not(.outbound) .msg-body { border-bottom-left-radius: 4px; }

.msg-meta {
  font-size: .7rem;
  color: var(--mesh-500);
  margin-top: 3px;
  padding: 0 2px;
}
.msg-row.outbound .msg-meta { text-align: right; }

.msg-sender { font-size: .72rem; color: var(--mesh-400); font-weight: 600; }
.msg-body .msg-sender { color: rgba(255,255,255,.65); }

.msg-signal {
  font-size: .68rem;
  color: var(--mesh-500);
  padding: 0 2px;
  margin-top: 2px;
  display: flex;
  align-items: center;
  gap: 2px;
  flex-wrap: wrap;
}

.channel-item {
  border-radius: 8px;
  padding: 9px 12px;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 10px;
  transition: background .15s;
  border-left: 3px solid transparent;
}
.channel-item:hover { background: rgba(63,184,109,.08); }
.channel-item.active {
  background: rgba(63,184,109,.13);
  border-left-color: #3FB86D;
}
.channel-badge {
  width: 26px;
  height: 26px;
  border-radius: 6px;
  background: var(--mesh-700);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: .72rem;
  font-weight: 700;
  color: #d0d0d8;
  flex-shrink: 0;
}
.channel-item.active .channel-badge { background: #3FB86D; color: #fff; }

.msg-compose {
  padding: 12px;
  border-top: 1px solid var(--tblr-border-color);
}

/* ── Node list table ─────────────────────────────────────────────────────────── */
.node-row { cursor: pointer; }
.node-row:hover td { background: rgba(63,184,109,.06) !important; }
.node-row.selected td { background: rgba(63,184,109,.1) !important; }

/* ── Dashboard stat cards ────────────────────────────────────────────────────── */
.stat-icon {
  width: 52px;
  height: 52px;
  border-radius: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 24px;
  flex-shrink: 0;
}

/* ── Scrollbar styling ───────────────────────────────────────────────────────── */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--mesh-700); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--mesh-600); }

/* ── Page title uppercase ────────────────────────────────────────────────────── */
.page-title { text-transform: uppercase; letter-spacing: .04em; }

/* ── Sidebar clock ───────────────────────────────────────────────────────────── */
.sidebar-clock {
  font-family: "Roboto Mono", "Courier New", monospace;
  color: var(--mesh-400);
  letter-spacing: .06em;
  line-height: 1.55;
  user-select: none;
}
.sidebar-clock-time { font-size: .82rem; }
.sidebar-clock-date { font-size: .70rem; color: var(--mesh-500); }

/* ── Utility ─────────────────────────────────────────────────────────────────── */
code, .font-mono { font-family: "Roboto Mono", "Courier New", monospace; font-size: .85em; }

.text-muted-sm { font-size: .78rem; color: var(--mesh-500) !important; }

/* ── Responsive tweaks ────────────────────────────────────────────────────────── */
@media (max-width: 768px) {
  .msg-body { max-width: 85%; }
  .chat-container { height: calc(100vh - 280px); }
}
