/**
 * 100x Philanthropy Module - Styles
 * Giving strategy, niche, principles
 */

/* Container */
.philanthropy-container {
  max-width: 1000px;
  margin: 0 auto;
  padding: 0 var(--spacing-md);
}

/* Header */
.philanthropy-header {
  display: flex;
  align-items: center;
  gap: var(--spacing-md);
  margin-bottom: var(--spacing-lg);
  padding-bottom: var(--spacing-md);
  border-bottom: 1px solid var(--border-color);
}

.philanthropy-header .back-btn {
  padding: var(--spacing-sm) var(--spacing-md);
  background: var(--bg-secondary);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  color: var(--text-secondary);
  cursor: pointer;
  transition: all var(--transition-fast);
}

.philanthropy-header .back-btn:hover {
  background: var(--bg-primary);
  color: var(--text-dark);
  border-color: var(--teal-accent);
}

.philanthropy-title h1 {
  font-family: var(--font-display);
  color: var(--text-dark);
  font-size: calc(2rem + var(--text-bump));
  margin: 0;
}

.philanthropy-title p {
  color: var(--text-secondary);
  margin: var(--spacing-xs) 0 0;
}

/* Context from Other Modules */
.philanthropy-context {
  background: linear-gradient(135deg, var(--teal-light) 0%, var(--bg-secondary) 100%);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  padding: var(--spacing-lg);
  margin-bottom: var(--spacing-lg);
}

.philanthropy-context h3 {
  font-family: var(--font-display);
  color: var(--text-dark);
  margin: 0 0 var(--spacing-md);
  font-size: calc(1rem + var(--text-bump));
  display: flex;
  align-items: center;
  gap: var(--spacing-sm);
}

.philanthropy-context h3 i {
  color: var(--teal-ink);
}

.philanthropy-context-item {
  padding: var(--spacing-sm) 0;
}

.philanthropy-context-item + .philanthropy-context-item {
  border-top: 1px solid var(--border-color);
  padding-top: var(--spacing-md);
  margin-top: var(--spacing-sm);
}

.philanthropy-context-label {
  font-size: calc(0.75rem + var(--text-bump));
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-muted);
  font-weight: 600;
}

.philanthropy-context-item p {
  margin: var(--spacing-xs) 0 0;
  color: var(--text-secondary);
  font-style: italic;
}

/* Sections */
.philanthropy-sections {
  display: flex;
  flex-direction: column;
  gap: var(--spacing-lg);
  margin-bottom: var(--spacing-lg);
}

.philanthropy-section {
  background: var(--bg-primary);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  padding: var(--spacing-lg);
  transition: all var(--transition-fast);
}

.philanthropy-section:hover {
  border-color: var(--teal-accent);
}

.philanthropy-section.has-content {
  background: linear-gradient(135deg, var(--bg-primary) 0%, var(--teal-light) 100%);
  border-color: var(--teal-accent);
}

.philanthropy-section-header {
  display: flex;
  align-items: flex-start;
  gap: var(--spacing-md);
  margin-bottom: var(--spacing-md);
}

.philanthropy-section-icon {
  width: 48px;
  height: 48px;
  border-radius: var(--radius-full);
  background: var(--bg-secondary);
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--teal-ink);
  font-size: calc(1.25rem + var(--text-bump));
  flex-shrink: 0;
}

.philanthropy-section.has-content .philanthropy-section-icon {
  background: var(--teal-fill);
  color: var(--text-on-accent);
}

.philanthropy-section-info {
  flex: 1;
  min-width: 0;
}

.philanthropy-section-info h3 {
  font-family: var(--font-display);
  color: var(--text-dark);
  font-size: calc(1.125rem + var(--text-bump));
  margin: 0;
}

.philanthropy-section-info p {
  color: var(--text-secondary);
  font-size: calc(0.875rem + var(--text-bump));
  margin: var(--spacing-xs) 0 0;
}

.philanthropy-section-status {
  flex-shrink: 0;
}

.philanthropy-section-status .status-badge {
  color: var(--teal-ink);
  font-size: calc(1.25rem + var(--text-bump));
}

/* Prompt styling — the section's question, set in the serif voice
   (entry-area grammar, owner's 2026-08-23 redesign; type lives with
   .entry-prompt in components/entry-area.css). */
.philanthropy-prompt {
  margin-bottom: var(--spacing-sm);
}

/* Section content */
.philanthropy-section-content {
  margin-top: var(--spacing-md);
}

.philanthropy-textarea {
  width: 100%;
  padding: var(--spacing-md);
  font-family: var(--font-body);
  font-size: calc(1rem + var(--text-bump));
  line-height: 1.6;
  color: var(--text-dark);
  background: var(--bg-secondary);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  resize: vertical;
  transition: all var(--transition-fast);
}

.philanthropy-textarea:focus {
  border-color: var(--teal-accent);
  box-shadow: var(--focus-ring);
  background: var(--bg-primary);
}

/* Actions */
.philanthropy-actions {
  display: flex;
  justify-content: center;
  margin-bottom: var(--spacing-xl);
}

/* Chat Section */
.philanthropy-chat-section {
  margin-bottom: var(--spacing-lg);
}

.philanthropy-chat-cta {
  text-align: center;
  padding-top: var(--spacing-md);
}

/* Summary Section */
.philanthropy-summary {
  margin-bottom: var(--spacing-lg);
}

.philanthropy-stats {
  display: flex;
  gap: var(--spacing-lg);
  padding-top: var(--spacing-md);
  flex-wrap: wrap;
}

.philanthropy-stat {
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  padding: var(--spacing-md);
  background: var(--bg-secondary);
  border-radius: var(--radius-md);
  min-width: 100px;
}

.philanthropy-stat-number {
  font-size: calc(2rem + var(--text-bump));
  font-weight: 700;
  color: var(--teal-ink);
  line-height: 1;
}

.philanthropy-stat-icon {
  font-size: calc(1.5rem + var(--text-bump));
  line-height: 1;
}

.philanthropy-stat-icon .text-success {
  color: var(--success);
}

.philanthropy-stat-label {
  font-size: calc(0.75rem + var(--text-bump));
  color: var(--text-muted);
  margin-top: var(--spacing-xs);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

/* Chat Container */
.philanthropy-chat-container {
  max-width: 900px;
  margin: 0 auto;
  padding: 0 var(--spacing-md);
  display: flex;
  flex-direction: column;
  height: calc(100dvh - 150px);
}

.philanthropy-chat-container .interview-header {
  display: flex;
  align-items: center;
  gap: var(--spacing-md);
  padding-bottom: var(--spacing-md);
  border-bottom: 1px solid var(--border-color);
  margin-bottom: var(--spacing-md);
  flex-shrink: 0;
}

.philanthropy-chat-container .interview-header .back-btn {
  padding: var(--spacing-sm) var(--spacing-md);
  background: var(--bg-secondary);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  color: var(--text-secondary);
  cursor: pointer;
  transition: all var(--transition-fast);
}

.philanthropy-chat-container .interview-header .back-btn:hover {
  background: var(--bg-primary);
  color: var(--text-dark);
}

.philanthropy-chat-container .interview-title h2 {
  font-family: var(--font-display);
  margin: 0;
  color: var(--text-dark);
}

.philanthropy-chat-container .interview-title p {
  color: var(--text-secondary);
  margin: var(--spacing-xs) 0 0;
}

.philanthropy-chat-container .chat-container {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 0;
  background: var(--bg-primary);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  overflow: hidden;
}

.philanthropy-chat-container .chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: var(--spacing-md);
}

.philanthropy-chat-container .chat-input-container {
  display: flex;
  gap: var(--spacing-sm);
  padding: var(--spacing-md);
  border-top: 1px solid var(--border-color);
  background: var(--bg-secondary);
}

.philanthropy-chat-container .chat-input {
  flex: 1;
  padding: var(--spacing-sm) var(--spacing-md);
  font-family: var(--font-body);
  font-size: calc(1rem + var(--text-bump));
  color: var(--text-dark);
  background: var(--bg-primary);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  resize: none;
  max-height: 100px;
}

.philanthropy-chat-container .chat-input:focus {
  border-color: var(--teal-accent);
}

.philanthropy-chat-container .send-btn {
  padding: var(--spacing-sm) var(--spacing-md);
  background: var(--teal-fill);
  color: var(--text-on-accent);
  border: none;
  border-radius: var(--radius-md);
  cursor: pointer;
  transition: all var(--transition-fast);
}

.philanthropy-chat-container .send-btn:hover {
  background: var(--navy-primary);
}

.philanthropy-chat-container .interview-actions {
  flex-shrink: 0;
  padding-top: var(--spacing-md);
}

/* Success state for buttons */
.btn-success {
  background: var(--success) !important;
  border-color: var(--success) !important;
  color: var(--text-light) !important;
}

/* ===== Rails parity helpers =====
   Markup-only additions the Rails rebuild needs that the current Firebase app
   handled in JS. No new visual design — these just supply flow/states for the
   server-rendered surfaces (per-section autosave status, the chat opener
   bubble, and the synthesis error slot). */

/* Per-section autosave status line (Rails replaces the JS debounce indicator). */
.philanthropy-field-status {
  font-size: calc(0.8rem + var(--text-bump));
  color: var(--text-muted);
  margin-top: var(--spacing-sm);
  min-height: 1rem;
}

/* Module chat: the Rails surface wraps the shared streaming interview-chat
   component. The seeded opener renders as the first `.message.ai` bubble inside
   the chat (via messages/_opener), identical to a streamed reply; this just
   supplies the flow. */
.philanthropy-chat-body {
  display: flex;
  flex-direction: column;
  gap: var(--spacing-md);
  margin-bottom: var(--spacing-lg);
}

/* Synthesis blocked / unreadable response slot (contract §4). */
.philanthropy-synth-error {
  display: flex;
  align-items: center;
  gap: var(--spacing-sm);
  margin-top: var(--spacing-md);
  padding: var(--spacing-sm) var(--spacing-md);
  background: #fef2f2;
  border: 1px solid #fecaca;
  border-radius: var(--radius-md);
  color: #b91c1c;
  font-size: calc(0.9rem + var(--text-bump));
}

.philanthropy-synth-error i {
  color: #dc2626;
}

/* Dark Theme */
[data-theme="dark"] .philanthropy-container {
  color: var(--text-dark);
}

[data-theme="dark"] .philanthropy-section {
  background: var(--bg-secondary);
}

[data-theme="dark"] .philanthropy-section.has-content {
  background: linear-gradient(135deg, var(--bg-secondary) 0%, rgba(74, 155, 181, 0.15) 100%);
}

[data-theme="dark"] .philanthropy-context {
  background: linear-gradient(135deg, rgba(74, 155, 181, 0.1) 0%, var(--bg-secondary) 100%);
}

[data-theme="dark"] .philanthropy-section-icon {
  background: var(--bg-tertiary);
}

[data-theme="dark"] .philanthropy-stat {
  background: var(--bg-tertiary);
}

[data-theme="dark"] .philanthropy-textarea {
  background: var(--bg-tertiary);
}

[data-theme="dark"] .philanthropy-textarea:focus {
  background: var(--bg-primary);
}

[data-theme="dark"] .philanthropy-chat-container .chat-container {
  background: var(--bg-secondary);
}

[data-theme="dark"] .philanthropy-chat-container .chat-input-container {
  background: var(--bg-tertiary);
}

[data-theme="dark"] .philanthropy-chat-container .chat-input {
  background: var(--bg-secondary);
}

/* Responsive */
@media (max-width: 768px) {
  .philanthropy-header {
    flex-wrap: wrap;
  }

  .philanthropy-title h1 {
    font-size: calc(1.5rem + var(--text-bump));
  }

  .philanthropy-section-header {
    flex-wrap: wrap;
  }

  .philanthropy-section-icon {
    width: 40px;
    height: 40px;
    font-size: calc(1rem + var(--text-bump));
  }

  .philanthropy-stats {
    justify-content: center;
  }

  .philanthropy-stat {
    flex: 1;
    min-width: 80px;
  }

  .philanthropy-chat-container {
    height: calc(100dvh - 120px);
  }
}

/* Print */
@media print {
  .philanthropy-header .back-btn,
  .philanthropy-actions,
  .philanthropy-chat-section,
  .philanthropy-chat-launch,
  .philanthropy-chat-cta {
    display: none;
  }

  .philanthropy-section {
    break-inside: avoid;
    page-break-inside: avoid;
    box-shadow: none;
    border: 1px solid #ccc;
    margin-bottom: var(--spacing-md);
  }

  .philanthropy-context {
    background: #f5f5f5;
    border: 1px solid #ccc;
  }

  .philanthropy-textarea {
    border: 1px solid #ccc;
    background: #f9f9f9;
    min-height: 60px;
  }
}

/* ===========================================
   Master-detail shell (the Library shell's grammar in philanthropy- names:
   one elevated viewport-fit card split into a master rail and a detail pane,
   each owning its own scroll. The rail sits a tonal step below the pane so
   the selected row's lift off its 3px teal edge reads. Rows are list
   grammar (one line, may ellipsize); the pane holds the selection whole.

   Below 900px it collapses list-first: the rail fills the screen and
   .is-detail-open (server-set for explicit ?entry= links, client-set on row
   taps) pushes the pane full-screen with a back affordance.)
   =========================================== */

.philanthropy-shell {
  display: grid;
  grid-template-columns: minmax(300px, 348px) minmax(0, 1fr);
  background: var(--surface-card);
  border: 1px solid var(--border-light);
  box-shadow: var(--shadow-sm);
  /* The card fits the viewport under the sticky chrome (--chrome-height is
     published live by chrome_height_controller; the fallback covers the
     pre-JS first paint) so both panes scroll internally, app-like. */
  height: calc(100dvh - var(--chrome-height, 140px) - 3.25rem);
  min-height: 32rem;
  overflow: hidden;
  margin-block: 0.25rem 1.5rem;
}

/* Entrance: the hub's motion grammar, once per session. */
.philanthropy-shell[data-entrance="play"] > * {
  animation: motion-rise var(--motion-enter) var(--ease-out) backwards;
}

.philanthropy-shell[data-entrance="play"] > :nth-child(1) { animation-delay: 0ms; }
.philanthropy-shell[data-entrance="play"] > :nth-child(2) { animation-delay: 60ms; }

/* ── The master rail ─────────────────────────────────────────────────────── */

.philanthropy-master {
  overflow-y: auto;
  border-right: 1px solid var(--border-light);
  /* A quiet tonal step below the detail pane, so the selected row's lift
     to the card surface reads. */
  background: var(--surface-page);
}

.philanthropy-masthead {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  padding: 1rem 1rem 1.05rem;
  border-bottom: 1px solid var(--border-light);
}

/* The At-a-Glance summary as a compact rail card: same bones as the old
   full-width section, smaller rhythm. */
.philanthropy-glance-rail .philanthropy-stats {
  padding-top: 0;
  gap: 0.5rem;
  flex-wrap: nowrap;
}

.philanthropy-glance-rail .philanthropy-stat {
  flex: 1;
  min-width: 0;
  padding: 0.55rem 0.4rem;
}

.philanthropy-glance-rail .philanthropy-stat-number {
  font-size: calc(1.35rem + var(--text-bump));
}

.philanthropy-glance-rail .philanthropy-stat-icon {
  font-size: calc(1.1rem + var(--text-bump));
}

.philanthropy-glance-rail .philanthropy-stat-label {
  font-size: calc(0.65rem + var(--text-bump));
}

/* The AI chat launcher, quiet and full-width in the masthead. */
.philanthropy-chat-launch {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.45rem;
  min-height: var(--tap);
  padding: 0.5rem 0.9rem;
  font-family: var(--font-ui);
  font-weight: 500;
  font-size: calc(13px * var(--text-scale));
  color: var(--teal-ink);
  background: var(--surface-card);
  border: 1px solid var(--border-light);
  text-decoration: none;
  transition: background var(--motion-quick) var(--ease-out);
}

@media (hover: hover) {
  .philanthropy-chat-launch:hover {
    background: var(--teal-light);
  }
}

/* ── Sections: quiet labels over row groups ──────────────────────────────── */

.philanthropy-index {
  padding-bottom: 1.25rem;
}

.philanthropy-rail-section-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 1rem;
  padding: 1.2rem 1.25rem 0.45rem;
}

.philanthropy-rail-section-head h2 {
  font-family: var(--font-ui);
  font-weight: 500;
  font-size: calc(12px * var(--text-scale));
  text-transform: uppercase;
  letter-spacing: 0.16em;
  color: var(--text-secondary);
  margin: 0;
}

/* ── Rows ────────────────────────────────────────────────────────────────── */

.philanthropy-rows {
  list-style: none;
  margin: 0;
  padding: 0;
}

.philanthropy-row {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 0.75rem;
  padding: 0.6rem 1.1rem 0.65rem 0.95rem;
  min-height: var(--tap);
  border-left: 3px solid transparent;
  text-decoration: none;
  transition: background var(--motion-quick) var(--ease-out),
              border-color var(--motion-quick) var(--ease-out);
}

@media (hover: hover) {
  a.philanthropy-row:hover:not([aria-current]) {
    background: color-mix(in srgb, var(--surface-card) 65%, transparent);
  }
}

/* The selected row lifts to the detail pane's surface off a teal edge. */
.philanthropy-row[aria-current] {
  background: var(--surface-card);
  border-left-color: var(--teal-accent);
}

.philanthropy-row-body {
  min-width: 0; /* let titles ellipsize instead of widening the rail */
}

.philanthropy-row-title {
  display: block;
  font-family: var(--font-heading);
  font-weight: 500;
  font-size: calc(14.5px * var(--text-scale));
  line-height: 1.35;
  color: var(--navy-primary);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* One line, may ellipsize — list grammar; the pane never truncates. */
.philanthropy-row-meta {
  display: block;
  margin-top: 0.15rem;
  font-family: var(--font-body);
  font-size: calc(12.5px * var(--text-scale));
  line-height: 1.5;
  color: var(--text-secondary);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* The quiet done mark on a written section. */
.philanthropy-row-done {
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
  font-family: var(--font-ui);
  font-weight: 500;
  font-size: calc(11.5px * var(--text-scale));
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--teal-ink);
  white-space: nowrap;
}

/* ── The detail pane ─────────────────────────────────────────────────────── */

.philanthropy-detail {
  overflow-y: auto;
  background: var(--surface-card);
}

turbo-frame#philanthropy_detail {
  display: block;
  min-height: 100%;
}

.philanthropy-pane {
  min-height: 100%;
}

.philanthropy-article {
  max-width: 960px;
  margin-inline: auto;
  padding: clamp(2rem, 5vh, 3rem) clamp(1.5rem, 4vw, 2.75rem) 4rem;
}

/* Member text in this pane's editors keeps the standard editor typography
   (var(--font-body), computing to exactly what the family module's editors
   compute to). Saved answers can arrive wrapped in Trix heading blocks
   (synthesized/imported statements), and the global heading rule (base.css
   h1..h6 → var(--font-heading), Frank Ruhl Libre) was rendering them as
   ~21px serif inside the editor — actiontext.css only resets the heading's
   SIZE (1.2em), never its family. Scoped to the pane's editors only: saved
   statements displayed elsewhere keep their styling. */
.philanthropy-pane trix-editor.trix-content :is(h1, h2, h3, h4, h5, h6) {
  font-family: var(--font-body);
  font-size: inherit;
  line-height: inherit;
}

.philanthropy-detail-head {
  padding-bottom: 1.4rem;
  border-bottom: 1px solid var(--border-light);
  margin-bottom: 1.9rem;
}

.philanthropy-detail-heading {
  font-family: var(--font-heading);
  font-weight: 500;
  font-size: calc(26px * var(--text-scale));
  line-height: 1.32;
  color: var(--navy-primary);
  margin: 0;
  text-wrap: balance;
}

.philanthropy-eyebrow {
  font-family: var(--font-ui);
  font-weight: 500;
  font-size: calc(12px * var(--text-scale));
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--text-secondary);
  margin: 0 0 0.6rem;
}

.philanthropy-detail-head .philanthropy-section-description {
  margin: 0.6rem 0 0;
  color: var(--text-secondary);
  font-size: calc(0.9rem + var(--text-bump));
}

/* ── The back affordance: narrow screens only ────────────────────────────── */

.philanthropy-detail-back {
  display: none;
  align-items: center;
  gap: 0.1rem;
  min-height: var(--tap);
  padding: 0.9rem clamp(1.25rem, 5vw, 2rem) 0;
  font-family: var(--font-ui);
  font-weight: 500;
  font-size: calc(12.5px * var(--text-scale));
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--teal-ink);
  text-decoration: none;
}

.philanthropy-detail-back .fa-sharp {
  font-size: 1.35em;
}

/* ── Narrow: list-first, detail pushes full-screen ───────────────────────── */

@media (max-width: 899.98px) {
  .philanthropy-shell {
    display: block;
    height: auto;
    min-height: 0;
    overflow: visible;
  }

  .philanthropy-master {
    border-right: 0;
    overflow: visible;
  }

  .philanthropy-detail {
    display: none;
    overflow: visible;
  }

  .philanthropy-shell.is-detail-open .philanthropy-master {
    display: none;
  }

  .philanthropy-shell.is-detail-open .philanthropy-detail {
    display: block;
  }

  .philanthropy-detail-back {
    display: inline-flex;
  }

  .philanthropy-article {
    padding-top: 1.25rem;
  }
}

@media (prefers-reduced-motion: reduce) {
  .philanthropy-shell[data-entrance="play"] > * {
    animation: none;
  }
}
