/* ============================================================
   Supreme Credit Master AGI V15 — RJ Business Solutions
   Royal Blue Premium Theme | Rick Jefferson
   ============================================================ */

:root {
  --bg: #04060f;
  --bg-2: #070b18;
  --surface: #0c1120;
  --surface-2: #111729;
  --surface-3: #172033;
  --border: rgba(65, 105, 225, 0.18);
  --border-2: rgba(65, 105, 225, 0.32);
  --text: #e8eaf6;
  --text-muted: #8fa3cc;
  --text-dim: #455880;
  --primary: #4169e1; /* Royal Blue */
  --primary-glow: rgba(65, 105, 225, 0.28);
  --primary-light: #5f83ef;
  --primary-dark: #2d4fb8;
  --accent: #00b4f5; /* Ice Blue accent */
  --accent-2: #ff6b6b;
  --accent-3: #ffd166;
  --gold: #d4a017; /* RJ Gold accent */
  --gold-glow: rgba(212, 160, 23, 0.2);
  --success: #06d6a0;
  --warning: #ffd166;
  --danger: #ff4757;
  --critical: #ff2d55;
  --sidebar-w: 290px;
  --radius: 12px;
  --radius-lg: 18px;
  --radius-xl: 24px;
  --shadow: 0 4px 24px rgba(0, 0, 0, 0.6);
  --shadow-lg: 0 8px 48px rgba(0, 0, 0, 0.8);
  --font: "Inter", sans-serif;
  --font-mono: "JetBrains Mono", monospace;
  --font-display: "Sora", sans-serif;
  --transition: all 0.22s cubic-bezier(0.4, 0, 0.2, 1);
  --royal-gradient: linear-gradient(135deg, #4169e1, #00b4f5);
  --royal-gradient-gold: linear-gradient(135deg, #4169e1, #d4a017);
  --royal-gradient-dark: linear-gradient(135deg, #2d4fb8, #4169e1);
}

[data-theme="light"] {
  --bg: #f0f2ff;
  --bg-2: #e8ecff;
  --surface: #fff;
  --surface-2: #f0f2ff;
  --surface-3: #e4e8ff;
  --border: rgba(65, 105, 225, 0.2);
  --border-2: rgba(65, 105, 225, 0.38);
  --text: #0a0f2e;
  --text-muted: #3a4a7a;
  --text-dim: #8090bb;
  --primary-glow: rgba(65, 105, 225, 0.12);
  --shadow: 0 4px 24px rgba(0, 0, 0, 0.1);
  --shadow-lg: 0 8px 48px rgba(0, 0, 0, 0.15);
}

*,
*::before,
*::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}
html {
  font-size: 16px;
  scroll-behavior: smooth;
}
body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  overflow: hidden;
  line-height: 1.6;
}
::selection {
  background: var(--primary-glow);
  color: var(--text);
}
::-webkit-scrollbar {
  width: 5px;
  height: 5px;
}
::-webkit-scrollbar-track {
  background: transparent;
}
::-webkit-scrollbar-thumb {
  background: var(--border-2);
  border-radius: 99px;
}
::-webkit-scrollbar-thumb:hover {
  background: var(--primary);
}
img {
  max-width: 100%;
}
a {
  color: var(--primary-light);
  text-decoration: none;
}
a:hover {
  text-decoration: underline;
}

/* ── Layout ── */
#app {
  display: grid;
  grid-template-columns: var(--sidebar-w) 1fr;
  height: 100vh;
  width: 100vw;
  transition: var(--transition);
}
#app.sidebar-collapsed {
  grid-template-columns: 0px 1fr;
}
#app.sidebar-collapsed #sidebar {
  transform: translateX(-100%);
  opacity: 0;
  pointer-events: none;
}

/* ── Sidebar ── */
#sidebar {
  background: linear-gradient(180deg, var(--bg-2) 0%, #060a17 100%);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  transition: var(--transition);
  position: relative;
  z-index: 10;
}
.sidebar-header {
  padding: 18px 16px 14px;
  border-bottom: 1px solid var(--border);
  background: linear-gradient(
    135deg,
    rgba(65, 105, 225, 0.08),
    rgba(0, 180, 245, 0.05)
  );
}

/* ── Logo Area ── */
.brand {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  margin-bottom: 14px;
}
.brand-logo {
  width: 100%;
  max-width: 220px;
  height: 52px;
  object-fit: contain;
  filter: drop-shadow(0 2px 12px rgba(65, 105, 225, 0.5));
  transition: var(--transition);
}
.brand-logo:hover {
  filter: drop-shadow(0 4px 20px rgba(65, 105, 225, 0.8));
}
.brand-tagline {
  font-family: var(--font-mono);
  font-size: 9px;
  color: var(--text-dim);
  letter-spacing: 0.12em;
  text-transform: uppercase;
  text-align: center;
}
.brand-version {
  font-family: var(--font-display);
  font-size: 11px;
  font-weight: 700;
  color: var(--primary-light);
  letter-spacing: 0.04em;
  text-align: center;
}
.brand-version span {
  color: var(--gold);
}

.btn-new-chat {
  width: 100%;
  background: var(--royal-gradient);
  color: #fff;
  border: none;
  border-radius: var(--radius);
  padding: 10px 14px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  transition: var(--transition);
  box-shadow: 0 3px 14px var(--primary-glow);
}
.btn-new-chat:hover {
  opacity: 0.9;
  transform: translateY(-1px);
  box-shadow: 0 6px 24px var(--primary-glow);
}

/* Model Panel */
.model-panel {
  padding: 10px 14px;
  border-bottom: 1px solid var(--border);
}
.model-panel-label,
.sidebar-section-label {
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.09em;
  color: var(--text-dim);
  margin-bottom: 7px;
}
.model-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 5px;
}
.model-chip {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 6px 8px;
  font-size: 10px;
  font-family: var(--font-mono);
  color: var(--text-muted);
  cursor: pointer;
  transition: var(--transition);
  text-align: center;
  user-select: none;
}
.model-chip:hover {
  border-color: var(--primary);
  color: var(--primary-light);
}
.model-chip.active {
  background: rgba(65, 105, 225, 0.18);
  border-color: var(--primary);
  color: var(--primary-light);
  font-weight: 700;
}
.model-chip.primary-model {
  grid-column: 1/-1;
  background: linear-gradient(
    90deg,
    rgba(65, 105, 225, 0.18),
    rgba(0, 180, 245, 0.12)
  );
  border-color: var(--primary);
  color: var(--primary-light);
  font-weight: 700;
}

.sidebar-section {
  padding: 10px 14px 4px;
}
.nav-item {
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 8px 10px;
  border-radius: 9px;
  cursor: pointer;
  font-size: 13px;
  color: var(--text-muted);
  transition: var(--transition);
  margin-bottom: 2px;
  user-select: none;
}
.nav-item:hover {
  background: rgba(65, 105, 225, 0.1);
  color: var(--text);
}
.nav-item.active {
  background: rgba(65, 105, 225, 0.15);
  color: var(--primary-light);
  font-weight: 600;
  border-left: 2px solid var(--primary);
}

#chat-history {
  flex: 1;
  overflow-y: auto;
  padding: 6px 10px;
}
.history-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 7px 10px;
  border-radius: 9px;
  cursor: pointer;
  font-size: 12px;
  color: var(--text-muted);
  transition: var(--transition);
  margin-bottom: 2px;
  user-select: none;
}
.history-item:hover {
  background: rgba(65, 105, 225, 0.08);
  color: var(--text);
}
.history-item.active {
  background: rgba(65, 105, 225, 0.14);
  color: var(--text);
  font-weight: 500;
}
.history-item-text {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  flex: 1;
}
.history-item-delete {
  opacity: 0;
  background: none;
  border: none;
  color: var(--danger);
  cursor: pointer;
  padding: 2px;
  border-radius: 4px;
  transition: var(--transition);
}
.history-item:hover .history-item-delete {
  opacity: 1;
}

/* RAG Panel */
#rag-panel {
  border-top: 1px solid var(--border);
  padding: 12px 14px;
}
.rag-panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 10px;
  cursor: pointer;
}
.rag-panel-title {
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  color: var(--text-muted);
  display: flex;
  align-items: center;
  gap: 6px;
}
.rag-status-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--text-dim);
  transition: var(--transition);
}
.rag-status-dot.active {
  background: var(--success);
  box-shadow: 0 0 6px var(--success);
}
.rag-status-dot.indexing {
  background: var(--warning);
  animation: pulse 1s infinite;
}
.rag-dropzone {
  border: 2px dashed var(--border-2);
  border-radius: var(--radius);
  padding: 12px;
  text-align: center;
  cursor: pointer;
  transition: var(--transition);
  font-size: 11px;
  color: var(--text-dim);
}
.rag-dropzone:hover,
.rag-dropzone.drag-over {
  border-color: var(--primary);
  background: var(--primary-glow);
  color: var(--primary-light);
}
.rag-progress {
  margin-top: 8px;
  height: 3px;
  background: var(--surface-3);
  border-radius: 99px;
  overflow: hidden;
  display: none;
}
.rag-progress.visible {
  display: block;
}
.rag-progress-bar {
  height: 100%;
  background: var(--royal-gradient);
  border-radius: 99px;
  transition: width 0.3s;
  width: 0%;
}
.rag-stats {
  display: flex;
  gap: 12px;
  margin-top: 8px;
  font-size: 10px;
  color: var(--text-dim);
  font-family: var(--font-mono);
}
.rag-doc-list {
  margin-top: 6px;
  max-height: 80px;
  overflow-y: auto;
}
.rag-doc-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 3px 0;
  font-size: 10px;
  color: var(--text-muted);
}
.rag-doc-delete {
  background: none;
  border: none;
  color: var(--danger);
  cursor: pointer;
  opacity: 0.6;
  font-size: 11px;
  padding: 0 2px;
}

/* Sidebar Footer */
.sidebar-footer {
  padding: 10px 14px;
  border-top: 1px solid var(--border);
  display: flex;
  gap: 4px;
  flex-direction: column;
}
.btn-sidebar-action {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 7px 10px;
  border-radius: 9px;
  cursor: pointer;
  font-size: 12px;
  color: var(--text-muted);
  background: none;
  border: none;
  width: 100%;
  text-align: left;
  transition: var(--transition);
}
.btn-sidebar-action:hover {
  background: rgba(65, 105, 225, 0.1);
  color: var(--text);
}

/* ── Main ── */
#main {
  display: flex;
  flex-direction: column;
  overflow: hidden;
  background: var(--bg);
  position: relative;
}

/* Topbar */
#topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 20px;
  border-bottom: 1px solid var(--border);
  background: linear-gradient(90deg, var(--bg-2), rgba(65, 105, 225, 0.04));
  flex-shrink: 0;
  gap: 12px;
}
.topbar-left {
  display: flex;
  align-items: center;
  gap: 10px;
}
.topbar-right {
  display: flex;
  align-items: center;
  gap: 6px;
}
#btn-toggle-sidebar {
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  padding: 6px;
  border-radius: 8px;
  display: flex;
  transition: var(--transition);
}
#btn-toggle-sidebar:hover {
  background: rgba(65, 105, 225, 0.12);
  color: var(--primary-light);
}
.topbar-title {
  font-family: var(--font-display);
  font-size: 14px;
  font-weight: 800;
  color: var(--text);
}
.topbar-badge {
  background: var(--royal-gradient);
  color: #fff;
  font-size: 9px;
  font-weight: 700;
  font-family: var(--font-mono);
  padding: 2px 8px;
  border-radius: 99px;
  letter-spacing: 0.06em;
  box-shadow: 0 2px 8px var(--primary-glow);
}
.topbar-badge-gold {
  background: var(--royal-gradient-gold);
  color: #fff;
  font-size: 9px;
  font-weight: 700;
  font-family: var(--font-mono);
  padding: 2px 8px;
  border-radius: 99px;
  letter-spacing: 0.06em;
}
.topbar-model-display {
  font-size: 11px;
  font-family: var(--font-mono);
  color: var(--primary-light);
  background: rgba(65, 105, 225, 0.15);
  border: 1px solid var(--border-2);
  padding: 4px 10px;
  border-radius: 99px;
}
.icon-btn {
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  padding: 7px;
  border-radius: 9px;
  display: flex;
  align-items: center;
  transition: var(--transition);
  position: relative;
}
.icon-btn:hover {
  background: rgba(65, 105, 225, 0.12);
  color: var(--primary-light);
}
.icon-btn .tooltip {
  position: absolute;
  bottom: calc(100% + 6px);
  left: 50%;
  transform: translateX(-50%);
  background: var(--surface-3);
  color: var(--text);
  font-size: 11px;
  padding: 4px 8px;
  border-radius: 6px;
  white-space: nowrap;
  pointer-events: none;
  opacity: 0;
  transition: var(--transition);
  border: 1px solid var(--border);
}
.icon-btn:hover .tooltip {
  opacity: 1;
}

/* Topbar Logo */
.topbar-logo {
  height: 28px;
  width: auto;
  object-fit: contain;
  filter: drop-shadow(0 1px 6px rgba(65, 105, 225, 0.4));
}

/* Violation Bar */
#violation-mode-bar {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 7px 20px;
  background: linear-gradient(
    90deg,
    rgba(65, 105, 225, 0.07),
    rgba(0, 180, 245, 0.04)
  );
  border-bottom: 1px solid rgba(65, 105, 225, 0.15);
  flex-shrink: 0;
  overflow-x: auto;
}
.vmode-label {
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--primary-light);
  white-space: nowrap;
  flex-shrink: 0;
}
.violation-chip {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 99px;
  padding: 3px 10px;
  font-size: 10px;
  font-family: var(--font-mono);
  color: var(--text-muted);
  cursor: pointer;
  white-space: nowrap;
  flex-shrink: 0;
  transition: var(--transition);
}
.violation-chip:hover {
  border-color: var(--primary);
  color: var(--primary-light);
}
.violation-chip.active {
  background: rgba(65, 105, 225, 0.2);
  border-color: var(--primary);
  color: var(--primary-light);
  font-weight: 600;
  box-shadow: 0 0 8px var(--primary-glow);
}

/* Chat */
#chat-container {
  flex: 1;
  overflow-y: auto;
  padding: 24px 0;
  scroll-behavior: smooth;
}

/* Welcome */
#welcome-screen {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: calc(100vh - 200px);
  padding: 40px 24px;
  text-align: center;
}
.welcome-logo {
  width: 280px;
  max-width: 80vw;
  height: auto;
  object-fit: contain;
  margin-bottom: 16px;
  filter: drop-shadow(0 4px 24px rgba(65, 105, 225, 0.5));
  animation: floatLogo 5s ease-in-out infinite;
}
@keyframes floatLogo {
  0%,
  100% {
    transform: translateY(0) scale(1);
  }
  50% {
    transform: translateY(-6px) scale(1.01);
  }
}
.welcome-title {
  font-family: var(--font-display);
  font-size: 30px;
  font-weight: 800;
  background: linear-gradient(
    135deg,
    var(--text),
    var(--primary-light),
    var(--accent),
    var(--gold)
  );
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  margin-bottom: 4px;
}
.welcome-v {
  font-family: var(--font-mono);
  font-size: 12px;
  color: var(--gold);
  font-weight: 700;
  letter-spacing: 0.1em;
  margin-bottom: 8px;
}
.welcome-sub {
  font-size: 14px;
  color: var(--text-muted);
  max-width: 480px;
  line-height: 1.7;
  margin-bottom: 28px;
}
.welcome-stats {
  display: flex;
  gap: 16px;
  flex-wrap: wrap;
  justify-content: center;
  margin-bottom: 28px;
}
.welcome-stat {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px 20px;
  text-align: center;
  transition: var(--transition);
}
.welcome-stat:hover {
  border-color: var(--primary);
  transform: translateY(-2px);
  box-shadow: 0 4px 16px var(--primary-glow);
}
.welcome-stat-val {
  font-family: var(--font-display);
  font-size: 22px;
  font-weight: 800;
  background: var(--royal-gradient);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}
.welcome-stat-label {
  font-size: 10px;
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  margin-top: 2px;
}
.suggestion-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 10px;
  width: 100%;
  max-width: 780px;
}
.suggestion-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 16px;
  cursor: pointer;
  text-align: left;
  transition: var(--transition);
}
.suggestion-card:hover {
  border-color: var(--primary);
  background: var(--surface-2);
  transform: translateY(-2px);
  box-shadow: 0 4px 20px var(--primary-glow);
}
.suggestion-card-icon {
  font-size: 22px;
  margin-bottom: 8px;
}
.suggestion-card-title {
  font-size: 13px;
  font-weight: 700;
  color: var(--text);
  margin-bottom: 4px;
}
.suggestion-card-desc {
  font-size: 11px;
  color: var(--text-muted);
  line-height: 1.5;
}

/* Messages */
.message-wrapper {
  padding: 6px 20px;
  max-width: 920px;
  margin: 0 auto;
  width: 100%;
  animation: msgFadeIn 0.3s ease-out;
}
@keyframes msgFadeIn {
  from {
    opacity: 0;
    transform: translateY(8px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}
.message {
  display: flex;
  gap: 12px;
  align-items: flex-start;
}
.message.user {
  flex-direction: row-reverse;
}
.msg-avatar {
  width: 34px;
  height: 34px;
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 16px;
  flex-shrink: 0;
}
.msg-avatar.ai {
  background: var(--royal-gradient);
  box-shadow: 0 0 14px var(--primary-glow);
}
.msg-avatar.user {
  background: var(--surface-3);
}
.msg-body {
  flex: 1;
  max-width: calc(100% - 50px);
}
.msg-meta {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 5px;
  flex-wrap: wrap;
}
.message.user .msg-meta {
  justify-content: flex-end;
}
.msg-author {
  font-size: 12px;
  font-weight: 700;
  color: var(--text-muted);
}
.msg-time {
  font-size: 10px;
  color: var(--text-dim);
  font-family: var(--font-mono);
}
.msg-model-badge {
  font-size: 9px;
  font-family: var(--font-mono);
  font-weight: 700;
  padding: 2px 7px;
  border-radius: 99px;
  background: rgba(65, 105, 225, 0.15);
  border: 1px solid var(--border-2);
  color: var(--primary-light);
}
.msg-rag-badge {
  font-size: 9px;
  font-family: var(--font-mono);
  font-weight: 600;
  padding: 2px 7px;
  border-radius: 99px;
  background: rgba(6, 214, 160, 0.12);
  border: 1px solid rgba(6, 214, 160, 0.3);
  color: var(--success);
}
.msg-content {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 4px 16px 16px 16px;
  padding: 14px 16px;
  font-size: 14px;
  line-height: 1.75;
  color: var(--text);
  position: relative;
}
.message.user .msg-content {
  background: linear-gradient(
    135deg,
    rgba(65, 105, 225, 0.14),
    rgba(0, 180, 245, 0.09)
  );
  border-color: var(--border-2);
  border-radius: 16px 4px 16px 16px;
}
.msg-content h1,
.msg-content h2,
.msg-content h3 {
  font-family: var(--font-display);
  font-weight: 700;
  margin: 16px 0 8px;
  color: var(--text);
}
.msg-content h1 {
  font-size: 20px;
}
.msg-content h2 {
  font-size: 17px;
}
.msg-content h3 {
  font-size: 15px;
}
.msg-content p {
  margin-bottom: 10px;
}
.msg-content ul,
.msg-content ol {
  padding-left: 20px;
  margin-bottom: 10px;
}
.msg-content li {
  margin-bottom: 4px;
}
.msg-content strong {
  font-weight: 700;
  color: var(--primary-light);
}
.msg-content em {
  color: var(--text-muted);
}
.msg-content code {
  font-family: var(--font-mono);
  font-size: 12px;
  background: rgba(65, 105, 225, 0.12);
  border: 1px solid var(--border);
  border-radius: 5px;
  padding: 1px 6px;
  color: var(--accent);
}
.msg-content pre {
  position: relative;
  background: #050810;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  overflow-x: auto;
  margin: 12px 0;
}
.msg-content pre code {
  background: none;
  border: none;
  padding: 0;
  color: inherit;
  font-size: 13px;
}
.code-copy-btn {
  position: absolute;
  top: 8px;
  right: 8px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  color: var(--text-muted);
  border-radius: 6px;
  padding: 3px 8px;
  font-size: 10px;
  cursor: pointer;
  font-family: var(--font-mono);
  transition: var(--transition);
}
.code-copy-btn:hover {
  background: var(--primary);
  color: #fff;
  border-color: var(--primary);
}
.msg-content blockquote {
  border-left: 3px solid var(--primary);
  padding-left: 14px;
  color: var(--text-muted);
  margin: 10px 0;
  font-style: italic;
}
.msg-content table {
  width: 100%;
  border-collapse: collapse;
  margin: 12px 0;
  font-size: 13px;
}
.msg-content th {
  background: rgba(65, 105, 225, 0.12);
  padding: 8px 12px;
  text-align: left;
  font-weight: 700;
  border: 1px solid var(--border);
  color: var(--primary-light);
}
.msg-content td {
  padding: 7px 12px;
  border: 1px solid var(--border);
  color: var(--text-muted);
}
.msg-content tr:hover td {
  background: rgba(65, 105, 225, 0.06);
}
.msg-content hr {
  border: none;
  border-top: 1px solid var(--border);
  margin: 16px 0;
}
.msg-actions {
  display: flex;
  gap: 4px;
  margin-top: 6px;
  opacity: 0;
  transition: var(--transition);
}
.message-wrapper:hover .msg-actions {
  opacity: 1;
}
.msg-action-btn {
  background: none;
  border: none;
  color: var(--text-dim);
  cursor: pointer;
  padding: 4px 7px;
  border-radius: 6px;
  font-size: 11px;
  display: flex;
  align-items: center;
  gap: 4px;
  transition: var(--transition);
}
.msg-action-btn:hover {
  background: rgba(65, 105, 225, 0.1);
  color: var(--primary-light);
}
.msg-image {
  max-width: 280px;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  margin-top: 8px;
}

/* Typing */
#typing-indicator {
  display: none;
  padding: 6px 20px;
  max-width: 920px;
  margin: 0 auto;
  width: 100%;
}
#typing-indicator.visible {
  display: block;
}
.typing-bubble {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 4px 16px 16px 16px;
  padding: 10px 14px;
  font-size: 12px;
  color: var(--text-muted);
}
.typing-dots {
  display: flex;
  gap: 4px;
}
.typing-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--primary);
  animation: typingBounce 1.2s infinite;
}
.typing-dot:nth-child(2) {
  animation-delay: 0.2s;
}
.typing-dot:nth-child(3) {
  animation-delay: 0.4s;
}
@keyframes typingBounce {
  0%,
  80%,
  100% {
    transform: scale(0.7);
    opacity: 0.5;
  }
  40% {
    transform: scale(1.1);
    opacity: 1;
  }
}
.typing-model-name {
  font-family: var(--font-mono);
  font-size: 10px;
  color: var(--primary-light);
}

/* Input */
#input-area {
  padding: 14px 20px 18px;
  border-top: 1px solid var(--border);
  background: linear-gradient(180deg, var(--bg-2), var(--bg));
  flex-shrink: 0;
}
#image-preview-container {
  display: none;
  margin-bottom: 10px;
  position: relative;
  width: fit-content;
}
#image-preview-container.visible {
  display: block;
}
#image-preview {
  max-width: 180px;
  max-height: 120px;
  border-radius: var(--radius);
  border: 1px solid var(--border-2);
}
#btn-remove-image {
  position: absolute;
  top: -6px;
  right: -6px;
  background: var(--danger);
  color: #fff;
  border: none;
  border-radius: 50%;
  width: 20px;
  height: 20px;
  font-size: 11px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
}
.input-box {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  background: var(--surface);
  border: 1px solid var(--border-2);
  border-radius: var(--radius-lg);
  padding: 8px 10px 8px 14px;
  transition: var(--transition);
}
.input-box:focus-within {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px var(--primary-glow);
}
#user-input {
  flex: 1;
  background: none;
  border: none;
  outline: none;
  color: var(--text);
  font-family: var(--font);
  font-size: 14px;
  line-height: 1.6;
  resize: none;
  max-height: 180px;
  min-height: 24px;
}
#user-input::placeholder {
  color: var(--text-dim);
}
.input-actions {
  display: flex;
  align-items: center;
  gap: 4px;
  flex-shrink: 0;
}
.input-icon-btn {
  background: none;
  border: none;
  color: var(--text-dim);
  cursor: pointer;
  padding: 6px;
  border-radius: 8px;
  display: flex;
  transition: var(--transition);
}
.input-icon-btn:hover {
  background: rgba(65, 105, 225, 0.12);
  color: var(--primary-light);
}
#btn-send {
  background: var(--royal-gradient);
  color: #fff;
  border: none;
  border-radius: 10px;
  width: 38px;
  height: 38px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: var(--transition);
  flex-shrink: 0;
  box-shadow: 0 3px 12px var(--primary-glow);
}
#btn-send:hover {
  transform: scale(1.06);
  box-shadow: 0 5px 20px var(--primary-glow);
}
#btn-send.streaming {
  background: linear-gradient(135deg, var(--danger), #ff6b6b);
  box-shadow: 0 2px 8px rgba(255, 71, 87, 0.3);
}
.input-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-top: 8px;
  padding: 0 4px;
}
.input-shortcuts {
  font-size: 10px;
  color: var(--text-dim);
  font-family: var(--font-mono);
}
.input-shortcuts kbd {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 1px 5px;
  font-size: 9px;
}
#char-counter {
  font-size: 10px;
  font-family: var(--font-mono);
  color: var(--text-dim);
}
#char-counter.warning {
  color: var(--warning);
}
#char-counter.danger {
  color: var(--danger);
}
.quick-actions {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
  margin-bottom: 10px;
}
.quick-chip {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 99px;
  padding: 5px 12px;
  font-size: 11px;
  cursor: pointer;
  color: var(--text-muted);
  transition: var(--transition);
  white-space: nowrap;
}
.quick-chip:hover {
  border-color: var(--primary);
  color: var(--primary-light);
  background: rgba(65, 105, 225, 0.1);
}

/* Modals */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(2, 4, 14, 0.75);
  backdrop-filter: blur(10px);
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.22s;
}
.modal-overlay.open {
  opacity: 1;
  pointer-events: all;
}
.modal {
  background: var(--surface);
  border: 1px solid var(--border-2);
  border-radius: var(--radius-xl);
  width: 100%;
  max-width: 700px;
  max-height: 90vh;
  overflow-y: auto;
  box-shadow:
    0 20px 80px rgba(0, 0, 0, 0.9),
    0 0 40px var(--primary-glow);
  transform: scale(0.95);
  transition: transform 0.22s;
}
.modal-overlay.open .modal {
  transform: scale(1);
}
.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 22px 26px 0;
}
.modal-title {
  font-family: var(--font-display);
  font-size: 18px;
  font-weight: 800;
  background: var(--royal-gradient);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}
.modal-close {
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  padding: 6px;
  border-radius: 8px;
  font-size: 22px;
  transition: var(--transition);
  line-height: 1;
}
.modal-close:hover {
  background: rgba(255, 71, 87, 0.1);
  color: var(--danger);
}
.modal-body {
  padding: 20px 26px 26px;
}
.settings-section {
  margin-bottom: 22px;
}
.settings-section-title {
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--primary-light);
  margin-bottom: 12px;
  padding-bottom: 6px;
  border-bottom: 1px solid var(--border);
}
.form-group {
  margin-bottom: 14px;
}
.form-label {
  display: block;
  font-size: 12px;
  font-weight: 600;
  color: var(--text-muted);
  margin-bottom: 6px;
}
.form-input {
  width: 100%;
  background: var(--surface-2);
  border: 1px solid var(--border-2);
  border-radius: var(--radius);
  padding: 9px 12px;
  color: var(--text);
  font-family: var(--font);
  font-size: 13px;
  outline: none;
  transition: var(--transition);
}
.form-input:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px var(--primary-glow);
}
.form-input::placeholder {
  color: var(--text-dim);
}
textarea.form-input {
  resize: vertical;
  min-height: 80px;
  font-family: var(--font-mono);
  font-size: 12px;
}
select.form-input {
  cursor: pointer;
  background: var(--surface-2);
}
.form-range {
  width: 100%;
  accent-color: var(--primary);
}
.range-display {
  font-family: var(--font-mono);
  font-size: 12px;
  color: var(--primary-light);
  float: right;
}
.toggle-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 0;
}
.toggle-info {
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.toggle-label {
  font-size: 13px;
  font-weight: 500;
  color: var(--text);
}
.toggle-desc {
  font-size: 11px;
  color: var(--text-dim);
}
.toggle {
  position: relative;
  width: 42px;
  height: 24px;
  flex-shrink: 0;
}
.toggle input {
  opacity: 0;
  width: 0;
  height: 0;
}
.toggle-slider {
  position: absolute;
  inset: 0;
  background: var(--surface-3);
  border-radius: 99px;
  cursor: pointer;
  transition: var(--transition);
}
.toggle-slider::before {
  content: "";
  position: absolute;
  width: 18px;
  height: 18px;
  left: 3px;
  top: 3px;
  background: var(--text-dim);
  border-radius: 50%;
  transition: var(--transition);
}
.toggle input:checked + .toggle-slider {
  background: var(--primary);
}
.toggle input:checked + .toggle-slider::before {
  transform: translateX(18px);
  background: #fff;
}
.btn-primary {
  background: var(--royal-gradient);
  color: #fff;
  border: none;
  border-radius: var(--radius);
  padding: 10px 20px;
  font-size: 13px;
  font-weight: 700;
  cursor: pointer;
  transition: var(--transition);
  box-shadow: 0 2px 10px var(--primary-glow);
}
.btn-primary:hover {
  opacity: 0.9;
  transform: translateY(-1px);
  box-shadow: 0 4px 18px var(--primary-glow);
}
.btn-secondary {
  background: var(--surface-2);
  color: var(--text-muted);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 10px 20px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: var(--transition);
}
.btn-secondary:hover {
  background: var(--surface-3);
  color: var(--text);
  border-color: var(--primary);
}
.modal-footer {
  display: flex;
  gap: 10px;
  justify-content: flex-end;
  padding-top: 16px;
  border-top: 1px solid var(--border);
  margin-top: 16px;
}
.letter-type-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(175px, 1fr));
  gap: 8px;
  margin-bottom: 16px;
}
.letter-type-card {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px;
  cursor: pointer;
  transition: var(--transition);
}
.letter-type-card:hover {
  border-color: var(--primary);
}
.letter-type-card.selected {
  background: rgba(65, 105, 225, 0.15);
  border-color: var(--primary);
  box-shadow: 0 0 8px var(--primary-glow);
}
.letter-type-card-title {
  font-size: 12px;
  font-weight: 700;
  color: var(--text);
  margin-bottom: 3px;
}
.letter-type-card-desc {
  font-size: 10px;
  color: var(--text-muted);
}

/* Toast */
#toast-container {
  position: fixed;
  bottom: 24px;
  right: 24px;
  z-index: 9999;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.toast {
  background: var(--surface-2);
  border: 1px solid var(--border-2);
  border-radius: var(--radius);
  padding: 12px 16px;
  font-size: 13px;
  color: var(--text);
  box-shadow: var(--shadow);
  display: flex;
  align-items: center;
  gap: 10px;
  animation: toastIn 0.3s ease-out;
  max-width: 340px;
}
.toast.success {
  border-left: 3px solid var(--success);
}
.toast.error {
  border-left: 3px solid var(--danger);
}
.toast.warning {
  border-left: 3px solid var(--warning);
}
.toast.info {
  border-left: 3px solid var(--primary);
}
@keyframes toastIn {
  from {
    opacity: 0;
    transform: translateX(20px);
  }
  to {
    opacity: 1;
    transform: translateX(0);
  }
}

/* Context Menu */
#context-menu {
  position: fixed;
  background: var(--surface-2);
  border: 1px solid var(--border-2);
  border-radius: var(--radius);
  padding: 6px;
  z-index: 9000;
  box-shadow: var(--shadow-lg);
  min-width: 185px;
  display: none;
}
#context-menu.visible {
  display: block;
}
.ctx-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 10px;
  border-radius: 7px;
  cursor: pointer;
  font-size: 12px;
  color: var(--text-muted);
  transition: var(--transition);
}
.ctx-item:hover {
  background: rgba(65, 105, 225, 0.1);
  color: var(--text);
}
.ctx-item.danger {
  color: var(--danger);
}
.ctx-item.danger:hover {
  background: rgba(255, 71, 87, 0.1);
}
.ctx-separator {
  height: 1px;
  background: var(--border);
  margin: 4px 0;
}

/* MFSN Banner */
#mfsn-banner {
  padding: 11px 20px;
  background: linear-gradient(
    90deg,
    rgba(65, 105, 225, 0.12),
    rgba(0, 180, 245, 0.08)
  );
  border-bottom: 1px solid rgba(65, 105, 225, 0.2);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-shrink: 0;
}
.mfsn-text {
  font-size: 12px;
  color: var(--text-muted);
}
.mfsn-text strong {
  color: var(--accent);
}
.mfsn-cta-group {
  display: flex;
  gap: 6px;
  flex-shrink: 0;
}
.mfsn-btn {
  font-size: 11px;
  font-weight: 700;
  padding: 5px 12px;
  border-radius: 99px;
  cursor: pointer;
  border: none;
  transition: var(--transition);
  text-decoration: none;
  display: inline-flex;
  align-items: center;
}
.mfsn-btn.primary {
  background: var(--royal-gradient);
  color: #fff;
  box-shadow: 0 2px 8px var(--primary-glow);
}
.mfsn-btn.primary:hover {
  text-decoration: none;
  opacity: 0.9;
}
.mfsn-btn.secondary {
  background: var(--surface-2);
  color: var(--text-muted);
  border: 1px solid var(--border);
}
.mfsn-btn.secondary:hover {
  border-color: var(--primary);
  color: var(--primary-light);
}
#mfsn-dismiss {
  background: none;
  border: none;
  color: var(--text-dim);
  cursor: pointer;
  font-size: 16px;
  line-height: 1;
  flex-shrink: 0;
}

/* ── Mobile & Sidebar Overlay ── */
.sidebar-overlay {
  position: fixed;
  inset: 0;
  background: rgba(4, 6, 15, 0.7);
  backdrop-filter: blur(4px);
  z-index: 90;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.3s;
}
.sidebar-overlay.visible {
  opacity: 1;
  pointer-events: all;
}

/* Loading */
#loading-overlay {
  position: fixed;
  inset: 0;
  background: var(--bg);
  z-index: 9999;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 16px;
  transition: opacity 0.5s;
}
#loading-overlay.hidden {
  opacity: 0;
  pointer-events: none;
}
.loader-logo {
  width: 260px;
  max-width: 80vw;
  height: auto;
  object-fit: contain;
  animation: pulseGlow 2s ease-in-out infinite;
  filter: drop-shadow(0 0 20px rgba(65, 105, 225, 0.7));
}
@keyframes pulseGlow {
  0%,
  100% {
    filter: drop-shadow(0 0 20px rgba(65, 105, 225, 0.7));
  }
  50% {
    filter: drop-shadow(0 0 40px rgba(65, 105, 225, 1))
      drop-shadow(0 0 60px rgba(0, 180, 245, 0.5));
  }
}
.loader-text {
  font-family: var(--font-display);
  font-size: 22px;
  font-weight: 800;
  background: var(--royal-gradient);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}
.loader-sub {
  font-size: 12px;
  color: var(--text-muted);
  font-family: var(--font-mono);
}
.loader-bar {
  width: 220px;
  height: 3px;
  background: var(--surface-3);
  border-radius: 99px;
  overflow: hidden;
  margin-top: 8px;
}
.loader-bar-fill {
  height: 100%;
  width: 0%;
  background: var(--royal-gradient);
  border-radius: 99px;
  animation: loadFill 1.5s ease-out forwards;
}
@keyframes loadFill {
  to {
    width: 100%;
  }
}

.pulse {
  animation: pulse 2s infinite;
}
@keyframes pulse {
  0%,
  100% {
    opacity: 1;
  }
  50% {
    opacity: 0.5;
  }
}
.hidden {
  display: none !important;
}
.streaming-cursor {
  display: inline-block;
  animation: blink 1s infinite;
}
@keyframes blink {
  0%,
  100% {
    opacity: 1;
  }
  50% {
    opacity: 0;
  }
}

/* Orch buttons */
.orch-btn {
  cursor: pointer;
  transition: var(--transition);
}
.orch-btn.active {
  background: rgba(65, 105, 225, 0.2);
  border-color: var(--primary);
  color: var(--primary-light);
  font-weight: 700;
}

/* Responsive */
@media (max-width: 768px) {
  #app {
    grid-template-columns: 1fr !important;
  }
  #sidebar {
    position: fixed;
    left: 0;
    top: 0;
    height: 100%;
    width: 290px;
    z-index: 101;
    transform: translateX(-100%);
    box-shadow: 20px 0 60px rgba(0, 0, 0, 0.5);
  }
  #app.sidebar-open #sidebar {
    transform: translateX(0);
    opacity: 1;
    pointer-events: all;
  }
  #topbar { padding: 10px 14px; }
  .topbar-logo { display: none; }
  .topbar-title { font-size: 13px; }

  #chat-container { padding: 12px 0; }
  .welcome-title { font-size: 20px; }
  .welcome-logo { width: 220px; }
  .welcome-sub { font-size: 13px; padding: 0 10px; }
  .suggestion-grid { grid-template-columns: 1fr; }

  .message-wrapper { padding: 4px 12px; }
  .msg-avatar { width: 28px; height: 28px; font-size: 13px; }
  .msg-content { padding: 10px 14px; font-size: 13px; border-radius: 4px 12px 12px 12px; }
  .message.user .msg-content { border-radius: 12px 4px 12px 12px; }

  #input-area { padding: 10px 12px 12px; }
  .quick-actions {
    flex-wrap: nowrap;
    overflow-x: auto;
    padding-bottom: 6px;
    -webkit-overflow-scrolling: touch;
    mask-image: linear-gradient(to right, black 85%, transparent);
  }
  .quick-chip { font-size: 10px; padding: 4px 10px; flex-shrink: 0; }
  .input-box { border-radius: 16px; padding: 6px 10px; }
  #user-input { font-size: 13px; }
  .input-icon-btn { padding: 4px; }

  .modal { width: 100%; height: 94vh; margin: 0; border-radius: 20px 20px 0 0; align-self: flex-end; }
  .modal-header { padding: 18px 20px 0; }
  .modal-body { padding: 16px 20px 20px; }
  .settings-section-title { font-size: 10px; }
  .modal-footer { flex-direction: column; gap: 8px; }
  .modal-footer .btn-secondary { width: 100%; order: 2; }
  .modal-footer .btn-primary { width: 100%; order: 1; }
  .modal-footer button[onclick="resetSettings()"] { width: 100%; margin-bottom: 4px; order: 3; }
}

/* Table Responsiveness Hack */
.msg-content table {
  display: block;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}
