/*
 * css/pages/account.css: /balance (SPEC 5.2), group account. Tokens only (css/tokens.css); the shared components
 * (band, card, amount, seg, tabs, table, chips, states, callout, steps) come from css/site.css untouched. What is
 * here is the page's own layout, designed at 360px first:
 *   .bal-head / .bal-who       the title row and the connected account pill
 *   .bal-grid                  Deposit beside Withdraw from 1024px
 *   .bal-steps                 approve and deposit as two numbered steps, each with its own button
 *   .bal-quote                 the ETH quote beside the pool's real balances (stacked under ~480px of card)
 *   .bal-grant                 the authorize form: one column, two from 640px, one row from 1280px
 *   .bal-table                 the grant table and the spend history: tables from 820px, labelled cards below
 *   .bal-sum                   the summaries inside the step dialogs (rendered outside <main>)
 */

/* ------------------------------------------------------------------------------------------------ head */
.bal-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 20px 24px; flex-wrap: wrap; }
.bal-head__copy { min-width: 0; }
.bal-who {
  display: inline-flex; align-items: center; gap: 10px; min-height: 36px; padding: 0 14px; max-width: 100%;
  border: 1px solid var(--line-strong); border-radius: var(--r-pill); background: var(--panel);
  font: 500 13px/1 var(--font-mono); color: var(--text); white-space: nowrap;
}
.bal-who__chain { color: var(--muted); padding-left: 10px; border-left: 1px solid var(--line-strong); }
@media (max-width: 479px) { .bal-who { width: 100%; justify-content: center; min-height: 44px; } }

/* ------------------------------------------------------------------------------------------------ page */
.bal { padding-bottom: var(--section); display: flex; flex-direction: column; gap: 24px; }
.bal-nw:empty { display: none; }
.bal-nw .state { max-width: 640px; }
.bal-body { display: flex; flex-direction: column; gap: 32px; }
.bal-overview { display: flex; flex-direction: column; gap: 12px; }
.bal-band dd { min-height: 1.3em; }
.bal-note { font-size: 14px; line-height: 1.55; color: var(--muted); max-width: 70ch; }
.bal-warn { color: var(--warn); }

.bal-grid { display: grid; grid-template-columns: minmax(0, 1fr); gap: 24px; align-items: start; }
@media (min-width: 1024px) { .bal-grid { grid-template-columns: minmax(0, 1.45fr) minmax(0, 1fr); } }

.bal-card { display: flex; flex-direction: column; gap: 20px; }
.bal-card__head { display: flex; flex-direction: column; gap: 6px; }
.bal-card__sub { font-size: 14.5px; line-height: 1.55; color: var(--body); max-width: 62ch; }
.bal-state:empty { display: none; }
.bal-state .state { padding: 18px; }
.bal-state > .chip { align-self: flex-start; }
.bal-state { display: flex; flex-direction: column; }
.bal-form { display: flex; flex-direction: column; gap: 20px; min-width: 0; }
.bal-form .callout { font-size: 14.5px; }
.bal-form.is-disabled-form .amount .input::placeholder { color: var(--faint); }

/* ------------------------------------------------------------------------------------------------ deposit */
.bal-dep { display: flex; flex-direction: column; gap: 20px; min-width: 0; }
.bal-tabs [role="tab"] { display: inline-flex; align-items: center; gap: 8px; }
.bal-tabs [role="tab"] .icon { color: var(--muted); }
.bal-tabs [role="tab"][aria-selected="true"] .icon { color: var(--accent); }
.bal-panel { min-width: 0; }
.bal-panel__lede { font-size: 14.5px; line-height: 1.55; color: var(--body); }
.bal-seg button { white-space: normal; line-height: 1.2; }

.bal-steps { list-style: none; display: flex; flex-direction: column; border: 1px solid var(--line); border-radius: var(--r3); background: var(--panel-3); }
.bal-step {
  display: grid; grid-template-columns: 28px minmax(0, 1fr); gap: 12px 14px; align-items: start;
  padding: 16px; border-bottom: 1px solid var(--line-row);
}
.bal-step:last-child { border-bottom: 0; }
.bal-step__n {
  width: 28px; height: 28px; display: grid; place-items: center; border-radius: 50%;
  border: 1px solid var(--line-strong); color: var(--muted); font: 600 13px/1 var(--font-mono);
}
.bal-step.is-next .bal-step__n { border-color: var(--accent); color: var(--accent); }
.bal-step.is-done .bal-step__n { border-color: var(--accent-line); background: var(--accent-tint); color: var(--accent); }
.bal-step__body { min-width: 0; display: flex; flex-direction: column; gap: 4px; padding-top: 3px; }
.bal-step__title { font: 700 15.5px/1.35 var(--font-body); color: var(--text); }
.bal-step__line { font-size: 14px; line-height: 1.55; color: var(--body); overflow-wrap: anywhere; }
.bal-step__go { grid-column: 2; justify-self: stretch; }
@media (min-width: 560px) {
  .bal-step { grid-template-columns: 28px minmax(0, 1fr) auto; align-items: center; }
  .bal-step__go { grid-column: 3; justify-self: end; }
  .bal-step__body { padding-top: 0; }
}

.bal-allow {
  display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 4px 16px;
  padding-top: 14px; border-top: 1px solid var(--line);
}
.bal-allow__text { font-size: 13px; line-height: 1.5; color: var(--muted); overflow-wrap: anywhere; min-width: 0; }
.bal-allow .btn--quiet { font-size: 14px; }

/* the ETH tab */
.bal-slip__box { position: relative; width: 150px; max-width: 100%; }
.bal-slip__box .input { padding-right: 40px; }
.bal-slip__unit { position: absolute; right: 14px; top: 50%; transform: translateY(-50%); font: 600 14px/1 var(--font-mono); color: var(--muted); pointer-events: none; }

.bal-quote { display: grid; grid-template-columns: minmax(0, 1fr); gap: 12px; }
@media (min-width: 560px) { .bal-quote { grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); } }
.bal-quote > .state { grid-column: 1 / -1; }
.bal-quote > .skeleton { grid-column: 1 / -1; padding: 8px 0; }
.bal-quote__main, .bal-quote__depth {
  display: flex; flex-direction: column; gap: 10px; min-width: 0;
  padding: 16px; border-radius: var(--r3); border: 1px solid var(--line); background: var(--panel-3);
}
.bal-quote__out { font: 500 24px/1.2 var(--font-mono); color: var(--text); font-variant-numeric: tabular-nums; overflow-wrap: anywhere; min-height: 1.2em; }
.bal-quote__rows { display: flex; flex-direction: column; }
.bal-quote__rows > div { display: flex; align-items: baseline; justify-content: space-between; gap: 4px 12px; flex-wrap: wrap; padding: 7px 0; border-top: 1px solid var(--line-row); }
.bal-quote__rows dt { font-size: 13.5px; color: var(--muted); }
.bal-quote__rows dd { font: 500 13.5px/1.4 var(--font-mono); color: var(--dim); font-variant-numeric: tabular-nums; text-align: right; overflow-wrap: anywhere; min-width: 0; }
.bal-quote__depth .note { margin-top: 2px; }
.bal-quote__warn { display: flex; align-items: flex-start; gap: 8px; font-size: 13.5px; line-height: 1.5; color: var(--warn); }
.bal-quote__warn .icon { margin-top: 2px; }

/* ------------------------------------------------------------------------------------------------ sections */
.bal-section { display: flex; flex-direction: column; gap: 20px; padding-top: 8px; }
.bal-section__head { display: flex; flex-direction: column; gap: 10px; }
.bal-section__line { font-size: 15.5px; line-height: 1.6; color: var(--body); max-width: 72ch; }
@media (max-width: 639px) { .bal-section__line { font-size: 15px; } }

/* authorize a key */
.bal-grant__fields { display: grid; grid-template-columns: minmax(0, 1fr); gap: 18px 20px; align-items: start; }
.bal-grant__fields .input[type="date"] { font: 500 15px/1.4 var(--font-mono); }
@media (min-width: 640px) {
  .bal-grant__fields { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .bal-grant__agent { grid-column: 1 / -1; }
}
@media (min-width: 1280px) {
  .bal-grant__fields { grid-template-columns: minmax(0, 2fr) minmax(0, 1.3fr) minmax(0, 1fr) minmax(0, 1.1fr); }
  .bal-grant__agent { grid-column: auto; }
}
.bal-grant__sum {
  padding: 12px 14px; border-radius: var(--r2); background: var(--panel-3); border: 1px solid var(--line);
  font: 500 13.5px/1.55 var(--font-mono); color: var(--dim); overflow-wrap: anywhere;
}
.bal-grant__foot { display: flex; justify-content: flex-end; }
@media (max-width: 639px) { .bal-grant__foot .btn { width: 100%; } }

/* ------------------------------------------------------------------------------------------------ tables */
.bal-table .table td, .bal-table .table th[scope="row"] { vertical-align: middle; }
.bal-table .table th[scope="row"] { font-weight: 600; color: var(--text); font-size: 14.5px; }
.bal-table .num { white-space: nowrap; }
.bal-cell__main { display: block; color: var(--text); }
.bal-cell__sub { display: block; margin-top: 2px; font: 400 12px/1.4 var(--font-mono); color: var(--faint); }
.bal-key { display: inline-flex; align-items: center; gap: 6px; min-width: 0; }
.bal-key__addr { font-size: 13.5px; font-weight: 500; color: var(--text); }
.bal-key .icon-btn { border-color: transparent; color: var(--muted); }
.bal-key .icon-btn:hover { color: var(--text); }
.bal-row-actions { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: 8px; }
.bal-table--keys tr.is-none .bal-key__addr { color: var(--muted); }
.bal-route { font-size: 13px; color: var(--dim); overflow-wrap: anywhere; }
.bal-route__m { color: var(--accent); font-weight: 600; }
.bal-amt { display: inline-flex; flex-direction: column; align-items: flex-end; gap: 4px; }
.bal-tx { display: inline-flex; align-items: center; gap: 6px; min-height: 32px; font-size: 13px; color: var(--dim); white-space: nowrap; }
.bal-tx:hover { color: var(--accent); }
.bal-tx .icon { color: var(--muted); }
.bal-c-time { color: var(--muted); }
.bal-c-time span { white-space: nowrap; }
.bal-more { align-self: center; margin-top: 12px; }
.bal-history { display: flex; flex-direction: column; }
@media (min-width: 820px) and (max-width: 1179px) {
  .bal-table .table th, .bal-table .table td { padding-inline: 12px; }
  .bal-c-time span { white-space: normal; }
}

/* under 820px each row is a card with labelled cells */
@media (max-width: 819px) {
  .bal-table { border: 0; background: none; overflow: visible; }
  .bal-table thead { display: none; }
  .bal-table table, .bal-table tbody { display: block; }
  .bal-table tr {
    display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px 14px; padding: 16px; margin-bottom: 10px;
    border: 1px solid var(--line); border-radius: var(--r3); background: var(--panel);
  }
  .bal-table tbody tr:hover { background: var(--panel); }
  .bal-table .table th, .bal-table .table td { display: block; padding: 0; border: 0; text-align: left; min-width: 0; }
  .bal-table .table td[data-label]::before {
    content: attr(data-label); display: block; margin-bottom: 3px;
    font: 600 11px/1.4 var(--font-mono); text-transform: uppercase; letter-spacing: .1em; color: var(--muted);
  }
  .bal-table .num { white-space: normal; overflow-wrap: anywhere; }
  .bal-c-time span { white-space: normal; }

  /* keys: key and state on top, four figures in two columns, the actions last */
  .bal-table--keys .bal-c-key { grid-column: 1; grid-row: 1; align-self: center; }
  .bal-table--keys .bal-c-state { grid-column: 2; grid-row: 1; justify-self: end; align-self: center; }
  .bal-table--keys .bal-c-state::before { display: none !important; }
  .bal-table--keys .bal-c-cap { grid-column: 1; grid-row: 2; }
  .bal-table--keys .bal-c-epoch { grid-column: 2; grid-row: 2; }
  .bal-table--keys .bal-c-spent { grid-column: 1; grid-row: 3; }
  .bal-table--keys .bal-c-exp { grid-column: 2; grid-row: 3; }
  .bal-table--keys .bal-c-act { grid-column: 1 / -1; grid-row: 4; }
  .bal-table--keys .bal-c-act:has(.bal-row-actions:empty) { display: none; }
  .bal-row-actions { justify-content: stretch; }
  .bal-row-actions .btn { flex: 1 1 140px; }

  /* history: service and amount on top, the route, then time and provider, the transaction last */
  .bal-table--hist .bal-c-svc { grid-column: 1; grid-row: 1; overflow-wrap: anywhere; }
  .bal-table--hist .table .bal-c-amt { grid-column: 2; grid-row: 1; justify-self: end; text-align: right; }
  .bal-table--hist .bal-c-amt::before { display: none !important; }
  .bal-table--hist .bal-c-route { grid-column: 1 / -1; grid-row: 2; }
  .bal-table--hist .bal-c-route::before { display: none !important; }
  .bal-table--hist .bal-c-time { grid-column: 1; grid-row: 3; }
  .bal-table--hist .bal-c-prov { grid-column: 2; grid-row: 3; }
  .bal-table--hist .bal-c-tx { grid-column: 1 / -1; grid-row: 4; }
  .bal-table--hist .bal-c-tx::before { display: none !important; }
  .bal-tx { min-height: 44px; }
}
@media (max-width: 359px) {
  .bal-table tr { grid-template-columns: minmax(0, 1fr); }
  .bal-table tr > * { grid-column: 1 !important; grid-row: auto !important; justify-self: start !important; text-align: left !important; }
}

/* ------------------------------------------------------------------------------------------------ dialog summaries */
.bal-sum { display: flex; flex-direction: column; }
.bal-sum > div { display: flex; align-items: baseline; justify-content: space-between; gap: 4px 16px; flex-wrap: wrap; padding: 7px 0; border-top: 1px solid var(--line-row); }
.bal-sum > div:first-child { border-top: 0; padding-top: 0; }
.bal-sum dt { font-size: 13.5px; color: var(--muted); }
.bal-sum dd { font: 500 13.5px/1.45 var(--font-mono); color: var(--text); font-variant-numeric: tabular-nums; text-align: right; overflow-wrap: anywhere; min-width: 0; }
.bal-sum-box { gap: 12px; }
.bal-sum-addr {
  padding: 10px 12px; border-radius: var(--r2); background: var(--bg-deep); border: 1px solid var(--line);
  font-size: 13px; line-height: 1.55; color: var(--text);
}

/* ------------------------------------------------------------------------------------------------ touch sizes */
/* the Max control inside the 56px amount field grows to the 44px tap size on touch widths */
@media (max-width: 819px) { .page--balance .amount__max { height: 44px; } }
