/* ── Theme variables ─────────────────────────────────────────── */
:root {
  --bg: #f0ede8;
  --surface: #ffffff;
  --surface-2: #e8e4de;
  --border: #ccc8c0;
  --border-dark: #b0aba1;
  --text: #1a1916;
  --text-muted: #4a4740;
  --text-faint: #7a7670;
  --accent: #1a1916;
  --accent-hover: #333028;
  --tag-bg: #dedad3;
  --tag-text: #3a3830;
  --shadow-sm: 0 1px 3px rgba(0,0,0,0.08);
  --shadow-md: 0 4px 16px rgba(0,0,0,0.10);
  --shadow-lg: 0 12px 40px rgba(0,0,0,0.16);
  --radius: 4px;
  --radius-lg: 8px;
}

[data-theme="dark"] {
  --bg: #141412;
  --surface: #1e1d1a;
  --surface-2: #272521;
  --border: #3a3830;
  --border-dark: #4e4b42;
  --text: #f0ede8;
  --text-muted: #b0aba1;
  --text-faint: #7a7670;
  --accent: #f0ede8;
  --accent-hover: #d8d4cc;
  --tag-bg: #2e2c28;
  --tag-text: #c8c4bb;
  --shadow-sm: 0 1px 3px rgba(0,0,0,0.3);
  --shadow-md: 0 4px 16px rgba(0,0,0,0.4);
  --shadow-lg: 0 12px 40px rgba(0,0,0,0.5);
}

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

/* Lock the viewport so the keyboard never resizes or zooms the layout */
html {
  overflow-x: hidden;
}

body {
  font-family: 'DM Mono', monospace;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  transition: background 0.2s, color 0.2s;
  /* Prevent horizontal scroll only — vertical scroll must remain free */
  overflow-x: hidden;
}

/* ── Header ──────────────────────────────────────────────────── */
header {
  padding: 32px 40px 0;
  max-width: 960px;
  width: 100%;
  margin: 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

.wordmark {
  font-family: 'Syne', sans-serif;
  font-weight: 800;
  font-size: 13px;
  letter-spacing: 0.2em;
  text-transform: uppercase;
  color: var(--text-muted);
}

/* ── Theme toggle ────────────────────────────────────────────── */
.theme-toggle {
  width: 36px;
  height: 36px;
  border: 1.5px solid var(--border-dark);
  border-radius: var(--radius);
  background: var(--surface);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-muted);
  transition: all 0.15s;
  flex-shrink: 0;
  position: relative;
  overflow: hidden;
}

.theme-toggle:hover {
  border-color: var(--accent);
  color: var(--accent);
}

.theme-toggle svg {
  width: 16px;
  height: 16px;
  stroke: currentColor;
  fill: none;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
  position: absolute;
  transition: opacity 0.15s, transform 0.2s;
}

/* Show/hide sun vs moon based on theme */
.icon-sun  { opacity: 0; transform: rotate(90deg) scale(0.7); pointer-events: none; }
.icon-moon { opacity: 1; transform: rotate(0deg) scale(1); }
[data-theme="dark"] .icon-sun  { opacity: 1; transform: rotate(0deg) scale(1); }
[data-theme="dark"] .icon-moon { opacity: 0; transform: rotate(-90deg) scale(0.7); pointer-events: none; }

/* ── Hero ────────────────────────────────────────────────────── */
.hero {
  padding: 48px 40px 40px;
  max-width: 960px;
  margin: 0 auto;
  width: 100%;
}

h1 {
  font-family: 'Syne', sans-serif;
  font-weight: 800;
  font-size: clamp(36px, 5vw, 58px);
  line-height: 1.05;
  letter-spacing: -0.02em;
  color: var(--text);
  margin-bottom: 12px;
}

.subtitle {
  font-size: 13px;
  color: var(--text-muted);
  letter-spacing: 0.02em;
  margin-bottom: 40px;
}

/* ── Search ──────────────────────────────────────────────────── */
.search-wrapper {
  display: flex;
  gap: 0;
  border: 1.5px solid var(--border-dark);
  border-radius: var(--radius);
  background: var(--surface);
  overflow: hidden;
  transition: border-color 0.15s;
}

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

#search-input {
  flex: 1;
  border: none;
  outline: none;
  padding: 14px 18px;
  font-family: 'DM Mono', monospace;
  /* Must be at least 16px to prevent iOS Safari from auto-zooming on focus */
  font-size: 16px;
  background: transparent;
  color: var(--text);
  letter-spacing: 0.01em;
}

#search-input::placeholder {
  color: var(--text-faint);
}

.search-btn {
  background: var(--accent);
  color: var(--bg);
  border: none;
  padding: 14px 22px;
  font-family: 'Syne', sans-serif;
  font-weight: 600;
  font-size: 12px;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  cursor: pointer;
  transition: background 0.15s;
}

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

/* ── Filters ─────────────────────────────────────────────────── */
.filters {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  margin-top: 16px;
}

.filter-btn {
  font-family: 'DM Mono', monospace;
  font-size: 11px;
  padding: 5px 12px;
  border: 1.5px solid var(--border-dark);
  border-radius: 2px;
  background: transparent;
  color: var(--text-muted);
  cursor: pointer;
  transition: all 0.12s;
  letter-spacing: 0.03em;
}

.filter-btn:hover, .filter-btn.active {
  border-color: var(--accent);
  color: var(--accent);
  background: var(--surface);
}

/* ── Main / Results ──────────────────────────────────────────── */
main {
  flex: 1;
  padding: 0 40px 40px;
  max-width: 960px;
  margin: 0 auto;
  width: 100%;
}

.results-meta {
  font-size: 11px;
  color: var(--text-muted);
  letter-spacing: 0.05em;
  text-transform: uppercase;
  margin-bottom: 20px;
  padding-top: 8px;
}

.results-grid {
  display: flex;
  flex-direction: column;
  gap: 1px;
  border: 1.5px solid var(--border);
  border-radius: var(--radius-lg);
  overflow: hidden;
  background: var(--border);
}

/* ── Cards ───────────────────────────────────────────────────── */
.card {
  background: var(--surface);
  padding: 22px 24px;
  cursor: pointer;
  transition: background 0.1s;
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 12px;
  align-items: start;
}

.card:hover {
  background: var(--surface-2);
}

.card-title {
  font-family: 'Syne', sans-serif;
  font-weight: 700;
  font-size: 15px;
  color: var(--text);
  letter-spacing: -0.01em;
  margin-bottom: 6px;
  line-height: 1.3;
}

.card-meta {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  align-items: center;
}

.tag {
  font-size: 10px;
  padding: 3px 8px;
  background: var(--tag-bg);
  color: var(--tag-text);
  border-radius: 2px;
  letter-spacing: 0.05em;
  font-weight: 500;
  white-space: nowrap;
}

.tag.level {
  background: var(--accent);
  color: var(--bg);
}

.card-arrow {
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-faint);
  transition: transform 0.2s, color 0.1s;
  margin-top: 2px;
}

.card-arrow svg {
  width: 18px;
  height: 18px;
  stroke: currentColor;
  fill: none;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.card:hover .card-arrow {
  transform: translateX(3px);
  color: var(--text);
}

/* ── Empty state ─────────────────────────────────────────────── */
.empty-state {
  text-align: center;
  padding: 80px 20px;
  color: var(--text-faint);
}

.empty-state .icon {
  display: flex;
  align-items: center;
  justify-content: center;
  margin: 0 auto 16px;
  opacity: 0.5;
}

.empty-state .icon svg {
  width: 40px;
  height: 40px;
  stroke: currentColor;
  fill: none;
  stroke-width: 1.5;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.empty-state h3 {
  font-family: 'Syne', sans-serif;
  font-weight: 700;
  font-size: 18px;
  color: var(--text-muted);
  margin-bottom: 8px;
}

.empty-state p {
  font-size: 13px;
  line-height: 1.6;
}

/* ── Modal ───────────────────────────────────────────────────── */
.modal-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.55);
  z-index: 100;
  backdrop-filter: blur(3px);
  -webkit-backdrop-filter: blur(3px);
  align-items: center;
  justify-content: center;
  padding: 20px;
}

.modal-overlay.open {
  display: flex;
  animation: fadeIn 0.15s ease;
}

@keyframes fadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

.modal {
  background: var(--surface);
  border-radius: var(--radius-lg);
  max-width: 600px;
  width: 100%;
  max-height: 88vh;
  overflow-y: auto;
  box-shadow: var(--shadow-lg);
  animation: slideUp 0.2s ease;
}

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

.modal-header {
  padding: 28px 28px 20px;
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  background: var(--surface);
  z-index: 1;
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 16px;
}

.modal-title {
  font-family: 'Syne', sans-serif;
  font-weight: 800;
  font-size: 20px;
  letter-spacing: -0.02em;
  line-height: 1.2;
  color: var(--text);
}

.modal-close {
  width: 32px;
  height: 32px;
  border: 1.5px solid var(--border-dark);
  border-radius: var(--radius);
  background: transparent;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-muted);
  flex-shrink: 0;
  transition: all 0.12s;
}

.modal-close:hover {
  border-color: var(--accent);
  color: var(--accent);
}

.modal-close svg {
  width: 14px;
  height: 14px;
  stroke: currentColor;
  fill: none;
  stroke-width: 2.5;
  stroke-linecap: round;
}

.modal-body {
  padding: 24px 28px 28px;
}

/* ── Info grid ───────────────────────────────────────────────── */
.info-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1px;
  background: var(--border);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  margin-bottom: 24px;
}

.info-cell {
  background: var(--surface);
  padding: 14px 16px;
}

.info-label {
  font-size: 10px;
  color: var(--text-muted);
  letter-spacing: 0.1em;
  text-transform: uppercase;
  margin-bottom: 4px;
  font-weight: 500;
}

.info-value {
  font-size: 14px;
  color: var(--text);
  font-weight: 500;
  line-height: 1.4;
}

.section-label {
  font-size: 10px;
  color: var(--text-muted);
  letter-spacing: 0.1em;
  text-transform: uppercase;
  font-weight: 500;
  margin-bottom: 12px;
}

/* ── Attachments ─────────────────────────────────────────────── */
.attachments-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-bottom: 24px;
}

.attachment-row {
  display: flex;
  align-items: center;
  gap: 6px;
}

.attachment-link {
  flex: 1;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 11px 14px;
  border: 1px solid var(--border-dark);
  border-radius: var(--radius);
  text-decoration: none;
  color: var(--text);
  font-size: 13px;
  transition: all 0.12s;
  background: var(--surface);
  min-width: 0;
}

.attachment-link:hover {
  border-color: var(--accent);
  background: var(--surface-2);
}

.attachment-name {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.attachment-download {
  flex-shrink: 0;
  width: 38px;
  height: 38px;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 1px solid var(--border-dark);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--text-muted);
  text-decoration: none;
  transition: all 0.12s;
}

.attachment-download:hover {
  border-color: var(--accent);
  color: var(--accent);
  background: var(--surface-2);
}

.attachment-download svg {
  width: 15px;
  height: 15px;
  stroke: currentColor;
  fill: none;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.attachment-icon {
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-muted);
  flex-shrink: 0;
}

.attachment-icon svg {
  width: 15px;
  height: 15px;
  stroke: currentColor;
  fill: none;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

/* ── SAQA button ─────────────────────────────────────────────── */
.saqa-btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  background: var(--accent);
  color: var(--bg);
  text-decoration: none;
  font-family: 'Syne', sans-serif;
  font-weight: 600;
  font-size: 12px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  padding: 12px 20px;
  border-radius: var(--radius);
  transition: background 0.12s;
}

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

.saqa-btn svg {
  width: 14px;
  height: 14px;
  stroke: currentColor;
  fill: none;
  stroke-width: 2.5;
  stroke-linecap: round;
  stroke-linejoin: round;
}

/* ── Footer ──────────────────────────────────────────────────── */
footer {
  border-top: 1px solid var(--border);
  padding: 20px 40px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  max-width: 960px;
  margin: 0 auto;
  width: 100%;
}

.footer-text {
  font-size: 11px;
  color: var(--text-muted);
  letter-spacing: 0.03em;
}

.footer-link {
  font-size: 11px;
  color: var(--text-muted);
  text-decoration: none;
  letter-spacing: 0.05em;
  font-weight: 500;
  border-bottom: 1px solid var(--border-dark);
  padding-bottom: 1px;
  transition: color 0.12s, border-color 0.12s;
}

.footer-link:hover {
  color: var(--text);
  border-color: var(--text);
}

/* ── Pagination ──────────────────────────────────────────────── */
.pagination {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 20px;
  justify-content: center;
}

.page-btn {
  font-family: 'DM Mono', monospace;
  font-size: 12px;
  padding: 6px 12px;
  border: 1.5px solid var(--border-dark);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--text-muted);
  cursor: pointer;
  transition: all 0.12s;
}

.page-btn:hover, .page-btn.active {
  border-color: var(--accent);
  color: var(--accent);
}

.page-btn:disabled {
  opacity: 0.3;
  cursor: not-allowed;
}

.page-info {
  font-size: 11px;
  color: var(--text-muted);
  letter-spacing: 0.05em;
}

/* ── PWA Toast ───────────────────────────────────────────────── */
.pwa-toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%) translateY(100px);
  background: var(--surface);
  border: 1.5px solid var(--border-dark);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px 16px;
  min-width: 280px;
  max-width: 360px;
  z-index: 200;
  cursor: pointer;
  opacity: 0;
  transition: transform 0.35s cubic-bezier(0.34, 1.56, 0.64, 1), opacity 0.3s ease;
  pointer-events: none;
}

.pwa-toast--visible {
  transform: translateX(-50%) translateY(0);
  opacity: 1;
  pointer-events: all;
}

.pwa-toast-icon {
  width: 36px;
  height: 36px;
  background: var(--accent);
  border-radius: var(--radius);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.pwa-toast-icon svg {
  width: 16px;
  height: 16px;
  stroke: var(--bg);
  fill: none;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.pwa-toast-text {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.pwa-toast-text strong {
  font-family: 'Syne', sans-serif;
  font-size: 13px;
  font-weight: 700;
  color: var(--text);
}

.pwa-toast-text span {
  font-size: 11px;
  color: var(--text-muted);
  letter-spacing: 0.02em;
}

.pwa-toast-close {
  width: 28px;
  height: 28px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: transparent;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-faint);
  flex-shrink: 0;
  transition: all 0.12s;
}

.pwa-toast-close:hover {
  border-color: var(--accent);
  color: var(--accent);
}

.pwa-toast-close svg {
  width: 12px;
  height: 12px;
  stroke: currentColor;
  fill: none;
  stroke-width: 2.5;
  stroke-linecap: round;
}

/* ── PWA Floating install button ─────────────────────────────── */
.pwa-fab {
  position: fixed;
  bottom: 24px;
  right: 24px;
  display: none;
  align-items: center;
  gap: 8px;
  font-family: 'Syne', sans-serif;
  font-weight: 600;
  font-size: 12px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  padding: 12px 18px;
  background: var(--accent);
  color: var(--bg);
  border: none;
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-md);
  cursor: pointer;
  z-index: 200;
  transition: background 0.15s, transform 0.15s, box-shadow 0.15s;
  transform: translateY(80px);
  opacity: 0;
}

.pwa-fab--visible {
  display: inline-flex;
  animation: fabSlideUp 0.35s cubic-bezier(0.34, 1.56, 0.64, 1) forwards;
}

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

.pwa-fab:hover {
  background: var(--accent-hover);
  box-shadow: var(--shadow-lg);
}

.pwa-fab svg {
  width: 14px;
  height: 14px;
  stroke: currentColor;
  fill: none;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

@media (max-width: 600px) {
  .pwa-toast { min-width: calc(100vw - 32px); max-width: calc(100vw - 32px); bottom: 16px; }
  .pwa-fab { bottom: 16px; right: 16px; }
}

/* ── Responsive ──────────────────────────────────────────────── */
@media (max-width: 600px) {
  header, .hero, main, footer { padding-left: 20px; padding-right: 20px; }
  h1 { font-size: 32px; }
  .info-grid { grid-template-columns: 1fr; }
  .card { grid-template-columns: 1fr; }
  .card-arrow { display: none; }
  footer { flex-direction: column; gap: 8px; text-align: center; }
}
