:root {
  --bg: #f5f6f8;
  --panel: #ffffff;
  --ink: #1c2733;
  --muted: #6b7785;
  --line: #e3e7ec;
  --brand: #2e7d32;
  --brand-ink: #1b5e20;
  --accent: #1976d2;
  --pos: #2e7d32;
  --neg: #d62728;
  --warn: #b26a00;
  --radius: 10px;
  --shadow: 0 1px 3px rgba(20, 30, 45, .08);
}

* { box-sizing: border-box; }
body {
  margin: 0;
  display: flex;
  min-height: 100vh;
  background: var(--bg);
  color: var(--ink);
  font-family: -apple-system, "Hiragino Kaku Gothic ProN", "Yu Gothic", Meiryo, sans-serif;
  font-size: 14px;
}

/* ── sidebar ── */
.sidebar {
  width: 224px;
  flex: 0 0 224px;
  background: #0f1b26;
  color: #cdd7e0;
  display: flex;
  flex-direction: column;
  position: sticky;
  top: 0;
  height: 100vh;
}
.brand { padding: 18px 18px 14px; font-weight: 700; font-size: 16px; color: #fff; }
.sidebar nav { display: flex; flex-direction: column; gap: 2px; padding: 4px 8px; }
.sidebar nav a {
  display: flex; align-items: center; gap: 10px;
  padding: 9px 12px; border-radius: 8px;
  color: #aeb9c4; text-decoration: none; font-size: 13.5px;
}
.sidebar nav a:hover { background: #18293a; color: #fff; }
.sidebar nav a.active { background: var(--brand); color: #fff; }
.sidebar nav .ico { width: 18px; text-align: center; }
.sidebar-foot { margin-top: auto; padding: 16px; font-size: 12px; }
.sidebar-foot a { color: #7f8fa0; text-decoration: none; }
.sidebar-foot a:hover { color: #fff; }

/* ── content ── */
.content { flex: 1; padding: 26px 32px 60px; max-width: 1200px; }
.page-head h1 { margin: 0; font-size: 22px; }
.page-head .sub { margin: 4px 0 18px; color: var(--muted); }

.panel {
  background: var(--panel); border: 1px solid var(--line);
  border-radius: var(--radius); box-shadow: var(--shadow);
  padding: 18px 20px; margin-bottom: 18px;
}
.panel h2 { margin: 0 0 12px; font-size: 15px; }
.panel h3 { margin: 14px 0 8px; font-size: 14px; color: var(--muted); }

/* ── metrics ── */
.metrics { display: flex; flex-wrap: wrap; gap: 14px; margin-bottom: 18px; }
.metric {
  background: var(--panel); border: 1px solid var(--line);
  border-radius: var(--radius); box-shadow: var(--shadow);
  padding: 14px 18px; min-width: 150px; flex: 1;
}
.metric .label { color: var(--muted); font-size: 12px; }
.metric .value { font-size: 22px; font-weight: 700; margin-top: 2px; }
.metric .delta { font-size: 12.5px; margin-top: 2px; }
.pos { color: var(--pos); } .neg { color: var(--neg); } .warn { color: var(--warn); }

/* ── tables ── */
table.grid { width: 100%; border-collapse: collapse; font-size: 13px; }
table.grid th, table.grid td {
  padding: 7px 10px; text-align: left; border-bottom: 1px solid var(--line);
  white-space: nowrap;
}
table.grid th { color: var(--muted); font-weight: 600; font-size: 12px; }
table.grid tbody tr:hover { background: #f8fafc; }
table.grid td.num, table.grid th.num { text-align: right; font-variant-numeric: tabular-nums; }
.scroll { overflow-x: auto; }

/* ── forms ── */
form.row { display: flex; flex-wrap: wrap; gap: 12px; align-items: flex-end; }
.field { display: flex; flex-direction: column; gap: 4px; }
.field label { font-size: 12px; color: var(--muted); }
input, select, button {
  font: inherit; padding: 8px 10px; border: 1px solid var(--line);
  border-radius: 8px; background: #fff; color: var(--ink);
}
input:focus, select:focus { outline: 2px solid #cfe3ff; border-color: var(--accent); }
button {
  cursor: pointer; background: var(--brand); color: #fff; border: none;
  font-weight: 600; padding: 9px 16px;
}
button:hover { background: var(--brand-ink); }
button.secondary { background: #eef1f4; color: var(--ink); }
button.secondary:hover { background: #e1e6ea; }
button.danger { background: #fdecea; color: var(--neg); }
button.danger:hover { background: #f9d7d2; }
button.link { background: none; color: var(--neg); padding: 2px 6px; font-weight: 500; }
button.link:hover { background: #fdecea; }

.tabs { display: flex; gap: 6px; border-bottom: 1px solid var(--line); margin-bottom: 16px; }
.tabs button {
  background: none; color: var(--muted); border: none; border-bottom: 2px solid transparent;
  border-radius: 0; padding: 8px 14px; font-weight: 600;
}
.tabs button.active { color: var(--brand-ink); border-bottom-color: var(--brand); }

.note { color: var(--muted); font-size: 12.5px; margin: 6px 0; }
.flash { background: #e8f5e9; color: var(--brand-ink); padding: 8px 12px;
         border-radius: 8px; font-size: 13px; margin-bottom: 12px; }
.error { background: #fdecea; color: var(--neg); padding: 8px 12px;
         border-radius: 8px; font-size: 13px; margin-bottom: 12px; }
.badge { display: inline-block; padding: 1px 8px; border-radius: 10px; font-size: 11.5px; font-weight: 600; }
.badge.buy { background: #e8f5e9; color: var(--pos); }
.badge.sell { background: #fdecea; color: var(--neg); }
.badge.watch { background: #fff4e0; color: var(--warn); }
.badge.hold { background: #eef1f4; color: var(--muted); }

.plotly-fig { width: 100%; margin: 8px 0; }
.spinner { display: none; color: var(--muted); font-size: 13px; }
.htmx-request .spinner { display: inline; }
.htmx-request.spinner { display: inline; }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 18px; }
@media (max-width: 680px) {
  .sidebar { display: none; }
  .grid-2 { grid-template-columns: 1fr; }
}
