:root {
  --primary: #1a5fa8;
  --primary-dark: #144a84;
  --accent: #e8f0fe;
  --border: #d0d7de;
  --bg: #f6f8fa;
  --white: #ffffff;
  --text: #1f2328;
  --text-muted: #636c76;
  --sat: #d0e4ff;
  --sun: #ffd0d0;
  --radius: 6px;
  --shadow: 0 1px 3px rgba(0,0,0,.1);
}

* { box-sizing: border-box; margin: 0; padding: 0; }

body {
  font-family: "メイリオ", Meiryo, "Hiragino Kaku Gothic ProN", sans-serif;
  font-size: 14px;
  color: var(--text);
  background: var(--bg);
  height: 100vh;
  overflow: hidden;
}

/* ========== ログイン画面 ========== */
#login-page {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 100vh;
  background: linear-gradient(135deg, #1a5fa8 0%, #2176c7 100%);
}

.login-card {
  background: var(--white);
  border-radius: 12px;
  padding: 40px 48px;
  width: 360px;
  box-shadow: 0 8px 24px rgba(0,0,0,.18);
}

.login-card h1 {
  font-size: 18px;
  font-weight: 700;
  color: var(--primary);
  margin-bottom: 28px;
  text-align: center;
}

.form-group {
  margin-bottom: 16px;
}

.form-group label {
  display: block;
  font-size: 12px;
  font-weight: 600;
  margin-bottom: 6px;
  color: var(--text-muted);
}

.form-group input {
  width: 100%;
  padding: 9px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 14px;
  outline: none;
  transition: border-color .15s;
}

.form-group input:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(26,95,168,.15);
}

.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 16px;
  border: none;
  border-radius: var(--radius);
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: background .15s, opacity .15s;
}

.btn:disabled { opacity: .5; cursor: not-allowed; }

.btn-primary {
  background: var(--primary);
  color: #fff;
  width: 100%;
  justify-content: center;
  padding: 10px;
}

.btn-primary:hover:not(:disabled) { background: var(--primary-dark); }

.btn-secondary {
  background: var(--white);
  color: var(--text);
  border: 1px solid var(--border);
}

.btn-secondary:hover:not(:disabled) { background: var(--bg); }

.btn-danger {
  background: #cf222e;
  color: #fff;
}

.btn-danger:hover:not(:disabled) { background: #a40e26; }

.btn-import {
  background: #2da44e;
  color: #fff;
}

.btn-import:hover:not(:disabled) { background: #1f7a38; }

.btn-bss {
  background: #7c4dff;
  color: #fff;
}

.btn-bss:hover:not(:disabled) { background: #6200ea; }

.error-msg {
  color: #cf222e;
  font-size: 13px;
  margin-top: 10px;
  text-align: center;
  min-height: 20px;
}

/* ========== メイン画面 ========== */
#main-page {
  display: flex;
  flex-direction: column;
  height: 100vh;
}

.header {
  background: var(--primary);
  color: #fff;
  padding: 0 20px;
  height: 52px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-shrink: 0;
  box-shadow: 0 2px 4px rgba(0,0,0,.15);
}

.header h1 {
  font-size: 16px;
  font-weight: 700;
}

.layout {
  display: flex;
  flex: 1;
  overflow: hidden;
}

/* ========== サイドバー ========== */
.sidebar {
  width: 200px;
  background: var(--white);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
}

.sidebar-header {
  padding: 12px;
  border-bottom: 1px solid var(--border);
  background: var(--accent);
}

.month-selectors {
  display: flex;
  gap: 6px;
}

.month-selectors select {
  flex: 1;
  padding: 6px 4px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 13px;
  background: var(--white);
}

.date-list {
  flex: 1;
  overflow-y: auto;
  padding: 6px 0;
}

.date-item {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 7px 14px;
  cursor: pointer;
  font-size: 13px;
  border-left: 3px solid transparent;
  transition: background .1s;
}

.date-item:hover { background: var(--bg); }

.date-item.active {
  background: var(--accent);
  border-left-color: var(--primary);
  font-weight: 600;
  color: var(--primary);
}

.date-item.sat { color: #0969da; }
.date-item.sun { color: #cf222e; }
.date-item.active.sat, .date-item.active.sun { color: var(--primary); }

/* ========== メインコンテンツ ========== */
.content {
  flex: 1;
  overflow-y: auto;
  padding: 16px 20px;
}

.content-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 14px;
}

.content-title {
  font-size: 16px;
  font-weight: 700;
}

.content-actions {
  display: flex;
  gap: 8px;
  align-items: center;
}

/* ========== 出勤予定表テーブル ========== */
.schedule-table-wrapper {
  overflow-x: auto;
}

.schedule-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
  background: var(--white);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
}

.schedule-table th {
  background: var(--primary);
  color: #fff;
  padding: 8px 10px;
  text-align: center;
  font-weight: 600;
  white-space: nowrap;
}

.schedule-table td {
  padding: 5px 6px;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}

.schedule-table tr:last-child td { border-bottom: none; }

.schedule-table tr:hover td { background: var(--bg); }

.schedule-table tr.row-unknown td { background: #ffe0e6; }
.schedule-table tr.row-unknown:hover td { background: #ffd0d8; }

.driver-name {
  font-weight: 600;
  white-space: nowrap;
  min-width: 80px;
}

.schedule-table select,
.schedule-table input[type="text"] {
  width: 100%;
  padding: 4px 6px;
  border: 1px solid var(--border);
  border-radius: 4px;
  font-size: 13px;
  background: var(--white);
  font-family: inherit;
}

.schedule-table select:disabled {
  background: #f0f0f0;
  color: #aaa;
  cursor: default;
}

.schedule-table select:focus,
.schedule-table input[type="text"]:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 2px rgba(26,95,168,.12);
}

.col-driver    { width: 90px; }
.col-attend    { width: 100px; }
.col-loc-in   { width: 90px; }
.col-time     { width: 90px; }
.col-loc-out  { width: 90px; }
.col-note     { min-width: 120px; }

/* ========== トースト通知 ========== */
#toast {
  position: fixed;
  bottom: 24px;
  right: 24px;
  padding: 12px 20px;
  border-radius: var(--radius);
  font-size: 14px;
  font-weight: 600;
  color: #fff;
  opacity: 0;
  transform: translateY(10px);
  transition: opacity .25s, transform .25s;
  pointer-events: none;
  z-index: 9999;
  white-space: pre-line;
  max-width: 360px;
}

#toast.show {
  opacity: 1;
  transform: translateY(0);
}

#toast.success { background: #2da44e; }
#toast.error   { background: #cf222e; }

/* ========== ローディング ========== */
.loading {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 40px;
  color: var(--text-muted);
  font-size: 14px;
  gap: 10px;
}

.spinner {
  width: 20px;
  height: 20px;
  border: 2px solid var(--border);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin .7s linear infinite;
}

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

.placeholder {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 200px;
  color: var(--text-muted);
  font-size: 14px;
}

.hidden { display: none !important; }

/* ========== スマホ対応 ========== */

/* トグルボタン：PCでは非表示 */
.sidebar-toggle { display: none !important; }

@media (max-width: 768px) {
  body {
    overflow: auto;
    height: auto;
  }

  /* ログインカード */
  .login-card {
    width: calc(100% - 32px);
    padding: 28px 20px;
  }

  /* ヘッダー */
  .header {
    padding: 0 12px;
    height: 48px;
  }

  .header h1 { font-size: 15px; }

  /* メイン画面 */
  #main-page {
    height: auto;
    min-height: 100vh;
  }

  /* レイアウト縦積み */
  .layout {
    flex-direction: column;
    overflow: visible;
  }

  /* サイドバー */
  .sidebar {
    width: 100%;
    border-right: none;
    border-bottom: 1px solid var(--border);
  }

  .sidebar-header {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 12px;
  }

  .month-selectors { flex: 1; }

  /* トグルボタン：スマホでは表示 */
  .sidebar-toggle {
    display: inline-flex !important;
    align-items: center;
    padding: 7px 10px;
    background: var(--white);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    font-size: 12px;
    font-weight: 600;
    color: var(--text);
    cursor: pointer;
    white-space: nowrap;
    flex-shrink: 0;
  }

  .sidebar-toggle.open {
    background: var(--accent);
    border-color: var(--primary);
    color: var(--primary);
  }

  /* 日付リスト：デフォルト非表示、openクラスで表示 */
  .date-list:not(.open) {
    display: none !important;
  }

  .date-list.open {
    display: block !important;
    flex: none;
    max-height: 220px;
    overflow-y: auto;
    padding: 4px 0;
  }

  /* 日付アイテム：タップしやすく */
  .date-item {
    padding: 10px 16px;
    font-size: 14px;
  }

  /* コンテンツ */
  .content {
    padding: 12px;
    overflow-y: visible;
  }

  /* コンテンツヘッダー折り返し */
  .content-header {
    flex-wrap: wrap;
    gap: 8px;
    margin-bottom: 10px;
  }

  .content-title { font-size: 15px; }

  .content-actions {
    flex-wrap: wrap;
    gap: 6px;
    width: 100%;
  }

  .content-actions .btn {
    flex: 1;
    justify-content: center;
    min-width: 120px;
    padding: 10px 8px;
    font-size: 13px;
  }

  /* テーブルの入力要素をタップしやすく */
  .schedule-table select,
  .schedule-table input[type="text"] {
    padding: 7px 4px;
    font-size: 14px;
  }

  .schedule-table th,
  .schedule-table td { padding: 6px 5px; }

  /* トースト */
  #toast {
    bottom: 16px;
    right: 12px;
    left: 12px;
    max-width: none;
    font-size: 13px;
  }
}
