/* ═══════════════════════════════════════════════════════════════════════
   AE Commission Tool — page-specific styles for /commission
   ───────────────────────────────────────────────────────────────────────
   Global brand tokens come from App Hub's ae-brand.css cross-origin
   reference (see <link> in commission.html). This file holds only what's
   page-specific: layout grid, plan-summary card, this-month tiles,
   the event form, and history list.
   ═══════════════════════════════════════════════════════════════════════ */

:root {
  --ae-purple: #5F51D5;
  --ae-orange: #FF5233;
  --ae-bg: #f6f6f8;
  --ae-surface: #ffffff;
  --ae-text: #2a2a30;
  --ae-text-soft: #6a6a72;
  --ae-border: #e3e3ea;
  --ae-border-strong: #cfcfd6;
  --ae-success: #2f9e6e;
  --ae-warning: #d97706;
  --ae-danger: #d44848;
  --ae-radius: 10px;
  --ae-radius-sm: 6px;
  --ae-shadow-sm: 0 1px 2px rgba(20, 20, 30, 0.04);
  --ae-shadow-md: 0 6px 16px rgba(20, 20, 30, 0.06), 0 2px 4px rgba(20, 20, 30, 0.04);
}

* { box-sizing: border-box; }

/* The HTML `hidden` attribute MUST win over any author-set `display`
   value (.gate, .actor, .form-row, .picker-selected, etc. all set
   display:flex/grid which have equal specificity to the UA's
   [hidden]{display:none} and beat it on cascade order). Without this
   global override, every `<div hidden>` element renders as if it
   weren't hidden, with surprising and very-hard-to-debug results
   (see the /admin "Admin only" stuck-screen bug, 2026-05-08).
   Important: .drilldown[hidden] intentionally keeps display:flex !important
   (slide-out animation needs it in the layout). It has higher
   specificity (020) than [hidden] (010) so it still wins. */
[hidden] { display: none !important; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--ae-bg);
  color: var(--ae-text);
  font-family: 'Aeonik', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, system-ui, sans-serif;
  font-size: 15px;
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
}

/* ── Page chrome ───────────────────────────────────────────────── */
header.page-header {
  position: sticky;
  top: 0;
  background: var(--ae-surface);
  border-bottom: 1px solid var(--ae-border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 24px;
  z-index: 10;
}
header.page-header .brand {
  display: flex;
  align-items: center;
  gap: 12px;
  text-decoration: none;
  color: inherit;
}
header.page-header .brand img {
  height: 28px;
  width: auto;
}
header.page-header .brand-title {
  font-size: 0.95rem;
  font-weight: 500;
}
header.page-header .brand-subtitle {
  font-size: 0.8rem;
  color: var(--ae-text-soft);
}
header.page-header .actor {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 0.85rem;
}
header.page-header .actor .who {
  color: var(--ae-text-soft);
}
header.page-header .actor button {
  background: none;
  border: 1px solid var(--ae-border);
  border-radius: var(--ae-radius-sm);
  color: var(--ae-text);
  font: inherit;
  padding: 5px 10px;
  cursor: pointer;
}
header.page-header .actor button:hover {
  border-color: var(--ae-border-strong);
}

/* ── Main layout ───────────────────────────────────────────────── */
main.page {
  max-width: 1100px;
  margin: 0 auto;
  padding: 24px;
}
main.page h1 {
  font-size: 1.6rem;
  font-weight: 600;
  margin: 0 0 6px;
}
main.page .page-subtitle {
  color: var(--ae-text-soft);
  margin: 0 0 24px;
  font-size: 0.95rem;
}

/* ── Hero card ─────────────────────────────────────────────────── */
.hero {
  background: linear-gradient(180deg, #ffffff 0%, #faf9ff 100%);
  border: 1px solid var(--ae-border);
  border-radius: 14px;
  padding: 28px 32px;
  margin-bottom: 14px;
  box-shadow: var(--ae-shadow-md);
}
.hero-greeting {
  font-size: 1.05rem;
  font-weight: 500;
}
.hero-period {
  color: var(--ae-text-soft);
  margin-bottom: 18px;
  font-size: 0.9rem;
}
.hero-amount {
  font-size: 3rem;
  font-weight: 600;
  color: var(--ae-purple);
  font-variant-numeric: tabular-nums;
  line-height: 1;
  margin-bottom: 4px;
}
.hero-amount-label {
  font-size: 0.9rem;
  color: var(--ae-text-soft);
  margin-bottom: 14px;
}
.hero-delta {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 4px 10px;
  border-radius: 999px;
  font-size: 0.8rem;
  font-weight: 500;
}
.hero-delta.up { background: #dcfce7; color: #15803d; }
.hero-delta.down { background: #fee2e2; color: #b91c1c; }
.hero-delta.neutral { background: #f1f1f5; color: var(--ae-text-soft); }
.hero-delta svg { stroke: currentColor; }

/* ── Supporting tiles ──────────────────────────────────────────── */
.tiles-row {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 12px;
  margin-bottom: 20px;
}
@media (max-width: 720px) {
  .tiles-row { grid-template-columns: 1fr; }
}

/* ── How-you-earn rules ────────────────────────────────────────── */
.earn-rules {
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.earn-rule {
  display: grid;
  grid-template-columns: 40px 1fr auto;
  align-items: center;
  gap: 14px;
  padding: 14px 16px;
  border: 1px solid var(--ae-border);
  border-radius: var(--ae-radius-sm);
  background: var(--ae-surface);
}
.earn-rule-icon {
  width: 40px;
  height: 40px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: #f3f1ff;
  color: var(--ae-purple);
  border-radius: 50%;
}
.earn-rule-text { display: flex; flex-direction: column; gap: 2px; }
.earn-rule-text-primary { font-weight: 500; }
.earn-rule-text-secondary {
  font-size: 0.82rem;
  color: var(--ae-text-soft);
}
.earn-rule-amount {
  font-size: 1.4rem;
  font-weight: 600;
  color: var(--ae-purple);
  font-variant-numeric: tabular-nums;
}

/* ── Two big CTAs ──────────────────────────────────────────────── */
.cta-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  margin-bottom: 4px;
}
@media (max-width: 560px) {
  .cta-grid { grid-template-columns: 1fr; }
}
.cta-card {
  background: var(--ae-surface);
  border: 1px solid var(--ae-border);
  border-radius: var(--ae-radius);
  padding: 18px 20px;
  text-align: left;
  cursor: pointer;
  font: inherit;
  color: inherit;
  display: flex;
  flex-direction: column;
  gap: 2px;
  transition: border-color 80ms, box-shadow 80ms, transform 80ms;
}
.cta-card:hover {
  border-color: var(--ae-purple);
  transform: translateY(-1px);
  box-shadow: 0 4px 12px rgba(95, 81, 213, 0.12);
}
.cta-card:focus-visible {
  outline: 2px solid color-mix(in srgb, var(--ae-purple) 35%, transparent);
  outline-offset: 2px;
}
.cta-card-icon {
  width: 40px;
  height: 40px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: #f3f1ff;
  color: var(--ae-purple);
  border-radius: 50%;
  margin-bottom: 10px;
}
.cta-card-label {
  font-weight: 600;
  font-size: 1.05rem;
  margin-bottom: 2px;
}
.cta-card-sub {
  font-size: 0.85rem;
  color: var(--ae-text-soft);
}

/* The CTAs replace the type-picker once the form opens. */
.type-picker-field { display: none; }

/* Active-type pill — header for the open form */
.active-type {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-size: 0.9rem;
  background: #f3f1ff;
  color: var(--ae-purple);
  padding: 6px 12px;
  border-radius: 999px;
  align-self: flex-start;
}
.active-type-label {
  color: var(--ae-text-soft);
  font-weight: 500;
}

/* ── Activity timeline ─────────────────────────────────────────── */
.timeline {
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.timeline-item {
  display: grid;
  grid-template-columns: 40px 1fr auto auto;
  gap: 14px;
  align-items: center;
  padding: 12px 14px;
  border: 1px solid var(--ae-border);
  border-radius: var(--ae-radius-sm);
  background: var(--ae-surface);
}
.timeline-item-icon {
  width: 40px;
  height: 40px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: #f3f1ff;
  color: var(--ae-purple);
  border-radius: 50%;
}
.timeline-item-content {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
}
.timeline-item-summary {
  font-weight: 500;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.timeline-item-meta {
  font-size: 0.82rem;
  color: var(--ae-text-soft);
}
.timeline-item-amount {
  font-weight: 600;
  color: var(--ae-purple);
  font-variant-numeric: tabular-nums;
}
@media (max-width: 560px) {
  .timeline-item {
    grid-template-columns: 32px 1fr auto;
  }
  .timeline-item .status-chip { grid-column: 2 / -1; justify-self: start; }
}

/* ── Cards / sections ──────────────────────────────────────────── */
.section {
  background: var(--ae-surface);
  border: 1px solid var(--ae-border);
  border-radius: var(--ae-radius);
  padding: 20px 24px;
  margin-bottom: 20px;
  box-shadow: var(--ae-shadow-sm);
}
.section-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 14px;
}
.section-header h2 {
  font-size: 1.05rem;
  font-weight: 600;
  margin: 0;
}
.section-header .section-meta {
  color: var(--ae-text-soft);
  font-size: 0.85rem;
}

/* ── Plan summary card ─────────────────────────────────────────── */
.plan-card {
  display: flex;
  flex-direction: column;
  gap: 16px;
}
.plan-meta {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
}
.plan-meta .plan-name {
  font-size: 1rem;
  font-weight: 500;
}
.plan-meta .plan-id {
  color: var(--ae-text-soft);
  font-family: 'DM Mono', ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 0.75rem;
}
.trigger-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 12px;
}
.trigger-card {
  border: 1px solid var(--ae-border);
  border-radius: var(--ae-radius-sm);
  padding: 14px;
  background: linear-gradient(180deg, #fafaff 0%, #ffffff 100%);
}
.trigger-card .trigger-label {
  font-weight: 500;
  margin-bottom: 6px;
}
.trigger-card .trigger-amount {
  font-size: 1.4rem;
  font-weight: 600;
  color: var(--ae-purple);
}
.trigger-card .trigger-detail {
  font-size: 0.82rem;
  color: var(--ae-text-soft);
  margin-top: 6px;
}

/* ── Stats tiles (this-month tally) ────────────────────────────── */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 12px;
}
.stat-tile {
  background: var(--ae-surface);
  border: 1px solid var(--ae-border);
  border-radius: var(--ae-radius);
  padding: 16px 18px;
}
.stat-tile .stat-label {
  font-size: 0.78rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--ae-text-soft);
  margin-bottom: 6px;
}
.stat-tile .stat-value {
  font-size: 1.6rem;
  font-weight: 600;
}
.stat-tile .stat-detail {
  font-size: 0.82rem;
  color: var(--ae-text-soft);
  margin-top: 4px;
}

/* ── Log-event panel ───────────────────────────────────────────── */
.cta-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}
.btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font: inherit;
  font-weight: 500;
  border-radius: var(--ae-radius-sm);
  padding: 9px 16px;
  cursor: pointer;
  border: 1px solid transparent;
  transition: background 80ms, border-color 80ms;
}
.btn-primary {
  background: var(--ae-purple);
  color: white;
}
.btn-primary:hover { background: #4f43c2; }
.btn-primary:disabled { opacity: 0.5; cursor: not-allowed; }
.btn-secondary {
  background: var(--ae-surface);
  color: var(--ae-text);
  border-color: var(--ae-border-strong);
}
.btn-secondary:hover { background: #f3f3f7; }
.btn-ghost {
  background: transparent;
  color: var(--ae-text-soft);
  border-color: transparent;
}
.btn-ghost:hover { background: #f0f0f5; color: var(--ae-text); }

/* ── Form ──────────────────────────────────────────────────────── */
.form {
  display: grid;
  gap: 16px;
}
.form-row {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 12px;
}
.field {
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.field label {
  font-size: 0.85rem;
  font-weight: 500;
}
.field .field-hint {
  font-size: 0.78rem;
  color: var(--ae-text-soft);
}
.field input,
.field select,
.field textarea {
  font: inherit;
  border: 1px solid var(--ae-border-strong);
  border-radius: var(--ae-radius-sm);
  padding: 8px 10px;
  background: var(--ae-surface);
  color: var(--ae-text);
}
.field input:focus,
.field select:focus,
.field textarea:focus {
  outline: 2px solid color-mix(in srgb, var(--ae-purple) 35%, transparent);
  outline-offset: -1px;
  border-color: var(--ae-purple);
}
.field textarea { min-height: 70px; resize: vertical; }
.field-error {
  color: var(--ae-danger);
  font-size: 0.78rem;
  margin-top: 2px;
  min-height: 0.78rem;
}

/* Type picker (segmented) */
.type-picker {
  display: inline-flex;
  border: 1px solid var(--ae-border-strong);
  border-radius: var(--ae-radius-sm);
  overflow: hidden;
  background: var(--ae-surface);
}
.type-picker label {
  padding: 8px 14px;
  cursor: pointer;
  border-right: 1px solid var(--ae-border-strong);
  font-size: 0.9rem;
}
.type-picker label:last-child { border-right: 0; }
.type-picker input[type="radio"] { position: absolute; opacity: 0; pointer-events: none; }
.type-picker input[type="radio"]:checked + .type-pill {
  background: var(--ae-purple);
  color: white;
  margin: -8px -14px;
  padding: 8px 14px;
  display: block;
}

/* Bounty preview */
.bounty-preview {
  background: linear-gradient(180deg, #fff8ec 0%, #ffffff 100%);
  border: 1px solid #f5d29c;
  border-radius: var(--ae-radius-sm);
  padding: 12px 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.bounty-preview .bounty-amount {
  font-size: 1.3rem;
  font-weight: 600;
  color: #b15c00;
}
.bounty-preview .bounty-reason {
  font-size: 0.82rem;
  color: var(--ae-text-soft);
}

/* ── Partner picker ────────────────────────────────────────────── */
.picker {
  position: relative;
}
.picker-input {
  width: 100%;
}
.picker-listbox {
  position: absolute;
  top: calc(100% + 4px);
  left: 0;
  right: 0;
  max-height: 280px;
  overflow-y: auto;
  background: var(--ae-surface);
  border: 1px solid var(--ae-border-strong);
  border-radius: var(--ae-radius-sm);
  box-shadow: var(--ae-shadow-md);
  z-index: 20;
  display: none;
}
.picker-listbox.open { display: block; }
.picker-listbox .picker-status {
  padding: 10px 12px;
  font-size: 0.85rem;
  color: var(--ae-text-soft);
}
.picker-option {
  padding: 8px 12px;
  cursor: pointer;
  border-bottom: 1px solid var(--ae-border);
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.picker-option:last-child { border-bottom: 0; }
.picker-option:hover, .picker-option[aria-selected="true"] {
  background: #f3f1ff;
}
.picker-option .opt-primary {
  font-weight: 500;
}
.picker-option .opt-secondary {
  font-size: 0.78rem;
  color: var(--ae-text-soft);
}
.picker-selected {
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: #f3f1ff;
  border: 1px solid #d8d3f3;
  border-radius: var(--ae-radius-sm);
  padding: 8px 12px;
  font-size: 0.9rem;
}
.picker-selected button {
  font: inherit;
  background: none;
  border: 0;
  color: var(--ae-text-soft);
  cursor: pointer;
  padding: 2px 6px;
}
.picker-selected button:hover { color: var(--ae-text); }

/* ── Event history ─────────────────────────────────────────────── */
.history-empty {
  text-align: center;
  padding: 28px 12px;
  color: var(--ae-text-soft);
}
.history-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.history-item {
  display: grid;
  grid-template-columns: 110px 1fr auto auto auto;
  gap: 14px;
  align-items: center;
  padding: 10px 14px;
  border: 1px solid var(--ae-border);
  border-radius: var(--ae-radius-sm);
  background: var(--ae-surface);
}
.history-item .h-date {
  font-family: 'DM Mono', ui-monospace, monospace;
  font-size: 0.85rem;
  color: var(--ae-text-soft);
}
.history-item .h-summary {
  font-size: 0.92rem;
}
.history-item .h-summary .partner {
  font-weight: 500;
}
.history-item .h-bounty {
  font-weight: 600;
  color: var(--ae-purple);
  font-variant-numeric: tabular-nums;
}
.status-chip {
  font-size: 0.72rem;
  padding: 3px 8px;
  border-radius: 999px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  font-weight: 500;
}
.status-chip.pending  { background: #fff4d4; color: #806000; }
.status-chip.approved { background: #d8f1e3; color: var(--ae-success); }
.status-chip.paid     { background: #dde1f8; color: #4a4ac9; }
.status-chip.voided   { background: #f4d7d7; color: var(--ae-danger); }

/* ── Toast ─────────────────────────────────────────────────────── */
.toast {
  position: fixed;
  bottom: 24px;
  right: 24px;
  background: var(--ae-text);
  color: white;
  padding: 12px 18px;
  border-radius: var(--ae-radius-sm);
  font-size: 0.9rem;
  box-shadow: var(--ae-shadow-md);
  opacity: 0;
  transform: translateY(8px);
  transition: opacity 160ms, transform 160ms;
  pointer-events: none;
  z-index: 30;
}
.toast.show {
  opacity: 1;
  transform: translateY(0);
}
.toast.success { background: var(--ae-success); }
.toast.error   { background: var(--ae-danger); }

/* ── Form-collapsed/expanded states ────────────────────────────── */
.event-form { display: none; }
.event-form.open { display: grid; }

/* ── Skeletons ─────────────────────────────────────────────────── */
.skeleton {
  background: linear-gradient(90deg, #eaeaef 25%, #f3f3f7 37%, #eaeaef 63%);
  background-size: 400% 100%;
  border-radius: var(--ae-radius-sm);
  animation: ae-shimmer 1.4s ease-in-out infinite;
  color: transparent;
}
@keyframes ae-shimmer {
  0% { background-position: 100% 50%; }
  100% { background-position: 0 50%; }
}

/* Hide the Aeonik @font-face fallback flicker on first paint by
   keeping text invisible until fonts settle (FOIT). 200ms cap so
   a flaky font network doesn't permanently hide content. */
.font-loading * { visibility: hidden; }
