/* ===== リセット・基本 ===== */
* { box-sizing: border-box; }

body {
  font-family: 'Meiryo', 'MS Gothic', 'Hiragino Kaku Gothic ProN', sans-serif;
  font-size: 13px;
  background: #f5f5f5;
  margin: 0;
}

/* ===== ヘッダー ===== */
#header {
  background: #1e3a5f;
  color: white;
  padding: 8px 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  position: sticky;
  top: 0;
  z-index: 100;
  box-shadow: 0 2px 4px rgba(0,0,0,0.3);
}

#header h1 {
  font-size: 16px;
  font-weight: bold;
  margin: 0;
}

/* ===== ナビゲーション ===== */
#nav {
  background: #2d4a6b;
  padding: 0 16px;
  display: flex;
  gap: 4px;
  position: sticky;
  top: 42px;
  z-index: 99;
}

.nav-btn {
  color: #ccc;
  background: none;
  border: none;
  padding: 8px 14px;
  cursor: pointer;
  font-size: 13px;
  border-bottom: 3px solid transparent;
  transition: all 0.2s;
}

.nav-btn:hover { color: white; background: rgba(255,255,255,0.1); }
.nav-btn.active { color: white; border-bottom-color: #60a5fa; }

/* ===== メインコンテンツ ===== */
#main {
  padding: 12px;
  overflow: hidden;
}

/* ===== ログイン画面 ===== */
#login-screen {
  max-width: 420px;
  margin: 60px auto;
  background: white;
  border-radius: 12px;
  box-shadow: 0 4px 20px rgba(0,0,0,0.15);
  padding: 40px;
}

#login-screen h2 {
  text-align: center;
  font-size: 22px;
  color: #1e3a5f;
  margin-bottom: 30px;
}

.employee-select-list {
  display: grid;
  gap: 8px;
  max-height: 400px;
  overflow-y: auto;
}

.employee-select-btn {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 16px;
  border: 2px solid #e5e7eb;
  border-radius: 8px;
  background: white;
  cursor: pointer;
  transition: all 0.2s;
  text-align: left;
  width: 100%;
}

.employee-select-btn:hover {
  border-color: #3b82f6;
  background: #eff6ff;
}

.employee-avatar {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: bold;
  font-size: 14px;
  flex-shrink: 0;
}

/* ===== 出勤表 ===== */
.attendance-container {
  background: white;
  border-radius: 8px;
  box-shadow: 0 2px 8px rgba(0,0,0,0.1);
  overflow: hidden;
}

.period-nav {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 16px;
  background: #f8fafc;
  border-bottom: 1px solid #e2e8f0;
}

.period-nav h2 {
  font-size: 16px;
  font-weight: bold;
  color: #1e3a5f;
  flex: 1;
}

.period-btn {
  padding: 6px 14px;
  background: #1e3a5f;
  color: white;
  border: none;
  border-radius: 6px;
  cursor: pointer;
  font-size: 13px;
}

.period-btn:hover { background: #2d4a6b; }

/* ===== テーブルラッパー ===== */
.table-wrapper {
  overflow-x: auto;
  overflow-y: auto;
  max-height: calc(100vh - 180px);
  position: relative;
}

/* ===== 出勤表テーブル ===== */
#attendance-table {
  border-collapse: collapse;
  table-layout: fixed;
  min-width: max-content;
}

#attendance-table th,
#attendance-table td {
  border: 1px solid #d1d5db;
  padding: 2px 3px;
  text-align: center;
  white-space: nowrap;
  user-select: none;
}

/* 固定列 */
.col-sticky-name {
  position: sticky;
  left: 0;
  z-index: 20;
  background: white;
  min-width: 90px;
  max-width: 90px;
  text-align: left;
  padding-left: 6px;
}

.col-sticky-total {
  position: sticky;
  right: 0;
  z-index: 15;
  background: #f9fafb;
  min-width: 40px;
  font-weight: bold;
}

/* ヘッダー行固定 */
#attendance-table thead th {
  position: sticky;
  background: white;
  z-index: 10;
}

#attendance-table thead tr:first-child th {
  top: 0;
  z-index: 25;
}

#attendance-table thead tr:nth-child(2) th {
  top: 24px;
  z-index: 24;
}

#attendance-table thead tr:nth-child(3) th {
  top: 48px;
  z-index: 23;
}

.col-sticky-name.header-sticky {
  z-index: 30 !important;
}

/* ヘッダースタイル */
.th-date {
  min-width: 38px;
  max-width: 38px;
  font-size: 12px;
  font-weight: normal;
  height: 24px;
}

.th-weekday {
  height: 24px;
  font-size: 11px;
}

/* 日付列の色（ヘッダー用） */
.col-saturday { background: #EBF5FF; }
.col-sunday   { background: #FFF0F0; }
.col-holiday  { background: #FFE4E4; }
.col-today    { outline: 2px solid #FBBF24 !important; outline-offset: -2px; }

.weekday-sat { color: #1d4ed8 !important; }
.weekday-sun { color: #dc2626 !important; }
.weekday-hol { color: #dc2626 !important; }

/* データセル */
.attendance-cell {
  min-width: 38px;
  max-width: 38px;
  height: 28px;
  cursor: pointer;
  font-size: 11px;
  font-weight: 500;
  position: relative;
  transition: opacity 0.1s;
  overflow: hidden;
  background: #ffffff; /* デフォルト白 */
}

/* 勤務区分なし＆土日祝のセル色 */
.attendance-cell.col-saturday { background: #EBF5FF; }
.attendance-cell.col-sunday   { background: #FFF0F0; }
.attendance-cell.col-holiday  { background: #FFE4E4; }

/* 勤務区分あり（style属性が付いている）場合はインラインstyleが優先 */
/* ※ CSSの詳細度: inline style > !important なし class → 上記はそのままでOK */

.attendance-cell:hover {
  opacity: 0.85;
  box-shadow: inset 0 0 0 2px rgba(0,0,0,0.3);
}

/* 今日のセル */
.cell-today-col {
  outline: 2px solid #FBBF24;
  outline-offset: -1px;
}

/* 従業員名行 */
.employee-row td.col-sticky-name {
  font-weight: 500;
  font-size: 12px;
}

/* 集計行 */
.summary-row td {
  background: #f9fafb;
  font-size: 11px;
  color: #374151;
}

/* ===== ドロップダウン ===== */
#cell-dropdown {
  position: fixed;
  background: white;
  border: 1px solid #d1d5db;
  border-radius: 8px;
  box-shadow: 0 8px 24px rgba(0,0,0,0.2);
  z-index: 1000;
  min-width: 160px;
  padding: 6px 0;
  overflow-y: auto;
  max-height: 320px;
}

.dropdown-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 7px 12px;
  cursor: pointer;
  transition: background 0.1s;
}

.dropdown-item:hover { background: #f3f4f6; }

.dropdown-color-dot {
  width: 16px;
  height: 16px;
  border-radius: 4px;
  flex-shrink: 0;
}

.dropdown-clear {
  border-top: 1px solid #e5e7eb;
  color: #6b7280;
  font-size: 12px;
}

/* ===== ツールチップ ===== */
#tooltip {
  position: fixed;
  background: rgba(17, 24, 39, 0.9);
  color: white;
  padding: 6px 10px;
  border-radius: 6px;
  font-size: 12px;
  pointer-events: none;
  z-index: 2000;
  white-space: pre-line;
  max-width: 200px;
  line-height: 1.5;
}

/* ===== モーダル ===== */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.5);
  z-index: 500;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
}

.modal-box {
  background: white;
  border-radius: 12px;
  width: 100%;
  max-width: 600px;
  max-height: 90vh;
  overflow-y: auto;
  box-shadow: 0 20px 60px rgba(0,0,0,0.3);
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 20px;
  border-bottom: 1px solid #e5e7eb;
}

.modal-header h3 { font-size: 16px; font-weight: bold; color: #1e3a5f; margin: 0; }
.modal-close { cursor: pointer; color: #6b7280; font-size: 18px; padding: 4px; }
.modal-close:hover { color: #111; }

.modal-body { padding: 20px; }
.modal-footer { padding: 16px 20px; border-top: 1px solid #e5e7eb; display: flex; gap: 8px; justify-content: flex-end; }

/* ===== フォーム ===== */
.form-group { margin-bottom: 14px; }
.form-label { display: block; font-size: 12px; color: #374151; margin-bottom: 4px; font-weight: 500; }
.form-input, .form-select {
  width: 100%;
  padding: 8px 10px;
  border: 1px solid #d1d5db;
  border-radius: 6px;
  font-size: 13px;
  outline: none;
}
.form-input:focus, .form-select:focus { border-color: #3b82f6; box-shadow: 0 0 0 2px rgba(59,130,246,0.15); }

/* ===== ボタン ===== */
.btn { padding: 8px 16px; border-radius: 6px; border: none; cursor: pointer; font-size: 13px; font-weight: 500; }
.btn-primary { background: #1e3a5f; color: white; }
.btn-primary:hover { background: #2d4a6b; }
.btn-danger { background: #dc2626; color: white; }
.btn-danger:hover { background: #b91c1c; }
.btn-secondary { background: #6b7280; color: white; }
.btn-secondary:hover { background: #4b5563; }
.btn-sm { padding: 5px 10px; font-size: 12px; }
.btn-success { background: #16a34a; color: white; }
.btn-success:hover { background: #15803d; }

/* ===== テーブル（管理画面用）===== */
.data-table {
  width: 100%;
  border-collapse: collapse;
}

.data-table th {
  background: #f3f4f6;
  padding: 8px 10px;
  text-align: left;
  font-size: 12px;
  font-weight: 600;
  color: #374151;
  border-bottom: 2px solid #e5e7eb;
}

.data-table td {
  padding: 8px 10px;
  border-bottom: 1px solid #f3f4f6;
  font-size: 13px;
  vertical-align: middle;
}

.data-table tr:hover td { background: #fafafa; }

/* ===== カード ===== */
.card {
  background: white;
  border-radius: 8px;
  box-shadow: 0 2px 6px rgba(0,0,0,0.08);
  overflow: hidden;
  margin-bottom: 16px;
}

.card-header {
  padding: 12px 16px;
  background: #f8fafc;
  border-bottom: 1px solid #e2e8f0;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.card-header h3 { font-size: 14px; font-weight: bold; color: #1e3a5f; margin: 0; }
.card-body { padding: 16px; }

/* ===== バッジ ===== */
.badge {
  display: inline-flex;
  align-items: center;
  padding: 2px 8px;
  border-radius: 12px;
  font-size: 11px;
  font-weight: 500;
}

/* ===== 有給管理カード ===== */
.paid-leave-bar {
  height: 8px;
  border-radius: 4px;
  background: #e5e7eb;
  overflow: hidden;
}

.paid-leave-fill {
  height: 100%;
  background: #16a34a;
  border-radius: 4px;
  transition: width 0.3s;
}

/* ===== 集計テーブル ===== */
.summary-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 11px;
}

.summary-table th {
  background: #1e3a5f;
  color: white;
  padding: 6px 4px;
  text-align: center;
  white-space: nowrap;
  font-weight: 500;
  position: sticky;
  top: 0;
}

.summary-table td {
  padding: 5px 4px;
  text-align: center;
  border-bottom: 1px solid #f0f0f0;
}

.summary-table tr:hover td { background: #f9fafb; }

/* ===== カラーピッカー ===== */
.color-preview {
  width: 30px;
  height: 30px;
  border-radius: 4px;
  border: 1px solid #d1d5db;
  cursor: pointer;
  display: inline-block;
}

/* ===== スクロールバー ===== */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: #f1f1f1; }
::-webkit-scrollbar-thumb { background: #c1c1c1; border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: #a8a8a8; }

/* ===== 時間入力ドロップダウン ===== */
#time-dropdown {
  position: fixed;
  background: white;
  border: 1px solid #d1d5db;
  border-radius: 8px;
  box-shadow: 0 8px 24px rgba(0,0,0,0.2);
  z-index: 1001;
  min-width: 140px;
  padding: 6px 0;
}

.time-option {
  padding: 8px 14px;
  cursor: pointer;
  font-size: 13px;
}

.time-option:hover { background: #f3f4f6; }

/* ===== レスポンシブ ===== */
@media (max-width: 640px) {
  #header h1 { font-size: 14px; }
  .nav-btn { padding: 6px 8px; font-size: 12px; }
  #main { padding: 8px; }
  .th-date { min-width: 32px; max-width: 32px; }
  .attendance-cell { min-width: 32px; max-width: 32px; font-size: 10px; }
  .col-sticky-name { min-width: 70px; max-width: 70px; font-size: 11px; }
}

/* ===== ローディング ===== */
.loading-overlay {
  position: fixed;
  inset: 0;
  background: rgba(255,255,255,0.8);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 9999;
}

.spinner {
  width: 40px;
  height: 40px;
  border: 4px solid #e5e7eb;
  border-top-color: #1e3a5f;
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

@keyframes spin { to { transform: rotate(360deg); } }

/* ===== トースト通知 ===== */
#toast-container {
  position: fixed;
  bottom: 20px;
  right: 20px;
  z-index: 9000;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.toast {
  padding: 10px 16px;
  border-radius: 8px;
  color: white;
  font-size: 13px;
  box-shadow: 0 4px 12px rgba(0,0,0,0.2);
  animation: slideIn 0.3s ease;
  max-width: 300px;
}

.toast-success { background: #16a34a; }
.toast-error { background: #dc2626; }
.toast-info { background: #1e3a5f; }

@keyframes slideIn {
  from { transform: translateX(100%); opacity: 0; }
  to { transform: translateX(0); opacity: 1; }
}

/* ===== 集計ハイライト ===== */
.count-positive { color: #1d4ed8; font-weight: bold; }
.count-warn { color: #dc2626; font-weight: bold; }

/* ===== 変更履歴 ===== */
.history-wt-badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 4px;
  font-size: 11px;
  font-weight: 600;
  white-space: nowrap;
  border: 1px solid rgba(0,0,0,0.08);
}

.history-wt-empty {
  background: #f3f4f6;
  color: #9ca3af;
  font-weight: normal;
  border-color: #e5e7eb;
}

.history-emp-badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 10px;
  font-size: 11px;
  font-weight: 600;
  white-space: nowrap;
  border: 1px solid rgba(0,0,0,0.08);
}

/* ===== 従業員並び替え（ドラッグ&ドロップ）===== */
.emp-sort-row {
  transition: background 0.1s;
}
.emp-sort-row:hover .drag-handle {
  color: #1e3a5f !important;
}
.emp-sort-row.drag-dragging {
  opacity: 0.4;
  background: #e0e7ff;
}
.emp-sort-row.drag-over {
  background: #dbeafe;
  border-top: 2px solid #3b82f6;
  box-shadow: 0 -2px 0 #3b82f6;
}
.drag-handle {
  touch-action: none;
  user-select: none;
}

/* ===== 2ヶ月表示用クラス ===== */

/* 月ラベル行（共通） */
.month-label-th {
  color: white;
  font-size: 12px;
  font-weight: bold;
  padding: 4px 6px;
  text-align: center;
  letter-spacing: 0.02em;
}

/* 奇数月ラベル: 濃紺 */
.month-label-odd {
  background: #1e3a5f;
  border-right: 3px solid #fff;
}

/* 偶数月ラベル: 深緑 */
.month-label-even {
  background: #2d5a1e;
  border-right: 3px solid #fff;
}

/* 月ラベル行（2ヶ月目・境界左ボーダー） */
.month-label-th2 {
  border-left: 3px solid #fff;
}

/* 2ヶ月目の先頭セルに太めの左ボーダーを付けて月の区切りを示す */
.cell-month-border {
  border-left: 3px solid #1e3a5f !important;
}

/* 2つ目の合計列（1つ目の右隣に重ねて sticky） */
.col-sticky-total2 {
  position: sticky;
  right: 41px;   /* 1つ目の合計列(40px) + 1px 隙間 */
  z-index: 15;
  background: #e8f5e3;   /* 偶数月カラーに合わせた薄緑 */
  min-width: 40px;
  font-weight: bold;
  border-left: 2px solid #8fbc8f;
}

/* ===== 奇数月・偶数月の列背景色 ===== */
/* 平日セル（勤務区分なし）への淡い色敷き */
/* 奇数月: 淡いブルー系 */
.col-month-odd {
  background-color: #f0f6ff;
}
/* 偶数月: 淡いグリーン系 */
.col-month-even {
  background-color: #f0fff4;
}

/* 土曜は奇偶月に関わらず青系（既存 col-saturday より優先させない→そのまま） */
/* 日曜・祝日は赤系（既存 col-sunday/col-holiday）→既存クラスが !important なので奇偶月は適用されない */

/* 勤務区分あり（inline style）の場合は JS の style= が最優先なので奇偶月色は見えない */

/* 月境界の2つ目の名前セル（2ヶ月目先頭に挿入） */
.col-sticky-name-2nd {
  position: sticky;
  left: 0;
  z-index: 20;
  background: white;
  min-width: 90px;
  max-width: 90px;
  text-align: left;
  padding-left: 6px;
  font-weight: 500;
  font-size: 12px;
  border-left: 3px solid #1e3a5f !important;
}

/* thead 固定時の z-index 上書き（4行 thead に対応） */
#attendance-table thead tr:nth-child(4) th {
  top: 72px;
  z-index: 22;
}

/* 月ラベル行（先頭行）は top:0 を JS で inline 指定しているが、
   CSS でも念のため thead tr:first-child を優先させる */
#attendance-table thead tr:first-child th.month-label-th {
  top: 0;
  z-index: 24;
}

/* 2ヶ月目名前列ヘッダー固定 */
#attendance-table thead th.col-sticky-name-2nd {
  position: sticky;
  z-index: 25 !important;
  background: white;
}
