/* Brailk - Minimal */

:root {
    --bg: #f5f5f5;
    --panel: #ffffff;
    --input: #fafafa;
    --border: #e0e0e0;
    --border-strong: #d0d0d0;
    --text: #1a1a1a;
    --text-secondary: #666666;
    --text-muted: #999999;
    --primary: #333333;
    --primary-hover: #000000;
    --radius: 6px;
    --font-sans:
        -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    --font-mono: "SF Mono", Monaco, "Cascadia Code", monospace;
}

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

html,
body {
    height: 100vh;
    overflow: hidden;
}

body {
    font-family: var(--font-sans);
    font-size: 14px;
    line-height: 1.5;
    color: var(--text);
    background-color: #F7F7F5;
    /* Editorial grid pattern */
    background-image: linear-gradient(#E5E5E5 1px, transparent 1px),
                      linear-gradient(90deg, #E5E5E5 1px, transparent 1px);
    background-size: 40px 40px;
}

.page {
    height: 100vh;
    display: flex;
    flex-direction: column;
    padding: 20px;
}

/* Main */
.main {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 20px;
    max-width: 1400px;
    margin: 0 auto;
    width: 100%;
}

/* Hero */
.hero {
    text-align: center;
    flex-shrink: 0;
}

.hero h1 {
    font-size: 24px;
    font-weight: 600;
    margin-bottom: 4px;
}

.hero-description {
    font-size: 14px;
    color: var(--text-secondary);
}

/* Converter */
.converter {
    background: var(--panel);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 20px;
    flex: 1;
    display: flex;
    flex-direction: column;
    min-height: 0;
}

.converter-layout {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 20px;
    flex: 1;
    min-height: 0;
}

@media (max-width: 900px) {
    .converter-layout {
        grid-template-columns: 1fr;
    }
}

/* Mobile optimizations */
@media (max-width: 768px) {
    .page {
        padding: 10px;
        overflow-y: auto;
        height: auto;
        min-height: 100vh;
    }

    .main {
        gap: 12px;
    }

    .hero h1 {
        font-size: 20px;
    }

    .converter {
        padding: 12px;
        flex: none;
        min-height: auto;
    }

    .converter-layout {
        display: flex;
        flex-direction: column;
        gap: 16px;
    }

    .input-panel,
    .output-panel {
        min-height: 250px;
    }

    .input-area {
        min-height: 150px;
    }

    .render-view {
        min-height: 150px;
        padding: 12px;
    }

    .panel-actions {
        gap: 8px;
    }

    .btn-icon {
        width: 36px;
        height: 36px;
    }

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

    .btn-primary {
        padding: 14px 24px;
        font-size: 14px;
        min-width: 160px;
    }

    .actions {
        padding-top: 12px;
    }

    .footer {
        padding: 16px 10px;
        font-size: 11px;
    }

    /* Touch-friendly improvements */
    button,
    .btn-icon,
    .btn-primary {
        min-height: 44px;
        min-width: 44px;
    }

    textarea {
        font-size: 16px; /* Prevents zoom on iOS */
    }

    /* Hide Typst tab on mobile by default - too cramped */
    .tab[data-tab="typst"] {
        display: none;
    }

    .tab[data-tab="rendered"] {
        width: 100%;
        text-align: center;
    }
}

/* Small mobile screens */
@media (max-width: 480px) {
    .hero h1 {
        font-size: 18px;
    }

    .input-panel,
    .output-panel {
        min-height: 200px;
    }

    .panel-header {
        flex-wrap: wrap;
        gap: 8px;
    }

    .input-area {
        min-height: 120px;
    }
}

/* Panels */
.input-panel,
.output-panel {
    display: flex;
    flex-direction: column;
    min-height: 0;
}

.panel-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 8px;
    flex-shrink: 0;
}

.panel-label {
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: var(--text-muted);
}

.panel-actions {
    display: flex;
    gap: 4px;
}

/* Icon Buttons */
.btn-icon {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 28px;
    height: 28px;
    background: transparent;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    color: var(--text-secondary);
    cursor: pointer;
    transition: all 0.15s;
}

.btn-icon:hover {
    border-color: var(--border-strong);
    color: var(--text);
    background: var(--bg);
}

.btn-icon svg {
    width: 14px;
    height: 14px;
}

/* Textarea */
.input-area {
    width: 100%;
    flex: 1;
    min-height: 0;
    padding: 12px;
    background: var(--input);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    color: var(--text);
    font-family: var(--font-mono);
    font-size: 13px;
    line-height: 1.6;
    resize: none;
    transition: border-color 0.15s;
}

.input-area:focus {
    outline: none;
    border-color: var(--text-secondary);
}

.input-area::placeholder {
    color: var(--text-muted);
}

/* Tabs */
.tabs {
    display: flex;
    gap: 2px;
}

.tab {
    padding: 4px 12px;
    background: transparent;
    border: none;
    border-radius: var(--radius);
    color: var(--text-secondary);
    font-size: 12px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.15s;
}

.tab:hover {
    color: var(--text);
    background: var(--bg);
}

.tab.active {
    background: var(--input);
    color: var(--text);
}

/* Output Content */
.output-content {
    flex: 1;
    min-height: 0;
    position: relative;
}

.tab-panel {
    display: none;
    height: 100%;
}

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

/* Render View */
.render-view {
    height: 100%;
    background: white;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: auto;
    padding: 20px;
}

.render-view img,
.render-view svg {
    max-width: 100%;
    height: auto;
}

.empty {
    text-align: center;
    color: var(--text-muted);
}

.empty p {
    font-size: 13px;
}

/* Code View */
.code-view {
    height: 100%;
    margin: 0;
    padding: 12px;
    background: var(--input);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    overflow: auto;
    font-family: var(--font-mono);
    font-size: 12px;
    line-height: 1.6;
}

/*.code-view code {
    color: var(--text);
}*/

.code-view code.placeholder {
    color: var(--text-muted);
}

/* Rendered Content */
.rendered-content {
    width: 100%;
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: auto;
}

.svg-container {
    width: 100%;
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: auto;
}

.svg-container svg {
    width: auto;
    height: auto;
    min-width: 200px;
    min-height: 100px;
    max-width: 100%;
    max-height: 100%;
}

/* Actions */
.actions {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
    padding-top: 16px;
    flex-shrink: 0;
}

.btn-primary {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 10px 32px;
    background: var(--primary);
    border: 1px solid var(--primary);
    border-radius: var(--radius);
    color: white;
    font-size: 13px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.15s;
    min-width: 140px;
}

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

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

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

.btn-primary > svg {
    width: 16px;
    height: 16px;
}

.btn-loader {
    display: flex;
    align-items: center;
    gap: 8px;
}

.spinner {
    animation: spin 1s linear infinite;
}

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

/* Status */
.status {
    font-size: 12px;
    color: var(--text-secondary);
    min-height: 18px;
}

.status.success {
    color: #16a34a;
}

.status.error {
    color: #dc2626;
}

/* Toast */
.toast {
    position: fixed;
    bottom: 30px;
    left: 50%;
    transform: translateX(-50%) translateY(100px);
    background: var(--text);
    color: white;
    padding: 16px 28px;
    border-radius: var(--radius);
    font-size: 16px;
    font-weight: 500;
    opacity: 0;
    transition: all 0.3s;
    z-index: 1000;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
    min-width: 200px;
    text-align: center;
}

.toast.show {
    transform: translateX(-50%) translateY(0);
    opacity: 1;
}

/* Error Container */
.error-container {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    text-align: center;
    padding: 32px 24px;
    height: 100%;
    background: linear-gradient(135deg, #fef2f2 0%, #fff5f5 100%);
    border-radius: var(--radius);
    border: 1px solid #fecaca;
}

.error-icon {
    width: 56px;
    height: 56px;
    border-radius: 50%;
    background: #fecaca;
    color: #dc2626;
    display: flex;
    align-items: center;
    justify-content: center;
    margin-bottom: 16px;
    animation: error-pop 0.3s ease-out;
}

@keyframes error-pop {
    0% {
        transform: scale(0);
        opacity: 0;
    }
    50% {
        transform: scale(1.1);
    }
    100% {
        transform: scale(1);
        opacity: 1;
    }
}

.error-content {
    max-width: 90%;
}

.error-title {
    font-weight: 600;
    font-size: 18px;
    color: #991b1b;
    margin: 0 0 8px 0;
}

.error-message {
    font-size: 14px;
    color: #7f1d1d;
    margin: 0 0 12px 0;
    line-height: 1.5;
}

.error-suggestion {
    font-size: 13px;
    color: #92400e;
    background: #fef3c7;
    padding: 12px 16px;
    border-radius: var(--radius);
    margin: 0;
}

.error-details {
    margin-top: 20px;
    width: 100%;
    max-width: 400px;
    font-size: 12px;
    color: var(--text-secondary);
    text-align: left;
}

.error-details summary {
    cursor: pointer;
    padding: 8px 12px;
    background: var(--bg);
    border-radius: var(--radius);
    user-select: none;
}

.error-details summary:hover {
    background: var(--input);
}

.error-details pre {
    margin-top: 8px;
    padding: 12px;
    background: var(--input);
    border-radius: var(--radius);
    overflow-x: auto;
    font-family: var(--font-mono);
    font-size: 11px;
    white-space: pre-wrap;
    word-break: break-all;
    max-height: 150px;
    overflow-y: auto;
}

/* Loading State */
.loading-state {
    flex-direction: column;
    gap: 12px;
}

.loading-state .spinner {
    width: 32px;
    height: 32px;
    border: 3px solid var(--border);
    border-top-color: var(--text);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

.loading-state p {
    color: var(--text-secondary);
    font-size: 14px;
}

/* Input Validation States */
.input-area.input-error {
    border-color: #dc2626;
    background-color: #fef2f2;
}

.input-area.input-warning {
    border-color: #f59e0b;
    background-color: #fffbeb;
}

.input-area.input-error:focus {
    border-color: #dc2626;
    box-shadow: 0 0 0 3px rgba(220, 38, 38, 0.1);
}

.input-area.input-warning:focus {
    border-color: #f59e0b;
    box-shadow: 0 0 0 3px rgba(245, 158, 11, 0.1);
}

/* Image Actions */
.image-actions {
    position: absolute;
    top: 12px;
    right: 12px;
    display: flex;
    gap: 8px;
    opacity: 0;
    transition: opacity 0.2s;
}

.rendered-content:hover .image-actions {
    opacity: 1;
}

.image-actions .btn-icon {
    background: var(--panel);
    border-color: var(--border-strong);
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 0 12px;
    width: auto;
    font-size: 12px;
    font-weight: 500;
}

.image-actions .btn-icon:hover {
    background: var(--bg);
    border-color: var(--text-secondary);
}

/* Rendered content positioning for image actions */
.rendered-content {
    position: relative;
    width: 100%;
    height: 100%;
}

/* Focus */
:focus {
    outline: 2px solid var(--text-secondary);
    outline-offset: 2px;
}

button:focus,
a:focus {
    outline: 2px solid var(--text-secondary);
    outline-offset: 2px;
}

/* Scrollbar */
::-webkit-scrollbar {
    width: 6px;
    height: 6px;
}

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

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

::-webkit-scrollbar-thumb:hover {
    background: var(--border-strong);
}

/* Footer */
.footer {
    text-align: center;
    padding: 12px 20px;
    font-size: 12px;
    color: var(--text-muted);
    flex-shrink: 0;
}

.footer a {
    color: var(--text-secondary);
    text-decoration: none;
    transition: color 0.15s;
}

.footer a:hover {
    color: var(--text);
    text-decoration: underline;
}
