/* Layout CSS — SIDEBAR FULL HEIGHT + THIN SCROLLBARS + DEPLOY SECTION */

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

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Roboto', 'Helvetica', 'Arial', sans-serif;
    background: var(--bg-base);
    color: var(--text-main);
    overflow: hidden;
    font-size: 13px;
}

/* Container */
.remix-container {
    display: flex;
    flex-direction: column;
    /* dvh follows the mobile browser chrome; vh stays as the fallback */
    height: 100vh;
    height: 100dvh;
    background: var(--bg-base);
}

/* Header */
.remix-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    background: var(--bg-elevated);
    border-bottom: 1px solid var(--border-main);
    padding: 8px 16px;
    min-height: 50px;
    z-index: 100;
    flex-shrink: 0;
}

.header-left {
    display: flex;
    align-items: center;
}

.remix-logo {
    display: flex;
    align-items: center;
    gap: 8px;
}

/* Overrides the fill="#fff" presentation attribute so the logo follows the theme */
.remix-logo svg path {
    fill: var(--text-bright);
}

.logo-text {
    font-weight: 600;
    font-size: 16px;
    color: var(--text-bright);
    margin-left: 4px;
}

.header-center {
    flex: 1;
    display: flex;
    justify-content: center;
    align-items: center;
    margin: 10px 0;
}

.current-file-name {
    font-size: 14px;
    color: var(--text-bright);
    font-weight: 500;
}

.header-right {
    display: flex;
    align-items: center;
    gap: 12px;
}

.network-indicator {
    display: flex;
    align-items: center;
}

.network-badge {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 4px 8px;
    background: var(--bg-muted-2);
    border-radius: 12px;
    font-size: 12px;
}

.network-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--danger-alt);
}

.network-dot.connected {
    background: var(--success-dark);
}

/* Proxy status */
.proxy-status {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 4px 8px;
    background: var(--bg-muted-2);
    border-radius: 12px;
    font-size: 11px;
    font-weight: 600;
}

.proxy-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--danger-alt);
}

.proxy-dot.connected {
    background: var(--success-dark);
}

.proxy-status-text {
    color: var(--text-bright);
}

/* MAIN STRUCTURE: remix-main is horizontal */
.remix-main {
    display: flex;
    flex-direction: row;
    flex: 1;
    overflow: hidden;
}

/* Icon panel on the left */
.remix-icon-panel {
    width: 50px;
    background: var(--bg-elevated);
    border-right: 1px solid var(--border-main);
    display: flex;
    flex-direction: column;
    padding: 8px 0;
    flex-shrink: 0;
}

.icon-group {
    display: flex;
    flex-direction: column;
}

.icon-item {
    width: 50px;
    height: 50px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: background-color 0.2s;
    color: var(--text-main);
    position: relative;
}

.icon-item:hover {
    background: var(--bg-hover);
}

.icon-item.active {
    background: var(--bg-hover);
    border-left: 3px solid var(--accent);
    color: var(--text-bright);
}

.icon-separator {
    height: 1px;
    background: var(--border-main);
    margin: 8px 8px;
}

/* MAIN CONTENT: now split into two parts */
.main-content {
    flex: 1;
    display: flex;
    flex-direction: row; /* CHANGED: now horizontal */
    overflow: hidden;
}

/* SIDEBAR: now fills the full height of main-content */
.remix-sidebar {
    width: 280px;
    background: var(--bg-panel);
    border-right: 1px solid var(--border-main);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    flex-shrink: 0;
    min-width: 250px;
    /* MAIN: sidebar now fills the full height */
}

/* Vertical resizer between sidebar and right part */
.vertical-resizer {
    width: 4px;
    background: var(--border-main);
    cursor: col-resize;
    flex-shrink: 0;
    transition: background-color 0.2s;
}

.vertical-resizer:hover {
    background: var(--accent);
}

/* RIGHT PART: editor + terminal */
.right-section {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow-y: scroll;
    min-width: 0;
}

/* Editor occupies the top part of right-section */
.remix-editor {
    flex: 1;
    display: flex;
    flex-direction: column;
    background: var(--bg-base);
    overflow: hidden;
    min-width: 0;
    min-height: 553px;
}

/* Horizontal resizer between editor and terminal */
.horizontal-resizer {
    height: 6px;
    background: var(--border-main);
    cursor: row-resize;
    flex-shrink: 0;
    transition: background-color 0.2s;
    /* Removed margin-left — resizer now spans the full width of the right part */
}

.horizontal-resizer:hover {
    background: var(--accent);
}

/* Terminal occupies the bottom part of right-section */
.remix-terminal {
    height: 180px;
    background: var(--bg-base);
    border-top: 1px solid var(--border-main);
    display: flex;
    flex-direction: column;
    flex-shrink: 0;
    /* Removed margin-left — terminal now spans the full width of the right part */
}

/* Plugin content */
.plugin-content {
    display: none;
    flex: 1;
    overflow: hidden;
    flex-direction: column;
    min-height: 0;
}
.plugin-content[data-content="udapp"] {
    overflow: visible;
}

.plugin-content.active {
    display: flex;
}

/* ADDED: special rule for the Deploy section */
.plugin-content[data-content="udapp"] {
    /* Deploy section works with scrolling inside deploy-config */
    overflow: visible;
}

.plugin-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 16px;
    border-bottom: 1px solid var(--border-main);
    background: var(--bg-elevated);
    flex-shrink: 0;
}

.plugin-header h3 {
    font-size: 14px;
    font-weight: 600;
    color: var(--text-bright);
    margin: 0;
}


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

.action-btn {
    width: 24px;
    height: 24px;
    background: transparent;
    border: none;
    color: var(--text-main);
    cursor: pointer;
    border-radius: 3px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.action-btn:hover {
    background: var(--border-main);
    color: var(--text-bright);
}

/* Workspace section fills the rest of plugin-content */
.workspace-section {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.workspace-selector {
    padding: 12px 16px;
    border-bottom: 1px solid var(--border-main);
    flex-shrink: 0;
}

.workspace-dropdown {
    width: 100%;
    background: var(--bg-input);
    border: 1px solid var(--border-strong);
    border-radius: 4px;
    color: var(--text-main);
    padding: 6px 8px;
    font-size: 12px;
}

.workspace-actions {
    padding: 12px 16px;
    border-bottom: 1px solid var(--border-main);
    display: flex;
    flex-direction: column;
    gap: 8px;
    flex-shrink: 0;
}

.workspace-action-btn {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 12px;
    background: var(--accent);
    border: none;
    border-radius: 4px;
    color: white;
    cursor: pointer;
    font-size: 12px;
    font-weight: 500;
    transition: background-color 0.2s;
}

.workspace-action-btn:hover {
    background: var(--accent-hover);
}

.workspace-action-btn svg {
    width: 16px;
    height: 16px;
}

/* File Explorer fills the rest of workspace-section */
.file-explorer {
    flex: 1;
    overflow-y: auto;
    padding: 8px 0;
}

.folder-item {
    margin-bottom: 4px;
}

.folder-header {
    display: flex;
    align-items: center;
    padding: 4px 16px;
    cursor: pointer;
    transition: background-color 0.2s;
    font-size: 13px;
}

.folder-header:hover {
    background: var(--bg-hover-soft);
}

.folder-icon {
    color: #dcb67a;
    margin-right: 6px;
}

.folder-name {
    flex: 1;
    color: var(--text-main);
}

.folder-actions {
    display: none;
    gap: 2px;
}

.folder-header:hover .folder-actions {
    display: flex;
}

.folder-action-btn {
    width: 16px;
    height: 16px;
    background: transparent;
    border: none;
    color: var(--text-main);
    cursor: pointer;
    border-radius: 2px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.folder-action-btn:hover {
    background: var(--border-main);
}

.folder-content {
    padding-left: 24px;
}

.file-item {
    display: flex;
    align-items: center;
    padding: 4px 16px;
    cursor: pointer;
    transition: background-color 0.2s;
    font-size: 13px;
    position: relative;
}

.file-item:hover {
    background: var(--bg-hover-soft);
}

.file-item.active {
    background: var(--bg-hover);
    color: var(--text-bright);
}

.file-icon {
    margin-right: 6px;
}

.file-name {
    color: var(--text-main);
    flex: 1;
}

.file-item.active .file-name {
    color: var(--text-bright);
}

/* File modification indicators */
.file-modified,
.tab-modified {
    color: #f6851b !important;
    font-weight: bold;
    margin-left: 4px;
}

/* Context Menu */
.context-menu {
    position: fixed;
    background: var(--bg-elevated);
    border: 1px solid var(--border-main);
    border-radius: 4px;
    padding: 4px 0;
    min-width: 150px;
    box-shadow: 0 4px 8px rgba(0, 0, 0, 0.3);
    z-index: 1000;
    font-size: 12px;
}

.context-menu-item {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 12px;
    cursor: pointer;
    color: var(--text-main);
    transition: background-color 0.2s;
}

.context-menu-item:hover {
    background: var(--bg-hover);
}

.context-menu-item.danger {
    color: var(--danger-strong);
}

.context-menu-item.danger:hover {
    background: rgba(244, 67, 54, 0.1);
}

.context-menu-separator {
    height: 1px;
    background: var(--border-main);
    margin: 4px 0;
}

/* Drag and Drop */
.file-item.dragging {
    opacity: 0.5;
}

.folder-content.drag-over {
    background: rgba(0, 122, 204, 0.1);
    border: 1px dashed var(--accent);
}

/* Animations */
.folder-content {
    transition: max-height 0.2s ease-out;
    overflow: hidden;
}

.folder-item.collapsed .folder-content {
    max-height: 0;
}

.folder-item.expanded .folder-content {
    max-height: 1000px;
}

@keyframes fadeIn {
    from { opacity: 0; transform: translateY(-5px); }
    to { opacity: 1; transform: translateY(0); }
}

/* Selection */
::selection {
    background: var(--accent);
    color: var(--text-bright);
}

/* THIN Scrollbar — 4px instead of 8px */
::-webkit-scrollbar {
    width: 4px;
    height: 4px;
}

::-webkit-scrollbar-track {
    background: var(--bg-base);
}

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

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


/* ============================================================================
   Mobile / narrow layout.
   The app collapses into one vertical column with a SINGLE scroller
   (.remix-main). Every section flows at its natural height — the old layout
   pinned them to hardcoded pixel heights (1020px / 1000px / 553px / 320px),
   which is why the icon panel stopped short of the bottom.
   ========================================================================= */
@media (max-width: 950px) {

    /* --- Header --- */
    .remix-header {
        padding: 6px 10px;
        min-height: 44px;
        gap: 8px;
    }

    .logo-text {
        font-size: 14px;
        margin-left: 0;
    }

    .header-right {
        gap: 6px;
        min-width: 0;
    }

    .network-badge {
        font-size: 11px;
        padding: 3px 7px;
    }

    /* Long names like "Unknown Network (12345)" must not push the badge off screen */
    .network-text {
        display: block;
        max-width: 34vw;
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
    }

    /* --- The one and only scroll container --- */
    .remix-main {
        flex-direction: column;
        overflow-x: hidden;
        overflow-y: auto;
        -webkit-overflow-scrolling: touch;
    }

    /* --- Icon panel: horizontal tab bar pinned to the bottom ---
       Sticky (not fixed) so it rides the .remix-main scroller, whose height
       already follows dvh — a fixed bar would sit under the browser chrome. */
    .remix-icon-panel {
        order: 2;
        position: sticky;
        bottom: 0;
        z-index: 50;
        flex-direction: row;
        align-items: center;
        width: 100%;
        padding: 0 4px;
        /* Keeps the icons clear of the iOS home indicator */
        padding-bottom: env(safe-area-inset-bottom, 0px);
        border-right: none;
        border-top: 1px solid var(--border-main);
        overflow-x: auto;
        overflow-y: hidden;
        scrollbar-width: none;
    }

    .remix-icon-panel::-webkit-scrollbar {
        display: none;
    }

    .icon-group {
        flex-direction: row;
    }

    /* Pushes the settings group to the far right of the bar */
    .icon-group:last-child {
        margin-left: auto;
    }

    .icon-separator {
        display: none;
    }

    .icon-item {
        width: 46px;
        height: 46px;
        flex-shrink: 0;
    }

    /* The active marker moves from the left edge to the top edge of the bar */
    .icon-item.active {
        border-left: none;
        border-top: 3px solid var(--accent);
    }

    /* --- Content column ---
       flex:0 0 auto so the column sizes to its content and .remix-main scrolls
       the total; with the desktop flex:1 the overflow height is unreliable. */
    .main-content {
        order: 1;
        flex: 0 0 auto;
        flex-direction: column;
        overflow: visible;
        /* Fills the scroller minus the bar, so the sticky bar sits at the
           bottom edge even when a panel is short on content */
        min-height: calc(100% - 46px);
    }

    .remix-sidebar,
    .right-section {
        width: 100%;
        min-width: 0;
        flex: 0 0 auto;
        overflow: visible;
    }

    .remix-sidebar {
        border-right: none;
        border-bottom: 1px solid var(--border-main);
    }

    /* Panels flow inside the page scroll instead of scrolling themselves */
    .plugin-content,
    .deploy-config,
    .file-explorer,
    .compiler-config,
    .search-config,
    .debugger-config,
    .settings-config {
        overflow: visible;
    }

    .deploy-config {
        height: auto;
    }

    /* --- Editor --- */
    .remix-editor {
        min-height: 55vh;
        min-height: 55dvh;
    }

    .editor-content {
        min-height: 260px;
    }

    .CodeMirror pre.CodeMirror-line,
    .CodeMirror pre.CodeMirror-line-like {
        font-size: 10px;
    }

    /* --- Terminal --- */
    .remix-terminal {
        height: 35vh;
        height: 35dvh;
        min-height: 170px;
    }

    /* --- Resizers are mouse-only, so they are dead weight on touch --- */
    .vertical-resizer,
    .horizontal-resizer {
        display: none;
    }

    /* --- Modals --- */
    .pasted-alert-modal {
        overflow-y: auto;
    }

    .pasted-alert-content {
        top: 0;
        position: absolute !important;
        min-height: 650px !important;
    }
}

/* Very narrow phones: the SECURE label is the first thing to drop */
@media (max-width: 420px) {
    .proxy-status-text {
        display: none;
    }

    .logo-text {
        font-size: 13px;
    }

    .network-text {
        max-width: 30vw;
    }
}

/* Touch devices keep :hover styles stuck after a tap, so neutralise the moving ones */
@media (hover: none) {
    .terminal-log:hover {
        background: rgba(255, 255, 255, 0.02);
        transform: none;
    }

    .terminal-log a:hover {
        transform: none;
        box-shadow: none;
        text-shadow: none;
    }

    .icon-item:hover {
        background: transparent;
    }

    .icon-item.active:hover {
        background: var(--bg-hover);
    }

    .vertical-resizer:hover,
    .horizontal-resizer:hover {
        background: var(--border-main);
    }
}
