:root {
    --bg-color: #0f111a;
    --panel-bg: rgba(25, 28, 41, 0.6);
    --panel-border: rgba(255, 255, 255, 0.08);
    --text-main: #f0f2f5;
    --text-muted: #9aa0a6;
    --primary: #2F5C4B;
    --primary-hover: #24473a;
    --accent: #D47A5A;
    --danger: #ef4444;
    --input-bg: rgba(0,0,0,0.2);
    --surface-light: rgba(255,255,255,0.05);
    --strong-color: #ffffff;
    --toast-bg: var(--panel-bg);
    --bg-image: radial-gradient(at 0% 0%, rgba(47, 92, 75, 0.15) 0px, transparent 50%), radial-gradient(at 100% 100%, rgba(212, 122, 90, 0.15) 0px, transparent 50%);
    --panel-backdrop: blur(16px);
    --panel-shadow: 0 8px 32px 0 rgba(0, 0, 0, 0.37);
}

:root[data-theme="light"] {
    --bg-color: #f8fafc;
    --panel-bg: #ffffff;
    --panel-border: #e2e8f0;
    --text-main: #000000;
    --text-muted: #333333;
    --primary: #2F5C4B;
    --primary-hover: #24473a;
    --accent: #D47A5A;
    --danger: #ef4444;
    --input-bg: #ffffff;
    --surface-light: #f1f5f9;
    --strong-color: #000000;
    --toast-bg: #ffffff;
    --bg-image: linear-gradient(135deg, #f6f8fb 0%, #e9eef5 100%);
    --panel-backdrop: none;
    --panel-shadow: 0 10px 40px -10px rgba(0, 0, 0, 0.08);
}

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

html {
    font-size: 13px; /* Skala ~80% (dari default 16px) */
}

body {
    font-family: 'Inter', sans-serif;
    background-color: var(--bg-color);
    background-image: var(--bg-image);
    background-attachment: fixed;
    color: var(--text-main);
    min-height: 100vh;
    line-height: 1.6;
}

.app-container {
    max-width: 1500px;
    width: 95%;
    margin: 0 auto;
    padding: 1rem;
    display: flex;
    flex-direction: column;
    gap: 1rem;
    height: 100vh;
}

/* Glassmorphism Utilities */
.glass-header, .glass-panel {
    background: var(--panel-bg);
    backdrop-filter: var(--panel-backdrop);
    -webkit-backdrop-filter: var(--panel-backdrop);
    border: 1px solid var(--panel-border);
    border-radius: 4px; /* Lancip / Sharp corners */
    box-shadow: var(--panel-shadow);
}

.glass-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0.1rem 1.5rem;
    box-shadow: 0 4px 30px rgba(0, 0, 0, 0.1);
    position: relative;
    z-index: 50;
}

.logo {
    display: flex;
    align-items: center;
    gap: 1rem;
    color: var(--primary);
}

.header-actions {
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

.logo h1 {
    font-size: 1.4rem;
    font-weight: 700;
    color: var(--text-main);
    letter-spacing: -0.03em;
}

.logo svg {
    color: #8b5cf6;
    stroke-width: 3;
    filter: drop-shadow(0 0 8px rgba(139, 92, 246, 0.4));
}

.logo-highlight {
    color: #8b5cf6;
}

.brand-name {
    font-weight: 700;
    letter-spacing: -0.02em;
    color: var(--text-main);
}

.brand-name .highlight {
    color: #8b5cf6;
}

.api-key-container input {
    background: rgba(0, 0, 0, 0.2);
    border: 1px solid var(--panel-border);
    padding: 0.5rem 1rem;
    border-radius: 2px;
    color: var(--text-main);
    width: 300px;
    transition: all 0.2s;
    font-family: 'Inter', sans-serif;
}

.api-key-container input:focus {
    outline: none;
    border-color: var(--primary);
    background: rgba(0, 0, 0, 0.4);
}

/* Main Layout */
.main-content {
    display: grid;
    grid-template-columns: 25rem 1fr;
    gap: 2rem;
    flex: 1;
    min-height: 0; /* Important for scroll */
}

/* Left Panel */
.input-panel {
    padding: 1rem;
    display: flex;
    flex-direction: column;
    gap: 1rem;
    overflow-y: auto;
}

.input-panel h2 {
    font-size: 1rem;
    color: var(--text-muted);
    font-weight: 500;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

/* Tabs */
.tabs {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
}

.tab-btn {
    background: rgba(255,255,255,0.05);
    border: 1px solid transparent;
    color: var(--text-muted);
    padding: 0.5rem 1rem;
    border-radius: 2px;
    cursor: pointer;
    font-size: 0.875rem;
    font-weight: 500;
    transition: all 0.2s ease;
}

.tab-btn:hover {
    background: rgba(255,255,255,0.1);
    color: var(--text-main);
}

.tab-btn.active {
    background: var(--primary);
    color: white;
    border-color: var(--primary-hover);
    box-shadow: 0 0 15px rgba(47, 92, 75, 0.3);
}

.tab-pane {
    display: none;
    animation: fadeIn 0.3s ease;
}

.tab-pane.active {
    display: block;
}

@keyframes fadeIn {
    from { opacity: 0; transform: translateY(5px); }
    to { opacity: 1; transform: translateY(0); }
}

/* Inputs */
textarea, input[type="text"], input[type="url"], input[type="password"], select {
    width: 100%;
    background: var(--input-bg);
    border: 1px solid var(--panel-border);
    border-radius: 2px;
    padding: 1rem;
    color: var(--text-main);
    font-family: inherit;
    transition: background 0.2s, border-color 0.2s;
}

textarea {
    min-height: 100px;
    resize: vertical;
}

textarea:focus, input[type="url"]:focus, select:focus {
    outline: none;
    border-color: var(--primary);
}

.file-upload {
    position: relative;
    overflow: hidden;
    display: inline-block;
    width: 100%;
}

.file-upload input[type="file"] {
    position: absolute;
    left: 0;
    top: 0;
    opacity: 0;
    cursor: pointer;
    width: 100%;
    height: 100%;
}

.file-upload label {
    display: block;
    padding: 2rem 1rem;
    text-align: center;
    background: var(--input-bg);
    border: 1px dashed var(--panel-border);
    border-radius: 2px;
    color: var(--text-muted);
    transition: all 0.2s;
}

.file-upload:hover label {
    border-color: var(--primary);
    color: var(--primary);
    background: rgba(47, 92, 75, 0.05);
}

select {
    appearance: none;
    background-image: url("data:image/svg+xml;charset=UTF-8,%3csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%239aa0a6' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3e%3cpolyline points='6 9 12 15 18 9'%3e%3c/polyline%3e%3c/svg%3e");
    background-repeat: no-repeat;
    background-position: right 1rem center;
    background-size: 1em;
}

select option {
    background-color: var(--bg-color);
    color: var(--text-main);
}

.settings-section {
    display: flex;
    flex-direction: column;
    gap: 1rem;
    margin-top: 1rem;
}

/* Button */
#generateBtn {
    margin-top: 1rem;
}

.primary-btn {
    background: linear-gradient(135deg, var(--primary), var(--accent));
    color: white;
    border: none;
    padding: 1rem;
    border-radius: 2px;
    font-weight: 600;
    font-size: 1rem;
    cursor: pointer;
    transition: transform 0.2s, box-shadow 0.2s;
    margin-top: auto;
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 0.5rem;
}

.primary-btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 20px rgba(47, 92, 75, 0.4);
}

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

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

/* Loader */
.loader {
    width: 20px;
    height: 20px;
    border: 2px solid rgba(255,255,255,0.3);
    border-radius: 50%;
    border-top-color: white;
    animation: spin 1s ease-in-out infinite;
}

.hidden {
    display: none !important;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

/* Right Panel */
.result-panel {
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.result-header {
    padding: 1.5rem;
    border-bottom: 1px solid var(--panel-border);
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.result-header h2 {
    font-size: 1.25rem;
    font-weight: 600;
}

.icon-btn {
    background: transparent;
    border: 1px solid var(--panel-border);
    color: var(--text-muted);
    border-radius: 2px;
    width: 40px;
    height: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all 0.2s;
}

.icon-btn:hover:not(:disabled) {
    background: rgba(255,255,255,0.1);
    color: var(--text-main);
}

.icon-btn:disabled {
    opacity: 0.3;
    cursor: not-allowed;
}

.result-content {
    flex: 1;
    overflow-y: auto;
    padding: 2rem;
    font-size: 1.05rem;
}

.empty-state {
    height: 100%;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    color: var(--text-muted);
    gap: 1rem;
    opacity: 0.5;
}

/* Markdown Styles */
.markdown-body h1, .markdown-body h2, .markdown-body h3 {
    margin-top: 1.5em;
    margin-bottom: 0.5em;
    color: var(--text-main);
    font-weight: 600;
}

.markdown-body h1 { font-size: 2em; border-bottom: 1px solid var(--panel-border); padding-bottom: 0.3em; }
.markdown-body h2 { font-size: 1.5em; border-bottom: 1px solid var(--panel-border); padding-bottom: 0.3em; }
.markdown-body h3 { font-size: 1.25em; }

.markdown-body h1:first-child, .markdown-body h2:first-child, .markdown-body h3:first-child {
    margin-top: 0;
}
.markdown-body p { margin-bottom: 1em; line-height: 1.6; }
.markdown-body ul, .markdown-body ol { margin-bottom: 1em; padding-left: 2em; }
.markdown-body li { margin-bottom: 0.5em; }
.markdown-body strong { color: var(--strong-color); }

/* Toast */
.toast {
    position: fixed;
    bottom: 2rem;
    right: 2rem;
    background: var(--toast-bg);
    backdrop-filter: blur(10px);
    border-left: 4px solid var(--danger);
    padding: 1rem 1.5rem;
    border-radius: 2px;
    box-shadow: 0 4px 20px rgba(0,0,0,0.15);
    color: var(--text-main);
    z-index: 1000;
    animation: slideIn 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

.toast.success {
    border-left-color: #10b981;
}

@keyframes slideIn {
    from { transform: translateX(100%); opacity: 0; }
    to { transform: translateX(0); opacity: 1; }
}

/* Responsive */
@media (max-width: 900px) {
    .main-content {
        grid-template-columns: 1fr;
    }
    .app-container {
        height: auto;
    }
}


/* Modal Styles */
.modal-overlay { position: fixed; top: 0; left: 0; right: 0; bottom: 0; background: rgba(0,0,0,0.5); display: flex; align-items: center; justify-content: center; z-index: 1000; opacity: 1; transition: opacity 0.3s; }
.modal-overlay.hidden { display: none; opacity: 0; pointer-events: none; }
.modal-content { width: 90%; max-width: 500px; padding: 1.5rem; max-height: 90vh; overflow-y: auto; }
.modal-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 1.5rem; }
.modal-header h2 { font-size: 1.25rem; font-weight: 600; }
.modal-tab-btn { padding: 0.5rem 1rem; border: none; background: none; color: var(--text-muted); cursor: pointer; border-bottom: 2px solid transparent; font-weight: 500; font-size: 0.95rem; transition: all 0.2s; }
.modal-tab-btn.active { color: var(--text-main); border-bottom-color: var(--text-main); }
.modal-body .tabs { display: flex; gap: 1rem; margin-bottom: 1.5rem; padding-bottom: 0.5rem; border-bottom: 1px solid rgba(255,255,255,0.1); }
.modal-tab-pane { display: none; }
.modal-tab-pane.active { display: block; }
.modal-footer { margin-top: 1.5rem; }
.publish-btn { font-size: 0.95rem; font-weight: 500; padding: 0 1.2rem; height: 40px; display: flex; align-items: center; gap: 0.5rem; }
.edit-btn { font-size: 0.95rem; font-weight: 500; padding: 0 1.2rem; height: 40px; display: flex; align-items: center; gap: 0.5rem; border-radius: 2px; cursor: pointer; transition: all 0.2s; }
.w-full { width: 100%; }

/* Editor Styles */
.result-content-wrapper { flex: 1; display: flex; flex-direction: column; overflow: hidden; height: 100%; }
.markdown-editor { flex: 1; width: 100%; height: 100%; background: transparent; border: none; color: var(--text-main); font-family: 'Inter', monospace; font-size: 1.05rem; padding: 2rem; resize: none; line-height: 1.6; }
.markdown-editor:focus { outline: none; border: none; box-shadow: none; background: transparent; }



/* Token & API Settings Styles */
.input-with-button { display: flex; gap: 0.5rem; }
.input-with-button input { flex: 1; }
.secondary-btn { background: var(--surface-light); border: 1px solid rgba(255,255,255,0.1); color: var(--text-primary); border-radius: 2px; padding: 0.5rem 1rem; cursor: pointer; }
.secondary-btn:hover { background: rgba(255,255,255,0.1); }
.metrics-indicator {
    margin-top: 1.5rem;
    padding-top: 1rem;
    border-top: 1px solid var(--panel-border);
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: 1.5rem; /* Increase gap slightly for readability */
    color: var(--text-muted);
    font-size: 0.85rem;
    font-weight: 500;
}

.metric-text {
    opacity: 0.8;
}

.metric-separator {
    opacity: 0.3;
}
.text-success { color: var(--success); }
.text-danger { color: var(--danger); }

/* Progress Bar Styles */
.progress-container {
    width: 100%;
    max-width: 400px;
    margin: 2rem auto;
    text-align: center;
}

.progress-bar-bg {
    width: 100%;
    height: 8px;
    background: rgba(255, 255, 255, 0.1);
    border-radius: 2px;
    overflow: hidden;
    margin-bottom: 1rem;
    position: relative;
}

.progress-fill {
    height: 100%;
    width: 0%;
    background: linear-gradient(90deg, var(--primary), var(--accent));
    border-radius: 2px;
    transition: width 0.3s ease-out;
    box-shadow: 0 0 10px rgba(47, 92, 75, 0.5);
}

.progress-fill.success {
    background: linear-gradient(90deg, #10b981, #34d399);
    box-shadow: 0 0 10px rgba(16, 185, 129, 0.5);
}

.progress-text {
    font-size: 0.95rem;
    color: var(--text-main);
    font-weight: 500;
    margin-bottom: 0.2rem;
}

.progress-percentage {
    font-size: 0.8rem;
    color: var(--text-muted);
}

/* Form Group Styles */
.form-group {
    display: flex;
    flex-direction: column;
    gap: 0.6rem;
    margin-bottom: 1.5rem;
}

.form-group label {
    font-weight: 500;
    color: var(--text-main);
    font-size: 0.95rem;
}

.form-group small {
    color: var(--text-muted);
    font-size: 0.85rem;
    line-height: 1.4;
}

#result_content img, .markdown-body img {
    max-width: 100%;
    max-height: 400px;
    object-fit: contain;
    border-radius: 2px;
    margin: 20px auto;
    display: block;
}

/* Dropdown Menu */
.dropdown {
    position: relative;
    display: inline-block;
}

.dropdown-content {
    display: none;
    position: absolute;
    right: 0;
    background-color: var(--panel-bg);
    min-width: 160px;
    box-shadow: 0px 8px 24px 0px rgba(0,0,0,0.15);
    z-index: 1000;
    border-radius: 2px;
    border: 1px solid var(--panel-border);
    overflow: hidden;
}

.dropdown-content a {
    color: var(--text-main);
    padding: 8px 12px;
    margin: 4px 8px;
    border-radius: 2px;
    text-decoration: none;
    display: block;
    font-size: 0.9rem;
    transition: background 0.2s;
}

.dropdown-content a:hover {
    background-color: var(--surface-light);
}

.secondary-btn { 
    background: var(--surface-light); 
    border: 1px solid var(--panel-border); 
    color: var(--text-main); 
    border-radius: 2px; 
    padding: 0.5rem 1rem; 
    cursor: pointer; 
    transition: background 0.2s;
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
}

.secondary-btn:hover { 
    background: var(--input-bg); 
}

.dropdown:hover .dropdown-content {
    display: block;
}

/* Print Styles */
@media print {
    body, html, .app-container, .main-content, .result-panel {
        height: auto !important;
        overflow: visible !important;
        display: block !important;
        background: transparent !important;
    }
    
    body * {
        visibility: hidden;
    }
    
    .result-content-wrapper, .result-content-wrapper *, .result-content, .result-content * {
        visibility: visible;
        color: black !important;
    }
    
    .result-content-wrapper, .result-content {
        position: relative !important;
        left: 0;
        top: 0;
        width: 100% !important;
        height: auto !important;
        overflow: visible !important;
        margin: 0 !important;
        padding: 0 !important;
        background: transparent !important;
        box-shadow: none !important;
        border: none !important;
        display: block !important;
    }

    #result_editor, .glass-header, .input-panel, .header-actions, .empty-state, .token-indicator, .result-header {
        display: none !important;
    }

    .result-content img, #result-container img {
        max-width: 100% !important;
        max-height: 25cm !important;
        width: auto !important;
        height: auto !important;
        object-fit: contain !important;
        page-break-inside: avoid;
        display: block !important;
        margin: 0 auto !important;
    }

    @page {
        margin: 2cm;
    }
}

/* Custom Native Toolbar */
.custom-toolbar {
    display: flex;
    gap: 0.25rem;
    padding: 0.5rem;
    background-color: var(--surface-light);
    border: 1px solid var(--panel-border);
    border-radius: 2px 2px 0 0;
    align-items: center;
    position: sticky;
    top: 0;
    z-index: 10;
}

.toolbar-btn {
    background: transparent;
    border: 1px solid transparent;
    color: var(--text-main);
    padding: 0.4rem 0.6rem;
    border-radius: 2px;
    cursor: pointer;
    font-size: 0.9rem;
    transition: background 0.2s;
}

.toolbar-btn:hover {
    background: rgba(255, 255, 255, 0.1);
}

.toolbar-separator {
    width: 1px;
    height: 20px;
    background-color: var(--panel-border);
    margin: 0 0.5rem;
}

.markdown-editor {
    border-top: none !important;
    border-radius: 0 0 2px 2px !important;
    height: 65vh; /* Keep fixed height for native smooth scrolling */
    min-height: auto;
}

/* User Profile Dropdown Styles */
.user-profile-menu {
    position: relative;
    display: inline-block;
    z-index: 9999;
}

.profile-btn {
    display: flex;
    align-items: center;
    gap: 8px;
    background: transparent;
    border: 1px solid var(--panel-border);
    padding: 6px 12px 6px 6px;
    border-radius: 30px;
    cursor: pointer;
    transition: all 0.2s ease;
    color: var(--text-main);
}

.profile-btn:hover {
    background: var(--surface-light);
    border-color: var(--primary);
}

.profile-avatar {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    background: linear-gradient(135deg, var(--primary), var(--accent));
    color: #ffffff;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 600;
    font-size: 14px;
}

.profile-avatar.large {
    width: 48px;
    height: 48px;
    font-size: 20px;
}

.profile-dropdown {
    position: absolute;
    top: calc(100% + 10px);
    right: 0;
    width: 260px;
    background: var(--panel-bg);
    backdrop-filter: var(--panel-backdrop);
    -webkit-backdrop-filter: var(--panel-backdrop);
    border-radius: 12px;
    box-shadow: var(--panel-shadow);
    border: 1px solid var(--panel-border);
    opacity: 0;
    visibility: hidden;
    transform: translateY(-10px);
    transition: all 0.2s cubic-bezier(0.175, 0.885, 0.32, 1.275);
    z-index: 9999;
}

.profile-dropdown.show {
    opacity: 1;
    visibility: visible;
    transform: translateY(0);
}

.dropdown-header {
    padding: 20px;
    display: flex;
    align-items: center;
    gap: 12px;
}

.dropdown-email {
    font-weight: 600;
    color: var(--text-main);
    font-size: 14px;
    word-break: break-all;
}

.dropdown-divider {
    height: 1px;
    background-color: var(--panel-border);
    margin: 4px 0;
}

.dropdown-item {
    display: flex;
    align-items: center;
    gap: 12px;
    width: 100%;
    padding: 12px 20px;
    border: none;
    background: transparent;
    color: var(--text-main);
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    text-align: left;
    transition: background 0.2s ease;
}

.dropdown-item:hover {
    background: var(--surface-light);
    color: var(--primary);
}

.dropdown-item svg {
    color: var(--text-muted);
}

.dropdown-item:hover svg {
    color: var(--primary);
}