/* Amazon FBA Calculator: inputs beside the result at wide widths, the worked fees and price table below.
   Colours come from the shared tokens, so the panel follows the light and dark themes. */
.fba {
  display: grid;
  gap: 1.1rem;
  padding: clamp(16px, 2.4vw, 32px);
  text-align: left;
  color: var(--ink);
  background: var(--bg-2);
  border: 2px solid var(--line);
  border-radius: 12px;
  box-shadow: 4px 4px 0 var(--shade);
}
.fba *, .fba *::before, .fba *::after { box-sizing: border-box; }
.fba [hidden] { display: none !important; }
.fba h2 { margin: 0 0 .35rem; font-size: 1.45rem; letter-spacing: -.02em; }
.fba h3 { margin: 0 0 .6rem; font-size: 1.1rem; }
.fba p { margin: 0; color: var(--ink-soft); }
.fba-head { display: grid; gap: .5rem; }
.fba-head p { max-width: 80ch; }
.fba .fba-sources { font-size: .88rem; color: var(--ink); }
.fba a { color: var(--ink); text-decoration: underline; text-underline-offset: 2px; }
.fba :is(input, select, button, summary, a, [tabindex]):focus-visible { outline: 3px solid var(--primary); outline-offset: 2px; }

.fba-modes { display: flex; flex-wrap: wrap; gap: .5rem; margin: 0; padding: 0; border: 0; min-width: 0; }
.fba-modes legend { width: 100%; margin-bottom: .45rem; padding: 0; font-weight: 700; }
.fba-modes label { position: relative; display: inline-flex; align-items: center; min-height: 42px; padding: .45rem .9rem; font-size: .95rem; font-weight: 650; background: var(--bg-2); border: 2px solid var(--line); border-radius: 999px; cursor: pointer; }
.fba-modes input { position: absolute; opacity: 0; pointer-events: none; }
.fba-modes label:has(input:checked) { color: var(--on-action); background: var(--action); box-shadow: 2px 2px 0 var(--shade); }
.fba-modes label:has(input:focus-visible) { outline: 3px solid var(--primary); outline-offset: 2px; }
.fba .fba-warn { padding: .5rem .75rem; font-weight: 600; color: var(--ink); background: var(--warning-soft); border-left: 4px solid var(--warning); border-radius: 6px; }

.fba-layout { display: grid; gap: 1.1rem; grid-template-columns: minmax(0, 1fr); align-items: start; }
@media (min-width: 1100px) { .fba-layout { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); } }
.fba-inputs, .fba-results { display: grid; gap: .9rem; min-width: 0; }

.fba fieldset.fba-group { display: grid; gap: .75rem; min-width: 0; margin: 0; padding: .9rem 1rem 1rem; background: var(--blue-tint); border: 2px solid var(--line); border-radius: 10px; }
.fba fieldset.fba-group.fba-alt { background: var(--paper-3); }
.fba fieldset.fba-group legend { padding: 0 .4rem; font-weight: 700; }
.fba label { display: grid; gap: .3rem; min-width: 0; font-size: .85rem; font-weight: 650; }
.fba input[type="text"], .fba select {
  width: 100%;
  min-width: 0;
  min-height: 42px;
  padding: .5rem .6rem;
  font: inherit;
  font-weight: 400;
  color: var(--ink);
  background: var(--field);
  border: 1.5px solid var(--border-soft);
  border-radius: 6px;
}
.fba input[aria-invalid="true"] { border-color: var(--error); box-shadow: 0 0 0 2px var(--error-soft); }
.fba .fba-check { display: flex; align-items: center; gap: .55rem; min-height: 42px; font-size: .92rem; font-weight: 500; }
.fba .fba-check input { flex: none; width: 1.2rem; height: 1.2rem; margin: 0; accent-color: var(--action); }
.fba-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(9.5rem, 1fr)); gap: .75rem 1rem; align-items: end; }
.fba-grid-dims { grid-template-columns: repeat(auto-fit, minmax(6.5rem, 1fr)); }

.fba button {
  display: inline-flex;
  align-items: center;
  min-height: 42px;
  padding: .5rem .95rem;
  font: inherit;
  font-weight: 650;
  color: var(--ink);
  background: var(--bg-2);
  border: 2px solid var(--line);
  border-radius: 8px;
  cursor: pointer;
}
.fba button:disabled { opacity: .5; cursor: default; }
.fba .fba-primary { color: var(--on-action); background: var(--action); box-shadow: 3px 3px 0 var(--shade); }
.fba .fba-primary:hover:not(:disabled) { background: var(--primary-dark); }
.fba .fba-link { display: inline; min-height: 0; padding: 0; font-weight: 600; text-decoration: underline; text-underline-offset: 2px; background: none; border: 0; }

.fba-advanced { padding: .75rem 1rem; border: 1.5px solid var(--border-soft); border-radius: 10px; }
.fba-advanced summary { min-height: 30px; font-weight: 700; cursor: pointer; }
.fba-advanced[open] { display: grid; gap: .75rem; }
.fba-advanced p { font-size: .88rem; }

.fba-result { display: grid; gap: .75rem; padding: 1rem 1.1rem 1.2rem; background: var(--pastel-green); border: 2px solid var(--line); border-radius: 10px; }
.fba-result h3 { margin: 0; }
.fba .fba-answer { font-size: clamp(1.45rem, 4vw, 2.05rem); font-weight: 800; letter-spacing: -.02em; line-height: 1.15; color: var(--ink); overflow-wrap: anywhere; }
.fba .fba-detail { color: var(--ink); max-width: 70ch; }
.fba-stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(10.5rem, 1fr)); gap: .55rem; margin: 0; }
.fba-stats:empty { display: none; }
.fba-stats div { padding: .5rem .65rem; background: var(--bg-2); border: 1.5px solid var(--border-soft); border-radius: 6px; min-width: 0; }
.fba-stats .fba-key { border: 2px solid var(--line); }
.fba-stats dt { font-size: .72rem; font-weight: 650; text-transform: uppercase; letter-spacing: .04em; color: var(--ink-soft); }
.fba-stats dd { margin: .2rem 0 0; font: 650 1.02rem var(--font-mono); overflow-wrap: anywhere; }
.fba-actions { display: flex; flex-wrap: wrap; gap: .6rem; }
.fba .fba-status { min-height: 1.2em; font-weight: 600; color: var(--ink); }
.fba .fba-status:empty { min-height: 0; }
.fba .fba-status[data-error="true"] { padding: .5rem .75rem; background: var(--error-soft); border-left: 4px solid var(--error); border-radius: 6px; }

.fba-table-wrap { max-width: 100%; overflow-x: auto; background: var(--bg-2); border: 1.5px solid var(--border-soft); border-radius: 6px; }
.fba table { width: 100%; border-collapse: collapse; font-size: .86rem; }
.fba caption { padding: .55rem .7rem; font-weight: 700; text-align: left; white-space: normal; color: var(--ink); }
.fba th, .fba td { padding: .4rem .7rem; text-align: right; white-space: nowrap; border-bottom: 1px solid var(--border-faint); }
.fba th:first-child, .fba td:first-child { text-align: left; }
.fba tbody th { font-weight: 500; }
.fba thead th { font-size: .74rem; text-transform: uppercase; letter-spacing: .04em; color: var(--ink-soft); background: var(--paper-3); }
.fba td { font-family: var(--font-mono); }
.fba tr.fba-total th, .fba tr.fba-total td { font-weight: 700; border-top: 1.5px solid var(--border-soft); }
.fba tr.fba-profit th, .fba tr.fba-profit td { font-weight: 800; background: var(--paper-3); border-top: 2px solid var(--line); }
.fba td[data-sign="neg"] { color: var(--error); }
.fba tr.fba-current th, .fba tr.fba-current td { font-weight: 700; background: var(--paper-3); }

.fba-work, .fba-whatif { display: grid; gap: .6rem; padding: 1rem; border: 2px solid var(--line); border-radius: 10px; min-width: 0; }
.fba-work-list { display: grid; gap: 0; margin: 0; }
.fba-work-list div { display: grid; grid-template-columns: minmax(9rem, 14rem) minmax(0, 1fr); gap: .25rem 1rem; padding: .5rem 0; border-bottom: 1px solid var(--border-faint); }
.fba-work-list div:last-child { border-bottom: 0; }
.fba-work-list dt { font-weight: 700; font-size: .9rem; }
.fba-work-list dd { margin: 0; font-size: .9rem; color: var(--ink); overflow-wrap: anywhere; }

.fba-whatif td { position: relative; }
.fba-bar { display: inline-block; width: calc(var(--w, 0) * .045rem); min-width: 2px; height: .55rem; margin-right: .45rem; vertical-align: middle; background: var(--success); border-radius: 2px; }
.fba-bar[data-sign="neg"] { background: var(--error); }

.fba-note { font-size: .85rem; }

/* A one-line result that stays in view while the inputs scroll on narrow screens. */
.fba .fba-peek { position: sticky; bottom: 0; z-index: 2; display: flex; flex-wrap: wrap; justify-content: space-between; gap: .25rem .75rem; padding: .55rem .8rem; font-weight: 700; color: var(--ink); background: var(--pastel-green); border: 2px solid var(--line); border-radius: 8px; box-shadow: 0 -2px 0 var(--bg-2); }
@media (min-width: 1100px) { .fba .fba-peek { display: none; } }

@media (max-width: 640px) {
  .fba-work-list div { grid-template-columns: minmax(0, 1fr); }
  .fba-stats { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .fba table { font-size: .8rem; }
  .fba th, .fba td { padding: .38rem .4rem; }
  .fba-compare th:first-child { white-space: normal; }
  .fba thead th, .fba-whatif tbody th { white-space: normal; letter-spacing: 0; }
  .fba-work, .fba-whatif { padding: .7rem .6rem; }
  .fba-whatif table { font-size: .76rem; }
  .fba-whatif th, .fba-whatif td { padding: .35rem .28rem; }
  .fba-bar { display: none; }
  .fba-modes label { flex: 1 1 100%; }
  .fba-actions button { flex: 1 1 auto; justify-content: center; }
}

/* Space the page holds for this view until it mounts (see .tool-view-placeholder in _workspace.css).
   Each height is a little under the space the view takes at that width, measured as how far the
   content below moves when the view replaces the placeholder, so nothing below it moves. Re-measure
   after changing the view's layout: node scripts/measure-tool-views.js --apply amazon-fba-calculator. */
.tool-view-placeholder[data-tool="amazon-fba-calculator"] { min-height: 3095px; }
@media (max-width: 1096px) { .tool-view-placeholder[data-tool="amazon-fba-calculator"] { min-height: 4254px; } }
@media (max-width: 676px) { .tool-view-placeholder[data-tool="amazon-fba-calculator"] { min-height: 5002px; } }
@media (max-width: 428px) { .tool-view-placeholder[data-tool="amazon-fba-calculator"] { min-height: 6762px; } }
