* { box-sizing: border-box; }
body {
  margin: 0;
  font-family: "Hiragino Kaku Gothic ProN", "Meiryo", "Yu Gothic", sans-serif;
  background: #f4f6f8;
  color: #263238;
  font-size: 14px;
}
.layout { display: flex; min-height: 100vh; }
.sidebar {
  width: 220px;
  background: #2f4858;
  color: #e0e6ea;
  padding: 20px 0;
  flex-shrink: 0;
}
.sidebar .brand {
  font-size: 15px;
  font-weight: bold;
  padding: 0 20px 20px;
  border-bottom: 1px solid #46606f;
  margin-bottom: 10px;
}
.sidebar a {
  display: block;
  padding: 10px 20px;
  color: #cfd8dc;
  text-decoration: none;
}
.sidebar a:hover, .sidebar a.active { background: #3f5b6c; color: #fff; }
.sidebar .user { padding: 12px 20px; font-size: 12px; color: #9fb0ba; border-top: 1px solid #46606f; margin-top: 10px; }

.main { flex: 1; padding: 28px 32px; }
h1 { font-size: 20px; margin: 0 0 18px; color: #1c313a; }
h2 { font-size: 16px; margin: 22px 0 10px; color: #1c313a; }

.card {
  background: #fff;
  border: 1px solid #e0e4e8;
  border-radius: 6px;
  padding: 20px;
  margin-bottom: 20px;
}

table { border-collapse: collapse; width: 100%; background: #fff; }
th, td {
  border: 1px solid #e0e4e8;
  padding: 8px 10px;
  text-align: left;
  font-size: 13px;
  vertical-align: top;
}
th { background: #eef2f5; color: #37474f; }
tr:nth-child(even) td { background: #fafbfc; }

.badge { display: inline-block; padding: 2px 8px; border-radius: 3px; font-size: 12px; }
.badge-ok { background: #e3f6e8; color: #1e7e34; }
.badge-warn { background: #fff4e0; color: #a65b00; }
.badge-bad { background: #fdeaea; color: #b02a2a; }

.btn {
  display: inline-block;
  background: #2f6690;
  color: #fff;
  border: none;
  padding: 9px 18px;
  border-radius: 4px;
  cursor: pointer;
  font-size: 13px;
  font-family: inherit;
  text-decoration: none;
}
.btn:hover { background: #244f70; }
.btn-secondary { background: #90a4ae; }
.btn-small { padding: 4px 10px; font-size: 12px; border-radius: 3px; }
.btn-muted { background: #b0bec5; }
.inline-form { display: inline-block; margin: 2px 4px 2px 0; }

input[type=text], input[type=password], input[type=number], textarea, select {
  padding: 8px;
  border: 1px solid #c8d0d6;
  border-radius: 4px;
  font-size: 13px;
  width: 100%;
  max-width: 420px;
}
label { display: block; margin: 12px 0 4px; font-weight: bold; font-size: 13px; }

.flash { padding: 10px 14px; border-radius: 4px; margin-bottom: 16px; font-size: 13px; }
.flash-error { background: #fdeaea; color: #b02a2a; }
.flash-success { background: #e3f6e8; color: #1e7e34; }

.login-wrap { display: flex; align-items: center; justify-content: center; height: 100vh; background: #2f4858; }
.login-box { background: #fff; padding: 36px; border-radius: 8px; width: 320px; }
.login-box h1 { text-align: center; }

.kpi-grid { display: flex; gap: 16px; flex-wrap: wrap; }
.kpi-box { background: #fff; border: 1px solid #e0e4e8; border-radius: 6px; padding: 16px 22px; min-width: 160px; }
.kpi-box .label { font-size: 12px; color: #78909c; }
.kpi-box .value { font-size: 24px; font-weight: bold; color: #1c313a; margin-top: 4px; }
.kpi-box .hint { font-size: 11px; color: #90a4ae; margin-top: 6px; line-height: 1.4; }

.kpi-grid-5 {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 12px;
}
.kpi-grid-5 .kpi-box { min-width: 0; padding: 12px 14px; }
.kpi-grid-5 .kpi-box .value { font-size: 21px; margin-top: 2px; }
.kpi-grid-5 .kpi-box .hint { margin-top: 4px; }
@media (max-width: 900px) {
  .kpi-grid-5 { grid-template-columns: repeat(3, 1fr); }
}
@media (max-width: 600px) {
  .kpi-grid-5 { grid-template-columns: repeat(2, 1fr); }
}

button.kpi-box {
  font-family: inherit;
  text-align: left;
  cursor: pointer;
  transition: border-color .15s ease, box-shadow .15s ease;
}
button.kpi-box:hover { border-color: #90a4ae; }
button.kpi-box.active {
  border-color: #2f6690;
  box-shadow: 0 0 0 1px #2f6690 inset;
}

.clear-banner {
  padding: 12px 16px;
  border-radius: 6px;
  margin-bottom: 18px;
  font-size: 13px;
  font-weight: bold;
}
.clear-banner-warn { background: #fdf2f2; color: #b02a2a; border: 1px solid #f3c8c8; }
.clear-banner-ok { background: #e3f6e8; color: #1e7e34; border: 1px solid #b7e3c2; }

/* ============ 案件一覧（Issueトラッカー風） ============ */
.issue-table { border-collapse: collapse; width: 100%; background: #fff; border: 1px solid #e0e4e8; border-radius: 6px; overflow: hidden; }
.issue-table th, .issue-table td {
  border: none;
  border-bottom: 1px solid #eef1f3;
  padding: 12px 14px;
  text-align: left;
  font-size: 13px;
  vertical-align: middle;
}
.issue-table th { background: #f7f9fa; color: #607d8b; font-size: 12px; font-weight: bold; }
.issue-table tr:last-child td { border-bottom: none; }
.issue-table tr:hover td { background: #f5f8fa; }

.case-cell { font-weight: bold; color: #1c313a; max-width: 320px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.case-cell .case-no { color: #90a4ae; font-weight: normal; font-size: 12px; margin-right: 8px; }
.case-cell .case-alt { color: #78909c; font-weight: normal; }

.state-badge, .ai-badge, .dict-badge {
  display: inline-flex; align-items: center; gap: 4px;
  padding: 3px 10px; border-radius: 12px; font-size: 12px; font-weight: bold; white-space: nowrap;
}
.state-critical { background: #fdeaea; color: #b02a2a; }
.state-warn { background: #fff4e0; color: #a65b00; }
.state-done { background: #e3f6e8; color: #1e7e34; }
.state-none { background: #eceff1; color: #607d8b; }

/* ============ 詳細スライドパネル ============ */
.detail-overlay {
  position: fixed; inset: 0; background: rgba(20,30,38,0.35);
  opacity: 0; pointer-events: none; transition: opacity .2s ease; z-index: 40;
}
.detail-overlay.open { opacity: 1; pointer-events: auto; }
.detail-panel {
  position: fixed; top: 0; right: 0; height: 100%; width: 460px; max-width: 92vw;
  background: #fff; box-shadow: -4px 0 18px rgba(20,30,38,0.18);
  transform: translateX(100%); transition: transform .25s ease; z-index: 41;
  display: flex; flex-direction: column;
}
.detail-panel.open { transform: translateX(0); }
.detail-panel-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 16px 20px; border-bottom: 1px solid #e0e4e8; flex-shrink: 0;
}
.detail-panel-header h3 { margin: 0; font-size: 15px; color: #1c313a; }
.detail-close { background: none; border: none; font-size: 22px; cursor: pointer; color: #78909c; line-height: 1; padding: 4px; }
.detail-close:hover { color: #1c313a; }
.detail-panel-body { padding: 18px 20px; overflow-y: auto; flex: 1; font-size: 13px; }
.detail-section { margin-bottom: 22px; }
.detail-section h4 {
  font-size: 11px; color: #90a4ae; text-transform: uppercase; letter-spacing: .04em;
  margin: 0 0 10px; border-bottom: 1px solid #eef2f5; padding-bottom: 6px;
}
.detail-row { display: flex; padding: 5px 0; align-items: flex-start; }
.detail-row .k { width: 120px; flex-shrink: 0; color: #78909c; }
.detail-row .v { flex: 1; }

/* AIコメント：長い場合は折りたたみ、クリックで展開 */
.ai-comment { position: relative; line-height: 1.7; }
.ai-comment.clamped {
  max-height: 4.9em;
  overflow: hidden;
}
.ai-comment.clamped::after {
  content: "";
  position: absolute;
  left: 0; right: 0; bottom: 0;
  height: 22px;
  background: linear-gradient(rgba(255,255,255,0), #fff 85%);
}
.comment-toggle-btn {
  display: none;
  margin: 4px 0 0;
  background: none;
  border: none;
  color: #2f6690;
  font-size: 12px;
  font-family: inherit;
  cursor: pointer;
  padding: 0;
}
.comment-toggle-btn:hover { text-decoration: underline; }

@media (max-width: 700px) {
  .detail-panel { width: 100vw; }
  .issue-table { display: block; overflow-x: auto; white-space: nowrap; }
}
