/* utilities.css – small helpers & buttons */
@import url("variables.css");

button:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

.answer-actions,
.report-actions {
  margin: 1em 0;
}

/* Standalone-page errors (auth gate, 429, startup): a quiet card,
   not an alarm block. In-page errors use .oh-toast instead. */
.error-banner {
  padding: 0.65rem 0.95rem;
  background: var(--container-bg);
  color: var(--fg);
  border: 1px solid var(--container-border);
  border-left: 3px solid var(--oh-red, #b91c1c);
  border-radius: var(--oh-radius-sm, 6px);
  margin: 1em 0;
  font-family: var(--oh-font-mono, monospace);
  font-size: 0.8rem;
  line-height: 1.5;
}

/* Ephemeral toast — in-page errors surface briefly, then leave.
   Fixed to the viewport so they never reflow the results area;
   auto-dismisses via animation, no JS needed. */
.oh-toast {
  position: fixed;
  right: 1.25rem;
  bottom: 1.25rem;
  z-index: 10000;
  max-width: 26rem;
  padding: 0.65rem 0.95rem;
  background: var(--container-bg);
  color: var(--fg);
  border: 1px solid var(--container-border);
  border-left: 3px solid var(--oh-red, #b91c1c);
  border-radius: var(--oh-radius-sm, 6px);
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.18);
  font-family: var(--oh-font-mono, monospace);
  font-size: 0.78rem;
  line-height: 1.5;
  animation:
    oh-toast-in 0.25s var(--oh-ease, ease),
    oh-toast-out 0.4s ease 4.6s forwards;
}
@keyframes oh-toast-in {
  from {
    opacity: 0;
    transform: translateY(8px);
  }
  to {
    opacity: 1;
    transform: none;
  }
}
@keyframes oh-toast-out {
  to {
    opacity: 0;
    transform: translateY(8px);
    visibility: hidden;
  }
}
@media (prefers-reduced-motion: reduce) {
  .oh-toast {
    /* still auto-dismiss — just no slide/fade transition */
    animation: oh-toast-out 0.01s ease 4.6s forwards;
  }
}

.ask-assistant-btn {
  margin-top: 0.5rem;
  padding: 0.35rem 0.75rem;
  background: var(--oh-accent);
  color: #fff;
  border: 1px solid var(--oh-accent-hover);
  border-radius: var(--oh-radius-sm, 4px);
  font-size: 0.85rem;
  cursor: pointer;
  transition: background 0.2s;
}
.ask-assistant-btn:hover {
  background: var(--oh-accent-hover);
}
html.oh-dark .ask-assistant-btn {
  background: var(--oh-accent);
  color: #fff;
  border: 1px solid var(--oh-accent-hover);
}
html.oh-dark .ask-assistant-btn:hover {
  background: var(--oh-accent-hover);
  color: #fff;
}

/* --- Legacy layout utility classes (migrated from styles.css) --- */
.flex { display: flex; }
.flex-1 { flex: 1 1 0%; }
.items-center { align-items: center; }

/* Gap utilities (using rem for consistency) */
.gap-1 { gap: 0.25rem; }
.gap-2 { gap: 0.5rem; }

/* Margin utilities (only the ones referenced in templates) */
.mr-3 { margin-right: 0.75rem; }
.mr-6 { margin-right: 1.5rem; }
.mt-2 { margin-top: 0.5rem; }
.mx-auto { margin-left: auto; margin-right: auto; }

/* Padding (px & p-4) */
.px-4 { padding-left: 1rem; padding-right: 1rem; }
.p-4 { padding: 1rem; }

/* Text helpers */
.text-sm { font-size: 0.875rem; }
.text-lg { font-size: 1.125rem; }
.font-bold { font-weight: 700; }
.text-blue-500 { color: var(--oh-accent); }
.underline { text-decoration: underline; }

/* Width helpers */
.w-full { width: 100%; }

/* --- Link colour normalisation ----------------------------------------- */
a, a:visited { color: var(--oh-accent); }
html.oh-dark a, html.oh-dark a:visited { color: var(--oh-accent); }

/* Preserve white nav links */
nav a, nav a:visited { color:#fff; }

/* --- Generic button dark-mode palette ---------------------------------- */
html.oh-dark button { background:var(--oh-elevated); color:var(--fg); border:1px solid var(--oh-border-strong); }
html.oh-dark button:hover:not(:disabled) { background:var(--oh-elevated-hover); }

/* Inputs / text areas to match dark grey */
html.oh-dark input, html.oh-dark textarea, html.oh-dark select {
  background:var(--oh-input-bg); color:var(--fg); border:1px solid var(--oh-border-strong);
}
html.oh-dark input:hover, html.oh-dark textarea:hover, html.oh-dark select:hover {
  background:var(--oh-elevated);
}

/* Ensure colour utilities adapt in dark mode when used on standalone elements */
html.oh-dark .text-blue-500 { color: var(--oh-accent); }

/* Ensure mobile no-horizontal-scroll.
   clip (not hidden): any non-visible overflow value on html/body creates a
   new scroll container, which silently breaks position:sticky on the top
   bar. clip prevents scrolling without a scroll container. */
html, body { overflow-x: clip; }

.container { max-width: 100%; box-sizing: border-box; }

.paper-summary-item, form, input, textarea, select {
  max-width: 100%;
  overflow-wrap: anywhere;
}

/* Skeleton loading pulse */
@keyframes oh-pulse {
  0% { background-color: var(--container-bg); }
  50% { background-color: var(--container-border); }
  100% { background-color: var(--container-bg); }
}
.skeleton {
  animation: oh-pulse 1.2s ease-in-out infinite;
  pointer-events:none;
  color: transparent !important;
}

/* --- Pin button & pinned item ------------------------------------------------ */
/* Paper list items need relative positioning for pin button */
#papers-list li {
  position: relative;
}

/* Optional hover tint for clarity */

.pager {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
}
.pager-pos {
  font-family: var(--oh-font-mono, monospace);
  font-size: 0.7rem;
  letter-spacing: 0.1em;
  color: var(--fg-muted, #888);
}
.pager button {
  background: none;
  border: none;
  color: var(--oh-blue, #0074d9);
  cursor: pointer;
  padding: 4px 6px;
  font-size: 0.85rem;
}
.pager button:hover:not(:disabled) {
  text-decoration: underline;
}
.pager button.active {
  font-weight: 600;
  text-decoration: underline;
}
.pager button:disabled {
  color: var(--fg-muted);
  opacity: 0.5;
  cursor: default;
}

/* Remove browser focus ring/yellow shadow on pager buttons */
.pager button:focus {
  outline: none;
  box-shadow: none;
}

/* Remove focus flash on paper titles and list items */
#papers-list a:focus,
#papers-list a:focus-visible,
#papers-list a:active,
#papers-list li:focus,
#papers-list li:focus-visible,
#papers-list li:active {
  outline: none !important;
  box-shadow: none !important;
}

#papers-list * {
  -webkit-tap-highlight-color: transparent;
}

/* ================================================================
   Shared page chrome — wraps + empty-state cards on every app page
   ================================================================ */

/* width:100% + border-box: body is `display:flex;flex-direction:column`,
   so a bare `margin:auto` flex item shrink-wraps to its content — empty
   pages rendered a narrower column than full ones. Forcing the width
   makes every page the same min(viewport, 900px) box. */
.page-wrap {
  width: 100%;
  box-sizing: border-box;
  max-width: 900px;
  margin: 1.1rem auto 2rem;
  padding: 0 1rem;
}

/* Shared button chrome — the app's standard secondary-button look.
   .btn-secondary is used across ~12 templates but previously had no CSS
   rule, so those buttons rendered as browser defaults (light) / the
   generic dark palette (dark). One consistent style for both. */
.btn-secondary,
.oh-search-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 0.82rem;
  padding: 6px 14px;
  border: 1px solid var(--container-border, #888);
  border-radius: 6px;
  /* lift off the card/page background — buttons shouldn't blend in */
  background: #fff;
  color: var(--fg, #222);
  cursor: pointer;
  text-decoration: none;
}
.btn-secondary:hover:not(:disabled),
.oh-search-btn:hover:not(:disabled) {
  border-color: var(--accent, #4a9eff);
  color: var(--accent, #4a9eff);
}
html.oh-dark .btn-secondary,
html.oh-dark .oh-search-btn {
  background: var(--oh-elevated);
  color: var(--fg);
  border-color: var(--oh-border-strong);
}
html.oh-dark .btn-secondary:hover:not(:disabled),
html.oh-dark .oh-search-btn:hover:not(:disabled) {
  background: var(--oh-elevated-hover);
  border-color: var(--accent);
  color: var(--accent);
}

/* Cancel button inside the in-flight search indicator. */
.oh-cancel-btn {
  font-size: 0.75rem;
  padding: 3px 12px;
  margin-left: 10px;
  border: 1px solid var(--container-border, #888);
  border-radius: 4px;
  background: transparent;
  color: var(--fg-muted, #888);
  cursor: pointer;
}
.oh-cancel-btn:hover { color: var(--fg, #eee); }

/* Caption under the cluster-viz scatter — explains what the chart means. */
.cluster-viz-caption {
  font-size: 0.78rem;
  color: var(--fg-muted, #888);
  text-align: center;
  margin-top: -1.5rem;
  padding: 0 1rem 0.5rem;
}

/* ------------------------------------------------------------
   Chips — ONE system for every small labelled pill in the app.
   Neutral outline for kind labels (SUBJECT, feed); soft accent
   tint for info signals (Highly cited, status); solid accent
   for counts (+N new). Mono caps = the brand voice for labels.
   ------------------------------------------------------------ */
.oh-chip,
.topic-kind,
.signal-badge,
.lib-status-chip {
  display: inline-flex;
  align-items: center;
  gap: 3px;
  font-family: var(--oh-font-mono, monospace);
  font-size: 0.65rem;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  line-height: 1.4;
  padding: 1px 7px;
  border-radius: 999px;
  border: 1px solid var(--container-border);
  color: var(--fg-muted);
  background: transparent;
  vertical-align: middle;
  white-space: nowrap;
}
.signal-badge,
.lib-status-chip {
  color: var(--oh-accent);
  border-color: transparent;
  background: var(--oh-accent-soft);
}
.lib-notion-badge {
  font-family: var(--oh-font-mono, monospace);
  font-size: 0.65rem;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--fg-muted);
  text-decoration: none;
  padding: 1px 7px;
  border-radius: 999px;
  border: 1px dashed var(--container-border);
  vertical-align: middle;
  white-space: nowrap;
}
.lib-notion-badge:hover {
  color: var(--oh-accent);
  border-color: var(--oh-accent);
}
.oh-topic-badge,
.oh-surface-badge {
  font-family: var(--oh-font-mono, monospace);
  border-radius: 999px;
  vertical-align: middle;
}

/* "Nothing here yet" card — one style for every empty page. */
.empty-state-card {
  border: 1px dashed var(--container-border, #555);
  border-radius: 8px;
  padding: 2rem;
  text-align: center;
  color: var(--fg-muted, #888);
}
.empty-state-card strong { color: var(--fg); display: block; margin-bottom: 0.4rem; }
.empty-state-card a { color: var(--oh-accent); }
.report-wrap {
  width: 100%;
  box-sizing: border-box;
  max-width: 1000px;
  margin: 1.1rem auto 2rem;
  padding: 0 1rem;
}

/* ================================================================
   Library page — .lib-* components (header, tabs, notion card, items)
   ================================================================ */

/* legacy alias — the three Library sub-tab pages all use .page-wrap now */
.lib-wrap {
  max-width: 900px;
  margin: 1.1rem auto 2rem;
  padding: 0 1rem;
}

/* Sub-tab strip — Papers | Topics | Reports inside the Library hub */
.lib-subtabs {
  display: flex;
  gap: 2px;
  border-bottom: 1px solid var(--container-border, #444);
}
.subtab-desc {
  font-size: 0.8rem;
  color: var(--fg-muted, #888);
  margin: 0.45rem 0 1.25rem;
}
.lib-subtab {
  padding: 7px 16px;
  font-size: 0.92rem;
  color: var(--fg-muted, #888);
  text-decoration: none;
  border-bottom: 2px solid transparent;
  margin-bottom: -1px;
}
.lib-subtab:hover {
  color: var(--fg, #eee);
}
.lib-subtab.active {
  color: var(--fg, #eee);
  border-bottom-color: var(--accent, #4a9eff);
  font-weight: 600;
}

/* Styled tooltip — reliable replacement for native title= hints.
   Usage: <button class="oh-tip" data-tip="…"> */
.oh-tip {
  position: relative;
}
.oh-tip::after {
  content: attr(data-tip);
  position: absolute;
  bottom: calc(100% + 8px);
  left: 50%;
  transform: translateX(-50%);
  width: max-content;
  max-width: 260px;
  white-space: normal;
  text-align: left;
  font-size: 0.78rem;
  font-weight: 400;
  line-height: 1.35;
  padding: 7px 10px;
  border-radius: 6px;
  border: 1px solid var(--container-border, #444);
  background: var(--container-bg, #1e1e1e);
  color: var(--fg, #eee);
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.35);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.12s ease;
  z-index: 60;
}
/* Below-anchor variant for elements near the top edge (e.g. the top bar). */
.oh-tip-below::after {
  bottom: auto;
  top: calc(100% + 8px);
}
.oh-tip:hover::after,
.oh-tip:focus-visible::after {
  opacity: 1;
}

.lib-header {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  margin-bottom: 1.25rem;
  flex-wrap: wrap;
}
.lib-header h1 {
  margin: 0;
  flex: 1 1 auto;
  font-size: 1.6rem;
}
.lib-header button,
.lib-header a {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  padding: 0.4rem 0.8rem;
  border: 1px solid var(--container-border, #d5d0c8);
  border-radius: 6px;
  background: var(--bg-card, #fff);
  color: var(--fg);
  font-size: 0.85rem;
  text-decoration: none;
  cursor: pointer;
  white-space: nowrap;
}
.lib-header button:hover,
.lib-header a:hover {
  border-color: var(--oh-accent);
  color: var(--oh-accent);
}

.lib-tabs {
  display: flex;
  gap: 0.25rem;
  border-bottom: 1px solid var(--container-border, #d5d0c8);
  margin-bottom: 1.25rem;
}
.lib-tabs a {
  padding: 0.45rem 0.9rem;
  color: var(--fg-muted, #888);
  text-decoration: none;
  font-size: 0.9rem;
  border-bottom: 2px solid transparent;
  margin-bottom: -1px;
}
.lib-tabs a:hover { color: var(--fg); }
.lib-tabs a.active {
  color: var(--oh-accent);
  border-bottom-color: var(--oh-accent);
  font-weight: 600;
}

.lib-notion-card {
  border: 1px solid var(--container-border, #d5d0c8);
  border-left: 3px solid var(--oh-accent);
  border-radius: 8px;
  padding: 0.9rem 1.1rem;
  margin-bottom: 1.25rem;
  background: var(--bg-card, #fff);
  font-size: 0.9rem;
}
.lib-notion-pick {
  display: flex;
  gap: 0.5rem;
  align-items: center;
  margin-top: 0.6rem;
  flex-wrap: wrap;
}
.lib-notion-pick select {
  padding: 0.4rem 0.6rem;
  border: 1px solid var(--container-border, #d5d0c8);
  border-radius: 6px;
  background: var(--bg-card, #fff);
  color: var(--fg);
  font-size: 0.85rem;
  min-width: 16rem;
}
.lib-notion-pick button {
  padding: 0.4rem 0.8rem;
  border: none;
  border-radius: 6px;
  background: var(--oh-accent);
  color: #fff;
  font-size: 0.85rem;
  cursor: pointer;
}
.lib-notion-connect {
  display: inline-block;
  margin-top: 0.6rem;
  padding: 0.4rem 0.9rem;
  background: var(--oh-accent);
  color: #fff;
  border-radius: 6px;
  text-decoration: none;
}
.lib-notion-hint {
  margin-top: 0.5rem;
  font-size: 0.8rem;
  color: var(--fg-muted, #888);
}

.lib-item {
  border: 1px solid var(--container-border, #d5d0c8);
  border-radius: 8px;
  padding: 1rem 1.15rem;
  margin-bottom: 0.85rem;
  background: var(--bg-card, #fff);
}
.lib-item h2 {
  margin: 0 0 0.3rem;
  font-size: 1.05rem;
  font-weight: 600;
  display: flex;
  align-items: center;
  gap: 0.6rem;
  flex-wrap: wrap;
}
.lib-item h2 a {
  color: var(--fg);
  text-decoration: none;
}
.lib-item h2 a:hover { color: var(--oh-accent); }
.lib-meta {
  font-size: 0.82rem;
  color: var(--fg-muted, #888);
  margin-bottom: 0.6rem;
}
.lib-actions {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  flex-wrap: wrap;
  font-size: 0.82rem;
}
.lib-actions button,
.lib-actions a {
  color: var(--oh-accent);
  background: none;
  border: none;
  padding: 0;
  font-size: 0.82rem;
  cursor: pointer;
  text-decoration: none;
}
.lib-actions button:hover,
.lib-actions a:hover { text-decoration: underline; }
.lib-status-select {
  margin-left: auto;
  padding: 0.25rem 0.4rem;
  border: 1px solid var(--container-border, #d5d0c8);
  border-radius: 6px;
  background: var(--bg-card, #fff);
  color: var(--fg);
  font-size: 0.8rem;
}
.lib-remove-btn { color: var(--oh-red, #c0392b) !important; }
