/* ═══════════════════════════════════════════════════════════════
   Design tokens
   ═══════════════════════════════════════════════════════════════ */
:root {
  --bg:          #0f1117;
  --bg2:         #1a1d27;
  --bg3:         #22263a;
  --surface:     #252a3d;
  --border:      #2e3450;
  --accent:      #5b7fff;
  --accent-dark: #3a5bdb;
  --accent-glow: rgba(91,127,255,.25);
  --text:        #eaedf5;
  --text-muted:  #7b82a0;
  --in-bubble:   #252a3d;
  --out-bubble:  #2d4adb;
  --danger:      #e05252;
  --success:     #3ecf8e;
  --warn:        #f5a623;
  --radius:      14px;
  --font:        -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  --sidebar-w:   340px;
  --header-h:    64px;
}

/* ── Reset ── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; }
body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
}

a { color: inherit; text-decoration: none; }
button { cursor: pointer; font-family: inherit; }
input, textarea, select { font-family: inherit; }

.hidden { display: none !important; }

/* ═══════════════════════════════════════════════════════════════
   Screens
   ═══════════════════════════════════════════════════════════════ */
.screen { width: 100%; height: 100%; }

/* ═══════════════════════════════════════════════════════════════
   Login
   ═══════════════════════════════════════════════════════════════ */
.login-screen {
  display: flex;
  align-items: center;
  justify-content: center;
  background: radial-gradient(ellipse at 50% 0%, #1c2455 0%, var(--bg) 70%);
  padding: 20px;
}

.login-card {
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: 24px;
  padding: 40px 32px;
  width: 100%;
  max-width: 380px;
  box-shadow: 0 24px 64px rgba(0,0,0,.6);
  text-align: center;
}

.login-logo { font-size: 48px; }
.login-title { font-size: 1.5rem; font-weight: 700; margin: 12px 0 4px; }
.login-sub { color: var(--text-muted); font-size: .9rem; margin-bottom: 28px; }

.login-card input[type="password"] {
  width: 100%;
  background: var(--bg3);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 16px;
  font-size: 1rem;
  color: var(--text);
  outline: none;
  transition: border-color .2s;
}
.login-card input[type="password"]:focus { border-color: var(--accent); }

.login-error {
  color: var(--danger);
  font-size: .85rem;
  margin-top: 8px;
  text-align: left;
}

.login-card button[type="submit"] {
  margin-top: 16px;
  width: 100%;
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: var(--radius);
  padding: 14px;
  font-size: 1rem;
  font-weight: 600;
  transition: background .2s, transform .1s;
}
.login-card button[type="submit"]:hover { background: var(--accent-dark); }
.login-card button[type="submit"]:active { transform: scale(.98); }

/* ═══════════════════════════════════════════════════════════════
   App layout
   ═══════════════════════════════════════════════════════════════ */
#app-screen {
  display: flex;
  height: 100%;
  overflow: hidden;
}

/* ── Sidebar ── */
.sidebar {
  width: var(--sidebar-w);
  min-width: var(--sidebar-w);
  background: var(--bg2);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  height: 100%;
  overflow: hidden;
  transition: transform .25s ease;
}

.sidebar-header {
  height: var(--header-h);
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 0 16px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}
.sidebar-logo { font-size: 24px; }
.sidebar-title { font-size: 1.1rem; font-weight: 700; flex: 1; }

.icon-btn {
  background: none;
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text-muted);
  padding: 6px 10px;
  font-size: .95rem;
  transition: color .2s, border-color .2s;
}
.icon-btn:hover { color: var(--danger); border-color: var(--danger); }

.sidebar-stats {
  display: flex;
  gap: 8px;
  padding: 10px 16px;
  flex-shrink: 0;
}
.stat {
  background: var(--bg3);
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 4px 12px;
  font-size: .78rem;
  color: var(--text-muted);
}

.sidebar-search-wrap {
  padding: 0 12px 10px;
  flex-shrink: 0;
}
#search-input {
  width: 100%;
  background: var(--bg3);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 10px 14px;
  color: var(--text);
  font-size: .9rem;
  outline: none;
  transition: border-color .2s;
}
#search-input:focus { border-color: var(--accent); }

.filter-tabs {
  display: flex;
  gap: 4px;
  padding: 0 12px 10px;
  flex-shrink: 0;
}
.filter-tab {
  flex: 1;
  background: var(--bg3);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 6px 4px;
  font-size: .78rem;
  color: var(--text-muted);
  transition: background .2s, color .2s, border-color .2s;
}
.filter-tab.active {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
  font-weight: 600;
}

/* ── Conversation list ── */
.conv-list {
  list-style: none;
  overflow-y: auto;
  flex: 1;
  padding: 0 8px 12px;
}
.conv-list::-webkit-scrollbar { width: 4px; }
.conv-list::-webkit-scrollbar-track { background: transparent; }
.conv-list::-webkit-scrollbar-thumb { background: var(--border); border-radius: 4px; }

.conv-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 10px;
  border-radius: 12px;
  cursor: pointer;
  transition: background .15s;
  position: relative;
}
.conv-item:hover { background: var(--bg3); }
.conv-item.active { background: var(--surface); }

.conv-avatar {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--accent), #a259ff);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.1rem;
  font-weight: 700;
  flex-shrink: 0;
  color: #fff;
}

.conv-body { flex: 1; min-width: 0; }
.conv-name {
  font-size: .9rem;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.conv-preview {
  font-size: .78rem;
  color: var(--text-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  margin-top: 2px;
}
.conv-preview.unread { color: var(--text); font-weight: 500; }

.conv-meta {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 4px;
  flex-shrink: 0;
}
.conv-time { font-size: .72rem; color: var(--text-muted); }
.conv-badge {
  background: var(--accent);
  color: #fff;
  border-radius: 10px;
  padding: 1px 7px;
  font-size: .72rem;
  font-weight: 700;
  min-width: 20px;
  text-align: center;
}

.status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  display: inline-block;
  margin-right: 2px;
}
.status-open    { background: var(--success); }
.status-pending { background: var(--warn); }
.status-closed  { background: var(--text-muted); }

/* ── Chat panel ── */
.chat-panel {
  flex: 1;
  display: flex;
  flex-direction: column;
  height: 100%;
  overflow: hidden;
  background: var(--bg);
  position: relative;
}

.chat-panel.empty-state .empty-placeholder { display: flex; }

.empty-placeholder {
  display: none;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  height: 100%;
  gap: 12px;
  color: var(--text-muted);
}
.empty-icon { font-size: 56px; opacity: .4; }

/* Back btn */
.back-btn {
  position: absolute;
  top: 14px;
  left: 12px;
  z-index: 10;
  background: var(--bg3);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text);
  padding: 7px 14px;
  font-size: .85rem;
  display: none;
}

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

.chat-user-info { display: flex; align-items: center; gap: 12px; flex: 1; min-width: 0; }

.avatar {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--accent), #a259ff);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 1rem;
  color: #fff;
  flex-shrink: 0;
}

.chat-user-name { font-weight: 700; font-size: .95rem; }
.chat-user-meta { font-size: .75rem; color: var(--text-muted); }

.status-select {
  background: var(--bg3);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 7px 10px;
  color: var(--text);
  font-size: .82rem;
  outline: none;
  cursor: pointer;
  transition: border-color .2s;
}
.status-select:focus { border-color: var(--accent); }

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

.msg-row {
  display: flex;
  max-width: 75%;
}
.msg-row.out { align-self: flex-end; flex-direction: row-reverse; }
.msg-row.in  { align-self: flex-start; }

.msg-bubble {
  padding: 10px 14px;
  border-radius: 18px;
  font-size: .9rem;
  line-height: 1.45;
  word-break: break-word;
  white-space: pre-wrap;
}
.msg-row.in  .msg-bubble {
  background: var(--in-bubble);
  border: 1px solid var(--border);
  border-bottom-left-radius: 4px;
}
.msg-row.out .msg-bubble {
  background: var(--out-bubble);
  border-bottom-right-radius: 4px;
}

.msg-time {
  font-size: .68rem;
  color: var(--text-muted);
  margin-top: 4px;
  text-align: right;
}
.msg-row.in .msg-time { text-align: left; }
.msg-sender {
  font-size: .72rem;
  font-weight: 600;
  color: rgba(255,255,255,.6);
  margin-bottom: 3px;
}

.date-separator {
  align-self: center;
  font-size: .73rem;
  color: var(--text-muted);
  background: var(--bg3);
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 3px 12px;
  margin: 8px 0;
}

/* Reply box */
.reply-box {
  padding: 12px 16px;
  border-top: 1px solid var(--border);
  background: var(--bg2);
  display: flex;
  flex-direction: column;
  gap: 8px;
  flex-shrink: 0;
}

/* ── Reply box overhaul ── */
#sender-name {
  background: var(--bg3);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 7px 12px;
  color: var(--text-muted);
  font-size: .8rem;
  outline: none;
  transition: border-color .2s;
  width: 200px;
}
#sender-name:focus { border-color: var(--accent); color: var(--text); }

/* Drop zone */
.drop-zone {
  position: relative;
  border: 1.5px dashed var(--border);
  border-radius: 12px;
  background: var(--bg3);
  transition: border-color .2s, background .2s;
  cursor: pointer;
  overflow: hidden;
}
.drop-zone:hover,
.drop-zone.drag-over {
  border-color: var(--accent);
  background: rgba(91,127,255,.07);
}

/* Hide the real file input but keep it clickable */
.drop-zone input[type="file"] {
  position: absolute;
  inset: 0;
  opacity: 0;
  cursor: pointer;
  width: 100%;
  height: 100%;
  z-index: 2;
}

.drop-zone-idle {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 14px;
  pointer-events: none;
}
.drop-icon { font-size: 1.2rem; }
.drop-label { font-size: .85rem; color: var(--text-muted); }
.drop-hint { font-size: .78rem; color: var(--text-muted); opacity: .6; }

/* Preview state */
.file-preview {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 14px;
}
.file-preview.hidden { display: none !important; }

.file-preview img {
  width: 52px;
  height: 52px;
  object-fit: cover;
  border-radius: 8px;
  border: 1px solid var(--border);
  flex-shrink: 0;
}

.preview-info {
  display: flex;
  flex-direction: column;
  gap: 2px;
  flex: 1;
  min-width: 0;
}
.preview-name {
  font-size: .82rem;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  color: var(--text);
}
.preview-size { font-size: .73rem; color: var(--text-muted); }

.remove-file {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 50%;
  color: var(--text-muted);
  width: 26px;
  height: 26px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: .75rem;
  flex-shrink: 0;
  transition: color .15s, border-color .15s;
  z-index: 3;
  position: relative;
}
.remove-file:hover { color: var(--danger); border-color: var(--danger); }

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

#reply-input {
  flex: 1;
  background: var(--bg3);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 12px 14px;
  color: var(--text);
  font-size: .9rem;
  outline: none;
  resize: none;
  max-height: 140px;
  overflow-y: auto;
  line-height: 1.45;
  transition: border-color .2s;
}
#reply-input:focus { border-color: var(--accent); }

.send-btn {
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: 12px;
  padding: 12px 20px;
  font-size: .9rem;
  font-weight: 600;
  white-space: nowrap;
  transition: background .2s, transform .1s;
  align-self: flex-end;
}
.send-btn:hover { background: var(--accent-dark); }
.send-btn:active { transform: scale(.97); }
.send-btn:disabled { opacity: .5; cursor: not-allowed; }

/* ═══════════════════════════════════════════════════════════════
   Responsive — mobile (≤ 640px)
   ═══════════════════════════════════════════════════════════════ */
@media (max-width: 640px) {
  :root { --sidebar-w: 100vw; }

  .sidebar {
    position: fixed;
    inset: 0;
    width: 100vw;
    z-index: 20;
    transform: translateX(0);
  }

  .sidebar.hidden-mobile {
    transform: translateX(-100%);
  }

  .chat-panel {
    position: fixed;
    inset: 0;
    width: 100vw;
    z-index: 10;
    transform: translateX(100%);
    transition: transform .25s ease;
  }

  .chat-panel.visible-mobile {
    transform: translateX(0);
  }

  .back-btn { display: block !important; }

  .msg-row { max-width: 88%; }
}
