:root {
    --primary: #00adee;
    --primary-dark: #008fc4;
    --primary-soft: #e9f8fe;
    --text: #12233d;
    --muted: #637083;
    --bg: #f4f9fc;
    --card: #ffffff;
    --border: #d7e8f1;
    --border-strong: #bddce9;
    --danger: #df2b21;
    --success: #087443;
    --warning: #8a5a00;
    --shadow: 0 14px 36px rgba(31, 83, 112, .08);
    --radius: 16px;
}

* { box-sizing: border-box; }
html { min-height: 100%; }
body {
    min-height: 100vh;
    margin: 0;
    display: flex;
    flex-direction: column;
    font-family: Inter, Arial, Helvetica, sans-serif;
    color: var(--text);
    background: var(--bg);
}
main { flex: 1; min-width: 0; }
a { color: var(--primary-dark); text-decoration: none; }
a:hover { color: #006e98; }
button, input, textarea { font: inherit; }
.container { width: min(1120px, calc(100% - 36px)); margin: 0 auto; }

.topbar {
    background: rgba(255,255,255,.96);
    border-bottom: 1px solid var(--border);
    position: sticky;
    top: 0;
    z-index: 40;
    backdrop-filter: blur(10px);
}
.nav-wrap {
    min-height: 68px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 24px;
}
.brand { display: flex; align-items: center; gap: 10px; font-weight: 800; color: var(--text); font-size: 18px; }
.brand-mark {
    width: 38px; height: 38px; border-radius: 11px;
    display: grid; place-items: center; background: var(--primary); color: white;
    box-shadow: 0 8px 18px rgba(0,173,238,.22);
}
nav { display: flex; align-items: center; gap: 18px; }
nav > a:not(.btn) { color: #42526a; font-weight: 700; font-size: 14px; }

.btn {
    display: inline-flex; align-items: center; justify-content: center;
    gap: 7px; min-height: 42px;
    border: 1px solid var(--primary); border-radius: 10px; padding: 10px 17px;
    background: var(--primary); color: white; font-weight: 800; cursor: pointer;
    transition: transform .15s ease, box-shadow .15s ease, background .15s ease;
}
.btn:hover { background: var(--primary-dark); color: white; transform: translateY(-1px); }
.btn-secondary { background: white; color: var(--text); border-color: var(--border-strong); }
.btn-secondary:hover { background: #f7fbfd; color: var(--text); }
.btn-danger { background: var(--danger); border-color: var(--danger); }
.btn-small { min-height: 36px; padding: 7px 12px; font-size: 13px; }
.btn-block { width: 100%; }

.hero { padding: 80px 0 52px; text-align: center; }
.hero h1 { margin: 0 0 16px; font-size: clamp(36px, 6vw, 64px); }
.hero p { max-width: 760px; margin: 0 auto 26px; color: var(--muted); font-size: 19px; line-height: 1.7; }
.actions, .toolbar, .form-actions, .two-button-row { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.actions { justify-content: center; }
.section, .page-section { padding: 38px 0 72px; }
.grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 20px; }
.card {
    background: var(--card); border: 1px solid var(--border);
    border-radius: var(--radius); padding: 24px; box-shadow: var(--shadow);
}
.card h2, .card h3 { margin-top: 0; }
.form-card { max-width: 680px; margin: 48px auto; }
.form-group { margin-bottom: 18px; }
label { display: block; margin-bottom: 8px; font-weight: 800; }
input[type="text"], input[type="email"], input[type="password"], input[type="file"] {
    width: 100%; min-height: 44px; padding: 11px 13px;
    border: 1px solid var(--border-strong); border-radius: 10px; background: white; color: var(--text);
}
input:focus, textarea:focus { outline: 3px solid rgba(0,173,238,.14); border-color: var(--primary); }
.help { margin-top: 8px; font-size: 13px; color: var(--muted); line-height: 1.55; }
.alert { padding: 12px 14px; border-radius: 10px; margin-bottom: 18px; }
.alert-error { background: #fef3f2; color: #b42318; border: 1px solid #fecdca; }
.alert-success { background: #ecfdf3; color: var(--success); border: 1px solid #abefc6; }
.dashboard-head, .page-heading {
    padding: 42px 0 24px; display: flex; justify-content: space-between; align-items: center; gap: 24px;
}
.dashboard-head h1, .page-heading h1 { margin: 0 0 8px; font-size: clamp(28px, 4vw, 38px); }
.page-heading p, .dashboard-head p { margin: 0; color: var(--muted); line-height: 1.6; }
.compact-heading { max-width: 820px; margin: 0 auto; }
.eyebrow { display: block; margin-bottom: 7px; color: var(--primary-dark); font-size: 12px; font-weight: 900; letter-spacing: .09em; text-transform: uppercase; }
.projects { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 18px; padding-bottom: 70px; }
.projects .card { min-width: 0; }
.project-meta { color: var(--muted); font-size: 14px; line-height: 1.75; overflow-wrap: anywhere; }
.project-actions { display: flex; gap: 9px; flex-wrap: wrap; margin-top: 18px; }
.empty { text-align: center; padding: 52px 24px; }
.code { font-family: Consolas, Monaco, monospace; background: #eff8fc; padding: 3px 7px; border-radius: 6px; }
.footer { border-top: 1px solid var(--border); background: white; color: var(--muted); padding: 22px 0; text-align: center; }
.checkbox-row { display:flex; gap:10px; align-items:flex-start; }

.create-project-card { max-width: 820px; margin: 0 auto; padding: 30px; }
.upload-choice {
    display: flex; gap: 16px; align-items: flex-start;
    padding: 18px; margin: 4px 0 24px;
    border: 1px dashed #9ed8ed; border-radius: 14px; background: #f8fdff;
}
.upload-choice-icon {
    width: 44px; height: 44px; border-radius: 12px; flex: none;
    display: grid; place-items: center; background: var(--primary-soft); color: var(--primary-dark); font-size: 24px; font-weight: 900;
}
.upload-choice-content { flex: 1; margin: 0; min-width: 0; }
.optional-text { margin-left: 6px; color: var(--muted); font-size: 12px; font-weight: 700; }

/* Workspace */
.workspace-page { padding: 0 24px 30px; }
.workspace-topbar {
    min-height: 88px; display: flex; align-items: center; justify-content: space-between; gap: 22px;
    width: min(1500px, 100%); margin: 0 auto; padding: 16px 0;
}
.workspace-title-area { display: flex; align-items: center; gap: 14px; min-width: 0; }
.workspace-back {
    width: 40px; height: 40px; border: 1px solid var(--border); border-radius: 10px;
    display: grid; place-items: center; background: white; color: var(--text); font-size: 21px; flex: none;
}
.workspace-title-line { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.workspace-title-line h1 { margin: 0; font-size: 22px; }
.workspace-url { display: block; margin-top: 4px; color: var(--muted); font-size: 13px; overflow-wrap: anywhere; }
.status-pill { padding: 4px 8px; border-radius: 999px; background: #eafaf2; color: var(--success); font-size: 11px; font-weight: 900; }
.workspace-actions { display: flex; gap: 9px; flex-wrap: wrap; justify-content: flex-end; }
.workspace-alert { width: min(1500px, 100%); margin: 0 auto 12px; }
.ide-shell {
    width: min(1500px, 100%); height: calc(100vh - 190px); min-height: 610px; margin: 0 auto;
    display: grid; grid-template-columns: 270px minmax(420px, 1fr) minmax(300px, 38%);
    border: 1px solid #cadde7; border-radius: 16px; overflow: hidden; background: white;
    box-shadow: 0 18px 46px rgba(25, 70, 96, .12);
}
.ide-sidebar, .preview-pane { min-width: 0; background: #f8fbfd; }
.ide-sidebar { display: flex; flex-direction: column; border-right: 1px solid var(--border); }
.ide-sidebar-head, .preview-head, .editor-toolbar {
    min-height: 62px; display: flex; align-items: center; justify-content: space-between; gap: 14px;
    padding: 11px 14px; border-bottom: 1px solid var(--border); background: white;
}
.ide-sidebar-head strong, .preview-head strong { display: block; margin-top: 2px; font-size: 14px; }
.ide-kicker { display: block; color: var(--muted); font-size: 10px; font-weight: 900; letter-spacing: .1em; }
.icon-button {
    width: 34px; height: 34px; border: 1px solid var(--border); border-radius: 9px; display: grid; place-items: center;
    background: white; color: var(--text); cursor: pointer; font-size: 18px;
}
.icon-button:hover { border-color: var(--primary); color: var(--primary-dark); }
.file-tree { flex: 1; min-height: 0; overflow: auto; padding: 8px 0; }
.tree-row { min-height: 34px; display: flex; align-items: center; padding-right: 8px; }
.tree-row:hover { background: #eef8fc; }
.tree-row.active { background: #dff5fd; box-shadow: inset 3px 0 0 var(--primary); }
.tree-indent { width: calc(var(--tree-level) * 16px); flex: none; }
.tree-folder-toggle, .tree-file-link {
    min-width: 0; flex: 1; height: 34px; display: flex; align-items: center; gap: 7px;
    padding: 0 7px; border: 0; background: transparent; color: #2b3d55; text-align: left; cursor: pointer; font-size: 13px;
}
.tree-file-link:hover { color: var(--text); }
.tree-chevron { width: 13px; transition: transform .15s ease; }
.tree-folder-toggle[aria-expanded="false"] .tree-chevron { transform: rotate(-90deg); }
.tree-symbol { width: 18px; text-align: center; color: var(--primary-dark); }
.tree-label { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tree-children.is-collapsed { display: none; }
.tree-empty { padding: 30px 16px; color: var(--muted); text-align: center; font-size: 13px; }
.sidebar-bottom-actions { border-top: 1px solid var(--border); padding: 9px; display: grid; gap: 4px; background: white; }
.sidebar-action {
    display: flex; align-items: center; gap: 9px; min-height: 36px; padding: 7px 9px; border-radius: 8px;
    color: #42526a; font-size: 13px; font-weight: 700; background: transparent; border: 0; cursor: pointer; text-align: left;
}
.sidebar-action:hover { background: var(--primary-soft); color: var(--primary-dark); }
.ide-main { min-width: 0; min-height: 0; background: #0f172a; }
.editor-form, .asset-preview-panel { height: 100%; display: flex; flex-direction: column; min-height: 0; }
.editor-toolbar { background: #fff; }
.editor-file-info { display: flex; align-items: center; gap: 10px; min-width: 0; }
.editor-file-icon { width: 32px; height: 32px; border-radius: 9px; background: var(--primary-soft); color: var(--primary-dark); display: grid; place-items: center; flex: none; }
.editor-file-info div { min-width: 0; }
.editor-file-info strong, .editor-file-info span { display: block; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.editor-file-info strong { font-size: 14px; }
.editor-file-info span { margin-top: 2px; color: var(--muted); font-size: 11px; }
.editor-toolbar-actions { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; justify-content: flex-end; }
.save-state { color: var(--success); font-size: 12px; font-weight: 800; }
.save-state.unsaved { color: var(--warning); }
.workspace-code-editor {
    flex: 1; min-height: 0; width: 100%; resize: none; border: 0; border-radius: 0; padding: 20px;
    background: #0f172a; color: #e5edf6; font: 14px/1.65 Consolas, Monaco, "Courier New", monospace;
    tab-size: 4; outline: none;
}
.editor-empty-state { height: 100%; display: grid; place-content: center; justify-items: center; padding: 36px; text-align: center; background: white; color: var(--text); }
.editor-empty-state p { max-width: 470px; color: var(--muted); line-height: 1.6; }
.editor-empty-icon { width: 66px; height: 66px; display: grid; place-items: center; border-radius: 18px; background: var(--primary-soft); color: var(--primary-dark); font-size: 30px; }
.asset-preview-body { flex: 1; display: grid; place-items: center; padding: 24px; overflow: auto; background: #f6f9fb; }
.asset-preview-body img, .asset-preview-body video { max-width: 100%; max-height: 100%; border-radius: 10px; box-shadow: var(--shadow); }
.asset-preview-body audio { width: min(500px, 100%); }
.asset-placeholder { color: var(--muted); }
.preview-pane { display: flex; flex-direction: column; border-left: 1px solid var(--border); }
.live-preview-frame { width: 100%; flex: 1; min-height: 0; border: 0; background: white; }

.side-panel-backdrop { position: fixed; inset: 0; z-index: 70; background: rgba(15, 31, 48, .42); }
.side-panel {
    position: fixed; top: 0; right: 0; z-index: 80; width: min(430px, 94vw); height: 100vh;
    background: white; box-shadow: -20px 0 50px rgba(18, 45, 64, .2); transform: translateX(105%); transition: transform .2s ease;
    display: flex; flex-direction: column;
}
.side-panel.is-open { transform: translateX(0); }
.side-panel-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 18px; padding: 22px; border-bottom: 1px solid var(--border); }
.side-panel-head h2 { margin: 0; font-size: 22px; }
.side-panel-body { padding: 20px; overflow: auto; }
.tool-section { padding: 18px 0; border-bottom: 1px solid var(--border); }
.tool-section:first-child { padding-top: 0; }
.tool-section h3 { margin: 0 0 6px; }
.tool-section p { margin: 0 0 14px; color: var(--muted); font-size: 13px; line-height: 1.55; }
.file-input { margin-bottom: 12px; }
.two-button-row > * { flex: 1; }
.compact-tool-links { display: grid; gap: 8px; }
.compact-tool-links a { display: flex; justify-content: space-between; padding: 10px 0; font-weight: 800; }
.security-note { margin-top: 18px; padding: 14px; border-radius: 11px; background: #fff8e8; color: #735015; }
.security-note p { margin: 5px 0 0; font-size: 12px; line-height: 1.5; }
body.panel-open { overflow: hidden; }

@media (max-width: 1180px) {
    .ide-shell { grid-template-columns: 250px minmax(420px, 1fr); }
    .preview-pane { display: none; }
}
@media (max-width: 780px) {
    .container { width: min(100% - 24px, 1120px); }
    .grid, .projects { grid-template-columns: 1fr; }
    .nav-wrap, .dashboard-head, .page-heading, .workspace-topbar { align-items: flex-start; }
    .nav-wrap { padding: 14px 0; flex-direction: column; }
    nav { flex-wrap: wrap; }
    .workspace-page { padding: 0 10px 18px; }
    .workspace-topbar { flex-direction: column; }
    .workspace-actions { justify-content: flex-start; }
    .ide-shell { height: auto; min-height: 720px; grid-template-columns: 1fr; grid-template-rows: 250px 620px; }
    .ide-sidebar { border-right: 0; border-bottom: 1px solid var(--border); }
    .editor-toolbar { align-items: flex-start; flex-direction: column; }
    .editor-toolbar-actions { width: 100%; justify-content: flex-start; }
    .upload-choice { flex-direction: column; }
}
@media (max-width: 520px) {
    .card, .create-project-card { padding: 18px; }
    .btn { width: 100%; }
    .project-actions .btn, .project-actions form { width: 100%; }
    .project-actions form .btn { width: 100%; }
    .workspace-actions { width: 100%; }
    .workspace-actions .btn { flex: 1; width: auto; }
}


/* File explorer icons and VS Code-style actions */
.tree-node {
    min-width: 0;
}

.tree-row {
    position: relative;
    min-height: 36px;
    display: flex;
    align-items: center;
    padding-left: calc(10px + (var(--tree-level) * 17px));
    padding-right: 34px;
    border-radius: 0;
}

.tree-row:hover {
    background: #eaf6fb;
}

.tree-row.active {
    background: #d8f1fb;
}

.tree-folder-toggle,
.tree-file-link {
    min-width: 0;
    flex: 1;
    display: flex;
    align-items: center;
    gap: 8px;
    border: 0;
    background: transparent;
    color: #16233a;
    padding: 7px 4px;
    font: inherit;
    text-align: left;
    cursor: pointer;
    text-decoration: none;
}

.tree-label {
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.tree-more-button {
    position: absolute;
    right: 5px;
    top: 50%;
    width: 28px;
    height: 27px;
    display: grid;
    place-items: center;
    transform: translateY(-50%);
    border: 0;
    border-radius: 6px;
    background: transparent;
    color: #54657b;
    font-weight: 800;
    letter-spacing: -1px;
    opacity: 0;
    cursor: pointer;
}

.tree-row:hover .tree-more-button,
.tree-row:focus-within .tree-more-button {
    opacity: 1;
}

.tree-more-button:hover {
    background: #c9e8f5;
    color: #0b6f9d;
}

.tree-children.is-collapsed {
    display: none;
}

.file-type-icon {
    width: 20px;
    height: 20px;
    flex: none;
    display: inline-grid;
    place-items: center;
    border-radius: 5px;
    font-size: 10px;
    font-weight: 900;
    line-height: 1;
    background: #e8eef4;
    color: #56657a;
}

.icon-folder {
    background: transparent;
    color: #60738b;
    font-size: 15px;
}

.icon-html {
    background: #fff0e8;
    color: #e55b22;
}

.icon-css {
    background: #e8f2ff;
    color: #2478d4;
}

.icon-js {
    background: #fff8cf;
    color: #8f7600;
    font-size: 8px;
}

.icon-json {
    background: #f1edff;
    color: #6f52c7;
    font-size: 8px;
}

.icon-text {
    background: #eef2f6;
    color: #596a80;
}

.icon-svg,
.icon-image {
    background: #e9fbf0;
    color: #18864a;
}

.icon-pdf {
    background: #ffeded;
    color: #cc3030;
}

.icon-audio,
.icon-video {
    background: #f4edff;
    color: #794cc7;
}

.icon-font {
    background: #edf7ff;
    color: #2b6d9d;
}

.file-context-menu {
    position: fixed;
    z-index: 3000;
    width: 190px;
    padding: 6px;
    border: 1px solid #cadce7;
    border-radius: 9px;
    background: #ffffff;
    box-shadow: 0 15px 38px rgba(18, 45, 67, 0.22);
}

.file-context-menu[hidden] {
    display: none;
}

.file-context-menu button {
    width: 100%;
    min-height: 34px;
    display: flex;
    align-items: center;
    border: 0;
    border-radius: 6px;
    background: transparent;
    color: #172238;
    padding: 7px 10px;
    font: inherit;
    font-size: 13px;
    text-align: left;
    cursor: pointer;
}

.file-context-menu button:hover {
    background: #e8f5fb;
}

.file-context-menu button.danger {
    color: #c72f29;
}

.file-context-menu button.danger:hover {
    background: #fff0ef;
}

.context-separator {
    height: 1px;
    margin: 5px 2px;
    background: #e3ebf0;
}

/* Keep the editor and preview equal and stable */
.ide-shell {
    grid-template-columns: 270px minmax(420px, 1.2fr) minmax(380px, 1fr);
}

.ide-main,
.preview-pane {
    min-width: 0;
}

.live-preview-frame {
    width: 100%;
    height: 100%;
    border: 0;
    background: #ffffff;
}

.editor-file-info .file-type-icon {
    width: 32px;
    height: 32px;
    font-size: 12px;
}

@media (max-width: 1180px) {
    .ide-shell {
        grid-template-columns: 245px minmax(420px, 1fr);
    }

    .preview-pane {
        grid-column: 1 / -1;
        min-height: 600px;
        border-left: 0;
        border-top: 1px solid #d4e5ee;
    }
}

@media (max-width: 760px) {
    .ide-shell {
        grid-template-columns: 1fr;
    }

    .ide-sidebar {
        min-height: 280px;
        max-height: 360px;
    }

    .ide-main {
        min-height: 560px;
    }

    .preview-pane {
        min-height: 600px;
    }

    .tree-more-button {
        opacity: 1;
    }
}


/* Real SVG language and file icons */
.file-type-icon {
    width: 20px;
    height: 20px;
    padding: 0;
    border-radius: 0;
    background: transparent;
    overflow: visible;
}

.file-type-icon svg {
    display: block;
    width: 18px;
    height: 18px;
}

.editor-file-info .file-type-icon {
    width: 32px;
    height: 32px;
    padding: 5px;
    border-radius: 8px;
    background: #edf8fc;
}

.editor-file-info .file-type-icon svg {
    width: 22px;
    height: 22px;
}


/* Reliable three-dot menu using native HTML details */
.tree-actions {
    position: absolute;
    right: 4px;
    top: 50%;
    z-index: 30;
    transform: translateY(-50%);
}

.tree-actions > summary {
    width: 29px;
    height: 28px;
    display: grid;
    place-items: center;
    border-radius: 6px;
    color: #506276;
    font-weight: 900;
    letter-spacing: -1px;
    cursor: pointer;
    list-style: none;
    opacity: 0;
    user-select: none;
}

.tree-actions > summary::-webkit-details-marker {
    display: none;
}

.tree-row:hover .tree-actions > summary,
.tree-row:focus-within .tree-actions > summary,
.tree-actions[open] > summary {
    opacity: 1;
}

.tree-actions > summary:hover,
.tree-actions[open] > summary {
    background: #cceaf6;
    color: #0479ad;
}

.tree-action-menu {
    position: absolute;
    top: 32px;
    right: 0;
    z-index: 4000;
    width: 178px;
    padding: 6px;
    border: 1px solid #cadce7;
    border-radius: 9px;
    background: #fff;
    box-shadow: 0 15px 38px rgba(18, 45, 67, .24);
}

.tree-action-menu a,
.tree-action-menu button {
    width: 100%;
    min-height: 34px;
    display: flex;
    align-items: center;
    border: 0;
    border-radius: 6px;
    background: transparent;
    color: #172238;
    padding: 7px 10px;
    font: inherit;
    font-size: 13px;
    text-align: left;
    text-decoration: none;
    cursor: pointer;
}

.tree-action-menu a:hover,
.tree-action-menu button:hover {
    background: #e8f5fb;
}

.tree-action-menu form {
    margin: 0;
    padding: 0;
}

.tree-action-menu button.danger {
    color: #c72f29;
}

.tree-action-menu button.danger:hover {
    background: #fff0ef;
}

@media (max-width: 760px) {
    .tree-actions > summary {
        opacity: 1;
    }
}
