/* =====================================================
   MIETSHIELD v3 — ChatGPT-Style Chat Interface
   ===================================================== */

/* ---------- DESIGN TOKENS ---------- */
:root {
  --bg-base:       #0b0f18;
  --bg-surface:    #111827;
  --bg-elevated:   #1f2937;
  --bg-input:      #1f2937;
  
  --glass-border:  rgba(255, 255, 255, 0.08);
  --border-focus:  rgba(255, 255, 255, 0.15);

  --accent:        #00c9a7;
  --accent-glow:   rgba(0, 201, 167, 0.15);
  --accent-dark:   #00a889;

  --text-primary:  #f1f5f9;
  --text-secondary:#94a3b8;
  --text-muted:    #64748b;

  --sidebar-w:     260px;
  --radius-sm:     8px;
  --radius-md:     12px;
  --radius-lg:     16px;
  --transition:    0.2s ease;
  
  --max-chat-width: 800px;
}

/* ---------- RESET ---------- */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { font-size: 16px; scroll-behavior: smooth; }
body {
  font-family: 'Inter', -apple-system, sans-serif;
  background: var(--bg-base);
  color: var(--text-primary);
  display: flex;
  height: 100vh;
  overflow: hidden;
}

::-webkit-scrollbar { width: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--glass-border); border-radius: 4px; }
::-webkit-scrollbar-thumb:hover { background: var(--border-focus); }

/* =====================================================
   SIDEBAR
   ===================================================== */
.sidebar {
  width: var(--sidebar-w);
  min-width: var(--sidebar-w);
  background: var(--bg-surface);
  border-right: 1px solid var(--glass-border);
  display: flex;
  flex-direction: column;
  padding: 16px 12px;
  gap: 16px;
  overflow-y: auto;
  transition: transform var(--transition);
  z-index: 50;
}

.sidebar.collapsed {
  transform: translateX(calc(-1 * var(--sidebar-w)));
  position: fixed;
  height: 100%;
}

.logo { display: flex; align-items: center; gap: 10px; padding: 4px; }
/* CSS Shield Logo */
.css-logo-shield {
  position: relative;
  width: 28px; height: 34px;
  background: linear-gradient(to bottom, #1a1a1a 33.3%, #d32f2f 33.3%, #d32f2f 66.6%, #fbc02d 66.6%);
  clip-path: polygon(50% 0%, 100% 12%, 100% 75%, 50% 100%, 0% 75%, 0% 12%);
  display: flex; align-items: center; justify-content: center;
}
.css-logo-shield::after {
  content: ''; position: absolute; top: 0; right: 0;
  width: 50%; height: 100%; background: rgba(0,0,0,0.25); pointer-events: none;
}
.css-logo-icon {
  width: 14px; height: 14px; color: white; z-index: 2; margin-top: 2px;
}
.css-logo-text {
  font-size: 1.15rem; font-weight: 700; color: var(--text-primary); letter-spacing: -0.2px;
}

.btn-new-chat {
  display: flex; align-items: center; gap: 10px;
  width: 100%; padding: 12px 14px;
  background: transparent;
  border: 1px solid var(--glass-border);
  border-radius: var(--radius-sm);
  color: var(--text-primary);
  font-family: inherit; font-size: 0.9rem; font-weight: 500;
  cursor: pointer;
  transition: all var(--transition);
}
.btn-new-chat:hover { background: var(--bg-elevated); border-color: var(--border-focus); }

.history-label {
  font-size: 0.75rem; font-weight: 600;
  color: var(--text-muted);
  padding: 8px 12px 4px;
}
.chat-history { flex: 1; display: flex; flex-direction: column; gap: 2px; }

.history-item {
  display: flex; align-items: center; justify-content: space-between;
  padding: 10px 12px; border-radius: var(--radius-sm);
  font-size: 0.85rem; color: var(--text-secondary);
  cursor: pointer;
  border: 1px solid transparent;
  transition: all var(--transition);
}
.history-item:hover { background: var(--bg-elevated); color: var(--text-primary); }
.history-item.active { background: var(--bg-elevated); color: var(--text-primary); font-weight: 500; }

.history-text {
  flex: 1;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}

.btn-edit-title {
  background: none; border: none; font-size: 0.8rem;
  opacity: 0; cursor: pointer; padding: 2px;
  transition: opacity 0.2s;
}
.history-item:hover .btn-edit-title { opacity: 0.6; }
.btn-edit-title:hover { opacity: 1 !important; transform: scale(1.1); }

.sidebar-footer {
  padding: 12px 4px 4px;
  border-top: 1px solid var(--glass-border);
  font-size: 0.75rem; color: var(--text-muted);
  display: flex; flex-direction: column; gap: 4px;
}

/* =====================================================
   MAIN CONTENT
   ===================================================== */
.main-content {
  flex: 1; display: flex; flex-direction: column; overflow: hidden;
  background: var(--bg-base);
  position: relative;
}

.topbar {
  display: flex; align-items: center; gap: 14px;
  padding: 14px 24px;
  border-bottom: 1px solid transparent; /* invisible unless scrolled, if desired */
  flex-shrink: 0;
}

.btn-toggle-sidebar {
  background: none; border: none; color: var(--text-secondary);
  font-size: 1.2rem; cursor: pointer; padding: 4px 6px;
  border-radius: var(--radius-sm);
  transition: all var(--transition);
}
.btn-toggle-sidebar:hover { background: var(--bg-elevated); color: var(--text-primary); }
.topbar-title { font-size: 1rem; font-weight: 600; flex: 1; color: var(--text-secondary); }

.session-badge {
  display: flex; align-items: center; gap: 6px;
  padding: 4px 12px; border-radius: 20px;
  background: var(--bg-surface); border: 1px solid var(--glass-border);
  font-size: 0.75rem; color: var(--text-secondary);
  font-family: 'Courier New', monospace;
}
.dot { width: 8px; height: 8px; border-radius: 50%; background: var(--text-muted); transition: background 0.3s; }
.dot.active { background: var(--accent); box-shadow: 0 0 6px var(--accent); }

/* =====================================================
   CHAT WINDOW
   ===================================================== */
.chat-window {
  flex: 1; overflow-y: auto;
  padding: 24px;
  display: flex; flex-direction: column; gap: 24px;
  scroll-behavior: smooth;
}

.chat-welcome {
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  text-align: center; gap: 16px;
  height: 100%; color: var(--text-secondary);
  animation: fadeUp 0.3s ease both;
}
.chat-welcome-icon { font-size: 3rem; }
.chat-welcome-title { font-size: 1.5rem; font-weight: 600; color: var(--text-primary); }
.chat-welcome-sub { font-size: 0.95rem; line-height: 1.6; max-width: 500px; }

/* Message Rows */
.message { 
  display: flex; gap: 16px; 
  animation: fadeUp 0.2s ease both; 
  width: 100%; max-width: var(--max-chat-width); margin: 0 auto;
}
.message.user { flex-direction: row-reverse; }

.message-avatar {
  width: 32px; height: 32px; border-radius: 50%; font-size: 0.9rem;
  display: flex; align-items: center; justify-content: center; flex-shrink: 0;
}
.message.user .message-avatar { background: var(--bg-surface); border: 1px solid var(--glass-border); display: none; } /* Hide user avatar for ChatGPT style */
.message.assistant .message-avatar { background: var(--accent-glow); border: 1px solid var(--accent); color: var(--accent); }

.message-bubble {
  padding: 12px 18px; border-radius: var(--radius-lg);
  font-size: 0.95rem; line-height: 1.65; word-break: break-word;
  max-width: 85%;
}

.message.user .message-bubble {
  background: var(--bg-surface);
  color: var(--text-primary);
}

.message.assistant .message-bubble {
  background: transparent;
  color: var(--text-primary);
  max-width: 100%;
}

/* Markdown Styling inside Assistant Bubble */
.message-bubble p { margin-bottom: 12px; }
.message-bubble p:last-child { margin-bottom: 0; }
.message-bubble ul, .message-bubble ol { margin-left: 20px; margin-bottom: 12px; }
.message-bubble li { margin-bottom: 4px; }
.message-bubble strong { color: #fff; font-weight: 600; }
.message-bubble h1, .message-bubble h2, .message-bubble h3 { margin-bottom: 12px; margin-top: 20px; font-weight: 600; color: #fff; }
.message-bubble h3 { font-size: 1.1rem; }

/* File Attachment in User Message */
.msg-attachment {
  display: flex; align-items: center; gap: 10px;
  background: rgba(255,255,255,0.05); border: 1px solid var(--glass-border);
  padding: 10px 14px; border-radius: var(--radius-md);
  margin-bottom: 10px; width: fit-content;
}
.msg-attachment-icon { font-size: 1.2rem; }
.msg-attachment-name { font-size: 0.85rem; font-weight: 500; }

/* Typing Dots */
.typing-dots { display: flex; gap: 4px; padding: 6px 0; }
.typing-dots span {
  width: 6px; height: 6px; background: var(--text-muted); border-radius: 50%;
  animation: bounce 1.2s infinite;
}
.typing-dots span:nth-child(2) { animation-delay: 0.2s; }
.typing-dots span:nth-child(3) { animation-delay: 0.4s; }
@keyframes bounce { 0%,80%,100% { transform: translateY(0); } 40% { transform: translateY(-5px); } }

/* =====================================================
   INPUT AREA
   ===================================================== */
.input-area-wrapper {
  padding: 16px 24px;
  background: linear-gradient(180deg, transparent 0%, var(--bg-base) 20%);
}

.chat-input-container {
  max-width: var(--max-chat-width); margin: 0 auto;
  background: var(--bg-input);
  border: 1px solid var(--glass-border);
  border-radius: var(--radius-lg);
  padding: 4px;
  display: flex; flex-direction: column;
  transition: border-color var(--transition);
}
.chat-input-container:focus-within { border-color: var(--border-focus); }

/* Attachment Preview */
.attachment-preview {
  padding: 8px 12px;
  border-bottom: 1px solid var(--glass-border);
}
.attachment-file {
  display: inline-flex; align-items: center; gap: 8px;
  background: var(--bg-base); border: 1px solid var(--glass-border);
  padding: 6px 12px; border-radius: var(--radius-sm);
}
.attachment-name { font-size: 0.8rem; font-weight: 500; max-width: 150px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.btn-remove-attachment {
  background: none; border: none; color: var(--text-muted); cursor: pointer;
  font-size: 0.9rem; margin-left: 4px;
}
.btn-remove-attachment:hover { color: var(--text-primary); }

.chat-input-form {
  display: flex; align-items: flex-end; gap: 8px;
  padding: 8px 8px 8px 12px;
}

.btn-attach {
  background: none; border: none; color: var(--text-secondary);
  cursor: pointer; padding: 8px; border-radius: var(--radius-sm);
  display: flex; align-items: center; justify-content: center;
  transition: all var(--transition); flex-shrink: 0;
}
.btn-attach:hover { color: var(--text-primary); background: rgba(255,255,255,0.05); }

.chat-input {
  flex: 1; padding: 10px 0;
  background: transparent; border: none;
  color: var(--text-primary); font-family: inherit; font-size: 0.95rem;
  outline: none; resize: none; min-height: 24px;
}
.chat-input::placeholder { color: var(--text-muted); }

.btn-send {
  width: 36px; height: 36px; border-radius: var(--radius-sm);
  background: var(--accent); border: none; color: #000;
  cursor: pointer; display: flex; align-items: center; justify-content: center;
  transition: all var(--transition); flex-shrink: 0;
}
.btn-send:hover { background: var(--accent-dark); }
.btn-send:disabled { background: var(--text-muted); color: var(--bg-base); cursor: not-allowed; }

.input-disclaimer {
  text-align: center; font-size: 0.75rem; color: var(--text-muted);
  margin-top: 12px;
}

/* =====================================================
   UTILITIES
   ===================================================== */
.hidden { display: none !important; }
@keyframes fadeUp {
  from { opacity: 0; transform: translateY(10px); }
  to   { opacity: 1; transform: translateY(0); }
}

@media (max-width: 768px) {
  .sidebar { position: fixed; height: 100%; transform: translateX(calc(-1 * var(--sidebar-w))); }
  .sidebar.open { transform: translateX(0); }
}

/* =====================================================
   MODAL
   ===================================================== */
.modal-overlay {
  position: fixed; inset: 0; z-index: 300;
  background: rgba(0, 0, 0, 0.6); backdrop-filter: blur(4px);
  display: flex; align-items: center; justify-content: center;
  opacity: 1; transition: opacity var(--transition);
}
.modal-overlay.hidden {
  opacity: 0; pointer-events: none;
}
.modal-content {
  background: var(--bg-elevated);
  border: 1px solid var(--glass-border);
  border-radius: var(--radius-lg);
  padding: 24px; width: 100%; max-width: 360px;
  box-shadow: 0 16px 40px rgba(0,0,0,0.5);
  transform: translateY(0); transition: transform 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}
.modal-overlay.hidden .modal-content { transform: translateY(20px); }
.modal-title { font-size: 1.1rem; font-weight: 600; margin-bottom: 16px; color: var(--text-primary); }
.modal-input {
  width: 100%; padding: 10px 14px;
  background: var(--bg-surface); border: 1px solid var(--glass-border);
  border-radius: var(--radius-md); color: var(--text-primary);
  font-family: inherit; font-size: 0.95rem; outline: none;
  margin-bottom: 20px; transition: border-color var(--transition);
}
.modal-input:focus { border-color: var(--accent); }
.modal-actions { display: flex; justify-content: flex-end; gap: 10px; }
.btn-cancel, .btn-save {
  padding: 8px 16px; border-radius: var(--radius-sm); font-size: 0.9rem;
  font-weight: 500; cursor: pointer; transition: all var(--transition); border: none;
}
.btn-cancel { background: transparent; color: var(--text-secondary); }
.btn-cancel:hover { background: var(--bg-surface); color: var(--text-primary); }
.btn-save { background: var(--accent); color: #000; }
.btn-save:hover { background: var(--accent-dark); }
