/* Design Tokens & Theme Settings */
:root {
  --bg-primary: #0f172a;
  --bg-secondary: #1b2640;
  --bg-tertiary: #080d1a;
  
  --accent-purple: #8b5cf6;
  --accent-purple-glow: rgba(139, 92, 246, 0.35);
  --accent-purple-dark: #6d28d9;
  
  --accent-cyan: #06b6d4;
  --accent-cyan-glow: rgba(6, 182, 212, 0.25);
  
  --accent-green: #10b981;
  --accent-green-glow: rgba(16, 185, 129, 0.2);
  
  --accent-red: #ef4444;
  --accent-red-glow: rgba(239, 68, 68, 0.2);
  
  --text-main: #f8fafc;
  --text-muted: #94a3b8;
  --text-dark: #64748b;
  
  --border-color: rgba(255, 255, 255, 0.06);
  --glass-bg: rgba(27, 38, 59, 0.6);
  --glass-border: rgba(255, 255, 255, 0.08);
  --glass-blur: blur(16px);
  
  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 16px;
  --radius-full: 9999px;
  
  --transition-fast: 0.2s cubic-bezier(0.4, 0, 0.2, 1);
  --transition-normal: 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  
  --shadow-lg: 0 10px 25px -5px rgba(0, 0, 0, 0.3), 0 8px 10px -6px rgba(0, 0, 0, 0.3);
  --shadow-purple: 0 0 20px rgba(139, 92, 246, 0.25);
}

/* Base Styles */
* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

body {
  font-family: 'Inter', sans-serif;
  background-color: var(--bg-primary);
  background-image: radial-gradient(circle at top, #1e1b4b 0%, var(--bg-primary) 70%);
  color: var(--text-main);
  height: 100vh;
  overflow: hidden;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

/* App Container Layout */
.app-container {
  display: flex;
  height: 100vh;
  width: 100vw;
  position: relative;
}

/* Sidebar Styling */
.sidebar {
  width: 320px;
  background-color: var(--bg-tertiary);
  border-right: 1px solid var(--border-color);
  display: flex;
  flex-direction: column;
  height: 100%;
  transition: transform var(--transition-normal);
  z-index: 10;
}

.sidebar-header {
  padding: 24px;
  border-bottom: 1px solid var(--border-color);
}

.logo {
  display: flex;
  align-items: center;
  gap: 12px;
}

.logo-icon {
  font-size: 28px;
  animation: pulse-glow 2.5s infinite ease-in-out;
}

.logo-text h2 {
  font-size: 18px;
  font-weight: 700;
  background: linear-gradient(135deg, #fff 0%, #a78bfa 100%);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
}

.logo-text span {
  font-size: 11px;
  color: var(--accent-cyan);
  text-transform: uppercase;
  letter-spacing: 1.5px;
  font-weight: 600;
}

.sidebar-content {
  flex-grow: 1;
  overflow-y: auto;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

/* Scrollbars */
::-webkit-scrollbar {
  width: 6px;
  height: 6px;
}

::-webkit-scrollbar-track {
  background: transparent;
}

::-webkit-scrollbar-thumb {
  background: rgba(255, 255, 255, 0.1);
  border-radius: var(--radius-full);
}

::-webkit-scrollbar-thumb:hover {
  background: rgba(255, 255, 255, 0.2);
}

/* Section Cards inside Sidebar */
.section-card {
  background: var(--glass-bg);
  backdrop-filter: var(--glass-blur);
  border: 1px solid var(--glass-border);
  border-radius: var(--radius-md);
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1);
}

.section-card.flex-grow {
  flex-grow: 1;
  min-height: 200px;
}

.section-title {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  font-weight: 600;
  color: var(--text-main);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.05);
  padding-bottom: 8px;
}

.section-title i {
  width: 14px;
  height: 14px;
  color: var(--accent-purple);
}

/* Form Controls */
.form-group {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.form-group label {
  font-size: 12px;
  color: var(--text-muted);
  font-weight: 500;
}

.input-wrapper {
  display: flex;
  position: relative;
  width: 100%;
}

.input-wrapper input {
  padding-right: 40px;
}

input[type="text"],
input[type="password"],
select,
textarea {
  width: 100%;
  padding: 10px 12px;
  background-color: rgba(15, 23, 42, 0.5);
  border: 1px solid var(--glass-border);
  border-radius: var(--radius-sm);
  color: var(--text-main);
  font-family: inherit;
  font-size: 13px;
  transition: all var(--transition-fast);
}

input[type="text"]:focus,
input[type="password"]:focus,
select:focus,
textarea:focus {
  outline: none;
  border-color: var(--accent-purple);
  box-shadow: 0 0 0 2px var(--accent-purple-glow);
  background-color: rgba(15, 23, 42, 0.8);
}

.help-text {
  font-size: 10px;
  color: var(--text-dark);
  line-height: 1.3;
}

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 10px 16px;
  border-radius: var(--radius-sm);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: all var(--transition-fast);
  border: none;
}

.btn-block {
  display: flex;
  width: 100%;
}

.btn-primary {
  background: linear-gradient(135deg, var(--accent-purple) 0%, var(--accent-purple-dark) 100%);
  color: white;
  box-shadow: var(--shadow-purple);
}

.btn-primary:hover {
  transform: translateY(-1px);
  filter: brightness(1.1);
  box-shadow: 0 0 25px rgba(139, 92, 246, 0.45);
}

.btn-primary:active {
  transform: translateY(0);
}

.btn-secondary {
  background-color: rgba(255, 255, 255, 0.06);
  color: var(--text-main);
  border: 1px solid var(--border-color);
}

.btn-secondary:hover {
  background-color: rgba(255, 255, 255, 0.1);
  border-color: rgba(255, 255, 255, 0.2);
}

.icon-btn {
  background: transparent;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 6px;
  border-radius: var(--radius-sm);
  transition: all var(--transition-fast);
}

.icon-btn:hover {
  color: var(--text-main);
  background-color: rgba(255, 255, 255, 0.05);
}

.input-wrapper .icon-btn {
  position: absolute;
  right: 6px;
  top: 50%;
  transform: translateY(-50%);
}

/* Status Indicator */
.status-indicator {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 11px;
  font-weight: 600;
  padding: 6px 10px;
  border-radius: var(--radius-sm);
  margin-top: 4px;
}

.status-indicator .status-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
}

.status-indicator.unconfigured {
  background-color: rgba(100, 116, 139, 0.1);
  color: var(--text-muted);
}
.status-indicator.unconfigured .status-dot {
  background-color: var(--text-dark);
}

.status-indicator.active {
  background-color: var(--accent-green-glow);
  color: var(--accent-green);
  border: 1px solid rgba(16, 185, 129, 0.15);
}
.status-indicator.active .status-dot {
  background-color: var(--accent-green);
  box-shadow: 0 0 8px var(--accent-green);
  animation: pulse-glow 1.5s infinite ease-in-out;
}

.status-indicator.error {
  background-color: var(--accent-red-glow);
  color: var(--accent-red);
  border: 1px solid rgba(239, 68, 68, 0.15);
}
.status-indicator.error .status-dot {
  background-color: var(--accent-red);
}

/* Range input styling */
input[type="range"] {
  -webkit-appearance: none;
  background: rgba(255, 255, 255, 0.1);
  height: 4px;
  border-radius: var(--radius-full);
  outline: none;
}

input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background-color: var(--accent-purple);
  cursor: pointer;
  transition: transform var(--transition-fast);
}

input[type="range"]::-webkit-slider-thumb:hover {
  transform: scale(1.2);
}

/* Model Specs details */
.model-specs {
  display: flex;
  gap: 6px;
}

.badge {
  font-size: 10px;
  padding: 2px 6px;
  background-color: rgba(255, 255, 255, 0.06);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  color: var(--text-muted);
  font-weight: 500;
}

/* Chat History List */
.history-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
  overflow-y: auto;
  flex-grow: 1;
}

.history-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 10px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  font-size: 12px;
  color: var(--text-muted);
  transition: all var(--transition-fast);
  border: 1px solid transparent;
}

.history-item:hover {
  background-color: rgba(255, 255, 255, 0.04);
  color: var(--text-main);
}

.history-item.active {
  background-color: rgba(139, 92, 246, 0.12);
  color: var(--text-main);
  border-color: rgba(139, 92, 246, 0.2);
}

.history-item-title {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  flex-grow: 1;
  padding-right: 8px;
}

.history-item .delete-history-btn {
  opacity: 0;
  color: var(--text-dark);
}

.history-item:hover .delete-history-btn {
  opacity: 1;
}

.history-item .delete-history-btn:hover {
  color: var(--accent-red);
}

.sidebar-footer {
  padding: 16px;
  border-top: 1px solid var(--border-color);
  display: flex;
  justify-content: center;
}

.api-info {
  font-size: 10px;
  color: var(--text-dark);
  font-family: 'Fira Code', monospace;
}

/* Main Chat Area Layout */
.chat-area {
  flex-grow: 1;
  display: flex;
  flex-direction: column;
  height: 100%;
  background-color: transparent;
  position: relative;
}

/* Chat Header */
.chat-header {
  height: 70px;
  border-bottom: 1px solid var(--border-color);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 24px;
  background-color: rgba(15, 23, 42, 0.3);
  backdrop-filter: var(--glass-blur);
}

.header-left {
  display: flex;
  align-items: center;
  gap: 16px;
}

.sidebar-toggle {
  display: none;
}

.current-model-info h1 {
  font-size: 16px;
  font-weight: 600;
  color: var(--text-main);
}

.current-model-info p {
  font-size: 11px;
  color: var(--text-muted);
}

/* Messages container */
.messages-container {
  flex-grow: 1;
  overflow-y: auto;
  padding: 24px;
  display: flex;
  flex-direction: column;
  gap: 24px;
}

/* Welcome Screen */
.welcome-screen {
  max-width: 720px;
  margin: auto;
  text-align: center;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 40px 20px;
}

.welcome-logo {
  font-size: 64px;
  margin-bottom: 16px;
  animation: float 4s infinite ease-in-out;
}

.welcome-screen h1 {
  font-size: 28px;
  font-weight: 700;
  margin-bottom: 12px;
  background: linear-gradient(135deg, #fff 30%, #a78bfa 100%);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
}

.welcome-screen p {
  color: var(--text-muted);
  font-size: 14px;
  margin-bottom: 32px;
  max-width: 540px;
}

.welcome-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 16px;
  width: 100%;
  margin-bottom: 40px;
}

.welcome-card {
  background: var(--glass-bg);
  backdrop-filter: var(--glass-blur);
  border: 1px solid var(--glass-border);
  border-radius: var(--radius-md);
  padding: 20px;
  text-align: left;
}

.welcome-card h3 {
  font-size: 13px;
  font-weight: 600;
  color: var(--accent-cyan);
  margin-bottom: 8px;
}

.welcome-card p {
  font-size: 12px;
  color: var(--text-muted);
  line-height: 1.4;
  margin: 0;
}

.quick-starts {
  width: 100%;
  text-align: left;
}

.quick-starts h3 {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-main);
  margin-bottom: 12px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.quick-start-buttons {
  display: flex;
  flex-direction: column;
  gap: 10px;
  width: 100%;
}

.quick-prompt-btn {
  background-color: rgba(255, 255, 255, 0.03);
  border: 1px solid var(--border-color);
  padding: 12px 16px;
  border-radius: var(--radius-sm);
  color: var(--text-muted);
  font-size: 13px;
  text-align: left;
  cursor: pointer;
  transition: all var(--transition-fast);
}

.quick-prompt-btn:hover {
  background-color: rgba(139, 92, 246, 0.08);
  border-color: rgba(139, 92, 246, 0.3);
  color: var(--text-main);
  transform: translateX(4px);
}

/* Chat Message Row */
.message-row {
  display: flex;
  gap: 16px;
  max-width: 850px;
  width: 100%;
  margin: 0 auto;
}

.message-row.user {
  flex-direction: row-reverse;
}

.avatar {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: bold;
  font-size: 14px;
  flex-shrink: 0;
  border: 1px solid rgba(255, 255, 255, 0.08);
}

.message-row.user .avatar {
  background: linear-gradient(135deg, var(--accent-purple) 0%, var(--accent-purple-dark) 100%);
  color: white;
}

.message-row.assistant .avatar {
  background-color: var(--bg-secondary);
  color: var(--accent-cyan);
  border-color: rgba(6, 182, 212, 0.2);
}

.message-content {
  display: flex;
  flex-direction: column;
  gap: 6px;
  max-width: calc(100% - 52px);
}

.bubble {
  padding: 12px 18px;
  border-radius: var(--radius-md);
  font-size: 14px;
  line-height: 1.6;
}

.message-row.user .bubble {
  background-color: rgba(139, 92, 246, 0.15);
  border: 1px solid rgba(139, 92, 246, 0.25);
  border-top-right-radius: 2px;
  color: var(--text-main);
}

.message-row.assistant .bubble {
  background-color: rgba(255, 255, 255, 0.02);
  border: 1px solid var(--border-color);
  border-top-left-radius: 2px;
  color: var(--text-main);
}

/* Text formats in bubbles */
.bubble p {
  margin-bottom: 12px;
}
.bubble p:last-child {
  margin-bottom: 0;
}

.bubble code {
  font-family: 'Fira Code', monospace;
  font-size: 12.5px;
  background-color: rgba(255, 255, 255, 0.08);
  padding: 2px 5px;
  border-radius: 4px;
  color: #f43f5e; /* Rose 500 */
}

.bubble pre {
  margin: 14px 0;
  border-radius: var(--radius-sm);
  overflow: hidden;
  box-shadow: var(--shadow-lg);
  border: 1px solid rgba(255, 255, 255, 0.05);
}

.bubble pre code {
  display: block;
  padding: 14px;
  overflow-x: auto;
  background-color: #0b0f19 !important;
  color: #f8fafc;
  font-size: 12px;
}

/* Code header block */
.code-header {
  background-color: #1e293b;
  border-bottom: 1px solid rgba(255, 255, 255, 0.05);
  padding: 6px 12px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 11px;
  color: var(--text-muted);
  font-family: 'Fira Code', monospace;
}

.code-copy-btn {
  background: transparent;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 4px;
  font-size: 10px;
}

.code-copy-btn:hover {
  color: var(--text-main);
}

/* Loader / Typing Indicator */
.typing-indicator {
  display: flex;
  align-items: center;
  gap: 4px;
  height: 24px;
}

.typing-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background-color: var(--text-muted);
  animation: pulse-dot 1.2s infinite ease-in-out;
}

.typing-dot:nth-child(2) {
  animation-delay: 0.2s;
}

.typing-dot:nth-child(3) {
  animation-delay: 0.4s;
}

/* Chat Footer / Input area */
.chat-footer {
  padding: 16px 24px 24px;
  background-color: transparent;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.input-panel {
  max-width: 850px;
  width: 100%;
  margin: 0 auto;
  display: flex;
  align-items: flex-end;
  background: var(--glass-bg);
  backdrop-filter: var(--glass-blur);
  border: 1px solid var(--glass-border);
  border-radius: var(--radius-lg);
  padding: 8px 12px;
  box-shadow: var(--shadow-lg);
  transition: border-color var(--transition-fast), box-shadow var(--transition-fast);
}

.input-panel:focus-within {
  border-color: rgba(139, 92, 246, 0.5);
  box-shadow: 0 0 20px rgba(139, 92, 246, 0.15), var(--shadow-lg);
}

.textarea-wrapper {
  flex-grow: 1;
  margin-right: 12px;
}

#chatInput {
  width: 100%;
  background: transparent;
  border: none;
  resize: none;
  max-height: 200px;
  padding: 8px 4px;
  color: var(--text-main);
  font-size: 14px;
  line-height: 1.5;
  box-shadow: none;
}

#chatInput:focus {
  outline: none;
}

.send-btn {
  background: linear-gradient(135deg, var(--accent-purple) 0%, var(--accent-purple-dark) 100%);
  color: white;
  border: none;
  width: 36px;
  height: 36px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: all var(--transition-fast);
  flex-shrink: 0;
}

.send-btn:disabled {
  background: rgba(255, 255, 255, 0.05);
  color: var(--text-dark);
  cursor: not-allowed;
}

.send-btn:not(:disabled):hover {
  transform: scale(1.05);
  filter: brightness(1.1);
  box-shadow: 0 0 12px rgba(139, 92, 246, 0.5);
}

.input-subtext {
  font-size: 11px;
  color: var(--text-dark);
  text-align: center;
}

.input-subtext a {
  color: var(--text-muted);
  text-decoration: none;
}

.input-subtext a:hover {
  color: var(--accent-purple);
  text-decoration: underline;
}

/* Animations */
@keyframes pulse-glow {
  0%, 100% {
    opacity: 0.6;
    filter: drop-shadow(0 0 2px var(--accent-purple-glow));
  }
  50% {
    opacity: 1;
    filter: drop-shadow(0 0 12px var(--accent-purple));
  }
}

@keyframes pulse-dot {
  0%, 100% {
    transform: scale(0.6);
    opacity: 0.4;
  }
  50% {
    transform: scale(1.1);
    opacity: 1;
  }
}

@keyframes float {
  0%, 100% {
    transform: translateY(0);
  }
  50% {
    transform: translateY(-8px);
  }
}

/* Helper Utilities */
.flex { display: flex; }
.items-center { align-items: center; }
.justify-between { justify-content: space-between; }
.gap-2 { gap: 8px; }
.mt-2 { margin-top: 8px; }

/* Responsive adjustments */
@media (max-width: 768px) {
  .sidebar {
    position: absolute;
    left: 0;
    top: 0;
    bottom: 0;
    transform: translateX(-100%);
    width: 280px;
    box-shadow: 10px 0 30px rgba(0, 0, 0, 0.5);
  }
  
  .sidebar.open {
    transform: translateX(0);
  }
  
  .sidebar-toggle {
    display: flex;
  }
  
  .welcome-grid {
    grid-template-columns: 1fr;
    gap: 12px;
  }
}

/* Balances Section Styles */
.balances-summary {
  background: rgba(255, 255, 255, 0.03);
  border-radius: var(--radius-sm);
  padding: 12px;
  border: 1px solid rgba(255, 255, 255, 0.05);
}

.total-balance-box {
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
}

.total-balance-box .lbl {
  font-size: 10px;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.total-balance-box .val {
  font-size: 20px;
  font-weight: 700;
  color: var(--accent-cyan);
  text-shadow: 0 0 10px var(--accent-cyan-glow);
  margin-top: 4px;
}

.balances-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
  max-height: 200px;
  overflow-y: auto;
  padding-right: 4px;
  margin-top: 4px;
}

.balance-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 10px;
  background: rgba(0, 0, 0, 0.2);
  border: 1px solid rgba(255, 255, 255, 0.04);
  border-radius: var(--radius-sm);
  font-size: 12px;
  transition: all var(--transition-fast);
}

.balance-item:hover {
  background: rgba(255, 255, 255, 0.02);
  border-color: rgba(255, 255, 255, 0.08);
}

.balance-item-key {
  font-family: 'Fira Code', monospace;
  color: var(--text-muted);
  text-overflow: ellipsis;
  overflow: hidden;
  white-space: nowrap;
  max-width: 160px;
}

.balance-item-val {
  font-weight: 600;
  color: var(--accent-green);
}

.balance-item.error-item {
  border-color: rgba(239, 68, 68, 0.15);
  background: rgba(239, 68, 68, 0.02);
}

.balance-item.error-item .balance-item-val {
  color: var(--accent-red);
}

