/* ============================================================================
   CHAT BASE STYLES - Shared Layout & Component Styles
   ============================================================================
   This file contains all layout, structural, and component styles shared
   between chat-calm.html and chat-dark.html. Color themes are defined
   separately in theme-specific CSS files using CSS custom properties.
   ========================================================================== */

/* ============================================================================
   RESET & BASE
   ========================================================================== */

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

html, body {
  height: 100%;
  overflow: hidden;
}

body {
  display: flex;
  flex-direction: column;
}

/* ============================================================================
   TOPBAR
   ========================================================================== */

.topbar {
  height: 62px;
  flex-shrink: 0;
  border-bottom-width: 1px;
  border-bottom-style: solid;
  border-bottom-color: var(--border-primary);
  display: flex;
  align-items: center;
  padding: 0 16px;
  gap: 10px;
  background: var(--bg-primary);
}

.tb-sep {
  width: 1px;
  height: 26px;
  margin: 0 6px;
  background: var(--border-primary);
}

.tb-model {
  font-size: 12px;
  font-weight: 600;
  color: var(--text-secondary);
}

.tb-spacer {
  flex: 1;
}

.tb-status {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 11px;
  font-weight: 700;
  padding: 5px 12px;
  border-radius: 20px;
  white-space: nowrap;
  flex-shrink: 0;
  background: var(--bg-status-badge);
  color: var(--text-status-badge);
}

.status-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--status-dot-color);
  animation: blink 2.5s ease-in-out infinite;
}

@keyframes blink {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.35; }
}

/* ============================================================================
   MAIN LAYOUT
   ========================================================================== */

.main {
  flex: 1;
  display: flex;
  overflow: hidden;
}

/* ============================================================================
   SIDEBAR
   ========================================================================== */

.sidebar {
  width: 220px;
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  padding: 16px 12px;
  gap: 4px;
  overflow-y: auto;
  background: var(--bg-sidebar);
  border-right: 1px solid var(--border-primary);
}

.sidebar::-webkit-scrollbar {
  width: 3px;
}

.sidebar::-webkit-scrollbar-thumb {
  background: var(--scrollbar-thumb);
  border-radius: 2px;
}

.sb-label {
  font-size: 10px;
  font-weight: 800;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  padding: 6px 8px 4px;
  margin-top: 6px;
  color: var(--text-tertiary);
}

.sb-label:first-child {
  margin-top: 0;
}

.sb-item {
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 9px 10px;
  border-radius: 12px;
  cursor: pointer;
  font-size: 13px;
  font-weight: 600;
  transition: background 0.15s, color 0.15s;
  border: 1px solid transparent;
  color: var(--text-primary);
}

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

.sb-item-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  flex-shrink: 0;
  background: var(--dot-color);
}

.sb-divider {
  height: 1px;
  margin: 8px 4px;
  background: var(--border-subtle);
}

.sb-stat-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 4px 8px;
  font-size: 11px;
  font-weight: 500;
  color: var(--text-secondary);
}

.sb-stat-val {
  font-size: 11px;
  font-weight: 800;
  color: var(--text-primary);
}

/* ============================================================================
   CHAT WRAPPER & MESSAGES
   ========================================================================== */

.chat-wrap {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  max-width: 820px;
  margin: 0 auto;
  width: 100%;
  padding: 0 20px;
  background: var(--bg-chat);
}

.messages {
  flex: 1;
  overflow-y: auto;
  padding: 32px 0 24px;
  display: flex;
  flex-direction: column;
  gap: 24px;
}

.messages::-webkit-scrollbar {
  width: 4px;
}

.messages::-webkit-scrollbar-thumb {
  background: var(--scrollbar-thumb);
  border-radius: 2px;
}

/* ============================================================================
   SYSTEM MESSAGES
   ========================================================================== */

.sys-msg {
  text-align: center;
  font-size: 12px;
  font-weight: 600;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 0 8px;
  color: var(--text-secondary);
}

.sys-msg::before,
.sys-msg::after {
  content: '';
  flex: 1;
  height: 1px;
  background: var(--border-subtle);
}

/* ============================================================================
   MESSAGE ROWS
   ========================================================================== */

.msg {
  display: flex;
  gap: 12px;
  align-items: flex-start;
}

.msg.user {
  flex-direction: row-reverse;
}

.msg-avatar {
  width: 36px;
  height: 36px;
  border-radius: 12px;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 12px;
  font-weight: 800;
  margin-top: 2px;
  background: var(--avatar-bg);
  color: var(--avatar-text);
}

.msg.ai .msg-avatar {
  background: var(--avatar-ai-bg);
  color: var(--avatar-ai-text);
}

.msg.user .msg-avatar {
  background: var(--avatar-user-bg);
  color: var(--avatar-user-text);
}

.msg-body {
  max-width: 640px;
  flex: 1;
}

.msg.user .msg-body {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
}

.msg-name {
  font-size: 11px;
  font-weight: 800;
  margin-bottom: 5px;
  letter-spacing: 0.02em;
  color: var(--text-secondary);
}

.msg-bubble {
  padding: 16px 20px;
  border-radius: 18px;
  font-size: 15px;
  line-height: 1.7;
  font-weight: 500;
  color: var(--text-primary);
}

.msg.ai .msg-bubble {
  border-width: 1px;
  border-style: solid;
  border-color: var(--border-bubble);
  border-top-left-radius: 4px;
  background: var(--bg-bubble-ai);
}

.msg.user .msg-bubble {
  border-top-right-radius: 4px;
  font-weight: 600;
  background: var(--bg-bubble-user);
  color: var(--text-bubble-user);
}

/* ============================================================================
   CITATIONS
   ========================================================================== */

.citations {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 12px;
}

.cite {
  display: flex;
  align-items: center;
  gap: 5px;
  font-size: 11px;
  font-weight: 700;
  padding: 4px 10px;
  border-radius: 20px;
  cursor: pointer;
  transition: background 0.15s;
  background: var(--bg-cite);
  color: var(--text-cite);
}

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

.cite-dot {
  width: 5px;
  height: 5px;
  border-radius: 50%;
  background: var(--dot-cite);
}

/* ============================================================================
   CONFIDENCE BARS
   ========================================================================== */

.confidence {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-top: 10px;
}

.conf-label {
  font-size: 11px;
  font-weight: 600;
  color: var(--text-secondary);
}

.conf-track {
  flex: 1;
  height: 4px;
  border-radius: 4px;
  overflow: hidden;
  max-width: 120px;
  background: var(--bg-confidence-track);
}

.conf-fill {
  height: 100%;
  border-radius: 4px;
  background: var(--bg-confidence-fill);
  transition: width 1.8s ease;
}

.conf-val {
  font-size: 11px;
  font-weight: 800;
  color: var(--text-secondary);
}

/* ============================================================================
   THINKING ANIMATION
   ========================================================================== */

.thinking {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 14px 18px;
  border-width: 1px;
  border-style: solid;
  border-color: var(--border-thinking);
  border-radius: 18px;
  border-top-left-radius: 4px;
  width: fit-content;
  font-size: 13px;
  font-weight: 600;
  background: var(--bg-thinking);
  color: var(--text-thinking);
}

.think-dots {
  display: flex;
  gap: 4px;
}

.think-dots span {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--dot-thinking);
  opacity: 0.3;
  animation: tdot 1.2s ease-in-out infinite;
}

.think-dots span:nth-child(2) {
  animation-delay: 0.18s;
}

.think-dots span:nth-child(3) {
  animation-delay: 0.36s;
}

@keyframes tdot {
  0%, 60%, 100% {
    opacity: 0.2;
    transform: scale(0.8);
  }
  30% {
    opacity: 1;
    transform: scale(1.2);
  }
}

/* ============================================================================
   AI CURSOR
   ========================================================================== */

.ai-cursor {
  display: inline-block;
  width: 2px;
  height: 17px;
  vertical-align: middle;
  margin-left: 2px;
  border-radius: 1px;
  background: var(--cursor-color);
  animation: cblink 0.8s step-end infinite;
}

@keyframes cblink {
  0%, 100% { opacity: 1; }
  50% { opacity: 0; }
}

/* ============================================================================
   INPUT AREA
   ========================================================================== */

.input-area {
  flex-shrink: 0;
  padding: 0 0 20px;
}

.input-card {
  border-width: 1.5px;
  border-style: solid;
  border-color: var(--border-input);
  border-radius: 20px;
  display: flex;
  align-items: center;
  gap: 0;
  overflow: hidden;
  transition: border-color 0.2s, box-shadow 0.2s;
  background: var(--bg-input-card);
}

.input-card:focus-within {
  border-color: var(--border-input-focus);
  box-shadow: var(--shadow-input-focus);
}

.input-field {
  flex: 1;
  padding: 14px 20px;
  font-size: 15px;
  font-weight: 500;
  background: transparent;
  border: none;
  outline: none;
  resize: none;
  min-height: 48px;
  max-height: 140px;
  line-height: 1.5;
  color: var(--text-input);
}

.input-field::placeholder {
  color: var(--text-input-placeholder);
  font-weight: 400;
}

.input-actions {
  padding: 10px 12px;
  display: flex;
  align-items: flex-end;
  gap: 6px;
}

.send-btn {
  width: 38px;
  height: 38px;
  border-radius: 12px;
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s, transform 0.1s;
  flex-shrink: 0;
  background: var(--bg-send-btn);
  color: var(--text-send-btn);
}

.send-btn:hover {
  background: var(--bg-send-btn-hover);
  transform: scale(1.04);
}

.send-btn:active {
  transform: scale(0.97);
}

.send-btn svg {
  width: 16px;
  height: 16px;
}

.input-hint {
  text-align: center;
  font-size: 11px;
  font-weight: 600;
  margin-top: 8px;
  color: var(--text-tertiary);
}

/* ============================================================================
   MOBILE OVERLAY
   ========================================================================== */

.sidebar-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.4);
  z-index: 99;
}

/* ============================================================================
   MOBILE RESPONSIVE (max-width: 768px)
   ========================================================================== */

@media (max-width: 768px) {
  /* Topbar adjustments */
  .topbar {
    padding: 0 12px;
    gap: 8px;
  }

  .topbar .tb-sep {
    display: none;
  }

  .topbar > div:not(:first-child):not(.tb-spacer):not(.tb-status):not(.mobile-menu-btn-wrap) {
    display: none;
  }

  .topbar .tb-center-info {
    display: none;
  }

  /* Sidebar mobile overlay */
  .sidebar {
    position: fixed;
    top: 62px;
    left: 0;
    bottom: 0;
    z-index: 100;
    width: 260px;
    transform: translateX(-100%);
    transition: transform 0.25s ease;
    border-right: none;
    border-left: 1px solid var(--border-primary);
  }

  .sidebar.open {
    transform: translateX(0);
  }

  .sidebar-overlay.open {
    display: block;
  }

  /* Chat wrap adjustments */
  .chat-wrap {
    padding: 0 12px;
  }

  /* Message bubble adjustments */
  .msg-bubble {
    padding: 12px 16px;
    font-size: 14px;
  }

  /* Avatar adjustments */
  .msg-avatar {
    width: 30px;
    height: 30px;
    font-size: 10px;
  }

  /* Message body max-width */
  .msg-body {
    max-width: calc(100vw - 80px);
  }

  /* Input field adjustments - 16px prevents iOS auto-zoom on focus */
  .input-field {
    padding: 12px 16px;
    font-size: 16px;
    min-height: 46px;
  }

  /* Shorter placeholder on mobile so it doesn't overflow */
  .input-field::placeholder {
    font-size: 14px;
    text-overflow: ellipsis;
  }
}
