:root {
    --primary: #2563eb;
    --primary-dark: #1d4ed8;
    --bg: #f1f5f9;
    --surface: #ffffff;
    --text: #1e293b;
    --text-muted: #64748b;
    --border: #e2e8f0;
    --success: #10b981;
    --success-bg: #d1fae5;
    --warning: #f59e0b;
    --warning-bg: #fef3c7;
    --danger: #ef4444;
    --danger-bg: #fee2e2;
    --info-bg: #dbeafe;
    --radius: 10px;
    --radius-lg: 14px;
    --shadow: 0 1px 3px rgba(0,0,0,0.08);
}

* { margin: 0; padding: 0; box-sizing: border-box; }
html, body { height: 100%; }
body { font-family: 'Inter', -apple-system, sans-serif; background: var(--bg); color: var(--text); font-size: 15px; line-height: 1.5; -webkit-font-smoothing: antialiased; }

.hidden { display: none !important; }
.screen { min-height: 100vh; }

/* Login */
#login-screen {
    display: flex; align-items: center; justify-content: center;
    background: linear-gradient(135deg, #0f172a, #1e293b); padding: 1rem;
}
.login-card { background: var(--surface); border-radius: var(--radius-lg); padding: 2.5rem; width: 100%; max-width: 380px; }
.login-logo { text-align: center; margin-bottom: 2rem; }
.logo-icon {
    display: inline-flex; align-items: center; justify-content: center;
    width: 52px; height: 52px; background: var(--primary); color: white;
    border-radius: var(--radius); font-weight: 700; font-size: 1.125rem; margin-bottom: 0.75rem;
}
.login-logo h1 { font-size: 1.375rem; }
.login-logo p { color: var(--text-muted); font-size: 0.875rem; }
.form-group { margin-bottom: 1rem; }
.form-group label { display: block; font-weight: 500; margin-bottom: 0.25rem; font-size: 0.875rem; }
.form-group input {
    width: 100%; padding: 0.75rem; border: 1.5px solid var(--border);
    border-radius: var(--radius); font-size: 1rem; font-family: inherit;
}
.form-group input:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px rgba(37,99,235,0.1); }
.alert { padding: 0.75rem; border-radius: var(--radius); font-size: 0.875rem; margin-bottom: 1rem; background: var(--danger-bg); color: var(--danger); }

.btn {
    display: inline-flex; align-items: center; justify-content: center; gap: 0.5rem;
    padding: 0.75rem 1.25rem; border: none; border-radius: var(--radius);
    font-size: 0.9375rem; font-weight: 600; font-family: inherit; cursor: pointer;
}
.btn-primary { background: var(--primary); color: white; }
.btn-primary:hover { background: var(--primary-dark); }
.btn-success { background: var(--success); color: white; }
.btn-warning { background: var(--warning); color: white; }
.btn-danger { background: var(--danger); color: white; }
.btn-outline { background: var(--surface); color: var(--text); border: 1.5px solid var(--border); }
.btn-full { width: 100%; }
.btn-sm { padding: 0.5rem 0.875rem; font-size: 0.8125rem; }

/* Header */
.driver-header {
    display: flex; align-items: center; justify-content: space-between;
    padding: 1rem 1.25rem; background: #0f172a; color: white;
    position: sticky; top: 0; z-index: 100;
}
.driver-info { display: flex; align-items: center; gap: 0.75rem; }
.logo-icon-sm {
    width: 36px; height: 36px; background: var(--primary); border-radius: 8px;
    display: flex; align-items: center; justify-content: center;
    font-weight: 700; font-size: 0.75rem; color: white;
}
.driver-info strong { display: block; font-size: 0.9375rem; }
.driver-info small { color: rgba(255,255,255,0.5); font-size: 0.75rem; }
.btn-icon { background: none; border: none; color: rgba(255,255,255,0.6); cursor: pointer; padding: 0.5rem; border-radius: 8px; }
.btn-icon:hover { color: white; background: rgba(255,255,255,0.1); }

/* Content */
.driver-content { max-width: 600px; margin: 0 auto; padding: 1.25rem; }
.day-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 1rem; }
.day-header h2 { font-size: 1.125rem; }
.date-badge { font-size: 0.8125rem; color: var(--text-muted); background: var(--surface); padding: 0.25rem 0.75rem; border-radius: 999px; border: 1px solid var(--border); }

/* Delivery Cards */
.delivery-list { display: flex; flex-direction: column; gap: 0.875rem; }
.delivery-card {
    background: var(--surface); border-radius: var(--radius-lg); padding: 1.25rem;
    box-shadow: var(--shadow); border: 1px solid var(--border);
    border-left: 4px solid var(--border); transition: all 0.15s;
}
.delivery-card.status-scheduled { border-left-color: var(--primary); }
.delivery-card.status-en_route { border-left-color: var(--warning); }
.delivery-card.status-arrived { border-left-color: #8b5cf6; }
.delivery-card.status-delivered { border-left-color: var(--success); opacity: 0.6; }
.delivery-card.status-failed { border-left-color: var(--danger); opacity: 0.6; }

.delivery-top { display: flex; justify-content: space-between; align-items: flex-start; margin-bottom: 0.75rem; }
.delivery-num { font-size: 0.75rem; font-weight: 700; color: var(--primary); background: var(--info-bg); padding: 0.125rem 0.5rem; border-radius: 4px; }
.delivery-badge { font-size: 0.6875rem; font-weight: 600; text-transform: uppercase; letter-spacing: 0.05em; padding: 0.25rem 0.625rem; border-radius: 999px; }
.delivery-badge.scheduled { background: var(--info-bg); color: var(--primary); }
.delivery-badge.en_route { background: var(--warning-bg); color: #92400e; }
.delivery-badge.arrived { background: #ede9fe; color: #5b21b6; }
.delivery-badge.delivered { background: var(--success-bg); color: #065f46; }
.delivery-badge.failed { background: var(--danger-bg); color: #991b1b; }

.delivery-customer { font-weight: 600; font-size: 1rem; margin-bottom: 0.25rem; }
.delivery-address { color: var(--text-muted); font-size: 0.875rem; margin-bottom: 0.5rem; }
.delivery-notes { font-size: 0.8125rem; padding: 0.5rem 0.75rem; background: #fffbeb; border-radius: 6px; margin-bottom: 0.75rem; border: 1px solid #fde68a; }
.delivery-phone { display: inline-flex; align-items: center; gap: 0.375rem; color: var(--primary); text-decoration: none; font-size: 0.875rem; font-weight: 500; margin-bottom: 0.75rem; }
.delivery-actions { padding: 0; }
.delivery-actions .btn { flex: 1; min-width: 0; }

.loading, .empty-state { text-align: center; padding: 3rem 1rem; color: var(--text-muted); }
.empty-state h3 { font-size: 1rem; color: var(--text); margin-bottom: 0.25rem; }

/* Photo Modal */
.photo-modal {
    position: fixed; top: 0; left: 0; right: 0; bottom: 0;
    background: rgba(0,0,0,0.7); z-index: 1000;
    display: flex; align-items: flex-end; justify-content: center;
    animation: fadeIn 0.2s ease;
}
.photo-modal-content {
    background: white; border-radius: 16px 16px 0 0; width: 100%; max-width: 500px;
    max-height: 90vh; overflow-y: auto; padding: 1.25rem;
}
.photo-modal-header {
    display: flex; justify-content: space-between; align-items: center;
    margin-bottom: 1rem; padding-bottom: 0.75rem; border-bottom: 1px solid #e2e8f0;
}
.photo-modal-header h3 { font-size: 1.125rem; font-weight: 600; margin: 0; }
.photo-close {
    background: none; border: none; font-size: 1.75rem; color: #64748b;
    cursor: pointer; padding: 0; line-height: 1;
}

/* Photo Grid */
.photo-grid {
    display: grid; grid-template-columns: repeat(3, 1fr); gap: 0.5rem;
    margin-bottom: 1rem; min-height: 60px;
}
.photo-thumb {
    position: relative; border-radius: 8px; overflow: hidden;
    aspect-ratio: 1; background: #f1f5f9;
}
.photo-thumb img {
    width: 100%; height: 100%; object-fit: cover; cursor: pointer;
}
.photo-meta {
    position: absolute; bottom: 0; left: 0; right: 0;
    background: rgba(0,0,0,0.6); color: white; font-size: 0.625rem;
    padding: 0.25rem 0.375rem; line-height: 1.3;
}
.photo-delete {
    position: absolute; top: 4px; right: 4px;
    background: rgba(239,68,68,0.9); color: white; border: none;
    width: 22px; height: 22px; border-radius: 50%; font-size: 0.75rem;
    cursor: pointer; display: flex; align-items: center; justify-content: center;
}
.photo-empty {
    grid-column: 1/-1; text-align: center; padding: 2rem;
    color: #64748b; font-size: 0.875rem;
}
.photo-count {
    text-align: center; font-size: 0.8125rem; color: #64748b;
    margin-bottom: 0.75rem;
}

/* Photo Actions */
.photo-actions {
    display: flex; gap: 0.75rem; justify-content: center;
}
.btn-capture {
    display: inline-flex; align-items: center; gap: 0.375rem;
    padding: 0.75rem 1.25rem; border-radius: 10px; font-size: 0.9375rem;
    font-weight: 500; cursor: pointer;
}
.photo-upload-status {
    text-align: center; margin-top: 0.75rem; font-size: 0.875rem;
    color: #2563eb; font-weight: 500;
}

/* Full Photo Viewer */
.photo-viewer {
    position: fixed; top: 0; left: 0; right: 0; bottom: 0;
    background: rgba(0,0,0,0.95); z-index: 2000;
    display: flex; align-items: center; justify-content: center;
    cursor: pointer;
}
.photo-viewer img {
    max-width: 95%; max-height: 95%; object-fit: contain;
    border-radius: 4px;
}

@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }

.route-locked {
    font-size: 0.75rem; color: #ef4444; margin-top: 0.375rem;
    font-weight: 500;
}

/* Delivery tap area */
.delivery-tap { cursor: pointer; }

/* Back button */
.btn-back-driver {
    display: inline-flex; align-items: center; gap: 0.25rem;
    background: none; border: none; color: #2563eb; font-size: 0.9375rem;
    font-weight: 500; font-family: inherit; cursor: pointer;
    padding: 0.5rem 0; margin-bottom: 0.5rem;
}

/* Status banner */
.detail-status-banner {
    text-align: center; padding: 0.75rem; border-radius: 10px;
    margin-bottom: 1rem; font-weight: 600; font-size: 0.9375rem;
    text-transform: capitalize;
}
.detail-status-banner.status-scheduled { background: #fef3c7; color: #92400e; }
.detail-status-banner.status-en_route { background: #dbeafe; color: #1e40af; }
.detail-status-banner.status-arrived { background: #ede9fe; color: #5b21b6; }
.detail-status-banner.status-delivered { background: #d1fae5; color: #065f46; }
.detail-status-banner.status-failed { background: #fee2e2; color: #991b1b; }

/* Detail sections */
.detail-section {
    background: white; border-radius: 12px; padding: 1rem 1.125rem;
    margin-bottom: 0.75rem; box-shadow: 0 1px 3px rgba(0,0,0,0.06);
}
.detail-section-title {
    font-size: 0.75rem; font-weight: 600; text-transform: uppercase;
    letter-spacing: 0.05em; color: #64748b; margin-bottom: 0.75rem;
}
.detail-field {
    display: flex; justify-content: space-between; align-items: flex-start;
    padding: 0.4rem 0; border-bottom: 1px solid #f1f5f9;
}
.detail-field:last-child { border-bottom: none; }
.detail-label { font-size: 0.8125rem; color: #64748b; flex-shrink: 0; }
.detail-val { font-size: 0.875rem; text-align: right; word-break: break-word; }
.detail-link { color: #2563eb; text-decoration: none; }
.detail-address {
    font-size: 0.9375rem; line-height: 1.6; color: #1e293b;
}
.detail-products {
    font-size: 0.875rem; line-height: 1.7; color: #1e293b;
    white-space: pre-line;
}

.detail-address-link {
    display: block; text-decoration: none; color: #1e293b;
    padding: 0.75rem; background: #f8fafc; border-radius: 8px;
    border: 1px solid #e2e8f0; transition: all 0.15s;
}
.detail-address-link:hover, .detail-address-link:active {
    background: #dbeafe; border-color: #2563eb;
}

/* Action buttons */
.btn-action {
    display: flex; align-items: center; justify-content: center; gap: 0.375rem;
    width: 100%; padding: 0.875rem; border: none; border-radius: 10px;
    font-size: 0.9375rem; font-weight: 600; font-family: inherit;
    cursor: pointer; transition: all 0.15s; margin-bottom: 0.5rem;
    text-decoration: none; color: white;
}
.btn-action:last-child { margin-bottom: 0; }
.action-row { display: flex; gap: 0.5rem; margin-bottom: 0.5rem; }
.action-row .btn-action { margin-bottom: 0; }

.btn-start { background: #2563eb; color: white; }
.btn-start:active { background: #1d4ed8; }

.btn-nav { background: #1e293b; color: white; flex: 1; }
.btn-nav:active { background: #0f172a; }

.btn-call { background: #0ea5e9; color: white; flex: 1; }
.btn-call:active { background: #0284c7; }

.btn-arrived { background: #f59e0b; color: white; }
.btn-arrived:active { background: #d97706; }

.btn-upload { background: #10b981; color: white; font-size: 1rem; padding: 1rem; }
.btn-upload:active { background: #059669; }

.btn-cannot { background: #ef4444; color: white; }
.btn-cannot:active { background: #dc2626; }

.btn-photos-done { background: #f1f5f9; color: #475569; font-size: 0.8125rem; padding: 0.625rem; }

.btn-delivered-confirm {
    background: #10b981; color: white; margin-top: 1rem;
    font-size: 1rem; padding: 1rem;
}
.btn-delivered-confirm:active { background: #059669; }

.action-complete {
    text-align: center; padding: 0.75rem; background: #d1fae5;
    color: #065f46; font-weight: 600; border-radius: 10px;
    margin-bottom: 0.5rem; font-size: 0.9375rem;
}
.action-failed {
    text-align: center; padding: 0.75rem; background: #fee2e2;
    color: #991b1b; font-weight: 600; border-radius: 10px;
    margin-bottom: 0.5rem; font-size: 0.9375rem;
}

.action-row-3 {
    display: flex; gap: 0.5rem;
}
.action-row-3 .btn-action {
    flex: 1; margin-bottom: 0; padding: 0.875rem 0.25rem;
    font-size: 0.8125rem; text-align: center;
}

.btn-nav { background: #f59e0b; color: white; }
.btn-nav:active { background: #d97706; }
.btn-arrived { background: #10b981; color: white; }
.btn-arrived:active { background: #059669; }
.action-row-3 .btn-action { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.delivery-actions { width: 100%; }
.action-row-3 { width: 100%; }

/* Notification Banner */
.notif-banner {
    display: flex; align-items: center; justify-content: space-between;
    gap: 0.75rem; padding: 0.875rem 1rem; margin: 0 0 1rem 0;
    background: #fef3c7; border: 1px solid #fbbf24; border-radius: 10px;
    animation: slideDown 0.3s ease;
}
.notif-banner.notif-denied {
    background: #fee2e2; border-color: #fca5a5;
}
.notif-banner.notif-success {
    background: #d1fae5; border-color: #6ee7b7;
}
.notif-banner-text {
    display: flex; flex-direction: column; gap: 0.125rem;
}
.notif-banner-text strong {
    font-size: 0.875rem; color: #1e293b;
}
.notif-banner-text span {
    font-size: 0.75rem; color: #64748b;
}
.notif-banner-btn {
    flex-shrink: 0; padding: 0.5rem 1.25rem; background: #2563eb;
    color: white; border: none; border-radius: 8px; font-size: 0.8125rem;
    font-weight: 600; font-family: inherit; cursor: pointer;
}
.notif-banner-btn:active { background: #1d4ed8; }

@keyframes slideDown {
    from { opacity: 0; transform: translateY(-10px); }
    to { opacity: 1; transform: translateY(0); }
}

/* Driver toast */
.driver-toast {
    position: fixed; top: 1rem; left: 50%; transform: translateX(-50%) translateY(-20px);
    background: #1e293b; color: white; padding: 0.75rem 1.5rem;
    border-radius: 10px; font-size: 0.875rem; font-weight: 500;
    z-index: 9999; opacity: 0; transition: all 0.3s;
    box-shadow: 0 4px 12px rgba(0,0,0,0.3);
}
.driver-toast.visible {
    opacity: 1; transform: translateX(-50%) translateY(0);
}

/* Tomorrow section */
.tomorrow-section {
    margin-top: 1.5rem; padding-top: 1rem;
    border-top: 2px dashed #e2e8f0;
}
.btn-tomorrow {
    background: #1e293b; color: white; width: 100%;
    padding: 1rem; font-size: 1rem;
}
.btn-tomorrow:active { background: #0f172a; }

.btn-back-today {
    display: inline-flex; align-items: center; gap: 0.25rem;
    background: none; border: none; color: #2563eb; font-size: 0.9375rem;
    font-weight: 500; font-family: inherit; cursor: pointer;
    padding: 0.5rem 0; margin-bottom: 0.75rem;
}

.tomorrow-preview {
    text-align: center; padding: 0.625rem; background: #f1f5f9;
    color: #64748b; font-size: 0.8125rem; font-weight: 500;
    border-radius: 8px;
}
