:root {
  --bg: #f5f7fa;
  --surface: #ffffff;
  --text: #1f2937;
  --muted: #6b7280;
  --primary: #2563eb;
  --primary-hover: #1d4ed8;
  --border: #e5e7eb;
  --warn: #ef4444;
  --legal-in: #60a5fa;
  --legal-out: #f87171;
  --shadow: 0 1px 3px rgba(0, 0, 0, 0.06), 0 1px 2px rgba(0, 0, 0, 0.04);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Hiragino Sans", "Yu Gothic UI", sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.6;
}

.app-header {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 24px 32px;
}
.app-header h1 { margin: 0 0 4px; font-size: 24px; }
.subtitle { margin: 0; color: var(--muted); font-size: 14px; }

.container {
  max-width: 1280px;
  margin: 0 auto;
  padding: 32px 24px;
}

/* 労基法: アップロード前に表示する折りたたみカード */
.upload-section {
  display: flex;
  flex-direction: column;
  gap: 16px;
}
.legal-rules-card {
  background: #f0f4ff;
  border: 1px solid #c7d2fe;
  border-radius: 10px;
  box-shadow: var(--shadow);
  overflow: hidden;
  max-width: 100%;
}
.legal-rules-card__summary {
  list-style: none;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 8px 12px;
  padding: 12px 14px 12px 40px;
  cursor: pointer;
  font-size: 14px;
  line-height: 1.4;
  color: #1e1b4b;
  user-select: none;
  position: relative;
  transition: background 0.15s;
}
.legal-rules-card__summary::-webkit-details-marker {
  display: none;
}
.legal-rules-card__summary::after {
  content: "";
  position: absolute;
  left: 12px;
  top: 50%;
  width: 0;
  height: 0;
  border-style: solid;
  border-width: 5px 0 5px 7px;
  border-color: transparent transparent transparent #4338ca;
  margin-top: -5px;
  transform-origin: 40% 50%;
  transition: transform 0.2s;
}
.legal-rules-card[open] .legal-rules-card__summary::after {
  transform: rotate(90deg);
}
.legal-rules-card__summary:hover {
  background: #e0e7ff;
}
.legal-rules-card__summary:focus {
  outline: none;
}
.legal-rules-card__summary:focus-visible {
  outline: 2px solid #6366f1;
  outline-offset: 2px;
  border-radius: 4px;
}
.legal-rules-card__title {
  font-weight: 700;
  flex: 1 1 12rem;
  min-width: 0;
}
.legal-rules-card__hint {
  font-size: 12px;
  color: #6366f1;
  font-weight: 500;
  flex-shrink: 0;
}
.legal-rules-card[open] .legal-rules-card__hint {
  color: #4f46e5;
}
.legal-rules-card__body {
  padding: 0 16px 16px 16px;
  border-top: 1px solid #c7d2fe;
  background: #fff;
  font-size: 13px;
  line-height: 1.65;
  color: var(--text);
}
.legal-rules-card__disclaimer {
  margin: 12px 0 10px;
  padding: 10px 12px;
  background: #fefce8;
  border: 1px solid #fef08a;
  border-radius: 8px;
  color: #713f12;
  font-size: 12px;
}
.legal-rules-list {
  margin: 0;
  padding: 0 0 0 1.4em;
}
.legal-rules-list li {
  margin: 0 0 10px;
  padding-left: 0.15em;
}
.legal-rules-list li:last-child {
  margin-bottom: 0;
}
.legal-rules-list strong {
  color: #312e81;
  font-size: 12px;
}
.legal-rules-list li > strong:first-child {
  display: block;
  margin-bottom: 3px;
  font-size: 13px;
}
@media (min-width: 640px) {
  .legal-rules-list li > strong:first-child {
    display: inline;
    margin-bottom: 0;
    font-size: inherit;
  }
  .legal-rules-list li > strong:first-child::after {
    content: " ";
  }
}

.matrix-top {
  margin-bottom: 28px;
}
.matrix-top h2 {
  margin-bottom: 8px;
}
.matrix-top > .table-note {
  margin-bottom: 12px;
  line-height: 1.5;
}
.matrix-scroll {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  border: 1px solid var(--border);
  border-radius: 10px;
  max-width: 100%;
  padding: 10px 12px 12px;
}
.fiscal-matrix {
  /* 固定2列＋月列（文字サイズに合わせ幅調整） */
  --member-col-w: 7.5rem;
  --c45-col-w: 3.65rem;
  /* 月列は約1.5倍（~2.95rem 相当から拡大） */
  --ym-col-w: 5.25rem;
  width: max-content;
  border-collapse: separate;
  border-spacing: 0;
  font-size: 15px;
}
.fiscal-matrix th,
.fiscal-matrix td {
  white-space: nowrap;
  padding: 7px 8px;
  border-bottom: 1px solid var(--border);
}
.fiscal-matrix thead th {
  position: sticky;
  top: 0;
  z-index: 2;
  background: #1e293b;
  color: #f8fafc;
  font-size: 14px;
  font-weight: 600;
  padding: 8px 7px;
}
.fiscal-matrix .col-member {
  position: sticky;
  left: 0;
  z-index: 3;
  min-width: var(--member-col-w);
  max-width: 10.5rem;
  background: #f8fafc;
  font-weight: 600;
  text-align: left;
  box-shadow: 2px 0 4px rgba(0, 0, 0, 0.06);
}
.fiscal-matrix thead .col-member {
  z-index: 4;
  background: #1e293b;
  color: #f8fafc;
}
.fiscal-matrix .col-c45 {
  position: sticky;
  left: var(--member-col-w);
  z-index: 3;
  min-width: var(--c45-col-w);
  max-width: var(--c45-col-w);
  width: var(--c45-col-w);
  background: #fff;
  text-align: center;
  font-variant-numeric: tabular-nums;
  box-shadow: 2px 0 4px rgba(0, 0, 0, 0.06);
  padding-left: 5px;
  padding-right: 5px;
}
.fiscal-matrix thead .col-c45 {
  left: var(--member-col-w);
  z-index: 4;
  background: #1e293b;
  color: #f8fafc;
}
.fiscal-matrix .col-ym {
  min-width: var(--ym-col-w);
  max-width: var(--ym-col-w);
  width: var(--ym-col-w);
  text-align: center;
  font-family: ui-monospace, "Cascadia Mono", "Consolas", monospace;
}
.fiscal-matrix .col-ot {
  min-width: var(--ym-col-w);
  max-width: var(--ym-col-w);
  width: var(--ym-col-w);
  text-align: center;
  font-variant-numeric: tabular-nums;
  font-family: ui-monospace, "Cascadia Mono", "Consolas", monospace;
  padding: 7px 6px;
}
.fiscal-matrix .col-empty {
  color: var(--muted);
  text-align: center;
}
.fiscal-matrix .ot-txt-1 { color: #b45309; font-weight: 600; }
.fiscal-matrix .ot-txt-2 { color: #c2410c; font-weight: 700; }
.fiscal-matrix .ot-txt-3 { color: #b91c1c; font-weight: 700; }
.fiscal-matrix .c45-high {
  background: #fef3c7;
  font-weight: 800;
  color: #92400e;
}
.fiscal-matrix tr.matrix-row-45warn {
  background: #fff7ed;
}
.fiscal-matrix tr.matrix-row-45warn .col-member {
  background: #ffedd5;
}
.fiscal-matrix tr.matrix-row-45warn .col-c45 {
  background: #fed7aa;
}
.fiscal-matrix tr.matrix-row-45viol {
  background: #fef2f2;
  outline: 1px solid #fecaca;
}
.fiscal-matrix tr.matrix-row-45viol .col-c45 { background: #fee2e2; font-weight: 800; }
.fiscal-matrix .c45-6 { background: #fef3c7; }
.fiscal-matrix .c45-7 { background: #fecaca; color: #7f1d1d; font-weight: 800; }
.fiscal-matrix .ot-watch-4 { background: #7f1d1d; color: #fff; font-weight: 800; }
.fiscal-matrix .ot-watch-3 { background: #b91c1c; color: #fff; font-weight: 700; }
.fiscal-matrix .ot-watch-2 { background: #dc2626; color: #fff; font-weight: 700; }
.fiscal-matrix .ot-watch-1 { background: #f97316; color: #fff; font-weight: 700; }
.fiscal-matrix .ot-watch-0 { background: #fef3c7; color: #78350f; }
.fiscal-matrix .ot-metric {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 3px;
  white-space: nowrap;
  min-width: 0;
  max-width: 100%;
  font-variant-numeric: tabular-nums;
  font-family: ui-monospace, "Cascadia Mono", "Consolas", monospace;
}
.fiscal-matrix .watch-label {
  display: inline-block;
  font-size: 9px;
  line-height: 1.1;
  background: #431407;
  color: #fff;
  border-radius: 2px;
  padding: 1px 2px;
  flex-shrink: 0;
  vertical-align: middle;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Hiragino Sans", "Yu Gothic UI", sans-serif;
}

.dropzone {
  background: var(--surface);
  border: 2px dashed var(--border);
  border-radius: 12px;
  padding: 40px 24px;
  text-align: center;
  transition: border-color 0.15s, background 0.15s;
  box-shadow: var(--shadow);
}
.dropzone.dragover {
  border-color: var(--primary);
  background: #eff6ff;
}
.dropzone p { margin: 0 0 16px; color: var(--muted); }

.file-button {
  display: inline-block;
  background: var(--primary);
  color: #fff;
  padding: 10px 24px;
  border-radius: 8px;
  cursor: pointer;
  font-weight: 500;
  transition: background 0.15s;
}
.file-button:hover { background: var(--primary-hover); }
.file-buttons { display: flex; flex-wrap: wrap; gap: 10px; justify-content: center; }
.file-button--secondary { background: #64748b; }
.file-button--secondary:hover { background: #475569; }
.load-warning { margin-top: 12px !important; font-size: 13px; color: #9a3412; background: #ffedd5; padding: 10px 12px; border-radius: 8px; }
.load-log { margin-top: 8px !important; font-size: 11px; color: var(--muted); line-height: 1.5; text-align: left; max-width: 100%; word-break: break-all; }
.fiscal-toolbar { display: flex; flex-wrap: wrap; align-items: center; gap: 10px 16px; margin-bottom: 20px; padding: 12px 16px; background: var(--surface); border-radius: 10px; border: 1px solid var(--border); }
.fiscal-label { font-weight: 600; font-size: 14px; }
.fiscal-select { padding: 8px 12px; border-radius: 8px; border: 1px solid var(--border); min-width: 220px; }
.fiscal-hint { font-size: 12px; color: var(--muted); }
.threshold-info { font-size: 13px; color: var(--muted); margin: 0 0 20px; padding: 10px 14px; background: #f0fdf4; border: 1px solid #bbf7d0; border-radius: 8px; }
.risk-block h2 { margin-top: 0; }
.risk-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 12px; margin-top: 12px; }
.risk-card { background: var(--surface); border: 1px solid var(--border); border-radius: 10px; padding: 12px 14px; box-shadow: var(--shadow); font-size: 13px; }
.risk-card--warn { border-color: #fbbf24; background: #fffbeb; }
.risk-card--bad { border-color: #f87171; background: #fef2f2; }
.risk-card__name { font-weight: 700; margin-bottom: 8px; color: var(--text); }
.risk-card__row { display: flex; justify-content: space-between; gap: 8px; margin: 4px 0; }
.risk-card__row span { color: var(--muted); }
.risk-card__small { font-size: 12px; flex-wrap: wrap; }
.compliance-block { background: #f8fafc; }
.year-compare { margin-top: 24px; }
.year-compare-table th, .year-compare-table td { font-size: 12px; }
.table-note .lg { color: #b45309; font-weight: 600; }
.table-note .or { color: #c2410c; font-weight: 700; }
.table-note .re { color: #b91c1c; font-weight: 800; }

.hint {
  margin-top: 16px !important;
  font-size: 12px;
  color: var(--muted);
}

.file-info {
  margin-top: 12px !important;
  font-size: 13px;
  color: var(--text);
  font-weight: 500;
}

.result-section { margin-top: 32px; }

.filter-bar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px 16px;
  margin-bottom: 20px;
  padding: 14px 18px;
  background: var(--surface);
  border-radius: 10px;
  box-shadow: var(--shadow);
  border: 1px solid var(--border);
}
.filter-bar label {
  font-size: 14px;
  font-weight: 600;
  color: var(--text);
}
.filter-bar__group {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px 12px;
}
.filter-bar__group + .filter-bar__group {
  padding-left: 16px;
  border-left: 1px solid var(--border);
}
.project-select,
.member-select {
  min-width: 200px;
  padding: 8px 12px;
  font-size: 14px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: #fff;
  color: var(--text);
}
.filter-hint {
  font-size: 12px;
  color: var(--muted);
  flex: 1 1 200px;
}
.chart-sub {
  font-weight: 400;
  font-size: 14px;
  color: var(--muted);
  margin-left: 6px;
}
.table-note {
  margin: 0 0 12px;
  font-size: 13px;
  color: var(--muted);
}

.threshold-bar {
  margin-bottom: 20px;
  padding: 16px 18px;
  background: var(--surface);
  border-radius: 10px;
  box-shadow: var(--shadow);
  border: 1px solid var(--border);
}
.threshold-title {
  display: block;
  font-size: 14px;
  font-weight: 600;
  margin-bottom: 8px;
}
.threshold-inputs {
  display: flex;
  flex-wrap: wrap;
  gap: 12px 20px;
  align-items: center;
  font-size: 14px;
}
.threshold-inputs label {
  display: flex;
  align-items: center;
  gap: 6px;
}
.th-input {
  width: 72px;
  padding: 6px 8px;
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 14px;
}
.threshold-hint {
  margin: 8px 0 0;
  font-size: 12px;
  color: var(--muted);
}

.chart-pair {
  display: grid;
  grid-template-columns: 1fr;
  gap: 20px;
  margin-bottom: 8px;
}
@media (min-width: 900px) {
  .chart-pair {
    grid-template-columns: 1fr 1fr;
  }
}
.chart-canvas-wrap {
  position: relative;
  height: 300px;
}

.alerts-block {
  background: var(--surface);
  border-radius: 12px;
  padding: 20px 24px;
  margin-bottom: 24px;
  box-shadow: var(--shadow);
  border: 1px solid var(--border);
}
.alerts-block h2 {
  margin: 0 0 8px;
  font-size: 16px;
}
.alert-list {
  list-style: none;
  margin: 0;
  padding: 0;
}
.alert-list .alert-item {
  padding: 10px 12px;
  margin-bottom: 8px;
  border-radius: 8px;
  font-size: 14px;
  border-left: 4px solid #ca8a04;
  background: #fffbeb;
}
.alert-list .alert-item.ot-sev-2 {
  border-left-color: #ea580c;
  background: #fff7ed;
}
.alert-list .alert-item.ot-sev-3 {
  border-left-color: #b91c1c;
  background: #fef2f2;
}
.alert-list .alert-none {
  color: var(--muted);
  font-size: 14px;
}

tr.ot-over td.ot-cell strong { font-weight: 700; }
tr.ot-over.ot-sev-1 { background: #fffbeb; }
tr.ot-over.ot-sev-2 { background: #ffedd5; }
tr.ot-over.ot-sev-3 { background: #fee2e2; }

.summary-cards {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 16px;
  margin-bottom: 32px;
}

.card {
  background: var(--surface);
  border-radius: 12px;
  padding: 20px;
  box-shadow: var(--shadow);
  border-left: 4px solid var(--primary);
}
.card.warn { border-left-color: var(--warn); }
.card-label { font-size: 12px; color: var(--muted); margin-bottom: 6px; }
.card-value { font-size: 22px; font-weight: 600; }

.chart-wrapper, .table-wrapper {
  background: var(--surface);
  border-radius: 12px;
  padding: 24px;
  margin-bottom: 24px;
  box-shadow: var(--shadow);
}
.chart-wrapper h2, .table-wrapper h2 {
  margin: 0 0 16px;
  font-size: 16px;
  color: var(--text);
}

#monthlyChart, #chartWork, #chartOvertime { max-height: 320px; }

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 14px;
}
th, td {
  padding: 10px 12px;
  text-align: right;
  border-bottom: 1px solid var(--border);
}
th:first-child, td:first-child { text-align: left; }
/* 月次表・メンバー別合計: 残業列は中央 */
#monthlyTable th:nth-child(4),
#monthlyTable td.ot-cell,
#memberTotalsTable th:nth-child(4),
#memberTotalsTable td:nth-child(4) {
  text-align: center;
}
th {
  background: #f9fafb;
  font-weight: 600;
  color: var(--muted);
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.03em;
}
tbody tr:hover { background: #f9fafb; }

.error-section {
  margin-top: 24px;
  background: #fef2f2;
  border: 1px solid #fecaca;
  color: #991b1b;
  padding: 16px 20px;
  border-radius: 8px;
}

.app-footer {
  text-align: center;
  padding: 24px;
  color: var(--muted);
  font-size: 13px;
}
.app-footer a { color: var(--primary); text-decoration: none; }
.app-footer a:hover { text-decoration: underline; }
