/* ==========================================
   Cosmologist - Modern Minimalist Styles
   Built on top of PicoCSS
   ========================================== */

/* ==========================================
   CSS Variables Override
   ========================================== */

:root {
    /* Override Pico defaults for our app */
    --pico-font-family: system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, sans-serif;
    --pico-font-family-monospace: 'SF Mono', Monaco, 'Cascadia Code', Consolas, monospace;
    
    /* App-specific colors - Updated to match reference */
    --app-bg: #fafafa;
    --app-surface: #ffffff;
    --app-surface-alt: #f5f5f5;
    --app-border: #e5e5e5;
    --app-border-hover: #d4d4d4;
    --app-text: #171717;
    --app-text-muted: #737373;
    --app-text-subtle: #a3a3a3;
    --app-primary: #171717;
    --app-primary-hover: #404040;
    --app-error: #ef4444;
    --app-error-bg: #fef2f2;
    --app-warning: #f59e0b;
    --app-warning-bg: #fef3c7;
    --app-success: #10b981;
    
    /* Spacing */
    --space-1: 0.25rem;
    --space-2: 0.5rem;
    --space-3: 0.75rem;
    --space-4: 1rem;
    --space-5: 1.5rem;
    --space-6: 2rem;
    --space-8: 3rem;
    
    /* Radius */
    --radius-sm: 0px;
    --radius-md: 0px;
    --radius-lg: 0px;
    
    /* Shadows */
    --shadow-xs: 0 1px 2px rgba(0, 0, 0, 0.03);
    --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.04), 0 1px 2px rgba(0, 0, 0, 0.02);
    --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.04), 0 2px 4px -1px rgba(0, 0, 0, 0.02);
    --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.05), 0 4px 6px -2px rgba(0, 0, 0, 0.03);
}

/* ==========================================
   Base Overrides
   ========================================== */

*, *::before, *::after {
    box-sizing: border-box;
}

html, body {
    height: 100%;
    margin: 0;
    padding: 0;
}

body {
    background-color: var(--app-bg);
    color: var(--app-text);
    overflow: hidden;
}

/* ==========================================
   App Layout
   ========================================== */

.app-container {
    display: flex;
    flex-direction: column;
    height: 100vh;
    max-height: 100vh;
    overflow: hidden;
    box-shadow: 0 0 0 1px var(--app-border);
}

/* ==========================================
   Header
   ========================================== */

.app-header {
    background: var(--app-surface);
    color: var(--app-text);
    padding: var(--space-6) var(--space-5);
    border-bottom: 1px solid var(--app-border);
    flex-shrink: 0;
}

.app-header h1 {
    font-size: 1.875rem;
    font-weight: 400;
    margin: 0 0 var(--space-2) 0;
    letter-spacing: -0.03em;
    color: var(--app-text);
    text-transform: uppercase;
}

.app-header .subtitle {
    font-size: 1rem;
    color: var(--app-text-muted);
    margin: 0;
    font-weight: 400;
}

/* ==========================================
   Footer
   ========================================== */

.app-footer {
    background-color: var(--app-surface);
    color: var(--app-text-subtle);
    padding: var(--space-4) var(--space-5);
    text-align: center;
    font-size: 0.8125rem;
    flex-shrink: 0;
    border-top: 1px solid var(--app-border);
}

.app-footer p {
    margin: 0;
    color: var(--app-text-subtle);
}

/* ==========================================
   Panels Layout
   ========================================== */

.panels-container {
    display: flex;
    flex: 1;
    gap: 0;
    padding: 0;
    overflow: hidden;
    background-color: var(--app-bg);
}

.panel {
    flex: 1;
    display: flex;
    flex-direction: column;
    background-color: var(--app-surface);
    border-radius: 0;
    box-shadow: none;
    overflow: hidden;
    border: none;
    border-right: 1px solid var(--app-border);
    margin-bottom: 0
}

.panel:last-child {
    border-right: none;
}

.panel-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: var(--space-4) var(--space-5);
    background-color: var(--app-surface);
    border-bottom: 1px solid var(--app-border);
    flex-shrink: 0;
}

.panel-header h2 {
    font-size: 0.8125rem;
    font-weight: 500;
    margin: 0;
    color: var(--app-text-muted);
    text-transform: uppercase;
    letter-spacing: 0.1em;
}

.panel-actions {
    display: flex;
    gap: var(--space-2);
    align-items: center;
}

.panel-content {
    flex: 1;
    overflow: auto;
    position: relative;
    background-color: var(--app-surface);
}

/* ==========================================
   Buttons
   ========================================== */

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: var(--space-2);
    padding: var(--space-2) var(--space-3);
    font-size: 0.8125rem;
    font-weight: 500;
    border: none;
    border-radius: 0;
    cursor: pointer;
    transition: all 0.15s ease;
    white-space: nowrap;
    text-decoration: none;
    line-height: 1.4;
}

.btn:focus {
    outline: 2px solid var(--app-primary);
    outline-offset: 2px;
}

.btn-primary {
    background-color: var(--app-primary);
    color: white;
}

.btn-primary:hover {
    background-color: var(--app-primary-hover);
}

.btn-primary:active {
    opacity: 0.9;
}

.btn-secondary {
    background-color: transparent;
    color: var(--app-text-muted);
    border: 1px solid var(--app-border);
}

.btn-secondary:hover {
    background-color: var(--app-surface-alt);
    color: var(--app-text);
    border-color: var(--app-border-hover);
}

.btn-icon {
    width: 16px;
    height: 16px;
    flex-shrink: 0;
}

/* SVG icons inherit color from parent */
.btn-primary .btn-icon {
    filter: brightness(0) invert(1);
}

.btn-secondary .btn-icon {
    opacity: 0.5;
}

.btn-secondary:hover .btn-icon {
    opacity: 1;
}

/* ==========================================
   Upload Area
   ========================================== */

.upload-area {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    height: 100%;
    padding: var(--space-8);
    margin: 0;
    border: none;
    border-radius: 0;
    background-color: var(--app-surface);
    transition: all 0.2s ease;
}

.upload-area.drag-over {
    background-color: var(--app-surface-alt);
}

.upload-icon {
    width: 48px;
    height: 48px;
    margin-bottom: var(--space-5);
    opacity: 0.3;
}

.upload-text {
    font-size: 1rem;
    color: var(--app-text);
    margin-bottom: var(--space-2);
    font-weight: 500;
}

.upload-text-secondary {
    font-size: 0.875rem;
    color: var(--app-text-muted);
    margin-bottom: var(--space-5);
}

.upload-buttons {
    display: flex;
    gap: var(--space-3);
    flex-wrap: wrap;
    justify-content: center;
}

.upload-description {
    width: 100%;
    max-width: 500px;
    margin-bottom: var(--space-8);
    padding: var(--space-5);
    background-color: var(--app-surface);
    border-radius: var(--radius-md);
    border: 1px solid var(--app-border);
    box-shadow: 8px 8px 0 0 rgba(0, 0, 0, 0.15);
}

.upload-description h3 {
    font-size: 1rem;
    font-weight: 500;
    color: var(--app-text);
    margin: 0 0 var(--space-4) 0;
}

.upload-description ol {
    margin: 0;
    padding-left: var(--space-5);
    font-size: 0.875rem;
    color: var(--app-text-muted);
    line-height: 1.7;
}

.upload-description li {
    margin-bottom: var(--space-2);
}

.upload-description li:last-child {
    margin-bottom: 0;
}

/* ==========================================
   Editor Area (UNCHANGED)
   ========================================== */

.editor-area {
    height: 100%;
    padding: var(--space-4);
}

.markdown-input-wrapper {
    position: relative;
    width: 100%;
    height: 100%;
}

.markdown-backdrop {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    padding: var(--space-4);
    font-family: var(--pico-font-family-monospace);
    font-size: 0.875rem;
    line-height: 1.6;
    white-space: pre-wrap;
    word-wrap: break-word;
    overflow: auto;
    border: 1px solid transparent;
    border-radius: var(--radius-md);
    pointer-events: none;
    color: transparent;
    background-color: var(--app-surface);
}

.markdown-backdrop .escape-error {
    color: transparent;
    background-color: var(--app-error-bg);
    border-radius: 2px;
    box-shadow: 0 0 0 1px var(--app-error);
}

#markdown-input {
    position: relative;
    width: 100%;
    height: 100%;
    padding: var(--space-4);
    font-family: var(--pico-font-family-monospace);
    font-size: 0.875rem;
    line-height: 1.6;
    border: 1px solid var(--app-border);
    border-radius: var(--radius-md);
    resize: none;
    outline: none;
    transition: border-color 0.15s ease, box-shadow 0.15s ease;
    background-color: transparent;
    color: var(--app-text);
}

#markdown-input:focus {
    border-color: var(--app-primary);
    box-shadow: 0 0 0 3px rgba(23, 23, 23, 0.05);
}

#markdown-input::placeholder {
    color: var(--app-text-subtle);
}

/* ==========================================
   View Toggle Tabs
   ========================================== */

.view-toggle {
    display: flex;
    background-color: var(--app-surface-alt);
    border-radius: 0;
    padding: 2px;
    gap: 2px;
    border: 1px solid var(--app-border);
}

.tab-btn {
    padding: var(--space-1) var(--space-3);
    font-size: 0.8125rem;
    font-weight: 500;
    border: none;
    background: transparent;
    color: var(--app-text-muted);
    cursor: pointer;
    border-radius: 0;
    transition: all 0.15s ease;
}

.tab-btn.active {
    background-color: var(--app-surface);
    color: var(--app-text);
    box-shadow: var(--shadow-xs);
}

.tab-btn:hover:not(.active) {
    color: var(--app-text);
}

/* ==========================================
   Output Views (UNCHANGED)
   ========================================== */

.output-view {
    height: 100%;
    overflow: auto;
}

.preview-view {
    padding: var(--space-4);
}

.markup-view {
    padding: var(--space-4);
}

.markup-output {
    font-family: var(--pico-font-family-monospace);
    font-size: 0.8125rem;
    line-height: 1.7;
    white-space: pre-wrap;
    word-wrap: break-word;
    background-color: var(--app-surface-alt);
    padding: var(--space-4);
    border-radius: var(--radius-md);
    border: 1px solid var(--app-border);
    margin: 0;
    color: var(--app-text);
}

.placeholder-text {
    color: var(--app-text-subtle);
    font-style: italic;
}

/* ==========================================
   Output Actions
   ========================================== */

.output-actions {
    display: flex;
    gap: var(--space-3);
    padding: var(--space-4) var(--space-5);
    border-top: 1px solid var(--app-border);
    background-color: var(--app-surface);
    justify-content: center;
}

/* ==========================================
   Warning Area
   ========================================== */

.warning-area {
    display: flex;
    align-items: center;
    gap: var(--space-3);
    padding: var(--space-4) var(--space-5);
    background-color: var(--app-warning-bg);
    border-top: 1px solid var(--app-warning);
}

.warning-icon {
    font-size: 1.25rem;
    line-height: 1;
}

.warning-text {
    font-size: 0.8125rem;
    color: var(--app-text);
    margin: 0;
}

/* ==========================================
   Error Highlighting (UNCHANGED)
   ========================================== */

.error-highlight {
    background-color: var(--app-error-bg) !important;
    border-left: 3px solid var(--app-error);
}

/* ==========================================
   Utility Classes
   ========================================== */

.hidden {
    display: none !important;
}

/* ==========================================
   Modal Styles
   ========================================== */

.modal {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 1000;
    display: flex;
    align-items: center;
    justify-content: center;
}

.modal.hidden {
    display: none;
}

.modal-overlay {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.4);
    backdrop-filter: blur(4px);
}

.modal-container {
    position: relative;
    background: var(--app-surface);
    border-radius: var(--radius-lg);
    box-shadow: 12px 12px 0 0 rgba(0, 0, 0, 0.15);
    border: 1px solid var(--app-border);
    width: 90%;
    max-width: 700px;
    max-height: 85vh;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: var(--space-5) var(--space-5);
    border-bottom: 1px solid var(--app-border);
    flex-shrink: 0;
}

.modal-header h2 {
    margin: 0;
    font-size: 1.125rem;
    font-weight: 500;
    color: var(--app-text);
}

.modal-close {
    background: none;
    border: none;
    font-size: 1.5rem;
    line-height: 1;
    color: var(--app-text-muted);
    cursor: pointer;
    padding: var(--space-1) var(--space-2);
    border-radius: 0;
    transition: all 0.15s ease;
}

.modal-close:hover {
    background: var(--app-surface-alt);
    color: var(--app-text);
}

.modal-content {
    padding: var(--space-5);
    overflow-y: auto;
    flex: 1;
}

.modal-content h1 {
    display: none; /* Hide the first h1 since it's in the header */
}

.modal-content h2 {
    font-size: 1.125rem;
    font-weight: 500;
    margin: var(--space-5) 0 var(--space-3) 0;
    padding-bottom: var(--space-2);
    border-bottom: 1px solid var(--app-border);
    color: var(--app-text);
}

.modal-content h2:first-of-type {
    margin-top: 0;
}

.modal-content h3 {
    font-size: 0.9375rem;
    font-weight: 500;
    margin: var(--space-4) 0 var(--space-2) 0;
    color: var(--app-text);
}

.modal-content p {
    margin: 0 0 var(--space-3) 0;
    line-height: 1.6;
    color: var(--app-text);
}

.modal-content code {
    background: var(--app-surface-alt);
    padding: 0.125rem 0.375rem;
    border-radius: var(--radius-sm);
    font-size: 0.8125rem;
    font-family: var(--pico-font-family-monospace);
}

.modal-content pre {
    background: var(--app-surface-alt);
    padding: var(--space-3);
    border-radius: var(--radius-md);
    overflow-x: auto;
    margin: var(--space-2) 0 var(--space-3) 0;
    border: 1px solid var(--app-border);
}

.modal-content pre code {
    background: none;
    padding: 0;
    font-size: 0.8125rem;
}

.modal-content strong {
    font-weight: 600;
    color: var(--app-text);
}

.modal-content ul,
.modal-content ol {
    margin: 0 0 var(--space-3) 0;
    padding-left: var(--space-5);
}

.modal-content li {
    margin-bottom: var(--space-1);
    line-height: 1.5;
}

/* ==========================================
   Responsive Design
   ========================================== */

@media (max-width: 768px) {
    .panels-container {
        flex-direction: column;
        padding: 0;
        gap: 0;
    }
    
    .panel {
        min-height: 40vh;
        border-right: none;
        border-bottom: 1px solid var(--app-border);
    }
    
    .panel:last-child {
        border-bottom: none;
    }
    
    .panel-header {
        flex-wrap: wrap;
        gap: var(--space-2);
        padding: var(--space-3) var(--space-4);
    }
    
    .panel-header h2 {
        font-size: 0.75rem;
    }
    
    .panel-actions {
        width: 100%;
        justify-content: flex-end;
    }
    
    .upload-buttons {
        flex-direction: column;
        width: 100%;
    }
    
    .upload-buttons .btn {
        width: 100%;
    }
    
    .app-header {
        padding: var(--space-4) var(--space-4);
    }
    
    .app-header h1 {
        font-size: 1.5rem;
    }
}

/* ==========================================
   Scrollbar Styling
   ========================================== */

::-webkit-scrollbar {
    width: 8px;
    height: 8px;
}

::-webkit-scrollbar-track {
    background: transparent;
}

::-webkit-scrollbar-thumb {
    background: var(--app-border);
    border-radius: 4px;
}

::-webkit-scrollbar-thumb:hover {
    background: var(--app-text-subtle);
}

/* Firefox scrollbar */
* {
    scrollbar-width: thin;
    scrollbar-color: var(--app-border) transparent;
}