:root {
    --st-primary: #2563eb;
    --st-primary-dark: #1d4ed8;
    --st-sidebar: #0f172a;
    --st-editor: #111827;
    --st-muted: #64748b;
}

body {
    background: #f4f7fb;
    color: #172033;
    min-height: 100vh;
}

.auth-shell {
    min-height: 100vh;
    background:
        radial-gradient(circle at top left, rgba(37, 99, 235, .28), transparent 36%),
        radial-gradient(circle at bottom right, rgba(14, 165, 233, .18), transparent 34%),
        #081120;
}

.auth-card {
    max-width: 470px;
    border: 0;
    border-radius: 1.25rem;
    box-shadow: 0 24px 80px rgba(0, 0, 0, .34);
}

.brand-mark {
    display: inline-grid;
    place-items: center;
    width: 44px;
    height: 44px;
    border-radius: 14px;
    color: #fff;
    background: linear-gradient(135deg, #2563eb, #06b6d4);
    box-shadow: 0 8px 24px rgba(37, 99, 235, .3);
}

.navbar-brand .brand-mark {
    width: 36px;
    height: 36px;
    border-radius: 11px;
}

.admin-sidebar {
    position: fixed;
    inset: 0 auto 0 0;
    width: 260px;
    background: var(--st-sidebar);
    color: #cbd5e1;
    z-index: 1030;
    overflow-y: auto;
}

.admin-sidebar .nav-link {
    color: #94a3b8;
    border-radius: .75rem;
    padding: .72rem .85rem;
    margin-bottom: .25rem;
}

.admin-sidebar .nav-link:hover,
.admin-sidebar .nav-link.active {
    color: #fff;
    background: rgba(255, 255, 255, .1);
}

.admin-main {
    margin-left: 260px;
    min-height: 100vh;
}

.admin-topbar {
    min-height: 68px;
    background: rgba(255, 255, 255, .92);
    backdrop-filter: blur(12px);
    border-bottom: 1px solid #e2e8f0;
}

.page-card,
.stat-card {
    border: 0;
    border-radius: 1rem;
    box-shadow: 0 8px 28px rgba(15, 23, 42, .06);
}

.stat-icon {
    width: 48px;
    height: 48px;
    display: grid;
    place-items: center;
    border-radius: 14px;
    background: #eff6ff;
    color: var(--st-primary);
    font-size: 1.25rem;
}

.table > :not(caption) > * > * {
    padding: .9rem .75rem;
    vertical-align: middle;
}

.badge-soft-success { background: #dcfce7; color: #166534; }
.badge-soft-danger { background: #fee2e2; color: #991b1b; }
.badge-soft-warning { background: #fef3c7; color: #92400e; }
.badge-soft-info { background: #dbeafe; color: #1e40af; }
.badge-soft-secondary { background: #e2e8f0; color: #334155; }

.code-once-box {
    border: 1px dashed #60a5fa;
    background: #eff6ff;
    border-radius: .9rem;
}

.editor-shell {
    height: calc(100dvh - 116px);
    min-height: 520px;
    max-height: calc(100dvh - 116px);
    display: grid;
    grid-template-columns: 300px minmax(0, 1fr);
    background: var(--st-editor);
    border-radius: 1rem;
    overflow: hidden;
    box-shadow: 0 18px 50px rgba(15, 23, 42, .16);
}

.admin-editor-shell {
    height: calc(100dvh - 172px);
    max-height: calc(100dvh - 172px);
}

.file-sidebar {
    min-height: 0;
    background: #0b1220;
    border-right: 1px solid rgba(255, 255, 255, .08);
    color: #cbd5e1;
    overflow-y: auto;
    overscroll-behavior: contain;
}

.file-sidebar-header {
    position: sticky;
    top: 0;
    z-index: 5;
    background: #0b1220;
    border-bottom: 1px solid rgba(255, 255, 255, .08);
}

.file-tree {
    min-width: 0;
}

.tree-section-label {
    color: #64748b;
    font-size: .72rem;
    font-weight: 700;
    letter-spacing: .06em;
    padding: .55rem .75rem .35rem;
    text-transform: uppercase;
}

.file-entry {
    display: flex;
    align-items: center;
    min-width: 0;
    border-radius: .65rem;
    transition: background .15s ease;
}

.file-entry:hover,
.file-entry:focus-within,
.file-entry.active {
    background: rgba(37, 99, 235, .25);
}

.file-link {
    color: #94a3b8;
    display: flex;
    align-items: center;
    gap: .65rem;
    flex: 1 1 auto;
    min-width: 0;
    padding: .58rem .45rem .58rem .72rem;
    border-radius: .65rem;
    text-decoration: none;
    overflow: hidden;
}

.file-link.nested-file {
    padding-left: calc(.75rem + (var(--tree-depth) * 1rem));
}

.file-link:hover,
.file-entry.active .file-link {
    color: #fff;
}

.file-link span {
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.file-entry-actions {
    display: flex;
    align-items: center;
    flex: 0 0 auto;
    padding-right: .25rem;
    opacity: .2;
    transition: opacity .15s ease;
}

.file-entry:hover .file-entry-actions,
.file-entry:focus-within .file-entry-actions,
.file-entry.active .file-entry-actions {
    opacity: 1;
}

.file-entry-actions form {
    margin: 0;
}

.file-quick-action {
    display: inline-grid;
    place-items: center;
    width: 28px;
    height: 28px;
    padding: 0;
    border: 0;
    border-radius: .45rem;
    color: #94a3b8;
    background: transparent;
    text-decoration: none;
}

.file-quick-action:hover,
.file-quick-action:focus-visible {
    color: #fff;
    background: rgba(255, 255, 255, .1);
    outline: none;
}

.folder-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: .35rem;
    min-width: 0;
    min-height: 36px;
    margin-top: .2rem;
    padding: .4rem .35rem .4rem calc(.7rem + (var(--tree-depth) * 1rem));
    border-radius: .6rem;
    color: #cbd5e1;
}

.folder-row:hover {
    background: rgba(255, 255, 255, .055);
}

.folder-row-name {
    display: flex;
    align-items: center;
    gap: .55rem;
    min-width: 0;
}

.folder-row-name > span {
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.folder-row-name .bi {
    color: #fbbf24;
}

.folder-row-actions {
    display: flex;
    align-items: center;
    flex-shrink: 0;
    opacity: .2;
    transition: opacity .15s ease;
}

.folder-row:hover .folder-row-actions,
.folder-row:focus-within .folder-row-actions {
    opacity: 1;
}

.folder-row-actions form {
    margin: 0;
}

.folder-action {
    display: inline-grid;
    place-items: center;
    width: 28px;
    height: 28px;
    padding: 0;
    border: 0;
    border-radius: .45rem;
    color: #94a3b8;
    background: transparent;
}

.folder-action:hover {
    color: #fff;
    background: rgba(255, 255, 255, .1);
}

.editor-pane {
    min-width: 0;
    min-height: 0;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    background: #111827;
}

.editor-toolbar {
    min-height: 60px;
    flex: 0 0 auto;
    background: #172033;
    border-bottom: 1px solid rgba(255, 255, 255, .08);
    color: #e2e8f0;
}

.editor-content {
    flex: 1 1 auto;
    min-width: 0;
    min-height: 0;
    display: flex;
    position: relative;
    overflow: hidden;
}

.editor-content > .CodeMirror {
    flex: 1 1 auto;
    min-width: 0;
    min-height: 0;
}

.CodeMirror {
    width: 100% !important;
    height: 100% !important;
    min-height: 0;
    font-size: 14px;
    line-height: 1.65;
    font-family: "SFMono-Regular", Consolas, "Liberation Mono", Menlo, monospace;
}

.CodeMirror-scroll {
    min-height: 0;
    overflow: auto !important;
    overscroll-behavior: contain;
}

.CodeMirror-hscrollbar,
.CodeMirror-vscrollbar {
    z-index: 8;
}

.editor-statusbar {
    min-height: 30px;
    flex: 0 0 auto;
    background: #1d4ed8;
    color: #eff6ff;
    font-size: .78rem;
}

.empty-editor {
    height: 100%;
    min-height: 0;
    display: grid;
    place-items: center;
    overflow-y: auto;
    color: #94a3b8;
    text-align: center;
    padding: 2rem;
}

.file-type-icon {
    width: 26px;
    flex: 0 0 26px;
    text-align: center;
    font-weight: 700;
    font-size: .66rem;
    color: #60a5fa;
}

.user-navbar {
    min-height: 68px;
    background: #fff;
    border-bottom: 1px solid #e2e8f0;
}

.form-control:focus,
.form-select:focus {
    border-color: #60a5fa;
    box-shadow: 0 0 0 .2rem rgba(37, 99, 235, .13);
}

.btn-primary {
    background: var(--st-primary);
    border-color: var(--st-primary);
}

.btn-primary:hover {
    background: var(--st-primary-dark);
    border-color: var(--st-primary-dark);
}

@media (max-width: 991.98px) {
    .admin-sidebar {
        transform: translateX(-100%);
        transition: transform .2s ease;
    }
    body.sidebar-open .admin-sidebar { transform: translateX(0); }
    .admin-main { margin-left: 0; }
    .editor-shell { grid-template-columns: 240px minmax(0, 1fr); }
}

@media (max-width: 767.98px) {
    .editor-shell {
        height: auto;
        max-height: none;
        min-height: calc(100dvh - 100px);
        grid-template-columns: 1fr;
    }
    .file-sidebar {
        max-height: 260px;
        border-right: 0;
        border-bottom: 1px solid rgba(255,255,255,.08);
    }
    .file-entry-actions,
    .folder-row-actions { opacity: 1; }
    .editor-pane {
        min-height: 560px;
        height: calc(100dvh - 110px);
    }
}

/* Workspace tree, drag/drop, and content search */
.editor-shell {
    position: relative;
}

.workspace-search-panel {
    padding: .75rem;
    background: #0b1220;
    border-bottom: 1px solid rgba(255, 255, 255, .08);
}

.workspace-search-panel .form-control,
.workspace-search-panel .btn {
    border-color: rgba(148, 163, 184, .28);
}

.workspace-search-panel .form-control {
    color: #e2e8f0;
    background: #111827;
}

.workspace-search-panel .form-control::placeholder {
    color: #64748b;
}

.workspace-search-panel .form-control:focus {
    color: #fff;
    background: #111827;
    border-color: #3b82f6;
    box-shadow: 0 0 0 .15rem rgba(59, 130, 246, .18);
}

.workspace-search-scope {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: .5rem;
    margin-top: .45rem;
    padding: .35rem .45rem;
    border-radius: .45rem;
    color: #bfdbfe;
    background: rgba(37, 99, 235, .18);
    font-size: .75rem;
}

.workspace-search-scope button {
    display: inline-grid;
    place-items: center;
    width: 22px;
    height: 22px;
    padding: 0;
    border: 0;
    border-radius: .35rem;
    color: #bfdbfe;
    background: transparent;
}

.workspace-search-scope button:hover {
    color: #fff;
    background: rgba(255, 255, 255, .1);
}

.workspace-search-status {
    min-height: 20px;
    margin-top: .45rem;
    color: #64748b;
    font-size: .72rem;
}

.workspace-search-results {
    max-height: min(330px, 42vh);
    margin-top: .35rem;
    overflow-y: auto;
    overscroll-behavior: contain;
    border: 1px solid rgba(148, 163, 184, .18);
    border-radius: .65rem;
    background: #111827;
}

.workspace-search-result {
    display: block;
    padding: .65rem .7rem;
    color: #cbd5e1;
    text-decoration: none;
    border-bottom: 1px solid rgba(148, 163, 184, .12);
}

.workspace-search-result:last-child {
    border-bottom: 0;
}

.workspace-search-result:hover,
.workspace-search-result:focus-visible {
    color: #fff;
    background: rgba(37, 99, 235, .22);
    outline: none;
}

.workspace-search-result-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: .65rem;
    margin-bottom: .25rem;
    font-size: .76rem;
    font-weight: 700;
}

.workspace-search-result-location {
    flex: 0 0 auto;
    color: #93c5fd;
    font-size: .68rem;
    font-weight: 600;
}

.workspace-search-result-snippet {
    color: #94a3b8;
    font-family: "SFMono-Regular", Consolas, "Liberation Mono", Menlo, monospace;
    font-size: .7rem;
    line-height: 1.45;
    white-space: pre-wrap;
    overflow-wrap: anywhere;
}

.workspace-search-result mark {
    padding: 0 .08rem;
    border-radius: .15rem;
    color: #111827;
    background: #fde047;
}

.workspace-search-empty {
    padding: 1rem;
    color: #64748b;
    font-size: .78rem;
    text-align: center;
}

.root-folder-row,
.folder-row {
    display: flex;
    align-items: center;
    gap: .15rem;
    min-width: 0;
    min-height: 38px;
    border-radius: .6rem;
}

.root-folder-row {
    margin-bottom: .2rem;
    padding: .35rem .35rem .35rem .3rem;
    color: #cbd5e1;
    background: rgba(255, 255, 255, .035);
}

.folder-row {
    justify-content: flex-start;
    padding: .35rem .35rem .35rem calc(.25rem + (var(--tree-depth) * .9rem));
}

.folder-toggle {
    display: inline-grid;
    place-items: center;
    flex: 0 0 24px;
    width: 24px;
    height: 28px;
    padding: 0;
    border: 0;
    border-radius: .4rem;
    color: #94a3b8;
    background: transparent;
}

.folder-toggle:hover,
.folder-toggle:focus-visible {
    color: #fff;
    background: rgba(255, 255, 255, .08);
    outline: none;
}

.folder-toggle .bi {
    transition: transform .15s ease;
}

.tree-folder.is-collapsed > .folder-row .folder-toggle .bi,
.folder-toggle.is-collapsed .bi {
    transform: rotate(-90deg);
}

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

.tree-folder .folder-icon-closed {
    display: none;
}

.tree-folder.is-collapsed > .folder-row .folder-icon-open {
    display: none;
}

.tree-folder.is-collapsed > .folder-row .folder-icon-closed {
    display: inline-block;
}

.tree-drag-handle {
    display: inline-grid;
    place-items: center;
    flex: 0 0 18px;
    width: 18px;
    color: #475569;
    cursor: grab;
}

.workspace-draggable:active .tree-drag-handle {
    cursor: grabbing;
}

.folder-row-name {
    flex: 1 1 auto;
}

.file-entry .file-link {
    padding-left: calc(.25rem + (var(--tree-depth, 0) * .9rem));
}

.file-entry .tree-drag-handle {
    margin-left: .15rem;
}

.folder-row-actions {
    margin-left: auto;
}

.workspace-draggable.is-dragging {
    opacity: .42;
}

.workspace-drop-target {
    outline: 2px solid transparent;
    outline-offset: -2px;
    transition: background .14s ease, outline-color .14s ease;
}

.workspace-drop-target.is-drop-target {
    color: #fff;
    background: rgba(34, 197, 94, .2);
    outline-color: #22c55e;
}

.workspace-drop-target.is-drop-invalid {
    background: rgba(239, 68, 68, .16);
    outline-color: #ef4444;
}

body.workspace-moving {
    cursor: progress;
}

body.workspace-moving .editor-shell {
    pointer-events: none;
    opacity: .88;
}

.workspace-toast {
    position: absolute;
    right: 1rem;
    bottom: 2.7rem;
    z-index: 30;
    max-width: min(420px, calc(100% - 2rem));
    padding: .75rem 1rem;
    border-radius: .65rem;
    color: #fff;
    background: #15803d;
    box-shadow: 0 12px 36px rgba(0, 0, 0, .3);
    font-size: .85rem;
}

.workspace-toast-danger {
    background: #b91c1c;
}

.cm-search-highlight {
    color: #111827 !important;
    background: #fde047 !important;
    border-radius: 2px;
    box-shadow: 0 0 0 1px rgba(250, 204, 21, .6);
}

@media (hover: none) {
    .tree-drag-handle {
        display: none;
    }
}

.folder-name-toggle {
    padding: 0;
    border: 0;
    color: inherit;
    background: transparent;
    text-align: left;
}

.folder-name-toggle:hover,
.folder-name-toggle:focus-visible {
    color: #fff;
    outline: none;
}
