.tool-panel {
  --tool-muted: #4a6058;
  --tool-surface: #fff;
  --tool-tint: #edf3ee;
  --tool-danger: #9c2735;
  color: var(--ink);
  padding: clamp(18px, 3.2vw, 46px);
  border: 1px solid var(--line);
  border-radius: clamp(22px, 3vw, 40px);
  background: var(--tool-surface);
  min-width: 0;
}

.tool-panel [hidden],
.tool-panel:not([data-ready]) [data-tool-enhanced] {
  display: none;
}

.tool-header {
  margin-bottom: clamp(20px, 3vw, 36px);
}

.tool-header h2,
.tool-panel h3 {
  color: var(--forest);
  font-weight: 650;
  letter-spacing: -.035em;
  line-height: 1.1;
  text-wrap: balance;
  margin: 0;
}

.tool-header h2 {
  font-size: clamp(1.6rem, 3vw, 2.6rem);
}

.tool-header p {
  margin: .7rem 0 0;
  color: var(--tool-muted);
  max-width: 64ch;
  line-height: 1.6;
}

.tool-panel h3 {
  font-size: clamp(1.13rem, 2vw, 1.4rem);
  margin-bottom: 1rem;
}

.tool-filters {
  display: flex;
  flex-wrap: wrap;
  gap: .9rem 1rem;
  align-items: flex-end;
  margin-bottom: 1.2rem;
}

.tool-market-filters {
  justify-content: space-between;
}

.tool-field {
  min-width: 0;
  display: grid;
  gap: .45rem;
}

.tool-filters .tool-field {
  min-width: min(100%, 12rem);
}

.tool-field label {
  font-size: .88rem;
  font-weight: 650;
  color: var(--forest);
}

.tool-field input,
.tool-field select {
  display: block;
  width: 100%;
  min-width: 0;
  min-height: 46px;
  padding: .5rem .85rem;
  color: var(--ink);
  background-color: var(--tool-surface);
  border: 1px solid #9aaca3;
  border-radius: 12px;
  font: inherit;
  font-size: 1rem;
}

.tool-field input[aria-invalid="true"] {
  border-color: var(--tool-danger);
}

.tool-panel :is(a, button, input, select, summary, [tabindex]):focus-visible {
  outline: 2px solid var(--green);
  outline-offset: 3px;
  scroll-margin-block: 7rem 2rem;
}

.tool-button {
  align-items: center;
  appearance: none;
  background: var(--forest);
  border: 1px solid var(--forest);
  border-radius: 999px;
  color: #fff;
  cursor: pointer;
  display: inline-flex;
  font: inherit;
  font-size: .92rem;
  font-weight: 650;
  justify-content: center;
  line-height: 1.2;
  min-height: 46px;
  padding: .65rem 1.15rem;
  text-align: center;
  touch-action: manipulation;
  transition: transform 140ms cubic-bezier(.23, 1, .32, 1);
}

.tool-button--outline {
  background: var(--tool-surface);
  color: var(--forest);
  border-color: #9aaca3;
}

.tool-button:active {
  transform: scale(.97);
}

.tool-external {
  color: var(--green);
  font-weight: 650;
  text-decoration: underline;
  text-decoration-thickness: .075em;
  text-underline-offset: .22em;
}

.tool-external span {
  display: inline-block;
  text-decoration: none;
  margin-inline-start: .1em;
}

.tool-calendar {
  display: inline-flex;
  align-items: center;
  gap: .25rem;
  min-height: 44px;
}

.tool-market-chart {
  margin-bottom: clamp(24px, 4vw, 46px);
  background: var(--tool-surface);
}

.tool-panel[data-tool="markets"] {
  border: 0;
  border-radius: 0;
  background: transparent;
  padding: 0;
}

.tool-panel[data-tool="markets"] .tool-market-chart {
  padding: clamp(15px, 2.2vw, 29px);
}

.tool-market-chart__head {
  display: flex;
  justify-content: space-between;
  align-items: flex-end;
  gap: 12px;
  flex-wrap: wrap;
}

.tool-market-chart h2,
.tool-directory-heading {
  margin: 0;
  font-size: clamp(24px, 2.5vw, 36px);
}

.tool-market-chart .tool-filters {
  margin: 0;
}

.tool-market-chart .tool-summary:empty {
  display: none;
}

.tool-market-frame {
  margin-top: 1rem;
  border: 1px solid var(--line);
  border-radius: 12px;
  overflow: hidden;
  background: var(--tool-surface);
  height: clamp(330px, 44vw, 535px);
}

.tool-market-frame iframe {
  display: block;
  border: 0;
  width: 100%;
  height: 100%;
}

@media (hover: hover) {
  .tool-button:hover {
    background: var(--green);
    border-color: var(--green);
    color: #fff;
  }

  .tool-external:hover {
    color: var(--forest);
    text-decoration-thickness: .13em;
  }
}

.tool-table-frame {
  border: 1px solid var(--line);
  border-radius: 15px;
  overflow: hidden;
  min-width: 0;
}

.tool-table-overflow {
  overflow-x: auto;
  overscroll-behavior-inline: contain;
}

.tool-table {
  border-collapse: collapse;
  border-spacing: 0;
  margin: 0;
  width: 100%;
  text-align: left;
}

.tool-table :is(th, td) {
  text-align: start;
  padding: .8rem clamp(.58rem, 1.6vw, 1.2rem);
  font-size: .91rem;
  line-height: 1.4;
}

.tool-table thead th {
  color: var(--forest);
  background: var(--tool-tint);
  font-weight: 650;
  font-size: .83rem;
}

.tool-table tbody tr + tr :is(th, td) {
  border-top: 1px solid var(--line);
}

.tool-table tbody th {
  color: var(--ink);
  font-weight: 650;
}

.tool-table tbody td {
  font-variant-numeric: tabular-nums;
}

.tool-market-table td:last-child {
  min-width: 9.5rem;
}

.tool-symbol {
  color: var(--forest);
  display: block;
  font-size: .98rem;
  font-variant-numeric: tabular-nums;
}

.tool-instrument-name {
  color: var(--tool-muted);
  display: block;
  font-size: .81rem;
  font-weight: 400;
  margin-top: .13rem;
}

.tool-account-table {
  min-width: 36.5rem;
}

.tool-account-table td {
  white-space: nowrap;
}

.tool-table-meta {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: .4rem .8rem;
  margin: 0 0 .7rem;
}

.tool-tag {
  display: inline-block;
  background: #e7f2dd;
  color: var(--forest);
  border-radius: 999px;
  font-size: .78rem;
  font-weight: 650;
  padding: .38rem .72rem;
}

.tool-note,
.tool-count {
  color: var(--tool-muted);
  font-size: .88rem;
  line-height: 1.55;
}

.tool-note {
  margin: .85rem 0 0;
}

.tool-count {
  margin: 0;
}

.tool-scroll-hint {
  display: none;
}

.tool-empty {
  background: var(--tool-tint);
  color: var(--forest);
  padding: .85rem 1rem;
  border-radius: 12px;
}

.tool-details {
  border-top: 1px solid var(--line);
  margin-top: 1.3rem;
  padding-top: .5rem;
}

.tool-details summary {
  cursor: pointer;
  color: var(--green);
  font-weight: 650;
  min-height: 44px;
  align-content: center;
  touch-action: manipulation;
}

.tool-details p {
  max-width: 70ch;
  margin: .5rem 0;
  color: var(--tool-muted);
  line-height: 1.55;
}

.tool-workspace {
  display: grid;
  grid-template-columns: minmax(12rem, 1fr) minmax(0, 1.8fr);
  align-items: start;
  gap: clamp(.85rem, 2vw, 1.4rem);
}

.tool-panel:not([data-ready]) .tool-workspace {
  grid-template-columns: minmax(0, 1fr);
}

.tool-control-panel,
.tool-result-panel {
  border-radius: clamp(16px, 2vw, 24px);
  border: 1px solid var(--line);
  padding: clamp(.8rem, 2vw, 1.6rem);
  min-width: 0;
}

.tool-control-panel {
  background: var(--paper);
  display: grid;
  gap: 1rem;
}

.tool-control-panel h3 {
  margin: 0;
}

.tool-control-panel .tool-button {
  justify-self: start;
}

.tool-field-hint,
.tool-field-error {
  margin: 0;
  color: var(--tool-muted);
  font-size: .78rem;
  line-height: 1.5;
}

.tool-field-error,
.tool-field input[aria-invalid="true"] ~ .tool-field-hint {
  color: var(--tool-danger);
}

.tool-rule-table {
  table-layout: auto;
}

.tool-rule-table :is(th, td):is(:first-child, :nth-child(2)) {
  width: 18%;
}

.tool-rule-state {
  color: var(--tool-muted);
}

.tool-rule-state[data-state="triggered"] {
  color: var(--green);
  font-weight: 650;
}

.tool-rule-state[data-state="blocked"] {
  color: #775718;
  font-weight: 650;
}

.tool-summary:empty {
  margin: 0;
}

.tool-totals {
  display: flex;
  flex-wrap: wrap;
  gap: 1rem 2.4rem;
  margin: 0 0 1.2rem;
}

.tool-totals dt {
  color: var(--tool-muted);
  font-size: .84rem;
  line-height: 1.35;
  margin-bottom: .3rem;
}

.tool-totals dd {
  color: var(--forest);
  font-size: clamp(1.35rem, 3.2vw, 2.1rem);
  font-weight: 650;
  font-variant-numeric: tabular-nums;
  letter-spacing: -.045em;
  line-height: 1.05;
  margin: 0;
  overflow-wrap: anywhere;
}

.tool-totals [data-direction="loss"] {
  color: var(--tool-danger);
}

.tool-totals [data-direction="gain"] {
  color: var(--green);
}

.tool-chart {
  border: 1px solid var(--line);
  border-radius: 15px;
  background: #f7faf6;
  margin: 0;
  padding: .75rem;
}

.tool-chart figcaption {
  font-size: .81rem;
  font-weight: 650;
  color: var(--forest);
  padding-inline: .35rem;
}

.tool-chart canvas {
  display: block;
  width: 100%;
  height: auto;
  min-height: 87px;
}

.tool-chart-labels {
  color: var(--tool-muted);
  display: flex;
  justify-content: space-between;
  font-size: .75rem;
  padding-inline: .35rem;
}

@media (max-width: 760px) {
  .tool-workspace {
    grid-template-columns: minmax(0, 1fr);
  }

  .tool-scroll-hint {
    display: block;
    margin: 0 0 .5rem;
  }

  .tool-account-table tr > :first-child {
    position: sticky;
    inset-inline-start: 0;
    z-index: 1;
    box-shadow: 1px 0 var(--line);
  }

  .tool-account-table tbody tr > :first-child {
    background: var(--tool-surface);
  }
}

@media (max-width: 480px) {
  .tool-panel {
    padding: 1rem;
  }

  .tool-filters .tool-field {
    width: 100%;
  }

  .tool-market-table :is(th, td) {
    padding-inline: .42rem;
    font-size: .77rem;
    overflow-wrap: anywhere;
  }

  .tool-symbol {
    font-size: .85rem;
  }

  .tool-instrument-name {
    font-size: .73rem;
  }

  .tool-market-table td:last-child {
    min-width: 0;
  }
}

@media (prefers-reduced-motion: reduce) {
  .tool-button {
    transition: none;
  }

  .tool-button:active {
    transform: none;
  }
}
