/* ── Quizzy Application Stylesheet ──
 *
 * This app is migrating to the official Clavisco Design System
 * (vendored, unmodified, in vendor/ds-styles/{tokens,components}.css).
 * Prefer `.cl-*` classes for anything the DS already provides — see
 * https://cl-design-system.clavisco.com/components/ for the catalogue.
 *
 * This file holds ONLY app-level additions that the DS does not provide,
 * namespaced `.qz-*` (Quizzy). Never redefine or override `.cl-*` styles
 * here; app classes only supply behavior or layout absent from the DS.
 *
 * Load order: tokens.css -> components.css -> application.css (this file)
 * -> tailwind.css. All tokens used below (--accent-*, --fg-*, --bg-*,
 * --border-*, --space-*, --radius-*, --fs-*) come from vendor/ds-styles/tokens.css.
 */

@layer components {
  /* ── Heading size fallback ──
   * The DS deliberately leaves bare <h1>/<h2> font-size unset (components.css
   * only sets weight/color/letter-spacing on h1-h4) so pages size headings
   * explicitly via `.cl-page-title` etc. Tailwind's preflight resets
   * `font-size: inherit` on all headings, so any page without a `.cl-*`
   * title class collapses its <h1> to body-text size. `.qz` on <body> gives
   * every page (migrated or not) a sane fallback; more specific `.cl-*`
   * selectors in the same layer (e.g. `.cl-card-head h2`) still win by
   * specificity.
   */
  .qz h1 { font-size: var(--fs-h1); }
  .qz h2 { font-size: var(--fs-h2); }

  /* Centered page column. Narrow pages opt in from the layout. */
  .qz-page {
    width: 100%;
    max-width: 1200px;
    margin-inline: auto;
  }

  .qz-page--narrow {
    max-width: 720px;
  }

  /* Two-language question text: Spanish on the first line, English on the second. */
  .qz-lang-stack {
    display: flex;
    flex-direction: column;
    gap: var(--space-3);
  }

  .qz-lang-label {
    margin-right: var(--space-2);
    color: var(--fg-3);
    font-size: var(--fs-label);
    font-weight: 600;
  }

  .qz-lang-en {
    color: var(--fg-3);
  }

  .qz-form-error {
    color: var(--neg-600);
    font-size: var(--fs-small);
    margin: 0;
  }

  /* ── Loading spinner ── */
  .qz-spinner {
    display: inline-block;
    width: 20px;
    height: 20px;
    border: 2px solid var(--border-1);
    border-top-color: var(--accent-500);
    border-radius: 50%;
    animation: qz-spin 0.6s linear infinite;
  }

  .qz-spinner--lg {
    width: 40px;
    height: 40px;
    border-width: 3px;
  }

  /* ── Responsive KPI grid (upstream `.cl-grid-4` is fixed-width) ── */
  .qz-kpi-grid {
    display: grid;
    grid-template-columns: 1fr;
    gap: var(--space-5);
  }

  @media (min-width: 768px) {
    .qz-kpi-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  }

  @media (min-width: 1024px) {
    .qz-kpi-grid { grid-template-columns: repeat(4, minmax(0, 1fr)); }
  }

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

  /* ── Star rating ── */
  .qz-rating {
    display: inline-flex;
    gap: 2px;
  }

  .qz-star {
    cursor: pointer;
    color: var(--fg-4);
    transition: color 0.1s;
    font-size: 18px;
    background: none;
    border: none;
    padding: 0;
  }

  .qz-star--filled {
    color: var(--warn-500);
  }

  .qz-star:hover {
    color: var(--warn-500);
  }

  .qz-star:focus-visible {
    outline: none;
    box-shadow: var(--shadow-focus);
    border-radius: var(--radius-1);
  }

  .qz-tag-remove {
    display: inline-grid;
    place-items: center;
    padding: 0;
    border: 0;
    background: transparent;
  }

  .qz-tag-remove:focus-visible {
    outline: none;
    box-shadow: var(--shadow-focus);
    border-radius: var(--radius-1);
  }

  /* ── Mobile nav drawer ── */
  .qz-mobile-nav {
    display: none;
    position: fixed;
    top: var(--h-shell);
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 39;
    background: var(--bg-canvas);
    padding: var(--space-6);
    overflow-y: auto;
  }

  .qz-mobile-nav--open {
    display: flex;
    flex-direction: column;
    gap: var(--space-2);
  }

  .qz-mobile-nav-link {
    display: flex;
    align-items: center;
    gap: var(--space-3);
    padding: var(--space-5) var(--space-6);
    border-radius: var(--radius-3);
    font-size: var(--fs-subtitle);
    color: var(--fg-1);
  }

  .qz-mobile-nav-link:hover {
    background: var(--bg-hover);
  }

  .qz-mobile-nav-link--active {
    background: var(--bg-selected);
    color: var(--fg-selected);
    font-weight: 600;
  }

  .qz-mobile-nav-signout {
    margin-top: var(--space-4);
  }

  /* ── Recent activity list ── */
  .qz-activity {
    list-style: none;
    margin: 0;
    padding: 0;
  }

  .qz-activity-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: var(--space-4);
    padding: var(--space-4) 0;
    border-bottom: 1px solid var(--border-1);
  }

  .qz-activity-item:last-child {
    border-bottom: none;
  }

  .qz-activity-item-content {
    display: flex;
    flex-direction: column;
    gap: 2px;
    flex: 1;
    min-width: 0;
  }

  .qz-activity-item-title {
    font-size: var(--fs-body);
    color: var(--fg-1);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .qz-activity-item-time {
    font-size: var(--fs-label);
    color: var(--fg-3);
  }

  /* ── Fill-in-the-blank placeholder ── */
  .qz-blank {
    display: inline-block;
    min-width: 120px;
    border-bottom: 2px solid var(--accent-500);
    margin: 0 4px;
  }

  /* ── Native checkbox accent ── */
  .qz-checkbox {
    accent-color: var(--accent-500);
    cursor: pointer;
  }

  .qz-interest-list {
    max-height: 320px;
    overflow: auto;
    display: flex;
    flex-direction: column;
    gap: var(--space-2);
  }

  .qz-interest-chip {
    display: inline-flex;
    align-items: center;
    gap: var(--space-2);
    padding: var(--space-2) var(--space-3);
    border: 1px solid var(--border-2);
    border-radius: var(--radius-pill);
    color: var(--fg-2);
    background: var(--bg-canvas);
    cursor: pointer;
    max-width: 100%;
    overflow-wrap: anywhere;
    min-height: 44px;
  }

  .qz-interest-chip:has(input:checked) {
    background: var(--bg-selected);
    border-color: var(--accent-500);
    color: var(--fg-1);
  }

  .qz-interest-chip:focus-within {
    outline: 2px solid var(--accent-500);
    outline-offset: 2px;
  }

  .qz-interest-chip input { accent-color: var(--accent-500); }
  .qz-interest-owner { display: block; color: var(--fg-3); font-size: var(--fs-small); }
  [data-controller="topic-interests"] [hidden] { display: none; }

  .qz-issue-panel {
    position: fixed;
    z-index: 40;
    right: var(--space-6);
    bottom: var(--space-6);
    width: min(28rem, calc(100vw - 2 * var(--space-6)));
    max-height: min(40rem, calc(100vh - var(--h-shell) - var(--space-8)));
    display: flex;
    flex-direction: column;
  }

  .qz-issue-panel[hidden] {
    display: none;
  }

  .qz-issue-panel-scroll {
    max-height: min(32rem, calc(100vh - var(--h-shell) - 8rem));
    overflow: auto;
  }

  .qz-issue-thumbs {
    display: flex;
    flex-wrap: wrap;
    gap: var(--space-2);
    margin-bottom: var(--space-2);
  }

  .qz-issue-thumb {
    display: flex;
    flex-direction: column;
    gap: var(--space-1);
    font-size: var(--fs-small);
    color: var(--fg-3);
  }

  .qz-issue-thumb img {
    width: 64px;
    height: 64px;
    object-fit: cover;
    border-radius: var(--radius-2);
  }

  .qz-issue-thumb--error {
    color: var(--neg-600);
  }
}
