/* =====================================================
   AI Chat - Main Stylesheet
   ChatGPT-like dark theme with glassmorphism
   ===================================================== */

/* CSS Variables */
:root {
  --bg-primary: #0d0d0d;
  --bg-secondary: #171717;
  --bg-tertiary: #212121;
  --bg-hover: #2a2a2a;
  --bg-active: #333333;
  --bg-sidebar: #171717;
  --bg-input: #2f2f2f;
  --bg-message-user: #2f2f2f;
  --bg-message-ai: transparent;

  --text-primary: #ececec;
  --text-secondary: #b4b4b4;
  --text-muted: #767676;
  --text-inverse: #000;

  --border-color: #2e2e2e;
  --border-light: #383838;

  --accent: #6366f1;
  --accent-hover: #5558e6;
  --accent-light: rgba(99, 102, 241, 0.15);

  --success: #10b981;
  --warning: #f59e0b;
  --danger: #ef4444;

  --sidebar-width: 260px;
  --header-height: 52px;

  --font-main:
    -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue",
    sans-serif;
  --font-mono: "SF Mono", "Fira Code", "Consolas", monospace;

  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 16px;

  --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.2);
  --shadow-md: 0 4px 12px rgba(0, 0, 0, 0.3);
  --shadow-lg: 0 8px 32px rgba(0, 0, 0, 0.4);

  --transition-fast: 0.15s ease;
  --transition-normal: 0.25s ease;
}

/* Reset */
*,
*::before,
*::after {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

html,
body {
  height: 100%;
  height: 100dvh;
  font-family: var(--font-main);
  font-size: 15px;
  line-height: 1.6;
  color: var(--text-primary);
  background: var(--bg-primary);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  overflow: hidden;
  overscroll-behavior: none;
  -webkit-overflow-scrolling: touch;
  touch-action: manipulation;
}

a {
  color: var(--accent);
  text-decoration: none;
}

button {
  font-family: var(--font-main);
  cursor: pointer;
  border: none;
  background: none;
  color: inherit;
}

/* ==================
   APP LAYOUT
   ================== */

.app-container {
  display: flex;
  height: 100vh;
  height: 100dvh;
  height: var(--app-vh, 100dvh);
  overflow: hidden;
  /* iOS safe area support */
  padding-top: constant(safe-area-inset-top);
  padding-top: env(safe-area-inset-top);
}

/* ==================
   SIDEBAR
   ================== */

.sidebar {
  width: var(--sidebar-width);
  min-width: var(--sidebar-width);
  background: var(--bg-sidebar);
  display: flex;
  flex-direction: column;
  border-right: 1px solid var(--border-color);
  transition:
    transform var(--transition-normal),
    opacity var(--transition-normal);
  z-index: 100;
}

.sidebar-header {
  padding: 12px;
  display: flex;
  gap: 8px;
  align-items: center;
}

.btn-new-chat {
  flex: 1;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 14px;
  background: var(--bg-tertiary);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  color: var(--text-primary);
  font-size: 14px;
  font-weight: 500;
  transition: all var(--transition-fast);
}

.btn-new-chat:hover {
  background: var(--bg-hover);
  border-color: var(--border-light);
}

.btn-sidebar-close {
  display: none;
  padding: 8px;
  border-radius: var(--radius-sm);
  color: var(--text-secondary);
}

.btn-sidebar-close:hover {
  background: var(--bg-hover);
}

.sidebar-search {
  padding: 0 12px 8px;
}

.sidebar-search input {
  width: 100%;
  padding: 8px 12px;
  background: var(--bg-tertiary);
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  color: var(--text-primary);
  font-size: 13px;
  transition: all var(--transition-fast);
}

.sidebar-search input:focus {
  outline: none;
  border-color: var(--border-light);
  background: var(--bg-hover);
}

.sidebar-search input::placeholder {
  color: var(--text-muted);
}

.sidebar-conversations {
  flex: 1;
  overflow-y: auto;
  padding: 4px 8px;
  scrollbar-width: thin;
  scrollbar-color: var(--bg-hover) transparent;
}

.sidebar-conversations::-webkit-scrollbar {
  width: 4px;
}

.sidebar-conversations::-webkit-scrollbar-thumb {
  background: var(--bg-hover);
  border-radius: 4px;
}

/* Conversation Items */
.conv-item {
  display: flex;
  align-items: center;
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: background var(--transition-fast);
  position: relative;
  margin-bottom: 1px;
  group: conv-item;
}

.conv-item:hover {
  background: var(--bg-hover);
}

.conv-item.active {
  background: var(--bg-active);
}

.conv-item-title {
  flex: 1;
  font-size: 14px;
  color: var(--text-secondary);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  padding-right: 4px;
}

.conv-item.active .conv-item-title {
  color: var(--text-primary);
}

.conv-item-actions {
  display: none;
  gap: 2px;
  flex-shrink: 0;
}

.conv-item:hover .conv-item-actions {
  display: flex;
}

.conv-item-btn {
  padding: 4px;
  border-radius: 4px;
  color: var(--text-muted);
  transition: all var(--transition-fast);
}

.conv-item-btn:hover {
  background: var(--bg-primary);
  color: var(--text-primary);
}

/* Sidebar Date Groups */
.conv-group-label {
  padding: 8px 12px 4px;
  font-size: 11px;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

/* Sidebar Footer */
.sidebar-footer {
  padding: 12px;
  border-top: 1px solid var(--border-color);
}

.sidebar-user-info {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px;
  border-radius: var(--radius-sm);
  margin-bottom: 8px;
}

.user-avatar {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: var(--accent);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 14px;
  font-weight: 600;
  text-transform: uppercase;
  flex-shrink: 0;
}

.user-details {
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.user-name {
  font-size: 13px;
  font-weight: 500;
  color: var(--text-primary);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.user-quota {
  font-size: 11px;
  color: var(--text-muted);
}

.sidebar-actions {
  display: flex;
  gap: 4px;
}

.btn-sidebar-action {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 8px;
  border-radius: var(--radius-sm);
  color: var(--text-secondary);
  transition: all var(--transition-fast);
}

.btn-sidebar-action:hover {
  background: var(--bg-hover);
  color: var(--text-primary);
}

/* Sidebar Overlay (mobile) */
.sidebar-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.6);
  z-index: 99;
  backdrop-filter: blur(4px);
}

/* ==================
   MAIN CONTENT
   ================== */

.main-content {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  position: relative;
}

/* Header */
.main-header {
  height: var(--header-height);
  display: flex;
  align-items: center;
  padding: 0 16px;
  border-bottom: 1px solid var(--border-color);
  background: var(--bg-secondary);
  gap: 12px;
  flex-shrink: 0;
}

.btn-menu {
  display: none;
  padding: 6px;
  border-radius: var(--radius-sm);
  color: var(--text-secondary);
}

.btn-menu:hover {
  background: var(--bg-hover);
}

.conversation-title {
  flex: 1;
  font-size: 16px;
  font-weight: 600;
  color: var(--text-primary);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.header-actions {
  display: flex;
  gap: 4px;
}

.btn-header-action {
  padding: 8px;
  border-radius: var(--radius-sm);
  color: var(--text-secondary);
  transition: all var(--transition-fast);
}

.btn-header-action:hover {
  background: var(--bg-hover);
  color: var(--text-primary);
}

/* ==================
   MESSAGES
   ================== */

.messages-container {
  flex: 1;
  overflow-y: auto;
  scroll-behavior: smooth;
  scrollbar-width: thin;
  scrollbar-color: var(--bg-hover) transparent;
}

.messages-container::-webkit-scrollbar {
  width: 6px;
}

.messages-container::-webkit-scrollbar-thumb {
  background: var(--bg-hover);
  border-radius: 6px;
}

/* Welcome Screen */
.welcome-screen {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  height: 100%;
  padding: 40px 20px;
  text-align: center;
}

.welcome-icon {
  font-size: 48px;
  margin-bottom: 16px;
  opacity: 0.8;
}

.welcome-screen h1 {
  font-size: 28px;
  font-weight: 700;
  color: var(--text-primary);
  margin-bottom: 8px;
}

.welcome-screen p {
  font-size: 16px;
  color: var(--text-secondary);
  margin-bottom: 32px;
}

.welcome-suggestions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  max-width: 600px;
  width: 100%;
}

.suggestion-chip {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 14px 16px;
  background: var(--bg-tertiary);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  color: var(--text-secondary);
  font-size: 14px;
  text-align: left;
  transition: all var(--transition-fast);
}

.suggestion-chip:hover {
  background: var(--bg-hover);
  border-color: var(--border-light);
  color: var(--text-primary);
}

.suggestion-chip svg {
  flex-shrink: 0;
  opacity: 0.7;
}

/* Message Bubbles */
.messages-list {
  max-width: 768px;
  margin: 0 auto;
  padding: 20px 24px 40px;
  width: 100%;
}

.message {
  margin-bottom: 24px;
  display: flex;
  gap: 16px;
  animation: messageIn 0.3s ease;
}

@keyframes messageIn {
  from {
    opacity: 0;
    transform: translateY(8px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.message-avatar {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 14px;
  font-weight: 600;
  flex-shrink: 0;
  margin-top: 2px;
}

.message-avatar.avatar-user {
  background: var(--accent);
  color: #fff;
  text-transform: uppercase;
}

.message-avatar.avatar-ai {
  background: linear-gradient(135deg, #10b981, #6366f1);
  color: #fff;
  font-size: 16px;
}

.message-body {
  flex: 1;
  min-width: 0;
}

.message-sender {
  font-size: 14px;
  font-weight: 600;
  color: var(--text-primary);
  margin-bottom: 4px;
}

.message-content {
  font-size: 15px;
  line-height: 1.7;
  color: var(--text-primary);
  word-wrap: break-word;
  overflow-wrap: break-word;
}

/* Markdown Rendering */
.message-content p {
  margin-bottom: 12px;
}

.message-content p:last-child {
  margin-bottom: 0;
}

.message-content h1,
.message-content h2,
.message-content h3,
.message-content h4,
.message-content h5,
.message-content h6 {
  margin-top: 20px;
  margin-bottom: 8px;
  font-weight: 600;
  line-height: 1.3;
}

.message-content h1 {
  font-size: 1.5em;
}
.message-content h2 {
  font-size: 1.3em;
}
.message-content h3 {
  font-size: 1.15em;
}

.message-content ul,
.message-content ol {
  margin: 8px 0;
  padding-left: 24px;
}

.message-content li {
  margin-bottom: 4px;
}

.message-content blockquote {
  border-left: 3px solid var(--accent);
  margin: 12px 0;
  padding: 8px 16px;
  background: var(--bg-tertiary);
  border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
  color: var(--text-secondary);
}

.message-content a {
  color: var(--accent);
  text-decoration: underline;
  text-underline-offset: 2px;
}

.message-content strong {
  font-weight: 600;
  color: var(--text-primary);
}

.message-content em {
  font-style: italic;
}

.message-content hr {
  border: none;
  border-top: 1px solid var(--border-color);
  margin: 16px 0;
}

.message-content table {
  width: 100%;
  border-collapse: collapse;
  margin: 12px 0;
  font-size: 14px;
}

.message-content th,
.message-content td {
  padding: 8px 12px;
  border: 1px solid var(--border-color);
  text-align: left;
}

.message-content th {
  background: var(--bg-tertiary);
  font-weight: 600;
}

/* Code blocks */
.message-content code {
  font-family: var(--font-mono);
  font-size: 13px;
  background: var(--bg-tertiary);
  padding: 2px 6px;
  border-radius: 4px;
  color: #e2e8f0;
}

.message-content pre {
  position: relative;
  margin: 12px 0;
  border-radius: var(--radius-sm);
  overflow: hidden;
  background: #1a1a2e;
}

.message-content pre code {
  display: block;
  padding: 16px;
  overflow-x: auto;
  background: none;
  border-radius: 0;
  line-height: 1.5;
  font-size: 13px;
}

.code-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 8px 16px;
  background: #141428;
  font-size: 12px;
  color: var(--text-muted);
}

.btn-copy {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 4px 10px;
  border-radius: 4px;
  font-size: 12px;
  color: var(--text-muted);
  transition: all var(--transition-fast);
  background: none;
  border: none;
  cursor: pointer;
}

.btn-copy:hover {
  background: rgba(255, 255, 255, 0.1);
  color: var(--text-primary);
}

.btn-copy.copied {
  color: var(--success);
}

/* Message actions */
.message-actions {
  display: flex;
  gap: 4px;
  margin-top: 8px;
  opacity: 0;
  transition: opacity var(--transition-fast);
}

.message:hover .message-actions {
  opacity: 1;
}

.btn-msg-action {
  padding: 4px 8px;
  border-radius: 4px;
  font-size: 12px;
  color: var(--text-muted);
  transition: all var(--transition-fast);
}

.btn-msg-action:hover {
  background: var(--bg-hover);
  color: var(--text-primary);
}

/* Typing Indicator */
.typing-indicator {
  max-width: 768px;
  margin: 0 auto;
  padding: 0 24px 20px;
  display: flex;
  gap: 16px;
  align-items: flex-start;
  animation: messageIn 0.3s ease;
}

.typing-avatar {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: linear-gradient(135deg, #10b981, #6366f1);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 16px;
  flex-shrink: 0;
}

.typing-dots {
  display: flex;
  gap: 4px;
  padding: 12px 0;
}

.typing-dots span {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--text-muted);
  animation: typingBounce 1.4s infinite;
}

.typing-dots span:nth-child(2) {
  animation-delay: 0.2s;
}
.typing-dots span:nth-child(3) {
  animation-delay: 0.4s;
}

@keyframes typingBounce {
  0%,
  60%,
  100% {
    transform: translateY(0);
    opacity: 0.4;
  }
  30% {
    transform: translateY(-6px);
    opacity: 1;
  }
}

/* ==================
   INPUT AREA
   ================== */

.input-container {
  padding: 12px 16px 16px;
  max-width: 768px;
  margin: 0 auto;
  width: 100%;
  /* Safe area: keep input above OS navigation bar */
  padding-bottom: constant(safe-area-inset-bottom);
  padding-bottom: env(safe-area-inset-bottom);
  padding-bottom: calc(16px + constant(safe-area-inset-bottom));
  padding-bottom: calc(16px + env(safe-area-inset-bottom));
  flex-shrink: 0;
}

.input-wrapper {
  display: flex;
  align-items: flex-end;
  background: var(--bg-input);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  padding: 8px 12px;
  transition: border-color var(--transition-fast);
  gap: 8px;
}

.input-wrapper:focus-within {
  border-color: var(--border-light);
}

.input-wrapper textarea {
  flex: 1;
  background: none;
  border: none;
  color: var(--text-primary);
  font-size: 15px;
  font-family: var(--font-main);
  line-height: 1.5;
  resize: none;
  max-height: 200px;
  padding: 6px 4px;
  overflow-y: auto;
}

.input-wrapper textarea:focus {
  outline: none;
}

.input-wrapper textarea::placeholder {
  color: var(--text-muted);
}

.btn-send {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--text-muted);
  color: var(--bg-primary);
  transition: all var(--transition-fast);
  flex-shrink: 0;
}

.btn-send:not(:disabled) {
  background: var(--text-primary);
}

.btn-send:not(:disabled):hover {
  background: #fff;
  transform: scale(1.05);
}

.btn-send:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.btn-send.btn-stop {
  background: #ef4444;
  color: #fff;
  opacity: 1;
  cursor: pointer;
  animation: pulse-stop 1.5s ease-in-out infinite;
}

.btn-send.btn-stop:hover {
  background: #dc2626;
  transform: scale(1.05);
}

@keyframes pulse-stop {
  0%,
  100% {
    box-shadow: 0 0 0 0 rgba(239, 68, 68, 0.4);
  }
  50% {
    box-shadow: 0 0 0 6px rgba(239, 68, 68, 0);
  }
}

.input-footer {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 6px 4px 0;
}

.model-badge {
  font-size: 11px;
  color: var(--text-muted);
  background: var(--bg-tertiary);
  padding: 2px 8px;
  border-radius: 4px;
}

.char-counter {
  font-size: 11px;
  color: var(--text-muted);
}

/* ==================
   MODALS
   ================== */

.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.6);
  backdrop-filter: blur(4px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 200;
  padding: 20px;
  animation: fadeIn 0.2s ease;
}

@keyframes fadeIn {
  from {
    opacity: 0;
  }
  to {
    opacity: 1;
  }
}

.modal-card {
  background: var(--bg-secondary);
  border-radius: var(--radius-lg);
  width: 100%;
  max-width: 480px;
  box-shadow: var(--shadow-lg);
  border: 1px solid var(--border-color);
  animation: slideUp 0.2s ease;
}

.modal-card.modal-small {
  max-width: 380px;
}

.modal-card.modal-large {
  max-width: 680px;
  max-height: 80vh;
  display: flex;
  flex-direction: column;
}

@keyframes slideUp {
  from {
    transform: translateY(16px);
    opacity: 0;
  }
  to {
    transform: translateY(0);
    opacity: 1;
  }
}

.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 16px 20px;
  border-bottom: 1px solid var(--border-color);
}

.modal-header h3 {
  font-size: 16px;
  font-weight: 600;
}

.modal-close {
  width: 28px;
  height: 28px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--radius-sm);
  font-size: 20px;
  color: var(--text-secondary);
  transition: all var(--transition-fast);
}

.modal-close:hover {
  background: var(--bg-hover);
}

.modal-body {
  padding: 20px;
}

.modal-scroll {
  overflow-y: auto;
  max-height: 60vh;
}

.modal-footer {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  padding: 16px 20px;
  border-top: 1px solid var(--border-color);
}

.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: 14px;
  font-family: var(--font-main);
  transition: all var(--transition-fast);
}

.modal-input:focus {
  outline: none;
  border-color: var(--accent);
}

.modal-textarea {
  resize: vertical;
  min-height: 80px;
}

.btn-modal {
  padding: 8px 20px;
  border-radius: var(--radius-sm);
  font-size: 14px;
  font-weight: 500;
  transition: all var(--transition-fast);
}

.btn-cancel {
  color: var(--text-secondary);
  background: var(--bg-tertiary);
}

.btn-cancel:hover {
  background: var(--bg-hover);
}

.btn-primary {
  background: var(--accent);
  color: #fff;
}

.btn-primary:hover {
  background: var(--accent-hover);
}

/* Quota Modal Content */
.quota-section {
  margin-bottom: 20px;
}

.quota-section h4 {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-secondary);
  margin-bottom: 10px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.quota-bar {
  margin-bottom: 12px;
}

.quota-bar-header {
  display: flex;
  justify-content: space-between;
  font-size: 13px;
  margin-bottom: 4px;
}

.quota-bar-label {
  color: var(--text-secondary);
}

.quota-bar-value {
  color: var(--text-primary);
  font-weight: 500;
}

.quota-progress {
  height: 6px;
  background: var(--bg-tertiary);
  border-radius: 3px;
  overflow: hidden;
}

.quota-progress-fill {
  height: 100%;
  border-radius: 3px;
  transition: width 0.5s ease;
}

/* ==================
   LOADING / SKELETON
   ================== */

.skeleton {
  background: linear-gradient(
    90deg,
    var(--bg-tertiary) 25%,
    var(--bg-hover) 50%,
    var(--bg-tertiary) 75%
  );
  background-size: 200% 100%;
  animation: shimmer 1.5s infinite;
  border-radius: var(--radius-sm);
}

.skeleton-line {
  height: 14px;
  margin-bottom: 10px;
  width: 80%;
}

.skeleton-line:nth-child(2) {
  width: 65%;
}
.skeleton-line:nth-child(3) {
  width: 50%;
}

.skeleton-block {
  height: 100px;
  width: 100%;
}

@keyframes shimmer {
  0% {
    background-position: 200% 0;
  }
  100% {
    background-position: -200% 0;
  }
}

.sidebar-loading {
  padding: 12px;
}

/* ==================
   RESPONSIVE
   ================== */

@media (max-width: 768px) {
  .sidebar {
    position: fixed;
    left: 0;
    top: 0;
    bottom: 0;
    transform: translateX(-100%);
    z-index: 100;
    box-shadow: var(--shadow-lg);
  }

  .sidebar.open {
    transform: translateX(0);
  }

  .sidebar-overlay.active {
    display: block;
  }

  .btn-sidebar-close {
    display: flex;
  }

  .btn-menu {
    display: flex;
  }

  .messages-list {
    padding: 16px;
  }

  .input-container {
    padding: 8px 12px 12px;
    padding-bottom: constant(safe-area-inset-bottom);
    padding-bottom: env(safe-area-inset-bottom);
    padding-bottom: calc(12px + constant(safe-area-inset-bottom));
    padding-bottom: calc(12px + env(safe-area-inset-bottom));
  }

  .main-content {
    /* Ensure main content uses dynamic viewport on mobile */
    height: 100%;
    height: 100dvh;
    max-height: 100dvh;
  }

  .welcome-suggestions {
    grid-template-columns: 1fr;
  }

  .welcome-screen h1 {
    font-size: 22px;
  }

  .message {
    gap: 10px;
  }
}

@media (max-width: 480px) {
  .welcome-screen {
    padding: 20px 16px;
  }

  .suggestion-chip {
    font-size: 13px;
    padding: 12px;
  }
}

/* ==================
   SCROLLBAR
   ================== */

::-webkit-scrollbar {
  width: 6px;
  height: 6px;
}

::-webkit-scrollbar-track {
  background: transparent;
}

::-webkit-scrollbar-thumb {
  background: var(--bg-active);
  border-radius: 4px;
}

::-webkit-scrollbar-thumb:hover {
  background: var(--text-muted);
}

/* ==================
   MISC
   ================== */

.toast {
  position: fixed;
  bottom: 24px;
  right: 24px;
  background: var(--bg-tertiary);
  border: 1px solid var(--border-color);
  color: var(--text-primary);
  padding: 12px 20px;
  border-radius: var(--radius-md);
  font-size: 14px;
  box-shadow: var(--shadow-md);
  z-index: 300;
  animation:
    slideUp 0.3s ease,
    fadeOut 0.3s ease 2.7s forwards;
}

@keyframes fadeOut {
  to {
    opacity: 0;
    transform: translateY(8px);
  }
}

.toast-error {
  border-color: rgba(239, 68, 68, 0.3);
  background: rgba(239, 68, 68, 0.1);
}

.toast-success {
  border-color: rgba(16, 185, 129, 0.3);
  background: rgba(16, 185, 129, 0.1);
}

/* Empty state */
.empty-state {
  text-align: center;
  padding: 40px 20px;
  color: var(--text-muted);
}

.empty-state svg {
  margin-bottom: 12px;
  opacity: 0.5;
}

/* =====================================================
   PWA Install Banner
   ===================================================== */
.pwa-install-banner {
  display: none;
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  z-index: 10000;
  padding: 0 16px 16px;
  justify-content: center;
  animation: pwa-slide-up 0.4s cubic-bezier(0.22, 1, 0.36, 1);
}

@keyframes pwa-slide-up {
  from {
    transform: translateY(100%);
    opacity: 0;
  }
  to {
    transform: translateY(0);
    opacity: 1;
  }
}

.pwa-install-content {
  display: flex;
  align-items: center;
  gap: 14px;
  max-width: 520px;
  width: 100%;
  padding: 16px 20px;
  background: var(--bg-secondary);
  border: 1px solid var(--border-light);
  border-radius: 16px;
  box-shadow:
    0 -4px 32px rgba(0, 0, 0, 0.4),
    0 0 0 1px rgba(255, 255, 255, 0.04);
  backdrop-filter: blur(16px);
}

.pwa-install-icon {
  width: 44px;
  height: 44px;
  min-width: 44px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--accent-light);
  color: var(--accent);
  border-radius: 12px;
}

.pwa-install-text {
  flex: 1;
  font-size: 14px;
  color: var(--text-secondary);
  line-height: 1.4;
}

.pwa-install-text strong {
  color: var(--text-primary);
}

.pwa-install-actions {
  display: flex;
  gap: 8px;
  flex-shrink: 0;
}

.pwa-btn {
  padding: 8px 16px;
  border: none;
  border-radius: 10px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s;
  white-space: nowrap;
}

.pwa-btn-install {
  background: var(--accent);
  color: #fff;
}

.pwa-btn-install:hover {
  background: var(--accent-hover);
  transform: translateY(-1px);
}

.pwa-btn-dismiss {
  background: var(--bg-tertiary);
  color: var(--text-secondary);
}

.pwa-btn-dismiss:hover {
  background: var(--bg-hover);
  color: var(--text-primary);
}

/* PWA Banner responsive */
@media (max-width: 480px) {
  .pwa-install-content {
    flex-wrap: wrap;
    gap: 12px;
    padding: 14px 16px;
  }

  .pwa-install-icon {
    width: 36px;
    height: 36px;
    min-width: 36px;
  }

  .pwa-install-icon svg {
    width: 20px;
    height: 20px;
  }

  .pwa-install-text {
    flex: 1;
    font-size: 13px;
  }

  .pwa-install-actions {
    width: 100%;
    justify-content: stretch;
  }

  .pwa-btn {
    flex: 1;
    text-align: center;
    padding: 10px 12px;
  }
}

/* =====================================================
   CAN v2.0 - Model Toggle
   ===================================================== */
.model-toggle {
  display: flex;
  gap: 4px;
  background: var(--bg-tertiary);
  border-radius: 8px;
  padding: 2px;
  border: 1px solid var(--border-color);
}

.model-toggle-btn {
  display: flex;
  align-items: center;
  gap: 5px;
  padding: 4px 10px;
  border: none;
  border-radius: 6px;
  background: transparent;
  color: var(--text-muted);
  font-size: 12px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.2s;
  white-space: nowrap;
}

.model-toggle-btn:hover {
  color: var(--text-secondary);
}

.model-toggle-btn.active {
  background: var(--bg-hover);
  color: var(--text-primary);
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.2);
}

.model-toggle-btn.active[data-model="v2"] {
  background: linear-gradient(
    135deg,
    rgba(139, 92, 246, 0.2),
    rgba(236, 72, 153, 0.15)
  );
  color: #c084fc;
  border: 1px solid rgba(139, 92, 246, 0.3);
}

.model-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  display: inline-block;
}

.model-dot.v1 {
  background: #10b981;
}

.model-dot.v2 {
  background: linear-gradient(135deg, #8b5cf6, #ec4899);
}

.v2-sparkle {
  font-size: 10px;
  margin-left: -2px;
}

/* =====================================================
   CAN v2.0 - Level Badge
   ===================================================== */
.level-badge {
  display: inline-block;
  font-size: 10px;
  font-weight: 700;
  padding: 1px 6px;
  border-radius: 4px;
  background: linear-gradient(
    135deg,
    rgba(99, 102, 241, 0.25),
    rgba(139, 92, 246, 0.25)
  );
  color: #a78bfa;
  margin-left: 6px;
  vertical-align: middle;
  letter-spacing: 0.3px;
}

/* =====================================================
   CAN v2.0 - XP Bar
   ===================================================== */
.xp-bar-container {
  width: 100%;
  height: 3px;
  background: var(--bg-active);
  border-radius: 2px;
  margin: 4px 0 2px;
  overflow: hidden;
}

.xp-bar-fill {
  height: 100%;
  background: linear-gradient(90deg, #6366f1, #8b5cf6, #a78bfa);
  border-radius: 2px;
  transition: width 0.6s ease;
  min-width: 2px;
}

/* =====================================================
   CAN v2.0 - Streak Indicator
   ===================================================== */
.streak-indicator {
  display: flex;
  align-items: center;
  gap: 3px;
  font-size: 11px;
  color: var(--text-muted);
  margin-top: 2px;
}

.streak-flame {
  font-size: 12px;
}

.streak-count {
  font-weight: 600;
  color: #f59e0b;
}

/* =====================================================
   CAN v2.0 - Message Model Badge
   ===================================================== */
.msg-model-badge {
  display: inline-block;
  font-size: 10px;
  font-weight: 500;
  padding: 1px 6px;
  border-radius: 3px;
  margin-left: 8px;
  vertical-align: middle;
}

.msg-model-v1 {
  background: rgba(16, 185, 129, 0.15);
  color: #10b981;
}

.msg-model-v2 {
  background: linear-gradient(
    135deg,
    rgba(139, 92, 246, 0.2),
    rgba(236, 72, 153, 0.15)
  );
  color: #c084fc;
}

/* =====================================================
   CAN v2.0 - XP Toast
   ===================================================== */
.toast-xp {
  border-color: rgba(99, 102, 241, 0.3);
  background: rgba(99, 102, 241, 0.12);
  color: #a78bfa;
  font-weight: 600;
}

.toast-levelup {
  border-color: rgba(251, 191, 36, 0.4);
  background: linear-gradient(
    135deg,
    rgba(99, 102, 241, 0.15),
    rgba(251, 191, 36, 0.15)
  );
  color: #fbbf24;
  font-size: 15px;
}

/* =====================================================
   CAN v2.0 - Achievement Popup
   ===================================================== */
.achievement-popup {
  position: fixed;
  top: 20px;
  right: 20px;
  z-index: 500;
  animation:
    achieveSlideIn 0.5s cubic-bezier(0.22, 1, 0.36, 1),
    achieveFadeOut 0.5s ease 3.5s forwards;
}

@keyframes achieveSlideIn {
  from {
    transform: translateX(100px) scale(0.8);
    opacity: 0;
  }
  to {
    transform: translateX(0) scale(1);
    opacity: 1;
  }
}

@keyframes achieveFadeOut {
  to {
    opacity: 0;
    transform: translateY(-10px);
  }
}

.achievement-card {
  display: flex;
  gap: 14px;
  align-items: center;
  padding: 16px 20px;
  background: var(--bg-secondary);
  border: 1px solid rgba(251, 191, 36, 0.3);
  border-radius: 14px;
  box-shadow:
    0 8px 32px rgba(0, 0, 0, 0.3),
    0 0 0 1px rgba(251, 191, 36, 0.1);
  max-width: 340px;
}

.achievement-icon {
  font-size: 36px;
  min-width: 44px;
  text-align: center;
}

.achievement-info {
  flex: 1;
}

.achievement-title {
  font-size: 12px;
  color: #fbbf24;
  font-weight: 600;
  letter-spacing: 0.5px;
  text-transform: uppercase;
  margin-bottom: 2px;
}

.achievement-name {
  font-size: 15px;
  font-weight: 700;
  color: var(--text-primary);
  margin-bottom: 2px;
}

.achievement-desc {
  font-size: 12px;
  color: var(--text-muted);
}

.achievement-xp {
  font-size: 12px;
  font-weight: 600;
  color: #a78bfa;
  margin-top: 4px;
}

/* =====================================================
   CAN v2.0 - Responsive
   ===================================================== */
@media (max-width: 768px) {
  .model-toggle-btn {
    font-size: 11px;
    padding: 3px 8px;
  }

  .achievement-card {
    max-width: 280px;
  }
}
