/* ToT 共通の土台スタイル。サイト共通の /css/common.css の後に読み込む。
   白基調・主操作は青・成功は緑・エラーは赤＋文字。common.css に合わせてダークモードにも対応。 */
:root {
  --tot-surface: #f6f8fb;
  --tot-field-bg: #ffffff;
  --tot-border: #d6dce5;
  --tot-input-border: #9aa5b5;
  --tot-text: #1a2230;
  --tot-muted: #5a6575;
  --tot-primary: #1d5fd1;
  --tot-primary-hover: #164ba8;
  --tot-primary-soft: #e8f0fd;
  --tot-on-primary: #ffffff;
  --tot-success: #157347;
  --tot-success-text: #0f5132;
  --tot-success-soft: #e7f5ee;
  --tot-danger: #b42318;
  --tot-danger-soft: #fdecea;
  --tot-focus: #f2a900;
  --tot-radius: 8px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --tot-surface: #20242b;
    --tot-field-bg: #15181d;
    --tot-border: #3a414c;
    --tot-input-border: #5c6675;
    --tot-text: #e8ecf2;
    --tot-muted: #a7b0bd;
    --tot-primary: #6ea2ff;
    --tot-primary-hover: #8fb7ff;
    --tot-primary-soft: #1d2a40;
    --tot-on-primary: #0b1220;
    --tot-success: #4cc38a;
    --tot-success-text: #9be0bd;
    --tot-success-soft: #15291f;
    --tot-danger: #ff8a7a;
    --tot-danger-soft: #3a1d1a;
  }
}

.tot-main *, .tot-main *::before, .tot-main *::after { box-sizing: border-box; }

.tot-main {
  max-width: 1080px;
  margin: 0 auto;
  padding: 16px 16px 64px;
  color: var(--tot-text);
  font-size: 16px;
  line-height: 1.7;
}
.tot-main a { color: var(--tot-primary); }
/* ツールの表示部分。中の2列・1列の切り替えは画面幅ではなくこの幅で決める（@container tot-tool。作業画面の並べて表示の片側でも合う） */
.tot-tool { container: tot-tool / inline-size; }
.tot-main :focus-visible { outline: 3px solid var(--tot-focus); outline-offset: 2px; }

.tot-visually-hidden {
  position: absolute !important;
  width: 1px; height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
}
.tot-main [hidden] { display: none !important; }

/* ── パンくず ── */
.tot-crumbs ol {
  display: flex;
  flex-wrap: wrap;
  gap: 0 6px;
  margin: 0 0 16px;
  padding: 0;
  list-style: none;
  font-size: 12px;
  color: var(--tot-muted);
}
.tot-crumbs li + li::before { content: "›"; margin-right: 6px; }
.tot-crumbs a { color: var(--tot-muted); text-decoration: none; }
.tot-crumbs a:hover { text-decoration: underline; }

/* ── タイトル ── */
.tot-version {
  display: inline-block;
  margin-bottom: 4px;
  padding: 0 8px;
  border: 1px solid var(--tot-border);
  border-radius: 999px;
  font-size: 12px;
  color: var(--tot-muted);
}
.tot-main .tot-open-tab {
  display: inline-flex; align-items: center; min-height: 36px; margin-left: 8px; padding: 2px 12px;
  border: 1px solid var(--tot-primary); border-radius: var(--tot-radius);
  font-size: 14px; font-weight: 600; text-decoration: none; vertical-align: middle;
}
.tot-main .tot-open-tab:hover { background: var(--tot-primary-soft); }
.tot-main .tot-title h1 { margin: 0 0 4px; font-size: 26px; line-height: 1.35; letter-spacing: 0; }
.tot-main .tot-lead { margin: 0 0 12px; color: var(--tot-muted); }

.tot-main .tot-privacy {
  display: flex;
  gap: 8px;
  align-items: flex-start;
  margin: 0 0 20px;
  padding: 10px 14px;
  border-radius: var(--tot-radius);
  background: var(--tot-success-soft);
  color: var(--tot-success-text);
  font-size: 14px;
}

.tot-doc { margin-top: 36px; }
.tot-main .tot-doc h2 {
  font-size: 20px;
  margin: 0 0 12px;
  padding-bottom: 6px;
  border-bottom: 1px solid var(--tot-border);
}

/* ── ボタン ── */
.tot-btn {
  appearance: none;
  min-height: 44px;
  padding: 8px 18px;
  border: 1px solid var(--tot-primary);
  border-radius: var(--tot-radius);
  background: transparent;
  color: var(--tot-primary);
  font: inherit;
  font-weight: 600;
  cursor: pointer;
}
.tot-btn:hover { background: var(--tot-primary-soft); }
.tot-btn-primary { background: var(--tot-primary); color: var(--tot-on-primary); }
.tot-btn-primary:hover { background: var(--tot-primary-hover); }
.tot-btn-quiet { border-color: var(--tot-border); color: var(--tot-muted); }
.tot-btn-quiet:hover { background: var(--tot-surface); }

@media (min-width: 900px) {
  .tot-main { padding: 24px 24px 80px; }
  .tot-main .tot-title h1 { font-size: 30px; }
}

/* 利用状況の計測の設定（src/shared/usage/usage-page.js。画面の下に出し、ツールの操作を妨げない。閉じられる） */
.tot-usage-note { position: fixed; left: 12px; right: 12px; bottom: 12px; z-index: 50; max-width: 720px; max-height: 70vh; overflow: auto; margin: 0 auto; padding: 12px 14px; border: 1px solid var(--tot-border); border-radius: var(--tot-radius); background: var(--tot-field-bg); color: var(--tot-text); font-size: 13px; line-height: 1.6; box-shadow: 0 4px 16px rgba(0, 0, 0, 0.15); }
.tot-usage-note p { margin: 0 0 6px; }
.tot-usage-title { font-weight: 700; font-size: 14px; }
.tot-usage-state { color: var(--tot-muted); }
.tot-usage-note a { color: var(--tot-primary); }
.tot-usage-actions { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 12px; margin-top: 8px; }
/* 「許可する」「許可しない」は同じ見た目（どちらかを目立たせない） */
.tot-usage-btn { min-height: 36px; padding: 4px 16px; border: 1px solid var(--tot-input-border); border-radius: 6px; background: var(--tot-surface); color: var(--tot-text); font: inherit; font-weight: 600; cursor: pointer; }
.tot-usage-btn:focus-visible, .tot-usage-note-close:focus-visible { outline: 3px solid var(--tot-focus); outline-offset: 2px; }
.tot-usage-note-close { margin-left: auto; padding: 2px 10px; border: 1px solid var(--tot-input-border); border-radius: 6px; background: transparent; color: var(--tot-text); font: inherit; cursor: pointer; }

/* TOT-044 eBay・Payoneer込み利益計算（TOT-001 の型に、モードの切り替え・詳細欄・損益分岐を足したもの） */
.tot-layout { display: grid; gap: 20px; }

.tot-form-note { margin: 0 0 12px; font-size: 14px; color: var(--tot-muted); }

.tot-group {
  margin: 0 0 16px;
  padding: 12px 16px 4px;
  border: 1px solid var(--tot-border);
  border-radius: var(--tot-radius);
}
.tot-group legend { padding: 0 6px; font-weight: 700; }

.tot-field { margin-bottom: 14px; }
.tot-field label { display: block; font-weight: 600; margin-bottom: 4px; }
.tot-input-wrap { display: flex; align-items: center; gap: 8px; }
.tot-input-wrap input {
  flex: 1;
  min-width: 0;
  min-height: 44px;
  padding: 8px 12px;
  border: 1px solid var(--tot-input-border);
  border-radius: var(--tot-radius);
  font: inherit;
  font-size: 18px;
  font-variant-numeric: tabular-nums;
  text-align: right;
  color: var(--tot-text);
  background: var(--tot-field-bg);
}
.tot-input-wrap input[aria-invalid="true"] { border: 2px solid var(--tot-danger); background: var(--tot-danger-soft); }
.tot-unit { width: 2em; font-weight: 600; color: var(--tot-muted); }
.tot-hint { margin: 2px 0 0; font-size: 13px; color: var(--tot-muted); }
.tot-rate-row { display: flex; flex-wrap: wrap; align-items: center; gap: 6px 12px; margin-top: 6px; }
.tot-rate-info { flex: 1 1 14em; margin: 0; font-size: 13px; color: var(--tot-muted); }
.tot-btn.tot-btn-small { min-height: 36px; padding: 4px 12px; font-size: 14px; }
.tot-btn:disabled { opacity: 0.55; cursor: not-allowed; background: transparent; }
.tot-field-error { margin: 4px 0 0; font-size: 14px; color: var(--tot-danger); font-weight: 600; }
.tot-field-error::before { content: "⚠ "; }
.tot-rate-msg { margin: 6px 0 0; font-size: 13px; color: var(--tot-muted); }
.tot-rate-msg.is-error { color: var(--tot-danger); font-weight: 600; }

.tot-actions { display: flex; flex-wrap: wrap; gap: 10px; }

/* ── 結果 ── */
.tot-result {
  padding: 16px;
  border: 1px solid var(--tot-border);
  border-radius: var(--tot-radius);
  background: var(--tot-surface);
}
.tot-result-title { margin: 0 0 8px; font-size: 18px; }
.tot-result-empty { margin: 0; color: var(--tot-muted); }
.tot-pending p { margin: 0 0 6px; }
.tot-pending-missing { color: var(--tot-muted); }
.tot-pending-error { color: var(--tot-danger); font-weight: 600; }

.tot-profit {
  padding: 14px 16px;
  border-radius: var(--tot-radius);
  border-left: 6px solid var(--tot-success);
  background: var(--tot-success-soft);
}
.tot-profit.is-loss { border-left-color: var(--tot-danger); background: var(--tot-danger-soft); }
.tot-profit-label { margin: 0; font-weight: 700; display: flex; align-items: center; gap: 8px; }
.tot-profit-value {
  margin: 0;
  font-size: clamp(28px, 8vw, 40px);
  font-weight: 800;
  line-height: 1.25;
  font-variant-numeric: tabular-nums;
  color: var(--tot-success);
  overflow-wrap: anywhere;
}
.tot-profit.is-loss .tot-profit-value { color: var(--tot-danger); }
.tot-profit-sub { margin: 2px 0 0; font-size: 12px; color: var(--tot-muted); }
.tot-gross {
  display: grid;
  grid-template-columns: auto 1fr;
  align-items: baseline;
  gap: 0 12px;
  margin-top: 10px;
  padding: 10px 16px;
  border: 1px solid var(--tot-border);
  border-radius: var(--tot-radius);
}
.tot-gross-label { margin: 0; font-weight: 700; }
.tot-gross-value { margin: 0; font-size: 24px; font-weight: 800; text-align: right; font-variant-numeric: tabular-nums; overflow-wrap: anywhere; }
.tot-gross .tot-profit-sub { grid-column: 1 / -1; }
.tot-badge { padding: 1px 10px; border-radius: 999px; font-size: 13px; }
.tot-badge-loss { background: var(--tot-danger); color: var(--tot-field-bg); }

.tot-breakdown { margin: 12px 0 0; }
.tot-breakdown > div {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 12px;
  padding: 8px 0;
  border-bottom: 1px solid var(--tot-border);
}
.tot-breakdown dt { font-weight: 600; }
.tot-breakdown dd { margin: 0; font-weight: 700; font-variant-numeric: tabular-nums; text-align: right; overflow-wrap: anywhere; }
.tot-note { display: block; font-size: 12px; font-weight: 400; color: var(--tot-muted); }

.tot-disclaimer { margin: 12px 0; font-size: 13px; color: var(--tot-muted); }
.tot-copy { display: flex; flex-wrap: wrap; align-items: center; gap: 10px; }
.tot-copy-msg { font-size: 14px; color: var(--tot-success); font-weight: 600; }

/* ── 説明 ── */
.tot-formula { margin: 0 0 12px; display: grid; gap: 6px; }
.tot-formula > div { display: grid; grid-template-columns: 6em 1fr; gap: 8px; }
.tot-formula dt { font-weight: 700; }
.tot-formula dd { margin: 0; }
.tot-rules { padding-left: 1.2em; margin: 0; }
.tot-rules li { margin-bottom: 4px; }
.tot-example { border-collapse: collapse; width: 100%; max-width: 640px; }
.tot-example th, .tot-example td { padding: 6px 10px; border: 1px solid var(--tot-border); text-align: left; }
.tot-example th { width: 7em; background: var(--tot-surface); white-space: nowrap; }
.tot-noscript { color: var(--tot-danger); font-weight: 700; }

/* 2列にするかはツールの表示幅で決める（作業画面の並べて表示の片側でも狭ければ縦に並べる。.tot-tool は base.css の tot-tool コンテナ） */
@container tot-tool (min-width: 840px) {
  .tot-layout { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 28px; align-items: start; }
  /* 結果が画面より長くなるので、sticky のまま結果の中だけをスクロールできるようにする（コピーのボタンまで届くように） */
  .tot-result { position: sticky; top: 72px; padding: 20px; max-height: calc(100vh - 88px); overflow-y: auto; overscroll-behavior: contain; }
}

/* ── TOT-044：モードの切り替え・詳細欄・損益分岐 ── */
.tot-pp-mode { margin: 0 0 14px; padding: 8px 12px 6px; border: 1px dashed var(--tot-border); border-radius: var(--tot-radius); }
.tot-pp-mode legend { padding: 0 4px; font-weight: 600; font-size: 15px; }
.tot-pp-radio { display: flex; align-items: flex-start; gap: 8px; min-height: 36px; padding: 4px 0; cursor: pointer; }
.tot-pp-radio input { width: 20px; height: 20px; margin: 3px 0 0; flex: none; accent-color: var(--tot-primary); }
.tot-pp-sub { margin: 0; }
.tot-pp-details { margin: 0 0 14px; padding: 4px 12px; border: 1px solid var(--tot-border); border-radius: var(--tot-radius); }
.tot-pp-details > summary, .tot-pp-breakdown > summary { min-height: 40px; padding: 8px 0; font-weight: 600; cursor: pointer; }
.tot-pp-details[open] > summary { margin-bottom: 8px; }
.tot-pp-warn { margin: 0 0 10px; padding: 8px 12px; border-left: 4px solid var(--tot-focus); background: var(--tot-field-bg); font-weight: 600; font-size: 14px; }
.tot-pp-block { margin: 0 0 10px; padding: 10px 14px; border-radius: var(--tot-radius); background: var(--tot-danger-soft); color: var(--tot-danger); font-weight: 700; }
.tot-profit.is-even { border-left-color: var(--tot-muted); background: var(--tot-field-bg); }
.tot-profit.is-even .tot-profit-value { color: var(--tot-text); }
.tot-badge.tot-pp-badge-is-gain { background: var(--tot-success); color: var(--tot-field-bg); }
.tot-badge.tot-pp-badge-is-even { background: var(--tot-muted); color: var(--tot-field-bg); }
.tot-badge.tot-pp-badge-is-loss { background: var(--tot-danger); color: var(--tot-field-bg); }
.tot-pp-be { margin-top: 12px; padding: 12px 16px; border: 1px solid var(--tot-primary); border-radius: var(--tot-radius); background: var(--tot-primary-soft); }
.tot-main .tot-pp-be h3 { margin: 0 0 4px; font-size: 15px; }
.tot-pp-be-value { margin: 0 0 4px; font-size: 26px; font-weight: 800; font-variant-numeric: tabular-nums; overflow-wrap: anywhere; }
.tot-pp-be-value.is-na { font-size: 18px; color: var(--tot-muted); }
.tot-pp-breakdown { margin-top: 12px; }
.tot-pp-manual-box { margin-top: 10px; }
.tot-pp-manual { width: 100%; min-height: 12em; padding: 8px; border: 1px solid var(--tot-input-border); border-radius: var(--tot-radius); font: inherit; font-size: 13px; color: var(--tot-text); background: var(--tot-field-bg); }
.tot-copy { margin-top: 12px; }
.tot-copy-msg.is-error { color: var(--tot-danger); }
.tot-table-scroll { overflow-x: auto; }
.tot-example th { white-space: normal; width: 10em; }
.tot-formula > div { grid-template-columns: 9em 1fr; }
@media (max-width: 480px) { .tot-formula > div { grid-template-columns: 1fr; gap: 0; } }
