/* ============================================
   SkillHub — Styles
   ============================================ */

/* --- CSS Variables --- */
:root {
  --bg-primary: #1a1a2e;
  --bg-secondary: #16213e;
  --bg-tertiary: #0f3460;
  --bg-chat: #1a1a2e;
  --bg-message-user: #0f3460;
  --bg-message-assistant: #16213e;
  --bg-code: #0d1117;
  --text-primary: #e0e0e0;
  --text-secondary: #a0a0a0;
  --text-muted: #666;
  --accent: #4cc9f0;
  --accent-hover: #3ab4d8;
  --danger: #e74c3c;
  --success: #2ecc71;
  --border: #2a2a4a;
  --sidebar-width: 280px;
  --panel-width: 300px;
  --radius-sm: 6px;
  --radius-md: 10px;
  --radius-lg: 16px;
  --shadow: 0 4px 24px rgba(0, 0, 0, 0.4);
  --transition: 0.2s ease;
}

/* --- Reset & Base --- */
*,
*::before,
*::after {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

html, body {
  height: 100%;
  overflow: hidden;
}

body {
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
  background: var(--bg-primary);
  color: var(--text-primary);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

a {
  color: var(--accent);
  text-decoration: none;
}

a:hover {
  text-decoration: underline;
}

button {
  font-family: inherit;
  cursor: pointer;
  border: none;
  background: none;
  color: inherit;
  font-size: inherit;
}

input, textarea, select {
  font-family: inherit;
  font-size: inherit;
  color: var(--text-primary);
}

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

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

::-webkit-scrollbar-thumb {
  background: var(--border);
  border-radius: 3px;
}

::-webkit-scrollbar-thumb:hover {
  background: var(--text-muted);
}

/* Firefox */
* {
  scrollbar-width: thin;
  scrollbar-color: var(--border) transparent;
}

/* ============================================
   AUTH SCREEN
   ============================================ */
#auth-screen {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 100vh;
  background: var(--bg-primary);
}

.auth-card {
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 48px 40px;
  width: 100%;
  max-width: 400px;
  box-shadow: var(--shadow);
  text-align: center;
}

.auth-brand {
  font-size: 28px;
  font-weight: 700;
  color: var(--text-primary);
  margin-bottom: 8px;
  letter-spacing: -0.5px;
}

.auth-brand span {
  color: var(--accent);
}

.auth-subtitle {
  color: var(--text-secondary);
  font-size: 14px;
  margin-bottom: 32px;
}

.auth-form {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.auth-input {
  width: 100%;
  padding: 12px 16px;
  background: var(--bg-primary);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text-primary);
  font-size: 15px;
  outline: none;
  transition: border-color var(--transition);
}

.auth-input:focus {
  border-color: var(--accent);
}

.auth-input::placeholder {
  color: var(--text-muted);
}

.auth-btn {
  width: 100%;
  padding: 12px;
  background: var(--accent);
  color: #1a1a2e;
  border-radius: var(--radius-sm);
  font-weight: 600;
  font-size: 15px;
  transition: background var(--transition);
}

.auth-btn:hover {
  background: var(--accent-hover);
}

.auth-btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.auth-error {
  color: var(--danger);
  font-size: 13px;
  min-height: 20px;
  margin-top: -8px;
}

.auth-connection {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  font-size: 13px;
  color: var(--text-muted);
  margin-top: 16px;
}

.connection-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--text-muted);
  display: inline-block;
}

.connection-dot.connected {
  background: var(--success);
}

.connection-dot.error {
  background: var(--danger);
}

/* ============================================
   APP SCREEN — Three-column layout
   ============================================ */
#app-screen {
  display: none;
  height: 100vh;
  overflow: hidden;
}

#app-screen.active {
  display: flex;
}

/* --- Left Sidebar --- */
.sidebar {
  width: var(--sidebar-width);
  min-width: var(--sidebar-width);
  background: var(--bg-secondary);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.sidebar-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 20px 16px 16px;
  border-bottom: 1px solid var(--border);
}

.sidebar-brand {
  font-size: 20px;
  font-weight: 700;
  letter-spacing: -0.3px;
}

.sidebar-brand span {
  color: var(--accent);
}

.sidebar-add-btn {
  width: 32px;
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg-tertiary);
  border-radius: var(--radius-sm);
  font-size: 18px;
  color: var(--text-secondary);
  transition: background var(--transition), color var(--transition);
}

.sidebar-add-btn:hover {
  background: var(--accent);
  color: #1a1a2e;
}

.channel-list {
  flex: 1;
  overflow-y: auto;
  padding: 8px;
}

.channel-item {
  display: flex;
  align-items: center;
  padding: 12px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: background var(--transition);
  margin-bottom: 2px;
  position: relative;
}

.channel-item:hover {
  background: var(--bg-tertiary);
}

.channel-item.active {
  background: var(--bg-tertiary);
  border-left: 3px solid var(--accent);
}

.channel-info {
  flex: 1;
  min-width: 0;
}

.channel-name {
  font-weight: 600;
  font-size: 14px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.channel-desc {
  font-size: 12px;
  color: var(--text-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  margin-top: 2px;
}

.channel-delete {
  opacity: 0;
  width: 24px;
  height: 24px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--radius-sm);
  color: var(--text-muted);
  font-size: 14px;
  transition: opacity var(--transition), color var(--transition), background var(--transition);
  margin-left: 4px;
  flex-shrink: 0;
}

.channel-item:hover .channel-delete {
  opacity: 1;
}

.channel-delete:hover {
  color: var(--danger);
  background: rgba(231, 76, 60, 0.15);
}

.channel-empty {
  text-align: center;
  color: var(--text-muted);
  font-size: 13px;
  padding: 40px 16px;
}

/* --- Center Chat Area --- */
.chat-area {
  flex: 1;
  display: flex;
  flex-direction: column;
  background: var(--bg-chat);
  min-width: 0;
  overflow: hidden;
}

.chat-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
  background: var(--bg-secondary);
  flex-shrink: 0;
}

.chat-header-title {
  font-size: 16px;
  font-weight: 600;
}

.chat-header-actions {
  display: flex;
  gap: 8px;
}

.chat-header-btn {
  width: 32px;
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--radius-sm);
  color: var(--text-secondary);
  transition: background var(--transition), color var(--transition);
}

.chat-header-btn:hover {
  background: var(--bg-tertiary);
  color: var(--text-primary);
}

.chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.chat-empty {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  height: 100%;
  color: var(--text-muted);
  text-align: center;
  padding: 40px;
}

.chat-empty-icon {
  font-size: 48px;
  margin-bottom: 16px;
  opacity: 0.3;
}

.chat-empty-title {
  font-size: 18px;
  font-weight: 600;
  color: var(--text-secondary);
  margin-bottom: 8px;
}

.chat-empty-desc {
  font-size: 14px;
  max-width: 320px;
}

/* --- Message Bubbles --- */
.message {
  display: flex;
  flex-direction: column;
  max-width: 75%;
  animation: fadeIn 0.25s ease;
}

.message-user {
  align-self: flex-end;
}

.message-assistant {
  align-self: flex-start;
}

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

.message-user .message-bubble {
  background: var(--bg-message-user);
  border-bottom-right-radius: 4px;
}

.message-assistant .message-bubble {
  background: var(--bg-message-assistant);
  border: 1px solid var(--border);
  border-bottom-left-radius: 4px;
}

.message-meta {
  font-size: 11px;
  color: var(--text-muted);
  margin-top: 4px;
  padding: 0 4px;
}

.message-user .message-meta {
  text-align: right;
}

.message-sender {
  font-weight: 600;
  color: var(--text-secondary);
}

/* --- Code Blocks inside messages --- */
.code-block {
  background: var(--bg-code);
  border-radius: var(--radius-sm);
  margin: 12px 0;
  overflow: hidden;
  border: 1px solid var(--border);
}

.code-block-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 12px;
  background: rgba(255, 255, 255, 0.05);
  border-bottom: 1px solid var(--border);
  font-size: 12px;
}

.code-block-lang {
  color: var(--text-secondary);
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.code-block-actions {
  display: flex;
  gap: 4px;
}

.code-block-btn {
  padding: 2px 8px;
  border-radius: 3px;
  font-size: 12px;
  color: var(--text-secondary);
  transition: background var(--transition), color var(--transition);
}

.code-block-btn:hover {
  background: rgba(255, 255, 255, 0.1);
  color: var(--text-primary);
}

.code-block-btn.save-btn:hover {
  color: var(--accent);
}

.code-block pre {
  padding: 12px 16px;
  overflow-x: auto;
  font-family: 'JetBrains Mono', 'Fira Code', 'Cascadia Code', 'Consolas', monospace;
  font-size: 13px;
  line-height: 1.6;
  color: var(--text-primary);
}

/* Inline code */
code:not([class]) {
  background: var(--bg-code);
  padding: 2px 6px;
  border-radius: 3px;
  font-family: 'JetBrains Mono', 'Fira Code', 'Cascadia Code', 'Consolas', monospace;
  font-size: 0.9em;
}

/* --- Thinking/Loading indicator --- */
.typing-indicator {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 12px 16px;
  background: var(--bg-message-assistant);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  border-bottom-left-radius: 4px;
  width: fit-content;
  animation: fadeIn 0.25s ease;
}

.typing-dot {
  width: 8px;
  height: 8px;
  background: var(--text-muted);
  border-radius: 50%;
  animation: typingBounce 1.4s infinite ease-in-out;
}

.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.6);
    opacity: 0.4;
  }
  40% {
    transform: scale(1);
    opacity: 1;
  }
}

/* --- Chat Input --- */
.chat-input-area {
  padding: 16px 20px;
  border-top: 1px solid var(--border);
  background: var(--bg-secondary);
  flex-shrink: 0;
}

.chat-input-wrapper {
  display: flex;
  align-items: flex-end;
  gap: 12px;
  background: var(--bg-primary);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 8px 12px;
  transition: border-color var(--transition);
}

.chat-input-wrapper:focus-within {
  border-color: var(--accent);
}

.chat-input {
  flex: 1;
  background: none;
  border: none;
  color: var(--text-primary);
  font-size: 14px;
  line-height: 1.5;
  resize: none;
  min-height: 24px;
  max-height: 160px;
  outline: none;
  padding: 4px 0;
}

.chat-input::placeholder {
  color: var(--text-muted);
}

.send-btn {
  width: 36px;
  height: 36px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--accent);
  color: #1a1a2e;
  border-radius: var(--radius-sm);
  font-size: 18px;
  transition: background var(--transition);
  flex-shrink: 0;
}

.send-btn:hover {
  background: var(--accent-hover);
}

.send-btn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

/* ============================================
   RIGHT PANEL — Saved Outputs
   ============================================ */
.saved-panel {
  width: var(--panel-width);
  min-width: var(--panel-width);
  background: var(--bg-secondary);
  border-left: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  transition: width var(--transition), min-width var(--transition), opacity var(--transition);
}

.saved-panel.collapsed {
  width: 0;
  min-width: 0;
  opacity: 0;
  border-left: none;
}

.saved-panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.saved-panel-title {
  font-size: 14px;
  font-weight: 600;
}

.saved-panel-toggle {
  width: 28px;
  height: 28px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--radius-sm);
  color: var(--text-secondary);
  font-size: 12px;
  transition: background var(--transition);
}

.saved-panel-toggle:hover {
  background: var(--bg-tertiary);
}

.saved-panel-content {
  flex: 1;
  overflow-y: auto;
  padding: 12px;
}

.saved-add-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  width: 100%;
  padding: 10px;
  background: var(--bg-tertiary);
  border-radius: var(--radius-sm);
  color: var(--text-secondary);
  font-size: 13px;
  font-weight: 500;
  transition: background var(--transition), color var(--transition);
  margin-bottom: 12px;
}

.saved-add-btn:hover {
  background: var(--accent);
  color: #1a1a2e;
}

/* --- Categories --- */
.saved-category {
  margin-bottom: 8px;
}

.category-header {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 10px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: background var(--transition);
  user-select: none;
}

.category-header:hover {
  background: var(--bg-tertiary);
}

.category-arrow {
  font-size: 10px;
  color: var(--text-muted);
  transition: transform var(--transition);
  width: 16px;
  flex-shrink: 0;
  text-align: center;
}

.saved-category.open .category-arrow {
  transform: rotate(90deg);
}

.category-name {
  font-size: 13px;
  font-weight: 600;
  flex: 1;
}

.category-count {
  font-size: 11px;
  color: var(--text-muted);
  background: var(--bg-primary);
  padding: 2px 8px;
  border-radius: 10px;
}

.category-items {
  display: none;
  padding: 4px 0 4px 24px;
}

.saved-category.open .category-items {
  display: block;
}

.saved-item {
  display: flex;
  align-items: center;
  padding: 6px 10px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: background var(--transition);
  margin-bottom: 2px;
}

.saved-item:hover {
  background: var(--bg-tertiary);
}

.saved-item-label {
  flex: 1;
  font-size: 13px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.saved-item-copy {
  opacity: 0;
  width: 22px;
  height: 22px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 3px;
  font-size: 11px;
  color: var(--text-muted);
  transition: opacity var(--transition), color var(--transition);
  flex-shrink: 0;
}

.saved-item:hover .saved-item-copy {
  opacity: 1;
}

.saved-item-copy:hover {
  color: var(--accent);
}

.saved-empty {
  text-align: center;
  color: var(--text-muted);
  font-size: 13px;
  padding: 32px 16px;
}

/* ============================================
   MODALS
   ============================================ */
.modal-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.6);
  backdrop-filter: blur(4px);
  z-index: 1000;
  align-items: center;
  justify-content: center;
  animation: fadeIn 0.2s ease;
}

.modal-overlay.active {
  display: flex;
}

.modal-card {
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 32px;
  width: 100%;
  max-width: 460px;
  box-shadow: var(--shadow);
  animation: slideUp 0.25s ease;
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 24px;
}

.modal-title {
  font-size: 18px;
  font-weight: 600;
}

.modal-close {
  width: 32px;
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--radius-sm);
  color: var(--text-secondary);
  font-size: 18px;
  transition: background var(--transition), color var(--transition);
}

.modal-close:hover {
  background: var(--bg-tertiary);
  color: var(--text-primary);
}

.modal-form {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.form-group {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.form-label {
  font-size: 13px;
  font-weight: 500;
  color: var(--text-secondary);
}

.form-input {
  width: 100%;
  padding: 10px 14px;
  background: var(--bg-primary);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text-primary);
  font-size: 14px;
  outline: none;
  transition: border-color var(--transition);
}

.form-input:focus {
  border-color: var(--accent);
}

.form-input::placeholder {
  color: var(--text-muted);
}

.form-input.mono {
  font-family: 'JetBrains Mono', 'Fira Code', 'Consolas', monospace;
  font-size: 13px;
}

.form-input[readonly] {
  opacity: 0.6;
  cursor: default;
}

textarea.form-input {
  resize: vertical;
  min-height: 80px;
  line-height: 1.5;
}

.form-select {
  width: 100%;
  padding: 10px 14px;
  background: var(--bg-primary);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text-primary);
  font-size: 14px;
  outline: none;
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath fill='%23a0a0a0' d='M6 8L1 3h10z'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 12px center;
  padding-right: 32px;
  cursor: pointer;
  transition: border-color var(--transition);
}

.form-select:focus {
  border-color: var(--accent);
}

.modal-actions {
  display: flex;
  gap: 10px;
  justify-content: flex-end;
  margin-top: 8px;
}

.btn-primary {
  padding: 10px 20px;
  background: var(--accent);
  color: #1a1a2e;
  border-radius: var(--radius-sm);
  font-weight: 600;
  font-size: 14px;
  transition: background var(--transition);
}

.btn-primary:hover {
  background: var(--accent-hover);
}

.btn-secondary {
  padding: 10px 20px;
  background: var(--bg-tertiary);
  color: var(--text-secondary);
  border-radius: var(--radius-sm);
  font-weight: 500;
  font-size: 14px;
  transition: background var(--transition), color var(--transition);
}

.btn-secondary:hover {
  background: var(--border);
  color: var(--text-primary);
}

.btn-danger {
  padding: 10px 20px;
  background: var(--danger);
  color: #fff;
  border-radius: var(--radius-sm);
  font-weight: 600;
  font-size: 14px;
  transition: opacity var(--transition);
}

.btn-danger:hover {
  opacity: 0.85;
}

/* --- View Saved Output Modal --- */
.modal-content-view {
  background: var(--bg-code);
  border-radius: var(--radius-sm);
  padding: 16px;
  max-height: 400px;
  overflow-y: auto;
  font-family: 'JetBrains Mono', 'Fira Code', 'Consolas', monospace;
  font-size: 13px;
  line-height: 1.6;
  white-space: pre-wrap;
  word-break: break-word;
  border: 1px solid var(--border);
}

/* ============================================
   ANIMATIONS
   ============================================ */
@keyframes fadeIn {
  from {
    opacity: 0;
  }
  to {
    opacity: 1;
  }
}

@keyframes slideUp {
  from {
    opacity: 0;
    transform: translateY(16px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@keyframes slideInRight {
  from {
    opacity: 0;
    transform: translateX(16px);
  }
  to {
    opacity: 1;
    transform: translateX(0);
  }
}

/* ============================================
   RESPONSIVE
   ============================================ */

/* Collapse right panel on medium screens */
@media (max-width: 1024px) {
  .saved-panel {
    position: fixed;
    right: 0;
    top: 0;
    bottom: 0;
    z-index: 100;
    box-shadow: -4px 0 24px rgba(0, 0, 0, 0.5);
    animation: slideInRight 0.2s ease;
  }

  .saved-panel.collapsed {
    transform: translateX(100%);
    opacity: 1;
  }
}

/* Sidebar toggle on small screens */
@media (max-width: 768px) {
  .sidebar {
    position: fixed;
    left: 0;
    top: 0;
    bottom: 0;
    z-index: 200;
    box-shadow: 4px 0 24px rgba(0, 0, 0, 0.5);
    transform: translateX(-100%);
    transition: transform 0.3s ease;
  }

  .sidebar.open {
    transform: translateX(0);
  }

  .mobile-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.5);
    z-index: 150;
  }

  .mobile-overlay.active {
    display: block;
  }

  .chat-header-hamburger {
    display: flex;
  }

  .saved-panel {
    width: 280px;
    min-width: 280px;
  }

  .message {
    max-width: 90%;
  }
}

/* Hamburger menu button (hidden on desktop) */
.chat-header-hamburger {
  display: none;
  width: 32px;
  height: 32px;
  align-items: center;
  justify-content: center;
  border-radius: var(--radius-sm);
  color: var(--text-secondary);
  font-size: 18px;
  transition: background var(--transition);
}

@media (max-width: 768px) {
  .chat-header-hamburger {
    display: flex;
  }
}

/* Utility class for hidden elements */
.hidden {
  display: none !important;
}