:root {
  --bg: #0a0e15;
  --surface: #111722;
  --surface-2: #161e2c;
  --border: #222c3c;
  --border-soft: #1a2230;
  --text: #e6e9ef;
  --muted: #8a94a6;
  --accent: #e8b84a;
  --accent-ink: #1a1306;
  --accent-soft: rgba(232, 184, 74, .12);
  --info: #6aa6ff;
  --warn: #f0a640;
  --radius: 12px;
  --radius-sm: 8px;
  --font: 'IBM Plex Sans JP', system-ui, -apple-system, 'Hiragino Sans', 'Yu Gothic UI', sans-serif;
  --mono: 'IBM Plex Mono', ui-monospace, 'SFMono-Regular', Menlo, monospace;
}
.scheme-jp { --up: #ff5f5f; --down: #2fbf88; --up-soft: rgba(255, 95, 95, .13); --down-soft: rgba(47, 191, 136, .13); }
.scheme-global { --up: #2fbf88; --down: #ff5f5f; --up-soft: rgba(47, 191, 136, .13); --down-soft: rgba(255, 95, 95, .13); }

* { box-sizing: border-box; }
html, body { margin: 0; }
body { background: var(--bg); color: var(--text); font-family: var(--font); font-size: 14px; line-height: 1.6; -webkit-font-smoothing: antialiased; }
a { color: var(--info); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3 { margin: 0; font-weight: 600; letter-spacing: .01em; }
h2 { font-size: 15px; }
code { font-family: var(--mono); background: var(--surface-2); padding: 1px 6px; border-radius: 4px; font-size: 12px; }
.mono { font-family: var(--mono); font-feature-settings: 'tnum'; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.up { color: var(--up); }
.down { color: var(--down); }
.flat { color: var(--muted); }
.warn-text { color: var(--warn); }
[hidden] { display: none !important; }

/* ---------- レイアウト ---------- */
.shell { display: flex; min-height: 100vh; }
.side {
  width: 228px; flex-shrink: 0; background: #0d121b; border-right: 1px solid var(--border-soft);
  display: flex; flex-direction: column; position: sticky; top: 0; height: 100vh;
}
.brand { display: flex; align-items: center; gap: 10px; padding: 22px 22px 18px; }
.brand-mark { color: var(--accent); font-size: 18px; }
.brand-name { font-weight: 700; font-size: 17px; letter-spacing: .04em; }
.side nav { display: flex; flex-direction: column; gap: 2px; padding: 8px 12px; flex: 1; }
.side nav a {
  display: flex; align-items: center; gap: 12px; padding: 10px 12px; border-radius: var(--radius-sm);
  color: var(--muted); font-weight: 500; transition: background .15s, color .15s;
}
.side nav a svg { width: 18px; height: 18px; fill: currentColor; opacity: .85; }
.side nav a:hover { background: var(--surface); color: var(--text); text-decoration: none; }
.side nav a.active { background: var(--accent-soft); color: var(--accent); }
.side-foot { padding: 16px 22px; border-top: 1px solid var(--border-soft); display: flex; justify-content: space-between; font-size: 12px; color: var(--muted); }

.main { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.topbar { display: flex; align-items: center; gap: 12px; padding: 20px 32px 8px; }
.topbar h1 { font-size: 22px; }
.menu-btn { display: none; background: none; border: 1px solid var(--border); color: var(--text); border-radius: 8px; padding: 4px 10px; font-size: 16px; cursor: pointer; }
.content { padding: 12px 32px 40px; display: flex; flex-direction: column; gap: 18px; max-width: 1400px; width: 100%; }
.foot-note { color: var(--muted); font-size: 11px; border-top: 1px solid var(--border-soft); padding-top: 14px; margin-top: 10px; }

/* ---------- 部品 ---------- */
.card { background: var(--surface); border: 1px solid var(--border-soft); border-radius: var(--radius); padding: 20px; }
.card > h2 { margin-bottom: 14px; }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 14px; flex-wrap: wrap; }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 18px; }
.grid-wide-left { grid-template-columns: 2fr 1fr; }
.toolbar { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; }
.btn-row { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.btn-row form { margin: 0; }
.summary-inline { display: flex; gap: 20px; flex-wrap: wrap; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  background: var(--surface-2); color: var(--text); border: 1px solid var(--border);
  border-radius: var(--radius-sm); padding: 9px 16px; font: inherit; font-weight: 500; cursor: pointer;
  transition: border-color .15s, background .15s; white-space: nowrap;
}
.btn:hover { border-color: #3a475d; text-decoration: none; }
.btn:disabled { opacity: .45; cursor: not-allowed; }
.btn-primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); font-weight: 600; }
.btn-primary:hover { background: #f2c766; border-color: #f2c766; }
.btn-ghost { background: transparent; }
.btn-sm { padding: 6px 12px; font-size: 13px; }
.btn-xs { padding: 3px 9px; font-size: 12px; }
.btn-block { width: 100%; }
.btn.loading { pointer-events: none; opacity: .7; }
.btn.loading::after { content: ''; width: 12px; height: 12px; border: 2px solid currentColor; border-right-color: transparent; border-radius: 50%; animation: spin .7s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

.flash { padding: 12px 16px; border-radius: var(--radius-sm); border: 1px solid; font-size: 13px; }
.flash-ok { background: rgba(106, 166, 255, .08); border-color: rgba(106, 166, 255, .35); }
.flash-error { background: rgba(255, 95, 95, .08); border-color: rgba(255, 95, 95, .4); }
.flash-warn { background: rgba(240, 166, 64, .08); border-color: rgba(240, 166, 64, .4); }

.seg { display: inline-flex; background: var(--bg); border: 1px solid var(--border); border-radius: 8px; padding: 2px; }
.seg button { background: none; border: 0; color: var(--muted); font: inherit; font-size: 12px; padding: 4px 10px; border-radius: 6px; cursor: pointer; }
.seg button.on { background: var(--surface-2); color: var(--text); }

.pill { display: inline-flex; align-items: center; gap: 4px; padding: 2px 10px; border-radius: 99px; font-size: 12px; font-weight: 600; white-space: nowrap; }
.dir-up { background: var(--up-soft); color: var(--up); }
.dir-down { background: var(--down-soft); color: var(--down); }
.dir-flat { background: rgba(138, 148, 166, .14); color: var(--muted); }
.badge { display: inline-block; padding: 2px 8px; border-radius: 6px; font-size: 11px; background: var(--surface-2); border: 1px solid var(--border); color: var(--muted); }
.badge-hit { color: #6ad9a8; border-color: rgba(106, 217, 168, .4); }
.badge-miss { color: #ff8a8a; border-color: rgba(255, 138, 138, .4); }
.badge-warn { color: var(--warn); border-color: rgba(240, 166, 64, .4); }
.tag { display: inline-block; margin-left: 6px; padding: 0 6px; border-radius: 4px; background: var(--surface-2); font-size: 11px; }

.stance { font-weight: 600; }
.stance-強気 { color: var(--up); }
.stance-やや強気 { color: color-mix(in srgb, var(--up) 70%, var(--text)); }
.stance-中立 { color: var(--text); }
.stance-やや弱気 { color: color-mix(in srgb, var(--down) 70%, var(--text)); }
.stance-弱気 { color: var(--down); }

/* ---------- ティッカー・KPI ---------- */
.ticker { display: grid; grid-template-columns: repeat(auto-fit, minmax(130px, 1fr)); gap: 1px; background: var(--border-soft); border: 1px solid var(--border-soft); border-radius: var(--radius); overflow: hidden; }
.tick { background: var(--surface); padding: 10px 14px; display: flex; flex-direction: column; }
.tick-label { font-size: 11px; color: var(--muted); }
.tick-price { font-size: 15px; font-weight: 500; }
.tick-chg { font-size: 12px; }

.kpis { display: grid; grid-template-columns: 1.3fr 1fr 1fr 1fr; gap: 18px; }
.kpi { background: var(--surface); border: 1px solid var(--border-soft); border-radius: var(--radius); padding: 18px 20px; }
.kpi-main { background: linear-gradient(135deg, #1a1608 0%, var(--surface) 60%); border-color: rgba(232, 184, 74, .25); }
.kpi-label { font-size: 12px; color: var(--muted); margin-bottom: 4px; }
.kpi-value { font-size: 26px; font-weight: 600; line-height: 1.25; }
.kpi-main .kpi-value { font-size: 30px; }
.kpi-sub { font-size: 12px; margin-top: 4px; color: var(--muted); }
.kpi-sub.up, .kpi-sub.down { color: inherit; }
.kpi-sub.up { color: var(--up); }
.kpi-sub.down { color: var(--down); }
.risk-dots { color: var(--warn); letter-spacing: 1px; }

/* ---------- テーブル ---------- */
.table-wrap { overflow-x: auto; }
.table { width: 100%; border-collapse: collapse; }
.table th { text-align: left; font-size: 11px; font-weight: 500; color: var(--muted); padding: 8px 10px; border-bottom: 1px solid var(--border); white-space: nowrap; }
.table td { padding: 11px 10px; border-bottom: 1px solid var(--border-soft); vertical-align: middle; }
.table tr:last-child td { border-bottom: 0; }
.table tbody tr:hover { background: rgba(255, 255, 255, .015); }
.table .num { text-align: right; white-space: nowrap; }
.table .name { font-weight: 500; color: var(--text); }
.table a:hover .name { color: var(--accent); }
.table.compact td { padding: 7px 10px; font-size: 13px; }
.table .actions { display: flex; gap: 6px; justify-content: flex-end; }
.table .actions form { margin: 0; }
.table .reason { max-width: 380px; color: var(--muted); }
.row-error td { background: rgba(255, 95, 95, .05); }

/* ---------- チャート ---------- */
.chart-box { position: relative; height: 260px; }
.chart-tall { height: 340px; }
.alloc { display: grid; grid-template-columns: 220px 1fr; gap: 18px; align-items: center; }
.chart-donut { height: 220px; }
.alloc-legend { list-style: none; padding: 0; margin: 0; display: flex; flex-direction: column; gap: 8px; }
.alloc-legend li { display: grid; grid-template-columns: 12px 1fr auto auto; gap: 10px; align-items: center; font-size: 13px; }
.alloc-legend i { width: 10px; height: 10px; border-radius: 3px; }
.alloc-legend .pct { color: var(--muted); font-family: var(--mono); font-size: 12px; min-width: 48px; text-align: right; }

/* ---------- 予測 ---------- */
.headline { font-size: 16px; font-weight: 600; margin: 0 0 12px; color: var(--accent); }
.pred-list { list-style: none; margin: 0 0 10px; padding: 0; display: flex; flex-direction: column; }
.pred-list li { display: grid; grid-template-columns: 1fr auto 120px; gap: 12px; align-items: center; padding: 9px 0; border-bottom: 1px solid var(--border-soft); }
.pred-list li:last-child { border-bottom: 0; }
.pred-name { color: var(--text); font-weight: 500; }
.conf { display: flex; align-items: center; gap: 8px; }
.conf-bar { flex: 1; height: 5px; background: var(--surface-2); border-radius: 3px; overflow: hidden; }
.conf-bar i { display: block; height: 100%; background: var(--accent); }

/* ---------- AIチーム ---------- */
.team { display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: 10px; margin-bottom: 14px; }
.agent { display: flex; gap: 12px; align-items: center; padding: 12px; background: var(--surface-2); border: 1px solid var(--border-soft); border-radius: var(--radius-sm); }
.agent-icon { width: 38px; height: 38px; flex-shrink: 0; display: grid; place-items: center; font-size: 20px; background: var(--bg); border-radius: 10px; }
.agent-icon.sm { display: inline-grid; width: 28px; height: 28px; font-size: 15px; vertical-align: middle; margin-right: 4px; }
.agent-name { font-weight: 600; }
.agent-chief { border-color: rgba(232, 184, 74, .35); }

.progress { height: 6px; background: var(--surface-2); border-radius: 3px; overflow: hidden; margin-bottom: 14px; }
.progress i { display: block; height: 100%; width: 0; background: var(--accent); transition: width .4s; }
.steps { list-style: none; margin: 0 0 10px; padding: 0; display: flex; flex-direction: column; gap: 2px; }
.steps li { display: grid; grid-template-columns: 22px 1fr; gap: 8px; padding: 6px 4px; font-size: 13px; }
.steps .st { text-align: center; }
.steps .st-pending { color: var(--muted); }
.steps .st-running { color: var(--accent); }
.steps .st-done { color: #6ad9a8; }
.steps .st-error { color: #ff8a8a; }
.steps .st-skipped { color: var(--muted); }
.steps .note { color: var(--muted); font-size: 12px; margin-left: 8px; }
.steps .err { color: #ff8a8a; font-size: 12px; display: block; }
.steps li.running { background: var(--accent-soft); border-radius: 6px; }

.report-tabs { display: flex; gap: 6px; flex-wrap: wrap; position: sticky; top: 0; z-index: 5; background: var(--bg); padding: 8px 0; }
.report-tabs a { padding: 6px 12px; border-radius: 99px; background: var(--surface); border: 1px solid var(--border-soft); color: var(--text); font-size: 13px; }
.report-tabs a:hover { border-color: var(--accent); text-decoration: none; }
.report-section { display: flex; flex-direction: column; gap: 14px; scroll-margin-top: 60px; }
.report-chief { border-color: rgba(232, 184, 74, .35); }

/* ---------- Markdown ---------- */
.md { line-height: 1.8; overflow-wrap: anywhere; }
.md:not(.rendered) { white-space: pre-wrap; }
.md h1, .md h2, .md h3, .md h4 { margin: 18px 0 8px; font-size: 15px; color: var(--accent); }
.md h2:first-child, .md h3:first-child { margin-top: 0; }
.md p { margin: 0 0 10px; }
.md ul, .md ol { margin: 0 0 10px; padding-left: 1.4em; }
.md li { margin: 2px 0; }
.md strong { color: #fff; }
.md table { border-collapse: collapse; width: 100%; margin: 8px 0 14px; font-size: 13px; display: block; overflow-x: auto; }
.md th, .md td { border: 1px solid var(--border); padding: 6px 10px; text-align: left; vertical-align: top; }
.md th { background: var(--surface-2); font-weight: 500; }
.md a { word-break: break-all; }
.sources { margin-top: 12px; font-size: 12px; color: var(--muted); }
.sources summary { cursor: pointer; }
.sources ol { margin: 8px 0 0; padding-left: 1.4em; }
details > summary { cursor: pointer; color: var(--muted); }

/* ---------- 銘柄ページ ---------- */
.symbol-head { display: flex; justify-content: space-between; gap: 20px; flex-wrap: wrap; align-items: center; }
.big-price { font-size: 32px; font-weight: 600; display: flex; gap: 14px; align-items: baseline; }
.big-price span { font-size: 16px; }
.held-box { display: flex; flex-direction: column; gap: 4px; font-size: 13px; }
.stats { display: grid; grid-template-columns: 1fr auto; gap: 10px 14px; margin: 0; }
.stats dt { color: var(--muted); font-size: 13px; }
.stats dd { margin: 0; text-align: right; }

/* ---------- フォーム ---------- */
.form { display: flex; flex-direction: column; gap: 14px; }
.form label { display: flex; flex-direction: column; gap: 6px; font-size: 13px; color: var(--muted); }
.form label > span { color: var(--muted); }
.form label.inline { flex-direction: row; align-items: center; gap: 8px; color: var(--text); display: inline-flex; margin-right: 16px; }
.form-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: 14px; }
.form-inline { flex-direction: row; flex-wrap: wrap; align-items: flex-end; }
.form-inline label { flex: 1; min-width: 140px; }
input, select, textarea {
  background: var(--bg); color: var(--text); border: 1px solid var(--border); border-radius: var(--radius-sm);
  padding: 9px 12px; font: inherit; width: 100%;
}
input[type=radio], input[type=checkbox] { width: auto; accent-color: var(--accent); }
input[type=file] { padding: 8px; }
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
fieldset { border: 1px solid var(--border); border-radius: var(--radius-sm); padding: 12px 16px; margin: 0; display: flex; flex-wrap: wrap; gap: 10px 4px; align-items: center; }
legend { color: var(--muted); font-size: 12px; padding: 0 6px; }
.input-btn { display: flex; gap: 6px; }
.input-btn input { flex: 1; }
.type-picker { display: flex; gap: 6px; flex-wrap: wrap; }
.type-opt input { display: none; }
.type-opt span { display: inline-block; padding: 8px 14px; border-radius: 99px; border: 1px solid var(--border); color: var(--text); cursor: pointer; }
.type-opt input:checked + span { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); font-weight: 600; }
.field-label { display: block; font-size: 13px; color: var(--muted); margin-bottom: 6px; }
.price-box .manual-price { flex-basis: 100%; }
.form-wide { max-width: 860px; }

.empty { text-align: center; padding: 40px 20px; }
.empty h2 { margin-bottom: 8px; font-size: 18px; }
.empty .btn { margin: 6px 4px 0; }

/* ---------- ログイン ---------- */
.auth-body { min-height: 100vh; display: grid; place-items: center; padding: 20px; background: radial-gradient(ellipse at top, #1a1608 0%, var(--bg) 60%); }
.auth-card { width: 100%; max-width: 380px; background: var(--surface); border: 1px solid var(--border-soft); border-radius: 16px; padding: 30px; }
.auth-brand { padding: 0 0 18px; }
.auth-card h1 { font-size: 20px; margin-bottom: 14px; }
.auth-card .flash { margin-bottom: 12px; }

.toast { position: fixed; right: 20px; bottom: 20px; z-index: 100; max-width: 380px; background: var(--surface-2); border: 1px solid var(--border); border-radius: var(--radius-sm); padding: 12px 16px; box-shadow: 0 10px 30px rgba(0, 0, 0, .4); font-size: 13px; animation: fadein .2s; }
.toast.error { border-color: rgba(255, 95, 95, .5); }
@keyframes fadein { from { opacity: 0; transform: translateY(6px); } }

/* ---------- レスポンシブ ---------- */
@media (max-width: 1100px) {
  .kpis { grid-template-columns: 1fr 1fr; }
  .grid-2, .grid-wide-left { grid-template-columns: 1fr; }
}
@media (max-width: 760px) {
  .side { position: fixed; left: 0; top: 0; z-index: 50; transform: translateX(-100%); transition: transform .2s; box-shadow: 0 0 40px rgba(0, 0, 0, .6); }
  .side.open { transform: none; }
  .menu-btn { display: block; }
  .topbar { padding: 14px 16px 4px; }
  .topbar h1 { font-size: 18px; }
  .content { padding: 10px 14px 30px; }
  .kpis { grid-template-columns: 1fr; }
  .alloc { grid-template-columns: 1fr; }
  .pred-list li { grid-template-columns: 1fr auto; }
  .pred-list .conf { grid-column: 1 / -1; }
  .card { padding: 16px; }
}
