/* Global Responsive Styles for IR Platform */
/* Optimized for Samsung Galaxy Tab A9 (10.5" - 1920x1200) and all devices */

/* ============================================
   Global Font Family - Inter (Modern UI Font)
   ============================================ */

* {
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif !important;
}

html, body {
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif !important;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-rendering: optimizeLegibility;
}

h1, h2, h3, h4, h5, h6,
.h1, .h2, .h3, .h4, .h5, .h6 {
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif !important;
  font-weight: 600;
  letter-spacing: -0.02em;
}

p, span, div, a, button, input, textarea, select, label, li, td, th {
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif !important;
}

/* ============================================
   Page Loading Overlay - shows while page/data is loading
   ============================================ */
.page-loading-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(255, 255, 255, 0.9);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 99999;
    transition: opacity 0.2s ease, visibility 0.2s ease;
}
.page-loading-overlay.hidden {
    opacity: 0;
    visibility: hidden;
    pointer-events: none;
}
.page-loading-content {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    text-align: center;
    gap: 1rem;
}
.page-loading-content .loader {
    display: inline-block;
    position: relative;
    transform: rotateZ(45deg);
    perspective: 1000px;
    border-radius: 50%;
    width: 48px;
    height: 48px;
    color: #0575E6;
}
.page-loading-content .loader:before,
.page-loading-content .loader:after {
    content: '';
    display: block;
    position: absolute;
    top: 0;
    left: 0;
    width: inherit;
    height: inherit;
    border-radius: 50%;
    transform: rotateX(70deg);
    animation: page-loading-spin 1s linear infinite;
}
.page-loading-content .loader:after {
    color: #003b5c;
    transform: rotateY(70deg);
    animation-delay: 0.4s;
}
@keyframes page-loading-spin {
    0%, 100% { box-shadow: 0.2em 0 0 0 currentcolor; }
    12% { box-shadow: 0.2em 0.2em 0 0 currentcolor; }
    25% { box-shadow: 0 0.2em 0 0 currentcolor; }
    37% { box-shadow: -0.2em 0.2em 0 0 currentcolor; }
    50% { box-shadow: -0.2em 0 0 0 currentcolor; }
    62% { box-shadow: -0.2em -0.2em 0 0 currentcolor; }
    75% { box-shadow: 0 -0.2em 0 0 currentcolor; }
    87% { box-shadow: 0.2em -0.2em 0 0 currentcolor; }
}
.page-loading-text {
    font-size: 0.9375rem;
    color: #344767;
}

/* DataTables processing - same 3D ring loader as page overlay */
div.dataTables_wrapper div.dataTables_processing {
    position: absolute !important;
    top: 50% !important;
    left: 50% !important;
    transform: translate(-50%, -50%) !important;
    width: auto !important;
    min-width: 100px !important;
    margin: 0 !important;
    padding: 1.5rem 1rem !important;
    text-align: center !important;
    border: none !important;
    background: transparent !important;
    box-shadow: none !important;
}
.datatable-processing-inner {
    display: flex !important;
    flex-direction: column !important;
    align-items: center !important;
    justify-content: center !important;
    gap: 0.75rem !important;
}
.datatable-processing-inner .loader {
    display: inline-block !important;
    position: relative !important;
    transform: rotateZ(45deg) !important;
    perspective: 1000px !important;
    border-radius: 50% !important;
    width: 40px !important;
    height: 40px !important;
    color: #0575E6 !important;
    flex-shrink: 0 !important;
}
.datatable-processing-inner .loader:before,
.datatable-processing-inner .loader:after {
    content: '' !important;
    display: block !important;
    position: absolute !important;
    top: 0 !important;
    left: 0 !important;
    width: inherit !important;
    height: inherit !important;
    border-radius: 50% !important;
    transform: rotateX(70deg) !important;
    animation: page-loading-spin 1s linear infinite !important;
}
.datatable-processing-inner .loader:after {
    color: #003b5c !important;
    transform: rotateY(70deg) !important;
    animation-delay: 0.4s !important;
}
.datatable-processing-inner .page-loading-text {
    font-size: 0.875rem !important;
    color: #344767 !important;
}

/* ============================================
   Tablet Optimizations (Samsung Galaxy Tab A9)
   ============================================ */

/* Large Tablets (10.5" - 1920x1200) */
@media (min-width: 992px) and (max-width: 1400px) {
    /* Typography */
    body {
        font-size: 1rem;
    }
    
    h1 { font-size: 2rem; }
    h2 { font-size: 1.75rem; }
    h3 { font-size: 1.5rem; }
    h4 { font-size: 1.25rem; }
    
    /* Containers */
    .container-fluid {
        padding-left: 1.5rem;
        padding-right: 1.5rem;
    }
    
    /* Cards */
    .card {
        border-radius: 16px;
        margin-bottom: 1.5rem;
    }
    
    /* Buttons */
    .btn {
        padding: 12px 24px;
        font-size: 1rem;
        min-height: 44px; /* Touch target */
    }
    
    /* Forms */
    .form-control {
        padding: 12px 16px;
        font-size: 1rem;
        min-height: 44px;
    }
    
    /* Tables */
    .table-responsive {
        font-size: 0.95rem;
    }
    
    /* Navbar */
    .navbar {
        padding: 0.75rem 1rem;
    }
    
    .navbar-brand img {
        max-height: 40px;
    }
}

/* Medium Tablets (768px - 991px) */
@media (min-width: 768px) and (max-width: 991px) {
    body {
        font-size: 0.95rem;
    }
    
    .container-fluid {
        padding-left: 1rem;
        padding-right: 1rem;
    }
    
    .card {
        margin-bottom: 1rem;
    }
    
    .btn {
        padding: 10px 20px;
        font-size: 0.95rem;
    }
    
    .form-control {
        padding: 10px 14px;
        font-size: 0.95rem;
    }
    
    /* Intervention report: wrap action buttons so they fit on tablet */
    .intervention-report-actions {
        flex-wrap: wrap !important;
    }
    .intervention-report-actions .btn {
        flex: 1 1 auto !important;
        min-width: 160px !important;
    }
}

/* ============================================
   Full-page scroll - allow scrolling to footer on ALL viewports
   (soft-ui max-height-vh-100 / h-100 on main otherwise cap height and trap scroll)
   ============================================ */
html {
    overflow-y: auto !important;
    overflow-x: hidden !important;
    height: auto !important;
    min-height: 100vh !important;
    -webkit-overflow-scrolling: touch;
}

body {
    overflow-y: auto !important;
    overflow-x: hidden !important;
    height: auto !important;
    min-height: 100vh !important;
    -webkit-overflow-scrolling: touch;
}

/* Remove height cap from main so content + footer can extend and page scrolls */
main.main-content,
main.main-content.position-relative,
main.main-content.max-height-vh-100,
main.main-content.h-100 {
    max-height: none !important;
    height: auto !important;
    min-height: 0 !important;
    overflow: visible !important;
}

/* Tablet/mobile: extra bottom padding so action buttons stay above taskbar */
@media (max-width: 991px) {
    body {
        padding-bottom: 5rem !important;
    }
    main.main-content .container-fluid {
        padding-bottom: 4rem !important;
        min-height: 0 !important;
        overflow: visible !important;
    }
}

/* ============================================
   Mobile Optimizations
   ============================================ */

@media (max-width: 767px) {
    /* Typography */
    body {
        font-size: 0.9rem;
    }
    
    h1 { font-size: 1.75rem; }
    h2 { font-size: 1.5rem; }
    h3 { font-size: 1.25rem; }
    h4 { font-size: 1.1rem; }
    
    /* Containers */
    .container-fluid {
        padding-left: 0.75rem;
        padding-right: 0.75rem;
    }
    
    /* Cards */
    .card {
        border-radius: 12px;
        margin-bottom: 1rem;
    }
    
    .card-body {
        padding: 1rem !important;
    }
    
    .card-header {
        padding: 1rem !important;
    }
    
    /* Card header with buttons - Stack on mobile */
    .card-header .d-flex.justify-content-between {
        flex-direction: column !important;
        align-items: flex-start !important;
        gap: 0.75rem !important;
    }
    
    .card-header .d-flex.justify-content-between > div:first-child {
        width: 100%;
    }
    
    /* Buttons in card headers - Responsive sizing */
    .card-header .btn,
    .card-header .btn-sm,
    .card-header a.btn {
        width: 100% !important;
        padding: 0.5rem 1rem !important;
        font-size: 0.875rem !important;
        margin: 0 !important;
    }
    
    .card-header h6 {
        font-size: 0.9375rem !important;
    }
    
    /* Buttons */
    .btn {
        padding: 10px 18px;
        font-size: 0.9rem;
        min-height: 44px;
        width: 100%;
        margin-bottom: 0.5rem;
    }
    
    .btn-group .btn {
        width: auto;
    }
    
    /* Intervention report page: wrap action buttons so they fit */
    .intervention-report-actions {
        flex-wrap: wrap !important;
    }
    .intervention-report-actions .btn {
        flex: 1 1 auto !important;
        min-width: 140px !important;
        width: auto !important;
    }
    
    /* Forms */
    .form-control {
        padding: 10px 12px;
        font-size: 16px; /* Prevents zoom on iOS */
        min-height: 44px;
    }
    
    .form-label {
        font-size: 0.9rem;
        margin-bottom: 0.5rem;
    }
    
    /* Tables */
    .table {
        font-size: 0.85rem;
    }
    
    .table-responsive {
        border-radius: 8px;
    }
    
    /* Navbar */
    .navbar {
        padding: 0.5rem 0.75rem;
    }
    
    .navbar-brand img {
        max-height: 35px;
    }
    
    /* Modals */
    .modal-dialog {
        margin: 0.5rem;
    }
    
    .modal-content {
        border-radius: 12px;
    }
    
    /* Alerts */
    .alert {
        padding: 0.75rem 1rem;
        font-size: 0.9rem;
        border-radius: 8px;
    }
}

/* Extra small: intervention report actions stack vertically */
@media (max-width: 576px) {
    .intervention-report-actions {
        flex-direction: column !important;
    }
    .intervention-report-actions .btn {
        width: 100% !important;
        min-width: 0 !important;
    }
}

/* ============================================
   Touch Device Optimizations
   ============================================ */

@media (hover: none) and (pointer: coarse) {
    /* Larger touch targets - exclude .checkbox-control and .btn-sm so form controls and table Select buttons stay normal size */
    a:not(.btn-sm), button:not(.btn-sm), .btn:not(.btn-sm), input[type="checkbox"]:not(.checkbox-control), input[type="radio"]:not(.checkbox-control) {
        min-height: 44px;
        min-width: 44px;
    }
    
    /* Remove hover effects on touch devices */
    .btn:hover {
        transform: none;
    }
    
    /* Better spacing for touch */
    .list-group-item {
        padding: 1rem;
    }
    
    .dropdown-item {
        padding: 0.75rem 1rem;
        min-height: 44px;
    }
}

/* ============================================
   Landscape Orientation
   ============================================ */

@media (min-width: 768px) and (max-width: 1024px) and (orientation: landscape) {
    .main-content {
        min-height: auto;
        padding: 1rem 0;
    }
    
    .page-header {
        min-height: auto;
    }
}

/* ============================================
   High DPI Displays
   ============================================ */

@media (-webkit-min-device-pixel-ratio: 2), (min-resolution: 192dpi) {
    body, input, textarea, select, button {
        -webkit-font-smoothing: antialiased;
        -moz-osx-font-smoothing: grayscale;
    }
}

/* ============================================
   Print Styles
   ============================================ */

@media print {
    .navbar,
    .btn,
    .pwa-install-btn {
        display: none !important;
    }
    
    .card {
        box-shadow: none;
        border: 1px solid #ddd;
    }
    
    body {
        background: white;
    }
}

/* ============================================
   Accessibility
   ============================================ */

/* Focus states for keyboard navigation */
*:focus-visible {
    outline: 3px solid #8392AB;
    outline-offset: 2px;
    border-radius: 4px;
}

/* Skip to content link */
.skip-to-content {
    position: absolute;
    top: -40px;
    left: 0;
    background: #003b5c;
    color: white;
    padding: 8px;
    text-decoration: none;
    z-index: 100;
}

.skip-to-content:focus {
    top: 0;
}

/* ============================================
   Global Responsive Components
   ============================================ */

/* Responsive Navbar */
@media (max-width: 991px) {
    .navbar-collapse {
        background: rgba(255, 255, 255, 0.98);
        border-radius: 12px;
        margin-top: 1rem;
        padding: 1rem;
        box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
    }
    
    .navbar-nav {
        gap: 0.5rem;
    }
    
    .nav-link {
        padding: 0.75rem 1rem !important;
        border-radius: 8px;
        transition: all 0.3s ease;
    }
    
    .nav-link:hover {
        background: rgba(0, 59, 92, 0.05);
    }
}

/* Responsive Tables */
@media (max-width: 991px) {
    .table-responsive {
        border-radius: 12px;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
    }
    
    .table {
        min-width: 600px;
    }
    
    .table th,
    .table td {
        padding: 0.75rem 0.5rem;
        font-size: 0.9rem;
    }
}

/* Responsive Cards */
@media (max-width: 767px) {
    .card {
        margin-bottom: 1rem;
    }
    
    .card-title {
        font-size: 1.1rem;
    }
    
    .card-text {
        font-size: 0.9rem;
    }
}

/* Responsive Forms */
@media (max-width: 767px) {
    .form-row {
        flex-direction: column;
    }
    
    .form-row .col,
    .form-row [class*="col-"] {
        width: 100%;
        margin-bottom: 1rem;
    }
    
    .input-group {
        flex-direction: column;
    }
    
    .input-group > * {
        width: 100% !important;
        margin-bottom: 0.5rem;
    }
}

/* Responsive Modals */
@media (max-width: 767px) {
    .modal-dialog {
        margin: 0.5rem;
        max-width: calc(100% - 1rem);
    }
    
    .modal-header {
        padding: 1rem;
    }
    
    .modal-body {
        padding: 1rem;
    }
    
    .modal-footer {
        padding: 1rem;
        flex-direction: column;
    }
    
    .modal-footer .btn {
        width: 100%;
        margin: 0.25rem 0;
    }
}

/* Responsive Dropdowns */
@media (max-width: 767px) {
    .dropdown-menu {
        width: 100%;
        max-width: 100%;
        border-radius: 12px;
        box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
    }
    
    .dropdown-item {
        padding: 0.75rem 1rem;
        font-size: 0.95rem;
    }
}

/* Responsive Buttons */
@media (max-width: 575px) {
    .btn-group {
        flex-direction: column;
        width: 100%;
    }
    
    .btn-group .btn {
        width: 100%;
        margin: 0.25rem 0;
        border-radius: 8px !important;
    }
    
    .btn-toolbar {
        flex-direction: column;
    }
    
    .btn-toolbar .btn-group {
        width: 100%;
        margin-bottom: 0.5rem;
    }
}

/* Responsive Grid System */
@media (max-width: 767px) {
    .row {
        margin-left: -0.5rem;
        margin-right: -0.5rem;
    }
    
    .row > * {
        padding-left: 0.5rem;
        padding-right: 0.5rem;
    }
    
    /* Make all columns full width on mobile */
    [class*="col-"] {
        flex: 0 0 100%;
        max-width: 100%;
    }
}

/* Responsive Utilities */
@media (max-width: 767px) {
    .text-md-start {
        text-align: center !important;
    }
    
    .text-md-end {
        text-align: center !important;
    }
    
    .d-md-none {
        display: none !important;
    }
    
    .d-md-block {
        display: block !important;
    }
    
    .mb-md-4 {
        margin-bottom: 1rem !important;
    }
    
    .mt-md-4 {
        margin-top: 1rem !important;
    }
    
    .py-md-4 {
        padding-top: 1rem !important;
        padding-bottom: 1rem !important;
    }
    
    .px-md-4 {
        padding-left: 1rem !important;
        padding-right: 1rem !important;
    }
}

/* Responsive Images */
img {
    max-width: 100%;
    height: auto;
    display: block;
}

.img-fluid {
    max-width: 100%;
    height: auto;
}

/* Responsive iframes and videos */
iframe, video, embed, object {
    max-width: 100%;
    height: auto;
}

/* Responsive Typography */
@media (max-width: 575px) {
    .display-1 { font-size: 2rem; }
    .display-2 { font-size: 1.75rem; }
    .display-3 { font-size: 1.5rem; }
    .display-4 { font-size: 1.25rem; }
}

/* Responsive Spacing */
@media (max-width: 767px) {
    .m-5 { margin: 1.5rem !important; }
    .p-5 { padding: 1.5rem !important; }
    .m-4 { margin: 1rem !important; }
    .p-4 { padding: 1rem !important; }
    .m-3 { margin: 0.75rem !important; }
    .p-3 { padding: 0.75rem !important; }
}

/* ============================================
   Performance Optimizations
   ============================================ */

/* Reduce animations on low-end devices */
@media (prefers-reduced-motion: reduce) {
    *,
    *::before,
    *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }
}

/* View eye links - no background, blue icon only (applies across all pages) */
.view-eye-link,
.equipment-view-link,
.intervention-file-view-btn,
a.view-eye-link,
a.equipment-view-link,
.btn.view-eye-link,
.btn.equipment-view-link {
    background: none !important;
    border: none !important;
    box-shadow: none !important;
}
.view-eye-link:hover,
.equipment-view-link:hover,
.intervention-file-view-btn:hover,
a.view-eye-link:hover,
a.equipment-view-link:hover {
    background: transparent !important;
    opacity: 0.8;
}
.file-view-btn {
    background: none !important;
    border: none !important;
    box-shadow: none !important;
}
.file-view-btn:hover {
    background: transparent !important;
    opacity: 0.8;
}

/* Pen/Edit icon - brand blue everywhere */
.fa-pen-to-square,
i.fa-pen-to-square {
    color: #0575E6 !important;
}
