/* =========================================
   DESIGN SYSTEM (CSS VARIABLES)
   ========================================= */
:root {
    --primary: #4f46e5;
    --primary-hover: #4338ca;
    --success: #10b981;
    --success-hover: #059669;
    --bg-body: #f8fafc;
    --bg-surface: #ffffff;
    --text-main: #0f172a;
    --text-muted: #64748b;
    --border: #e2e8f0;
    --radius: 16px;
    --radius-sm: 8px;
    --shadow-sm: 0 1px 3px rgba(0,0,0,0.1);
    --shadow-md: 0 4px 6px -1px rgba(0,0,0,0.1), 0 2px 4px -2px rgba(0,0,0,0.1);
    --transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

/* =========================================
   GLOBAL STYLES & ACCESSIBILITY
   ========================================= */
body { 
    font-family: 'Inter', sans-serif; 
    background-color: var(--bg-body);
    color: var(--text-main);
    margin: 0; padding: 20px; line-height: 1.5;
}
.container { max-width: 800px; margin: 20px auto; }

/* Mengunci scroll di background body saat fullscreen aktif */
body.viewer-fullscreen-active { overflow: hidden; }

/* Focus styles untuk Keyboard Navigation */
:focus-visible { outline: 3px solid var(--primary); outline-offset: 2px; border-radius: 4px; }

/* =========================================
   TABS NAVIGATION
   ========================================= */
.tabs {
    display: flex; flex-wrap: wrap; gap: 6px;
    background: var(--border); padding: 6px;
    border-radius: var(--radius); margin-bottom: 24px;
}
.tab-btn {
    flex: 1; min-width: 120px; padding: 12px;
    background: transparent; color: var(--text-muted);
    font-weight: 600; font-size: 14px;
    border: none; border-radius: 12px; cursor: pointer;
    transition: var(--transition);
    display: flex; align-items: center; justify-content: center; gap: 8px;
}
.tab-btn:hover { color: var(--text-main); background: rgba(255,255,255,0.5); }
.tab-btn.active { background: var(--bg-surface); color: var(--primary); box-shadow: var(--shadow-sm); }

/* =========================================
   SURFACE / CARD STYLES
   ========================================= */
.card {
    background: var(--bg-surface); padding: 30px;
    border-radius: var(--radius); box-shadow: var(--shadow-md);
    display: none; animation: fadeIn 0.4s ease-in-out;
}
.card.active { display: block; }
@keyframes fadeIn {
    from { opacity: 0; transform: translateY(10px); }
    to { opacity: 1; transform: translateY(0); }
}
h2 { margin-top: 0; font-size: 24px; font-weight: 700; color: var(--text-main); }
p.subtitle { color: var(--text-muted); margin-top: -10px; margin-bottom: 24px; font-size: 14px; }

/* =========================================
   CUSTOM FILE DROPZONE (DENGAN DRAGOVER STATE)
   ========================================= */
.dropzone-wrapper { position: relative; margin-bottom: 24px; }
.dropzone-input {
    position: absolute; width: 100%; height: 100%;
    opacity: 0; cursor: pointer; z-index: 10;
}
.dropzone-ui {
    border: 2px dashed var(--border); border-radius: var(--radius);
    padding: 30px 20px; text-align: center; background: var(--bg-body);
    transition: var(--transition); display: flex; flex-direction: column;
    align-items: center; justify-content: center; gap: 12px;
}
/* Visual Feedback saat Dragging */
.dropzone-wrapper:hover .dropzone-ui,
.dropzone-wrapper.dragover .dropzone-ui {
    border-color: var(--primary); background: #eff6ff; transform: scale(1.01);
}
.dropzone-ui svg { width: 42px; height: 42px; color: var(--primary); transition: var(--transition); }
.dropzone-wrapper.dragover .dropzone-ui svg { transform: translateY(-5px); }
.dropzone-ui .dz-title { font-weight: 600; color: var(--text-main); font-size: 15px; }
.dropzone-ui .dz-desc { color: var(--text-muted); font-size: 13px; }
.file-info {
    display: none; margin-top: 12px; padding: 12px; background: #f0fdf4;
    border: 1px solid #bbf7d0; border-radius: var(--radius-sm);
    color: #166534; font-size: 14px; font-weight: 500; text-align: center;
}

/* =========================================
   FORM ELEMENTS & BUTTONS
   ========================================= */
.form-group {
    background: var(--bg-body); padding: 20px; border-radius: var(--radius-sm);
    margin-bottom: 24px; border: 1px solid var(--border);
}
.form-label { display: block; font-weight: 600; margin-bottom: 12px; font-size: 14px; }
.radio-options { display: flex; gap: 16px; margin-bottom: 20px; flex-wrap: wrap; }
.radio-options label { display: flex; align-items: center; gap: 8px; font-size: 14px; font-weight: 500; cursor: pointer; }
.text-input {
    width: 100%; padding: 12px 16px; border: 1px solid var(--border);
    border-radius: var(--radius-sm); font-family: 'Inter', sans-serif;
    font-size: 14px; box-sizing: border-box; transition: var(--transition);
}
.text-input:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px rgba(79, 70, 229, 0.1); }
.help-text { font-size: 12px; color: var(--text-muted); margin-top: 6px; display: block; }

.btn {
    width: 100%; padding: 16px; background: var(--success); color: white;
    border: none; border-radius: var(--radius-sm); font-size: 16px; font-weight: 600;
    font-family: 'Inter', sans-serif; cursor: pointer; transition: var(--transition);
    display: flex; justify-content: center; align-items: center; gap: 10px; position: relative;
}
.btn:hover:not(:disabled) { background: var(--success-hover); transform: translateY(-1px); }
.btn:disabled { opacity: 0.7; cursor: not-allowed; }
.btn-download { background: var(--primary); width: auto; padding: 10px 20px; font-size: 14px; border-radius: 20px; display: inline-flex; }
.btn-download:hover:not(:disabled) { background: var(--primary-hover); }

/* Animasi Loading Spin */
@keyframes spin { to { transform: rotate(360deg); } }
.icon-spin { animation: spin 1s linear infinite; }

/* =========================================
   PDF VIEWER PRO (DENGAN FULLSCREEN CSS)
   ========================================= */
.viewer-container {
    display: none; border: 1px solid var(--border);
    border-radius: var(--radius-sm); overflow: hidden; background: #e2e8f0;
    margin-top: 20px; transition: var(--transition);
}
.viewer-toolbar {
    background: var(--bg-surface); padding: 12px 16px;
    display: flex; justify-content: space-between; align-items: center;
    border-bottom: 1px solid var(--border); flex-wrap: wrap; gap: 10px;
}
.toolbar-group { display: flex; align-items: center; gap: 8px; background: var(--bg-body); padding: 4px; border-radius: 8px; }
.tool-btn {
    background: white; border: 1px solid var(--border); padding: 6px 12px;
    border-radius: 6px; cursor: pointer; display: flex; align-items: center; justify-content: center;
    transition: var(--transition); color: var(--text-main);
}
.tool-btn:hover:not(:disabled) { background: var(--primary); color: white; border-color: var(--primary); }
.tool-btn.active-state { background: var(--primary); color: white; border-color: var(--primary); }
.tool-btn:disabled { opacity: 0.5; cursor: not-allowed; }
.page-info { font-size: 14px; font-weight: 600; min-width: 90px; text-align: center; }

.viewer-canvas-wrapper {
    height: 60vh; max-height: 600px; 
    overflow: auto; /* Memastikan scroll nyala secara default */
    padding: 24px; display: flex; justify-content: center; align-items: flex-start;
}
#theViewerCanvas {
    box-shadow: 0 10px 25px rgba(0,0,0,0.1); 
    border-radius: 4px; background: white;
}

/* STATE: IS-FULLSCREEN */
.viewer-container.is-fullscreen {
    position: fixed;
    top: 0; left: 0; right: 0; bottom: 0;
    width: 100vw; 
    height: 100vh; /* Fallback support */
    height: 100dvh; /* Modern mobile support */
    z-index: 99999;
    margin: 0; border-radius: 0; border: none;
    display: flex; flex-direction: column;
}

/* KUNCI PERBAIKAN SCROLL LAPTOP/DESKTOP DI FULLSCREEN */
.viewer-container.is-fullscreen .viewer-canvas-wrapper {
    flex: 1 1 auto; /* Mengizinkan wrapper mengambil sisa ruang dan menyesuaikan isi */
    height: auto; 
    min-height: 0; /* Bugfix spesifik Flexbox agar scroll-y bisa aktif jika isi melebih batas */
    max-height: none; 
    background: #cbd5e1; 
    overflow-y: auto; /* Memaksa scroll bar vertikal muncul jika diperlukan */
    -webkit-overflow-scrolling: touch; /* Scroll mulus di iOS/Mac */
}

/* =========================================
   THUMBNAIL & PREVIEW AREAS
   ========================================= */
.preview-box {
    display: none; margin-bottom: 24px; border: 1px solid var(--border);
    border-radius: var(--radius-sm); overflow: hidden; background: var(--bg-body);
}
.preview-header { background: var(--border); padding: 12px 16px; font-weight: 600; font-size: 14px; display: flex; justify-content: space-between; }
.preview-content { height: 350px; overflow-y: auto; padding: 20px; display: flex; flex-direction: column; align-items: center; gap: 20px; }
.preview-page canvas { max-width: 100%; height: auto; box-shadow: var(--shadow-md); border-radius: 4px; }
.page-badge { background: var(--text-main); color: white; font-size: 12px; padding: 4px 10px; border-radius: 12px; margin-bottom: 8px; display: inline-block; }

.img-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(100px, 1fr)); gap: 12px; margin-top: 16px; }
.img-card { position: relative; aspect-ratio: 1; border-radius: var(--radius-sm); overflow: hidden; border: 1px solid var(--border); background: #fff; }
.img-card img { width: 100%; height: 100%; object-fit: cover; }
.img-card-badge { position: absolute; top: 4px; left: 4px; background: rgba(0,0,0,0.7); color: white; font-size: 10px; font-weight: 600; padding: 2px 6px; border-radius: 4px; z-index: 2;}

.result-item { background: #fff; border: 1px solid var(--border); border-radius: var(--radius-sm); padding: 20px; margin-top: 16px; text-align: center; }
.result-item canvas { max-width: 100%; height: auto; border: 1px solid #eee; margin-bottom: 16px; }

/* =========================================
   STATUS MESSAGES
   ========================================= */
.status-msg { margin-top: 20px; padding: 16px; border-radius: var(--radius-sm); text-align: center; font-weight: 500; font-size: 14px; }
.status-msg.info { background: #eff6ff; color: #1d4ed8; border: 1px solid #bfdbfe; }
.status-msg.success { background: #f0fdf4; color: #15803d; border: 1px solid #bbf7d0;}
.status-msg.error { background: #fef2f2; color: #b91c1c; border: 1px solid #fecaca;}