/* ============================================================
   Mazda 3 Troubleshooting Assistant — Mobile-First CSS
   Dark automotive theme
   ============================================================ */

/* ---- CSS Variables ---- */
:root {
  --bg: #0a0a14;
  --bg-card: #1e1e2e;
  --bg-card-alt: #16213e;
  --bg-input: #12121f;
  --border: #2a2a3e;
  --text-primary: #e8e8f0;
  --text-secondary: #9090b0;
  --text-muted: #606080;
  --accent: #4f8ef7;
  --accent-dark: #2563eb;
  --accent-red: #ef4444;
  --accent-green: #22c55e;
  --accent-amber: #f59e0b;
  --bubble-user: #1e3a5f;
  --bubble-assistant: #1e2e1e;
  --header-height: 56px;
  --nav-height: 60px;
  --sheet-radius: 20px;
  --radius: 12px;
  --radius-sm: 8px;
}

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

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

body {
  background: var(--bg);
  color: var(--text-primary);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  line-height: 1.5;
  min-height: 100vh;
  overflow-x: hidden;
}

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

a:hover {
  text-decoration: underline;
}

pre, code {
  font-family: "SF Mono", Consolas, "Liberation Mono", Menlo, monospace;
  font-size: 0.875rem;
}

code {
  background: var(--bg-card);
  padding: 2px 6px;
  border-radius: 4px;
  color: var(--accent);
}

pre {
  background: var(--bg-card);
  padding: 12px;
  border-radius: var(--radius-sm);
  overflow-x: auto;
  color: var(--text-secondary);
}

/* ---- App Header ---- */
.app-header {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  height: var(--header-height);
  background: var(--bg-card);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 16px;
  z-index: 100;
  -webkit-backdrop-filter: blur(8px);
  backdrop-filter: blur(8px);
}

.header-title {
  display: flex;
  align-items: center;
  gap: 8px;
  font-weight: 600;
  font-size: 1rem;
  color: var(--text-primary);
}

.header-icon {
  font-size: 1.2rem;
}

.mode-toggle {
  background: none;
  border: none;
  cursor: pointer;
  padding: 4px;
}

.mode-badge {
  display: inline-block;
  padding: 4px 10px;
  border-radius: 20px;
  font-size: 0.75rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.mode-badge.beginner {
  background: rgba(34, 197, 94, 0.2);
  color: var(--accent-green);
  border: 1px solid rgba(34, 197, 94, 0.3);
}

.mode-badge.expert {
  background: rgba(79, 142, 247, 0.2);
  color: var(--accent);
  border: 1px solid rgba(79, 142, 247, 0.3);
}

/* ---- Main Content ---- */
.main-content {
  padding-top: var(--header-height);
  padding-bottom: var(--nav-height);
  min-height: 100vh;
}

/* ---- Bottom Navigation ---- */
.bottom-nav {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  height: var(--nav-height);
  background: var(--bg-card);
  border-top: 1px solid var(--border);
  display: flex;
  z-index: 100;
  -webkit-backdrop-filter: blur(8px);
  backdrop-filter: blur(8px);
}

.nav-tab {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  color: var(--text-muted);
  text-decoration: none;
  font-size: 0.6875rem;
  padding: 8px 4px;
  transition: color 0.15s;
  -webkit-tap-highlight-color: transparent;
}

.nav-tab:hover {
  color: var(--text-secondary);
  text-decoration: none;
}

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

.nav-icon {
  font-size: 1.1rem;
  line-height: 1;
}

.nav-label {
  font-weight: 500;
}

/* The More nav-tab is a button, reset its styles */
button.nav-tab {
  background: none;
  border: none;
  cursor: pointer;
  font-family: inherit;
}

/* ---- More Menu Overlay ---- */
.more-menu-overlay {
  position: fixed;
  inset: 0;
  z-index: 98;
  background: rgba(0, 0, 0, 0.4);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease;
}

.more-menu-overlay.visible {
  opacity: 1;
  pointer-events: auto;
}

/* ---- More Menu Popup ---- */
.more-menu {
  position: fixed;
  bottom: var(--nav-height);
  right: 0;
  z-index: 99;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-bottom: none;
  border-radius: var(--radius) var(--radius) 0 0;
  min-width: 200px;
  padding: 8px 0;
  transform: translateY(100%);
  opacity: 0;
  pointer-events: none;
  transition: transform 0.25s cubic-bezier(0.4, 0, 0.2, 1),
              opacity 0.25s cubic-bezier(0.4, 0, 0.2, 1);
  box-shadow: 0 -4px 24px rgba(0, 0, 0, 0.4);
}

.more-menu.open {
  transform: translateY(0);
  opacity: 1;
  pointer-events: auto;
}

.more-menu-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 20px;
  color: var(--text-secondary);
  text-decoration: none;
  font-size: 0.9375rem;
  font-weight: 500;
  transition: background 0.15s, color 0.15s;
  -webkit-tap-highlight-color: transparent;
}

.more-menu-item:hover {
  background: rgba(79, 142, 247, 0.08);
  color: var(--text-primary);
  text-decoration: none;
}

.more-menu-item.active {
  color: var(--accent);
}

.more-menu-icon {
  font-size: 1.1rem;
  line-height: 1;
  width: 24px;
  text-align: center;
}

.more-menu-label {
  flex: 1;
}

/* ============================================================
   Chat Page
   ============================================================ */

.chat-messages {
  display: flex;
  flex-direction: column;
  padding: 16px 12px;
  gap: 12px;
  overflow-y: auto;
  min-height: calc(100vh - var(--header-height) - var(--nav-height) - 70px);
  padding-bottom: 80px;
}

.message {
  display: flex;
  max-width: 100%;
}

.user-message {
  justify-content: flex-end;
}

.assistant-message {
  justify-content: flex-start;
}

.message-bubble {
  max-width: 85%;
  padding: 12px 14px;
  border-radius: var(--radius);
  font-size: 0.9375rem;
  line-height: 1.5;
  word-wrap: break-word;
  overflow-wrap: break-word;
}

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

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

/* Markdown content inside assistant bubbles */
.assistant-message .message-bubble p {
  margin: 0 0 0.5em 0;
}
.assistant-message .message-bubble p:last-child {
  margin-bottom: 0;
}
.assistant-message .message-bubble h3,
.assistant-message .message-bubble h4 {
  margin: 0.8em 0 0.3em 0;
  color: var(--accent);
  font-size: 1rem;
}
.assistant-message .message-bubble ul,
.assistant-message .message-bubble ol {
  margin: 0.3em 0;
  padding-left: 1.4em;
}
.assistant-message .message-bubble li {
  margin: 0.2em 0;
}
.assistant-message .message-bubble hr {
  border: none;
  border-top: 1px solid var(--border);
  margin: 0.8em 0;
}
.assistant-message .message-bubble code {
  background: rgba(255,255,255,0.1);
  padding: 1px 5px;
  border-radius: 3px;
  font-size: 0.85em;
}
.assistant-message .message-bubble strong {
  color: var(--text-primary);
}
.assistant-message .message-bubble .ref-chip,
.assistant-message .message-bubble .dtc-chip {
  display: inline-block;
  margin: 3px 2px;
  vertical-align: middle;
}

/* Thinking / loading bubbles */
.thinking-bubble {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 14px 18px;
  min-width: 60px;
}

.dot {
  display: inline-block;
  width: 8px;
  height: 8px;
  background: var(--text-muted);
  border-radius: 50%;
  animation: bounce 1.2s infinite ease-in-out;
}

.dot:nth-child(1) { animation-delay: 0s; }
.dot:nth-child(2) { animation-delay: 0.2s; }
.dot:nth-child(3) { animation-delay: 0.4s; }

@keyframes bounce {
  0%, 80%, 100% { transform: scale(0.8); opacity: 0.5; }
  40% { transform: scale(1.1); opacity: 1; }
}

/* Chat input bar */
.chat-input-bar {
  position: fixed;
  bottom: var(--nav-height);
  left: 0;
  right: 0;
  padding: 10px 12px;
  background: var(--bg);
  border-top: 1px solid var(--border);
  z-index: 90;
}

.input-container {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: 24px;
  padding: 8px 8px 8px 14px;
}

.chat-textarea {
  flex: 1;
  background: none;
  border: none;
  outline: none;
  color: var(--text-primary);
  font-family: inherit;
  font-size: 0.9375rem;
  resize: none;
  max-height: 120px;
  overflow-y: auto;
  line-height: 1.4;
  padding: 2px 0;
}

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

.send-btn {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: var(--accent);
  border: none;
  color: white;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: background 0.15s, transform 0.1s;
  -webkit-tap-highlight-color: transparent;
}

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

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

.send-btn:disabled {
  background: var(--text-muted);
  cursor: not-allowed;
}

/* Reference chips in messages */
.ref-chips-container {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 8px;
}

.ref-chip {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  min-height: 36px;
  padding: 6px 12px;
  background: rgba(79, 142, 247, 0.15);
  border: 1px solid rgba(79, 142, 247, 0.35);
  border-radius: 20px;
  color: var(--accent);
  font-size: 0.8125rem;
  font-weight: 500;
  cursor: pointer;
  transition: background 0.15s;
  -webkit-tap-highlight-color: transparent;
  white-space: nowrap;
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  text-align: left;
}

.ref-chip:hover {
  background: rgba(79, 142, 247, 0.25);
}

.tsb-chip {
  background: rgba(245, 158, 11, 0.15);
  border-color: rgba(245, 158, 11, 0.35);
  color: var(--accent-amber);
}

.tsb-chip:hover {
  background: rgba(245, 158, 11, 0.25);
}

/* DTC inline chips in chat */
.dtc-chip {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  min-height: 36px;
  padding: 6px 12px;
  background: rgba(239, 68, 68, 0.15);
  border: 1px solid rgba(239, 68, 68, 0.35);
  border-radius: 6px;
  color: var(--accent-red);
  font-size: 0.8125rem;
  font-weight: 600;
  text-decoration: none;
}

.dtc-chip:hover {
  background: rgba(239, 68, 68, 0.25);
  text-decoration: none;
}

/* API key warning */
.api-key-warning {
  max-width: 500px;
  margin: 40px auto;
  padding: 24px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  text-align: center;
}

.api-key-warning h2 {
  font-size: 1.25rem;
  margin-bottom: 12px;
  color: var(--accent-amber);
}

.api-key-warning p {
  color: var(--text-secondary);
  margin-bottom: 12px;
  font-size: 0.9375rem;
}

.warning-icon {
  font-size: 2.5rem;
  margin-bottom: 12px;
}

/* ============================================================
   Bottom Sheet
   ============================================================ */

.sheet-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.6);
  z-index: 200;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.25s ease;
  -webkit-backdrop-filter: blur(2px);
  backdrop-filter: blur(2px);
}

.sheet-overlay.visible {
  opacity: 1;
  pointer-events: all;
}

.bottom-sheet {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  height: 78vh;
  background: var(--bg-card);
  border-top-left-radius: var(--sheet-radius);
  border-top-right-radius: var(--sheet-radius);
  z-index: 201;
  display: flex;
  flex-direction: column;
  transform: translateY(100%);
  transition: transform 0.3s cubic-bezier(0.32, 0.72, 0, 1);
  overflow: hidden;
  border-top: 1px solid var(--border);
}

.bottom-sheet.open {
  transform: translateY(0);
}

.sheet-handle {
  width: 40px;
  height: 4px;
  background: var(--text-muted);
  border-radius: 2px;
  margin: 10px auto 6px;
  flex-shrink: 0;
  opacity: 0.5;
}

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

.sheet-title {
  font-weight: 600;
  font-size: 0.9375rem;
  color: var(--text-primary);
  flex: 1;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  padding-right: 8px;
}

.sheet-close {
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  font-size: 1rem;
  padding: 4px 8px;
  border-radius: var(--radius-sm);
  flex-shrink: 0;
  -webkit-tap-highlight-color: transparent;
}

.sheet-close:hover {
  color: var(--text-primary);
  background: var(--border);
}

.sheet-content {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
  -webkit-overflow-scrolling: touch;
}

/* ============================================================
   Article content (inside bottom sheet)
   ============================================================ */

.ref-article {
  max-width: 100%;
}

.ref-title {
  font-size: 1rem;
  font-weight: 600;
  color: var(--text-primary);
  margin-bottom: 4px;
  line-height: 1.3;
}

.ref-path {
  font-size: 0.75rem;
  color: var(--text-muted);
  margin-bottom: 16px;
}

.article-content {
  font-size: 0.875rem;
  color: var(--text-secondary);
  line-height: 1.6;
}

.article-content h1,
.article-content h2,
.article-content h3,
.article-content h4 {
  color: var(--text-primary);
  margin: 16px 0 8px;
  font-size: 0.9375rem;
}

.article-content p {
  margin-bottom: 10px;
}

.article-content table {
  width: 100%;
  border-collapse: collapse;
  margin-bottom: 12px;
  overflow-x: auto;
  display: block;
  font-size: 0.8125rem;
}

.article-content th,
.article-content td {
  border: 1px solid var(--border);
  padding: 6px 8px;
  text-align: left;
}

.article-content th {
  background: var(--bg-card-alt);
  color: var(--text-primary);
  font-weight: 600;
}

.article-content img {
  max-width: 100%;
  height: auto;
  border-radius: var(--radius-sm);
  display: block;
  margin: 12px auto;
  cursor: zoom-in;
}

/* Pinch-to-zoom diagram container */
.diagram-img-container {
  overflow: hidden;
  position: relative;
  touch-action: none;
}

.diagram-img-container img {
  max-width: 100%;
  display: block;
  transform-origin: 0 0;
}

.zoom-controls {
  position: absolute;
  bottom: 10px;
  right: 10px;
  display: flex;
  gap: 4px;
  z-index: 10;
}

.zoom-btn {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  border: 1px solid var(--border);
  background: var(--bg-card);
  color: var(--text-primary);
  font-size: 1.1rem;
  font-weight: 700;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0.85;
  transition: opacity 0.15s, background 0.15s;
  -webkit-tap-highlight-color: transparent;
}

.zoom-btn:hover, .zoom-btn:active {
  opacity: 1;
  background: var(--bg-card-alt);
}

.zoom-reset {
  font-size: 0.9rem;
}

.article-content a {
  color: var(--accent);
}

.article-content dl {
  margin-bottom: 10px;
}

.article-content dd {
  margin-left: 16px;
}

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

.ref-meta {
  font-size: 0.75rem;
  margin-top: 8px;
}

/* ============================================================
   Page containers (DTC, TSB, Browse)
   ============================================================ */

.page-container {
  padding: 16px 12px;
  max-width: 768px;
  margin: 0 auto;
}

.page-header {
  margin-bottom: 16px;
}

.page-title {
  font-size: 1.25rem;
  font-weight: 700;
  color: var(--text-primary);
}

/* Search form */
.search-form {
  margin-bottom: 16px;
}

.search-bar {
  display: flex;
  gap: 8px;
  margin-bottom: 8px;
}

.search-input {
  flex: 1;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 10px 14px;
  color: var(--text-primary);
  font-family: inherit;
  font-size: 0.9375rem;
  outline: none;
  transition: border-color 0.15s;
}

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

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

.search-btn {
  background: var(--accent);
  color: white;
  border: none;
  border-radius: var(--radius-sm);
  padding: 10px 16px;
  font-size: 0.875rem;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
  transition: background 0.15s;
  -webkit-tap-highlight-color: transparent;
}

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

.filter-row {
  display: flex;
  gap: 8px;
}

.system-select {
  flex: 1;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 8px 12px;
  color: var(--text-primary);
  font-family: inherit;
  font-size: 0.875rem;
  outline: none;
  cursor: pointer;
}

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

/* ---- DTC cards ---- */
.dtc-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.dtc-card {
  display: flex;
  align-items: center;
  gap: 12px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px;
  text-decoration: none;
  color: var(--text-primary);
  transition: border-color 0.15s, background 0.15s;
  -webkit-tap-highlight-color: transparent;
}

.dtc-card:hover {
  border-color: var(--accent);
  background: var(--bg-card-alt);
  text-decoration: none;
}

.dtc-card-code {
  font-size: 0.9375rem;
  font-weight: 700;
  color: var(--accent-red);
  min-width: 60px;
  font-family: "SF Mono", Consolas, monospace;
}

.dtc-card-desc {
  font-size: 0.875rem;
  color: var(--text-secondary);
  flex: 1;
}

/* DTC detail */
.dtc-detail {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
}

.dtc-header {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 12px;
}

.dtc-code {
  font-size: 1.75rem;
  font-weight: 700;
  color: var(--accent-red);
  font-family: "SF Mono", Consolas, monospace;
}

.dtc-badge {
  background: rgba(239, 68, 68, 0.15);
  color: var(--accent-red);
  border: 1px solid rgba(239, 68, 68, 0.3);
  padding: 3px 8px;
  border-radius: 6px;
  font-size: 0.75rem;
  font-weight: 600;
}

.dtc-description {
  font-size: 1rem;
  font-weight: 500;
  color: var(--text-primary);
  margin-bottom: 20px;
  line-height: 1.4;
}

.dtc-section {
  margin-bottom: 20px;
}

.section-label {
  font-size: 0.75rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-muted);
  margin-bottom: 8px;
}

.dtc-inline-diagram {
  margin-bottom: 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}

.dtc-diagram-label {
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-muted);
  padding: 6px 10px;
  background: var(--bg);
  border-bottom: 1px solid var(--border);
}

.dtc-inline-diagram .diagram-img-container {
  background: #0d0d1a;
}

.article-content {
  font-size: 0.875rem;
  line-height: 1.6;
  color: var(--text-secondary);
  overflow-x: auto;
}

.article-content img {
  max-width: 100%;
  height: auto;
  border-radius: 4px;
  margin: 8px 0;
}

.article-content table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.8rem;
  margin: 8px 0;
}

.article-content td, .article-content th {
  padding: 6px 8px;
  border: 1px solid var(--border);
}

.dtc-tsb-card {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px;
  margin-bottom: 8px;
  cursor: pointer;
  transition: border-color 0.15s;
}

.dtc-tsb-card:hover {
  border-color: var(--accent);
}

.dtc-tsb-title {
  font-size: 0.875rem;
  font-weight: 500;
  color: var(--text-primary);
  margin-bottom: 4px;
}

.dtc-tsb-desc {
  font-size: 0.8rem;
  color: var(--text-muted);
  line-height: 1.4;
}

.dtc-causes {
  font-size: 0.9rem;
  color: var(--text-secondary);
  line-height: 1.6;
  white-space: pre-wrap;
}

.dtc-causes-list {
  margin: 0;
  padding-left: 1.2em;
  font-size: 0.9rem;
  color: var(--text-secondary);
  line-height: 1.6;
}

.dtc-causes-list li {
  margin-bottom: 4px;
}

.dtc-steps {
  font-size: 0.9rem;
  color: var(--text-secondary);
  line-height: 1.6;
}

.chip-list {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

/* ---- TSB cards ---- */
.tsb-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.tsb-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px;
  cursor: pointer;
  transition: border-color 0.15s, background 0.15s;
  -webkit-tap-highlight-color: transparent;
}

.tsb-card:hover {
  border-color: var(--accent-amber);
  background: var(--bg-card-alt);
}

.tsb-card-header {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 6px;
}

.tsb-bulletin-id {
  font-size: 0.75rem;
  font-weight: 700;
  font-family: "SF Mono", Consolas, monospace;
  color: var(--accent-amber);
  background: rgba(245, 158, 11, 0.1);
  padding: 2px 6px;
  border-radius: 4px;
}

.tsb-system-tag {
  font-size: 0.6875rem;
  color: var(--text-muted);
  background: var(--bg);
  padding: 2px 6px;
  border-radius: 4px;
  border: 1px solid var(--border);
}

.tsb-card-title {
  font-size: 0.9375rem;
  font-weight: 600;
  color: var(--text-primary);
  margin-bottom: 4px;
  line-height: 1.3;
}

.tsb-card-desc {
  font-size: 0.8125rem;
  color: var(--text-secondary);
  line-height: 1.4;
}

/* ---- Browse ---- */
/* ---- Browse: System Grid ---- */
.back-link {
  display: inline-block;
  color: var(--accent);
  font-size: 0.875rem;
  font-weight: 500;
  margin-bottom: 12px;
  text-decoration: none;
}

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

.system-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 10px;
  max-height: calc(100vh - 220px);
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}
@media (max-width: 480px) {
  .system-grid {
    grid-template-columns: 1fr;
    gap: 8px;
  }
  .system-card {
    padding: 14px;
  }
}

.system-card {
  display: flex;
  flex-direction: column;
  justify-content: center;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  text-decoration: none;
  transition: border-color 0.15s, background 0.15s;
  -webkit-tap-highlight-color: transparent;
}

.system-card:hover {
  border-color: var(--accent);
  background: var(--bg-card-alt);
  text-decoration: none;
}

.system-name {
  font-size: 0.875rem;
  font-weight: 600;
  color: var(--text-primary);
  line-height: 1.3;
  margin-bottom: 4px;
}

.system-count {
  font-size: 0.75rem;
  color: var(--text-muted);
}

/* Article list */
.article-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.article-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px;
  cursor: pointer;
  transition: border-color 0.15s;
  -webkit-tap-highlight-color: transparent;
}

.article-card:hover {
  border-color: var(--accent);
}

.article-card-type {
  font-size: 0.6875rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-muted);
  margin-bottom: 4px;
}

.article-card-title {
  font-size: 0.875rem;
  font-weight: 500;
  color: var(--text-primary);
  line-height: 1.3;
  margin-bottom: 4px;
}

.article-card-path {
  font-size: 0.75rem;
  color: var(--text-muted);
}

/* Empty state */
.empty-state {
  text-align: center;
  color: var(--text-muted);
  padding: 40px 20px;
  font-size: 0.9rem;
}

/* ============================================================
   Chat Toolbar (New Chat + History buttons)
   ============================================================ */

.chat-toolbar {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  padding: 8px 12px;
  border-bottom: 1px solid var(--border);
}

.chat-toolbar-btn {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  background: none;
  border: 1px solid var(--border);
  border-radius: 20px;
  color: var(--text-secondary);
  font-family: inherit;
  font-size: 0.75rem;
  font-weight: 500;
  padding: 5px 12px;
  cursor: pointer;
  text-decoration: none;
  transition: background 0.15s, border-color 0.15s, color 0.15s;
  -webkit-tap-highlight-color: transparent;
}

.chat-toolbar-btn:hover {
  background: var(--bg-card);
  border-color: var(--accent);
  color: var(--accent);
  text-decoration: none;
}

/* ============================================================
   History Page
   ============================================================ */

.history-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.history-card {
  display: flex;
  align-items: center;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  transition: border-color 0.15s, background 0.15s;
  -webkit-tap-highlight-color: transparent;
}

.history-card:hover {
  border-color: var(--accent);
  background: var(--bg-card-alt);
}

.history-card-link {
  flex: 1;
  padding: 14px;
  text-decoration: none;
  color: inherit;
  min-width: 0;
}

.history-card-link:hover {
  text-decoration: none;
}

.history-card-preview {
  font-size: 0.9375rem;
  font-weight: 500;
  color: var(--text-primary);
  line-height: 1.3;
  margin-bottom: 6px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.history-card-meta {
  display: flex;
  align-items: center;
  gap: 12px;
  font-size: 0.75rem;
  color: var(--text-muted);
}

.history-card-count {
  background: var(--bg);
  padding: 1px 6px;
  border-radius: 4px;
  border: 1px solid var(--border);
}

.history-delete-btn {
  flex-shrink: 0;
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  padding: 14px 14px;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: color 0.15s, background 0.15s;
  -webkit-tap-highlight-color: transparent;
  border-left: 1px solid var(--border);
}

.history-delete-btn:hover {
  color: var(--accent-red);
  background: rgba(239, 68, 68, 0.08);
}

.history-start-btn {
  display: inline-block;
  margin-top: 16px;
  padding: 10px 20px;
  background: var(--accent);
  color: white;
  border-radius: 20px;
  font-size: 0.875rem;
  font-weight: 600;
  text-decoration: none;
  transition: background 0.15s;
}

.history-start-btn:hover {
  background: var(--accent-dark);
  text-decoration: none;
}

/* ============================================================
   Context Bar — Related items above input
   ============================================================ */

.context-bar {
  position: fixed;
  bottom: calc(var(--nav-height) + 62px);
  left: 0;
  right: 0;
  border-top: 1px solid var(--border);
  padding: 6px 12px;
  background: var(--bg);
  z-index: 90;
}

.context-bar-label {
  font-size: 0.65rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-muted);
  margin-bottom: 4px;
  font-weight: 600;
}

.context-items {
  display: flex;
  gap: 6px;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
  padding-bottom: 2px;
}

.context-items::-webkit-scrollbar {
  display: none;
}

.context-chip {
  display: inline-flex;
  align-items: center;
  gap: 3px;
  flex-shrink: 0;
  min-height: 36px;
  padding: 6px 14px;
  border-radius: 14px;
  border: 1px solid var(--border);
  background: var(--bg-card);
  color: var(--text-secondary);
  font-size: 0.8125rem;
  font-family: inherit;
  cursor: pointer;
  white-space: nowrap;
  transition: border-color 0.15s, background 0.15s;
  -webkit-tap-highlight-color: transparent;
}

.context-chip:hover,
.context-chip:active {
  border-color: var(--accent);
  background: var(--bg-card-alt);
  color: var(--text-primary);
}

.context-chip-dtc {
  border-color: rgba(239, 68, 68, 0.3);
}

.context-chip-diagram {
  border-color: rgba(59, 130, 246, 0.3);
}

.context-chip-tsb {
  border-color: rgba(234, 179, 8, 0.3);
}

/* ---- Diagram grid (DTC detail) ---- */
.diagram-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(120px, 1fr));
  gap: 8px;
}
.diagram-thumb {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 6px;
  overflow: hidden;
  cursor: pointer;
}
.diagram-thumb img {
  width: 100%;
  height: 80px;
  object-fit: cover;
}
.diagram-thumb-label {
  display: block;
  font-size: 0.7rem;
  padding: 4px 6px;
  color: var(--text-muted);
  text-align: center;
}

/* ---- Broken image fallback ---- */
img[src^="/diagrams/"], img[src^="/content-images/"] {
    min-height: 40px;
    background: #f0f0f5;
    border-radius: 8px;
}

.img-unavailable {
    padding: 12px 16px;
    background: #2a2a3d;
    border-radius: 8px;
    color: #9090b0;
    font-size: 0.85rem;
    text-align: center;
    margin: 8px 0;
}

/* ============================================================
   Tablet / Desktop
   ============================================================ */

@media (min-width: 768px) {
  .message-bubble {
    max-width: 70%;
  }

  .chat-messages {
    padding: 24px;
    max-width: 800px;
    margin: 0 auto;
    padding-bottom: 90px;
  }

  .chat-input-bar {
    left: 50%;
    transform: translateX(-50%);
    width: 100%;
    max-width: 800px;
  }

  .context-bar {
    left: 50%;
    transform: translateX(-50%);
    width: 100%;
    max-width: 800px;
  }

  .bottom-sheet {
    max-width: 640px;
    left: 50%;
    transform: translateX(-50%) translateY(100%);
    border-radius: var(--sheet-radius) var(--sheet-radius) 0 0;
  }

  .bottom-sheet.open {
    transform: translateX(-50%) translateY(0);
  }

  .page-container {
    padding: 24px;
  }
}

/* ---- TSB PDF Embed ---- */
.tsb-pdf-embed {
    margin: 8px 0;
    border-radius: 8px;
    overflow: hidden;
}
.tsb-pdf-embed embed {
    border: none;
    border-radius: 8px;
    min-height: 600px;
}
.tsb-pdf-embed a {
    display: block;
    text-align: center;
    padding: 16px;
    color: #fff;
    background: #3060d0;
    border-radius: 8px;
    font-weight: 600;
    text-decoration: none;
    margin-top: 8px;
}
.tsb-pdf-embed a:active {
    background: #2050b0;
}
@media (max-width: 768px) {
    .tsb-pdf-embed embed {
        display: none;
    }
    .tsb-pdf-embed a {
        font-size: 1.1rem;
        padding: 20px;
    }
}

/* ============================================================
   Search Page
   ============================================================ */

.search-input-lg {
  font-size: 1.0625rem;
  padding: 12px 16px;
}

.search-results-section {
  margin-bottom: 24px;
}

.search-section-header {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 10px;
}

.search-section-title {
  font-size: 1rem;
  font-weight: 700;
  color: var(--text-primary);
}

.search-count-badge {
  font-size: 0.75rem;
  font-weight: 700;
  padding: 2px 8px;
  border-radius: 10px;
  line-height: 1.4;
}

.search-count-red {
  background: rgba(239, 68, 68, 0.15);
  color: var(--accent-red);
}

.search-count-amber {
  background: rgba(245, 158, 11, 0.15);
  color: var(--accent-amber);
}

.search-count-blue {
  background: rgba(79, 142, 247, 0.15);
  color: var(--accent);
}

.search-cards-grid {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.search-diagram-card {
  border-left: 3px solid var(--accent-amber);
}

/* ============================================================
   Reference Page — Collapsible Sections
   ============================================================ */

.ref-section {
  margin-bottom: 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}

.ref-section-header {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 14px 16px;
  background: var(--bg-card);
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
  transition: background 0.15s;
}

.ref-section-header:hover {
  background: var(--bg-card-alt);
}

.ref-section-arrow {
  font-size: 0.7rem;
  color: var(--text-muted);
  transition: transform 0.2s ease;
  display: inline-block;
  flex-shrink: 0;
}

.ref-section.open .ref-section-arrow {
  transform: rotate(90deg);
}

.ref-section-title {
  font-size: 0.9375rem;
  font-weight: 600;
  color: var(--text-primary);
  flex: 1;
}

.ref-section-count {
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--text-muted);
  background: var(--bg);
  padding: 2px 8px;
  border-radius: 10px;
  border: 1px solid var(--border);
  flex-shrink: 0;
}

.ref-section-body {
  display: none;
  padding: 8px 12px 12px;
  background: var(--bg);
}

.ref-section.open .ref-section-body {
  display: block;
}

/* Compact article card variant (title only, less padding) */
.article-card--compact {
  padding: 10px 12px;
}

.article-card--compact .article-card-title {
  margin-bottom: 0;
}

/* ============================================================
   Diagram Browser Page
   ============================================================ */

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

.diagram-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px;
  cursor: pointer;
  transition: border-color 0.15s, background 0.15s;
  -webkit-tap-highlight-color: transparent;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.diagram-card:hover {
  border-color: var(--accent);
  background: var(--bg-card-alt);
}

.diagram-card-title {
  font-size: 0.875rem;
  font-weight: 600;
  color: var(--text-primary);
  line-height: 1.3;
  word-break: break-word;
}

.diagram-card-path {
  font-size: 0.6875rem;
  color: var(--text-muted);
  line-height: 1.3;
}

.diagram-type-badge {
  display: inline-block;
  align-self: flex-start;
  padding: 2px 8px;
  border-radius: 4px;
  font-size: 0.6875rem;
  font-weight: 600;
  white-space: nowrap;
}

/* Color variants for diagram type badges */
.diagram-type-badge.diagram-type-system-schematic {
  background: rgba(79, 142, 247, 0.15);
  color: var(--accent);
  border: 1px solid rgba(79, 142, 247, 0.3);
}

.diagram-type-badge.diagram-type-connector-wire-view {
  background: rgba(34, 197, 94, 0.15);
  color: var(--accent-green);
  border: 1px solid rgba(34, 197, 94, 0.3);
}

.diagram-type-badge.diagram-type-location-view {
  background: rgba(245, 158, 11, 0.15);
  color: var(--accent-amber);
  border: 1px solid rgba(245, 158, 11, 0.3);
}

/* Default badge color for other diagram types */
.diagram-type-badge {
  background: rgba(144, 144, 176, 0.15);
  color: var(--text-secondary);
  border: 1px solid rgba(144, 144, 176, 0.3);
}

/* Override default with specific types (repeat for specificity) */
.diagram-type-system-schematic {
  background: rgba(79, 142, 247, 0.15);
  color: var(--accent);
  border: 1px solid rgba(79, 142, 247, 0.3);
}

.diagram-type-connector-wire-view {
  background: rgba(34, 197, 94, 0.15);
  color: var(--accent-green);
  border: 1px solid rgba(34, 197, 94, 0.3);
}

.diagram-type-location-view {
  background: rgba(245, 158, 11, 0.15);
  color: var(--accent-amber);
  border: 1px solid rgba(245, 158, 11, 0.3);
}

/* Responsive: 3+ cols on tablet, 4 on desktop */
@media (min-width: 600px) {
  .diagram-grid {
    grid-template-columns: repeat(3, 1fr);
  }
}

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