/** ===== CSS Variables (Krita Dark Orange + accent) ===== **/
:root {
  --bg-primary: #1f1f1f;        /* Window BackgroundNormal */
  --bg-secondary: #242424;        /* Window BackgroundAlternate */
  --bg-content: #202020;         /* View BackgroundNormal */
  --bg-content-alt: #292929;
  --bg-hover: #2a2a2a;
  --bg-active: #2f2f2f;
  --bg-code: #1a1a1a;

  --text-primary: #efefef;       /* ForegroundNormal */
  --text-secondary: #b0b0b0;     /* Muted */
  --text-tertiary: #7a7a7a;
  --text-inactive: #808080;      /* ForegroundInactive */

  --accent-primary: #B24C48;     /* User accent - terracotta red */
  --accent-primary-hover: #c95a56;
  --accent-primary-dim: #8a3a37;
  --accent-secondary: #FF9A00;   /* Orange from Krita */
  --accent-gold: #B4711F;         /* Golden brown */

  --border-color: #333333;
  --border-light: #3a3a3a;
  --shadow-color: rgba(0,0,0,0.4);

  --sidebar-width: 300px;
  --header-height: 56px;
  --radius: 10px;
  --radius-sm: 6px;
  --transition: 0.2s ease;
}

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

html {
  font-size: 16px;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  scroll-behavior: smooth;
  -webkit-text-size-adjust: 100%;
}

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

/** ===== App Layout ===== **/
#app {
  display: flex;
  min-height: 100vh;
}

/** ===== Mobile Header ===== **/
.mobile-header {
  display: none;
  position: fixed;
  top: 0; left: 0; right: 0;
  height: var(--header-height);
  background: var(--bg-secondary);
  border-bottom: 1px solid var(--border-color);
  z-index: 100;
  align-items: center;
  padding: 0 16px;
  justify-content: space-between;
}

.menu-toggle {
  display: flex;
  flex-direction: column;
  gap: 5px;
  background: none;
  border: none;
  cursor: pointer;
  padding: 8px;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}
.menu-toggle span {
  display: block;
  width: 22px;
  height: 2px;
  background: var(--text-primary);
  border-radius: 1px;
  transition: var(--transition);
}
.menu-toggle.active span:nth-child(1) { transform: translateY(7px) rotate(45deg); }
.menu-toggle.active span:nth-child(2) { opacity: 0; }
.menu-toggle.active span:nth-child(3) { transform: translateY(-7px) rotate(-45deg); }

.site-title {
  font-size: 1.1rem;
  font-weight: 600;
  color: var(--text-primary);
  letter-spacing: -0.3px;
}
.header-spacer { width: 38px; }

.mobile-search-toggle {
  display: none;
  background: none;
  border: none;
  color: var(--text-primary);
  padding: 8px;
  cursor: pointer;
  border-radius: var(--radius-sm);
  transition: background var(--transition);
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}
.mobile-search-toggle:hover { background: var(--bg-hover); }

/** ===== Mobile Search Overlay ===== **/
.mobile-search-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: var(--bg-primary);
  z-index: 150;
  flex-direction: column;
  padding-top: env(safe-area-inset-top, 0);
  padding-bottom: env(safe-area-inset-bottom, 0);
}
.mobile-search-overlay.show {
  display: flex;
  animation: fadeIn 0.15s ease;
}
.mobile-search-header {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 14px;
  border-bottom: 1px solid var(--border-color);
  background: var(--bg-secondary);
  flex-shrink: 0;
}
.mobile-search-box {
  position: relative;
  flex: 1;
  display: flex;
  align-items: center;
}
.mobile-search-icon {
  position: absolute;
  left: 12px;
  color: var(--text-tertiary);
  pointer-events: none;
}
#mobileSearchInput {
  width: 100%;
  background: var(--bg-content);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  padding: 12px 12px 12px 40px;
  color: var(--text-primary);
  font-size: 1rem;
  font-family: inherit;
  outline: none;
  transition: border-color var(--transition), box-shadow var(--transition);
}
#mobileSearchInput::placeholder { color: var(--text-tertiary); }
#mobileSearchInput:focus {
  border-color: var(--accent-primary);
  box-shadow: 0 0 0 3px rgba(178,76,72,0.15);
}
.mobile-search-cancel {
  background: none;
  border: none;
  color: var(--text-secondary);
  font-size: 0.95rem;
  padding: 8px 4px;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}
.mobile-search-cancel:active { color: var(--text-primary); }

.mobile-search-results {
  flex: 1;
  overflow-y: auto;
  padding: 8px 0;
  -webkit-overflow-scrolling: touch;
}
.mobile-search-results::-webkit-scrollbar { width: 6px; }
.mobile-search-results::-webkit-scrollbar-thumb { background: var(--border-light); border-radius: 3px; }
.mobile-search-hint {
  padding: 24px 20px;
  text-align: center;
  color: var(--text-tertiary);
  font-size: 0.9rem;
}

.mobile-search-empty {
  padding: 24px 20px;
  text-align: center;
  color: var(--text-tertiary);
  font-size: 0.95rem;
}

.mobile-search-result-item {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  padding: 12px 16px;
  cursor: pointer;
  transition: background var(--transition);
  border-bottom: 1px solid var(--border-color);
  -webkit-tap-highlight-color: transparent;
}
.mobile-search-result-item:last-child { border-bottom: none; }
.mobile-search-result-item:hover,
.mobile-search-result-item.active { background: rgba(178,76,72,0.12); }
.mobile-search-result-item.active .mobile-search-result-number { color: var(--accent-primary); }
.mobile-search-result-number {
  font-family: 'JetBrains Mono', monospace;
  font-size: 0.85rem;
  font-weight: 500;
  color: var(--text-tertiary);
  min-width: 34px;
  margin-top: 2px;
}
.mobile-search-result-info { flex: 1; min-width: 0; }
.mobile-search-result-title {
  font-size: 0.95rem;
  line-height: 1.35;
  color: var(--text-primary);
  margin-bottom: 4px;
  word-wrap: break-word;
}
.mobile-search-result-meta {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 0.75rem;
  color: var(--text-tertiary);
}

/** ===== Sidebar ===== **/
.sidebar {
  width: var(--sidebar-width);
  background: var(--bg-secondary);
  border-right: 1px solid var(--border-color);
  display: flex;
  flex-direction: column;
  position: fixed;
  top: 0; left: 0; bottom: 0;
  z-index: 90;
  transition: transform var(--transition);
}

.sidebar-header {
  padding: 20px 20px 12px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-bottom: 1px solid var(--border-color);
}
.sidebar-title {
  font-size: 1.15rem;
  font-weight: 600;
  color: var(--text-primary);
}
.ticket-count {
  background: var(--accent-primary);
  color: #fff;
  font-size: 0.75rem;
  font-weight: 600;
  padding: 2px 8px;
  border-radius: 12px;
}

.search-box {
  position: relative;
  padding: 12px 16px;
}
.search-box input {
  width: 100%;
  background: var(--bg-content);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  padding: 10px 36px 10px 12px;
  color: var(--text-primary);
  font-size: 0.9rem;
  font-family: inherit;
  outline: none;
  transition: border-color var(--transition), box-shadow var(--transition);
}
.search-box input::placeholder { color: var(--text-tertiary); }
.search-box input:focus {
  border-color: var(--accent-primary);
  box-shadow: 0 0 0 3px rgba(178,76,72,0.15);
}
.search-icon {
  position: absolute;
  right: 26px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--text-tertiary);
  pointer-events: none;
}

.complexity-filter {
  padding: 0 16px 12px;
  border-bottom: 1px solid var(--border-color);
}
.filter-label {
  display: block;
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--text-tertiary);
  margin-bottom: 8px;
}
.filter-buttons {
  display: flex;
  gap: 6px;
}
.filter-buttons button {
  width: 32px;
  height: 32px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-color);
  background: var(--bg-content);
  color: var(--text-secondary);
  font-size: 0.8rem;
  font-weight: 600;
  cursor: pointer;
  transition: var(--transition);
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}
.filter-buttons button:hover {
  border-color: var(--accent-primary);
  color: var(--text-primary);
}
.filter-buttons button.active {
  background: var(--accent-primary);
  border-color: var(--accent-primary);
  color: #fff;
}

.ticket-list {
  flex: 1;
  overflow-y: auto;
  padding: 8px 12px;
  -webkit-overflow-scrolling: touch;
}
.ticket-list::-webkit-scrollbar { width: 6px; }
.ticket-list::-webkit-scrollbar-track { background: transparent; }
.ticket-list::-webkit-scrollbar-thumb { background: var(--border-light); border-radius: 3px; }

.ticket-item {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: background var(--transition);
  margin-bottom: 4px;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}
.ticket-item:hover { background: var(--bg-hover); }
.ticket-item.active {
  background: rgba(178,76,72,0.12);
  border-left: 3px solid var(--accent-primary);
  padding-left: 9px;
}
.ticket-item.active .item-number { color: var(--accent-primary); }

.item-number {
  font-family: 'JetBrains Mono', monospace;
  font-size: 0.8rem;
  font-weight: 500;
  color: var(--text-tertiary);
  min-width: 28px;
  margin-top: 2px;
}
.item-info { flex: 1; min-width: 0; }
.item-title {
  font-size: 0.85rem;
  line-height: 1.4;
  color: var(--text-primary);
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}
.item-meta {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-top: 4px;
}
.complexity-dots {
  display: flex;
  gap: 3px;
}
.complexity-dots span {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--border-light);
  transition: background var(--transition);
}
.complexity-dots span.filled {
  background: var(--accent-primary);
  box-shadow: 0 0 4px rgba(178,76,72,0.4);
}
.item-source-count {
  font-size: 0.7rem;
  color: var(--text-tertiary);
}

/** ===== Main Content ===== **/
.main-content {
  flex: 1;
  margin-left: var(--sidebar-width);
  min-height: 100vh;
  min-width: 0;
}

.content-wrapper {
  max-width: 860px;
  margin: 0 auto;
  padding: 40px 48px;
  min-width: 0;
  overflow-x: hidden;
}

/** ===== Welcome Screen ===== **/
.welcome-screen {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 70vh;
  text-align: center;
}
.welcome-inner { max-width: 500px; }
.welcome-screen h1 {
  font-size: 2.4rem;
  font-weight: 700;
  margin-bottom: 12px;
  letter-spacing: -1px;
  color: var(--text-primary);
}
.welcome-subtitle {
  font-size: 1.1rem;
  color: var(--text-secondary);
  margin-bottom: 28px;
}
.complexity-legend {
  display: flex;
  flex-direction: column;
  gap: 8px;
  align-items: center;
  margin-bottom: 28px;
}
.legend-item {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 0.9rem;
  color: var(--text-secondary);
}
.legend-bar {
  display: inline-flex;
  gap: 2px;
}
.legend-bar span {
  display: block;
  width: 8px;
  height: 8px;
  border-radius: 1px;
  background: var(--border-light);
}
.legend-bar span.filled {
  background: var(--accent-primary);
}
.welcome-hint {
  font-size: 0.85rem;
  color: var(--text-tertiary);
}

/** ===== Ticket View ===== **/
.ticket-view { animation: fadeIn 0.3s ease; }
@keyframes fadeIn { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: translateY(0); } }

.ticket-header {
  margin-bottom: 32px;
  padding-bottom: 20px;
  border-bottom: 1px solid var(--border-color);
}
.ticket-meta {
  display: flex;
  align-items: center;
  gap: 16px;
  margin-bottom: 12px;
}
.ticket-number {
  font-family: 'JetBrains Mono', monospace;
  font-size: 0.85rem;
  font-weight: 500;
  color: var(--text-tertiary);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.complexity-indicator {
  display: flex;
  align-items: center;
  gap: 4px;
}
.complexity-bar {
  width: 28px;
  height: 6px;
  border-radius: 3px;
  background: var(--border-light);
  transition: background var(--transition);
}
.complexity-bar.filled {
  background: var(--accent-primary);
  box-shadow: 0 0 6px rgba(178,76,72,0.35);
}
.complexity-label {
  font-size: 0.75rem;
  color: var(--text-tertiary);
  margin-left: 6px;
}

.ticket-title {
  font-size: 1.7rem;
  font-weight: 700;
  line-height: 1.3;
  color: var(--text-primary);
  letter-spacing: -0.5px;
  margin-bottom: 16px;
}

.ticket-actions {
  display: flex;
  gap: 10px;
  align-items: center;
}
.ticket-actions button {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 16px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-color);
  background: var(--bg-content);
  color: var(--text-secondary);
  font-size: 0.85rem;
  font-family: inherit;
  cursor: pointer;
  transition: var(--transition);
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}
.ticket-actions button:hover {
  border-color: var(--accent-primary);
  color: var(--text-primary);
  background: var(--bg-hover);
}
.btn-sources {
  background: var(--accent-primary) !important;
  border-color: var(--accent-primary) !important;
  color: #fff !important;
  font-weight: 500;
}
.btn-sources:hover {
  background: var(--accent-primary-hover) !important;
  border-color: var(--accent-primary-hover) !important;
}
.btn-prev, .btn-next {
  padding: 8px 14px !important;
  font-weight: 600;
}

/** ===== Markdown Body ===== **/
.markdown-body {
  font-size: 1rem;
  line-height: 1.75;
  color: var(--text-primary);
  word-wrap: break-word;
}

.markdown-body h1,
.markdown-body h2,
.markdown-body h3,
.markdown-body h4 {
  font-weight: 600;
  color: var(--text-primary);
  margin-top: 1.8em;
  margin-bottom: 0.7em;
  line-height: 1.3;
}
.markdown-body h1 { font-size: 1.5rem; border-bottom: 1px solid var(--border-color); padding-bottom: 0.3em; margin-top: 0; }
.markdown-body h2 { font-size: 1.25rem; color: var(--accent-secondary); }
.markdown-body h3 { font-size: 1.1rem; color: var(--text-secondary); }
.markdown-body h4 { font-size: 1rem; }

.markdown-body p { margin-bottom: 1em; }
.markdown-body strong { color: var(--accent-secondary); font-weight: 600; }
.markdown-body em { color: var(--text-secondary); font-style: italic; }

.markdown-body blockquote {
  margin: 1.2em 0;
  padding: 12px 16px;
  border-left: 3px solid var(--accent-primary);
  background: var(--bg-content);
  border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
  color: var(--text-secondary);
}
.markdown-body blockquote p:last-child { margin-bottom: 0; }

.markdown-body ul, .markdown-body ol {
  margin: 1em 0;
  padding-left: 1.5em;
}
.markdown-body li { margin-bottom: 0.4em; }
.markdown-body li > ul, .markdown-body li > ol { margin: 0.3em 0; }

/* Interactive checklists */
.markdown-body ul:has(li input[type="checkbox"]) {
  list-style: none;
  padding-left: 0.2em;
}
.markdown-body li:has(input[type="checkbox"]) {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  margin-bottom: 0.6em;
}
.markdown-body li input[type="checkbox"] {
  appearance: none;
  width: 18px;
  height: 18px;
  border: 2px solid var(--border-light);
  border-radius: 4px;
  background: var(--bg-content);
  cursor: pointer;
  margin-top: 3px;
  flex-shrink: 0;
  transition: var(--transition);
  position: relative;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}
.markdown-body li input[type="checkbox"]:hover {
  border-color: var(--accent-primary);
}
.markdown-body li input[type="checkbox"]:checked {
  background: var(--accent-primary);
  border-color: var(--accent-primary);
}
.markdown-body li input[type="checkbox"]:checked::after {
  content: '';
  position: absolute;
  left: 5px;
  top: 1px;
  width: 5px;
  height: 10px;
  border: solid #fff;
  border-width: 0 2px 2px 0;
  transform: rotate(45deg);
}
.markdown-body li.checked-text {
  opacity: 0.55;
  text-decoration: line-through;
  text-decoration-color: var(--accent-primary);
  text-decoration-thickness: 1px;
}

/* Tables */
.markdown-body table {
  width: 100%;
  border-collapse: collapse;
  margin: 1.2em 0;
  font-size: 0.9rem;
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  overflow: hidden;
  max-width: 100%;
  display: block;
  overflow-x: auto;
}
.markdown-body th {
  background: var(--bg-content-alt);
  color: var(--accent-secondary);
  font-weight: 600;
  text-align: left;
  padding: 10px 14px;
  border-bottom: 2px solid var(--border-light);
}
.markdown-body td {
  padding: 8px 14px;
  border-bottom: 1px solid var(--border-color);
  color: var(--text-primary);
}
.markdown-body tr:last-child td { border-bottom: none; }
.markdown-body tr:nth-child(even) { background: rgba(255,255,255,0.02); }
.markdown-body tr:hover { background: rgba(178,76,72,0.04); }

/* Code */
.markdown-body code {
  font-family: 'JetBrains Mono', monospace;
  font-size: 0.85em;
  background: var(--bg-code);
  color: var(--accent-secondary);
  padding: 2px 6px;
  border-radius: 4px;
  border: 1px solid var(--border-color);
  word-break: break-word;
  overflow-wrap: break-word;
  white-space: pre-wrap;
}
.markdown-body pre {
  background: var(--bg-code);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  padding: 16px;
  overflow-x: auto;
  margin: 1.2em 0;
  max-width: 100%;
}
.markdown-body pre code {
  background: none;
  border: none;
  padding: 0;
  color: var(--text-primary);
  font-size: 0.85rem;
  line-height: 1.6;
  white-space: pre;
  word-break: normal;
}
.markdown-body pre::-webkit-scrollbar { height: 6px; }
.markdown-body pre::-webkit-scrollbar-thumb { background: var(--border-light); border-radius: 3px; }

/* KaTeX integration */
.katex { font-size: 1.08em; }
.katex-display {
  margin: 1.2em 0;
  overflow-x: auto;
  padding: 8px 0;
}
.katex-display::-webkit-scrollbar { height: 4px; }
.katex-display::-webkit-scrollbar-thumb { background: var(--border-light); border-radius: 2px; }

/* HR */
.markdown-body hr {
  border: none;
  height: 1px;
  background: var(--border-color);
  margin: 2em 0;
}

/* Images inside markdown */
.markdown-body img {
  max-width: 100%;
  border-radius: var(--radius-sm);
  margin: 1em 0;
}

/* Checklist progress bar */
.checklist-progress {
  margin: 12px 0 20px;
  padding: 12px 16px;
  background: var(--bg-content);
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-color);
}
.checklist-progress-label {
  display: flex;
  justify-content: space-between;
  font-size: 0.85rem;
  color: var(--text-secondary);
  margin-bottom: 8px;
}
.checklist-progress-bar {
  width: 100%;
  height: 6px;
  background: var(--bg-code);
  border-radius: 3px;
  overflow: hidden;
}
.checklist-progress-fill {
  height: 100%;
  background: linear-gradient(90deg, var(--accent-primary), var(--accent-secondary));
  border-radius: 3px;
  transition: width 0.4s ease;
}

/** ===== Modal (Sources) ===== **/
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.75);
  backdrop-filter: blur(4px);
  z-index: 200;
  display: none;
  align-items: center;
  justify-content: center;
  padding: 20px;
  opacity: 0;
  transition: opacity 0.25s ease;
}
.modal-overlay.show {
  display: flex;
  opacity: 1;
}
.modal {
  background: var(--bg-secondary);
  border: 1px solid var(--border-color);
  border-radius: var(--radius);
  width: 100%;
  max-width: 700px;
  max-height: 85vh;
  display: flex;
  flex-direction: column;
  box-shadow: 0 20px 60px var(--shadow-color);
  transform: translateY(12px);
  transition: transform 0.25s ease;
}
.modal-overlay.show .modal { transform: translateY(0); }

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 20px;
  border-bottom: 1px solid var(--border-color);
}
.modal-header h3 {
  font-size: 1.1rem;
  font-weight: 600;
  color: var(--text-primary);
}
.modal-close {
  background: none;
  border: none;
  color: var(--text-tertiary);
  cursor: pointer;
  padding: 4px;
  border-radius: 6px;
  transition: var(--transition);
  display: flex;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}
.modal-close:hover {
  color: var(--text-primary);
  background: var(--bg-hover);
}

.modal-body {
  padding: 20px;
  overflow-y: auto;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
  gap: 16px;
}
.modal-body::-webkit-scrollbar { width: 6px; }
.modal-body::-webkit-scrollbar-thumb { background: var(--border-light); border-radius: 3px; }

.scan-thumb {
  cursor: pointer;
  border-radius: var(--radius-sm);
  overflow: hidden;
  border: 2px solid var(--border-color);
  transition: var(--transition);
  background: var(--bg-content);
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}
.scan-thumb:hover {
  border-color: var(--accent-primary);
  transform: translateY(-2px);
  box-shadow: 0 8px 20px rgba(0,0,0,0.3);
}
.scan-thumb img {
  width: 100%;
  height: 160px;
  object-fit: cover;
  object-position: top;
  display: block;
}
.scan-thumb-caption {
  padding: 8px;
  font-size: 0.75rem;
  color: var(--text-tertiary);
  text-align: center;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/** ===== Lightbox ===== **/
.lightbox {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.92);
  z-index: 300;
  display: none;
  align-items: center;
  justify-content: center;
  flex-direction: column;
  padding: 40px 20px;
  opacity: 0;
  transition: opacity 0.3s ease;
}
.lightbox.show {
  display: flex;
  opacity: 1;
}
.lightbox img {
  max-width: 100%;
  max-width: 100vw;
  max-height: calc(100vh - 120px);
  object-fit: contain;
  border-radius: var(--radius-sm);
  box-shadow: 0 10px 40px rgba(0,0,0,0.5);
  transition: opacity 0.2s ease, transform 0.2s ease;
}
.lightbox img.swipe-out-left { opacity: 0; transform: translateX(-30px); }
.lightbox img.swipe-out-right { opacity: 0; transform: translateX(30px); }

.lightbox-close,
.lightbox-nav {
  position: absolute;
  background: rgba(255,255,255,0.12);
  border: none;
  color: #fff;
  width: 48px;
  height: 48px;
  border-radius: 50%;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: var(--transition);
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}
.lightbox-close:hover,
.lightbox-nav:hover { background: rgba(255,255,255,0.25); }
.lightbox-close { top: 20px; right: 20px; z-index: 301; }
.lightbox-prev { top: 50%; left: 20px; transform: translateY(-50%); z-index: 301; }
.lightbox-next { top: 50%; right: 20px; transform: translateY(-50%); z-index: 301; }

.lightbox-nav:disabled { opacity: 0; pointer-events: none; }

.lightbox-caption {
  margin-top: 16px;
  color: rgba(255,255,255,0.7);
  font-size: 0.9rem;
  max-width: 80%;
  text-align: center;
}

/** ===== Mobile First Responsive ===== **/
@media (max-width: 768px) {
  :root { --sidebar-width: 100vw; }

  .mobile-header { display: flex; }
  .mobile-search-toggle { display: flex; }

  .sidebar {
    transform: translateX(-100%);
    width: 85vw;
    max-width: 320px;
    top: var(--header-height);
    bottom: 0;
    border-right: none;
    box-shadow: 4px 0 20px rgba(0,0,0,0.5);
    border-radius: 0 var(--radius) var(--radius) 0;
    background: var(--bg-secondary);
    padding-bottom: env(safe-area-inset-bottom, 0);
  }
  .sidebar.open { transform: translateX(0); }

  .sidebar-backdrop {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.5);
    z-index: 89;
    opacity: 0;
    transition: opacity 0.25s ease;
  }
  .sidebar-backdrop.show { display: block; opacity: 1; }

  .main-content {
    margin-left: 0;
    padding-top: var(--header-height);
  }
  .content-wrapper {
    padding: 20px 18px;
    max-width: 100%;
    min-width: 0;
    overflow-x: hidden;
  }

  .welcome-screen { min-height: calc(70vh - var(--header-height)); }
  .welcome-screen h1 { font-size: 1.8rem; }
  .welcome-subtitle { font-size: 1rem; }

  .ticket-title { font-size: 1.35rem; word-wrap: break-word; }
  .ticket-actions {
    flex-wrap: wrap;
    gap: 8px;
  }
  .ticket-actions button {
    padding: 10px 14px;
    min-height: 40px;
    font-size: 0.9rem;
  }
  .btn-prev, .btn-next {
    flex: 1;
    justify-content: center;
    min-width: 60px;
  }
  .btn-sources { width: 100%; justify-content: center; order: -1; }

  .markdown-body { font-size: 0.95rem; word-wrap: break-word; overflow-wrap: break-word; }
  .markdown-body pre,
  .markdown-body table,
  .markdown-body .katex-display {
    max-width: 100%;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
  }
  .markdown-body table { font-size: 0.8rem; display: block; width: 100%; }
  .markdown-body th, .markdown-body td { padding: 6px 8px; white-space: nowrap; }
  .markdown-body img { max-width: 100%; height: auto; }
  .markdown-body code { word-break: break-word; }
  .katex { font-size: 0.95em; }

  .modal {
    max-height: 90vh;
    border-radius: var(--radius) var(--radius) 0 0;
    max-width: 100%;
  }
  .modal-overlay { align-items: flex-end; padding: 0; }

  .modal-body {
    grid-template-columns: repeat(2, 1fr);
    gap: 12px;
    padding: 16px;
  }
  .scan-thumb img { height: 120px; }

  .lightbox { padding: 20px 12px; }
  .lightbox img { max-height: calc(100vh - 110px); max-width: 100%; }
  .lightbox-close { top: 12px; right: 12px; width: 42px; height: 42px; }
  .lightbox-prev { left: 8px; width: 42px; height: 42px; }
  .lightbox-next { right: 8px; width: 42px; height: 42px; }
}

@media (max-width: 480px) {
  :root { --header-height: 52px; }

  .mobile-header { padding: 0 12px; }
  .site-title { font-size: 1rem; }

  .content-wrapper { padding: 16px 10px; }
  .welcome-screen h1 { font-size: 1.55rem; }
  .welcome-subtitle { font-size: 0.95rem; }

  .ticket-title { font-size: 1.2rem; }
  .ticket-meta { flex-wrap: wrap; gap: 8px; }
  .complexity-bar { width: 24px; height: 5px; }

  .modal-body { grid-template-columns: repeat(2, 1fr); gap: 10px; }
  .scan-thumb img { height: 100px; }
  .scan-thumb-caption { font-size: 0.7rem; }

  .lightbox { padding: 16px 8px; }
  .lightbox img { max-height: calc(100vh - 100px); }
  .lightbox-close { top: 10px; right: 10px; width: 40px; height: 40px; }
  .lightbox-prev { left: 4px; width: 38px; height: 38px; }
  .lightbox-next { right: 4px; width: 38px; height: 38px; }

  .markdown-body pre { padding: 12px; font-size: 0.8rem; }
  .markdown-body table { font-size: 0.75rem; }
}

/** ===== Touch & accessibility helpers ===== **/
button, .ticket-item, .scan-thumb {
  touch-action: manipulation;
}

/* Reduce motion if requested */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
    scroll-behavior: auto !important;
  }
}
