/* Qmeter Agents — component layer. Import order: tokens.css, globals.css, this file. */

html, body { height: 100%; }
#app { height: 100dvh; }
.hidden { display: none !important; }
.sr-only {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0,0,0,0); white-space: nowrap; border: 0;
}

.icon-btn {
  display: inline-flex; align-items: center; justify-content: center;
  width: 36px; height: 36px; border-radius: var(--radius-chip);
  border: none; background: transparent; color: var(--ink-body); cursor: pointer;
  transition: background var(--dur-fast) var(--ease);
}
.icon-btn:hover { background: var(--bg-muted); }

.status-dot {
  display: inline-block; width: 8px; height: 8px; border-radius: 999px;
  background: var(--gradient-accent); margin-right: 6px;
}

.eyebrow {
  display: inline-block; font-family: var(--font-medium);
  font-size: var(--fs-eyebrow); letter-spacing: var(--ls-eyebrow); text-transform: uppercase;
  color: #fff; padding: var(--space-2) 14px; border-radius: var(--radius-chip);
  background: var(--gradient-accent); margin-bottom: var(--space-4);
}

.btn {
  height: 48px; padding: 0 22px; border-radius: var(--radius-btn);
  font-family: var(--font-medium); font-size: 15px; cursor: pointer; border: none;
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  transition: transform var(--dur-fast) var(--ease), box-shadow var(--dur) var(--ease);
  width: 100%;
}
.btn:hover { transform: translateY(-1px); box-shadow: var(--shadow); }
.btn:active { transform: translateY(0); }
.btn--primary { background: var(--ink-strong); color: var(--ink-inverse); }
.btn--primary:disabled { opacity: .5; cursor: default; transform: none; box-shadow: none; }

.input {
  background: var(--bg-surface); border: 1px solid var(--border-solid);
  border-radius: var(--radius-sm); padding: var(--space-3) 14px;
  font-family: var(--font-body); font-size: 15px; color: var(--ink-body);
  width: 100%; transition: border-color var(--dur-fast) var(--ease), box-shadow var(--dur-fast) var(--ease);
}
.input::placeholder { color: var(--ink-muted); }
.input:focus { outline: none; border-color: var(--accent-solid); box-shadow: 0 0 0 3px var(--accent-ring); }

/* ---------- Login ---------- */
.login-screen {
  height: 100%; display: flex; align-items: center; justify-content: center;
  padding: var(--space-5); background: var(--bg-page); overflow-y: auto;
}
.login-card {
  width: 100%; max-width: 380px; background: var(--bg-surface);
  border: 1px solid var(--border); border-radius: var(--radius-card);
  padding: var(--space-8) var(--space-6); box-shadow: var(--shadow-lift);
  text-align: center; display: flex; flex-direction: column; align-items: center;
  margin: auto;
}
.login-mark img { height: 34px; width: auto; margin-bottom: var(--space-5); }
.login-card h1 { font-size: 22px; margin: 0 0 var(--space-5); }
.login-field { width: 100%; text-align: left; margin-bottom: var(--space-3); }
.login-field label { display: block; font-size: var(--fs-xs); color: var(--ink-muted); margin-bottom: 6px; }
.login-submit { margin-top: var(--space-2); }
.login-error {
  color: var(--danger); font-size: var(--fs-xs); min-height: 18px; margin-top: var(--space-3);
  transition: opacity var(--dur-fast) var(--ease);
}

/* ---------- App shell ---------- */
.app-shell { display: flex; height: 100%; background: var(--bg-page); }

.sidebar {
  width: 320px; flex-shrink: 0; background: var(--bg-surface);
  border-right: 1px solid var(--border); display: flex; flex-direction: column;
  box-shadow: var(--shadow-sm);
}
.sidebar-header { padding: var(--space-5) var(--space-4) var(--space-3); display: flex; align-items: center; }
.sidebar-header img { height: 20px; width: auto; }

.agent-list { flex: 1; overflow-y: auto; padding: var(--space-2); }

.agent-item {
  display: flex; align-items: center; gap: 12px; width: 100%;
  padding: 10px 12px; border-radius: var(--radius-sm); border: none;
  background: transparent; cursor: pointer; text-align: left; margin-bottom: 2px;
  transition: background var(--dur-fast) var(--ease), transform var(--dur-fast) var(--ease);
}
.agent-item:hover { background: var(--bg-muted); transform: translateY(-1px); }
.agent-item:active { transform: translateY(0); }
.agent-item.active { background: var(--bg-muted); }

.avatar {
  flex-shrink: 0; width: 44px; height: 44px; border-radius: 999px;
  background: var(--gradient-accent); padding: 2px;
}
.avatar-inner {
  width: 100%; height: 100%; border-radius: 999px; background: var(--ink-strong);
  color: var(--ink-inverse); display: flex; align-items: center; justify-content: center;
  font-family: var(--font-medium); font-size: 16px;
}

.agent-item-body { min-width: 0; flex: 1; }
.agent-item-row { display: flex; align-items: baseline; justify-content: space-between; gap: 8px; }
.agent-item-name {
  font-family: var(--font-medium); font-size: 15px; color: var(--ink-strong);
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-width: 0;
}
.agent-item-time { font-size: var(--fs-xs); color: var(--ink-muted); flex-shrink: 0; }
.agent-item-preview {
  font-size: var(--fs-sm); color: var(--ink-muted); margin-top: 2px;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}

.sidebar-footer { padding: var(--space-3) var(--space-4); border-top: 1px solid var(--border); }
.logout-btn {
  background: none; border: none; color: var(--ink-muted); font-size: var(--fs-sm); cursor: pointer;
  padding: 4px 0; transition: color var(--dur-fast) var(--ease);
}
.logout-btn:hover { color: var(--ink-strong); }

/* ---------- Main / chat ---------- */
.main { flex: 1; display: flex; flex-direction: column; min-width: 0; }

.main-header {
  display: flex; align-items: center; gap: 12px;
  padding: var(--space-3) var(--space-5); border-bottom: 1px solid var(--border);
  padding-top: max(var(--space-3), env(safe-area-inset-top));
  background: var(--bg-surface); flex-shrink: 0; box-shadow: var(--shadow-sm); position: relative; z-index: 1;
}
.back-btn { display: none; margin-left: -6px; }
.header-avatar {
  width: 38px; height: 38px; border-radius: 999px; background: var(--gradient-accent);
  padding: 2px; flex-shrink: 0;
}
.header-avatar::after {
  content: ""; display: block; width: 100%; height: 100%; border-radius: 999px; background: var(--ink-strong);
}
.header-info { min-width: 0; }
.header-info h2 { font-size: 16px; margin: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.header-status { display: flex; align-items: center; font-size: var(--fs-xs); color: var(--ink-muted); }

.messages {
  flex: 1; overflow-y: auto; padding: var(--space-6) var(--space-5);
  display: flex; flex-direction: column; gap: var(--space-4);
}
.messages-inner { max-width: 720px; width: 100%; margin: 0 auto; display: flex; flex-direction: column; gap: var(--space-4); }

.empty-state { margin: auto; text-align: center; max-width: 320px; }
.empty-state h2 { font-size: 22px; margin-bottom: var(--space-2); }
.empty-state p { color: var(--ink-muted); font-size: var(--fs-sm); }

.msg-row {
  display: flex; gap: 10px; max-width: 78%;
  animation: msg-in 0.32s var(--ease);
}
@keyframes msg-in {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}
@media (prefers-reduced-motion: reduce) {
  .msg-row { animation: none; }
}
.msg-row.user { align-self: flex-end; flex-direction: row-reverse; }
.msg-row.assistant { align-self: flex-start; }

.msg-avatar { width: 30px; height: 30px; border-radius: 999px; background: var(--gradient-accent); padding: 2px; flex-shrink: 0; }
.msg-avatar-inner {
  width: 100%; height: 100%; border-radius: 999px; background: var(--ink-strong); color: var(--ink-inverse);
  display: flex; align-items: center; justify-content: center; font-family: var(--font-medium); font-size: 12px;
}

.msg-bubble {
  font-size: var(--fs-body); line-height: var(--lh-body); white-space: pre-wrap; word-wrap: break-word;
  transition: box-shadow var(--dur) var(--ease);
}
.msg-row.user .msg-bubble {
  background: var(--ink-strong); color: var(--ink-inverse);
  border-radius: 16px 16px 4px 16px; padding: 12px 16px;
}
.msg-row.assistant .msg-bubble {
  background: var(--bg-surface); color: var(--ink-body); border: 1px solid var(--border);
  border-radius: 16px 16px 16px 4px; padding: 12px 16px; box-shadow: var(--shadow-sm);
}
.msg-time { font-size: var(--fs-xs); color: var(--ink-muted); margin-top: 4px; }
.msg-row.user .msg-time { text-align: right; }

.typing-dots { display: flex; gap: 4px; padding: 6px 2px; }
.typing-dots span {
  width: 6px; height: 6px; border-radius: 999px; background: var(--ink-faint);
  animation: bounce 1.2s infinite ease-in-out;
}
.typing-dots span:nth-child(2) { animation-delay: .15s; }
.typing-dots span:nth-child(3) { animation-delay: .3s; }
@keyframes bounce {
  0%, 60%, 100% { transform: translateY(0); opacity: .5; }
  30% { transform: translateY(-4px); opacity: 1; }
}

.composer {
  display: flex; align-items: flex-end; gap: 8px;
  background: var(--bg-surface); border-top: 1px solid var(--border);
  padding: var(--space-3) var(--space-4);
  padding-bottom: max(var(--space-3), env(safe-area-inset-bottom));
  flex-shrink: 0; box-shadow: 0 -2px 8px rgba(0,0,0,.03);
}
.composer-input {
  flex: 1; border: 1px solid var(--border-solid); border-radius: 14px;
  padding: 12px 14px; resize: none; max-height: 160px;
  font-family: var(--font-body); font-size: 15px; color: var(--ink-body); background: var(--bg-surface);
  transition: border-color var(--dur-fast) var(--ease), box-shadow var(--dur-fast) var(--ease);
}
.composer-input:focus { outline: none; border-color: var(--accent-solid); box-shadow: 0 0 0 3px var(--accent-ring); }
.composer-input::placeholder { color: var(--ink-muted); }

.send {
  flex-shrink: 0; width: 40px; height: 40px; border-radius: 999px; border: none;
  background: var(--ink-strong); color: #fff; cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  transition: transform var(--dur-fast) var(--ease), box-shadow var(--dur-fast) var(--ease), background var(--dur-fast) var(--ease);
}
.send:hover:not(:disabled) { transform: translateY(-1px) scale(1.04); box-shadow: var(--shadow); }
.send:active:not(:disabled) { transform: translateY(0) scale(1); }
.send:disabled { background: var(--border-solid); color: var(--ink-faint); cursor: default; }

/* ---------- Dark mode ---------- */
@media (prefers-color-scheme: dark) {
  body, .login-screen, .app-shell { background: var(--dark-bg); }
  .login-card, .sidebar, .main-header, .composer, .msg-row.assistant .msg-bubble {
    background: var(--dark-surface); border-color: var(--dark-border);
  }
  .login-card, .sidebar, .main-header, .composer { border-color: var(--dark-border); }
  .login-mark img, .sidebar-header img { filter: invert(1) brightness(2); }
  .login-card h1, .agent-item-name, .header-info h2, .empty-state h2,
  .msg-row.assistant .msg-bubble { color: var(--dark-ink); }
  .login-field label { color: var(--dark-muted); }
  .input, .composer-input { background: var(--dark-bg); border-color: var(--dark-border); color: var(--dark-ink); }
  .input::placeholder, .composer-input::placeholder { color: var(--dark-muted); }
  .agent-item:hover, .agent-item.active { background: rgba(255,255,255,0.06); }
  .agent-item-time, .agent-item-preview, .header-status, .empty-state p, .msg-time { color: var(--dark-muted); }
  .msg-row.user .msg-bubble { background: var(--ink-inverse); color: var(--ink-strong); }
  .avatar-inner, .msg-avatar-inner, .header-avatar::after { background: var(--ink-inverse); color: var(--ink-strong); }
  .send:disabled { background: var(--dark-border); color: var(--dark-muted); }
  .icon-btn { color: var(--dark-ink); }
  .icon-btn:hover { background: rgba(255,255,255,0.08); }
  .logout-btn { color: var(--dark-muted); }
  .logout-btn:hover { color: var(--dark-ink); }
}

/* ---------- Mobile: WhatsApp-style list <-> thread navigation ---------- */
@media (max-width: 768px) {
  .app-shell { position: relative; overflow: hidden; }
  .sidebar, .main {
    position: absolute; inset: 0; width: 100%;
    transition: transform var(--dur) var(--ease);
  }
  .main { transform: translateX(100%); }
  .app-shell.show-thread .sidebar { transform: translateX(-100%); }
  .app-shell.show-thread .main { transform: translateX(0); }
  .back-btn { display: inline-flex; }
  .msg-row { max-width: 88%; }
}
