/* ============================================================
   SamCoding IDE — Premium Design Token System
   ============================================================ */

:root {
    /* — Surface — */
    --ide-surface-base: #f8f9fb;
    --ide-surface-editor: #ffffff;
    --ide-surface-panel: #f2f4f7;
    --ide-surface-header: #eceef2;
    --ide-surface-toolbar: #f4f5f8;
    --ide-surface-statusbar: #eceef2;
    --ide-surface-hover: #e8eaef;
    --ide-surface-active: #dfe2e8;

    /* — Border — */
    --ide-border: #dce0e6;
    --ide-border-subtle: #e8eaef;
    --ide-border-focus: #5b8def;

    /* — Text — */
    --ide-text-primary: #1a1d23;
    --ide-text-secondary: #5a6069;
    --ide-text-tertiary: #858b95;
    --ide-text-inverse: #ffffff;

    /* — Accent — */
    --ide-accent: #2563d4;
    --ide-accent-hover: #1d4fad;
    --ide-accent-subtle: rgba(37, 99, 212, 0.08);

    /* — Semantic — */
    --ide-success: #16853e;
    --ide-success-bg: rgba(22, 133, 62, 0.08);
    --ide-danger: #d32f2f;
    --ide-danger-bg: rgba(211, 47, 47, 0.06);
    --ide-warning: #b8860b;
    --ide-warning-bg: rgba(184, 134, 11, 0.07);

    /* — Resize — */
    --ide-resize-surface: #e4e7ec;
    --ide-resize-grip: #b0b7c3;
    --ide-resize-active: #5b8def;

    /* — Scrollbar — */
    --ide-scrollbar: #c5c9d0;
    --ide-scrollbar-hover: #a0a6af;

    /* — Misc — */
    --ide-kbd-bg: rgba(0, 0, 0, 0.06);
    --ide-kbd-border: rgba(0, 0, 0, 0.1);
    --ide-shadow-dropdown: 0 4px 16px rgba(0, 0, 0, 0.08), 0 1px 4px rgba(0, 0, 0, 0.04);

    /* — Transition — */
    --ide-transition: 150ms ease;
}

[data-bs-theme="dark"] {
    /* — Surface — */
    --ide-surface-base: #0d0e13;
    --ide-surface-editor: #111218;
    --ide-surface-panel: #14151c;
    --ide-surface-header: #191a22;
    --ide-surface-toolbar: #111218;
    --ide-surface-statusbar: #0d0e13;
    --ide-surface-hover: #1e1f28;
    --ide-surface-active: #252630;

    /* — Toolbar btn — */
    --ide-toolbar-btn-bg: #1e2030;

    /* — Border — */
    --ide-border: #222330;
    --ide-border-subtle: #1a1b24;
    --ide-border-focus: #5b8def;

    /* — Text — */
    --ide-text-primary: #e8eaf0;
    --ide-text-secondary: #a0a4b0;
    --ide-text-tertiary: #6a6e7a;
    --ide-text-inverse: #0d0e13;

    /* — Accent — */
    --ide-accent: #5b8def;
    --ide-accent-hover: #7aa3f5;
    --ide-accent-subtle: rgba(91, 141, 239, 0.1);

    /* — Semantic — */
    --ide-success: #3dba6a;
    --ide-success-bg: rgba(61, 186, 106, 0.1);
    --ide-danger: #e86060;
    --ide-danger-bg: rgba(232, 96, 96, 0.1);
    --ide-warning: #d4a633;
    --ide-warning-bg: rgba(212, 166, 51, 0.1);

    /* — Resize — */
    --ide-resize-surface: #1a1b24;
    --ide-resize-grip: #353840;
    --ide-resize-active: #5b8def;

    /* — Scrollbar — */
    --ide-scrollbar: #282a34;
    --ide-scrollbar-hover: #383b46;

    /* — Misc — */
    --ide-kbd-bg: rgba(255, 255, 255, 0.06);
    --ide-kbd-border: rgba(255, 255, 255, 0.08);
    --ide-shadow-dropdown: 0 4px 20px rgba(0, 0, 0, 0.3), 0 1px 6px rgba(0, 0, 0, 0.2);
}


/* ============================================================
   Layout
   ============================================================ */

html, body {
    height: 100%;
    overflow: hidden;
}

.wrapper {
    height: 100vh;
    display: flex;
    flex-direction: column;
    background: var(--ide-surface-base);
}

.content-page {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    margin: 0 !important;
    padding: 0 !important;
}


/* ============================================================
   Toolbar
   ============================================================ */

.ide-toolbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 5px 10px;
    border-bottom: 1px solid var(--ide-border);
    background: var(--ide-surface-toolbar);
    flex-shrink: 0;
    gap: 6px;
    flex-wrap: wrap;
}

.ide-lang-select {
    width: auto;
    min-width: 155px;
    max-width: 220px;
    font-size: 13px;
    height: 30px;
    padding: 0 28px 0 8px;
    border: 1px solid var(--ide-border);
    border-radius: 4px;
    background: var(--ide-surface-editor);
    color: var(--ide-text-primary);
    transition: border-color var(--ide-transition);
    cursor: pointer;
}

.ide-lang-select:focus {
    border-color: var(--ide-border-focus);
    outline: none;
    box-shadow: 0 0 0 2px var(--ide-accent-subtle);
}

.ide-lang-select:hover {
    border-color: var(--ide-text-tertiary);
}

/* Toolbar buttons — uniform height */
.ide-toolbar .btn {
    font-size: 13px;
    padding: 0 10px;
    height: 30px;
    border-radius: 4px;
    transition: all var(--ide-transition);
    display: inline-flex;
    align-items: center;
}

.ide-toolbar .btn-sm {
    line-height: 1;
}

.ide-toolbar .btn-outline-secondary {
    color: var(--ide-text-secondary);
    border-color: var(--ide-border);
    background: var(--ide-toolbar-btn-bg, var(--ide-surface-editor));
}

.ide-toolbar .btn-outline-secondary:hover {
    color: var(--ide-text-primary);
    background: var(--ide-surface-hover);
    border-color: var(--ide-text-tertiary);
}

.ide-toolbar .btn-outline-secondary:active {
    background: var(--ide-surface-active);
}

.ide-toolbar .btn-success {
    background: var(--ide-success);
    border-color: var(--ide-success);
    color: var(--ide-text-inverse);
}

.ide-toolbar .btn-success:hover {
    filter: brightness(1.08);
}

.ide-toolbar .btn-success:active {
    filter: brightness(0.95);
}

.ide-toolbar kbd {
    font-size: 11px;
    padding: 1px 5px;
    background: var(--ide-kbd-bg);
    border: 1px solid var(--ide-kbd-border);
    border-radius: 3px;
    font-family: inherit;
}


/* ============================================================
   IDE Container & Panels
   ============================================================ */

.ide-container {
    flex: 1;
    display: flex;
    overflow: hidden;
    min-height: 0;
}

.ide-panel {
    display: flex;
    flex-direction: column;
    min-width: 0;
    min-height: 0;
    overflow: hidden;
}

.ide-editor-panel {
    flex: 1 1 60%;
    background: var(--ide-surface-editor);
}

.ide-io-panel {
    flex: 0 0 35%;
    min-width: 240px;
    display: flex;
    flex-direction: column;
    background: var(--ide-surface-editor);
}

.ide-editor {
    flex: 1;
    min-height: 0;
}


/* ============================================================
   Resize Handles
   ============================================================ */

.ide-resize-handle {
    flex-shrink: 0;
    background: var(--ide-resize-surface);
    position: relative;
    z-index: 10;
    transition: background var(--ide-transition);
}

.ide-resize-handle:hover,
.ide-resize-handle.active {
    background: var(--ide-accent-subtle);
}

/* Vertikal (editor | io) */
.ide-resize-v {
    width: 8px;
    cursor: col-resize;
    display: flex;
    align-items: center;
    justify-content: center;
    border-left: 1px solid var(--ide-border);
    border-right: 1px solid var(--ide-border);
}

.ide-resize-v::after {
    content: "···";
    position: absolute;
    left: 50%;
    transform: translateX(-50%) rotate(90deg);
    font-size: 14px;
    letter-spacing: 2px;
    color: var(--ide-resize-grip);
    transition: color var(--ide-transition);
    line-height: 1;
}

.ide-resize-v:hover::after,
.ide-resize-v.active::after {
    color: var(--ide-resize-active);
}

/* Gorizontal (input | output) */
.ide-resize-h {
    height: 8px;
    cursor: row-resize;
    display: flex;
    align-items: center;
    justify-content: center;
    border-top: 1px solid var(--ide-border);
    border-bottom: 1px solid var(--ide-border);
}

.ide-resize-h::after {
    content: "···";
    position: absolute;
    top: 50%;
    transform: translateY(-50%);
    font-size: 14px;
    letter-spacing: 2px;
    color: var(--ide-resize-grip);
    transition: color var(--ide-transition);
    line-height: 1;
}

.ide-resize-h:hover::after,
.ide-resize-h.active::after {
    color: var(--ide-resize-active);
}


/* ============================================================
   Input / Output
   ============================================================ */

.ide-io-section {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-height: 0;
    overflow: hidden;
}

.ide-io-header {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 5px 10px;
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.6px;
    color: var(--ide-text-tertiary);
    background: var(--ide-surface-header);
    border-bottom: 1px solid var(--ide-border-subtle);
    flex-shrink: 0;
    user-select: none;
}

.ide-io-header i {
    font-size: 13px;
    opacity: 0.6;
}

.ide-io-textarea {
    flex: 1;
    width: 100%;
    border: none;
    outline: none;
    resize: none;
    padding: 8px 12px;
    font-family: 'JetBrains Mono', 'Cascadia Code', 'Fira Code', 'Source Code Pro', 'SF Mono', Consolas, monospace;
    font-size: 13px;
    line-height: 1.6;
    background: var(--ide-surface-editor);
    color: var(--ide-text-primary);
    min-height: 0;
    tab-size: 4;
}

.ide-io-textarea::placeholder {
    color: var(--ide-text-tertiary);
    opacity: 0.7;
}

.ide-io-textarea:focus {
    background: var(--ide-surface-editor);
}

.ide-io-output {
    flex: 1;
    padding: 8px 12px;
    font-family: 'JetBrains Mono', 'Cascadia Code', 'Fira Code', 'Source Code Pro', 'SF Mono', Consolas, monospace;
    font-size: 13px;
    line-height: 1.6;
    overflow: auto;
    white-space: pre-wrap;
    word-break: break-all;
    background: var(--ide-surface-editor);
    color: var(--ide-text-primary);
    min-height: 0;
    tab-size: 4;
}

.ide-output-empty {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    height: 100%;
    gap: 10px;
    color: var(--ide-text-tertiary);
    opacity: 0.5;
}

.ide-output-empty i {
    font-size: 36px;
}

.ide-output-empty span {
    font-size: 13px;
}

/* Output status */
.ide-output-success {
    color: var(--ide-success);
}

.ide-output-error {
    color: var(--ide-danger);
}

.ide-output-warning {
    color: var(--ide-warning);
}


/* ============================================================
   Statusbar
   ============================================================ */

.ide-statusbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 2px 12px;
    border-top: 1px solid var(--ide-border);
    background: var(--ide-surface-statusbar);
    flex-shrink: 0;
    font-size: 11px;
    color: var(--ide-text-tertiary);
    user-select: none;
}

.ide-statusbar .text-muted {
    color: var(--ide-text-tertiary) !important;
}


/* ============================================================
   Run Button Animation
   ============================================================ */

#btn-run.running {
    pointer-events: none;
    opacity: 0.75;
}

#btn-run.running i {
    animation: ide-spin 0.8s linear infinite;
}

@keyframes ide-spin {
    from { transform: rotate(0deg); }
    to { transform: rotate(360deg); }
}


/* ============================================================
   Scrollbar
   ============================================================ */

.ide-io-output::-webkit-scrollbar,
.ide-io-textarea::-webkit-scrollbar {
    width: 6px;
    height: 6px;
}

.ide-io-output::-webkit-scrollbar-track,
.ide-io-textarea::-webkit-scrollbar-track {
    background: transparent;
}

.ide-io-output::-webkit-scrollbar-thumb,
.ide-io-textarea::-webkit-scrollbar-thumb {
    background: var(--ide-scrollbar);
    border-radius: 3px;
}

.ide-io-output::-webkit-scrollbar-thumb:hover,
.ide-io-textarea::-webkit-scrollbar-thumb:hover {
    background: var(--ide-scrollbar-hover);
}

.ide-io-output::-webkit-scrollbar-corner,
.ide-io-textarea::-webkit-scrollbar-corner {
    background: transparent;
}


/* ============================================================
   Monaco Editor Overrides
   ============================================================ */

.monaco-host {
    width: 100%;
    height: 100%;
}


/* ============================================================
   Mobile Responsive (< 768px)
   ============================================================ */

@media (max-width: 768px) {
    .ide-container {
        flex-direction: column;
    }

    .ide-resize-v {
        width: 100%;
        height: 8px;
        cursor: row-resize;
        border-left: none;
        border-right: none;
        border-top: 1px solid var(--ide-border);
        border-bottom: 1px solid var(--ide-border);
    }

    .ide-resize-v::after {
        width: 32px;
        height: 3px;
        left: 50%;
        top: 50%;
        transform: translate(-50%, -50%);
    }

    .ide-io-panel {
        flex: 0 0 40%;
        min-width: unset;
        min-height: 140px;
    }

    .ide-lang-select {
        min-width: 120px;
    }

    .ide-toolbar {
        padding: 4px 8px;
    }
}


/* ============================================================
   Run Status Text
   ============================================================ */

#run-status {
    color: var(--ide-text-tertiary);
    font-size: 12px;
}


/* ============================================================
   Toolbar — Brand, Theme Toggle, Locale
   ============================================================ */

.ide-toolbar-brand {
    display: flex;
    align-items: center;
    text-decoration: none;
    flex-shrink: 0;
    margin-right: 4px;
}

.ide-toolbar-icon {
    width: 30px;
    height: 30px;
    padding: 0;
    display: inline-flex;
    align-items: center;
    justify-content: center;
}

.ide-toolbar-sep {
    width: 1px;
    height: 18px;
    background: var(--ide-border);
    margin: 0 2px;
    flex-shrink: 0;
}

.ide-locale-wrap {
    display: flex;
    align-items: center;
}

.ide-locale-select {
    appearance: none;
    -webkit-appearance: none;
    border: 1px solid var(--ide-border);
    border-radius: 4px;
    background: var(--ide-toolbar-btn-bg, var(--ide-surface-editor));
    color: var(--ide-text-secondary);
    font-size: 11px;
    font-weight: 600;
    padding: 0 6px;
    height: 30px;
    cursor: pointer;
    letter-spacing: 0.5px;
    transition: all var(--ide-transition);
    width: auto;
    line-height: 30px;
}

.ide-locale-select:hover {
    color: var(--ide-text-primary);
    border-color: var(--ide-text-tertiary);
}

.ide-locale-select:focus {
    outline: none;
    border-color: var(--ide-border-focus);
    box-shadow: 0 0 0 2px var(--ide-accent-subtle);
}

.ide-output-stats {
    color: var(--ide-text-tertiary);
    font-size: 11px;
}


/* ============================================================
   Loading Screen — Neon Geometric Lines
   ============================================================ */

:root {
    --ide-neon-blue: #1a6fff;
    --ide-neon-cyan: #00e5ff;
    --ide-neon-bg: #f8f9fb;
}

[data-bs-theme="dark"] {
    --ide-neon-blue: #2979ff;
    --ide-neon-cyan: #00e5ff;
    --ide-neon-bg: #0d0e13;
}

.ide-loading {
    position: fixed;
    inset: 0;
    z-index: 10000;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--ide-neon-bg);
    transition: opacity 0.5s ease, visibility 0.5s ease;
}

.ide-loading.ide-loading-done {
    opacity: 0;
    visibility: hidden;
    pointer-events: none;
}

.ide-loading-content {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 28px;
    max-width: 340px;
    width: 100%;
    padding: 0 16px;
}

/* Neon motion container */
.ide-loading-motion {
    width: 220px;
    height: 170px;
    opacity: 0;
    transform: translateY(10px) scale(0.95);
    animation: ide-load-fadein 0.8s ease 0.1s forwards;
}

.ide-motion-svg {
    width: 100%;
    height: 100%;
    overflow: visible;
}

/* Neon lines — chasing around triangle path */
.ide-neon-line {
    will-change: stroke-dashoffset;
}

/* perimeter ~860 for outer, ~740 inner, ~600 accent */
.ide-neon-outer {
    stroke-dasharray: 500 360;
    animation: ide-neon-chase-outer 6s linear infinite;
}

.ide-neon-inner {
    stroke-dasharray: 430 310;
    animation: ide-neon-chase-inner 5s linear infinite;
}

.ide-neon-accent {
    stroke-dasharray: 350 250;
    animation: ide-neon-chase-accent 7s linear infinite;
}

@keyframes ide-neon-chase-outer {
    from { stroke-dashoffset: 0; }
    to { stroke-dashoffset: -860; }
}

@keyframes ide-neon-chase-inner {
    from { stroke-dashoffset: 0; }
    to { stroke-dashoffset: -740; }
}

@keyframes ide-neon-chase-accent {
    from { stroke-dashoffset: 0; }
    to { stroke-dashoffset: -600; }
}

/* Traveling light dots */
.ide-neon-traveler {
    opacity: 0;
    animation: ide-neon-traveler-appear 0.3s ease 1.5s forwards;
}
.ide-neon-traveler-2 {
    animation-delay: 2s;
}

@keyframes ide-neon-traveler-appear {
    to { opacity: 1; }
}

/* Corner nodes pulse */
.ide-neon-node {
    opacity: 0;
    animation: ide-neon-node-in 0.5s ease forwards;
}
.ide-neon-node-1 { animation-delay: 1.8s; }
.ide-neon-node-2 { animation-delay: 1.2s; }
.ide-neon-node-3 { animation-delay: 2.0s; }

@keyframes ide-neon-node-in {
    to { opacity: 0.8; }
}

/* Status text */
.ide-loading-status {
    font-size: 12px;
    color: var(--ide-text-tertiary);
    text-align: center;
    opacity: 0;
    animation: ide-load-fadein 0.4s ease 1s forwards;
    min-height: 1.4em;
}

/* Progress bar */
.ide-loading-progress {
    width: 100%;
    max-width: 200px;
    height: 2px;
    background: var(--ide-border-subtle);
    border-radius: 1px;
    overflow: hidden;
    opacity: 0;
    animation: ide-load-fadein 0.4s ease 1.2s forwards;
}

.ide-loading-bar {
    height: 100%;
    width: 0%;
    background: linear-gradient(90deg, #4A90D9, #C850C0, #FF6B9D);
    border-radius: 1px;
    animation: ide-loading-indeterminate 2s ease-in-out infinite;
}

@keyframes ide-loading-indeterminate {
    0% { width: 0%; margin-left: 0%; }
    50% { width: 40%; margin-left: 30%; }
    100% { width: 0%; margin-left: 100%; }
}

.ide-loading-bar.ide-loading-determinate {
    animation: none;
    transition: width 0.3s ease;
}

@keyframes ide-load-fadein {
    to { opacity: 1; transform: translateY(0) scale(1); }
}

/* Error state */
.ide-loading-error {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 12px;
    color: var(--ide-text-secondary);
    font-size: 13px;
    text-align: center;
}

.ide-loading-retry {
    border: 1px solid var(--ide-border);
    background: transparent;
    color: var(--ide-text-primary);
    padding: 6px 16px;
    border-radius: 4px;
    font-size: 13px;
    cursor: pointer;
    transition: all var(--ide-transition);
}

.ide-loading-retry:hover {
    background: var(--ide-surface-hover);
    border-color: var(--ide-text-tertiary);
}

/* Reduced motion */
@media (prefers-reduced-motion: reduce) {
    .ide-loading-motion,
    .ide-loading-brand,
    .ide-loading-progress,
    .ide-loading-status {
        opacity: 1 !important;
        transform: none !important;
        animation: none !important;
    }
    .ide-neon-outer,
    .ide-neon-inner,
    .ide-neon-accent {
        animation: none !important;
    }
    .ide-neon-traveler,
    .ide-neon-node {
        animation: none !important;
        opacity: 0.7 !important;
    }
    .ide-loading-bar {
        animation: none !important;
        width: 60% !important;
    }
}

/* Stop animations after loading done */
.ide-loading-done .ide-motion-svg * {
    animation-play-state: paused !important;
}

/* App reveal */
#ide-app {
    transition: opacity 0.3s ease;
}

#ide-app.ide-app-ready {
    opacity: 1 !important;
}
