/* CME COT 持倉報告 (designer mockup-cme-cot-v2). Terminal register on role vars, so
   body.dark-mode needs no per-rule overrides here — main.css remaps the vars.
   The card / segment / table recipes are this page's own copies (crypto pages have no
   shared `.card`; twstock pages each carry theirs). */

#box_main.cot {
  width: 1020px;
  min-width: 0;
  padding-top: var(--space-16);
  padding-left: var(--space-16);
}

.cot .mono {
  font-variant-numeric: tabular-nums;
}

.cot .pos {
  color: var(--color-greenText);
}

.cot .neg {
  color: var(--color-redText);
}

/* ── page head ── */
.cot .pagehead {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: var(--space-12) var(--space-16);
  margin-bottom: var(--space-16);
}

.cot .titlewrap h1 {
  margin: 0;
  color: var(--ink);
}

.cot .asof {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--space-4) var(--space-8);
  margin: var(--space-4) 0 0;
  font-size: 12px;
  color: var(--chart-caption);
}

.cot .asof .dot {
  width: 3px;
  height: 3px;
  border-radius: var(--radius-pill);
  background: currentColor;
}

/* ── segment (same recipe as the twstock toolbar) ── */
.cot .segment {
  display: inline-flex;
  border: 1px solid var(--border-frame);
  border-radius: var(--radius-sm);
}

.cot .segment button {
  position: relative;
  height: 32px;
  padding: 0 var(--space-12);
  border: none;
  border-right: 1px solid var(--border-frame);
  background: transparent;
  color: var(--color-greyMedium);
  font-family: inherit;
  font-size: 12px;
  white-space: nowrap;
  cursor: pointer;
  transition: background var(--motion-fast) var(--ease-standard);
}

body.dark-mode .cot .segment button {
  color: var(--color-greyLightMedium);
}

/* 44 hit area without growing the 32 control */
.cot .segment button::before {
  content: "";
  position: absolute;
  inset: -6px 0;
}

.cot .segment button:first-child {
  border-radius: calc(var(--radius-sm) - 1px) 0 0 calc(var(--radius-sm) - 1px);
}

.cot .segment button:last-child {
  border-right: none;
  border-radius: 0 calc(var(--radius-sm) - 1px) calc(var(--radius-sm) - 1px) 0;
}

.cot .segment button:hover {
  background: var(--surface-muted);
}

.cot .segment button.active {
  background: var(--surface-control-on);
  color: var(--ink);
  font-weight: 600;
}

/* ── cards ── */
.cot .card {
  display: block;
  background: var(--surface-card);
  border: none;
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-md);
  padding: var(--space-16);
}

.cot .card-h {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: var(--space-8);
  margin-bottom: var(--space-12);
}

.cot .card-h h6 {
  margin: 0;
  color: var(--ink);
}

.cot .card-h .meta {
  font-size: 12px;
  color: var(--chart-caption);
}

.cot .card-h .right {
  display: flex;
  align-items: center;
  gap: var(--space-8);
}

.cot .full {
  margin-top: var(--space-16);
}

/* ── summary card (SSR) ── */
.cot .nowrap {
  white-space: nowrap;
}

/* contract switch: the meta line hides while the body waits under its skeleton */
.cot .ssr-summary.is-wait .card-h .meta,
.cot .ssr-summary.is-wait .ssr-date {
  visibility: hidden;
}

.cot .sum_err {
  margin: 0;
  padding: var(--space-16) 0;
  font-size: 13px;
  text-align: center;
  color: var(--color-redText);
}

.cot .ssr-summary .ssr-date {
  color: var(--chart-caption);
}

.cot .ssr-summary .ssr-lead {
  color: var(--ink-2);
}

/* the conditional basis-trade note: framed, never filled or coloured */
.cot .basis-note {
  max-width: 52em;
  margin: 0 0 var(--space-16);
  padding: var(--space-8) var(--space-12);
  border: 1px solid var(--border-frame);
  border-radius: var(--radius-sm);
  font-size: 13px;
  line-height: 1.6;
  color: var(--ink-2);
}

.cot .duo {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: var(--space-16);
  padding-top: var(--space-16);
  border-top: 1px solid var(--border-hairline);
}

.cot .duo .grp {
  min-width: 0;
}

.cot .duo .grp + .grp {
  padding-left: var(--space-16);
  border-left: 1px solid var(--border-hairline);
}

.cot .duo .nm {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: var(--space-8);
  font-size: 13px;
  font-weight: 600;
  color: var(--ink);
}

.cot .duo .nv {
  margin-top: var(--space-4);
  font-size: 28px;
  font-weight: 600;
  line-height: 1.2;
  color: var(--ink);
}

.cot .duo .nv.pos {
  color: var(--color-greenText);
}

.cot .duo .nv.neg {
  color: var(--color-redText);
}

.cot .duo .nv small {
  margin-left: var(--space-6);
  font-family: var(--font-sans);
  font-size: 13px;
  font-weight: 400;
  color: var(--chart-caption);
}

.cot .duo .ls {
  margin-top: var(--space-2);
  font-size: 12px;
  color: var(--chart-caption);
}

.cot .duo .ls .mono {
  color: var(--ink);
}

.cot .pct {
  display: flex;
  flex-direction: column;
  gap: var(--space-4);
  margin-top: var(--space-12);
}

.cot .pct-line,
.cot .pct-ends {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: var(--space-8);
  font-size: 12px;
  color: var(--chart-caption);
}

.cot .pct-line .mono {
  font-size: 13px;
  font-weight: 600;
  color: var(--ink);
}

.cot .pct-track {
  position: relative;
  height: 4px;
  overflow: hidden;
  border-radius: var(--radius-pill);
  background: var(--surface-muted);
}

.cot .pct-fill {
  height: 100%;
  border-radius: var(--radius-pill);
}

.cot .duo .mini_tag {
  font-weight: 600;
}

/* ── analysis grid ── */
.cot .analysis {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 320px;
  gap: var(--space-16);
  align-items: start;
}

.cot .col-main,
.cot .col-side {
  display: flex;
  flex-direction: column;
  gap: var(--space-16);
  min-width: 0;
}

.cot .chart_box {
  position: relative;
  height: 320px;
}

.cot .chart-foot {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  align-items: center;
  gap: var(--space-8) var(--space-16);
  margin-top: var(--space-8);
}

.cot .chart_note {
  margin: 0;
  font-size: 12px;
  line-height: 1.6;
  color: var(--chart-caption);
}

.cot .leg {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-4) var(--space-12);
}

.cot .leg-item {
  display: inline-flex;
  align-items: center;
  gap: var(--space-6);
  font-size: 12px;
  color: var(--chart-caption);
}

.cot .swatch {
  display: inline-block;
  flex: none;
  width: 8px;
  height: 8px;
  border-radius: var(--radius-micro);
}

.cot .swatch-line {
  display: inline-block;
  width: 12px;
  border-bottom: 1px solid var(--chart-price);
}

.cot .swatch-dash {
  display: inline-block;
  width: 12px;
  border-bottom: 1px dashed var(--chart-cutoff);
}

/* ── outlined control ── */
.cot .ctrl {
  position: relative;
  display: inline-flex;
  align-items: center;
  height: 28px;
  padding: 0 var(--space-12);
  border: 1px solid var(--border-frame);
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--ink);
  font-family: inherit;
  font-size: 12px;
  cursor: pointer;
  transition: background var(--motion-fast) var(--ease-standard);
}

.cot .ctrl::before {
  content: "";
  position: absolute;
  inset: -9px 0;
}

.cot .ctrl:hover {
  background: var(--surface-muted);
}

/* ── tables ── */
.cot .tbl-wrap {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

.cot .tbl-wrap.capped {
  max-height: 420px;
  overflow-y: auto;
}

.cot .is-wait .tbl-wrap.capped {
  min-height: 420px;
}

.cot table.tbl {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
  font-variant-numeric: tabular-nums;
}

.cot table.tbl thead th {
  position: sticky;
  top: 0;
  z-index: 1;
  padding: var(--space-8) var(--space-12);
  border-bottom: 1px solid var(--border-hairline);
  background: var(--surface-card);
  color: var(--chart-caption);
  font-size: 12px;
  font-weight: 600;
  text-align: right;
  white-space: nowrap;
}

/* 本週各類部位: on desktop the seven columns must fit the card, so long es/pt/vi headers
   wrap instead of clipping the last one; ≤768 the table scrolls anyway and headers stay on
   one line (每週明細 never wraps) */
.cot table.tbl_wrap_head thead th {
  white-space: normal;
  vertical-align: bottom;
}

.cot table.tbl thead th:first-child {
  text-align: left;
}

.cot table.tbl tbody td {
  padding: 7px var(--space-12);
  border-bottom: 1px solid var(--border-hairline);
  color: var(--ink);
  font-family: var(--font-mono);
  text-align: right;
  white-space: nowrap;
}

.cot table.tbl tbody td:first-child {
  color: var(--ink-2);
  text-align: left;
}

.cot table.tbl tbody td.lbl {
  font-family: inherit;
}

.cot table.tbl tbody td .swatch {
  margin-right: var(--space-8);
}

.cot table.tbl tbody td .mini_tag {
  margin-left: var(--space-6);
  vertical-align: 1px;
  font-family: var(--font-sans);
}

.cot table.tbl tbody td.pos {
  color: var(--color-greenText);
}

.cot table.tbl tbody td.neg {
  color: var(--color-redText);
}

.cot table.tbl tbody td.dim {
  color: var(--chart-caption);
}

.cot table.tbl tbody tr:hover td {
  background: var(--surface-row-hover);
}

.cot .is-wait .skel {
  background: var(--surface-card);
}

/* ── explain cards (SEO copy, always in the HTML) ── */
.cot .explain h2 {
  margin: 0 0 var(--space-8);
  color: var(--ink);
}

.cot .explain p,
.cot .explain li {
  font-size: 13px;
  line-height: 1.7;
  color: var(--ink-2);
}

.cot .explain p {
  max-width: 44em;
  margin: 0;
}

.cot .explain ul {
  margin: 0;
  padding-left: 18px;
}

.cot .explain li + li {
  margin-top: var(--space-4);
}

.cot .explain .who_src {
  margin-top: var(--space-8);
  font-size: 12px;
  color: var(--chart-caption);
}

.cot .explain b {
  font-weight: 600;
  color: var(--ink);
}

.cot .article h2 {
  margin: var(--space-24) 0 var(--space-8);
}

.cot .article h2:first-child {
  margin-top: 0;
}

.cot .qlink {
  color: var(--link-quiet);
  text-decoration: underline;
  text-underline-offset: 3px;
}

.cot .qlink:hover {
  color: var(--link-quiet-hover);
}

.cot .source {
  margin: var(--space-24) 0 0;
  padding-top: var(--space-16);
  border-top: 1px solid var(--border-hairline);
  font-size: 12px;
  line-height: 1.6;
  color: var(--chart-caption);
}

/* ── states ── */
.cot .loader_wrap {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: var(--space-12);
  padding: var(--space-32) 0;
  font-size: 13px;
  color: var(--chart-caption);
}

.cot .loader_wrap .msg.error {
  color: var(--color-redText);
}

/* ── RWD (site steps 1300 / 768) ── */
@media (max-width: 1300px) {
  #box_main.cot {
    width: 588px;
    padding-left: 0;
  }

  /* the offcanvas button names the page; the date line stays */
  .cot .titlewrap h1 {
    display: none;
  }

  .cot .analysis {
    grid-template-columns: minmax(0, 1fr);
  }
}

@media (max-width: 768px) {
  #box_main.cot {
    width: 350px;
  }

  .cot .pagehead,
  .cot .chart-foot {
    flex-direction: column;
    align-items: stretch;
  }

  .cot .segment {
    display: flex;
  }

  .cot .segment button {
    flex: 1;
    padding: 0 var(--space-8);
  }

  .cot .duo {
    grid-template-columns: minmax(0, 1fr);
  }

  .cot .duo .grp + .grp {
    padding: var(--space-16) 0 0;
    border-left: none;
    border-top: 1px solid var(--border-hairline);
  }

  .cot .chart_box {
    height: 280px;
  }

  .cot table.tbl_wrap_head thead th {
    white-space: nowrap;
  }

  .cot table.tbl thead th,
  .cot table.tbl tbody td {
    padding: var(--space-4) var(--space-8);
  }
}
