/* === Variables — MCP Celcoin Brand === */
:root {
  --bg-primary: #0B0A12;
  --bg-secondary: #13111D;
  --bg-tertiary: #1A1726;
  --bg-card: #1A1726;
  --bg-card-elevated: #211D30;
  --bg-hover: #2A2540;
  --bg-input: #1A1726;
  --accent: #7664FA;
  --accent-deep: #5B45D6;
  --accent-hover: #5038C9;
  --accent-light: #806DFB;
  --accent-glow: #9B8CFF;
  --accent-dim: rgba(118, 100, 250, 0.15);
  --accent-glow-shadow: rgba(118, 100, 250, 0.3);
  --teal: #14B8A6;
  --teal-hover: #0D9488;
  --teal-light: #2DD4BF;
  --text-primary: #F0EDF7;
  --text-secondary: #9B95AD;
  --text-muted: #6E6882;
  --border: #2A2540;
  --border-subtle: #221E33;
  --user-msg: #211D30;
  --assistant-msg: #1A1726;
  --error: #F87171;
  --success: #34D399;
  --warning: #FBBF24;
  --info: #60A5FA;
  --tool-call: #2A1F4A;
  --tool-call-border: rgba(118, 100, 250, 0.3);
  --tool-call-text: #9B8CFF;
  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 16px;
  --radius-xl: 20px;
  --shadow: 0 4px 24px rgba(0,0,0,0.4);
  --font: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
  --font-heading: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
  --font-mono: 'SF Mono', 'Fira Code', 'Roboto Mono', monospace;
  --gradient-brand: linear-gradient(135deg, #5B45D6 0%, #7664FA 40%, #9B8CFF 100%);
  --gradient-brand-vivid: linear-gradient(135deg, #5038C9 0%, #7664FA 50%, #14B8A6 100%);
  --gradient-glow: radial-gradient(ellipse 80% 60% at 50% -10%, rgba(118,100,250,0.2) 0%, transparent 60%);
}

/* === Reset === */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; overflow: hidden; }
body {
  font-family: var(--font);
  background: var(--bg-primary);
  color: var(--text-primary);
  -webkit-font-smoothing: antialiased;
}

/* === Layout === */
#app {
  display: flex;
  height: 100vh;
  width: 100vw;
  overflow: hidden;
}

/* === Sidebar === */
.sidebar {
  width: 280px;
  min-width: 280px;
  background: var(--bg-secondary);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  transition: transform 0.3s ease, width 0.3s ease, min-width 0.3s ease;
  z-index: 100;
}
.sidebar.collapsed {
  transform: translateX(-100%);
  width: 0;
  min-width: 0;
  border: none;
  overflow: hidden;
}
.sidebar-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px;
  border-bottom: 1px solid var(--border);
}
.logo-area { display: flex; align-items: center; gap: 10px; }
.logo-icon svg { width: 36px; height: 36px; }
.logo-text { display: flex; flex-direction: column; }
.brand-name {
  font-weight: 700;
  font-size: 16px;
  background: var(--gradient-brand);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
}
.brand-sub { font-size: 11px; color: var(--text-secondary); }

.sidebar-section { padding: 12px 16px; }
.section-title {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-muted);
  margin-bottom: 8px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.badge {
  background: var(--accent-dim);
  color: var(--accent-light);
  font-size: 10px;
  font-weight: 700;
  padding: 2px 8px;
  border-radius: 10px;
}

.sidebar-btn {
  width: 100%;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 12px;
  border: none;
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--text-primary);
  font-size: 13px;
  cursor: pointer;
  transition: background 0.2s;
}
.sidebar-btn:hover, .sidebar-btn.active { background: var(--bg-hover); }

.tools-section { flex: 1; overflow-y: auto; }
.tools-list { display: flex; flex-direction: column; gap: 2px; }
.tool-domain {
  padding: 6px 8px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: background 0.2s;
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.tool-domain:hover { background: var(--bg-hover); }
.tool-domain-name { font-size: 12px; color: var(--text-secondary); }
.tool-domain-count {
  font-size: 10px;
  color: var(--accent-light);
  background: var(--accent-dim);
  padding: 1px 6px;
  border-radius: 8px;
}

.sidebar-footer {
  border-top: 1px solid var(--border);
  padding-bottom: 8px;
}
.resources-list { display: flex; flex-direction: column; gap: 2px; }
.resource-item {
  font-size: 11px;
  color: var(--text-muted);
  padding: 4px 8px;
  border-radius: var(--radius-sm);
}
.version-info {
  text-align: center;
  font-size: 10px;
  color: var(--text-muted);
  padding: 8px;
}

/* === Chat Area === */
.chat-area {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
  position: relative;
  background: var(--bg-primary);
  background-image: var(--gradient-glow);
}

.chat-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 20px;
  border-bottom: 1px solid var(--border);
  background: rgba(19, 17, 29, 0.9);
  backdrop-filter: blur(12px);
}
.chat-header-left { display: flex; align-items: center; gap: 8px; }
.chat-header-right { display: flex; align-items: center; gap: 4px; }
.model-badge {
  font-size: 12px;
  font-weight: 600;
  color: var(--accent-light);
  background: var(--accent-dim);
  padding: 4px 10px;
  border-radius: 12px;
}
.header-sep { color: var(--text-muted); }
.header-label { font-size: 12px; color: var(--text-secondary); }

.icon-btn {
  background: transparent;
  border: none;
  color: var(--text-secondary);
  cursor: pointer;
  padding: 6px;
  border-radius: var(--radius-sm);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.2s, color 0.2s;
}
.icon-btn:hover { background: var(--bg-hover); color: var(--text-primary); }

/* === Messages === */
.messages {
  flex: 1;
  overflow-y: auto;
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 16px;
  scroll-behavior: smooth;
}
.messages::-webkit-scrollbar { width: 6px; }
.messages::-webkit-scrollbar-track { background: transparent; }
.messages::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }

/* Welcome */
.welcome-screen {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  flex: 1;
  text-align: center;
  padding: 40px 20px;
}
.welcome-logo { margin-bottom: 16px; }
.welcome-logo svg { width: 280px; height: auto; }
.welcome-screen h1 {
  font-size: 28px;
  font-weight: 700;
  margin-bottom: 8px;
  background: var(--gradient-brand);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
}
.welcome-sub {
  color: var(--text-secondary);
  font-size: 14px;
  max-width: 500px;
  margin-bottom: 32px;
}

.quick-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  justify-content: center;
  max-width: 600px;
  margin-bottom: 40px;
}
.quick-action {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 10px 16px;
  border: 1px solid var(--border);
  border-radius: 24px;
  background: var(--bg-card);
  color: var(--text-primary);
  font-size: 13px;
  cursor: pointer;
  transition: all 0.2s;
}
.quick-action:hover {
  border-color: var(--accent);
  background: var(--accent-dim);
  box-shadow: 0 0 20px var(--accent-glow-shadow);
  transform: translateY(-1px);
}
.qa-icon { font-size: 16px; }
.qa-text { white-space: nowrap; }

.domains-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 12px;
  max-width: 550px;
}
.domain-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 16px 12px;
  text-align: center;
  transition: all 0.25s;
}
.domain-card:hover {
  border-color: var(--accent);
  transform: translateY(-3px);
  box-shadow: 0 8px 24px rgba(118, 100, 250, 0.15);
}
.domain-icon { font-size: 24px; margin-bottom: 6px; }
.domain-name { font-size: 12px; font-weight: 600; color: var(--text-primary); }
.domain-count { font-size: 11px; color: var(--teal); margin-top: 2px; }

/* Message bubbles */
.message {
  display: flex;
  gap: 12px;
  max-width: 85%;
  animation: fadeIn 0.3s ease;
}
@keyframes fadeIn { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: translateY(0); } }

.message.user { align-self: flex-end; flex-direction: row-reverse; }
.message.assistant { align-self: flex-start; }
.message.tool-call-msg { align-self: flex-start; max-width: 70%; }

.msg-avatar {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 14px;
  flex-shrink: 0;
}
.message.user .msg-avatar { background: var(--accent-dim); color: var(--accent-light); }
.message.assistant .msg-avatar { background: var(--accent-dim); }

.msg-content {
  padding: 12px 16px;
  border-radius: var(--radius-lg);
  font-size: 14px;
  line-height: 1.6;
  word-break: break-word;
}
.message.user .msg-content {
  background: var(--accent-deep);
  border-bottom-right-radius: 4px;
  color: #F0EDF7;
}
.message.assistant .msg-content {
  background: var(--assistant-msg);
  border: 1px solid var(--border);
  border-bottom-left-radius: 4px;
}
.msg-content p { margin-bottom: 8px; }
.msg-content p:last-child { margin-bottom: 0; }
.msg-content code {
  background: var(--accent-dim);
  color: var(--accent-glow);
  padding: 2px 6px;
  border-radius: 4px;
  font-size: 13px;
  font-family: var(--font-mono);
}
.msg-content pre {
  background: var(--bg-primary);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 12px;
  overflow-x: auto;
  margin: 8px 0;
}
.msg-content pre code {
  background: none;
  padding: 0;
  color: var(--text-primary);
}
.msg-content table {
  border-collapse: collapse;
  width: 100%;
  margin: 8px 0;
  font-size: 13px;
}
.msg-content th, .msg-content td {
  border: 1px solid var(--border);
  padding: 6px 10px;
  text-align: left;
}
.msg-content th {
  background: var(--bg-card-elevated);
  font-weight: 600;
  color: var(--accent-light);
}
.msg-content ul, .msg-content ol {
  padding-left: 20px;
  margin: 6px 0;
}
.msg-content strong { color: var(--accent-light); }
.msg-content a { color: var(--teal-light); text-decoration: none; }
.msg-content a:hover { text-decoration: underline; }

/* Tool call bubble */
.tool-call-bubble {
  background: var(--tool-call);
  border: 1px solid var(--tool-call-border);
  border-radius: var(--radius-md);
  padding: 10px 14px;
  font-size: 12px;
}
.tool-call-header {
  display: flex;
  align-items: center;
  gap: 6px;
  color: var(--tool-call-text);
  font-weight: 600;
  margin-bottom: 4px;
}
.tool-call-header svg { width: 14px; height: 14px; }
.tool-call-params {
  color: var(--text-muted);
  font-family: var(--font-mono);
  font-size: 11px;
  max-height: 80px;
  overflow-y: auto;
  white-space: pre-wrap;
}

/* Status / typing */
.status-msg {
  align-self: flex-start;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 16px;
  font-size: 12px;
  color: var(--text-muted);
}
.typing-dots {
  display: flex;
  gap: 4px;
}
.typing-dots span {
  width: 6px;
  height: 6px;
  background: var(--accent);
  border-radius: 50%;
  animation: bounce 1.4s ease 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: scale(0.6); opacity: 0.4; }
  40% { transform: scale(1); opacity: 1; }
}

/* Error */
.error-msg {
  background: rgba(248, 113, 113, 0.1);
  border: 1px solid rgba(248, 113, 113, 0.3);
  color: var(--error);
  padding: 10px 14px;
  border-radius: var(--radius-md);
  font-size: 13px;
  align-self: center;
}

/* === Input === */
.input-area {
  padding: 12px 20px 16px;
  background: rgba(19, 17, 29, 0.95);
  backdrop-filter: blur(12px);
  border-top: 1px solid var(--border);
}
.input-container {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 8px 12px;
  transition: border-color 0.2s, box-shadow 0.2s;
}
.input-container:focus-within {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-glow-shadow);
}
textarea {
  flex: 1;
  background: transparent;
  border: none;
  outline: none;
  color: var(--text-primary);
  font-family: var(--font);
  font-size: 14px;
  resize: none;
  max-height: 150px;
  line-height: 1.5;
  padding: 4px 0;
}
textarea::placeholder { color: var(--text-muted); }

.send-btn {
  background: var(--gradient-brand);
  border: none;
  border-radius: 50%;
  width: 36px;
  height: 36px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: all 0.2s;
  flex-shrink: 0;
}
.send-btn svg { stroke: white; }
.send-btn:disabled { opacity: 0.3; cursor: not-allowed; }
.send-btn:not(:disabled):hover {
  transform: scale(1.08);
  box-shadow: 0 0 20px var(--accent-glow-shadow);
}

.input-footer {
  text-align: center;
  font-size: 10px;
  color: var(--text-muted);
  margin-top: 8px;
}

/* === Tools Panel === */
.tools-panel {
  position: fixed;
  right: 0;
  top: 0;
  width: 420px;
  height: 100vh;
  background: var(--bg-secondary);
  border-left: 1px solid var(--border);
  z-index: 200;
  display: flex;
  flex-direction: column;
  box-shadow: -4px 0 32px rgba(0,0,0,0.5);
  transition: transform 0.3s ease;
}
.tools-panel.hidden { transform: translateX(100%); }
.tools-panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
}
.tools-panel-header h3 {
  font-size: 16px;
  font-weight: 600;
  background: var(--gradient-brand);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
}
.tools-panel-content {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
}
.tool-group { margin-bottom: 20px; }
.tool-group-title {
  font-size: 13px;
  font-weight: 700;
  color: var(--accent-light);
  margin-bottom: 8px;
  display: flex;
  align-items: center;
  gap: 8px;
}
.tool-item {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 10px 12px;
  margin-bottom: 6px;
  cursor: pointer;
  transition: all 0.2s;
}
.tool-item:hover {
  border-color: var(--accent);
  background: var(--bg-hover);
}
.tool-item-name {
  font-size: 12px;
  font-weight: 600;
  color: var(--teal-light);
  font-family: var(--font-mono);
}
.tool-item-desc {
  font-size: 11px;
  color: var(--text-secondary);
  margin-top: 2px;
}
.tool-item-params {
  display: none;
  margin-top: 8px;
  padding-top: 8px;
  border-top: 1px solid var(--border);
  font-size: 11px;
  color: var(--text-muted);
  font-family: var(--font-mono);
  white-space: pre-wrap;
}
.tool-item.expanded .tool-item-params { display: block; }

/* === Mobile === */
.mobile-toggle {
  display: none;
  position: fixed;
  top: 12px;
  left: 12px;
  z-index: 150;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text-primary);
  padding: 8px;
  cursor: pointer;
}

@media (max-width: 768px) {
  .sidebar {
    position: fixed;
    left: 0;
    top: 0;
    height: 100vh;
    transform: translateX(-100%);
    box-shadow: var(--shadow);
  }
  .sidebar.open { transform: translateX(0); }
  .mobile-toggle { display: flex; }
  .chat-header { padding-left: 52px; }
  .message { max-width: 95%; }
  .domains-grid { grid-template-columns: repeat(2, 1fr); }
  .tools-panel { width: 100%; }
}

@media (max-width: 480px) {
  .quick-actions { flex-direction: column; align-items: center; }
  .welcome-screen h1 { font-size: 22px; }
}

/* === Login Screen === */
.login-screen {
  position: fixed;
  inset: 0;
  z-index: 1000;
  background: var(--bg-primary);
  background-image: var(--gradient-glow);
  display: flex;
  align-items: center;
  justify-content: center;
}
.login-screen.hidden { display: none; }
.login-card {
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: var(--radius-xl);
  padding: 48px 40px;
  width: 400px;
  max-width: 90vw;
  text-align: center;
  box-shadow: 0 16px 64px rgba(0,0,0,0.5), 0 0 80px rgba(118, 100, 250, 0.08);
}
.login-logo { margin-bottom: 20px; }
.login-title {
  font-size: 22px;
  font-weight: 700;
  margin-bottom: 6px;
  background: var(--gradient-brand);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
}
.login-sub {
  font-size: 13px;
  color: var(--text-secondary);
  margin-bottom: 28px;
}
.login-input-wrap {
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 6px 10px;
  transition: border-color 0.2s, box-shadow 0.2s;
}
.login-input-wrap:focus-within {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-glow-shadow);
}
.login-input-wrap input {
  flex: 1;
  background: transparent;
  border: none;
  outline: none;
  color: var(--text-primary);
  font-family: var(--font);
  font-size: 14px;
  padding: 8px 4px;
}
.login-input-wrap input::placeholder { color: var(--text-muted); }
.login-submit {
  background: var(--gradient-brand);
  border: none;
  border-radius: 50%;
  width: 38px;
  height: 38px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  flex-shrink: 0;
  transition: all 0.2s;
}
.login-submit svg { stroke: white; }
.login-submit:hover {
  transform: scale(1.08);
  box-shadow: 0 0 20px var(--accent-glow-shadow);
}
.login-error {
  margin-top: 12px;
  font-size: 13px;
  color: var(--error);
  padding: 8px 12px;
  background: rgba(248, 113, 113, 0.1);
  border: 1px solid rgba(248, 113, 113, 0.2);
  border-radius: var(--radius-sm);
}
.login-error.hidden { display: none; }

/* === Renew Modal === */
.modal-overlay {
  position: fixed;
  inset: 0;
  z-index: 900;
  background: rgba(11, 10, 18, 0.85);
  backdrop-filter: blur(8px);
  display: flex;
  align-items: center;
  justify-content: center;
  animation: fadeIn 0.2s ease;
}
.modal-overlay.hidden { display: none; }
.modal-card {
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: var(--radius-xl);
  padding: 36px 32px;
  width: 380px;
  max-width: 90vw;
  text-align: center;
  box-shadow: 0 16px 64px rgba(0,0,0,0.6);
}
.modal-icon { margin-bottom: 16px; }
.modal-title {
  font-size: 18px;
  font-weight: 700;
  color: var(--warning);
  margin-bottom: 6px;
}
.modal-sub {
  font-size: 13px;
  color: var(--text-secondary);
  margin-bottom: 16px;
}
.modal-countdown {
  font-size: 28px;
  font-weight: 700;
  font-family: var(--font-mono);
  color: var(--warning);
  margin-bottom: 24px;
}
.modal-actions {
  display: flex;
  gap: 10px;
  justify-content: center;
}
.modal-btn {
  padding: 10px 24px;
  border-radius: var(--radius-md);
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  border: none;
  transition: all 0.2s;
}
.modal-btn.primary {
  background: var(--gradient-brand);
  color: white;
}
.modal-btn.primary:hover {
  box-shadow: 0 0 20px var(--accent-glow-shadow);
  transform: translateY(-1px);
}
.modal-btn.secondary {
  background: var(--bg-card);
  border: 1px solid var(--border);
  color: var(--text-secondary);
}
.modal-btn.secondary:hover {
  background: var(--bg-hover);
  color: var(--text-primary);
}

/* === Utility === */
.hidden { display: none !important; }
