/* ==========================================================================
   RIMS Institutional Design System CSS
   ========================================================================== */

:root {
    --rims-primary: #1e3a8a;
    --rims-primary-hover: #1e40af;
    --rims-sidebar-bg: #0f172a;
    --rims-sidebar-text: #94a3b8;
    --rims-sidebar-hover: #1e293b;
    --rims-sidebar-active: #3b82f6;
    --rims-header-bg: #ffffff;
    --rims-border: #e2e8f0;
    --rims-bg-body: #f8fafc;
    --rims-card-bg: #ffffff;
    --rims-text-main: #0f172a;
    --rims-text-muted: #64748b;
    --rims-font: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
}

body {
    font-family: var(--rims-font);
    background-color: var(--rims-bg-body);
    color: var(--rims-text-main);
    margin: 0;
    padding: 0;
    font-size: 0.9rem;
}

/* App Layout Grid */
.app-layout {
    display: flex;
    min-height: 100vh;
}

/* Sidebar */
.app-sidebar {
    width: 250px;
    background-color: var(--rims-sidebar-bg);
    color: var(--rims-sidebar-text);
    display: flex;
    flex-direction: column;
    flex-shrink: 0;
    position: sticky;
    top: 0;
    height: 100vh;
    border-right: 1px solid #1e293b;
    z-index: 100;
}

.sidebar-header {
    padding: 1.25rem 1.25rem 1rem;
    border-bottom: 1px solid #1e293b;
}

.sidebar-brand {
    display: flex;
    align-items: center;
    text-decoration: none;
    color: #ffffff;
    font-weight: 700;
    font-size: 1.15rem;
    letter-spacing: 0.5px;
}

.brand-badge {
    background-color: var(--rims-primary);
    color: white;
    width: 32px;
    height: 32px;
    border-radius: 6px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    margin-right: 0.6rem;
    font-size: 1rem;
}

.brand-subtitle {
    display: block;
    font-size: 0.7rem;
    text-transform: uppercase;
    color: #64748b;
    letter-spacing: 1px;
    margin-top: 0.25rem;
    padding-left: 2.6rem;
}

.sidebar-nav {
    flex: 1;
    overflow-y: auto;
    padding: 0.75rem 0.5rem;
}

.nav-list {
    list-style: none;
    padding: 0;
    margin: 0;
}

.nav-section-title {
    font-size: 0.68rem;
    font-weight: 600;
    text-transform: uppercase;
    color: #64748b;
    letter-spacing: 0.75px;
    padding: 0.75rem 0.75rem 0.25rem;
}

.nav-link {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.55rem 0.75rem;
    color: #94a3b8;
    text-decoration: none;
    border-radius: 6px;
    font-size: 0.85rem;
    font-weight: 500;
    transition: all 0.15s ease;
}

.nav-link i {
    font-size: 1.05rem;
}

.nav-link:hover {
    background-color: var(--rims-sidebar-hover);
    color: #f1f5f9;
}

.nav-link.active {
    background-color: var(--rims-primary);
    color: #ffffff;
    font-weight: 600;
}

.sidebar-footer {
    padding: 1rem;
    border-top: 1px solid #1e293b;
    background-color: rgba(0, 0, 0, 0.2);
}

.user-profile {
    display: flex;
    align-items: center;
}

.user-meta .user-name {
    font-size: 0.82rem;
    color: #f1f5f9;
    max-width: 170px;
}

.user-meta .user-role {
    font-size: 0.65rem;
}

/* Main Area */
.app-main {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-width: 0;
}

/* Compact Header */
.app-header {
    background-color: var(--rims-header-bg);
    border-bottom: 1px solid var(--rims-border);
    padding: 0.9rem 1.5rem;
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.page-header-title {
    font-size: 1.25rem;
    font-weight: 700;
    margin: 0;
    color: var(--rims-text-main);
    line-height: 1.2;
}

.page-header-subtitle {
    font-size: 0.8rem;
}

.app-content {
    flex: 1;
    padding: 1.5rem;
}

.app-footer {
    background-color: var(--rims-header-bg);
    border-top: 1px solid var(--rims-border);
    padding: 0.75rem 1.5rem;
}

/* Cards */
.rims-card {
    background: var(--rims-card-bg);
    border: 1px solid var(--rims-border);
    border-radius: 8px;
    box-shadow: 0 1px 2px 0 rgba(0, 0, 0, 0.04);
    margin-bottom: 1.25rem;
}

.rims-card-header {
    padding: 0.85rem 1.25rem;
    border-bottom: 1px solid var(--rims-border);
    background-color: #fafbfc;
    display: flex;
    align-items: center;
    justify-content: space-between;
    border-top-left-radius: 8px;
    border-top-right-radius: 8px;
}

.rims-card-title {
    font-size: 0.95rem;
    font-weight: 600;
    margin: 0;
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.rims-card-body {
    padding: 1.25rem;
}

/* Table Styling */
.rims-table {
    margin-bottom: 0;
    font-size: 0.86rem;
}

.rims-table th {
    background-color: #f1f5f9;
    color: #475569;
    font-weight: 600;
    font-size: 0.78rem;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    border-bottom: 1px solid var(--rims-border);
    padding: 0.65rem 0.85rem;
    vertical-align: middle;
}

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

.rims-table tbody tr:hover {
    background-color: #f8fafc;
}

/* Status Badges */
.badge-active {
    background-color: #ecfdf5;
    color: #065f46;
    border: 1px solid #a7f3d0;
    font-weight: 600;
    font-size: 0.72rem;
    padding: 0.25rem 0.5rem;
    border-radius: 4px;
}

.badge-inactive {
    background-color: #f1f5f9;
    color: #475569;
    border: 1px solid #cbd5e1;
    font-weight: 500;
    font-size: 0.72rem;
    padding: 0.25rem 0.5rem;
    border-radius: 4px;
}

.badge-needs-attention {
    background-color: #fff1f2;
    color: #be123c;
    border: 1px solid #fecdd3;
    font-weight: 600;
    font-size: 0.72rem;
    padding: 0.25rem 0.5rem;
    border-radius: 4px;
}

.badge-ok {
    background-color: #f0fdf4;
    color: #166534;
    border: 1px solid #bbf7d0;
    font-weight: 600;
    font-size: 0.72rem;
    padding: 0.25rem 0.5rem;
    border-radius: 4px;
}

/* Dashboard Metric Cards */
.metric-card {
    border-radius: 8px;
    padding: 1.2rem;
    background: #ffffff;
    border: 1px solid var(--rims-border);
    display: flex;
    align-items: center;
    gap: 1rem;
    box-shadow: 0 1px 3px 0 rgba(0, 0, 0, 0.04);
}

.metric-icon {
    width: 48px;
    height: 48px;
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.4rem;
}

.metric-data h3 {
    font-size: 1.6rem;
    font-weight: 700;
    margin: 0;
    line-height: 1.1;
}

.metric-data p {
    font-size: 0.8rem;
    color: var(--rims-text-muted);
    margin: 0;
    text-transform: uppercase;
    font-weight: 600;
    letter-spacing: 0.5px;
}

/* Empty State */
.empty-state {
    padding: 3rem 1.5rem;
    text-align: center;
}

.empty-state-icon {
    font-size: 2.75rem;
    color: #94a3b8;
    margin-bottom: 0.75rem;
}

.empty-state h4 {
    font-size: 1.1rem;
    font-weight: 600;
    margin-bottom: 0.5rem;
}

.empty-state p {
    color: var(--rims-text-muted);
    font-size: 0.875rem;
    max-width: 420px;
    margin: 0 auto 1.25rem;
}

/* ==========================================================================
   ASP.NET Core Validation Summary
   Hide empty validation summary containers rendered by framework TagHelper
   ========================================================================== */
.validation-summary-valid {
    display: none !important;
}

/* ==========================================================================
   Mobile Responsive Architecture (< 992px)
   ========================================================================== */
@media (max-width: 991.98px) {
    /* Off-canvas sidebar */
    .app-sidebar {
        position: fixed;
        top: 0;
        left: 0;
        bottom: 0;
        width: 270px;
        height: 100vh;
        z-index: 1050;
        transform: translateX(-100%);
        transition: transform 0.25s ease-in-out;
        box-shadow: 0 0.5rem 1rem rgba(0, 0, 0, 0.25);
    }

    body.sidebar-open .app-sidebar {
        transform: translateX(0);
    }

    /* Off-canvas backdrop */
    .sidebar-backdrop {
        display: none;
    }

    body.sidebar-open .sidebar-backdrop {
        display: block;
        position: fixed;
        top: 0;
        left: 0;
        right: 0;
        bottom: 0;
        background-color: rgba(15, 23, 42, 0.6);
        z-index: 1040;
    }

    body.sidebar-open {
        overflow: hidden;
    }

    /* Full width main container */
    .app-main {
        width: 100%;
        min-width: 0;
        flex: 1;
    }

    .app-content {
        padding: 1rem 0.75rem;
        min-width: 0;
        width: 100%;
    }

    /* Responsive header */
    .app-header {
        padding: 0.75rem 1rem;
        flex-wrap: wrap;
        gap: 0.5rem;
    }

    .app-header .header-left {
        min-width: 0;
        flex: 1;
    }

    .app-header .page-header-title {
        font-size: 1.15rem;
    }

    .app-header .header-right {
        display: flex;
        flex-wrap: wrap;
        gap: 0.5rem;
        justify-content: flex-start;
        width: 100%;
    }
}

/* ==========================================================================
   Mobile Form & Inspection Responsive Presentation (< 768px)
   ========================================================================== */
@media (max-width: 767.98px) {
    /* New Inspection entry card treatment */
    #inspectionEntryTable {
        border: none;
    }

    #inspectionEntryTable thead {
        display: none;
    }

    #inspectionEntryTable tbody,
    #inspectionEntryTable tr.inspection-row {
        display: block;
        width: 100%;
    }

    #inspectionEntryTable tr.inspection-row {
        background: #ffffff;
        border: 1px solid var(--rims-border);
        border-radius: 8px;
        padding: 0.85rem;
        margin-bottom: 0.85rem;
        box-shadow: 0 1px 2px rgba(0, 0, 0, 0.04);
    }

    #inspectionEntryTable tr.inspection-row > td {
        display: block;
        width: 100% !important;
        padding: 0.25rem 0;
        border: none;
        text-align: left !important;
    }

    .mobile-field-label {
        font-size: 0.75rem;
        font-weight: 600;
        color: var(--rims-text-muted);
        text-transform: uppercase;
        margin-bottom: 0.2rem;
        display: block;
    }

    /* Metric cards on mobile */
    .metric-card {
        padding: 0.85rem;
    }

    .metric-icon {
        width: 40px;
        height: 40px;
        font-size: 1.2rem;
    }

    .metric-data h3 {
        font-size: 1.3rem;
    }
}

/* ==========================================================================
   Print Stylesheet
   ========================================================================== */
@media print {
    @page {
        margin: 10mm;
    }

    .app-sidebar,
    .sidebar-backdrop,
    #sidebarToggle,
    .app-header,
    .app-footer,
    .no-print,
    .btn,
    .filter-card,
    .modal {
        display: none !important;
    }

    html, body {
        background: #ffffff !important;
        color: #000000 !important;
        font-size: 8pt !important;
        margin: 0 !important;
        padding: 0 !important;
        width: 100% !important;
    }

    /* Remove flex layout constraints */
    .app-layout,
    .app-main,
    .app-content {
        display: block !important;
        width: 100% !important;
        max-width: 100% !important;
        min-width: 0 !important;
        margin: 0 !important;
        padding: 0 !important;
        overflow: visible !important;
        height: auto !important;
        min-height: auto !important;
        float: none !important;
    }

    /* Prevent table-responsive scroll containment clipping */
    .table-responsive {
        display: block !important;
        width: 100% !important;
        max-width: 100% !important;
        overflow: visible !important;
        margin: 0 !important;
        padding: 0 !important;
    }

    /* Use available printable width and prevent fixed width blowing */
    table,
    .table,
    .rims-table {
        width: 100% !important;
        max-width: 100% !important;
        table-layout: auto !important;
        border-collapse: collapse !important;
        page-break-inside: auto;
    }

    tr {
        page-break-inside: avoid;
        page-break-after: auto;
    }

    /* Allow cells and badges to wrap text cleanly */
    .rims-table th,
    .rims-table td {
        padding: 0.25rem 0.35rem !important;
        font-size: 7.5pt !important;
        line-height: 1.2 !important;
        white-space: normal !important;
        word-break: normal !important;
        overflow-wrap: break-word !important;
        border: 1px solid #cbd5e1 !important;
    }

    /* Prevent rigid inline column widths from forcing clipping */
    .rims-table th {
        width: auto !important;
        background-color: #f1f5f9 !important;
        color: #0f172a !important;
    }

    .badge,
    .badge-active,
    .badge-inactive,
    .badge-needs-attention,
    .badge-ok,
    .text-nowrap {
        white-space: normal !important;
        word-break: normal !important;
        border: 1px solid #94a3b8 !important;
        color: #000000 !important;
        background: transparent !important;
        font-size: 7pt !important;
        padding: 0.1rem 0.25rem !important;
    }

    .rims-card {
        border: none !important;
        box-shadow: none !important;
        margin-bottom: 0.75rem !important;
        background: transparent !important;
    }

    .rims-card-header {
        border-bottom: 1px solid #000 !important;
        background: transparent !important;
        padding: 0.35rem 0 !important;
    }

    .rims-card-body {
        padding: 0 !important;
    }

    .print-header {
        display: block !important;
        margin-bottom: 1rem !important;
        border-bottom: 2px solid #000000 !important;
        padding-bottom: 0.5rem !important;
    }
}