/* Doctor Discovery — categorized results accordion (DOCTOR_DISCOVERY_PLAN §5F).
   Scoped under #kaiPanel1Discovery so it never leaks into the rest of the
   Kai shell. Light theme to match the current onboarding. */

#kaiPanel1Discovery .disc-wrap,
#kaiConfirmDiscovery .disc-wrap {
  width: 100%;
  max-width: 880px;
  margin: 0 auto;
  text-align: left;
}

/* #1: embedded under the profile on the confirm screen — give it breathing
   room + a divider so it reads as its own section. */
.kai-discovery-embed {
  margin-top: 1.25rem;
  padding-top: 1.25rem;
  border-top: 1px solid #e3e8ef;
}

/* Live search progress (shown while extractors run) */
.disc-progress { margin: 1rem 0 0; }
.disc-progress-row {
  display: flex; align-items: center; gap: .6rem;
  padding: .45rem .2rem; font-size: .95rem; color: #475569;
}
.disc-progress-row .disc-pr-state { width: 1.4rem; text-align: center; }
.disc-progress-row.is-done { color: #0f172a; }
.disc-progress-row.is-error { color: #b91c1c; }

/* Total banner */
.disc-total-banner {
  background: linear-gradient(135deg, #f0f7ff, #e8f0fe);
  border: 1px solid #dbe7fb; border-radius: 12px;
  padding: 16px 20px; margin: .4rem 0 1rem;
  display: flex; justify-content: space-between; align-items: center; gap: 1rem;
}
.disc-total-count { font-size: 1.25rem; font-weight: 800; color: #0b2a4a; }
.disc-total-sub { font-size: .85rem; color: #5a6b82; }

/* Accordion */
.disc-accordion {
  border: 1px solid #e3e8ef; border-radius: 10px;
  margin-bottom: 12px; overflow: hidden; background: #fff;
}
.disc-accordion-header {
  display: flex; align-items: center; gap: .6rem;
  padding: 13px 16px; cursor: pointer; user-select: none;
  background: #fafbfc; transition: background .15s;
}
.disc-accordion-header:hover { background: #f1f5f9; }
.disc-cat-icon { display: inline-flex; align-items: center; color: #475569; }
.disc-cat-icon svg { display: block; }
.disc-accordion-title { font-weight: 700; color: #1e293b; flex: 1; }
.disc-count-badge {
  background: #2563eb; color: #fff; border-radius: 999px;
  padding: 2px 10px; font-size: .8rem; font-weight: 700;
}
.disc-chevron { transition: transform .25s ease; color: #94a3b8; font-size: .9rem; }
.disc-accordion.is-open .disc-chevron { transform: rotate(90deg); }
.disc-selectall {
  background: none; border: 1px solid #cbd5e1; border-radius: 7px;
  padding: 3px 10px; font-size: .8rem; color: #334155; cursor: pointer;
}
.disc-selectall:hover { background: #eef2f7; }

.disc-accordion-body { max-height: 0; overflow: hidden; transition: max-height .28s ease-out; }
.disc-accordion.is-open .disc-accordion-body { max-height: 60vh; overflow-y: auto; }

/* Resource card */
.disc-card {
  display: flex; align-items: flex-start; gap: 12px;
  padding: 11px 16px; border-top: 1px solid #f1f5f9; transition: background .12s;
}
.disc-card:hover { background: #f8fafc; }
.disc-card.is-selected { background: #eaf3fe; }
.disc-card-cb { flex-shrink: 0; width: 18px; height: 18px; margin-top: 2px; accent-color: #2563eb; cursor: pointer; }
.disc-card-thumb {
  flex-shrink: 0; width: 92px; height: 56px; border-radius: 6px;
  object-fit: cover; background: #e2e8f0;
}
.disc-card-main { min-width: 0; flex: 1; }
.disc-card-title { font-weight: 600; color: #0f172a; line-height: 1.3; }
.disc-card-meta { font-size: .8rem; color: #64748b; margin-top: 3px; }
.disc-card-low { color: #b45309; }      /* low-confidence "verify" hint */
.disc-card-view {
  font-size: .8rem; color: #2563eb; text-decoration: none; white-space: nowrap;
}
.disc-card-view:hover { text-decoration: underline; }

/* Summary / action bar */
.disc-summary-bar {
  position: sticky; bottom: 0; background: #fff;
  border-top: 1px solid #e3e8ef; padding: 12px 4px; margin-top: .5rem;
  display: flex; justify-content: space-between; align-items: center; gap: 1rem; flex-wrap: wrap;
}
.disc-selected-count { font-weight: 600; color: #334155; }
.disc-warn { font-size: .8rem; color: #94a3b8; margin-top: .6rem; }

.disc-empty { text-align: center; color: #64748b; padding: 2rem 1rem; }

/* Import progress bar (chunked import) */
/* #5: import progress is a centered modal with a dimmed backdrop so it's
   impossible to miss even with a long picked list. */
.disc-import-modal {
  position: fixed; inset: 0; z-index: 1000;
  display: flex; align-items: center; justify-content: center; padding: 1rem;
}
.disc-import-modal[hidden] { display: none; }
.disc-import-backdrop {
  position: absolute; inset: 0; background: rgba(15, 23, 42, .55);
  backdrop-filter: blur(2px);
}
.disc-import-dialog {
  position: relative; z-index: 1; width: min(420px, 92vw);
  background: #fff; border-radius: 16px; padding: 1.3rem 1.4rem;
  box-shadow: 0 18px 50px rgba(15, 23, 42, .28);
  text-align: center; animation: kai-draft-in .2s ease;
}
.disc-import-title { font-weight: 800; color: #0f172a; margin: 0 0 .8rem; }
.disc-import-bar {
  height: 10px; border-radius: 999px; background: #e6edf6; overflow: hidden;
}
.disc-import-fill {
  display: block; height: 100%; width: 0; border-radius: 999px;
  background: linear-gradient(90deg, #2563eb, #38bdf8); transition: width .3s ease;
}
.disc-import-label { font-size: .88rem; color: #475569; margin: .7rem 0 0; }
.disc-import-actions {
  margin-top: 1rem; display: flex; gap: .6rem; justify-content: center;
  align-items: center; flex-wrap: wrap;
}
.disc-import-actions[hidden] { display: none; }
.disc-import-dismiss {
  padding: .5rem 1.1rem; border-radius: 999px;
  border: 1px solid #cbd5e1; background: #fff; color: #0f172a;
  font-weight: 600; cursor: pointer;
}
.disc-import-dismiss:hover { background: #f1f5f9; }

/* Failed imports list */
.disc-failures {
  margin: .75rem 0 0; padding: .75rem .9rem; border-radius: 10px;
  background: #fef2f2; border: 1px solid #fecaca;
}
.disc-failures-head { margin: 0 0 .4rem; font-weight: 700; color: #b91c1c; font-size: .9rem; }
.disc-failures-list { margin: 0; padding-left: 1.1rem; }
.disc-failures-list li { font-size: .85rem; color: #7f1d1d; margin: .15rem 0; }
.disc-fail-title { font-weight: 600; }
.disc-fail-why { color: #b45309; }

/* #2 incr.2 — in-shell organize: drafted playbook cards + nested nodes */
.kai-organize-item {
  display: flex; align-items: center; justify-content: space-between; gap: .75rem;
  padding: .5rem .7rem; border: 1px solid #eef2f7; border-radius: 8px;
  background: #fff; margin: .35rem 0;
}
.kai-organize-item-title { color: #0f172a; font-size: .92rem; }
.kai-organize-item-type {
  font-size: .72rem; text-transform: uppercase; letter-spacing: .03em;
  color: #64748b; background: #f1f5f9; border-radius: 999px; padding: 2px 8px; white-space: nowrap;
}
.kai-organize-pb {
  border: 1px solid #dbe7fb; border-radius: 12px;
  margin: .9rem 0; background: linear-gradient(135deg, #f7fbff, #eef4fe); overflow: hidden;
}
/* #2 incr.3: collapsible header */
.kai-organize-pb-header {
  display: flex; align-items: center; gap: .6rem; width: 100%;
  padding: 13px 16px; background: none; border: none; cursor: pointer; text-align: left;
}
.kai-organize-pb-chev {
  color: #2563eb; font-size: .8rem; transition: transform .2s ease; flex-shrink: 0;
}
.kai-organize-pb:not(.is-collapsed) .kai-organize-pb-chev { transform: rotate(90deg); }
.kai-organize-pb-title { font-weight: 800; color: #0b2a4a; font-size: 1.05rem; flex: 1; }
.kai-organize-pb-badge {
  background: #2563eb; color: #fff; border-radius: 999px;
  padding: 2px 10px; font-size: .8rem; font-weight: 700; flex-shrink: 0;
}
.kai-organize-pb-body { padding: 0 16px 14px; }
.kai-organize-pb.is-collapsed .kai-organize-pb-body { display: none; }
.kai-organize-pb-desc { font-size: .85rem; color: #5a6b82; margin: 0 0 .3rem; }
/* #2 (Ramy 2026-06-23): borrowed-playbook originator credit in the organizer. */
.kai-organize-pb-credit {
  display: inline-block; font-size: .78rem; font-weight: 600;
  color: #6d28d9; background: #f5f3ff; border: 1px solid #e9e3ff;
  padding: 3px 10px; border-radius: 999px; margin: 0 0 .5rem;
}

/* #2 incr.4: two-pane organize — playbook list left, detail right */
.kai-organize-2pane {
  display: flex; gap: 1rem; align-items: flex-start;
  border: 1px solid #e3e8ef; border-radius: 12px; overflow: hidden; background: #fff;
}
.kai-organize-sidebar {
  flex: 0 0 220px; max-width: 240px; border-right: 1px solid #eef2f7;
  background: #fafbfc; padding: .5rem; display: flex; flex-direction: column; gap: .25rem;
  max-height: 60vh; overflow-y: auto;
}
.kai-organize-side-item {
  display: flex; align-items: center; gap: .5rem; width: 100%;
  padding: .6rem .7rem; border: none; border-radius: 8px; background: none;
  cursor: pointer; text-align: left; transition: background .12s;
}
.kai-organize-side-item:hover { background: #eef2f7; }
.kai-organize-side-item.is-active { background: #e8f0fe; }
.kai-organize-side-label { flex: 1; font-weight: 600; color: #1e293b; font-size: .92rem; }
.kai-organize-side-item.is-active .kai-organize-side-label { color: #0b2a4a; }
.kai-organize-side-badge {
  background: #2563eb; color: #fff; border-radius: 999px;
  padding: 1px 9px; font-size: .75rem; font-weight: 700; flex-shrink: 0;
}
.kai-organize-detail { flex: 1; min-width: 0; padding: 1rem 1.1rem; max-height: 60vh; overflow-y: auto; }

/* #2 incr.5: drag-drop + editing */
.kai-organize-draggable { cursor: grab; }
.kai-organize-draggable:active { cursor: grabbing; }
.kai-organize-draggable.is-dragging { opacity: .45; }
.kai-organize-grip { color: #94a3b8; font-size: .9rem; flex-shrink: 0; cursor: grab; }
.kai-organize-side-item.is-drop-hover,
.kai-organize-node.is-drop-hover,
.kai-organize-detail.is-drop-hover {
  outline: 2px dashed #2563eb; outline-offset: -2px; background: #eef5ff; border-radius: 8px;
}
.kai-organize-node {
  border: 1px solid transparent; border-radius: 8px; padding: .3rem .4rem; margin-top: .5rem;
}
.kai-editable { border-bottom: 1px dashed transparent; cursor: text; }
.kai-editable:hover { border-bottom-color: #94a3b8; }
.kai-editable[contenteditable="true"] { outline: none; border-bottom-color: #2563eb; background: #f8fbff; }
.kai-organize-addpb {
  margin-top: .4rem; width: 100%; padding: .55rem; border: 1px dashed #cbd5e1; border-radius: 8px;
  background: none; color: #2563eb; font-weight: 600; cursor: pointer; font-size: .88rem;
}
.kai-organize-addpb:hover { background: #eef2f7; }
.kai-organize-addcat {
  margin-top: .6rem; padding: .4rem .8rem; border: 1px dashed #cbd5e1; border-radius: 8px;
  background: none; color: #2563eb; font-weight: 600; cursor: pointer; font-size: .85rem;
}
.kai-organize-addcat:hover { background: #eef2f7; }
/* #4: nested "+ Add subcategory" sits indented under its category. */
.kai-organize-addsub { margin-left: .2rem; font-size: .8rem; padding: .3rem .7rem; }

/* #3 (Ramy 2026-06-23): keep the organize container a stable width. The
   parent .kai-explain-stack is a centered flex column, so a non-full-width
   child shrinks to its content — which made the editor jump narrower when a
   playbook was added. Pin both the work area and the 2-pane to 100%. */
.kai-organize-work { width: 100%; }
.kai-organize-2pane { width: 100%; }

/* Reflow (Ramy 2026-06-24): content rows inside categories — styled to match
   the public playbook (a clean list of items under each category). */
.kai-organize-node-name {
  font-weight: 700; color: #334155; font-size: .92rem; margin: .45rem 0 .2rem;
}
.kai-organize-item {
  display: flex; align-items: center; gap: .55rem;
  padding: .45rem .6rem; margin-top: .3rem;
  border: 1px solid #eef2f7; border-radius: 8px; background: #fff;
}
.kai-organize-item:hover { border-color: #dbe3ee; background: #fafbfc; }
.kai-organize-item-type {
  font-size: .68rem; font-weight: 700; letter-spacing: .04em; text-transform: uppercase;
  color: #64748b; background: #f1f5f9; border-radius: 5px; padding: 1px 7px; flex-shrink: 0;
}

/* #5: preview link on each content row (opens the detail page in a new tab). */
.kai-organize-item-title {
  flex: 1; min-width: 0; font-size: .9rem; color: #1e293b;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.kai-organize-item-preview {
  flex-shrink: 0; font-size: .78rem; font-weight: 600; color: #2563eb;
  text-decoration: none; white-space: nowrap;
  /* Reflow (Ramy 2026-06-24): now a <button> opening the in-app preview. */
  background: none; border: 0; padding: 2px 6px; cursor: pointer;
  border-radius: 6px; font-family: inherit;
}
.kai-organize-item-preview:hover { text-decoration: underline; background: #eef5ff; }

/* #1: explicit remove (×) — pulls an item out of its playbook back to
   "Not placed" without dragging. */
.kai-organize-item-remove {
  flex-shrink: 0; border: none; background: none; cursor: pointer;
  color: #94a3b8; font-size: 1.15rem; line-height: 1; padding: 0 .15rem;
  border-radius: 6px; transition: color .12s, background .12s;
}
.kai-organize-item-remove:hover { color: #dc2626; background: #fef2f2; }
@media (max-width: 640px) {
  .kai-organize-2pane { flex-direction: column; }
  .kai-organize-sidebar {
    flex-basis: auto; max-width: none; width: 100%; flex-direction: row;
    overflow-x: auto; max-height: none; border-right: none; border-bottom: 1px solid #eef2f7;
  }
  .kai-organize-side-item { width: auto; white-space: nowrap; }
}

/* #2 incr.3: auto/manual choice cards */
.kai-organize-choice {
  display: flex; gap: 1rem; flex-wrap: wrap; justify-content: center;
  max-width: 720px; margin: 1rem auto 0;
}
/* Reflow (Ramy 2026-06-24): `display:flex` above was overriding the `hidden`
   attribute, so the choice cards never hid after a choice was made (and on
   re-entry). Honor [hidden]. */
.kai-organize-choice[hidden] { display: none; }
.kai-organize-choice-card {
  flex: 1 1 280px; display: flex; flex-direction: column; gap: .4rem;
  padding: 1.4rem 1.25rem; border: 1.5px solid #dbe7fb; border-radius: 14px;
  background: #fff; cursor: pointer; text-align: left; transition: border-color .15s, box-shadow .15s, transform .1s;
}
.kai-organize-choice-card:hover {
  border-color: #2563eb; box-shadow: 0 6px 22px rgba(37,99,235,.14); transform: translateY(-2px);
}
.kai-organize-choice-emoji { font-size: 1.6rem; }
.kai-organize-choice-title { font-weight: 800; color: #0b2a4a; font-size: 1.05rem; }
.kai-organize-choice-sub { font-size: .85rem; color: #5a6b82; line-height: 1.4; }
.kai-organize-node { margin-top: .6rem; }
.kai-organize-node-name { font-weight: 700; color: #1e293b; font-size: .9rem; margin: .3rem 0 .15rem; }
.kai-organize-node-d2 { margin-left: .85rem; }
.kai-organize-node-d3 { margin-left: 1.7rem; }
.kai-organize-node-d2 .kai-organize-node-name { font-weight: 600; color: #334155; }
.kai-organize-node-d3 .kai-organize-node-name { font-weight: 600; color: #475569; font-size: .85rem; }

/* ── Phase 4: owner notification FAB + review modal ─────────────── */
.kdf-fab { position: fixed; bottom: 24px; right: 24px; z-index: 1000; }
.kdf-fab-btn {
  width: 60px; height: 60px; border-radius: 50%; border: none; cursor: pointer;
  background: #fff; box-shadow: 0 4px 16px rgba(0,0,0,.18); position: relative;
  padding: 0; overflow: visible; transition: transform .15s;
}
.kdf-fab-btn:hover { transform: scale(1.06); }
.kdf-fab-avatar { width: 60px; height: 60px; border-radius: 50%; object-fit: cover; display: block; }
.kdf-fab-badge {
  position: absolute; top: -4px; right: -4px; background: #e53935; color: #fff;
  border-radius: 11px; min-width: 22px; height: 22px; font-size: 12px; font-weight: 700;
  display: flex; align-items: center; justify-content: center; padding: 0 6px;
}
.kdf-fab.has-suggestions .kdf-fab-btn { animation: kdf-pulse 2.2s ease-in-out infinite; }
@keyframes kdf-pulse {
  0%, 100% { box-shadow: 0 4px 16px rgba(0,0,0,.18); }
  50% { box-shadow: 0 4px 24px rgba(37,99,235,.45); }
}
.kdf-popup {
  position: absolute; bottom: 72px; right: 0; width: 300px; background: #fff;
  border: 1px solid #e3e8ef; border-radius: 12px; box-shadow: 0 8px 30px rgba(0,0,0,.14);
  padding: 14px 16px;
}
.kdf-popup-head { font-weight: 700; color: #0f172a; margin-bottom: .4rem; }
.kdf-popup-body { font-size: .9rem; color: #475569; }
.kdf-cat-list { margin: .4rem 0 0; padding-left: 1.1rem; }
.kdf-cat-list li { margin: .1rem 0; }
.kdf-popup-actions { display: flex; justify-content: flex-end; gap: .5rem; margin-top: .8rem; }

.kdf-modal {
  position: fixed; inset: 0; z-index: 1001; background: rgba(15,23,42,.45);
  display: flex; align-items: center; justify-content: center; padding: 1rem;
}
/* The `hidden` attribute must beat the display:flex above, or the modal
   shows empty on every owner page load and the close button looks dead. */
.kdf-modal[hidden] { display: none; }
.kdf-modal-card {
  background: #fff; border-radius: 14px; width: 100%; max-width: 760px;
  max-height: 86vh; overflow-y: auto; padding: 0 20px 16px;
}
.kdf-modal-head {
  position: sticky; top: 0; background: #fff; display: flex; justify-content: space-between;
  align-items: center; padding: 16px 0 12px; font-weight: 800; color: #0f172a;
  border-bottom: 1px solid #eef2f7; margin-bottom: .6rem;
}
.kdf-modal-close { background: none; border: none; font-size: 1.6rem; line-height: 1; color: #94a3b8; cursor: pointer; }

/* #4: "Your links" section — profiles + social, saved to the profile (not content) */
.disc-links-section {
  border: 1px solid #e2e8f0; border-radius: 12px; background: #fbfdff;
  padding: .8rem .9rem; margin-bottom: 1rem;
}
.disc-links-head { margin-bottom: .55rem; }
.disc-links-title { font-weight: 800; color: #0f172a; }
.disc-links-sub { font-size: .8rem; color: #64748b; margin-top: 2px; }
.disc-link-row {
  display: flex; align-items: center; gap: .6rem;
  padding: .5rem .15rem; border-top: 1px solid #eef2f7;
}
.disc-link-row:first-of-type { border-top: none; }
.disc-link-cb { flex-shrink: 0; width: 18px; height: 18px; accent-color: #2563eb; cursor: pointer; }
.disc-link-icon { flex-shrink: 0; color: #475569; display: inline-flex; }
.disc-link-main { flex: 1; min-width: 0; }
.disc-link-label { font-weight: 600; color: #0f172a; line-height: 1.3; }
.disc-link-url {
  font-size: .8rem; color: #64748b; margin-top: 2px;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.disc-link-row.is-selected { background: #eaf3fe; border-radius: 8px; }

/* #2 incr.7: live streaming draft progress (playbook + category names) */
.kai-organize-draftprog { padding: .4rem 0; }
.kai-organize-draftlist { margin-top: .5rem; }
.kai-draft-pb {
  display: flex; align-items: center; gap: .5rem;
  font-weight: 700; color: #0f172a; padding: .35rem 0 .15rem;
  animation: kai-draft-in .25s ease;
}
.kai-draft-cat {
  display: flex; align-items: center; gap: .5rem;
  color: #475569; font-size: .9rem; padding: .12rem 0 .12rem 1.6rem;
  animation: kai-draft-in .25s ease;
}
/* #4: colored (non-emoji) markers for the streaming draft list */
.kai-draft-ico { display: inline-flex; color: #2563eb; flex-shrink: 0; }
.kai-draft-ico-sm { display: inline-flex; color: #94a3b8; flex-shrink: 0; }
@keyframes kai-draft-in {
  from { opacity: 0; transform: translateY(3px); }
  to   { opacity: 1; transform: translateY(0); }
}
