/* Root CSS Variables for EWS Harmonized Palette & A11Y Compliance */
:root {
    /* Base Canvas & Cards */
    --bg-canvas: #f8fafc;
    --bg-card: #ffffff;
    --border-card-sharp: #1e293b; /* Refined 1px sharp dark slate border */
    --border-subtle: #e2e8f0;

    /* Typography Neutrals */
    --text-main: #0f172a;
    --text-muted: #64748b;

    /* Functional Blue (Primary, Highlight, Focus) */
    --color-primary-light: #e0f2fe;
    --color-primary: #0284c7;
    --color-primary-hover: #075985;
    --color-primary-dark: #075985;
    --color-primary-text: #0c4a6e;

    /* Status Green (Tuntas / Aman / Berhasil) */
    --color-tuntas-light: #dcfce7;
    --color-tuntas: #10b981;
    --color-tuntas-hover: #047857;
    --color-tuntas-dark: #047857;
    --color-tuntas-text: #064e3b; /* WCAG AAA Compliant Dark Text (10.5:1) */

    /* Status Yellow/Amber (Berisiko / Peringatan / Perhatian) */
    --color-berisiko-light: #fef3c7;
    --color-berisiko: #f59e0b;
    --color-berisiko-hover: #b45309;
    --color-berisiko-dark: #b45309;
    --color-berisiko-text: #78350f; /* WCAG AAA Compliant Dark Text (8.9:1) */

    /* Status Red (Tidak Tuntas / Gagal / Kritis) */
    --color-tidaktuntas-light: #fee2e2;
    --color-tidaktuntas: #ef4444;
    --color-tidaktuntas-hover: #be123c;
    --color-tidaktuntas-dark: #be123c;
    --color-tidaktuntas-text: #881337; /* WCAG AAA Compliant Dark Text (11.2:1) */
}

/* Global styles & resets */
html,
body {
    margin: 0;
    padding: 0;
    min-height: 100%;
    min-height: 100dvh;
    font-family: 'Inter', sans-serif;
    background-color: var(--bg-canvas);
    color: #0f172a;
}

/* Typography System Standards & High-Contrast Utility Classes */
.font-metric-number {
    font-size: clamp(1.875rem, 4vw, 3rem); /* 30px to 48px */
    font-weight: 900;
    letter-spacing: -0.03em;
    line-height: 1.1;
    color: #0f172a; /* slate-900 */
}

.font-heading-page {
    font-size: clamp(1.25rem, 2.5vw, 1.875rem); /* 20px to 30px */
    font-weight: 800;
    letter-spacing: -0.02em;
    line-height: 1.25;
    color: #0f172a;
}

.font-heading-section {
    font-size: clamp(1rem, 1.5vw, 1.25rem); /* 16px to 20px */
    font-weight: 700;
    line-height: 1.3;
    color: #0f172a;
}

.font-body-custom {
    font-size: clamp(0.875rem, 1vw, 1rem); /* 14px to 16px */
    font-weight: 500;
    line-height: 1.6;
    color: #334155; /* slate-700 */
}

.table-header-label {
    font-size: 0.75rem; /* 12px mobile */
    font-weight: 800;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: #334155; /* High-contrast slate-700 */
}

@media (min-width: 768px) {
    .table-header-label {
        font-size: 0.875rem; /* 14px desktop */
    }
}

.badge-label {
    font-size: 0.75rem; /* 12px */
    font-weight: 700;
    padding: 0.25rem 0.75rem;
    border-radius: 0.5rem;
    display: inline-flex;
    items-center: center;
    gap: 0.375rem;
}

@media (min-width: 640px) {
    .badge-label {
        font-size: 0.875rem; /* 14px */
    }
}

/* Custom Smooth Scrollbar for Tables & Panels (Swipeable & Scrollable) */
.custom-scrollbar {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: thin;
    scrollbar-color: #cbd5e1 transparent;
}

.custom-scrollbar::-webkit-scrollbar {
    height: 6px;
    width: 6px;
}

.custom-scrollbar::-webkit-scrollbar-track {
    background: #f1f5f9;
    border-radius: 4px;
}

.custom-scrollbar::-webkit-scrollbar-thumb {
    background: #94a3b8;
    border-radius: 4px;
}

.custom-scrollbar::-webkit-scrollbar-thumb:hover {
    background: #64748b;
}

/* Strict Responsive Dual-View Display Rules */
@media (max-width: 767px) {
    .desktop-only-view {
        display: none !important;
    }
    .mobile-only-view {
        display: block !important;
    }
}

@media (min-width: 768px) {
    .desktop-only-view {
        display: block !important;
    }
    .mobile-only-view {
        display: none !important;
    }
}

/* ==========================================================================
   MASTER PRINT STYLESHEET (A4 Ready, Responsive, Clean & Crisp for All 3 Roles)
   ========================================================================== */
@media print {
    /* Page Configuration: A4 Portrait with 10mm margins */
    @page {
        size: A4 portrait;
        margin: 10mm 12mm 10mm 12mm;
    }

    /* Reset Body & Canvas for Print */
    html, body {
        background: #ffffff !important;
        color: #000000 !important;
        font-family: 'Times New Roman', Times, Arial, sans-serif !important;
        font-size: 11pt !important;
        line-height: 1.4 !important;
        width: 100% !important;
        height: auto !important;
        margin: 0 !important;
        padding: 0 !important;
        overflow: visible !important;
        -webkit-print-color-adjust: exact !important;
        print-color-adjust: exact !important;
    }

    /* Hide Non-Printable Elements Completely */
    aside,
    header,
    nav,
    .no-print,
    .print\:hidden,
    #sidebar-overlay,
    #toast-container,
    #logout-loading-overlay,
    #notif-modal,
    button,
    form.print\:hidden,
    .dashboard-sidebar,
    .sidebar-header-card {
        display: none !important;
    }

    /* Full Width Print Container */
    .dashboard-shell,
    .dashboard-main,
    .print-document-container {
        display: block !important;
        width: 100% !important;
        max-width: 100% !important;
        margin: 0 !important;
        padding: 0 !important;
        background: transparent !important;
        box-shadow: none !important;
        border: none !important;
        overflow: visible !important;
    }

    /* Show Print-Only Elements */
    .print\:block {
        display: block !important;
    }
    .print\:flex {
        display: flex !important;
    }
    .print\:grid {
        display: grid !important;
    }

    /* High-Contrast Print Kop Surat & Tables */
    .print-kop-surat {
        border-bottom: 3px double #000000 !important;
        padding-bottom: 8px !important;
        margin-bottom: 12px !important;
    }

    table {
        width: 100% !important;
        max-width: 100% !important;
        border-collapse: collapse !important;
        margin-top: 10px !important;
        margin-bottom: 15px !important;
        font-size: 9.5pt !important;
        page-break-inside: auto !important;
    }

    tr {
        page-break-inside: avoid !important;
        break-inside: avoid !important;
    }

    thead {
        display: table-header-group !important;
    }

    tfoot {
        display: table-footer-group !important;
    }

    th, td {
        border: 1px solid #1e293b !important;
        padding: 5px 8px !important;
        color: #000000 !important;
        background-color: transparent !important;
    }

    th {
        background-color: #f1f5f9 !important;
        font-weight: bold !important;
        text-transform: uppercase !important;
    }

    /* Status Badges in Print */
    .badge-print {
        border: 1px solid #1e293b !important;
        padding: 2px 8px !important;
        border-radius: 9999px !important;
        font-weight: bold !important;
        font-size: 8.5pt !important;
        display: inline-block !important;
        color: #000000 !important;
    }

    /* Signatures Section (Never Splits Across Pages) */
    .print-signatures {
        display: grid !important;
        grid-template-columns: repeat(2, minmax(0, 1fr)) !important;
        page-break-inside: avoid !important;
        break-inside: avoid !important;
        margin-top: 25px !important;
    }
}

body {
    min-height: 100vh;
    min-height: 100dvh;
    box-sizing: border-box;
    padding-bottom: env(safe-area-inset-bottom);
}

a {
    text-decoration: none;
    color: inherit;
}

/* Material Symbols Outlined styling (Protected against auto-translation breaking icons) */
.material-symbols-outlined,
.notranslate {
    font-family: 'Material Symbols Outlined' !important;
    font-weight: normal;
    font-style: normal;
    font-size: 24px;
    line-height: 1;
    letter-spacing: normal;
    text-transform: none !important;
    display: inline-block;
    white-space: nowrap;
    word-wrap: normal;
    direction: ltr;
    -webkit-font-feature-settings: 'liga';
    font-feature-settings: 'liga';
    -webkit-font-smoothing: antialiased;
    font-variation-settings: 'FILL' 0, 'wght' 400, 'GRAD' 0, 'opsz' 24;
    translate: no !important;
}

.material-symbols-outlined.fill {
    font-variation-settings: 'FILL' 1;
}

/* Ensure crisp single vector SVG dropdown chevron across all select inputs */
select,
.custom-select,
.filter-select {
    appearance: none !important;
    -webkit-appearance: none !important;
    -moz-appearance: none !important;
    background-image: url("data:image/svg+xml,%3csvg xmlns='http://www.w3.org/2000/svg' fill='none' viewBox='0 0 20 20'%3e%3cpath stroke='%2364748b' stroke-linecap='round' stroke-linejoin='round' stroke-width='1.8' d='M6 8l4 4 4-4'/%3e%3c/svg%3e") !important;
    background-position: right 0.65rem center !important;
    background-repeat: no-repeat !important;
    background-size: 1.2rem 1.2rem !important;
    padding-right: 2.25rem !important;
    cursor: pointer;
}

/* Crisp Sharp-Cornered Dashboard Aesthetic */
.rounded-3xl,
.rounded-2xl,
.rounded-xl {
    border-radius: 8px !important;
}

.rounded-lg {
    border-radius: 6px !important;
}

.rounded-md {
    border-radius: 4px !important;
}

/* Sharp Card & Panel Borders */
.bg-surface-container-lowest,
.glass-card,
.card-shadow {
    border-radius: 8px !important;
    border: 1px solid #cbd5e1 !important; /* Crisp slate-300 border */
    box-shadow: 0 1px 4px rgba(15, 23, 42, 0.04) !important;
}

/* Card with 1px Sharp Dark Slate Border */
.card-sharp {
    background-color: var(--bg-card);
    border: 1px solid var(--border-card-sharp);
    box-shadow: 0 2px 8px rgba(30, 41, 59, 0.04);
}

/* Status Badge Utility Classes (WCAG AAA Compliant) */
.badge-tuntas {
    display: inline-flex;
    align-items: center;
    gap: 0.375rem;
    padding: 0.25rem 0.75rem;
    font-size: 0.75rem;
    font-weight: 700;
    border-radius: 9999px;
    background-color: var(--color-tuntas-light);
    color: var(--color-tuntas-text);
    border: 1px solid rgba(16, 185, 129, 0.3);
}

.badge-berisiko {
    display: inline-flex;
    align-items: center;
    gap: 0.375rem;
    padding: 0.25rem 0.75rem;
    font-size: 0.75rem;
    font-weight: 700;
    border-radius: 9999px;
    background-color: var(--color-berisiko-light);
    color: var(--color-berisiko-text);
    border: 1px solid rgba(245, 158, 11, 0.3);
}

.badge-tidaktuntas {
    display: inline-flex;
    align-items: center;
    gap: 0.375rem;
    padding: 0.25rem 0.75rem;
    font-size: 0.75rem;
    font-weight: 700;
    border-radius: 9999px;
    background-color: var(--color-tidaktuntas-light);
    color: var(--color-tidaktuntas-text);
    border: 1px solid rgba(239, 68, 68, 0.3);
}

/* Primary EWS Action Button */
.btn-primary-ews {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    padding: 0.5rem 1rem;
    font-size: 0.75rem;
    font-weight: 700;
    border-radius: 0.5rem;
    background-color: var(--color-primary);
    color: #ffffff;
    transition: all 0.2s ease-in-out;
    cursor: pointer;
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.05);
}
.btn-primary-ews:hover {
    background-color: var(--color-primary-hover);
}
.btn-primary-ews:focus {
    outline: none;
    box-shadow: 0 0 0 3px var(--color-primary-light);
}

/* Sharp Buttons & Input Controls */
input,
select,
textarea,
button {
    border-radius: 6px !important;
}

/* Preserve roundness only for circular avatar images & status dot indicators */
img.rounded-full,
span.rounded-full.w-2,
span.rounded-full.w-3,
span.rounded-full.w-4,
div.rounded-full.w-10,
div.rounded-full.w-12,
button#mobile-menu-btn,
button#notif-btn,
button#profile-btn {
    border-radius: 9999px !important;
}

/* Compact & Spacious UI Scaling ("Perjauh/Perkecil Tampilan & Responsif") */
@media (min-width: 1024px) {
    html {
        font-size: 87.5% !important; /* 14px base font size for spacious, wide dashboard view */
    }
}

@media (min-width: 768px) and (max-width: 1023px) {
    html {
        font-size: 84% !important;
    }
}

@media (max-width: 767px) {
    html,
    body,
    main,
    .dashboard-layout,
    .dashboard-shell,
    .dashboard-main {
        max-width: 100vw !important;
        overflow-x: hidden !important;
    }

    header {
        max-width: 100vw !important;
        overflow: visible !important;
        z-index: 9999 !important;
    }

    html {
        font-size: 90% !important; /* Touch-friendly scaling for mobile HP */
    }

    .p-lg,
    .p-xl {
        padding: 0.95rem !important;
    }

    /* Wrap header title and text naturally on mobile HP - no text cut off */
    h1, h2, h3, h4, h5, h6, p, div:not(.overflow-x-auto):not(#settings-dropdown):not(#notif-dropdown):not(#profile-dropdown) {
        max-width: 100% !important;
        white-space: normal !important;
        overflow-wrap: break-word !important;
        word-break: break-word !important;
    }

    #notif-modal {
        z-index: 999999 !important;
    }

    /* Header Dropdown Menus (Settings, Notif, Profile) Styling & Protection */
    #settings-dropdown,
    #notif-dropdown,
    #profile-dropdown,
    .header-dropdown {
        word-break: normal !important;
        overflow-wrap: normal !important;
        white-space: normal !important;
        box-shadow: 0 20px 25px -5px rgba(0, 0, 0, 0.15), 0 8px 10px -6px rgba(0, 0, 0, 0.1) !important;
    }

    #settings-dropdown {
        min-width: 220px !important;
        width: 240px !important;
    }

    #profile-dropdown {
        min-width: 240px !important;
        width: 260px !important;
    }

    #notif-dropdown {
        min-width: 300px !important;
        width: 340px !important;
    }

    @media (max-width: 639px) {
        #settings-dropdown,
        #profile-dropdown {
            position: fixed !important;
            top: 64px !important;
            right: 12px !important;
            left: auto !important;
            width: 260px !important;
            max-width: calc(100vw - 24px) !important;
            z-index: 99999 !important;
        }

        #notif-dropdown {
            position: fixed !important;
            top: 64px !important;
            left: 12px !important;
            right: 12px !important;
            width: calc(100vw - 24px) !important;
            min-width: unset !important;
            z-index: 99999 !important;
        }
    }

    /* Guarantee action buttons and badges NEVER break text into vertical word columns */
    .action-btn,
    .badge,
    .table-btn {
        white-space: nowrap !important;
    }

    button.w-full,
    a.w-full,
    input.w-full,
    select.w-full {
        width: 100% !important;
        max-width: 100% !important;
    }

    /* Full-width action buttons on mobile */
    .mobile-full-btn {
        width: 100% !important;
    }

    /* Modal max width and scroll handling for smartphones */
    .fixed.inset-0 > div {
        max-width: 94vw !important;
        max-height: 90vh !important;
    }

    /* Touch-friendly input heights on mobile HP */
    input:not([type="checkbox"]):not([type="radio"]),
    select,
    button {
        min-height: 42px !important;
    }
}

/* Strict Table-Only Horizontal Scroll Lock */
.overflow-x-auto {
    max-width: 100% !important;
    overflow-x: auto !important;
    -webkit-overflow-scrolling: touch;
    display: block !important;
}

.overflow-x-auto table,
.overflow-x-auto td,
.overflow-x-auto th {
    white-space: nowrap !important;
}

/* Compact padding & gaps for cards & containers */
.p-lg {
    padding: 1.15rem !important;
}

.p-xl {
    padding: 1.35rem !important;
}

.gap-lg {
    gap: 1.15rem !important;
}

/* Compact inputs & select dropdowns */
input:not([type="checkbox"]):not([type="radio"]),
select,
textarea {
    padding-top: 0.45rem !important;
    padding-bottom: 0.45rem !important;
}