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

:root {
  --bg: #f4f7fb;
  --surface: #ffffff;
  --primary: #5b8dee;
  --primary-dark: #3a6fd8;
  --accent: #a8d5ba;
  --text: #2d3748;
  --muted: #718096;
  --border: #e2e8f0;
  --danger: #e53e3e;
  --teen-bubble: #5b8dee;
  --support-bubble: #e9edf7;
  --radius: 16px;
  --shadow: 0 4px 24px rgba(91,141,238,.12);
}

body {
  font-family: 'Segoe UI', system-ui, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
}

/* ── LANDING / FORMS ── */
.card {
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 2.5rem 2rem;
  width: 100%;
  max-width: 420px;
  text-align: center;
}

.card .logo {
  font-size: 2.8rem;
  margin-bottom: .5rem;
}

.card h1 {
  font-size: 1.5rem;
  font-weight: 700;
  margin-bottom: .4rem;
  color: var(--text);
}

.card p {
  color: var(--muted);
  font-size: .95rem;
  line-height: 1.6;
  margin-bottom: 1.8rem;
}

input[type="text"],
input[type="password"],
input[type="email"] {
  width: 100%;
  padding: .75rem 1rem;
  border: 2px solid var(--border);
  border-radius: 10px;
  font-size: 1rem;
  color: var(--text);
  background: var(--bg);
  outline: none;
  transition: border .2s;
  margin-bottom: 1rem;
}

input[type="text"]:focus,
input[type="password"]:focus,
input[type="email"]:focus { border-color: var(--primary); }

button.btn {
  width: 100%;
  padding: .8rem;
  border: none;
  border-radius: 10px;
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
  transition: background .2s, transform .1s;
}

button.btn:active { transform: scale(.98); }

button.btn-primary {
  background: var(--primary);
  color: #fff;
}

button.btn-primary:hover { background: var(--primary-dark); }

button.btn-danger {
  background: #fff;
  color: var(--danger);
  border: 2px solid var(--danger);
  margin-top: .6rem;
}

button.btn-danger:hover { background: #fff5f5; }

.hint {
  font-size: .8rem;
  color: var(--muted);
  margin-top: 1rem;
}

/* ── WAITING SCREEN ── */
#waiting-screen {
  text-align: center;
}

.spinner {
  width: 48px;
  height: 48px;
  border: 5px solid var(--border);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin 1s linear infinite;
  margin: 1.5rem auto;
}

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

/* ── CHAT LAYOUT ── */
#chat-screen {
  width: 100%;
  max-width: 640px;
  height: 100vh;
  display: flex;
  flex-direction: column;
}

.chat-header {
  background: var(--surface);
  padding: 1rem 1.2rem;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: .8rem;
  box-shadow: 0 2px 8px rgba(0,0,0,.04);
}

.chat-header .avatar {
  width: 38px;
  height: 38px;
  border-radius: 50%;
  background: var(--accent);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.2rem;
}

.chat-header .info h2 { font-size: 1rem; font-weight: 700; }
.chat-header .info span { font-size: .78rem; color: var(--muted); }

.chat-header .end-btn {
  margin-left: auto;
  background: none;
  border: none;
  color: var(--muted);
  font-size: .85rem;
  cursor: pointer;
  padding: .3rem .7rem;
  border-radius: 8px;
  transition: background .15s;
}

.chat-header .end-btn:hover { background: #fff0f0; color: var(--danger); }

.messages {
  flex: 1;
  overflow-y: auto;
  padding: 1.2rem;
  display: flex;
  flex-direction: column;
  gap: .7rem;
  background: var(--bg);
}

.msg {
  max-width: 75%;
  padding: .65rem .95rem;
  border-radius: 18px;
  font-size: .95rem;
  line-height: 1.5;
  word-break: break-word;
}

.msg.mine {
  align-self: flex-end;
  background: var(--teen-bubble);
  color: #fff;
  border-bottom-right-radius: 4px;
}

.msg.theirs {
  align-self: flex-start;
  background: var(--support-bubble);
  color: var(--text);
  border-bottom-left-radius: 4px;
}

.msg .ts {
  display: block;
  font-size: .68rem;
  opacity: .65;
  margin-top: .25rem;
  text-align: right;
}

.msg.theirs .ts { text-align: left; }

.system-msg {
  text-align: center;
  font-size: .82rem;
  color: var(--muted);
  padding: .3rem 0;
}

.chat-input-bar {
  display: flex;
  gap: .5rem;
  padding: .9rem 1rem;
  background: var(--surface);
  border-top: 1px solid var(--border);
}

.chat-input-bar input {
  flex: 1;
  margin: 0;
  padding: .65rem 1rem;
}

.chat-input-bar button {
  width: auto;
  padding: .65rem 1.2rem;
  border-radius: 10px;
}

/* ── SUPPORTER DASHBOARD ── */
.dashboard {
  width: 100vw;
  height: 100vh;
  display: flex;
  flex-direction: column;
  align-self: stretch;
}

.dash-header {
  background: var(--surface);
  padding: 1rem 1.5rem;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: 1rem;
}

.dash-header h1 { font-size: 1.1rem; font-weight: 700; }
.dash-header span { color: var(--muted); font-size: .85rem; margin-left: auto; }

.dash-body {
  display: flex;
  flex: 1;
  overflow: hidden;
}

/* sidebar */
.sidebar {
  width: 220px;
  min-width: 180px;
  background: var(--surface);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  overflow-y: auto;
}

.sidebar h3 {
  padding: .9rem 1rem .5rem;
  font-size: .8rem;
  text-transform: uppercase;
  letter-spacing: .08em;
  color: var(--muted);
}

.queue-item {
  padding: .8rem 1rem;
  border-bottom: 1px solid var(--border);
  cursor: pointer;
  transition: background .15s;
  display: flex;
  align-items: center;
  gap: .7rem;
}

.queue-item:hover { background: var(--bg); }

.queue-item.active { background: #eef3fd; }

.queue-item .q-avatar {
  width: 34px; height: 34px;
  border-radius: 50%;
  background: var(--primary);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: .85rem;
  font-weight: 700;
  flex-shrink: 0;
}

.queue-item .q-info { flex: 1; min-width: 0; }
.queue-item .q-info .q-name { font-weight: 600; font-size: .92rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.queue-item .q-info .q-sub { font-size: .76rem; color: var(--muted); }

.queue-item .accept-btn {
  font-size: .75rem;
  padding: .3rem .6rem;
  width: auto;
  background: var(--primary);
  color: #fff;
  border: none;
  border-radius: 8px;
  cursor: pointer;
  flex-shrink: 0;
}

.queue-item .accept-btn:hover { background: var(--primary-dark); }

.empty-queue {
  padding: 1.5rem 1rem;
  text-align: center;
  color: var(--muted);
  font-size: .87rem;
}

/* main chat area */
.dash-chat {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.no-session {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  color: var(--muted);
  gap: .5rem;
}

.no-session .icon { font-size: 3rem; }

/* ── RESPONSIVE ── */
@media (max-width: 600px) {
  .dash-body { flex-direction: column; }
  .sidebar { width: 100%; min-width: unset; border-right: none; border-bottom: 1px solid var(--border); max-height: 220px; }
}
