/* ═══════════════════════════════════════════════════════════════════════════
   COMPOSE — Citations v3
   Compact popover that opens from the toolbar citation button.
   Same visual language as the link popover — consistent popup style.
   No shadows. No side-panel. No full-screen takeover.
   ═══════════════════════════════════════════════════════════════════════════ */

/* ── Citation popover shell ──────────────────────────────────────────── */
#citation-sheet {
  position: fixed;
  top: calc(var(--topbar-h) + var(--toolbar-h) + 8px);
  left: 50%;
  transform: translateX(-50%) translateY(-8px);
  z-index: calc(var(--z-toolbar) + 10);
  background: var(--bg-card);
  border: 1px solid var(--border-strong);
  border-radius: var(--r-lg);
  width: min(480px, calc(100vw - 32px));
  /* Explicit height = max-height so flex children (cite-pop-body) can grow.
     flex: 1 1 0 on a child requires a DEFINITE height on the parent.
     max-height alone is not definite for flex purposes — height is. */
  height: min(82dvh, 680px);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  opacity: 0;
  pointer-events: none;
  transition: opacity var(--t-fast) var(--ease), transform var(--t-fast) var(--ease);
}

#citation-sheet:not([hidden]) {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
  pointer-events: auto;
}

/* ── Popover header ──────────────────────────────────────────────────── */
.cite-pop-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 14px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.cite-pop-title {
  font-size: 13px;
  font-weight: 600;
  color: var(--text);
  letter-spacing: -0.01em;
}

.cite-pop-close {
  width: 24px; height: 24px;
  border-radius: 6px;
  display: flex; align-items: center; justify-content: center;
  color: var(--text-muted);
  transition: background var(--t-fast) var(--ease), color var(--t-fast) var(--ease);
}
.cite-pop-close svg { width: 11px; height: 11px; }
.cite-pop-close:hover { background: var(--fill-muted); color: var(--text); }

/* ── Scrollable body ─────────────────────────────────────────────────── */
.cite-pop-body {
  flex: 1 1 0;
  overflow-y: auto;
  padding: 14px 16px;
}

.cite-pop-body::-webkit-scrollbar { width: 4px; }
.cite-pop-body::-webkit-scrollbar-track { background: transparent; }
.cite-pop-body::-webkit-scrollbar-thumb { background: var(--border-strong); border-radius: 99px; }

/* ── Section label ───────────────────────────────────────────────────── */
.cite-pop-label {
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--text-muted);
  margin-bottom: 8px;
}

/* ── Type / style / mode tabs ─────────────────────────────────────────── */
.citation-type-tabs {
  display: flex;
  gap: 4px;
  flex-wrap: wrap;
  margin-bottom: 10px;
}

.citation-type-tab {
  height: 26px;
  padding: 0 10px;
  border-radius: 6px;
  font-size: 12px;
  font-weight: 500;
  color: var(--text-sec);
  background: var(--fill-muted);
  border: 1.5px solid transparent;
  transition: all var(--t-fast) var(--ease);
  letter-spacing: -0.01em;
}
.citation-type-tab:hover { background: var(--fill-active); color: var(--text); }
.citation-type-tab.is-active {
  background: var(--fill-selected);
  border-color: rgba(var(--accent-rgb), .35);
  color: var(--accent);
  font-weight: 600;
}

/* ── Fields grid ─────────────────────────────────────────────────────── */
.citation-fields {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin-bottom: 4px;
}

.field--full { grid-column: 1 / -1; }

/* Field label */
.citation-row-label {
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.07em;
  text-transform: uppercase;
  color: var(--text-muted);
  display: block;
  margin-bottom: 4px;
  margin-top: 8px;
  padding-top: 8px;
  border-top: 1px solid var(--border);
}
.citation-row-label:first-of-type {
  border-top: none;
  margin-top: 0;
  padding-top: 0;
}

/* ── Footer with insert button ───────────────────────────────────────── */
.cite-pop-footer {
  padding: 10px 14px;
  border-top: 1px solid var(--border);
  flex-shrink: 0;
}

/* ── Citation list (in sidebar outline) ─────────────────────────────── */
.citation-list-item {
  padding: 6px 10px;
  border-radius: var(--r-md);
  cursor: pointer;
  transition: background var(--t-fast) var(--ease);
  margin-bottom: 2px;
}
.citation-list-item:hover { background: var(--fill-hover); }
.citation-list-ref { font-size: 11px; font-weight: 700; color: var(--accent); margin-bottom: 2px; }
.citation-list-text { font-size: 12px; color: var(--text-sec); line-height: 1.5; }

/* ── Mobile ──────────────────────────────────────────────────────────── */
@media (max-width: 767px) {
  #citation-sheet {
    /* On mobile: toolbar is fixed at bottom.
       Anchor sheet between topbar bottom and bottom toolbar top.
       position:fixed + top + bottom = browser computes a definite height,
       so flex children (cite-pop-body) can grow to fill it correctly.
       DO NOT set height:auto — that collapses the definite height. */
    top: calc(var(--topbar-h) + 8px) !important;
    bottom: calc(var(--toolbar-h) + env(safe-area-inset-bottom, 0px) + 8px) !important;
    left: 12px !important;
    right: 12px !important;
    width: auto !important;
    /* Override the desktop height — let top+bottom determine it */
    height: unset !important;
    max-height: unset !important;
    transform: none !important;
    opacity: 0;
    pointer-events: none;
    transition: opacity var(--t-fast) var(--ease);
  }
  #citation-sheet:not([hidden]) {
    opacity: 1 !important;
    pointer-events: auto !important;
    transform: none !important;
  }
}

/* ── Backdrop for citation popover ──────────────────────────────────── */
#citation-backdrop {
  display: none;
}

/* ── Field validation error ──────────────────────────────────────────── */
.cite-field-error {
  font-size: 12px;
  color: var(--status-error);
  margin: 6px 0 0;
  padding: 6px 10px;
  background: rgba(138, 48, 48, 0.08);
  border-radius: var(--r-sm);
  border: 1px solid rgba(138, 48, 48, 0.18);
}
