/* =============================================================================
   DISPATCH — Mobile-first CSS
   ============================================================================= */

:root {
    --dp-primary: #1a3a5c;
    --dp-primary-light: #2a5a8c;
    --dp-cyan: #4fc3f7;
    --dp-bg: #f4f7fb;
    --dp-card: #ffffff;
    --dp-border: #e2e8f0;
    --dp-text: #1a202c;
    --dp-text-secondary: #4a5568;
    --dp-text-muted: #a0aec0;
    --dp-success: #10b981;
    --dp-success-bg: #ecfdf5;
    --dp-warning: #f59e0b;
    --dp-warning-bg: #fffbeb;
    --dp-danger: #ef4444;
    --dp-danger-bg: #fef2f2;
    --dp-info: #3b82f6;
    --dp-radius: 12px;
    --dp-radius-sm: 8px;
    --dp-shadow: 0 1px 3px rgba(0,0,0,0.04), 0 4px 12px rgba(0,0,0,0.04);
    --safe-top: env(safe-area-inset-top, 0px);
    --safe-bottom: env(safe-area-inset-bottom, 0px);
}

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

body {
    font-family: 'DM Sans', -apple-system, 'Segoe UI', system-ui, sans-serif;
    background: var(--dp-bg);
    color: var(--dp-text);
    min-height: 100vh;
    -webkit-font-smoothing: antialiased;
    overflow-x: hidden;
}

/* Header */
.dp-header {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: calc(12px + var(--safe-top)) 16px 12px;
    background: var(--dp-primary);
    color: white;
    position: sticky;
    top: 0;
    z-index: 100;
}

.dp-back {
    color: white;
    text-decoration: none;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 36px;
    height: 36px;
    border-radius: 10px;
    background: rgba(255,255,255,0.12);
    flex-shrink: 0;
}

.dp-header-center {
    flex: 1;
    min-width: 0;
}

.dp-header-center h1 {
    font-size: 18px;
    font-weight: 700;
    line-height: 1.2;
}

.dp-date-label {
    font-size: 12px;
    opacity: 0.75;
    font-weight: 500;
}

.dp-refresh {
    background: rgba(255,255,255,0.12);
    border: none;
    color: white;
    width: 36px;
    height: 36px;
    border-radius: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    flex-shrink: 0;
    transition: background 0.15s;
}

.dp-refresh:active { background: rgba(255,255,255,0.25); }

.dp-refresh.spinning svg {
    animation: spin 0.6s linear;
}

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

/* Date bar */
.dp-date-bar {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 10px 16px;
    background: white;
    border-bottom: 1px solid var(--dp-border);
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
}

.dp-date-btn {
    padding: 7px 14px;
    border-radius: 20px;
    border: 1.5px solid var(--dp-border);
    background: white;
    font-size: 13px;
    font-weight: 600;
    color: var(--dp-text-secondary);
    cursor: pointer;
    white-space: nowrap;
    transition: all 0.15s;
    font-family: inherit;
}

.dp-date-btn.active {
    background: var(--dp-primary);
    color: white;
    border-color: var(--dp-primary);
}

.dp-date-btn:active:not(.active) {
    background: var(--dp-bg);
}

.dp-date-input {
    padding: 7px 10px;
    border-radius: 20px;
    border: 1.5px solid var(--dp-border);
    font-size: 13px;
    font-weight: 500;
    color: var(--dp-text-secondary);
    font-family: inherit;
    background: white;
    margin-left: auto;
    max-width: 140px;
}

/* Stats bar */
.dp-stats {
    display: flex;
    gap: 2px;
    padding: 10px 16px;
    background: white;
    border-bottom: 1px solid var(--dp-border);
}

.dp-stat {
    flex: 1;
    text-align: center;
    padding: 6px 4px;
    border-radius: var(--dp-radius-sm);
}

.dp-stat-value {
    display: block;
    font-size: 20px;
    font-weight: 700;
    line-height: 1.2;
    color: var(--dp-primary);
}

.dp-stat-warning .dp-stat-value {
    color: var(--dp-danger);
}

.dp-stat-label {
    display: block;
    font-size: 11px;
    color: var(--dp-text-muted);
    font-weight: 500;
    margin-top: 2px;
}

/* Tabs */
.dp-tabs {
    display: flex;
    gap: 0;
    padding: 0 16px;
    background: white;
    border-bottom: 2px solid var(--dp-border);
    position: sticky;
    top: 60px;
    z-index: 90;
}

.dp-tab {
    flex: 1;
    padding: 12px 8px;
    border: none;
    background: none;
    font-size: 14px;
    font-weight: 600;
    color: var(--dp-text-muted);
    cursor: pointer;
    position: relative;
    font-family: inherit;
    transition: color 0.15s;
}

.dp-tab.active {
    color: var(--dp-primary);
}

.dp-tab.active::after {
    content: '';
    position: absolute;
    bottom: -2px;
    left: 16px;
    right: 16px;
    height: 2.5px;
    background: var(--dp-primary);
    border-radius: 2px;
}

/* Content area */
.dp-content {
    padding: 12px 16px calc(24px + var(--safe-bottom));
    min-height: 50vh;
}

/* Mission cards */
.dp-mission-card {
    background: var(--dp-card);
    border-radius: var(--dp-radius);
    box-shadow: var(--dp-shadow);
    padding: 14px;
    margin-bottom: 10px;
    cursor: pointer;
    transition: transform 0.1s, box-shadow 0.15s;
    border-left: 4px solid var(--dp-primary-light);
    -webkit-tap-highlight-color: transparent;
}

.dp-mission-card:active {
    transform: scale(0.985);
}

.dp-mission-card.non-assignee {
    border-left-color: var(--dp-danger);
    background: linear-gradient(135deg, #fff 90%, var(--dp-danger-bg));
}

.dp-mission-card.terminee {
    opacity: 0.6;
    border-left-color: var(--dp-success);
}

.dp-mission-card.en-cours {
    border-left-color: var(--dp-warning);
}

.dp-mission-top {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    margin-bottom: 6px;
}

.dp-mission-code {
    font-weight: 700;
    font-size: 15px;
    color: var(--dp-primary);
}

.dp-mission-heure {
    font-size: 13px;
    font-weight: 600;
    color: var(--dp-text-secondary);
    background: var(--dp-bg);
    padding: 2px 8px;
    border-radius: 6px;
}

.dp-mission-route {
    font-size: 13px;
    color: var(--dp-text-secondary);
    margin-bottom: 8px;
    line-height: 1.3;
}

.dp-mission-route .arrow {
    color: var(--dp-text-muted);
    margin: 0 4px;
}

.dp-mission-bottom {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
}

.dp-mission-assignee {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 13px;
    font-weight: 500;
}

.dp-avatar {
    width: 28px;
    height: 28px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 11px;
    font-weight: 700;
    color: white;
    flex-shrink: 0;
}

.dp-avatar.assigned {
    background: var(--dp-primary);
}

.dp-avatar.unassigned {
    background: var(--dp-danger);
}

.dp-badge {
    display: inline-block;
    padding: 3px 8px;
    border-radius: 6px;
    font-size: 11px;
    font-weight: 600;
    white-space: nowrap;
}

.dp-badge-danger {
    background: var(--dp-danger-bg);
    color: var(--dp-danger);
}

.dp-badge-success {
    background: var(--dp-success-bg);
    color: var(--dp-success);
}

.dp-badge-warning {
    background: var(--dp-warning-bg);
    color: var(--dp-warning);
}

.dp-badge-info {
    background: #eff6ff;
    color: var(--dp-info);
}

.dp-mission-vehicle {
    font-size: 12px;
    color: var(--dp-text-muted);
    font-weight: 500;
}

/* Empty state */
.dp-empty {
    text-align: center;
    padding: 48px 24px;
    color: var(--dp-text-muted);
}

.dp-empty-icon {
    font-size: 48px;
    margin-bottom: 12px;
    display: block;
}

.dp-empty-text {
    font-size: 15px;
    font-weight: 500;
}

/* Trajet cards (create tab) */
.dp-trajet-card {
    background: var(--dp-card);
    border-radius: var(--dp-radius);
    box-shadow: var(--dp-shadow);
    padding: 14px;
    margin-bottom: 10px;
    cursor: pointer;
    transition: transform 0.1s;
    border: 1.5px solid var(--dp-border);
    -webkit-tap-highlight-color: transparent;
}

.dp-trajet-card:active {
    transform: scale(0.985);
    border-color: var(--dp-primary);
}

.dp-trajet-code {
    font-weight: 700;
    font-size: 15px;
    color: var(--dp-primary);
    margin-bottom: 4px;
}

.dp-trajet-route {
    font-size: 13px;
    color: var(--dp-text-secondary);
    margin-bottom: 6px;
}

.dp-trajet-meta {
    display: flex;
    gap: 12px;
    font-size: 12px;
    color: var(--dp-text-muted);
    font-weight: 500;
}

/* Create mission form */
.dp-create-form {
    background: var(--dp-card);
    border-radius: var(--dp-radius);
    box-shadow: var(--dp-shadow);
    padding: 16px;
    margin-top: 12px;
}

.dp-create-title {
    font-size: 15px;
    font-weight: 700;
    color: var(--dp-primary);
    margin-bottom: 14px;
}

.dp-form-group {
    margin-bottom: 14px;
}

.dp-form-label {
    display: block;
    font-size: 12px;
    font-weight: 600;
    color: var(--dp-text-secondary);
    margin-bottom: 6px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.dp-form-input {
    width: 100%;
    padding: 10px 12px;
    border: 1.5px solid var(--dp-border);
    border-radius: var(--dp-radius-sm);
    font-size: 14px;
    font-family: inherit;
    color: var(--dp-text);
    background: white;
    transition: border-color 0.15s;
}

.dp-form-input:focus {
    outline: none;
    border-color: var(--dp-primary);
}

/* Pills selector */
.dp-pills {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
}

.dp-pill {
    padding: 8px 12px;
    border-radius: 20px;
    border: 1.5px solid var(--dp-border);
    background: white;
    font-size: 13px;
    font-weight: 500;
    color: var(--dp-text-secondary);
    cursor: pointer;
    font-family: inherit;
    transition: all 0.15s;
    -webkit-tap-highlight-color: transparent;
}

.dp-pill:active { background: var(--dp-bg); }

.dp-pill.selected {
    background: var(--dp-primary);
    color: white;
    border-color: var(--dp-primary);
}

.dp-pill-small {
    padding: 6px 10px;
    font-size: 12px;
}

/* Buttons */
.dp-btn {
    width: 100%;
    padding: 14px;
    border: none;
    border-radius: var(--dp-radius);
    font-size: 15px;
    font-weight: 700;
    cursor: pointer;
    font-family: inherit;
    transition: all 0.15s;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    -webkit-tap-highlight-color: transparent;
}

.dp-btn:active:not(:disabled) {
    transform: scale(0.97);
}

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

.dp-btn-primary {
    background: var(--dp-primary);
    color: white;
}

.dp-btn-success {
    background: var(--dp-success);
    color: white;
}

.dp-btn-danger {
    background: var(--dp-danger);
    color: white;
}

/* Bottom sheet */
.dp-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.4);
    z-index: 200;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.25s;
}

.dp-overlay.active {
    opacity: 1;
    pointer-events: auto;
}

.dp-sheet {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    background: white;
    border-radius: 20px 20px 0 0;
    z-index: 201;
    transform: translateY(100%);
    transition: transform 0.3s cubic-bezier(0.32, 0.72, 0, 1);
    max-height: 85vh;
    display: flex;
    flex-direction: column;
    padding-bottom: var(--safe-bottom);
}

.dp-sheet.active {
    transform: translateY(0);
}

.dp-sheet-handle {
    width: 36px;
    height: 4px;
    background: #d1d5db;
    border-radius: 2px;
    margin: 10px auto 0;
}

.dp-sheet-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 14px 20px 10px;
}

.dp-sheet-header h2 {
    font-size: 17px;
    font-weight: 700;
}

.dp-sheet-close {
    background: none;
    border: none;
    font-size: 24px;
    color: var(--dp-text-muted);
    cursor: pointer;
    width: 36px;
    height: 36px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
}

.dp-sheet-close:active {
    background: var(--dp-bg);
}

.dp-sheet-body {
    padding: 0 20px 20px;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    flex: 1;
}

.dp-sheet-section {
    margin-bottom: 16px;
}

.dp-sheet-section-title {
    font-size: 12px;
    font-weight: 600;
    color: var(--dp-text-muted);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin-bottom: 8px;
}

.dp-sheet-current {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 10px 12px;
    background: var(--dp-bg);
    border-radius: var(--dp-radius-sm);
    margin-bottom: 12px;
    font-size: 13px;
    font-weight: 500;
}

.dp-sheet-current .dp-badge {
    margin-left: auto;
}

/* Toast */
.dp-toast {
    position: fixed;
    bottom: calc(32px + var(--safe-bottom));
    left: 50%;
    transform: translateX(-50%) translateY(100px);
    padding: 12px 20px;
    border-radius: var(--dp-radius);
    font-size: 14px;
    font-weight: 600;
    z-index: 999;
    transition: transform 0.3s cubic-bezier(0.32, 0.72, 0, 1);
    white-space: nowrap;
    box-shadow: 0 8px 24px rgba(0,0,0,0.15);
    max-width: calc(100vw - 32px);
}

.dp-toast.show {
    transform: translateX(-50%) translateY(0);
}

.dp-toast.success {
    background: var(--dp-success);
    color: white;
}

.dp-toast.error {
    background: var(--dp-danger);
    color: white;
}

.dp-toast.info {
    background: var(--dp-primary);
    color: white;
}

/* Loading spinner */
.dp-loading {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 48px;
}

.dp-spinner {
    width: 32px;
    height: 32px;
    border: 3px solid var(--dp-border);
    border-top-color: var(--dp-primary);
    border-radius: 50%;
    animation: spin 0.7s linear infinite;
}

/* Conflict alert */
.dp-conflict {
    background: var(--dp-warning-bg);
    border: 1.5px solid var(--dp-warning);
    border-radius: var(--dp-radius-sm);
    padding: 10px 12px;
    font-size: 13px;
    color: #92400e;
    margin-bottom: 12px;
    font-weight: 500;
    line-height: 1.4;
}

/* Section separator in create tab */
.dp-section-title {
    font-size: 13px;
    font-weight: 700;
    color: var(--dp-text-secondary);
    margin-bottom: 10px;
    margin-top: 4px;
}

/* Search input */
.dp-search {
    width: 100%;
    padding: 10px 12px 10px 36px;
    border: 1.5px solid var(--dp-border);
    border-radius: var(--dp-radius);
    font-size: 14px;
    font-family: inherit;
    color: var(--dp-text);
    background: white url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%23a0aec0' stroke-width='2.5'%3E%3Ccircle cx='11' cy='11' r='8'/%3E%3Cpath d='m21 21-4.3-4.3'/%3E%3C/svg%3E") no-repeat 12px center;
    margin-bottom: 12px;
    transition: border-color 0.15s;
}

.dp-search:focus {
    outline: none;
    border-color: var(--dp-primary);
}

/* Responsive tweaks */
@media (min-width: 480px) {
    .dp-content { max-width: 480px; margin: 0 auto; }
    .dp-date-bar { justify-content: center; }
    .dp-stats { max-width: 480px; margin: 0 auto; }
}
