:root {
    --bg-dark: #0a0c10;
    --bg-panel: #161b22;
    --bg-lighter: #21262d;
    --accent: #c8a45d;
    --accent-hover: #e3c483;
    --text-main: #c9d1d9;
    --text-muted: #8b949e;
    --text-dim: #8b949e;
    --text-bright: #ffffff;
    --border: rgba(255, 255, 255, 0.1);
    
    --font-ui: 'Inter', sans-serif;
    --font-mono: 'JetBrains Mono', monospace;
}

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

html, body {
    width: 100vw;
    height: 100vh;
    margin: 0;
    padding: 0;
    overflow: hidden;
    background-color: var(--bg-dark);
    color: var(--text-main);
    font-family: var(--font-ui);
    display: flex;
    flex-direction: column;
}

/* ---------------- 1. FULL WIDTH TOP NAVBAR HEADER ---------------- */
.app-header {
    height: 50px;
    width: 100vw;
    background: #11151f;
    background-image: linear-gradient(180deg, #171c28 0%, #0e121a 100%);
    border-bottom: 1px solid rgba(255, 255, 255, 0.12);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 16px;
    position: relative;
    z-index: 1000;
    flex-shrink: 0;
    user-select: none;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.5);
}

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

.brand {
    display: flex;
    align-items: center;
    gap: 10px;
    white-space: nowrap;
}

.brand-icon {
    font-size: 1.2rem;
    color: var(--accent);
    filter: drop-shadow(0 0 6px rgba(200, 164, 93, 0.5));
}

.brand-title {
    font-size: 1rem;
    font-weight: 700;
    color: #ffffff;
    letter-spacing: 1px;
}

.header-vdivider {
    width: 1px;
    height: 24px;
    background: rgba(255, 255, 255, 0.12);
}

.app-nav {
    display: flex;
    align-items: center;
    gap: 8px;
}

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

.view-controls-group {
    display: flex;
    align-items: center;
    gap: 4px;
    background: #0b0e14;
    padding: 3px 6px;
    border-radius: 6px;
    border: 1px solid rgba(255, 255, 255, 0.08);
}

/* ---------------- 2. BUTTON STYLING (RESET & CYBER THEME) ---------------- */
button.app-btn, a.app-btn {
    all: unset;
    box-sizing: border-box;
    background: #1c2230 !important;
    background-image: linear-gradient(180deg, #242c3d 0%, #181d29 100%) !important;
    border: 1px solid rgba(255, 255, 255, 0.14) !important;
    color: #e1e7ed !important;
    padding: 6px 13px !important;
    border-radius: 6px !important;
    font-family: var(--font-ui) !important;
    font-size: 0.82rem !important;
    font-weight: 600 !important;
    cursor: pointer !important;
    display: inline-flex !important;
    align-items: center !important;
    gap: 8px !important;
    transition: all 0.2s cubic-bezier(0.16, 1, 0.3, 1) !important;
    height: 32px !important;
    line-height: 1 !important;
    box-shadow: 0 2px 5px rgba(0, 0, 0, 0.4), inset 0 1px 0 rgba(255, 255, 255, 0.1) !important;
    white-space: nowrap !important;
    text-decoration: none !important;
}

button.app-btn:hover, a.app-btn:hover {
    background: #2a3447 !important;
    background-image: linear-gradient(180deg, #333f57 0%, #212938 100%) !important;
    color: #ffffff !important;
    border-color: rgba(200, 164, 93, 0.5) !important;
    box-shadow: 0 4px 14px rgba(0, 0, 0, 0.6), 0 0 10px rgba(200, 164, 93, 0.25) !important;
    transform: translateY(-1px) !important;
}

button.app-btn:active {
    transform: translateY(0) !important;
    box-shadow: inset 0 2px 4px rgba(0, 0, 0, 0.7) !important;
}

button.app-btn.view-btn {
    background: transparent !important;
    border: none !important;
    box-shadow: none !important;
    padding: 4px 10px !important;
    height: 28px !important;
    color: #8b949e !important;
}

button.app-btn.view-btn:hover {
    background: rgba(255, 255, 255, 0.08) !important;
    color: #ffffff !important;
    transform: none !important;
}

button.app-btn.view-btn.active {
    background: rgba(200, 164, 93, 0.15) !important;
    color: var(--accent) !important;
}

/* Icon Accent Colors */
.icon-accent { color: var(--accent) !important; filter: drop-shadow(0 0 4px rgba(200, 164, 93, 0.3)); }
.icon-discord { color: #5865F2 !important; filter: drop-shadow(0 0 4px rgba(88, 101, 242, 0.4)); }
.icon-green { color: #2ea043 !important; filter: drop-shadow(0 0 4px rgba(46, 160, 67, 0.4)); }
.icon-amber { color: #ffbd2e !important; filter: drop-shadow(0 0 4px rgba(255, 189, 46, 0.4)); }
.icon-purple { color: #a855f7 !important; filter: drop-shadow(0 0 4px rgba(168, 85, 247, 0.4)); }
.arrow-icon { font-size: 0.65rem !important; margin-left: 2px !important; opacity: 0.8 !important; }

/* ---------------- 3. DROPDOWN MENU FIX (Z-INDEX & OVERLAY) ---------------- */
.logic-dropdown {
    position: relative !important;
    display: inline-block !important;
}

.logic-dropdown .dropdown-menu {
    display: none !important;
    position: absolute !important;
    top: calc(100% + 6px) !important;
    left: 0 !important;
    min-width: 220px !important;
    background: #141822 !important;
    border: 1px solid rgba(255, 255, 255, 0.18) !important;
    border-radius: 8px !important;
    box-shadow: 0 14px 40px rgba(0, 0, 0, 0.85), 0 0 15px rgba(200, 164, 93, 0.2) !important;
    z-index: 99999 !important;
    padding: 6px 0 !important;
    flex-direction: column !important;
}

.logic-dropdown.open .dropdown-menu {
    display: flex !important;
    flex-direction: column !important;
}

button.dropdown-item {
    all: unset !important;
    box-sizing: border-box !important;
    width: 100% !important;
    display: flex !important;
    align-items: center !important;
    gap: 10px !important;
    padding: 10px 16px !important;
    background: #141822 !important;
    color: #c9d1d9 !important;
    font-family: var(--font-ui) !important;
    font-size: 0.84rem !important;
    font-weight: 500 !important;
    cursor: pointer !important;
    text-align: left !important;
    white-space: nowrap !important;
    transition: background 0.15s, color 0.15s !important;
}

button.dropdown-item:hover {
    background: rgba(200, 164, 93, 0.18) !important;
    color: #ffffff !important;
}

.dropdown-divider {
    height: 1px !important;
    background: rgba(255, 255, 255, 0.08) !important;
    margin: 6px 0 !important;
}

.badge-beta {
    font-size: 0.6rem;
    background: var(--accent);
    color: #000;
    padding: 2px 5px;
    border-radius: 3px;
    font-weight: bold;
    margin-left: auto;
}

/* ---------------- 4. MAIN WORKSPACE CONTAINER (FULL SCREEN BODY) ---------------- */
.app-workspace {
    flex: 1;
    width: 100vw;
    height: calc(100vh - 50px);
    display: flex;
    flex-direction: row;
    position: relative;
    overflow: hidden;
}

/* Custom Scratch-like Sidebar */
.logic-custom-sidebar {
    min-width: 60px;
    width: 95px;
    background: #0f141c;
    border-right: 1px solid rgba(255, 255, 255, 0.08);
    display: flex;
    flex-direction: column;
    padding: 0.5rem 0;
    overflow-y: auto;
    transition: width 0.3s;
    overflow-x: hidden;
    white-space: nowrap;
    flex-shrink: 0;
}

.logic-custom-sidebar.collapsed {
    width: 0 !important;
    min-width: 0 !important;
    padding: 0;
    border: none;
}

.logic-custom-sidebar .cat-btn {
    background: transparent;
    border: none;
    color: var(--text-dim);
    padding: 0.6rem 0.2rem;
    font-size: 0.72rem;
    font-family: var(--font-ui);
    cursor: pointer;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.3rem;
    transition: all 0.2s ease;
    text-align: center;
}

.logic-custom-sidebar .cat-btn i {
    font-size: 1.2rem;
    color: var(--accent);
    opacity: 0.7;
}

.logic-custom-sidebar .cat-btn:hover {
    color: var(--text-bright);
    background: rgba(255, 255, 255, 0.05);
}

.logic-custom-sidebar .cat-btn:hover i {
    opacity: 1;
}

/* Resizers */
.sidebar-resizer {
    width: 5px;
    background: #181d28;
    border-left: 1px solid rgba(255, 255, 255, 0.05);
    border-right: 1px solid rgba(255, 255, 255, 0.05);
    cursor: col-resize;
    transition: background 0.2s;
    z-index: 10;
    flex-shrink: 0;
}

.sidebar-resizer:hover, .sidebar-resizer.dragging {
    background: var(--accent);
}

/* Blockly Wrapper */
.blockly-wrapper {
    flex: 1;
    position: relative;
    height: 100%;
    min-width: 0;
    background-color: var(--bg-dark);
}

#blocklyDiv {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
}

/* Blockly Dark Overrides */
.blocklySvg, .blocklyMainBackground {
    background-color: var(--bg-dark) !important;
    fill: var(--bg-dark) !important;
}
.blocklyToolboxDiv {
    background-color: var(--bg-panel) !important;
    border-right: 1px solid var(--border) !important;
}
.blocklyTreeLabel {
    color: #fff !important;
    font-family: var(--font-ui) !important;
    font-size: 0.85rem;
}
.blocklyTreeRow {
    background-color: transparent !important;
}
.blocklyTreeRow.blocklyTreeSelected {
    background-color: var(--accent) !important;
}
.blocklyTreeRow.blocklyTreeSelected .blocklyTreeLabel {
    color: #000 !important;
    font-weight: 600;
}
.blocklyFlyoutBackground {
    fill: var(--bg-lighter) !important;
    fill-opacity: 1 !important;
}
.blocklyScrollbarHandle {
    fill: var(--accent) !important;
}
.blocklyFlyoutLabelText {
    fill: #fff !important;
    font-weight: 600;
    font-family: var(--font-ui) !important;
}
.blocklyHtmlInput {
    color: #000 !important;
    background-color: #fff !important;
    border: 1px solid #ccc !important;
    padding: 2px !important;
}

/* Right Output Code Panel */
.code-panel {
    flex: 0 0 380px;
    width: 380px;
    display: flex;
    flex-direction: column;
    background: var(--bg-panel);
    border-left: 1px solid var(--border);
    height: 100%;
    overflow: hidden;
}

.code-panel.collapsed {
    display: none !important;
}

.panel-header {
    padding: 12px 18px;
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: space-between;
    background: #11151f;
    flex-shrink: 0;
}

.panel-header h3 {
    font-size: 0.92rem;
    font-weight: 600;
    color: var(--text-main);
    display: flex;
    align-items: center;
    gap: 8px;
}

/* Engine Toggle */
.engine-toggle {
    display: flex;
    background: var(--bg-dark);
    border: 1px solid var(--border);
    border-radius: 4px;
    overflow: hidden;
}

.radio-label {
    padding: 4px 10px;
    font-size: 0.75rem;
    font-weight: 600;
    cursor: pointer;
    color: var(--text-muted);
    transition: 0.2s;
    user-select: none;
}

.radio-label:has(input:checked) {
    background: var(--accent);
    color: #000;
}

.radio-label input {
    display: none;
}

/* Code Preview */
.code-preview {
    flex: 1;
    padding: 15px;
    overflow: auto;
    background: var(--bg-dark);
    margin: 12px;
    border: 1px solid var(--border);
    border-radius: 6px;
}

.code-preview pre {
    margin: 0 !important;
    background: transparent !important;
    padding: 0 !important;
    font-family: var(--font-mono) !important;
    font-size: 0.85rem !important;
    white-space: pre-wrap;
    word-wrap: break-word;
}

/* Actions */
.panel-actions {
    padding: 12px 15px;
    display: flex;
    gap: 8px;
    border-top: 1px solid var(--border);
    flex-shrink: 0;
}

.btn {
    flex: 1;
    padding: 8px 12px;
    border: none;
    border-radius: 6px;
    font-family: var(--font-ui);
    font-size: 0.8rem;
    font-weight: 600;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    transition: 0.2s;
}

.btn.primary {
    background: var(--accent);
    color: #000;
}
.btn.primary:hover {
    background: var(--accent-hover);
}

.btn.success {
    background: #2ea043;
    color: #fff;
}
.btn.success:hover {
    background: #3fb950;
}

.btn.outline {
    background: transparent;
    border: 1px solid var(--border);
    color: var(--text-main);
}
.btn.outline:hover {
    background: rgba(255, 255, 255, 0.05);
}

.btn.danger {
    background: #ff4757;
    color: #fff;
}
.btn.danger:hover {
    background: #ff6b81;
}

/* Support Banner */
.support-banner {
    padding: 12px;
    margin: 0 12px 12px 12px;
    background: rgba(255, 255, 255, 0.03);
    border: 1px dashed rgba(255, 255, 255, 0.1);
    border-radius: 6px;
    text-align: center;
    flex-shrink: 0;
}
.support-banner p {
    font-size: 0.78rem;
    color: var(--text-dim);
    margin: 0 0 8px 0;
    line-height: 1.3;
    font-style: italic;
}
.support-banner .bmc-button img {
    height: 34px !important;
    width: auto !important;
    transition: transform 0.2s ease;
}
.support-banner .bmc-button:hover img {
    transform: scale(1.05);
}

/* ---------------- 5. MODALS & OVERLAYS ---------------- */
.logic-modal-overlay {
    position: fixed;
    top: 0; left: 0; width: 100vw; height: 100vh;
    background: rgba(0, 0, 0, 0.75);
    z-index: 99999;
    display: flex;
    align-items: center;
    justify-content: center;
    backdrop-filter: blur(5px);
}
.logic-modal {
    background: var(--bg-panel);
    border: 1px solid rgba(255, 255, 255, 0.15);
    border-radius: 10px;
    width: 850px;
    max-width: 95vw;
    height: 600px;
    max-height: 90vh;
    display: flex;
    flex-direction: column;
    box-shadow: 0 20px 50px rgba(0, 0, 0, 0.8), 0 0 20px rgba(200, 164, 93, 0.15);
    overflow: hidden;
}
.logic-modal-header {
    padding: 14px 20px;
    border-bottom: 1px solid var(--border);
    display: flex;
    justify-content: space-between;
    align-items: center;
    background: #11151f;
}
.logic-modal-header h2 {
    margin: 0;
    font-size: 1.05rem;
    color: var(--text-bright);
    display: flex;
    align-items: center;
    gap: 10px;
}
.logic-modal-header .btn-close {
    background: transparent;
    border: none;
    color: var(--text-dim);
    font-size: 1.2rem;
    cursor: pointer;
    transition: color 0.2s;
}
.logic-modal-header .btn-close:hover {
    color: #ff4757;
}
.logic-modal-body {
    display: flex;
    flex: 1;
    overflow: hidden;
}
.templates-sidebar {
    width: 220px;
    background: #0f141c;
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    padding: 10px 0;
    overflow-y: auto;
}
.template-cat-btn {
    background: transparent;
    border: none;
    color: var(--text-dim);
    padding: 12px 20px;
    text-align: left;
    font-size: 0.88rem;
    font-family: var(--font-ui);
    cursor: pointer;
    transition: all 0.2s;
    display: flex;
    align-items: center;
    gap: 10px;
}
.template-cat-btn:hover {
    background: rgba(255, 255, 255, 0.05);
    color: var(--text-main);
}
.template-cat-btn.active {
    background: rgba(200, 164, 93, 0.15);
    color: var(--accent);
    border-left: 3px solid var(--accent);
}
.templates-content {
    flex: 1;
    padding: 20px;
    overflow-y: auto;
    background: var(--bg-panel);
}
.templates-content h3 {
    margin-top: 0;
    color: var(--text-main);
    border-bottom: 1px solid var(--border);
    padding-bottom: 10px;
    margin-bottom: 20px;
    font-size: 1rem;
}
.templates-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
    gap: 15px;
}
.template-card {
    background: var(--bg-dark);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 15px;
    display: flex;
    flex-direction: column;
    transition: transform 0.2s, border-color 0.2s;
}
.template-card:hover {
    transform: translateY(-2px);
    border-color: rgba(200, 164, 93, 0.4);
}
.template-card h4 {
    margin: 0 0 8px 0;
    color: var(--accent);
    font-size: 0.95rem;
}
.template-card p {
    font-size: 0.82rem;
    color: var(--text-dim);
    margin: 0 0 14px 0;
    line-height: 1.4;
    flex: 1;
}
.load-template-btn {
    width: 100%;
}

/* Confirm Modal Box Specific */
.confirm-modal-box {
    width: 440px;
    height: auto;
    max-height: 85vh;
}

/* ---------------- 6. TOAST NOTIFICATIONS ---------------- */
.toast-container {
    position: fixed;
    top: 20px;
    right: 20px;
    z-index: 100000;
    display: flex;
    flex-direction: column;
    gap: 10px;
    pointer-events: none;
}

.toast {
    pointer-events: auto;
    min-width: 280px;
    max-width: 400px;
    background: #141822;
    border: 1px solid rgba(255, 255, 255, 0.18);
    border-radius: 8px;
    padding: 12px 16px;
    display: flex;
    align-items: flex-start;
    gap: 12px;
    box-shadow: 0 12px 35px rgba(0, 0, 0, 0.7), 0 0 15px rgba(200, 164, 93, 0.15);
    color: #fff;
    font-family: var(--font-ui);
    animation: toastSlideIn 0.3s cubic-bezier(0.16, 1, 0.3, 1) forwards;
    transition: opacity 0.3s ease, transform 0.3s ease;
}

.toast.toast-hiding {
    opacity: 0;
    transform: translateX(30px);
}

.toast-icon {
    font-size: 1.2rem;
    margin-top: 2px;
}

.toast-success .toast-icon { color: #2ea043; }
.toast-info .toast-icon { color: var(--accent); }
.toast-warning .toast-icon { color: #ffbd2e; }
.toast-error .toast-icon { color: #ff4757; }

.toast-body {
    flex: 1;
}

.toast-title {
    font-weight: 600;
    font-size: 0.85rem;
    color: #fff;
    margin-bottom: 2px;
}

.toast-desc {
    font-size: 0.78rem;
    color: var(--text-muted);
    line-height: 1.35;
}

.toast-close {
    background: transparent;
    border: none;
    color: var(--text-muted);
    font-size: 1rem;
    cursor: pointer;
    padding: 0;
    margin-left: 5px;
    transition: color 0.15s;
}

.toast-close:hover {
    color: #fff;
}

/* ---------------- Template filter + badges (hybrid workshop) ---------------- */
.tpl-filter {
    display: flex;
    background: var(--bg-dark);
    border: 1px solid var(--border);
    border-radius: 6px;
    overflow: hidden;
    margin-left: auto;
    margin-right: 12px;
    flex-shrink: 0;
}
.tpl-filter button {
    background: transparent;
    border: none;
    color: var(--text-muted);
    font-family: var(--font-ui);
    font-size: 0.72rem;
    font-weight: 700;
    letter-spacing: 0.4px;
    padding: 6px 12px;
    cursor: pointer;
    transition: all 0.15s;
}
.tpl-filter button + button {
    border-left: 1px solid var(--border);
}
.tpl-filter button:hover {
    color: #fff;
    background: rgba(255, 255, 255, 0.06);
}
.tpl-filter button.active {
    background: var(--accent);
    color: #000;
}
.tpl-badge {
    display: inline-block;
    vertical-align: middle;
    font-size: 0.58rem;
    font-weight: 800;
    letter-spacing: 0.6px;
    padding: 2px 7px;
    border-radius: 4px;
    margin-left: 8px;
    font-family: var(--font-ui);
}
.tpl-badge.b-off {
    background: rgba(200, 164, 93, 0.18);
    color: var(--accent);
    border: 1px solid rgba(200, 164, 93, 0.45);
}
.tpl-badge.b-com {
    background: rgba(88, 101, 242, 0.16);
    color: #8b9bff;
    border: 1px solid rgba(88, 101, 242, 0.5);
}
.tpl-badge.b-yours {
    background: rgba(46, 160, 67, 0.16);
    color: #3fb950;
    border: 1px solid rgba(46, 160, 67, 0.5);
}

@keyframes toastSlideIn {
    from {
        opacity: 0;
        transform: translateX(40px);
    }
    to {
        opacity: 1;
        transform: translateX(0);
    }
}
