/* ============================================
   MAIN.CSS - Layout, Variáveis, Header, Geral
   ============================================ */

:root {
    --primary: #1a1a1a;
    --accent: #2d5a27;
    --accent-hover: #1e3d1a;
    --bg-workspace: #eef2f5;
    --border: #d1d9e0;
    --bg-header: #ffffff;
    --bg-toolbar: #f8f9fa;
    --text-muted: #6c757d;
    --shadow-sm: 0 2px 10px rgba(0,0,0,0.03);
    --shadow-md: 0 5px 15px rgba(0,0,0,0.1);
    --shadow-lg: 0 15px 40px rgba(0,0,0,0.12);
    --radius-sm: 4px;
    --radius-md: 6px;
    --radius-lg: 10px;
    --transition: 0.2s ease;
}

* { box-sizing: border-box; }

body {
    margin: 0; padding: 0;
    font-family: 'Inter', sans-serif;
    background-color: var(--bg-workspace);
    height: 100vh;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

/* ===== HEADER ===== */
header {
    background: var(--bg-header);
    min-height: 64px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 1.5rem;
    border-bottom: 1px solid var(--border);
    box-shadow: var(--shadow-sm);
    z-index: 20;
    flex-wrap: wrap;
    gap: 10px;
}

.brand {
    font-weight: 800;
    font-size: 1.3rem;
    letter-spacing: -0.5px;
    display: flex;
    align-items: center;
    gap: 10px;
    font-family: 'Playfair Display', serif;
    flex: 0 0 auto;
    cursor: default;
}

.brand span { color: var(--accent); font-style: italic; }
.brand .fa-crown { color: #d4af37; }

.config-area {
    display: flex;
    align-items: center;
    gap: 15px;
    flex: 1;
    justify-content: center;
    flex-wrap: wrap;
}

.checkbox-wrapper {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 0.85rem;
    color: #444;
    cursor: pointer;
    user-select: none;
    background: var(--bg-toolbar);
    padding: 5px 12px;
    border-radius: var(--radius-sm);
    border: 1px solid var(--border);
    transition: background var(--transition);
}

.checkbox-wrapper:hover { background: #e9ecef; }
.checkbox-wrapper input { cursor: pointer; accent-color: var(--accent); }

.theme-control-group {
    display: flex;
    align-items: center;
    gap: 6px;
    background: var(--bg-toolbar);
    padding: 4px 8px;
    border-radius: var(--radius-md);
    border: 1px solid var(--border);
}

.color-picker-wrap {
    display: flex;
    align-items: center;
    gap: 3px;
    cursor: pointer;
    padding: 2px 4px;
    border-radius: var(--radius-sm);
    border: 1px solid transparent;
    transition: border var(--transition);
}
.color-picker-wrap:hover {
    border-color: var(--border);
}
#accent-color-picker {
    width: 20px;
    height: 20px;
    border: none;
    padding: 0;
    cursor: pointer;
    background: none;
    border-radius: 3px;
}

.nav-btn {
    background: white;
    border: 1px solid var(--border);
    width: 28px;
    height: 28px;
    border-radius: var(--radius-sm);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    color: #555;
    transition: all var(--transition);
    font-size: 0.75rem;
}

.nav-btn:hover {
    background: var(--accent);
    color: white;
    border-color: var(--accent);
}

#theme-selector {
    padding: 4px 6px;
    border-radius: var(--radius-sm);
    border: 1px solid var(--border);
    font-weight: 500;
    background: white;
    min-width: 200px;
    cursor: pointer;
    font-family: 'Inter', sans-serif;
    font-size: 0.85rem;
}

.export-group {
    display: flex;
    gap: 8px;
}

.btn-export {
    background: var(--primary);
    color: white;
    border: none;
    padding: 8px 20px;
    border-radius: var(--radius-md);
    font-weight: 600;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 8px;
    transition: all var(--transition);
    box-shadow: 0 3px 6px rgba(0,0,0,0.1);
    font-family: 'Montserrat', sans-serif;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    font-size: 0.8rem;
    height: 36px;
}

.btn-export:hover { background: #000; transform: translateY(-1px); }
.btn-export:active { transform: translateY(0); }
.btn-export.pdf { background: #c0392b; }
.btn-export.pdf:hover { background: #a93226; }
.btn-export:disabled { opacity: 0.6; cursor: not-allowed; transform: none; }

/* ===== MAIN LAYOUT ===== */
main {
    display: flex;
    flex: 1;
    height: calc(100vh - 64px - 28px - 28px);
}

/* ===== FOOTER ===== */
.app-footer {
    background: var(--bg-header);
    border-top: 1px solid var(--border);
    padding: 4px 15px;
    font-size: 0.75rem;
    text-align: center;
    color: var(--text-muted);
    flex: 0 0 auto;
    height: 28px;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
}
.app-footer a {
    color: var(--text-muted);
    text-decoration: none;
    display: inline-flex;
    align-items: center;
    gap: 5px;
    transition: color var(--transition);
}
.app-footer a:hover {
    color: var(--accent);
    text-decoration: underline;
}
.footer-sep {
    color: #ccc;
    font-size: 0.65rem;
}
.footer-pix {
    color: var(--text-muted);
}
.footer-pix:hover {
    color: #1e4d3a;
}

.hidden { display: none !important; }

/* ===== TOAST ===== */
.toast-container {
    position: fixed;
    bottom: 30px;
    left: 50%;
    transform: translateX(-50%);
    z-index: 1000;
    display: flex;
    flex-direction: column-reverse;
    gap: 8px;
}

.toast {
    background: #333;
    color: white;
    padding: 10px 20px;
    border-radius: 50px;
    box-shadow: 0 5px 15px rgba(0,0,0,0.2);
    font-size: 0.85rem;
    animation: toastIn 0.3s ease;
    display: flex;
    align-items: center;
    gap: 8px;
    white-space: nowrap;
}

.toast.success { background: #27ae60; }
.toast.error { background: #c0392b; }
.toast.info { background: #3498db; }

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

/* ===== SCROLLBAR ===== */
::-webkit-scrollbar { width: 8px; height: 8px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: #ccc; border-radius: 4px; }
::-webkit-scrollbar-thumb:hover { background: #aaa; }

/* ===== STATUS BAR ===== */
.status-bar {
    background: var(--bg-header);
    border-top: 1px solid var(--border);
    padding: 4px 15px;
    font-size: 0.75rem;
    color: var(--text-muted);
    display: flex;
    justify-content: space-between;
    align-items: center;
    height: 28px;
    flex: 0 0 auto;
}

.status-bar .stats { display: flex; gap: 15px; }
.status-bar .stats span { display: flex; align-items: center; gap: 4px; }
.status-bar .save-status { color: var(--accent); }

/* Auto-save toggle */
.autosave-toggle {
    background: none;
    border: 1px solid var(--border);
    color: var(--text-muted);
    font-size: 0.7rem;
    padding: 2px 8px;
    border-radius: 4px;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    gap: 4px;
    font-family: 'Inter', sans-serif;
    transition: all var(--transition);
}
.autosave-toggle:hover { background: #f0f0f0; }
.autosave-toggle.on { color: var(--accent); border-color: var(--accent); }
.autosave-toggle.off { color: #999; border-color: #ccc; }

/* ===== SPLIT RESIZE ===== */
.resize-handle {
    width: 4px;
    background: var(--border);
    cursor: col-resize;
    transition: background var(--transition);
    flex: 0 0 4px;
}

.resize-handle:hover { background: var(--accent); }

/* ============================================
   MOBILE / RESPONSIVO
   ============================================ */

.mobile-tabs {
    display: none;
}

/* Tablets e abaixo — compactação geral */
@media (max-width: 1024px) {
    .checkbox-wrapper { font-size: 0.78rem; padding: 4px 10px; }
    #theme-selector { min-width: 140px; font-size: 0.78rem; }
    .export-group { gap: 4px; }
    .btn-export { padding: 6px 12px; font-size: 0.72rem; height: 32px; }
    .brand { font-size: 1.1rem; }
    header { padding: 0 0.8rem; gap: 6px; min-height: 54px; }
    .config-area { gap: 8px; }
}

/* Smartphones grandes / tablets pequenos — layout empilhado */
@media (max-width: 768px) {
    header {
        min-height: 44px;
        padding: 0 0.5rem;
        gap: 4px;
        flex-wrap: nowrap;
    }
    .brand { font-size: 0.85rem; gap: 4px; }
    .brand .brand-text { display: none !important; }
    .brand .fa-crown { font-size: 0.8rem; }

    .config-area {
        gap: 4px; flex: 1; justify-content: flex-start;
        flex-wrap: nowrap; overflow-x: auto;
        -webkit-overflow-scrolling: touch; scrollbar-width: none;
        padding: 2px 0;
    }
    .config-area::-webkit-scrollbar { display: none; }
    .checkbox-wrapper {
        font-size: 0.7rem; padding: 3px 8px; gap: 4px;
        white-space: nowrap; flex-shrink: 0;
    }
    .checkbox-wrapper input { width: 12px; height: 12px; }
    .theme-control-group { padding: 2px 4px; gap: 3px; flex-shrink: 0; }
    .nav-btn { width: 24px; height: 24px; font-size: 0.65rem; }
    #theme-selector { min-width: 110px; font-size: 0.7rem; padding: 2px 4px; }
    .color-picker-wrap { padding: 1px 2px; }
    #accent-color-picker { width: 16px; height: 16px; }
    .export-group { flex-shrink: 0; }
    .btn-export { padding: 4px 8px; font-size: 0.65rem; height: 28px; gap: 4px; letter-spacing: 0.3px; box-shadow: none; }
    .btn-export span { display: none; }
    .btn-export i { font-size: 0.75rem; }

    /* Main empilhado vertical */
    main { flex-direction: column; overflow: hidden; }

    /* Editor em cima, Preview embaixo */
    .editor-pane {
        width: 100% !important; min-width: 0 !important;
        height: 50%; flex: none; max-height: 50vh;
        border-bottom: 2px solid var(--border);
    }
    .preview-pane { height: 50%; max-height: 50vh; flex: none; }
    .book-paper { max-width: 100% !important; padding: 0 4px; }
    #preview-content { padding: 20px 16px !important; font-size: 0.95rem !important; }

    /* Toolbar com scroll */
    .editor-toolbar {
        padding: 4px 6px; gap: 2px; overflow-x: auto;
        flex-wrap: nowrap; -webkit-overflow-scrolling: touch;
        scrollbar-width: none;
    }
    .editor-toolbar::-webkit-scrollbar { display: none; }
    .tool-btn { width: 28px; height: 28px; font-size: 0.75rem; flex-shrink: 0; }
    .tool-separator { margin: 0 2px; }
    .tool-group { gap: 1px; flex-shrink: 0; }
    textarea#markdown-input { padding: 0.8rem 1rem; font-size: 13px; line-height: 1.6; }

    /* Resize vira horizontal */
    .resize-handle { width: 100% !important; height: 6px; cursor: row-resize; flex: 0 0 6px; }

    /* Status compacto */
    .status-bar { height: 26px; padding: 2px 8px; font-size: 0.65rem; }
    .status-bar .stats span { font-size: 0.65rem; }
    .status-bar .stats span:nth-child(n+3) { display: none; }
    .app-footer { height: 26px; font-size: 0.65rem; padding: 2px 8px; }
    .toast-container { bottom: 50px; }
    .toast { font-size: 0.75rem; padding: 8px 14px; }
    .find-replace-bar { padding: 6px 8px; }
    .find-replace-bar input { font-size: 0.78rem; padding: 4px 8px; }

    /* Modais */
    .modal { width: 95% !important; margin: 10px auto; max-height: 90vh; }
    .modal-xl { width: 98% !important; }
    .modal-body { padding: 14px; }
    .modal-header { padding: 10px 14px; }
    .modal-header h3 { font-size: 0.95rem; }
    .modal-footer { padding: 8px 14px; flex-wrap: wrap; gap: 4px; }
    .modal-footer .btn { font-size: 0.78rem; padding: 6px 12px; }
    .template-grid { grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)) !important; gap: 10px !important; }
    .pix-modal { width: 92% !important; padding: 20px; }
    .pix-values { grid-template-columns: repeat(2, 1fr) !important; gap: 6px; }
}

/* Telas muito pequenas (< 480px) — modo tab: ou editor OU preview */
@media (max-width: 480px) {
    header { min-height: 40px; }
    .brand { font-size: 0.75rem; }
    .nav-btn { width: 22px; height: 22px; font-size: 0.6rem; }
    #theme-selector { min-width: 80px; font-size: 0.65rem; padding: 1px 3px; }
    .btn-export { padding: 3px 6px; height: 24px; }
    .btn-export i { font-size: 0.65rem; }
    .tool-btn { width: 26px; height: 26px; font-size: 0.7rem; }
    textarea#markdown-input { padding: 0.6rem 0.8rem; font-size: 12px; }
    #preview-content { padding: 16px 12px !important; font-size: 0.88rem !important; }
    .status-bar .stats span:nth-child(n+2) { display: none; }
    .status-bar .stats span:first-child { display: inline-flex; }
    .status-bar { height: 24px; }

    /* Tab bar inferior fixa */
    .mobile-tabs {
        display: flex !important;
        position: fixed;
        bottom: 0; left: 0; right: 0;
        z-index: 100;
        background: var(--bg-header);
        border-top: 1px solid var(--border);
        box-shadow: 0 -2px 10px rgba(0,0,0,0.06);
    }
    .mobile-tab { flex: 1; padding: 8px 4px; border: none; background: transparent;
        font-family: 'Inter', sans-serif; font-size: 0.7rem; font-weight: 500;
        color: var(--text-muted); display: flex; align-items: center;
        justify-content: center; gap: 4px; cursor: pointer;
        border-top: 2px solid transparent; transition: all 0.2s;
    }
    .mobile-tab.active { color: var(--accent); border-top-color: var(--accent); background: var(--accent)08; }
    .mobile-tab i { font-size: 0.8rem; }

    /* Cada painel ocupa toda a area */
    .app-footer { height: 0; overflow: hidden; padding: 0; }
    main { height: calc(100vh - 40px - 24px - 44px); }
    .editor-pane, .preview-pane { height: 100% !important; max-height: none !important; }
    .resize-handle { display: none; }
    .editor-pane.mobile-hidden { display: none !important; }
    .preview-pane.mobile-hidden { display: none !important; }
    .editor-pane.mobile-visible { display: flex !important; }
    .preview-pane.mobile-visible { display: flex !important; }
}

/* Tablet retrato */
@media (min-width: 769px) and (max-width: 1024px) {
    .editor-pane { min-width: 250px; }
    #theme-selector { min-width: 150px; }
    textarea#markdown-input { padding: 1rem 1.5rem; }
    #preview-content { padding: 30px 40px !important; }
}
