/* ── Design tokens ─────────────────────────────────────── */
:root {
  --color-header-bg:   #1E3A4A;
  --color-pdf-bg:      #F7F5F2;
  --color-agent-bg:    #FFFFFF;
  --color-accent:      #5C8A6E;
  --color-body:        #1C1C1E;
  --color-secondary:   #666666;
  --color-support-bg:  #FFFBF5;

  --font-heading: 'Lora', Georgia, serif;
  --font-body:    'Inter', system-ui, sans-serif;

  --header-height: 68px;
}

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

html {
  font-size: 17px;
  line-height: 1.6;
  color: var(--color-body);
  font-family: var(--font-body);
}

body {
  min-height: 100dvh;
  background: var(--color-pdf-bg);
}

/* ── Focus rings ───────────────────────────────────────── */
:focus-visible {
  outline: 3px solid var(--color-accent);
  outline-offset: 2px;
  border-radius: 2px;
}

/* ── Skip link ─────────────────────────────────────────── */
.skip-link {
  position: absolute;
  top: -100%;
  left: 1rem;
  background: var(--color-accent);
  color: #fff;
  padding: 0.5rem 1rem;
  border-radius: 0 0 4px 4px;
  font-size: 0.875rem;
  font-weight: 600;
  text-decoration: none;
  z-index: 1000;
}
.skip-link:focus {
  top: 0;
}

/* ── Site header ───────────────────────────────────────── */
.site-header {
  background: var(--color-header-bg);
  color: #fff;
  height: var(--header-height);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 1.5rem;
  gap: 1rem;
  position: sticky;
  top: 0;
  z-index: 100;
}

.header-titles {
  display: flex;
  flex-direction: column;
  gap: 0.05rem;
}

.site-title {
  font-family: var(--font-heading);
  font-size: 1.25rem;
  font-weight: 700;
  line-height: 1.2;
  color: #fff;
}

.site-subtitle {
  font-family: var(--font-body);
  font-size: 0.8rem;
  font-weight: 400;
  color: rgba(255,255,255,0.78);
  letter-spacing: 0.01em;
}

.btn-download {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  background: var(--color-accent);
  color: #fff;
  border: none;
  border-radius: 6px;
  padding: 0.45rem 1rem;
  font-family: var(--font-body);
  font-size: 0.875rem;
  font-weight: 600;
  text-decoration: none;
  cursor: pointer;
  white-space: nowrap;
  transition: background 0.15s ease, opacity 0.15s ease;
  flex-shrink: 0;
}
.btn-download:hover {
  background: #4a7359;
}
.btn-download:focus-visible {
  outline-color: #fff;
}


.header-actions {
  display: flex;
  gap: 0.5rem;
  flex-shrink: 0;
}

/* Mobile-only elements — hidden on desktop */
.btn-dl-mobile,
.mobile-save-tip {
  display: none;
}

/* ── Main layout ───────────────────────────────────────── */
.app-layout {
  display: flex;
  height: calc(100dvh - var(--header-height));
}

/* Embed mode: no header, full viewport */
body.embed-mode .app-layout {
  height: 100dvh;
}

/* ── PDF panel ─────────────────────────────────────────── */
.pdf-panel {
  flex: 1 1 auto;
  background: var(--color-pdf-bg);
  overflow-y: auto;
  height: 100%;
  padding: 1.5rem 1.5rem 3rem;
  min-width: 0;
}

#pdf-container {
  display: flex;
  flex-direction: column;
  gap: 1rem;
  align-items: center;
}

#pdf-container canvas {
  display: block;
  width: 100%;
  height: auto;
  border-radius: 3px;
  box-shadow: 0 1px 4px rgba(0,0,0,0.12);
}

.pdf-loading {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.75rem;
  padding: 4rem 0;
  color: var(--color-secondary);
  font-size: 0.9rem;
}

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

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

@media (prefers-reduced-motion: reduce) {
  .spinner {
    animation: none;
    border-top-color: var(--color-accent);
    opacity: 0.6;
  }
}

.pdf-error {
  color: #b0392a;
  background: #fff4f3;
  border: 1px solid #f5c6c1;
  border-radius: 6px;
  padding: 1rem 1.25rem;
  font-size: 0.9rem;
  margin: 2rem auto;
  max-width: 480px;
  text-align: center;
}

/* ── Panel divider ─────────────────────────────────────── */
.panel-divider {
  flex: 0 0 5px;
  width: 5px;
  background: rgba(0,0,0,0.08);
  cursor: col-resize;
  z-index: 10;
  transition: background 0.15s;
  user-select: none;
}
.panel-divider:hover,
.panel-divider.is-dragging {
  background: var(--color-accent);
}

/* ── Agent panel ───────────────────────────────────────── */
.agent-panel {
  flex: 0 0 32%;
  min-width: 240px;
  max-width: 60%;
  background: var(--color-agent-bg);
  overflow-y: auto;
  height: 100%;
  padding: 2rem 1.75rem 3rem;
  display: flex;
  flex-direction: column;
  gap: 1.25rem;
}

.agent-heading {
  font-family: var(--font-heading);
  font-size: 1.5rem;
  font-weight: 700;
  color: var(--color-body);
}

.agent-descriptor {
  font-size: 0.9375rem;
  color: var(--color-secondary);
  line-height: 1.55;
}

.agent-language-note {
  font-size: 0.95rem;
  color: var(--color-body);
  line-height: 1.5;
  background: #F0F5F2;
  border-left: 3px solid var(--color-accent);
  border-radius: 6px;
  padding: 0.75rem 1rem;
}

.agent-language-note a {
  color: var(--color-accent);
  font-weight: 600;
  white-space: nowrap;
}

.suggestion-section {
  margin-top: 0.25rem;
}

.suggestion-label {
  font-size: 0.85rem;
  color: var(--color-secondary);
  margin: 0 0 0.5rem;
}

.suggestion-list {
  list-style: none;
  padding-left: 0.5rem;
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
}

.suggestion-list li {
  font-size: 0.95rem;
  color: #1C1C1E;
  line-height: 1.45;
}

.suggestion-list li::before {
  content: "→";
  color: var(--color-accent);
  margin-right: 0.4rem;
}

/* Inline widget overrides */
elevenlabs-convai {
  position: static !important;
  display: block !important;
  width: 100% !important;
  min-height: 220px !important;
}

/* ── Support box ───────────────────────────────────────── */
.support-box {
  background: var(--color-support-bg);
  border-left: 4px solid var(--color-accent);
  border-radius: 0 6px 6px 0;
  padding: 1rem 1.25rem;
  flex-shrink: 0;
}

.support-box h2 {
  font-family: var(--font-body);
  font-size: 0.875rem;
  font-weight: 700;
  color: var(--color-body);
  margin-bottom: 0.35rem;
}

.support-box p {
  font-size: 0.8125rem;
  color: var(--color-secondary);
  line-height: 1.55;
}

.support-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 0.55rem;
}

.support-list li {
  font-size: 0.8rem;
  color: var(--color-secondary);
  line-height: 1.45;
  padding-bottom: 0.55rem;
  border-bottom: 1px solid rgba(0, 0, 0, 0.07);
}

.support-list li:last-child {
  border-bottom: none;
  padding-bottom: 0;
}

.support-list a {
  color: var(--color-accent);
  font-weight: 600;
  white-space: nowrap;
}

/* ── Mobile tab bar (hidden on desktop) ────────────────── */
.mobile-tabs {
  display: none;
}

/* ── Mobile layout ─────────────────────────────────────── */
@media (max-width: 768px) {
  /* Header: auto height, two-row layout */
  .site-header {
    flex-direction: column;
    align-items: stretch;
    padding: 0.75rem 1rem;
    gap: 0.5rem;
    height: auto;
  }

  .site-subtitle {
    display: none;
  }

  .site-title {
    font-size: 1rem;
  }

  .header-actions {
    display: flex;
  }

  .header-actions .btn-download {
    flex: 1;
    justify-content: center;
  }

  .btn-dl-desktop {
    display: none;
  }

  .btn-dl-mobile {
    display: inline-flex;
    flex: 1;
    justify-content: center;
  }

  .header-actions {
    flex-wrap: wrap;
  }

  .mobile-save-tip {
    display: block;
    color: rgba(255, 255, 255, 0.8);
    font-size: 0.75rem;
    line-height: 1.4;
    width: 100%;
    margin-top: 0.15rem;
  }

  /* Tab bar: sticky below header */
  .mobile-tabs {
    display: flex;
    position: sticky;
    top: var(--header-height); /* JS syncs this to actual rendered header height */
    z-index: 90;
    background: var(--color-header-bg);
    height: 44px;
    flex-shrink: 0;
  }

  .mobile-tab {
    flex: 1;
    background: transparent;
    color: rgba(255, 255, 255, 0.6);
    border: none;
    border-bottom: 3px solid transparent;
    padding: 0;
    font-family: var(--font-body);
    font-size: 0.95rem;
    font-weight: 600;
    cursor: pointer;
    transition: color 0.15s, border-color 0.15s;
    white-space: nowrap;
  }

  .mobile-tab.is-active {
    color: #fff;
    border-bottom-color: var(--color-accent);
  }

  /* App layout: fill viewport below header + tab bar, with relative
     positioning so absolute-positioned panels fill it correctly */
  .app-layout {
    position: relative;
    display: block;
    height: calc(100dvh - var(--header-height) - 44px);
    overflow: hidden;
  }

  .panel-divider {
    display: none;
  }

  /* Both panels fill the container; only the active one is visible.
     visibility (not display:none) keeps clientWidth available for PDF.js. */
  .pdf-panel,
  .agent-panel {
    position: absolute;
    inset: 0;
    overflow-y: auto;
    flex: none;
    min-width: unset;
    max-width: unset;
    visibility: hidden;
    pointer-events: none;
  }

  .pdf-panel {
    padding: 1.25rem 0.75rem 3rem;
  }

  .agent-panel {
    display: flex;
    flex-direction: column;
    gap: 1.25rem;
    padding: 1.5rem 1.25rem 140px;
  }

  .pdf-panel.is-active,
  .agent-panel.is-active {
    visibility: visible;
    pointer-events: auto;
    z-index: 1;
  }

  /* Embed mode: no header/tabs — restore normal stacked layout */
  body.embed-mode .app-layout {
    display: flex;
    flex-direction: column;
    height: 100dvh;
    overflow-y: auto;
  }

  body.embed-mode .pdf-panel,
  body.embed-mode .agent-panel {
    position: static;
    visibility: visible;
    pointer-events: auto;
    flex: none;
    height: auto;
    width: 100%;
  }

  body.embed-mode .agent-panel {
    display: flex;
  }

  /* Force the ElevenLabs floating bubble to a fixed viewport position
     so it escapes any panel clipping/stacking contexts on mobile */
  elevenlabs-convai {
    position: fixed !important;
    bottom: 1rem !important;
    right: 1rem !important;
    z-index: 9999 !important;
  }
}
