/* ===========================================================================
   Trend Console
   考え方は運転盤（ハイパフォーマンスHMI）と同じ。
   平常時は無彩色に沈め、色は「人が手を動かす必要がある」ところにだけ出す。
   =========================================================================== */

:root {
  --field:    #CFD2CD;
  --panel:    #E6E8E3;
  --panel-hi: #F3F4F1;
  --ink:      #14181A;
  --ink-2:    #5B625E;
  --ink-3:    #848A83;
  --rule:     #A9AEA7;
  --rule-2:   #BEC2BB;

  --act:      #8F5502;   /* 発注が必要 */
  --act-bg:   #F6EBD8;
  --alarm:    #93261B;   /* 手仕舞いが必要 */
  --alarm-bg: #F4DED9;
  --info:     #2A4351;   /* 逆指値の付け替え */

  --sans: "IBM Plex Sans JP", system-ui, sans-serif;
  --cond: "IBM Plex Sans Condensed", "IBM Plex Sans JP", sans-serif;
  --mono: "IBM Plex Mono", ui-monospace, monospace;

  --gap: 1.25rem;
  --edge: clamp(0.9rem, 3vw, 2.25rem);
}

* { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  background: var(--field);
  color: var(--ink);
  font-family: var(--sans);
  font-size: 15px;
  line-height: 1.6;
  /* 盤面の質感。ごく薄いグリッドだけ敷いて、それ以上は飾らない。 */
  background-image:
    linear-gradient(rgba(0,0,0,.022) 1px, transparent 1px),
    linear-gradient(90deg, rgba(0,0,0,.022) 1px, transparent 1px);
  background-size: 28px 28px;
}

:focus-visible { outline: 2px solid var(--ink); outline-offset: 2px; }

h1, h2, h3 { margin: 0; font-weight: 600; }
p { margin: 0 0 .6rem; }
code { font-family: var(--mono); font-size: .92em; background: var(--panel-hi); padding: 0 .25em; }
b, strong { font-weight: 600; }

/* ── ヘッダ（タグバー） ───────────────────────────────────────────────── */

.rail {
  display: flex; align-items: center; gap: 1.5rem; flex-wrap: wrap;
  padding: .7rem var(--edge);
  background: var(--ink);
  color: var(--panel-hi);
  border-bottom: 3px solid var(--rule);
}
.rail__mark {
  width: 13px; height: 13px; flex: none;
  background: var(--panel-hi);
  clip-path: polygon(50% 0, 100% 100%, 0 100%);
}
.rail__title {
  font-family: var(--cond);
  font-size: 1.12rem; font-weight: 700;
  letter-spacing: .13em; text-transform: uppercase;
}
.rail__tags { display: flex; gap: 1.6rem; margin: 0; flex-wrap: wrap; flex: 1; }
.tag dt {
  font-family: var(--cond); font-size: .64rem; font-weight: 600;
  letter-spacing: .16em; text-transform: uppercase; color: #9AA39D;
}
.tag dd { margin: 0; font-family: var(--mono); font-size: .88rem; }

/* ── タブ ────────────────────────────────────────────────────────────── */

.tabs {
  display: flex; gap: 0;
  padding: 0 var(--edge);
  background: var(--panel);
  border-bottom: 1px solid var(--rule);
}
.tab {
  appearance: none; border: 0; background: none; cursor: pointer;
  font-family: var(--cond); font-size: .82rem; font-weight: 600;
  letter-spacing: .1em;
  padding: .8rem 1.4rem;
  color: var(--ink-2);
  border-bottom: 3px solid transparent;
  margin-bottom: -1px;
}
.tab:hover { color: var(--ink); }
.tab.is-on { color: var(--ink); border-bottom-color: var(--ink); }

/* ── レイアウト ──────────────────────────────────────────────────────── */

main { padding: var(--gap) var(--edge) 3rem; max-width: 1180px; margin: 0 auto; }
.view > section { margin-bottom: 2.4rem; }

.eyebrow {
  font-family: var(--cond); font-size: .66rem; font-weight: 600;
  letter-spacing: .18em; text-transform: uppercase; color: var(--ink-2);
  margin: 0 0 .5rem;
}
.section-h {
  font-size: 1.02rem;
  padding-bottom: .4rem; margin-bottom: .9rem;
  border-bottom: 1px solid var(--rule);
  display: flex; align-items: baseline; gap: .6rem;
}
.section-h__n { font-family: var(--mono); font-size: .82rem; color: var(--ink-2); }
.lede { color: var(--ink-2); max-width: 62ch; }
.hint { font-size: .8rem; color: var(--ink-2); margin: .5rem 0 0; }
.warn {
  font-size: .84rem; color: var(--alarm);
  border-left: 3px solid var(--alarm); padding-left: .7rem; margin-top: 1rem;
}
.panel {
  background: var(--panel); border: 1px solid var(--rule);
  padding: 1.2rem 1.3rem;
}

/* ── リスクゲージ ────────────────────────────────────────────────────── */

.gauge { background: var(--panel); border: 1px solid var(--rule); padding: 1rem 1.2rem 1.1rem; }
.gauge__bar { display: flex; gap: 3px; height: 26px; margin-bottom: .5rem; }
.gauge__bar i { flex: 1; background: var(--rule-2); }
.gauge__bar i.on { background: var(--ink); }
.gauge__bar i.over { background: var(--alarm); }
.gauge__read { font-family: var(--mono); font-size: .86rem; margin: 0 0 .9rem; }

.readout {
  display: grid; grid-template-columns: repeat(auto-fit, minmax(112px, 1fr));
  gap: .8rem 1.4rem; margin: 0;
  border-top: 1px solid var(--rule-2); padding-top: .85rem;
}
.readout dt {
  font-family: var(--cond); font-size: .64rem; letter-spacing: .14em;
  text-transform: uppercase; color: var(--ink-2);
}
.readout dd { margin: 0; font-family: var(--mono); font-size: 1.02rem; }

/* ── 指示票（この画面の主役） ────────────────────────────────────────── */

#tickets { display: grid; gap: .7rem; }

.ticket {
  display: grid;
  grid-template-columns: 6px 8.5rem 1fr auto;
  align-items: center;
  gap: 0 1.1rem;
  background: var(--panel-hi);
  border: 1px solid var(--rule);
  padding: .85rem 1.1rem .85rem 0;
  /* 券の角を落とす。切符と同じで「もぎ取って使う」ものだという合図。 */
  clip-path: polygon(0 0, calc(100% - 11px) 0, 100% 11px, 100% 100%, 0 100%);
}
.ticket__bar { grid-row: 1 / -1; align-self: stretch; background: var(--rule); }
.ticket__act {
  font-family: var(--cond); font-weight: 700; font-size: 1.02rem;
  letter-spacing: .08em; padding-left: 1.1rem;
}
.ticket__line { font-family: var(--mono); font-size: .95rem; }
.ticket__note { grid-column: 3 / -1; font-size: .78rem; color: var(--ink-2); }
.ticket__copy {
  appearance: none; cursor: pointer; background: none;
  border: 1px solid var(--rule); color: var(--ink-2);
  font-family: var(--cond); font-size: .68rem; letter-spacing: .1em;
  padding: .3rem .6rem;
}
.ticket__copy:hover { border-color: var(--ink); color: var(--ink); }

.ticket--exit  { background: var(--alarm-bg); border-color: var(--alarm); }
.ticket--exit  .ticket__bar { background: var(--alarm); }
.ticket--exit  .ticket__act { color: var(--alarm); }
.ticket--buy   { background: var(--act-bg); border-color: var(--act); }
.ticket--buy   .ticket__bar { background: var(--act); }
.ticket--buy   .ticket__act { color: var(--act); }
.ticket--stop  .ticket__bar { background: var(--info); }
.ticket--stop  .ticket__act { color: var(--info); }
.ticket--skip  { background: transparent; border-style: dashed; }
.ticket--skip  .ticket__act { color: var(--ink-3); }

.idle {
  border: 1px solid var(--rule); background: var(--panel);
  padding: 2.6rem 1.2rem; text-align: center;
}
.idle b {
  display: block; font-family: var(--cond); font-weight: 600;
  font-size: 1.9rem; letter-spacing: .1em; color: var(--ink-2);
}
.idle span { font-size: .84rem; color: var(--ink-3); }

/* ── 表 ──────────────────────────────────────────────────────────────── */

.scroll { overflow-x: auto; border: 1px solid var(--rule); background: var(--panel-hi); }
.grid { width: 100%; border-collapse: collapse; font-family: var(--mono); font-size: .82rem; }
.grid th {
  position: sticky; top: 0;
  font-family: var(--cond); font-size: .64rem; font-weight: 600;
  letter-spacing: .12em; text-transform: uppercase;
  text-align: right; white-space: nowrap;
  background: var(--panel); color: var(--ink-2);
  padding: .5rem .7rem; border-bottom: 1px solid var(--rule);
}
.grid th:first-child, .grid td:first-child { text-align: left; }
.grid td {
  text-align: right; white-space: nowrap;
  padding: .42rem .7rem; border-bottom: 1px solid var(--rule-2);
}
.grid tbody tr:hover { background: var(--panel); }
.grid .num--neg { color: var(--alarm); }
.grid .is-break { font-weight: 600; color: var(--act); }
.grid .empty { text-align: center; color: var(--ink-3); padding: 1.6rem; font-family: var(--sans); }

/* 直前N日高値までの距離を、行の中に小さなバーで出す */
.dist { display: flex; align-items: center; justify-content: flex-end; gap: .5rem; }
.dist__track { width: 62px; height: 7px; background: var(--rule-2); position: relative; }
.dist__fill { position: absolute; top: 0; bottom: 0; background: var(--ink-2); }
.dist__fill.over { background: var(--act); }

.linkish {
  appearance: none; border: 0; background: none; cursor: pointer;
  color: var(--alarm); font-family: var(--cond); font-size: .68rem;
  letter-spacing: .1em; padding: .1rem .3rem;
}
.linkish:hover { text-decoration: underline; }

/* ── フォーム ────────────────────────────────────────────────────────── */

.addpos { margin-top: 1.1rem; background: var(--panel); border: 1px solid var(--rule); padding: 1rem 1.1rem; }
.addpos__row { display: flex; flex-wrap: wrap; gap: .8rem; align-items: flex-end; }
label { display: block; font-size: .78rem; color: var(--ink-2); }
input, textarea, select {
  display: block; width: 100%; margin-top: .25rem;
  font-family: var(--mono); font-size: .88rem; color: var(--ink);
  background: var(--panel-hi); border: 1px solid var(--rule);
  padding: .42rem .55rem;
}
.addpos__row label { flex: 1 1 8rem; }
textarea { resize: vertical; }

.fields { display: grid; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); gap: .9rem 1.2rem; }
.split { display: flex; flex-wrap: wrap; gap: .9rem; align-items: flex-end; margin-top: .9rem; }
.split label { flex: 0 1 11rem; }
.actions { display: flex; flex-wrap: wrap; gap: .6rem; margin-top: 1.3rem; }

.btn {
  appearance: none; cursor: pointer;
  font-family: var(--cond); font-size: .78rem; font-weight: 600; letter-spacing: .09em;
  padding: .5rem 1rem;
  background: var(--panel-hi); color: var(--ink);
  border: 1px solid var(--ink);
}
.btn:hover { background: var(--ink); color: var(--panel-hi); }
.btn--primary { background: var(--ink); color: var(--panel-hi); }
.btn--primary:hover { background: var(--panel-hi); color: var(--ink); }
.btn--danger { border-color: var(--alarm); color: var(--alarm); }
.btn--danger:hover { background: var(--alarm); color: var(--panel-hi); }
.btn[disabled] { opacity: .45; cursor: progress; }

/* ── 通知 ────────────────────────────────────────────────────────────── */

.banner {
  margin: 0 var(--edge); padding: .7rem 1rem;
  font-size: .84rem; border: 1px solid var(--rule); background: var(--panel-hi);
  border-left: 4px solid var(--ink-2);
}
.banner.is-bad { border-left-color: var(--alarm); color: var(--alarm); background: var(--alarm-bg); }

/* ── バックテスト出力 ────────────────────────────────────────────────── */

.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(130px, 1fr)); gap: 1px; background: var(--rule); border: 1px solid var(--rule); }
.stat { background: var(--panel-hi); padding: .7rem .85rem; }
.stat dt { font-family: var(--cond); font-size: .62rem; letter-spacing: .12em; text-transform: uppercase; color: var(--ink-2); }
.stat dd { margin: .15rem 0 0; font-family: var(--mono); font-size: 1.12rem; }
.stat dd.neg { color: var(--alarm); }

.chart { background: var(--panel-hi); border: 1px solid var(--rule); padding: .6rem; margin-top: 1.1rem; }
.chart svg { display: block; width: 100%; height: auto; }
.chart .eq { fill: none; stroke: var(--ink); stroke-width: 1.6; }
.chart .bh { fill: none; stroke: var(--ink-3); stroke-width: 1.2; stroke-dasharray: 4 3; }
.chart .dd { fill: var(--alarm); opacity: .17; }
.chart .axis { stroke: var(--rule); stroke-width: 1; }
.chart text { font-family: var(--mono); font-size: 10px; fill: var(--ink-2); }
.chart .split-line { stroke: var(--act); stroke-width: 1.4; stroke-dasharray: 3 3; }

.legend { display: flex; gap: 1.2rem; font-size: .74rem; color: var(--ink-2); margin-top: .5rem; }
.legend i { display: inline-block; width: 16px; height: 2px; vertical-align: middle; margin-right: .4rem; }

.rules { margin: 0; padding-left: 1.3rem; }
.rules li { margin-bottom: .35rem; }

.foot { padding: 1.4rem var(--edge) 2.5rem; font-size: .76rem; color: var(--ink-2); border-top: 1px solid var(--rule); }

/* ── 動き ────────────────────────────────────────────────────────────── */

.is-loading .gauge__bar i { animation: sweep 1.1s linear infinite; }
.gauge__bar i:nth-child(2n) { animation-delay: .07s; }
@keyframes sweep { 0%,100% { opacity: 1 } 50% { opacity: .35 } }

@media (prefers-reduced-motion: reduce) {
  * { animation-duration: .001ms !important; transition-duration: .001ms !important; }
}

@media (max-width: 620px) {
  .ticket { grid-template-columns: 6px 1fr; padding-right: .8rem; }
  .ticket__act { grid-column: 2; padding-left: .9rem; }
  .ticket__line { grid-column: 2; padding-left: .9rem; }
  .ticket__note { grid-column: 2; padding-left: .9rem; }
  .ticket__copy { grid-column: 2; justify-self: start; margin-left: .9rem; margin-top: .4rem; }
  .rail__tags { gap: 1rem; }
}
