/* Template Generator Styles */
/* Isolated styles untuk template generator */

.template-generator-container {
    width: 100%;
    height: 100vh;
    display: flex;
    overflow: hidden;
    background: var(--color-bg-app, #f8fafc);
}

/* Loading State */
.loading-container {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    height: 100vh;
    gap: 1rem;
    color: #64748b;
    font-family: system-ui, -apple-system, sans-serif;
}

.loading {
    width: 32px;
    height: 32px;
    border: 3px solid #e2e8f0;
    border-top: 3px solid #3b82f6;
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

/* React App Container */
#template-generator-root {
    width: 100%;
    height: 100vh;
}

body, #template-generator-root {
    font-family: var(--font-ui, system-ui, -apple-system, sans-serif);
    color: var(--color-text-primary, #1f2937);
}

/* Sidebar Styles */
.template-sidebar {
    width: clamp(320px, 36vw, 440px);
    flex-shrink: 0;
    background: var(--color-bg-panel, #ffffff);
    border-right: 1px solid var(--color-border-panel, #e2e8f0);
    overflow-y: auto;
}

.template-sidebar-header {
    padding: 1rem;
    border-bottom: 1px solid #e2e8f0;
    background: #f8fafc;
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.template-sidebar-content {
    padding: 1rem;
}

/* Preview Panel */
.template-preview {
    flex: 1;
    min-width: 0;
    overflow-y: auto;
    background: var(--color-bg-preview, #f1f5f9);
    padding: 1rem;
}

.template-preview-container {
    max-width: 210mm;
    width: 100%;
    margin: 0 auto;
    background: var(--color-bg-panel, #ffffff);
    box-shadow: 0 4px 6px -1px var(--color-shadow-panel, rgba(0, 0, 0, 0.1));
    min-height: 297mm;
    overflow: hidden;
}

/* Print Styles */
@media print {
    .template-sidebar {
        display: none !important;
    }
    
    .template-preview {
        background: white !important;
        padding: 0 !important;
    }
    
    .template-preview-container {
        box-shadow: none !important;
        margin: 0 !important;
        max-width: none !important;
    }
}

/* Form Styles */
.template-form-group {
    margin-bottom: 0.9rem;
}

.template-form-label {
    display: block;
    font-size: var(--font-size-xs, 12px);
    font-weight: 500;
    color: var(--color-text-label, #374151);
    margin-bottom: 0.25rem;
}

.template-form-input {
    width: 100%;
    padding: 0.55rem 0.65rem;
    border: 1px solid var(--color-border-input, #d1d5db);
    border-radius: 0.375rem;
    font-size: var(--font-size-sm, 13px);
    transition: border-color 0.15s;
    min-height: 34px;
    background: #fff;
}
.template-form-input::placeholder {
    color: #9ca3af;
}

.template-form-input:focus {
    outline: none;
    border-color: var(--color-primary-mid, #3b82f6);
    box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.12);
}

.template-form-select {
    width: 100%;
    padding: 0.55rem 0.65rem;
    border: 1px solid var(--color-border-input, #d1d5db);
    border-radius: 0.375rem;
    font-size: var(--font-size-sm, 13px);
    background: white;
}

/* Tab Styles */
.template-tabs {
    display: flex;
    border-bottom: 1px solid #e2e8f0;
    background: white;
}

.template-tab {
    padding: 0.75rem 1rem;
    background: none;
    border: none;
    cursor: pointer;
    font-size: var(--font-size-sm, 13px);
    color: var(--color-text-secondary, #6b7280);
    border-bottom: 2px solid transparent;
    transition: all 0.15s;
}

.template-tab:hover {
    color: var(--color-text-primary, #374151);
    background: var(--color-bg-hover, #f9fafb);
}

.template-tab.active {
    color: var(--color-primary-mid, #3b82f6);
    border-bottom-color: var(--color-primary-mid, #3b82f6);
    background: var(--color-primary-xlight, #f0f9ff);
}

/* Button Styles */
.template-btn {
    padding: 0.5rem 1rem;
    border: none;
    border-radius: 0.375rem;
    font-size: 0.875rem;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.15s;
}

.template-btn-primary {
    background: var(--color-btn-primary, #3b82f6);
    color: var(--color-btn-primary-txt, #ffffff);
}

.template-btn-primary:hover {
    background: var(--color-btn-primary-hv, #2563eb);
}

.template-btn-secondary {
    background: var(--color-btn-secondary, #6b7280);
    color: var(--color-btn-secondary-txt, #ffffff);
}

.template-btn-secondary:hover {
    background: var(--color-btn-secondary-hv, #4b5563);
}

/* Section styling */
.form-section {
    border: 1px solid var(--color-border-panel, #e5e7eb);
    background: var(--color-bg-section, #fff);
    border-radius: 0.5rem;
    padding: 1rem;
}

.section-title {
    padding-bottom: 0.5rem;
    border-bottom: 1px dashed var(--color-border-panel, #e5e7eb);
    margin-bottom: 0.5rem;
}

.section-subtitle {
    padding-top: 0.25rem;
    margin-top: 0.5rem;
}

/* A4 Page Styles */
/* Document typography + layout baseline (scoped to Template Generator) */
.a4-page {
    width: 210mm;
    min-height: 297mm;
    padding: 15mm;
    background: white;
    margin: 0 auto;
    box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1);
    font-family: "Times New Roman", Times, serif;
    font-size: 11pt;
    line-height: 1.6;
    color: #000;
}

@media print {
    .a4-page {
        box-shadow: none;
        margin: 0;
        padding: 15mm;
        width: 100% !important;
        min-height: 100%;
        box-sizing: border-box;
    }
    .template-preview-container {
        padding: 0 !important;
        background: #fff !important;
        overflow: visible !important;
    }
    .template-generator-container {
        background: #fff !important;
        overflow: visible !important;
    }
    .template-preview {
        overflow: visible !important;
    }
}

/* Utility Classes from Tailwind */
.text-center { text-align: center; }
.text-sm { font-size: 0.875rem; }
.text-lg { font-size: 1.125rem; }
.text-md { font-size: 1rem; }
.text-xs { font-size: 0.75rem; }
.text-\[10px\] { font-size: 10px; }
.font-bold { font-weight: 700; }
.font-medium { font-weight: 500; }
.uppercase { text-transform: uppercase; }
.underline { text-decoration: underline; }
.italic { font-style: italic; }
.leading-relaxed { line-height: 1.625; }
.text-justify { text-align: justify; }
.mb-6 { margin-bottom: 1.5rem; }
.mt-4 { margin-top: 1rem; }
.mt-12 { margin-top: 3rem; }
.ml-8 { margin-left: 2rem; }
.mr-8 { margin-right: 2rem; }
.space-y-1 > * + * { margin-top: 0.25rem; }
.space-y-2 > * + * { margin-top: 0.5rem; }
.space-y-3 > * + * { margin-top: 0.75rem; }
.space-y-4 > * + * { margin-top: 1rem; }
.space-y-6 > * + * { margin-top: 1.5rem; }
.grid { display: grid; }
.grid-cols-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
/* Escaped selectors for bracketed class names */
.grid-cols-\[150px_10px_1fr\] { grid-template-columns: 150px 10px 1fr; }
.grid-cols-\[120px_10px_1fr\] { grid-template-columns: 120px 10px 1fr; }

/* Align label ":" value rows consistently */
.a4-page .grid-cols-\[150px_10px_1fr\],
.a4-page .grid-cols-\[120px_10px_1fr\] {
    align-items: baseline;
    column-gap: 6px;
}
.a4-page .grid-cols-\[150px_10px_1fr\] > span:nth-child(2),
.a4-page .grid-cols-\[120px_10px_1fr\] > span:nth-child(2) {
    text-align: center;
    width: 10px;
}
.gap-2 { gap: 0.5rem; }
.gap-3 { gap: 0.75rem; }
.w-full { width: 100%; }
.w-1\/2 { width: 50%; }
.h-8 { height: 2rem; }
.h-20 { height: 5rem; }
.border { border-width: 1px; }
.border-black { border-color: #000; }
.border-collapse { border-collapse: collapse; }
.p-2 { padding: 0.5rem; }
.bg-gray-100 { background-color: #f3f4f6; }
.bg-gray-50 { background-color: #f9fafb; }
.bg-blue-50 { background-color: #eff6ff; }
.text-blue-600 { color: #2563eb; }
.list-disc { list-style-type: disc; }
.flex { display: flex; }
.flex-1 { flex: 1 1 0%; }
.flex-col { flex-direction: column; }
.items-center { align-items: center; }
.justify-center { justify-content: center; }
.justify-between { justify-content: space-between; }
.items-end { align-items: flex-end; }
.relative { position: relative; }
.overflow-hidden { overflow: hidden; }
.overflow-y-auto { overflow-y: auto; }
.h-screen { height: 100vh; }
.no-print { display: block; }
.tracking-wider { letter-spacing: 0.05em; }
.rounded-md { border-radius: 0.375rem; }
.shadow-sm { box-shadow: 0 1px 2px 0 rgba(0, 0, 0, 0.05); }
.transition-colors { transition-property: color, background-color, border-color; }
.transition-all { transition-property: all; }

/* Print-specific */
@media print {
    .no-print { display: none !important; }
}

/* Kop Surat Specific */
.kop-surat-preview .kop-line {
    height: 2px;
    background: #000;
    margin: 0.5rem 0;
}

/* Table Styles */
.w-full { width: 100%; }
.border-collapse { border-collapse: collapse; }
.border { border: 1px solid #000; }
.border-black { border-color: #000; }
.p-2 { padding: 0.5rem; }
.bg-gray-100 { background-color: #f3f4f6; }

/* Print-friendly table header */
@media print {
    .bg-gray-100 { background-color: #f3f4f6 !important; }
    th { -webkit-print-color-adjust: exact; print-color-adjust: exact; }
}

/* Compact table rows for print (fit 35 rows) */
@media print {
    .a4-page table {
        font-size: 10pt;
    }
    .a4-page table th,
    .a4-page table td {
        padding: 3px 6px !important;
        line-height: 1.2;
    }
    .a4-page table td {
        height: 20px;
    }
    .a4-page .h-8 {
        height: 20px !important;
    }
}

/* Hide scrollbars for print (Template Generator only) */
@media print {
    .template-generator-container::-webkit-scrollbar,
    .template-preview::-webkit-scrollbar,
    .template-preview-container::-webkit-scrollbar {
        width: 0;
        height: 0;
    }
}

/* Responsive layout */
@media (max-width: 960px) {
    .template-app {
        flex-direction: column;
        height: 100vh;
    }
    .template-sidebar {
        width: 100%;
        max-height: 55vh;
        border-right: none;
        border-bottom: 1px solid #e2e8f0;
    }
    .template-preview {
        padding: 0.75rem;
    }
    .template-preview-container {
        max-width: 100%;
        min-height: auto;
    }
}
