/* ==========================================================================
   CSS Variables & Reset
   ========================================================================== */
:root {
    --primary: #4F46E5; /* Indigo 600 */
    --primary-hover: #4338CA;
    --secondary: #10B981; /* Emerald 500 */
    --bg-color: #F3F4F6; /* Gray 100 */
    --surface-color: #FFFFFF;
    --text-main: #1F2937; /* Gray 800 */
    --text-muted: #6B7280; /* Gray 500 */
    --border-color: #E5E7EB; /* Gray 200 */
    --shadow-sm: 0 1px 2px 0 rgba(0, 0, 0, 0.05);
    --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06);
    --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.1), 0 4px 6px -2px rgba(0, 0, 0, 0.05);
    --border-radius-lg: 12px;
    --border-radius-md: 8px;
    --border-radius-sm: 4px;
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

body {
    background-color: var(--bg-color);
    color: var(--text-main);
    line-height: 1.5;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

/* ==========================================================================
   Typography & Layout
   ========================================================================== */
.navbar {
    background: var(--surface-color);
    padding: 1rem 2rem;
    box-shadow: var(--shadow-sm);
    display: flex;
    align-items: center;
    justify-content: space-between;
    border-bottom: 1px solid var(--border-color);
}

.logo {
    font-size: 1.5rem;
    font-weight: 800;
    color: var(--text-main);
}

.logo span {
    color: var(--primary);
}

.navbar p {
    color: var(--text-muted);
    font-size: 0.9rem;
    font-weight: 500;
}

.container {
    display: flex;
    flex: 1;
    max-width: 1400px;
    margin: 0 auto;
    width: 100%;
    padding: 2rem;
    gap: 2rem;
}

/* ==========================================================================
   Sidebar & Controls
   ========================================================================== */
.sidebar {
    width: 320px;
    background: var(--surface-color);
    border-radius: var(--border-radius-lg);
    box-shadow: var(--shadow-md);
    padding: 1.5rem;
    display: flex;
    flex-direction: column;
    gap: 2rem;
    height: fit-content;
}

.control-group h3 {
    font-size: 1rem;
    margin-bottom: 1rem;
    color: var(--text-main);
    border-bottom: 2px solid var(--border-color);
    padding-bottom: 0.5rem;
}

.file-input {
    display: none;
}

.btn {
    display: inline-block;
    width: 100%;
    padding: 0.75rem 1rem;
    text-align: center;
    border-radius: var(--border-radius-md);
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s ease;
    border: none;
    font-size: 0.95rem;
}

.btn-outline {
    background: transparent;
    border: 2px dashed var(--primary);
    color: var(--primary);
}

.btn-outline:hover {
    background: rgba(79, 70, 229, 0.05);
}

.btn-primary {
    background: var(--primary);
    color: white;
    box-shadow: var(--shadow-md);
}

.btn-primary:hover:not(:disabled) {
    background: var(--primary-hover);
    transform: translateY(-1px);
}

.btn-primary:disabled {
    background: var(--text-muted);
    cursor: not-allowed;
    opacity: 0.7;
    transform: none;
}

.btn-icon {
    width: 36px;
    height: 36px;
    padding: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--bg-color);
    border: 1px solid var(--border-color);
    border-radius: var(--border-radius-sm);
    cursor: pointer;
    transition: background 0.2s;
}

.btn-icon:hover {
    background: var(--border-color);
}

/* ==========================================================================
   Signature Gallery
   ========================================================================== */
.signature-gallery {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 1rem;
}

.signature-item {
    border: 2px solid var(--border-color);
    border-radius: var(--border-radius-md);
    padding: 0.5rem;
    cursor: pointer;
    transition: all 0.2s ease;
    background: var(--bg-color);
    display: flex;
    align-items: center;
    justify-content: center;
    height: 80px;
}

.signature-item img {
    max-width: 100%;
    max-height: 100%;
    object-fit: contain;
}

.signature-item:hover {
    border-color: var(--primary);
    background: white;
}

.signature-item.selected {
    border-color: var(--primary);
    background: rgba(79, 70, 229, 0.1);
    box-shadow: 0 0 0 2px var(--primary) inset;
}

/* ==========================================================================
   Workspace & PDF Canvas
   ========================================================================== */
.workspace {
    flex: 1;
    background: var(--surface-color);
    border-radius: var(--border-radius-lg);
    box-shadow: var(--shadow-md);
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.workspace-header {
    padding: 1rem 1.5rem;
    border-bottom: 1px solid var(--border-color);
    display: flex;
    justify-content: space-between;
    align-items: center;
    background: #FAFAFA;
}

.workspace-header h2 {
    font-size: 1.1rem;
    color: var(--text-main);
}

.pagination {
    display: flex;
    align-items: center;
    gap: 1rem;
    font-size: 0.9rem;
    font-weight: 500;
}

.pdf-container {
    flex: 1;
    position: relative;
    overflow: auto;
    background: #E5E7EB;
    /* Use padding and block layout to prevent flexbox clipping when content is large */
    padding: 2rem;
    text-align: center;
}

/* Ensure the canvas sits inside relative container but maintains its rendered size */
.pdf-wrapper {
    position: relative;
    box-shadow: var(--shadow-lg);
    background: white;
    display: inline-block;
    text-align: left;
    /* Prevent shrinking below rendered size */
    flex-shrink: 0;
    max-width: 100%;
}

canvas#pdf-canvas {
    display: block;
    width: 100%;
    height: auto;
}

.placeholder-text {
    color: var(--text-muted);
    font-size: 1.2rem;
    font-weight: 500;
    text-align: center;
}

/* ==========================================================================
   Signature Overlay (Interact.js)
   ========================================================================== */
.signature-overlay {
    position: absolute;
    top: 50px;
    left: 50px;
    width: 150px;
    height: auto;
    border: 2px dashed rgba(79, 70, 229, 0.6);
    background: rgba(79, 70, 229, 0.05);
    cursor: move;
    touch-action: none;
    user-select: none;
    box-sizing: border-box;
    z-index: 10;
}

.signature-overlay.hidden {
    display: none;
}

.signature-overlay img {
    width: 100%;
    height: 100%;
    pointer-events: none; /* Let the container handle dragging */
    object-fit: contain;
    display: block;
}

/* Resize Handles */
.resize-handle {
    position: absolute;
    width: 12px;
    height: 12px;
    background-color: white;
    border: 2px solid var(--primary);
    border-radius: 50%;
    z-index: 11;
}

.resize-handle.top-left {
    top: -6px;
    left: -6px;
    cursor: nwse-resize;
}

.resize-handle.top-right {
    top: -6px;
    right: -6px;
    cursor: nesw-resize;
}

.resize-handle.bottom-left {
    bottom: -6px;
    left: -6px;
    cursor: nesw-resize;
}

.resize-handle.bottom-right {
    bottom: -6px;
    right: -6px;
    cursor: nwse-resize;
}

/* Status Message */
.status-message {
    margin-top: 1rem;
    font-size: 0.9rem;
    text-align: center;
    font-weight: 500;
}

.status-message.success { color: var(--secondary); }
.status-message.error { color: #EF4444; }
.status-message.info { color: var(--primary); }

/* ==========================================================================
   Responsive Design
   ========================================================================== */
@media (max-width: 768px) {
    .container {
        flex-direction: column;
        padding: 1rem;
        gap: 1rem;
    }

    .navbar {
        padding: 1rem;
        flex-direction: column;
        gap: 0.5rem;
        text-align: center;
    }

    .sidebar {
        width: 100%;
        order: 1; /* pastikan sidebar di atas workspace di mobile jika diinginkan, atau order: 2 jika di bawah */
    }

    .workspace {
        width: 100%;
        min-height: 500px;
        order: 2;
    }

    .pdf-container {
        padding: 1rem;
    }

    /* Memperbesar resize handle untuk layar sentuh di mobile */
    .resize-handle {
        width: 24px;
        height: 24px;
    }
    .resize-handle.top-left { top: -12px; left: -12px; }
    .resize-handle.top-right { top: -12px; right: -12px; }
    .resize-handle.bottom-left { bottom: -12px; left: -12px; }
    .resize-handle.bottom-right { bottom: -12px; right: -12px; }
}
