:root {
  --cl-primary: #1a3a5c;
  --cl-secondary: #2e6b9e;
  --cl-accent: #3498db;
  --cl-bg: #f0f4f8;
  --cl-card: #ffffff;
  --cl-text: #2c3e50;
  --cl-text-light: #7f8c8d;
  --cl-border: #dce4ec;
  --signal-blue: #2196F3;
  --signal-green: #4CAF50;
  --signal-lightyellow: #FDD835;
  --signal-yellow: #FF9800;
  --signal-lightred: #FF7043;
  --signal-red: #F44336;
  --signal-white: #e0e0e0;
}
* { margin: 0; padding: 0; box-sizing: border-box; }
body { font-family: 'Segoe UI', 'Meiryo', 'Yu Gothic', sans-serif; background: var(--cl-bg); color: var(--cl-text); }

/* Cover Page */
.cover-page {
  min-height: 100vh; display: flex; flex-direction: column; align-items: center; justify-content: center;
  background: linear-gradient(135deg, var(--cl-primary) 0%, var(--cl-secondary) 100%);
  color: white; padding: 40px;
}
.cover-page h1 { font-size: 2.4em; margin-bottom: 8px; letter-spacing: 2px; }
.cover-page .subtitle { font-size: 1.1em; opacity: 0.85; margin-bottom: 40px; }
.month-selector {
  display: flex; align-items: center; gap: 12px; margin-bottom: 36px;
  background: rgba(255,255,255,0.12); padding: 16px 28px; border-radius: 12px;
}
.month-selector label { font-size: 1em; font-weight: 600; }
.month-selector select {
  padding: 8px 16px; border-radius: 8px; border: none; font-size: 1em;
  background: white; color: var(--cl-primary); cursor: pointer; font-weight: 600;
}
.dept-grid {
  display: grid; grid-template-columns: repeat(3, 1fr); gap: 16px; max-width: 720px; width: 100%;
}
.dept-card {
  background: rgba(255,255,255,0.12); border: 1px solid rgba(255,255,255,0.2);
  border-radius: 12px; padding: 20px 24px; text-align: center; cursor: pointer;
  transition: all 0.2s; font-size: 1.05em; font-weight: 600;
}
.dept-card:hover { background: rgba(255,255,255,0.25); transform: translateY(-2px); }
.dept-card.active { background: rgba(255,255,255,0.3); border-color: white; }
.dept-card.disabled { opacity: 0.4; cursor: not-allowed; }

/* Dashboard Page */
.dashboard-page { display: none; min-height: 100vh; padding: 0; }
.dash-header {
  background: linear-gradient(135deg, var(--cl-primary), var(--cl-secondary));
  color: white; padding: 12px 28px; display: flex; align-items: center; justify-content: space-between;
  position: sticky; top: 0; z-index: 100;
}
.dash-header h2 { font-size: 1.3em; }
.dash-header .dept-name { font-size: 1.1em; opacity: 0.9; }
.dash-header .month-badge {
  background: rgba(255,255,255,0.2); padding: 4px 14px; border-radius: 20px; font-weight: 600;
}
.back-btn {
  background: rgba(255,255,255,0.15); border: 1px solid rgba(255,255,255,0.3);
  color: white; padding: 6px 16px; border-radius: 8px; cursor: pointer; font-size: 0.9em;
}
.back-btn:hover { background: rgba(255,255,255,0.3); }

/* Dashboard Body Layout */
.dash-body { padding: 4px 10px; }
.section-title {
  font-size: 0.85em; color: var(--cl-primary);
  padding-bottom: 3px; border-bottom: 2px solid var(--cl-accent);
  display: inline-block; white-space: nowrap; margin: 0 0 4px 0;
}
.chart-row {
  display: flex; gap: 16px; margin-bottom: 19px;
}
.chart-area {
  display: grid; grid-template-columns: 1fr 1fr; gap: 4px;
  width: 50%; flex-shrink: 0;
}
.chart-side {
  flex: 1; display: flex; flex-direction: column; justify-content: space-between;
}
.ai-comment {
  background: linear-gradient(135deg, #f0f7ff, #e8f0fe); border: 1px solid #c4d9f2;
  border-radius: 6px; padding: 6px 10px; font-size: 0.72em; line-height: 1.5;
  color: var(--cl-text); flex: 1; margin-top: 4px; overflow: hidden;
}
.ai-comment .ai-label {
  font-size: 0.85em; font-weight: 700; color: var(--cl-accent); margin-bottom: 2px;
}
.kpi-grid {
  display: grid; grid-template-columns: repeat(6, minmax(0, 1fr));
  grid-template-rows: repeat(10, auto); grid-auto-flow: column; gap: 3px;
  width: 100%;
}

/* Signal toggle */
.signal-toggle { display: flex; gap: 2px; margin-left: 4px; }
.signal-toggle button {
  padding: 1px 6px; border: 1px solid var(--cl-border); border-radius: 4px;
  background: white; font-size: 0.65em; cursor: pointer; white-space: nowrap;
}
.signal-toggle button.active { background: var(--cl-accent); color: white; border-color: var(--cl-accent); }

/* Key item cards - compact */
.key-item-card {
  background: var(--cl-card); border-radius: 6px; padding: 5px 7px;
  border: 1px solid var(--cl-border);
}
.key-item-header { display: flex; align-items: center; gap: 6px; margin-bottom: 3px; }
.key-item-header .signals { display: flex; gap: 3px; }
.signal {
  width: 14px; height: 14px; border-radius: 50%; border: 1.5px solid #bbb; display: inline-block;
}
.signal.blue { background: var(--signal-blue); border-color: var(--signal-blue); }
.signal.green { background: var(--signal-green); border-color: var(--signal-green); }
.signal.lightyellow { background: var(--signal-lightyellow); border-color: var(--signal-lightyellow); }
.signal.yellow { background: var(--signal-yellow); border-color: var(--signal-yellow); }
.signal.lightred { background: var(--signal-lightred); border-color: var(--signal-lightred); }
.signal.red { background: var(--signal-red); border-color: var(--signal-red); }
.signal.white { background: var(--signal-white); border-color: #ccc; }
.signal-label { font-size: 0.5em; color: var(--cl-text-light); text-align: center; }
.key-item-name { font-weight: 700; font-size: 0.7em; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.key-item-values { display: grid; grid-template-columns: 1fr 1fr; gap: 3px; margin-bottom: 3px; }
.val-box { background: var(--cl-bg); border-radius: 4px; padding: 2px 5px; border: 1px solid var(--cl-border); }
.val-box .label { font-size: 0.55em; color: var(--cl-text-light); }
.val-box .value { font-size: 0.75em; font-weight: 700; }
.val-box .pct { font-size: 0.65em; font-weight: 600; margin-left: 2px; }
.pct.good { color: var(--signal-green); }
.pct.warn { color: var(--signal-yellow); }
.pct.bad { color: var(--signal-red); }
.chart-container { height: 118px; }

/* Signal styles */
.signal.diamond { border-radius: 2px; transform: rotate(45deg); }
.signal-summary-table { display: flex; flex-direction: column; gap: 1px; margin-left: 12px; }
.summary-row { display: flex; align-items: center; }
.summary-legend {
  display: flex; align-items: center; gap: 3px; min-width: 68px;
  font-size: 0.65em; color: var(--cl-text-light); white-space: nowrap;
}
.summary-legend .legend-circle {
  width: 9px; height: 9px; border-radius: 50%; border: 1.5px solid #999; background: #ccc; display: inline-block;
}
.summary-legend .legend-diamond {
  width: 9px; height: 9px; border-radius: 1px; border: 1.5px solid #999; background: #ccc;
  display: inline-block; transform: rotate(45deg);
}
.summary-cell {
  display: flex; align-items: center; gap: 2px; min-width: 34px;
  justify-content: center; font-weight: 600; font-size: 0.7em;
}
.summary-cell.summary-label { color: var(--cl-text-light); font-weight: 400; font-size: 0.6em; }
.summary-cell .dot { width: 10px; height: 10px; border-radius: 50%; display: inline-block; }
.summary-cell .dot.diamond { border-radius: 1px; transform: rotate(45deg); }

/* KPI items - compact */
.kpi-item {
  background: var(--cl-card); border-radius: 4px; padding: 2px 4px;
  border: 1px solid var(--cl-border); font-size: 0.62em;
  display: flex; align-items: flex-start; gap: 3px;
}
.kpi-item.is-kgi {
  background: linear-gradient(135deg, #eaf2fb, #dce8f5);
  border-color: var(--cl-accent); font-weight: 700;
}
.kpi-item .kpi-signals { display: flex; flex-direction: column; align-items: center; gap: 0; flex-shrink: 0; padding-top: 1px; }
.kpi-item .signal { width: 11px; height: 11px; }
.kpi-item .kpi-body { flex: 1; min-width: 0; }
.kpi-item .kpi-no { font-size: 0.75em; color: var(--cl-accent); font-weight: 700; margin-right: 2px; }
.kpi-item .kpi-name {
  font-size: 1.1em; line-height: 1.2; overflow: hidden;
  text-overflow: ellipsis; white-space: nowrap; display: block;
}
.kpi-item.is-kgi .kpi-name { font-size: 1.1em; white-space: nowrap; }
.kpi-item .kpi-vals {
  display: flex; flex-direction: column; gap: 2px; margin-top: 0; font-size: 0.8em; color: var(--cl-text-light);
}
.kpi-item .kpi-vals .actual { font-weight: 700; color: var(--cl-text); }
.kpi-item .kpi-vals .plan-val { color: #666; }
.kpi-item .kpi-vals .na { color: #999; font-style: italic; }

/* Loading overlay */
.loading-overlay {
  position: fixed; top: 0; left: 0; width: 100%; height: 100%;
  background: rgba(26,58,92,0.85); display: flex; flex-direction: column;
  align-items: center; justify-content: center; color: white; z-index: 9999;
  font-size: 1.3em;
}
.loading-overlay .spinner {
  width: 40px; height: 40px; border: 4px solid rgba(255,255,255,0.3);
  border-top-color: white; border-radius: 50%; animation: spin 0.8s linear infinite;
  margin-bottom: 16px;
}
@keyframes spin { to { transform: rotate(360deg); } }
