/* ───────────────────────────────────────────────────────────
   Coach Drawer — push-aside teaching companion
   Reusable component. Books is first consumer; other pages
   register lessons via window.Coach.register(pageKey, lessons).
   ─────────────────────────────────────────────────────────── */

:root {
  --coach-width: 420px;
  --coach-bg: #fbfbfd;
  --coach-surface: #ffffff;
  --coach-border: #e8e9ee;
  --coach-text: #16191f;
  --coach-muted: #6b7280;
  --coach-faint: #9ca3af;
  --coach-accent: #4378eb;
  --coach-accent-soft: #eef4ff;
  --coach-success: #047857;
  --coach-success-soft: #dcfce7;
  --coach-warn: #92400e;
  --coach-warn-soft: #fef3c7;
  --coach-info: #5b21b6;
  --coach-info-soft: #ede9fe;
  --coach-shadow: 0 1px 2px rgba(15,23,42,0.04);
  --coach-elevation: -16px 0 32px -16px rgba(15,23,42,0.10), -1px 0 0 rgba(15,23,42,0.04);
}

/* ─── push-aside mechanics ─── */
body.coach-ready { transition: margin-right 0.28s cubic-bezier(.2,.7,.2,1); }
@media (min-width: 1100px) {
  body.coach-open { margin-right: var(--coach-width); }
}

/* ─── invite button (lives in page header) ─── */
.coach-invite {
  display: inline-flex; align-items: center; gap: 8px;
  padding: 8px 14px 8px 12px;
  border-radius: 999px;
  background: linear-gradient(135deg, #f3f0ff 0%, #eef4ff 100%);
  border: 1px solid #d9c8ff;
  color: var(--coach-info);
  font: inherit; font-size: 12.5px; font-weight: 700;
  letter-spacing: 0.1px;
  cursor: pointer;
  position: relative;
  box-shadow: var(--coach-shadow);
  transition: transform .12s ease, box-shadow .12s ease, border-color .12s ease;
}
.coach-invite:hover {
  transform: translateY(-1px);
  box-shadow: 0 6px 14px -6px rgba(91,33,182,0.30);
  border-color: #c4b5fd;
}
.coach-invite:active { transform: translateY(0); }
.coach-invite .ci-spark {
  width: 16px; height: 16px; flex: none;
  display: inline-flex; align-items: center; justify-content: center;
}
.coach-invite .ci-spark svg { width: 16px; height: 16px; }
.coach-invite .ci-dot {
  position: absolute; top: 4px; right: 4px;
  width: 8px; height: 8px; border-radius: 50%;
  background: #ef4444; border: 2px solid #fff;
  display: none;
}
.coach-invite[data-new="1"] .ci-dot { display: block; }
body.coach-open .coach-invite {
  background: #fff; border-color: #d9c8ff; color: var(--coach-info);
}

/* ─── drawer shell ─── */
.coach-drawer {
  position: fixed; top: 0; right: 0; bottom: 0;
  width: var(--coach-width); max-width: 100vw;
  background: var(--coach-bg);
  border-left: 1px solid var(--coach-border);
  box-shadow: var(--coach-elevation);
  z-index: 250;
  display: flex; flex-direction: column;
  transform: translateX(calc(100% + 32px));
  transition: transform 0.28s cubic-bezier(.2,.7,.2,1);
  visibility: hidden;
  font-family: 'Plus Jakarta Sans', -apple-system, system-ui, sans-serif;
  color: var(--coach-text);
}
.coach-drawer.open { transform: translateX(0); visibility: visible; }

/* small-screen overlay fallback */
@media (max-width: 1099px) {
  .coach-drawer { width: min(420px, 92vw); }
  .coach-backdrop {
    position: fixed; inset: 0; background: rgba(15,23,42,0.20);
    backdrop-filter: blur(2px);
    opacity: 0; pointer-events: none; transition: opacity .2s ease;
    z-index: 240;
  }
  .coach-backdrop.open { opacity: 1; pointer-events: auto; }
}
@media (min-width: 1100px) {
  .coach-backdrop { display: none; }
}

/* ─── drawer header ─── */
.coach-head {
  padding: 18px 16px 14px 20px;
  border-bottom: 1px solid var(--coach-border);
  background: linear-gradient(180deg, #fff, #fbfbfd);
  display: grid; grid-template-columns: 1fr auto auto; align-items: center;
  gap: 6px;
  flex: none;
}
.coach-head .ch-title {
  display: flex; align-items: center; gap: 9px;
  font-size: 14px; font-weight: 800; letter-spacing: -0.1px;
  line-height: 1;
}
.coach-head .ch-title .ch-spark {
  width: 20px; height: 20px;
  background: linear-gradient(135deg, #c4b5fd, #a5b4fc);
  border-radius: 6px; display: inline-flex; align-items: center; justify-content: center;
  color: #fff;
  box-shadow: 0 1px 3px rgba(91,33,182,0.25);
}
.coach-head .ch-title .ch-spark svg { width: 12px; height: 12px; }
.coach-head .ch-sub {
  grid-column: 1 / -1;
  font-size: 11.5px; color: var(--coach-muted);
  margin-top: 6px; line-height: 1.4;
}
.coach-iconbtn {
  width: 30px; height: 30px; border-radius: 8px;
  background: transparent; border: 1px solid transparent;
  color: var(--coach-muted); cursor: pointer;
  display: inline-flex; align-items: center; justify-content: center;
  transition: background .12s, color .12s, border-color .12s;
}
.coach-iconbtn:hover { background: #fff; color: var(--coach-text); border-color: var(--coach-border); }
.coach-iconbtn svg { width: 16px; height: 16px; }

/* ─── drawer body ─── */
.coach-body {
  flex: 1; overflow-y: auto; overflow-x: hidden;
  padding: 16px 18px 24px;
  scrollbar-width: thin; scrollbar-color: #d1d5db transparent;
}
.coach-body::-webkit-scrollbar { width: 6px; }
.coach-body::-webkit-scrollbar-thumb { background: #d1d5db; border-radius: 3px; }

.coach-section { margin-bottom: 20px; }
.coach-section:last-child { margin-bottom: 0; }
.coach-section-label {
  font-size: 10px; font-weight: 800; letter-spacing: 0.7px; text-transform: uppercase;
  color: var(--coach-faint); margin: 0 0 10px;
}

/* ─── rhythm cards ─── */
.coach-rhythm {
  display: grid; grid-template-columns: repeat(2, 1fr); gap: 8px;
}
.cr-card {
  background: var(--coach-surface);
  border: 1px solid var(--coach-border); border-radius: 12px;
  padding: 12px 12px 11px;
  display: flex; flex-direction: column; gap: 4px;
  position: relative;
  transition: transform .12s ease, border-color .12s ease;
}
.cr-card:hover { transform: translateY(-1px); border-color: #d1d5db; }
.cr-card .cr-cycle {
  font-size: 9.5px; font-weight: 800; letter-spacing: 0.5px; text-transform: uppercase;
  color: var(--coach-faint);
}
.cr-card .cr-status {
  font-size: 13px; font-weight: 700; color: var(--coach-text);
  line-height: 1.3;
  display: flex; align-items: center; gap: 6px;
}
.cr-card .cr-detail {
  font-size: 11px; color: var(--coach-muted); line-height: 1.45;
}
.cr-card[data-state="ok"] .cr-status::before {
  content: ""; width: 8px; height: 8px; border-radius: 50%;
  background: #10b981; flex: none;
}
.cr-card[data-state="warn"] .cr-status::before {
  content: ""; width: 8px; height: 8px; border-radius: 50%;
  background: #f59e0b; flex: none;
}
.cr-card[data-state="todo"] .cr-status::before {
  content: ""; width: 8px; height: 8px; border-radius: 50%;
  background: #cbd5e1; flex: none;
}
.cr-card[data-state="loading"] .cr-status::before {
  content: ""; width: 8px; height: 8px; border-radius: 50%;
  background: #e5e7eb; flex: none;
  animation: cr-pulse 1.2s ease-in-out infinite;
}
@keyframes cr-pulse { 50% { opacity: 0.4; } }

/* ─── action items ─── */
.coach-actions { display: flex; flex-direction: column; gap: 8px; }
.ca-item {
  background: var(--coach-surface);
  border: 1px solid var(--coach-border); border-radius: 12px;
  padding: 12px 14px;
  display: flex; flex-direction: column; gap: 6px;
}
.ca-row {
  display: flex; align-items: flex-start; gap: 10px;
}
.ca-icon {
  flex: none; width: 22px; height: 22px; border-radius: 50%;
  display: inline-flex; align-items: center; justify-content: center;
  font-size: 12px; font-weight: 800;
  margin-top: 1px;
}
.ca-icon[data-state="ok"]    { background: var(--coach-success-soft); color: var(--coach-success); }
.ca-icon[data-state="warn"]  { background: var(--coach-warn-soft); color: var(--coach-warn); }
.ca-icon[data-state="todo"]  { background: #f1f5f9; color: #64748b; }
.ca-icon[data-state="info"]  { background: var(--coach-info-soft); color: var(--coach-info); }
.ca-icon svg { width: 13px; height: 13px; }
.ca-body { flex: 1; min-width: 0; }
.ca-title {
  font-size: 13px; font-weight: 700; line-height: 1.35; color: var(--coach-text);
}
.ca-detail {
  font-size: 12px; color: var(--coach-muted); line-height: 1.5; margin-top: 2px;
}
.ca-cta {
  display: inline-flex; align-items: center; gap: 4px;
  margin-top: 6px;
  padding: 5px 10px;
  font: inherit; font-size: 11.5px; font-weight: 700;
  background: var(--coach-accent-soft); color: var(--coach-accent);
  border: 1px solid #d4e0fc; border-radius: 7px;
  cursor: pointer;
  transition: background .12s, border-color .12s;
}
.ca-cta:hover { background: #dee9ff; border-color: #b6c8f7; }
.ca-cta svg { width: 12px; height: 12px; }

/* ─── AI receipts (the "what AI did" line) ─── */
.ai-receipt {
  font-size: 11px; line-height: 1.45;
  color: var(--coach-info);
  display: flex; align-items: flex-start; gap: 6px;
  padding: 6px 10px;
  background: var(--coach-info-soft);
  border-radius: 7px;
  margin-top: 6px;
}
.ai-receipt .ar-spark {
  flex: none; width: 12px; height: 12px;
  display: inline-flex; align-items: center; justify-content: center;
  margin-top: 1px; color: var(--coach-info);
}
.ai-receipt .ar-spark svg { width: 12px; height: 12px; }
.ai-receipt strong { font-weight: 800; }

/* ─── QB comparison (silenceable) ─── */
.qb-compare {
  font-size: 11px; line-height: 1.45;
  color: var(--coach-muted);
  font-style: italic;
  margin-top: 6px;
  padding-left: 10px;
  border-left: 2px solid #e5e7eb;
}
.qb-compare strong { color: var(--coach-text); font-style: normal; font-weight: 700; }
body.coach-no-qb .qb-compare { display: none; }

/* ─── teaching prose (expandable) ─── */
.coach-teach {
  background: var(--coach-surface);
  border: 1px solid var(--coach-border);
  border-radius: 12px;
  overflow: hidden;
}
.coach-teach summary {
  list-style: none; cursor: pointer;
  padding: 12px 14px;
  display: flex; align-items: center; justify-content: space-between;
  font-size: 12.5px; font-weight: 700; color: var(--coach-text);
  user-select: none;
}
.coach-teach summary::-webkit-details-marker { display: none; }
.coach-teach summary::after {
  content: ""; width: 8px; height: 8px;
  border-right: 2px solid var(--coach-faint);
  border-bottom: 2px solid var(--coach-faint);
  transform: rotate(45deg);
  transition: transform .15s ease;
  margin-right: 4px;
}
.coach-teach[open] summary::after { transform: rotate(225deg); }
.coach-teach summary:hover { background: #f8fafc; }
.coach-teach .ct-body {
  padding: 0 14px 14px;
  font-size: 12.5px; line-height: 1.6;
  color: #2c3340;
}
.coach-teach .ct-body p { margin: 0 0 10px; }
.coach-teach .ct-body p:last-child { margin: 0; }
.coach-teach .ct-body strong { color: var(--coach-text); font-weight: 700; }
.coach-teach .ct-body em { color: var(--coach-info); font-style: normal; font-weight: 600; }
.coach-teach .ct-body ul {
  margin: 0 0 10px; padding-left: 18px;
}
.coach-teach .ct-body li { margin-bottom: 4px; }

/* ─── settings panel ─── */
.coach-settings {
  position: absolute;
  top: 56px; right: 12px;
  background: #fff; border: 1px solid var(--coach-border); border-radius: 10px;
  box-shadow: 0 12px 28px -8px rgba(15,23,42,0.18);
  padding: 10px 12px;
  display: none; flex-direction: column; gap: 8px;
  width: 220px;
  z-index: 10;
}
.coach-settings.open { display: flex; }
.coach-settings .cs-row {
  display: flex; align-items: center; gap: 10px;
  font-size: 12.5px; cursor: pointer;
  padding: 6px 0;
}
.coach-settings .cs-row input { margin: 0; }
.coach-settings .cs-row .cs-meta {
  font-size: 11px; color: var(--coach-muted);
  margin-top: 2px;
}
.coach-settings .cs-divider { height: 1px; background: var(--coach-border); margin: 2px 0; }
.coach-settings .cs-link {
  font-size: 12px; color: var(--coach-accent); cursor: pointer;
  background: none; border: none; padding: 4px 0; text-align: left; font-family: inherit;
}
.coach-settings .cs-link:hover { text-decoration: underline; }

/* ─── tiny "no lesson yet" empty state ─── */
.coach-empty {
  text-align: center; padding: 32px 16px;
  font-size: 12.5px; color: var(--coach-muted); line-height: 1.55;
}
.coach-empty .ce-icon { font-size: 28px; opacity: 0.5; margin-bottom: 8px; }

/* ─── reduced motion ─── */
@media (prefers-reduced-motion: reduce) {
  body.coach-ready, .coach-drawer { transition: none; }
}

/* ─── dark mode support (matches Cool Slate dark) ─── */
@media (prefers-color-scheme: dark) {
  :root {
    --coach-bg: #0f1218;
    --coach-surface: #161a22;
    --coach-border: #2a2f3a;
    --coach-text: #e6e8ec;
    --coach-muted: #9aa3b2;
    --coach-faint: #6b7280;
  }
  .coach-head { background: linear-gradient(180deg, #161a22, #0f1218); }
  .coach-invite { background: linear-gradient(135deg, #2a213d 0%, #1d2738 100%); border-color: #3a2f5c; color: #c4b5fd; }
  .qb-compare { border-left-color: #2a2f3a; }
}
