/* Custom CSS for FSM Application - Mobile-First Design */

/* Base styles for better mobile experience */
body {
    font-size: 16px; /* Prevent zoom on iOS */
    line-height: 1.5;
}

/* Enhanced touch targets for mobile */
.btn {
    min-height: 44px; /* Apple's recommended touch target size */
    padding: 0.75rem 1rem;
}

.btn-sm {
    min-height: 38px;
    padding: 0.5rem 0.75rem;
}

/* Improved form controls for mobile */
.form-control,
.form-select {
    min-height: 44px;
    font-size: 16px; /* Prevent zoom on iOS */
    border-radius: 0.375rem;
}

.form-control:focus,
.form-select:focus {
    box-shadow: 0 0 0 0.25rem rgba(13, 110, 253, 0.25);
}

/* Card enhancements */
.card {
    border-radius: 0.5rem;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
    margin-bottom: 1rem;
}

.card-header {
    background: var(--bs-gray-100);
    border-bottom: 1px solid var(--bs-border-color);
    padding: 1rem;
}

.card-body {
    padding: 1rem;
}

/* Navigation improvements */
.navbar-brand {
    font-weight: 600;
    font-size: 1.25rem;
}

/* Logo styling */
.navbar-brand img {
    max-height: 32px;
    width: auto;
    object-fit: contain;
}

.navbar-nav .nav-link {
    padding: 0.5rem 0.7rem;
    font-weight: 500;
    white-space: nowrap;
    display: flex;
    align-items: center;
}

/* Keep the expanded navbar compact so all items stay on one tidy line */
@media (min-width: 1200px) and (max-width: 1499px) {
    .navbar-nav .nav-link {
        padding: 0.5rem 0.5rem;
        font-size: 0.9rem;
    }
}

/* Mobile-optimized tables */
.table-responsive {
    border-radius: 0.375rem;
    border: 1px solid var(--bs-border-color);
    -webkit-overflow-scrolling: touch; /* Smooth scrolling on iOS */
}

.table {
    margin-bottom: 0;
    min-width: 800px; /* Ensure tables don't compress too much */
}

.table th {
    border-top: none;
    font-weight: 600;
    background: var(--bs-gray-50);
    white-space: nowrap; /* Prevent header text wrapping */
}

.table td {
    vertical-align: middle;
    padding: 0.75rem 0.5rem; /* Better spacing for mobile */
}

/* Mobile table improvements */
@media (max-width: 768px) {
    .table th,
    .table td {
        padding: 0.5rem 0.25rem;
        font-size: 0.875rem;
    }
}

/* Priority badges and status indicators */
.badge {
    font-size: 0.75em;
    padding: 0.35em 0.65em;
}

/* Dashboard card improvements */
.dashboard-card {
    transition: transform 0.2s ease-in-out, box-shadow 0.2s ease-in-out;
    cursor: pointer;
}

.dashboard-card:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.2);
}

/* Ensure links don't change text color */
a .dashboard-card {
    color: inherit;
}

a:hover .dashboard-card {
    color: inherit;
}

/* Service call priority indicators */
.priority-urgent {
    border-left: 4px solid #dc3545;
}

.priority-high {
    border-left: 4px solid #fd7e14;
}

.priority-normal {
    border-left: 4px solid #6c757d;
}

/* Status indicators */
.status-open {
    color: #0d6efd;
}

.status-assigned {
    color: #17a2b8;
}

.status-hold {
    color: #ffc107;
}

.status-closed {
    color: #198754;
}

.status-cancelled {
    color: #6c757d;
}

/* Customer search dropdown */
.customer-search-dropdown {
    position: absolute;
    top: 100%;
    left: 0;
    right: 0;
    background: white;
    border: 1px solid #ced4da;
    border-radius: 0.375rem;
    box-shadow: 0 0.5rem 1rem rgba(0, 0, 0, 0.15);
    max-height: 200px;
    overflow-y: auto;
    z-index: 1000;
    display: none;
}

.customer-search-item {
    padding: 0.75rem 1rem;
    cursor: pointer;
    border-bottom: 1px solid #dee2e6;
    transition: background-color 0.15s ease-in-out;
}

.customer-search-item:hover {
    background-color: #f8f9fa;
}

.customer-search-item:last-child {
    border-bottom: none;
}

.customer-search-item .customer-name {
    font-weight: 500;
    color: #212529;
}

.customer-search-item .customer-details {
    font-size: 0.875rem;
    color: #6c757d;
    margin-top: 0.25rem;
}

.customer-search-no-results {
    padding: 1rem;
    text-align: center;
    color: #6c757d;
    font-style: italic;
}

/* Mobile optimizations for search */
@media (max-width: 768px) {
    .customer-search-dropdown {
        max-height: 150px;
    }
    
    .customer-search-item {
        padding: 1rem 0.75rem;
        min-height: 60px;
    }
    
    .customer-search-item .customer-name {
        font-size: 1rem;
    }
    
    .customer-search-item .customer-details {
        font-size: 0.8rem;
    }
}

/* Enhanced spacing for mobile */
.container {
    padding-left: 1rem;
    padding-right: 1rem;
}

/* Alert improvements */
.alert {
    border-radius: 0.5rem;
    border: none;
    padding: 1rem;
}

.alert-dismissible .btn-close {
    padding: 1rem;
}

/* Form improvements */
.form-label {
    font-weight: 600;
    margin-bottom: 0.5rem;
}

.form-text {
    font-size: 0.875rem;
    margin-top: 0.25rem;
}

/* Checkbox and radio improvements */
.form-check {
    padding-left: 1.75rem;
    margin-bottom: 0.75rem;
}

.form-check-input {
    width: 1.25rem;
    height: 1.25rem;
    margin-left: -1.75rem;
    margin-top: 0.125rem;
}

.form-check-label {
    margin-left: 0.5rem;
}

/* Modal improvements for mobile */
.modal-dialog {
    margin: 1rem;
}

.modal-content {
    border-radius: 0.5rem;
    border: none;
}

.modal-header {
    border-bottom: 1px solid var(--bs-border-color);
    padding: 1rem;
}

.modal-body {
    padding: 1rem;
}

.modal-footer {
    border-top: 1px solid var(--bs-border-color);
    padding: 1rem;
}

/* Chart container improvements */
.chart-container {
    position: relative;
    height: 300px;
    margin: 1rem 0;
}

/* Loading states */
.loading {
    opacity: 0.6;
    pointer-events: none;
}

.loading::after {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    width: 20px;
    height: 20px;
    border: 2px solid #f3f3f3;
    border-top: 2px solid #007bff;
    border-radius: 50%;
    animation: spin 1s linear infinite;
    transform: translate(-50%, -50%);
}

@keyframes spin {
    0% { transform: translate(-50%, -50%) rotate(0deg); }
    100% { transform: translate(-50%, -50%) rotate(360deg); }
}

/* Responsive improvements */
@media (max-width: 576px) {
    .container {
        padding-left: 0.75rem;
        padding-right: 0.75rem;
    }
    
    .card-body {
        padding: 0.75rem;
    }
    
    .btn {
        font-size: 0.875rem;
    }
    
    .modal-dialog {
        margin: 0.5rem;
    }
    
    /* Stack form elements on small screens */
    .row > .col-md-6,
    .row > .col-md-4,
    .row > .col-md-3 {
        margin-bottom: 1rem;
    }
    
    /* Larger touch targets for checkboxes */
    .form-check {
        padding: 0.75rem;
        background: var(--bs-gray-50);
        border-radius: 0.375rem;
        margin-bottom: 0.5rem;
    }
}

@media (max-width: 768px) {
    /* Horizontal scrolling for action buttons */
    .card-footer .d-flex {
        overflow-x: auto;
        padding-bottom: 0.5rem;
    }
    
    .card-footer .btn {
        white-space: nowrap;
        flex-shrink: 0;
    }
    
    /* Better spacing for dashboard cards */
    .dashboard-card {
        margin-bottom: 1rem;
    }
}

/* Dark theme enhancements */
[data-bs-theme="dark"] .card {
    background: var(--bs-dark);
    border-color: var(--bs-gray-700);
}

[data-bs-theme="dark"] .table th {
    background: var(--bs-gray-800);
}

[data-bs-theme="dark"] .form-check {
    background: var(--bs-gray-800);
}

/* Accessibility improvements */
.sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}

/* Focus indicators */
.btn:focus,
.form-control:focus,
.form-select:focus {
    outline: 2px solid var(--bs-primary);
    outline-offset: 2px;
}

/* Print styles */
@media print {
    .navbar,
    .btn,
    .modal,
    .alert {
        display: none !important;
    }
    
    .card {
        border: 1px solid #000;
        break-inside: avoid;
    }
    
    .container {
        max-width: none;
    }
}

/* Additional mobile enhancements */
@media (max-width: 768px) {
    /* Improve button spacing */
    .btn-group .btn {
        margin-bottom: 0.25rem;
        flex: 1;
    }
    
    /* Better form layout */
    .row .col-md-6 {
        margin-bottom: 1rem;
    }
    
    /* Responsive navigation improvements */
    .navbar-collapse {
        border-top: 1px solid var(--bs-border-color);
        margin-top: 0.5rem;
        padding-top: 0.5rem;
    }
    
    .navbar-nav .nav-item {
        margin-bottom: 0.25rem;
    }
    
    .navbar-nav .nav-link {
        border-radius: 0.375rem;
        margin: 0.125rem 0;
    }
    
    .navbar-nav .nav-link:hover {
        background: var(--bs-gray-100);
    }
    
    /* Mobile-friendly dropdowns */
    .dropdown-menu {
        font-size: 0.95rem;
    }
    
    .dropdown-item {
        padding: 0.75rem 1rem;
        border-radius: 0.375rem;
    }
    
    /* Improve card spacing */
    .card {
        margin-bottom: 1.5rem;
    }
    
    /* Better modals on mobile */
    .modal-dialog {
        margin: 1rem 0.5rem;
    }
    
    /* Improve alerts visibility */
    .alert {
        border-radius: 0.5rem;
        font-weight: 500;
    }
}

/* Touch-friendly enhancements for all screen sizes */
.btn:active,
.btn:focus {
    transform: translateY(1px);
    transition: transform 0.1s ease;
}

.card:hover {
    transition: all 0.2s ease;
}

/* Improved accessibility */
.form-control:focus,
.form-select:focus,
.btn:focus {
    outline: 2px solid var(--bs-primary);
    outline-offset: 2px;
}

/* Animation for smooth transitions */
.fade-in {
    animation: fadeIn 0.3s ease-in;
}

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

/* High contrast mode support */
@media (prefers-contrast: high) {
    .btn {
        border-width: 2px;
    }
    
    .card {
        border-width: 2px;
    }
    
    .badge {
        border: 1px solid currentColor;
    }
}

/* Fixed bottom quick actions for mobile */
.mobile-quick-actions {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    background: var(--bs-white);
    border-top: 1px solid var(--bs-border-color);
    padding: 0.75rem;
    z-index: 1050;
    display: none;
    box-shadow: 0 -2px 10px rgba(0, 0, 0, 0.1);
}

.mobile-quick-actions .btn {
    font-size: 0.75rem;
    padding: 0.5rem 0.25rem;
    border-radius: 0.5rem;
    font-weight: 500;
    text-align: center;
    line-height: 1.2;
    min-height: 50px;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
}

.mobile-quick-actions .btn i {
    font-size: 1.1rem;
    margin-bottom: 2px;
}

.mobile-quick-actions .btn small {
    font-size: 0.7rem;
    line-height: 1;
}

/* Show quick actions only on mobile */
@media (max-width: 768px) {
    .mobile-quick-actions {
        display: block;
    }
    
    /* Add bottom padding to main content to prevent overlap */
    body {
        padding-bottom: 80px;
    }
    
    /* Hide the desktop quick actions section on mobile */
    .desktop-quick-actions {
        display: none;
    }
}

/* Ensure quick actions stay above other elements */
.mobile-quick-actions {
    backdrop-filter: blur(10px);
}

/* Dark theme support for mobile quick actions */
[data-bs-theme="dark"] .mobile-quick-actions {
    background: var(--bs-dark);
    border-top-color: var(--bs-gray-700);
}

/* Reduced motion support */
@media (prefers-reduced-motion: reduce) {
    *,
    *::before,
    *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }
}

/* Tappable call links generated by the linkify_phones filter */
.call-link {
    display: inline-flex;
    align-items: center;
    gap: 0.15rem;
    font-weight: 600;
    color: #2ecc71 !important;
    text-decoration: none;
    white-space: nowrap;
    padding: 0.05rem 0.3rem;
    border-radius: 0.3rem;
    background-color: rgba(46, 204, 113, 0.12);
}
.call-link:hover,
.call-link:focus {
    color: #27ae60 !important;
    background-color: rgba(46, 204, 113, 0.22);
    text-decoration: none;
}
.call-link .fa-phone {
    font-size: 0.85em;
}

/* ===== Dashboard stat cards & service-call grid (mobile-friendly) ===== */
.stat-grid .stat-card,
.stat-card {
    border: none;
    border-radius: 14px;
    color: #e8eef7;
    background: #1f2a3a;
    box-shadow: 0 2px 6px rgba(0,0,0,.12);
    transition: transform .12s ease, box-shadow .12s ease;
    border-left: 5px solid rgba(255,255,255,.25);
}
.stat-card:hover { transform: translateY(-2px); box-shadow: 0 8px 18px rgba(0,0,0,.28); }
.stat-card .card-body { padding: .7rem .85rem; }
.stat-card .stat-label { font-size: .78rem; opacity: .95; font-weight: 600; line-height: 1.1; text-shadow: 0 1px 2px rgba(0,0,0,.25); }
.stat-card .stat-value { font-size: 1.7rem; font-weight: 800; line-height: 1.1; margin-top: .15rem; text-shadow: 0 1px 2px rgba(0,0,0,.25); }
@media (max-width: 575.98px) {
    .stat-card .stat-value { font-size: 1.35rem; }
    .stat-card .stat-label { font-size: .72rem; }
}
/* Full-colour stat cards (white text), vivid + high-contrast for sunlight.
   Each colour is dark enough that the white value/label stays readable. */
.stat-card.accent-blue   { background: linear-gradient(135deg, #2563eb, #1d4ed8); }
.stat-card.accent-indigo { background: linear-gradient(135deg, #4f46e5, #4338ca); }
.stat-card.accent-teal   { background: linear-gradient(135deg, #0d9488, #0f766e); }
.stat-card.accent-cyan   { background: linear-gradient(135deg, #0891b2, #0e7490); }
.stat-card.accent-amber  { background: linear-gradient(135deg, #d97706, #b45309); }
.stat-card.accent-pink   { background: linear-gradient(135deg, #db2777, #be185d); }
.stat-card.accent-red    { background: linear-gradient(135deg, #dc2626, #b91c1c); }
.stat-card.accent-orange { background: linear-gradient(135deg, #ea580c, #c2410c); }
.stat-card.accent-green  { background: linear-gradient(135deg, #16a34a, #15803d); }
.stat-card.accent-grey   { background: linear-gradient(135deg, #64748b, #475569); }
.stat-card.accent-slate  { background: linear-gradient(135deg, #475569, #334155); }

/* Service-call grid */
.sc-grid { width: 100%; table-layout: fixed; }
.sc-grid thead th { font-size: .72rem; letter-spacing: .03em; text-transform: uppercase; color: #6b7280; }
.sc-grid td { vertical-align: top; }
/* Wrap long content so the table fits the screen (no horizontal scroll) */
.sc-grid th, .sc-grid td { word-break: break-word; overflow-wrap: anywhere; white-space: normal; }
.sc-grid .sc-title, .sc-grid .sc-desc { overflow-wrap: anywhere; }
/* Larger, easier-to-read problem description on phones (user feedback) */
@media (max-width: 575.98px) {
    .sc-grid .sc-desc { font-size: .95rem; line-height: 1.35; }
}
.sc-type-badge { background: #3a2a2a; color: #ffd9d0; font-weight: 600; letter-spacing: .02em; }
.sc-pending-badge { letter-spacing: .03em; animation: scPendingPulse 1.6s ease-in-out infinite; }
@keyframes scPendingPulse {
    0%, 100% { box-shadow: 0 0 0 0 rgba(220, 53, 69, .55); }
    50% { box-shadow: 0 0 0 6px rgba(220, 53, 69, 0); }
}
@media (prefers-reduced-motion: reduce) {
    .sc-pending-badge { animation: none; }
}
.sc-expand { width: 30px; height: 30px; padding: 0; line-height: 1; }
.sc-detail td { background: transparent; }
/* Detail row should span full width without forcing scroll */
.sc-detail td { white-space: normal; word-break: break-word; }

/* Dark-theme fixes for components with hardcoded light colours */
[data-bs-theme="dark"] .customer-search-dropdown {
    background: var(--bs-body-bg);
    border-color: var(--bs-border-color);
}
[data-bs-theme="dark"] .customer-search-item { border-bottom-color: var(--bs-border-color); }
[data-bs-theme="dark"] .customer-search-item:hover { background-color: var(--bs-tertiary-bg); }
[data-bs-theme="dark"] .customer-search-item .customer-name { color: var(--bs-body-color); }
[data-bs-theme="dark"] .customer-search-item .customer-details,
[data-bs-theme="dark"] .customer-search-no-results { color: var(--bs-secondary-color); }
[data-bs-theme="dark"] .sc-grid thead th { color: #9aa6b2; }
[data-bs-theme="dark"] .card-header { background: var(--bs-tertiary-bg); }
[data-bs-theme="dark"] .navbar-nav .nav-link:hover { background: var(--bs-tertiary-bg); }

/* ===== Field / bright-sunlight readability (default light theme) ===== */
/* Engineers work outdoors in strong light, so the default theme uses
   high-contrast near-black text, darker "muted" text and stronger borders. */
[data-bs-theme="light"] {
    --bs-body-color: #15181c;          /* near-black body text */
    --bs-secondary-color: #3d4349;     /* darker "muted" text, still secondary */
    --bs-tertiary-color: #565c63;
    --bs-border-color: #c2c9d0;         /* stronger card/table edges */
    --bs-border-color-translucent: rgba(0, 0, 0, .15);
}
[data-bs-theme="light"] .text-muted { color: #3d4349 !important; }
[data-bs-theme="light"] .sc-grid thead th { color: #1f2733; font-weight: 700; }
[data-bs-theme="light"] .sc-grid .sc-title { color: #11141a; }
[data-bs-theme="light"] .sc-grid .sc-desc { color: #353b42 !important; }
[data-bs-theme="light"] .card {
    border: 1px solid #cbd2d9;
    box-shadow: 0 2px 6px rgba(0, 0, 0, .12);
}
/* Stat cards are dark-on-light; brighten their labels for outdoor reading. */
.stat-card .stat-label { opacity: .95; font-weight: 600; }
/* Outline buttons with pale text (warning/info) are hard to read in sunlight:
   darken their resting text/border; keep the bright solid look on hover/active. */
[data-bs-theme="light"] .btn-outline-warning { color: #8a5500; border-color: #c98a00; }
[data-bs-theme="light"] .btn-outline-warning:hover,
[data-bs-theme="light"] .btn-outline-warning:focus {
    color: #15181c; background-color: #ffc107; border-color: #ffc107;
}
[data-bs-theme="light"] .btn-outline-info { color: #0a6678; border-color: #0a8ca6; }
[data-bs-theme="light"] .btn-outline-info:hover,
[data-bs-theme="light"] .btn-outline-info:focus {
    color: #15181c; background-color: #0dcaf0; border-color: #0dcaf0;
}

/* Install App floating button (PWA) */
.install-app-fab {
    position: fixed;
    right: 16px;
    bottom: 16px;
    z-index: 1060;
    border-radius: 999px;
    font-weight: 600;
    box-shadow: 0 4px 14px rgba(0, 0, 0, 0.25);
}

/* Lift it above the mobile quick-actions bar on small screens */
@media (max-width: 768px) {
    .install-app-fab {
        bottom: 92px;
    }
}
