* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}
@keyframes spin { to { transform: rotate(360deg); } }

:root {
    --primary: #ea580c;
    --primary-dark: #c2410c;
    --primary-light: #fed7aa;
    --sidebar-bg: #1e293b;
    --sidebar-hover: #334155;
    --bg: #fafaf9;
    --card-bg: #ffffff;
    --text: #1e293b;
    --text-light: #64748b;
    --border: #e7e5e4;
    --green: #22c55e;
    --orange: #f59e0b;
    --red: #ef4444;
    --purple: #8b5cf6;
    --blue: #3b82f6;
}

body {
    font-family: 'Segoe UI', 'Hiragino Sans', 'Yu Gothic', sans-serif;
    background: var(--bg);
    color: var(--text);
    display: flex;
    min-height: 100vh;
}

/* サイドバー */
.sidebar {
    width: 240px;
    background: var(--sidebar-bg);
    color: #fff;
    flex-shrink: 0;
    position: fixed;
    top: 0;
    left: 0;
    height: 100vh;
    z-index: 1000;
    transition: width 0.3s ease;
    overflow-y: auto;
    overflow-x: hidden;
    scrollbar-width: none;
    -ms-overflow-style: none;
}

.sidebar::-webkit-scrollbar {
    display: none;
}

@media (min-width: 769px) {
    .sidebar.collapsed {
        width: 56px;
    }
    .sidebar.collapsed:hover {
        width: 240px;
        box-shadow: 4px 0 20px rgba(0,0,0,0.3);
    }
    .sidebar.collapsed .nav-item {
        padding: 12px 16px;
        justify-content: center;
    }
    .sidebar.collapsed:hover .nav-item {
        padding: 12px 20px;
        justify-content: flex-start;
    }
    .sidebar.collapsed .nav-item .nav-label {
        opacity: 0;
        width: 0;
        overflow: hidden;
        display: inline-block;
    }
    .sidebar.collapsed:hover .nav-item .nav-label {
        opacity: 1;
        width: auto;
        display: inline;
    }
    .sidebar.collapsed .nav-item .nav-icon {
        margin: 0;
    }
    .sidebar.collapsed .sub-app-header {
        font-size: 0;
        color: transparent;
        overflow: hidden;
        border-top: 1px solid rgba(255,255,255,0.1);
        padding: 4px 0 !important;
        margin-top: 4px !important;
    }
    .sidebar.collapsed:hover .sub-app-header {
        font-size: 0.7rem;
        color: #94a3b8;
        border-top: none;
        padding: 8px 20px !important;
        margin-top: 8px !important;
    }
    .content.sidebar-collapsed {
        margin-left: 56px !important;
    }
}

.sidebar-header {
    padding: 20px;
    border-bottom: 1px solid rgba(255,255,255,0.1);
    white-space: nowrap;
}

.sidebar-header h2 {
    font-size: 1.2rem;
    font-weight: 700;
}

.nav-menu {
    list-style: none;
    padding: 10px 0 20px 0;
    overflow-y: auto;
    max-height: 100vh;
    scrollbar-width: none;
    -ms-overflow-style: none;
}

.nav-menu::-webkit-scrollbar {
    display: none;
}

.nav-item {
    padding: 12px 20px;
    cursor: pointer;
    transition: background 0.2s;
    display: flex;
    align-items: center;
    gap: 10px;
    font-size: 0.95rem;
    white-space: nowrap;
}

.nav-item:hover {
    background: var(--sidebar-hover);
}

.nav-item.active {
    background: var(--primary);
    font-weight: 600;
}

.nav-icon {
    font-size: 1.1rem;
    flex-shrink: 0;
}

/* メインコンテンツ */
.content {
    margin-left: 240px;
    flex: 1;
    min-height: 100vh;
    overflow-x: hidden;
}

.topbar {
    background: var(--card-bg);
    padding: 6px 16px;
    display: flex;
    align-items: center;
    gap: 12px;
    border-bottom: 1px solid var(--border);
    position: sticky;
    top: 0;
    z-index: 50;
}

.topbar h1 {
    font-size: 1.1rem;
    flex: 1;
}

.topbar-right {
    color: var(--text-light);
    font-size: 0.9rem;
    display: flex;
    align-items: center;
    gap: 12px;
}
.topbar-user { font-size: 0.85rem; }
.topbar-btn {
    border: none; border-radius: 6px; padding: 4px 12px;
    font-size: 0.8rem; cursor: pointer; white-space: nowrap;
}
.topbar-btn-feedback { background: #f59e0b; color: #fff; }
.topbar-btn-logout { background: none; border: 1px solid #d1d5db; color: #64748b; }

/* モバイルボトムナビ: PCでは非表示 */
.mobile-bottom-nav { display: none; }
.mobile-action-sheet { display: none; }

.menu-toggle {
    display: none;
    background: none;
    border: none;
    font-size: 1.5rem;
    cursor: pointer;
    color: var(--text);
}

/* ページ */
.page {
    display: none;
    padding: 10px 16px;
}

.page.active {
    display: block;
}

.page-actions {
    display: flex;
    gap: 8px;
    margin-bottom: 8px;
    align-items: center;
    flex-wrap: wrap;
}

/* カード・統計 */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 16px;
    margin-bottom: 24px;
}

.stat-card {
    background: var(--card-bg);
    border-radius: 12px;
    padding: 20px;
    box-shadow: 0 1px 3px rgba(0,0,0,0.08);
    border-left: 4px solid var(--primary);
}

.stat-card.blue { border-left-color: var(--blue); }
.stat-card.orange { border-left-color: var(--orange); }
.stat-card.green { border-left-color: var(--green); }
.stat-card.purple { border-left-color: var(--purple); }
.stat-card.red { border-left-color: var(--red); }

.stat-label {
    font-size: 0.85rem;
    color: var(--text-light);
    margin-bottom: 8px;
}

.stat-value {
    font-size: 1.8rem;
    font-weight: 700;
}

.stat-value small {
    font-size: 1rem;
    color: var(--text-light);
    font-weight: 400;
}

.dashboard-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(320px, 1fr));
    gap: 16px;
}

.dashboard-grid .wide {
    grid-column: 1 / -1;
}

.card {
    background: var(--card-bg);
    border-radius: 12px;
    padding: 20px;
    box-shadow: 0 1px 3px rgba(0,0,0,0.08);
}

.card h3 {
    font-size: 1rem;
    margin-bottom: 16px;
    color: var(--text);
}

/* ステータスバー */
.status-bar {
    margin-bottom: 12px;
}

.status-bar-label {
    display: flex;
    justify-content: space-between;
    font-size: 0.85rem;
    margin-bottom: 4px;
}

.status-bar-track {
    height: 8px;
    background: var(--bg);
    border-radius: 4px;
    overflow: hidden;
}

.status-bar-fill {
    height: 100%;
    border-radius: 4px;
    transition: width 0.5s;
}

.status-bar-fill.blue { background: var(--blue); }
.status-bar-fill.green { background: var(--green); }
.status-bar-fill.orange { background: var(--orange); }
.status-bar-fill.red { background: var(--red); }
.status-bar-fill.purple { background: var(--purple); }

/* チャート */
.chart-container {
    display: flex;
    align-items: flex-end;
    gap: 8px;
    height: 200px;
    padding-top: 20px;
}

.chart-bar-wrapper {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    height: 100%;
    justify-content: flex-end;
}

.chart-bar {
    width: 100%;
    max-width: 48px;
    background: var(--primary);
    border-radius: 4px 4px 0 0;
    min-height: 2px;
    transition: height 0.5s;
}

.chart-label {
    font-size: 0.7rem;
    color: var(--text-light);
    margin-top: 6px;
    text-align: center;
}

.chart-value {
    font-size: 0.7rem;
    color: var(--text);
    margin-bottom: 4px;
    font-weight: 600;
}

/* テーブル */
.table-container {
    overflow-x: auto;
}

.data-table {
    width: 100%;
    border-collapse: collapse;
    background: var(--card-bg);
    border-radius: 12px;
    overflow: hidden;
    box-shadow: 0 1px 3px rgba(0,0,0,0.08);
}

.data-table th {
    background: var(--sidebar-bg);
    color: #fff;
    padding: 12px 16px;
    text-align: left;
    font-size: 0.85rem;
    font-weight: 600;
    white-space: nowrap;
}
.data-table th.sortable {
    cursor: pointer;
    user-select: none;
    position: relative;
    padding-right: 22px;
}
.data-table th.sortable:hover {
    background: rgba(255,255,255,0.1);
}
.data-table th.sortable::after {
    content: '⇅';
    position: absolute;
    right: 6px;
    opacity: 0.4;
    font-size: 0.75rem;
}
.data-table th.sortable.sort-asc::after {
    content: '▲';
    opacity: 0.9;
}
.data-table th.sortable.sort-desc::after {
    content: '▼';
    opacity: 0.9;
}

.data-table td {
    padding: 8px 12px;
    border-bottom: 1px solid var(--border);
    font-size: 0.85rem;
    line-height: 1.3;
}

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

/* ステータスバッジ */
.badge {
    display: inline-block;
    padding: 3px 10px;
    border-radius: 12px;
    font-size: 0.8rem;
    font-weight: 600;
}

.badge-green { background: #dcfce7; color: #166534; }
.badge-blue { background: #dbeafe; color: #1e40af; }
.badge-orange { background: #fef3c7; color: #92400e; }
.badge-red { background: #fee2e2; color: #991b1b; }
.badge-gray { background: #f1f5f9; color: #475569; }
.badge-purple { background: #f3e8ff; color: #6b21a8; }

/* ボタン */
.btn {
    padding: 8px 16px;
    border: none;
    border-radius: 8px;
    cursor: pointer;
    font-size: 0.9rem;
    font-weight: 600;
    transition: background 0.2s;
}

.btn-primary {
    background: var(--primary);
    color: #fff;
}

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

.btn-sm {
    padding: 4px 10px;
    font-size: 0.8rem;
}

.btn-danger {
    background: var(--red);
    color: #fff;
}

.btn-success {
    background: var(--green);
    color: #fff;
}

.btn-edit {
    background: var(--orange);
    color: #fff;
}

/* フォーム */
.input, .select {
    padding: 8px 12px;
    border: 1px solid var(--border);
    border-radius: 8px;
    font-size: 0.9rem;
    outline: none;
    transition: border 0.2s;
}

.input:focus, .select:focus {
    border-color: var(--primary);
}

/* モーダル */
.modal-overlay {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0,0,0,0.5);
    z-index: 200;
    justify-content: center;
    align-items: center;
}

.modal-overlay.active {
    display: flex;
}

.modal {
    background: var(--card-bg);
    border-radius: 16px;
    width: 90%;
    max-width: 560px;
    max-height: 85vh;
    overflow-y: auto;
}

.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 20px 24px;
    border-bottom: 1px solid var(--border);
}

.modal-header h3 {
    font-size: 1.1rem;
}

.modal-close {
    background: none;
    border: none;
    font-size: 1.5rem;
    cursor: pointer;
    color: var(--text-light);
}

.modal-body {
    padding: 24px;
}

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

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

.form-group input,
.form-group select,
.form-group textarea {
    width: 100%;
    padding: 10px 12px;
    border: 1px solid var(--border);
    border-radius: 8px;
    font-size: 0.9rem;
    outline: none;
}

.form-group input:focus,
.form-group select:focus,
.form-group textarea:focus {
    border-color: var(--primary);
}

.form-group textarea {
    resize: vertical;
    min-height: 60px;
}

.form-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 12px;
}

.form-actions {
    display: flex;
    gap: 8px;
    justify-content: flex-end;
    margin-top: 20px;
    flex-wrap: wrap;
}
.form-actions .btn {
    white-space: nowrap;
}

/* 地図 */
.map-wrapper {
    border-radius: 12px;
    overflow: hidden;
    box-shadow: 0 1px 3px rgba(0,0,0,0.08);
}

/* カレンダー配車表 */
#dispatch-calendar {
    overflow-x: hidden;
}

.input-date {
    padding: 5px 10px;
    border: 1px solid var(--border);
    border-radius: 6px;
    font-size: 0.85rem;
    cursor: pointer;
}

.cal-controls {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-bottom: 8px;
    flex-wrap: wrap;
    box-sizing: border-box;
}

.cal-week-label {
    font-weight: 700;
    font-size: 1rem;
    min-width: 200px;
    text-align: center;
}

.cal-grid {
    display: grid;
    border: 1px solid var(--border);
    border-radius: 12px;
    overflow: hidden;
    background: var(--card-bg);
    box-shadow: 0 1px 3px rgba(0,0,0,0.08);
    user-select: none;
    -webkit-user-select: none;
}

.cal-header {
    background: var(--sidebar-bg);
    color: #fff;
    padding: 10px 6px;
    text-align: center;
    font-size: 0.8rem;
    font-weight: 600;
    border-right: 1px solid rgba(255,255,255,0.1);
    position: sticky;
    top: 0;
    z-index: 6;
}

.cal-header.cal-today {
    background: var(--primary);
}

.cal-header.cal-weekend {
    background: #374151;
}

.cal-vehicle-col {
    text-align: left;
    padding-left: 12px;
}

.cal-vehicle-label {
    background: #f8fafc;
    padding: 8px 10px;
    border-bottom: 1px solid var(--border);
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    justify-content: center;
    gap: 2px;
}

.cal-vehicle-name {
    font-size: 0.8rem;
    font-weight: 700;
    color: var(--text);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.cal-vehicle-info {
    font-size: 0.7rem;
    color: var(--text-light);
    display: flex;
    align-items: center;
    gap: 4px;
}

/* 日付タブ */
.cal-day-tabs {
    display: flex;
    gap: 4px;
}

.cal-day-tab {
    padding: 6px 14px;
    border: 1px solid var(--border);
    border-radius: 6px;
    background: var(--card-bg);
    cursor: pointer;
    font-size: 0.85rem;
    font-weight: 600;
    transition: all 0.15s;
}

.cal-day-tab:hover {
    background: #f0f7ff;
}

.cal-day-tab.active {
    background: var(--primary);
    color: #fff;
    border-color: var(--primary);
}

.cal-day-tab.today:not(.active) {
    border-color: var(--primary);
    color: var(--primary);
}

/* ガントチャート */
.gantt-wrapper {
    overflow-x: auto;
    overflow-y: auto;
    max-height: calc(60vh - 60px);
    min-height: 180px;
    border-bottom: 2px solid #e2e8f0;
}

.gantt-grid {
    display: grid;
    border: 1px solid var(--border);
    border-radius: 12px;
    background: var(--card-bg);
    box-shadow: 0 1px 3px rgba(0,0,0,0.08);
    user-select: none;
    -webkit-user-select: none;
    min-width: 800px;
}

.gantt-hour-header {
    font-size: 0.7rem;
    padding: 8px 2px;
}

.gantt-timeline {
    position: relative;
    min-height: 44px;
    border-bottom: 1px solid var(--border);
    cursor: pointer;
}

.gantt-timeline:hover {
    background: #fafbfc;
}

.gantt-gridline {
    position: absolute;
    top: 0;
    bottom: 0;
    width: 1px;
    background: var(--border);
    pointer-events: none;
}

.gantt-bar {
    position: absolute;
    top: 4px;
    bottom: 4px;
    border-radius: 4px;
    display: flex;
    align-items: center;
    cursor: pointer;
    transition: box-shadow 0.15s;
    z-index: 2;
    min-width: 20px;
    overflow: hidden;
}

.gantt-bar:hover {
    box-shadow: 0 2px 8px rgba(0,0,0,0.2);
    z-index: 3;
}

.gantt-bar.ev-blue { background: #dbeafe; color: #1e40af; border-left: 3px solid #2563eb; }
.gantt-bar.ev-green { background: #dcfce7; color: #166534; border-left: 3px solid #22c55e; }
.gantt-bar.ev-gray { background: #f1f5f9; color: #475569; border-left: 3px solid #94a3b8; }
.gantt-bar.ev-red { background: #fee2e2; color: #991b1b; border-left: 3px solid #ef4444; }

.gantt-bar-text {
    position: absolute;
    left: 6px;
    right: 6px;
    top: 50%;
    transform: translateY(-50%);
    font-size: 0.65rem;
    font-weight: 600;
    white-space: nowrap;
    overflow: hidden;
    display: flex;
    align-items: center;
    pointer-events: none;
}
.bar-addr-pickup, .bar-addr-delivery {
    overflow: hidden;
    text-overflow: ellipsis;
    flex: 1;
    min-width: 0;
}
.bar-addr-delivery { text-align: right; }
/* 非表示にする（後方互換用） */
.gantt-bar-start, .gantt-bar-end { display: none; }

.gantt-bar-label {
    font-size: 0.7rem;
    font-weight: 600;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    padding: 0 6px;
    pointer-events: none;
}

.gantt-bar-resize {
    position: absolute;
    top: 0;
    bottom: 0;
    width: 8px;
    cursor: ew-resize;
    z-index: 5;
}

.gantt-bar-resize-left {
    left: -2px;
}

.gantt-bar-resize-right {
    right: -2px;
}

.gantt-bar-resize:hover {
    background: rgba(0,0,0,0.1);
    border-radius: 2px;
}

.gantt-bar.dragging {
    opacity: 0.4;
    box-shadow: 0 4px 12px rgba(0,0,0,0.3);
    z-index: 10;
    pointer-events: none;
}

.gantt-timeline.drag-over {
    background: #f0f7ff !important;
}

/* Requirement 5: 整備中車両のグレーアウト */
.gantt-timeline.maintenance {
    background: #f3f4f6 !important;
    cursor: not-allowed;
}
.gantt-timeline.maintenance:hover {
    background: #e5e7eb !important;
}

#unassigned-panel {
    max-height: 200px;
    overflow-y: auto;
    padding: 12px;
}

#unassigned-panel.drag-over {
    background: #fef3c7 !important;
    border: 2px dashed #d97706;
    box-shadow: 0 0 8px rgba(217, 119, 6, 0.3);
}

.gantt-bar-ghost {
    position: absolute;
    top: 4px;
    bottom: 4px;
    background: rgba(37, 99, 235, 0.25);
    border: 2px dashed #2563eb;
    border-radius: 4px;
    z-index: 5;
    pointer-events: none;
    display: flex;
    align-items: center;
    justify-content: center;
}

.gantt-ghost-label {
    font-size: 0.7rem;
    font-weight: 700;
    color: #1e40af;
    white-space: nowrap;
}

.gantt-bar.multi-day {
    background: repeating-linear-gradient(
        45deg,
        transparent,
        transparent 3px,
        rgba(255,255,255,0.15) 3px,
        rgba(255,255,255,0.15) 6px
    ), var(--bar-bg, #dbeafe);
    border-style: dashed;
}
.gantt-bar.blue.multi-day { --bar-bg: #93c5fd; }
.gantt-bar.green.multi-day { --bar-bg: #86efac; }
.gantt-bar.orange.multi-day { --bar-bg: #fdba74; }

/* 未配車案件パネル */
.unassigned-list {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 4px;
    overflow: visible;
    padding-top: 8px;
}

.unassigned-item {
    display: flex;
    align-items: stretch;
    gap: 4px;
    padding: 4px 6px;
    background: #fffbeb;
    border: 1px solid #fbbf24;
    border-radius: 5px;
    cursor: grab;
    font-size: 0.72rem;
    transition: background 0.15s, transform 0.15s, box-shadow 0.15s;
    user-select: none;
    min-width: 0;
    position: relative;
    z-index: 0;
}

.unassigned-item:hover {
    background: #fef3c7;
    transform: translateY(-6px);
    box-shadow: 0 4px 12px rgba(251, 191, 36, 0.35);
    z-index: 10;
    border-color: #f59e0b;
}

.unassigned-item:active {
    cursor: grabbing;
    transform: translateY(-2px);
    box-shadow: 0 2px 6px rgba(251, 191, 36, 0.25);
}

/* ドライバー労働時間バー */
.mini-bar {
    height: 6px;
    background: var(--bg);
    border-radius: 3px;
    overflow: hidden;
    margin: 2px 0;
}

.mini-bar-fill {
    height: 100%;
    border-radius: 3px;
    transition: width 0.5s;
}

.mini-bar-fill.blue { background: var(--blue); }
.mini-bar-fill.orange { background: var(--orange); }
.mini-bar-fill.red { background: var(--red); }

/* アラート */
.alert {
    padding: 10px 16px;
    border-radius: 8px;
    font-size: 0.85rem;
    font-weight: 600;
    margin-bottom: 12px;
}

.alert-orange {
    background: #fef3c7;
    color: #92400e;
    border: 1px solid #f59e0b;
}

.alert-red {
    background: #fee2e2;
    color: #991b1b;
    border: 1px solid #ef4444;
}

/* 売上バーチャート */
.rev-bar-row {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-bottom: 8px;
}

.rev-bar-label {
    font-size: 0.8rem;
    font-weight: 600;
    min-width: 100px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.rev-bar-track {
    flex: 1;
    height: 18px;
    background: var(--bg);
    border-radius: 4px;
    overflow: hidden;
}

.rev-bar-fill {
    height: 100%;
    background: var(--primary);
    border-radius: 4px;
    transition: width 0.5s;
}

.rev-bar-fill.green {
    background: var(--green);
}

.rev-bar-value {
    font-size: 0.8rem;
    font-weight: 700;
    min-width: 80px;
    text-align: right;
}

/* 頻度曜日チェックボックス */
.freq-days-row {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
}

.freq-day-check {
    display: flex;
    align-items: center;
    gap: 4px;
    padding: 4px 10px;
    border: 1px solid var(--border);
    border-radius: 6px;
    font-size: 0.85rem;
    cursor: pointer;
    user-select: none;
}

.freq-day-check:has(input:checked) {
    background: var(--primary);
    color: #fff;
    border-color: var(--primary);
}

.freq-day-check input { display: none; }

/* 案件名リンク */
.link-cell {
    color: var(--primary);
    text-decoration: none;
    font-weight: 600;
    cursor: pointer;
}

.link-cell:hover {
    text-decoration: underline;
}

/* 地図 */
#page-map {
    position: relative;
    z-index: 0;
}

#map {
    position: relative;
    z-index: 0;
}

.map-icon {
    font-size: 22px;
    text-align: center;
    line-height: 28px;
}

/* レスポンシブ */
@media (max-width: 768px) {
    html, body { max-width: 100vw; overflow-x: hidden; }
    .sidebar { transform: translateX(-100%); }
    .sidebar.open { transform: translateX(0); }
    .content { margin-left: 0; max-width: 100vw; overflow-x: hidden; }
    .menu-toggle { display: block; }
    .stats-grid { grid-template-columns: repeat(2, 1fr); }
    .form-row { grid-template-columns: 1fr; }

    /* タッチターゲット */
    .btn, button { min-height: 40px; }
    .btn-sm { min-height: 36px; padding: 6px 10px; }
    .input, .select, input, select, textarea { min-height: 40px; font-size: 16px; }
    .nav-item { min-height: 48px; }
    .data-table td { padding: 10px 8px; }
    .page { padding: 8px 10px; }
    /* スマホ: ヘッダー・サイドバー非表示 */
    .topbar { display: none !important; }
    .sidebar { display: none !important; }
    .menu-toggle { display: none !important; }
    .content { padding-top: 0; margin-left: 0; padding-bottom: calc(56px + env(safe-area-inset-bottom, 0px)); }

    /* モーダル: 後ろが透けて見える */
    .modal-overlay { background: rgba(0,0,0,0.4) !important; }
    .modal { width: 92%; max-width: 92%; max-height: 75vh; border-radius: 12px; margin: auto; margin-top: 8vh; overflow-y: auto; padding: 12px; font-size: 0.85rem; }
    .modal .form-group { margin-bottom: 8px; }
    .modal .form-group label { font-size: 0.75rem; }
    .modal select, .modal input { font-size: 0.8rem; padding: 6px; }

    /* モバイルコンパクトコントロール */
    .m-cal-controls { padding: 4px 6px; background: #fff; border-bottom: 1px solid var(--border); }
    .m-cal-row { display: flex; align-items: center; gap: 3px; justify-content: center; }
    .m-cal-btn { border: none; background: #f1f5f9; border-radius: 4px; padding: 4px 8px; font-size: 0.75rem; cursor: pointer; min-height: 28px; flex-shrink: 0; }
    .m-cal-btn.m-cal-action { background: #ea580c; color: #fff; }
    .m-cal-tab { border: none; background: #f1f5f9; border-radius: 4px; padding: 4px 6px; font-size: 0.7rem; cursor: pointer; white-space: nowrap; flex-shrink: 0; }
    .m-cal-tab.active { background: var(--primary); color: #fff; }
    .m-cal-tab.today { box-shadow: inset 0 -2px 0 #ea580c; }
    .m-cal-select { border: 1px solid #d1d5db; border-radius: 4px; padding: 2px 4px; font-size: 0.65rem; min-height: 24px; background: #fff; flex: 1; max-width: 100px; }
    .m-cal-date-label { position: relative; overflow: hidden; width: 32px; min-width: 32px; padding: 4px 0; text-align: center; }
    .m-cal-date-input { position: absolute; top: 0; left: 0; width: 32px; height: 100%; opacity: 0; cursor: pointer; font-size: 16px; }
    .m-filter-panel { display: none; gap: 4px; padding: 4px 6px; align-items: center; flex-wrap: wrap; }
    .m-filter-panel.open { display: flex; }
    .m-filter-chip {
        font-size: 0.6rem; padding: 3px 8px; border-radius: 12px;
        border: 1px solid #d1d5db; background: #f9fafb; color: #374151;
        cursor: pointer; white-space: nowrap;
    }
    .m-filter-chip.active {
        background: #ea580c; color: #fff; border-color: #ea580c;
    }

    /* ガントチャート: 横→縦モード */
    .gantt-grid { min-width: unset !important; }
    .gantt-bar-resize { display: none; }
    .cal-legend { display: none; }

    /* 配車表ページ: 配車表だけスクロール */
    #page-dispatches.active {
        display: flex !important;
        flex-direction: column;
        height: calc(100vh - 56px - env(safe-area-inset-bottom, 0px));
        overflow: hidden;
        padding-bottom: 0;
        margin-top: 0;
        max-width: 100vw;
    }
    #page-dispatches #dispatch-calendar {
        display: flex;
        flex-direction: column;
        flex: 1 1 0;
        min-height: 0;
        overflow: hidden;
        max-width: 100vw;
    }
    .m-cal-controls { flex: 0 0 auto; }

    /* 縦ガントグリッド */
    body.no-select, body.no-select * {
        -webkit-user-select: none !important;
        user-select: none !important;
        -webkit-touch-callout: none !important;
    }
    .vertical-gantt-wrapper {
        overflow-x: auto; overflow-y: auto;
        flex: 1 1 0;
        max-height: none;
        -webkit-overflow-scrolling: touch;
        border: 1px solid var(--border);
        border-radius: 8px;
        background: #fff;
    }
    .vertical-gantt {
        display: grid;
        min-width: max-content;
        -webkit-user-select: none;
        user-select: none;
    }
    /* ヘッダー行（グリッド外、固定、自身ではスクロール不可） */
    .vg-header-row {
        flex: 0 0 auto;
        display: flex;
        overflow: hidden;
        max-width: 100vw;
        touch-action: none;
        pointer-events: none;
    }
    .vg-header-row .vg-vehicle-header { pointer-events: auto; }
    .vg-corner {
        background: var(--primary); color: #fff;
        font-size: 0.6rem; font-weight: 700;
        display: flex; align-items: center; justify-content: center;
        border-right: 1px solid rgba(255,255,255,0.3);
    }
    .vg-vehicle-header {
        background: var(--primary); color: #fff;
        font-size: 0.55rem; font-weight: 600;
        padding: 4px 2px; text-align: center;
        border-right: 1px solid rgba(255,255,255,0.2);
        white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
        display: flex; align-items: center; justify-content: center; flex-direction: column;
    }
    .vg-time-label {
        position: sticky; left: 0; z-index: 10;
        background: #f8fafc; color: var(--text-dark);
        font-size: 0.65rem; font-weight: 700;
        display: flex; align-items: flex-start; justify-content: center;
        padding-top: 2px;
        border-right: 1px solid var(--border);
        border-bottom: 1px solid #f0f0f0;
    }
    .vg-cell {
        position: relative;
        border-right: 1px solid #f0f0f0;
        border-bottom: 1px solid #f0f0f0;
        min-height: 40px;
    }
    .vg-bar {
        position: absolute; left: 2px; right: 2px;
        border-radius: 4px;
        font-size: 0.55rem; font-weight: 600;
        padding: 3px 4px;
        overflow: hidden;
        z-index: 2;
        -webkit-user-select: none;
        user-select: none;
        -webkit-touch-callout: none;
        touch-action: none;
        cursor: pointer;
        display: flex; flex-direction: column;
        line-height: 1.2;
        border-bottom: 2px solid rgba(0,0,0,0.15);
        box-shadow: 0 1px 2px rgba(0,0,0,0.08);
    }
    .vg-bar-driver {
        font-weight: 700; font-size: 0.6rem;
        white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
        background: rgba(255,255,255,0.6); border-radius: 2px;
        padding: 0 3px; margin-bottom: 1px;
        display: inline-block; width: fit-content;
    }
    .vg-bar-addr { font-size: 0.5rem; opacity: 0.85; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

    /* コントロール折りたたみ */
    .cal-controls { flex-direction: column; gap: 6px; padding: 6px; max-width: calc(100vw - 16px); }
    .cal-controls > div { flex-wrap: wrap; gap: 4px; }
    .cal-day-tabs { overflow-x: auto; -webkit-overflow-scrolling: touch; flex-wrap: nowrap; }
    .cal-day-tab { min-width: 55px; flex-shrink: 0; padding: 6px 8px; font-size: 0.75rem; }
    .mobile-filter-toggle { display: inline-block; }
    .mobile-filter-panel { display: none; }
    .mobile-filter-panel.open { display: flex; flex-wrap: wrap; gap: 6px; }

    /* 未配車パネル */
    .unassigned-list { grid-template-columns: 1fr !important; }

    /* ボトムナビ */
    /* その他メニュー */
    .mobile-more-menu { position: fixed; top: 0; left: 0; right: 0; bottom: 0; z-index: 200; }
    .mobile-more-backdrop { position: absolute; top: 0; left: 0; right: 0; bottom: 0; background: rgba(0,0,0,0.4); }
    .mobile-more-panel {
        position: absolute; bottom: calc(56px + env(safe-area-inset-bottom, 0px)); left: 10px; right: 10px;
        background: #fff; border-radius: 16px;
        box-shadow: 0 -4px 20px rgba(0,0,0,0.2);
        padding: 0; max-height: 70vh; overflow-y: auto;
    }
    .mobile-more-header {
        padding: 12px 16px; font-weight: 700; font-size: 0.9rem;
        border-bottom: 1px solid #e2e8f0; display: flex; align-items: center; justify-content: space-between;
    }
    .mobile-more-panel button {
        display: block; width: 100%; text-align: left;
        padding: 14px 16px; border: none; background: none;
        font-size: 0.85rem; cursor: pointer;
    }
    .mobile-more-panel button:nth-child(even) { background: #f8fafc; }
    .mobile-more-panel button:active { background: #e2e8f0; }
    .mobile-more-panel button:last-child { border-radius: 0 0 16px 16px; }

    .mobile-bottom-nav {
        display: grid; grid-template-columns: repeat(5, 1fr);
        position: fixed; bottom: 0; left: 0; right: 0;
        background: #fff; border-top: 1px solid var(--border);
        z-index: 100;
        padding-bottom: env(safe-area-inset-bottom, 0);
        box-shadow: 0 -2px 10px rgba(0,0,0,0.1);
    }
    .mobile-bottom-nav button {
        display: flex; flex-direction: column; align-items: center; justify-content: center;
        border: none; background: transparent; color: var(--text-light);
        font-size: 0.6rem; padding: 4px 0; gap: 1px; cursor: pointer;
    }
    .mobile-bottom-nav button.active { color: var(--primary); }
    .mobile-bottom-nav button .nav-emoji { font-size: 1.2rem; }
    .page { padding-bottom: 64px; }

    /* アクションシート */
    .mobile-action-sheet {
        position: fixed; inset: 0; z-index: 2000; display: flex;
        flex-direction: column; justify-content: flex-end;
    }
    .action-sheet-backdrop { flex: 1; background: rgba(0,0,0,0.4); }
    .action-sheet-content {
        background: #fff; border-radius: 16px 16px 0 0;
        padding: 16px; padding-bottom: 32px;
        max-height: 60vh; overflow-y: auto;
    }
    .action-sheet-content button {
        display: block; width: 100%; padding: 14px; margin-bottom: 8px;
        border: none; border-radius: 10px; background: #f1f5f9;
        font-size: 1rem; font-weight: 600; text-align: center; cursor: pointer;
    }
    .action-sheet-content button:active { background: #e2e8f0; }
    .action-sheet-content .action-sheet-cancel { color: #dc2626; background: #fee2e2; }

    /* 未配車FAB + スライドパネル */
    #unassigned-panel { display: none !important; } /* デスクトップ用パネルを非表示 */
    .unassigned-fab {
        position: fixed; bottom: 70px; right: 16px; z-index: 99;
        width: 56px; height: 56px; border-radius: 50%;
        background: var(--primary); color: #fff; border: none;
        font-size: 1.4rem; box-shadow: 0 4px 12px rgba(0,0,0,0.3);
        display: flex; align-items: center; justify-content: center;
        cursor: pointer;
    }
    .unassigned-fab .fab-badge {
        position: absolute; top: -4px; right: -4px;
        background: #dc2626; color: #fff; font-size: 0.65rem; font-weight: 700;
        min-width: 20px; height: 20px; border-radius: 10px;
        display: flex; align-items: center; justify-content: center;
        padding: 0 4px;
    }
    .unassigned-slide-panel {
        position: fixed; bottom: 56px; left: 0; right: 0;
        height: 50vh; background: #fff; z-index: 98;
        border-radius: 16px 16px 0 0;
        box-shadow: 0 -4px 20px rgba(0,0,0,0.15);
        transform: translateY(100%);
        transition: transform 0.3s ease;
        overflow-y: auto; padding: 12px;
        -webkit-overflow-scrolling: touch;
    }
    .unassigned-slide-panel.open { transform: translateY(0); }
    .unassigned-slide-panel .panel-handle {
        width: 40px; height: 4px; background: #cbd5e1; border-radius: 2px;
        margin: 0 auto 10px; display: block;
    }
}

@media (max-width: 480px) {
    .stats-grid { grid-template-columns: 1fr; }
    .stat-value { font-size: 1.3rem; }
    .topbar h1 { font-size: 0.85rem; }
    .vg-vehicle-header { font-size: 0.55rem; }
}

/* 印刷スタイル */
@media print {
    .sidebar, .topbar, .cal-controls, .page-actions,
    .modal-overlay, .menu-toggle, #unassigned-panel,
    .btn, button { display: none !important; }

    .content { margin-left: 0 !important; }

    .page { display: block !important; padding: 0 !important; }
    .page:not(.active) { display: none !important; }

    .gantt-wrapper { overflow: visible !important; }
    .gantt-grid { min-width: auto !important; }

    .data-table { box-shadow: none !important; }
    .card { box-shadow: none !important; border: 1px solid #ddd; }

    body { background: #fff; }
}
