@import url("https://fonts.googleapis.com/css2?family=Poppins:wght@400;500;600;700&display=swap");

/* ========================================
   CSS Variables & Design Tokens
   ======================================== */
:root {
    /* Colors */
    --ink: #2b2b2b;
    --ink-light: #2b2b2b;
    --muted: #6b6b6b;
    --muted-light: #9b9b9b;
    --brand: #f2c94c;
    --brand-dark: #e3b93b;
    --brand-light: #f6d877;
    --accent: #f2c94c;
    --accent-light: #f6d877;
    --success: #6fcf97;
    --success-light: #e9f7ef;
    --warning: #f2994a;
    --warning-light: #fdf1e6;
    --danger: #eb5757;
    --danger-light: #fdecec;
    --info: #56ccf2;
    --info-light: #e7f7fd;
    --card: #ffffff;
    --bg: #ffffff;
    --bg-alt: #f5f5f5;
    --stroke: #bdbdbd;
    --stroke-light: #e6e6e6;
    
    /* Spacing */
    --space-xs: 0.25rem;
    --space-sm: 0.5rem;
    --space-md: 1rem;
    --space-lg: 1.5rem;
    --space-xl: 2rem;
    --space-2xl: 3rem;
    
    /* Border Radius */
    --radius: 10px;
    --radius-sm: 8px;
    --radius-xs: 6px;
    --radius-full: 999px;
    
    /* Shadows */
    --shadow-sm: none;
    --shadow: none;
    --shadow-lg: none;
    --shadow-brand: none;
    
    /* Touch targets - minimum 44px for mobile */
    --touch-target: 48px;
    --touch-target-sm: 44px;
    
    /* Transitions */
    --transition-fast: 150ms ease;
    --transition: 250ms ease;
    --transition-slow: 400ms ease;
}

/* ========================================
   Animations
   ======================================== */
@keyframes floatIn {
    from {
        opacity: 0;
        transform: translateY(12px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

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

@keyframes pulse {
    0%, 100% { transform: scale(1); }
    50% { transform: scale(1.02); }
}

@keyframes shimmer {
    0% { background-position: -200% 0; }
    100% { background-position: 200% 0; }
}

@keyframes slideUp {
    from {
        opacity: 0;
        transform: translateY(20px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* ========================================
   Base Styles
   ======================================== */
*,
*::before,
*::after {
    box-sizing: border-box;
}

html {
    -webkit-tap-highlight-color: transparent;
    -webkit-text-size-adjust: 100%;
    scroll-behavior: smooth;
}

body {
    font-family: "Poppins", "Inter", "Noto Sans", -apple-system, BlinkMacSystemFont, sans-serif;
    margin: 0;
    min-height: 100vh;
    min-height: -webkit-fill-available;
    color: var(--ink);
    line-height: 1.6;
    background: var(--bg);
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

h1, h2, h3, h4, h5, h6 {
    font-family: "Poppins", "Inter", "Noto Sans", -apple-system, BlinkMacSystemFont, sans-serif;
    letter-spacing: 0;
    color: var(--ink);
    margin-top: 0;
    line-height: 1.35;
    font-weight: 600;
}

h1 { font-size: clamp(1.5rem, 5vw, 2rem); }
h2 { font-size: clamp(1.35rem, 4vw, 1.75rem); }
h3 { font-size: clamp(1.15rem, 3vw, 1.4rem); }
h4 { font-size: clamp(1.05rem, 2.5vw, 1.2rem); }
h5 { font-size: 1rem; }

a {
    color: var(--ink);
    text-decoration: none;
    transition: opacity var(--transition-fast);
}

a:hover, a:focus {
    opacity: 0.7;
}

/* ========================================
   Mobile Header (Sticky)
   ======================================== */
.mobile-header {
    position: sticky;
    top: 0;
    z-index: 100;
    background: var(--bg);
    border-bottom: 1px solid var(--stroke-light);
    padding: var(--space-sm) var(--space-md);
    margin: 0 calc(-1 * var(--space-md));
    margin-bottom: var(--space-md);
}

.mobile-header-content {
    display: flex;
    flex-direction: column;
    align-items: stretch;
    gap: var(--space-xs);
    max-width: 100%;
}

.mobile-header-left {
    display: flex;
    align-items: center;
    gap: var(--space-sm);
    min-width: 0;
    flex: 1;
    width: 100%;
}

.mobile-header-left h2 {
    font-size: 1.1rem;
    margin: 0;
    flex: 1;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.mobile-header-actions {
    display: flex;
    align-items: center;
    gap: var(--space-sm);
    width: 100%;
    flex-wrap: nowrap;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
}

.mobile-header-actions .lang-switch {
    margin-left: auto;
}

.mobile-header-actions .btn-group {
    flex-wrap: nowrap;
}

.logout-button {
    order: 99;
}

.header-logo {
    width: 28px;
    height: 28px;
    object-fit: contain;
    display: inline-block;
}

.mobile-header .header-logo {
    width: 24px;
    height: 24px;
}

.admin-header .header-logo {
    width: 32px;
    height: 32px;
}

/* ========================================
   Page Layout
   ======================================== */
.page-shell {
    padding: var(--space-md);
    padding-top: var(--space-lg);
    padding-bottom: calc(var(--space-2xl) + env(safe-area-inset-bottom, 0px));
    animation: floatIn 0.5s ease both;
    max-width: 100%;
    overflow-x: hidden;
}

@media (min-width: 768px) {
    .page-shell {
        padding: var(--space-xl) var(--space-lg);
        padding-bottom: var(--space-2xl);
    }
}

/* ========================================
   Cards - Enhanced for Mobile
   ======================================== */
.card {
    border-radius: var(--radius);
    border: 1px solid var(--stroke);
    background: var(--card);
    animation: slideUp 0.4s ease both;
    transition: border-color var(--transition), transform var(--transition);
    overflow: hidden;
}

.card:hover {
    border-color: var(--stroke);
}

.card-body {
    padding: var(--space-lg);
}

.card-title {
    font-weight: 700;
    margin-bottom: var(--space-sm);
    display: flex;
    align-items: center;
    gap: var(--space-sm);
}

.card-text,
.text-muted {
    color: var(--muted) !important;
    font-size: 0.95rem;
}

/* Mission Cards - Mobile Optimized */
.mission-card {
    margin-bottom: var(--space-md);
}

.mission-card .card {
    transition: transform var(--transition), box-shadow var(--transition);
    cursor: pointer;
}

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

.mission-card .card-title {
    font-size: 1.1rem;
    color: var(--ink);
    margin-bottom: var(--space-sm);
}

.mission-card .card-title i {
    color: var(--muted);
    font-size: 1rem;
}

.mission-card .card-text {
    font-size: 0.95rem;
    margin-bottom: var(--space-xs);
    display: flex;
    align-items: flex-start;
    gap: var(--space-sm);
}

.mission-card .card-text i {
    color: var(--muted);
    flex-shrink: 0;
    margin-top: 2px;
}

/* Status Badges */
.status-badge {
    display: inline-flex;
    align-items: center;
    gap: var(--space-xs);
    padding: var(--space-xs) var(--space-sm);
    border-radius: var(--radius-full);
    font-size: 0.85rem;
    font-weight: 600;
}

.status-badge.completed {
    background: var(--success-light);
    color: var(--success);
}

.status-badge.scheduled {
    background: var(--info-light);
    color: var(--info);
}

.status-badge.pending {
    background: var(--warning-light);
    color: var(--warning);
}

.status-badge.not-completed {
    background: var(--danger-light);
    color: var(--danger);
}

/* ========================================
   Buttons - Touch Optimized
   ======================================== */
.btn {
    border-radius: var(--radius-xs);
    padding: 0.75rem 1.5rem;
    font-weight: 600;
    font-size: 0.95rem;
    letter-spacing: 0.01em;
    min-height: var(--touch-target);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: var(--space-sm);
    transition: all var(--transition);
    border: 1px solid transparent;
    cursor: pointer;
    -webkit-tap-highlight-color: transparent;
    user-select: none;
}

.btn:active {
    transform: scale(0.97);
}

.btn-primary {
    background: var(--brand);
    border-color: var(--brand);
    color: var(--ink);
}

.btn-primary:hover,
.btn-primary:focus {
    background: var(--brand-dark);
    border-color: var(--brand-dark);
    color: var(--ink);
}

.btn-success {
    background: var(--success);
    border-color: var(--success);
    color: var(--ink);
}

.btn-success:hover,
.btn-success:focus {
    background: #047857;
    border-color: #047857;
    color: white;
}

.btn-secondary {
    background: var(--bg-alt);
    border-color: var(--bg-alt);
    color: var(--ink);
}

.btn-secondary:hover,
.btn-secondary:focus {
    background: var(--stroke);
    border-color: var(--stroke);
    color: var(--ink);
}

.btn-outline-secondary {
    background: transparent;
    border-color: var(--stroke);
    color: var(--ink);
}

.btn-outline-secondary:hover,
.btn-outline-secondary:focus {
    background: var(--bg-alt);
    border-color: var(--stroke);
    color: var(--ink);
}

.btn-outline-secondary.active {
    background: var(--brand);
    border-color: var(--brand);
    color: var(--ink);
}

.btn-outline-primary {
    background: transparent;
    border-color: var(--brand);
    color: var(--ink);
}

.btn-outline-primary:hover,
.btn-outline-primary:focus {
    background: var(--brand);
    border-color: var(--brand);
    color: var(--ink);
}

.btn-lg {
    padding: 1rem 2rem;
    font-size: 1.05rem;
    min-height: 56px;
}

.btn-sm {
    padding: 0.5rem 1rem;
    font-size: 0.875rem;
    min-height: var(--touch-target-sm);
}

/* Full width button on mobile */
.btn-block-mobile {
    width: 100%;
}

@media (min-width: 576px) {
    .btn-block-mobile {
        width: auto;
    }
}

/* ========================================
   Forms - Mobile Optimized
   ======================================== */
.form-control,
.form-select {
    border-radius: var(--radius-sm);
    border: 1px solid var(--stroke);
    padding: 0.875rem 1rem;
    font-size: 1rem;
    min-height: var(--touch-target);
    transition: border-color var(--transition);
    background-color: var(--card);
}

.form-control:focus,
.form-select:focus {
    border-color: var(--brand);
    outline: none;
}

.form-control::placeholder {
    color: var(--muted-light);
}

.form-label {
    font-weight: 600;
    color: var(--ink-light);
    margin-bottom: var(--space-sm);
    font-size: 0.9rem;
}

.form-check-input {
    width: 24px;
    height: 24px;
    border-radius: var(--radius-xs);
    border: 1px solid var(--stroke);
    cursor: pointer;
    transition: all var(--transition-fast);
}

.form-check-input:checked {
    background-color: var(--brand);
    border-color: var(--brand);
}

.form-check-input:focus {
    outline: none;
}

.form-check-label {
    font-size: 0.95rem;
    cursor: pointer;
    padding-left: var(--space-sm);
}

/* Toggle Switch */
.form-switch .form-check-input {
    width: 52px;
    height: 28px;
    border-radius: var(--radius-full);
}

.form-switch .form-check-input:checked {
    background-image: url("data:image/svg+xml,%3csvg xmlns='http://www.w3.org/2000/svg' viewBox='-4 -4 8 8'%3e%3ccircle r='3' fill='%23fff'/%3e%3c/svg%3e");
}

textarea.form-control {
    min-height: 120px;
    resize: vertical;
}

/* Input Groups */
.input-group {
    display: flex;
    gap: var(--space-sm);
}

.input-group .form-control {
    flex: 1;
}

.input-group .btn {
    flex-shrink: 0;
}

/* ========================================
   Signature Pad - Touch Optimized
   ======================================== */
.signature-pad {
    background: var(--bg-alt);
    border-radius: var(--radius-sm);
    border: 1px dashed var(--stroke);
    touch-action: none;
    cursor: crosshair;
    transition: border-color var(--transition);
}

.signature-pad:focus,
.signature-pad:active {
    border-color: var(--brand);
    border-style: solid;
}

.signature-pad-container {
    position: relative;
}

.signature-pad-hint {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    color: var(--muted-light);
    font-size: 0.9rem;
    pointer-events: none;
    text-align: center;
}

/* ========================================
   Action Row - Mobile Layout
   ======================================== */
.action-row {
    display: flex;
    gap: var(--space-sm);
    flex-wrap: wrap;
}

@media (max-width: 575.98px) {
    .action-row {
        flex-direction: column;
    }
    
    .action-row .btn {
        width: 100%;
    }
}

/* ========================================
   Language Switcher
   ======================================== */
.lang-switch {
    display: flex;
    align-items: center;
    gap: var(--space-sm);
    flex-wrap: wrap;
}

.lang-switch .btn-group {
    display: flex;
    gap: 2px;
    background: var(--bg-alt);
    padding: 3px;
    border-radius: var(--radius-xs);
}

.lang-switch .btn {
    padding: 0.4rem 0.75rem;
    min-height: 36px;
    font-size: 0.8rem;
    border: none;
    background: transparent;
    color: var(--muted);
}

.lang-switch .btn.active {
    background: var(--card);
    color: var(--ink);
}

/* ========================================
   Auth Card (Login, Forgot Password)
   ======================================== */
.auth-card {
    max-width: 420px;
    width: 100%;
    margin: auto;
}

.auth-card .card-title {
    text-align: center;
    margin-bottom: var(--space-lg);
}

.auth-card .form-control {
    margin-bottom: var(--space-md);
}

.auth-card .btn-primary {
    margin-top: var(--space-sm);
}

/* ========================================
   Document Card
   ======================================== */
.document-card {
    max-width: 900px;
    margin: 0 auto;
}

.document-card pre {
    white-space: pre-wrap;
    font-size: 0.95rem;
    margin-bottom: 0;
    background: var(--bg-alt);
    padding: var(--space-md);
    border-radius: var(--radius-sm);
}

.pdf-frame {
    width: 100%;
    min-height: 70vh;
    border: 1px solid var(--stroke);
    border-radius: var(--radius-sm);
    background: var(--card);
}

/* ========================================
   Photo Grid - Mobile Optimized
   ======================================== */
.photo-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: var(--space-sm);
}

@media (min-width: 576px) {
    .photo-grid {
        grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
        gap: var(--space-md);
    }
}

.photo-grid a {
    display: block;
    aspect-ratio: 1;
    overflow: hidden;
    border-radius: var(--radius-sm);
}

.photo-grid img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    border-radius: var(--radius-sm);
    border: 1px solid var(--stroke);
    transition: transform var(--transition);
}

.photo-grid a:hover img,
.photo-grid a:focus img {
    transform: scale(1.05);
}

.photo-list {
    display: flex;
    flex-direction: column;
    gap: var(--space-sm);
}

.photo-list-row {
    display: flex;
    align-items: center;
    gap: var(--space-sm);
    padding: var(--space-sm);
    border: 1px solid var(--stroke);
    border-radius: var(--radius-sm);
    background: var(--card);
}

.photo-thumb {
    width: 52px;
    height: 52px;
    object-fit: cover;
    border-radius: 10px;
    border: 1px solid var(--stroke);
}

.camera-modal {
    position: fixed;
    inset: 0;
    z-index: 1050;
    background: rgba(15, 23, 42, 0.6);
    display: flex;
    align-items: center;
    justify-content: center;
    padding: var(--space-md);
}

.camera-modal-content {
    width: min(640px, 100%);
    background: var(--card);
    border-radius: var(--radius);
    border: 1px solid var(--stroke);
    display: flex;
    flex-direction: column;
    gap: var(--space-md);
    padding: var(--space-md);
}

.camera-modal-header,
.camera-modal-footer {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: var(--space-sm);
}

.camera-modal-body video {
    width: 100%;
    border-radius: var(--radius-sm);
    background: #000;
}

/* ========================================
   Mission Detail - Mobile Optimized
   ======================================== */
.mission-info-item {
    display: flex;
    flex-direction: column;
    padding: var(--space-md) 0;
    border-bottom: 1px solid var(--stroke-light);
}

.mission-info-item:last-child {
    border-bottom: none;
}

.mission-info-label {
    font-size: 0.8rem;
    font-weight: 600;
    color: var(--muted);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    margin-bottom: var(--space-xs);
}

.mission-info-value {
    font-size: 1rem;
    color: var(--ink);
}

.mission-section {
    margin-top: var(--space-lg);
    padding-top: var(--space-lg);
    border-top: 2px solid var(--stroke-light);
}

.mission-section-title {
    font-size: 1rem;
    font-weight: 700;
    color: var(--ink);
    margin-bottom: var(--space-md);
    display: flex;
    align-items: center;
    gap: var(--space-sm);
}

.mission-section-title i {
    color: var(--brand);
}

/* ========================================
   Client Info Card
   ======================================== */
.client-info-card {
    background: var(--bg-alt);
    border-radius: var(--radius-sm);
    padding: var(--space-md);
}

.client-info-grid {
    display: grid;
    grid-template-columns: 1fr;
    gap: var(--space-sm);
}

@media (min-width: 576px) {
    .client-info-grid {
        grid-template-columns: repeat(2, 1fr);
    }
}

/* ========================================
   Comments Section
   ======================================== */
.comment-box {
    background: var(--bg-alt);
    border-radius: var(--radius-sm);
    padding: var(--space-md);
    margin-bottom: var(--space-sm);
}

.comment-label {
    font-size: 0.75rem;
    font-weight: 600;
    color: var(--muted);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    margin-bottom: var(--space-xs);
}

.comment-text {
    font-size: 0.95rem;
    color: var(--ink);
    line-height: 1.5;
}

/* ========================================
   Loading States
   ======================================== */
.loading {
    position: relative;
    pointer-events: none;
}

.loading::after {
    content: "";
    position: absolute;
    inset: 0;
    background: rgba(0, 0, 0, 0.03);
}

.btn.loading {
    color: transparent;
}

.btn.loading::before {
    content: "";
    position: absolute;
    width: 20px;
    height: 20px;
    border: 2px solid currentColor;
    border-right-color: transparent;
    border-radius: 50%;
    animation: spin 0.75s linear infinite;
}

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

/* ========================================
   Empty States
   ======================================== */
.empty-state {
    text-align: center;
    padding: var(--space-2xl) var(--space-lg);
    color: var(--muted);
}

.empty-state-icon {
    font-size: 3rem;
    margin-bottom: var(--space-md);
    opacity: 0.5;
}

.empty-state-title {
    font-size: 1.1rem;
    font-weight: 600;
    color: var(--ink);
    margin-bottom: var(--space-sm);
}

.empty-state-text {
    font-size: 0.95rem;
}

/* ========================================
   Alerts & Notifications
   ======================================== */
.alert {
    border-radius: var(--radius-sm);
    padding: var(--space-md);
    margin-bottom: var(--space-md);
    border: none;
    display: flex;
    align-items: flex-start;
    gap: var(--space-sm);
}

.alert-success {
    background: var(--success-light);
    color: var(--success);
}

.alert-warning {
    background: var(--warning-light);
    color: var(--warning);
}

.alert-danger {
    background: var(--danger-light);
    color: var(--danger);
}

.alert-info {
    background: var(--info-light);
    color: var(--info);
}

/* ========================================
   Tables - Mobile Responsive
   ======================================== */
.table-responsive {
    border-radius: var(--radius-sm);
    overflow: hidden;
}

.table {
    margin-bottom: 0;
}

.table th {
    font-weight: 600;
    font-size: 0.8rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--muted);
    border-bottom: 2px solid var(--stroke);
    padding: var(--space-md);
}

.table td {
    padding: var(--space-md);
    vertical-align: middle;
    border-bottom: 1px solid var(--stroke-light);
}

/* ========================================
   Admin Specific Styles
   ======================================== */
.admin-header {
    display: flex;
    flex-direction: column;
    gap: var(--space-md);
    margin-bottom: var(--space-lg);
}

@media (min-width: 768px) {
    .admin-header {
        flex-direction: row;
        align-items: center;
        justify-content: space-between;
    }
}

.admin-filters {
    display: flex;
    flex-wrap: wrap;
    gap: var(--space-sm);
    margin-bottom: var(--space-md);
}

/* ========================================
   Utilities
   ======================================== */
.text-success { color: var(--success) !important; }
.text-warning { color: var(--warning) !important; }
.text-danger { color: var(--danger) !important; }
.text-info { color: var(--info) !important; }
.text-brand { color: var(--brand) !important; }

.bg-success-light { background: var(--success-light) !important; }
.bg-warning-light { background: var(--warning-light) !important; }
.bg-danger-light { background: var(--danger-light) !important; }
.bg-info-light { background: var(--info-light) !important; }

.rounded-lg { border-radius: var(--radius) !important; }
.rounded-sm { border-radius: var(--radius-sm) !important; }
.rounded-full { border-radius: var(--radius-full) !important; }

.shadow-sm { box-shadow: var(--shadow-sm) !important; }
.shadow { box-shadow: var(--shadow) !important; }
.shadow-lg { box-shadow: var(--shadow-lg) !important; }

/* Safe area padding for notched devices */
.safe-area-bottom {
    padding-bottom: env(safe-area-inset-bottom, 0px);
}

/* Hide on mobile */
@media (max-width: 575.98px) {
    .hide-mobile { display: none !important; }
}

/* Hide on desktop */
@media (min-width: 576px) {
    .hide-desktop { display: none !important; }
}

/* ========================================
   Mobile Specific Overrides
   ======================================== */
@media (max-width: 575.98px) {
    h1 {
        font-size: 1.5rem;
    }

    h2 {
        font-size: 1.35rem;
    }

    .page-shell {
        padding: var(--space-md);
        padding-bottom: calc(var(--space-xl) + env(safe-area-inset-bottom, 20px));
    }

    .card-body {
        padding: var(--space-md);
    }

    .input-group {
        flex-direction: column;
        gap: var(--space-sm);
    }

    .input-group .form-control {
        width: 100%;
        border-radius: var(--radius-sm);
    }

    .input-group .btn {
        width: 100%;
    }

    .pdf-frame {
        min-height: 60vh;
    }
    
    /* Larger touch targets on mobile */
    .btn {
        min-height: 52px;
        padding: 0.875rem 1.25rem;
    }
    
    .btn-sm {
        min-height: var(--touch-target);
    }
    
    .form-control,
    .form-select {
        min-height: 52px;
        font-size: 16px; /* Prevents iOS zoom on focus */
    }
    
    /* Stack language switch on mobile */
    .lang-switch {
        width: 100%;
        justify-content: flex-end;
    }
}

/* ========================================
   Print Styles
   ======================================== */
@media print {
    body {
        background: white;
    }
    
    .card {
        box-shadow: none;
        border: 1px solid #ddd;
    }
    
    .btn,
    .lang-switch,
    .mobile-header {
        display: none !important;
    }
}
