/* narraOS Design Tokens */
:root {
    /* Common */
    --nos-tray-height: 41px;
    --nos-header-height: 36px;

    /* Light Theme (Default) */
    --bg-color: #ffffff;
    --text-color: #202124;
    --panel-bg: #f8f9fa;
    --border-color: #dadce0;
    --accent-color: #1a73e8;
    /* Google Blue */
    --input-bg: #ffffff;
    --input-border: #dadce0;
    --viz-bg: radial-gradient(circle at center, #f8f9fa 0%, #ffffff 100%);
    --shadow: 0 1px 2px rgba(60, 64, 67, 0.3);

    --sidebar-bg: #f8f9fa;
}

/* Dark Theme Override */
@media (prefers-color-scheme: dark) {
    :root {
        --bg-color: #202124;
        /* Darker Background */
        --text-color: #e0e0e0;
        --panel-bg: #2d2d2d;
        --border-color: #5f6368;
        --accent-color: #8ab4f8;
        --input-bg: #1e1f20;
        --input-border: #5f6368;
        --viz-bg: radial-gradient(circle at center, #2d2d2d 0%, #202124 100%);
        --shadow: 0 4px 8px rgba(0, 0, 0, 0.5);

        --sidebar-bg: #171717;
        /* Explicit Dark Sidebar */
    }

    /* DARK SCROLLBARS (Native & Webkit) */
    ::-webkit-scrollbar {
        width: 10px;
        height: 10px;
    }

    ::-webkit-scrollbar-track {
        background: #2d2d2d;
    }

    ::-webkit-scrollbar-thumb {
        background: #5f6368;
        border-radius: 5px;
        border: 2px solid #2d2d2d;
    }

    ::-webkit-scrollbar-thumb:hover {
        background: #8ab4f8;
    }

    html {
        scrollbar-color: #5f6368 #2d2d2d;
    }
}

body.theme-light {
    --bg-color: #ffffff;
    --text-color: #202124;
    --panel-bg: #f8f9fa;
    --border-color: #dadce0;
    --input-bg: #ffffff;
    --viz-bg: radial-gradient(circle at center, #f8f9fa 0%, #ffffff 100%);
    --sidebar-bg: #f8f9fa;
}

body.theme-dark {
    --bg-color: #202124;
    --text-color: #e0e0e0;
    --panel-bg: #2d2d2d;
    --border-color: #5f6368;
    --input-bg: #1e1f20;
    --viz-bg: radial-gradient(circle at center, #2d2d2d 0%, #202124 100%);
    --sidebar-bg: #171717;
}

/* Force Dark Scrollbars for themed body explicitly */
body.theme-dark ::-webkit-scrollbar {
    width: 10px;
    height: 10px;
}

body.theme-dark ::-webkit-scrollbar-track {
    background: #2d2d2d;
}

body.theme-dark ::-webkit-scrollbar-thumb {
    background: #5f6368;
    border-radius: 5px;
    border: 2px solid #2d2d2d;
}

body.theme-dark ::-webkit-scrollbar-thumb:hover {
    background: #8ab4f8;
}

body {
    font-family: 'Google Sans', 'Roboto', sans-serif;
    background-color: var(--bg-color);
    color: var(--text-color);
    margin: 0;
    padding: 0;
    overflow: hidden;
    font-size: 14px;
}

/* LOGIN OVERLAY */
#login-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    background: var(--bg-color);
    z-index: 9999;
    display: flex;
    justify-content: center;
    align-items: center;
}

.login-box {
    background: var(--panel-bg);
    padding: 2rem;
    border-radius: 8px;
    box-shadow: var(--shadow);
    width: 320px;
    text-align: center;
    border: 1px solid var(--border-color);
}

.login-box h2 {
    color: var(--accent-color);
    margin-bottom: 2rem;
    margin-top: 0;
}

input,
select,
textarea {
    width: 100%;
    background: var(--input-bg);
    border: 1px solid var(--input-border);
    color: var(--text-color);
    padding: 10px 12px;
    border-radius: 4px;
    box-sizing: border-box;
    outline: none;
    font-family: inherit;
    margin-bottom: 10px;
}

input:focus,
select:focus,
textarea:focus {
    border-color: var(--accent-color);
    border-width: 2px;
    padding: 9px 11px;
}

.btn {
    background: var(--accent-color);
    color: var(--bg-color);
    /* Contrast */
    border: none;
    padding: 8px 16px;
    border-radius: 4px;
    cursor: pointer;
    font-weight: 500;
    font-family: inherit;
    transition: opacity 0.2s;
}

.btn:hover {
    opacity: 0.9;
}

.btn-outline {
    background: transparent;
    color: var(--accent-color);
    border: 1px solid var(--border-color);
}

.btn-outline:hover {
    background: rgba(26, 115, 232, 0.1);
    border-color: var(--accent-color);
}

#app {
    display: flex;
    height: 100vh;
}

aside {
    width: 250px;
    background: var(--sidebar-bg);
    border-right: 1px solid var(--border-color);
    display: flex;
    flex-direction: column;
    padding: 1rem;
}

aside h1 {
    font-size: 1.1rem;
    margin-bottom: 1.5rem;
    color: var(--accent-color);
    font-weight: 500;
}

#sidebar-nav {
    flex: 1;
    overflow-y: auto;
    font-size: 13px;
    margin-top: 10px;
}

main {
    flex: 1;
    position: relative;
    overflow: hidden;
    display: flex;
    flex-direction: column;
}

header {
    padding: 0 20px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    height: 50px;
    flex-shrink: 0;
    background: var(--bg-color);
}

header h2 {
    font-size: 16px;
    font-weight: 500;
    margin: 0;
    color: var(--text-color);
}

/* NEW VIEW TABS (Below Title) */
.viz-tabs {
    display: flex;
    gap: 20px;
    padding: 0 20px;
    border-bottom: 1px solid var(--border-color);
    background: var(--bg-color);
    flex-shrink: 0;
    overflow-x: auto;
}

.viz-tab-btn {
    background: transparent;
    border: none;
    padding: 10px 0;
    color: var(--text-color);
    opacity: 0.6;
    cursor: pointer;
    font-size: 13px;
    font-weight: 500;
    border-bottom: 2px solid transparent;
    font-family: inherit;
    white-space: nowrap;
}

.viz-tab-btn:hover {
    opacity: 1;
}

.viz-tab-btn.active {
    opacity: 1;
    color: var(--accent-color);
    border-bottom-color: var(--accent-color);
}

.view-section {
    display: none;
    flex: 1;
    overflow: hidden;
    height: 100%;
    width: 100%;
    flex-direction: column;
}

.view-section.active {
    display: flex;
}

/* VIZ STYLES */
#viz-container {
    flex: 1;
    overflow: hidden;
    background: var(--viz-bg);
    display: flex;
}

#chart {
    width: 100%;
    height: 100%;
}

/* FILE MANAGER */
#manager-container {
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    padding: 0;
    width: 100%;
    height: 100%;
    background: var(--bg-color);
}

.upload-zone {
    display: none;
    /* Explicitly hidden/removed */
}

/* Control Panel */
#control-panel {
    width: 300px;
    background: var(--panel-bg);
    border-left: 1px solid var(--border-color);
    padding: 1rem;
    display: flex;
    flex-direction: column;
}

.divider {
    height: 1px;
    background: var(--border-color);
    margin: 1rem 0;
}

#theme-toggle {
    cursor: pointer;
    padding: 8px;
    border-radius: 50%;
    background: transparent;
    border: none;
    color: var(--text-color);
}

/* Empty State */
.empty-state {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    height: 100%;
    opacity: 0.5;
    text-align: center;
}

/* NEW PAPER LAYOUT SYSTEM */

/* The view-layer is generic for toggling visibility */
.view-layer {
    display: none;
}

/* The Paper Sheet style (static, grows with content) */
.paper-sheet {
    width: 210mm;
    /* A4 Width approx */
    min-height: 100px;
    /* Minimal height just to show something if empty */
    height: auto;
    /* Fits content exactly */

    margin-bottom: 2rem;

    background: var(--input-bg);
    box-shadow: var(--shadow);
    border: 1px solid var(--border-color);
    box-sizing: border-box;

    padding: 3rem;
    /* Document padding */

    /* No internal scrolling */
    overflow: visible;

    transform-origin: top center;
    /* For zooming */
    transition: transform 0.1s;
}

#md-editor {
    font-family: 'Google Sans', sans-serif;
    outline: none;
}

#text-editor {
    font-family: 'Roboto Mono', 'Menlo', 'Monaco', 'Courier New', monospace;
    font-size: 14px;
    line-height: 1.6;
    outline: none;
    resize: none;
    white-space: pre-wrap;
    background-color: transparent;
    color: var(--text-color);
    /* Border inherited from paper-sheet (1px solid var(--border-color)) */
}

/* Toolbar Styles */
.toolbar {
    display: flex;
    flex-wrap: wrap;
    gap: 0.25rem;
    padding: 0.5rem;
    background-color: var(--panel-bg);
    border-bottom: 1px solid var(--border-color);
    align-items: center;
    justify-content: center;
    width: 100%;
}

.toolbar button {
    background-color: var(--input-bg);
    color: var(--text-color);
    border: 1px solid var(--border-color);
    border-radius: 0.25rem;
    padding: 0.25rem 0.5rem;
    min-width: 32px;
    font-weight: bold;
    font-size: 0.85rem;
    cursor: pointer;
    height: 30px;
    /* Fixed height for consistency */
    display: flex;
    align-items: center;
    justify-content: center;
}

.toolbar button:hover {
    background-color: var(--border-color);
}

.toolbar .separator {
    height: 20px;
    width: 1px;
    background-color: var(--border-color);
    margin: 0 6px;
}

/* Custom Dropdown Styles */
.select-wrapper {
    position: relative;
}

#format-btn {
    background-color: var(--input-bg);
    color: var(--text-color);
    border: 1px solid var(--border-color);
    border-radius: 0.25rem;
    padding: 0 2rem 0 0.75rem;
    font-size: 0.85rem;
    font-weight: 500;
    cursor: pointer;
    height: 30px;
    width: 140px;
    /* Fixed width */
    text-align: left;
    display: flex;
    align-items: center;
    justify-content: flex-start;

    /* Arrow Icon */
    background-image: url("data:image/svg+xml,%3csvg xmlns='http://www.w3.org/2000/svg' fill='none' viewBox='0 0 20 20'%3e%3cpath stroke='%239ca3af' stroke-linecap='round' stroke-linejoin='round' stroke-width='1.5' d='M6 8l4 4 4-4'/%3e%3c/svg%3e");
    background-position: right 0.5rem center;
    background-repeat: no-repeat;
    background-size: 1.5em 1.5em;
}

.dropdown-menu {
    display: none;
    position: absolute;
    top: 100%;
    left: 0;
    width: 100%;
    background: var(--panel-bg);
    border: 1px solid var(--border-color);
    box-shadow: var(--shadow);
    border-radius: 4px;
    z-index: 1000;
    margin-top: 4px;
    max-height: 200px;
    overflow-y: auto;
}

.dropdown-item {
    padding: 8px 12px;
    cursor: pointer;
    font-size: 0.9rem;
    color: var(--text-color);
}

.dropdown-item:hover {
    background-color: var(--border-color);
}

/* Table Styles within Editor */
#md-editor table,
#md-preview-container table {
    width: 100%;
    border-collapse: collapse;
    margin: 1rem 0;
}

#md-editor th,
#md-preview-container th {
    background: var(--panel-bg);
    padding: 8px;
    border: 1px solid var(--border-color);
    text-align: left;
}

#md-editor td,
#md-preview-container td {
    padding: 8px;
    border: 1px solid var(--border-color);
}

/* Markdown View Specific Toolbar */
#md-view-toolbar {
    justify-content: flex-end;
    /* Align to right */
    padding-right: 20px;
    width: 100%;
    /* Full width within the View Container */
    box-sizing: border-box;
    /* Include padding in width */
    margin-right: 0;
    /* No margin needed as it is inside the column */
}

/* NarraOS Sidebar Header Styles - GFE (Gemini Frontend) Inspired */
.gfe-section-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 10px 15px;
    margin-bottom: 5px;
    border-bottom: 1px solid var(--border-color);
}

.gfe-section-title {
    font-size: 14px;
    font-weight: 500;
    color: var(--text-color);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    opacity: 0.8;
}

.gfe-header-actions {
    display: flex;
    gap: 8px;
    /* Space between buttons */
    align-items: center;
    width: 60%;
    /* Take remaining space */
    justify-content: flex-end;
    /* Align right */
}

/* Specific styling for the 3 main buttons to be "Equal Width" if requested? 
   User said "ocupem o espaço horizontal... igualmente". 
   Does this mean flexible width? 
   If they are icon buttons, equal width means simple sizing.
   If they are text buttons, flex: 1.
   They are Icon buttons now. Let's make them flex: 1 to fill the space. 
*/
.gfe-header-actions button {
    background: var(--panel-bg);
    border: 1px solid var(--border-color);
    color: var(--text-color);
    padding: 6px;
    border-radius: 4px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    /* Equal width logic */
    flex: 1;
    height: 32px;
    opacity: 0.8;
    transition: all 0.2s;
}

.gfe-header-actions button:hover {
    background: var(--input-bg);
    opacity: 1;
    border-color: var(--accent-color);
}

.gfe-header-actions button:hover {
    background: rgba(128, 128, 128, 0.1);
    opacity: 1;
}

.gfe-header-actions button svg {
    width: 16px;
    height: 16px;
    stroke-width: 2px;
    /* Ensure visibility */
}

/* Toggle Slider Styles */
.switch {
    position: relative;
    display: inline-block;
    width: 40px;
    height: 20px;
    margin: 0;
    /* reset */
}

.switch input {
    opacity: 0;
    width: 0;
    height: 0;
    margin: 0;
}

.slider {
    position: absolute;
    cursor: pointer;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-color: var(--border-color);
    transition: .4s;
    border-radius: 20px;
}

.slider:before {
    position: absolute;
    content: "";
    height: 16px;
    width: 16px;
    left: 2px;
    bottom: 2px;
    background-color: var(--bg-color);
    /* Match theme bg for contrast inside thumb */
    transition: .4s;
    border-radius: 50%;
}

input:checked+.slider {
    background-color: var(--accent-color);
}

input:checked+.slider:before {
    transform: translateX(20px);
}

/* Ensure Textarea Contrast */
textarea {
    background-color: var(--input-bg);
    color: var(--text-color);
}

/* Prevent Horizontal Scroll */
#node-info {
    overflow-x: hidden;
}