* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body, html {
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    height: 100%;
    overflow: hidden;
    margin: 0;
    font-size: 14px;
    color: #333;
}

a{
    text-decoration: none;
    color: #333;
}

.container {
    display: flex;
    flex-direction: column;
    height: 100vh;
    max-width: 100% !important;
    padding: 0 !important;
}

/* Brand Styling */
.brand-section {
    padding-bottom: 15px;
    text-align: center;
    border-bottom: 2px solid #f0f0f0;
    margin-bottom: 15px;
}

.brand-logo {
    font-size: 1.45rem;
    font-weight: 800;
    letter-spacing: -0.5px;
    user-select: none;
}

.brand-blue {
    color: #4158d0;
    text-shadow: 1px 1px 0px rgba(0,0,0,0.05);
}

.brand-pdf {
    color: #764ba2;
}

.brand-tagline {
    font-size: 0.7rem;
    color: #999;
    text-transform: uppercase;
    letter-spacing: 1px;
}

/* Main Content */
.main-content {
    display: flex;
    flex: 1;
    height: 100vh;
    margin: 0 !important;
    padding: 10px !important;
    gap: 10px !important;
    background: #eef2f7; /* Latar belakang lebih bersih agar dokumen lebih kontras */
    overflow: hidden;
    min-height: 0;
    min-width: 0;
}

/* Sidebar */
.sidebar {
    width: 260px !important;
    flex-shrink: 0;
    background: white;
    border-radius: 8px !important;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
    overflow-y: auto;
    padding: 15px !important;
    max-height: 100%;
    transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

.control-panel h3 {
    color: #667eea;
    font-size: 0.9rem;
    text-transform: uppercase;
    letter-spacing: 1px;
    margin: 8px 0 4px 0 !important;
}

.control-panel h3:first-child {
    margin-top: 0;
}

.sidebar hr {
    border: none;
    border-top: 1px solid #eee;
    margin: 8px 0 !important;
}

.file-input-wrapper {
    position: relative;
    display: block;
}

.file-input {
    display: none;
}

.file-label,
.file-input:hover~.file-label {
    display: block;
    padding: 8px 10px;
    background: #f0f0f0;
    border: 2px dashed #667eea;
    border-radius: 6px;
    text-align: center;
    cursor: pointer;
    transition: all 0.3s ease;
    font-size: 14px;
    font-weight: 500;
}

.file-input:hover~.file-label {
    background: #e8e8ff;
    border-color: #764ba2;
}

/* Buttons */
.btn {
    width: 100%;
    padding: 10px 10px !important;
    border: none;
    border-radius: 6px;
    font-size: 0.85rem !important;
    cursor: pointer;
    transition: all 0.3s ease;
    margin-bottom: 4px !important;
    display: block;
}

.btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
}

.btn:active {
    transform: translateY(0);
}

.btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
    transform: none;
}

.btn-primary {
    background: #4158d0; /* Biru solid yang lebih profesional */
    color: white;
}

.btn-secondary {
    background: #e8e8ff;
    color: #667eea;
    border: 1px solid #667eea;
}

.btn-secondary:hover {
    background: #d4d4ff;
}

.btn-danger {
    background: #ff6b6b;
    color: white;
}

.btn-danger:hover {
    background: #ee5a52;
}

.btn-success {
    background: #51cf66;
    color: white;
}

.btn-success:hover {
    background: #40c057;
}

/* Footer Styling */
.brand-footer-text {
    font-size: 11px;
    color: #aaa;
    text-align: center;
}

.brand-link {
    color: #667eea;
    font-weight: bold;
}

.btn-warning {
    background: #ffa94d;
    color: white;
}

.btn-warning:hover {
    background: #ff9800;
}

/* Tombol Toggle Mobile */
.sidebar-toggle {
    display: none;
}

.btn-sm {
    padding: 8px 12px;
    font-size: 12px;
    width: auto;
    margin-right: 10px;
    margin-bottom: 0;
}

/* Signature Controls */
.signature-controls {
    display: flex;
    flex-direction: column;
}

/* Settings */
.settings {
    display: flex;
    flex-direction: column;
    gap: 15px;
}

.settings label {
    display: flex;
    flex-direction: column;
    gap: 8px;
    font-size: 13px;
    color: #666;
    font-weight: 500;
}

.settings span {
    display: flex;
    justify-content: space-between;
}

.slider {
    width: 100%;
    height: 6px;
    border-radius: 3px;
    background: #ddd;
    outline: none;
    -webkit-appearance: none;
    appearance: none;
    cursor: pointer;
}

.slider::-webkit-slider-thumb {
    -webkit-appearance: none;
    appearance: none;
    width: 18px;
    height: 18px;
    border-radius: 50%;
    background: #667eea;
    cursor: pointer;
    box-shadow: 0 2px 5px rgba(102, 126, 234, 0.4);
}

.slider::-moz-range-thumb {
    width: 18px;
    height: 18px;
    border-radius: 50%;
    background: #667eea;
    cursor: pointer;
    border: none;
    box-shadow: 0 2px 5px rgba(102, 126, 234, 0.4);
}

.color-input {
    width: 50px;
    height: 40px;
    border: none;
    border-radius: 6px;
    cursor: pointer;
}

/* Canvas Area */
.canvas-area {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-height: 0;
    padding: 0 !important;
    background-color: transparent;
    /* Allow flex child to shrink below content size */
}

.pdf-viewer-wrapper {
    flex: 1;
    background: white;
    border-radius: 8px !important;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
    display: flex;
    align-items: flex-start;
    justify-content: center;
    overflow-x: auto;
    overflow-y: auto;
    position: relative;
    /* Prevent scroll jacking during drag */
    overscroll-behavior: contain;
}

.pdf-viewer {
    width: 100%;
    display: flex;
    align-items: center;
    flex-direction: column;
    gap: 20px;
    color: #999;
    cursor: crosshair;
    position: relative;
    padding: 20px;
    /* Don't set height/overflow here - let wrapper handle scrolling */
}

.preview-hint {
    text-align: center;
    color: #666;
    margin-bottom: 10px;
    font-size: 13px;
}

.pdf-viewer p {
    font-size: 16px;
    text-align: center;
}

.pdf-viewer canvas {
    display: block;
    width: auto;
    max-width: 100%;
    height: auto;
    box-sizing: border-box;
    border: 1px solid #eee;
    margin: 12px auto;
    background: white;
    cursor: grab;
    user-select: none;
    pointer-events: auto;
    /* Better mobile touch support for dragging */
    touch-action: manipulation;
    transition: outline 0.2s ease;
}

.pdf-viewer canvas.active-page {
    outline: 3px solid #667eea;
    outline-offset: 4px;
}

/* Hidden Class */
.hidden {
    display: none !important;
}

/* Modal */
.modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.5);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
}

.modal.hidden {
    display: none;
}

.modal-content {
    background: white;
    border-radius: 12px;
    max-width: 900px;
    width: 90%;
    max-height: 90vh;
    overflow: auto;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.3);
    display: flex;
    flex-direction: column;
}

.modal-header {
    padding: 20px;
    border-bottom: 1px solid #eee;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.modal-header h2 {
    color: #667eea;
    font-size: 20px;
}

.close-btn {
    background: none;
    border: none;
    font-size: 28px;
    cursor: pointer;
    color: #999;
    padding: 0;
    width: 30px;
    height: 30px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.close-btn:hover {
    color: #333;
}

.modal-body {
    padding: 20px;
    flex: 1;
    overflow-y: auto;
}

.modal-footer {
    padding: 20px;
    border-top: 1px solid #eee;
    display: flex;
    gap: 10px;
    justify-content: flex-end;
}

.manual-content h4 {
    color: #4158d0;
    margin: 15px 0 5px 0;
}

.manual-content ul {
    padding-left: 20px;
    margin-bottom: 10px;
}

.manual-content p {
    line-height: 1.6;
    margin-bottom: 10px;
}

.modal-footer .btn {
    width: auto;
    padding: 10px 20px;
    margin-bottom: 0;
}

/* Drawing Canvas */
#drawingCanvas {
    border: 2px solid #ddd;
    border-radius: 6px;
    cursor: crosshair;
    background: white;
    display: block;
    margin: 20px auto;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
}

.drawing-tools {
    display: flex;
    gap: 20px;
    margin-bottom: 20px;
    flex-wrap: wrap;
    align-items: center;
}

.drawing-tools label {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 14px;
    color: #666;
}

.drawing-tools .slider {
    width: 150px;
}

/* Signature Preview */
.signature-preview {
    display: flex;
    flex-direction: column;
}

.signature-preview-area {
    width: 100%;
    min-height: 400px;
    max-height: 600px;
    border: 2px solid #ddd;
    border-radius: 6px;
    position: relative;
    overflow-x: auto;
    overflow-y: auto;
    background: white;
    box-shadow: inset 0 2px 5px rgba(0, 0, 0, 0.05);
    /* Prevent scroll jacking during signature drag */
    overscroll-behavior: contain;
    display: flex;
    align-items: flex-start;
    justify-content: center;
    padding: 20px;
}

.signature-preview-area::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    pointer-events: none;
    z-index: 1;
}

.signature-preview-bg {
    position: relative;
    z-index: 2;
    background: white;
    margin: auto;
}

.signature-preview-bg canvas {
    display: block;
    border: 1px solid #eee;
    margin: 0;
}

.signature-preview-area>div:not(.signature-preview-bg) {
    position: absolute;
    cursor: grab;
    user-select: none;
    outline: 1px dashed transparent;
    transition: box-shadow 0.2s ease, outline-color 0.2s ease;
    padding: 0 !important;
    margin: 0 !important;
    background: transparent !important;
    border: none !important;
    border-radius: 0 !important;
    z-index: 3;
}

.signature-preview-area>div:not(.signature-preview-bg):hover {
    box-shadow: 0 2px 8px rgba(102, 126, 234, 0.3) !important;
    outline-color: #667eea !important;
}

.signature-preview-area>div:not(.signature-preview-bg):active {
    cursor: grabbing;
    box-shadow: 0 4px 12px rgba(102, 126, 234, 0.4) !important;
    outline-color: #667eea !important;
}

.signature-preview-area img,
.signature-preview-area canvas {
    display: block;
}

/* Status Bar */
.status-bar {
    background: white;
    padding: 12px 20px;
    border-top: 1px solid #eee;
    font-size: 13px;
    color: #666;
    text-align: right;
    box-shadow: 0 -2px 10px rgba(0, 0, 0, 0.05);
}

/* Scrollbar Styling */
::-webkit-scrollbar {
    width: 8px;
    height: 8px;
}

::-webkit-scrollbar-track {
    background: #f1f1f1;
}

::-webkit-scrollbar-thumb {
    background: #667eea;
    border-radius: 4px;
}

::-webkit-scrollbar-thumb:hover {
    background: #764ba2;
}

/* Responsive */
@media (max-width: 1024px) {
    .main-content {
        flex-direction: row; /* Tetap menyamping */
        gap: 10px;
        position: relative;
    }

    .sidebar {
        position: absolute;
        left: 10px;
        top: 10px;
        bottom: 10px;
        width: 240px !important;
        z-index: 1000;
        background: rgba(255, 255, 255, 0.95);
        backdrop-filter: blur(5px);
        box-shadow: 2px 0 15px rgba(0,0,0,0.2);
    }

    /* Kondisi Sidebar Tersembunyi */
    .sidebar.collapsed {
        transform: translateX(-110%);
    }

    .sidebar-toggle {
        display: flex;
        position: fixed;
        bottom: 20px;
        left: 20px;
        width: 48px;
        height: 48px;
        background: #4158d0;
        color: white;
        border: none;
        border-radius: 50%;
        align-items: center;
        justify-content: center;
        z-index: 2000;
        box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
        cursor: pointer;
        transition: background 0.3s ease, transform 0.2s ease;
    }

    .sidebar-toggle:active {
        transform: scale(0.9);
    }

    .canvas-area {
        margin-left: 0; /* Biarkan tertutup sedikit atau user bisa scroll */
    }
    
    .modal-content {
        width: 95%;
    }

    #drawingCanvas {
        max-width: 100%;
        height: auto;
    }
}

@media (max-width: 768px) {
    .header h1 {
        font-size: 20px;
    }

    .modal-content {
        border-radius: 8px;
    }

    .drawing-tools {
        flex-direction: column;
    }

    .drawing-tools label {
        width: 100%;
    }
}

/* Signature Individual Overlays */
.signature-overlay-container {
    cursor: grab;
    user-select: none;
    outline: 1px solid transparent;
    outline-offset: 2px;
    transition: outline-color 0.3s ease, opacity 0.3s ease;
}

.signature-overlay-container.selected {
    outline-color: #4158d0;
    z-index: 60 !important;
}

.text-overlay-container {
    white-space: nowrap;
    line-height: 1.2;
}

.signature-delete-btn {
    position: absolute;
    top: -15px;
    right: -15px;
    background: transparent;
    color: #ee5253;
    border: none;
    display: none; /* Muncul hanya saat parent memiliki class .selected */
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: opacity 0.2s ease, color 0.2s ease;
    padding: 0;
    line-height: 0;
}

.signature-overlay-container.selected .signature-delete-btn {
    display: flex;
}

.signature-delete-btn:hover {
    transform: scale(1.2);
    background: #ff4757;
    background: transparent;
}