:root {
    color-scheme: dark;
    --bg: #090b0e;
    --panel: #101419;
    --panel2: #0b0e12;
    --border: #252b33;
    --text: #e6edf3;
    --muted: #8b949e;
    --purple: #7c3aed;
    --purple2: #8b5cf6;
    --danger: #ff7b72;
    --success: #7ee787;
    --line: #68707a;
    --topbar: #0d1116;
    --editor-bg: #11161b;
    --gutter-bg: #0e1318;
    --terminal-bg: #080a0d;
    --help-bg: #0d1117;
    --selection: rgba(74, 105, 160, .55);
}

* { box-sizing: border-box; }

html, body {
    width: 100%;
    height: 100%;
    margin: 0;
}

body {
    overflow: hidden;
    background: var(--bg);
    color: var(--text);
    font-family: Inter, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

.app-shell {
    height: 100vh;
    display: flex;
    flex-direction: column;
}

.topbar {
    height: 72px;
    flex: 0 0 72px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 18px;
    border-bottom: 1px solid var(--border);
    background: var(--topbar);
}

.brand {
    font-size: 18px;
    font-weight: 750;
}

.subtitle {
    color: var(--muted);
    font-size: 11px;
    margin-top: 3px;
}

.actions {
    display: flex;
    gap: 9px;
}

.button {
    border: 1px solid transparent;
    border-radius: 7px;
    padding: 9px 12px;
    color: white;
    font-weight: 650;
    cursor: pointer;
}

.button:disabled {
    opacity: .45;
    cursor: default;
}

.button.primary { background: var(--purple); }
.button.primary:hover:not(:disabled) { background: var(--purple2); }

.button.secondary {
    background: #161b22;
    border-color: #30363d;
}

.button.danger {
    background: #2a1719;
    border-color: #59262c;
    color: #ffb4ad;
}

.shortcut {
    margin-left: 7px;
    opacity: .65;
    font-size: 11px;
}

.workspace {
    flex: 1;
    min-height: 0;
    display: grid;
    grid-template-columns: minmax(0, 1.65fr) minmax(390px, .95fr);
    gap: 10px;
    padding: 10px;
}

.panel {
    min-width: 0;
    min-height: 0;
    overflow: hidden;
    border: 1px solid var(--border);
    border-radius: 9px;
    background: var(--panel);
}

.panel-heading {
    height: 40px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 11px;
    border-bottom: 1px solid var(--border);
    font-size: 12px;
    font-weight: 650;
}

.muted {
    color: var(--muted);
    font-size: 10px;
    font-weight: 450;
}

/* ---------- LOCAL C# EDITOR ---------- */

.editor-panel {
    display: flex;
    flex-direction: column;
}

.editor-shell {
    flex: 1;
    min-height: 0;
    display: flex;
    background: var(--editor-bg);
}

.line-numbers {
    width: 52px;
    flex: 0 0 52px;
    overflow: hidden;
    padding-top: 14px;
    border-right: 1px solid #20262d;
    background: var(--gutter-bg);
    color: var(--line);
    text-align: right;
    user-select: none;
    font-family: "SFMono-Regular", Consolas, "Liberation Mono", monospace;
    font-size: var(--editor-font-size, 13px);
    line-height: var(--editor-line-height, 21px);
}

#lineNumbersInner {
    padding-right: 12px;
    white-space: pre;
    will-change: transform;
}

.code-layer {
    position: relative;
    flex: 1;
    min-width: 0;
    min-height: 0;
}

#highlightLayer,
#diagnosticLayer,
#codeEditor {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    margin: 0;
    border: 0;
    padding: 14px 16px 80px;
    font-family: "SFMono-Regular", Consolas, "Liberation Mono", monospace;
    font-size: var(--editor-font-size, 13px);
    line-height: var(--editor-line-height, 21px);
    tab-size: 4;
    white-space: pre;
    overflow: auto;
}

#highlightLayer {
    z-index: 1;
    pointer-events: none;
    background: transparent;
    color: #d4d4d4;
}

#highlightCode {
    font: inherit;
}

#diagnosticLayer {
    z-index: 2;
    pointer-events: none;
    background: transparent;
    color: transparent;
    overflow: auto;
}

#diagnosticCode { font: inherit; color: transparent; }
#diagnosticCode .diag-error { color: transparent; text-decoration-line: underline; text-decoration-style: wavy; text-decoration-color: #f85149; text-decoration-thickness: 1.5px; text-underline-offset: 3px; }
#diagnosticCode .diag-warning { color: transparent; text-decoration-line: underline; text-decoration-style: wavy; text-decoration-color: #d29922; text-decoration-thickness: 1.5px; text-underline-offset: 3px; }

#codeEditor {
    z-index: 3;
    resize: none;
    outline: none;
    background: transparent;
    color: transparent;
    caret-color: #ffffff;
    -webkit-text-fill-color: transparent;
}

#codeEditor::selection {
    background: var(--selection);
}

.tok-keyword { color: #c586c0; }
.tok-type { color: #4ec9b0; }
.tok-string { color: #ce9178; }
.tok-char { color: #ce9178; }
.tok-comment { color: #6a9955; }
.tok-number { color: #b5cea8; }
.tok-preprocessor { color: #c8c8c8; }
.tok-identifier { color: #dcdcaa; }

/* ---------- CONSOLE ---------- */

.console-panel {
    display: flex;
    flex-direction: column;
}

.console-actions {
    display: flex;
    align-items: center;
    gap: 10px;
}

.text-button {
    border: 0;
    background: transparent;
    color: #b69cff;
    cursor: pointer;
    padding: 3px;
}

.console-font-controls {
    display: inline-flex;
    align-items: center;
    gap: 3px;
}

.console-font-button {
    min-width: 30px;
    height: 28px;
    padding: 0 6px;
    border: 1px solid var(--border);
    border-radius: 6px;
    background: var(--panel2);
    color: var(--text);
    cursor: pointer;
    font: 700 11px/1 system-ui, sans-serif;
    touch-action: manipulation;
}

.console-font-button:hover { filter: brightness(1.08); }

.terminal {
    flex: 1;
    min-height: 0;
    overflow: auto;
    background: var(--terminal-bg);
    cursor: text;
}

#consoleOutput {
    margin: 0;
    padding: 14px 14px 4px;
    white-space: pre-wrap;
    word-break: break-word;
    color: var(--text);
    font-family: "SFMono-Regular", Consolas, "Liberation Mono", monospace;
    font-size: var(--console-font-size, 13px);
    line-height: 1.54;
}

.console-input-row {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 0 14px 14px;
    font-family: "SFMono-Regular", Consolas, "Liberation Mono", monospace;
    font-size: var(--console-font-size, 13px);
    line-height: 1.54;
}

.console-input-row.hidden { display: none; }

.prompt {
    color: #a78bfa;
    user-select: none;
}

#consoleInput {
    flex: 1;
    min-width: 0;
    border: 0;
    outline: 0;
    padding: 0;
    background: transparent;
    color: white;
    caret-color: white;
    font: inherit;
}

.console-help {
    flex: 0 0 auto;
    border-top: 1px solid var(--border);
    padding: 8px 10px;
    color: var(--muted);
    background: var(--help-bg);
    font-size: 10px;
}

.console-help code {
    color: #d0d7de;
    font-family: "SFMono-Regular", Consolas, monospace;
}

.console-muted { color: var(--muted); }
.console-error { color: var(--danger); }
.console-input-echo { color: #d0d7de; }
.console-ok { color: var(--success); }

@media (max-width: 900px) {
    body { overflow: auto; }
    .app-shell { height: auto; min-height: 100vh; }

    .workspace {
        grid-template-columns: 1fr;
        grid-template-rows: 65vh 55vh;
    }

    .shortcut { display: none; }
}


/* ---------- THEME SWITCH ---------- */

html, body, .topbar, .panel, .editor-shell, .line-numbers,
.terminal, .console-help, .button {
    transition: background-color .18s ease, border-color .18s ease, color .18s ease;
}

body.light-theme {
    color-scheme: light;
    --bg: #f4f6f8;
    --panel: #ffffff;
    --panel2: #ffffff;
    --border: #d8dee4;
    --text: #1f2328;
    --muted: #656d76;
    --line: #8c959f;
    --topbar: #ffffff;
    --editor-bg: #ffffff;
    --gutter-bg: #f6f8fa;
    --terminal-bg: #ffffff;
    --help-bg: #f6f8fa;
    --selection: rgba(9, 105, 218, .22);
}

body.light-theme .button.secondary {
    background: #f6f8fa;
    border-color: #d0d7de;
    color: #24292f;
}

body.light-theme .button.danger {
    background: #fff1f0;
    border-color: #ffccc7;
    color: #a8071a;
}

body.light-theme #codeEditor {
    caret-color: #111827;
}

body.light-theme .tok-keyword { color: #af00db; }
body.light-theme .tok-type { color: #267f99; }
body.light-theme .tok-string,
body.light-theme .tok-char { color: #a31515; }
body.light-theme .tok-comment { color: #008000; }
body.light-theme .tok-number { color: #098658; }
body.light-theme .tok-preprocessor { color: #795e26; }
body.light-theme .tok-identifier { color: #795e26; }

body.light-theme #highlightLayer {
    color: #1f2328;
}

body.light-theme .console-help code {
    color: #24292f;
}

body.light-theme #consoleInput {
    color: #1f2328;
    caret-color: #1f2328;
}

body.light-theme .console-input-echo {
    color: #24292f;
}

/* ---------- ANSI CONSOLE COLORS ---------- */

/* foreground */
.ansi-fg-30 { color: #4b5563; }
.ansi-fg-31 { color: #ef4444; }
.ansi-fg-32 { color: #22c55e; }
.ansi-fg-33 { color: #eab308; }
.ansi-fg-34 { color: #3b82f6; }
.ansi-fg-35 { color: #d946ef; }
.ansi-fg-36 { color: #06b6d4; }
.ansi-fg-37 { color: #e5e7eb; }

.ansi-fg-90 { color: #9ca3af; }
.ansi-fg-91 { color: #f87171; }
.ansi-fg-92 { color: #4ade80; }
.ansi-fg-93 { color: #fde047; }
.ansi-fg-94 { color: #60a5fa; }
.ansi-fg-95 { color: #e879f9; }
.ansi-fg-96 { color: #22d3ee; }
.ansi-fg-97 { color: #ffffff; }

/* background */
.ansi-bg-40 { background-color: #111827; }
.ansi-bg-41 { background-color: #b91c1c; }
.ansi-bg-42 { background-color: #15803d; }
.ansi-bg-43 { background-color: #a16207; }
.ansi-bg-44 { background-color: #1d4ed8; }
.ansi-bg-45 { background-color: #a21caf; }
.ansi-bg-46 { background-color: #0e7490; }
.ansi-bg-47 { background-color: #d1d5db; }

.ansi-bg-100 { background-color: #4b5563; }
.ansi-bg-101 { background-color: #ef4444; }
.ansi-bg-102 { background-color: #22c55e; }
.ansi-bg-103 { background-color: #eab308; }
.ansi-bg-104 { background-color: #3b82f6; }
.ansi-bg-105 { background-color: #d946ef; }
.ansi-bg-106 { background-color: #06b6d4; }
.ansi-bg-107 { background-color: #f9fafb; }

.ansi-bold { font-weight: 700; }
.ansi-underline { text-decoration: underline; }

/* In light theme "default" console text follows theme; explicit ConsoleColor stays explicit. */
body.light-theme .ansi-fg-30 { color: #111827; }
body.light-theme .ansi-fg-37 { color: #374151; }
body.light-theme .ansi-fg-97 { color: #111827; }


/* ---------- CONSOLE INPUT INHERITS ConsoleColor ---------- */

/*
   #consoleInput раньше имел фиксированный color.
   Эти селекторы более специфичны и позволяют ANSI-классам
   задавать цвет прямо во время набора Console.ReadLine().
*/
#consoleInput.ansi-fg-30 { color: #4b5563; }
#consoleInput.ansi-fg-31 { color: #ef4444; }
#consoleInput.ansi-fg-32 { color: #22c55e; }
#consoleInput.ansi-fg-33 { color: #eab308; }
#consoleInput.ansi-fg-34 { color: #3b82f6; }
#consoleInput.ansi-fg-35 { color: #d946ef; }
#consoleInput.ansi-fg-36 { color: #06b6d4; }
#consoleInput.ansi-fg-37 { color: #e5e7eb; }

#consoleInput.ansi-fg-90 { color: #9ca3af; }
#consoleInput.ansi-fg-91 { color: #f87171; }
#consoleInput.ansi-fg-92 { color: #4ade80; }
#consoleInput.ansi-fg-93 { color: #fde047; }
#consoleInput.ansi-fg-94 { color: #60a5fa; }
#consoleInput.ansi-fg-95 { color: #e879f9; }
#consoleInput.ansi-fg-96 { color: #22d3ee; }
#consoleInput.ansi-fg-97 { color: #ffffff; }

#consoleInput.ansi-bg-40 { background-color: #111827; }
#consoleInput.ansi-bg-41 { background-color: #b91c1c; }
#consoleInput.ansi-bg-42 { background-color: #15803d; }
#consoleInput.ansi-bg-43 { background-color: #a16207; }
#consoleInput.ansi-bg-44 { background-color: #1d4ed8; }
#consoleInput.ansi-bg-45 { background-color: #a21caf; }
#consoleInput.ansi-bg-46 { background-color: #0e7490; }
#consoleInput.ansi-bg-47 { background-color: #d1d5db; }

#consoleInput.ansi-bg-100 { background-color: #4b5563; }
#consoleInput.ansi-bg-101 { background-color: #ef4444; }
#consoleInput.ansi-bg-102 { background-color: #22c55e; }
#consoleInput.ansi-bg-103 { background-color: #eab308; }
#consoleInput.ansi-bg-104 { background-color: #3b82f6; }
#consoleInput.ansi-bg-105 { background-color: #d946ef; }
#consoleInput.ansi-bg-106 { background-color: #06b6d4; }
#consoleInput.ansi-bg-107 { background-color: #f9fafb; }

body.light-theme #consoleInput.ansi-fg-30 { color: #111827; }
body.light-theme #consoleInput.ansi-fg-37 { color: #374151; }
body.light-theme #consoleInput.ansi-fg-97 { color: #111827; }

/* Небольшой внутренний отступ нужен, если активирован BackgroundColor. */
#consoleInput[class*="ansi-bg-"] {
    padding-left: 3px;
    padding-right: 3px;
}


/* ---------- Users / personal projects ---------- */

.auth-page {
    min-height: 100vh;
    display: grid;
    place-items: center;
    padding: 28px;
    background:
        radial-gradient(circle at 20% 20%, rgba(124, 58, 237, .22), transparent 34%),
        radial-gradient(circle at 80% 70%, rgba(6, 182, 212, .14), transparent 34%),
        var(--bg);
}

.auth-card {
    width: min(460px, 100%);
    padding: 38px;
    border: 1px solid var(--border);
    border-radius: 26px;
    background: var(--panel);
    box-shadow: 0 28px 80px rgba(0, 0, 0, .25);
}

.auth-logo {
    width: 58px;
    height: 58px;
    display: grid;
    place-items: center;
    margin-bottom: 22px;
    border-radius: 17px;
    background: linear-gradient(135deg, #7c3aed, #9333ea);
    color: white;
    font-size: 25px;
    font-weight: 900;
}

.auth-card h1 { margin: 0 0 8px; font-size: 30px; }
.auth-lead { margin: 0 0 28px; color: var(--muted); line-height: 1.55; }
.auth-form { display: grid; gap: 18px; }
.auth-form label { display: grid; gap: 8px; font-weight: 700; }

.auth-form input,
.new-project-form input,
.project-name-bar input {
    border: 1px solid var(--border);
    background: var(--editor-bg);
    color: var(--text);
    outline: none;
    transition: border-color .15s, box-shadow .15s;
}

.auth-form input {
    width: 100%;
    box-sizing: border-box;
    padding: 13px 14px;
    border-radius: 12px;
    font: inherit;
}

.auth-form input:focus,
.new-project-form input:focus,
.project-name-bar input:focus {
    border-color: #8b5cf6;
    box-shadow: 0 0 0 3px rgba(139, 92, 246, .14);
}

.auth-submit { width: 100%; justify-content: center; margin-top: 4px; min-height: 48px; }

.auth-note {
    margin-top: 24px;
    padding: 14px 16px;
    border-radius: 13px;
    background: rgba(124, 58, 237, .10);
    color: var(--muted);
    line-height: 1.5;
    font-size: 14px;
}

.validation-summary, .field-error { color: #ef4444; font-size: 13px; }
.validation-summary:empty, .field-error:empty { display: none; }

.projects-page {
    width: 100%;
    height: 100vh;
    min-height: 100vh;
    overflow-y: auto;
    overflow-x: hidden;
    -webkit-overflow-scrolling: touch;
    overscroll-behavior-y: contain;
    background: var(--bg);
    color: var(--text);
}

.projects-header {
    min-height: 82px;
    padding: 16px 28px;
    border-bottom: 1px solid var(--border);
    background: var(--panel);
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 20px;
}

.user-actions, .project-card-actions, .brand-row, .editor-top-left {
    display: flex;
    align-items: center;
    gap: 10px;
}

.editor-top-left { align-items: flex-start; flex-direction: column; gap: 5px; }

.nickname-pill {
    display: inline-flex;
    align-items: center;
    min-height: 36px;
    padding: 0 12px;
    border-radius: 999px;
    background: rgba(124, 58, 237, .11);
    border: 1px solid rgba(124, 58, 237, .22);
    color: #a78bfa;
    font-weight: 800;
    font-size: 14px;
}

body.light-theme .nickname-pill { color: #6d28d9; }
.small-pill { min-height: 26px; padding: 0 9px; font-size: 12px; }

.projects-content {
    width: min(1260px, calc(100% - 40px));
    margin: 0 auto;
    padding: 38px 0 70px;
}

.projects-hero {
    display: flex;
    justify-content: space-between;
    align-items: flex-end;
    gap: 28px;
    margin-bottom: 30px;
}

.projects-hero h1 { margin: 0 0 8px; font-size: clamp(30px, 4vw, 46px); }
.projects-hero p { margin: 0; max-width: 650px; color: var(--muted); line-height: 1.55; }
.new-project-form { display: flex; gap: 10px; }

.new-project-form input {
    min-width: 230px;
    padding: 10px 13px;
    border-radius: 11px;
    font: inherit;
}

.projects-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(330px, 1fr));
    gap: 18px;
}

.project-card {
    border: 1px solid var(--border);
    border-radius: 18px;
    background: var(--panel);
    overflow: hidden;
    transition: transform .15s, border-color .15s, box-shadow .15s;
}

.project-card:hover {
    transform: translateY(-2px);
    border-color: rgba(139, 92, 246, .52);
    box-shadow: 0 14px 34px rgba(0, 0, 0, .12);
}

.project-main {
    display: flex;
    gap: 16px;
    min-height: 128px;
    padding: 20px;
    color: inherit;
    text-decoration: none;
}

.project-icon {
    flex: 0 0 auto;
    width: 48px;
    height: 48px;
    border-radius: 13px;
    display: grid;
    place-items: center;
    background: rgba(124, 58, 237, .12);
    color: #a78bfa;
    font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
    font-weight: 900;
}

.project-info h2 { margin: 2px 0 6px; font-size: 19px; word-break: break-word; }
.project-info p { margin: 0 0 12px; color: var(--muted); font-family: ui-monospace, SFMono-Regular, Menlo, monospace; }
.project-info span { color: var(--muted); font-size: 12px; }

.project-card-actions {
    padding: 13px 16px;
    border-top: 1px solid var(--border);
    flex-wrap: wrap;
}

.button.small { min-height: 34px; padding: 7px 10px; font-size: 12px; }

.button.danger-outline {
    color: #ef4444;
    border: 1px solid rgba(239, 68, 68, .28);
    background: transparent;
}

.empty-projects {
    min-height: 360px;
    display: grid;
    place-items: center;
    align-content: center;
    text-align: center;
    gap: 8px;
    border: 1px dashed var(--border);
    border-radius: 22px;
    background: var(--panel);
}

.empty-projects h2 { margin: 5px 0 0; }
.empty-projects p { margin: 0 0 18px; color: var(--muted); }
.empty-icon { font-size: 34px; font-weight: 900; color: #8b5cf6; }

.welcome-banner {
    margin-bottom: 20px;
    padding: 13px 16px;
    border-radius: 12px;
    background: rgba(34, 197, 94, .11);
    border: 1px solid rgba(34, 197, 94, .24);
}

.back-link {
    color: #8b5cf6;
    text-decoration: none;
    font-weight: 800;
    font-size: 13px;
}

.back-link:hover { text-decoration: underline; }

.project-name-bar {
    min-height: 52px;
    padding: 8px 18px;
    display: flex;
    align-items: center;
    gap: 14px;
    border-bottom: 1px solid var(--border);
    background: var(--panel);
}

.project-name-bar input {
    width: min(430px, 50vw);
    padding: 8px 11px;
    border-radius: 9px;
    font: 700 15px/1.2 inherit;
}

.save-status {
    color: #22c55e;
    font-size: 12px;
    font-weight: 800;
    white-space: nowrap;
}

.save-status.dirty { color: #eab308; }
.save-status.save-error { color: #ef4444; }

@media (max-width: 900px) {
    .projects-header, .projects-hero, .topbar {
        align-items: flex-start;
        flex-direction: column;
    }
    .new-project-form { width: 100%; }
    .new-project-form input { flex: 1; min-width: 0; }
    .actions { flex-wrap: wrap; }
}

@media (max-width: 600px) {
    .projects-page { height: auto; min-height: 100vh; overflow: visible; }
    .projects-content { width: min(100% - 24px, 1260px); padding-top: 24px; }
    .projects-header { padding: 14px 16px; }
    .new-project-form { flex-direction: column; }
    .projects-grid { grid-template-columns: 1fr; }
    .auth-card { padding: 26px 20px; }
    .project-name-bar { align-items: stretch; flex-direction: column; }
    .project-name-bar input { width: 100%; box-sizing: border-box; }
}

/* ---------- Collaboration ---------- */
.access-panel, .dashboard-section {
    margin-bottom: 26px;
    padding: 20px;
    border: 1px solid var(--border);
    border-radius: 18px;
    background: var(--panel);
}
.access-panel { display:flex; align-items:end; justify-content:space-between; gap:24px; }
.access-panel h2, .dashboard-section h2 { margin:0 0 8px; }
.access-panel p { margin:0; color:var(--muted); max-width:680px; line-height:1.5; }
.access-request-form { display:flex; gap:10px; min-width:min(430px,100%); }
.access-request-form input { flex:1; min-width:0; padding:10px 12px; border-radius:10px; border:1px solid var(--border); background:var(--editor-bg); color:var(--text); font:inherit; }
.access-error-banner { margin-bottom:20px; padding:13px 16px; border-radius:12px; color:#ef4444; background:rgba(239,68,68,.10); border:1px solid rgba(239,68,68,.24); }
.attention-section { border-color:rgba(234,179,8,.35); }
.count-badge { display:inline-grid; place-items:center; min-width:25px; height:25px; padding:0 7px; border-radius:999px; font-size:12px; background:#eab308; color:#111827; }
.request-list, .granted-list { display:grid; gap:10px; margin-top:14px; }
.request-row, .granted-row { display:flex; justify-content:space-between; align-items:center; gap:14px; padding:13px 14px; border:1px solid var(--border); border-radius:12px; }
.request-row span, .granted-row span { color:var(--muted); }
.request-actions { display:flex; gap:8px; }
.shared-grid { display:grid; grid-template-columns:repeat(auto-fill,minmax(280px,1fr)); gap:12px; margin-top:14px; }
.shared-card { display:flex; align-items:center; gap:13px; padding:16px; border:1px solid var(--border); border-radius:14px; color:var(--text); text-decoration:none; transition:.15s; }
.shared-card:hover { border-color:#8b5cf6; transform:translateY(-1px); }
.shared-card div:last-child { display:grid; gap:4px; }
.shared-card span { color:var(--muted); font-size:12px; }
.shared-avatar { width:42px; height:42px; flex:0 0 42px; display:grid; place-items:center; border-radius:50%; background:rgba(124,58,237,.14); color:#a78bfa; font-weight:900; }
.pending-chips { display:flex; flex-wrap:wrap; gap:8px; margin-top:12px; }
.pending-chip { padding:8px 11px; border-radius:999px; background:rgba(234,179,8,.10); border:1px solid rgba(234,179,8,.24); color:var(--muted); font-size:13px; }
.live-access-badge, .foreign-space-badge, .presence-box { display:inline-flex; align-items:center; min-height:28px; padding:0 9px; border-radius:999px; font-size:12px; font-weight:800; }
.live-access-badge { color:#22c55e; background:rgba(34,197,94,.10); border:1px solid rgba(34,197,94,.22); }
.foreign-space-badge { color:#f59e0b; background:rgba(245,158,11,.10); border:1px solid rgba(245,158,11,.22); }
.presence-box { color:#22c55e; background:rgba(34,197,94,.08); border:1px solid rgba(34,197,94,.18); white-space:nowrap; }
.shared-title { margin-top:7px; }
.shared-project-card .project-main { min-height:110px; }
@media (max-width: 800px) {
    .access-panel, .request-row, .granted-row { flex-direction:column; align-items:stretch; }
    .access-request-form { min-width:0; width:100%; }
}


/* ---------- Project metadata + live project presence ---------- */
.project-dates { display:grid; gap:4px; margin-top:10px; }
.project-dates span { display:block; color:var(--muted); font-size:11px; line-height:1.35; }
.project-info .open-hint { display:block; margin-top:10px; }
.project-live-status { padding:9px 14px; border-bottom:1px solid rgba(34,197,94,.28); background:rgba(34,197,94,.11); color:#22c55e; font-size:12px; font-weight:850; }
.project-card.project-active-now { border-color:rgba(34,197,94,.72); box-shadow:0 0 0 2px rgba(34,197,94,.10), 0 16px 38px rgba(34,197,94,.10); }
.project-card.project-active-now .project-icon { background:rgba(34,197,94,.13); color:#22c55e; }

/* ---------- Editor IntelliSense-lite + diagnostics ---------- */
.autocomplete-box { position:absolute; z-index:10; width:min(320px, calc(100% - 16px)); max-height:224px; overflow:auto; padding:5px; border:1px solid #3b4450; border-radius:9px; background:#151a20; box-shadow:0 16px 42px rgba(0,0,0,.42); }
.autocomplete-box[hidden] { display:none; }
.autocomplete-item { width:100%; min-height:39px; display:flex; align-items:center; justify-content:space-between; gap:10px; padding:6px 8px; border:0; border-radius:6px; background:transparent; color:#e6edf3; text-align:left; cursor:pointer; font:12px/1.2 ui-monospace,SFMono-Regular,Menlo,monospace; }
.autocomplete-item:hover, .autocomplete-item.active { background:#263042; }
.autocomplete-item span { min-width:0; display:flex; align-items:baseline; gap:10px; }
.autocomplete-item strong { color:#dcdcaa; font-weight:800; }
.autocomplete-item small { color:#8b949e; white-space:nowrap; overflow:hidden; text-overflow:ellipsis; }
.autocomplete-item kbd { min-width:26px; color:#8b949e; font:10px/1 system-ui,sans-serif; text-align:right; }
.diagnostics-summary { flex:0 0 auto; min-height:34px; display:flex; align-items:center; gap:14px; padding:6px 12px; border-top:1px solid var(--border); background:var(--panel2); font-size:11px; overflow:hidden; }
.diagnostics-ok { color:#22c55e; font-weight:800; white-space:nowrap; }
.diagnostics-bad { color:#f85149; font-weight:850; white-space:nowrap; }
.diagnostics-warn { color:#d29922; font-weight:850; white-space:nowrap; }
.diagnostics-message { color:var(--muted); white-space:nowrap; overflow:hidden; text-overflow:ellipsis; }
.diagnostics-hint { margin-left:auto; color:var(--muted); white-space:nowrap; overflow:hidden; text-overflow:ellipsis; }
body.light-theme .autocomplete-box { background:#ffffff; border-color:#c8d1dc; box-shadow:0 14px 36px rgba(0,0,0,.16); }
body.light-theme .autocomplete-item { color:#1f2328; }
body.light-theme .autocomplete-item:hover, body.light-theme .autocomplete-item.active { background:#eef2f7; }
body.light-theme .autocomplete-item strong { color:#795e26; }
@media (max-width:800px) { .diagnostics-hint { display:none; } }

/* ---------- Admin dashboard ---------- */
.admin-button { background:rgba(245,158,11,.12); border-color:rgba(245,158,11,.34); color:#fbbf24; text-decoration:none; }
.admin-button:hover { background:rgba(245,158,11,.20); }
.admin-pill { color:#fbbf24; background:rgba(245,158,11,.10); border-color:rgba(245,158,11,.28); }
.admin-content { padding-bottom:90px; }
.admin-hero { display:flex; align-items:flex-end; justify-content:space-between; gap:24px; margin-bottom:24px; }
.admin-hero h1 { margin:0 0 8px; font-size:clamp(30px,4vw,46px); }
.admin-hero p { margin:0; color:var(--muted); }
.admin-search-form { display:flex; gap:9px; min-width:min(520px,100%); }
.admin-search-form input { flex:1; min-width:0; padding:10px 13px; border-radius:10px; border:1px solid var(--border); background:var(--editor-bg); color:var(--text); font:inherit; }
.admin-search-form a, .projects-header a.button { text-decoration:none; display:inline-flex; align-items:center; justify-content:center; }
.admin-stats { display:grid; grid-template-columns:repeat(4,minmax(0,1fr)); gap:12px; margin-bottom:24px; }
.admin-stat { padding:18px; border:1px solid var(--border); border-radius:15px; background:var(--panel); }
.admin-stat strong { display:block; margin-bottom:4px; font-size:24px; }
.admin-stat span { color:var(--muted); font-size:12px; }
.admin-users-list { display:grid; gap:16px; }
.admin-user-card { overflow:hidden; border:1px solid var(--border); border-radius:18px; background:var(--panel); }
.admin-user-head { display:flex; align-items:center; justify-content:space-between; gap:20px; padding:18px 20px; }
.admin-user-identity { display:flex; align-items:center; gap:14px; min-width:0; }
.admin-user-identity h2 { margin:0 0 6px; font-size:20px; }
.admin-user-meta { display:flex; flex-wrap:wrap; gap:6px 18px; color:var(--muted); font-size:11px; }
.admin-project-count { flex:0 0 auto; padding:7px 10px; border-radius:999px; color:#a78bfa; background:rgba(124,58,237,.12); border:1px solid rgba(124,58,237,.22); font-size:12px; font-weight:800; }
.admin-no-projects { padding:14px 20px 18px; border-top:1px solid var(--border); color:var(--muted); font-size:13px; }
.admin-projects-table-wrap { overflow:auto; border-top:1px solid var(--border); }
.admin-projects-table { width:100%; border-collapse:collapse; min-width:700px; }
.admin-projects-table th, .admin-projects-table td { padding:12px 16px; text-align:left; border-bottom:1px solid var(--border); vertical-align:middle; }
.admin-projects-table tr:last-child td { border-bottom:0; }
.admin-projects-table th { color:var(--muted); background:var(--panel2); font-size:11px; text-transform:uppercase; letter-spacing:.04em; }
.admin-projects-table td { font-size:13px; }
.admin-projects-table td:first-child { display:grid; gap:4px; }
.admin-projects-table small { color:var(--muted); font-family:ui-monospace,SFMono-Regular,Menlo,monospace; font-size:10px; }
.admin-empty { min-height:280px; }
@media (max-width:900px) { .admin-hero { align-items:stretch; flex-direction:column; } .admin-search-form { min-width:0; width:100%; } .admin-stats { grid-template-columns:repeat(2,minmax(0,1fr)); } }
@media (max-width:600px) { .admin-search-form { flex-direction:column; } .admin-stats { grid-template-columns:1fr 1fr; } .admin-user-head { align-items:flex-start; flex-direction:column; } }

/* ---------- Mobile editor / phone-first layout ---------- */
.mobile-code-toolbar { display: none; }

@media (max-width: 700px), (max-height: 600px) and (pointer: coarse) {
    html, body { min-width: 0; height: 100%; }
    body { overflow: hidden; overscroll-behavior: none; }

    .app-shell {
        height: 100dvh;
        min-height: 100dvh;
        overflow: hidden;
        padding-bottom: env(safe-area-inset-bottom);
    }

    .topbar {
        height: auto;
        min-height: 54px;
        flex: 0 0 auto;
        padding: 7px 10px;
        align-items: center;
        flex-direction: row;
        gap: 8px;
    }

    .editor-top-left {
        min-width: 0;
        flex: 1;
        gap: 2px;
    }

    .back-link { font-size: 11px; }
    .brand { font-size: 14px; white-space: nowrap; }
    .brand-row { min-width: 0; gap: 6px; flex-wrap: nowrap; }
    .nickname-pill.small-pill { display: none; }
    .foreign-space-badge { max-width: 130px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

    .actions {
        position: fixed;
        z-index: 50;
        left: 0;
        right: 0;
        bottom: 0;
        display: grid;
        grid-template-columns: 46px 46px minmax(96px, 1fr) minmax(120px, 1.35fr);
        gap: 7px;
        padding: 8px 10px calc(8px + env(safe-area-inset-bottom));
        border-top: 1px solid var(--border);
        background: color-mix(in srgb, var(--topbar) 94%, transparent);
        -webkit-backdrop-filter: blur(14px);
        backdrop-filter: blur(14px);
        box-shadow: 0 -8px 24px rgba(0,0,0,.24);
    }

    .actions .presence-box,
    .actions .save-status { display: none; }

    .actions .button {
        min-width: 0;
        min-height: 46px;
        padding: 8px 7px;
        border-radius: 11px;
        font-size: 13px;
        white-space: nowrap;
        touch-action: manipulation;
    }

    #themeButton, #resetButton {
        width: 46px;
        overflow: hidden;
        font-size: 0;
    }
    #themeButton #themeIcon { font-size: 18px; }
    #themeButton #themeText { display: none; }
    #resetButton::before { content: "↺"; font-size: 21px; }
    #runButton { font-size: 14px; }
    #stopButton { font-size: 12px; }
    .shortcut { display: none; }

    .project-name-bar {
        min-height: 44px;
        flex: 0 0 auto;
        padding: 5px 10px;
        display: grid;
        grid-template-columns: minmax(0, 1fr) auto;
        align-items: center;
        gap: 8px;
        flex-direction: unset;
    }

    .project-name-bar input {
        width: 100%;
        min-width: 0;
        padding: 7px 9px;
        font-size: 16px;
    }
    .project-name-bar > .muted { max-width: 118px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
    #realtimeState { display: none; }

    .workspace {
        min-height: 0;
        grid-template-columns: 1fr;
        grid-template-rows: minmax(0, 60fr) minmax(0, 40fr);
        gap: 6px;
        padding: 6px 6px 70px;
        overflow: hidden;
    }

    .panel { border-radius: 8px; }
    .panel-heading { height: 34px; padding: 0 9px; }

    .mobile-code-toolbar {
        flex: 0 0 auto;
        display: flex;
        gap: 5px;
        overflow-x: auto;
        padding: 5px 6px;
        border-bottom: 1px solid var(--border);
        background: var(--panel2);
        scrollbar-width: none;
        -webkit-overflow-scrolling: touch;
    }
    .mobile-code-toolbar::-webkit-scrollbar { display: none; }
    .mobile-code-toolbar button {
        flex: 0 0 36px;
        height: 34px;
        border: 1px solid var(--border);
        border-radius: 7px;
        background: var(--panel);
        color: var(--text);
        font: 700 16px/1 ui-monospace, SFMono-Regular, Menlo, monospace;
        touch-action: manipulation;
    }
    .mobile-code-toolbar button[data-action="tab"] { flex-basis: 48px; font-size: 11px; }

    .line-numbers {
        width: 38px;
        flex-basis: 38px;
        padding-top: 10px;
        font-size: 12px;
        line-height: 21px;
    }
    #lineNumbersInner { padding-right: 8px; }

    #highlightLayer,
    #diagnosticLayer,
    #codeEditor {
        padding: 10px 10px 70px;
        font-size: 14px;
        line-height: 21px;
        -webkit-overflow-scrolling: touch;
    }

    #codeEditor, #highlightLayer, #diagnosticLayer {
        font-size: var(--editor-font-size, 16px);
        line-height: var(--editor-line-height, 24px);
    }
    .line-numbers {
        font-size: max(11px, calc(var(--editor-font-size, 16px) - 3px));
        line-height: var(--editor-line-height, 24px);
    }

    .diagnostics-summary {
        min-height: 28px;
        padding: 4px 8px;
        font-size: 10px;
    }
    .diagnostics-hint, .diagnostics-message { display: none; }

    .console-panel { min-height: 0; }
    .console-actions { gap: 5px; }
    .console-font-controls { gap: 2px; }
    .console-font-button { min-width: 29px; height: 28px; padding: 0 4px; font-size: 10px; }
    #runMeta { max-width: 145px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
    #consoleOutput { padding: 10px 10px 3px; font-size: var(--console-font-size, 13px); line-height: 1.5; }
    .console-input-row { padding: 0 10px 10px; font-size: max(16px, var(--console-font-size, 13px)); line-height: 1.5; }
    #consoleInput { min-height: 30px; }
    .console-help { display: none; }

    .autocomplete-box {
        position: fixed !important;
        z-index: 80;
        left: 8px !important;
        right: 8px !important;
        bottom: calc(66px + env(safe-area-inset-bottom));
        top: auto !important;
        width: auto;
        max-height: min(36dvh, 260px);
    }
    .autocomplete-item { min-height: 44px; font-size: 13px; }
}

@media (max-width: 390px) {
    .actions { grid-template-columns: 42px 42px minmax(88px, 1fr) minmax(108px, 1.25fr); padding-left: 6px; padding-right: 6px; gap: 5px; }
    .actions .button { min-height: 44px; padding-left: 4px; padding-right: 4px; }
    #themeButton, #resetButton { width: 42px; }
    #runButton { font-size: 13px; }
    #stopButton { font-size: 11px; }
    .project-name-bar > .muted { display: none; }
    .project-name-bar { grid-template-columns: 1fr; }
}

/* ---------- Mobile dashboard scrolling fix ---------- */
/*
   The phone editor intentionally locks body scrolling. Dashboard pages use
   .projects-page as their own scroll container, so keep that container fixed
   to the visible viewport and scroll it vertically on phones.
*/
@media (max-width: 700px), (max-height: 600px) and (pointer: coarse) {
    .projects-page {
        width: 100%;
        height: 100dvh;
        min-height: 100dvh;
        overflow-y: auto;
        overflow-x: hidden;
        -webkit-overflow-scrolling: touch;
        overscroll-behavior-y: auto;
        touch-action: pan-y;
    }

    .projects-content {
        padding-bottom: calc(80px + env(safe-area-inset-bottom));
    }
}


/* ---------- Editor text size controls ---------- */
.editor-heading-actions { display:flex; align-items:center; gap:8px; }
.editor-font-controls { display:inline-flex; align-items:center; gap:3px; }
.editor-font-button {
    min-width:30px; height:28px; padding:0 6px; border:1px solid var(--border); border-radius:6px;
    background:var(--panel2); color:var(--text); cursor:pointer; font:700 11px/1 system-ui,sans-serif;
    touch-action:manipulation;
}
.editor-font-button:disabled, .console-font-button:disabled { opacity:.4; cursor:default; }

/* Phone turned sideways: keep controls visible and use the wide screen efficiently. */
@media (orientation: landscape) and (max-height: 600px) and (pointer: coarse) {
    .app-shell { height:100dvh; min-height:100dvh; }
    .topbar { min-height:44px; padding:4px 8px; }
    .back-link { font-size:10px; }
    .brand { font-size:13px; }
    .foreign-space-badge, .nickname-pill.small-pill { display:none; }

    .project-name-bar { min-height:36px; padding:3px 8px; }
    .project-name-bar input { padding:5px 8px; font-size:14px; }
    .project-name-bar > .muted { display:none; }

    .workspace {
        grid-template-columns:minmax(0, 58fr) minmax(0, 42fr);
        grid-template-rows:minmax(0, 1fr);
        gap:5px; padding:5px 5px 62px;
    }
    .panel-heading { height:30px; padding:0 7px; }
    .editor-font-button, .console-font-button { min-width:28px; height:25px; padding:0 4px; }
    .mobile-code-toolbar { gap:3px; padding:3px 5px; }
    .mobile-code-toolbar button { flex-basis:32px; height:30px; font-size:14px; }
    .mobile-code-toolbar button[data-action="tab"] { flex-basis:44px; }
    .diagnostics-summary { display:none; }

    .actions {
        grid-template-columns:42px 42px minmax(100px, 1fr) minmax(120px, 1.2fr);
        padding:6px 8px calc(6px + env(safe-area-inset-bottom)); gap:5px;
    }
    .actions .button { min-height:40px; padding:5px 6px; }
    #themeButton, #resetButton { width:42px; }

    .autocomplete-box { bottom:calc(56px + env(safe-area-inset-bottom)); max-height:min(42dvh,220px); }
    #runMeta { max-width:100px; }
    .console-actions { gap:3px; }
}
