/* カスハラ対策システム */
:root {
  --bg: #f4f5f7;
  --surface: #ffffff;
  --ink: #1d2433;
  --ink-2: #4a5468;
  --muted: #7a8396;
  --line: #e3e6ec;
  --line-2: #eef0f4;
  --primary: #2b4c7e;
  --primary-ink: #ffffff;
  --primary-soft: #e8eef8;
  --side: #1b2638;
  --side-ink: #c5cddc;
  --ok: #1f8a5b;
  --warn: #b7791f;
  --danger: #c0392b;
  --lv-none: #9aa3b2;
  --lv-low: #d9b341;
  --lv-medium: #e67e22;
  --lv-high: #d64532;
  --lv-critical: #8e1b4a;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(20, 30, 50, 0.06), 0 1px 1px rgba(20, 30, 50, 0.04);
  --font: "Hiragino Sans", "Hiragino Kaku Gothic ProN", "Noto Sans JP", "Yu Gothic UI", Meiryo, system-ui, sans-serif;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; font-family: var(--font); font-size: 14px; line-height: 1.6; color: var(--ink); background: var(--bg); }
a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }
h1 { font-size: 22px; margin: 0 0 2px; line-height: 1.35; }
h2 { font-size: 15px; margin: 0 0 12px; }
h3 { font-size: 13px; margin: 16px 0 8px; color: var(--ink-2); }
p { margin: 0 0 10px; }
small, .small { font-size: 12px; }
.muted { color: var(--muted); }
.text-danger { color: var(--danger); }
.nowrap { white-space: nowrap; }
.num { text-align: right; font-variant-numeric: tabular-nums; }
code, .mono { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; }

/* ---------- layout ---------- */
.layout { display: flex; min-height: 100vh; }
.sidebar { width: 232px; flex-shrink: 0; background: var(--side); color: var(--side-ink); display: flex; flex-direction: column; position: sticky; top: 0; height: 100vh; }
.brand { display: flex; align-items: center; gap: 10px; padding: 18px 18px 16px; color: #fff; }
.brand:hover { text-decoration: none; }
.brand-mark { width: 32px; height: 32px; border-radius: 8px; background: linear-gradient(135deg, #e0564a, #b02a5a); display: grid; place-items: center; color: #fff; flex-shrink: 0; }
.brand-text { font-weight: 700; font-size: 15px; line-height: 1.25; }
.brand-text small { display: block; font-weight: 400; font-size: 11px; color: var(--side-ink); }
.side-nav { flex: 1; padding: 6px 10px; display: flex; flex-direction: column; gap: 2px; overflow-y: auto; }
.side-link { display: flex; align-items: center; gap: 10px; padding: 9px 12px; border-radius: 8px; color: var(--side-ink); font-size: 14px; }
.side-link:hover { background: rgba(255, 255, 255, 0.06); color: #fff; text-decoration: none; }
.side-link.active { background: rgba(255, 255, 255, 0.12); color: #fff; font-weight: 600; }
.sidebar-foot { padding: 12px; border-top: 1px solid rgba(255, 255, 255, 0.08); display: flex; flex-direction: column; gap: 8px; }
.admin-chip { display: flex; align-items: center; gap: 10px; color: #fff; padding: 4px; border-radius: 8px; }
.admin-chip:hover { background: rgba(255, 255, 255, 0.06); text-decoration: none; }
.avatar { width: 30px; height: 30px; border-radius: 50%; background: #3d5277; display: grid; place-items: center; font-weight: 700; font-size: 13px; }
.admin-name { font-size: 13px; line-height: 1.3; }
.admin-name small { display: block; color: var(--side-ink); font-size: 11px; }
.sidebar .btn-ghost { color: var(--side-ink); border-color: rgba(255, 255, 255, 0.15); }
.content { flex: 1; min-width: 0; padding: 26px 32px 60px; max-width: 1440px; }
.menu-toggle { display: none; }

/* ---------- common parts ---------- */
.page-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; margin-bottom: 20px; flex-wrap: wrap; }
.crumb { font-size: 12px; color: var(--muted); margin-bottom: 4px; }
.subject-title { word-break: break-word; }
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); padding: 18px 20px; margin-bottom: 18px; }
.card.narrow { max-width: 560px; }
.card-head { display: flex; justify-content: space-between; align-items: center; gap: 12px; margin-bottom: 12px; flex-wrap: wrap; }
.card-head h2 { margin: 0; }
.table-card { padding: 0; overflow: hidden; }
.table-card .empty { padding: 30px; }
.grid-2 { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 0 18px; }
.span-2 { grid-column: span 2; }
.empty { color: var(--muted); text-align: center; padding: 18px 0; margin: 0; }
.btn-row { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.stack { display: flex; flex-direction: column; gap: 12px; }
.stack-sm { display: flex; flex-direction: column; gap: 6px; margin-bottom: 6px; }
.inline-form { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; margin-bottom: 10px; }
.inline-form input[type="text"], .inline-form input[type="email"], .inline-form input[type="search"] { flex: 1; min-width: 160px; }

/* ---------- buttons & forms ---------- */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; padding: 8px 14px; border-radius: 8px; border: 1px solid var(--line); background: var(--surface); color: var(--ink); font: inherit; font-size: 13px; font-weight: 600; cursor: pointer; white-space: nowrap; line-height: 1.4; }
.btn:hover { background: #f7f8fa; text-decoration: none; }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn-primary { background: var(--primary); border-color: var(--primary); color: var(--primary-ink); }
.btn-primary:hover { background: #22406b; }
.btn-ghost { background: transparent; }
.btn-small { padding: 5px 10px; font-size: 12px; }
.btn-block { width: 100%; }
.btn-danger-outline { color: var(--danger); border-color: #efc2bd; }
.btn-danger-outline:hover { background: #fdf2f1; }
input[type="text"], input[type="email"], input[type="password"], input[type="search"], input[type="number"], input[type="date"], select, textarea {
  font: inherit; font-size: 14px; color: var(--ink); background: #fff; border: 1px solid #d3d8e0; border-radius: 8px; padding: 8px 10px; width: 100%; max-width: 100%;
}
input:focus, select:focus, textarea:focus { outline: 2px solid rgba(43, 76, 126, 0.25); border-color: var(--primary); }
textarea { resize: vertical; line-height: 1.6; }
.field { display: flex; flex-direction: column; gap: 5px; }
.field > span { font-size: 12px; font-weight: 600; color: var(--ink-2); }
fieldset { border: 0; padding: 0; margin: 0; }
.form-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 14px; margin-bottom: 16px; }
.form-grid .span-2 { grid-column: span 2; }
.checks { display: flex; flex-direction: column; gap: 8px; margin: 4px 0 18px; }
.checks label { display: flex; gap: 8px; align-items: flex-start; }
.checks input { margin-top: 4px; }
.warn-check { color: var(--warn); font-weight: 600; }

/* ---------- flash / pills / badges ---------- */
.flash { padding: 10px 14px; border-radius: 8px; margin-bottom: 16px; font-size: 13px; }
.flash-success { background: #e8f6ef; color: #17633f; border: 1px solid #bfe5d1; }
.flash-error { background: #fdf0ee; color: #9b2c20; border: 1px solid #f3c7c1; }
.notice { background: var(--primary-soft); color: var(--primary); border-radius: 8px; padding: 8px 12px; font-size: 13px; }
.pill { display: inline-block; padding: 1px 9px; border-radius: 999px; font-size: 11px; font-weight: 600; background: #eef0f4; color: var(--ink-2); vertical-align: middle; }
.pill-ok { background: #e3f4ec; color: var(--ok); }
.pill-warn { background: #fbf1df; color: var(--warn); }
.pill-danger { background: #fbe7e4; color: var(--danger); }
.badge { display: inline-block; min-width: 64px; text-align: center; padding: 2px 8px; border-radius: 6px; font-size: 11px; font-weight: 700; color: #fff; vertical-align: middle; }
.badge.lv-none { background: var(--lv-none); }
.badge.lv-low { background: var(--lv-low); color: #3d300a; }
.badge.lv-medium { background: var(--lv-medium); }
.badge.lv-high { background: var(--lv-high); }
.badge.lv-critical { background: var(--lv-critical); }
.status { display: inline-block; padding: 1px 8px; border-radius: 999px; font-size: 11px; font-weight: 600; border: 1px solid; vertical-align: middle; }
.st-new { color: var(--danger); border-color: #f0bdb7; background: #fdf3f2; }
.st-in_progress { color: var(--primary); border-color: #c4d2e8; background: var(--primary-soft); }
.st-escalated { color: #7a3fb0; border-color: #dcc8ef; background: #f6f0fc; }
.st-resolved { color: var(--ok); border-color: #bfe0cf; background: #eef8f3; }
.st-false_positive { color: var(--muted); border-color: var(--line); background: #f6f7f9; }
.tags { display: flex; flex-wrap: wrap; gap: 4px; margin: 4px 0 0; }
.tag { font-size: 11px; padding: 0 7px; border-radius: 4px; background: #f1f3f6; color: var(--ink-2); }
.tag-strong { background: #fbe9e7; color: #a33224; font-weight: 600; font-size: 12px; padding: 2px 8px; }

/* ---------- dashboard ---------- */
.setup-card { border-left: 4px solid var(--warn); }
.checklist { list-style: none; padding: 0; margin: 0; display: flex; flex-direction: column; gap: 6px; }
.checklist li::before { content: "○"; color: var(--warn); margin-right: 8px; font-weight: 700; }
.checklist li.done::before { content: "✓"; color: var(--ok); }
.kpis { display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 14px; margin-bottom: 18px; }
.kpi { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); padding: 14px 16px; display: flex; flex-direction: column; color: var(--ink); }
a.kpi:hover { text-decoration: none; border-color: #c9d2e0; }
.kpi-label { font-size: 12px; color: var(--muted); font-weight: 600; }
.kpi-value { font-size: 30px; font-weight: 700; line-height: 1.2; margin: 4px 0 2px; font-variant-numeric: tabular-nums; }
.kpi-value small { font-size: 16px; margin-left: 2px; }
.kpi-sub { font-size: 12px; color: var(--muted); }
.kpi-alert { border-left: 4px solid var(--danger); }
.kpi-alert .kpi-value { color: var(--danger); }
.legend { display: flex; gap: 12px; font-size: 12px; color: var(--muted); flex-wrap: wrap; }
.lv-dot { display: inline-block; width: 10px; height: 10px; border-radius: 2px; margin-right: 4px; vertical-align: -1px; }
.lv-dot.lv-low, .seg.lv-low { background: var(--lv-low); }
.lv-dot.lv-medium, .seg.lv-medium { background: var(--lv-medium); }
.lv-dot.lv-high, .seg.lv-high { background: var(--lv-high); }
.lv-dot.lv-critical, .seg.lv-critical { background: var(--lv-critical); }
.barchart { display: flex; align-items: stretch; gap: 3px; height: 180px; padding-bottom: 20px; border-bottom: 1px solid var(--line); position: relative; }
.bar-col { flex: 1; display: flex; flex-direction: column; justify-content: flex-end; align-items: center; position: relative; min-width: 0; }
.bar-col:hover { background: var(--line-2); border-radius: 4px 4px 0 0; }
.bar-stack { width: 70%; max-width: 22px; display: flex; flex-direction: column; border-radius: 3px 3px 0 0; overflow: hidden; min-height: 0; }
.seg { display: block; min-height: 2px; }
.bar-label { position: absolute; bottom: -20px; font-size: 10px; color: var(--muted); white-space: nowrap; }
.chart-foot { font-size: 11px; margin: 6px 0 0; }
.inc-list { list-style: none; padding: 0; margin: 0; }
.inc-list li a { display: flex; gap: 10px; align-items: center; padding: 9px 4px; border-bottom: 1px solid var(--line-2); color: var(--ink); }
.inc-list li:last-child a { border-bottom: 0; }
.inc-list li a:hover { background: #fafbfc; text-decoration: none; }
.inc-main { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.inc-main strong { font-size: 13px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.inc-main small { color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.hbars { list-style: none; padding: 0; margin: 0; display: flex; flex-direction: column; gap: 8px; }
.hbars li { display: grid; grid-template-columns: 170px 1fr 34px; gap: 10px; align-items: center; font-size: 13px; }
.hbar-label { color: var(--ink); }
.hbar { height: 10px; background: var(--line-2); border-radius: 5px; overflow: hidden; }
.hbar span { display: block; height: 100%; background: linear-gradient(90deg, #e67e22, #d64532); border-radius: 5px; }
.hbar-num { text-align: right; font-weight: 600; font-variant-numeric: tabular-nums; }

/* ---------- tables ---------- */
.table-scroll { overflow-x: auto; }
.table { width: 100%; border-collapse: collapse; font-size: 13px; }
.table th { text-align: left; font-size: 11px; font-weight: 700; color: var(--muted); padding: 10px 12px; background: #fafbfc; border-bottom: 1px solid var(--line); white-space: nowrap; }
.table td { padding: 10px 12px; border-bottom: 1px solid var(--line-2); vertical-align: top; }
.table tr:last-child td { border-bottom: 0; }
.table.compact th, .table.compact td { padding: 7px 8px; }
.card .table.compact th { background: transparent; }
.row-link { cursor: pointer; }
.row-link:hover td { background: #fafbfd; }
.row-link.is-new td:first-child { box-shadow: inset 3px 0 0 var(--danger); }
.is-disabled td { color: var(--muted); background: #fbfbfc; }
.chk { width: 32px; }
.subject-cell { min-width: 280px; max-width: 520px; }
.subject-cell strong { display: block; }
.subject-cell small { display: block; color: var(--ink-2); overflow: hidden; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; }
.bulk-bar { display: flex; gap: 8px; align-items: center; padding: 10px 12px; border-top: 1px solid var(--line); background: #fafbfc; }
.bulk-bar select { width: auto; }
.pager { display: flex; justify-content: center; gap: 12px; align-items: center; }

/* ---------- incidents list ---------- */
.tabs { display: flex; gap: 2px; border-bottom: 1px solid var(--line); margin-bottom: 14px; overflow-x: auto; }
.tab { padding: 8px 14px; color: var(--ink-2); border-bottom: 2px solid transparent; white-space: nowrap; font-weight: 600; font-size: 13px; }
.tab:hover { text-decoration: none; color: var(--ink); }
.tab.active { color: var(--primary); border-bottom-color: var(--primary); }
.filters { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 10px 14px; align-items: end; }
.filters label { display: flex; flex-direction: column; gap: 4px; }
.filters label > span { font-size: 11px; font-weight: 700; color: var(--muted); }
.range { display: flex; gap: 4px; align-items: center; }
.filter-actions { display: flex; gap: 6px; }

/* ---------- incident detail ---------- */
.detail-grid { display: grid; grid-template-columns: minmax(0, 1fr) 340px; gap: 18px; align-items: start; }
.detail-side { position: sticky; top: 16px; }
.ai-card { border-left: 5px solid var(--lv-none); }
.lv-border-low { border-left: 5px solid var(--lv-low) !important; }
.lv-border-medium { border-left: 5px solid var(--lv-medium) !important; }
.lv-border-high { border-left: 5px solid var(--lv-high) !important; }
.lv-border-critical { border-left: 5px solid var(--lv-critical) !important; }
.lv-border-none { border-left: 5px solid var(--lv-none) !important; }
.ai-summary { font-size: 15px; font-weight: 600; }
.ai-dl { display: grid; grid-template-columns: 130px 1fr; gap: 10px 14px; margin: 14px 0 0; }
.ai-dl dt { font-size: 12px; font-weight: 700; color: var(--muted); }
.ai-dl dd { margin: 0; }
blockquote { margin: 0 0 6px; padding: 6px 10px; background: #fdf4f2; border-left: 3px solid var(--lv-high); border-radius: 0 6px 6px 0; font-size: 13px; }
.mail-meta { display: grid; grid-template-columns: 80px 1fr; gap: 4px 12px; font-size: 13px; margin: 0 0 14px; }
.mail-meta dt { color: var(--muted); }
.mail-meta dd { margin: 0; word-break: break-all; }
.mail-body { white-space: pre-wrap; word-break: break-word; font-family: var(--font); font-size: 14px; line-height: 1.8; background: #fafbfc; border: 1px solid var(--line-2); border-radius: 8px; padding: 16px; margin: 0; max-height: 640px; overflow: auto; }
.timeline { list-style: none; padding: 0; margin: 0; }
.timeline li { position: relative; padding: 0 0 14px 18px; border-left: 2px solid var(--line); margin-left: 6px; }
.timeline li::before { content: ""; position: absolute; left: -6px; top: 4px; width: 10px; height: 10px; border-radius: 50%; background: var(--line); }
.timeline li.tl-note::before { background: var(--primary); }
.timeline li.tl-system::before { background: var(--warn); }
.tl-head { display: flex; gap: 10px; font-size: 12px; }
.tl-body { white-space: pre-wrap; font-size: 13px; }
.tl-note .tl-body { background: #f7f9fc; border-radius: 6px; padding: 6px 10px; margin-top: 4px; }
.mini-list { list-style: none; padding: 0; margin: 0; font-size: 12px; }
.mini-list li { padding: 6px 0; border-bottom: 1px solid var(--line-2); display: flex; flex-direction: column; }
.mini-list .badge { min-width: 0; font-size: 10px; }

/* ---------- settings ---------- */
.kv { display: grid; grid-template-columns: 130px 1fr; gap: 8px 12px; margin: 0 0 12px; font-size: 13px; }
.kv dt { color: var(--muted); font-weight: 600; }
.kv dd { margin: 0; }
.test-result { margin-top: 14px; padding: 12px 14px; background: #fafbfc; border-radius: 8px; border: 1px solid var(--line); }
.issued-card { border-left: 4px solid var(--ok); }
.secret { font-size: 16px; background: #f1f3f6; padding: 3px 8px; border-radius: 6px; user-select: all; }
.rules-text { white-space: pre-wrap; font-family: var(--font); font-size: 14px; line-height: 1.9; margin: 0; }
details summary { cursor: pointer; margin-bottom: 0; }
details[open] summary { margin-bottom: 12px; }

/* ---------- plain pages ---------- */
body.plain { display: grid; place-items: center; min-height: 100vh; padding: 16px; background: linear-gradient(160deg, #1b2638, #2b4c7e); }
.plain-box { background: #fff; border-radius: 14px; padding: 32px; width: 100%; max-width: 400px; box-shadow: 0 20px 50px rgba(0, 0, 0, 0.25); }
.login-box { display: flex; flex-direction: column; gap: 14px; }
.login-brand { display: flex; align-items: center; gap: 12px; margin-bottom: 6px; }
.login-brand strong { display: block; font-size: 17px; }
.login-brand small { color: var(--muted); }

/* ---------- responsive ---------- */
@media (max-width: 1200px) {
  .kpis { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .filters, .form-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (max-width: 960px) {
  .grid-2, .detail-grid { grid-template-columns: minmax(0, 1fr); }
  .span-2, .form-grid .span-2 { grid-column: auto; }
  .detail-side { position: static; }
}
@media (max-width: 760px) {
  .sidebar { position: fixed; left: 0; top: 0; z-index: 30; transform: translateX(-100%); transition: transform 0.2s; }
  body.sidebar-open .sidebar { transform: none; box-shadow: 0 0 40px rgba(0, 0, 0, 0.4); }
  .menu-toggle { display: inline-flex; background: none; border: 0; padding: 4px; margin: -6px 0 8px -4px; color: var(--ink); cursor: pointer; }
  .content { padding: 16px 16px 48px; }
  .kpis { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .filters, .form-grid { grid-template-columns: minmax(0, 1fr); }
  .hbars li { grid-template-columns: 120px 1fr 28px; }
  .ai-dl { grid-template-columns: minmax(0, 1fr); gap: 4px; }
  .ai-dl dd { margin-bottom: 8px; }
  h1 { font-size: 19px; }
}
@media print {
  .sidebar, .menu-toggle, .no-print, .page-head .btn { display: none !important; }
  body { background: #fff; }
  .content { padding: 0; }
  .card { box-shadow: none; border: 0; }
}
