/* レイアウト：PC では左ナビ＋本文、狭い画面では上部の横スクロールタブ。
   色は「藍鼠（あいねず）」系の落ち着いた中間色＋深い藍の差し色。 */
:root {
  --bg: #f4f6f7;
  --surface: #ffffff;
  --surface-2: #eef2f3;
  --line: #d9e0e2;
  --fg: #16232a;
  --fg-2: #4a5a62;
  --fg-3: #6f7f87;
  --accent: #1f4f7a;
  --accent-soft: #e3ecf5;
  --up: #b4372f;      /* 値上げ */
  --up-soft: #f8e6e4;
  --down: #1d7a4a;    /* 値下げ */
  --down-soft: #e2f2e9;
  --warn: #9a6400;
  --warn-soft: #fbf0d9;
  --muted-soft: #eceff0;
  --s1: #2a78d6; --s2: #eb6834; --s3: #1baf7a; --s4: #eda100; --s5: #e87ba4;
  --s6: #008300; --s7: #6250d6; --s8: #e34948;
  --font-ui: "BIZ UDPGothic", "Hiragino Sans", "Yu Gothic UI", "Meiryo", sans-serif;
  --font-num: "Inter", "BIZ UDPGothic", system-ui, sans-serif;
  --radius: 6px;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #11181c; --surface: #182227; --surface-2: #1f2b31; --line: #2c3a41;
    --fg: #e6ecee; --fg-2: #b2bfc5; --fg-3: #8697a0;
    --accent: #7fb0e0; --accent-soft: #1f3247;
    --up: #ef8a80; --up-soft: #3a2422; --down: #6fcf9a; --down-soft: #1b3326;
    --warn: #e9b44c; --warn-soft: #362b14; --muted-soft: #222d32;
    --s1: #3987e5; --s2: #d95926; --s3: #199e70; --s4: #c98500; --s5: #d55181;
    --s6: #0ca30c; --s7: #9085e9; --s8: #e66767;
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #11181c; --surface: #182227; --surface-2: #1f2b31; --line: #2c3a41;
  --fg: #e6ecee; --fg-2: #b2bfc5; --fg-3: #8697a0;
  --accent: #7fb0e0; --accent-soft: #1f3247;
  --up: #ef8a80; --up-soft: #3a2422; --down: #6fcf9a; --down-soft: #1b3326;
  --warn: #e9b44c; --warn-soft: #362b14; --muted-soft: #222d32;
  --s1: #3987e5; --s2: #d95926; --s3: #199e70; --s4: #c98500; --s5: #d55181;
  --s6: #0ca30c; --s7: #9085e9; --s8: #e66767;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg); color: var(--fg);
  font-family: var(--font-ui); font-size: 14px; line-height: 1.6;
}
.num, td.num, .kpi-value { font-family: var(--font-num); font-variant-numeric: tabular-nums; }
a { color: var(--accent); }
button, select, input { font: inherit; color: inherit; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* ---- 構造 ---- */
.app { display: grid; grid-template-columns: 220px minmax(0, 1fr); min-height: 100vh; }
.side {
  background: var(--surface); border-right: 1px solid var(--line);
  padding: 20px 12px; position: sticky; top: 0; height: 100vh; overflow-y: auto;
}
.brand { padding: 0 8px 16px; border-bottom: 1px solid var(--line); margin-bottom: 12px; }
.brand-title { font-weight: 700; font-size: 15px; line-height: 1.4; }
.brand-sub { color: var(--fg-3); font-size: 12px; }
.nav { display: flex; flex-direction: column; gap: 2px; }
.nav a {
  display: block; padding: 8px 10px; border-radius: var(--radius); text-decoration: none;
  color: var(--fg-2); font-size: 13.5px;
}
.nav a:hover { background: var(--surface-2); color: var(--fg); }
.nav a[aria-current="page"] { background: var(--accent-soft); color: var(--accent); font-weight: 700; }
.side-foot { margin-top: 20px; padding: 12px 8px 0; border-top: 1px solid var(--line); color: var(--fg-3); font-size: 12px; }

.main { min-width: 0; padding-block: 20px 48px; padding-left: max(24px, env(safe-area-inset-left, 0px)); padding-right: max(24px, env(safe-area-inset-right, 0px)); }
.topbar { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 16px; margin-bottom: 16px; }
.page-title { font-size: 20px; font-weight: 700; margin: 0; text-wrap: balance; }
.updated { color: var(--fg-2); font-size: 12.5px; margin-left: auto; }
.notice {
  display: flex; gap: 10px; align-items: flex-start;
  background: var(--warn-soft); color: var(--fg); border: 1px solid var(--warn);
  border-radius: var(--radius); padding: 10px 14px; margin-bottom: 16px; font-size: 13px;
}
.notice strong { color: var(--warn); white-space: nowrap; }

.panel { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; min-width: 0; }
.panel h2 { font-size: 15px; margin: 0 0 4px; }
.panel .sub { color: var(--fg-3); font-size: 12px; margin: 0 0 12px; }
.grid { display: grid; gap: 16px; }
.grid-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.stack { display: flex; flex-direction: column; gap: 16px; }

/* ---- KPI ---- */
.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 12px; margin-bottom: 16px; }
.kpi { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px 14px; }
.kpi-label { color: var(--fg-2); font-size: 12px; letter-spacing: .02em; }
.kpi-value { font-size: 26px; font-weight: 600; line-height: 1.3; }
.kpi-note { color: var(--fg-3); font-size: 11.5px; }
.kpi.up .kpi-value { color: var(--up); }
.kpi.down .kpi-value { color: var(--down); }
.kpi.err .kpi-value { color: var(--warn); }

/* ---- チップ ---- */
.chip { display: inline-flex; align-items: center; gap: 4px; padding: 1px 8px; border-radius: 999px; font-size: 12px; white-space: nowrap; border: 1px solid transparent; }
.chip.up { background: var(--up-soft); color: var(--up); }
.chip.down { background: var(--down-soft); color: var(--down); }
.chip.new { background: var(--accent-soft); color: var(--accent); }
.chip.end, .chip.muted { background: var(--muted-soft); color: var(--fg-2); }
.chip.warn { background: var(--warn-soft); color: var(--warn); }
.chip.ok { background: var(--down-soft); color: var(--down); }
.chip.unl { background: var(--surface-2); color: var(--fg-2); border-color: var(--line); }
.swatch { display: inline-block; width: 10px; height: 10px; border-radius: 2px; margin-right: 6px; vertical-align: baseline; }

/* ---- ニュース ---- */
.news { list-style: none; margin: 0; padding: 0; }
.news li { display: grid; grid-template-columns: 88px minmax(0, 1fr) auto; gap: 10px; align-items: baseline; padding: 9px 0; border-bottom: 1px solid var(--line); }
.news li:last-child { border-bottom: 0; }
.news .what { min-width: 0; }
.news .meta { color: var(--fg-3); font-size: 12px; }

/* ---- フィルタ ---- */
.filters { display: flex; flex-wrap: wrap; gap: 10px 12px; align-items: flex-end; margin-bottom: 14px; }
.field { display: flex; flex-direction: column; gap: 3px; min-width: 0; }
.field label { font-size: 11.5px; color: var(--fg-2); letter-spacing: .02em; }
.field select, .field input {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 6px 8px; min-width: 110px; max-width: 100%;
}
.field input[type="number"] { width: 110px; min-width: 0; }
.btn {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 6px 12px; cursor: pointer; white-space: nowrap;
}
.btn:hover { border-color: var(--accent); color: var(--accent); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--surface); }
.btn.primary:hover { opacity: .9; color: var(--surface); }
.seg { display: inline-flex; border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; }
.seg button { border: 0; background: var(--surface); padding: 6px 12px; cursor: pointer; }
.seg button + button { border-left: 1px solid var(--line); }
.seg button[aria-pressed="true"] { background: var(--accent); color: var(--surface); }

/* ---- 表 ---- */
.table-wrap { overflow-x: auto; border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface); }
table { border-collapse: collapse; width: 100%; font-size: 13px; }
th, td { padding: 7px 10px; border-bottom: 1px solid var(--line); text-align: left; vertical-align: top; }
th { background: var(--surface-2); color: var(--fg-2); font-weight: 600; font-size: 12px; white-space: nowrap; position: sticky; top: 0; }
th.sortable { cursor: pointer; user-select: none; }
th.sortable:hover { color: var(--accent); }
td.num, th.num { text-align: right; white-space: nowrap; }
tr:hover td { background: var(--surface-2); }
td .small { display: block; color: var(--fg-3); font-size: 11.5px; }
.cell-na { color: var(--fg-3); font-size: 12px; }
.cell-best { font-weight: 700; color: var(--accent); }
.matrix td.num { min-width: 92px; }
.pager { display: flex; gap: 8px; align-items: center; justify-content: flex-end; margin-top: 8px; color: var(--fg-2); font-size: 12.5px; }

/* ---- グラフ ---- */
.chart-box { position: relative; height: 340px; }
.legend { display: flex; flex-wrap: wrap; gap: 6px 16px; font-size: 12.5px; color: var(--fg-2); margin-bottom: 8px; }

/* ---- 企業分析 ---- */
.company-pick { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 16px; }
.company-pick button { border: 1px solid var(--line); background: var(--surface); padding: 6px 14px; border-radius: 999px; cursor: pointer; }
.company-pick button[aria-pressed="true"] { border-color: var(--accent); background: var(--accent-soft); color: var(--accent); font-weight: 700; }

/* ---- AI分析 ---- */
.ai-sec { border-top: 1px solid var(--line); padding-top: 12px; margin-top: 12px; }
.ai-sec:first-of-type { border-top: 0; margin-top: 0; padding-top: 0; }
.ai-sec h3 { font-size: 14px; margin: 0 0 8px; }
.ai-list { margin: 0 0 8px; padding-left: 0; list-style: none; display: flex; flex-direction: column; gap: 6px; }
.ai-list li { display: grid; grid-template-columns: 64px minmax(0, 1fr); gap: 8px; align-items: baseline; }
.tag { font-size: 11px; padding: 1px 6px; border-radius: 4px; text-align: center; white-space: nowrap; }
.tag.fact { background: var(--accent-soft); color: var(--accent); }
.tag.infer { background: var(--warn-soft); color: var(--warn); }

.muted { color: var(--fg-3); }
.mt { margin-top: 16px; }
.empty { padding: 24px; text-align: center; color: var(--fg-3); }
code { font-size: 12px; background: var(--surface-2); padding: 1px 4px; border-radius: 3px; }

/* ---- レスポンシブ ---- */
@media (max-width: 900px) {
  .app { grid-template-columns: minmax(0, 1fr); }
  .side { position: sticky; top: 0; height: auto; z-index: 5; padding: 10px max(16px, env(safe-area-inset-right, 0px)) 0 max(16px, env(safe-area-inset-left, 0px)); border-right: 0; border-bottom: 1px solid var(--line); }
  .brand { border: 0; padding: 0 0 6px; margin: 0; }
  .brand-sub, .side-foot { display: none; }
  .nav { flex-direction: row; overflow-x: auto; gap: 4px; padding-bottom: 8px; }
  .nav a { white-space: nowrap; padding: 6px 10px; }
  .main { padding-left: max(16px, env(safe-area-inset-left, 0px)); padding-right: max(16px, env(safe-area-inset-right, 0px)); }
  .grid-2 { grid-template-columns: minmax(0, 1fr); }
  .updated { margin-left: 0; }
  .news li { grid-template-columns: minmax(0, 1fr); gap: 2px; }
  .chart-box { height: 280px; }
}
@media (prefers-reduced-motion: reduce) { * { transition: none !important; animation: none !important; } }
