/* ============================================================
   style.css — Wh04m1 AI Terminal v3.0
   Baseado no teu CSS original, adaptado ao novo HTML
   ============================================================ */

:root {
  --bg-primary: #0a0e1a;
  --bg-secondary: #111827;
  --bg-tertiary: #1a1f35;
  --bg-card: #0f172a;
  --text-primary: #e2e8f0;
  --text-secondary: #94a3b8;
  --text-dim: #64748b;
  --text-faint: #475569;
  --accent: #3b82f6;
  --accent-hover: #2563eb;
  --success: #22c55e;
  --warning: #f59e0b;
  --danger: #ef4444;
  --border-color: #1e293b;
  --border-light: #334155;
  --shadow: 0 4px 20px rgba(0, 0, 0, 0.3);
  --shadow-lg: 0 10px 40px rgba(0, 0, 0, 0.5);
  --radius: 12px;
  --radius-lg: 16px;
  --radius-sm: 8px;
  --sidebar-width: 280px;
  --header-height: 56px;
  --font-mono: 'JetBrains Mono', 'Fira Code', 'Consolas', monospace;
  --font-sans: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
}

body.light-theme {
  --bg-primary: #f8fafc;
  --bg-secondary: #f1f5f9;
  --bg-tertiary: #e2e8f0;
  --bg-card: #ffffff;
  --text-primary: #0f172a;
  --text-secondary: #334155;
  --text-dim: #64748b;
  --text-faint: #94a3b8;
  --border-color: #cbd5e1;
  --border-light: #94a3b8;
  --shadow: 0 4px 20px rgba(0, 0, 0, 0.08);
  --shadow-lg: 0 10px 40px rgba(0, 0, 0, 0.12);
}

* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

body {
  font-family: var(--font-sans);
  background: var(--bg-primary);
  color: var(--text-primary);
  height: 100vh;
  overflow: hidden;
  transition: background 0.3s, color 0.3s;
}

/* ==================== SIDEBAR ==================== */
#sidebar {
  position: fixed;
  left: 0;
  top: 0;
  width: var(--sidebar-width);
  height: 100vh;
  background: var(--bg-secondary);
  border-right: 1px solid var(--border-color);
  display: flex;
  flex-direction: column;
  z-index: 100;
  transition: transform 0.3s ease;
}

#sidebar.closed {
  transform: translateX(-100%);
}

.sidebar-header {
  padding: 16px 20px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-bottom: 1px solid var(--border-color);
}

.sidebar-logo {
  font-size: 1.2rem;
  font-weight: 700;
  color: var(--accent);
}

.sidebar-close {
  background: none;
  border: none;
  color: var(--text-dim);
  font-size: 1.2rem;
  cursor: pointer;
  display: none;
}

.sidebar-user {
  padding: 16px 20px;
  display: flex;
  align-items: center;
  gap: 12px;
  cursor: pointer;
  border-bottom: 1px solid var(--border-color);
  transition: background 0.2s;
}

.sidebar-user:hover {
  background: var(--bg-tertiary);
}

.sidebar-avatar {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: var(--accent);
  display: flex;
  align-items: center;
  justify-content: center;
  color: white;
  font-size: 1rem;
}

.sidebar-user-info {
  flex: 1;
  min-width: 0;
}

#sidebarUserName {
  font-weight: 600;
  font-size: 0.9rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.sidebar-user-plan {
  font-size: 0.75rem;
  color: var(--text-dim);
}

.btn-new-chat {
  margin: 12px 16px;
  padding: 10px;
  background: var(--accent);
  color: white;
  border: none;
  border-radius: var(--radius-sm);
  font-size: 0.85rem;
  font-weight: 600;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  transition: background 0.2s;
}

.btn-new-chat:hover {
  background: var(--accent-hover);
}

.sidebar-search {
  padding: 0 16px 12px;
}

#chatSearch {
  width: 100%;
  padding: 8px 12px;
  background: var(--bg-tertiary);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  color: var(--text-primary);
  font-size: 0.8rem;
  outline: none;
}

#chatSearch:focus {
  border-color: var(--accent);
}

.sidebar-conversations {
  flex: 1;
  overflow-y: auto;
  padding: 8px 0;
}

.sidebar-section-title {
  padding: 8px 20px;
  font-size: 0.75rem;
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

#chatList {
  padding: 0 8px;
}

.chat-item {
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: space-between;
  transition: background 0.2s;
  margin: 2px 0;
}

.chat-item:hover {
  background: var(--bg-tertiary);
}

.chat-item.active {
  background: var(--bg-tertiary);
  border-left: 3px solid var(--accent);
}

.chat-item-title {
  flex: 1;
  font-size: 0.82rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  color: var(--text-secondary);
}

.chat-item-del {
  background: none;
  border: none;
  color: var(--text-faint);
  cursor: pointer;
  padding: 4px;
  opacity: 0;
  transition: opacity 0.2s;
}

.chat-item:hover .chat-item-del {
  opacity: 1;
}

.chat-item-del:hover {
  color: var(--danger);
}

.sidebar-footer {
  padding: 12px 16px;
  border-top: 1px solid var(--border-color);
  display: flex;
  gap: 8px;
  justify-content: center;
}

.sidebar-footer button {
  background: var(--bg-tertiary);
  border: 1px solid var(--border-color);
  color: var(--text-dim);
  width: 36px;
  height: 36px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s;
}

.sidebar-footer button:hover {
  background: var(--accent);
  color: white;
  border-color: var(--accent);
}

/* ==================== MAIN CONTENT ==================== */
.main-content {
  margin-left: var(--sidebar-width);
  height: 100vh;
  display: flex;
  flex-direction: column;
  transition: margin-left 0.3s;
}

#sidebar.closed ~ .main-content,
.main-content.full {
  margin-left: 0;
}

/* ==================== HEADER ==================== */
header {
  height: var(--header-height);
  padding: 0 20px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-bottom: 1px solid var(--border-color);
  background: var(--bg-secondary);
  flex-shrink: 0;
}

.menu-btn {
  background: none;
  border: none;
  color: var(--text-dim);
  font-size: 1.2rem;
  cursor: pointer;
  display: none;
  padding: 8px;
}

.header-info {
  display: flex;
  align-items: center;
  gap: 8px;
}

#currentModelDisplay {
  font-size: 0.9rem;
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

#loginBtn {
  padding: 8px 16px;
  background: var(--accent);
  color: white;
  border: none;
  border-radius: var(--radius-sm);
  font-size: 0.82rem;
  cursor: pointer;
  font-weight: 500;
  transition: background 0.2s;
}

#loginBtn:hover {
  background: var(--accent-hover);
}

/* ==================== CHAT CONTAINER ==================== */
.chat-container {
  flex: 1;
  overflow-y: auto;
  padding: 20px 24px;
  scroll-behavior: smooth;
}

.chat-container::-webkit-scrollbar {
  width: 6px;
}

.chat-container::-webkit-scrollbar-track {
  background: transparent;
}

.chat-container::-webkit-scrollbar-thumb {
  background: var(--border-color);
  border-radius: 3px;
}

/* ==================== MESSAGES ==================== */
.msg {
  max-width: 800px;
  margin: 0 auto 16px;
  padding: 16px 20px;
  border-radius: var(--radius);
  line-height: 1.65;
  font-size: 0.93rem;
  animation: fadeIn 0.3s ease;
}

@keyframes fadeIn {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}

.msg.user {
  background: var(--bg-tertiary);
  border: 1px solid var(--border-color);
  color: var(--text-primary);
  margin-left: 40px;
}

.msg.ai {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  color: var(--text-primary);
  margin-right: 40px;
}

.msg.ai p {
  margin: 8px 0;
}

.msg.ai strong {
  color: var(--accent);
}

.msg.ai em {
  color: var(--text-secondary);
}

.msg.system-info {
  background: rgba(59, 130, 246, 0.1);
  border: 1px solid rgba(59, 130, 246, 0.2);
  color: var(--text-secondary);
  font-size: 0.82rem;
  text-align: center;
  padding: 8px 16px;
}

.msg.typing {
  opacity: 0.7;
}

/* ==================== CODE BLOCKS ==================== */
.code-block {
  margin: 16px 0;
  border: 1px solid var(--border-color);
  border-radius: var(--radius);
  overflow: hidden;
  background: #0f172a;
}

.code-header {
  background: #1e293b;
  padding: 10px 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 0.78rem;
  color: var(--text-secondary);
  border-bottom: 1px solid var(--border-color);
}

.code-copy {
  padding: 4px 12px;
  background: var(--accent);
  color: white;
  border: none;
  border-radius: 4px;
  font-size: 0.75rem;
  cursor: pointer;
  transition: background 0.2s;
}

.code-copy:hover {
  background: var(--accent-hover);
}

.code-block pre {
  margin: 0;
  padding: 16px;
  overflow-x: auto;
  font-family: var(--font-mono);
  font-size: 0.85rem;
  line-height: 1.6;
  color: #e2e8f0;
}

.code-block code {
  font-family: inherit;
}

.inline-code {
  background: #1e293b;
  padding: 2px 6px;
  border-radius: 4px;
  font-family: var(--font-mono);
  font-size: 0.85em;
  color: #67e8f9;
}

/* ==================== WELCOME BOX ==================== */
.welcome-box {
  max-width: 600px;
  margin: 40px auto;
  text-align: center;
  padding: 40px 24px;
}

.welcome-header {
  font-size: 1.6rem;
  margin-bottom: 8px;
  color: var(--accent);
}

.welcome-subtitle {
  color: var(--text-dim);
  font-size: 0.9rem;
  margin-bottom: 32px;
}

.welcome-modes,
.welcome-tips,
.welcome-commands {
  text-align: left;
  margin: 20px 0;
  padding: 16px 20px;
  background: var(--bg-tertiary);
  border-radius: var(--radius);
  border: 1px solid var(--border-color);
}

.welcome-modes strong,
.welcome-tips strong,
.welcome-commands strong {
  color: var(--text-secondary);
  display: block;
  margin-bottom: 8px;
}

.welcome-modes ul,
.welcome-commands ul {
  list-style: none;
  padding: 0;
}

.welcome-modes li,
.welcome-commands li {
  padding: 8px 0;
  border-bottom: 1px solid var(--border-color);
}

.welcome-modes li:last-child,
.welcome-commands li:last-child {
  border-bottom: none;
}

.welcome-modes small,
.welcome-commands small {
  color: var(--text-dim);
  font-size: 0.82rem;
}

.welcome-tips {
  background: rgba(59, 130, 246, 0.08);
  border-color: rgba(59, 130, 246, 0.2);
}

.welcome-shortcuts {
  margin-top: 24px;
  padding: 12px;
  font-size: 0.78rem;
  color: var(--text-dim);
  background: var(--bg-tertiary);
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-color);
}

/* ==================== INPUT AREA ==================== */
.input-area {
  flex-shrink: 0;
  padding: 12px 24px 20px;
  border-top: 1px solid var(--border-color);
  background: var(--bg-secondary);
}

.input-wrap {
  max-width: 800px;
  margin: 0 auto;
  display: flex;
  align-items: flex-end;
  gap: 8px;
  background: var(--bg-tertiary);
  border: 1px solid var(--border-color);
  border-radius: var(--radius);
  padding: 8px 12px;
  transition: border-color 0.2s;
}

.input-wrap:focus-within {
  border-color: var(--accent);
}

.btn-icon {
  background: none;
  border: none;
  color: var(--text-dim);
  font-size: 1.1rem;
  cursor: pointer;
  padding: 6px;
  border-radius: 6px;
  transition: all 0.2s;
  flex-shrink: 0;
}

.btn-icon:hover {
  color: var(--accent);
  background: rgba(59, 130, 246, 0.1);
}

#input {
  flex: 1;
  background: none;
  border: none;
  color: var(--text-primary);
  font-family: var(--font-sans);
  font-size: 0.93rem;
  resize: none;
  outline: none;
  padding: 4px 0;
  min-height: 24px;
  max-height: 200px;
  line-height: 1.5;
}

#input::placeholder {
  color: var(--text-faint);
}

.btn-send,
.btn-stop {
  background: var(--accent);
  color: white;
  border: none;
  width: 36px;
  height: 36px;
  border-radius: 8px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.9rem;
  transition: all 0.2s;
  flex-shrink: 0;
}

.btn-send:hover {
  background: var(--accent-hover);
}

.btn-send:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.btn-stop {
  background: var(--danger);
}

.btn-stop:hover {
  background: #dc2626;
}

.input-footer {
  max-width: 800px;
  margin: 8px auto 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 0.75rem;
  color: var(--text-dim);
}

#modelSelect {
  background: var(--bg-tertiary);
  color: var(--text-primary);
  border: 1px solid var(--border-color);
  border-radius: 6px;
  padding: 4px 10px;
  font-size: 0.78rem;
  cursor: pointer;
  outline: none;
  max-width: 180px;
}

#modelSelect:focus {
  border-color: var(--accent);
}

#modelSelect option {
  background: var(--bg-secondary);
  color: var(--text-primary);
}

#msgCount {
  font-weight: 600;
  color: var(--text-dim);
}

/* ==================== MODAIS ==================== */
.modal {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.6);
  backdrop-filter: blur(4px);
  z-index: 1000;
  align-items: center;
  justify-content: center;
}

.modal.open {
  display: flex;
}

.modal-content {
  background: var(--bg-secondary);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  padding: 0;
  width: 92%;
  max-width: 420px;
  box-shadow: var(--shadow-lg);
  animation: modalIn 0.25s ease;
}

@keyframes modalIn {
  from { opacity: 0; transform: scale(0.95) translateY(10px); }
  to { opacity: 1; transform: scale(1) translateY(0); }
}

.modal-header {
  padding: 20px 24px 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.modal-header h2 {
  font-size: 1.2rem;
  font-weight: 700;
  color: var(--text-primary);
}

.modal-close {
  background: none;
  border: none;
  color: var(--text-dim);
  font-size: 1.5rem;
  cursor: pointer;
  padding: 4px;
  line-height: 1;
}

.modal-close:hover {
  color: var(--danger);
}

.modal-body {
  padding: 20px 24px 24px;
}

.modal-error {
  color: var(--danger);
  font-size: 0.82rem;
  margin-bottom: 12px;
  min-height: 20px;
}

.modal-input {
  width: 100%;
  padding: 10px 14px;
  background: var(--bg-tertiary);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  color: var(--text-primary);
  font-size: 0.9rem;
  margin-bottom: 12px;
  outline: none;
  transition: border-color 0.2s;
}

.modal-input:focus {
  border-color: var(--accent);
}

.modal-btn {
  width: 100%;
  padding: 12px;
  background: var(--accent);
  color: white;
  border: none;
  border-radius: var(--radius-sm);
  font-size: 0.95rem;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.2s;
  margin-top: 4px;
}

.modal-btn:hover {
  background: var(--accent-hover);
}

/* ==================== TOAST ==================== */
#toast {
  position: fixed;
  bottom: 24px;
  right: 24px;
  padding: 12px 20px;
  border-radius: var(--radius-sm);
  z-index: 9999;
  font-size: 0.85rem;
  font-weight: 500;
  box-shadow: var(--shadow-lg);
  display: none;
  animation: toastIn 0.3s ease;
  max-width: 320px;
}

@keyframes toastIn {
  from { opacity: 0; transform: translateY(12px); }
  to { opacity: 1; transform: translateY(0); }
}

/* ==================== RESPONSIVE ==================== */
@media (max-width: 900px) {
  #sidebar {
    transform: translateX(-100%);
  }
  
  #sidebar.open {
    transform: translateX(0);
  }
  
  .sidebar-close {
    display: block;
  }
  
  .main-content {
    margin-left: 0;
  }
  
  .menu-btn {
    display: flex;
  }
  
  .chat-container {
    padding: 16px;
  }
  
  .msg {
    margin-left: 0 !important;
    margin-right: 0 !important;
  }
  
  .input-area {
    padding: 8px 12px 16px;
  }
  
  .welcome-box {
    padding: 20px 16px;
    margin: 20px auto;
  }
}

@media (max-width: 600px) {
  header {
    padding: 0 12px;
  }
  
  .header-info span:last-child {
    display: none;
  }
  
  .chat-container {
    padding: 12px;
  }
  
  .msg {
    padding: 12px 16px;
    font-size: 0.88rem;
  }
  
  #modelSelect {
    max-width: 140px;
    font-size: 0.72rem;
  }
}

/* ==================== SCROLLBAR GLOBAL ==================== */
::-webkit-scrollbar {
  width: 6px;
  height: 6px;
}

::-webkit-scrollbar-track {
  background: transparent;
}

::-webkit-scrollbar-thumb {
  background: var(--border-color);
  border-radius: 3px;
}

::-webkit-scrollbar-thumb:hover {
  background: var(--text-faint);
}

/* ==================== SELEÇÃO ==================== */
::selection {
  background: rgba(59, 130, 246, 0.3);
  color: var(--text-primary);
}

/* ==================== ANIMAÇÕES EXTRAS ==================== */
.fa-fade {
  animation: fadePulse 1.5s ease-in-out infinite;
}

@keyframes fadePulse {
  0%, 100% { opacity: 0.4; }
  50% { opacity: 1; }
}

.fa-spin {
  animation: spin 1s linear infinite;
}

@keyframes spin {
  from { transform: rotate(0deg); }
  to { transform: rotate(360deg); }
}