/* ── Reset & Base ── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --sidebar-bg: #1a1a1a;
  --sidebar-hover: #2a2a2a;
  --sidebar-active: #2a2a2a;
  --accent: #A72D3A;
  --accent-hover: #8B2330;
  --accent-light: #fdf2f3;
  --text-primary: #f8fafc;
  --text-secondary: #9ca3af;
  --chat-bg: #F5F5F5;
  --msg-user-bg: #A72D3A;
  --msg-ai-bg: #ffffff;
  --input-border: #D1D5DB;
  --border: #D1D5DB;
  --shadow: 0 1px 3px rgba(0,0,0,.08), 0 1px 2px rgba(0,0,0,.06);
}

html, body { height: 100%; font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif; font-size: 15px; line-height: 1.5; }

/* ── Login Overlay ── */
.login-overlay {
  position: fixed; inset: 0; z-index: 100;
  background: linear-gradient(135deg, #1a1a1a 0%, #3a0d12 100%);
  display: flex; align-items: center; justify-content: center;
}

.login-overlay.hidden { display: none; }

.login-card {
  background: white; border-radius: 16px; padding: 48px 40px;
  width: 100%; max-width: 420px;
  box-shadow: 0 25px 50px rgba(0,0,0,.4);
  display: flex; flex-direction: column; align-items: center; gap: 12px;
}

.login-logo {
  display: flex; align-items: center; gap: 10px; margin-bottom: 8px;
}

.login-logo .logo-icon {
  width: 44px; height: 44px; background: var(--accent); border-radius: 10px;
  display: flex; align-items: center; justify-content: center;
}

.login-logo .logo-icon svg { width: 24px; height: 24px; color: white; fill: white; }
.login-logo .logo-name { font-size: 24px; font-weight: 700; color: #0f172a; }

.login-card h2 { font-size: 20px; font-weight: 600; color: #0f172a; text-align: center; }
.login-card p { color: #64748b; font-size: 14px; text-align: center; margin-bottom: 8px; }

.login-input {
  width: 100%; padding: 12px 16px; font-size: 15px;
  border: 2px solid var(--border); border-radius: 10px; outline: none;
  transition: border-color .2s;
}
.login-input:focus { border-color: var(--accent); }

.login-btn {
  width: 100%; padding: 12px; font-size: 15px; font-weight: 600;
  background: var(--accent); color: white; border: none; border-radius: 10px;
  cursor: pointer; transition: background .2s;
}
.login-btn:hover { background: var(--accent-hover); }

.login-error { color: #ef4444; font-size: 13px; display: none; }
.login-error.show { display: block; }

/* ── App Layout ── */
.app {
  display: flex; height: 100vh; overflow: hidden;
}
.app.hidden { display: none; }

/* ── Sidebar ── */
.sidebar {
  width: 260px; flex-shrink: 0;
  background: var(--sidebar-bg);
  display: flex; flex-direction: column;
  overflow: hidden;
}

.sidebar-header {
  padding: 16px 14px 14px;
  border-bottom: 1px solid rgba(255,255,255,.06);
}

/* Chat navbar */
.chat-navbar {
  flex-shrink: 0;
  height: 56px;
  background: #ffffff;
  border-bottom: 1px solid var(--border);
  display: flex; align-items: center; justify-content: flex-end;
  padding: 0 20px;
  gap: 12px;
}

.page-logo {
  height: 32px; width: auto;
}

/* Hamburger — hidden on desktop */
.hamburger-btn {
  display: none;
  background: none; border: none; cursor: pointer;
  padding: 6px; border-radius: 8px; color: #374151;
  margin-right: auto;
  transition: background .15s;
}
.hamburger-btn:hover { background: #f1f5f9; }
.hamburger-btn svg { width: 22px; height: 22px; display: block; }

/* Mobile sidebar overlay */
.sidebar-overlay {
  display: none;
  position: fixed; inset: 0; z-index: 40;
  background: rgba(0,0,0,.5);
}

/* Text wordmark */
.wordmark {
  font-family: Georgia, 'Times New Roman', serif;
  font-size: 22px; font-weight: 400; color: #f8fafc;
  letter-spacing: 0.5px;
}
.wordmark-bracket { color: #f8fafc; font-weight: 300; }
.wordmark-ai { color: #A72D3A; font-style: italic; }

.team-badge {
  display: flex; align-items: center; gap: 8px;
  background: rgba(255,255,255,.06); border-radius: 8px;
  padding: 8px 12px;
}
.team-label { font-size: 11px; font-weight: 600; color: var(--text-secondary); text-transform: uppercase; letter-spacing: .5px; }
.team-name-display { font-size: 14px; font-weight: 600; color: var(--text-primary); }

.sidebar-actions { padding: 12px 12px 8px; }

.new-chat-btn {
  width: 100%; padding: 9px 12px; font-size: 14px; font-weight: 500;
  background: rgba(167,45,58,.15); color: #f5a0a8;
  border: 1px solid rgba(167,45,58,.35); border-radius: 8px;
  cursor: pointer; transition: all .2s; text-align: left;
  display: flex; align-items: center; gap: 8px;
}
.new-chat-btn:hover { background: rgba(167,45,58,.3); color: white; }
.new-chat-btn svg { width: 16px; height: 16px; flex-shrink: 0; }

.session-list {
  flex: 1; overflow-y: auto; padding: 4px 8px;
}
.session-list::-webkit-scrollbar { width: 4px; }
.session-list::-webkit-scrollbar-track { background: transparent; }
.session-list::-webkit-scrollbar-thumb { background: rgba(255,255,255,.1); border-radius: 2px; }

.session-group-label {
  font-size: 11px; font-weight: 600; color: var(--text-secondary);
  text-transform: uppercase; letter-spacing: .5px;
  padding: 8px 8px 4px;
}

.session-item {
  padding: 9px 10px; border-radius: 8px; cursor: pointer;
  transition: background .15s; margin-bottom: 2px;
}
.session-item:hover { background: var(--sidebar-hover); }
.session-item.active { background: var(--sidebar-active); }

.session-title {
  font-size: 13px; color: var(--text-primary); font-weight: 500;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.session-meta { font-size: 11px; color: var(--text-secondary); margin-top: 2px; }

.sidebar-footer {
  padding: 12px; border-top: 1px solid rgba(255,255,255,.06);
}

.logout-btn {
  width: 100%; padding: 8px 12px; font-size: 13px; font-weight: 500;
  background: transparent; color: var(--text-secondary); border: 1px solid rgba(255,255,255,.1);
  border-radius: 8px; cursor: pointer; transition: all .2s;
  display: flex; align-items: center; gap: 8px;
}
.logout-btn:hover { background: rgba(255,255,255,.05); color: var(--text-primary); }
.logout-btn svg { width: 15px; height: 15px; }

/* ── Chat Area ── */
.chat-area {
  flex: 1; display: flex; flex-direction: column; overflow: hidden;
  background: var(--chat-bg);
}

.chat-messages {
  flex: 1; overflow-y: auto; padding: 32px 24px 16px;
  display: flex; flex-direction: column; gap: 20px;
}
.chat-messages::-webkit-scrollbar { width: 6px; }
.chat-messages::-webkit-scrollbar-thumb { background: #e2e8f0; border-radius: 3px; }

.welcome-state {
  flex: 1; display: flex; flex-direction: column;
  align-items: center; justify-content: center; gap: 12px;
  color: #94a3b8; text-align: center; padding: 40px;
}
.welcome-state .welcome-icon {
  width: 56px; height: 56px; background: #f1f5f9; border-radius: 16px;
  display: flex; align-items: center; justify-content: center;
}
.welcome-state .welcome-icon svg { width: 28px; height: 28px; color: var(--accent); stroke: var(--accent); }
.welcome-state h3 { font-size: 18px; font-weight: 600; color: #374151; }
.welcome-state p { font-size: 14px; max-width: 320px; }

/* Message rows */
.message-row {
  display: flex; flex-direction: column; max-width: 76%; gap: 4px;
}
.message-row.user { align-self: flex-end; align-items: flex-end; }
.message-row.assistant { align-self: flex-start; align-items: flex-start; }

.message-sender {
  font-size: 11px; font-weight: 600; color: #64748b;
  text-transform: uppercase; letter-spacing: .4px; padding: 0 4px;
}

.message-bubble {
  padding: 12px 16px; border-radius: 16px; font-size: 14.5px; line-height: 1.6;
  white-space: pre-wrap; word-wrap: break-word;
}

.message-row.user .message-bubble {
  background: var(--accent); color: white; border-bottom-right-radius: 4px;
}
.message-row.assistant .message-bubble {
  background: var(--msg-ai-bg); color: #1e293b; border-bottom-left-radius: 4px;
}

/* Markdown-like formatting in assistant messages */
.message-row.assistant .message-bubble strong { font-weight: 700; }
.message-row.assistant .message-bubble em { font-style: italic; }

.message-time { font-size: 11px; color: #94a3b8; padding: 0 4px; }

/* Typing indicator */
.typing-indicator {
  display: flex; align-items: center; gap: 4px;
  padding: 14px 16px; background: var(--msg-ai-bg); border-radius: 16px; border-bottom-left-radius: 4px;
  align-self: flex-start;
}
.typing-indicator span {
  width: 7px; height: 7px; background: #94a3b8; border-radius: 50%;
  animation: typing 1.2s infinite ease-in-out;
}
.typing-indicator span:nth-child(2) { animation-delay: .2s; }
.typing-indicator span:nth-child(3) { animation-delay: .4s; }
@keyframes typing {
  0%, 60%, 100% { transform: translateY(0); opacity: .5; }
  30% { transform: translateY(-6px); opacity: 1; }
}

/* ── Input Area ── */
.chat-input-area {
  padding: 16px 24px 20px;
  border-top: 1px solid var(--border);
  background: white;
}

.chat-input-wrapper {
  display: flex; align-items: flex-end; gap: 10px;
  background: #f8fafc; border: 2px solid var(--input-border);
  border-radius: 14px; padding: 10px 10px 10px 16px;
  transition: border-color .2s;
}
.chat-input-wrapper:focus-within { border-color: var(--accent); }

.chat-input {
  flex: 1; background: transparent; border: none; outline: none;
  font-size: 15px; line-height: 1.5; resize: none; max-height: 200px;
  font-family: inherit; color: #0f172a;
}
.chat-input::placeholder { color: #94a3b8; }

.send-btn {
  width: 36px; height: 36px; flex-shrink: 0;
  background: var(--accent); color: white; border: none; border-radius: 9px;
  cursor: pointer; transition: background .2s; display: flex; align-items: center; justify-content: center;
}
.send-btn:hover:not(:disabled) { background: var(--accent-hover); }
.send-btn:disabled { background: #c7d2fe; cursor: not-allowed; }
.send-btn svg { width: 17px; height: 17px; fill: none; stroke: white; stroke-width: 2; }

.input-hint {
  font-size: 12px; color: #94a3b8; margin-top: 6px; text-align: center;
}

/* ── Admin Page ── */
.admin-app { min-height: 100vh; background: #f8fafc; }

.admin-nav {
  background: var(--sidebar-bg); padding: 0 24px;
  display: flex; align-items: center; justify-content: space-between; height: 60px;
}
.admin-nav .logo {
  display: flex; align-items: center;
  background: none; border-bottom: none; padding: 0; margin: 0;
}
.admin-badge {
  background: rgba(167,45,58,.2); color: #f5a0a8;
  border: 1px solid rgba(167,45,58,.35);
  padding: 4px 12px; border-radius: 20px; font-size: 13px; font-weight: 600;
}

.admin-content { max-width: 1100px; margin: 0 auto; padding: 32px 24px; }

.admin-section {
  background: white; border-radius: 14px; border: 1px solid var(--border);
  box-shadow: var(--shadow); margin-bottom: 28px; overflow: hidden;
}

.admin-section-header {
  padding: 18px 24px; border-bottom: 1px solid var(--border);
  display: flex; align-items: center; justify-content: space-between;
}
.admin-section-header h2 { font-size: 16px; font-weight: 600; color: #0f172a; }
.admin-section-header p { font-size: 13px; color: #64748b; margin-top: 2px; }

.admin-section-body { padding: 24px; }

.system-prompt-textarea {
  width: 100%; min-height: 280px; padding: 14px 16px;
  font-size: 14px; font-family: 'SF Mono', 'Fira Code', monospace; line-height: 1.7;
  border: 2px solid var(--border); border-radius: 10px; outline: none; resize: vertical;
  transition: border-color .2s; color: #1e293b;
}
.system-prompt-textarea:focus { border-color: var(--accent); }

.prompt-meta { font-size: 12px; color: #94a3b8; margin-top: 8px; }

.btn {
  padding: 9px 20px; font-size: 14px; font-weight: 600;
  border-radius: 8px; border: none; cursor: pointer; transition: all .2s;
}
.btn-primary { background: var(--accent); color: white; }
.btn-primary:hover { background: var(--accent-hover); }
.btn-danger { background: white; color: #ef4444; border: 1px solid #fca5a5; }
.btn-danger:hover { background: #fef2f2; }
.btn-sm { padding: 5px 12px; font-size: 13px; }

.teams-grid {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 16px;
}

.team-card {
  border: 1px solid var(--border); border-radius: 10px; padding: 16px;
  cursor: pointer; transition: all .15s;
}
.team-card:hover { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-light); }
.team-card.selected { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-light); }

.team-card-name { font-size: 15px; font-weight: 700; color: #0f172a; }
.team-card-meta { font-size: 13px; color: #64748b; margin-top: 4px; }

.conversations-panel { }

.session-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 12px 16px; background: #f8fafc; border-radius: 8px; margin-bottom: 12px;
}
.session-header h4 { font-size: 14px; font-weight: 600; color: #374151; }

.admin-messages { display: flex; flex-direction: column; gap: 8px; }

.admin-msg {
  display: flex; align-items: flex-start; gap: 12px;
  padding: 12px 14px; border-radius: 8px; border: 1px solid var(--border);
}
.admin-msg.user { background: #fafaff; }
.admin-msg.assistant { background: #f8fafc; }

.admin-msg-role {
  font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: .4px;
  padding: 2px 8px; border-radius: 4px; flex-shrink: 0; margin-top: 1px;
}
.admin-msg.user .admin-msg-role { background: #eef2ff; color: var(--accent); }
.admin-msg.assistant .admin-msg-role { background: #f0fdf4; color: #16a34a; }

.admin-msg-content {
  flex: 1; font-size: 13.5px; color: #374151; line-height: 1.6; white-space: pre-wrap;
}
.admin-msg-time { font-size: 11px; color: #94a3b8; flex-shrink: 0; margin-top: 2px; }

/* Auth gate */
.auth-gate {
  min-height: 100vh; background: linear-gradient(135deg, #1a1a1a 0%, #3a0d12 100%);
  display: flex; align-items: center; justify-content: center;
}
.auth-card {
  background: white; border-radius: 14px; padding: 40px; width: 100%; max-width: 380px;
  box-shadow: 0 20px 40px rgba(0,0,0,.3); text-align: center;
}
.auth-card h2 { font-size: 20px; font-weight: 700; color: #0f172a; margin-bottom: 8px; }
.auth-card p { font-size: 14px; color: #64748b; margin-bottom: 24px; }
.auth-input {
  width: 100%; padding: 12px 16px; font-size: 15px;
  border: 2px solid var(--border); border-radius: 8px; outline: none; margin-bottom: 12px;
  transition: border-color .2s;
}
.auth-input:focus { border-color: var(--accent); }
.auth-error { color: #ef4444; font-size: 13px; margin-top: 8px; display: none; }
.auth-error.show { display: block; }

/* Toast */
.toast {
  position: fixed; bottom: 24px; right: 24px; z-index: 999;
  background: #0f172a; color: white; padding: 12px 20px; border-radius: 10px;
  font-size: 14px; box-shadow: 0 8px 24px rgba(0,0,0,.2);
  transform: translateY(100px); opacity: 0; transition: all .3s;
}
.toast.show { transform: translateY(0); opacity: 1; }
.toast.success { background: #166534; }
.toast.error { background: #991b1b; }

/* Utils */
.hidden { display: none !important; }
.flex { display: flex; }
.gap-2 { gap: 8px; }
.mt-2 { margin-top: 8px; }
.mt-4 { margin-top: 16px; }

/* ── Mobile ── */
@media (max-width: 768px) {
  /* Sidebar slides in from left as overlay */
  .sidebar {
    position: fixed; inset-block: 0; left: 0; z-index: 50;
    width: 280px;
    transform: translateX(-100%);
    transition: transform .25s ease;
  }
  .sidebar.open { transform: translateX(0); }
  .sidebar-overlay.open { display: block; }

  /* Show hamburger, navbar left-aligned */
  .hamburger-btn { display: flex; align-items: center; justify-content: center; }
  .chat-navbar { justify-content: space-between; }

  /* Messages fill more width */
  .message-row { max-width: 90%; }
  .chat-messages { padding: 20px 14px 12px; }

  /* Input area tighter */
  .chat-input-area { padding: 10px 12px 14px; }
  .input-hint { display: none; }

  /* Login card full-width with less padding */
  .login-card { padding: 36px 24px; border-radius: 0; min-height: 100dvh; justify-content: center; }

  /* Admin responsive */
  .admin-content { padding: 20px 16px; }
  .admin-section-header { flex-direction: column; align-items: flex-start; gap: 10px; }
  .admin-section-body { padding: 16px; }
  .admin-msg { flex-wrap: wrap; }
  .admin-msg-time { width: 100%; text-align: left; }
}
