/* =====================================================================
 *  配車予定表アプリ（CakePHP版）  スタイル（1920×900 を想定）
 * ===================================================================== */
* { box-sizing: border-box; }

:root {
    --c-primary: #2563eb;
    --c-primary-d: #1d4ed8;
    --c-danger: #dc2626;
    --c-border: #d1d5db;
    --c-bg: #f3f4f6;
    --c-head: #1f2937;
    --c-driver: #e0f2fe;
    --c-vehicle: #ede9fe;
    --c-job: #dcfce7;
    --c-note: #fef3c7;
}

html, body {
    margin: 0;
    font-family: "Segoe UI", "Hiragino Kaku Gothic ProN", "Meiryo", sans-serif;
    background: var(--c-bg);
    color: #111827;
    font-size: 14px;
}

/* ---- ヘッダ ---- */
.app-header {
    display: flex;
    align-items: center;
    gap: 24px;
    background: var(--c-head);
    color: #fff;
    padding: 0 20px;
    height: 52px;
}
.app-header__brand { font-weight: bold; font-size: 16px; }
.app-header__brand-link { color: #fff; text-decoration: none; }
.app-header__brand-link:hover { color: #d1d5db; }
.app-header__spacer { flex: 1; }
.app-header__logout { display: flex; align-items: center; gap: 10px; }
.app-header__user { color: #9ca3af; }

/* ---- ハンバーガーボタン ---- */
.app-header__menu-btn {
    background: none; border: 0; cursor: pointer; padding: 0;
    width: 38px; height: 38px; border-radius: 6px;
    display: inline-flex; align-items: center; justify-content: center;
}
.app-header__menu-btn:hover { background: rgba(255, 255, 255, .12); }
.app-header__menu-icon, .app-header__menu-icon::before, .app-header__menu-icon::after {
    display: block; width: 20px; height: 2px; background: #fff; border-radius: 2px; transition: .2s ease;
}
.app-header__menu-icon { position: relative; }
.app-header__menu-icon::before, .app-header__menu-icon::after { content: ''; position: absolute; left: 0; }
.app-header__menu-icon::before { top: -6px; }
.app-header__menu-icon::after { top: 6px; }
/* 開いているときは × に変形 */
body.menu-open .app-header__menu-icon { background: transparent; }
body.menu-open .app-header__menu-icon::before { top: 0; transform: rotate(45deg); }
body.menu-open .app-header__menu-icon::after { top: 0; transform: rotate(-45deg); }

/* ---- スライドメニュー ---- */
.app-menu {
    position: fixed; top: 52px; left: 0; z-index: 50;
    width: 264px; max-width: 82vw; max-height: calc(100vh - 52px); overflow-y: auto;
    background: #fff; border-right: 1px solid var(--c-border);
    box-shadow: 2px 0 14px rgba(0, 0, 0, .14); padding: 12px;
    visibility: hidden; transform: translateX(-100%);
    transition: transform .2s ease, visibility .2s ease;
}
body.menu-open .app-menu { visibility: visible; transform: translateX(0); }
.app-menu__home {
    display: block; font-weight: bold; color: var(--c-head); text-decoration: none;
    padding: 10px 12px; border-radius: 8px;
}
.app-menu__home:hover { background: #f3f4f6; }
.app-menu__group { margin-top: 14px; }
.app-menu__heading { font-size: 12px; color: #9ca3af; margin: 0 0 4px; padding: 0 12px; letter-spacing: .04em; }
.app-menu__link { display: block; color: #111827; text-decoration: none; padding: 9px 12px; border-radius: 8px; font-size: 14px; }
.app-menu__link:hover { background: #eff6ff; color: var(--c-primary); }
.app-menu__overlay { position: fixed; inset: 52px 0 0 0; z-index: 40; background: rgba(0, 0, 0, .35); }

/* ---- メイン ---- */
.app-main { max-width: 1100px; margin: 24px auto; padding: 0 20px; }
.app-main--wide { max-width: 1880px; }
.app-main--center { display: flex; justify-content: center; align-items: center; min-height: calc(100vh - 100px); }

.page-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 16px; }
.page-head h1 { font-size: 20px; margin: 0; }
.page-head__actions { display: flex; gap: 10px; }
.section-title { font-size: 16px; margin: 28px 0 12px; }

/* ---- ホーム（タイルメニュー） ---- */
.home-tiles {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
    gap: 16px;
}
.home-tile {
    display: flex;
    flex-direction: column;
    gap: 6px;
    background: #fff;
    border: 1px solid var(--c-border);
    border-radius: 10px;
    padding: 20px 18px;
    text-decoration: none;
    color: inherit;
    transition: border-color .15s, box-shadow .15s, transform .15s;
}
.home-tile:hover {
    border-color: var(--c-primary);
    box-shadow: 0 4px 12px rgba(37, 99, 235, .15);
    transform: translateY(-2px);
}
.home-tile__icon { font-size: 28px; line-height: 1; }
.home-tile__title { font-size: 16px; font-weight: bold; color: var(--c-head); }
.home-tile__desc { font-size: 13px; color: #6b7280; }
/* 準備中（リンク先未設定）のタイル：クリック不可・淡色表示 */
.home-tile--disabled { cursor: default; opacity: .55; background: #f9fafb; }
.home-tile--disabled:hover { border-color: var(--c-border); box-shadow: none; transform: none; }

/* ホーム: グループ見出し */
.home-group { margin-bottom: 28px; }
.home-group__heading {
    font-size: 15px; color: var(--c-head); margin: 0 0 12px;
    padding-bottom: 6px; border-bottom: 2px solid var(--c-border);
}

/* ---- インラインの追加フォーム ---- */
.inline-form {
    display: flex; align-items: center; gap: 12px; flex-wrap: wrap;
    background: #fff; border: 1px solid var(--c-border); border-radius: 10px;
    padding: 16px 20px; margin-bottom: 16px;
}
.inline-form .field { margin-bottom: 0; }
.inline-form .field--inline input { width: 220px; }

/* ---- ドラッグ＆ドロップ並べ替えリスト ---- */
.sortable { list-style: none; margin: 0 0 12px; padding: 0; max-width: 560px; }
.sortable__item {
    display: flex; align-items: center; gap: 12px;
    background: #fff; border: 1px solid var(--c-border); border-radius: 8px;
    padding: 10px 14px; margin-bottom: 8px; cursor: grab;
}
.sortable__item.is-dragging { opacity: .5; border-style: dashed; cursor: grabbing; }
.sortable__handle { color: #9ca3af; font-size: 18px; line-height: 1; cursor: grab; user-select: none; }
.sortable__name { flex: 1; font-weight: bold; }
.sortable__actions { display: flex; gap: 8px; }
.sortable__actions form { margin: 0; }
.sortable__empty { color: #9ca3af; padding: 16px; background: #fff; border: 1px dashed var(--c-border); border-radius: 8px; }

/* ---- 休日パターン: 曜日チェック ---- */
.day-checks { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 4px; }
.day-check {
    display: inline-flex; align-items: center; gap: 6px;
    border: 1px solid var(--c-border); border-radius: 8px; padding: 8px 12px;
    cursor: pointer; user-select: none; background: #fff;
}
.day-check input { width: auto; margin: 0; }
.day-check__label { font-size: 14px; }
.day-check:has(input:checked) { background: #eff6ff; border-color: var(--c-primary); }

/* ---- レコード詳細 ---- */
.detail-card {
    background: #fff; border: 1px solid var(--c-border); border-radius: 10px;
    padding: 8px 24px; max-width: 640px; margin: 0;
}
.detail-row { display: flex; gap: 16px; padding: 12px 0; border-bottom: 1px solid var(--c-border); }
.detail-row:last-child { border-bottom: none; }
.detail-row dt { flex: 0 0 180px; margin: 0; color: #6b7280; font-size: 13px; }
.detail-row dd { flex: 1; margin: 0; font-size: 15px; word-break: break-word; }

/* ---- Flash / アラート ---- */
.message, .alert { padding: 10px 14px; border-radius: 6px; margin-bottom: 16px; }
.message.success, .alert--success { background: #dcfce7; color: #166534; }
.message.error, .alert--error { background: #fee2e2; color: #991b1b; }

/* ---- ボタン ---- */
.btn {
    display: inline-block; border: 1px solid var(--c-border); background: #fff;
    color: #111827; padding: 7px 14px; border-radius: 6px; cursor: pointer;
    text-decoration: none; font-size: 14px; line-height: 1.2;
}
.btn:hover { background: #f9fafb; }
.btn--primary { background: var(--c-primary); border-color: var(--c-primary); color: #fff; }
.btn--primary:hover { background: var(--c-primary-d); }
.btn--danger { background: #fff; border-color: var(--c-danger); color: var(--c-danger); }
.btn--danger:hover { background: var(--c-danger); color: #fff; }
.btn--ghost { background: transparent; border-color: #4b5563; color: #fff; }
.btn--block { width: 100%; }
.btn--small { padding: 4px 10px; font-size: 13px; }

/* ---- フォーム ---- */
.field { display: block; margin-bottom: 14px; }
.field__label { display: block; font-size: 13px; color: #374151; margin-bottom: 4px; }
.field__label em { color: var(--c-danger); font-style: normal; }
.field input[type=text], .field input[type=password], .field input[type=date], .field select,
input[type=text], input[type=password], input[type=date], select {
    width: 100%; padding: 8px 10px; border: 1px solid var(--c-border); border-radius: 6px; font-size: 14px;
}
.field--inline { display: flex; align-items: center; gap: 8px; }
.field--inline input { width: auto; }
.field__row { display: flex; gap: 8px; align-items: stretch; }
.field__row input { flex: 1; }
.field__row .btn { white-space: nowrap; }
.field__hint { display: block; font-size: 12px; color: #6b7280; margin-top: 4px; }
.field__pair { display: flex; gap: 14px; }
.field__pair .field { flex: 1; }
.error-message { color: var(--c-danger); font-size: 12px; margin-top: 4px; }

.form-card, .auth-card, .create-box {
    background: #fff; border: 1px solid var(--c-border); border-radius: 10px; padding: 24px;
}
.form-card { max-width: 520px; }
.form-card__actions { display: flex; gap: 10px; justify-content: flex-end; margin-top: 8px; }
.form-card__note { font-size: 13px; color: #6b7280; margin: 4px 0 14px; padding-top: 12px; border-top: 1px solid var(--c-border); }

.auth-card { width: 360px; }
.auth-card__title { margin: 0 0 20px; font-size: 20px; text-align: center; }
.auth-card__foot { text-align: center; margin: 16px 0 0; font-size: 13px; }

.create-box { margin-bottom: 8px; }
.create-box__title { margin: 0 0 16px; font-size: 16px; }
.create-box__form { display: flex; align-items: flex-end; gap: 16px; flex-wrap: wrap; }
.create-box__form .field { margin-bottom: 0; }

/* ---- テーブル ---- */
.table { width: 100%; border-collapse: collapse; background: #fff; border: 1px solid var(--c-border); border-radius: 8px; overflow: hidden; }
.table th, .table td { border-bottom: 1px solid #e5e7eb; padding: 10px 12px; text-align: left; }
.table thead th { background: #f9fafb; font-size: 13px; color: #374151; }
.table__actions { display: flex; gap: 8px; align-items: center; }
.table__actions form { margin: 0; }
.table__empty { text-align: center; color: #9ca3af; padding: 24px; }

/* ---- 配車表エディタ ---- */
.dispatch-toolbar {
    display: flex; align-items: center; justify-content: space-between;
    background: #fff; border: 1px solid var(--c-border); border-radius: 10px;
    padding: 14px 20px; margin-bottom: 16px; gap: 16px;
}
.dispatch-toolbar__info { display: flex; align-items: center; gap: 16px; }
.dispatch-toolbar__info h1 { font-size: 18px; margin: 0; }
.dispatch-toolbar__info small { color: #6b7280; font-weight: normal; }
.dispatch-toolbar__title { padding: 6px 10px; border: 1px solid var(--c-border); border-radius: 6px; width: 220px; }
.dispatch-toolbar__controls { display: flex; align-items: center; gap: 14px; }

.save-status { font-size: 13px; }
.save-status--ok { color: #166534; }
.save-status--err { color: var(--c-danger); }
.save-status--busy { color: #6b7280; }

.dispatch-body { display: flex; gap: 16px; align-items: flex-start; }
.dispatch-grid-wrap { flex: 1; background: #fff; border: 1px solid var(--c-border); border-radius: 10px; padding: 16px; overflow: auto; }
.dispatch-grid-wrap--full { width: 100%; }
.grid-hint { color: #6b7280; font-size: 12px; margin: 12px 0 0; }

/* ---- 配車グリッド ---- */
.grid { width: 100%; border-collapse: collapse; }
.grid th, .grid td { border: 1px solid #cbd5e1; padding: 6px; vertical-align: top; }
.grid thead th { background: #f1f5f9; text-align: center; font-size: 13px; padding: 8px; white-space: nowrap; }
.grid__rowctl { width: 36px; background: #f8fafc; text-align: center; white-space: nowrap; padding: 4px; }
.rowbtn { display: block; width: 24px; margin: 2px auto; border: 1px solid var(--c-border); background: #fff; border-radius: 4px; cursor: pointer; line-height: 1.2; }
.rowbtn:hover { background: #eef2ff; }

.cell { min-width: 150px; height: 56px; }
/* 空セルはテーブルセルのまま（display:block にすると列から外れて崩れる）。
   高さは .cell の height と行の自動ストレッチで揃う。 */
.cell--empty { background: #fcfdff; }
.cell--over { background: #eff6ff; outline: 2px dashed var(--c-primary); outline-offset: -2px; }
/* 案件は入っているのにドライバー／車両が空欄の警告（赤枠） */
.cell--missing { box-shadow: inset 0 0 0 2px var(--c-danger); background: #fef2f2; }

/* ---- チップ（ドラッグ要素） ---- */
.chip {
    position: relative; display: flex; flex-direction: column; gap: 2px;
    border: 1px solid #94a3b8; border-radius: 6px; padding: 6px 22px 6px 8px;
    background: #fff; cursor: grab; user-select: none;
}
.chip:active { cursor: grabbing; }
.chip--dragging { opacity: .4; }
.chip--driver { background: var(--c-driver); border-color: #7dd3fc; }
.chip--vehicle { background: var(--c-vehicle); border-color: #c4b5fd; }
.chip--job { background: var(--c-job); border-color: #86efac; }
.chip--note { background: var(--c-note); border-color: #fcd34d; }
/* 繰り返し利用できる要素（のりかえ等）は破線枠＋斜体で区別 */
.chip--reusable { border-style: dashed; font-style: italic; }
/* 一覧側で配車表に配置済みのドライバー・車両に添える「配置済み」バッジ */
.chip__placed { align-self: flex-start; margin-top: 3px; font-size: 10px; line-height: 1.5; color: #fff; background: #6b7280; border-radius: 8px; padding: 0 7px; }
.pool__list .chip--placed { border-style: dashed; }
/* その日が休日のドライバー：背景を薄くして識別 */
.chip--holiday { background: #f3f4f6; border-color: #e5e7eb; color: #9ca3af; opacity: .7; }
.chip--holiday .chip__main { font-weight: 500; }
.chip__holiday { align-self: flex-start; margin-top: 3px; font-size: 10px; line-height: 1.5; color: #fff; background: #f59e0b; border-radius: 8px; padding: 0 7px; }
.chip__main { font-weight: 600; font-size: 13px; }
.chip__sub { font-size: 11px; color: #475569; }
.chip__remove {
    position: absolute; top: 2px; right: 2px; width: 18px; height: 18px;
    border: none; background: transparent; color: #64748b; cursor: pointer;
    font-size: 14px; line-height: 1; border-radius: 4px;
}
.chip__remove:hover { background: rgba(0,0,0,.08); color: #111827; }

/* ---- 右側プール（種別混在の単一リスト＋絞り込み） ---- */
.dispatch-pools { width: 380px; flex: none; display: flex; flex-direction: column; gap: 12px; }
.pool { background: #fff; border: 1px solid var(--c-border); border-radius: 10px; padding: 12px; }
.pool__title { margin: 0 0 10px; font-size: 14px; border-bottom: 2px solid #e5e7eb; padding-bottom: 6px; }
.pool__filter { display: flex; align-items: center; gap: 8px; margin-bottom: 10px; }
.pool__filter-label { font-size: 13px; font-weight: 600; color: #374151; white-space: nowrap; }
.pool__filter-select { flex: 1; padding: 6px 8px; border: 1px solid var(--c-border); border-radius: 6px; font-size: 13px; background: #fff; }
.pool__list { display: flex; flex-direction: column; gap: 8px; max-height: 30vh; overflow: auto; }
/* 縦スクロールを抑えるため一覧は2列グリッドで表示 */
.pool__list--all { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; max-height: calc(100vh - 230px); overflow: auto; align-content: start; }
.pool__list--all .pool__empty { grid-column: 1 / -1; }
.pool__empty { color: #9ca3af; font-size: 13px; margin: 4px 0; }
/* 混在リストでの種別ラベル */
.chip__type { align-self: flex-start; font-size: 10px; font-weight: 700; color: #475569; background: rgba(0,0,0,.06); border-radius: 6px; padding: 0 6px; }
/* 庸車（クリックで情報入力できるチップ） */
.chip--clickable { cursor: pointer; }
.chip--charter { border-style: dashed; }
.chip__sub--placeholder { color: #9ca3af; font-style: italic; }

/* ---- モーダル ---- */
.modal { position: fixed; inset: 0; background: rgba(17,24,39,.5); display: flex; align-items: center; justify-content: center; z-index: 1000; }
.modal[hidden] { display: none; }
.modal__box { background: #fff; border-radius: 10px; padding: 22px; width: 360px; max-width: 92vw; box-shadow: 0 10px 40px rgba(0,0,0,.25); }
.modal__title { margin: 0 0 16px; font-size: 16px; }
.modal__fields { display: flex; flex-direction: column; gap: 12px; }
.modal__field { display: flex; flex-direction: column; gap: 4px; }
.modal__field-label { font-size: 13px; font-weight: 600; color: #374151; }
.modal__input { padding: 8px 10px; border: 1px solid var(--c-border); border-radius: 6px; font-size: 14px; }
.modal__actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 20px; }

/* ====== 注文登録フォーム ====== */
.order-titlebar { display: flex; align-items: center; justify-content: space-between; background: #fff; border: 1px solid var(--c-border); border-radius: 10px; padding: 18px 24px; margin-bottom: 18px; }
.order-titlebar h1 { margin: 0; font-size: 22px; }
.order-reset { width: 38px; height: 38px; display: inline-flex; align-items: center; justify-content: center; background: var(--c-primary); color: #fff; border-radius: 50%; font-size: 18px; text-decoration: none; }
.order-reset:hover { background: var(--c-primary-d); }

.order-form { display: block; }
.order-sec { background: #fff; border: 1px solid var(--c-border); border-radius: 10px; margin-bottom: 18px; overflow: hidden; }
.order-sec__head { background: #f8fafc; border-bottom: 1px solid var(--c-border); padding: 16px 24px; font-size: 18px; font-weight: 700; }
.order-sec__body { padding: 20px 24px; }

.order-row { display: flex; align-items: flex-start; gap: 16px; padding: 10px 0; }
.order-row__label { width: 200px; flex: none; font-weight: 700; font-size: 14px; padding-top: 8px; }
.order-row__control { flex: 1; display: flex; align-items: center; flex-wrap: wrap; gap: 8px; }
.order-inline { gap: 8px; }
.order-checks { gap: 8px 18px; }
.order-row__control .sep { color: #6b7280; }

.inp { padding: 8px 10px; border: 1px solid var(--c-border); border-radius: 6px; font-size: 14px; min-width: 120px; }
.inp--wide { width: 100%; max-width: 620px; }
.inp--code { width: 90px; text-align: center; }
.inp--code2 { width: 70px; text-align: center; }
textarea.inp { resize: vertical; }

.opt { display: inline-flex; align-items: center; gap: 5px; cursor: pointer; font-size: 14px; white-space: nowrap; }
.opt input { accent-color: var(--c-primary); width: 16px; height: 16px; cursor: pointer; }

.btn--zip { background: #2563eb; color: #fff; border-color: #2563eb; }
.btn--zip:hover { background: #1d4ed8; }

.order-actions { display: flex; justify-content: flex-end; gap: 10px; margin: 8px 0 40px; }
