/* ============================================================
   LocalChat — chat.css
   Dark theme Telegram-like + animații subtile + responsive
   ============================================================ */

:root {
  --bg-chat:      #0e1621;
  --bg-sidebar:   #17212b;
  --bubble-in:    #182533;
  --bubble-out:   #2b5278;
  --text:         #ffffff;
  --text-sec:     #708499;
  --accent:       #5eb5f7;
  --accent-dim:   rgba(94, 181, 247, 0.15);
  --hover:        #202b36;
  --border:       #232e3c;
  --danger:       #e57373;
  --radius:       12px;
  --header-h:     56px;
  --sidebar-w:    240px;
  --input-h:      auto;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

/* iOS: elimină așteptarea de double-tap-to-zoom (fix 2-tap bug) */
html { touch-action: manipulation; }

html, body {
  height: 100%;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg-chat);
  color: var(--text);
  font-size: 15px;
  line-height: 1.45;
  overflow: hidden;
}

/* ── Layout ─────────────────────────────────────────────────── */
.app {
  display: grid;
  grid-template-rows: var(--header-h) 1fr;
  grid-template-columns: var(--sidebar-w) 1fr;
  grid-template-areas:
    "header header"
    "sidebar chat";
  height: 100vh;
  height: 100dvh;
}

/* Sidebar colapsat (desktop) — comutat de butonul hamburger */
.app.collapsed {
  grid-template-columns: 1fr;
  grid-template-areas:
    "header"
    "chat";
}
.app.collapsed .sidebar { display: none; }

/* ── Header ─────────────────────────────────────────────────── */
.header {
  grid-area: header;
  display: flex;
  align-items: center;
  flex-wrap: nowrap;
  gap: 8px 10px;
  padding: 6px 12px;
  background: var(--bg-sidebar);
  border-bottom: 1px solid var(--border);
  z-index: 20;
  min-height: var(--header-h);
}

.header .brand {
  font-weight: 700;
  font-size: 17px;
  letter-spacing: 0.2px;
  display: flex;
  align-items: center;
  gap: 8px;
  white-space: nowrap;
}
.header .brand .logo {
  width: 26px; height: 26px;
  border-radius: 8px;
  background: linear-gradient(135deg, var(--accent), #2b5278);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 14px;
}

.header .spacer { flex: 0 0 0; }

.icon-btn {
  background: transparent;
  border: 1px solid transparent;
  color: var(--text-sec);
  width: 38px; height: 38px;
  border-radius: 10px;
  cursor: pointer;
  font-size: 17px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s ease, color 0.15s ease, transform 0.1s ease;
}
.icon-btn:hover { background: var(--hover); color: var(--text); }
.icon-btn:active { transform: scale(0.94); }
.icon-btn.active { color: var(--accent); background: var(--accent-dim); }

/* Hamburger — mai vizibil */
.icon-btn.menu-btn {
  width: 44px; height: 44px;
  color: var(--text);
  background: var(--hover);
  border: 1px solid var(--border);
}
.icon-btn.menu-btn:hover { background: var(--accent-dim); color: var(--accent); border-color: var(--accent); }

.device-label {
  display: flex;
  align-items: center;
  gap: 6px;
  background: var(--hover);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 4px 10px;
  margin-left: auto;
  flex: 0 1 auto;
  min-width: 0;
  max-width: 220px;
}
.device-label .tag { color: var(--text-sec); font-size: 13px; }
.device-label input {
  background: transparent;
  border: none;
  outline: none;
  color: var(--text);
  font-size: 16px; /* ≥16px: iOS Safari nu face auto-zoom la focus */
  width: 100%;
  min-width: 0;
  font-family: inherit;
}
.device-label input::placeholder { color: var(--text-sec); }

/* ── Sidebar ────────────────────────────────────────────────── */
.sidebar {
  grid-area: sidebar;
  background: var(--bg-sidebar);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
.sidebar .side-title {
  padding: 14px 16px 8px;
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 1px;
  color: var(--text-sec);
  font-weight: 600;
}
.channel-list {
  list-style: none;
  flex: 1;
  overflow-y: auto;
  padding: 0 8px;
}
.channel-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 9px 12px;
  border-radius: 10px;
  cursor: pointer;
  color: var(--text-sec);
  transition: background 0.18s ease, color 0.18s ease;
  position: relative;
  animation: slideIn 0.22s ease-out;
}
.channel-item:hover { background: var(--hover); color: var(--text); }
.channel-item.active {
  background: var(--accent-dim);
  color: var(--accent);
  font-weight: 600;
}
.channel-item .hash { opacity: 0.7; }
.channel-item .ch-name { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.channel-item .del {
  opacity: 0;
  border: none;
  background: transparent;
  color: var(--text-sec);
  cursor: pointer;
  font-size: 14px;
  padding: 2px 4px;
  border-radius: 6px;
  transition: opacity 0.15s, color 0.15s, background 0.15s;
}
.channel-item:hover .del { opacity: 0.8; }
.channel-item .del:hover { color: var(--danger); background: rgba(229,115,115,0.12); }

/* contor mesaje + fișiere pe canal (iconiță + cifră) */
.channel-item .counts {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-size: 11px;
  color: var(--text-sec);
  white-space: nowrap;
  flex-shrink: 0;
}
.channel-item .counts .cnt {
  display: inline-flex;
  align-items: center;
  gap: 3px;
}
.channel-item .counts .cnt svg { opacity: 0.75; flex-shrink: 0; }
.channel-item .counts .cnt b { font-weight: 600; }
.channel-item.active .counts { color: var(--accent); }
.channel-item.active .counts .cnt svg { opacity: 0.9; }

.add-channel {
  padding: 10px 12px;
  margin: 8px;
  border: 1px dashed var(--border);
  border-radius: 10px;
  background: transparent;
  color: var(--text-sec);
  cursor: pointer;
  font-size: 14px;
  font-family: inherit;
  transition: border-color 0.15s, color 0.15s, background 0.15s;
}
.add-channel:hover { border-color: var(--accent); color: var(--accent); background: var(--accent-dim); }

/* ── Chat area ──────────────────────────────────────────────── */
.chat {
  grid-area: chat;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  position: relative;
}
.chat-header {
  padding: 12px 20px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: 10px;
  background: rgba(23, 33, 43, 0.4);
}
.chat-header .ch-title { font-weight: 600; font-size: 16px; }
.chat-header .ch-title .hash { color: var(--text-sec); }

.messages {
  flex: 1;
  overflow-y: auto;
  padding: 16px 20px 8px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  scroll-behavior: smooth;
}

/* ── Message bubbles ────────────────────────────────────────── */
.msg {
  max-width: 72%;
  display: flex;
  flex-direction: column;
  animation: msgIn 0.18s ease-out;
}
.msg.out { align-self: flex-end; }
.msg.in  { align-self: flex-start; }

.msg .meta {
  display: flex;
  align-items: baseline;
  gap: 8px;
  padding: 0 6px;
  margin-bottom: 2px;
}
.msg.out .meta { flex-direction: row-reverse; }
.msg .device {
  font-size: 12px;
  font-weight: 600;
  color: var(--accent);
}
.msg .time { font-size: 11px; color: var(--text-sec); }

.bubble {
  padding: 8px 12px;
  border-radius: var(--radius);
  word-wrap: break-word;
  overflow-wrap: break-word;
  white-space: pre-wrap;
  position: relative;
}
.msg.in  .bubble { background: var(--bubble-in); border-bottom-left-radius: 4px; }
.msg.out .bubble { background: var(--bubble-out); border-bottom-right-radius: 4px; animation: outIn 0.16s ease-out; }

.bubble .body { font-size: 15px; }
.bubble .body:empty { display: none; }

/* attachments */
.attachments { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 6px; }
.attachments:only-child { margin-top: 0; }

.att-img {
  max-width: 280px;
  max-height: 280px;
  border-radius: 10px;
  cursor: pointer;
  display: block;
  transition: transform 0.15s ease, opacity 0.15s ease;
  touch-action: manipulation; /* iOS: tap unic, fără așteptare double-tap */
}
.att-img:hover { transform: scale(1.02); }

.att-card {
  display: flex;
  align-items: center;
  gap: 10px;
  background: rgba(0,0,0,0.22);
  border: 1px solid rgba(255,255,255,0.06);
  border-radius: 10px;
  padding: 8px 12px;
  min-width: 180px;
  max-width: 280px;
}
.att-card .file-ico {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 34px; height: 34px;
  flex-shrink: 0;
  color: var(--accent);
  background: var(--accent-dim);
  border-radius: 8px;
}
.att-card .file-ico svg { width: 22px; height: 22px; }
.att-card .file-info { flex: 1; min-width: 0; }
.att-card .file-name {
  font-size: 13px;
  font-weight: 500;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.att-card .file-size { font-size: 11px; color: var(--text-sec); }
.att-card .dl-btn {
  border: none;
  background: var(--accent);
  color: #0e1621;
  font-weight: 600;
  font-size: 12px;
  padding: 5px 10px;
  border-radius: 8px;
  cursor: pointer;
  transition: filter 0.15s, transform 0.1s;
}
.att-card .dl-btn:hover { filter: brightness(1.1); }
.att-card .dl-btn:active { transform: scale(0.95); }

/* ── Card Open Graph (thumbnail URL) ─────────────────────────── */
.og-card {
  display: flex;
  gap: 10px;
  margin-top: 8px;
  padding: 8px;
  background: rgba(0,0,0,0.25);
  border: 1px solid rgba(255,255,255,0.08);
  border-radius: 10px;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s;
  max-width: 320px;
}
.og-card:hover { background: rgba(0,0,0,0.35); border-color: var(--accent); }
.og-card .og-thumb {
  width: 64px; height: 64px;
  flex-shrink: 0;
  border-radius: 8px;
  overflow: hidden;
  background: var(--hover);
  display: flex;
  align-items: center;
  justify-content: center;
}
.og-card .og-thumb img { width: 100%; height: 100%; object-fit: cover; }
.og-card .og-fallback { font-size: 24px; opacity: 0.6; }
.og-card .og-meta { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 3px; }
.og-card .og-title {
  font-size: 13px; font-weight: 600; color: var(--text);
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.og-card .og-desc {
  font-size: 11px; color: var(--text-sec);
  overflow: hidden; text-overflow: ellipsis;
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical;
}
.og-card .og-desc:empty { display: none; }

/* linkuri în mesaj */
.bubble .body a { color: var(--accent); text-decoration: underline; word-break: break-all; }
.msg.out .bubble a { color: #cfe8ff; }

/* delete msg button */
.msg .del-msg {
  align-self: flex-end;
  border: none;
  background: transparent;
  color: var(--text-sec);
  font-size: 12px;
  cursor: pointer;
  padding: 2px 6px;
  border-radius: 6px;
  opacity: 0;
  transition: opacity 0.15s, color 0.15s, background 0.15s;
}
.msg:hover .del-msg { opacity: 0.8; }
.msg .del-msg:hover { color: var(--danger); background: rgba(229,115,115,0.12); }

/* fade-out before removal */
.msg.removing { animation: msgOut 0.2s ease-in forwards; }

/* ── Empty state ────────────────────────────────────────────── */
.empty {
  margin: auto;
  text-align: center;
  color: var(--text-sec);
  padding: 40px;
}
.empty .big { font-size: 40px; margin-bottom: 12px; }

/* ── Input bar ──────────────────────────────────────────────── */
.input-bar {
  border-top: 1px solid var(--border);
  padding: 12px 16px;
  background: rgba(23,33,43,0.5);
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.pending-files {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}
.pending-files:empty { display: none; }
.pending-file {
  display: flex;
  align-items: center;
  gap: 6px;
  background: var(--hover);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 4px 8px;
  font-size: 12px;
  animation: msgIn 0.15s ease-out;
}
.pending-file .rm {
  border: none; background: transparent; color: var(--text-sec);
  cursor: pointer; font-size: 13px; padding: 0 2px;
}
.pending-file .rm:hover { color: var(--danger); }

.input-row { display: flex; align-items: flex-end; gap: 10px; }

.attach-btn {
  border: none;
  background: transparent;
  color: var(--text-sec);
  font-size: 20px;
  width: 42px; height: 42px;
  border-radius: 10px;
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
  flex-shrink: 0;
}
.attach-btn:hover { background: var(--hover); color: var(--accent); }

textarea#msg-input {
  flex: 1;
  resize: none;
  background: var(--hover);
  border: 1px solid var(--border);
  border-radius: 12px;
  color: var(--text);
  font-family: inherit;
  font-size: 16px; /* ≥16px: iOS Safari nu face auto-zoom la focus */
  padding: 10px 14px;
  max-height: 160px;
  outline: none;
  transition: border-color 0.15s, box-shadow 0.15s;
  line-height: 1.4;
}
textarea#msg-input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-dim);
}
textarea#msg-input::placeholder { color: var(--text-sec); }

.send-btn {
  border: none;
  background: var(--accent);
  color: #0e1621;
  font-weight: 700;
  font-size: 18px;
  width: 42px; height: 42px;
  border-radius: 12px;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: box-shadow 0.18s ease, transform 0.1s ease, filter 0.15s;
  flex-shrink: 0;
}
.send-btn:hover { box-shadow: 0 0 16px rgba(94,181,247,0.5); filter: brightness(1.05); }
.send-btn:active { transform: scale(0.97); }
.send-btn:disabled { opacity: 0.5; cursor: not-allowed; box-shadow: none; }

/* upload progress */
.progress-wrap {
  height: 4px;
  border-radius: 2px;
  background: var(--border);
  overflow: hidden;
  display: none;
}
.progress-wrap.active { display: block; }
.progress-bar {
  height: 100%;
  width: 0%;
  background: var(--accent);
  border-radius: 2px;
  transition: width 0.2s ease;
}

/* ── Drag & drop overlay ────────────────────────────────────── */
.drop-overlay {
  position: absolute;
  inset: 0;
  background: rgba(14,22,33,0.85);
  border: 3px dashed var(--accent);
  border-radius: 8px;
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 30;
  font-size: 18px;
  color: var(--accent);
  font-weight: 600;
  pointer-events: none;
}
.drop-overlay.active { display: flex; animation: msgIn 0.15s ease-out; }

/* ── Toast ──────────────────────────────────────────────────── */
.toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%) translateY(20px);
  background: var(--bg-sidebar);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 10px 18px;
  border-radius: 10px;
  font-size: 14px;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s, transform 0.2s;
  z-index: 100;
  box-shadow: 0 8px 24px rgba(0,0,0,0.4);
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
.toast.error { border-color: var(--danger); }

/* ── Image lightbox ─────────────────────────────────────────── */
.lightbox {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.9);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 200;
  cursor: zoom-out;
  padding: 24px;
  touch-action: pan-y; /* permite swipe-ul orizontal pe imagine */
}
.lightbox.active { display: flex; animation: msgIn 0.15s ease-out; }
.lightbox img {
  max-width: 100%;
  max-height: 100%;
  border-radius: 8px;
  box-shadow: 0 12px 48px rgba(0,0,0,0.6);
  transition: transform 0.12s ease-out;
  will-change: transform;
}

/* ── Animations ─────────────────────────────────────────────── */
@keyframes msgIn {
  from { opacity: 0; transform: translateY(8px); }
  to   { opacity: 1; transform: translateY(0); }
}
@keyframes outIn {
  from { opacity: 0; transform: scale(0.98); }
  to   { opacity: 1; transform: scale(1); }
}
@keyframes msgOut {
  from { opacity: 1; transform: translateY(0); }
  to   { opacity: 0; transform: translateY(6px); }
}
@keyframes slideIn {
  from { opacity: 0; transform: translateX(-10px); }
  to   { opacity: 1; transform: translateX(0); }
}

/* ── Scrollbar ──────────────────────────────────────────────── */
::-webkit-scrollbar { width: 8px; height: 8px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 4px; }
::-webkit-scrollbar-thumb:hover { background: var(--text-sec); }

/* ── Responsive (sidebar → drawer) ──────────────────────────── */
@media (max-width: 720px) {
  .app {
    grid-template-columns: 1fr;
    grid-template-areas:
      "header"
      "chat";
  }
  .sidebar {
    position: fixed;
    top: var(--header-h);
    bottom: 0;
    left: 0;
    width: min(280px, 85vw);
    transform: translateX(-100%);
    transition: transform 0.25s ease;
    z-index: 40;
    box-shadow: 8px 0 24px rgba(0,0,0,0.4);
  }
  .sidebar.open { transform: translateX(0); }
  .sidebar-backdrop {
    position: fixed;
    inset: var(--header-h) 0 0 0;
    background: rgba(0,0,0,0.5);
    z-index: 35;
    display: none;
  }
  .sidebar-backdrop.active { display: block; animation: msgIn 0.15s ease-out; }
  .msg { max-width: 88%; }
  .device-label { max-width: 140px; }
  .device-label input { width: 80px; }
}
