/* ==========================================
   1. VARIÁVEIS GLOBAIS
   ========================================== */
:root {
    --primary: #6366f1;
    --primary-hover: #4f46e5;
    --bg-body: #0f172a;
    --bg-panel: #1e293b;
    --bg-topbar: #020617;
    --border-color: rgba(255, 255, 255, 0.1);
    
    --text-main: #f8fafc;
    --text-muted: #94a3b8;
    
    --radius-sm: 4px;
    --radius-md: 8px;
    --shadow-lg: 0 10px 25px -5px rgba(0, 0, 0, 0.3);
}

/* ==========================================
   2. RESET E BASE
   ========================================== */
* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
    font-family: 'Inter', sans-serif;
    -webkit-tap-highlight-color: transparent;
}

body {
    background-color: var(--bg-body);
    color: var(--text-main);
    overflow: hidden; 
    height: 100vh;
}

::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { 
    background: rgba(255, 255, 255, 0.1); 
    border-radius: 10px; 
}
::-webkit-scrollbar-thumb:hover { background: var(--primary); }

/* ==========================================
   3. LAYOUT PRINCIPAL
   ========================================== */
.main-container {
    display: flex;
    height: calc(100vh - 40px); 
    width: 100%;
}

.column { height: 100%; display: flex; flex-direction: column; }

.left-col {
    background-color: var(--bg-panel);
    flex-shrink: 0;
    width: 260px;
    border-right: 1px solid var(--border-color);
}

.center-col {
    flex: 1;
    background-color: var(--bg-body);
    overflow-y: auto;
    padding: 10px 25px 50px 25px; 
    position: relative;
}

.right-col {
    background-color: var(--bg-panel);
    flex-shrink: 0;
    width: 320px;
    border-left: 1px solid var(--border-color);
}

.mobile-overlay {
    position: fixed; top: 0; left: 0; width: 100vw; height: 100vh;
    background: rgba(0,0,0,0.6); z-index: 15; display: none;
    backdrop-filter: blur(4px);
}
.mobile-overlay.active { display: block; }

/* ==========================================
   4. BOTOES E INPUTS
   ========================================== */
button { transition: all 0.2s ease; cursor: pointer; border: none; outline: none; }
button:active { transform: scale(0.96); }

input, textarea {
    background: rgba(255, 255, 255, 0.03);
    border: 1px solid var(--border-color);
    color: var(--text-main);
    padding: 10px;
    border-radius: var(--radius-sm);
    outline: none;
}

/* ==========================================
   5. POPUPS
   ========================================== */
.popup-overlay {
    position: fixed; top: 0; left: 0; width: 100vw; height: 100vh;
    background-color: rgba(2, 6, 23, 0.8);
    backdrop-filter: blur(8px);
    z-index: 9990;
    display: none;
    align-items: center;
    justify-content: center;
    opacity: 0;
    transition: opacity 0.2s;
}

.popup-overlay.active { display: flex; opacity: 1; }

.popup-content {
    background-color: var(--bg-panel);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-lg);
    transform: scale(0.95);
    transition: transform 0.2s;
    overflow: hidden;
}

.popup-overlay.active .popup-content { transform: scale(1); }

.tool-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 15px;
}

.tool-item:hover {
    background: rgba(255, 255, 255, 0.05) !important;
    border-color: var(--primary) !important;
}

/* ==========================================
   6. RESPONSIVIDADE
   ========================================== */

/* Interruptor (Toggle Switch) */
.switch-container { position: relative; display: inline-block; width: 38px; height: 20px; }
.switch-container input { opacity: 0; width: 0; height: 0; }
.switch-slider { position: absolute; cursor: pointer; top: 0; left: 0; right: 0; bottom: 0; background-color: #334155; transition: .4s; border-radius: 34px; }
.switch-slider:before { position: absolute; content: ""; height: 14px; width: 14px; left: 3px; bottom: 3px; background-color: white; transition: .4s; border-radius: 50%; }
input:checked + .switch-slider { background-color: var(--primary); }
input:checked + .switch-slider:before { transform: translateX(18px); }

/* Lógica de Colapso de Título */
.tool-title-input {
    white-space: nowrap; /* Predefinido: Uma linha só */
    overflow-x: auto;
    resize: none;
    display: block;
}

/* Quando o modo de colapso está ativo (adicionaremos esta classe ao body via JS) */
body.modo-colapso-titulos .tool-title-input {
    white-space: normal !important; /* Permite várias linhas */
    overflow: hidden;
}

.aba-item { cursor: pointer; color: var(--text-muted); font-size: 13px; font-weight: 700; text-transform: uppercase; padding: 5px 0; }
.aba-item.active { color: var(--primary); border-bottom: 2px solid var(--primary); }

.arquivo-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
    gap: 15px;
    margin-top: 10px;
}

.gaveta-card {
    height: 120px;
    background: linear-gradient(145deg, rgba(255, 255, 255, 0.05) 0%, rgba(255, 255, 255, 0.01) 100%);
    border: 1px solid rgba(255, 255, 255, 0.08);
    border-radius: 12px;
    padding: 20px;
    display: flex;
    flex-direction: column;
    justify-content: flex-end; /* Empurra o texto para o fundo do cartão */
    cursor: pointer;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    position: relative;
    overflow: hidden;
}

/* O título da gaveta */
.gaveta-titulo {
    font-weight: 700;
    color: #f8fafc;
    font-size: 16px;
    margin-bottom: 4px;
    letter-spacing: 0.3px;
}

/* O subtítulo com as contagens */
.gaveta-info {
    font-size: 10px;
    color: var(--text-muted);
    text-transform: uppercase;
    font-weight: 600;
    letter-spacing: 0.8px;
    display: flex;
    gap: 10px;
}


.gaveta-card:hover {
    background: rgba(255, 255, 255, 0.08);
    transform: translateY(-4px);
    border-color: var(--primary);
    box-shadow: 0 10px 20px rgba(0, 0, 0, 0.3);
}

/* Badge circular para prateleiras */
.prateleira-card {
    background: rgba(255, 255, 255, 0.03);
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 8px;
    padding: 14px;
    text-align: center;
    font-weight: 800;
    font-size: 11px;
    color: #94a3b8;
    text-transform: uppercase;
    transition: 0.2s;
}

.prateleira-card:hover {
    background: white;
    color: #0f172a;
    border-color: white;
}

.btn-lab-action {
    background: var(--primary); color: white; padding: 8px 20px; border-radius: 4px;
    font-weight: 800; font-size: 10px; cursor: pointer;
}

.btn-plus-circle {
    width: 30px; height: 30px; border-radius: 50%; background: #22c55e;
    color: white; font-size: 20px; display: flex; align-items: center; justify-content: center;
}

.arquivo-nav-header { display: flex; align-items: center; gap: 15px; margin-bottom: 20px; }

/* Estilo para as abas FEED / ARQUIVO */
.aba-item {
    font-size: 11px;
    font-weight: 800;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 1px;
    padding: 8px 0;
    position: relative;
    transition: 0.2s;
}

.aba-item.active {
    color: var(--primary);
}

.aba-item.active::after {
    content: "";
    position: absolute;
    bottom: -1px; /* Cola na linha da borda do container */
    left: 0;
    width: 100%;
    height: 2px;
    background-color: var(--primary);
}

.tool-title-input {
    min-height: 30px !important; /* Altura mínima de uma linha */
    height: auto;
    overflow: hidden;
    resize: none;
    padding: 10px 18px;
    box-sizing: border-box;
}
#editor-container {
    /* Garante que o padding e bordas não afetam o cálculo do scrollHeight */
    box-sizing: border-box;
}

.tool-title-input {
    /* Importante para o cálculo inicial não ser zero */
    min-height: 24px; 
    display: block;
}

.tree-folder-content { display: none; padding-left: 15px; border-left: 1px solid rgba(255,255,255,0.05); margin-left: 10px; }
.tree-folder-content.open { display: block; }
.tree-item { cursor: pointer; padding: 5px 8px; border-radius: 4px; transition: 0.2s; display: flex; align-items: center; gap: 8px; }
.tree-item:hover { background: rgba(255,255,255,0.05); }
.tree-folder-header { font-weight: 700; color: var(--text-muted); font-size: 11px; text-transform: uppercase; margin-top: 5px; }

:root {
    /* Pega a altura da área do relógio do iPhone */
    --safe-top: env(safe-area-inset-top);
}


/* Ajusta a coluna da esquerda para não ficar por baixo do topo */
.main-container {
    height: calc(100vh - (40px + var(--safe-top)));
}

/* Ajuste para Safe Areas do iPhone */
.top-menu {
    display: flex;
    /* env(safe-area-inset-top) deteta automaticamente o tamanho do relógio/notch do iPhone */
    padding-top: env(safe-area-inset-top) !important; 
    height: calc(40px + env(safe-area-inset-top)) !important; 
    background-color: var(--bg-topbar); 
    align-items: center; 
    padding-left: 10px;
    padding-right: 10px;
    padding-bottom: 0;
    justify-content: space-between; 
    border-bottom: 1px solid rgba(255, 255, 255, 0.05); 
    gap: 10px;
    box-sizing: content-box; /* Importante para o cálculo da altura no iOS */
}

.main-container {
    height: calc(100dvh - (40px + env(safe-area-inset-top)));
}

/* Garante que o editor não fique por baixo da barra de navegação do iOS */
.center-col {
    padding-bottom: calc(60px + env(safe-area-inset-bottom)) !important;
}

/* No final do styles/global.css */

@media (max-width: 768px) {
    .left-col {
        /* Garante que o menu começa abaixo do relógio do iPhone */
        padding-top: env(safe-area-inset-top) !important;
        background-color: var(--bg-panel) !important;
    }
    
    /* Garante que o fundo da barra de abas (Local/Share/etc) é visível */
    .left-buttons {
        background-color: var(--bg-panel) !important;
        border-bottom: 1px solid var(--border-color);
    }
}

#offline-banner {
    position: fixed;
    /* Fica logo abaixo da safe area do iPhone */
    top: env(safe-area-inset-top); 
    left: 0;
    width: 100%;
    background-color: #ea580c; /* Laranja forte (Aviso) */
    color: white;
    text-align: center;
    padding: 8px 10px;
    font-size: 11px;
    font-weight: 800;
    text-transform: uppercase;
    letter-spacing: 1px;
    z-index: 100000; /* Acima de tudo */
    box-shadow: 0 4px 10px rgba(0,0,0,0.3);
    animation: slideDown 0.3s ease-out;
}

/* Pequena animação de entrada */
@keyframes slideDown {
    from { transform: translateY(-100%); }
    to { transform: translateY(0); }
}

/* Estilo para quando a net volta (Verde) */
#offline-banner.online-success {
    background-color: #22c55e;
}

/* Lógica de Colapso de Título */
.tool-title-input {
    white-space: nowrap !important; /* Força linha única por defeito */
    overflow-x: auto !important;
    overflow-y: hidden !important;
    resize: none;
    display: block;
    height: 35px; /* Altura base para uma linha */
}

/* Quando o modo de colapso está ativo no BODY */
body.modo-colapso-titulos .tool-title-input {
    white-space: pre-wrap !important; /* Permite quebra de linha */
    overflow-x: hidden !important;
    overflow-y: hidden !important;
    height: auto; /* Deixa o JS ou o conteúdo definir a altura */
}
