/* Costs page (costs.js): one card with the answer and the three figures side by side, the budget change and a
   footnote inside it, then the cost table.
   Card frame, stats, pills and states come from ui/ui.css; the budget bar colours from style.css. */
.costs-page > .ui-card, .costs-page > .costs-failure { margin-bottom: 16px; }

/* 1. The answer, with the figures beside it */
.costs-band { display: grid; grid-template-columns: minmax(0, 1fr) minmax(260px, 340px); gap: 24px 32px; align-items: start; }
.costs-answer-body { display: flex; flex-direction: column; gap: 12px; min-width: 0; }
.costs-answer-top { display: flex; flex-wrap: wrap; align-items: flex-start; justify-content: space-between; gap: 12px 24px; }
.costs-answer-words { flex: 1 1 320px; min-width: 0; }
.costs-page .costs-answer-title { display: flex; flex-wrap: wrap; align-items: baseline; gap: 4px 12px; margin: 0; font-size: 18px; line-height: 26px; font-weight: 500; color: var(--text); }
.costs-answer-amount { font-size: 40px; line-height: 48px; font-weight: 600; letter-spacing: -1px; font-variant-numeric: tabular-nums; color: var(--text); }
.costs-answer-amount.warn { color: var(--text); }
.costs-answer-amount.bad { color: #B91C1C; }
.costs-page .costs-answer-sub { margin: 0; font-size: 14px; line-height: 20px; color: var(--secondary); }
.costs-answer-tools { display: flex; flex-wrap: wrap; align-items: center; justify-content: flex-end; gap: 12px; }
.costs-answer-tools > button { min-height: var(--control-h); height: var(--control-h); padding: 0 24px; font-size: 14px; }
.costs-state:empty { display: none; }
.costs-page .costs-callout { display: flex; align-items: flex-start; gap: 8px; width: fit-content; max-width: 100%; margin: 0; padding: 8px 12px; border: 1px solid var(--border); border-radius: 8px; background: var(--page); color: var(--secondary); font-size: 14px; line-height: 20px; }
.costs-callout svg { flex: none; margin-top: 2px; }
.costs-page .costs-callout.good { border-color: #BBF7D0; background: #F0FDF4; color: #166534; }
.costs-page .costs-callout.warn { border-color: var(--warn-border); background: var(--warn-bg); color: var(--warn-text); }
.costs-page .costs-callout.bad { border-color: #FECACA; background: #FEF2F2; color: #991B1B; }
.costs-page .costs-bar { height: 16px; margin-top: 4px; }
.costs-scale { display: flex; flex-wrap: wrap; align-items: baseline; justify-content: space-between; gap: 8px 24px; font-size: 13px; line-height: 20px; }
.costs-scale .costs-legend { gap: 4px 24px; }
.costs-scale-end { margin-left: auto; color: var(--text); font-weight: 600; font-variant-numeric: tabular-nums; white-space: nowrap; }
.costs-bar-plain .limit-marker { display: none; }
.costs-loading { display: flex; flex-direction: column; gap: 16px; }

/* 2. Change budget: opens inside the card, under the answer */
.costs-change { margin-top: 16px; padding-top: 16px; border-top: 1px solid var(--border); }
.costs-page .costs-change-title { margin: 0; font-size: 16px; line-height: 24px; font-weight: 600; }
.costs-page .costs-change-hint { margin: 0 0 12px; font-size: 13px; line-height: 20px; color: var(--secondary); }
.costs-change-grid { display: grid; grid-template-columns: minmax(0, 1.25fr) minmax(260px, 1fr); gap: 24px 32px; align-items: start; }
.costs-change-main { display: flex; flex-direction: column; align-items: flex-start; min-width: 0; }
.costs-page .costs-field-label { display: block; margin: 0 0 8px; font-size: 14px; font-weight: 500; color: var(--text); }
.costs-money-field { position: relative; width: 100%; max-width: 240px; }
.costs-money-sign { position: absolute; left: 12px; top: 50%; transform: translateY(-50%); color: var(--muted); font-size: 14px; pointer-events: none; }
.costs-page .costs-money-field input { width: 100%; padding-left: 24px; font-variant-numeric: tabular-nums; }
.costs-page .costs-field-error { margin: 8px 0 0; font-size: 13px; line-height: 20px; color: #B91C1C; }
.costs-page .costs-field-error:empty { display: none; }
.costs-page [aria-invalid="true"] { border-color: #B91C1C; }
.costs-preview { align-self: stretch; }
.costs-preview:empty { display: none; }
.costs-page .costs-preview-line { display: flex; align-items: flex-start; gap: 8px; margin: 8px 0 0; font-size: 14px; line-height: 20px; color: #166534; }
.costs-page .costs-preview-line.bad { color: #991B1B; }
.costs-preview-line svg { flex: none; margin-top: 2px; }
.costs-page .costs-preview-bar { height: 12px; margin-top: 8px; }
.costs-confirm { align-self: stretch; margin-top: 12px; padding: 12px; border: 1px solid var(--border); border-radius: 8px; background: var(--page); }
.costs-page .costs-confirm-text { margin: 0 0 8px; font-size: 14px; line-height: 20px; color: var(--text); }
.costs-confirm input { width: 100%; max-width: 240px; }
.costs-change-actions { display: flex; flex-wrap: wrap; gap: 12px; margin-top: 12px; }
.costs-change-actions > button { min-height: var(--control-h); height: var(--control-h); padding: 0 24px; font-size: 14px; }
.costs-unit { padding: 16px; border: 1px solid var(--border); border-radius: var(--radius-card); background: var(--page); }
.costs-page .costs-unit-title { margin: 0 0 4px; font-size: 14px; line-height: 20px; font-weight: 600; }
.costs-unit-list { margin: 0; }
.costs-unit-row { display: flex; justify-content: space-between; align-items: baseline; gap: 12px; padding: 8px 0; border-bottom: 1px solid var(--border); }
.costs-unit-row:last-child { border-bottom: 0; padding-bottom: 0; }
.costs-unit-row dt { display: flex; flex-direction: column; min-width: 0; font-size: 14px; line-height: 20px; }
.costs-unit-row dt span { font-size: 12px; color: var(--muted); }
.costs-unit-row dd { margin: 0; font-size: 14px; font-weight: 600; text-align: right; font-variant-numeric: tabular-nums; }

/* 3. Figures: a short list beside the answer, label on the left and the figure on the right */
.costs-figures { min-width: 0; padding-left: 32px; border-left: 1px solid var(--border); }
.costs-figures .ui-stats { display: flex; flex-direction: column; gap: 0; }
.costs-figures .ui-stat { display: grid; grid-template-columns: minmax(0, 1fr) auto; align-items: baseline; gap: 0 12px; padding: 12px 0; border-bottom: 1px solid var(--border); }
.costs-figures .ui-stat:first-child { padding-top: 0; }
.costs-figures .ui-stat:last-child { padding-bottom: 0; border-bottom: 0; }
.costs-figures .ui-stat-value { font-size: 20px; line-height: 28px; text-align: right; }
.costs-figures .ui-stat-note { grid-column: 2; text-align: right; }
.costs-figures .skeleton-stats { display: flex; flex-direction: column; gap: 16px; }

/* 4. Footnote: the last line of the card */
.costs-footnote { margin: 16px 0 0; padding-top: 12px; border-top: 1px solid var(--border); font-size: 13px; line-height: 20px; color: var(--muted); }
.costs-page .costs-footnote-line { display: flex; align-items: flex-start; gap: 8px; margin: 0; font-size: 13px; color: var(--muted); }
.costs-footnote-line svg { flex: none; margin-top: 4px; }
.costs-more { margin-top: 0; }
.costs-more-list { max-width: 820px; margin: 4px 0 0; padding-left: 24px; color: var(--secondary); }
.costs-more-list li + li { margin-top: 4px; }

/* 5. Cost by environment: search and "Include deleted" sit in the heading row; rows are 40px */
#cost-table-card .ui-card-actions { flex: 1 1 auto; justify-content: flex-end; }
.costs-toolbar { display: flex; flex: 1 1 auto; flex-wrap: wrap; align-items: center; justify-content: flex-end; gap: 8px 16px; min-width: 0; }
.costs-search { flex: 0 1 340px; }
.costs-results:empty { display: none; }
.costs-page .costs-deleted { font-size: 13px; font-weight: 400; color: var(--secondary); cursor: pointer; }
.costs-table-wrap { overflow-x: auto; border: 1px solid var(--border); border-radius: 8px; }
.costs-table { width: 100%; border-collapse: separate; border-spacing: 0; font-size: 13px; }
.costs-table th, .costs-table td { box-sizing: border-box; height: 40px; padding: 0 12px; border-bottom: 1px solid var(--border); text-align: left; vertical-align: middle; white-space: nowrap; }
.costs-table thead th { height: 40px; background: var(--page); font-weight: 600; color: var(--secondary); }
.costs-table tbody tr:last-child > * { border-bottom: 0; }
.costs-table tbody th { min-width: 200px; white-space: normal; font-weight: 400; }
.costs-table .num { text-align: right; font-variant-numeric: tabular-nums; }
.costs-table tr.costs-group > * { height: 40px; }
.costs-table tr.costs-group:hover > * { background: var(--subtle); }
.costs-toggle { display: flex; align-items: center; gap: 8px; min-height: 32px; padding: 4px 0; border: 0; background: none; color: var(--text); font: inherit; text-align: left; }
.costs-toggle-text { display: flex; flex-wrap: wrap; align-items: baseline; gap: 0 8px; min-width: 0; }
.costs-toggle-text strong { font-weight: 600; overflow-wrap: anywhere; }
.costs-toggle-detail { font-size: 12px; color: var(--muted); }
.costs-chevron { flex: none; color: var(--muted); transition: transform .15s; }
.costs-toggle[aria-expanded="true"] .costs-chevron { transform: rotate(90deg); }
.costs-toggle:hover strong { color: var(--active-text); }
.costs-pill { display: inline-flex; align-items: center; gap: 8px; padding: 2px 12px; border-radius: 999px; background: var(--subtle); color: var(--secondary); font-size: 12px; font-weight: 600; }
.costs-pill::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.costs-pill.running { background: #DCFCE7; color: #166534; }
.costs-pill.paused { background: #EFEBE5; color: #4A453F; }
.costs-pill.shared { background: #DBEAFE; color: #1D4ED8; }
.costs-pill.deleted { background: transparent; color: var(--muted); padding-left: 0; }
.costs-table .share-col { width: 180px; }
.costs-share-bar { display: inline-flex; width: 96px; height: 8px; margin-right: 12px; border-radius: 999px; background: var(--subtle); overflow: hidden; vertical-align: middle; }
.costs-share-bar span { border-radius: 999px; background: #E0701F; }
.costs-share-value { font-variant-numeric: tabular-nums; color: var(--secondary); }
.costs-table tr.costs-resource > *, .costs-table tr.costs-history > * { color: var(--secondary); background: var(--page); }
.costs-table tr.costs-resource td:first-child { padding-left: 40px; white-space: normal; }
.costs-table tr.costs-resource-history td:first-child { padding-left: 64px; }
.costs-table tr.costs-history td:first-child { padding-left: 32px; white-space: normal; }
.costs-table tr.costs-history .costs-toggle strong { font-weight: 500; color: var(--secondary); }
.costs-resource-name > span { display: inline; }
.costs-resource-name > span + span { margin-left: 8px; }
.costs-resource-hours { font-size: 12px; color: var(--muted); }
.costs-table tr.costs-empty td { padding: 16px; white-space: normal; }
/* On a wide screen the table needs no sideways scroll, so its header can stay in view under the top bar. */
@media (min-width: 1000px) {
  .costs-table-wrap { overflow: clip; }
  .costs-table thead th { position: sticky; top: var(--bar-h, 56px); z-index: 1; }
}
@media (min-width: 701px) and (max-width: 999px) {
  .costs-table .share-col { width: auto; }
  .costs-share-bar { width: 64px; margin-right: 8px; }
}
.costs-pager { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 8px 16px; margin-top: 12px; }
.costs-pager-buttons { display: flex; align-items: center; gap: 12px; }
.costs-pager-buttons button { min-height: var(--control-h-compact); height: var(--control-h-compact); padding: 0 12px; font-size: 13px; }

@media (max-width: 900px) {
  .costs-change-grid { grid-template-columns: minmax(0, 1fr); }
  .costs-band { grid-template-columns: minmax(0, 1fr); gap: 16px; }
  .costs-figures { padding: 16px 0 0; border-left: 0; border-top: 1px solid var(--border); }
}
@media (max-width: 700px) {
  .costs-answer-amount { font-size: 32px; }
  .costs-answer-tools { flex: 1 1 100%; justify-content: flex-start; }
  .costs-answer-tools > button { flex: 1 1 auto; }
  .costs-figures .ui-stat { padding: 8px 0; }
  .costs-toolbar { flex: 1 1 100%; justify-content: flex-start; }
  .costs-search { flex: 1 1 100%; }
  /* The table becomes one block per environment */
  .costs-table-wrap { overflow: visible; }
  .costs-table thead { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
  .costs-table tr { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 16px; padding: 12px; border-bottom: 1px solid var(--border); }
  .costs-table tbody tr:last-child { border-bottom: 0; }
  .costs-table th, .costs-table td { display: block; height: auto !important; padding: 0 !important; border: 0; white-space: normal; text-align: left; }
  .costs-table tbody th, .costs-table td:first-child { flex: 1 1 100%; min-width: 0; }
  .costs-table td[data-label]::before { content: attr(data-label) " "; color: var(--muted); }
  .costs-table td.num { text-align: left; }
  .costs-table .share-col { width: auto; flex: 1 1 100%; }
  .costs-table td:empty, .costs-table td.share-col:not(:has(span)) { display: none; }
  .costs-table td.share-col[data-label]::before { content: none; }
  .costs-table tr.costs-group > * { height: auto; }
  .costs-table tr.costs-resource, .costs-table tr.costs-history { padding-left: 32px; background: var(--page); }
  .costs-table tr.costs-resource-history { padding-left: 48px; }
  .costs-table tr.costs-resource > *, .costs-table tr.costs-history > * { background: transparent; }
  .costs-table tbody tr.costs-resource td:first-child, .costs-table tr.costs-history td:first-child { padding-left: 0 !important; }
  .costs-table tr.costs-group td:nth-child(2) { order: 0; }
  .costs-pager { justify-content: center; }
}
.costs-footnote-row { display: flex; flex-wrap: wrap; align-items: center; gap: 4px 24px; }
.costs-footnote-row .text-button { min-height: 32px; margin-left: auto; padding: 0; font-size: 13px; font-weight: 500; color: var(--active-text); }
.costs-footnote-row .costs-more[open] { order: 3; flex: 1 1 100%; }
.costs-page .costs-preview-line.warn { color: var(--warn-text); }
.costs-page .costs-preview-line:not(.good):not(.warn):not(.bad) { color: var(--secondary); }
#budget-limit { appearance: textfield; -moz-appearance: textfield; }
#budget-limit::-webkit-outer-spin-button, #budget-limit::-webkit-inner-spin-button { -webkit-appearance: none; margin: 0; }
.costs-page .costs-callout.good { border-color: var(--border); background: var(--card); color: var(--text); }

.workspace-budgets {padding:24px;margin-block:24px;}
.workspace-budgets h2 {margin-top:0;}
.workspace-budgets>select {max-width:100%;min-width:220px;margin-block:12px;}
.spend-periods,.spend-controls {display:flex;align-items:end;flex-wrap:wrap;gap:16px;}
.spend-period {flex:1 1 260px;border:1px solid var(--border,#ded8d1);border-radius:12px;padding:16px;}
.spend-controls label {display:flex;flex-direction:column;gap:8px;flex:1 1 180px;max-width:300px;}
.spend-controls input {width:100%;}
.spend-form textarea {display:block;width:100%;max-width:650px;min-height:80px;margin-block:8px 16px;}
.spend-review {margin-top:20px;}
.spend-review button {margin:0 12px 8px 0;}
.workspace-budgets [hidden] {display:none!important;}
.spend-preview {margin-top:20px;padding:20px;border:1px solid var(--active-border,var(--border,#ded8d1));border-radius:12px;background:var(--active-bg,#fff5ec);}
.spend-preview>h3 {margin-top:0;}
.spend-preview-outcome {font-weight:600;}
.spend-environments {margin-block:20px;}
.spend-environment-list {margin:0;padding:0;list-style:none;}
.spend-environment-row {display:grid;grid-template-columns:minmax(0,1fr) minmax(0,2fr);gap:12px;padding:12px 0;border-bottom:1px solid var(--border,#ded8d1);overflow-wrap:anywhere;}
.spend-environment-row:last-child {border-bottom:0;}
.spend-environment-row small {display:block;margin-top:4px;color:var(--secondary);}
.spend-environment-row[data-state="failed"]>div {color:var(--danger-text,#a33124);}
@media(max-width:600px){.spend-preview{padding:14px;}.spend-environment-row{grid-template-columns:1fr;gap:4px;}}
