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

:root {
    --primary: #C42B2B;
    --primary-light: #D94444;
    --primary-dark: #9E1E1E;
    --accent: #5A5A5A;
    --bg: #f0f2f5;
    --card: #ffffff;
    --text: #1a1a1a;
    --text-light: #667781;
    --border: #e0e0e0;
    --danger: #dc3545;
    --radius: 12px;
    --shadow: 0 2px 8px rgba(0,0,0,0.08);
    --escorte: #2B6BC4;
    --escorte-dark: #1E4E9E;
    --cctv: #7B2FC4;
    --cctv-dark: #5A1E9E;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background: var(--bg);
    color: var(--text);
    min-height: 100vh;
    -webkit-tap-highlight-color: transparent;
}

.app {
    max-width: 480px;
    margin: 0 auto;
    padding-bottom: 100px;
}

/* HEADER */
.header {
    background: var(--primary);
    color: white;
    padding: 16px 16px 12px;
    display: flex;
    align-items: center;
    gap: 12px;
}

.header-logo {
    width: 48px;
    height: 48px;
    object-fit: contain;
    border-radius: 8px;
    background: white;
    padding: 4px;
}

.header-text h1 {
    font-size: 1.2rem;
    font-weight: 700;
}

.subtitle {
    font-size: 0.8rem;
    opacity: 0.85;
    margin-top: 2px;
}

/* NAV */
.nav {
    display: flex;
    background: var(--card);
    border-bottom: 1px solid var(--border);
    position: sticky;
    top: 0;
    z-index: 100;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    box-shadow: var(--shadow);
}

.nav-btn {
    flex: 0 0 auto;
    min-width: 72px;
    border: none;
    background: none;
    padding: 10px 6px;
    cursor: pointer;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 4px;
    font-size: 0.7rem;
    color: var(--text-light);
    border-bottom: 3px solid transparent;
    transition: all 0.2s;
    white-space: nowrap;
}

.nav-btn.active {
    color: var(--primary);
    border-bottom-color: var(--primary);
    font-weight: 600;
}

.nav-btn-cctv.active {
    color: var(--cctv);
    border-bottom-color: var(--cctv);
}

.nav-btn-escorte.active {
    color: var(--escorte);
    border-bottom-color: var(--escorte);
}

.nav-icon {
    font-size: 1.2rem;
}

.nav-label {
    font-size: 0.65rem;
}

.nav-btn-admin {
    flex: 0 0 auto;
    min-width: 56px;
}

/* TAB CONTENT */
.tab-content {
    display: none;
    padding: 16px;
}

.tab-content.active {
    display: block;
}

.tab-content h2 {
    font-size: 1.15rem;
    margin-bottom: 16px;
    color: var(--primary-dark);
}

/* FORM */
.form {
    display: flex;
    flex-direction: column;
    gap: 14px;
}

.form-group {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.form-group label {
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--text);
}

.form-group input,
.form-group textarea,
.form-group select {
    border: 1.5px solid var(--border);
    border-radius: 8px;
    padding: 10px 12px;
    font-size: 0.95rem;
    font-family: inherit;
    background: var(--card);
    color: var(--text);
    transition: border-color 0.2s;
    width: 100%;
}

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

.form-group textarea {
    resize: vertical;
}

.form-row {
    display: flex;
    gap: 12px;
}

.form-row .form-group {
    flex: 1;
}

/* FIELDSET */
.form-fieldset {
    border: 1.5px solid var(--border);
    border-radius: var(--radius);
    padding: 14px;
    background: var(--card);
}

.form-fieldset legend {
    font-size: 0.9rem;
    font-weight: 700;
    color: var(--primary);
    padding: 0 8px;
}

.form-fieldset .form-group + .form-group {
    margin-top: 10px;
}

/* TOGGLE */
.toggle-group {
    display: flex;
    gap: 8px;
}

.toggle {
    flex: 1;
    cursor: pointer;
}

.toggle input {
    display: none;
}

.toggle span {
    display: block;
    text-align: center;
    padding: 8px 12px;
    border: 1.5px solid var(--border);
    border-radius: 8px;
    font-size: 0.85rem;
    font-weight: 500;
    background: var(--card);
    transition: all 0.2s;
}

.toggle input:checked + span {
    background: var(--primary);
    color: white;
    border-color: var(--primary);
}

/* HIDDEN */
.hidden {
    display: none !important;
}

/* BUTTONS */
.btn {
    border: none;
    border-radius: 8px;
    padding: 12px 20px;
    font-size: 0.95rem;
    font-weight: 600;
    cursor: pointer;
    font-family: inherit;
    transition: all 0.2s;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
}

.btn-preview {
    background: var(--primary);
    color: white;
    width: 100%;
    margin-top: 8px;
}

.btn-preview:active {
    background: var(--primary-dark);
    transform: scale(0.98);
}

.btn-copy {
    background: var(--primary-light);
    color: white;
    flex: 1;
}

.btn-share {
    background: #25d366;
    color: white;
    flex: 1;
}

.btn-copy:active,
.btn-share:active {
    transform: scale(0.97);
}

.btn-small {
    background: var(--primary);
    color: white;
    padding: 8px 16px;
    font-size: 0.85rem;
}

.form-actions {
    margin-top: 4px;
}

/* MODAL */
.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0,0,0,0.5);
    z-index: 1000;
    display: flex;
    align-items: flex-end;
    justify-content: center;
}

.modal {
    background: var(--card);
    border-radius: 16px 16px 0 0;
    width: 100%;
    max-width: 480px;
    max-height: 85vh;
    display: flex;
    flex-direction: column;
    animation: slideUp 0.25s ease;
}

@keyframes slideUp {
    from { transform: translateY(100%); }
    to { transform: translateY(0); }
}

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

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

.modal-close {
    background: none;
    border: none;
    font-size: 1.3rem;
    cursor: pointer;
    color: var(--text-light);
    padding: 4px 8px;
}

.modal-body {
    padding: 16px;
    font-size: 0.85rem;
    line-height: 1.6;
    overflow-y: auto;
    flex: 1;
    white-space: pre-wrap;
    word-wrap: break-word;
    font-family: inherit;
    background: #f8f9fa;
    margin: 12px;
    border-radius: 8px;
}

.modal-actions {
    display: flex;
    gap: 10px;
    padding: 12px 16px 20px;
}

/* ADMIN */
.admin-section {
    background: var(--card);
    border-radius: var(--radius);
    padding: 16px;
    box-shadow: var(--shadow);
}

.admin-section h3 {
    font-size: 1rem;
    margin-bottom: 12px;
    color: var(--primary);
}

.admin-add {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin-bottom: 12px;
}

.admin-add input {
    min-width: 0;
}

.admin-add .btn {
    flex-shrink: 0;
}

@media (max-width: 480px) {
    .admin-add {
        flex-direction: column;
    }
    .admin-add input,
    .admin-add .btn {
        width: 100%;
    }
}

.admin-add input {
    flex: 1;
    border: 1.5px solid var(--border);
    border-radius: 8px;
    padding: 8px 12px;
    font-size: 0.9rem;
    font-family: inherit;
}

.admin-add input:focus {
    outline: none;
    border-color: var(--primary-light);
}

.admin-list {
    list-style: none;
}

.admin-list li {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 10px 12px;
    border-bottom: 1px solid var(--border);
    font-size: 0.9rem;
}

.admin-list li:last-child {
    border-bottom: none;
}

.admin-list .delete-btn {
    background: none;
    border: none;
    color: var(--danger);
    cursor: pointer;
    font-size: 1.1rem;
    padding: 2px 6px;
}

/* ADMIN LOGIN */
.admin-login-box {
    background: var(--card);
    border-radius: var(--radius);
    padding: 24px 16px;
    box-shadow: var(--shadow);
    text-align: center;
}

.admin-login-box h2 {
    margin-bottom: 8px;
    color: var(--primary-dark);
}

.admin-login-desc {
    font-size: 0.85rem;
    color: var(--text-light);
    margin-bottom: 20px;
}

.admin-login-box .form-group {
    text-align: left;
    margin-bottom: 12px;
}

.admin-login-box .btn {
    margin-top: 8px;
}

label.required::after {
    content: ' *';
    color: var(--danger);
    font-weight: 700;
}

.admin-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 16px;
}

.admin-header h2 {
    font-size: 1.15rem;
    color: var(--primary-dark);
}

.btn-logout {
    background: var(--accent) !important;
    font-size: 0.75rem !important;
    padding: 6px 12px !important;
}

.admin-content {
    display: flex;
    flex-direction: column;
    gap: 0;
}

.admin-section + .admin-section {
    margin-top: 16px;
}

.admin-desc {
    font-size: 0.85rem;
    color: var(--text-light);
    margin-bottom: 12px;
}

.share-box {
    background: #f8f9fa;
    border-radius: 8px;
    padding: 12px;
    margin-bottom: 12px;
    border: 1px solid var(--border);
}

.share-url {
    font-size: 0.85rem;
    color: var(--primary);
    font-weight: 600;
    word-break: break-all;
    margin-bottom: 6px;
}

.share-pin {
    font-size: 0.85rem;
    color: var(--text);
}

.share-actions {
    display: flex;
    gap: 8px;
}

.btn-whatsapp {
    background: #25d366 !important;
}

/* TOAST */
.toast {
    position: fixed;
    bottom: 30px;
    left: 50%;
    transform: translateX(-50%);
    background: var(--primary-dark);
    color: white;
    padding: 10px 24px;
    border-radius: 24px;
    font-size: 0.85rem;
    font-weight: 500;
    z-index: 2000;
    animation: fadeInOut 2s ease;
    pointer-events: none;
}

@keyframes fadeInOut {
    0% { opacity: 0; transform: translateX(-50%) translateY(10px); }
    15% { opacity: 1; transform: translateX(-50%) translateY(0); }
    85% { opacity: 1; transform: translateX(-50%) translateY(0); }
    100% { opacity: 0; transform: translateX(-50%) translateY(-10px); }
}

/* PIN SCREEN */
.pin-screen {
    position: fixed;
    inset: 0;
    background: linear-gradient(135deg, #1a1a1a 0%, #2d2d2d 100%);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    z-index: 5000;
    padding: 24px;
}

.pin-screen.hidden {
    display: none !important;
}

.pin-logo {
    width: 120px;
    height: 120px;
    object-fit: contain;
    margin-bottom: 24px;
    border-radius: 16px;
    background: white;
    padding: 12px;
}

.pin-title {
    color: white;
    font-size: 1.3rem;
    font-weight: 700;
    margin-bottom: 6px;
}

.pin-subtitle {
    color: #aaa;
    font-size: 0.85rem;
    margin-bottom: 32px;
}

.pin-dots {
    display: flex;
    gap: 12px;
    margin-bottom: 32px;
}

.pin-dot {
    width: 16px;
    height: 16px;
    border-radius: 50%;
    border: 2px solid #666;
    background: transparent;
    transition: all 0.15s;
}

.pin-dot.filled {
    background: var(--primary);
    border-color: var(--primary);
}

.pin-dot.error {
    background: #ff4444;
    border-color: #ff4444;
    animation: pinShake 0.4s ease;
}

@keyframes pinShake {
    0%, 100% { transform: translateX(0); }
    25% { transform: translateX(-6px); }
    75% { transform: translateX(6px); }
}

.phone-display {
    background: rgba(255,255,255,0.08);
    border: 1.5px solid #555;
    border-radius: 12px;
    padding: 16px 20px;
    margin-bottom: 8px;
    min-width: 260px;
    text-align: center;
}

.phone-text {
    color: white;
    font-size: 1.4rem;
    font-weight: 600;
    letter-spacing: 2px;
    font-family: 'SF Mono', 'Courier New', monospace;
}

.numpad {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 10px;
    max-width: 280px;
    width: 100%;
    margin-top: 16px;
}

.numpad-btn {
    background: rgba(255,255,255,0.1);
    border: 1px solid rgba(255,255,255,0.15);
    color: white;
    font-size: 1.5rem;
    font-weight: 500;
    border-radius: 50%;
    width: 70px;
    height: 70px;
    cursor: pointer;
    transition: all 0.15s;
    display: flex;
    align-items: center;
    justify-content: center;
    margin: 0 auto;
    -webkit-tap-highlight-color: transparent;
    user-select: none;
}

.numpad-btn:active {
    background: rgba(255,255,255,0.25);
    transform: scale(0.95);
}

.numpad-delete {
    font-size: 1.3rem;
    background: rgba(255,255,255,0.05);
}

.numpad-submit {
    background: var(--primary) !important;
    border-color: var(--primary) !important;
    font-size: 1.5rem;
}

.numpad-submit:active {
    background: var(--primary-dark) !important;
}

.phone-display.shake {
    animation: pinShake 0.4s ease;
}

.login-error {
    color: #ff6b6b;
    font-size: 0.85rem;
    text-align: center;
    margin-bottom: 4px;
}

.user-status {
    font-size: 0.75rem;
    padding: 2px 8px;
    border-radius: 10px;
    margin-right: 4px;
}

.user-status.active {
    background: #25d366;
    color: white;
}

.user-status.inactive {
    background: #999;
    color: white;
}

/* ==================== ADMIN SEARCH & PAGINATION ==================== */

.admin-search {
    width: 100%;
    border: 1.5px solid var(--border);
    border-radius: 8px;
    padding: 8px 12px;
    font-size: 0.85rem;
    font-family: inherit;
    margin-bottom: 8px;
}

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

.admin-count {
    font-size: 0.75rem;
    font-weight: 400;
    color: var(--text-light);
    margin-left: 4px;
}

.admin-pagination {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 12px;
    margin-top: 8px;
    font-size: 0.8rem;
    color: var(--text-light);
}

.admin-pagination button {
    background: var(--primary);
    color: white;
    border: none;
    border-radius: 6px;
    padding: 4px 10px;
    font-size: 0.75rem;
    cursor: pointer;
    font-family: inherit;
}

.admin-pagination button:disabled {
    background: var(--border);
    color: var(--text-light);
    cursor: default;
}

/* ==================== CCTV STYLES ==================== */

#cctv-alerte h2,
#cctv-etat h2 {
    color: var(--cctv-dark);
}

#cctv-alerte .btn-preview,
#cctv-etat .btn-preview {
    background: var(--cctv);
}

#cctv-alerte .btn-preview:active,
#cctv-etat .btn-preview:active {
    background: var(--cctv-dark);
}

#cctv-alerte select:focus,
#cctv-alerte input:focus,
#cctv-alerte textarea:focus,
#cctv-etat select:focus,
#cctv-etat input:focus,
#cctv-etat textarea:focus {
    border-color: var(--cctv);
}

/* CCTV État Caméras Grid */
.cctv-etat-grid {
    display: flex;
    flex-direction: column;
    gap: 6px;
    margin-top: 4px;
}

.cctv-etat-row {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 10px;
    border: 1.5px solid var(--border);
    border-radius: 8px;
    background: var(--card);
    transition: all 0.2s;
}

.cctv-etat-row.hs {
    border-color: var(--danger);
    background: #fff5f5;
}

.cctv-etat-row .cam-name {
    flex: 1;
    font-size: 0.85rem;
    font-weight: 500;
}

.cctv-etat-row .cam-status {
    font-size: 0.75rem;
    font-weight: 600;
    padding: 2px 8px;
    border-radius: 10px;
    cursor: pointer;
    user-select: none;
    transition: all 0.2s;
}

.cctv-etat-row .cam-status.ok {
    background: #25d366;
    color: white;
}

.cctv-etat-row .cam-status.hs {
    background: var(--danger);
    color: white;
}

.cctv-etat-row .cam-reason {
    width: 100%;
    margin-top: 4px;
    border: 1px solid var(--border);
    border-radius: 6px;
    padding: 6px 8px;
    font-size: 0.8rem;
    font-family: inherit;
}

.cctv-etat-row-wrap {
    display: flex;
    flex-direction: column;
    gap: 4px;
    padding: 8px 10px;
    border: 1.5px solid var(--border);
    border-radius: 8px;
    background: var(--card);
    transition: all 0.2s;
}

.cctv-etat-row-wrap.hs {
    border-color: var(--danger);
    background: #fff5f5;
}

.cctv-etat-row-wrap .cam-top {
    display: flex;
    align-items: center;
    gap: 8px;
}

/* ==================== ESCORTE STYLES ==================== */

.esc-reminder {
    background: #FFF3CD;
    border: 1.5px solid #FFCA2C;
    border-radius: 8px;
    padding: 10px 14px;
    font-size: 0.8rem;
    font-weight: 600;
    color: #856404;
    text-align: center;
    margin-bottom: 16px;
}

#esc-prise-en-charge h2,
#esc-suivi h2,
#esc-fin-journee h2,
#esc-incident h2,
#esc-handover h2 {
    color: var(--escorte-dark);
}

#esc-prise-en-charge .form-fieldset legend,
#esc-suivi .form-fieldset legend,
#esc-fin-journee .form-fieldset legend,
#esc-incident .form-fieldset legend,
#esc-handover .form-fieldset legend {
    color: var(--escorte);
}

#esc-prise-en-charge .btn-preview,
#esc-suivi .btn-preview,
#esc-fin-journee .btn-preview,
#esc-incident .btn-preview,
#esc-handover .btn-preview {
    background: var(--escorte);
}

#esc-prise-en-charge .btn-preview:active,
#esc-suivi .btn-preview:active,
#esc-fin-journee .btn-preview:active,
#esc-incident .btn-preview:active,
#esc-handover .btn-preview:active {
    background: var(--escorte-dark);
}

.esc-truck-list {
    display: flex;
    flex-direction: column;
    gap: 8px;
    margin-bottom: 10px;
}

.esc-truck-row {
    display: flex;
    align-items: center;
    gap: 8px;
}

.esc-truck-num {
    font-weight: 700;
    font-size: 0.9rem;
    min-width: 24px;
    color: var(--escorte);
}

.esc-truck-input {
    flex: 1;
    border: 1.5px solid var(--border);
    border-radius: 8px;
    padding: 8px 12px;
    font-size: 0.9rem;
    font-family: inherit;
    background: var(--card);
    color: var(--text);
}

.esc-truck-input:focus {
    outline: none;
    border-color: var(--escorte);
}

.esc-truck-remove {
    background: none;
    border: none;
    color: var(--danger);
    font-size: 1.4rem;
    cursor: pointer;
    padding: 0 6px;
    line-height: 1;
}

.btn-add-truck {
    background: var(--escorte) !important;
    align-self: flex-start;
    font-size: 0.8rem !important;
    padding: 6px 14px !important;
}

.btn-add-truck:active {
    background: var(--escorte-dark) !important;
}

/* GEOLOCATION */
.input-with-geo {
    display: flex;
    gap: 6px;
    align-items: stretch;
}

.input-with-geo input {
    flex: 1;
    min-width: 0;
}

.btn-geo {
    background: var(--escorte);
    border: none;
    border-radius: 8px;
    color: white;
    font-size: 1.1rem;
    padding: 0 12px;
    cursor: pointer;
    transition: all 0.2s;
    flex-shrink: 0;
    display: flex;
    align-items: center;
    justify-content: center;
}

.btn-geo:active {
    background: var(--escorte-dark);
    transform: scale(0.95);
}

.btn-geo.loading {
    opacity: 0.6;
    pointer-events: none;
    animation: geoPulse 1s infinite;
}

@keyframes geoPulse {
    0%, 100% { opacity: 0.6; }
    50% { opacity: 1; }
}

.geo-link {
    font-size: 0.75rem;
    color: var(--escorte);
    margin-top: 2px;
    word-break: break-all;
}

.geo-link a {
    color: var(--escorte);
    text-decoration: underline;
}
