/* ==== リセット・ベース ==== */
* { box-sizing: border-box; margin: 0; padding: 0; }
body {
    font-family: -apple-system, 'Hiragino Sans', 'ＭＳ Ｐゴシック', sans-serif;
    background: #f5f7fa;
    color: #333;
    line-height: 1.5;
}

/* ==== ヘッダー ==== */
header {
    background: linear-gradient(135deg, #4a6cf7 0%, #5f85ef 100%);
    color: white;
    padding: 1rem 2rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
    gap: 0.75rem;
    box-shadow: 0 2px 4px rgba(0,0,0,0.1);
}
header h1 { font-size: 1.5rem; white-space: nowrap; margin: 0; }

/* ヘッダーブランド: ロゴ + タイトル */
.header-brand {
    display: flex;
    align-items: center;
    gap: 0.85rem;
}
.brand-logo {
    height: 42px;
    width: auto;
    /* 透過PNG: 青ヘッダーに直接配置（白枠なし） */
    filter: drop-shadow(0 1px 2px rgba(0,0,0,0.25));
}

/* アプリフッター: 制作者表示 */
.app-footer {
    text-align: center;
    padding: 0.7rem 1rem;
    background: #fafafa;
    border-top: 1px solid #e5e7eb;
    color: #6b7280;
    font-size: 0.8rem;
    letter-spacing: 0.02em;
}
.app-footer strong {
    color: #1e3a8a;
    font-weight: 700;
    margin: 0 0.3rem;
}
.app-footer .footer-sep {
    color: #d1d5db;
    margin: 0 0.6rem;
}
.app-footer .footer-url {
    color: #4a6cf7;
}
.header-info {
    font-size: 0.9rem;
    opacity: 0.95;
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 0.5rem;
}
.header-info label { font-weight: 500; }
.header-info select {
    padding: 0.35rem 0.5rem;
    border: none;
    border-radius: 4px;
    font-size: 0.9rem;
    font-weight: 500;
    background: white;
    color: #333;
    cursor: pointer;
}
.date-picker-input {
    padding: 0.3rem 0.5rem;
    border: none;
    border-radius: 4px;
    font-size: 0.85rem;
    font-weight: 500;
    background: white;
    color: #333;
    cursor: pointer;
    font-family: inherit;
}
.date-picker-input::-webkit-calendar-picker-indicator { cursor: pointer; }

/* ==== メイン ==== */
main {
    max-width: 1400px;
    margin: 0 auto;
    padding: 1rem;
}

/* ==== タブ ==== */
.tabs {
    display: flex;
    gap: 0.5rem;
    border-bottom: 2px solid #e0e0e0;
    margin-bottom: 1rem;
}
.tab-btn {
    padding: 0.75rem 1.5rem;
    border: none;
    background: transparent;
    font-size: 1rem;
    font-weight: 500;
    cursor: pointer;
    border-bottom: 3px solid transparent;
    transition: all 0.2s;
}
.tab-btn:hover { color: #4a6cf7; }
.tab-btn.active {
    color: #4a6cf7;
    border-bottom-color: #4a6cf7;
}
.tab-content { display: none; }
.tab-content.active { display: block; }

/* ==== セクションヘッダー ==== */
.section-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1rem;
    flex-wrap: wrap;
    gap: 1rem;
}
.section-header h2 { font-size: 1.25rem; }
.summary { color: #666; font-size: 0.95rem; }

/* エンジンバージョン切替ピッカー */
.engine-version-picker {
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.3rem 0.6rem;
    margin-right: 0.5rem;
    background: #f3f6fa;
    border: 1px solid #c8d4e6;
    border-radius: 6px;
    font-size: 0.9rem;
    color: #344;
    vertical-align: middle;
}
.engine-version-picker label {
    display: inline-flex;
    align-items: center;
    gap: 0.2rem;
    cursor: pointer;
    user-select: none;
}
.engine-version-picker input[type="radio"] {
    margin: 0;
    cursor: pointer;
}
.engine-version-picker label:has(input:checked) {
    font-weight: bold;
    color: #1565c0;
}

/* ==== ボタン ==== */
.btn {
    padding: 0.6rem 1.2rem;
    border: none;
    border-radius: 6px;
    font-size: 0.95rem;
    cursor: pointer;
    transition: all 0.2s;
    font-weight: 500;
}
.btn.primary {
    background: #4a6cf7;
    color: white;
}
.btn.primary:hover { background: #3a5ce7; transform: translateY(-1px); }
.btn.secondary {
    background: #e9ecef;
    color: #333;
}
.btn.secondary:hover { background: #dde1e5; }
.btn.warn {
    background: #ff9800;
    color: white;
}
.btn.warn:hover { background: #e08800; transform: translateY(-1px); }
.btn.finalize {
    background: linear-gradient(135deg, #2ecc71 0%, #27ae60 100%);
    color: white;
    font-weight: 700;
    box-shadow: 0 2px 6px rgba(39, 174, 96, 0.35);
    border: 1px solid #229954;
}
.btn.finalize:hover {
    background: linear-gradient(135deg, #27ae60 0%, #1e8449 100%);
    transform: translateY(-1px);
    box-shadow: 0 4px 10px rgba(39, 174, 96, 0.45);
}
.btn:disabled { opacity: 0.5; cursor: not-allowed; transform: none !important; }
.btn-sm { padding: 0.35rem 0.75rem; font-size: 0.85rem; }

/* ==== ドロップゾーン（ドラッグ&ドロップでファイル受け取り）==== */
.drop-zone {
    border: 2px dashed #93c5fd;
    border-radius: 10px;
    padding: 1.5rem 1rem;
    text-align: center;
    background: #f0f7ff;
    cursor: pointer;
    transition: all 0.2s ease;
    position: relative;
}
.drop-zone:hover {
    border-color: #4a6cf7;
    background: #e8f0ff;
}
.drop-zone.drag-over {
    border-color: #1e40af;
    border-style: solid;
    background: linear-gradient(135deg, #dbeafe 0%, #bfdbfe 100%);
    transform: scale(1.02);
    box-shadow: 0 4px 12px rgba(30, 64, 175, 0.15);
}
.drop-zone.uploading {
    border-color: #f59e0b;
    background: #fffbeb;
    pointer-events: none;
}
.drop-zone.success {
    border-color: #10b981;
    background: #ecfdf5;
}
.drop-zone-content {
    pointer-events: none; /* ドロップイベントを親で確実に拾うため */
}
.drop-zone-content button { pointer-events: auto; } /* ボタンは別 */
.drop-zone-icon {
    font-size: 2.2rem;
    margin-bottom: 0.3rem;
    line-height: 1;
}
.drop-zone-main {
    font-size: 1rem;
    font-weight: 600;
    color: #1e3a8a;
    margin-bottom: 0.4rem;
}
.drop-zone-sub {
    font-size: 0.9rem;
    color: #555;
    margin-bottom: 0.3rem;
}
.drop-zone-hint {
    font-size: 0.8rem;
    color: #888;
}
.drop-zone.drag-over .drop-zone-icon { transform: scale(1.2); }

.form-group {
    margin-bottom: 1.25rem;
}
.form-group label {
    display: block;
    margin-bottom: 0.4rem;
    font-weight: 500;
    color: #333;
}
.form-group input[type="text"],
.form-group textarea {
    width: 100%;
    padding: 0.6rem 0.75rem;
    border: 1px solid #ccc;
    border-radius: 6px;
    font-size: 0.95rem;
    font-family: inherit;
}
.form-group textarea {
    resize: vertical;
    min-height: 100px;
}
.form-group small {
    display: block;
    margin-top: 0.3rem;
    color: #888;
    font-size: 0.8rem;
}

/* ==== ドライバーグリッド ==== */
.drivers-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
    gap: 0.5rem;
    background: white;
    border-radius: 8px;
    padding: 1rem;
    box-shadow: 0 1px 3px rgba(0,0,0,0.05);
}
.driver-card {
    display: flex;
    align-items: stretch;
    padding: 0.5rem 0.75rem;
    border-radius: 6px;
    border: 1px solid #e0e0e0;
    transition: all 0.15s;
    user-select: none;
    flex-direction: column;
    gap: 4px;
}
.driver-card:hover { border-color: #4a6cf7; }
.driver-card.absent {
    background: #ffe5e5;
    border-color: #ff6b6b;
}
.driver-card.absent .driver-name {
    color: #c0392b;
    text-decoration: line-through;
}
.driver-card.partial {
    background: #fff8e1;
    border-color: #ffb84a;
}
.driver-card.from-calendar { border-left: 3px solid #4a90e2; }

.driver-info { flex: 1; min-width: 0; }
.driver-name { font-weight: 500; }
.driver-meta {
    font-size: 0.8rem;
    color: #666;
    display: flex;
    gap: 0.5rem;
    margin-top: 2px;
}
.driver-card.absent .driver-meta { color: #c0392b; }
.driver-cat { padding: 1px 6px; border-radius: 3px; background: #e0e0e0; font-size: 0.75rem; }
.driver-cat.c100 { background: #d4edda; color: #155724; }
.driver-cat.c50 { background: #fff3cd; color: #856404; }
.driver-cat.spot { background: #d1ecf1; color: #0c5460; }
.driver-cat.nagano { background: #cce5ff; color: #004085; }
.driver-diff { font-size: 0.75rem; }
.driver-diff.plus { color: #0070c0; }
.driver-diff.minus { color: #ff0000; }
.driver-leave-count {
    font-size: 0.7rem;
    color: #888;
    margin-top: 2px;
}

/* 4チェックボックス: 1/2/3/全休 */
.off-checks {
    display: flex;
    gap: 4px;
    margin-top: 4px;
    flex-wrap: wrap;
}
.off-chk {
    display: inline-flex;
    align-items: center;
    gap: 2px;
    font-size: 0.72rem;
    padding: 2px 6px;
    border: 1px solid #ddd;
    border-radius: 4px;
    background: #fafafa;
    cursor: pointer;
    user-select: none;
}
.off-chk input { margin: 0; cursor: pointer; }
.off-chk:hover { background: #eef; }
.off-chk.k1.on { background: #ffd1d1; border-color: #ff6b6b; color: #b71c1c; }
.off-chk.k2.on { background: #fff3a0; border-color: #f5b941; color: #8c5a00; }
.off-chk.k3.on { background: #d0e8ff; border-color: #4a90e2; color: #0d47a1; }
.off-chk.full.on { background: #6c757d; border-color: #495057; color: white; }
.off-chk.leader { border-color: #f0c040; }
.off-chk.leader.on {
    background: linear-gradient(135deg, #fff7d6 0%, #ffe9a3 100%);
    border-color: #d4a017;
    color: #6b4f00;
    font-weight: 600;
    box-shadow: 0 0 0 1px #f0c040 inset;
}
.off-chk input:disabled + ,
.off-chk:has(input:disabled) { opacity: 0.4; cursor: not-allowed; }

/* ドライバーカードがリーダー指名されたら強調 */
.driver-card.is-leader {
    border-color: #d4a017;
    box-shadow: 0 0 0 2px #ffe9a3 inset, 0 2px 6px rgba(212, 160, 23, 0.18);
    background: linear-gradient(180deg, #fffbe9 0%, #ffffff 60%);
}
.driver-card.is-leader .driver-name::after {
    content: ' 👑';
    color: #d4a017;
    font-size: 1.1em;
}

/* チェックリスト上のリーダー強調 */
.checklist-row.is-leader {
    background: linear-gradient(180deg, #fffbe9 0%, #ffffff 100%);
    border-left: 3px solid #d4a017;
}
.checklist-row .leader-crown {
    margin-right: 2px;
    font-size: 0.95em;
    filter: drop-shadow(0 0 1px rgba(212, 160, 23, 0.6));
}

/* ==== 配車表レイアウト（2カラム）==== */
.dispatch-layout {
    display: grid;
    grid-template-columns: 1fr 320px;
    gap: 1rem;
    align-items: start;
}
@media (max-width: 1100px) {
    .dispatch-layout { grid-template-columns: 1fr; }
}

/* ==== 出勤者チェックリスト ==== */
.checklist-pane {
    background: white;
    border-radius: 8px;
    box-shadow: 0 1px 3px rgba(0,0,0,0.05);
    overflow: hidden;
    position: sticky;
    top: 1rem;
    max-height: calc(100vh - 2rem);
    display: flex;
    flex-direction: column;
}
.checklist-header {
    background: #4a6cf7;
    color: white;
    padding: 0.75rem 1rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-shrink: 0;
}
.checklist-header h3 { font-size: 1rem; }
.checklist-legend { display: flex; gap: 0.4rem; }
.legend-item {
    font-size: 0.7rem;
    padding: 2px 6px;
    border-radius: 3px;
    background: rgba(255,255,255,0.2);
}
.checklist-body {
    overflow-y: auto;
    flex: 1;
    padding: 0.5rem;
}
.checklist-row {
    display: grid;
    grid-template-columns: 1fr auto 24px 24px 24px 30px 30px;
    gap: 3px;
    padding: 6px 6px;
    border-bottom: 1px solid #f0f0f0;
    align-items: center;
    transition: background 0.15s;
}
.checklist-revenue {
    font-size: 0.72rem;
    font-weight: 600;
    color: #555;
    white-space: nowrap;
    text-align: right;
    min-width: 50px;
}
.checklist-revenue.high { color: #0070c0; }
.checklist-revenue.low { color: #c0392b; }
.checklist-row:hover { background: #f8fafd; }
.checklist-name {
    font-size: 0.85rem;
    font-weight: 500;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    cursor: pointer;
    padding: 2px 4px;
    border-radius: 3px;
    transition: background 0.1s;
}
.checklist-name:hover {
    background: #4a6cf7;
    color: white;
}
.checklist-name:hover .cat-badge { background: rgba(255,255,255,0.25) !important; color: white !important; }
.checklist-name:active { transform: scale(0.96); }
.checklist-name .cat-badge {
    font-size: 0.65rem;
    padding: 1px 4px;
    border-radius: 2px;
    margin-right: 4px;
    vertical-align: middle;
}
.checklist-name .cat-100 { background: #d4edda; color: #155724; }
.checklist-name .cat-50 { background: #fff3cd; color: #856404; }
.checklist-name .cat-spot { background: #d1ecf1; color: #0c5460; }
.checklist-name .cat-nagano { background: #cce5ff; color: #004085; }
.kentei-check {
    height: 24px;
    border: 1.5px solid #ccc;
    border-radius: 4px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    font-size: 0.65rem;
    font-weight: 600;
    color: #999;
    user-select: none;
    transition: all 0.15s;
    padding: 0 2px;
}
.kentei-check:hover { border-color: #4a6cf7; }
.kentei-check.checked-1 { background: #ffe5e5; border-color: #ff6b6b; color: #c0392b; }
.kentei-check.checked-2 { background: #fff3cd; border-color: #ffc107; color: #856404; }
.kentei-check.checked-3 { background: #d1ecf1; border-color: #17a2b8; color: #0c5460; }
.kentei-check.checked-dr { background: #e7d6ff; border-color: #8b5cf6; color: #6b21a8; }
.kentei-check.checked-dp { background: #d1f5d3; border-color: #22c55e; color: #14532d; }

.legend-item.legend-dr { background: rgba(139, 92, 246, 0.5); }
.legend-item.legend-dp { background: rgba(34, 197, 94, 0.5); }
.checklist-row.all-checked {
    background: #f0f4ff;
    opacity: 0.55;
    text-decoration: line-through;
    text-decoration-color: #aaa;
}

/* ==== 配車表 ==== */
.dispatch-container {
    background: white;
    border-radius: 8px;
    box-shadow: 0 1px 3px rgba(0,0,0,0.05);
    overflow: hidden;
}
.dispatch-table {
    width: 100%;
    border-collapse: collapse;
}
.dispatch-table th {
    background: #4a6cf7;
    color: white;
    padding: 0.75rem 0.5rem;
    text-align: left;
    font-weight: 600;
    font-size: 0.9rem;
    position: sticky;
    top: 0;
    z-index: 1;
}
.dispatch-table td {
    padding: 0.5rem;
    border-bottom: 1px solid #eee;
    font-size: 0.9rem;
}
.dispatch-table tr.kentei-1 { background: #fff; }
.dispatch-table tr.kentei-2 { background: #f8fafd; }
.dispatch-table tr.kentei-3 { background: #fafafa; }
.dispatch-table tr:hover { background: #f0f4ff; }
.dispatch-table tr.vizamil td.hospital { color: #c0392b; font-weight: 500; }
.dispatch-table td.kentei-label {
    font-weight: 700;
    color: #4a6cf7;
    text-align: center;
}
.dispatch-table td.hospital { font-weight: 500; }
.dispatch-table td.driver-cell { min-width: 220px; position: relative; }
.driver-input-wrap {
    display: flex;
    align-items: stretch;
    gap: 2px;
}
.driver-input {
    flex: 1;
    padding: 0.4rem 0.5rem;
    border: 1px solid #ddd;
    border-radius: 4px 0 0 4px;
    font-size: 0.9rem;
    background: #fffee6;
    min-width: 0;
}
.driver-input:focus {
    outline: none;
    border-color: #4a6cf7;
    background: white;
}
.driver-input.filled { background: #d4edda; }
.driver-input.spot { color: #008000; font-weight: bold; }
.driver-input.nagano { color: #0000ff; font-weight: bold; }
.driver-dropdown-btn {
    border: 1px solid #ddd;
    border-left: 0;
    border-radius: 0 4px 4px 0;
    background: #f5f5f5;
    color: #555;
    padding: 0 0.5rem;
    cursor: pointer;
    font-size: 0.75rem;
    user-select: none;
}
.driver-dropdown-btn:hover { background: #4a6cf7; color: white; }

/* アクティブ行の強調表示（クリック割当のターゲットを明確に） */
.dispatch-table tr.active-row { background: #fff3cd !important; }
.dispatch-table tr.active-row td { box-shadow: inset 0 0 0 1px #f5b941; }
.dispatch-table td.driver-cell.active-cell .driver-input { border-color: #f5b941; box-shadow: 0 0 0 2px rgba(245,185,65,0.3); }

/* フラッシュメッセージ */
.flash-banner {
    position: fixed;
    top: 1rem;
    left: 50%;
    transform: translateX(-50%) translateY(-150%);
    background: #4a6cf7;
    color: white;
    padding: 0.75rem 1.25rem;
    border-radius: 8px;
    font-size: 0.9rem;
    box-shadow: 0 4px 12px rgba(0,0,0,0.2);
    z-index: 9999;
    transition: transform 0.25s ease-out;
    max-width: 90%;
    text-align: center;
}
.flash-banner.show { transform: translateX(-50%) translateY(0); }
.flash-banner.warn { background: #f5b941; color: #111; }
.flash-banner.error { background: #dc3545; }

/* ==== サジェストポップアップ ==== */
.suggest-popup {
    position: fixed;
    background: white;
    border: 1px solid #ddd;
    border-radius: 6px;
    box-shadow: 0 4px 12px rgba(0,0,0,0.15);
    max-height: 300px;
    overflow-y: auto;
    z-index: 1000;
    min-width: 220px;
}
.suggest-item {
    padding: 0.5rem 0.75rem;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.5rem;
    border-bottom: 1px solid #f0f0f0;
}
.suggest-item:hover, .suggest-item.active { background: #f0f4ff; }
.suggest-item .sug-name { font-weight: 500; }
.suggest-item .sug-meta { font-size: 0.75rem; color: #999; }
.hidden { display: none !important; }

/* ==== モーダル ==== */
.modal {
    position: fixed;
    top: 0; left: 0; right: 0; bottom: 0;
    background: rgba(0,0,0,0.5);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 2000;
}
.modal-content {
    background: white;
    border-radius: 8px;
    max-width: 90%;
    max-height: 80%;
    width: 800px;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}
.modal-header {
    background: #4a6cf7;
    color: white;
    padding: 1rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
}
.modal-close {
    background: none;
    border: none;
    color: white;
    font-size: 1.2rem;
    cursor: pointer;
}
#log-content {
    flex: 1;
    padding: 1rem;
    overflow: auto;
    font-family: 'SF Mono', Consolas, monospace;
    font-size: 0.85rem;
    background: #f8f9fa;
    white-space: pre-wrap;
}

/* ==== 結果サマリ ==== */
#result-summary, #driver-summary {
    background: white;
    border-radius: 8px;
    padding: 1rem;
    margin-bottom: 1rem;
    box-shadow: 0 1px 3px rgba(0,0,0,0.05);
}
.summary-card {
    display: inline-block;
    padding: 0.75rem 1.25rem;
    margin: 0.25rem;
    border-radius: 6px;
    background: #f0f4ff;
    color: #4a6cf7;
    font-weight: 500;
}
.summary-card.red { background: #ffe5e5; color: #c0392b; }

/* === 結果タブのコンパクトサマリ（pill形式）=== */
.result-summary-compact {
    display: flex;
    flex-wrap: wrap;
    gap: 0.4rem;
    align-items: center;
    background: white;
    border-radius: 8px;
    padding: 0.6rem 1rem;
    margin-bottom: 0.75rem;
    box-shadow: 0 1px 3px rgba(0,0,0,0.05);
}
.summary-pill {
    display: inline-block;
    padding: 0.3rem 0.7rem;
    border-radius: 999px;
    background: #f0f4ff;
    color: #4a6cf7;
    font-size: 0.85rem;
    font-weight: 500;
}
.summary-pill.ok { background: #d4edda; color: #155724; }
.summary-pill.red { background: #ffe5e5; color: #c0392b; }
.summary-pill.kentei { background: #fff3cd; color: #856404; }

/* === 結果タブの配車表（Excelフォーマット風）=== */
#result-table-wrap {
    background: white;
    border-radius: 8px;
    box-shadow: 0 1px 3px rgba(0,0,0,0.05);
    overflow: auto;
    margin-bottom: 1rem;
}
.result-table { width: 100%; border-collapse: collapse; font-size: 0.92rem; }
.result-table thead th {
    position: sticky; top: 0;
    background: #4a6cf7; color: white;
    padding: 0.55rem 0.5rem;
    text-align: center;
    font-weight: 600;
    border: 1px solid #3955d8;
}
.result-table tbody td {
    padding: 0.45rem 0.6rem;
    border: 1px solid #e8e8e8;
    vertical-align: middle;
}
.result-table .seq { text-align: center; color: #888; width: 3.5rem; }
.result-table .kentei-label {
    text-align: center; font-weight: 600; width: 3rem;
    background: #f5f7ff;
}
.result-table tr.kentei-1 .kentei-label { background: #fff0f0; color: #c0392b; }
.result-table tr.kentei-2 .kentei-label { background: #fffbe5; color: #8c5a00; }
.result-table tr.kentei-3 .kentei-label { background: #e8f3ff; color: #0d47a1; }
.result-table .hospital { font-weight: 500; }
.result-table .edaban { text-align: center; color: #666; width: 4rem; }
.result-table .driver { font-weight: 500; }
.result-table .driver.driver-spot { color: #008000; }
.result-table .driver.driver-nagano { color: #0000ff; }
.result-table .driver.driver-50 { color: #c2410c; }
.result-table .driver .empty { color: #aaa; font-style: italic; font-weight: normal; }
.result-table .qty { text-align: center; width: 4rem; }
.result-table .time { font-family: ui-monospace, Menlo, Consolas, monospace; width: 9rem; }
.result-table tr.empty-slot td { background: #fff7e6; }
.result-table tr.vizamil .hospital { color: #d32f2f; font-weight: 600; }

.driver-row {
    display: flex;
    justify-content: space-between;
    padding: 0.4rem 0.75rem;
    border-bottom: 1px solid #eee;
}
.driver-row:hover { background: #f0f4ff; }

/* === 結果タブの整合性チェックバナー === */
.validation-banner {
    display: flex;
    gap: 0.85rem;
    padding: 0.85rem 1rem;
    border-radius: 8px;
    margin-bottom: 0.75rem;
    box-shadow: 0 1px 3px rgba(0,0,0,0.05);
    border-left: 5px solid;
    align-items: flex-start;
}
.validation-banner.hidden { display: none; }
.validation-banner .vb-icon { font-size: 1.6rem; line-height: 1; flex-shrink: 0; }
.validation-banner .vb-content { flex: 1; min-width: 0; }
.validation-banner .vb-title { font-weight: 600; font-size: 1rem; margin-bottom: 0.4rem; }
.validation-banner .vb-list {
    list-style: none;
    padding: 0;
    margin: 0;
    font-size: 0.9rem;
}
.validation-banner .vb-list li {
    padding: 0.3rem 0;
    border-top: 1px solid rgba(0,0,0,0.06);
}
.validation-banner .vb-list li:first-child { border-top: 0; }
.validation-banner .vb-list li strong { color: inherit; }
.validation-banner .vb-details { font-size: 0.82rem; color: #555; margin-top: 0.15rem; }
.validation-banner .vb-note {
    font-size: 0.78rem;
    color: #888;
    margin-top: 0.15rem;
    font-style: italic;
}
.validation-banner .btn { margin-top: 0.75rem; }
.validation-banner .vb-msg { font-size: 0.88rem; color: #555; }

.validation-banner.ok {
    background: #d4edda;
    border-left-color: #28a745;
    color: #155724;
}
.validation-banner.error {
    background: #f8d7da;
    border-left-color: #dc3545;
    color: #721c24;
}
.validation-banner.error .vb-details { color: #721c24; }
.validation-banner.warn {
    background: #fff3cd;
    border-left-color: #ffc107;
    color: #8c5a00;
}
.validation-banner.warn .vb-details { color: #8c5a00; }
.validation-banner.info {
    background: #d1ecf1;
    border-left-color: #17a2b8;
    color: #0c5460;
}

/* === 結果タブの小タブ === */
.sub-tabs {
    display: flex;
    gap: 4px;
    margin-bottom: 0.75rem;
    border-bottom: 2px solid #e0e0e0;
}
.sub-tab-btn {
    background: transparent;
    border: none;
    padding: 0.55rem 1.1rem;
    font-size: 0.92rem;
    color: #666;
    cursor: pointer;
    border-bottom: 3px solid transparent;
    margin-bottom: -2px;
    transition: all 0.15s;
}
.sub-tab-btn:hover { background: #f0f4ff; color: #4a6cf7; }
.sub-tab-btn.active {
    color: #4a6cf7;
    border-bottom-color: #4a6cf7;
    font-weight: 600;
}
.sub-tab-content { display: none; }
.sub-tab-content.active { display: block; }

/* === ドライバー別リスト === */
.driver-list-summary {
    background: white;
    padding: 0.6rem 1rem;
    border-radius: 6px;
    box-shadow: 0 1px 3px rgba(0,0,0,0.05);
    margin-bottom: 0.75rem;
    color: #555;
    font-size: 0.95rem;
}
.driver-list-summary strong { color: #4a6cf7; font-size: 1.1rem; padding: 0 2px; }
.driver-list {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(360px, 1fr));
    gap: 0.6rem;
}
.driver-card-result {
    background: white;
    border-radius: 8px;
    box-shadow: 0 1px 3px rgba(0,0,0,0.06);
    border-left: 4px solid #4a6cf7;
    padding: 0.7rem 0.9rem;
}
.driver-card-result .driver-card-header {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    margin-bottom: 0.5rem;
    flex-wrap: wrap;
}
.driver-card-result .driver-card-name {
    font-weight: 600;
    font-size: 1rem;
    flex: 1;
}
.driver-card-result .cat-badge {
    font-size: 0.7rem;
    padding: 2px 6px;
    border-radius: 3px;
}
.driver-card-result .cat-100 { background: #d4edda; color: #155724; }
.driver-card-result .cat-50 { background: #fff3cd; color: #856404; }
.driver-card-result .cat-spot { background: #d1ecf1; color: #0c5460; }
.driver-card-result .cat-nagano { background: #cce5ff; color: #004085; }
.driver-card-result .driver-card-stats { display: flex; gap: 4px; flex-shrink: 0; }
.driver-card-result .stat {
    background: #f0f4ff;
    color: #4a6cf7;
    padding: 2px 8px;
    border-radius: 999px;
    font-size: 0.78rem;
    font-weight: 500;
}
.driver-card-result .stat.rev { background: #fff3cd; color: #8c5a00; }
.driver-card-result .driver-card-kenteis { display: flex; flex-direction: column; gap: 4px; }
.kentei-group {
    display: flex;
    align-items: flex-start;
    gap: 6px;
    padding: 4px 0;
}
.kentei-group .kentei-label-pill {
    flex-shrink: 0;
    padding: 2px 8px;
    border-radius: 4px;
    font-size: 0.75rem;
    font-weight: 600;
    background: #f5f5f5;
}
.kentei-group.k1 .kentei-label-pill { background: #ffe5e5; color: #c0392b; }
.kentei-group.k2 .kentei-label-pill { background: #fff3cd; color: #8c5a00; }
.kentei-group.k3 .kentei-label-pill { background: #d1ecf1; color: #0c5460; }
.hosp-chip-list {
    display: flex;
    flex-wrap: wrap;
    gap: 4px;
    flex: 1;
}
.hosp-chip {
    display: inline-flex;
    align-items: center;
    gap: 3px;
    padding: 2px 7px;
    background: #fafafa;
    border: 1px solid #e0e0e0;
    border-radius: 4px;
    font-size: 0.82rem;
}
.hosp-chip.manual { background: #fff8e1; border-color: #ffcc80; }
.hosp-chip.auto { background: #e8f5e9; border-color: #a5d6a7; }
.hosp-chip.mixed { background: #f3e5f5; border-color: #ce93d8; }

/* 手入力/自動バッジ */
.src-badge {
    display: inline-block;
    padding: 0 4px;
    border-radius: 3px;
    font-size: 0.7rem;
    font-weight: 700;
    margin-right: 3px;
    line-height: 1.4;
}
.src-badge.src-manual { background: #ff9800; color: white; }
.src-badge.src-auto { background: #4caf50; color: white; }
.src-badge.src-mixed { background: #9c27b0; color: white; }
/* 結果テーブルのセル内バッジ */
.result-table .driver .src-badge { margin-right: 5px; vertical-align: middle; }

/* ドライバー枝番（3桁または5桁） — 結果タブ内のみ表示 */
.driver-edaban {
    color: #1e3a8a;
    font-size: 0.85em;
    font-weight: 600;
    margin-right: 4px;
    padding: 1px 5px;
    background: #e0e7ff;
    border-radius: 3px;
    font-variant-numeric: tabular-nums;
    letter-spacing: 0.02em;
}

/* 病院運賃（ドライバー別タブ内、病院チップに併記） */
.hosp-chip .hosp-rev {
    color: #1565c0;
    font-size: 0.85em;
    font-weight: 600;
    margin-left: 4px;
    font-variant-numeric: tabular-nums;
}
.hosp-chip .hosp-count {
    background: #4a6cf7;
    color: white;
    padding: 0 4px;
    border-radius: 3px;
    font-size: 0.72rem;
    margin-left: 2px;
}
.hosp-chip .hosp-time {
    color: #999;
    font-size: 0.72rem;
    font-family: ui-monospace, Menlo, Consolas, monospace;
    margin-left: 4px;
}
/* 当月この病院への配車回数（前日まで） */
.hosp-chip .hosp-visits {
    color: #2e7d32;
    background: #e8f5e9;
    border-radius: 8px;
    padding: 1px 6px;
    font-size: 0.72rem;
    font-weight: 700;
    margin-left: 4px;
}
.hosp-chip .hosp-visits.zero {
    color: #b35900;
    background: #fff3e0;
}
.empty-state {
    text-align: center;
    color: #999;
    padding: 2rem;
    background: white;
    border-radius: 8px;
}

/* === 病院別マトリクス（小タブ3）=== */
.hosp-mx-summary {
    margin: 0 0 0.6rem 0;
    color: #555;
    font-size: 0.9rem;
}
.hosp-mx-summary strong { color: #1f2937; font-size: 1rem; }

.hosp-mx-table {
    width: 100%;
    border-collapse: collapse;
    background: white;
    font-size: 0.88rem;
}
.hosp-mx-table thead th {
    background: #1f2937;
    color: white;
    padding: 0.55rem 0.5rem;
    text-align: left;
    font-weight: 600;
    position: sticky;
    top: 0;
    z-index: 1;
}
.hosp-mx-table thead .hosp-mx-name-col { width: 20%; }
.hosp-mx-table thead .hosp-mx-k1-col,
.hosp-mx-table thead .hosp-mx-k2-col,
.hosp-mx-table thead .hosp-mx-k3-col { width: 26.66%; }

.hosp-mx-table tbody tr { border-bottom: 1px solid #e5e7eb; }
.hosp-mx-table tbody tr:nth-child(even) { background: #fafafa; }
.hosp-mx-table tbody tr:hover { background: #f0f7ff; }

.hosp-mx-name {
    padding: 0.5rem 0.6rem;
    font-weight: 600;
    color: #1f2937;
    vertical-align: top;
    border-right: 1px solid #e5e7eb;
}
.hosp-mx-name.vizamil { color: #c0392b; }
.hosp-mx-count {
    margin-left: 6px;
    font-size: 0.75rem;
    color: #888;
    font-weight: 500;
}

.hosp-mx-cell {
    padding: 0.4rem 0.5rem;
    vertical-align: top;
    border-right: 1px solid #f0f0f0;
}
.hosp-mx-cell.empty-cell {
    color: #ccc;
    text-align: center;
}

.hosp-mx-entry {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 2px 0;
}
.hosp-mx-entry + .hosp-mx-entry {
    border-top: 1px dashed #e5e7eb;
    margin-top: 2px;
    padding-top: 4px;
}
.hosp-mx-entry.is-empty { opacity: 0.7; }

.hosp-mx-time {
    flex-shrink: 0;
    font-family: monospace;
    font-size: 0.78rem;
    color: #666;
    min-width: 5.2em;
}
.hosp-mx-driver {
    font-weight: 500;
    color: #1f2937;
}
.hosp-mx-driver.driver-spot { color: #008000; font-weight: 600; }
.hosp-mx-driver.driver-nagano { color: #1e40af; font-weight: 600; }
.hosp-mx-driver.driver-50 { color: #c2410c; }

.hosp-mx-stack {
    display: inline-block;
    margin-left: 5px;
    padding: 0 5px;
    background: #fde68a;
    border-radius: 3px;
    font-size: 0.72rem;
    font-weight: 600;
    color: #92400e;
}

/* === 印刷用 === */
@media print {
    /* ① 不要要素を非表示 */
    header, nav.tabs, .sub-tabs, .section-header > div, #result-summary,
    .modal, #driver-summary, .hosp-mx-summary, .app-footer { display: none !important; }
    .tab-content:not(.active) { display: none !important; }
    main { padding: 0; }

    /* ② 印刷色設定を最大限尊重させる（ブラウザ既定で背景色OFFになるのを防ぐ） */
    html, body, .result-table, .result-table * {
        -webkit-print-color-adjust: exact !important;
        print-color-adjust: exact !important;
        color-adjust: exact !important;
    }

    /* ③ 結果テーブル本体: 全セルに必ず枠線を入れる（背景色が出ない印刷機への保険） */
    .result-table { font-size: 10pt; border-collapse: collapse !important; }
    .result-table th, .result-table td {
        border: 0.7pt solid #000 !important;
        padding: 3pt 5pt !important;
    }

    /* ④ 表ヘッダ: 黒文字+太字+太枠で「背景色未印刷でも読める」ようにする
       ※ 背景印刷OFFでも白背景に黒太字が残るので確実に視認可能 */
    .result-table thead th {
        background: #d9d9d9 !important;
        color: #000 !important;
        font-weight: 700 !important;
        border: 1.2pt solid #000 !important;
    }

    /* ⑤ 検定区切り行: 同じく太字+太枠で背景なしでも視認可能 */
    .kentei-separator td {
        background: #ececec !important;
        color: #000 !important;
        font-weight: 700 !important;
        border-top: 1.5pt solid #000 !important;
        border-bottom: 1.5pt solid #000 !important;
    }

    @page { margin: 1cm; size: A4; }
}

/* ==== 検定区切り ==== */
.kentei-separator {
    background: #e8ecf5 !important;
    font-weight: 700;
    color: #4a6cf7;
    text-align: center;
}
.kentei-separator td { padding: 0.5rem !important; }

/* ==== レスポンシブ調整（iPad / 狭幅ブラウザ対応）==== */
@media (max-width: 900px) {
    header { padding: 0.75rem 1rem; }
    header h1 { font-size: 1.2rem; }
    main { padding: 0.6rem; }
    .section-header h2 { font-size: 1.1rem; }
    .drivers-grid {
        grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
        gap: 0.4rem;
    }
    .driver-list {
        grid-template-columns: 1fr;
    }
    .dispatch-layout { grid-template-columns: 1fr; }
}

@media (max-width: 600px) {
    header h1 { font-size: 1.05rem; }
    .header-info { font-size: 0.78rem; gap: 0.35rem; }
    .header-info select { padding: 0.25rem 0.4rem; font-size: 0.8rem; max-width: 110px; }
    .btn { padding: 0.45rem 0.8rem; font-size: 0.85rem; }
    .btn.btn-sm { padding: 0.3rem 0.6rem; font-size: 0.78rem; }
    .tab-btn { padding: 0.5rem 0.8rem; font-size: 0.9rem; }
    .drivers-grid {
        grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
    }
    .driver-card { padding: 0.4rem 0.5rem; }
    .driver-card .driver-name { font-size: 0.9rem; }
    .off-chk { font-size: 0.7rem; padding: 1px 4px; }
    .dispatch-table { font-size: 0.8rem; }
    .dispatch-table td { padding: 0.3rem 0.4rem; }
    .driver-input { font-size: 0.85rem; }
    .summary-pill { font-size: 0.75rem; padding: 0.2rem 0.5rem; }
    .sub-tab-btn { padding: 0.45rem 0.8rem; font-size: 0.85rem; }
    .driver-card-result { padding: 0.55rem 0.7rem; }
    .driver-card-result .driver-card-name { font-size: 0.92rem; }
}

/* ===== 自動配車 実行前 確認モーダル ===== */
.pre-auto-check {
    display: flex;
    align-items: center;
    gap: 0.6rem;
    padding: 0.65rem 0.75rem;
    margin-bottom: 0.5rem;
    border: 1px solid #e5e7eb;
    border-radius: 6px;
    background: #f9fafb;
    cursor: pointer;
    user-select: none;
    transition: background 0.15s, border-color 0.15s;
}
.pre-auto-check:hover { background: #f3f4f6; }
.pre-auto-check input[type="checkbox"] {
    width: 18px;
    height: 18px;
    margin: 0;
    cursor: pointer;
    flex: 0 0 auto;
}
.pre-auto-check span { font-size: 0.95em; color: #1f2937; line-height: 1.3; }
.pre-auto-check:has(input:checked) {
    background: #ecfdf5;
    border-color: #6ee7b7;
}
.pre-auto-check:has(input:checked) span { color: #065f46; font-weight: 600; }

/* ==== ④マスタ管理タブ ==== */

.master-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: 12px;
    margin-bottom: 12px;
}

.master-funnel-warning {
    background: #fff3cd;
    border: 1px solid #ffc107;
    color: #664d03;
    padding: 12px 16px;
    border-radius: 6px;
    font-size: 14px;
    line-height: 1.6;
}

.master-funnel-warning code {
    background: rgba(0, 0, 0, 0.05);
    padding: 2px 6px;
    border-radius: 3px;
    font-family: 'SF Mono', Menlo, monospace;
}

.master-sub {
    display: none;
}

.master-sub.active {
    display: block;
}

.master-toolbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 8px;
    padding: 8px 12px;
    background: #f8f9fa;
    border-radius: 6px;
}

.master-counter {
    color: #495057;
    font-size: 14px;
}

.master-table-wrap {
    overflow-x: auto;
    border: 1px solid #dee2e6;
    border-radius: 6px;
}

.master-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 14px;
}

.master-table th,
.master-table td {
    padding: 8px 12px;
    text-align: left;
    border-bottom: 1px solid #dee2e6;
    white-space: nowrap;
}

.master-table thead th {
    background: #e9ecef;
    font-weight: 600;
    position: sticky;
    top: 0;
}

.master-table tbody tr:hover {
    background: #f1f3f5;
}

.master-table tbody tr.master-row-hidden {
    opacity: 0.45;
    background: #f8f9fa;
}

.master-table .master-row-actions {
    display: flex;
    gap: 4px;
}

.master-table .master-role-badge {
    display: inline-block;
    padding: 2px 8px;
    border-radius: 12px;
    font-size: 12px;
    font-weight: 600;
}

.master-table .master-role-regular { background: #d1e7dd; color: #0f5132; }
.master-table .master-role-spot    { background: #fff3cd; color: #664d03; }
.master-table .master-role-nagano  { background: #cfe2ff; color: #084298; }

/* ==== ドロワー ==== */

.master-drawer-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.3);
    z-index: 999;
}

.master-drawer-overlay.open {
    display: block;
}

.master-drawer {
    position: fixed;
    top: 0;
    right: 0;
    height: 100vh;
    width: 420px;
    max-width: 90vw;
    background: white;
    box-shadow: -4px 0 16px rgba(0, 0, 0, 0.12);
    transform: translateX(100%);
    transition: transform 0.22s ease-out;
    display: flex;
    flex-direction: column;
    z-index: 1000;
}

.master-drawer.open {
    transform: translateX(0);
}

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

.master-drawer-header h3 {
    margin: 0;
    font-size: 18px;
}

.master-drawer-close {
    background: none;
    border: none;
    font-size: 24px;
    cursor: pointer;
    color: #6c757d;
    padding: 0 8px;
}

.master-drawer-body {
    flex: 1;
    overflow-y: auto;
    padding: 20px;
}

.master-drawer-footer {
    display: flex;
    justify-content: flex-end;
    gap: 8px;
    padding: 12px 20px;
    border-top: 1px solid #dee2e6;
}

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

.master-form-group label {
    display: block;
    font-weight: 600;
    margin-bottom: 4px;
    font-size: 14px;
    color: #212529;
}

.master-form-group label .required {
    color: #dc3545;
    margin-left: 2px;
}

.master-form-group input[type="text"],
.master-form-group input[type="number"],
.master-form-group select {
    width: 100%;
    padding: 8px 10px;
    border: 1px solid #ced4da;
    border-radius: 4px;
    font-size: 14px;
    box-sizing: border-box;
}

.master-form-group .master-radio-group {
    display: flex;
    flex-wrap: wrap;
    gap: 12px;
}

.master-form-group .master-radio-group label {
    font-weight: normal;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    gap: 4px;
}

.master-form-group .master-fixed-value {
    padding: 8px 10px;
    background: #e9ecef;
    border-radius: 4px;
    color: #495057;
    font-size: 14px;
}

.master-form-error {
    color: #dc3545;
    font-size: 12px;
    margin-top: 4px;
}

.master-form-global-error {
    background: #f8d7da;
    color: #842029;
    padding: 8px 12px;
    border-radius: 4px;
    margin-bottom: 12px;
    font-size: 14px;
}


/* ==== 保存ドロップダウン（結果タブ右上）==== */

.save-dropdown {
    position: relative;
    display: inline-block;
}

.save-dropdown-menu {
    display: none;
    position: absolute;
    top: calc(100% + 4px);
    right: 0;
    min-width: 180px;
    background: white;
    border: 1px solid #dee2e6;
    border-radius: 6px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.12);
    z-index: 100;
    overflow: hidden;
}

.save-dropdown.open .save-dropdown-menu {
    display: block;
}

.save-dropdown-item {
    display: block;
    width: 100%;
    padding: 10px 16px;
    background: none;
    border: none;
    text-align: left;
    font-size: 14px;
    cursor: pointer;
    color: #212529;
}

.save-dropdown-item:hover {
    background: #f1f3f5;
}

.save-dropdown-csv {
    display: none;
}

.save-dropdown-csv.visible {
    display: block;
}

/* ==== CSV 形式選択ダイアログ ==== */

.csv-format-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.3);
    z-index: 999;
}

.csv-format-overlay.open {
    display: block;
}

.csv-format-dialog {
    display: none;
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 420px;
    max-width: 90vw;
    background: white;
    border-radius: 8px;
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.18);
    z-index: 1000;
}

.csv-format-dialog.open {
    display: block;
}

.csv-format-dialog-header {
    padding: 16px 20px;
    border-bottom: 1px solid #dee2e6;
}

.csv-format-dialog-header h3 {
    margin: 0;
    font-size: 18px;
}

.csv-format-dialog-body {
    padding: 16px 20px;
}

.csv-format-option {
    display: block;
    padding: 12px;
    margin-bottom: 8px;
    border: 1px solid #dee2e6;
    border-radius: 6px;
    cursor: pointer;
}

.csv-format-option:hover {
    background: #f8f9fa;
}

.csv-format-option input[type="radio"] {
    margin-right: 8px;
}

.csv-format-option-title {
    font-weight: 600;
    display: inline;
}

.csv-format-option-desc {
    display: block;
    margin-top: 4px;
    margin-left: 24px;
    font-size: 12px;
    color: #6c757d;
}

.csv-format-dialog-footer {
    display: flex;
    justify-content: flex-end;
    gap: 8px;
    padding: 12px 20px;
    border-top: 1px solid #dee2e6;
}
