/*
 * delegation.css — Track N · Delegation Graph + Budget Simulator (V4)
 *
 * Page-specific layout on top of Track A's tokens (styles.css).
 * Implements the two-column Civic Candor delegation surface:
 *   Left  — topic delegation table + cumulative alignment + override-pending banner
 *   Right — participatory budget simulator: donut SVG + slider rows + audit receipt
 *
 * Design ground rules (PRD §6 + track-n.md §10):
 *   - All colours via var(--token). Zero hardcoded hex/rgb values.
 *   - Three-family type stack (--serif / --sans / --mono).
 *   - No emoji, no gradients, no rounded-left-border accent strips.
 *
 * Token reference (subset used here):
 *   --paper, --paper-2, --paper-3
 *   --ink, --ink-2, --ink-3, --ink-4
 *   --civic, --civic-soft
 *   --risk, --risk-soft
 *   --support, --support-soft
 *   --highlight
 *   --rule, --rule-soft
 *   --serif, --sans, --mono
 */

/* ─── Shell ──────────────────────────────────────────────────────────────── */

.deleg-shell {
  display: flex;
  flex-direction: column;
  height: 100vh;
  width: 100%;
  background: var(--paper);
  color: var(--ink);
  font-family: var(--sans);
  -webkit-font-smoothing: antialiased;
  overflow: hidden;
}

/* ─── Two-column body ────────────────────────────────────────────────────── */

.deleg-body {
  display: grid;
  grid-template-columns: 1fr 1fr;
  flex: 1;
  min-height: 0;
  overflow: hidden;
}

/* ─── Left column ────────────────────────────────────────────────────────── */

.deleg-left {
  padding: 24px 28px;
  border-right: 1px solid var(--rule);
  overflow-y: auto;
  display: flex;
  flex-direction: column;
}

/* ─── Masthead ───────────────────────────────────────────────────────────── */

.deleg-masthead {
  margin-bottom: 4px;
}

.deleg-masthead__row {
  display: flex;
  align-items: baseline;
  gap: 12px;
}

.deleg-masthead__wordmark {
  font-size: 22px;
  letter-spacing: -0.02em;
  color: var(--ink);
}

.deleg-masthead__tag {
  font-size: 9px;
  color: var(--ink-3);
  letter-spacing: 0.12em;
  text-transform: uppercase;
}

/* ─── Headline + subline ─────────────────────────────────────────────────── */

.deleg-headline {
  font-size: 34px;
  margin: 8px 0 4px;
  line-height: 1.1;
  letter-spacing: -0.01em;
  text-wrap: balance;
  color: var(--ink);
}

.deleg-sub {
  font-size: 13px;
  color: var(--ink-3);
  margin: 0 0 22px;
  line-height: 1.5;
  max-width: 380px;
}

/* ─── "You" summary block ────────────────────────────────────────────────── */

.deleg-you-block {
  display: flex;
  align-items: stretch;
  border: 1px solid var(--rule);
  margin-bottom: 20px;
}

.deleg-you-block__left {
  width: 110px;
  padding: 16px 14px;
  background: var(--ink);
  color: var(--paper);
  display: flex;
  flex-direction: column;
  justify-content: center;
  flex-shrink: 0;
}

.deleg-you-block__label {
  font-size: 9px;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  opacity: 0.7;
  color: var(--paper);
}

.deleg-you-block__name {
  font-size: 20px;
  line-height: 1;
  margin-top: 4px;
  color: var(--paper);
}

.deleg-you-block__meta {
  font-size: 10px;
  opacity: 0.7;
  margin-top: 6px;
  color: var(--paper);
}

.deleg-you-block__right {
  flex: 1;
  padding: 12px 14px;
  background: var(--paper);
}

.deleg-you-block__sub {
  font-size: 9px;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--ink-3);
  margin-bottom: 6px;
}

.deleg-you-block__score-row {
  display: flex;
  align-items: baseline;
  gap: 8px;
  margin-bottom: 6px;
}

.deleg-you-block__score {
  font-size: 26px;
  line-height: 1;
  color: var(--ink);
}

.deleg-you-block__delta {
  font-size: 11px;
  color: var(--support);
}

.deleg-you-block__bar-track {
  height: 3px;
  background: var(--paper-3);
  display: flex;
}

.deleg-you-block__bar-fill {
  height: 100%;
  background: var(--civic);
  transition: width 0.3s ease;
}

/* ─── Override-pending banner ────────────────────────────────────────────── */

.deleg-override-banner {
  margin-bottom: 20px;
  padding: 14px;
  background: var(--highlight);
  border: 1px solid oklch(75% 0.1 85);
  display: flex;
  align-items: flex-start;
  gap: 12px;
}

.deleg-override-banner[hidden] { display: none; }

.deleg-override-banner__label {
  font-size: 9px;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: oklch(40% 0.12 65);
  margin-top: 2px;
  flex-shrink: 0;
}

.deleg-override-banner__body {
  flex: 1;
  font-size: 13px;
  color: var(--ink);
  line-height: 1.4;
}

.deleg-override-banner__body strong { font-weight: 600; }

.deleg-override-banner__actions {
  display: flex;
  gap: 6px;
  font-size: 11px;
  margin-top: 6px;
  flex-wrap: wrap;
}

/* ─── Delegation table ───────────────────────────────────────────────────── */

.deleg-table {
  display: flex;
  flex-direction: column;
  gap: 1px;
  background: var(--rule);
  border: 1px solid var(--rule);
}

.deleg-table__loading {
  padding: 16px;
  font-size: 12px;
  color: var(--ink-3);
  background: var(--paper);
}

.deleg-table__row {
  background: var(--paper);
  padding: 14px 16px;
  display: grid;
  grid-template-columns: 1fr 1.1fr 80px 90px;
  gap: 14px;
  align-items: center;
}

.deleg-table__topic {
  /* topic name + trail */
}

.deleg-table__topic-name {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  font-weight: 500;
  color: var(--ink);
}

.deleg-table__topic-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  flex-shrink: 0;
}

.deleg-table__trail {
  font-family: var(--mono);
  font-size: 10px;
  color: var(--ink-3);
  margin-top: 2px;
}

.deleg-table__delegate-name {
  font-size: 13px;
  color: var(--ink);
}

.deleg-table__delegate-role {
  font-size: 10.5px;
  color: var(--ink-3);
}

.deleg-table__delegate-self {
  font-size: 12px;
  font-style: italic;
  color: var(--ink-2);
}

.deleg-table__align-score {
  font-family: var(--mono);
  font-size: 16px;
  font-weight: 500;
  line-height: 1;
}

.deleg-table__align-score--high   { color: var(--support); }
.deleg-table__align-score--mid    { color: var(--civic);   }
.deleg-table__align-score--low    { color: var(--risk);    }

.deleg-table__align-label {
  font-size: 9.5px;
  color: var(--ink-3);
}

.deleg-table__align-direct {
  font-family: var(--mono);
  font-size: 10px;
  color: var(--ink-3);
}

.deleg-table__actions {
  display: flex;
  gap: 4px;
  justify-content: flex-end;
}

.deleg-table__btn {
  font-family: var(--mono);
  font-size: 9px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  padding: 5px 7px;
  border: 1px solid var(--rule);
  background: transparent;
  cursor: pointer;
  color: var(--ink-2);
  border-radius: 2px;
  transition: opacity 0.1s ease;
}

.deleg-table__btn:hover { opacity: 0.7; }

.deleg-table__btn--revoke {
  border-color: var(--risk);
  color: var(--risk);
}

/* ─── Empty state ────────────────────────────────────────────────────────── */

.deleg-empty {
  margin-top: 20px;
  padding: 20px 16px;
  border: 1px dashed var(--rule);
  font-size: 13px;
  color: var(--ink-2);
  text-align: center;
  background: var(--paper);
}

.deleg-empty[hidden] { display: none; }

/* ─── Right column ───────────────────────────────────────────────────────── */

.deleg-right {
  padding: 24px 28px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
}

/* ─── Budget header ──────────────────────────────────────────────────────── */

.deleg-budget-tag {
  font-size: 9px;
  color: var(--ink-3);
  letter-spacing: 0.12em;
  text-transform: uppercase;
  margin-bottom: 8px;
}

.deleg-budget-headline {
  font-size: 28px;
  margin: 0 0 6px;
  line-height: 1.15;
  letter-spacing: -0.01em;
  text-wrap: balance;
  color: var(--ink);
}

.deleg-budget-sub {
  font-size: 12.5px;
  color: var(--ink-3);
  margin: 0 0 20px;
  line-height: 1.5;
}

.deleg-budget-total {
  color: var(--ink);
}

/* ─── Donut row ──────────────────────────────────────────────────────────── */

.deleg-donut-row {
  display: flex;
  gap: 24px;
  align-items: center;
  margin-bottom: 22px;
}

.deleg-donut-svg {
  width: 180px;
  height: 180px;
  flex-shrink: 0;
}

.deleg-aggregate {
  flex: 1;
}

.deleg-aggregate__header {
  font-size: 9px;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--ink-3);
  margin-bottom: 8px;
}

.deleg-aggregate__row {
  display: flex;
  gap: 8px;
  align-items: center;
  padding: 4px 0;
  font-size: 11.5px;
  border-bottom: 1px dashed var(--rule-soft);
}

.deleg-aggregate__row-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  flex-shrink: 0;
}

.deleg-aggregate__row-who {
  color: var(--ink-2);
  min-width: 90px;
}

.deleg-aggregate__row-order {
  color: var(--ink-3);
  font-size: 11px;
}

.deleg-aggregate__gap {
  margin-top: 10px;
  padding: 8px 10px;
  background: var(--paper);
  font-size: 11px;
  color: var(--ink-2);
  line-height: 1.5;
}

/* ─── Sliders ────────────────────────────────────────────────────────────── */

.deleg-sliders {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-bottom: 20px;
}

.deleg-slider-row {
  display: grid;
  grid-template-columns: 130px 1fr 54px 52px;
  gap: 12px;
  align-items: center;
}

.deleg-slider-row__label {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 12px;
  color: var(--ink);
}

.deleg-slider-row__dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  flex-shrink: 0;
}

.deleg-slider-row__track {
  height: 6px;
  background: var(--paper-3);
  position: relative;
  overflow: hidden;
}

.deleg-slider-row__fill {
  height: 100%;
  transition: width 0.15s ease;
}

.deleg-slider-row__pct {
  font-family: var(--mono);
  font-size: 12px;
  text-align: right;
  color: var(--ink);
}

.deleg-slider-row__btns {
  display: flex;
  gap: 2px;
}

.deleg-slider-row__btn {
  width: 22px;
  height: 22px;
  border: 1px solid var(--rule);
  background: var(--paper);
  cursor: pointer;
  font-family: inherit;
  font-size: 14px;
  line-height: 1;
  border-radius: 2px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--ink);
  transition: background 0.1s ease;
}

.deleg-slider-row__btn:hover {
  background: var(--paper-3);
}

/* ─── Audit receipt ──────────────────────────────────────────────────────── */

.deleg-receipt {
  border: 1px solid var(--rule);
  background: var(--paper);
  padding: 14px;
  margin-bottom: 16px;
}

.deleg-receipt__header {
  font-size: 9px;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--ink-3);
  margin-bottom: 8px;
}

.deleg-receipt__body {
  font-size: 11px;
  color: var(--ink-2);
  line-height: 1.5;
  margin-bottom: 10px;
}

.deleg-receipt__hash {
  font-size: 10px;
  color: var(--ink-3);
  word-break: break-all;
  line-height: 1.4;
}

.deleg-receipt__badge {
  display: inline-block;
  margin-left: 6px;
  color: var(--support);
  font-size: 10px;
}

.deleg-receipt__badge[hidden] { display: none; }

/* ─── Actions ────────────────────────────────────────────────────────────── */

.deleg-actions {
  display: flex;
  gap: 8px;
}

.deleg-actions__submit {
  flex: 1;
}

/* ─── Responsive collapse ────────────────────────────────────────────────── */
/* Below 900px: budget panel stacks below delegation graph.                   */

@media (max-width: 900px) {
  .deleg-shell {
    height: auto;
    min-height: 100vh;
    overflow: visible;
  }

  .deleg-body {
    grid-template-columns: 1fr;
    grid-template-rows: auto auto;
    overflow: visible;
  }

  .deleg-left {
    border-right: none;
    border-bottom: 1px solid var(--rule);
    overflow-y: visible;
  }

  .deleg-right {
    overflow-y: visible;
  }

  .deleg-donut-row {
    flex-direction: column;
    align-items: flex-start;
  }

  .deleg-donut-svg {
    width: 160px;
    height: 160px;
  }
}

/* Tablet portrait (641–820px) — retain the 2-rail Delegation + Budget
 * side-by-side layout instead of stacking. Column ratios shift slightly
 * to give the slider table room for percentages on a portrait viewport. */
@media (min-width: 641px) and (max-width: 820px) {
  .deleg-shell {
    height: 100vh;
    overflow: hidden;
  }
  .deleg-body {
    grid-template-columns: 1fr 1fr;
    grid-template-rows: none;
    overflow: hidden;
  }
  .deleg-left {
    border-right: 1px solid var(--rule);
    border-bottom: none;
    padding: 18px 16px;
    overflow-y: auto;
  }
  .deleg-right {
    padding: 18px 16px;
    overflow-y: auto;
  }
}

@media (max-width: 640px) {
  .deleg-left,
  .deleg-right {
    padding: 16px;
  }

  .deleg-table__row {
    grid-template-columns: 1fr 1fr;
    grid-template-rows: auto auto;
    row-gap: 8px;
  }

  .deleg-slider-row {
    grid-template-columns: 110px 1fr 44px 44px;
    gap: 8px;
  }
}

/* ── 375px-class refinements (≤480px) ────────────────────────────────────── */
/* Mobile responsiveness pass (HP52 §8.B.2). The 34px serif headline plus
 * the fixed 110px "You" inline block crowded the 343px content width
 * (375 viewport − 32px padding). Stack the You-block, shrink the
 * headlines, and collapse the slider row so the topic + percentage
 * stack vertically — both still readable, no overflow. */
@media (max-width: 480px) {
  .deleg-headline { font-size: 26px; }
  .deleg-budget-headline { font-size: 22px; }
  .deleg-you-block {
    flex-direction: column;
  }
  .deleg-you-block__left {
    width: 100%;
    padding: 12px 14px;
  }
  .deleg-table__row {
    grid-template-columns: 1fr;
    grid-template-rows: auto auto auto auto;
    row-gap: 6px;
  }
  .deleg-slider-row {
    grid-template-columns: 1fr 40px 50px;
    grid-template-rows: auto auto;
    gap: 6px;
    align-items: center;
  }
  .deleg-slider-row__label {
    grid-column: 1 / -1;
  }
  .deleg-slider-row__track {
    grid-column: 1 / 2;
    grid-row: 2;
  }
  .deleg-slider-row__pct {
    grid-column: 2 / 3;
    grid-row: 2;
  }
  .deleg-slider-row__btns {
    grid-column: 3 / 4;
    grid-row: 2;
  }
  .deleg-actions {
    flex-direction: column;
  }
}
