@import url("https://fonts.googleapis.com/css2?family=Space+Grotesk:wght@400;600&display=swap");

:root {
  color-scheme: dark;
  --bg: #0f1117;
  --bg-gradient-mid: #151822;
  --panel: #1a1d27;
  --ink: #e4e6ed;
  --accent: #6c8cff;
  --muted: #7a7f8e;
  --border: #2a2d3a;
  --shadow: 0 18px 40px rgba(0, 0, 0, 0.3);
  --radius: 18px;
  --surface-hover: #252a3a;
  --surface-deep: #13151e;
  --surface-card: #1e2130;
  --accent-on-dark: #0f1117;
  --success-bg: #1a2e1a;
  --success-text: #66bb6a;
  --success-border: #2e4a2e;
  --error-bg: #2e1a1a;
  --error-text: #ef5350;
  --error-border: #4a2e2e;
  --warning-bg: #2a2210;
  --warning-text: #ffb74d;
  --warning-border: #3d3318;
  --weather-accent: #d9a47f;
  --discover-accent: #d96f3b;
  --route-accent: #c98b5f;
  --raw-accent: #bfae9f;
  font-family: "Space Grotesk", "Avenir Next", "Futura", sans-serif;
}

* {
  box-sizing: border-box;
}

.startup-overlay {
  position: fixed;
  inset: 0;
  z-index: 9999;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  background: var(--bg);
  color: var(--muted);
  font-size: 16px;
  gap: 16px;
}

.startup-spinner {
  width: 36px;
  height: 36px;
  border: 3px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

body {
  margin: 0;
  background: linear-gradient(120deg, var(--bg) 0%, var(--bg-gradient-mid) 60%, var(--bg) 100%);
  color: var(--ink);
  min-height: 100vh;
  height: 100vh;
  overflow: hidden;
  -webkit-overflow-scrolling: touch;
}

.app {
  margin: 0 auto;
  padding: 16px 24px 0;
  display: flex;
  flex-direction: column;
  height: 100vh;
  overflow: hidden;
}

.header {
  display: flex;
  flex-wrap: wrap;
  gap: 16px;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 12px;
  flex-shrink: 0;
}

.header h1 {
  margin: 0 0 4px;
  font-size: 24px;
}

.brand-logo {
  height: 40px;
  width: auto;
  margin-bottom: 8px;
}

.header p {
  margin: 0;
  color: var(--muted);
}

.header .session {
  margin-top: 6px;
  font-size: 12px;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--muted);
}

.controls {
  display: flex;
  gap: 16px;
  flex-wrap: wrap;
}

.controls label {
  display: flex;
  flex-direction: column;
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--muted);
  gap: 6px;
}

select {
  padding: 8px 12px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--panel);
  color: var(--ink);
}

.layout {
  display: flex;
  gap: 16px;
  flex: 1;
  min-height: 0;
  overflow: hidden;
}

.session-sidebar {
  width: 240px;
  min-width: 200px;
  background: var(--panel);
  border-radius: var(--radius);
  padding: 16px;
  box-shadow: var(--shadow);
  border: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

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

.sidebar-header h3 {
  margin: 0;
  font-size: 14px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--muted);
}

.btn-new-session {
  background: var(--accent);
  color: var(--accent-on-dark);
  border: none;
  border-radius: 8px;
  width: 28px;
  height: 28px;
  font-size: 18px;
  font-weight: 600;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
}

.btn-new-session:hover {
  opacity: 0.85;
}

.session-list {
  list-style: none;
  margin: 0;
  padding: 0;
  overflow-y: auto;
  flex: 1;
}

.session-list li {
  padding: 10px 12px;
  border-radius: 10px;
  cursor: pointer;
  margin-bottom: 4px;
  font-size: 13px;
  color: var(--ink);
  border: 1px solid transparent;
  transition: background 0.15s;
}

.session-list li:hover {
  background: var(--surface-hover);
}

.session-list li.active {
  background: var(--surface-hover);
  border-color: var(--accent);
}

.session-list li .session-preview {
  display: block;
  color: var(--muted);
  font-size: 12px;
  margin-top: 2px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.session-list li .session-meta {
  display: block;
  color: var(--muted);
  font-size: 11px;
  margin-top: 2px;
}

.content-area {
  flex: 1;
  min-width: 0;
  min-height: 0;
  display: flex;
  flex-direction: column;
  gap: 16px;
  overflow: hidden;
}

.panel {
  background: var(--panel);
  border-radius: var(--radius);
  padding: 20px;
  box-shadow: var(--shadow);
  border: 1px solid var(--border);
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.result-block {
  display: flex;
  flex-direction: column;
  gap: 10px;
  background: var(--surface-deep);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 14px 16px;
}

.result-title {
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--muted);
}

.result-card {
  padding: 12px 14px;
  border-radius: 12px;
  background: var(--surface-card);
  border: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.result-name {
  font-weight: 600;
}

.result-desc {
  color: var(--muted);
  font-size: 14px;
}

.result-meta {
  font-size: 12px;
  color: var(--accent);
}

.result-link {
  font-size: 13px;
  color: var(--accent);
  text-decoration: none;
}

.result-link:hover {
  text-decoration: underline;
}

.result-details {
  margin-top: 6px;
  font-size: 13px;
  color: var(--muted);
}

.result-details summary {
  cursor: pointer;
  color: var(--accent);
}

.result-details pre {
  background: var(--surface-deep);
  border-radius: 10px;
  padding: 10px 12px;
  white-space: pre-wrap;
  word-break: break-word;
  color: var(--ink);
}

@media (max-width: 640px) {
  body {
    height: auto;
    overflow: auto;
    -webkit-overflow-scrolling: touch;
  }

  .app {
    padding: 8px 12px 0;
    height: auto;
    min-height: 100vh;
    overflow: visible;
  }

  .header {
    flex-direction: column;
    align-items: flex-start;
    margin-bottom: 8px;
    gap: 8px;
  }

  .header h1 {
    font-size: 20px;
  }

  .header > div > p {
    font-size: 12px;
  }

  .layout {
    flex-direction: column;
    overflow: visible;
  }
  .session-sidebar {
    width: 100%;
    max-height: 200px;
  }

  .content-area {
    overflow: visible;
    min-height: 0;
  }

  .panel {
    padding: 12px;
    overflow: visible;
    min-height: 0;
    border-radius: 12px;
  }

  .chat {
    overflow: visible;
    min-height: 0;
  }

  .chat-log {
    max-height: 60vh;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
  }

  .app-footer {
    padding: 4px 0 6px;
    font-size: 9px;
  }

  /* --- Mobile toolbar --- */
  .session-sidebar {
    display: none;
    width: 100%;
    max-height: none;
    position: fixed;
    top: 44px;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 500;
    border-radius: 0;
    padding-bottom: 60px;
  }

  .session-sidebar.mobile-visible {
    display: flex;
  }

  .knowledge-panel {
    display: none;
  }

  .knowledge-panel.mobile-visible {
    display: block;
    position: fixed;
    top: 44px;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 500;
    border-radius: 0;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    padding-bottom: 60px;
    background: var(--panel);
  }

  .header {
    display: none;
  }

  /* Offset content below the fixed header */
  .layout {
    margin-top: 44px;
  }

  .app-footer {
    display: none;
  }

  .content-area[data-mobile-tab="chat"] #chat-view {
    display: flex;
  }

  .content-area[data-mobile-tab="knowledge"] #chat-view {
    display: none;
  }
}

/* --- Mobile-only elements (hidden on desktop) --- */
.mobile-header {
  display: none;
}

.mobile-toolbar {
  display: none;
}

@media (max-width: 640px) {
  .mobile-header {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 12px 16px;
    background: var(--bg);
    border-bottom: 1px solid var(--border);
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    z-index: 600;
  }

  .mobile-header-title {
    font-size: 15px;
    font-weight: 600;
    color: var(--ink);
    letter-spacing: 0.02em;
  }

  .mobile-toolbar {
    display: flex;
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    z-index: 1000;
    background: var(--panel);
    border-top: 1px solid var(--border);
    padding: 4px 0;
    padding-bottom: env(safe-area-inset-bottom, 4px);
    justify-content: space-around;
    align-items: center;
  }

  .mobile-tab {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 2px;
    background: none;
    border: none;
    color: var(--muted);
    font-size: 10px;
    padding: 6px 12px;
    cursor: pointer;
    border-radius: 8px;
    transition: color 0.15s;
  }

  .mobile-tab.active {
    color: var(--accent);
  }

  .mobile-tab svg {
    width: 20px;
    height: 20px;
  }

  /* Push content up so toolbar doesn't cover it */
  .app {
    padding-bottom: 56px;
  }
}
}

/* --- Advanced toggle (removed — framework selector now inline) --- */

.advanced-controls {
  width: 100%;
}

/* --- Suggestion chips --- */
.suggestion-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin: 4px 0 8px;
  animation: chipsFadeIn 0.3s ease;
}

.suggestion-chips .chip {
  padding: 8px 16px;
  border-radius: 20px;
  border: 1px solid var(--accent);
  background: color-mix(in srgb, var(--accent) 8%, transparent);
  color: var(--accent);
  cursor: pointer;
  font-size: 13px;
  font-weight: 600;
  transition: background 0.2s, color 0.2s;
}

.suggestion-chips .chip:hover {
  background: var(--accent);
  color: var(--accent-on-dark);
}

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

/* --- Footer --- */
.app-footer {
  padding: 6px 0 8px;
  text-align: center;
  font-size: 10px;
  color: color-mix(in srgb, var(--muted) 60%, transparent);
  letter-spacing: 0.03em;
  flex-shrink: 0;
}

.app-footer strong {
  color: var(--muted);
  font-weight: 600;
}
