:root {
  --bg: #ffffff;
  --side: #f0f2f6;
  --text: #262730;
  --muted: #6b6f7b;
  --line: #e1e4ea;
  --accent: #ff4b4b;
  --bar: #4c8bf5;
  --bar2: #f5a04c;
  --contract: #b35c00;
  --bad: #c62828;
  --warn-bg: #fff8e1;
  --error-bg: #fdecea;
  --row-hover: #f5f7fb;
  --row-selected: #e6efff;
}
* { box-sizing: border-box; }
body {
  margin: 0; display: flex; min-height: 100vh; background: var(--bg); color: var(--text);
  font-family: "Segoe UI", "Hiragino Sans", "Yu Gothic UI", "Meiryo", sans-serif; font-size: 14px;
}
#sidebar { width: 300px; flex: none; background: var(--side); padding: 20px 16px; overflow-y: auto; height: 100vh; position: sticky; top: 0; }
#main { flex: 1; min-width: 0; padding: 20px 32px 60px; }
h1 { font-size: 28px; margin: 0 0 4px; }
h2 { font-size: 20px; margin: 24px 0 8px; }
h3 { font-size: 16px; margin: 16px 0 6px; }
.caption { color: var(--muted); font-size: 13px; margin: 4px 0 8px; }
a { color: #1a5fd0; }

/* 絞り込み */
.field { margin-bottom: 16px; }
.field > label, .field > .label { display: block; font-size: 13px; margin-bottom: 4px; }
.radios { display: flex; flex-wrap: wrap; gap: 4px 12px; }
.radios label, .check { display: inline-flex; align-items: center; gap: 4px; cursor: pointer; }
.check { margin-bottom: 8px; }
.multi { position: relative; }
.multi > button { width: 100%; text-align: left; padding: 6px 8px; border: 1px solid var(--line); border-radius: 6px; background: #fff; cursor: pointer; font: inherit; }
.multi .panel { display: none; position: absolute; z-index: 10; left: 0; right: 0; max-height: 320px; overflow-y: auto; background: #fff; border: 1px solid var(--line); border-radius: 6px; padding: 6px 8px; box-shadow: 0 4px 12px rgba(0,0,0,.12); }
.multi.open .panel { display: block; }
.multi .panel label { display: flex; gap: 6px; padding: 3px 0; cursor: pointer; }
.multi .panel .clear { font-size: 12px; margin-bottom: 4px; }
.chips { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 4px; }
.chip { background: var(--accent); color: #fff; border-radius: 4px; padding: 1px 6px; font-size: 12px; }

/* タブ */
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--line); margin: 12px 0 16px; flex-wrap: wrap; }
.tabs button { border: none; background: none; padding: 8px 14px; font: inherit; cursor: pointer; color: var(--muted); border-bottom: 2px solid transparent; }
.tabs button.active { color: var(--accent); border-bottom-color: var(--accent); }

/* 数値 */
.metrics { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 12px; margin: 8px 0 16px; }
.metric .label { font-size: 13px; color: var(--muted); }
.metric .value { font-size: 26px; }

/* 表 */
.table-wrap { overflow: auto; border: 1px solid var(--line); border-radius: 6px; }
table { border-collapse: collapse; width: 100%; font-size: 13px; }
th, td { padding: 4px 8px; border-bottom: 1px solid var(--line); text-align: left; white-space: nowrap; max-width: 360px; overflow: hidden; text-overflow: ellipsis; }
th { position: sticky; top: 0; background: #fafbfc; cursor: pointer; user-select: none; font-weight: 600; }
td.num { text-align: right; }
tbody tr.clickable { cursor: pointer; }
tbody tr:hover { background: var(--row-hover); }
tbody tr.selected { background: var(--row-selected); }
td.contract { color: var(--contract); }
td.bad { color: var(--bad); font-weight: bold; }
td.wrap { white-space: normal; min-width: 240px; }

/* 項目 / 内容 */
.items td:first-child { color: var(--muted); width: 220px; }
.items td { white-space: normal; max-width: none; }
.longtext { white-space: pre-wrap; margin: 0 0 12px; line-height: 1.6; }
.cols2 { display: grid; grid-template-columns: 1fr 1fr; gap: 24px; }
@media (max-width: 1000px) { .cols2 { grid-template-columns: 1fr; } }

/* 知らせ */
.warn { background: var(--warn-bg); padding: 10px 14px; border-radius: 6px; margin: 8px 0; }
.error { background: var(--error-bg); padding: 10px 14px; border-radius: 6px; margin: 8px 0; }
.info { background: #e8f1fd; padding: 10px 14px; border-radius: 6px; margin: 8px 0; }
.loading { color: var(--muted); padding: 12px 0; }

/* 入力 */
.row-fields { display: flex; flex-wrap: wrap; gap: 12px 20px; align-items: flex-end; margin-bottom: 12px; }
.row-fields .field { margin: 0; min-width: 160px; }
input[type=text], input[type=number], input[type=date] { padding: 6px 8px; border: 1px solid var(--line); border-radius: 6px; font: inherit; }
button.link, a.button, button.button { display: inline-block; padding: 6px 14px; border: 1px solid var(--line); border-radius: 6px; background: #fff; cursor: pointer; font: inherit; color: var(--text); text-decoration: none; }
button.link:hover, a.button:hover { border-color: var(--accent); color: var(--accent); }

/* グラフ */
.chart { margin: 8px 0 20px; }
.chart svg { width: 100%; height: auto; display: block; }
.chart text { font-size: 12px; fill: var(--muted); }
.legend { display: flex; gap: 16px; font-size: 12px; color: var(--muted); }
.legend span::before { content: ""; display: inline-block; width: 10px; height: 10px; margin-right: 4px; background: var(--c); }

/* ダイアログ */
dialog { width: min(1200px, 94vw); max-height: 90vh; border: none; border-radius: 10px; padding: 0 24px 24px; box-shadow: 0 10px 40px rgba(0,0,0,.25); }
dialog::backdrop { background: rgba(0,0,0,.35); }
.dialog-head { display: flex; justify-content: space-between; align-items: center; position: sticky; top: 0; background: #fff; padding-top: 12px; z-index: 2; }
.dialog-head .close { border: none; background: none; font-size: 24px; cursor: pointer; }

/* 右下のロボット（chat.js） */
.robot-btn { position: fixed; right: 20px; bottom: 20px; z-index: 50; width: 56px; height: 56px; border-radius: 50%; border: none;
  background: #1a5fd0; color: #fff; --robot-face: #1a5fd0; cursor: pointer; padding: 11px; box-shadow: 0 4px 14px rgba(0,0,0,.25); }
.robot-btn:hover, .robot-btn.open { background: #154ca6; --robot-face: #154ca6; }
.robot-btn svg { width: 100%; height: 100%; display: block; }
.chat-panel { position: fixed; right: 20px; bottom: 88px; z-index: 50; width: min(600px, calc(100vw - 32px)); height: min(680px, calc(100vh - 110px));
  display: flex; flex-direction: column; background: #fff; border: 1px solid var(--line); border-radius: 12px; box-shadow: 0 10px 40px rgba(0,0,0,.2); }
.chat-panel[hidden] { display: none; }
.chat-head { display: flex; justify-content: space-between; align-items: center; padding: 10px 14px; border-bottom: 1px solid var(--line); }
.chat-head-buttons { display: flex; gap: 8px; align-items: center; }
.chat-head .link { padding: 3px 10px; font-size: 13px; }
.chat-head .close { border: none; background: none; font-size: 22px; cursor: pointer; line-height: 1; }
.chat-log { flex: 1; overflow-y: auto; padding: 12px 14px; display: flex; flex-direction: column; gap: 8px; }
.chat-msg { padding: 8px 12px; border-radius: 10px; line-height: 1.6; overflow-wrap: anywhere; }
.chat-msg p { margin: 0 0 6px; }
.chat-msg p:last-child { margin-bottom: 0; }
.chat-msg ul, .chat-msg ol { margin: 4px 0 6px; padding-left: 20px; }
.chat-msg.user { align-self: flex-end; max-width: 85%; background: var(--row-selected); white-space: pre-wrap; }
.chat-msg.bot { align-self: stretch; background: var(--side); }
.chat-msg pre, .chat-tool pre { white-space: pre-wrap; background: #fff; border: 1px solid var(--line); border-radius: 6px; padding: 6px 8px; font-size: 12px; margin: 4px 0; }
.chat-msg code { background: #fff; padding: 0 3px; border-radius: 3px; }
.chat-heading { font-weight: 600; }
.chat-table { overflow-x: auto; margin: 4px 0 8px; background: #fff; border: 1px solid var(--line); border-radius: 6px; }
.chat-table th, .chat-table td { max-width: 220px; font-size: 12px; }
.chat-table th { cursor: default; }
.chat-tool { color: var(--muted); font-size: 12px; }
.chat-tool summary { cursor: pointer; }
.chat-busy { color: var(--muted); font-size: 13px; animation: chat-blink 1.2s infinite; }
@keyframes chat-blink { 50% { opacity: .4; } }
.chat-example { display: block; width: 100%; text-align: left; margin: 4px 0; padding: 6px 10px; border: 1px solid var(--line); border-radius: 8px; background: #fff; cursor: pointer; font: inherit; }
.chat-example:hover { border-color: #1a5fd0; color: #1a5fd0; }
.chat-input { display: flex; gap: 8px; padding: 10px 12px; border-top: 1px solid var(--line); align-items: flex-end; }
.chat-input textarea { flex: 1; resize: none; padding: 6px 8px; border: 1px solid var(--line); border-radius: 6px; font: inherit; max-height: 160px; }
.button.primary { background: #1a5fd0; border-color: #1a5fd0; color: #fff; }
.button.primary:hover { background: #154ca6; color: #fff; }

/* ログイン画面など */
.notice { max-width: 640px; margin: 80px auto; padding: 0 20px; }

@media (max-width: 800px) {
  body { display: block; }
  #sidebar { width: auto; height: auto; position: static; }
  #main { padding: 16px; }
  .chat-panel { right: 16px; bottom: 84px; }
  .robot-btn { right: 16px; bottom: 16px; }
}
