/* Base Variables & Theme */
:root {
    --bg-color: #0d1117;
    --bg-color-secondary: rgba(22, 27, 34, 0.6);
    --text-primary: #e6edf3;
    --text-secondary: #848d97;
    --border-color: rgba(48, 54, 61, 0.8);
    --primary-color: #58a6ff;
    --primary-hover: #3182ce;
    --danger-color: #f85149;
    --success-color: #2ea043;
    --success-bg: rgba(46, 160, 67, 0.15);

    --glass-bg: rgba(22, 27, 34, 0.7);
    --glass-border: rgba(255, 255, 255, 0.1);
    --glass-shadow: 0 8px 32px 0 rgba(0, 0, 0, 0.37);

    --radius-sm: 6px;
    --radius-md: 12px;
    --radius-lg: 16px;

    --transition: all 0.2s ease-in-out;
    --font-sans: 'Inter', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

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

body {
    background-color: var(--bg-color);
    color: var(--text-primary);
    font-family: var(--font-sans);
    line-height: 1.6;
    min-height: 100vh;
    display: flex;
    justify-content: center;
    background-image:
        radial-gradient(circle at 15% 50%, rgba(88, 166, 255, 0.08), transparent 25%),
        radial-gradient(circle at 85% 30%, rgba(163, 113, 247, 0.08), transparent 25%);
}

.hidden {
    display: none !important;
}

/* Glassmorphism Classes */
.glass-panel {
    background: var(--glass-bg);
    backdrop-filter: blur(16px);
    -webkit-backdrop-filter: blur(16px);
    border: 1px solid var(--glass-border);
    box-shadow: var(--glass-shadow);
}

/* Layout */
.app-container {
    width: 100%;
    max-width: 1400px;
    padding: 24px;
    display: flex;
    flex-direction: column;
    gap: 24px;
    height: 100vh;
}

header {
    border-radius: var(--radius-lg);
    padding: 20px 32px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-shrink: 0;
}

.header-left {
    display: flex;
    align-items: center;
    gap: 16px;
}

.logo-icon {
    width: 32px;
    height: 32px;
    color: var(--primary-color);
}

h1 {
    font-size: 1.5rem;
    font-weight: 600;
    margin-bottom: 2px;
}

.subtitle {
    color: var(--text-secondary);
    font-size: 0.875rem;
}

.main-content {
    display: flex;
    gap: 24px;
    flex: 1;
    min-height: 0;
    /* needed for flex-child scrolling to work */
}

.panel {
    flex: 1;
    border-radius: var(--radius-lg);
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.panel-header {
    padding: 20px 24px 16px;
    border-bottom: 1px solid var(--border-color);
}

.panel-header h2 {
    font-size: 1.125rem;
    font-weight: 600;
}

.flex-between {
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.input-panel {
    padding-bottom: 24px;
}

.form-group {
    padding: 20px 24px 0;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.flex-fill {
    flex: 1;
    display: flex;
    min-height: 0;
}

.form-group label {
    font-size: 0.875rem;
    font-weight: 500;
    color: var(--text-secondary);
    display: flex;
    align-items: center;
    gap: 6px;
}

.tooltip-icon {
    display: inline-flex;
    color: var(--text-secondary);
    cursor: help;
}

.tooltip-icon i {
    width: 14px;
    height: 14px;
}

textarea {
    flex: 1;
    width: 100%;
    background-color: rgba(13, 17, 23, 0.8);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    padding: 16px;
    color: var(--text-primary);
    font-family: 'SFMono-Regular', Consolas, 'Liberation Mono', Menlo, Courier, monospace;
    font-size: 0.875rem;
    resize: none;
    transition: var(--transition);
}

textarea:focus,
input:focus,
select:focus {
    outline: none;
    border-color: var(--primary-color);
    box-shadow: 0 0 0 3px rgba(88, 166, 255, 0.2);
}

.panel-actions {
    padding: 20px 24px 0;
}

/* Tabs */
.tabs {
    display: flex;
    border-bottom: 1px solid var(--border-color);
    padding: 0 16px;
}

.tab-btn {
    background: none;
    border: none;
    color: var(--text-secondary);
    padding: 12px 16px;
    font-size: 0.875rem;
    font-weight: 500;
    cursor: pointer;
    border-bottom: 2px solid transparent;
    transition: var(--transition);
}

.tab-btn:hover {
    color: var(--text-primary);
}

.tab-btn.active {
    color: var(--primary-color);
    border-bottom-color: var(--primary-color);
}

.tab-content-container {
    flex: 1;
    overflow: hidden;
    display: flex;
    flex-direction: column;
}

.tab-pane {
    display: none;
    flex: 1;
    height: 100%;
    overflow: auto;
}

.tab-pane.active {
    display: flex;
    /* Preview empty state needs flex */
}

/* Right Panel Content */
#previewTab {
    padding: 24px;
    flex-direction: column;
}

#markdownOutput {
    height: 100%;
    border-radius: 0;
    border: none;
    background: transparent;
}

#markdownOutput:focus {
    box-shadow: none;
}

.empty-state {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    color: var(--text-secondary);
    gap: 16px;
}

.empty-state i {
    width: 48px;
    height: 48px;
    opacity: 0.5;
}

/* Buttons */
.btn {
    border: none;
    background: transparent;
    cursor: pointer;
    font-family: inherit;
    font-size: 0.875rem;
    border-radius: var(--radius-sm);
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    transition: var(--transition);
}

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

.btn-secondary {
    background-color: var(--bg-color-secondary);
    border: 1px solid var(--border-color);
    color: var(--text-primary);
    padding: 8px 16px;
}

.btn-secondary:hover:not(:disabled) {
    background-color: rgba(48, 54, 61, 0.4);
}

.btn-primary {
    background-color: var(--primary-color);
    color: #fff;
    padding: 10px 20px;
    font-weight: 500;
}

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

.btn-large {
    padding: 14px 24px;
    font-size: 1rem;
    font-weight: 600;
}

.btn-icon {
    width: 36px;
    height: 36px;
    border-radius: var(--radius-sm);
    color: var(--text-secondary);
}

.btn-icon:hover:not(:disabled) {
    background-color: var(--bg-color-secondary);
    color: var(--text-primary);
}

.btn-icon i {
    width: 18px;
    height: 18px;
}

.w-full {
    width: 100%;
}

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

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

/* Modal */
.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.6);
    backdrop-filter: blur(4px);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    opacity: 1;
    transition: opacity 0.2s;
}

.modal-overlay.hidden {
    opacity: 0;
    pointer-events: none;
}

.modal {
    width: 100%;
    max-width: 500px;
    border-radius: var(--radius-lg);
    display: flex;
    flex-direction: column;
    transform: translateY(0);
    transition: transform 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

.modal-overlay.hidden .modal {
    transform: translateY(20px);
}

.modal-header {
    padding: 20px 24px;
    border-bottom: 1px solid var(--border-color);
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.modal-header h2 {
    font-size: 1.25rem;
}

.modal-body {
    padding: 8px 0 24px;
}

.modal-footer {
    padding: 16px 24px;
    border-top: 1px solid var(--border-color);
    display: flex;
    justify-content: flex-end;
}

/* Forms in Modal */
.input-with-icon {
    position: relative;
    display: flex;
    align-items: center;
}

.input-with-icon i {
    position: absolute;
    left: 12px;
    width: 16px;
    height: 16px;
    color: var(--text-secondary);
}

.input-with-icon input {
    width: 100%;
    background-color: rgba(13, 17, 23, 0.8);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    padding: 10px 12px 10px 36px;
    color: var(--text-primary);
    font-size: 0.875rem;
    transition: var(--transition);
}

.select-wrapper {
    position: relative;
    display: flex;
    align-items: center;
}

.select-wrapper select {
    width: 100%;
    background-color: rgba(13, 17, 23, 0.8);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    padding: 10px 36px 10px 12px;
    color: var(--text-primary);
    font-size: 0.875rem;
    appearance: none;
    cursor: pointer;
    transition: var(--transition);
}

.select-wrapper select option {
    background-color: var(--bg-color);
}

.select-wrapper i {
    position: absolute;
    right: 12px;
    width: 16px;
    height: 16px;
    color: var(--text-secondary);
    pointer-events: none;
}

.modal-body textarea {
    height: 100px;
}

.required {
    color: var(--danger-color);
}

.alert-group {
    padding-top: 24px;
}

.api-notice {
    background-color: var(--success-bg);
    border: 1px solid rgba(46, 160, 67, 0.3);
    color: var(--text-primary);
    padding: 12px 16px;
    border-radius: var(--radius-md);
    font-size: 0.85rem;
    display: flex;
    gap: 12px;
    align-items: flex-start;
}

.api-notice i {
    width: 18px;
    height: 18px;
    color: var(--success-color);
    flex-shrink: 0;
    margin-top: 2px;
}

/* Toast */
.toast {
    position: fixed;
    bottom: 24px;
    right: 24px;
    background-color: var(--glass-bg);
    border: 1px solid var(--border-color);
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    color: var(--text-primary);
    padding: 12px 20px;
    border-radius: var(--radius-md);
    display: flex;
    align-items: center;
    gap: 12px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.5);
    transform: translateY(0);
    opacity: 1;
    transition: all 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
    z-index: 2000;
}

.toast.hidden {
    transform: translateY(20px);
    opacity: 0;
    pointer-events: none;
}

.toast.error .toast-icon {
    color: var(--danger-color);
}

.toast.success .toast-icon {
    color: var(--success-color);
}

/* Markdown Styles (Github style approximate) */
.markdown-body {
    color: var(--text-primary);
    font-size: 15px;
}

.markdown-body h1,
.markdown-body h2 {
    border-bottom: 1px solid var(--border-color);
    padding-bottom: 0.3em;
    margin-top: 24px;
    margin-bottom: 16px;
    font-weight: 600;
}

.markdown-body h1 {
    font-size: 2em;
}

.markdown-body h2 {
    font-size: 1.5em;
}

.markdown-body h3 {
    font-size: 1.25em;
    margin-top: 24px;
    margin-bottom: 16px;
    font-weight: 600;
}

.markdown-body ul,
.markdown-body ol {
    margin-bottom: 16px;
    padding-left: 2em;
}

.markdown-body li {
    margin-bottom: 4px;
}

.markdown-body p {
    margin-bottom: 16px;
}

.markdown-body code {
    background-color: rgba(110, 118, 129, 0.2);
    padding: 0.2em 0.4em;
    border-radius: 6px;
    font-family: ui-monospace, SFMono-Regular, SF Mono, Menlo, Consolas, Liberation Mono, monospace;
    font-size: 85%;
}

/* Responsive */
@media (max-width: 800px) {
    .main-content {
        flex-direction: column;
    }

    .panel {
        flex: none;
        height: 50vh;
    }

    .app-container {
        height: auto;
    }
}