@import url('https://cdn.jsdelivr.net/gh/orioncactus/pretendard/dist/web/static/pretendard.css');

:root {
    --primary: #4F46E5;
    --primary-hover: #4338CA;
    --bg-color: #F3F4F6;
    --surface: #FFFFFF;
    --text-main: #111827;
    --text-muted: #6B7280;
    --border: #E5E7EB;
    --doc-bg: #FFFFFF;
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

body {
    font-family: 'Pretendard', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    background-color: var(--bg-color);
    color: var(--text-main);
    height: 100vh;
    overflow: hidden;
}

.app-container {
    display: flex;
    height: 100vh;
}

/* Sidebar Styling */
.sidebar {
    width: 420px;
    background-color: var(--surface);
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    overflow-y: auto;
    box-shadow: 4px 0 15px rgba(0, 0, 0, 0.02);
    z-index: 10;
}

.header {
    padding: 24px;
    background: linear-gradient(135deg, #4F46E5, #3B82F6);
    color: white;
}

.header h1 {
    font-size: 22px;
    font-weight: 700;
    margin-bottom: 6px;
}

.header p {
    font-size: 13px;
    opacity: 0.9;
}

#payslip-form {
    padding: 24px;
    display: flex;
    flex-direction: column;
    gap: 28px;
}

.form-section h2 {
    font-size: 16px;
    font-weight: 700;
    margin-bottom: 14px;
    color: var(--text-main);
    display: flex;
    align-items: center;
}

.section-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 14px;
}

.section-header h2 {
    margin-bottom: 0;
}

.input-group {
    margin-bottom: 14px;
}

.input-group label {
    display: block;
    font-size: 13px;
    font-weight: 600;
    margin-bottom: 6px;
    color: var(--text-muted);
}

input[type="text"],
input[type="number"] {
    width: 100%;
    padding: 10px 12px;
    border: 1px solid var(--border);
    border-radius: 8px;
    font-family: inherit;
    font-size: 14px;
    transition: all 0.2s;
    background-color: #F9FAFB;
}

input:focus {
    outline: none;
    border-color: var(--primary);
    background-color: var(--surface);
    box-shadow: 0 0 0 3px rgba(79, 70, 229, 0.1);
}

.item-row {
    display: flex;
    gap: 8px;
    margin-bottom: 10px;
    align-items: center;
}

.item-row input.item-name {
    flex: 1.2;
}

.item-row input.item-amount {
    flex: 1;
    text-align: right;
    font-variant-numeric: tabular-nums;
}

.btn-remove {
    background: none;
    border: none;
    color: #EF4444;
    cursor: pointer;
    padding: 6px;
    border-radius: 6px;
    transition: all 0.1s;
    display: flex;
    align-items: center;
    justify-content: center;
}

.btn-remove:hover {
    background-color: #FEE2E2;
}

.btn-sm {
    padding: 6px 12px;
    font-size: 12px;
    border-radius: 6px;
    cursor: pointer;
    font-weight: 600;
    transition: all 0.2s;
}

.btn-outline {
    background: white;
    border: 1px solid var(--border);
    color: var(--text-main);
}

.btn-outline:hover {
    border-color: var(--primary);
    color: var(--primary);
    background-color: #EEF2FF;
}

.btn-primary {
    width: 100%;
    padding: 14px;
    background-color: var(--primary);
    color: white;
    border: none;
    border-radius: 10px;
    font-size: 15px;
    font-weight: 600;
    cursor: pointer;
    transition: background-color 0.2s, transform 0.1s;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    box-shadow: 0 4px 6px -1px rgba(79, 70, 229, 0.2);
}

.btn-primary:active {
    transform: translateY(1px);
}

.btn-primary:hover {
    background-color: var(--primary-hover);
}

/* Preview Area */
.preview-area {
    flex: 1;
    overflow-y: auto;
    padding: 40px;
    display: flex;
    justify-content: center;
    align-items: flex-start;
    background-color: #E2E8F0;
}

/* Document Standard A4 styling */
.document-wrapper {
    background: white;
    box-shadow: 0 20px 25px -5px rgba(0, 0, 0, 0.1), 0 10px 10px -5px rgba(0, 0, 0, 0.04);
    width: 210mm;
    min-height: 297mm;
    padding: 22mm;
    margin: 0 auto 40px auto;
    border-radius: 4px;
}

.document {
    width: 100%;
    height: 100%;
    display: flex;
    flex-direction: column;
}

.doc-header {
    text-align: center;
    margin-bottom: 35px;
    border-bottom: 2px solid #111827;
    padding-bottom: 25px;
}

.doc-title {
    font-size: 34px;
    font-weight: 800;
    letter-spacing: 16px;
    margin-bottom: 35px;
    margin-left: 16px;
    /* offset for letter spacing */
}

.meta-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 14px;
    text-align: left;
}

.meta-table th {
    width: 15%;
    background-color: #F3F4F6;
    padding: 10px 12px;
    border: 1px solid #9CA3AF;
    font-weight: 700;
    text-align: center;
    color: #111827;
}

.meta-table td {
    width: 35%;
    padding: 10px 12px;
    border: 1px solid #9CA3AF;
    font-weight: 500;
}

.details-grid {
    display: flex;
    gap: 24px;
    margin-bottom: 30px;
}

.details-column {
    flex: 1;
}

.details-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 14px;
}

.details-table th,
.details-table td {
    border: 1px solid #9CA3AF;
    padding: 12px 14px;
}

.details-table thead th {
    background-color: #F3F4F6;
    font-weight: 700;
    text-align: center;
}

.details-table tbody td:first-child {
    text-align: center;
    background-color: #F9FAFB;
    font-weight: 500;
    color: #374151;
}

.details-table tbody td:last-child {
    text-align: right;
    font-variant-numeric: tabular-nums;
    font-weight: 500;
}

.details-table tfoot th {
    background-color: #E5E7EB;
    text-align: center;
    font-weight: 700;
}

.details-table tfoot td {
    background-color: #F3F4F6;
    text-align: right;
    font-weight: 700;
    font-variant-numeric: tabular-nums;
    font-size: 15px;
}

.summary-box {
    margin-top: 15px;
    border: 2px solid #111827;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 24px 32px;
    background-color: #F9FAFB;
}

.summary-label {
    font-size: 18px;
    font-weight: 800;
}

.summary-amount {
    font-size: 26px;
    font-weight: 800;
    color: #111827;
    letter-spacing: 1px;
}

.doc-footer {
    margin-top: auto;
    text-align: center;
    padding-top: 60px;
    padding-bottom: 20px;
}

.footer-notice {
    font-size: 17px;
    font-weight: 600;
    margin-bottom: 45px;
}

.signature-area {
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 16px;
    position: relative;
}

.signature-area h2 {
    font-size: 26px;
    font-weight: 800;
    letter-spacing: 1px;
}

.stamp-placeholder {
    width: 64px;
    height: 64px;
    border: 2px solid #EF4444;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    color: #EF4444;
    font-size: 13px;
    font-weight: bold;
    opacity: 0.9;
    transform: rotate(-10deg);
}

/* Print Styles */
@media print {
    @page {
        size: auto;
        /* Allow browser to scale to A4/A5 */
        margin: 0;
    }

    body {
        background-color: white;
        -webkit-print-color-adjust: exact;
        print-color-adjust: exact;
    }

    .no-print {
        display: none !important;
    }

    .app-container {
        display: block;
        height: auto;
        width: 100%;
    }

    .preview-area {
        padding: 0;
        background: none;
        display: block;
        width: 100%;
    }

    .document-wrapper {
        box-shadow: none;
        margin: 0;
        width: 100%;
        max-width: 210mm;
        min-height: 297mm;
        padding: 20mm;
        page-break-after: always;
    }

    /* Override last page break */
    .document-wrapper:last-child {
        page-break-after: auto;
    }
}

/* Modal Styling */
.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-color: rgba(0, 0, 0, 0.5);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    animation: fadeIn 0.2s;
}

.modal-overlay.hidden {
    display: none;
}

.modal-content {
    background: white;
    width: 600px;
    max-width: 90vw;
    border-radius: 12px;
    box-shadow: 0 20px 25px -5px rgba(0, 0, 0, 0.1);
    overflow: hidden;
    display: flex;
    flex-direction: column;
}

.modal-header {
    padding: 20px 24px;
    border-bottom: 1px solid var(--border);
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.modal-header h2 {
    font-size: 18px;
    font-weight: 700;
}

.btn-close {
    background: none;
    border: none;
    font-size: 24px;
    cursor: pointer;
    color: var(--text-muted);
    transition: color 0.1s;
}

.btn-close:hover {
    color: var(--text-main);
}

.modal-tabs {
    display: flex;
    border-bottom: 1px solid var(--border);
    padding: 0 24px;
    background-color: #F9FAFB;
}

.tab-btn {
    padding: 14px 20px;
    background: none;
    border: none;
    border-bottom: 2px solid transparent;
    font-size: 14px;
    font-weight: 600;
    color: var(--text-muted);
    cursor: pointer;
    transition: all 0.2s;
}

.tab-btn:hover {
    color: var(--primary);
}

.tab-btn.active {
    color: var(--primary);
    border-bottom-color: var(--primary);
}

.tab-content {
    padding: 24px;
    display: none;
    max-height: 60vh;
    overflow-y: auto;
}

.tab-content.active {
    display: block;
}

/* File Upload Box */
.upload-box {
    border: 2px dashed var(--border);
    border-radius: 10px;
    padding: 40px 20px;
    text-align: center;
    background-color: #F9FAFB;
    transition: border-color 0.2s, background-color 0.2s;
}

.upload-box:hover,
.upload-box.dragover {
    border-color: var(--primary);
    background-color: #EEF2FF;
}

.upload-box input[type="file"] {
    display: none;
}

.upload-label {
    cursor: pointer;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 12px;
    color: var(--text-muted);
}

.upload-label p {
    font-size: 14px;
    font-weight: 500;
}

/* Mapping Grid */
.mapping-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 12px;
    max-height: 250px;
    overflow-y: auto;
    padding-right: 8px;
}

.mapping-item {
    background: #F9FAFB;
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 10px 14px;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.mapping-item span.excel-col {
    font-weight: 600;
    font-size: 13px;
    color: var(--primary);
    flex: 1;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.mapping-item select {
    flex: 1;
    padding: 6px 8px;
    border: 1px solid var(--border);
    border-radius: 4px;
    font-size: 12px;
}

@keyframes fadeIn {
    from {
        opacity: 0;
    }

    to {
        opacity: 1;
    }
}