/* ============================================================
   Page components: headers, hero, cards, queues, timeline, tabs, profiles.
   Uses the tokens defined in app.css.
   ============================================================ */
.page-header { display: flex; flex-wrap: wrap; align-items: flex-end; justify-content: space-between; gap: var(--sp-4); margin-bottom: var(--sp-6); }
.page-header-text { min-width: 0; flex: 1 1 320px; }
.page-header h1 { margin: 0; }
.eyebrow { font-size: var(--fs-xs); font-weight: 600; text-transform: uppercase; letter-spacing: 0.08em; color: var(--muted); margin: 0 0 var(--sp-2); }
.eyebrow a { color: var(--muted); text-decoration: none; }
.eyebrow a:hover { color: var(--primary); text-decoration: underline; }
.page-sub { color: var(--muted); margin: var(--sp-2) 0 0; max-width: 70ch; }
.page-header-actions { display: flex; flex-wrap: wrap; gap: var(--sp-2); }
.page-head .page-header { margin-bottom: var(--sp-4); flex: 1; }

.section-head { display: flex; align-items: center; justify-content: space-between; gap: var(--sp-3); margin: var(--sp-8) 0 var(--sp-3); }
.section-head h2 { margin: 0; display: flex; align-items: center; gap: var(--sp-2); }
.card > .section-head:first-child { margin-top: 0; }
.count { display: inline-grid; place-items: center; min-width: 24px; height: 22px; padding: 0 7px; border-radius: 999px; background: var(--surface-3); color: var(--text-2); font-size: var(--fs-xs); font-weight: 700; }
.link-more { display: inline-flex; align-items: center; gap: 6px; font-size: var(--fs-sm); font-weight: 600; text-decoration: none; color: var(--primary); }
.link-more .icon { width: 15px; height: 15px; }
.ok-line { display: flex; align-items: center; gap: var(--sp-2); color: var(--green); font-weight: 500; margin: 0; }

.grid-4 { grid-template-columns: repeat(auto-fit, minmax(185px, 1fr)); }
.two-col { display: grid; gap: var(--sp-5); grid-template-columns: 1fr; margin-top: var(--sp-5); }
.two-col > * { min-width: 0; }
@media (min-width: 1100px) {
  .two-col { grid-template-columns: minmax(0, 1fr) 340px; }
  .side-sticky { position: sticky; top: calc(var(--topbar-h) + var(--sp-5)); align-self: start; }
}

/* hero (agent balance) */
.hero-grid { display: grid; gap: var(--sp-4); grid-template-columns: 1fr; }
@media (min-width: 860px) { .hero-grid { grid-template-columns: 1.4fr 1fr; } }
.hero { background: var(--navy); color: var(--navy-text); border-radius: var(--r-lg); padding: var(--sp-6); display: flex; flex-direction: column; justify-content: center; }
.hero-label { display: flex; align-items: center; gap: var(--sp-2); margin: 0; font-weight: 500; color: var(--navy-text); }
.hero-label .icon { color: #8fb3ff; }
.hero-value { font-size: clamp(2rem, 6vw, 2.75rem); font-weight: 700; letter-spacing: -0.03em; color: #fff; margin: var(--sp-2) 0; font-variant-numeric: tabular-nums; line-height: 1.1; }
.hero-note { margin: 0; color: var(--navy-muted); font-size: var(--fs-sm); max-width: 46ch; }
.hero-warn { display: flex; gap: var(--sp-2); align-items: center; margin: var(--sp-4) 0 0; padding: var(--sp-2) var(--sp-3); border-radius: var(--r-sm); background: #3b1717; color: #fecaca; font-size: var(--fs-sm); }
.kpi-stack { display: grid; gap: var(--sp-4); }

/* job cards */
.card-list { display: grid; gap: var(--sp-4); grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); }
.job-card { display: block; background: var(--surface); border: 1px solid var(--border); border-radius: var(--r); padding: var(--sp-5); color: var(--text); text-decoration: none; box-shadow: var(--shadow); transition: border-color 0.12s, transform 0.12s; }
.job-card:hover { border-color: var(--primary); color: var(--text); transform: translateY(-1px); }
.job-card-head { display: flex; justify-content: space-between; align-items: flex-start; gap: var(--sp-3); margin-bottom: var(--sp-4); }
.job-code { font-weight: 700; margin: 0; }
.job-desc { color: var(--muted); font-size: var(--fs-sm); margin: 2px 0 0; }
.job-card-foot { display: flex; flex-wrap: wrap; gap: var(--sp-4) var(--sp-6); margin-top: var(--sp-4); font-size: var(--fs-xs); color: var(--muted); }
.job-card-foot span { display: flex; flex-direction: column; gap: 2px; }
.job-card-foot strong { color: var(--text); font-size: var(--fs-sm); font-variant-numeric: tabular-nums; }
.job-flag { display: flex; align-items: center; gap: 6px; margin: var(--sp-3) 0 0; font-size: var(--fs-sm); font-weight: 600; color: var(--amber-text); }
.job-flag .icon { color: var(--amber); width: 16px; height: 16px; }

/* meter */
.meter-top { display: flex; justify-content: space-between; gap: var(--sp-2); font-size: var(--fs-sm); color: var(--text-2); margin-bottom: 6px; }
.meter-word { font-weight: 600; font-size: var(--fs-xs); }
.meter-bar { height: 8px; border-radius: 999px; background: var(--surface-3); overflow: hidden; }
.meter-bar span { display: block; height: 100%; border-radius: 999px; }
.meter-green .meter-bar span { background: var(--green); }
.meter-green .meter-word { color: var(--green); }
.meter-amber .meter-bar span { background: var(--amber); }
.meter-amber .meter-word { color: var(--amber); }
.meter-red .meter-bar span { background: var(--red); }
.meter-red .meter-word { color: var(--red); }

/* list rows */
.list-card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--r); box-shadow: var(--shadow); overflow: hidden; }
.list-card.flat { border: 0; box-shadow: none; border-radius: 0; margin: 0 calc(-1 * var(--sp-2)); }
.list-row { display: flex; align-items: center; gap: var(--sp-3); padding: var(--sp-3) var(--sp-4); border-bottom: 1px solid var(--border); color: var(--text); text-decoration: none; }
.list-row:last-child { border-bottom: 0; }
a.list-row:hover { background: var(--surface-2); color: var(--text); }
.row-ico { display: inline-grid; place-items: center; width: 36px; height: 36px; border-radius: 9px; background: var(--surface-3); color: var(--text-2); flex: 0 0 auto; }
.ico-amber { background: var(--amber-bg); color: var(--amber); }
.ico-red { background: var(--red-bg); color: var(--red); }
.ico-green { background: var(--green-bg); color: var(--green); }
.row-main { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.row-main strong { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.row-main small { color: var(--muted); font-size: var(--fs-sm); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.row-side { display: flex; flex-direction: column; align-items: flex-end; gap: 4px; text-align: right; font-variant-numeric: tabular-nums; }
.row-side small { color: var(--muted); font-size: var(--fs-xs); }
.row-actions { display: flex; flex-wrap: wrap; gap: 6px; justify-content: flex-end; }
@media (max-width: 480px) {
  .list-row { flex-wrap: wrap; }
  .row-side { flex-direction: row; align-items: center; width: 100%; justify-content: space-between; padding-left: 48px; }
}

/* task queue (approver / finance) */
.task-list { display: grid; gap: var(--sp-3); }
.task { display: grid; grid-template-columns: auto 1fr auto auto; align-items: center; gap: var(--sp-4); padding: var(--sp-4) var(--sp-5); background: var(--surface);
  border: 1px solid var(--border); border-left: 4px solid var(--amber); border-radius: var(--r); color: var(--text); text-decoration: none; box-shadow: var(--shadow); }
.task:hover { border-color: var(--primary); border-left-color: var(--primary); color: var(--text); }
.task-main { min-width: 0; display: flex; flex-direction: column; gap: 2px; }
.task-title { display: flex; gap: 6px; flex-wrap: wrap; }
.task-sub { color: var(--text-2); font-size: var(--fs-sm); }
.task-chips { display: flex; flex-wrap: wrap; align-items: center; gap: var(--sp-2); margin-top: 4px; }
.task-chips .icon { width: 14px; height: 14px; vertical-align: -2px; }
.task-money { text-align: right; display: flex; flex-direction: column; font-variant-numeric: tabular-nums; }
.task-money small { color: var(--muted); font-size: var(--fs-xs); }
.task-money strong { font-size: var(--fs-lg); }
@media (max-width: 720px) {
  .task { grid-template-columns: auto 1fr; }
  .task-money { grid-column: 1 / -1; flex-direction: row; justify-content: space-between; align-items: baseline; text-align: left; border-top: 1px solid var(--border); padding-top: var(--sp-3); }
  .task-cta { grid-column: 1 / -1; width: 100%; }
}

/* pipeline */
.pipe { display: flex; gap: 3px; height: 14px; border-radius: 999px; overflow: hidden; background: var(--surface-3); margin: var(--sp-2) 0 var(--sp-4); }
.pipe-seg { display: block; min-width: 6px; }
.seg-gray { background: var(--gray); }
.seg-amber { background: var(--amber); }
.seg-blue { background: var(--blue); }
.seg-green { background: var(--green); }
.seg-red { background: var(--red); }
.pipe-legend { list-style: none; padding: 0; margin: 0; display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: var(--sp-2); }
.pipe-legend a { display: flex; align-items: center; justify-content: space-between; gap: var(--sp-2); padding: var(--sp-2) var(--sp-3); border: 1px solid var(--border); border-radius: var(--r-sm); text-decoration: none; color: var(--text); }
.pipe-legend a:hover { border-color: var(--primary); color: var(--text); }

/* activity feed */
.activity { list-style: none; padding: 0; margin: 0; display: grid; gap: var(--sp-4); }
.activity li { display: flex; gap: var(--sp-3); font-size: var(--fs-sm); line-height: 1.4; }
.activity small { display: block; color: var(--muted); font-size: var(--fs-xs); margin-top: 2px; }
.avatar-xs { width: 28px; height: 28px; font-size: 0.6875rem; background: var(--surface-3); color: var(--text-2); }
.avatar-lg { width: 48px; height: 48px; font-size: var(--fs-md); background: var(--primary-soft); color: var(--primary); }

/* timeline */
.timeline { list-style: none; margin: 0; padding: 0; position: relative; }
.tl-item { position: relative; display: flex; gap: var(--sp-4); padding-bottom: var(--sp-5); }
.tl-item:last-child { padding-bottom: 0; }
.tl-item:not(:last-child)::before { content: ""; position: absolute; left: 15px; top: 34px; bottom: 2px; width: 2px; background: var(--border); }
.tl-dot { display: inline-grid; place-items: center; width: 32px; height: 32px; border-radius: 50%; flex: 0 0 auto; background: var(--surface-3); color: var(--text-2); }
.tl-dot .icon { width: 16px; height: 16px; }
.tl-green .tl-dot { background: var(--green-bg); color: var(--green); }
.tl-red .tl-dot { background: var(--red-bg); color: var(--red); }
.tl-amber .tl-dot { background: var(--amber-bg); color: var(--amber); }
.tl-blue .tl-dot { background: var(--blue-bg); color: var(--blue); }
.tl-body { padding-top: 5px; min-width: 0; }
.tl-title { font-weight: 600; margin: 0; }
.tl-meta { color: var(--muted); font-size: var(--fs-sm); margin: 2px 0 0; }
.tl-text { margin-top: var(--sp-2); font-size: var(--fs-sm); color: var(--text-2); background: var(--surface-2); border: 1px solid var(--border); border-radius: var(--r-sm); padding: var(--sp-2) var(--sp-3); }
.tl-text:empty { display: none; }

/* summary panel */
.summary { margin: 0; }
.summary-row { display: flex; justify-content: space-between; gap: var(--sp-3); padding: 10px 0; border-bottom: 1px solid var(--border); font-size: var(--fs-sm); }
.summary-row:last-child { border-bottom: 0; }
.summary-row dt { color: var(--muted); }
.summary-row dd { margin: 0; font-weight: 600; text-align: right; white-space: nowrap; font-variant-numeric: tabular-nums; }
.summary-row.is-strong { background: var(--primary-soft); margin: 4px calc(-1 * var(--sp-3)); padding: 12px var(--sp-3); border-radius: var(--r-sm); border-bottom: 0; }
.summary-row.is-strong dt, .summary-row.is-strong dd { color: var(--blue-text); font-weight: 700; font-size: var(--fs-base); }
.summary-card h2, aside .card h2 { margin-top: 0; }
.hint { font-size: var(--fs-xs); font-weight: 600; padding: 1px 6px; border-radius: 4px; background: var(--amber-bg); color: var(--amber-text); cursor: help; }

/* budget (job) */
.budget-figs { display: grid; gap: var(--sp-5); grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); margin-bottom: var(--sp-5); }
.budget .label { font-size: var(--fs-sm); color: var(--muted); margin: 0; }
.budget .fig { font-size: 1.5rem; font-weight: 700; letter-spacing: -0.02em; margin: 4px 0; font-variant-numeric: tabular-nums; }
.calc-details > summary { cursor: pointer; font-weight: 600; list-style: none; display: flex; align-items: center; justify-content: space-between; min-height: 28px; }
.calc-details > summary::-webkit-details-marker { display: none; }
.calc-details > summary span { display: inline-flex; align-items: center; gap: var(--sp-2); }
.calc-details > summary::after { content: "Show"; font-size: var(--fs-sm); color: var(--primary); }
.calc-details[open] > summary::after { content: "Hide"; }
.calc-details[open] > summary { margin-bottom: var(--sp-4); }

/* toolbar, tabs, search */
.toolbar { display: flex; flex-wrap: wrap; justify-content: space-between; align-items: center; gap: var(--sp-3); margin-bottom: var(--sp-4); }
.tabs { display: flex; gap: 4px; overflow-x: auto; padding: 4px; background: var(--surface-3); border-radius: var(--r); max-width: 100%; scrollbar-width: thin; }
.tab { display: inline-flex; align-items: center; gap: 6px; min-height: 36px; padding: 0 var(--sp-3); border-radius: var(--r-sm); white-space: nowrap; color: var(--text-2); text-decoration: none; font-size: var(--fs-sm); font-weight: 600; }
.tab:hover { color: var(--text); background: var(--surface-2); }
.tab[aria-current="page"] { background: var(--surface); color: var(--text); box-shadow: var(--shadow); }
.tab-count { font-size: var(--fs-xs); color: var(--muted); background: var(--surface-3); border-radius: 999px; padding: 0 6px; min-width: 20px; text-align: center; }
.tab[aria-current="page"] .tab-count { background: var(--primary-soft); color: var(--primary); }
.search { position: relative; flex: 0 1 300px; min-width: 200px; }
.search .icon { position: absolute; left: 12px; top: 50%; transform: translateY(-50%); color: var(--muted); pointer-events: none; }
.search input { padding-left: 38px; min-height: 40px; }
@media (max-width: 640px) { .search { flex: 1 1 100%; } }
.row-link { cursor: pointer; }
.cell-sub { display: block; color: var(--muted); font-size: var(--fs-xs); font-weight: 400; margin-top: 2px; }
.who-cell { display: inline-flex; align-items: center; gap: var(--sp-2); }

/* agent profiles */
.profile-grid { display: grid; gap: var(--sp-4); grid-template-columns: repeat(auto-fill, minmax(290px, 1fr)); }
.profile { display: block; background: var(--surface); border: 1px solid var(--border); border-radius: var(--r); padding: var(--sp-5); color: var(--text); text-decoration: none; box-shadow: var(--shadow); transition: border-color 0.12s, transform 0.12s; }
.profile:hover { border-color: var(--primary); color: var(--text); transform: translateY(-1px); }
.profile.is-inactive { opacity: 0.75; }
.profile-head { display: flex; align-items: center; gap: var(--sp-3); }
.profile-id { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.profile-id small { color: var(--muted); font-size: var(--fs-sm); }
.profile-stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: var(--sp-2); margin: var(--sp-4) 0 0; padding-top: var(--sp-4); border-top: 1px solid var(--border); }
.profile-stats dt { font-size: var(--fs-xs); color: var(--muted); }
.profile-stats dd { margin: 2px 0 0; font-weight: 700; font-size: var(--fs-sm); font-variant-numeric: tabular-nums; }

/* chips (settings navigator) */
.chip-nav { display: flex; flex-wrap: wrap; gap: var(--sp-2); margin-bottom: var(--sp-5); position: sticky; top: var(--topbar-h); z-index: 5; padding: var(--sp-2) 0; background: var(--bg); }
.chip { display: inline-flex; align-items: center; min-height: 34px; padding: 0 var(--sp-3); border: 1px solid var(--border-strong); border-radius: 999px; background: var(--surface); color: var(--text-2); text-decoration: none; font-size: var(--fs-sm); font-weight: 500; }
.chip:hover { border-color: var(--primary); color: var(--primary); }
details.group { scroll-margin-top: calc(var(--topbar-h) + 64px); }
@media (max-width: 640px) { .chip-nav { position: static; flex-wrap: nowrap; overflow-x: auto; } .chip { white-space: nowrap; } }

/* empty states, toasts */
.empty-ico { display: inline-grid; place-items: center; width: 52px; height: 52px; border-radius: 14px; background: var(--primary-soft); color: var(--primary); margin-bottom: var(--sp-3); }
.empty-ico .icon { width: 24px; height: 24px; }
.empty-title { font-weight: 700; color: var(--text) !important; font-size: var(--fs-md); margin-bottom: var(--sp-1) !important; }
.toast { display: flex; align-items: center; gap: var(--sp-2); }

/* forms inside cards */
form.card > h2:first-child { margin-top: 0; padding-bottom: var(--sp-3); margin-bottom: var(--sp-5); border-bottom: 1px solid var(--border); }

@media print {
  .chip-nav, .toolbar, .page-header-actions { display: none !important; }
  .two-col { display: block; }
  .hero { background: #fff; color: #000; border: 1px solid #bbb; }
  .hero-value { color: #000; }
}
