/* BTMesh — style.css */

/* ───────────────────────────── Reset & tokens ─────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg:        #0a0a0a;
  --bg2:       #111111;
  --bg3:       #181818;
  --bg4:       #222222;
  --border:    #2a2a2a;
  --accent:    #00e676;
  --accent-d:  #00b85c;
  --text:      #e8e8e8;
  --text-dim:  #888888;
  --text-dimmer: #555;
  --danger:    #ff4444;
  --warn:      #ffaa00;
  --sidebar-w: 240px;
  --header-h:  52px;
  --input-h:   56px;
  --radius:    10px;
  --font:      'SF Mono', 'Fira Code', 'Consolas', 'Courier New', monospace;
}

html, body {
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 13px;
  line-height: 1.5;
  overflow: hidden;
}

/* ───────────────────────────── Screens ─────────────────────────────────── */
.screen { display: none; width: 100%; height: 100%; }
.screen.active { display: flex; }

/* ───────────────────────────── Setup screen ─────────────────────────────── */
#setup-screen {
  align-items: center;
  justify-content: center;
  padding: 24px;
  background:
    radial-gradient(ellipse 60% 50% at 50% 0%, rgba(0,230,118,.08) 0%, transparent 70%),
    var(--bg);
}

.setup-wrap {
  width: 100%;
  max-width: 420px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 32px;
}

.setup-logo {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
}

.logo-ring {
  width: 80px;
  height: 80px;
  animation: spin-slow 20s linear infinite;
}

@keyframes spin-slow { to { transform: rotate(360deg); } }

.setup-logo h1 {
  font-size: 2rem;
  font-weight: 700;
  letter-spacing: 0.1em;
  color: var(--accent);
}

.tagline {
  color: var(--text-dim);
  font-size: 11px;
  text-align: center;
}

.setup-form {
  width: 100%;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.field-label {
  color: var(--text-dim);
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

input[type="text"] {
  width: 100%;
  padding: 12px 14px;
  background: var(--bg3);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  font-family: var(--font);
  font-size: 14px;
  outline: none;
  transition: border-color 0.15s;
}
input[type="text"]:focus { border-color: var(--accent); }

.btn-primary {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 13px 20px;
  background: var(--accent);
  color: #000;
  border: none;
  border-radius: var(--radius);
  font-family: var(--font);
  font-size: 13px;
  font-weight: 700;
  cursor: pointer;
  transition: background 0.15s, transform 0.1s;
}
.btn-primary:hover  { background: var(--accent-d); }
.btn-primary:active { transform: scale(0.98); }
.btn-primary:disabled { opacity: 0.5; cursor: default; }

.btn-ghost {
  padding: 10px 16px;
  background: transparent;
  color: var(--text-dim);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-family: var(--font);
  font-size: 12px;
  cursor: pointer;
  transition: border-color 0.15s;
}
.btn-ghost:hover { border-color: var(--text-dim); }

.setup-note {
  color: var(--text-dimmer);
  font-size: 11px;
  line-height: 1.6;
  text-align: center;
}
.setup-note strong { color: var(--accent); }

.setup-info {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  justify-content: center;
}

.info-pill {
  padding: 4px 10px;
  background: var(--bg3);
  border: 1px solid var(--border);
  border-radius: 999px;
  font-size: 11px;
  color: var(--text-dim);
}

/* ───────────────────────────── App screen layout ─────────────────────────── */
#app-screen {
  flex-direction: row;
  height: 100%;
  overflow: hidden;
}

/* ───────────────────────────── Sidebar ─────────────────────────────────── */
#sidebar-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.6);
  z-index: 90;
}

#sidebar {
  width: var(--sidebar-w);
  height: 100%;
  background: var(--bg2);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
  z-index: 100;
}

.sidebar-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 14px;
  border-bottom: 1px solid var(--border);
  height: var(--header-h);
}

.my-identity {
  display: flex;
  align-items: center;
  gap: 7px;
  font-size: 13px;
  font-weight: 600;
  color: var(--accent);
  overflow: hidden;
}
.my-identity span:last-child { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.sidebar-nav {
  flex: 1;
  overflow-y: auto;
  padding: 10px 0;
}
.sidebar-nav::-webkit-scrollbar { width: 4px; }
.sidebar-nav::-webkit-scrollbar-thumb { background: var(--border); border-radius: 2px; }

.nav-section-label {
  padding: 10px 14px 4px;
  font-size: 10px;
  font-weight: 700;
  color: var(--text-dimmer);
  letter-spacing: 0.1em;
  text-transform: uppercase;
}

.channel-item, .peer-item {
  display: flex;
  align-items: center;
  gap: 7px;
  padding: 7px 14px;
  cursor: pointer;
  border-radius: 6px;
  margin: 1px 6px;
  transition: background 0.1s;
  color: var(--text-dim);
  font-size: 13px;
  user-select: none;
}
.channel-item:hover, .peer-item:hover { background: var(--bg3); color: var(--text); }
.channel-item.active, .peer-item.active {
  background: rgba(0,230,118,.12);
  color: var(--accent);
}

.channel-hash { color: var(--text-dimmer); font-weight: 700; }
.channel-name { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.peer-name    { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.badge {
  background: var(--accent);
  color: #000;
  font-size: 10px;
  font-weight: 700;
  padding: 1px 6px;
  border-radius: 999px;
  min-width: 18px;
  text-align: center;
  flex-shrink: 0;
}

.sidebar-footer {
  padding: 12px;
  border-top: 1px solid var(--border);
}

.btn-scan {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 9px;
  background: transparent;
  border: 1px dashed var(--border);
  border-radius: var(--radius);
  color: var(--text-dim);
  font-family: var(--font);
  font-size: 12px;
  cursor: pointer;
  transition: border-color 0.15s, color 0.15s;
}
.btn-scan:hover { border-color: var(--accent); color: var(--accent); }
.btn-scan span  { font-size: 16px; line-height: 1; }

/* ───────────────────────────── Main content ─────────────────────────────── */
#main-content {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  min-width: 0;
}

/* Header */
#chat-header {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 0 16px;
  height: var(--header-h);
  border-bottom: 1px solid var(--border);
  background: var(--bg2);
  flex-shrink: 0;
}

.sidebar-toggle { display: none; }

.header-titles {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
}

#chat-title {
  font-size: 14px;
  font-weight: 700;
  color: var(--text);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

#chat-subtitle {
  font-size: 11px;
  color: var(--text-dimmer);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

#ble-status {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-shrink: 0;
  font-size: 11px;
  color: var(--text-dim);
}

/* Messages */
#messages-container {
  flex: 1;
  overflow-y: auto;
  padding: 16px 0 8px;
  display: flex;
  flex-direction: column;
}
#messages-container::-webkit-scrollbar { width: 4px; }
#messages-container::-webkit-scrollbar-thumb { background: var(--border); border-radius: 2px; }

#messages-list {
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding: 0 12px;
  min-height: 100%;
  justify-content: flex-end;
}

/* Message bubbles */
.msg-wrap {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  max-width: 72%;
  gap: 3px;
}
.msg-wrap.own { align-self: flex-end; align-items: flex-end; }

.msg-meta {
  display: flex;
  align-items: baseline;
  gap: 6px;
  padding: 0 4px;
}
.msg-wrap.own .msg-meta { flex-direction: row-reverse; }

.msg-sender { font-size: 11px; font-weight: 700; color: var(--accent); }
.msg-wrap.own .msg-sender { color: var(--accent-d); }
.msg-time   { font-size: 10px; color: var(--text-dimmer); }

.msg-bubble {
  background: var(--bg3);
  border: 1px solid var(--border);
  border-radius: 14px 14px 14px 4px;
  padding: 9px 13px;
  font-size: 13px;
  line-height: 1.5;
  word-break: break-word;
  max-width: 100%;
}
.msg-wrap.own .msg-bubble {
  background: rgba(0,230,118,.12);
  border-color: rgba(0,230,118,.25);
  border-radius: 14px 14px 4px 14px;
}

/* Image messages */
.msg-image-wrap { padding: 8px; }
.msg-image {
  max-width: 280px;
  max-height: 280px;
  border-radius: 8px;
  display: block;
  cursor: zoom-in;
  object-fit: cover;
}
.msg-filename {
  font-size: 10px;
  color: var(--text-dimmer);
  margin-top: 4px;
}

/* File attachment */
.msg-file {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 14px;
}
.file-ico     { font-size: 20px; flex-shrink: 0; }
.file-details { flex: 1; min-width: 0; }
.file-name    { display: block; font-size: 12px; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.file-sz      { display: block; font-size: 10px; color: var(--text-dimmer); }
.file-dl {
  flex-shrink: 0;
  padding: 5px 10px;
  background: var(--accent);
  color: #000;
  text-decoration: none;
  border-radius: 6px;
  font-size: 11px;
  font-weight: 700;
}

.send-progress {
  font-size: 10px;
  color: var(--accent);
  margin-top: 4px;
}

/* System messages */
.sys-msg {
  text-align: center;
  font-size: 11px;
  color: var(--text-dimmer);
  padding: 6px 0;
  font-style: italic;
}

/* Input area */
#input-area {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 12px;
  border-top: 1px solid var(--border);
  background: var(--bg2);
  flex-shrink: 0;
  min-height: var(--input-h);
}

#input-area input[type="text"] {
  flex: 1;
  padding: 10px 14px;
  border-radius: 20px;
  font-size: 13px;
}

.icon-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  background: transparent;
  border: none;
  border-radius: 8px;
  color: var(--text-dim);
  font-size: 16px;
  cursor: pointer;
  transition: background 0.1s, color 0.1s;
  flex-shrink: 0;
}
.icon-btn:hover { background: var(--bg3); color: var(--text); }

.btn-send {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  background: var(--accent);
  border: none;
  border-radius: 50%;
  color: #000;
  cursor: pointer;
  flex-shrink: 0;
  transition: background 0.15s, transform 0.1s;
}
.btn-send:hover  { background: var(--accent-d); }
.btn-send:active { transform: scale(0.9); }

/* Status dots */
.status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  flex-shrink: 0;
}
.status-dot.online   { background: var(--accent); box-shadow: 0 0 0 2px rgba(0,230,118,.2); }
.status-dot.offline  { background: var(--text-dimmer); }
.status-dot.scanning { background: var(--warn); animation: pulse 1.5s ease-in-out infinite; }

@keyframes pulse {
  0%, 100% { opacity: 1; }
  50%       { opacity: 0.3; }
}

/* ───────────────────────────── File modal ─────────────────────────────── */
#file-modal {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.75);
  align-items: center;
  justify-content: center;
  z-index: 200;
  padding: 20px;
}
#file-modal.open { display: flex; }

.modal-box {
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: 14px;
  width: 100%;
  max-width: 420px;
  display: flex;
  flex-direction: column;
  gap: 16px;
  padding: 20px;
  max-height: 90vh;
  overflow-y: auto;
}

.modal-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
}
.modal-title { font-size: 14px; font-weight: 700; word-break: break-all; }
.modal-sub   { font-size: 11px; color: var(--text-dim); margin-top: 2px; }

#file-preview {
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg3);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  min-height: 100px;
}

.preview-img {
  max-width: 100%;
  max-height: 240px;
  border-radius: 8px;
  object-fit: contain;
}

.file-icon-big { font-size: 48px; }

.modal-dest {
  font-size: 11px;
  color: var(--text-dim);
  text-align: center;
}

.modal-actions {
  display: flex;
  gap: 10px;
}
.modal-actions .btn-primary { flex: 1; }

/* ───────────────────────────── Toasts ─────────────────────────────────── */
#toast-container {
  position: fixed;
  bottom: 20px;
  right: 20px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  z-index: 300;
  pointer-events: none;
}

.toast {
  padding: 10px 16px;
  border-radius: var(--radius);
  font-size: 12px;
  max-width: 320px;
  opacity: 0;
  transform: translateX(20px);
  transition: opacity 0.25s, transform 0.25s;
  pointer-events: auto;
}
.toast.show      { opacity: 1; transform: none; }
.toast.info      { background: var(--bg3); border: 1px solid var(--border); }
.toast.error     { background: #2a0000; border: 1px solid var(--danger); color: var(--danger); }
.toast.warn      { background: #2a1800; border: 1px solid var(--warn); color: var(--warn); }

.banner {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  padding: 10px 20px;
  font-size: 12px;
  z-index: 400;
  text-align: center;
}
.banner.warn { background: #2a1800; color: var(--warn); border-bottom: 1px solid var(--warn); }

/* ───────────────────────────── Mobile (≤ 700px) ─────────────────────────── */
@media (max-width: 700px) {
  #sidebar {
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    transform: translateX(-100%);
    transition: transform 0.25s ease;
  }
  #sidebar.open { transform: translateX(0); }
  #sidebar-overlay.open { display: block; }

  .sidebar-toggle { display: flex; }

  .msg-wrap { max-width: 88%; }
  .msg-image { max-width: 220px; max-height: 220px; }

  #toast-container { right: 12px; bottom: 12px; }
}
