/* ═══════════════════════════════════════════════════════════
   LAYOUT
   ═══════════════════════════════════════════════════════════ */
.app {
  display: flex;
  height: 100vh;
  width: 100vw;
  overflow: hidden;
}

/* ═══════════════════════════════════════════════════════════
   SIDEBAR
   ═══════════════════════════════════════════════════════════ */
/* ── Search bar ── */
.sidebar-search {
  padding: 8px 16px 0;
}

.sidebar-search-input {
  width: 100%;
  padding: 8px 10px 8px 32px;
  background: var(--bg-card);
  color: var(--text-primary);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-family: inherit;
  font-size: 12px;
  transition: border-color var(--transition-fast);
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='14' height='14' viewBox='0 0 24 24' fill='none' stroke='%2371717a' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Ccircle cx='11' cy='11' r='8'%3E%3C/circle%3E%3Cline x1='21' y1='21' x2='16.65' y2='16.65'%3E%3C/line%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: 10px center;
}

.sidebar-search-input:focus {
  outline: none;
  border-color: var(--accent);
}

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

.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;
  transition: margin-left var(--transition-slow), opacity var(--transition-normal);
  z-index: 100;
}

.sidebar.collapsed {
  margin-left: calc(-1 * var(--sidebar-width));
  opacity: 0;
  pointer-events: none;
}

.sidebar-header {
  padding: 16px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.sidebar-logo {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 14px;
}

.sidebar-logo .wolf-icon {
  font-size: 26px;
  line-height: 1;
}

.sidebar-logo h1 {
  font-size: 18px;
  font-weight: 700;
  letter-spacing: -0.3px;
  background: linear-gradient(135deg, var(--accent), #4ade80);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.btn-new-chat {
  width: 100%;
  padding: 10px 16px;
  background: var(--accent);
  color: #000;
  border: none;
  border-radius: var(--radius-sm);
  font-family: inherit;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  transition: background var(--transition-fast), transform var(--transition-fast);
}

.btn-new-chat:hover {
  background: var(--accent-hover);
  transform: translateY(-1px);
}

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

.btn-new-chat svg {
  width: 16px;
  height: 16px;
}

/* Conversation List */
.sidebar-conversations {
  flex: 1;
  overflow-y: auto;
  padding: 8px;
}

.sidebar-section-label {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.8px;
  color: var(--text-tertiary);
  padding: 12px 8px 6px;
}

.conversation-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: background var(--transition-fast);
  margin-bottom: 2px;
  position: relative;
  group: true;
}

.conversation-item:hover {
  background: var(--bg-card-hover);
}

.conversation-item.active {
  background: var(--accent-dim);
  border: 1px solid var(--accent-dim-border);
}

.conversation-item .conv-icon {
  font-size: 14px;
  flex-shrink: 0;
  width: 20px;
  text-align: center;
}

.conversation-item .conv-info {
  flex: 1;
  min-width: 0;
}

.conversation-item .conv-title {
  font-size: 13px;
  font-weight: 500;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  color: var(--text-primary);
}

.conversation-item .conv-time {
  font-size: 11px;
  color: var(--text-tertiary);
  margin-top: 2px;
}

.conversation-item .conv-delete {
  opacity: 0;
  background: none;
  border: none;
  color: var(--text-tertiary);
  cursor: pointer;
  padding: 4px;
  border-radius: 4px;
  transition: opacity var(--transition-fast), color var(--transition-fast), background var(--transition-fast);
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
}

.conversation-item:hover .conv-delete {
  opacity: 1;
}

.conversation-item .conv-delete:hover {
  color: var(--danger);
  background: var(--danger-dim);
}

.conversation-item .conv-delete svg {
  width: 14px;
  height: 14px;
}

/* Sidebar Footer / Settings */

/* Sidebar Plans */
.sidebar-plans {
  border-top: 1px solid var(--border);
  padding: 0;
}

.sidebar-section-toggle {
  cursor: pointer;
  display: flex;
  align-items: center;
  user-select: none;
  padding: 10px 16px;
  transition: background var(--transition-fast);
}

.sidebar-section-toggle:hover {
  background: rgba(255,255,255,0.03);
}

.plans-badge {
  background: var(--accent);
  color: #fff;
  font-size: 10px;
  font-weight: 700;
  padding: 1px 6px;
  border-radius: 10px;
  margin-left: 6px;
}

.plans-chevron {
  transition: transform var(--transition-fast);
}

.plans-chevron.open {
  transform: rotate(90deg);
}

.plans-list {
  padding: 0 8px 8px;
}

.plan-item {
  padding: 8px 10px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  font-size: 12px;
  margin-bottom: 2px;
  transition: background var(--transition-fast);
}

.plan-item:hover {
  background: rgba(255,255,255,0.05);
}

.plan-item-goal {
  font-weight: 600;
  color: var(--text-primary);
  margin-bottom: 4px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.plan-item-meta {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 10px;
  color: var(--text-muted);
}

.plan-progress {
  flex: 1;
  height: 3px;
  background: var(--border);
  border-radius: 2px;
  overflow: hidden;
}

.plan-progress-bar {
  height: 100%;
  background: var(--accent);
  border-radius: 2px;
  transition: width 0.3s ease;
}

.sidebar-footer {
  padding: 12px 16px;
  border-top: 1px solid var(--border);
  flex-shrink: 0;
}

/* Providers row */
.providers-row {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  margin-bottom: 8px;
  align-items: center;
}

.provider-badge {
  display: inline-flex;
  align-items: center;
  padding: 2px 8px;
  font-size: 10px;
  font-weight: 600;
  border-radius: 10px;
  background: var(--bg-card);
  color: var(--text-secondary);
  border: 1px solid var(--border);
  letter-spacing: 0.3px;
}

.provider-badge[data-kind="ollama"] {
  border-color: #60a5fa44;
  color: #60a5fa;
}

.provider-badge[data-kind="openai"] {
  border-color: #34d39944;
  color: #34d399;
}

.provider-badge[data-kind="gpt4all"] {
  border-color: #fbbf2444;
  color: #fbbf24;
}

.provider-add-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 20px;
  height: 20px;
  font-size: 14px;
  font-weight: 600;
  border-radius: 50%;
  background: transparent;
  color: var(--text-tertiary);
  border: 1px dashed var(--border);
  cursor: pointer;
  transition: all var(--transition-fast);
  padding: 0;
  line-height: 1;
}

.provider-add-btn:hover {
  color: var(--accent);
  border-color: var(--accent);
  background: var(--accent-alpha);
}

.sidebar-footer label {
  display: block;
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.8px;
  color: var(--text-tertiary);
  margin-bottom: 6px;
}

.model-selector {
  width: 100%;
  padding: 8px 10px;
  background: var(--bg-card);
  color: var(--text-primary);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-family: inherit;
  font-size: 12px;
  cursor: pointer;
  transition: border-color var(--transition-fast);
  appearance: none;
  -webkit-appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%2371717a' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='6 9 12 15 18 9'%3E%3C/polyline%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 10px center;
  padding-right: 28px;
}

.model-selector:focus {
  outline: none;
  border-color: var(--accent);
}

.model-selector option {
  background: var(--bg-card);
  color: var(--text-primary);
}

.pull-model-area {
  margin-top: 10px;
}

.pull-model-row {
  display: flex;
  gap: 6px;
}

.pull-model-input {
  flex: 1;
  padding: 7px 10px;
  background: var(--bg-card);
  color: var(--text-primary);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-family: inherit;
  font-size: 12px;
  transition: border-color var(--transition-fast);
}

.pull-model-input:focus {
  outline: none;
  border-color: var(--accent);
}

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

.btn-pull {
  padding: 7px 12px;
  background: var(--bg-card);
  color: var(--text-secondary);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-family: inherit;
  font-size: 11px;
  font-weight: 600;
  cursor: pointer;
  transition: all var(--transition-fast);
  white-space: nowrap;
}

.btn-pull:hover {
  background: var(--bg-card-hover);
  color: var(--text-primary);
  border-color: var(--border-light);
}

.pull-status {
  font-size: 11px;
  color: var(--text-tertiary);
  margin-top: 6px;
  min-height: 16px;
}

.pull-status.success { color: var(--accent); }
.pull-status.error { color: var(--danger); }

/* ═══════════════════════════════════════════════════════════
   MAIN AREA
   ═══════════════════════════════════════════════════════════ */
.main {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
  position: relative;
}

/* Header */
.main-header {
  height: var(--header-height);
  min-height: var(--header-height);
  display: flex;
  align-items: center;
  padding: 0 16px;
  border-bottom: 1px solid var(--border);
  gap: 12px;
  background: var(--bg-primary);
  z-index: 10;
}

.btn-toggle-sidebar {
  background: none;
  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 var(--transition-fast), color var(--transition-fast);
}

.btn-toggle-sidebar:hover {
  background: var(--bg-card);
  color: var(--text-primary);
}

.btn-toggle-sidebar svg {
  width: 20px;
  height: 20px;
}

.main-header-title {
  font-size: 14px;
  font-weight: 500;
  color: var(--text-secondary);
  flex: 1;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.connection-status {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 11px;
  color: var(--text-tertiary);
  flex-shrink: 0;
}

.connection-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--text-muted);
  transition: background var(--transition-normal);
}

.connection-dot.connected {
  background: var(--accent);
  box-shadow: 0 0 6px rgba(33,194,94,0.5);
}

.connection-dot.error {
  background: var(--danger);
  box-shadow: 0 0 6px rgba(239,68,68,0.5);
}

/* ── Ollama Status Badge ── */
.ollama-badge {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 11px;
  color: var(--text-tertiary);
  padding: 4px 10px;
  border-radius: 20px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  flex-shrink: 0;
  transition: all var(--transition-fast);
}

.ollama-badge.online {
  color: var(--accent);
  border-color: var(--accent-dim-border);
  background: var(--accent-dim);
}

.ollama-badge.offline {
  color: var(--danger);
  border-color: rgba(239,68,68,0.2);
  background: var(--danger-dim);
}

.ollama-badge .ollama-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: currentColor;
}

/* ── Header Action Buttons ── */
.header-actions {
  display: flex;
  align-items: center;
  gap: 4px;
  flex-shrink: 0;
}

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

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

.header-btn svg {
  width: 18px;
  height: 18px;
}

/* ── Export Dropdown ── */
.export-dropdown {
  display: none;
  position: absolute;
  top: 100%;
  right: 0;
  margin-top: 4px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow-md);
  z-index: 50;
  min-width: 160px;
  overflow: hidden;
}

.export-dropdown.visible {
  display: block;
  animation: fadeIn 0.15s ease;
}

.export-dropdown-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 12px;
  font-size: 13px;
  color: var(--text-secondary);
  cursor: pointer;
  transition: background var(--transition-fast);
  border: none;
  background: none;
  width: 100%;
  font-family: inherit;
  text-align: left;
}

.export-dropdown-item:hover {
  background: var(--bg-card-hover);
  color: var(--text-primary);
}

/* ── Error Banner (in chat) ── */
.error-banner {
  margin: 12px 0;
  padding: 12px 16px;
  background: var(--danger-dim);
  border: 1px solid rgba(239,68,68,0.3);
  border-radius: var(--radius-sm);
  display: flex;
  align-items: flex-start;
  gap: 10px;
  animation: messageSlideIn 0.3s ease;
}

.error-banner-icon { font-size: 16px; flex-shrink: 0; margin-top: 1px; }
.error-banner-text { flex: 1; }
.error-banner-title { font-size: 13px; font-weight: 600; color: var(--danger); margin-bottom: 2px; }
.error-banner-detail { font-size: 12px; color: var(--text-secondary); }

.error-banner-retry {
  background: var(--danger);
  color: #fff;
  border: none;
  border-radius: 4px;
  padding: 4px 10px;
  font-size: 11px;
  font-weight: 600;
  font-family: inherit;
  cursor: pointer;
  flex-shrink: 0;
  margin-top: 2px;
  transition: background var(--transition-fast);
}

.error-banner-retry:hover { background: var(--danger-hover); }

/* ═══════════════════════════════════════════════════════════
   INPUT AREA
   ═══════════════════════════════════════════════════════════ */
.input-area {
  padding: 12px 20px 16px;
  background: var(--bg-primary);
  border-top: 1px solid var(--border);
}

.input-area-inner {
  max-width: 800px;
  margin: 0 auto;
}

.input-row {
  display: flex;
  gap: 10px;
  align-items: flex-end;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 8px 12px 8px 16px;
  transition: border-color var(--transition-fast), box-shadow var(--transition-fast);
}

.input-row:focus-within {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(33,194,94,0.1);
}

#messageInput {
  flex: 1;
  background: none;
  border: none;
  color: var(--text-primary);
  font-family: inherit;
  font-size: 14px;
  line-height: 1.5;
  resize: none;
  min-height: 24px;
  max-height: 120px;
  padding: 4px 0;
  outline: none;
}

#messageInput::placeholder {
  color: var(--text-muted);
}

.btn-send {
  width: 36px;
  height: 36px;
  background: var(--accent);
  border: none;
  border-radius: 50%;
  color: #000;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: all var(--transition-fast);
}

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

.btn-send:active {
  transform: scale(0.95);
}

.btn-send:disabled {
  background: var(--bg-card);
  color: var(--text-muted);
  cursor: not-allowed;
  transform: none;
}

.btn-send svg {
  width: 18px;
  height: 18px;
}

.input-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-top: 6px;
  padding: 0 4px;
}

.input-model-label {
  font-size: 11px;
  color: var(--text-muted);
}

.input-hint {
  font-size: 11px;
  color: var(--text-muted);
}

.input-hint kbd {
  background: var(--bg-card);
  padding: 1px 5px;
  border-radius: 3px;
  font-family: inherit;
  font-size: 10px;
  border: 1px solid var(--border);
}

/* ═══════════════════════════════════════════════════════════
   MOBILE OVERLAY
   ═══════════════════════════════════════════════════════════ */
.sidebar-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.5);
  z-index: 99;
  backdrop-filter: blur(2px);
}

.sidebar-overlay.visible {
  display: block;
  animation: fadeIn 0.2s ease;
}

/* ═══════════════════════════════════════════════════════════
   RESPONSIVE
   ═══════════════════════════════════════════════════════════ */
@media (max-width: 768px) {
  .sidebar {
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    z-index: 100;
    box-shadow: var(--shadow-lg);
  }

  .sidebar.collapsed {
    margin-left: calc(-1 * var(--sidebar-width));
  }

  .message-content {
    max-width: 85%;
  }

  .suggested-prompts {
    grid-template-columns: 1fr;
  }

  .messages-inner {
    padding: 16px 12px;
  }

  .input-area {
    padding: 10px 12px 14px;
  }
}

@media (max-width: 480px) {
  .message-content {
    max-width: 90%;
  }
}
