/* Design System & Variables */
:root {
    --primary-color: #0d3b66;     /* Deep navy blue representing Barantin */
    --secondary-color: #f4d35e;   /* Gold accent */
    --accent-color: #e76f51;      /* Coral for alerts or highlights */
    --text-color: #2b2d42;        /* Dark gray text */
    --bg-color: #f0f2f5;          /* Neutral gray background for screen preview */
    --page-bg: #ffffff;           /* White page background */
    --border-color: #d1d5db;      /* Muted borders */
    --shadow-color: rgba(0, 0, 0, 0.1);
    --progress-color: #2ec4b6;    /* Teal for progress bar */
}

/* Base resets & styles */
* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

html, body {
    max-width: 100vw;
    overflow-x: hidden;
}

body {
    background-color: var(--bg-color);
    font-family: 'Inter', system-ui, -apple-system, sans-serif;
    color: var(--text-color);
    line-height: 1.6;
    padding: 95px 0 40px 0; /* Extra top padding to accommodate the dual progress bars */
}

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

/* Progress Tracker Header (Screen only) */
.progress-container {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    background-color: #ffffff;
    box-shadow: 0 2px 10px rgba(0,0,0,0.1);
    z-index: 1000;
    padding: 12px 30px;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.progress-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    width: 100%;
}

.progress-label {
    font-weight: 600;
    font-size: 13px;
    color: var(--primary-color);
    min-width: 180px;
}

.progress-bar-wrapper {
    flex-grow: 1;
    margin: 0 20px;
    background-color: #e9ecef;
    border-radius: 10px;
    height: 10px;
    overflow: hidden;
    position: relative;
}

.progress-bar-fill {
    height: 100%;
    width: 15%;
    background-color: var(--progress-color);
    border-radius: 10px;
    transition: width 0.5s ease-in-out;
}

.progress-percent {
    font-weight: 700;
    font-size: 13px;
    color: var(--progress-color);
    min-width: 140px;
    text-align: right;
}

/* Page Layout for A4 Screen Simulation */
.page {
    background-color: var(--page-bg);
    width: 210mm;
    max-width: calc(100vw - 24px);
    min-height: 297mm;
    padding: 20mm 20mm 25mm 20mm; /* Outer margins managed via layout padding, extra bottom space for footer */
    margin: 30px auto;
    box-shadow: 0 4px 20px var(--shadow-color);
    position: relative;
    border-radius: 4px;
    display: flex;
    flex-direction: column;
    justify-content: flex-start;
    box-sizing: border-box;
}

/* Page margins content wrapper to enforce exact 2cm (20mm) */
.page-content {
    width: 100%;
    height: 100%;
    display: flex;
    flex-direction: column;
    flex-grow: 1;
}

.cover-page {
    background-image: linear-gradient(to bottom, rgba(13, 59, 102, 0.92), rgba(13, 59, 102, 0.88)), url('gedung_induk.jpeg');
    background-size: cover;
    background-position: center;
    background-repeat: no-repeat;
    color: #ffffff;
    text-align: center;
    justify-content: space-between;
    align-items: center;
    padding: 20mm 15mm;
    box-shadow: inset 0 0 100px rgba(0,0,0,0.5);
}

.cover-page .page-content {
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    align-items: center;
    height: 100%;
    flex-grow: 1;
}

.cover-header {
    width: 100%;
}

.cover-logo {
    width: 110px;
    height: auto;
    margin: 0 auto 15px;
    display: block;
    filter: drop-shadow(0 4px 8px rgba(0,0,0,0.3));
}

.cover-institution {
    font-size: 18px;
    font-weight: 800;
    letter-spacing: 1px;
    color: #ffffff;
    text-transform: uppercase;
    text-shadow: 0 2px 4px rgba(0,0,0,0.3);
}

.cover-subinstitution {
    font-size: 13px;
    font-weight: 600;
    margin-top: 5px;
    color: var(--secondary-color);
    text-transform: uppercase;
    border-bottom: 2px solid var(--secondary-color);
    padding-bottom: 15px;
    text-shadow: 0 2px 4px rgba(0,0,0,0.3);
    letter-spacing: 0.5px;
}

.cover-body {
    margin: 40px 0;
}

.cover-title {
    font-size: 26px;
    font-weight: 800;
    line-height: 1.3;
    color: #ffffff;
    text-transform: uppercase;
    text-shadow: 0 2px 6px rgba(0,0,0,0.4);
}

.cover-subtitle {
    font-size: 14px;
    font-weight: 500;
    margin-top: 20px;
    color: #e2e8f0;
    line-height: 1.6;
    text-shadow: 0 1px 3px rgba(0,0,0,0.3);
}

.cover-progress-badge {
    margin: 30px auto 0;
    display: inline-flex;
    align-items: center;
    background-color: rgba(46, 196, 182, 0.2);
    border: 1px solid var(--progress-color);
    color: #ffffff;
    padding: 8px 16px;
    border-radius: 20px;
    font-weight: 700;
    font-size: 13px;
    backdrop-filter: blur(4px);
    box-shadow: 0 2px 6px rgba(0,0,0,0.15);
}

.cover-footer {
    width: 100%;
    font-size: 14px;
    font-weight: 700;
    color: var(--secondary-color);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    text-shadow: 0 1px 3px rgba(0,0,0,0.3);
}

/* SK (Keputusan Kepala) styling */
.sk-header {
    text-align: center;
    margin-bottom: 25px;
    border-bottom: 2px double var(--primary-color);
    padding-bottom: 15px;
}

.sk-title {
    font-size: 16px;
    font-weight: 700;
    text-transform: uppercase;
    line-height: 1.4;
}

.sk-section-title {
    font-size: 14px;
    font-weight: 700;
    margin: 15px 0 5px;
    text-transform: uppercase;
}

.sk-table {
    width: 100%;
    border-collapse: collapse;
    margin-bottom: 15px;
    font-size: 13px;
}

.sk-table td {
    vertical-align: top;
    padding: 4px 8px;
}

.sk-table td.label {
    width: 120px;
    font-weight: 700;
}

.sk-table td.separator {
    width: 15px;
    text-align: center;
}

.sk-list {
    list-style-type: none;
    margin-left: 20px;
    font-size: 13px;
}

.sk-list li {
    margin-bottom: 8px;
    text-align: justify;
    position: relative;
    padding-left: 20px;
}

.sk-list li::before {
    position: absolute;
    left: 0;
    font-weight: 700;
}

.sk-list-alphabet li::before {
    content: attr(data-letter) ".";
}

.sk-list-dec li::before {
    content: attr(data-number) ".";
}

.sk-signature {
    margin-top: 30px;
    display: flex;
    justify-content: flex-end;
    font-size: 13px;
}

.signature-block {
    width: 250px;
    text-align: left;
}

.signature-space {
    height: 70px;
}

/* Content Table Styles */
.spp-table {
    width: 100%;
    border-collapse: collapse;
    margin: 15px 0;
    font-size: 12px;
}

.spp-table th, .spp-table td {
    border: 1px solid var(--border-color);
    padding: 6px 8px;
    text-align: left;
}

.spp-table th {
    background-color: var(--primary-color);
    color: #ffffff;
    font-weight: 700;
    text-transform: uppercase;
    font-size: 11px;
    letter-spacing: 0.5px;
}

.spp-table tr:nth-child(even) {
    background-color: #f9fafb;
}

/* Maklumat Pelayanan styling */
.maklumat-container {
    border: 3px double var(--primary-color);
    padding: 20px;
    border-radius: 8px;
    background-color: rgba(13, 59, 102, 0.02);
    margin-top: 20px;
}

.maklumat-title {
    text-align: center;
    font-size: 18px;
    font-weight: 800;
    color: var(--primary-color);
    margin-bottom: 20px;
    text-transform: uppercase;
}

.maklumat-list {
    list-style-type: decimal;
    margin-left: 20px;
    font-size: 14px;
}

.maklumat-list li {
    margin-bottom: 12px;
    padding-left: 5px;
    font-weight: 500;
}

/* Kata Pengantar Page */
.section-title {
    text-align: center;
    font-size: 20px;
    font-weight: 700;
    text-transform: uppercase;
    color: var(--primary-color);
    margin-bottom: 30px;
    position: relative;
    padding-bottom: 10px;
}

.section-title::after {
    content: '';
    position: absolute;
    bottom: 0;
    left: 50%;
    transform: translateX(-50%);
    width: 60px;
    height: 3px;
    background-color: var(--secondary-color);
}

.text-paragraph {
    text-align: justify;
    text-indent: 40px;
    margin-bottom: 15px;
    font-size: 14px;
    line-height: 1.7;
}

/* Daftar Isi Styling */
.toc-list {
    list-style-type: none;
    margin-top: 10px;
}

.toc-item {
    display: flex;
    justify-content: space-between;
    align-items: flex-end;
    margin-bottom: 8px;
    font-size: 14px;
}

.toc-item.level-1 {
    font-weight: 700;
    margin-top: 15px;
    text-transform: uppercase;
}

.toc-item.level-2 {
    font-weight: 600;
    padding-left: 20px;
}

.toc-item.level-3 {
    font-weight: 400;
    padding-left: 40px;
    font-size: 13px;
    color: #4b5563;
}

.toc-title-link {
    color: var(--text-color);
    text-decoration: none;
    background: var(--page-bg);
    padding-right: 5px;
    position: relative;
    z-index: 2;
    display: inline-block;
    max-width: 85%;
}

.toc-dots {
    flex-grow: 1;
    border-bottom: 1px dotted #9ca3af;
    margin: 0 5px 4px;
    position: relative;
    z-index: 1;
}

.toc-page {
    background: var(--page-bg);
    padding-left: 5px;
    position: relative;
    z-index: 2;
    font-weight: 600;
}

/* Interactive elements */
.toc-title-link:hover {
    color: var(--primary-color);
    text-decoration: underline;
}

/* Print CSS */
@media print {
    body {
        background-color: #ffffff;
        padding: 0;
        margin: 0;
    }
    .progress-container {
        display: none; /* Hide screen progress bar when printing */
    }
    .page {
        width: 210mm;
        height: 297mm;
        margin: 0;
        padding: 20mm 20mm 25mm 20mm; /* Simulate print margins */
        box-shadow: none;
        border-radius: 0;
        page-break-after: always;
        page-break-inside: avoid;
        box-sizing: border-box;
        position: relative;
        background-color: var(--page-bg);
        -webkit-print-color-adjust: exact;
        print-color-adjust: exact;
    }
    .cover-page {
        padding: 30mm 20mm;
        box-sizing: border-box;
        height: 297mm;
    }
    .cover-progress-badge {
        display: none; /* Hide progress badge on cover when printing */
    }
    @page {
        size: A4;
        margin: 0;
    }
}

/* Page Footer Styling */
.page-footer {
    position: absolute;
    bottom: 1.2cm;
    left: 2cm;
    right: 2cm;
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-size: 9px;
    color: #6b7280;
    border-top: 1px solid #e5e7eb;
    padding-top: 8px;
    font-family: 'Inter', sans-serif;
}
.footer-text {
    font-style: italic;
}
.footer-page {
    font-weight: 600;
}

/* Floating Back to TOC Button */
.floating-toc-btn {
    position: fixed;
    bottom: 30px;
    right: 30px;
    background-color: var(--primary-color);
    color: #ffffff;
    border: 2px solid var(--secondary-color);
    border-radius: 50px;
    width: 56px;
    height: 56px;
    padding: 0;
    cursor: pointer;
    box-shadow: 0 6px 20px rgba(0, 0, 0, 0.25);
    z-index: 9999;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    opacity: 0;
    visibility: hidden;
    transform: translateY(10px);
}
.floating-toc-btn .btn-text {
    max-width: 0;
    overflow: hidden;
    white-space: nowrap;
    transition: max-width 0.3s ease, margin-left 0.3s ease;
    font-size: 14px;
    font-weight: 700;
    margin-left: 0;
    color: #ffffff;
    font-family: 'Inter', system-ui, -apple-system, sans-serif;
}
.floating-toc-btn.show {
    opacity: 1;
    visibility: visible;
    transform: translateY(0);
}
.floating-toc-btn:hover {
    width: 150px;
    background-color: #124c80;
    transform: translateY(-3px);
    box-shadow: 0 8px 25px rgba(0, 0, 0, 0.35);
}
.floating-toc-btn:hover .btn-text {
    max-width: 80px;
    margin-left: 8px;
}
.floating-toc-btn:active {
    transform: translateY(-1px);
}
@media print {
    .floating-toc-btn {
        display: none !important;
    }
}

/* Responsive Screen Fitting Styles (Mobile & Tablet) */
@media screen and (max-width: 820px) {
    body {
        padding: 95px 8px 30px 8px;
    }

    .page {
        width: 100%;
        max-width: 100%;
        min-height: auto;
        padding: 20px 15px 45px 15px;
        margin: 15px auto;
        border-radius: 8px;
        box-shadow: 0 2px 10px var(--shadow-color);
    }

    .cover-page {
        padding: 40px 20px !important;
        min-height: 80vh;
    }

    .cover-title {
        font-size: 20px;
    }

    .cover-institution {
        font-size: 14px;
    }

    .cover-subinstitution {
        font-size: 11px;
    }

    .cover-logo {
        width: 80px;
    }

    .progress-container {
        padding: 8px 12px;
        gap: 4px;
    }

    .progress-label, .progress-percent {
        font-size: 11px;
        min-width: auto;
    }

    .progress-bar-wrapper {
        margin: 0 8px;
        height: 8px;
    }

    .page-footer {
        left: 15px;
        right: 15px;
        bottom: 12px;
        font-size: 8px;
    }

    .toc-item {
        font-size: 12px;
    }

    .toc-title-link {
        max-width: 75%;
    }

    table, .spp-table, .sk-table {
        display: block;
        width: 100% !important;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
    }

    .sk-signature {
        margin-top: 25px;
    }

    .signature-block {
        width: 100%;
        max-width: 250px;
    }
}

@media screen and (max-width: 480px) {
    body {
        padding: 105px 4px 20px 4px;
    }

    .page {
        padding: 15px 10px 40px 10px;
        margin: 10px auto;
    }

    .cover-page {
        padding: 30px 12px !important;
    }

    .cover-title {
        font-size: 18px;
    }

    .text-paragraph {
        text-indent: 20px;
        font-size: 13px;
    }

    .floating-toc-btn {
        bottom: 15px;
        right: 15px;
        width: 46px;
        height: 46px;
    }
}
