/* ============================================================
   AI Auto-organize / Auto-file  (js/autofile.js)
   ------------------------------------------------------------
   A non-intrusive right-side suggestions panel + a subtle
   "Organize" affordance pill. Theme-aware: every colour comes
   from style.css custom properties that flip in dark mode.
   All classes are `af-` prefixed. Sits above the page content
   but below modals/search (z ~700 vs modals ~500? — no scrim,
   so it never blocks the page). Uses 720 to clear sidebars.
   ============================================================ */

/* ---------------- side panel ---------------- */
.af-panel {
  position: fixed;
  top: 14px;
  right: 14px;
  bottom: 14px;
  z-index: 720;
  width: 340px;
  max-width: calc(100vw - 28px);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  background: var(--bg-modal);
  border: 1px solid var(--border);
  border-radius: var(--radius-pane);
  box-shadow: var(--shadow-pane);
  transform: translateX(calc(100% + 24px));
  opacity: 0;
  transition: transform 0.22s cubic-bezier(0.22, 1, 0.36, 1), opacity 0.22s ease;
}
.af-panel.af-in {
  transform: none;
  opacity: 1;
}
@media (prefers-reduced-motion: reduce) {
  .af-panel { transition: none; }
}

/* ---------------- header ---------------- */
.af-head {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  padding: 14px 14px 12px;
  border-bottom: 1px solid var(--border);
}
.af-head-main { flex: 1; min-width: 0; }
.af-head-title {
  display: flex;
  align-items: center;
  gap: 7px;
  font-size: 14px;
  font-weight: 650;
  color: var(--text);
}
.af-head-ic { color: var(--accent); }
.af-head-sub {
  margin-top: 2px;
  font-size: 12.5px;
  color: var(--text-light);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.af-close {
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 26px;
  height: 26px;
  border: none;
  border-radius: 7px;
  background: transparent;
  color: var(--text-faint);
  cursor: pointer;
  transition: background 0.14s, color 0.14s;
}
.af-close:hover { background: var(--bg-hover); color: var(--text); }

/* ---------------- body / sections ---------------- */
.af-body {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  padding: 6px 14px 16px;
}
.af-section { margin-top: 14px; }
.af-sec-head {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-bottom: 8px;
  font-size: 11px;
  font-weight: 650;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--text-faint);
}
.af-sec-ic { color: var(--text-faint); }

.af-empty {
  padding: 10px 12px;
  font-size: 12.5px;
  line-height: 1.5;
  color: var(--text-light);
  background: var(--bg-hover);
  border-radius: var(--radius-ctl);
}

/* ---------------- rows (related / parent) ---------------- */
.af-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 10px;
  border-radius: var(--radius-ctl);
  transition: background 0.14s;
}
.af-row:hover { background: var(--bg-hover); }
.af-row + .af-row { margin-top: 2px; }
.af-parent {
  background: color-mix(in srgb, var(--accent) 8%, transparent);
  border: 1px solid color-mix(in srgb, var(--accent) 26%, transparent);
}

.af-row-label { flex: 1; min-width: 0; }
.af-row-title {
  display: block;
  font-size: 13px;
  font-weight: 500;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.af-meter {
  margin-top: 5px;
  height: 3px;
  border-radius: 3px;
  background: var(--bg-active);
  overflow: hidden;
}
.af-meter-fill {
  height: 100%;
  border-radius: 3px;
  background: var(--accent);
  opacity: 0.85;
}

.af-row-actions {
  display: flex;
  flex-direction: column;
  gap: 4px;
  flex-shrink: 0;
}

/* ---------------- buttons ---------------- */
.af-btn {
  padding: 4px 10px;
  font-size: 12px;
  font-weight: 600;
  border-radius: 7px;
  border: 1px solid transparent;
  cursor: pointer;
  white-space: nowrap;
  transition: background 0.14s, color 0.14s, border-color 0.14s, opacity 0.14s;
}
.af-btn:disabled { opacity: 0.6; cursor: default; }
.af-btn-primary {
  background: var(--accent);
  color: #fff;
}
.af-btn-primary:hover:not(:disabled) { background: var(--accent-hover); }
.af-btn-ghost {
  background: transparent;
  color: var(--text-light);
  border-color: var(--border-strong);
}
.af-btn-ghost:hover:not(:disabled) {
  background: var(--bg-hover);
  color: var(--text);
}

/* ---------------- tags ---------------- */
.af-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}
.af-chip {
  display: inline-flex;
  align-items: center;
  gap: 3px;
  padding: 4px 10px 4px 8px;
  font-size: 12.5px;
  font-weight: 500;
  color: var(--text-light);
  background: var(--bg-hover);
  border: 1px solid var(--border);
  border-radius: 999px;
  cursor: pointer;
  transition: background 0.14s, color 0.14s, border-color 0.14s;
}
.af-chip > span:first-child { color: var(--text-faint); font-weight: 600; }
.af-chip:hover:not(:disabled) {
  color: var(--text);
  border-color: var(--accent-soft);
  background: color-mix(in srgb, var(--accent) 10%, var(--bg-hover));
}
.af-chip-added {
  color: var(--accent);
  border-color: var(--accent-soft);
  background: color-mix(in srgb, var(--accent) 14%, transparent);
  cursor: default;
}
.af-chip-added::after { content: " ✓"; }

.af-refining {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-top: 8px;
  font-size: 11.5px;
  color: var(--text-faint);
}
.af-spin { animation: af-spin 1.1s linear infinite; }
@keyframes af-spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) { .af-spin { animation: none; } }

/* ---------------- affordance pill ---------------- */
.af-aff {
  position: fixed;
  right: 18px;
  bottom: 18px;
  z-index: 710;
  display: flex;
  align-items: center;
  gap: 2px;
  padding: 3px;
  background: var(--bg-modal);
  border: 1px solid var(--border);
  border-radius: 999px;
  box-shadow: var(--shadow-card);
  transform: translateY(14px) scale(0.96);
  opacity: 0;
  pointer-events: none;
  transition: transform 0.2s cubic-bezier(0.22, 1, 0.36, 1), opacity 0.2s ease;
}
.af-aff.af-aff-in {
  transform: none;
  opacity: 1;
  pointer-events: auto;
}
.af-aff-open {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 12px;
  font-size: 12.5px;
  font-weight: 600;
  color: var(--text);
  background: transparent;
  border: none;
  border-radius: 999px;
  cursor: pointer;
  transition: background 0.14s, color 0.14s;
}
.af-aff-open:hover { background: var(--bg-hover); }
.af-aff-ic { color: var(--accent); }
.af-aff-x {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 24px;
  height: 24px;
  color: var(--text-faint);
  background: transparent;
  border: none;
  border-radius: 999px;
  cursor: pointer;
  transition: background 0.14s, color 0.14s;
}
.af-aff-x:hover { background: var(--bg-hover); color: var(--text); }

/* narrow screens: full-width sheet from the right */
@media (max-width: 560px) {
  .af-panel {
    top: auto;
    bottom: 0;
    right: 0;
    left: 0;
    width: 100%;
    max-width: 100%;
    max-height: 76vh;
    border-radius: var(--radius-pane) var(--radius-pane) 0 0;
    transform: translateY(calc(100% + 24px));
  }
  .af-panel.af-in { transform: none; }
}
