@import url('variables.css');

/* ============ Reset ============ */
*, *::before, *::after { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  font-family: var(--font-body);
  font-size: var(--fs-base);
  color: var(--text-primary);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
  overflow: hidden;
}
img { max-width: 100%; display: block; }
button { font-family: inherit; }
a { color: inherit; }
::selection { background: var(--accent); color: var(--accent-contrast); }

/* scrollbars */
* { scrollbar-width: thin; scrollbar-color: var(--border-strong) transparent; }
*::-webkit-scrollbar { width: 6px; height: 6px; }
*::-webkit-scrollbar-thumb { background: var(--border-strong); border-radius: 4px; }

/* ============ App shell ============ */
#app {
  height: 100dvh;
  display: grid;
  grid-template-columns: var(--sidebar-w) 1fr;
  background: var(--bg);
}
@media (max-width: 860px) {
  #app { grid-template-columns: 1fr; }
  #app[data-pane="list"] .pane-detail { display: none; }
  #app[data-pane="detail"] .pane-list { display: none; }
}

.pane-list {
  background: var(--bg-elevated);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  min-width: 0;
}
.pane-detail {
  display: flex;
  flex-direction: column;
  min-width: 0;
  background: var(--bg);
  position: relative;
}

/* ============ Topbar ============ */
.topbar {
  height: var(--topbar-h);
  min-height: var(--topbar-h);
  display: flex;
  align-items: center;
  gap: var(--sp-3);
  padding: 0 var(--sp-4);
  padding-top: var(--safe-top);
  border-bottom: 1px solid var(--border);
  background: var(--bg-elevated);
}
.brand {
  display: flex;
  align-items: center;
  gap: var(--sp-2);
  font-family: var(--font-display);
  font-weight: 600;
  font-size: var(--fs-lg);
  letter-spacing: 0.2px;
}
.brand .mark { width: 28px; height: 28px; border-radius: var(--r-sm); }
.brand small {
  display: block;
  font-family: var(--font-body);
  font-size: 10px;
  font-weight: 500;
  letter-spacing: 0.6px;
  text-transform: uppercase;
  color: var(--text-muted);
}

/* ============ Nav rail (icons) ============ */
.rail {
  display: flex;
  gap: var(--sp-1);
  padding: var(--sp-2) var(--sp-3);
  border-bottom: 1px solid var(--border);
  overflow-x: auto;
}
.rail-btn {
  display: flex; align-items: center; gap: var(--sp-1);
  border: none; background: transparent; color: var(--text-secondary);
  padding: var(--sp-2) var(--sp-3); border-radius: var(--r-full);
  font-size: var(--fs-sm); font-weight: 600; cursor: pointer;
  white-space: nowrap;
  transition: background var(--dur-fast) var(--ease), color var(--dur-fast) var(--ease);
}
.rail-btn:hover { background: var(--bg-surface-2); color: var(--text-primary); }
.rail-btn.active { background: var(--accent); color: var(--accent-contrast); }
.rail-btn svg { width: 16px; height: 16px; }

/* ============ Search ============ */
.search-box {
  margin: var(--sp-3);
  display: flex; align-items: center; gap: var(--sp-2);
  background: var(--bg-surface); border: 1px solid var(--border);
  border-radius: var(--r-full); padding: var(--sp-2) var(--sp-3);
}
.search-box input {
  border: none; background: transparent; outline: none; color: var(--text-primary);
  font-size: var(--fs-sm); width: 100%;
}
.search-box svg { width: 16px; height: 16px; color: var(--text-muted); flex-shrink: 0; }

/* ============ Conversation list ============ */
.list-scroll { flex: 1; overflow-y: auto; padding-bottom: var(--sp-5); }
.conv-item {
  display: flex; align-items: center; gap: var(--sp-3);
  padding: var(--sp-3) var(--sp-4);
  cursor: pointer; border: none; background: transparent; width: 100%; text-align: left;
  border-left: 3px solid transparent;
  transition: background var(--dur-fast) var(--ease);
}
.conv-item:hover { background: var(--bg-surface); }
.conv-item.active { background: var(--bg-surface); border-left-color: var(--accent); }
.avatar {
  width: 44px; height: 44px; border-radius: var(--r-full);
  display: flex; align-items: center; justify-content: center;
  font-weight: 700; font-size: var(--fs-sm); color: var(--accent-contrast);
  background: linear-gradient(135deg, var(--gold-500), var(--clay-500));
  flex-shrink: 0; position: relative;
}
.avatar.node { background: linear-gradient(135deg, var(--info-500), var(--indigo-700)); }
.presence-dot {
  position: absolute; bottom: -1px; right: -1px; width: 12px; height: 12px;
  border-radius: 50%; border: 2px solid var(--bg-elevated);
}
.presence-dot.online { background: var(--success-500); }
.presence-dot.mesh { background: var(--gold-500); }
.presence-dot.offline { background: var(--text-muted); }
.conv-meta { flex: 1; min-width: 0; }
.conv-top { display: flex; justify-content: space-between; gap: var(--sp-2); }
.conv-name { font-weight: 600; font-size: var(--fs-sm); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.conv-time { font-size: 11px; color: var(--text-muted); flex-shrink: 0; }
.conv-preview { display: flex; justify-content: space-between; gap: var(--sp-2); margin-top: 2px; }
.conv-snippet { font-size: var(--fs-xs); color: var(--text-secondary); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.badge {
  min-width: 18px; height: 18px; padding: 0 5px; border-radius: var(--r-full);
  background: var(--accent); color: var(--accent-contrast); font-size: 10px; font-weight: 700;
  display: flex; align-items: center; justify-content: center; flex-shrink: 0;
}
.chip {
  font-size: 9px; font-weight: 700; letter-spacing: 0.4px; text-transform: uppercase;
  padding: 1px 6px; border-radius: var(--r-full); color: var(--text-muted); border: 1px solid var(--border-strong);
}

/* ============ Empty states ============ */
.empty-state {
  flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center;
  text-align: center; padding: var(--sp-7); color: var(--text-secondary); gap: var(--sp-3);
}
.empty-state .glyph { width: 88px; height: 88px; opacity: 0.9; margin-bottom: var(--sp-2); }
.empty-state h2 { font-family: var(--font-display); color: var(--text-primary); font-size: var(--fs-lg); margin: 0; }
.empty-state p { max-width: 360px; margin: 0; font-size: var(--fs-sm); }

/* ============ Chat header ============ */
.chat-header {
  height: var(--topbar-h); min-height: var(--topbar-h);
  display: flex; align-items: center; gap: var(--sp-3);
  padding: 0 var(--sp-4); padding-top: var(--safe-top);
  border-bottom: 1px solid var(--border); background: var(--bg-elevated);
}
.chat-header .who { flex: 1; min-width: 0; }
.chat-header .who .name { font-weight: 700; font-size: var(--fs-sm); }
.chat-header .who .status { font-size: 11px; color: var(--text-muted); }
.icon-btn {
  width: 36px; height: 36px; border-radius: var(--r-full); border: none;
  background: transparent; color: var(--text-secondary); display: flex; align-items: center; justify-content: center;
  cursor: pointer; transition: background var(--dur-fast) var(--ease);
}
.icon-btn:hover { background: var(--bg-surface-2); color: var(--text-primary); }
.icon-btn svg { width: 19px; height: 19px; }
.back-btn { display: none; }
@media (max-width: 860px) { .back-btn { display: flex; } }

/* ============ Messages ============ */
.messages {
  flex: 1; overflow-y: auto; padding: var(--sp-5) var(--sp-5) var(--sp-3);
  display: flex; flex-direction: column; gap: 2px;
}
.day-divider {
  align-self: center; font-size: 11px; color: var(--text-muted);
  background: var(--bg-surface); border: 1px solid var(--border);
  padding: 2px 12px; border-radius: var(--r-full); margin: var(--sp-4) 0;
}
.msg-row { display: flex; margin: 3px 0; max-width: 78%; }
.msg-row.out { align-self: flex-end; justify-content: flex-end; }
.msg-row.in { align-self: flex-start; }
.bubble {
  padding: var(--sp-2) var(--sp-3); border-radius: var(--r-md);
  font-size: var(--fs-base); line-height: 1.42; position: relative;
  box-shadow: var(--shadow-1);
  word-wrap: break-word; white-space: pre-wrap;
}
.msg-row.out .bubble { background: var(--bubble-out); border-bottom-right-radius: 4px; color: var(--text-primary); }
.msg-row.in .bubble { background: var(--bubble-in); border-bottom-left-radius: 4px; border: 1px solid var(--border); }
.bubble .meta {
  display: flex; align-items: center; gap: 4px; justify-content: flex-end;
  font-size: 10px; color: var(--text-muted); margin-top: 4px;
}
.bubble .meta svg { width: 13px; height: 13px; }
.tick.sent { color: var(--text-muted); }
.tick.delivered { color: var(--text-secondary); }
.tick.read { color: var(--info-500); }
.tick.mesh { color: var(--gold-500); }
.bubble.system {
  background: transparent; border: 1px dashed var(--border-strong); color: var(--text-muted);
  align-self: center; font-size: var(--fs-xs); text-align: center;
}
.route-badge {
  display: inline-flex; align-items: center; gap: 3px; font-size: 9px; font-weight: 700;
  letter-spacing: 0.3px; text-transform: uppercase; color: var(--text-muted); margin-top: 3px;
}
.route-badge svg { width: 11px; height: 11px; }

/* voice note bubble */
.voice-note { display: flex; align-items: center; gap: var(--sp-2); min-width: 200px; }
.voice-note .play-btn {
  width: 34px; height: 34px; border-radius: 50%; border: none; background: var(--accent);
  color: var(--accent-contrast); flex-shrink: 0; display: flex; align-items: center; justify-content: center; cursor: pointer;
}
.voice-note .wave { flex: 1; height: 24px; display: flex; align-items: center; gap: 2px; }
.voice-note .wave span { width: 2px; background: currentColor; opacity: 0.5; border-radius: 2px; }

/* file bubble */
.file-card { display: flex; align-items: center; gap: var(--sp-2); min-width: 220px; }
.file-icon { width: 38px; height: 38px; border-radius: var(--r-sm); background: var(--bg-surface-2); display: flex; align-items: center; justify-content: center; flex-shrink: 0; }
.file-info { min-width: 0; }
.file-name { font-size: var(--fs-sm); font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.file-sub { font-size: 11px; color: var(--text-muted); }

/* image bubble */
.img-bubble { border-radius: var(--r-md); overflow: hidden; max-width: 260px; cursor: pointer; }
.img-bubble img { width: 100%; display: block; }

/* ============ Composer ============ */
.composer {
  display: flex; align-items: flex-end; gap: var(--sp-2);
  padding: var(--sp-3) var(--sp-4);
  padding-bottom: calc(var(--sp-3) + var(--safe-bottom));
  border-top: 1px solid var(--border); background: var(--bg-elevated);
}
.composer-input {
  flex: 1; min-height: 40px; max-height: 140px; overflow-y: auto;
  border-radius: var(--r-lg); border: 1px solid var(--border);
  background: var(--bg-surface); padding: var(--sp-2) var(--sp-4);
  font-size: var(--fs-base); color: var(--text-primary); outline: none;
  line-height: 1.4;
}
.composer-input:empty::before { content: attr(data-placeholder); color: var(--text-muted); }
.send-btn {
  width: 42px; height: 42px; border-radius: 50%; border: none; background: var(--accent);
  color: var(--accent-contrast); display: flex; align-items: center; justify-content: center;
  cursor: pointer; flex-shrink: 0; transition: transform var(--dur-fast) var(--ease);
}
.send-btn:active { transform: scale(0.92); }
.send-btn svg { width: 19px; height: 19px; }
.mic-btn.recording { background: var(--danger-500); animation: pulse 1.2s infinite; }
@keyframes pulse { 0%,100%{ box-shadow: 0 0 0 0 rgba(214,69,69,0.5);} 50%{ box-shadow: 0 0 0 8px rgba(214,69,69,0);} }

/* ============ Buttons / forms (generic) ============ */
.btn {
  border: none; border-radius: var(--r-full); padding: var(--sp-3) var(--sp-5);
  font-weight: 700; font-size: var(--fs-sm); cursor: pointer;
  transition: transform var(--dur-fast) var(--ease), background var(--dur-fast) var(--ease);
}
.btn-primary { background: var(--accent); color: var(--accent-contrast); }
.btn-primary:hover { transform: translateY(-1px); }
.btn-ghost { background: transparent; color: var(--text-primary); border: 1px solid var(--border-strong); }
.btn-danger { background: var(--danger-500); color: #fff; }
.btn-block { width: 100%; }
.field { display: flex; flex-direction: column; gap: 6px; margin-bottom: var(--sp-4); }
.field label { font-size: var(--fs-xs); font-weight: 600; color: var(--text-secondary); }
.field input, .field textarea, .field select {
  background: var(--bg-surface); border: 1px solid var(--border); border-radius: var(--r-md);
  padding: var(--sp-3); color: var(--text-primary); font-size: var(--fs-base); outline: none;
  font-family: inherit;
}
.field input:focus, .field textarea:focus, .field select:focus { box-shadow: var(--focus-ring); border-color: var(--accent); }
.hint { font-size: 11px; color: var(--text-muted); }

/* ============ Modal / sheet ============ */
.overlay {
  position: fixed; inset: 0; background: rgba(0,0,0,0.5);
  display: flex; align-items: center; justify-content: center; z-index: 100;
  backdrop-filter: blur(2px);
}
.modal {
  background: var(--bg-elevated); border-radius: var(--r-lg); width: min(440px, 92vw);
  max-height: 88vh; overflow-y: auto; box-shadow: var(--shadow-lift); border: 1px solid var(--border);
}
.modal-header { display: flex; align-items: center; justify-content: space-between; padding: var(--sp-5) var(--sp-5) var(--sp-3); }
.modal-header h3 { margin: 0; font-family: var(--font-display); font-size: var(--fs-lg); }
.modal-body { padding: 0 var(--sp-5) var(--sp-5); }
@media (max-width: 560px) {
  .overlay { align-items: flex-end; }
  .modal { width: 100%; border-radius: var(--r-lg) var(--r-lg) 0 0; max-height: 92vh; }
}

/* ============ Toast ============ */
#toast-root { position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%); z-index: 200; display: flex; flex-direction: column; gap: 8px; }
.toast {
  background: var(--bg-surface); color: var(--text-primary); border: 1px solid var(--border-strong);
  padding: 10px 18px; border-radius: var(--r-full); box-shadow: var(--shadow-2); font-size: var(--fs-sm);
  animation: toast-in var(--dur-slow) var(--ease);
}
@keyframes toast-in { from { opacity: 0; transform: translateY(8px);} to { opacity: 1; transform: translateY(0);} }

/* ============ Identity / onboarding ============ */
.onboard-screen {
  height: 100dvh; width: 100%; display: flex; align-items: center; justify-content: center;
  background:
    radial-gradient(circle at 15% 20%, rgba(232,169,60,0.10), transparent 45%),
    radial-gradient(circle at 85% 80%, rgba(196,98,45,0.10), transparent 45%),
    var(--indigo-950);
  padding: var(--sp-5); position: relative; overflow: hidden;
}
.onboard-card {
  width: min(460px, 100%); background: var(--indigo-900); border: 1px solid var(--border);
  border-radius: var(--r-lg); padding: var(--sp-7) var(--sp-6); box-shadow: var(--shadow-lift);
  position: relative; z-index: 1;
}
.onboard-card .wordmark { display: flex; align-items: center; gap: var(--sp-3); margin-bottom: var(--sp-5); }
.onboard-card .wordmark img { width: 44px; height: 44px; }
.onboard-card .wordmark h1 { font-family: var(--font-display); font-size: var(--fs-2xl); margin: 0; color: var(--cloth-100); }
.onboard-card .tagline { color: rgba(247,243,234,0.7); font-size: var(--fs-sm); margin: 0 0 var(--sp-6); }
.identity-preview {
  display: flex; align-items: center; gap: var(--sp-3); background: var(--indigo-850);
  border: 1px solid var(--border); border-radius: var(--r-md); padding: var(--sp-3); margin-bottom: var(--sp-5);
}
.identity-preview code { font-family: var(--font-mono); color: var(--gold-300); font-size: var(--fs-md); }
.step-dots { display: flex; gap: 6px; justify-content: center; margin-top: var(--sp-5); }
.step-dots span { width: 6px; height: 6px; border-radius: 50%; background: var(--border-strong); }
.step-dots span.active { background: var(--gold-500); width: 18px; border-radius: 4px; }

/* ============ Settings / lists ============ */
.settings-section { margin-bottom: var(--sp-6); }
.settings-section h4 {
  font-size: 11px; text-transform: uppercase; letter-spacing: 0.6px; color: var(--text-muted);
  margin: 0 0 var(--sp-2) var(--sp-4);
}
.settings-row {
  display: flex; align-items: center; gap: var(--sp-3); padding: var(--sp-3) var(--sp-4);
  background: var(--bg-surface); cursor: pointer;
}
.settings-row:first-child { border-radius: var(--r-md) var(--r-md) 0 0; }
.settings-row:last-child { border-radius: 0 0 var(--r-md) var(--r-md); }
.settings-row + .settings-row { border-top: 1px solid var(--border); }
.settings-row .label { flex: 1; font-size: var(--fs-sm); font-weight: 500; }
.settings-row .value { font-size: var(--fs-xs); color: var(--text-muted); }

/* toggle switch */
.switch { position: relative; width: 42px; height: 24px; flex-shrink: 0; }
.switch input { opacity: 0; width: 0; height: 0; }
.switch .track {
  position: absolute; inset: 0; background: var(--bg-surface-2); border-radius: var(--r-full);
  transition: background var(--dur-base) var(--ease); border: 1px solid var(--border-strong);
}
.switch .track::before {
  content: ""; position: absolute; width: 18px; height: 18px; left: 2px; top: 2px;
  background: var(--cloth-100); border-radius: 50%; transition: transform var(--dur-base) var(--ease);
  box-shadow: var(--shadow-1);
}
.switch input:checked + .track { background: var(--accent); }
.switch input:checked + .track::before { transform: translateX(18px); }

/* ============ Connectivity strip ============ */
.conn-strip {
  display: flex; align-items: center; gap: 6px; padding: 6px var(--sp-4);
  font-size: 11px; font-weight: 600; border-bottom: 1px solid var(--border);
}
.conn-strip .dot { width: 7px; height: 7px; border-radius: 50%; }
.conn-strip.mode-internet { background: rgba(63,166,107,0.10); color: var(--success-500); }
.conn-strip.mode-internet .dot { background: var(--success-500); }
.conn-strip.mode-mesh { background: rgba(232,169,60,0.10); color: var(--gold-500); }
.conn-strip.mode-mesh .dot { background: var(--gold-500); }
.conn-strip.mode-offline { background: rgba(107,107,107,0.12); color: var(--text-muted); }
.conn-strip.mode-offline .dot { background: var(--text-muted); }

/* ============ Nearby / mesh radar ============ */
.radar-wrap { display: flex; flex-direction: column; align-items: center; padding: var(--sp-6); gap: var(--sp-4); }
.radar {
  width: 220px; height: 220px; border-radius: 50%; position: relative;
  background: radial-gradient(circle, var(--bg-surface) 0%, var(--bg-elevated) 100%);
  border: 1px solid var(--border);
}
.radar .ring { position: absolute; border: 1px solid var(--border-strong); border-radius: 50%; }
.radar .sweep {
  position: absolute; inset: 0; border-radius: 50%;
  background: conic-gradient(from 0deg, rgba(232,169,60,0.35), transparent 70%);
  animation: sweep 3.2s linear infinite;
}
@keyframes sweep { to { transform: rotate(360deg); } }
.radar .node-dot {
  position: absolute; width: 10px; height: 10px; border-radius: 50%; background: var(--gold-500);
  box-shadow: 0 0 0 4px rgba(232,169,60,0.2);
}
.radar .self-dot {
  position: absolute; top: 50%; left: 50%; width: 12px; height: 12px; margin: -6px;
  border-radius: 50%; background: var(--info-500); box-shadow: 0 0 0 6px rgba(78,143,224,0.2);
}

/* ============ Utility ============ */
.hidden { display: none !important; }
.row { display: flex; align-items: center; }
.gap-2 { gap: var(--sp-2); }
.gap-3 { gap: var(--sp-3); }
.text-muted { color: var(--text-muted); }
.mono { font-family: var(--font-mono); }
.skeleton {
  background: linear-gradient(90deg, var(--bg-surface) 25%, var(--bg-surface-2) 37%, var(--bg-surface) 63%);
  background-size: 400% 100%; animation: shimmer 1.4s ease infinite; border-radius: var(--r-sm);
}
@keyframes shimmer { 0% { background-position: 100% 0; } 100% { background-position: -100% 0; } }
