/* 運行スケジュール - 横長カレンダー・観光バス運行管理 */
:root {
  --col-a-width: 56px;
  --col-b-width: 64px;
  --day-col-width: 80px;
  --cell-line-height: 48px;
  --header-bg: #f0f0f0;
  --border: 1px solid #ccc;
  --font: "Segoe UI", "Meiryo", "Yu Gothic", sans-serif;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: var(--font);
  font-size: 14px;
  background: #fafafa;
  color: #202124;
  -webkit-tap-highlight-color: transparent;
}

.app-header {
  position: sticky;
  top: 0;
  z-index: 10;
  background: #fff;
  padding: 8px 16px;
  border-bottom: var(--border);
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.header-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.app-header h1 {
  margin: 0;
  font-size: 1.15rem;
  font-weight: 700;
  color: #1a237e;
}

.save-indicator {
  font-size: 11px;
  color: #4caf50;
  font-weight: 500;
  opacity: 0.7;
  transition: opacity 0.3s;
}
.save-indicator.show {
  opacity: 1;
}

.header-controls {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px;
}

.header-group {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 2px 6px;
  border-radius: 6px;
  background: #f8f9fa;
  border: 1px solid #e8e8e8;
}

.header-group-nav {
  background: #e8eef4;
}

.month-label {
  font-weight: 700;
  font-size: 14px;
  padding: 0 8px;
  color: #1a237e;
  min-width: 100px;
  text-align: center;
}

.btn-today {
  background: #1a73e8 !important;
  color: #fff !important;
  border-color: #1a73e8 !important;
  font-weight: 600;
}
.btn-today:hover {
  background: #1557b0 !important;
}

.header-controls .header-label {
  display: flex;
  align-items: center;
  gap: 6px;
}

.search-wrap {
  flex: 1;
  min-width: 120px;
  max-width: 220px;
}

#gasUrl {
  width: 100%;
  min-width: 180px;
  max-width: 280px;
  padding: 6px 8px;
  border: var(--border);
  border-radius: 4px;
}

#searchInput {
  width: 100%;
  padding: 6px 10px;
  border: var(--border);
  border-radius: 4px;
  font-size: 12px;
}

button {
  padding: 6px 12px;
  border: var(--border);
  border-radius: 4px;
  background: #fff;
  cursor: pointer;
  font-size: 12px;
}

button:hover {
  background: #f1f3f4;
}

button.btn-danger {
  background: #fce8e6;
  border-color: #c5221f;
  color: #c5221f;
}

button.btn-danger:hover {
  background: #f5c6c3;
}

#btnCreateNextYear {
  background: #e8f0fe;
  border-color: #1a73e8;
  color: #1a73e8;
}

.status {
  color: #5f6368;
  font-size: 11px;
}

.status.error { color: #c5221f; }
.status.success { color: #137333; }

/* グリッド */
.grid-wrap {
  overflow: auto;
  max-height: calc(100vh - 56px);
  padding: 8px;
  -webkit-overflow-scrolling: touch;
}

.schedule-grid {
  display: inline-block;
  border: var(--border);
  border-radius: 2px;
  background: #fff;
  box-shadow: 0 1px 3px rgba(0,0,0,0.08);
  min-width: min-content;
}

.calendar-table {
  border-collapse: collapse;
  table-layout: fixed;
  font-size: 11px;
  width: max-content; /* Ensure table doesn't shrink below content */
}

.calendar-table thead {
  position: sticky;
  top: 0;
  z-index: 40;
}

.calendar-table th,
.calendar-table td {
  border: 1px solid #bbb;
  padding: 0;
  vertical-align: middle;
}

.calendar-table .col-slot-wrap {
  background: #e8eef4;
  font-weight: 600;
  padding: 6px 8px;
  text-align: center;
  position: sticky;
  left: 0;
  z-index: 70;
}

.calendar-table th.col-a-label {
  width: var(--col-a-width);
  min-width: var(--col-a-width);
  background: #e0e8f0;
  font-weight: 600;
  font-size: 10px;
  padding: 4px 6px;
  text-align: center;
  position: sticky;
  left: 0;
  z-index: 70;
  box-shadow: 1px 0 0 #e0e0e0;
}

.calendar-table th.col-b-label {
  width: var(--col-b-width);
  min-width: var(--col-b-width);
  background: #e8ecf0;
  font-weight: 600;
  font-size: 10px;
  padding: 4px 6px;
  text-align: center;
  position: sticky;
  left: var(--col-a-width);
  z-index: 70;
  box-shadow: 1px 0 0 #e0e0e0;
}

.calendar-table .col-a {
  width: var(--col-a-width);
  min-width: var(--col-a-width);
  background: #f0f4f8;
  font-weight: 600;
  padding: 4px 6px;
  text-align: center;
  position: sticky;
  left: 0;
  z-index: 60;
  box-shadow: 1px 0 0 #e0e0e0;
}

.calendar-table .col-b {
  width: var(--col-b-width);
  min-width: var(--col-b-width);
  background: #f8fafc;
  padding: 4px 6px;
  text-align: center;
  font-size: 11px;
  position: sticky;
  left: var(--col-a-width);
  z-index: 60;
  box-shadow: 1px 0 0 #e0e0e0;
}

.calendar-table .col-b.col-b-id {
  font-weight: 700;
  font-size: 12px;
}

.calendar-table .col-b.col-b-red {
  color: #c5221f;
}

.calendar-table td.col-a-continue {
  background: #f0f4f8;
  border-top: none;
}

.calendar-table td.col-b-continue {
  background: #f8fafc;
  border-top: none;
}

.calendar-table th.col-day {
  width: calc(var(--day-col-width) * 2);
  min-width: calc(var(--day-col-width) * 2);
  background: #e8eef4;
  font-weight: 600;
  text-align: center;
  padding: 4px 0;
  position: sticky;
  top: 0;
  z-index: 40;
}

.calendar-table th.col-ampm {
  width: var(--day-col-width);
  min-width: var(--day-col-width);
  background: #f0f0f0;
  font-weight: 500;
  font-size: 10px;
  padding: 2px 4px;
  color: #555;
  text-align: center;
  position: sticky;
  top: 0;
  z-index: 40;
}

/* 土曜＝青 */
.calendar-table th.col-day.saturday {
  background: #e3f2fd;
  color: #1565c0;
  position: sticky;
  top: 0;
  z-index: 40;
}

.calendar-table th.col-ampm.saturday {
  background: #bbdefb;
  color: #0d47a1;
  position: sticky;
  top: 0;
  z-index: 40;
}

/* 日曜・祝日＝赤 */
.calendar-table th.col-day.sunday,
.calendar-table th.col-day.holiday {
  background: #ffebee;
  color: #c62828;
  position: sticky;
  top: 0;
  z-index: 40;
}

.calendar-table th.col-ampm.sunday,
.calendar-table th.col-ampm.holiday {
  background: #ffcdd2;
  color: #b71c1c;
  position: sticky;
  top: 0;
  z-index: 40;
}

/* その他＝白黒（デフォルト） */
.calendar-table th.col-day {
  color: #202124;
}

td.field-cell {
  background: #fff;
  color: #202124;
}

td.field-cell.saturday {
  background: #e3f2fd;
  color: #1565c0;
}

td.field-cell.sunday,
td.field-cell.holiday {
  background: #ffebee;
  color: #c62828;
}

/* データセル（旧互換） */
.calendar-table td.cell-day {
  width: var(--day-col-width);
  min-width: var(--day-col-width);
  height: 0;
  padding: 0;
  position: relative;
}

/* ========== 3行独立構造（field-row / field-cell） ========== */
.field-row td.field-cell {
  border-top: 1px dotted #ddd;
  border-bottom: none;
}

.field-row-first td.field-cell {
  border-top: 2px solid #999;
}

.field-row-last td.field-cell {
  border-bottom: 2px solid #999;
}

td.field-cell {
  width: var(--day-col-width);
  min-width: var(--day-col-width);
  height: var(--cell-line-height);
  padding: 0;
  position: relative;
  vertical-align: middle;
  cursor: col-resize;
}

td.field-cell .field-content {
  min-height: var(--cell-line-height);
  height: var(--cell-line-height);
  padding: 0 2px;
  overflow: hidden;
  white-space: normal;
  word-break: break-all;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 16px;
  font-weight: 600;
  outline: none;
  text-align: center;
  width: 100%;
  box-sizing: border-box;
  cursor: text;
  line-height: 1.1;
}

td.field-cell:hover {
  background-color: rgba(26, 115, 232, 0.06);
}

td.field-cell.field-has-data {
  position: relative;
  border-left: 1px solid #999;
  border-right: 1px solid #999;
  box-shadow: inset 0 0 0 2px rgba(80, 80, 80, 0.5);
  z-index: 1;
}

.field-cell-vendor {
  border-bottom: 1px solid #e0e0e0;
}

.field-cell-destination {
  border-bottom: 1px solid #e8e8e8;
}

.field-cell-driver .field-content {
  color: #1a237e;
}

.segments-container {
  display: flex;
  flex-direction: column;
  flex: 1;
}

.segment-row {
  display: flex;
  flex-direction: column;
  padding: 3px 4px;
  border-bottom: 1px solid #e8e8e8;
  background: #fff;
}

.segment-row:last-child {
  border-bottom: none;
}

.segment-row-sub {
  background: #f8f9fa;
  border-top: 1px dashed #ccc;
}

.segment-route {
  font-size: 11px;
  font-weight: 600;
  color: #202124;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  min-height: 18px;
  line-height: 18px;
  text-align: center;
}

.segment-driver {
  font-size: 10px;
  font-weight: 500;
  color: #1a237e;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  min-height: 16px;
  line-height: 16px;
  text-align: center;
}

.route-container {
  display: flex;
  flex-direction: column;
  gap: 2px;
  margin: 2px 0;
  flex: 1;
  min-height: 0;
}

.route-stop {
  display: flex;
  align-items: center;
  gap: 3px;
  font-size: 10px;
  line-height: 1.2;
  padding: 2px 0;
}

.route-stop .stop-name {
  font-weight: 600;
  overflow: hidden;
  text-overflow: ellipsis;
  flex: 1;
  min-width: 0;
}

.route-stop .stop-driver {
  font-size: 9px;
  opacity: 0.7;
  white-space: nowrap;
  flex-shrink: 0;
}

.route-stop .stop-arrow {
  font-size: 8px;
  color: #999;
  flex-shrink: 0;
}

.route-arrow {
  text-align: center;
  font-size: 8px;
  color: #ccc;
  line-height: 1;
}

.route-destination {
  margin-top: 2px;
  padding-top: 2px;
  border-top: 1px solid #f0f0f0;
  font-weight: 700;
}

.drivers-line {
  padding: 2px 0;
  font-size: 9px;
  line-height: 1.2;
  color: #1a237e;
  font-weight: 600;
  overflow: hidden;
  text-overflow: ellipsis;
  border-top: 1px solid #f0f0f0;
}

.vendor-line-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-bottom: 1px solid #f0f0f0;
  min-height: var(--cell-line-height);
  padding-right: 4px;
}
.vendor-line-header .line {
  border-bottom: none;
  flex: 1;
  background: transparent !important;
}
.vendor-line-header .period-display {
  font-size: 9px;
  opacity: 0.8;
  white-space: nowrap;
  margin-left: 4px;
}

.dest-line {
  display: none;
}

.dest-line {
  display: flex;
  align-items: center;
  flex-wrap: nowrap;
  overflow: hidden;
  gap: 0;
  cursor: pointer;
}
.dest-seg {
  display: inline-flex;
  align-items: center;
  white-space: nowrap;
  flex-shrink: 1;
  min-width: 0;
}
.dest-seg-from {
  opacity: 0.55;
  font-size: 10px;
  overflow: hidden;
  text-overflow: ellipsis;
}
.dest-arrow {
  margin: 0 2px;
  font-size: 10px;
  opacity: 0.6;
  flex-shrink: 0;
}
.dest-seg-to {
  font-weight: 700;
  overflow: hidden;
  text-overflow: ellipsis;
}
.dest-seg-first {
  font-weight: 600;
}
.dest-seg-time {
  font-size: 9px;
  opacity: 0.7;
  margin-left: 2px;
  flex-shrink: 0;
}
.dest-seg-sep {
  margin: 0 3px;
  opacity: 0.35;
  font-size: 10px;
  flex-shrink: 0;
}
.dest-seg:last-child .dest-seg-to {
  font-weight: 800;
}


/* 検索ヒット */
td.field-cell.search-hit {
  background: #c8e6c9 !important;
  box-shadow: inset 0 0 0 2px #2e7d32;
}

/* 今日のハイライト */
.calendar-table th.today-col {
  background: #fff3e0 !important;
  border-bottom: 3px solid #ff9800;
  color: #e65100 !important;
  font-weight: 700;
}
td.field-cell.today-cell {
  box-shadow: inset 0 0 0 2px #ff9800;
}

/* ドライバー重複警告 */
td.field-cell.driver-conflict {
  box-shadow: inset 0 0 0 2px #f44336;
  position: relative;
}
td.field-cell.driver-conflict::after {
  content: '⚠';
  position: absolute;
  top: 1px;
  right: 3px;
  font-size: 10px;
  color: #f44336;
  pointer-events: none;
}

/* ドライバー交代バッジ（イメージに合わせた表示） */
.driver-change-badge {
  display: inline-block;
  padding: 2px 6px;
  margin-right: 4px;
  font-size: 10px;
  font-weight: 600;
  color: #1a73e8;
  background: #fff;
  border: 1px solid #1a73e8;
  border-radius: 4px;
  white-space: nowrap;
  vertical-align: middle;
}

/* ========== ドラッグ＆ドロップ・リサイズ（セル全体・旧互換） ========== */
.cell-drag-handle {
  position: absolute;
  top: 50%;
  left: -8px;
  transform: translateY(-50%);
  width: 14px;
  height: 14px;
  font-size: 10px;
  line-height: 12px;
  text-align: center;
  color: #555;
  background: #fff;
  border: 1px solid #ccc;
  cursor: grab;
  z-index: 10;
  border-radius: 4px;
  user-select: none;
  -webkit-user-select: none;
  box-shadow: 0 1px 2px rgba(0,0,0,0.1);
}

.cell-delete-btn {
  position: absolute;
  top: -6px;
  right: -6px;
  width: 14px;
  height: 14px;
  font-size: 10px;
  line-height: 12px;
  text-align: center;
  color: #555;
  background: #fff;
  border: 1px solid #ccc;
  cursor: pointer;
  z-index: 10;
  border-radius: 50%;
  user-select: none;
  -webkit-user-select: none;
  box-shadow: 0 1px 2px rgba(0,0,0,0.1);
}

.line-color-btn {
  position: absolute;
  top: 50%;
  right: 18px;
  transform: translateY(-50%);
  /* ... rest ... */
}

.field-cell.field-has-data .cell-drag-handle {
  display: block;
  opacity: 0.8;
}

.field-cell.field-has-data:hover .cell-drag-handle {
  opacity: 1;
}

.cell-drag-handle:hover {
  color: #1a73e8 !important;
  background: #e3f2fd !important;
}

.cell-drag-handle:active {
  cursor: grabbing;
}

.cell-resize-left,
.cell-resize-right {
  position: absolute;
  top: 0;
  bottom: 0;
  width: 10px;
  cursor: col-resize;
  z-index: 5;
  background: transparent;
  transition: background 0.15s;
}

.cell-resize-left {
  left: 0;
  border-radius: 2px 0 0 2px;
}

.cell-resize-right {
  right: 0;
  border-radius: 0 2px 2px 0;
}

.field-cell.field-has-data:hover .cell-resize-left,
.field-cell.field-has-data:hover .cell-resize-right {
  background: rgba(26, 115, 232, 0.15);
}

.cell-resize-left:hover,
.cell-resize-right:hover {
  background: rgba(26, 115, 232, 0.4) !important;
}

/* field-cell リサイズカーソル（左右端） */
td.field-cell.field-has-data {
  cursor: col-resize;
}

td.field-cell.field-has-data .field-content {
  cursor: text;
}

td.field-cell.field-has-data .field-content {
  padding-left: 22px;
  padding-right: 22px;
}

/* ========== 業者名カラーボタン ========== */
.line-color-btn {
  display: none;
  position: absolute;
  top: 50%;
  right: 18px;
  transform: translateY(-50%);
  width: 16px;
  height: 16px;
  font-size: 10px;
  line-height: 16px;
  text-align: center;
  cursor: pointer;
  z-index: 6;
  border-radius: 50%;
  user-select: none;
  -webkit-user-select: none;
  background: rgba(255,255,255,0.9);
  transition: background 0.15s, transform 0.15s;
}

td.field-cell.field-has-data:hover .line-color-btn {
  display: block;
}

.line-color-btn:hover {
  background: #e3f2fd;
  transform: translateY(-50%) scale(1.15);
}

/* ========== 業者名カラーポップアップ ========== */
.vendor-color-popup {
  background: #fff;
  border: 1px solid #dadce0;
  border-radius: 10px;
  padding: 12px 14px;
  box-shadow: 0 6px 20px rgba(0,0,0,0.18);
  min-width: 190px;
  max-width: 240px;
}

.vendor-color-popup-title {
  font-size: 12px;
  font-weight: 700;
  color: #1a237e;
  margin-bottom: 8px;
}

.vendor-color-popup-row {
  display: flex;
  align-items: flex-end;
  gap: 10px;
  flex-wrap: wrap;
}

.vendor-color-popup-label {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 4px;
  font-size: 11px;
  font-weight: 600;
  color: #5f6368;
}

.vendor-color-popup-input {
  width: 38px;
  height: 30px;
  padding: 2px;
  border: 1px solid #dadce0;
  border-radius: 6px;
  cursor: pointer;
}

.vendor-color-popup-reset {
  padding: 5px 10px;
  font-size: 11px;
  background: #f5f5f5;
  border: 1px solid #dadce0;
  border-radius: 6px;
  cursor: pointer;
  color: #5f6368;
}

.vendor-color-popup-reset:hover {
  background: #fce8e6;
  border-color: #f44336;
  color: #c5221f;
}

.drag-source {
  opacity: 0.35;
  background: #f5f5f5 !important;
  border-style: dashed !important;
}

.drag-over {
  background: #e3f2fd !important;
  box-shadow: inset 0 0 0 2px #1a73e8 !important;
}

.resize-preview {
  background: #e8f5e9 !important;
  box-shadow: inset 0 0 0 2px #43a047 !important;
}

.resize-shrink {
  background: #ffebee !important;
  box-shadow: inset 0 0 0 2px #e53935 !important;
  opacity: 0.6;
}

.resize-shrink::after {
  content: '✕';
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  font-size: 16px;
  color: #c62828;
  font-weight: 700;
  pointer-events: none;
  z-index: 4;
}

.drag-ghost {
  font-size: 11px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 4px 6px;
  overflow: hidden;
}

/* Delete button on cells */
.cell-delete-btn {
  position: absolute;
  top: 2px;
  right: 2px;
  width: 16px;
  height: 16px;
  font-size: 10px;
  line-height: 16px;
  text-align: center;
  color: transparent;
  cursor: pointer;
  z-index: 3;
  border-radius: 50%;
  user-select: none;
  -webkit-user-select: none;
  transition: color 0.15s, background 0.15s;
}

.field-cell.field-has-data .cell-delete-btn {
  color: #999;
  opacity: 0.85;
}

.field-cell.field-has-data:hover .cell-delete-btn {
  opacity: 1;
}

.cell-drag-handle,
.cell-delete-btn,
.line-color-btn {
  z-index: 10;
}

.cell-delete-btn {
  right: -2px;
  top: -8px;
  background: #fff;
  border: 1px solid #ccc;
  width: 14px;
  height: 14px;
  line-height: 12px;
  border-radius: 50%;
  font-size: 10px;
  box-shadow: 0 1px 2px rgba(0,0,0,0.1);
}

.line-color-btn {
  right: 20px; 
}

.cell-delete-btn:hover {
  color: #fff !important;
  background: #e53935 !important;
}

/* 候補選択パネル（右側／スマホは下部） */
.candidate-panel {
  position: fixed;
  z-index: 90;
  top: 52px;
  right: 0;
  bottom: 0;
  width: 220px;
  background: #fff;
  border-left: var(--border);
  box-shadow: -2px 0 8px rgba(0,0,0,0.08);
  overflow-y: auto;
  padding: 12px;
}

.candidate-panel[hidden] {
  display: none !important;
}

.candidate-panel-title {
  font-weight: 600;
  font-size: 12px;
  margin-bottom: 10px;
  padding-bottom: 6px;
  border-bottom: 1px solid #e0e0e0;
  color: #202124;
}

.candidate-panel-section {
  margin-bottom: 14px;
}

.candidate-panel-label {
  font-size: 10px;
  color: #5f6368;
  margin-bottom: 4px;
  font-weight: 600;
}

.candidate-panel-list {
  display: flex;
  flex-direction: column;
  gap: 2px;
  max-height: 140px;
  overflow-y: auto;
}

.candidate-panel-item {
  padding: 6px 8px;
  font-size: 11px;
  font-weight: 600;
  cursor: pointer;
  border-radius: 4px;
  background: #f8f9fa;
  border: 1px solid transparent;
}

.candidate-panel-item:hover {
  background: #e8f0fe;
  border-color: #1a73e8;
  color: #1a73e8;
}

.candidate-panel-item:active {
  background: #d2e3fc;
}

/* 候補ドロップダウン（入力補完用） */
.candidate-dropdown {
  position: fixed;
  z-index: 1000;
  max-height: 200px;
  overflow-y: auto;
  background: #fff;
  border: var(--border);
  border-radius: 4px;
  box-shadow: 0 4px 12px rgba(0,0,0,0.15);
  padding: 4px 0;
}

.candidate-item {
  padding: 8px 12px;
  cursor: pointer;
  font-size: 12px;
  font-weight: 600;
}

.candidate-item:hover {
  background: #f1f3f4;
}

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

/* 非表示時は必ず隠す（hidden属性の確実な適用） */
.modal[hidden] {
  display: none !important;
}

.confirm-modal {
  z-index: 200;
}

.modal-confirm {
  max-width: 360px;
  padding: 28px 24px 20px;
  text-align: center;
}

.confirm-message {
  margin: 0 0 24px;
  font-size: 15px;
  line-height: 1.6;
  color: #202124;
}

.confirm-actions {
  display: flex;
  gap: 10px;
  justify-content: center;
}

.confirm-btn-ok {
  padding: 10px 24px;
  background: #d93025;
  color: #fff;
  border: none;
  border-radius: 6px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
}

.confirm-btn-ok:hover {
  background: #b3261e;
}

.confirm-btn-cancel {
  padding: 10px 24px;
  background: #fff;
  color: #5f6368;
  border: 1px solid #dadce0;
  border-radius: 6px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
}

.confirm-btn-cancel:hover {
  background: #f1f3f4;
}

.modal-content {
  background: #fff;
  border-radius: 8px;
  padding: 20px;
  max-width: 480px;
  width: 100%;
  max-height: 90vh;
  overflow-y: auto;
}

.modal-content h2 {
  margin: 0 0 12px;
  font-size: 1.1rem;
}

.modal-desc {
  margin: 0 0 16px;
  font-size: 12px;
  color: #5f6368;
}

.modal-content label {
  display: block;
  margin-bottom: 12px;
  font-size: 12px;
  font-weight: 500;
}

.modal-content textarea {
  width: 100%;
  margin-top: 4px;
  padding: 8px;
  border: var(--border);
  border-radius: 4px;
  font-family: inherit;
  font-size: 12px;
  resize: vertical;
}

.modal-actions {
  margin-top: 16px;
  display: flex;
  gap: 8px;
}

/* ========== セル編集モーダル（新デザイン v2） ========== */
.modal-cell-form-v2 {
  max-width: 560px;
  width: 100%;
  max-height: 90vh;
  padding: 0;
  border-radius: 12px;
  overflow-y: auto;
  overflow-x: hidden;
  box-shadow: 0 24px 48px rgba(0,0,0,0.12);
}

.cell-form-header {
  background: linear-gradient(135deg, #1a237e 0%, #283593 100%);
  color: #fff;
  padding: 20px 24px;
}

.cell-form-header h2 {
  margin: 0;
  font-size: 1.35rem;
  font-weight: 700;
  letter-spacing: 0.02em;
}

.cell-form-subtitle {
  margin: 6px 0 0;
  font-size: 12px;
  opacity: 0.9;
}

.cell-form-section {
  padding: 16px 24px;
  border-bottom: 1px solid #e8ecf0;
}

.cell-form-section:last-of-type {
  border-bottom: none;
}

.cell-form-section-title {
  margin: 0 0 12px;
  font-size: 13px;
  font-weight: 700;
  color: #1a237e;
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.cell-form-section-num {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 24px;
  height: 24px;
  background: #e8eaf6;
  color: #1a237e;
  border-radius: 50%;
  font-size: 12px;
}

.cell-form-section-hint {
  font-size: 11px;
  font-weight: 500;
  color: #5f6368;
}

.cell-form-period-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
}

.cell-form-period-card {
  background: #f8f9fa;
  border-radius: 8px;
  padding: 12px;
  border: 1px solid #e8ecf0;
}

.cell-form-label {
  display: block;
  font-size: 11px;
  font-weight: 600;
  color: #5f6368;
  margin-bottom: 6px;
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

.cell-form-input {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid #dadce0;
  border-radius: 8px;
  font-size: 14px;
  margin-bottom: 8px;
  box-sizing: border-box;
}

.cell-form-input:focus {
  outline: none;
  border-color: #1a73e8;
  box-shadow: 0 0 0 2px rgba(26, 115, 232, 0.2);
}

.cell-form-driver-wrap {
  display: flex;
  gap: 8px;
  align-items: center;
  flex-wrap: nowrap;
}

.cell-form-select {
  flex-shrink: 0;
  min-width: 100px;
  max-width: 140px;
  padding: 8px 10px;
  border: 1px solid #dadce0;
  border-radius: 8px;
  font-size: 13px;
  background: #fff;
  cursor: pointer;
}

.cell-form-driver-wrap .cell-form-driver-input {
  flex: 1;
  min-width: 0;
}

.cell-form-radio-group {
  display: flex;
  gap: 12px;
  margin-top: 6px;
}

.cell-form-radio {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 13px;
  cursor: pointer;
  margin: 0;
}

.cell-form-radio input {
  width: 18px;
  height: 18px;
}

.cell-form-two-col {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
}

.cell-form-field {
  margin-bottom: 0;
}

.cell-form-waypoints-list,
.cell-form-handovers-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-bottom: 10px;
}

.cell-form-waypoint-row {
  display: grid;
  grid-template-columns: 1fr 72px 70px 1fr auto;
  gap: 8px;
  align-items: center;
  padding: 10px 12px;
  background: #f8f9fa;
  border-radius: 8px;
  border: 1px solid #e8ecf0;
}

.cell-form-waypoint-row .cell-form-waypoint-input {
  min-width: 0;
}

.cell-form-waypoint-row .cell-form-wp-day,
.cell-form-waypoint-row .cell-form-wp-ampm {
  padding: 8px 6px;
  border: 1px solid #dadce0;
  border-radius: 6px;
  font-size: 12px;
  background: #fff;
}

.cell-form-waypoint-row .cell-form-waypoint-driver {
  padding: 8px 10px;
  border: 1px solid #dadce0;
  border-radius: 6px;
  font-size: 13px;
  min-width: 0;
}

.cell-form-remove-btn {
  padding: 6px 10px;
  font-size: 11px;
  background: #fff;
  border: 1px solid #dadce0;
  border-radius: 6px;
  color: #5f6368;
  cursor: pointer;
}

.cell-form-remove-btn:hover {
  background: #fce8e6;
  border-color: #f44336;
  color: #c5221f;
}

.cell-form-add-btn {
  padding: 10px 16px;
  font-size: 13px;
  font-weight: 600;
  background: #e8eaf6;
  color: #1a237e;
  border: 1px dashed #3f51b5;
  border-radius: 8px;
  cursor: pointer;
  width: 100%;
}

.cell-form-add-btn:hover {
  background: #c5cae9;
}

.cell-form-driver-main {
  margin-bottom: 8px;
}

.cell-form-hint {
  margin: 0 0 10px;
  font-size: 11px;
  color: #5f6368;
}

.cell-form-handover-item {
  display: grid;
  grid-template-columns: 1fr 72px 70px auto;
  gap: 8px;
  align-items: center;
  padding: 10px 12px;
  background: #f8f9fa;
  border-radius: 8px;
  border: 1px solid #e8ecf0;
}

.cell-form-handover-item .cell-form-handover-driver {
  padding: 8px 10px;
  border: 1px solid #dadce0;
  border-radius: 6px;
  font-size: 13px;
  min-width: 0;
}

.cell-form-handover-item .cell-form-handover-day,
.cell-form-handover-item .cell-form-handover-ampm {
  padding: 8px 6px;
  border: 1px solid #dadce0;
  border-radius: 6px;
  font-size: 12px;
  background: #fff;
}

.cell-form-handover-item .cell-form-remove-btn {
  padding: 6px 10px;
}

.cell-form-colors-row {
  display: flex;
  gap: 24px;
  align-items: flex-end;
  flex-wrap: wrap;
}

.cell-form-color-field {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 6px;
}

.cell-form-color-input {
  width: 48px;
  height: 36px;
  padding: 2px;
  border: 1px solid #dadce0;
  border-radius: 8px;
  cursor: pointer;
}

.cell-form-actions {
  display: flex;
  gap: 10px;
  padding: 16px 24px;
  background: #f5f5f5;
  border-top: 1px solid #e0e0e0;
  flex-wrap: wrap;
}

.cell-form-btn {
  padding: 10px 20px;
  font-size: 14px;
  font-weight: 600;
  border-radius: 8px;
  border: none;
  cursor: pointer;
}

.cell-form-btn-primary {
  background: #1a73e8;
  color: #fff;
}

.cell-form-btn-primary:hover {
  background: #1557b0;
}

.cell-form-btn-danger {
  background: #fff;
  color: #c5221f;
  border: 1px solid #c5221f;
}

.cell-form-btn-danger:hover {
  background: #fce8e6;
}

.cell-form-btn-secondary {
  background: #fff;
  color: #5f6368;
  border: 1px solid #dadce0;
}

.cell-form-btn-secondary:hover {
  background: #f1f3f4;
}


/* 候補の色設定 */
.candidates-colors-block {
  margin: 14px 0;
  padding: 10px 0;
  border-top: 1px solid #e0e0e0;
}

.candidates-colors-title {
  margin: 10px 0 6px;
  font-size: 12px;
  font-weight: 600;
  color: #5f6368;
}

.candidates-colors-list {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 8px;
}

.candidates-color-row {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 8px;
  background: #f5f5f5;
  border-radius: 6px;
  font-size: 12px;
}

.candidates-color-row span {
  max-width: 120px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.candidates-color-row input[type="color"] {
  width: 28px;
  height: 28px;
  padding: 2px;
  border: 1px solid #ccc;
  border-radius: 4px;
  cursor: pointer;
}

.modal-summary .summary-table {
  width: 100%;
  border-collapse: collapse;
  margin-bottom: 12px;
  font-size: 12px;
}

.modal-summary .summary-table th,
.modal-summary .summary-table td {
  border: 1px solid #e0e0e0;
  padding: 8px;
  text-align: left;
}

.modal-summary .summary-table th {
  background: #f5f5f5;
}

.summary-slots {
  margin: 8px 0 0;
  font-size: 12px;
  color: #5f6368;
}

.summary-section-title {
  margin: 16px 0 8px;
  font-size: 13px;
  font-weight: 700;
  color: #1a237e;
  border-bottom: 2px solid #1a73e8;
  padding-bottom: 4px;
}
.summary-section-title:first-child {
  margin-top: 0;
}

.summary-export {
  margin-top: 12px;
  padding-top: 10px;
  border-top: 1px solid #e0e0e0;
}

.loading {
  padding: 40px;
  text-align: center;
  color: #5f6368;
}

/* ========== スマホ表示対応 ========== */
@media (max-width: 768px) {
  :root {
    --col-a-width: 44px;
    --col-b-width: 48px;
    --day-col-width: 56px;
    --cell-line-height: 36px;
  }

  .app-header {
    padding: 6px 8px;
    gap: 4px;
  }

  .app-header h1 {
    font-size: 0.95rem;
  }

  .header-controls {
    width: 100%;
    gap: 4px;
  }

  .header-group {
    flex-wrap: wrap;
    padding: 2px 4px;
  }

  .month-label {
    font-size: 12px;
    min-width: 80px;
  }

  .header-controls .header-label {
    width: 100%;
  }

  #gasUrl {
    max-width: none;
  }

  .search-wrap {
    max-width: none;
    min-width: 0;
  }

  button {
    padding: 10px 12px;
    min-height: 44px;
    font-size: 11px;
  }

  .calendar-table {
    font-size: 10px;
  }

  .calendar-table .col-a,
  .calendar-table .col-b {
    padding: 2px 4px;
    font-size: 10px;
  }

  td.field-cell .field-content {
    font-size: 13px;
    min-height: var(--cell-line-height);
    height: var(--cell-line-height);
  }

  .grid-wrap {
    padding: 4px;
    max-height: calc(100vh - 120px);
  }

  .modal {
    padding: 8px;
    align-items: flex-end;
  }

  .modal-content {
    max-height: 85vh;
    padding: 16px;
    border-radius: 12px 12px 0 0;
  }

  .modal-cell-form-v2 .cell-form-section {
    padding: 12px 16px;
  }

  .modal-cell-form-v2 .cell-form-period-grid {
    grid-template-columns: 1fr;
  }

  .modal-cell-form-v2 .cell-form-two-col {
    grid-template-columns: 1fr;
  }

  .modal-cell-form-v2 .cell-form-waypoint-row {
    grid-template-columns: 1fr 1fr auto;
    grid-template-rows: auto auto;
  }
  .modal-cell-form-v2 .cell-form-waypoint-row .cell-form-waypoint-input {
    grid-column: 1 / -1;
  }
  .modal-cell-form-v2 .cell-form-waypoint-row .cell-form-waypoint-driver {
    grid-column: 1 / -1;
  }

  .modal-cell-form-v2 .cell-form-handover-item {
    grid-template-columns: 1fr 1fr auto;
  }

  .modal-cell-form-v2 .cell-form-actions {
    padding: 12px 16px;
    flex-direction: column;
  }
  .modal-cell-form-v2 .cell-form-btn {
    width: 100%;
  }

  .cell-drag-handle {
    width: 28px;
    height: 16px;
    font-size: 12px;
    line-height: 16px;
    color: #90a4ae;
    background: rgba(255,255,255,0.9);
  }

  .cell-resize-left,
  .cell-resize-right {
    width: 10px;
    background: rgba(26, 115, 232, 0.15);
  }

  .cell-delete-btn {
    width: 20px;
    height: 20px;
    font-size: 12px;
    line-height: 20px;
    color: #999;
  }

  td.field-cell.field-has-data:hover .line-color-btn {
    display: block;
  }

  .candidate-dropdown {
    max-height: 160px;
  }

  .candidate-item {
    padding: 12px 14px;
    min-height: 44px;
    display: flex;
    align-items: center;
  }

  /* 候補パネル：画面下部で常に見え、はみ出さない */
  .candidate-panel {
    top: auto;
    right: 0;
    left: 0;
    bottom: 0;
    width: 100%;
    max-height: 32vh;
    display: flex;
    flex-direction: column;
    padding: 10px;
    border-left: none;
    border-top: var(--border);
    box-shadow: 0 -2px 12px rgba(0,0,0,0.1);
    overflow-y: auto;
  }

  .candidate-panel-title {
    flex-shrink: 0;
    margin-bottom: 8px;
  }

  .candidate-panel-section {
    flex: 1;
    min-height: 0;
    margin-bottom: 8px;
  }

  .candidate-panel-list {
    max-height: 80px;
  }

  .candidate-panel-item {
    padding: 10px 12px;
    min-height: 40px;
    display: flex;
    align-items: center;
    font-size: 12px;
  }
}

@media (max-width: 480px) {
  :root {
    --day-col-width: 48px;
  }

  .app-header h1 {
    font-size: 0.95rem;
  }

  .header-group {
    flex-wrap: wrap;
    width: 100%;
  }

  button {
    padding: 8px 10px;
    min-height: 40px;
  }
}

/* ========== 印刷用レイアウト ========== */
@media print {
  body {
    font-size: 9px;
    background: #fff;
  }

  .app-header {
    position: static;
    padding: 4px 8px;
    border-bottom: 2px solid #000;
    page-break-after: avoid;
  }

  .header-controls,
  .save-indicator,
  .candidate-panel,
  .candidate-dropdown,
  .modal,
  #status {
    display: none !important;
  }

  .header-top h1 {
    font-size: 14px;
    color: #000;
  }

  .grid-wrap {
    overflow: visible;
    max-height: none;
    padding: 0;
  }

  .schedule-grid {
    box-shadow: none;
    border: none;
  }

  .calendar-table {
    font-size: 8px;
    page-break-inside: auto;
  }

  .calendar-table th,
  .calendar-table td {
    border: 1px solid #333;
  }

  .calendar-table th.col-day,
  .calendar-table th.col-ampm {
    background: #f0f0f0 !important;
    color: #000 !important;
    -webkit-print-color-adjust: exact;
    print-color-adjust: exact;
  }

  .calendar-table th.col-day.saturday,
  .calendar-table th.col-ampm.saturday {
    color: #1565c0 !important;
  }

  .calendar-table th.col-day.sunday,
  .calendar-table th.col-day.holiday,
  .calendar-table th.col-ampm.sunday,
  .calendar-table th.col-ampm.holiday {
    color: #c62828 !important;
  }

  .calendar-table th.today-col {
    border-bottom: 2px solid #000;
    background: #f0f0f0 !important;
    color: #000 !important;
  }

  td.field-cell .field-content {
    min-height: 12px;
    padding: 1px 2px;
    font-size: 8px;
  }

  .segment-row {
    padding: 1px 2px;
  }

  .segment-route {
    font-size: 8px;
    min-height: 12px;
    line-height: 12px;
  }

  .segment-driver {
    font-size: 7px;
    min-height: 10px;
    line-height: 10px;
  }

  .vendor-line-header .period-display {
    font-size: 7px;
  }

  td.field-cell.today-cell {
    box-shadow: none;
  }

  td.field-cell.driver-conflict::after {
    font-size: 8px;
  }

  .driver-change-badge {
    font-size: 7px;
    padding: 1px 3px;
  }

  .calendar-table .col-a,
  .calendar-table .col-b {
    position: static;
    box-shadow: none;
  }

  .calendar-table th.col-a-label,
  .calendar-table th.col-b-label,
  .calendar-table .col-slot-wrap {
    position: static;
    box-shadow: none;
  }

  .cell-drag-handle,
  .cell-resize-left,
  .cell-resize-right,
  .cell-delete-btn,
  .line-color-btn,
  .vendor-color-popup {
    display: none !important;
  }

  td.field-cell {
    cursor: default;
  }

  @page {
    size: landscape;
    margin: 5mm;
  }
}

/* 車両設定モーダル */
.modal-slots {
  max-width: 500px;
}
.slots-actions {
  display: flex;
  justify-content: flex-end;
  margin-bottom: 12px;
}
.slots-add-btn {
  background: #1a73e8;
  color: #fff;
  border: none;
  padding: 6px 12px;
  border-radius: 4px;
  font-weight: 600;
  cursor: pointer;
}
.slots-add-btn:hover {
  background: #1557b0;
}
.slots-list-container {
  border: 1px solid #ddd;
  border-radius: 4px;
  overflow: hidden;
}
.slots-list-header {
  display: flex;
  background: #f1f3f4;
  padding: 8px 12px;
  font-weight: 600;
  border-bottom: 1px solid #ddd;
}
.slots-list {
  max-height: 400px;
  overflow-y: auto;
}
.slot-item {
  display: flex;
  align-items: center;
  padding: 8px 12px;
  border-bottom: 1px solid #eee;
  gap: 8px;
}
.slot-item:last-child {
  border-bottom: none;
}
.slots-col-cat {
  flex: 1;
  font-size: 13px;
}
.slots-col-id {
  width: 80px;
  font-size: 13px;
}
.slots-col-action {
  width: 60px;
  text-align: right;
}
.slot-input {
  width: 100%;
  padding: 4px;
  border: 1px solid #ddd;
  border-radius: 3px;
}
.slot-btn-remove {
  background: #fff;
  color: #d93025;
  border: 1px solid #d93025;
  padding: 2px 6px;
  border-radius: 3px;
  font-size: 11px;
  cursor: pointer;
}
.slot-btn-remove:hover {
  background: #fce8e6;
}

/* 種別・車番セルの編集可能スタイル */
.slot-editable {
  cursor: text;
  transition: background-color 0.2s;
}
.slot-editable:hover {
  background-color: #e8f0fe !important;
}
.slot-editable:focus {
  background-color: #fff !important;
  outline: 2px solid #1a73e8;
  outline-offset: -2px;
}

/* 候補リスト設定モーダル */
.modal-candidates {
  max-width: 600px;
}

.candidates-header {
  margin-bottom: 20px;
}

.candidates-header h2 {
  margin: 0 0 4px;
  font-size: 18px;
  font-weight: 700;
  color: #1a237e;
}

.candidates-subtitle {
  margin: 0;
  font-size: 13px;
  color: #5f6368;
}

.candidates-tabs {
  display: flex;
  gap: 2px;
  margin-bottom: 16px;
  border-bottom: 2px solid #e8e8e8;
}

.candidates-tab-btn {
  padding: 10px 16px;
  background: none;
  border: none;
  font-size: 14px;
  font-weight: 500;
  color: #5f6368;
  cursor: pointer;
  position: relative;
  transition: color 0.2s;
}

.candidates-tab-btn:hover {
  color: #202124;
}

.candidates-tab-btn.active {
  color: #1a73e8;
  font-weight: 600;
}

.candidates-tab-btn.active::after {
  content: '';
  position: absolute;
  bottom: -2px;
  left: 0;
  right: 0;
  height: 2px;
  background: #1a73e8;
}

.candidates-tab-content {
  display: none;
}

.candidates-tab-content.active {
  display: block;
}

.candidates-input-group {
  display: flex;
  gap: 6px;
  margin-bottom: 12px;
}

.candidates-input {
  flex: 1;
  padding: 8px 12px;
  border: 1px solid #dadce0;
  border-radius: 4px;
  font-size: 14px;
  font-family: inherit;
}

.candidates-input:focus {
  outline: none;
  border-color: #1a73e8;
  box-shadow: 0 0 0 3px rgba(26, 115, 232, 0.1);
}

.candidates-add-btn {
  padding: 8px 16px;
  background: #1a73e8;
  color: #fff;
  border: none;
  border-radius: 4px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.2s;
}

.candidates-add-btn:hover {
  background: #1557b0;
}

.candidates-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
  max-height: 300px;
  overflow-y: auto;
  margin-bottom: 12px;
}

.candidates-item {
  display: flex;
  align-items: center;
  padding: 10px 12px;
  background: #f8f9fa;
  border: 1px solid #e8e8e8;
  border-radius: 4px;
  gap: 8px;
  transition: background 0.2s;
}

.candidates-item:hover {
  background: #f1f3f4;
}

.candidates-item-name {
  flex: 1;
  font-size: 14px;
  color: #202124;
  word-break: break-word;
}

.candidates-item-color-input {
  width: 36px;
  height: 36px;
  padding: 2px;
  border: 1px solid #dadce0;
  border-radius: 4px;
  cursor: pointer;
}

.candidates-item-delete {
  padding: 6px 10px;
  background: #fff;
  color: #d93025;
  border: 1px solid #d93025;
  border-radius: 4px;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.2s;
}

.candidates-item-delete:hover {
  background: #fce8e6;
}

.candidates-note {
  margin: 8px 0 0;
  font-size: 12px;
  color: #5f6368;
  font-style: italic;
}

.candidates-btn-save {
  background: #1a73e8;
  color: #fff;
  border: none;
  padding: 10px 24px;
  border-radius: 4px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.2s;
}

.candidates-btn-save:hover {
  background: #1557b0;
}

.candidates-btn-close {
  background: #fff;
  color: #5f6368;
  border: 1px solid #dadce0;
  padding: 10px 24px;
  border-radius: 4px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s;
}

.candidates-btn-close:hover {
  border-color: #5f6368;
  background: #f8f9fa;
}

/* スマホ時の編集UI非表示 */
@media (max-width: 768px) {
  .mobile-view .cell-delete-btn,
  .mobile-view .cell-drag-handle,
  .mobile-view .cell-resize-left,
  .mobile-view .cell-resize-right,
  .mobile-view .line-color-btn {
    display: none !important;
  }
  
  .mobile-view .slot-editable {
    cursor: default !important;
  }
  
  .mobile-view .slot-editable:hover {
    background-color: inherit !important;
  }
  
  /* セル編集フォームの保存・削除ボタン非表示 */
  .mobile-view #btnCellFormSave,
  .mobile-view #btnCellFormDelete {
    display: none !important;
  }
  
  /* スマホではセルの入力を完全に無効化 */
  .mobile-view .field-content {
    pointer-events: none !important;
    user-select: none !important;
    -webkit-user-select: none !important;
  }
  
  .mobile-view td.field-cell:hover {
    background-color: inherit !important;
  }
}
