/* Custom styles for Maintenance Management System */

/* =====================================================
   ROOT DESIGN TOKENS
   ===================================================== */
:root {
    /* Brand colors */
    --mm-primary: #0d6efd;
    --mm-secondary: #6c757d;
    --mm-success: #198754;
    --mm-warning: #ffc107;
    --mm-danger: #dc3545;
    --mm-info: #0dcaf0;

    /* Status semantic colors */
    --mm-status-ok: #198754;
    --mm-status-pending: #ffc107;
    --mm-status-overdue: #dc3545;
    --mm-status-progress: #0dcaf0;

    /* Spacing */
    --mm-space-xs: 0.25rem;
    --mm-space-sm: 0.5rem;
    --mm-space-md: 1rem;
    --mm-space-lg: 1.5rem;
    --mm-space-xl: 2rem;

    /* Card */
    --mm-card-radius: 0.5rem;
    --mm-card-shadow: 0 1px 3px rgba(0, 0, 0, 0.3), 0 1px 2px rgba(0, 0, 0, 0.2);
    --mm-card-shadow-hover: 0 4px 12px rgba(0, 0, 0, 0.4);
    --mm-card-padding: 1.25rem;

    /* Table */
    --mm-table-border: rgba(255, 255, 255, 0.08);
    --mm-table-stripe: rgba(255, 255, 255, 0.025);
    --mm-table-hover: rgba(255, 255, 255, 0.05);

    /* Navbar */
    --mm-navbar-height: 56px;
}

/* =====================================================
   GLOBAL BASE STYLES
   ===================================================== */
body {
    font-size: 0.9375rem;
    line-height: 1.6;
}

/* Page titles */
.page-title {
    font-size: 1.5rem;
    font-weight: 600;
    margin: 0;
}

.page-subtitle {
    color: rgba(255, 255, 255, 0.55);
    font-size: 0.875rem;
    margin: 0;
}

/* Section dividers */
.section-divider {
    border-top: 1px solid rgba(255, 255, 255, 0.08);
    margin: var(--mm-space-lg) 0;
}

/* =====================================================
   NAVIGATION
   ===================================================== */
.navbar {
    padding-top: 0.6rem;
    padding-bottom: 0.6rem;
    border-bottom: 1px solid rgba(255, 255, 255, 0.07);
}

.navbar-brand {
    font-weight: 600;
}

.navbar-nav .nav-link {
    font-size: 0.875rem;
    padding: 0.45rem 0.65rem;
    border-radius: 0.35rem;
    transition: background 0.15s, color 0.15s;
    color: rgba(255, 255, 255, 0.75);
}

.navbar-nav .nav-link:hover {
    background: rgba(255, 255, 255, 0.07);
    color: #fff;
}

.navbar-nav .nav-link.active {
    background: rgba(13, 110, 253, 0.2);
    color: #fff;
    font-weight: 500;
}

/* Group nav items visually */
.navbar-nav .nav-item + .nav-item {
    margin-left: 0.1rem;
}

/* iOS-specific logo fixes */
.navbar-logo {
    display: block !important;
    visibility: visible !important;
    opacity: 1 !important;
    height: 36px !important;
    width: auto !important;
    min-height: 36px;
    max-height: 36px;
    object-fit: contain;
    image-rendering: -webkit-optimize-contrast;
    image-rendering: crisp-edges;
    -webkit-user-select: none;
    user-select: none;
    pointer-events: none;
}

@supports (-webkit-touch-callout: none) {
    .navbar-logo {
        -webkit-transform: translateZ(0);
        transform: translateZ(0);
        -webkit-backface-visibility: hidden;
        backface-visibility: hidden;
        will-change: transform;
    }
}

.navbar-text-brand {
    font-weight: 600;
    color: inherit;
    font-size: 0.95rem;
}

/* =====================================================
   PAGE HEADERS (consistent across all pages)
   ===================================================== */
.page-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: var(--mm-space-lg);
    flex-wrap: wrap;
    gap: var(--mm-space-sm);
}

.page-header-left {
    display: flex;
    align-items: center;
    gap: var(--mm-space-md);
}

.page-header-icon {
    width: 48px;
    height: 48px;
    border-radius: 0.5rem;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(13, 110, 253, 0.15);
    color: var(--mm-primary);
    font-size: 1.2rem;
    flex-shrink: 0;
}

.page-header-actions {
    display: flex;
    gap: var(--mm-space-sm);
    align-items: center;
    flex-wrap: wrap;
}

/* =====================================================
   CARDS
   ===================================================== */
.card {
    border-radius: var(--mm-card-radius);
    box-shadow: var(--mm-card-shadow);
    border-color: rgba(255, 255, 255, 0.1);
    transition: box-shadow 0.2s ease;
}

.card:hover {
    box-shadow: var(--mm-card-shadow-hover);
}

.card-header {
    padding: 0.85rem var(--mm-card-padding);
    border-bottom-color: rgba(255, 255, 255, 0.08);
    background: transparent;
    font-weight: 600;
}

.card-header h5,
.card-header h6 {
    font-weight: 600;
    margin: 0;
}

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

/* Metric / stat cards */
.metric-card {
    position: relative;
    overflow: hidden;
    cursor: pointer;
    border: 1px solid rgba(255, 255, 255, 0.1);
}

.metric-card .metric-icon {
    width: 52px;
    height: 52px;
    border-radius: 0.5rem;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.4rem;
    flex-shrink: 0;
}

.metric-card .metric-value {
    font-size: 2rem;
    font-weight: 700;
    line-height: 1;
    margin-bottom: 0.15rem;
}

.metric-card .metric-label {
    font-size: 0.82rem;
    color: rgba(255, 255, 255, 0.6);
    text-transform: uppercase;
    letter-spacing: 0.04em;
}

.metric-card-primary .metric-icon { background: rgba(13, 110, 253, 0.18); color: #6ea8fe; }
.metric-card-info    .metric-icon { background: rgba(13, 202, 240, 0.15); color: #6edff6; }
.metric-card-danger  .metric-icon { background: rgba(220, 53, 69, 0.18);  color: #ea868f; }
.metric-card-warning .metric-icon { background: rgba(255, 193, 7, 0.18);  color: #ffda6a; }
.metric-card-success .metric-icon { background: rgba(25, 135, 84, 0.18);  color: #75b798; }

/* Dashboard card (original, kept for backward compat) */
.dashboard-card {
    transition: transform 0.15s ease, box-shadow 0.15s ease;
}

.dashboard-card:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 20px rgba(0, 0, 0, 0.4) !important;
}

/* =====================================================
   TABLES
   ===================================================== */
.table {
    --bs-table-border-color: var(--mm-table-border);
    font-size: 0.9rem;
}

.table thead th {
    font-size: 0.78rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: rgba(255, 255, 255, 0.55);
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
    padding: 0.65rem 0.85rem;
    white-space: nowrap;
}

.table tbody tr {
    border-bottom: 1px solid var(--mm-table-border);
    transition: background 0.1s;
}

.table tbody tr:hover {
    background-color: var(--mm-table-hover);
}

/* Alternating rows for readability */
.table-striped tbody tr:nth-of-type(odd) {
    background-color: var(--mm-table-stripe);
}

.table tbody td {
    padding: 0.75rem 0.85rem;
    vertical-align: middle;
    border-bottom: 1px solid var(--mm-table-border);
}

.table tbody tr:last-child td {
    border-bottom: none;
}

/* Table danger row */
.table-danger {
    --bs-table-bg: rgba(220, 53, 69, 0.1);
}

/* =====================================================
   FILTER BARS
   ===================================================== */
.filter-card {
    background: rgba(255, 255, 255, 0.03);
    border: 1px solid rgba(255, 255, 255, 0.07);
}

.filter-card .form-label {
    font-size: 0.8rem;
    font-weight: 500;
    color: rgba(255, 255, 255, 0.65);
    text-transform: uppercase;
    letter-spacing: 0.04em;
    margin-bottom: 0.3rem;
}

/* =====================================================
   BUTTONS (consistent sizing & grouping)
   ===================================================== */
.btn-group .btn {
    border-radius: 0;
}

.btn-group .btn:first-child {
    border-radius: 0.375rem 0 0 0.375rem;
}

.btn-group .btn:last-child {
    border-radius: 0 0.375rem 0.375rem 0;
}

/* Action button group for table rows */
.action-btn-group {
    display: flex;
    gap: 0.25rem;
    align-items: center;
    flex-wrap: nowrap;
}

/* =====================================================
   BADGES
   ===================================================== */
.badge {
    font-size: 0.73em;
    font-weight: 500;
    letter-spacing: 0.02em;
    padding: 0.35em 0.6em;
}

/* =====================================================
   MODALS (consistent header/body/footer)
   ===================================================== */
.modal-content {
    border: 1px solid rgba(255, 255, 255, 0.12);
    border-radius: 0.6rem;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.5);
}

.modal-header {
    padding: 1rem 1.25rem;
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
    align-items: center;
}

.modal-title {
    font-size: 1rem;
    font-weight: 600;
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.modal-title i {
    color: var(--mm-primary);
}

.modal-body {
    padding: 1.25rem;
}

.modal-footer {
    padding: 0.85rem 1.25rem;
    border-top: 1px solid rgba(255, 255, 255, 0.1);
    gap: 0.5rem;
}

/* =====================================================
   FORMS (consistent labels, inputs, help text)
   ===================================================== */
.form-label {
    font-size: 0.85rem;
    font-weight: 500;
    margin-bottom: 0.3rem;
    color: rgba(255, 255, 255, 0.85);
}

.form-control:focus,
.form-select:focus {
    border-color: var(--mm-primary);
    box-shadow: 0 0 0 0.2rem rgba(13, 110, 253, 0.2);
}

.form-text {
    font-size: 0.78rem;
    color: rgba(255, 255, 255, 0.5);
}

/* Invalid state */
.form-control.is-invalid,
.form-select.is-invalid {
    border-color: var(--mm-danger);
}

.invalid-feedback {
    font-size: 0.8rem;
}

/* =====================================================
   LIST GROUPS
   ===================================================== */
.list-group-item {
    border-color: rgba(255, 255, 255, 0.08);
    padding: 0.7rem 1rem;
}

.list-group-item-action:hover {
    background-color: rgba(255, 255, 255, 0.05);
}

.list-group-item-danger {
    background-color: rgba(220, 53, 69, 0.1);
    border-color: rgba(220, 53, 69, 0.2);
}

/* =====================================================
   ALERTS
   ===================================================== */
.alert {
    border: none;
    border-radius: 0.4rem;
    font-size: 0.9rem;
}

/* =====================================================
   DASHBOARD SPECIFIC
   ===================================================== */
.dashboard-metric {
    text-align: center;
    padding: var(--mm-space-lg);
}

.dashboard-metric i {
    font-size: 2rem;
    margin-bottom: 0.5rem;
}

/* Recent activity sections */
.activity-list .list-group-item {
    padding: 0.65rem 1rem;
}

/* =====================================================
   BREADCRUMBS
   ===================================================== */
.breadcrumb {
    background-color: transparent;
    padding: 0;
    font-size: 0.85rem;
}

.breadcrumb-item + .breadcrumb-item::before {
    color: rgba(255, 255, 255, 0.4);
}

/* =====================================================
   FILE UPLOAD
   ===================================================== */
.form-control[type="file"] {
    padding: 0.375rem 0.75rem;
}

/* =====================================================
   MOBILE RESPONSIVE
   ===================================================== */
@media (max-width: 768px) {
    .container {
        padding-left: 10px;
        padding-right: 10px;
    }

    .card-body {
        padding: 0.85rem;
    }

    /* Hide desktop tables, show mobile cards */
    .has-mobile-cards .table-responsive {
        display: none !important;
    }

    .has-mobile-cards .mobile-cards {
        display: block !important;
    }

    /* Page header stacking */
    .page-header {
        flex-direction: column;
        align-items: stretch;
        gap: 0.75rem;
    }

    .page-header-actions {
        justify-content: flex-start;
    }

    /* Legacy d-flex headers */
    .d-flex.justify-content-between.align-items-center.mb-4 {
        flex-direction: column !important;
        align-items: stretch !important;
        gap: 0.75rem;
    }

    .d-flex.justify-content-between.align-items-center.mb-4 h2,
    .d-flex.justify-content-between.align-items-center.mb-4 h1 {
        font-size: 1.35rem;
        text-align: center;
    }

    .d-flex.justify-content-between.align-items-center.mb-4 .btn,
    .d-flex.justify-content-between.align-items-center.mb-4 .d-flex.gap-2 {
        width: 100%;
    }

    .d-flex.justify-content-between.align-items-center.mb-4 .d-flex.gap-2 {
        flex-wrap: wrap;
        justify-content: center;
    }

    /* Modals full-screen on mobile */
    .modal-dialog {
        margin: 0;
        max-width: 100%;
        min-height: 100vh;
    }

    .modal-content {
        border-radius: 0;
        min-height: 100vh;
    }

    .modal-body {
        padding: 1rem;
        overflow-y: auto;
        max-height: calc(100vh - 130px);
    }

    .modal-header {
        border-radius: 0;
        position: sticky;
        top: 0;
        z-index: 10;
        background: var(--bs-modal-bg, #212529);
    }

    .modal-footer {
        position: sticky;
        bottom: 0;
        background: var(--bs-modal-bg, #212529);
        border-radius: 0;
        padding: 0.75rem 1rem;
    }

    /* Touch targets */
    .btn {
        min-height: 44px;
        padding: 0.5rem 1rem;
    }

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

    .btn-group .btn {
        padding: 0.5rem 0.75rem;
    }

    /* Form controls */
    .form-control,
    .form-select {
        min-height: 44px;
        font-size: 16px;
    }

    .form-check-input {
        width: 1.25em;
        height: 1.25em;
    }

    .form-check-label {
        padding-left: 0.25rem;
    }

    /* Navbar */
    .navbar-brand span.navbar-text-brand {
        font-size: 0.88rem;
    }

    .navbar-logo {
        height: 30px !important;
        min-height: 30px;
        max-height: 30px;
    }

    /* Badges */
    .badge {
        font-size: 0.68em;
        padding: 0.3em 0.5em;
    }

    .row > [class*="col-md-"] {
        margin-bottom: 0.5rem;
    }

    .alert {
        padding: 0.75rem;
        font-size: 0.875rem;
    }

    .dropdown-menu {
        width: 100%;
        max-width: 280px;
    }

    /* Table headers smaller on mobile fallback */
    .table thead th {
        font-size: 0.72rem;
    }
}

/* =====================================================
   MOBILE CARD COMPONENT
   ===================================================== */
.mobile-cards {
    display: none;
}

.mobile-card {
    background: var(--bs-card-bg, #212529);
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: var(--mm-card-radius);
    padding: 1rem;
    margin-bottom: 0.75rem;
    box-shadow: var(--mm-card-shadow);
}

.mobile-card.border-danger {
    border-left: 3px solid var(--mm-danger);
}

.mobile-card.border-warning {
    border-left: 3px solid var(--mm-warning);
}

.mobile-card-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    margin-bottom: 0.65rem;
    padding-bottom: 0.5rem;
    border-bottom: 1px solid rgba(255, 255, 255, 0.08);
}

.mobile-card-title {
    font-weight: 600;
    font-size: 0.95rem;
    margin: 0;
    flex: 1;
}

.mobile-card-body {
    font-size: 0.875rem;
}

.mobile-card-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0.3rem 0;
    border-bottom: 1px solid rgba(255, 255, 255, 0.04);
}

.mobile-card-row:last-child {
    border-bottom: none;
}

.mobile-card-label {
    color: rgba(255, 255, 255, 0.5);
    font-size: 0.78rem;
    text-transform: uppercase;
    letter-spacing: 0.03em;
    flex-shrink: 0;
    margin-right: 0.5rem;
}

.mobile-card-value {
    font-weight: 500;
    text-align: right;
    font-size: 0.875rem;
}

.mobile-card-actions {
    display: flex;
    gap: 0.4rem;
    margin-top: 0.65rem;
    padding-top: 0.65rem;
    border-top: 1px solid rgba(255, 255, 255, 0.08);
    flex-wrap: wrap;
}

.mobile-card-actions .btn {
    flex: 1;
    min-width: 70px;
    font-size: 0.82rem;
}

/* =====================================================
   DESKTOP OVERRIDE
   ===================================================== */
@media (min-width: 769px) {
    .has-mobile-cards .table-responsive {
        display: block !important;
    }

    .mobile-cards {
        display: none !important;
    }
}

/* =====================================================
   EXTRA SMALL SCREENS
   ===================================================== */
@media (max-width: 480px) {
    .container {
        padding-left: 8px;
        padding-right: 8px;
    }

    h2 {
        font-size: 1.2rem;
    }

    .mobile-card {
        padding: 0.75rem;
    }

    .btn {
        font-size: 0.875rem;
    }
}

/* =====================================================
   PRINT STYLES
   ===================================================== */
@media print {
    .navbar,
    .btn,
    .modal,
    .alert {
        display: none !important;
    }

    .card {
        border: 1px solid #000 !important;
        break-inside: avoid;
    }

    .table {
        color: #000 !important;
    }
}

/* =====================================================
   MISC UTILITIES
   ===================================================== */
.btn:disabled {
    opacity: 0.6;
    cursor: not-allowed;
}

.fade-in {
    animation: fadeIn 0.3s ease-in;
}

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

::-webkit-scrollbar {
    width: 6px;
}

::-webkit-scrollbar-track {
    background: rgba(255, 255, 255, 0.05);
}

::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.25);
    border-radius: 3px;
}

::-webkit-scrollbar-thumb:hover {
    background: rgba(255, 255, 255, 0.4);
}

/* Text utilities */
.text-maintenance-primary { color: var(--mm-primary) !important; }
.bg-maintenance-primary { background-color: var(--mm-primary) !important; }

/* Overdue indicator pulse */
.overdue-indicator {
    position: relative;
}

.overdue-indicator::after {
    content: '';
    position: absolute;
    top: -2px;
    right: -2px;
    width: 10px;
    height: 10px;
    border-radius: 50%;
    background: var(--mm-danger);
    animation: pulse 2s infinite;
}

@keyframes pulse {
    0%   { box-shadow: 0 0 0 0 rgba(220, 53, 69, 0.6); }
    70%  { box-shadow: 0 0 0 8px rgba(220, 53, 69, 0); }
    100% { box-shadow: 0 0 0 0 rgba(220, 53, 69, 0); }
}
