/* ============================================================
   Inbox Agent — classic dark AI-chat aesthetic (ChatGPT/Grok)
   ============================================================ */

:root {
  --bg: #131316;
  --bg-sidebar: #0b0b0d;
  --bg-elevated: #1c1c21;
  --bg-hover: #232329;
  --bg-active: #2a2a31;
  --border: #2a2a31;
  --border-soft: #222228;
  --text: #ececf1;
  --text-secondary: #a6a6b3;
  --text-muted: #6e6e7e;
  --accent: #10a37f;
  --accent-soft: rgba(16, 163, 127, 0.14);
  --amber: #f5a623;
  --amber-soft: rgba(245, 166, 35, 0.14);
  --red: #ef4146;
  --bubble-user: #26262e;
  --bubble-agent: #10a37f;
  --bubble-agent-deep: #0d8a6c;
  --radius: 14px;
  --sidebar-w: 300px;
  --font: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 15px;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
}

.app {
  display: flex;
  height: 100dvh;
  overflow: hidden;
}

/* ---------------- Sidebar ---------------- */

.sidebar {
  width: var(--sidebar-w);
  min-width: var(--sidebar-w);
  background: var(--bg-sidebar);
  border-right: 1px solid var(--border-soft);
  display: flex;
  flex-direction: column;
  z-index: 30;
}

.sidebar-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 14px 10px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  font-weight: 600;
  font-size: 15px;
  letter-spacing: 0.01em;
}

.brand-mark { display: grid; place-items: center; }
.brand-mark svg { display: block; border-radius: 6px; }

.icon-btn {
  display: grid;
  place-items: center;
  width: 32px;
  height: 32px;
  border: none;
  border-radius: 8px;
  background: transparent;
  color: var(--text-secondary);
  cursor: pointer;
  transition: background 0.15s ease, color 0.15s ease;
}
.icon-btn:hover { background: var(--bg-hover); color: var(--text); }
.icon-btn:active { transform: scale(0.96); }
.icon-btn.spinning svg { animation: spin 0.8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* Search */

.search-wrap {
  position: relative;
  margin: 2px 12px 10px;
}
.search-icon {
  position: absolute;
  top: 50%;
  left: 11px;
  transform: translateY(-50%);
  color: var(--text-muted);
  pointer-events: none;
}
#search {
  width: 100%;
  padding: 9px 12px 9px 34px;
  border: 1px solid var(--border-soft);
  border-radius: 10px;
  background: var(--bg-elevated);
  color: var(--text);
  font: inherit;
  font-size: 13.5px;
  outline: none;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}
#search::placeholder { color: var(--text-muted); }
#search:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

/* Filter chips */

.filters {
  display: flex;
  gap: 6px;
  padding: 0 12px 12px;
}
.filter-chip {
  flex: 1;
  padding: 6px 0;
  border: 1px solid var(--border-soft);
  border-radius: 999px;
  background: transparent;
  color: var(--text-secondary);
  font: inherit;
  font-size: 12.5px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.15s ease;
}
.filter-chip:hover { background: var(--bg-hover); color: var(--text); }
.filter-chip.active {
  background: var(--accent-soft);
  border-color: var(--accent);
  color: var(--accent);
}

/* Thread list */

.thread-list {
  flex: 1;
  overflow-y: auto;
  padding: 2px 8px 8px;
  scrollbar-width: thin;
  scrollbar-color: var(--border) transparent;
}
.thread-list::-webkit-scrollbar { width: 6px; }
.thread-list::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }

.thread-item {
  display: flex;
  gap: 11px;
  width: 100%;
  padding: 10px;
  margin-bottom: 2px;
  border: none;
  border-radius: 10px;
  background: transparent;
  color: inherit;
  font: inherit;
  text-align: left;
  cursor: pointer;
  transition: background 0.13s ease;
}
.thread-item:hover { background: var(--bg-hover); }
.thread-item.active { background: var(--bg-active); }

.avatar {
  flex: none;
  width: 36px;
  height: 36px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  font-size: 14px;
  font-weight: 600;
  color: #fff;
}

.thread-meta { min-width: 0; flex: 1; }

.thread-top {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 8px;
}
.thread-subject {
  font-size: 13.5px;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.thread-time {
  flex: none;
  font-size: 11px;
  color: var(--text-muted);
}
.thread-bottom {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-top: 3px;
}
.thread-snippet {
  font-size: 12.5px;
  color: var(--text-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* Decision badges */

.badge {
  flex: none;
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 2px 9px;
  border-radius: 999px;
  font-size: 10.5px;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}
.badge::before {
  content: "";
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: currentColor;
}
.badge.answer  { background: var(--accent-soft); color: #34d399; }
.badge.escalate { background: var(--amber-soft); color: var(--amber); }

/* Sidebar footer */

.sidebar-footer {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 11px 16px;
  border-top: 1px solid var(--border-soft);
  font-size: 12px;
  color: var(--text-muted);
}
.status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--text-muted);
  transition: background 0.3s ease;
}
.status-dot.online { background: #34d399; box-shadow: 0 0 6px rgba(52, 211, 153, 0.7); }
.status-dot.offline { background: var(--red); }
.footer-count { margin-left: auto; }

/* ---------------- Main pane ---------------- */

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

.main-header {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 22px;
  border-bottom: 1px solid var(--border-soft);
  background: rgba(19, 19, 22, 0.85);
  backdrop-filter: blur(10px);
}
.menu-btn { display: none; }

.main-header-titles { min-width: 0; flex: 1; }
.main-title {
  margin: 0;
  font-size: 15.5px;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.main-subtitle {
  margin: 1px 0 0;
  font-size: 12.5px;
  color: var(--text-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.header-badge { flex: none; }

/* Chat area */

.chat {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.chat-scroll {
  flex: 1;
  overflow-y: auto;
  padding: 28px 0 32px;
  scrollbar-width: thin;
  scrollbar-color: var(--border) transparent;
}
.chat-scroll::-webkit-scrollbar { width: 8px; }
.chat-scroll::-webkit-scrollbar-thumb { background: var(--border); border-radius: 4px; }

.chat-inner {
  max-width: 780px;
  margin: 0 auto;
  padding: 0 24px;
  display: flex;
  flex-direction: column;
  gap: 22px;
}

/* Message rows */

.msg {
  display: flex;
  gap: 12px;
  max-width: 88%;
  animation: rise 0.28s ease both;
}
@keyframes rise {
  from { opacity: 0; transform: translateY(8px); }
  to   { opacity: 1; transform: none; }
}
.msg.incoming { align-self: flex-start; }
.msg.agent    { align-self: flex-end; flex-direction: row-reverse; }

.msg .avatar { width: 32px; height: 32px; font-size: 12.5px; margin-top: 2px; }
.avatar.bot { background: linear-gradient(135deg, var(--accent), #0d8a6c); }
.avatar.warn { background: linear-gradient(135deg, #f5a623, #d97706); }

.msg-body { min-width: 0; }

.msg-label {
  display: flex;
  align-items: baseline;
  gap: 8px;
  margin-bottom: 5px;
  font-size: 11.5px;
  color: var(--text-muted);
}
.msg.agent .msg-label { justify-content: flex-end; }
.msg-label .who { font-weight: 600; color: var(--text-secondary); }

.bubble {
  padding: 12px 16px;
  border-radius: var(--radius);
  font-size: 14px;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.25);
}
.msg.incoming .bubble {
  background: var(--bubble-user);
  border: 1px solid var(--border-soft);
  border-top-left-radius: 4px;
}
.msg.agent .bubble {
  background: linear-gradient(160deg, var(--bubble-agent), var(--bubble-agent-deep));
  color: #f4fffb;
  border-top-right-radius: 4px;
}
.msg.agent.escalate .bubble {
  background: linear-gradient(160deg, #4a3a17, #3a2d10);
  border: 1px solid rgba(245, 166, 35, 0.35);
  color: #fde9c4;
}

.bubble .bubble-title {
  display: block;
  font-weight: 600;
  margin-bottom: 6px;
}

.bubble.clamped .bubble-text {
  display: -webkit-box;
  -webkit-line-clamp: 10;
  -webkit-box-orient: vertical;
  overflow: hidden;
}
.show-more {
  margin-top: 8px;
  padding: 0;
  border: none;
  background: none;
  color: inherit;
  font: inherit;
  font-size: 12.5px;
  font-weight: 600;
  opacity: 0.75;
  cursor: pointer;
  text-decoration: underline;
}
.show-more:hover { opacity: 1; }

/* Divider between conversation and verdict */

.verdict-divider {
  display: flex;
  align-items: center;
  gap: 12px;
  color: var(--text-muted);
  font-size: 11.5px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  margin: 4px 0;
}
.verdict-divider::before,
.verdict-divider::after {
  content: "";
  flex: 1;
  height: 1px;
  background: var(--border-soft);
}

/* ---------------- Composer (human-in-the-loop reply) ---------------- */

.composer-wrap {
  flex: none;
  padding: 10px 24px 16px;
  border-top: 1px solid var(--border-soft);
  background: linear-gradient(180deg, rgba(19, 19, 22, 0.6), var(--bg));
}
.composer-wrap > * {
  max-width: 780px;
  margin-left: auto;
  margin-right: auto;
}

.composer-note {
  font-size: 12px;
  color: var(--text-muted);
  padding: 0 4px 8px;
}
.composer-note.error { color: var(--red); }

.composer {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  padding: 10px 10px 10px 16px;
  border: 1px solid var(--border);
  border-radius: 18px;
  background: var(--bg-elevated);
  box-shadow: 0 4px 18px rgba(0, 0, 0, 0.35);
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}
.composer:focus-within {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft), 0 4px 18px rgba(0, 0, 0, 0.35);
}

#composer-text {
  flex: 1;
  border: none;
  background: transparent;
  color: var(--text);
  font: inherit;
  font-size: 14px;
  line-height: 1.5;
  resize: none;
  outline: none;
  max-height: 220px;
  padding: 4px 0;
}
#composer-text::placeholder { color: var(--text-muted); }
#composer-text:disabled { opacity: 0.55; }

.send-btn {
  flex: none;
  display: grid;
  place-items: center;
  width: 36px;
  height: 36px;
  border: none;
  border-radius: 12px;
  background: var(--accent);
  color: #fff;
  cursor: pointer;
  transition: background 0.15s ease, transform 0.1s ease;
}
.send-btn:hover { background: #0d8a6c; }
.send-btn:active { transform: scale(0.94); }
.send-btn:disabled { background: var(--bg-hover); color: var(--text-muted); cursor: not-allowed; }

.composer-hint {
  font-size: 11px;
  color: var(--text-muted);
  padding: 7px 4px 0;
}
.composer-hint strong { color: var(--text-secondary); font-weight: 500; }

/* Empty / loading / error states */

.state {
  flex: 1;
  height: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 14px;
  text-align: center;
  padding: 0 32px;
  color: var(--text-muted);
}
.state .state-icon {
  width: 64px;
  height: 64px;
  border-radius: 18px;
  display: grid;
  place-items: center;
  background: var(--bg-elevated);
  border: 1px solid var(--border-soft);
  color: var(--text-secondary);
}
.state h2 { margin: 0; font-size: 17px; color: var(--text); font-weight: 600; }
.state p { margin: 0; max-width: 420px; font-size: 13.5px; line-height: 1.6; }
.state code {
  background: var(--bg-elevated);
  border: 1px solid var(--border-soft);
  border-radius: 6px;
  padding: 2px 7px;
  font-size: 12.5px;
}
.state .retry-btn {
  margin-top: 4px;
  padding: 8px 20px;
  border: 1px solid var(--accent);
  border-radius: 999px;
  background: var(--accent-soft);
  color: var(--accent);
  font: inherit;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.15s ease;
}
.state .retry-btn:hover { background: var(--accent); color: #fff; }

/* Skeleton loading */

.skeleton-item {
  display: flex;
  gap: 11px;
  padding: 10px;
  border-radius: 10px;
}
.sk {
  background: linear-gradient(90deg, var(--bg-elevated) 25%, var(--bg-hover) 50%, var(--bg-elevated) 75%);
  background-size: 200% 100%;
  animation: shimmer 1.4s infinite;
  border-radius: 6px;
}
@keyframes shimmer { to { background-position: -200% 0; } }
.sk.circle { width: 36px; height: 36px; border-radius: 50%; flex: none; }
.sk.line { height: 11px; margin-bottom: 8px; }
.sk.w60 { width: 60%; }
.sk.w85 { width: 85%; }
.sk-lines { flex: 1; padding-top: 4px; }

/* Sidebar scrim (mobile) */

.sidebar-scrim {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.55);
  z-index: 25;
  opacity: 0;
  transition: opacity 0.2s ease;
}

/* ---------------- Responsive ---------------- */

@media (max-width: 860px) {
  .sidebar {
    position: fixed;
    top: 0;
    bottom: 0;
    left: 0;
    transform: translateX(-105%);
    transition: transform 0.25s cubic-bezier(0.4, 0, 0.2, 1);
    box-shadow: 8px 0 32px rgba(0, 0, 0, 0.5);
  }
  .sidebar.open { transform: none; }
  .sidebar-scrim.visible { display: block; opacity: 1; }
  .menu-btn { display: grid; }
  .msg { max-width: 100%; }
  .chat-inner { padding: 0 16px; }
  .composer-wrap { padding: 8px 12px 12px; }
}
