/* BMW R1150GS Garage Companion — Dark Mode */

:root {
  --bg-primary: #1a1a2e;
  --bg-secondary: #16213e;
  --bg-card: #0f3460;
  --bg-input: #1a1a3e;
  --accent: #0066b3;
  --accent-light: #3399dd;
  --text-primary: #f0f0f0;
  --text-secondary: #a0a8c0;
  --text-muted: #6a7090;
  --border: #2a2a4e;
  --danger: #e94560;
  --success: #4ade80;
  --mark-bg: #0066b344;
  --mark-text: #66bbff;
}

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

html {
  font-size: 18px;
  -webkit-text-size-adjust: 100%;
}

body {
  font-family: system-ui, -apple-system, BlinkMacSystemFont, sans-serif;
  background: var(--bg-primary);
  color: var(--text-primary);
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

/* --- Header --- */

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

header h1 {
  font-size: 1.1rem;
  font-weight: 700;
  letter-spacing: 0.5px;
}

header h1 span {
  color: var(--accent-light);
}

header .subtitle {
  font-size: 0.7rem;
  color: var(--text-muted);
}

/* --- Tabs --- */

.tab-bar {
  display: flex;
  background: var(--bg-secondary);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.tab-bar button {
  flex: 1;
  min-height: 60px;
  background: none;
  border: none;
  color: var(--text-secondary);
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
  border-bottom: 3px solid transparent;
  transition: all 0.2s;
}

.tab-bar button.active {
  color: var(--text-primary);
  border-bottom-color: var(--accent);
  background: rgba(0, 102, 179, 0.1);
}

.tab-bar button:active {
  background: rgba(0, 102, 179, 0.2);
}

/* --- Tab content --- */

.tab-content {
  flex: 1;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}

.tab-panel {
  display: none;
  padding: 16px;
  min-height: 100%;
}

.tab-panel.active {
  display: flex;
  flex-direction: column;
}

/* --- Browse tab --- */

.category-group {
  margin-bottom: 24px;
}

.category-group h2 {
  font-size: 0.9rem;
  color: var(--accent-light);
  text-transform: uppercase;
  letter-spacing: 1px;
  margin-bottom: 12px;
  padding-bottom: 6px;
  border-bottom: 1px solid var(--border);
}

.diagram-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 12px;
}

@media (min-width: 768px) and (orientation: landscape) {
  .diagram-grid {
    grid-template-columns: repeat(3, 1fr);
  }
}

@media (min-width: 1024px) {
  .diagram-grid {
    grid-template-columns: repeat(3, 1fr);
  }
}

.diagram-card {
  background: var(--bg-card);
  border-radius: 8px;
  overflow: hidden;
  cursor: pointer;
  transition: transform 0.15s, box-shadow 0.15s;
  border: 1px solid var(--border);
}

.diagram-card:active {
  transform: scale(0.97);
}

.diagram-card img {
  width: 100%;
  aspect-ratio: 4/3;
  object-fit: contain;
  background: #fff;
  padding: 4px;
}

.diagram-card .card-label {
  padding: 8px 10px;
  font-size: 0.75rem;
  color: var(--text-secondary);
  line-height: 1.3;
}

.diagram-card .card-label strong {
  color: var(--text-primary);
  display: block;
  margin-bottom: 2px;
}

/* --- Search tab --- */

.search-box {
  position: relative;
  margin-bottom: 16px;
  flex-shrink: 0;
}

.search-box input {
  width: 100%;
  min-height: 60px;
  padding: 16px 20px;
  font-size: 1rem;
  background: var(--bg-input);
  border: 2px solid var(--border);
  border-radius: 12px;
  color: var(--text-primary);
  outline: none;
  transition: border-color 0.2s;
}

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

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

.search-results {
  flex: 1;
}

.result-section h3 {
  font-size: 0.85rem;
  color: var(--accent-light);
  text-transform: uppercase;
  letter-spacing: 1px;
  margin: 16px 0 10px;
}

.result-item {
  background: var(--bg-card);
  border-radius: 8px;
  padding: 14px 16px;
  margin-bottom: 10px;
  border: 1px solid var(--border);
  cursor: pointer;
}

.result-item:active {
  background: var(--bg-secondary);
}

.result-item .result-source {
  font-size: 0.65rem;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-bottom: 4px;
}

.result-item .result-title {
  font-size: 0.9rem;
  font-weight: 600;
  margin-bottom: 6px;
}

.result-item .result-snippet {
  font-size: 0.8rem;
  color: var(--text-secondary);
  line-height: 1.5;
}

.result-item .result-snippet mark {
  background: var(--mark-bg);
  color: var(--mark-text);
  padding: 1px 3px;
  border-radius: 3px;
}

.search-diagram-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 10px;
}

@media (min-width: 768px) and (orientation: landscape) {
  .search-diagram-grid {
    grid-template-columns: repeat(3, 1fr);
  }
}

.empty-state {
  text-align: center;
  padding: 48px 24px;
  color: var(--text-muted);
  font-size: 0.9rem;
}

/* --- Ask tab --- */

.chat-container {
  display: flex;
  flex-direction: column;
  height: 100%;
  min-height: 0;
}

.chat-messages {
  flex: 1;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding-bottom: 16px;
}

.chat-message {
  margin-bottom: 14px;
  max-width: 85%;
}

.chat-message.user {
  margin-left: auto;
  text-align: right;
}

.chat-message .bubble {
  display: inline-block;
  padding: 12px 16px;
  border-radius: 16px;
  font-size: 0.9rem;
  line-height: 1.5;
  text-align: left;
}

.chat-message.user .bubble {
  background: var(--accent);
  color: #fff;
  border-bottom-right-radius: 4px;
}

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

.chat-message.assistant .bubble strong {
  color: var(--accent-light);
}

.chat-message.assistant .bubble code {
  background: rgba(0, 0, 0, 0.3);
  padding: 1px 5px;
  border-radius: 4px;
  font-size: 0.85em;
}

.chat-message.thinking .bubble {
  background: var(--bg-secondary);
  color: var(--text-muted);
  font-style: italic;
}

.chat-input {
  display: flex;
  gap: 10px;
  padding-top: 12px;
  border-top: 1px solid var(--border);
  flex-shrink: 0;
}

.chat-input textarea {
  flex: 1;
  min-height: 60px;
  max-height: 120px;
  padding: 16px;
  font-size: 1rem;
  font-family: inherit;
  background: var(--bg-input);
  border: 2px solid var(--border);
  border-radius: 12px;
  color: var(--text-primary);
  resize: none;
  outline: none;
  transition: border-color 0.2s;
}

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

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

.chat-input button {
  min-width: 70px;
  min-height: 60px;
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: 12px;
  font-size: 1rem;
  font-weight: 700;
  cursor: pointer;
  transition: background 0.2s;
}

.chat-input button:active {
  background: var(--accent-light);
}

.chat-input button:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

/* --- Overlay / Modal --- */

.overlay {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.95);
  z-index: 1000;
  display: none;
  flex-direction: column;
  align-items: center;
  justify-content: center;
}

.overlay.active {
  display: flex;
}

.overlay-close {
  position: absolute;
  top: 16px;
  right: 16px;
  width: 60px;
  height: 60px;
  background: rgba(255, 255, 255, 0.15);
  border: 2px solid rgba(255, 255, 255, 0.3);
  border-radius: 50%;
  color: #fff;
  font-size: 1.5rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1001;
}

.overlay-close:active {
  background: rgba(255, 255, 255, 0.3);
}

.overlay-label {
  position: absolute;
  bottom: 24px;
  left: 16px;
  right: 16px;
  text-align: center;
  color: var(--text-secondary);
  font-size: 0.8rem;
  line-height: 1.4;
  padding: 10px;
  background: rgba(0, 0, 0, 0.6);
  border-radius: 8px;
}

.overlay-image-container {
  width: 100%;
  height: 100%;
  overflow: auto;
  -webkit-overflow-scrolling: touch;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 70px 16px 80px;
}

.overlay-image-container img {
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
  touch-action: pinch-zoom;
}

/* --- Manual page modal --- */

.manual-modal {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: var(--bg-primary);
  z-index: 1000;
  display: none;
  flex-direction: column;
}

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

.manual-modal-header {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 16px;
  background: var(--bg-secondary);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.manual-modal-header button {
  min-width: 60px;
  min-height: 48px;
  background: rgba(255, 255, 255, 0.1);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text-primary);
  font-size: 0.9rem;
  cursor: pointer;
}

.manual-modal-header h2 {
  flex: 1;
  font-size: 0.95rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.manual-modal-content {
  flex: 1;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: 20px 16px;
  font-size: 0.9rem;
  line-height: 1.7;
  color: var(--text-secondary);
}

.manual-modal-content h1,
.manual-modal-content h2,
.manual-modal-content h3 {
  color: var(--text-primary);
  margin: 20px 0 10px;
}

.manual-modal-content h1 { font-size: 1.2rem; }
.manual-modal-content h2 { font-size: 1.05rem; }
.manual-modal-content h3 { font-size: 0.95rem; }

.manual-modal-content p {
  margin-bottom: 12px;
}

.manual-modal-content code {
  background: rgba(0, 0, 0, 0.3);
  padding: 2px 6px;
  border-radius: 4px;
}

.manual-modal-content ul,
.manual-modal-content ol {
  padding-left: 24px;
  margin-bottom: 12px;
}

/* --- Loading --- */

.loading {
  text-align: center;
  padding: 32px;
  color: var(--text-muted);
}

@keyframes pulse {
  0%, 100% { opacity: 0.4; }
  50% { opacity: 1; }
}

.loading-dots span {
  animation: pulse 1.4s infinite;
}
.loading-dots span:nth-child(2) { animation-delay: 0.2s; }
.loading-dots span:nth-child(3) { animation-delay: 0.4s; }

/* --- Scrollbar styling --- */

::-webkit-scrollbar {
  width: 6px;
}

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

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