/* Next.js shell overrides (loaded after FastAPI /static/style.css) */

:root {
  --app-header-h: 0px;
  --app-sidebar-w: 280px;
}

@media (max-width: 768px) {
  :root {
    --app-header-h: 0px;
  }
}

/* Header is no longer used; keep pages flush to top. */
body {
  padding-top: 0 !important;
}

/* Prevent scroll chaining / rubber-band where supported */
html,
body {
  overscroll-behavior-y: none;
}

/* Subtle page enter animation (used to reduce "severe" route transitions) */
.qg-enter {
  opacity: 0;
}

.qg-enter.qg-enter-active {
  opacity: 1;
  transition: opacity 180ms ease;
}

@media (prefers-reduced-motion: reduce) {
  .qg-enter,
  .qg-enter.qg-enter-active {
    opacity: 1;
    transition: none;
  }
}

.header-right {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: 12px;
}

/* Signed-in header layout: align logo over sidebar, nav over main column. */
.qg-header-signed-in {
  padding-left: 18px !important;
  padding-right: 18px !important;
}

.qg-header-signed-in .header-content {
  max-width: none !important;
  margin: 0 !important;
}

.qg-header-signed-in .header-left {
  width: 100%;
  display: grid !important;
  grid-template-columns: var(--app-sidebar-w) 1fr auto;
  align-items: center;
  gap: 18px;
}

.qg-header-signed-in .logo {
  justify-self: center;
}

.qg-header-signed-in .top-nav {
  justify-self: start;
  margin-left: 6px;
}

.qg-header-signed-in .header-right {
  justify-self: end;
  margin-left: 0;
}

@media (max-width: 900px) {
  .qg-header-signed-in .header-left {
    grid-template-columns: auto 1fr auto;
  }
  .qg-header-signed-in .logo {
    justify-self: start;
  }
  .qg-header-signed-in .top-nav {
    justify-self: center;
    margin-left: 0;
  }
}

.auth-chip {
  appearance: none;
  background: transparent;
  border: none;
  padding: 0;
  font: inherit;
  color: inherit;
}

.examples-link {
  color: inherit;
  text-decoration: underline;
  text-underline-offset: 2px;
}

/* System notices (e.g., conversation compaction) */
.system-message .message-content {
  display: inline-block;
  background: rgba(250, 204, 21, 0.16);
  border: 1px solid rgba(250, 204, 21, 0.35);
  color: var(--text-primary);
  padding: 10px 12px;
  border-radius: 10px;
  font-size: 13px;
  line-height: 1.35;
  white-space: pre-wrap;
}

.system-message {
  text-align: center;
}

/* Ask AI quota hint under the composer */
.quota-hint {
  font-size: 12px;
  color: var(--text-secondary);
  padding: 8px 2px 0 2px;
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
}

.quota-buy-link {
  appearance: none;
  border: 0;
  background: none;
  padding: 0;
  color: var(--text-secondary);
  font: inherit;
  font-weight: 500;
  cursor: pointer;
  text-decoration: underline;
  text-underline-offset: 2px;
}

.quota-buy-link:disabled {
  cursor: default;
  opacity: 0.7;
  text-decoration: none;
}

.quota-error {
  color: #9b1c1c;
}

.qg-top-right {
  position: fixed;
  top: 12px;
  right: 14px;
  z-index: 140;
}

/* Signed-in shell layout: sidebar + legacy chat */
.app-shell {
  display: flex;
  min-height: calc(100vh - var(--app-header-h));
}

.app-shell.qg-sidebar-collapsed {
  --app-sidebar-w: 56px;
}

.app-sidebar {
  width: var(--app-sidebar-w);
  flex: 0 0 auto;
  border-right: 1px solid var(--border-gray);
  background: var(--white);
  padding: 14px 12px;
  position: fixed;
  top: var(--app-header-h);
  left: 0;
  height: calc(100vh - var(--app-header-h));
  overflow: auto;
  z-index: 90;
  transition: width 110ms ease-out, padding 110ms ease-out;
  will-change: width;
}

.app-shell.qg-sidebar-collapsed .app-sidebar {
  /* Keep top padding consistent so the toggle doesn't jump vertically. */
  padding: 14px 12px;
}

.app-shell.qg-sidebar-collapsed .sidebar-nav,
.app-shell.qg-sidebar-collapsed .sidebar-spacer,
.app-shell.qg-sidebar-collapsed .sidebar-title,
.app-shell.qg-sidebar-collapsed .sidebar-list,
.app-shell.qg-sidebar-collapsed .sidebar-error,
.app-shell.qg-sidebar-collapsed .sidebar-empty {
  display: none;
}

.app-shell.qg-sidebar-collapsed .sidebar-brand {
  /* Keep a placeholder so the toggle's vertical alignment stays identical,
     but don't let the (large) logo force the collapsed sidebar width. */
  visibility: hidden;
  width: 1px;
  overflow: hidden;
  padding: 0;
}

.app-shell.qg-sidebar-collapsed .sidebar-brand-logo {
  width: 1px;
  height: 40px;
}

.app-shell.qg-sidebar-collapsed .sidebar-toggle {
  grid-column: 1 / -1;
  justify-self: center;
  transform: translateX(2px);
}

.sidebar-title {
  font-size: 12px;
  font-weight: 700;
  color: var(--text-primary);
  margin-bottom: 6px;
}

.sidebar-new {
  width: 100%;
  background: var(--light-gray);
  border: 1px solid var(--border-gray);
  color: var(--text-primary);
  padding: 10px 12px;
  border-radius: 10px;
  font-size: 13px;
  cursor: pointer;
  text-align: left;
  margin-bottom: 12px;
}

.sidebar-new:hover {
  background: var(--border-gray);
}

.sidebar-new-link {
  appearance: none;
  background: transparent;
  border: none;
  padding: 0;
  margin: 0;
  font: inherit;
  font-size: 13px;
  font-weight: 500;
  color: var(--text-secondary);
  cursor: pointer;
  text-align: left;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  line-height: 1.1;
  text-decoration: none;
}

.sidebar-top {
  display: grid;
  grid-template-columns: 1fr auto;
  grid-template-rows: 44px;
  align-items: center;
  height: 44px;
  min-height: 44px;
  margin-bottom: 10px;
}

.sidebar-brand {
  grid-column: 1;
  grid-row: 1;
  display: inline-flex;
  align-items: center;
  gap: 10px;
  text-decoration: none;
  color: var(--text-primary);
  padding: 2px 2px;
}

.sidebar-brand-logo {
  width: 130px;
  height: 40px;
  object-fit: contain;
}

.sidebar-toggle {
  grid-column: 2;
  grid-row: 1;
  justify-self: end;
  align-self: center;
  appearance: none;
  background: transparent;
  border: none;
  color: var(--text-secondary);
  border-radius: 0;
  padding: 2px;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.sidebar-toggle:hover {
  color: var(--text-primary);
}

.sidebar-new-link:hover {
  color: var(--text-primary);
  text-decoration: underline;
  text-underline-offset: 2px;
}

.sidebar-new-label {
  line-height: 1.2;
}

.sidebar-spacer {
  height: 18px;
}

.sidebar-nav {
  display: flex;
  flex-direction: column;
  gap: 2px;
  margin-top: 0;
}

.sidebar-nav-icon {
  display: inline-flex;
  flex: 0 0 32px;
  width: 32px;
  align-items: center;
  justify-content: center;
  line-height: 0;
}

.sidebar-nav-icon-img {
  width: 18px;
  height: 18px;
  display: block;
  object-fit: contain;
}

.sidebar-nav-label {
  display: inline;
  white-space: nowrap !important;
  overflow-wrap: normal !important;
  word-break: keep-all !important;
  hyphens: none !important;
}

.sidebar-nav-item {
  appearance: none;
  background: transparent;
  border: none;
  text-decoration: none;
  font: inherit;
  cursor: pointer;
  box-sizing: border-box;
  display: flex;
  align-items: center;
  width: 100%;
  min-height: 34px;
  text-align: left;
  padding: 8px 8px 8px 0;
  border-radius: 10px;
  color: var(--text-primary);
  font-size: 15px;
  font-weight: 650;
  white-space: nowrap !important;
  overflow: hidden;
  text-overflow: ellipsis;
  overflow-wrap: normal !important;
  word-break: keep-all !important;
  hyphens: none !important;
}

.sidebar-nav-item-new {
  font-family: "Times New Roman", Times, serif;
  font-size: 13px;
  font-weight: 500;
  color: var(--text-secondary);
}

.sidebar-nav-item-new:hover {
  color: var(--text-primary);
  text-decoration: underline;
  text-underline-offset: 2px;
  background: transparent;
}

.sidebar-nav-item:hover {
  background: var(--light-gray);
}

.sidebar-nav-item-active {
  background: var(--light-gray);
}

.app-shell.qg-sidebar-collapsed .sidebar-nav {
  display: flex;
  margin-top: 0;
  gap: 2px;
}

.app-shell.qg-sidebar-collapsed .sidebar-nav-item {
  display: flex;
  align-items: center;
  justify-content: flex-start;
  min-height: 34px;
  padding: 8px 8px 8px 0;
  border-radius: 10px;
}

.app-shell.qg-sidebar-collapsed .sidebar-nav-icon {
  display: inline-flex;
  color: var(--text-primary);
}

.app-shell.qg-sidebar-collapsed .sidebar-nav-item-new .sidebar-nav-icon {
  color: inherit;
}

.app-shell.qg-sidebar-collapsed .sidebar-nav-label {
  display: inline-block;
  width: 0;
  min-width: 0;
  overflow: hidden;
  opacity: 0;
  pointer-events: none;
  white-space: nowrap !important;
}

.app-shell.qg-sidebar-expanding .sidebar-recents {
  display: none;
}

.app-shell.qg-sidebar-collapsed .sidebar-nav-item-new:hover {
  color: var(--text-primary);
  text-decoration: underline;
  text-underline-offset: 2px;
  background: transparent;
}

.sidebar-error,
.sidebar-empty {
  font-size: 13px;
  color: var(--text-secondary);
  padding: 6px 2px;
}

.sidebar-inline-link {
  appearance: none;
  background: transparent;
  border: none;
  padding: 0;
  margin: 0;
  font: inherit;
  font-size: 12px;
  color: var(--text-secondary);
  text-decoration: underline;
  text-underline-offset: 2px;
  cursor: pointer;
}

.sidebar-inline-link:hover {
  color: var(--text-primary);
}

.sidebar-list {
  display: flex;
  flex-direction: column;
  gap: 0;
  border-top: 1px solid var(--border-gray);
}

.sidebar-item {
  width: 100%;
  border: none;
  border-bottom: 1px solid var(--border-gray);
  background: transparent;
  border-radius: 0;
  padding: 10px 4px;
  cursor: pointer;
  text-align: left;
}

.sidebar-item:hover {
  background: var(--light-gray);
}

.sidebar-item-active {
  background: var(--light-gray);
}

.sidebar-item-title {
  font-size: 13px;
  font-weight: 400;
  font-family: "Times New Roman", Times, serif;
  color: var(--text-primary);
  margin-bottom: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  display: block;
}

.sidebar-item-meta {
  font-size: 12px;
  color: var(--text-tertiary);
}

.app-main {
  flex: 1;
  min-width: 0;
  margin-left: var(--app-sidebar-w);
  transition: margin-left 110ms ease-out;
  will-change: margin-left;
}

/* Re-center the legacy fixed input within the main column (avoid overlapping sidebar) */
.app-shell .input-container {
  left: calc(50% + (var(--app-sidebar-w) / 2));
  width: calc(100% - 40px - var(--app-sidebar-w));
  transition: left 110ms ease-out, width 110ms ease-out;
  will-change: left, width;
}

.app-shell .input-cover {
  left: var(--app-sidebar-w);
  transition: left 110ms ease-out;
  will-change: left;
}

@media (max-width: 900px) {
  .app-shell {
    flex-direction: column;
  }
  .app-sidebar {
    position: static;
    width: auto;
    height: auto;
    border-right: none;
    border-bottom: 1px solid var(--border-gray);
    transition: none;
    will-change: auto;
  }
  .app-shell .input-container {
    left: 50%;
    width: calc(100% - 40px);
    transition: none;
    will-change: auto;
  }
  .app-shell .input-cover {
    left: 0;
    transition: none;
    will-change: auto;
  }
  .app-main {
    margin-left: 0;
    transition: none;
    will-change: auto;
  }
}

@media (prefers-reduced-motion: reduce) {
  .app-sidebar,
  .app-main,
  .app-shell .input-container,
  .app-shell .input-cover {
    transition: none !important;
    will-change: auto !important;
  }
}

@media (prefers-reduced-motion: reduce) {
  /* No special expanding behavior when motion is reduced. */
}

/* Explore page: study picker title */
.explore-study-title {
  font-family: "Times New Roman", Times, serif;
  color: var(--text-primary);
  font-size: 16px;
  font-weight: 600;
  padding-left: 12px;
  margin: 0 0 10px 0;
}

/* Keep the title text aligned with the input's text inset. */

.explore-selected-title {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.explore-landing-block {
  margin-top: 28px;
}

.explore-landing {
  max-width: 820px;
  margin: 0 auto;
}

.explore-landing .landing-headline {
  font-family: "Times New Roman", Times, serif;
}

.explore-hero-search-row {
  width: 100%;
}

.explore-hero-search-row .explore-field,
.explore-hero-search-row .explore-field-row,
.explore-hero-search-row .explore-input-wrap {
  width: 100%;
}

.explore-hero-search {
  height: 52px;
  padding: 0 16px;
  border-radius: 14px;
  font-size: 16px;
  box-shadow: var(--shadow-sm);
  font-family: "Times New Roman", Times, serif;
}

.explore-hero-search::placeholder {
  font-family: "Times New Roman", Times, serif;
}

.explore-clear-hidden {
  display: none !important;
}

.explore-cohorts {
  width: 100%;
}

.explore-cohorts .landing-study-name {
  font-family: "Times New Roman", Times, serif;
}

.explore-cohorts-label {
  font-family: "Times New Roman", Times, serif;
  font-size: 14px;
  font-weight: 400;
  color: var(--text-secondary);
  margin-bottom: 12px;
}

.explore-landing .explore-auth-line {
  margin-top: 54px;
  margin-bottom: 0;
  font-size: 18px;
  line-height: 1.4;
  color: var(--text-tertiary);
  font-weight: 400;
  font-family: "Times New Roman", Times, serif;
}

.explore-landing .explore-auth-line .auth-chip {
  color: var(--text-secondary);
  font-family: inherit;
}

.explore-landing .explore-auth-line .auth-chip:hover {
  color: var(--text-primary);
}

.explore-cohorts {
  margin-top: 42px;
}

/* Shared "open link" icon (matches Explore result icon, but safe for sanitized markdown). */
.qg-ext-icon {
  width: 14px;
  height: 14px;
  display: inline-block;
  background-color: currentColor;
  vertical-align: middle;
  -webkit-mask-repeat: no-repeat;
  mask-repeat: no-repeat;
  -webkit-mask-position: center;
  mask-position: center;
  -webkit-mask-size: contain;
  mask-size: contain;
  -webkit-mask-image: url("data:image/svg+xml,%3Csvg%20xmlns%3D%27http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg%27%20viewBox%3D%270%200%2024%2024%27%20fill%3D%27none%27%3E%3Cpath%20d%3D%27M14%205h5v5%27%20stroke%3D%27%23000%27%20stroke-width%3D%272.2%27%20stroke-linecap%3D%27round%27%20stroke-linejoin%3D%27round%27%2F%3E%3Cpath%20d%3D%27M10%2014L19%205%27%20stroke%3D%27%23000%27%20stroke-width%3D%272.2%27%20stroke-linecap%3D%27round%27%20stroke-linejoin%3D%27round%27%2F%3E%3Cpath%20d%3D%27M19%2014v4a2%202%200%200%201-2%202H7a2%202%200%200%201-2-2V7a2%202%200%200%201%202-2h4%27%20stroke%3D%27%23000%27%20stroke-width%3D%272.2%27%20stroke-linecap%3D%27round%27%20stroke-linejoin%3D%27round%27%2F%3E%3C%2Fsvg%3E");
  mask-image: url("data:image/svg+xml,%3Csvg%20xmlns%3D%27http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg%27%20viewBox%3D%270%200%2024%2024%27%20fill%3D%27none%27%3E%3Cpath%20d%3D%27M14%205h5v5%27%20stroke%3D%27%23000%27%20stroke-width%3D%272.2%27%20stroke-linecap%3D%27round%27%20stroke-linejoin%3D%27round%27%2F%3E%3Cpath%20d%3D%27M10%2014L19%205%27%20stroke%3D%27%23000%27%20stroke-width%3D%272.2%27%20stroke-linecap%3D%27round%27%20stroke-linejoin%3D%27round%27%2F%3E%3Cpath%20d%3D%27M19%2014v4a2%202%200%200%201-2%202H7a2%202%200%200%201-2-2V7a2%202%200%200%201%202-2h4%27%20stroke%3D%27%23000%27%20stroke-width%3D%272.2%27%20stroke-linecap%3D%27round%27%20stroke-linejoin%3D%27round%27%2F%3E%3C%2Fsvg%3E");
}

/* Persistent Feedback button + modal */
.feedback-fab {
  position: fixed;
  right: 18px;
  bottom: 18px;
  z-index: 200;
  appearance: none;
  background: transparent;
  border: none;
  font-family: "Times New Roman", Times, serif;
  color: var(--text-secondary);
  padding: 8px 10px;
  border-radius: 10px;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
}

.feedback-fab:hover {
  color: var(--text-primary);
  text-decoration: underline;
  text-underline-offset: 2px;
}

.feedback-modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.18);
  z-index: 220;
  display: flex;
  align-items: flex-end;
  justify-content: flex-end;
  padding: 16px;
}

.feedback-modal {
  width: min(520px, calc(100vw - 32px));
  background: var(--white);
  border: 1px solid var(--border-gray);
  border-radius: 12px;
  box-shadow: var(--shadow-lg);
  padding: 14px 14px 12px 14px;
}

.feedback-modal-title {
  font-size: 14px;
  font-weight: 700;
  color: var(--text-primary);
  margin-bottom: 2px;
}

.feedback-modal-subtitle {
  font-size: 13px;
  color: var(--text-secondary);
  margin-bottom: 12px;
}

.feedback-label {
  display: block;
  font-size: 12px;
  color: var(--text-secondary);
  margin-bottom: 10px;
}

.feedback-textarea,
.feedback-input {
  display: block;
  width: 100%;
  margin-top: 6px;
  padding: 10px 10px;
  border-radius: 10px;
  border: 1px solid var(--border-gray);
  background: var(--white);
  font-family: inherit;
  font-size: 13px;
  outline: none;
}

.feedback-textarea:focus,
.feedback-input:focus {
  border-color: rgba(0, 102, 204, 0.35);
  box-shadow: 0 0 0 3px rgba(0, 102, 204, 0.08);
}

.feedback-meta {
  font-size: 12px;
  color: var(--text-secondary);
  margin: 6px 0 10px 0;
}

.feedback-url {
  color: var(--text-tertiary);
}

.feedback-error {
  font-size: 13px;
  color: #B00020;
  margin: 0 0 10px 0;
}

.feedback-success {
  font-size: 13px;
  color: var(--success);
  margin: 0 0 10px 0;
}

.feedback-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  margin-top: 6px;
}

.feedback-btn {
  appearance: none;
  border: 1px solid var(--border-gray);
  background: var(--light-gray);
  color: var(--text-primary);
  padding: 8px 10px;
  border-radius: 10px;
  font-size: 13px;
  cursor: pointer;
}

.feedback-btn:hover {
  background: var(--border-gray);
}

.feedback-btn:disabled {
  opacity: 0.65;
  cursor: default;
}

.feedback-btn-secondary {
  background: transparent;
  color: var(--text-secondary);
}

.feedback-btn-secondary:hover {
  background: var(--light-gray);
  color: var(--text-primary);
}

@media (max-width: 600px) {
  .feedback-fab {
    right: 12px;
    bottom: 12px;
  }
  .feedback-modal-overlay {
    align-items: flex-end;
    justify-content: center;
  }
}
