/* ═══════════════════════════════════════════════════════
   FBP Support Chat V2 — Operator Console
   Design: Dark sidebar + light content, amber brand accent
   ═══════════════════════════════════════════════════════ */

:root {
  --sidebar-bg: #1e2028;
  --sidebar-hover: #282b34;
  --sidebar-active: #32363f;
  --sidebar-border: #2d313a;
  --header-bg: #16181e;
  --content-bg: #ffffff;
  --content-bg-alt: #f8f9fa;
  --page-bg: #f0f1f3;
  --brand: #d4891c;
  --brand-dark: #b47216;
  --brand-light: #fef3e2;
  --brand-glow: rgba(212, 137, 28, 0.25);
  --green: #22c55e;
  --green-bg: #dcfce7;
  --green-text: #166534;
  --red: #ef4444;
  --red-bg: #fee2e2;
  --red-text: #991b1b;
  --msg-customer-bg: #f0f4f8;
  --msg-operator-bg: #fef3e2;
  --msg-system-bg: #f3f4f6;
  --text-on-dark: #e5e7eb;
  --text-muted-dark: #9ca3af;
  --text-primary: #111827;
  --text-secondary: #6b7280;
  --border-light: #e5e7eb;
  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 16px;
  --radius-pill: 999px;
  --sidebar-width: 360px;
}

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

html, body {
  height: 100%;
  margin: 0;
  font-family: -apple-system, "Segoe UI", "Inter", system-ui, sans-serif;
  background: var(--page-bg);
  color: var(--text-primary);
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
}

.app-shell {
  height: 100dvh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

/* ── Top Bar ── */
.topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0 20px;
  height: 56px;
  min-height: 56px;
  background: var(--header-bg);
  border-bottom: 1px solid var(--sidebar-border);
  z-index: 10;
}
.topbar h1 {
  margin: 0;
  font-size: 1rem;
  font-weight: 700;
  color: var(--text-on-dark);
  letter-spacing: -0.01em;
}
.topbar p {
  margin: 2px 0 0;
  font-size: 0.78rem;
  color: var(--text-muted-dark);
}
.topbar-right {
  display: flex;
  gap: 8px;
  align-items: center;
}

/* ── Pills ── */
.pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  border-radius: var(--radius-pill);
  padding: 5px 12px;
  font-size: 0.75rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}
.pill.online {
  background: var(--green-bg);
  color: var(--green-text);
}
.pill.online::before {
  content: '';
  width: 7px; height: 7px;
  border-radius: 50%;
  background: var(--green);
  animation: pulse-dot 2s ease-in-out infinite;
}
.pill.offline {
  background: var(--red-bg);
  color: var(--red-text);
}
.pill.offline::before {
  content: '';
  width: 7px; height: 7px;
  border-radius: 50%;
  background: var(--red);
}

/* ── Buttons ── */
button {
  appearance: none;
  border: 0;
  border-radius: var(--radius-sm);
  padding: 7px 14px;
  font: inherit;
  font-size: 0.82rem;
  font-weight: 600;
  cursor: pointer;
  transition: background 150ms ease, opacity 150ms ease, transform 100ms ease;
}
button:active:not([disabled]) { transform: scale(0.97); }
button[disabled] { opacity: 0.4; cursor: not-allowed; }

#availabilityToggleBtn.offline-mode { background: var(--green); color: #fff; }
#availabilityToggleBtn.online-mode { background: var(--red); color: #fff; }

#refreshBtn {
  background: rgba(255,255,255,0.1);
  color: var(--text-muted-dark);
}
#refreshBtn:hover {
  background: rgba(255,255,255,0.18);
  color: var(--text-on-dark);
}

#closeSessionBtn {
  background: transparent;
  color: var(--red);
  border: 1px solid var(--red);
  font-size: 0.8rem;
  padding: 6px 12px;
}
#closeSessionBtn:hover:not([disabled]) { background: var(--red); color: #fff; }

/* ── Layout ── */
.layout {
  flex: 1;
  display: grid;
  grid-template-columns: var(--sidebar-width) 1fr;
  min-height: 0;
}

/* ── Sidebar ── */
.sidebar {
  background: var(--sidebar-bg);
  display: flex;
  flex-direction: column;
  min-height: 0;
  overflow: hidden;
  border-right: 1px solid var(--sidebar-border);
}
.sidebar-head {
  padding: 14px 14px 12px;
  border-bottom: 1px solid var(--sidebar-border);
}
.sidebar-head input[type="search"] {
  width: 100%;
  background: rgba(255,255,255,0.07);
  border: 1px solid var(--sidebar-border);
  border-radius: var(--radius-sm);
  padding: 9px 12px;
  font: inherit;
  font-size: 0.88rem;
  color: var(--text-on-dark);
  outline: none;
  transition: border-color 150ms ease, background 150ms ease;
}
.sidebar-head input[type="search"]::placeholder { color: var(--text-muted-dark); }
.sidebar-head input[type="search"]:focus {
  border-color: var(--brand);
  background: rgba(255,255,255,0.1);
}

.sessions {
  flex: 1;
  overflow-y: auto;
  padding: 8px;
}
.sessions::-webkit-scrollbar { width: 6px; }
.sessions::-webkit-scrollbar-track { background: transparent; }
.sessions::-webkit-scrollbar-thumb { background: rgba(255,255,255,0.12); border-radius: 3px; }
.sessions::-webkit-scrollbar-thumb:hover { background: rgba(255,255,255,0.2); }

.empty {
  padding: 24px 16px;
  color: var(--text-muted-dark);
  font-size: 0.88rem;
  text-align: center;
}

/* ── Session Cards ── */
.session-card {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  width: 100%;
  text-align: left;
  padding: 12px;
  margin-bottom: 4px;
  border-radius: var(--radius-md);
  background: transparent;
  color: var(--text-on-dark);
  border: 1px solid transparent;
  cursor: pointer;
  transition: background 120ms ease, border-color 120ms ease;
  font-size: 0.88rem;
}
.session-card:hover { background: var(--sidebar-hover); }
.session-card.active {
  background: var(--sidebar-active);
  border-left: 3px solid var(--brand);
}

.session-avatar {
  width: 36px; height: 36px; min-width: 36px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.82rem;
  font-weight: 700;
  color: #fff;
  margin-top: 2px;
}

.session-info { flex: 1; min-width: 0; }

.session-header {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 8px;
}
.session-name {
  font-weight: 600;
  font-size: 0.88rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.session-time {
  font-size: 0.73rem;
  color: var(--text-muted-dark);
  white-space: nowrap;
  flex-shrink: 0;
}
.session-detail {
  margin-top: 2px;
  font-size: 0.76rem;
  color: var(--text-muted-dark);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.session-preview {
  margin-top: 4px;
  font-size: 0.82rem;
  color: var(--text-muted-dark);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  line-height: 1.3;
}
.session-card.active .session-preview,
.session-card.active .session-detail { color: #b0b5be; }

.status-dot {
  width: 8px; height: 8px; min-width: 8px;
  border-radius: 50%;
  margin-top: 6px;
  margin-left: 4px;
}
.status-dot.st-active { background: var(--green); }
.status-dot.st-closed { background: #6b7280; }

/* ── Conversation Area ── */
.conversation {
  display: flex;
  flex-direction: column;
  min-width: 0; min-height: 0;
  background: var(--content-bg);
}
.conversation-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 14px 20px;
  border-bottom: 1px solid var(--border-light);
  background: var(--content-bg);
  min-height: 56px;
}
.conversation-head h2 {
  margin: 0;
  font-size: 1rem;
  font-weight: 700;
  color: var(--text-primary);
}
.meta {
  margin-top: 2px;
  font-size: 0.78rem;
  color: var(--text-secondary);
  line-height: 1.3;
}

/* ── Messages ── */
.messages {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  background: var(--content-bg-alt);
}
.messages::-webkit-scrollbar { width: 6px; }
.messages::-webkit-scrollbar-track { background: transparent; }
.messages::-webkit-scrollbar-thumb { background: rgba(0,0,0,0.1); border-radius: 3px; }

.message {
  padding: 10px 14px;
  border-radius: var(--radius-lg);
  max-width: min(680px, 85%);
  animation: message-enter 0.25s ease-out;
  position: relative;
}
.message.customer {
  align-self: flex-start;
  background: var(--msg-customer-bg);
  border-bottom-left-radius: 4px;
}
.message.operator {
  align-self: flex-end;
  background: var(--msg-operator-bg);
  border-bottom-right-radius: 4px;
}
.message.system {
  align-self: center;
  background: var(--msg-system-bg);
  color: var(--text-secondary);
  max-width: 520px;
  text-align: center;
  font-size: 0.85rem;
}

.message-head {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 10px;
}
.message-head strong { font-size: 0.82rem; font-weight: 700; }
.message.customer .message-head strong { color: #1e40af; }
.message.operator .message-head strong { color: var(--brand-dark); }
.message.system .message-head strong { color: var(--text-secondary); }

.message-meta {
  font-size: 0.73rem;
  color: var(--text-secondary);
  white-space: nowrap;
}
.message-body {
  white-space: pre-wrap;
  word-break: break-word;
  line-height: 1.5;
  margin-top: 4px;
  font-size: 0.9rem;
}
.message a { color: var(--brand-dark); text-decoration: underline; text-decoration-color: rgba(180,114,22,0.3); }
.message a:hover { text-decoration-color: var(--brand-dark); }

.attachment-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  margin-top: 8px;
  padding: 6px 12px;
  border-radius: var(--radius-pill);
  background: rgba(212,137,28,0.12);
  color: var(--brand-dark);
  font-weight: 600;
  font-size: 0.82rem;
  text-decoration: none;
  transition: background 120ms ease;
}
.attachment-chip:hover { background: rgba(212,137,28,0.22); }

.message.new-message {
  animation: message-enter 0.25s ease-out, message-glow 3s ease-out;
}

@keyframes message-enter {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}
@keyframes message-glow {
  0% { box-shadow: 0 0 0 0 rgba(239,68,68,0.3); }
  15% { box-shadow: 0 0 16px 5px rgba(239,68,68,0.45); }
  50% { box-shadow: 0 0 10px 3px rgba(239,68,68,0.2); }
  100% { box-shadow: none; }
}

/* ── Composer ── */
.composer {
  padding: 14px 20px 16px;
  border-top: 1px solid var(--border-light);
  background: var(--content-bg);
}
.composer textarea {
  width: 100%;
  border: 1px solid var(--border-light);
  border-radius: var(--radius-md);
  padding: 10px 14px;
  font: inherit;
  font-size: 0.9rem;
  background: #fff;
  resize: vertical;
  min-height: 72px;
  outline: none;
  transition: border-color 150ms ease, box-shadow 150ms ease;
}
.composer textarea:focus {
  border-color: var(--brand);
  box-shadow: 0 0 0 3px var(--brand-glow);
}
.composer-row {
  display: flex;
  gap: 8px;
  align-items: center;
  margin-top: 10px;
  flex-wrap: wrap;
}
.composer-row input[type="url"] {
  flex: 1;
  min-width: 120px;
  border: 1px solid var(--border-light);
  border-radius: var(--radius-sm);
  padding: 8px 12px;
  font: inherit;
  font-size: 0.85rem;
  outline: none;
  transition: border-color 150ms ease;
}
.composer-row input[type="url"]:focus { border-color: var(--brand); }
.composer-row input[type="url"]::placeholder { color: #aaa; }
.composer-row input[type="file"] {
  font-size: 0.82rem;
  color: var(--text-secondary);
  max-width: 200px;
}
input[type="file"]::file-selector-button {
  appearance: none;
  border: 1px solid var(--border-light);
  border-radius: var(--radius-sm);
  background: var(--content-bg-alt);
  color: var(--text-primary);
  padding: 6px 12px;
  font: inherit;
  font-size: 0.8rem;
  font-weight: 600;
  cursor: pointer;
  margin-right: 8px;
}
input[type="file"]::file-selector-button:hover { background: var(--border-light); }

#sendBtn {
  background: var(--brand);
  color: #fff;
  border-radius: var(--radius-sm);
  padding: 8px 20px;
  font-weight: 700;
  font-size: 0.88rem;
  white-space: nowrap;
}
#sendBtn:hover:not([disabled]) { background: var(--brand-dark); }

/* ── Upload Status ── */
.upload-status { margin-top: 10px; }
.upload-bar {
  width: 100%;
  height: 6px;
  border-radius: var(--radius-pill);
  background: rgba(212,137,28,0.15);
  overflow: hidden;
}
.upload-bar-fill {
  width: 0; height: 100%;
  border-radius: var(--radius-pill);
  background: linear-gradient(90deg, var(--brand), var(--brand-dark));
  transition: width 120ms linear;
}
.attachment-info {
  margin-top: 6px;
  font-size: 0.8rem;
  color: var(--text-secondary);
}

/* ── Utilities ── */
.hidden { display: none !important; }

@keyframes pulse-dot {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.4; }
}

/* ── Responsive ── */
@media (max-width: 980px) {
  :root { --sidebar-width: 100%; }
  body { overflow: auto; }
  .app-shell { height: auto; min-height: 100dvh; overflow: visible; }
  .layout { grid-template-columns: 1fr; overflow: auto; }
  .sidebar { min-height: 200px; max-height: 35vh; }
  .conversation { overflow: visible; }
  .messages { max-height: 50vh; }
  .topbar { flex-wrap: wrap; height: auto; padding: 12px 16px; gap: 8px; }
}
