:root {
  --primary: #7b1a2e;
  --primary-dark: #5a0f1f;
  --primary-light: #a83250;
  --secondary: #64748b;
  --success: #16a34a;
  --warning: #d97706;
  --danger: #dc2626;
  --bg: #f1f5f9;
  --card-bg: #ffffff;
  --text: #1e293b;
  --text-muted: #64748b;
  --border: #e2e8f0;
  --shadow: 0 1px 3px rgba(0,0,0,0.12), 0 1px 2px rgba(0,0,0,0.08);
  --shadow-md: 0 4px 6px rgba(0,0,0,0.1), 0 2px 4px rgba(0,0,0,0.06);
  --radius: 12px;
  --radius-sm: 8px;
  --series-actual: #7b1a2e;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Hiragino Kaku Gothic ProN', 'Yu Gothic', sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
}
a { color: inherit; }
button { font-family: inherit; }

/* ---------- ログイン画面 ---------- */
.login-screen {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(160deg, #3d0b17 0%, #7b1a2e 45%, #5a0f1f 100%);
  padding: 24px;
}
.login-card {
  width: 100%;
  max-width: 380px;
  background: #fff;
  border-radius: 18px;
  border-top: 4px solid var(--primary);
  box-shadow: var(--shadow-md);
  padding: 36px 30px;
}
.login-card .logo-row { display: flex; justify-content: center; margin-bottom: 18px; }
.login-card .logo-row img { height: 48px; filter: drop-shadow(0 2px 4px rgba(0,0,0,.15)); }
.login-card h1 {
  text-align: center;
  font-size: 17px;
  font-weight: 900;
  letter-spacing: 0.10em;
  margin: 0 0 24px;
  color: var(--primary-dark);
}
.login-card .field { margin-bottom: 16px; }
.login-card label { display: block; font-size: 12px; font-weight: 700; color: var(--text-muted); margin-bottom: 6px; }
.login-card .error-msg { color: var(--danger); font-size: 12.5px; margin: -8px 0 14px; min-height: 1em; }

/* ---------- フォーム部品 ---------- */
.form-control {
  width: 100%;
  border: 2px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 10px 12px;
  font-size: 14px;
  background: #f8fafc;
  transition: border-color .15s, background .15s;
}
.form-control:focus { outline: none; border-color: var(--primary); background: #fff; }
select.form-control {
  appearance: none;
  background-image: url("data:image/svg+xml;charset=UTF-8,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 20 20'%3E%3Cpath fill='%2364748b' d='M5.5 7.5l4.5 4.5 4.5-4.5z'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 10px center;
  padding-right: 32px;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  border: none;
  border-radius: var(--radius-sm);
  min-height: 40px;
  padding: 9px 18px;
  font-size: 14px;
  font-weight: 700;
  cursor: pointer;
  transition: transform .1s, box-shadow .15s;
}
.btn:active { transform: scale(0.97); }
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-dark); }
.btn-secondary { background: #fff; color: var(--text); border: 1px solid var(--border); }
.btn-secondary:hover { background: #f8fafc; }
.btn-block { width: 100%; }

/* ---------- ヘッダー・ナビ ---------- */
.app-header {
  background: linear-gradient(135deg, var(--primary-dark) 0%, var(--primary) 100%);
  color: #fff;
  padding: 0 20px;
  height: 56px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  position: sticky;
  top: 0;
  z-index: 20;
}
.app-header .brand { display: flex; align-items: center; gap: 10px; font-weight: 900; font-size: 15px; }
.app-header .brand img { height: 28px; }
.app-header .user-menu { display: flex; align-items: center; gap: 14px; font-size: 13px; }
.app-header .user-menu button { background: rgba(255,255,255,.15); color: #fff; border: none; border-radius: 999px; padding: 6px 14px; font-size: 12.5px; font-weight: 700; cursor: pointer; }
.app-header .user-menu button:hover { background: rgba(255,255,255,.28); }

.tab-nav {
  display: flex;
  gap: 4px;
  background: #fff;
  border-bottom: 1px solid var(--border);
  padding: 0 16px;
  overflow-x: auto;
}
.tab-nav a {
  display: block;
  padding: 12px 16px;
  font-size: 13.5px;
  font-weight: 700;
  color: var(--text-muted);
  text-decoration: none;
  border-bottom: 3px solid transparent;
  white-space: nowrap;
}
.tab-nav a.active { color: var(--primary); border-bottom-color: var(--primary); }

main.container { max-width: 1180px; margin: 0 auto; padding: 22px 16px 60px; }

/* ---------- カード ---------- */
.card { background: var(--card-bg); border-radius: var(--radius); box-shadow: var(--shadow); padding: 20px; margin-bottom: 20px; }
.card h2 { font-size: 15px; font-weight: 900; margin: 0 0 16px; }
.card-row { display: flex; gap: 20px; flex-wrap: wrap; }
.card-row > .card { flex: 1 1 320px; margin-bottom: 0; }

/* ---------- KPIタイル ---------- */
.kpi-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 14px; margin-bottom: 20px; }
.kpi-tile { background: var(--card-bg); border-radius: var(--radius); box-shadow: var(--shadow); padding: 16px 18px; }
.kpi-tile .kpi-label { font-size: 12px; color: var(--text-muted); font-weight: 700; margin-bottom: 6px; }
.kpi-tile .kpi-value { font-size: 24px; font-weight: 900; color: var(--text); line-height: 1.2; }
.kpi-tile .kpi-value small { font-size: 13px; font-weight: 700; color: var(--text-muted); margin-left: 2px; }
.kpi-tile .kpi-sub { font-size: 11.5px; color: var(--text-muted); margin-top: 4px; }

/* ---------- 検索フォーム ---------- */
.filter-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 12px; margin-bottom: 14px; }
.filter-grid .field label { display: block; font-size: 11.5px; font-weight: 700; color: var(--text-muted); margin-bottom: 4px; }
.filter-actions { display: flex; gap: 10px; justify-content: flex-end; }

/* ---------- テーブル ---------- */
.data-table-wrap { overflow-x: auto; }
table.data-table { width: 100%; border-collapse: collapse; font-size: 13px; }
table.data-table th, table.data-table td { padding: 9px 10px; border-bottom: 1px solid var(--border); text-align: left; white-space: nowrap; }
table.data-table th { color: var(--text-muted); font-weight: 700; font-size: 12px; }
table.data-table tbody tr:hover { background: #f8fafc; }
table.data-table td.num { text-align: right; font-variant-numeric: tabular-nums; }

.badge { display: inline-block; padding: 3px 9px; border-radius: 999px; font-size: 11px; font-weight: 700; }
.badge-success { background: #dcfce7; color: #166534; }
.badge-warning { background: #fef3c7; color: #92400e; }
.badge-muted { background: #e2e8f0; color: var(--text-muted); }

.pagination { display: flex; align-items: center; justify-content: center; gap: 14px; margin-top: 16px; font-size: 13px; }

.empty-state { text-align: center; color: var(--text-muted); padding: 40px 10px; font-size: 13.5px; }
.loading-state { text-align: center; color: var(--text-muted); padding: 40px 10px; font-size: 13.5px; }
.error-banner { background: #fef2f2; color: var(--danger); border: 1px solid #fecaca; border-radius: var(--radius-sm); padding: 12px 16px; font-size: 13px; margin-bottom: 16px; }

/* ---------- チャート ---------- */
.chart-wrap { position: relative; }
.chart-wrap svg { width: 100%; height: auto; display: block; overflow: visible; }
.chart-tooltip {
  position: absolute;
  pointer-events: none;
  background: #1e293b;
  color: #fff;
  font-size: 12px;
  padding: 6px 10px;
  border-radius: 6px;
  box-shadow: var(--shadow-md);
  transform: translate(-50%, -110%);
  white-space: nowrap;
  opacity: 0;
  transition: opacity .1s;
  z-index: 10;
}
.chart-tooltip.visible { opacity: 1; }
.chart-axis-label { font-size: 10.5px; fill: var(--text-muted); }
.chart-line { fill: none; stroke: var(--series-actual); stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.chart-dot { fill: var(--series-actual); }
.chart-bar { fill: var(--series-actual); }
.chart-bar-track { fill: #f1f5f9; }

@media (max-width: 640px) {
  main.container { padding: 16px 10px 60px; }
  .card { padding: 16px; }
  table.data-table th, table.data-table td { padding: 8px 6px; }
}
