/* ============================================================================
   OCR.chat design system
   ========================================================================== */
:root {
    --oc-primary: #7c3aed;
    --oc-primary-dark: #6d28d9;
    --oc-primary-soft: #f5f3ff;
    --oc-ink: #0f172a;
    --oc-body: #344256;
    --oc-muted: #64748b;
    --oc-line: #e7ecf3;
    --oc-bg-soft: #f6f8fc;
    --oc-radius: 0.85rem;
    --oc-radius-sm: 0.6rem;
    --oc-shadow-sm: 0 1px 2px rgba(15, 23, 42, .06), 0 1px 3px rgba(15, 23, 42, .05);
    --oc-shadow: 0 4px 20px rgba(15, 23, 42, .07);
    --oc-shadow-lg: 0 18px 50px -16px rgba(15, 23, 42, .22);

    /* Map onto Bootstrap so its components inherit the palette */
    --bs-primary: var(--oc-primary);
    --bs-primary-rgb: 124, 58, 237;
    --bs-link-color: var(--oc-primary);
    --bs-link-hover-color: var(--oc-primary-dark);
    --bs-body-color: var(--oc-body);
    --bs-border-color: var(--oc-line);
    --bs-body-font-family: 'Inter', system-ui, -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

body {
    display: flex;
    flex-direction: column;
    min-height: 100vh;
    font-family: var(--bs-body-font-family);
    color: var(--oc-body);
    -webkit-font-smoothing: antialiased;
    text-rendering: optimizeLegibility;
    background: #fff;
}
main { flex: 1; }

h1, h2, h3, h4, h5, h6, .navbar-brand {
    font-family: var(--bs-body-font-family);
    color: var(--oc-ink);
    font-weight: 700;
    letter-spacing: -0.018em;
}
.display-4, .display-5, .display-6 { letter-spacing: -0.03em; font-weight: 800; }
.lead { color: var(--oc-muted); font-weight: 400; }
a { text-decoration: none; }
a:hover { text-decoration: none; }
.text-muted { color: var(--oc-muted) !important; }
hr { border-color: var(--oc-line); opacity: 1; }

/* ---------- Buttons ---------- */
.btn { font-weight: 600; border-radius: 0.6rem; padding: 0.55rem 1.15rem; transition: transform .12s ease, box-shadow .12s ease, background .12s ease; }
.btn-lg { padding: 0.8rem 1.6rem; }
.btn-sm { padding: 0.35rem 0.8rem; border-radius: 0.5rem; }
.btn-primary { background: var(--oc-primary); border-color: var(--oc-primary); box-shadow: 0 6px 16px -6px rgba(37, 99, 235, .6); }
.btn-primary:hover, .btn-primary:focus { background: var(--oc-primary-dark); border-color: var(--oc-primary-dark); transform: translateY(-1px); }
.btn-outline-primary { color: var(--oc-primary); border-color: #c9d8f6; }
.btn-outline-primary:hover { background: var(--oc-primary); border-color: var(--oc-primary); }
.btn-outline-secondary { color: var(--oc-body); border-color: var(--oc-line); }
.btn-outline-secondary:hover { background: var(--oc-ink); border-color: var(--oc-ink); color: #fff; }
.btn-success { background: #16a34a; border-color: #16a34a; box-shadow: 0 6px 16px -6px rgba(22, 163, 74, .55); }
.btn-success:hover { background: #15803d; border-color: #15803d; transform: translateY(-1px); }

/* ---------- Navbar ---------- */
.navbar {
    background: rgba(255, 255, 255, .9) !important;
    backdrop-filter: saturate(180%) blur(10px);
    border-bottom: 1px solid var(--oc-line);
    padding-top: .7rem; padding-bottom: .7rem;
    position: sticky; top: 0; z-index: 1030;
}
.navbar-brand { font-weight: 800; font-size: 1.25rem; display: inline-flex; align-items: center; gap: .55rem; color: var(--oc-ink); }
.brand-logo { border-radius: 7px; display: block; }
.navbar .nav-link { color: var(--oc-body); font-weight: 500; padding: .4rem .85rem; border-radius: .5rem; }
.navbar .nav-link:hover { color: var(--oc-primary); }
.navbar .nav-link.active { color: var(--oc-primary); font-weight: 600; }
.dropdown-menu { max-height: 320px; overflow-y: auto; border-color: var(--oc-line); border-radius: .65rem; box-shadow: var(--oc-shadow); }

/* ---------- Sections ---------- */
.section-soft { background: var(--oc-bg-soft); }
.eyebrow { text-transform: uppercase; letter-spacing: .08em; font-size: .78rem; font-weight: 700; color: var(--oc-primary); }

/* ---------- Cards ---------- */
.card { border-color: var(--oc-line); border-radius: var(--oc-radius); }
.feature-card {
    background: #fff;
    border: 1px solid var(--oc-line);
    border-radius: var(--oc-radius);
    padding: 1.4rem;
    height: 100%;
    box-shadow: var(--oc-shadow-sm);
    transition: transform .15s ease, box-shadow .15s ease, border-color .15s ease;
}
a .feature-card:hover, .feature-card.hoverable:hover {
    transform: translateY(-3px);
    box-shadow: var(--oc-shadow);
    border-color: #d4e0f7;
}
.feature-emoji { font-size: 1.7rem; margin-bottom: .5rem; line-height: 1; }

/* ---------- Forms ---------- */
.form-control, .form-select { border-color: var(--oc-line); border-radius: .6rem; padding: .6rem .85rem; }
.form-control:focus, .form-select:focus { border-color: var(--oc-primary); box-shadow: 0 0 0 .2rem rgba(37, 99, 235, .15); }
.input-group-text { border-color: var(--oc-line); background: var(--oc-bg-soft); }

/* ---------- Accordion (FAQ) ---------- */
.accordion { --bs-accordion-border-color: var(--oc-line); --bs-accordion-border-radius: var(--oc-radius-sm); }
.accordion-item { border-color: var(--oc-line); margin-bottom: .6rem; border-radius: var(--oc-radius-sm) !important; overflow: hidden; }
.accordion-button { font-weight: 600; color: var(--oc-ink); }
.accordion-button:not(.collapsed) { background: var(--oc-primary-soft); color: var(--oc-primary-dark); box-shadow: none; }
.accordion-button:focus { box-shadow: none; border-color: var(--oc-line); }

/* ---------- Tables ---------- */
.table { --bs-table-border-color: var(--oc-line); color: var(--oc-body); }
.table thead th { color: var(--oc-muted); font-weight: 600; font-size: .85rem; text-transform: uppercase; letter-spacing: .03em; border-bottom-width: 1px; }

/* ---------- Breadcrumb ---------- */
.breadcrumb { --bs-breadcrumb-divider: '›'; }
.breadcrumb-item, .breadcrumb-item a { color: var(--oc-muted); }
.breadcrumb-item.active { color: var(--oc-body); }

/* ---------- Badges ---------- */
.badge { font-weight: 600; }

/* ---------- Footer ---------- */
.site-footer { background: var(--oc-ink); color: #cbd5e1; padding: 3rem 0 1.5rem; }
.site-footer a { color: #cbd5e1; text-decoration: none; }
.site-footer a:hover { color: #fff; text-decoration: none; }
.site-footer h6 { color: #fff; font-size: .8rem; text-transform: uppercase; letter-spacing: .06em; margin-bottom: .9rem; }
.site-footer .footer-brand { color: #fff; font-weight: 800; font-size: 1.15rem; display: inline-flex; align-items: center; gap: .5rem; }
.site-footer .footer-brand .brand-logo { box-shadow: 0 0 0 1px rgba(255,255,255,.12); }
.site-footer .footer-link { display: block; padding: .2rem 0; font-size: .92rem; }
.site-footer hr { border-color: rgba(255, 255, 255, .12); }

/* ============================================================================
   Components
   ========================================================================== */

/* ---------- OCR uploader ---------- */
.drop-zone {
    position: relative;
    border: 2px dashed #c2cede;
    border-radius: var(--oc-radius);
    background: linear-gradient(180deg, #fbfdff 0%, #f4f8ff 100%);
    padding: 3rem 1.5rem;
    cursor: pointer;
    text-align: center;
    transition: border-color .15s, background .15s, box-shadow .15s, transform .15s;
}
/* Recognition-language picker tucked into the top-left corner of the drop zone */
.zone-lang { position: absolute; top: .75rem; left: .75rem; text-align: left; z-index: 3; }
.zone-lang .lang-picker { width: auto !important; }
.zone-lang .lang-picker-btn,
.zone-lang .form-select-sm {
    width: auto;
    min-width: 0;
    max-width: 200px;
    font-size: .8rem;
    padding: .25rem 1.6rem .25rem .6rem;
    background-color: rgba(255, 255, 255, .9);
    border-color: var(--oc-line);
    color: var(--oc-body);
    box-shadow: 0 1px 2px rgba(15, 23, 42, .06);
}
.drop-zone:hover, .drop-zone:focus { border-color: var(--oc-primary); box-shadow: var(--oc-shadow); outline: none; }
.drop-zone.drag { border-color: var(--oc-primary); background: #e7f0ff; box-shadow: 0 0 0 4px rgba(37, 99, 235, .14); transform: scale(1.01); }
.drop-zone.busy { opacity: .6; pointer-events: none; }
.drop-icon { font-size: 2.9rem; line-height: 1; margin-bottom: .5rem; }

/* ---------- How-to steps ---------- */
.howto-step { display: flex; gap: .9rem; align-items: flex-start; margin-bottom: 1.1rem; }
.howto-num {
    flex: 0 0 auto; width: 34px; height: 34px; border-radius: 50%;
    background: var(--oc-primary-soft); color: var(--oc-primary-dark);
    display: flex; align-items: center; justify-content: center; font-weight: 800; font-size: .95rem;
    border: 1px solid #d4e0f7;
}
.tool-prose { font-size: 1.04rem; line-height: 1.7; color: var(--oc-body); }
.tool-prose h2 { margin-top: 2rem; margin-bottom: .9rem; }
.tool-prose ul li { margin-bottom: .35rem; }

/* ---------- Result review ---------- */
.result-pane { border: 1px solid var(--oc-line); border-radius: var(--oc-radius-sm); overflow: hidden; background: #fff; height: 100%; box-shadow: var(--oc-shadow-sm); }
.result-pane-head { background: var(--oc-bg-soft); border-bottom: 1px solid var(--oc-line); padding: .55rem .9rem; font-weight: 600; font-size: .82rem; color: var(--oc-muted); text-transform: uppercase; letter-spacing: .04em; }
.result-pane-body { padding: 1rem; max-height: 78vh; overflow: auto; }
.result-output { white-space: pre-wrap; word-break: break-word; font-size: .95rem; line-height: 1.6; }
.result-output.md-render { white-space: normal; }
.result-output.md-render table { border-collapse: collapse; width: 100%; margin: .75rem 0; }
.result-output.md-render th, .result-output.md-render td { border: 1px solid var(--oc-line); padding: .35rem .55rem; }
.result-output .lowconf { background: #fff3cd; border-bottom: 1px dotted #d39e00; }

/* ---------- Chat with the document (conversational OCR) ---------- */
.chat-messages { max-height: 48vh; overflow-y: auto; display: flex; flex-direction: column; gap: .75rem; padding: .25rem; }
.chat-msg { display: flex; flex-direction: column; max-width: 88%; }
.chat-msg.chat-user { align-self: flex-end; align-items: flex-end; }
.chat-msg.chat-assistant { align-self: flex-start; align-items: flex-start; }
.chat-bubble { padding: .6rem .85rem; border-radius: var(--oc-radius-sm); font-size: .95rem; line-height: 1.55; word-break: break-word; }
.chat-user .chat-bubble { background: var(--oc-primary); color: #fff; border-bottom-right-radius: .2rem; }
.chat-assistant .chat-bubble { background: var(--oc-bg-soft); color: var(--oc-ink); border: 1px solid var(--oc-line); border-bottom-left-radius: .2rem; }
.chat-bubble p:last-child { margin-bottom: 0; }
.chat-bubble table { border-collapse: collapse; width: 100%; margin: .5rem 0; }
.chat-bubble th, .chat-bubble td { border: 1px solid var(--oc-line); padding: .3rem .5rem; font-size: .9em; }
.chat-cites { margin-top: .3rem; display: flex; flex-wrap: wrap; gap: .3rem; }
.chat-cite { font-size: .72rem; font-weight: 600; color: var(--oc-primary-dark); background: var(--oc-primary-soft); border-radius: .35rem; padding: .1rem .4rem; cursor: help; }

/* ---------- API docs / code ---------- */
.api-code { background: #0b1220; color: #e6edf3; border-radius: var(--oc-radius-sm); padding: 1.1rem 1.2rem; overflow-x: auto; font-size: .85rem; line-height: 1.55; }
.api-code code { color: inherit; background: none; padding: 0; }
code { color: #be185d; background: #fdf2f8; padding: .08em .35em; border-radius: .3rem; font-size: .88em; }
.api-code code, pre code { background: none; padding: 0; }
.nav-tabs .nav-link { color: var(--oc-muted); font-weight: 600; }
.nav-tabs .nav-link.active { color: var(--oc-primary); }

/* ---------- Misc ---------- */
.hidden { display: none !important; }
.spinner-border-sm { width: 1rem; height: 1rem; }
.pricing-card { border: 1px solid var(--oc-line); border-radius: var(--oc-radius); box-shadow: none; transition: transform .15s ease, box-shadow .15s ease, border-color .15s ease; }
.pricing-card:hover { transform: translateY(-4px); box-shadow: var(--oc-shadow); border-color: #d4e0f7; }
.pricing-card.featured { border: 1.5px solid var(--oc-primary); box-shadow: var(--oc-shadow); }
.popular-badge { background: var(--oc-primary-soft); color: var(--oc-primary-dark); font-weight: 600; letter-spacing: .02em; }
#card-element { border: 1px solid var(--oc-line); padding: 0.75rem; border-radius: 0.6rem; }
.alert ul { margin: 0; padding-left: 1rem; }
.alert { border-radius: var(--oc-radius-sm); }

@media (max-width: 768px) {
    .display-4 { font-size: 2rem; }
    .display-5 { font-size: 1.9rem; }
}

/* Subtle OCR / Describe-image mode toggle above the uploader */
.oc-mode-toggle {
    display: inline-flex;
    gap: .15rem;
    padding: .2rem;
    background: rgba(15, 23, 42, .04);
    border-radius: 999px;
}
.oc-mode-toggle .btn {
    border: none;
    background: transparent;
    color: var(--oc-body);
    opacity: .65;
    font-weight: 500;
    border-radius: 999px;
    padding: .2rem .8rem;
    box-shadow: none;
}
.oc-mode-toggle .btn:hover { opacity: 1; }
.oc-mode-toggle .btn-check:checked + .btn {
    background: #fff;
    color: var(--oc-primary);
    opacity: 1;
    font-weight: 600;
    box-shadow: 0 1px 2px rgba(15, 23, 42, .08);
}

/* ===== Chat workspace (PDF.chat) ===================================== */
/* Side-by-side: rendered PDF viewer + chat panel. */
.chat-workspace { align-items: stretch; }

.pdf-viewer-card,
.chat-card {
  border: 1px solid var(--oc-line);
  border-radius: var(--oc-radius-sm);
  background: #fff;
  box-shadow: var(--oc-shadow-sm);
  overflow: hidden;
  height: calc(100vh - 160px);
  min-height: 480px;
  display: flex;
  flex-direction: column;
}
.pdf-viewer-head,
.chat-card-head {
  background: var(--oc-bg-soft);
  border-bottom: 1px solid var(--oc-line);
  padding: .6rem .9rem;
  font-weight: 600;
  font-size: .9rem;
  display: flex;
  align-items: center;
  gap: .5rem;
  flex-shrink: 0;
}

/* PDF pages column */
.pdf-pages {
  flex: 1 1 auto;
  overflow: auto;
  background: #f1f5f9;
  padding: 1rem;
  text-align: center;
}
.pdf-page {
  position: relative;
  margin: 0 auto 1rem;
  background: #fff;
  box-shadow: 0 2px 10px -4px rgba(15, 23, 42, .35);
  border-radius: 2px;
}
.pdf-page canvas { display: block; }
.pdf-page.pdf-flash { outline: 3px solid var(--oc-primary); outline-offset: 2px; transition: outline-color .3s; }

/* PDF.js text layer (selectable + citation highlight target) */
.textLayer {
  position: absolute;
  inset: 0;
  overflow: hidden;
  line-height: 1;
  opacity: 1;
}
.textLayer span,
.textLayer br {
  color: transparent;
  position: absolute;
  white-space: pre;
  cursor: text;
  transform-origin: 0 0;
}
.textLayer .cite-hl {
  background: rgba(250, 204, 21, .55);
  border-radius: 2px;
  box-shadow: 0 0 0 1px rgba(202, 138, 4, .5);
}

/* Chat column */
.chat-card { padding: 0; }
.chat-card .chat-summary,
.chat-card .suggested-qs { padding: .75rem .9rem 0; flex-shrink: 0; }
.chat-summary-label {
  font-size: .72rem; text-transform: uppercase; letter-spacing: .04em;
  font-weight: 700; color: var(--oc-muted); margin-bottom: .2rem;
}
.chat-summary {
  background: var(--oc-primary-soft);
  border-radius: var(--oc-radius-sm);
  margin: .75rem .9rem 0;
  padding: .6rem .75rem;
}
.suggested-q {
  border: 1px solid #c9d8f6;
  background: #fff;
  color: var(--oc-primary-dark);
  border-radius: 999px;
  padding: .25rem .7rem;
  font-size: .82rem;
  cursor: pointer;
  transition: background .15s, border-color .15s;
}
.suggested-q:hover { background: var(--oc-primary-soft); border-color: var(--oc-primary); }

.chat-card .chat-messages {
  flex: 1 1 auto;
  max-height: none;
  overflow-y: auto;
  padding: .9rem;
}
.chat-card #chat-status { flex-shrink: 0; }
.chat-input-row {
  display: flex;
  gap: .5rem;
  padding: .75rem .9rem;
  border-top: 1px solid var(--oc-line);
  background: var(--oc-bg-soft);
  flex-shrink: 0;
}

/* Clickable citation chips */
.chat-cite {
  font-size: .72rem;
  font-weight: 600;
  color: var(--oc-primary-dark);
  background: var(--oc-primary-soft);
  border: 1px solid #c9d8f6;
  border-radius: .35rem;
  padding: .05rem .35rem;
  cursor: pointer;
  line-height: 1.4;
}
.chat-cite:hover { background: var(--oc-primary); color: #fff; border-color: var(--oc-primary); }
.chat-cite-inline { margin: 0 1px; vertical-align: baseline; }

/* Typing indicator */
.chat-typing { display: inline-flex; gap: 4px; align-items: center; padding: 2px 0; }
.chat-typing span {
  width: 6px; height: 6px; border-radius: 50%;
  background: var(--oc-muted); opacity: .5;
  animation: chatTyping 1.2s infinite ease-in-out;
}
.chat-typing span:nth-child(2) { animation-delay: .2s; }
.chat-typing span:nth-child(3) { animation-delay: .4s; }
@keyframes chatTyping { 0%, 60%, 100% { transform: translateY(0); opacity: .4; } 30% { transform: translateY(-4px); opacity: 1; } }

@media (max-width: 991.98px) {
  .pdf-viewer-card { height: 60vh; min-height: 360px; }
  .chat-card { height: auto; min-height: 480px; }
}

/* Compare-models (Pro) — side-by-side model answers */
.chat-compare-result { width: 100%; }
.compare-grid { display: flex; gap: .75rem; overflow-x: auto; padding-bottom: .5rem; }
.compare-col { flex: 0 0 280px; min-width: 280px; border: 1px solid var(--bs-border-color, #dee2e6); border-radius: .5rem; padding: .6rem .7rem; background: #fff; }
.compare-model { font-weight: 600; font-size: .85rem; margin-bottom: .4rem; color: var(--oc-primary, #4f46e5); }
.compare-col .chat-bubble { background: transparent; padding: 0; font-size: .9rem; }
#chat-compare { font-size: .85rem; }
