/* =========================================================
   TrustLine — base.css
   Shared design tokens, reset, typography, layout helpers,
   shared components (brandbar, cards, buttons, modal).
   Dark mode is default; light mode via [data-theme="light"].
   ========================================================= */

/* ── Google Fonts are loaded in base.html ────────────────── */

/* ── Design tokens — dark (default) ───────────────────────── */
:root {
  --bg:          #0B1220;
  --surface:     #121B2E;
  --surface-alt: #17233A;
  --border:      #223252;
  --text:        #E8ECF6;
  --text-muted:  #8C98B8;
  --accent:      #2FD48C;
  --accent-soft: rgba(47,212,140,0.12);
  --danger:      #F2495C;
  --danger-soft: rgba(242,73,92,0.12);
  --warn:        #F0B429;
  --warn-soft:   rgba(240,180,41,0.12);
  --info:        #7C8CF8;
  --info-soft:   rgba(124,140,248,0.12);
  --shadow:      0 20px 50px rgba(0,0,0,0.35);
  --radius:      10px;
  --radius-sm:   7px;
  --transition:  0.15s ease;

  /* ── Wallet / sender colours ─── */
  --aaib:        #3b82f6;
  --aaib-soft:   rgba(59,130,246,0.12);
  --vf441:       #a855f7;
  --vf441-soft:  rgba(168,85,247,0.12);
  --vf301:       #06b6d4;
  --vf301-soft:  rgba(6,182,212,0.12);

  /* ── High-value threshold ────── */
  --high-value:       #f97316;
  --high-value-soft:  rgba(249,115,22,0.12);
}

/* ── Light mode overrides ──────────────────────────────────── */
[data-theme="light"] {
  --bg:          #F0F4FA;
  --surface:     #FFFFFF;
  --surface-alt: #EDF1F8;
  --border:      #C8D4E8;
  --text:        #18243C;
  --text-muted:  #5A6880;
  --accent:      #1AAD72;
  --accent-soft: rgba(26,173,114,0.10);
  --danger:      #D63347;
  --danger-soft: rgba(214,51,71,0.08);
  --warn:        #B07820;
  --warn-soft:   rgba(176,120,32,0.10);
  --info:        #4252C8;
  --info-soft:   rgba(66,82,200,0.10);
  --shadow:      0 8px 30px rgba(0,0,0,0.10);

  /* ── Wallet / sender colours (light) ─── */
  --aaib:        #2563eb;
  --aaib-soft:   rgba(37,99,235,0.09);
  --vf441:       #7c3aed;
  --vf441-soft:  rgba(124,58,237,0.09);
  --vf301:       #0891b2;
  --vf301-soft:  rgba(8,145,178,0.09);
  --high-value:       #ea580c;
  --high-value-soft:  rgba(234,88,12,0.09);
}

/* ── Animation keyframes ────────────────────────────────────── */
@keyframes pulse-fresh {
  0%, 100% { box-shadow: 0 0 0 0 rgba(47,212,140,0.0); }
  50%       { box-shadow: 0 0 14px 4px rgba(47,212,140,0.40); }
}
@keyframes pulse-warn {
  0%, 100% { box-shadow: 0 0 0 0 rgba(240,180,41,0.0); }
  50%       { box-shadow: 0 0 14px 4px rgba(240,180,41,0.45); }
}
@keyframes pulse-danger {
  0%, 100% { box-shadow: 0 0 0 0 rgba(242,73,92,0.0); }
  50%       { box-shadow: 0 0 16px 5px rgba(242,73,92,0.55); }
}

/* ── Reset ─────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; }
body {
  font-family: 'Inter', -apple-system, sans-serif;
  background: var(--bg);
  color: var(--text);
  margin: 0;
  padding: 20px;
  transition: background var(--transition), color var(--transition);
}
a { color: inherit; }

/* ── Brandbar ───────────────────────────────────────────────── */
.brandbar {
  display: flex;
  align-items: center;
  gap: 9px;
  margin-bottom: 4px;
}
.brandbar svg  { width: 24px; height: 24px; }
.brandbar .word {
  font-family: 'Space Grotesk', sans-serif;
  font-weight: 700;
  font-size: 1.15em;
}
.brandbar .word span { color: var(--accent); }
.eyebrow {
  font-size: 0.70em;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--text-muted);
  margin: 0 0 16px 33px;
}

/* ── Topbar ────────────────────────────────────────────────── */
.topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  border-bottom: 1px solid var(--border);
  padding-bottom: 14px;
  margin-bottom: 14px;
  flex-wrap: wrap;
  gap: 8px;
}
h1 {
  font-family: 'Space Grotesk', sans-serif;
  color: var(--text);
  margin: 0;
  font-size: 1.25em;
  font-weight: 600;
}
.who { font-size: 0.85em; color: var(--text-muted); }
.who strong { color: var(--text); }
.who a      { color: var(--danger); text-decoration: none; margin-left: 10px; }
.who .devlink { color: var(--info); font-weight: 600; }

/* ── Theme toggle ──────────────────────────────────────────── */
.theme-toggle {
  background: var(--surface-alt);
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 5px 11px;
  cursor: pointer;
  font-size: 0.85em;
  color: var(--text-muted);
  transition: all var(--transition);
  line-height: 1;
}
.theme-toggle:hover { border-color: var(--accent); color: var(--text); }

/* ── Role badge ────────────────────────────────────────────── */
.role-badge {
  background: var(--info-soft);
  color: var(--info);
  padding: 2px 9px;
  border-radius: 10px;
  font-size: 0.70em;
  margin-left: 8px;
  font-family: 'JetBrains Mono', monospace;
  letter-spacing: 0.05em;
}

/* ── Cards ────────────────────────────────────────────────── */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  margin: 14px 0;
}

/* ── Generic buttons ──────────────────────────────────────── */
.btn-primary {
  background: var(--accent);
  color: #052015;
  border: none;
  border-radius: var(--radius-sm);
  padding: 9px 18px;
  cursor: pointer;
  font-weight: 600;
  font-family: 'Space Grotesk', sans-serif;
  font-size: 0.9em;
  transition: filter var(--transition);
}
.btn-primary:hover { filter: brightness(1.08); }

.btn-danger {
  background: var(--danger-soft);
  color: var(--danger);
  border: 1px solid rgba(242,73,92,0.35);
  border-radius: var(--radius-sm);
  padding: 6px 12px;
  cursor: pointer;
  font-size: 0.78em;
}
.btn-ghost {
  background: var(--surface-alt);
  color: var(--text-muted);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 6px 12px;
  cursor: pointer;
  font-size: 0.78em;
  font-family: 'Inter', sans-serif;
  transition: all var(--transition);
}
.btn-ghost:hover { color: var(--text); border-color: var(--info); }

/* ── View / filter toggle buttons ──────────────────────────── */
.view-toggle { display: flex; gap: 6px; margin: 12px 0; flex-wrap: wrap; }
.view-btn {
  padding: 7px 13px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text-muted);
  border-radius: var(--radius-sm);
  cursor: pointer;
  font-size: 0.82em;
  font-family: 'Inter', sans-serif;
  transition: all var(--transition);
}
.view-btn:hover { border-color: var(--accent); color: var(--text); }
.view-btn.active {
  background: var(--accent-soft);
  border-color: var(--accent);
  color: var(--accent);
}
.sender-toggle .view-btn.active {
  background: var(--info-soft);
  border-color: var(--info);
  color: var(--info);
}
.view-btn:disabled { opacity: 0.3; cursor: not-allowed; }

/* ── Pagination ────────────────────────────────────────────── */
.pagination-controls {
  display: none;
  justify-content: space-between;
  align-items: center;
  margin-top: 14px;
  padding: 12px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}
.page-info {
  font-size: 0.85em;
  color: var(--text-muted);
  font-family: 'JetBrains Mono', monospace;
}
.page-info strong { color: var(--text); }

/* ── Empty state ───────────────────────────────────────────── */
.empty {
  text-align: center;
  color: var(--text-muted);
  padding: 40px 20px;
  font-size: 0.9em;
}

/* ── Search/filter bar ─────────────────────────────────────── */
.search-bar {
  display: flex;
  gap: 8px;
  margin: 12px 0;
  flex-wrap: wrap;
  align-items: center;
}
.search-bar input[type="text"],
.search-bar input[type="date"] {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
  padding: 8px 12px;
  font-family: 'Inter', sans-serif;
  font-size: 0.84em;
  transition: border-color var(--transition);
}
.search-bar input[type="text"] { flex: 1; min-width: 180px; }
.search-bar input:focus { outline: none; border-color: var(--accent); }
.search-bar label { font-size: 0.78em; color: var(--text-muted); white-space: nowrap; }

/* ── Modal ─────────────────────────────────────────────────── */
.modal-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.65);
  z-index: 1000;
  align-items: center;
  justify-content: center;
  padding: 20px;
}
.modal-overlay.open { display: flex; }
.modal {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 28px;
  max-width: 680px;
  width: 100%;
  max-height: 85vh;
  overflow-y: auto;
  box-shadow: var(--shadow);
  position: relative;
}
.modal-close {
  position: absolute;
  top: 16px; right: 16px;
  background: var(--surface-alt);
  border: 1px solid var(--border);
  border-radius: 50%;
  width: 32px; height: 32px;
  cursor: pointer;
  font-size: 1em;
  color: var(--text-muted);
  display: flex; align-items: center; justify-content: center;
  transition: all var(--transition);
}
.modal-close:hover { color: var(--text); border-color: var(--danger); }
.modal h2 {
  font-family: 'Space Grotesk', sans-serif;
  font-size: 1.1em;
  margin: 0 0 18px;
  color: var(--text);
}

/* ── Summary stats grid (inside modal) ─────────────────────── */
.summary-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
  gap: 10px;
  margin-bottom: 18px;
}
.summary-stat {
  background: var(--surface-alt);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 12px;
  text-align: center;
}
.summary-stat .label { font-size: 0.70em; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.05em; }
.summary-stat .value { font-size: 1.5em; font-weight: 600; font-family: 'JetBrains Mono', monospace; color: var(--accent); margin-top: 4px; }
.summary-stat.info  .value { color: var(--info); }
.summary-stat.warn  .value { color: var(--warn); }
.summary-stat.ok    .value { color: var(--accent); }

/* ── Utility ────────────────────────────────────────────────────────────── */
.mono { font-family: 'JetBrains Mono', monospace; }
.container { max-width: 860px; margin: auto; }
.container-wide { max-width: 960px; margin: auto; }

/* ── Offline banner ─────────────────────────────────────────────────────── */
.offline-banner {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  background: var(--danger-soft);
  border: 1px solid var(--danger);
  color: var(--danger);
  border-radius: var(--radius-sm);
  padding: 9px 14px;
  margin: 8px 0;
  font-size: 0.85em;
  font-weight: 600;
  animation: offlinePulse 2s ease-in-out infinite;
}
@keyframes offlinePulse {
  0%, 100% { opacity: 1; }
  50%       { opacity: 0.65; }
}

/* ── Phone status bar ───────────────────────────────────────────────────── */
.phone-status-bar {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 14px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--surface);
  font-size: 0.82em;
  margin: 8px 0;
  flex-wrap: wrap;
  transition: background var(--transition), border-color var(--transition);
}
.phone-status-bar .ps-dot   { font-size: 0.9em; }
.phone-status-bar .ps-label { font-weight: 600; color: var(--text); }
.phone-status-bar .ps-state { font-family: 'JetBrains Mono', monospace; font-size: 0.9em; }

/* State colours */
.ps-online  { border-color: var(--accent);  background: var(--accent-soft); }
.ps-online  .ps-state { color: var(--accent); }
.ps-idle    { border-color: var(--warn);    background: var(--warn-soft); }
.ps-idle    .ps-state { color: var(--warn); }
.ps-offline { border-color: var(--danger);  background: var(--danger-soft); }
.ps-offline .ps-state { color: var(--danger); }
.ps-unknown { border-color: var(--border);  background: var(--surface); }
.ps-unknown .ps-state { color: var(--text-muted); }

/* Chips (battery, signal, last-seen) */
.ps-chip {
  background: var(--surface-alt);
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 2px 9px;
  font-family: 'JetBrains Mono', monospace;
  font-size: 0.88em;
  color: var(--text-muted);
}
.ps-chip.ps-muted { opacity: 0.7; }
.ps-chip.ps-low-bat {
  border-color: var(--danger);
  color: var(--danger);
  animation: lowBatPulse 1.5s ease-in-out infinite;
}
@keyframes lowBatPulse {
  0%, 100% { opacity: 1; }
  50%       { opacity: 0.45; }
}

/* ── Footer Signature ───────────────────────────────────────────────────── */
.footer-signature {
  display: flex;
  align-items: center;
  justify-content: center;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 40px;
  padding: 20px 0;
  font-size: 0.75em;
  color: var(--text-muted);
  border-top: 1px dashed var(--border);
  font-family: 'JetBrains Mono', monospace;
  letter-spacing: 0.05em;
}
.footer-signature span {
  white-space: nowrap;
}
.footer-signature strong {
  color: var(--accent);
  font-weight: 600;
}
.footer-signature .dot {
  opacity: 0.5;
}

/* ── Toast Notifications ───────────────────────────────────── */
#toast-container {
  position: fixed;
  bottom: 20px;
  right: 20px;
  z-index: 9999;
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.toast {
  background: var(--surface-alt);
  color: var(--text);
  padding: 12px 20px;
  border-radius: var(--radius-sm);
  border-left: 4px solid var(--accent);
  box-shadow: 0 4px 15px rgba(0,0,0,0.3);
  font-size: 0.9em;
  font-weight: 500;
  display: flex;
  align-items: center;
  gap: 8px;
  opacity: 0;
  transform: translateX(100%);
  animation: slideInToast 0.3s forwards ease-out;
}
.toast.toast-error {
  border-left-color: var(--danger);
}
.toast.toast-hiding {
  animation: slideOutToast 0.3s forwards ease-in;
}
@keyframes slideInToast {
  to { opacity: 1; transform: translateX(0); }
}
@keyframes slideOutToast {
  to { opacity: 0; transform: translateX(100%); }
}

/* ── Micro-Animations ──────────────────────────────────────── */
.message-card {
  transition: transform 0.2s ease, opacity 0.2s ease, box-shadow 0.2s ease;
}
.message-card:hover {
  transform: translateY(-2px);
  box-shadow: 0 8px 24px rgba(0,0,0,0.2);
}
.message-card.hiding {
  opacity: 0;
  transform: scale(0.95);
}
.new-pulse {
  animation: newMsgPulse 2s infinite;
}
@keyframes newMsgPulse {
  0% { box-shadow: 0 0 0 0 rgba(47,212,140,0.4); }
  70% { box-shadow: 0 0 0 10px rgba(47,212,140,0); }
  100% { box-shadow: 0 0 0 0 rgba(47,212,140,0); }
}

/* ── Duplicate Stacking ────────────────────────────────────── */
.duplicate-stack {
  position: relative;
  margin-bottom: 12px;
}
.duplicate-stack .message-card:not(:first-child) {
  display: none;
}
.duplicate-stack.expanded .message-card:not(:first-child) {
  display: flex; /* Reverts to original layout */
  margin-top: -10px; /* Slight overlap or margin */
  border-top-left-radius: 0;
  border-top-right-radius: 0;
  border-top: 1px dashed var(--border);
  opacity: 0.8;
}
.stack-badge {
  position: absolute;
  top: -12px;
  right: -10px;
  background: var(--warn);
  color: #000;
  border-radius: 20px;
  padding: 4px 12px;
  font-size: 0.75em;
  font-weight: 700;
  cursor: pointer;
  z-index: 10;
  box-shadow: 0 4px 12px rgba(0,0,0,0.3);
  transition: transform 0.2s;
}
.stack-badge:hover {
  transform: translateY(-2px);
}
.duplicate-stack.expanded .stack-badge {
  background: var(--surface-alt);
  color: var(--text-muted);
  border: 1px solid var(--border);
}
