:root {
    --space-1: 3px;
    --space-2: 6px;
    --space-3: 9px;
    --space-4: 12px;
    --space-5: 18px;
    --space-6: 26px;

    --radius-sm: 7px;
    --radius: 10px;
    --radius-lg: 14px;

    --topbar-height: 46px;
    --sidebar-width: 300px;
}

html,
body {
    height: 100%;
    margin: 0;
    font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
    font-weight: 400;
    background: var(--surface-base);
    color: var(--text-main);
    overflow: hidden;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

#app {
    height: 100%;
}

* {
    box-sizing: border-box;
    scrollbar-color: var(--scrollbar-thumb) var(--scrollbar-track);
    scrollbar-width: thin;
}

*::-webkit-scrollbar {
    width: 11px;
    height: 11px;
}

*::-webkit-scrollbar-track {
    background: var(--scrollbar-track);
}

*::-webkit-scrollbar-thumb {
    border: 3px solid var(--scrollbar-track);
    border-radius: 999px;
    background: var(--scrollbar-thumb);
}

*::-webkit-scrollbar-thumb:hover {
    background: var(--scrollbar-thumb-hover);
}

button,
input,
select {
    font: inherit;
}

:focus-visible {
    outline: none;
}

.icon {
    width: 16px;
    height: 16px;
    flex: none;
}

/* ---------- Buttons ---------- */

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: var(--space-2);
    min-height: 32px;
    padding: 0 12px;
    border: 1px solid var(--line);
    border-radius: var(--radius-sm);
    background: var(--surface-panel);
    color: var(--text-main);
    font-weight: 500;
    cursor: pointer;
    transition: background 0.12s ease, border-color 0.12s ease, color 0.12s ease;
}

.btn:hover {
    border-color: var(--line-strong);
    background: var(--surface-muted);
}

.btn:focus-visible {
    outline: none;
    border-color: var(--accent);
    box-shadow: 0 0 0 3px var(--accent-soft);
}

.btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

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

.btn-primary:hover {
    border-color: var(--accent-strong);
    background: var(--accent-strong);
    color: var(--on-accent-strong);
}

.btn-ghost {
    border-color: transparent;
    background: transparent;
}

.btn-ghost:hover {
    background: var(--surface-muted);
    border-color: transparent;
}

.btn-danger {
    border-color: var(--danger);
    background: var(--danger);
    color: var(--on-danger);
}

.btn-danger:hover {
    filter: brightness(0.95);
    background: var(--danger);
    border-color: var(--danger);
}

.icon-button {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 26px;
    height: 26px;
    padding: 0;
    border: 1px solid transparent;
    border-radius: var(--radius-sm);
    background: transparent;
    color: var(--text-muted);
    cursor: pointer;
    transition: background 0.12s ease, color 0.12s ease;
}

.icon-button:hover {
    background: var(--surface-muted);
    color: var(--text-main);
}

.icon-button:disabled {
    cursor: default;
}

.icon-button:disabled:hover {
    background: transparent;
    color: var(--text-muted);
}

.refresh-icon {
    transform-origin: center;
}

.refresh-icon-loading {
    animation: refresh-icon-spin 0.8s linear infinite;
}

.app-link {
    color: var(--accent-strong);
    text-decoration: none;
    font-weight: 600;
}

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

/* ---------- App shell ---------- */

.app-shell {
    height: 100vh;
    min-height: 0;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    background: var(--surface-base);
    color: var(--text-main);
    font-size: 0.875rem;
    line-height: 1.5;
}

.app-body {
    flex: 1 1 auto;
    display: grid;
    grid-template-columns: var(--sidebar-width) minmax(0, 1fr);
    min-height: 0;
}

.app-shell.sidebar-hidden .app-body,
.app-shell.settings-chrome .app-body,
.app-shell.changes-chrome .app-body {
    grid-template-columns: minmax(0, 1fr);
}

.app-shell.settings-chrome .sidebar-toggle,
.app-shell.changes-chrome .sidebar-toggle {
    display: none;
}

.app-main {
    min-width: 0;
    min-height: 0;
    overflow: auto;
    background: var(--surface-main);
}

.app-topbar {
    flex: 0 0 var(--topbar-height);
    height: var(--topbar-height);
    min-height: var(--topbar-height);
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: var(--space-4);
    padding: 0 var(--space-5);
    background: var(--surface-panel);
    border-bottom: 1px solid var(--line);
    position: sticky;
    top: 0;
    z-index: 30;
}

.topbar-left {
    display: inline-flex;
    align-items: center;
    gap: var(--space-2);
    min-width: 0;
}

.sidebar-toggle {
    color: var(--text-muted);
}

.pane-sidebar-toggle {
    flex: none;
}

.tablet-sidebar-toggle {
    display: none;
}

.app-brand {
    display: inline-flex;
    align-items: center;
    gap: var(--space-2);
    color: var(--text-main);
    font-weight: 600;
    letter-spacing: -0.01em;
    text-decoration: none;
}

.app-brand .icon {
    color: var(--accent);
    width: 20px;
    height: 20px;
}

.login-link {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-height: 32px;
    padding: 0 12px;
    border-radius: var(--radius-sm);
    border: 1px solid var(--accent);
    color: var(--accent-strong);
    text-decoration: none;
    font-weight: 600;
    background: var(--surface-panel);
}

.login-link:hover {
    background: var(--accent-soft);
}

.login-link.large {
    min-height: 38px;
    padding-inline: 18px;
}

/* ---------- Profile menu ---------- */

.profile-menu {
    position: relative;
}

.profile-menu summary {
    list-style: none;
}

.profile-menu summary::-webkit-details-marker {
    display: none;
}

.profile-link {
    cursor: pointer;
    min-height: 32px;
    max-width: 220px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: var(--space-2);
    padding: 0 4px;
    border: 1px solid transparent;
    border-radius: var(--radius-sm);
    color: var(--text-main);
    font-weight: 500;
    text-decoration: none;
}

.profile-link:hover {
    color: var(--accent-strong);
}

.profile-link .icon {
    width: 18px;
    height: 18px;
    flex: none;
    color: var(--text-muted);
}

.profile-link:hover .icon {
    color: var(--accent-strong);
}

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

.profile-caret {
    width: 14px;
    height: 14px;
    transition: transform 0.15s ease;
}

.profile-menu[open] .profile-caret {
    transform: rotate(180deg);
}

.profile-popover {
    position: absolute;
    top: calc(100% + 6px);
    right: 0;
    z-index: 40;
    width: 224px;
    padding: var(--space-2);
    display: grid;
    gap: var(--space-1);
    background: var(--surface-panel);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    box-shadow: var(--shadow-2);
}

.profile-popover a,
.menu-command {
    width: 100%;
    min-height: 32px;
    display: flex;
    align-items: center;
    justify-content: flex-start;
    gap: var(--space-2);
    padding: 0 8px;
    border: 1px solid transparent;
    border-radius: var(--radius-sm);
    color: var(--text-main);
    background: transparent;
    text-decoration: none;
    cursor: pointer;
    font: inherit;
    text-align: left;
}

.profile-popover a:hover,
.menu-command:hover {
    background: var(--surface-muted);
}

.menu-command.danger {
    color: var(--danger);
}

.menu-command.danger:hover {
    background: var(--danger-soft);
}

.menu-command .icon,
.profile-popover a .icon {
    width: 16px;
    height: 16px;
    flex: none;
    color: var(--text-muted);
}

.theme-actions {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: var(--space-1);
    margin: var(--space-1) 0;
}

.theme-actions button {
    min-height: 30px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 4px;
    padding: 0 6px;
    border: 1px solid var(--line);
    border-radius: var(--radius-sm);
    background: var(--surface-main);
    color: var(--text-main);
    cursor: pointer;
    font: inherit;
    font-size: 0.82rem;
}

.theme-actions button .icon {
    width: 14px;
    height: 14px;
    flex: none;
    color: var(--text-muted);
}

.theme-actions button:hover {
    border-color: var(--line-strong);
}

.theme-actions button.active {
    border-color: var(--accent);
    color: var(--accent-strong);
    background: var(--accent-soft);
}

.theme-actions button.active .icon {
    color: var(--accent-strong);
}

/* ---------- Topbar search ---------- */

.topbar-search-key {
    flex: none;
    padding: 1px 5px;
    border: 1px solid var(--line);
    border-radius: 5px;
    font-size: 0.7rem;
    color: var(--text-muted);
}

/* ---------- Profile chip ---------- */

.profile-chip {
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    gap: var(--space-2);
    max-width: 220px;
    height: 32px;
    padding: 3px 8px 3px 3px;
    border-radius: 999px;
    background: var(--surface-muted);
    color: var(--text-main);
}

.profile-chip:hover {
    background: var(--accent-soft);
}

.profile-avatar {
    flex: none;
    width: 26px;
    height: 26px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    background: var(--accent);
    color: var(--on-accent);
    font-size: 0.7rem;
    font-weight: 600;
}

/* ---------- Command palette ---------- */

.palette-backdrop {
    position: fixed;
    inset: 0;
    z-index: 1000;
    display: flex;
    justify-content: center;
    align-items: flex-start;
    padding: 12vh var(--space-4) var(--space-4);
    background: var(--modal-backdrop);
    backdrop-filter: blur(3px);
    animation: modal-fade 0.16s ease;
}

.palette {
    width: min(560px, 92vw);
    max-height: 62vh;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    background: var(--surface-panel);
    border: 1px solid var(--line);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-2);
    animation: modal-pop 0.17s cubic-bezier(0.2, 0.9, 0.3, 1);
}

.palette-input-row {
    flex: none;
    display: flex;
    align-items: center;
    gap: var(--space-2);
    padding: var(--space-3) var(--space-4);
    border-bottom: 1px solid var(--line);
}

.palette-input-row .icon {
    width: 17px;
    height: 17px;
    flex: none;
    color: var(--text-muted);
}

.palette-input-row input {
    flex: 1;
    min-width: 0;
    border: none;
    background: transparent;
    color: var(--text-main);
    font: inherit;
    font-size: 0.95rem;
    outline: none;
}

.palette-list {
    flex: 1 1 auto;
    min-height: 0;
    overflow-y: auto;
    padding: var(--space-2);
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.palette-item {
    display: flex;
    align-items: center;
    gap: var(--space-3);
    width: 100%;
    height: 38px;
    padding: 0 var(--space-3);
    border: none;
    border-radius: var(--radius-sm);
    background: transparent;
    color: var(--text-main);
    cursor: pointer;
    text-align: left;
}

.palette-item .icon {
    width: 16px;
    height: 16px;
    flex: none;
    color: var(--text-muted);
}

.palette-item.highlighted {
    background: var(--accent-soft);
    color: var(--accent-strong);
}

.palette-item.highlighted .icon {
    color: var(--accent-strong);
}

.palette-item-title {
    flex: 1;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.palette-item-project {
    flex: none;
    font-size: 0.78rem;
    color: var(--text-muted);
}

.palette-empty {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: var(--space-2);
    padding: var(--space-5);
    color: var(--text-muted);
}

.palette-empty .icon {
    width: 22px;
    height: 22px;
}

/* ---------- Sidebar ---------- */

.knowledge-sidebar {
    height: 100%;
    min-height: 0;
    overflow-x: hidden;
    overflow-y: auto;
    overscroll-behavior: contain;
    padding: var(--space-2);
    background: var(--surface-panel);
    border-right: 1px solid var(--line);
    display: flex;
    flex-direction: column;
    gap: var(--space-2);
}

.app-shell.sidebar-hidden .knowledge-sidebar {
    display: none;
}

.sidebar-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: var(--space-2);
}

.sidebar-title {
    display: inline-flex;
    align-items: center;
    gap: var(--space-2);
    font-weight: 600;
    letter-spacing: -0.01em;
}

.sidebar-title .icon {
    color: var(--accent);
    width: 16px;
    height: 16px;
}

.sidebar-new-project {
    width: 100%;
}

.sidebar-error {
    padding: var(--space-2) var(--space-3);
    border-radius: var(--radius-sm);
    color: var(--danger);
    background: var(--danger-soft);
    font-size: 0.85rem;
}

.sidebar-empty {
    display: grid;
    gap: var(--space-3);
    padding: var(--space-4) var(--space-2);
    color: var(--text-muted);
    text-align: center;
}

.sidebar-empty p {
    margin: 0;
}

.sidebar-login {
    color: var(--accent-strong);
    font-weight: 600;
    text-decoration: none;
}

/* ---------- Tree ---------- */

.tree {
    display: flex;
    flex-direction: column;
    gap: var(--space-2);
    font-size: 0.78rem;
}

.tree-project {
    display: flex;
    flex-direction: column;
    gap: var(--space-1);
}

.tree-row {
    display: flex;
    align-items: center;
    gap: var(--space-1);
    min-height: 26px;
    padding: 0 2px 0 var(--space-1);
    border-radius: var(--radius-sm);
    border: 1px solid transparent;
}

.tree-row:hover {
    background: var(--surface-muted);
}

.tree-project-row {
    font-weight: 600;
    min-height: 28px;
}

.tree-project-row .tree-icon {
    color: var(--accent);
}

.tree-label {
    flex: 1;
    min-width: 0;
    display: inline-flex;
    align-items: center;
    gap: var(--space-1);
    min-height: 22px;
    padding: 0 2px;
    border: none;
    background: transparent;
    color: inherit;
    cursor: pointer;
    text-align: left;
}

.tree-icon {
    color: var(--text-muted);
    width: 16px;
    height: 16px;
    flex: none;
}

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

.tree-rename-input {
    flex: 1;
    min-width: 0;
    height: 22px;
    padding: 0 6px;
    border: 1px solid var(--accent);
    border-radius: var(--radius-sm);
    background: var(--surface-main);
    color: var(--text-main);
    font: inherit;
    font-size: inherit;
    outline: none;
}

.tree-rename-input:focus {
    box-shadow: 0 0 0 2px var(--accent-soft);
}

.tree-actions button.icon-button:hover {
    color: var(--danger);
}

.document-presence-badge {
    width: 18px;
    height: 18px;
    flex: none;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    color: var(--text-muted);
}

.document-presence-badge.editing {
    color: var(--warning);
}

.document-presence-badge.viewing {
    color: var(--accent);
}

.document-presence-badge .icon {
    width: 13px;
    height: 13px;
}

.tree-twisty {
    width: 18px;
    height: 18px;
    flex: none;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border: none;
    background: transparent;
    color: var(--text-muted);
    cursor: pointer;
    border-radius: var(--radius-sm);
}

.tree-twisty:hover {
    color: var(--text-main);
}

.tree-twisty .icon {
    width: 15px;
    height: 15px;
    transition: transform 0.15s ease;
}

.tree-twisty.expanded .icon {
    transform: rotate(90deg);
}

.tree-children {
    display: flex;
    flex-direction: column;
    gap: 1px;
    margin-left: 9px;
    padding-left: var(--space-1);
    border-left: 1px solid var(--line);
}

.tree-document-row .tree-label {
    font-weight: 500;
}

.tree-document-row::before {
    content: "";
    width: 18px;
    height: 18px;
    flex: none;
}

.tree-document-row.active {
    background: var(--accent-soft);
}

.tree-document-row.active .tree-label,
.tree-document-row.active .tree-icon {
    color: var(--accent-strong);
}

.tree-empty {
    padding: var(--space-1) var(--space-2);
    color: var(--text-muted);
    font-size: 0.82rem;
    font-style: italic;
}

.tree-actions {
    display: inline-flex;
    align-items: center;
    gap: 2px;
    flex: none;
}

.tree-row .icon-button {
    width: 20px;
    height: 20px;
    opacity: 0;
    visibility: hidden;
    pointer-events: none;
}

.tree-row:hover .icon-button,
.tree-row:focus-within .icon-button,
.tree-document-row.active .icon-button,
.node-menu[open] > .icon-button {
    opacity: 1;
    visibility: visible;
    pointer-events: auto;
}

.tree-row.drag-over {
    border-color: var(--accent);
    border-style: dashed;
    background: var(--accent-soft);
}

/* ---------- Node action / add menu ---------- */

.node-menu {
    position: relative;
    display: inline-flex;
}

.node-menu summary {
    list-style: none;
}

.node-menu summary::-webkit-details-marker {
    display: none;
}

.menu-overlay {
    position: fixed;
    inset: 0;
    z-index: 50;
    background: transparent;
}

.node-menu-popover {
    position: absolute;
    top: calc(100% + 4px);
    right: 0;
    z-index: 60;
    width: 168px;
    padding: var(--space-1);
    display: grid;
    gap: 2px;
    background: var(--surface-panel);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    box-shadow: var(--shadow-2);
}

.node-menu-popover .menu-command .icon {
    width: 15px;
    height: 15px;
}

/* ---------- Modal ---------- */

.modal-backdrop {
    position: fixed;
    inset: 0;
    z-index: 1000;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: var(--space-4);
    background: var(--modal-backdrop);
    backdrop-filter: blur(3px);
    animation: modal-fade 0.16s ease;
}

.modal-panel {
    width: min(440px, 100%);
    max-height: calc(100vh - 2 * var(--space-4));
    display: flex;
    flex-direction: column;
    overflow: hidden;
    background: var(--surface-panel);
    border: 1px solid var(--line);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-2);
    animation: modal-pop 0.17s cubic-bezier(0.2, 0.9, 0.3, 1);
}

.modal-panel:focus {
    outline: none;
}

.modal-header {
    flex: none;
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: var(--space-3);
    padding: var(--space-4) var(--space-4) var(--space-3);
}

.modal-title {
    margin: 0;
    font-size: 1rem;
    font-weight: 600;
    letter-spacing: -0.01em;
    line-height: 1.3;
}

.modal-close {
    margin: -4px -4px 0 0;
    flex: none;
}

.modal-body {
    flex: 1 1 auto;
    min-height: 0;
    overflow: auto;
    padding: 0 var(--space-4) var(--space-4);
    display: flex;
    flex-direction: column;
    gap: var(--space-3);
}

.modal-message {
    margin: 0;
    color: var(--text-muted);
    line-height: 1.5;
}

/* Icon + message row used by destructive confirmations. */
.modal-confirm {
    display: flex;
    align-items: flex-start;
    gap: var(--space-3);
}

.modal-confirm-icon {
    flex: none;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 36px;
    height: 36px;
    border-radius: 999px;
    color: var(--accent-strong);
    background: var(--accent-soft);
}

.modal-confirm.danger .modal-confirm-icon {
    color: var(--danger);
    background: var(--danger-soft);
}

.modal-confirm-icon .icon {
    width: 18px;
    height: 18px;
}

.modal-form {
    display: flex;
    flex: 1 1 auto;
    min-height: 0;
    flex-direction: column;
}

.modal-field {
    display: grid;
    gap: var(--space-1);
}

.modal-field-label {
    font-weight: 500;
    font-size: 0.85rem;
    color: var(--text-muted);
}

.modal-footer {
    flex: none;
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: var(--space-2);
    padding: var(--space-3) var(--space-4);
    border-top: 1px solid var(--line);
    background: color-mix(in srgb, var(--surface-muted) 45%, var(--surface-panel));
}

.modal-footer .btn {
    min-width: 84px;
}

.text-input {
    width: 100%;
    min-height: 36px;
    padding: 0 11px;
    border: 1px solid var(--line);
    border-radius: var(--radius-sm);
    background: var(--surface-main);
    color: var(--text-main);
    transition: border-color 0.12s ease, box-shadow 0.12s ease;
}

.text-input:focus {
    border-color: var(--accent);
    box-shadow: 0 0 0 3px var(--accent-soft);
}

@keyframes modal-fade {
    from {
        opacity: 0;
    }

    to {
        opacity: 1;
    }
}

@keyframes modal-pop {
    from {
        opacity: 0;
        transform: translateY(8px) scale(0.98);
    }

    to {
        opacity: 1;
        transform: none;
    }
}

@keyframes refresh-icon-spin {
    to {
        transform: rotate(360deg);
    }
}

@media (prefers-reduced-motion: reduce) {
    .refresh-icon-loading,
    .modal-backdrop,
    .modal-panel {
        animation: none;
    }
}

/* ---------- Move dialog ---------- */

.move-list {
    display: flex;
    flex-direction: column;
    gap: 2px;
    max-height: 320px;
    overflow: auto;
    padding: var(--space-1);
    border: 1px solid var(--line);
    border-radius: var(--radius-sm);
    background: var(--surface-main);
}

.move-option {
    display: flex;
    align-items: center;
    gap: var(--space-2);
    min-height: 30px;
    padding: 0 10px;
    border: 1px solid transparent;
    border-radius: var(--radius-sm);
    background: transparent;
    color: var(--text-main);
    cursor: pointer;
    text-align: left;
}

.move-option:hover {
    background: var(--surface-muted);
}

.move-option.selected {
    border-color: var(--accent);
    background: var(--accent-soft);
    color: var(--accent-strong);
}

.move-option .icon {
    color: var(--text-muted);
}

.move-option.selected .icon {
    color: var(--accent-strong);
}

.move-hint {
    margin-left: auto;
    font-size: 0.75rem;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.04em;
}

/* ---------- Workspace / editor ---------- */

.workspace {
    height: calc(100vh - var(--topbar-height));
    display: flex;
    flex-direction: column;
    min-height: 0;
}

.workspace-alert {
    padding: var(--space-2) var(--space-4);
    border-bottom: 1px solid var(--line);
    background: var(--danger-soft);
    color: var(--danger);
}

.editor-grid {
    flex: 1;
    min-height: 0;
    display: grid;
    grid-template-columns: minmax(0, 1fr);
    grid-template-rows: minmax(0, 1fr);
}

.editor-grid.panes-2 {
    grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
}

.editor-pane {
    min-width: 0;
    min-height: 0;
    display: grid;
    grid-template-rows: 41px minmax(0, 1fr);
    border-right: 1px solid var(--line);
    background: var(--surface-panel);
    transition: filter 0.12s ease, opacity 0.12s ease;
}

.editor-pane:last-child {
    border-right: none;
}

.editor-grid.panes-2 .editor-pane:not(.active) {
    opacity: 0.56;
    filter: saturate(0.65) blur(0.5px);
}

.editor-grid.panes-2 .editor-pane:focus-within {
    opacity: 1;
    filter: none;
}

.editor-pane.drag-over {
    opacity: 1;
    filter: none;
    box-shadow: inset 0 0 0 2px var(--accent), inset 0 0 0 999px var(--accent-soft);
}

.editor-pane.active {
    box-shadow: inset 0 0 0 2px var(--accent);
    position: relative;
    z-index: 1;
}

.editor-pane.active.drag-over {
    box-shadow: inset 0 0 0 2px var(--accent), inset 0 0 0 999px var(--accent-soft);
}

.pane-bar {
    display: flex;
    align-items: center;
    gap: var(--space-2);
    min-width: 0;
    padding: 0 var(--space-2);
    border-bottom: 1px solid var(--line);
    background: var(--surface-base);
}

.pane-tabs {
    display: flex;
    align-items: center;
    gap: 3px;
    min-width: 0;
    flex: 1;
    overflow-x: auto;
    padding: 4px 0;
    scrollbar-width: none;
}

.pane-tabs::-webkit-scrollbar {
    display: none;
}

.pane-tab {
    display: inline-flex;
    align-items: center;
    max-width: 200px;
    min-width: 0;
    height: 28px;
    margin: 0;
    padding: 0 2px 0 0;
    border: 1px solid transparent;
    border-radius: var(--radius-sm);
    background: transparent;
    color: var(--text-muted);
    font-size: 0.78rem;
}

.pane-tab:hover {
    background: var(--surface-muted);
    color: var(--text-main);
}

.pane-tab.active {
    border-color: var(--line);
    background: var(--surface-main);
    color: var(--text-main);
    box-shadow: var(--shadow-1);
}

.pane-tab-title {
    flex: 1;
    min-width: 0;
    display: inline-flex;
    align-items: center;
    gap: var(--space-2);
    height: 100%;
    padding: 0 6px 0 9px;
    border: none;
    background: transparent;
    color: inherit;
    cursor: pointer;
    overflow: hidden;
}

.pane-tab-icon {
    width: 15px;
    height: 15px;
    flex: none;
    color: var(--text-muted);
}

.pane-tab.active .pane-tab-icon {
    color: var(--accent);
}

.pane-tab-title span {
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.pane-tab.active .pane-tab-title {
    font-weight: 500;
}

.tab-close {
    flex: none;
    width: 20px;
    height: 20px;
    margin: 0;
    padding: 0;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border: none;
    border-radius: var(--radius-sm);
    background: transparent;
    color: var(--text-muted);
    cursor: pointer;
}

.tab-close:hover {
    color: var(--danger);
    background: var(--surface-muted);
}

.tab-close .icon {
    width: 14px;
    height: 14px;
}

.pane-bar-tools {
    flex: none;
    display: inline-flex;
    align-items: center;
    gap: var(--space-1);
}

.save-pill {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    height: 24px;
    padding: 0 9px;
    border-radius: 999px;
    background: var(--surface-muted);
    color: var(--text-muted);
    font-size: 0.78rem;
    white-space: nowrap;
}

.save-pill .icon {
    width: 14px;
    height: 14px;
}

.save-pill.saved .icon {
    color: var(--accent);
}

.save-pill.saving {
    color: var(--accent);
}

.save-pill.dirty {
    color: var(--warning);
}

.save-pill.retrying,
.save-pill.blocked,
.save-pill.conflict {
    color: var(--danger);
    background: var(--danger-soft);
}

.save-pill-spin {
    animation: refresh-icon-spin 0.8s linear infinite;
}

.save-pill-round {
    flex: none;
    width: 28px;
    height: 28px;
    padding: 0;
    gap: 0;
    justify-content: center;
}

.save-pill-round .icon {
    width: 16px;
    height: 16px;
}

.save-pill.clickable {
    cursor: pointer;
}

.save-pill-action {
    margin-left: 2px;
    padding: 0 7px;
    height: 18px;
    border: 1px solid currentColor;
    border-radius: 999px;
    background: transparent;
    color: inherit;
    font: inherit;
    font-size: 0.74rem;
    cursor: pointer;
}

.save-pill-action:hover {
    background: var(--surface-main);
}

.pane-tool .icon {
    width: 17px;
    height: 17px;
}

.doc-header {
    flex: none;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: var(--space-4);
    padding: var(--space-4) var(--space-5);
    border-bottom: 1px solid var(--line);
    background: var(--surface-panel);
}

.doc-header-text {
    display: flex;
    flex-direction: column;
    gap: var(--space-2);
    min-width: 0;
}

.doc-title {
    margin: 0;
    font-size: 1.4rem;
    font-weight: 600;
    letter-spacing: -0.01em;
    line-height: 1.2;
}

.doc-meta {
    display: inline-flex;
    align-items: center;
    gap: var(--space-2);
    padding: 2px 0;
    color: var(--text-muted);
    font-size: 0.8rem;
}

.doc-meta-avatar {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 20px;
    height: 20px;
    flex: none;
    border-radius: 50%;
    background: var(--accent-soft);
    color: var(--accent-strong);
    font-size: 0.66rem;
    font-weight: 600;
}

.pane-editor-body {
    flex: 1 1 auto;
    min-height: 0;
    min-width: 0;
    position: relative;
}

.pane-editor {
    display: flex;
    flex-direction: column;
    min-height: 0;
    min-width: 0;
}

.markdown-editor-host {
    height: 100%;
    min-width: 0;
    color: var(--text-main);
    font-size: 16px;
}

.milkdown-shell {
    display: flex;
    flex-direction: column;
    height: 100%;
    min-width: 0;
    overflow: hidden;
    border: none;
    background: var(--surface-panel);
}

.milkdown-editor-root {
    flex: 1 1 auto;
    min-height: 0;
    min-width: 0;
    overflow: hidden;
    background: var(--surface-panel);
}

.milkdown-editor-root .milkdown {
    display: flex;
    flex-direction: column;
    height: 100%;
    min-height: 0;
    overflow: hidden;
    background: var(--surface-panel);
    --crepe-color-background: var(--surface-panel);
    --crepe-color-on-background: var(--text-main);
    --crepe-color-surface: var(--surface-panel);
    --crepe-color-surface-low: var(--surface-muted);
    --crepe-color-on-surface: var(--text-main);
    --crepe-color-on-surface-variant: color-mix(in srgb, var(--text-main) 78%, var(--text-muted));
    --crepe-color-outline: var(--line);
    --crepe-color-primary: var(--accent-strong);
    --crepe-color-secondary: color-mix(in srgb, var(--accent) 18%, var(--surface-panel));
    --crepe-color-on-secondary: var(--text-main);
    --crepe-color-inverse: var(--text-main);
    --crepe-color-on-inverse: var(--surface-panel);
    --crepe-color-inline-code: var(--accent-strong);
    --crepe-color-error: var(--danger);
    --crepe-color-hover: var(--surface-muted);
    --crepe-color-selected: color-mix(in srgb, var(--accent) 20%, var(--surface-panel));
    --crepe-color-inline-area: color-mix(in srgb, var(--accent) 16%, var(--surface-panel));
    --crepe-font-title: inherit;
    --crepe-font-default: inherit;
    --crepe-font-code: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", monospace;
    --crepe-shadow-1: var(--shadow-2);
    --crepe-shadow-2: var(--shadow-2);
}

.milkdown-editor-root .milkdown .milkdown-top-bar {
    position: static;
    flex: 0 0 auto;
    height: 34px;
    min-height: 34px;
    padding: 0 8px;
    flex-wrap: nowrap;
    overflow: visible;
    overflow-anchor: none;
    border-bottom-color: var(--line);
    background: color-mix(in srgb, var(--surface-muted) 78%, var(--surface-panel));
}

.milkdown-editor-root .milkdown .milkdown-top-bar .top-bar-inner {
    flex-wrap: nowrap;
    width: max-content;
    min-width: 100%;
}

.milkdown-editor-root .milkdown .milkdown-top-bar .top-bar-heading-selector {
    padding: 2px;
}

.milkdown-editor-root .milkdown .milkdown-top-bar .top-bar-heading-button {
    height: 28px;
    padding: 3px 2px 3px 8px;
}

.milkdown-editor-root .milkdown .milkdown-top-bar .top-bar-heading-button,
.milkdown-editor-root .milkdown .milkdown-top-bar .top-bar-item {
    border-radius: 6px;
}

.milkdown-editor-root .milkdown .milkdown-top-bar .top-bar-item {
    width: 22px;
    height: 22px;
    margin: 2px;
    padding: 2px;
}

.milkdown-editor-root .milkdown .milkdown-top-bar .top-bar-item {
    color: var(--text-main);
}

.milkdown-editor-root .milkdown .milkdown-top-bar .top-bar-item svg {
    width: 18px;
    height: 18px;
    color: var(--text-main);
    fill: currentColor;
}

.milkdown-editor-root .milkdown .milkdown-top-bar .top-bar-item.active,
.milkdown-editor-root .milkdown .milkdown-top-bar .top-bar-item.active svg {
    color: var(--accent-strong);
}

.milkdown-editor-root .milkdown .milkdown-top-bar .top-bar-divider {
    height: 20px;
    margin: 4px 3px;
}

.milkdown-editor-root .milkdown .milkdown-top-bar .top-bar-heading-button .top-bar-chevron {
    width: 18px;
    height: 18px;
}

.milkdown-editor-root .milkdown .milkdown-top-bar .top-bar-heading-button .top-bar-chevron svg {
    width: 14px;
    height: 14px;
}

.milkdown-editor-root .milkdown .milkdown-top-bar .top-bar-heading-dropdown {
    border: 1px solid var(--line);
}

.milkdown-editor-root .milkdown .ProseMirror {
    flex: 1 1 auto;
    min-height: 0;
    padding: 22px 24px 56px;
    outline: none;
    color: var(--text-main);
    caret-color: var(--accent-strong);
    line-height: 1.6;
    overflow: auto;
    overflow-anchor: none;
    overflow-wrap: anywhere;
    scrollbar-gutter: stable;
}

.milkdown-editor-root .milkdown .ProseMirror:focus-visible {
    box-shadow: none;
}

.milkdown-shell[data-read-only="true"] .milkdown .ProseMirror {
    background: color-mix(in srgb, var(--surface-panel) 82%, var(--surface-muted));
}

.milkdown-editor-root .milkdown .ProseMirror > *:first-child {
    margin-top: 0;
}

.milkdown-editor-root .milkdown .ProseMirror > :is(.ProseMirror-widget, .prosemirror-virtual-cursor):first-child + * {
    margin-top: 0;
}

.milkdown-editor-root .milkdown .ProseMirror > *:last-child {
    margin-bottom: 0;
}

.milkdown-editor-root .milkdown .ProseMirror h1,
.milkdown-editor-root .milkdown .ProseMirror h2,
.milkdown-editor-root .milkdown .ProseMirror h3 {
    margin: 0.8em 0 0.45em;
    color: var(--text-main);
    line-height: 1.2;
}

.milkdown-editor-root .milkdown .ProseMirror blockquote {
    margin: 1rem 0;
    padding: 0.15rem 0 0.15rem 1rem;
    border-left: 3px solid var(--accent);
    color: var(--text-muted);
}

.milkdown-editor-root .milkdown .ProseMirror code {
    padding: 0.1rem 0.28rem;
    border-radius: 4px;
    background: var(--crepe-color-inline-area);
    color: var(--crepe-color-inline-code);
    font-size: 0.92em;
}

.milkdown-editor-root .milkdown .ProseMirror pre {
    padding: 0.85rem 1rem;
    overflow: auto;
    border: 1px solid var(--line);
    border-radius: 6px;
    background: color-mix(in srgb, var(--surface-muted) 72%, var(--surface-panel));
}

.milkdown-editor-root .milkdown .ProseMirror pre code {
    padding: 0;
    background: transparent;
}

.milkdown-editor-root .milkdown .ProseMirror table {
    width: 100%;
    margin: 1rem 0;
    border-collapse: collapse;
    table-layout: fixed;
}

.milkdown-editor-root .milkdown .ProseMirror th,
.milkdown-editor-root .milkdown .ProseMirror td {
    min-width: 80px;
    padding: 0.45rem 0.55rem;
    border: 1px solid var(--line);
    font-size: 0.875rem;
    line-height: 1.45;
    vertical-align: top;
}

.milkdown-editor-root .milkdown .ProseMirror th p,
.milkdown-editor-root .milkdown .ProseMirror td p,
.milkdown-editor-root .milkdown .ProseMirror th li,
.milkdown-editor-root .milkdown .ProseMirror td li {
    font-size: inherit;
    line-height: inherit;
}

.milkdown-editor-root .milkdown .ProseMirror th {
    background: var(--surface-muted);
    font-weight: 600;
}

.milkdown-editor-root .milkdown .ProseMirror ul,
.milkdown-editor-root .milkdown .ProseMirror ol {
    padding-left: 1.5rem;
}

.milkdown-editor-root .milkdown .ProseMirror li::marker {
    color: var(--text-muted);
}

.milkdown-editor-root .milkdown .milkdown-list-item-block li .label-wrapper {
    color: var(--text-muted);
}

.milkdown-editor-root .milkdown .milkdown-list-item-block li .label-wrapper svg {
    fill: currentColor;
}

.milkdown-editor-root .milkdown .ProseMirror li[data-item-type="task"] {
    position: relative;
    padding-left: 0.35rem;
    list-style: none;
}

.milkdown-editor-root .milkdown .ProseMirror li[data-item-type="task"]::before {
    content: "";
    display: inline-block;
    width: 0.9rem;
    height: 0.9rem;
    margin-right: 0.5rem;
    border: 1px solid var(--line-strong);
    border-radius: 3px;
    background: var(--surface-panel);
    vertical-align: -0.12rem;
}

.milkdown-editor-root .milkdown .ProseMirror li[data-item-type="task"][data-checked="true"]::after {
    content: "";
    position: absolute;
    left: 0.25rem;
    top: 0.56rem;
    width: 0.48rem;
    height: 0.24rem;
    border-left: 2px solid var(--accent);
    border-bottom: 2px solid var(--accent);
    transform: rotate(-45deg);
}

.pane-empty,
.workspace-empty,
.login-entry {
    min-height: 260px;
    display: grid;
    place-content: center;
    gap: var(--space-3);
    text-align: center;
    color: var(--text-muted);
}

.login-entry h1 {
    margin: 0;
    color: var(--text-main);
}

/* ---------- Forms / admin ---------- */

.form-surface {
    max-width: 920px;
    margin: 0 auto;
    padding: var(--space-5);
}

.form-panel {
    display: grid;
    gap: var(--space-4);
    padding: var(--space-5);
    background: var(--surface-panel);
    border: 1px solid var(--line);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-1);
}

.form-panel h1 {
    margin: 0;
}

.form-row {
    display: grid;
    gap: var(--space-1);
}

.form-row > span {
    font-weight: 500;
    font-size: 0.9rem;
}

.form-row input,
.form-row select {
    min-height: 34px;
    padding: 0 10px;
    border: 1px solid var(--line);
    border-radius: var(--radius-sm);
    background: var(--surface-main);
    color: var(--text-main);
}

.form-row input:focus,
.form-row select:focus {
    border-color: var(--accent);
}

.form-panel button[type="button"],
.form-panel button[type="submit"] {
    justify-self: start;
}

.form-panel button {
    min-height: 32px;
    padding: 0 12px;
    border: 1px solid var(--accent);
    border-radius: var(--radius-sm);
    background: var(--accent);
    color: var(--on-accent);
    font-weight: 600;
    cursor: pointer;
}

.form-panel button:hover {
    background: var(--accent-strong);
    border-color: var(--accent-strong);
    color: var(--on-accent-strong);
}

.admin-list,
.access-grid {
    display: grid;
    gap: var(--space-2);
}

.admin-row,
.access-row {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    gap: var(--space-3);
    align-items: center;
    min-height: 38px;
    padding: var(--space-2) var(--space-3);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    background: var(--surface-main);
}

.access-row {
    grid-template-columns: minmax(0, 1fr) auto auto;
}

.admin-row button {
    min-height: 28px;
    padding: 0 10px;
    background: var(--surface-panel);
    color: var(--text-main);
    border: 1px solid var(--line);
}

.admin-row button:hover {
    border-color: var(--accent);
    background: var(--surface-panel);
}

.form-actions,
.pagination-row,
.row-actions,
.role-card-header {
    display: flex;
    flex-wrap: wrap;
    gap: var(--space-2);
    align-items: center;
}

.muted-actions {
    margin-top: var(--space-3);
}

.comment-item,
.history-item,
.role-card {
    display: grid;
    gap: var(--space-2);
}

.role-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
    gap: var(--space-3);
}

.role-card,
.comment-item,
.history-item {
    padding: var(--space-3);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    background: var(--surface-main);
}

.admin-table-wrap {
    overflow: auto;
    border: 1px solid var(--line);
    border-radius: var(--radius);
    background: var(--surface-panel);
}

.admin-table {
    width: 100%;
    min-width: 680px;
    border-collapse: collapse;
}

.admin-table th,
.admin-table td {
    padding: var(--space-3);
    border-bottom: 1px solid var(--line);
    text-align: left;
    vertical-align: middle;
}

.admin-table th {
    background: var(--surface-muted);
    color: var(--text-muted);
    font-size: 0.82rem;
    font-weight: 600;
    text-transform: uppercase;
}

.admin-table tbody tr:last-child td {
    border-bottom: 0;
}

.table-checks,
.table-actions {
    display: flex;
    flex-wrap: wrap;
    gap: var(--space-2);
    align-items: center;
}

.table-check {
    display: inline-flex;
    gap: var(--space-1);
    align-items: center;
    white-space: nowrap;
}

.admin-table button {
    min-height: 28px;
    padding: 0 10px;
    background: var(--surface-main);
    color: var(--text-main);
    border: 1px solid var(--line);
}

.admin-table button:hover {
    border-color: var(--accent);
    background: var(--surface-panel);
    color: var(--text-main);
}

.status-pill {
    min-height: 22px;
    display: inline-flex;
    align-items: center;
    padding: 0 8px;
    border-radius: var(--radius-sm);
    font-size: 0.82rem;
    font-weight: 600;
}

.status-pill.success {
    color: var(--accent-strong);
    background: var(--accent-soft);
}

.status-pill.warning {
    color: var(--warning);
    background: color-mix(in srgb, var(--warning) 14%, transparent);
}

.status-pill.danger {
    color: var(--danger);
    background: var(--danger-soft);
}

.role-check {
    color: var(--accent-strong);
}

.role-empty {
    color: var(--text-muted);
}

.permission-list {
    display: grid;
    gap: var(--space-1);
}

/* ---------- Settings layout ---------- */

.settings-shell {
    display: grid;
    grid-template-columns: 232px minmax(0, 1fr);
    align-items: start;
    min-height: calc(100vh - var(--topbar-height));
}

.settings-rail {
    position: sticky;
    top: 0;
    align-self: stretch;
    display: flex;
    flex-direction: column;
    gap: 2px;
    padding: var(--space-5) var(--space-3);
    border-right: 1px solid var(--line);
    background: var(--surface-panel);
}

.settings-rail-group {
    margin: var(--space-4) var(--space-2) var(--space-1);
    color: var(--text-muted);
    font-size: 0.72rem;
    font-weight: 600;
    letter-spacing: 0.04em;
    text-transform: uppercase;
}

.settings-rail-group:first-child {
    margin-top: 0;
}

.settings-rail-link {
    display: flex;
    align-items: center;
    gap: var(--space-3);
    min-height: 34px;
    padding: 0 var(--space-3);
    border-radius: var(--radius-sm);
    color: var(--text-muted);
    text-decoration: none;
    font-weight: 600;
}

.settings-rail-link .icon {
    width: 18px;
    height: 18px;
}

.settings-rail-link:hover {
    background: var(--surface-muted);
    color: var(--text-main);
}

.settings-rail-link.router-link-active {
    background: var(--accent-soft);
    color: var(--accent-strong);
}

.settings-content {
    min-width: 0;
    padding: var(--space-5);
}

.settings-view {
    max-width: 1000px;
    margin: 0 auto;
    display: grid;
    gap: var(--space-4);
}

.settings-view.is-narrow {
    max-width: 680px;
}

.settings-head {
    display: flex;
    flex-wrap: wrap;
    gap: var(--space-3);
    align-items: flex-end;
    justify-content: space-between;
}

.settings-head h1 {
    margin: 0;
}

.settings-subtitle {
    margin: var(--space-1) 0 0;
    color: var(--text-muted);
    font-size: 0.85rem;
}

.settings-head-actions {
    display: flex;
    flex-wrap: wrap;
    gap: var(--space-2);
}

.settings-back {
    display: inline-flex;
    align-items: center;
    gap: var(--space-1);
    width: fit-content;
}

.settings-back .icon {
    width: 16px;
    height: 16px;
}

.settings-section {
    display: grid;
    gap: var(--space-3);
    padding: var(--space-4);
    border: 1px solid var(--line);
    border-radius: var(--radius-lg);
    background: var(--surface-panel);
    box-shadow: var(--shadow-1);
}

.settings-section-head h2 {
    margin: 0;
    font-size: 0.95rem;
}

.settings-section-body {
    display: grid;
    gap: var(--space-3);
}

.settings-actions {
    display: flex;
    gap: var(--space-2);
}

.settings-form-card {
    border: 1px solid var(--line);
    border-radius: var(--radius-lg);
    background: var(--surface-panel);
    box-shadow: var(--shadow-1);
    overflow: hidden;
}

.profile-identity {
    display: flex;
    align-items: center;
    gap: var(--space-4);
    padding: var(--space-4) var(--space-5);
}

.setting-row {
    display: grid;
    grid-template-columns: 190px minmax(0, 1fr);
    gap: var(--space-5);
    padding: var(--space-4) var(--space-5);
    border-top: 1px solid var(--line);
}

.setting-row-label {
    font-size: 0.9rem;
    font-weight: 500;
}

.setting-row-desc {
    margin-top: 3px;
    color: var(--text-muted);
    font-size: 0.78rem;
    line-height: 1.5;
}

.setting-control {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    gap: var(--space-3);
    min-width: 0;
}

.setting-input {
    width: 100%;
    max-width: 300px;
    min-height: 34px;
    padding: 0 10px;
    border: 1px solid var(--line);
    border-radius: var(--radius-sm);
    background: var(--surface-main);
    color: var(--text-main);
}

.setting-input:focus {
    border-color: var(--accent);
    box-shadow: 0 0 0 3px var(--accent-soft);
    outline: none;
}

.setting-input[readonly] {
    background: var(--surface-base);
    color: var(--text-muted);
}

.control-field {
    display: flex;
    flex-direction: column;
    gap: 3px;
    width: 100%;
    max-width: 300px;
}

.control-field-label {
    color: var(--text-muted);
    font-size: 0.78rem;
}

@media (max-width: 640px) {
    .setting-row {
        grid-template-columns: minmax(0, 1fr);
        gap: var(--space-3);
    }
}

.profile-identity-avatar {
    flex: none;
    width: 48px;
    height: 48px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    background: var(--accent);
    color: var(--on-accent);
    font-size: 1.05rem;
    font-weight: 600;
}

.profile-identity-text {
    min-width: 0;
}

.profile-identity-name {
    font-size: 1.05rem;
    font-weight: 600;
}

.profile-identity-email {
    color: var(--text-muted);
    font-size: 0.85rem;
}

.settings-save-bar {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: var(--space-2);
    padding: var(--space-3) var(--space-4);
    border-top: 1px solid var(--line);
    background: color-mix(in srgb, var(--surface-muted) 45%, var(--surface-panel));
}

.settings-save-bar .btn {
    min-width: 84px;
}

.settings-save-hint {
    margin-right: auto;
    color: var(--text-muted);
    font-size: 0.85rem;
}

.settings-save-hint.dirty {
    color: var(--warning);
    font-weight: 600;
}

.toggle-row {
    display: inline-flex;
    align-items: center;
    gap: var(--space-2);
    cursor: pointer;
}

.inline-form {
    display: flex;
    flex-wrap: wrap;
    gap: var(--space-2);
    align-items: center;
}

.inline-form input,
.inline-form select {
    min-height: 34px;
    padding: 0 10px;
    border: 1px solid var(--line);
    border-radius: var(--radius-sm);
    background: var(--surface-main);
    color: var(--text-main);
}

.inline-form input {
    flex: 1 1 220px;
}

.settings-search {
    position: relative;
    display: flex;
    align-items: center;
}

.settings-search .icon {
    position: absolute;
    left: 10px;
    width: 16px;
    height: 16px;
    color: var(--text-muted);
    pointer-events: none;
}

.settings-search input {
    width: 100%;
    min-height: 36px;
    padding: 0 10px 0 32px;
    border: 1px solid var(--line);
    border-radius: var(--radius-sm);
    background: var(--surface-main);
    color: var(--text-main);
}

.settings-state {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: var(--space-2);
    padding: var(--space-5);
    color: var(--text-muted);
    text-align: center;
}

.settings-state .icon {
    width: 22px;
    height: 22px;
}

.settings-state-error {
    color: var(--danger);
}

.settings-spinner {
    animation: refresh-icon-spin 0.8s linear infinite;
}

.user-cell {
    display: inline-flex;
    align-items: center;
    gap: var(--space-3);
}

.user-avatar {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 28px;
    height: 28px;
    flex-shrink: 0;
    border-radius: 50%;
    background: var(--accent-soft);
    color: var(--accent-strong);
    font-size: 0.72rem;
    font-weight: 600;
}

.project-cell {
    display: inline-flex;
    align-items: center;
    gap: var(--space-2);
}

.project-cell .icon {
    width: 18px;
    height: 18px;
    color: var(--accent);
}

.theme-options {
    display: grid;
    gap: var(--space-2);
    max-width: 360px;
}

.theme-option {
    display: flex;
    align-items: center;
    gap: var(--space-3);
    min-height: 44px;
    padding: 0 var(--space-3);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    background: var(--surface-main);
    color: var(--text-main);
    font-weight: 600;
    cursor: pointer;
}

.theme-option:hover {
    border-color: var(--line-strong);
}

.theme-option.active {
    border-color: var(--accent);
    background: var(--accent-soft);
    color: var(--accent-strong);
}

.theme-option-check {
    margin-left: auto;
    width: 18px;
    height: 18px;
}

.document-activity-panel {
    display: grid;
    gap: var(--space-4);
    max-height: 42%;
    overflow: auto;
    padding: var(--space-3);
    border-top: 1px solid var(--line);
    background: var(--surface-panel);
}

.document-activity-panel h2 {
    margin: 0 0 var(--space-2);
    font-size: 0.95rem;
}

.document-activity-panel textarea {
    width: 100%;
    min-height: 72px;
    resize: vertical;
}

.history-item pre {
    max-height: 180px;
    overflow: auto;
    padding: var(--space-2);
    background: var(--surface-panel);
    border: 1px solid var(--line);
    border-radius: var(--radius);
}

/* ---------- Responsive ---------- */

@media (max-width: 1100px) {
    .desktop-sidebar-toggle {
        display: none;
    }

    .tablet-sidebar-toggle {
        display: inline-flex;
    }

    .app-body {
        grid-template-columns: minmax(0, 1fr);
    }

    .knowledge-sidebar {
        display: none;
    }

    .app-shell.sidebar-open .app-body {
        grid-template-columns: var(--sidebar-width) minmax(0, 1fr);
    }

    .app-shell.sidebar-open .knowledge-sidebar {
        display: flex;
    }
}

@media (max-width: 880px) {
    .app-body,
    .app-shell.sidebar-open .app-body {
        grid-template-columns: 1fr;
    }

    .knowledge-sidebar {
        min-height: auto;
        max-height: 46vh;
        border-right: none;
        border-bottom: 1px solid var(--line);
    }

    .workspace {
        height: auto;
        min-height: 58vh;
    }

    .editor-grid,
    .editor-grid.panes-2 {
        grid-template-columns: 1fr;
    }

    .editor-pane {
        min-height: 520px;
        border-right: none;
        border-bottom: 1px solid var(--line);
    }

    .settings-shell {
        grid-template-columns: 1fr;
    }

    .settings-rail {
        position: static;
        flex-direction: row;
        flex-wrap: nowrap;
        gap: var(--space-1);
        overflow-x: auto;
        padding: var(--space-2) var(--space-3);
        border-right: none;
        border-bottom: 1px solid var(--line);
    }

    .settings-rail-group {
        display: none;
    }

    .settings-rail-link {
        white-space: nowrap;
    }
}

@media (max-width: 760px) {
    .topbar-switch-item span {
        display: none;
    }

    .topbar-switch-search .topbar-search-key {
        display: none;
    }
}

/* ---------- Toggle switch ---------- */

.toggle-switch {
    display: inline-flex;
    align-items: center;
    gap: var(--space-2);
    cursor: pointer;
}

.toggle-switch.disabled {
    cursor: not-allowed;
    opacity: 0.55;
}

.toggle-switch-input {
    position: absolute;
    width: 1px;
    height: 1px;
    margin: 0;
    opacity: 0;
}

.toggle-switch-track {
    position: relative;
    flex: none;
    width: 32px;
    height: 18px;
    border-radius: 999px;
    background: var(--line-strong);
    transition: background 0.12s ease;
}

.toggle-switch-knob {
    position: absolute;
    top: 2px;
    left: 2px;
    width: 14px;
    height: 14px;
    border-radius: 50%;
    background: #fff;
    box-shadow: var(--shadow-1);
    transition: left 0.12s ease;
}

.toggle-switch-input:checked + .toggle-switch-track {
    background: var(--accent);
}

.toggle-switch-input:checked + .toggle-switch-track .toggle-switch-knob {
    left: 16px;
}

.toggle-switch-input:focus-visible + .toggle-switch-track {
    box-shadow: 0 0 0 3px var(--accent-soft);
}

.toggle-switch-label {
    font-size: 0.85rem;
}

/* ---------- Roles master-detail ---------- */

.roles-shell {
    display: grid;
    grid-template-columns: 230px minmax(0, 1fr);
    align-items: stretch;
    min-height: 440px;
    overflow: hidden;
    border: 1px solid var(--line);
    border-radius: var(--radius-lg);
    background: var(--surface-panel);
    box-shadow: var(--shadow-1);
}

.role-readonly-note {
    display: flex;
    align-items: center;
    gap: var(--space-2);
    margin: var(--space-3) 0 var(--space-1);
    padding: var(--space-2) var(--space-3);
    border-radius: var(--radius-sm);
    background: var(--surface-muted);
    color: var(--text-muted);
    font-size: 0.82rem;
}

.role-readonly-note .icon {
    width: 15px;
    height: 15px;
}

.role-list {
    display: flex;
    flex-direction: column;
    gap: 2px;
    padding: 10px 8px;
    border-right: 1px solid var(--line);
    background: var(--surface-base);
}

.role-list-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 4px 6px 8px;
    font-size: 0.72rem;
    font-weight: 600;
    letter-spacing: 0.04em;
    text-transform: uppercase;
    color: var(--text-muted);
}

.role-list-new {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    border: none;
    background: none;
    color: var(--accent-strong);
    font: inherit;
    font-size: 0.78rem;
    font-weight: 500;
    text-transform: none;
    letter-spacing: 0;
    cursor: pointer;
}

.role-list-new .icon {
    width: 14px;
    height: 14px;
}

.role-list-group {
    margin: 8px 6px 2px;
    font-size: 0.7rem;
    font-weight: 600;
    letter-spacing: 0.04em;
    text-transform: uppercase;
    color: var(--text-muted);
}

.role-list-item {
    display: flex;
    align-items: center;
    gap: 8px;
    width: 100%;
    padding: 7px 8px;
    border: 1px solid transparent;
    border-radius: var(--radius-sm);
    background: transparent;
    color: var(--text-main);
    font: inherit;
    font-size: 0.85rem;
    text-align: left;
    cursor: pointer;
}

.role-list-item:hover {
    background: var(--surface-muted);
}

.role-list-item.active {
    border-color: var(--line);
    background: var(--surface-main);
    font-weight: 500;
    box-shadow: var(--shadow-1);
}

.role-list-item .icon {
    width: 16px;
    height: 16px;
    color: var(--text-muted);
}

.role-list-item.active .icon {
    color: var(--accent);
}

.role-list-name {
    flex: 1;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.role-list-item .status-pill {
    margin-left: auto;
}

.role-list-dot {
    flex: none;
    margin-left: auto;
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: var(--warning);
}

.role-create {
    display: flex;
    flex-direction: column;
    gap: 6px;
    margin-top: 8px;
    padding: 8px;
    border: 1px solid var(--line);
    border-radius: var(--radius-sm);
    background: var(--surface-main);
}

.role-create input,
.role-create select {
    min-height: 32px;
    padding: 0 8px;
    border: 1px solid var(--line);
    border-radius: var(--radius-sm);
    background: var(--surface-panel);
    color: var(--text-main);
}

.role-create-actions {
    display: flex;
    gap: 6px;
    justify-content: flex-end;
}

.role-detail {
    display: flex;
    flex-direction: column;
    min-width: 0;
}

.role-detail-head {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 14px 18px;
    border-bottom: 1px solid var(--line);
}

.role-detail-head h2 {
    margin: 0;
    font-size: 1rem;
    font-weight: 600;
}

.role-detail-body {
    flex: 1;
    min-height: 0;
    overflow: auto;
    padding: 4px 18px;
}

.perm-group {
    padding: 12px 0;
    border-bottom: 1px solid var(--line);
}

.perm-group:last-child {
    border-bottom: none;
}

.perm-group-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 4px;
}

.perm-group-head span {
    font-size: 0.85rem;
    font-weight: 600;
}

.perm-group-all {
    border: none;
    background: none;
    color: var(--accent-strong);
    font: inherit;
    font-size: 0.78rem;
    cursor: pointer;
}

.perm-row {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 7px 0;
}

.perm-row-label {
    flex: 1;
    min-width: 0;
    font-size: 0.85rem;
}

.perm-row .toggle-switch,
.perm-row .perm-lock {
    margin-left: auto;
}

.perm-lock {
    width: 15px;
    height: 15px;
    color: var(--text-muted);
}

.role-detail .settings-save-bar {
    border: none;
    border-top: 1px solid var(--line);
    border-radius: 0;
}

/* ---------- Access matrix ---------- */

.access-card {
    overflow: hidden;
    border: 1px solid var(--line);
    border-radius: var(--radius-lg);
    background: var(--surface-panel);
    box-shadow: var(--shadow-1);
}

.access-tools {
    display: flex;
    align-items: center;
    gap: var(--space-3);
    padding: var(--space-3) var(--space-4);
    border-bottom: 1px solid var(--line);
}

.access-tools .settings-search {
    flex: 1;
    max-width: 300px;
}

.access-count {
    margin-left: auto;
    font-size: 0.8rem;
    color: var(--text-muted);
}

.access-table-wrap {
    max-height: 60vh;
    border: none;
    border-radius: 0;
    background: transparent;
}

.access-matrix thead th {
    position: sticky;
    top: 0;
    z-index: 2;
}

.access-matrix .access-role-col {
    text-align: center;
    white-space: nowrap;
}

.access-matrix .access-cell {
    text-align: center;
    vertical-align: middle;
}

.access-matrix .access-cell.changed {
    background: color-mix(in srgb, var(--warning) 12%, transparent);
}

.access-user-col {
    min-width: 220px;
    text-align: left;
}

.access-user-text {
    display: flex;
    flex-direction: column;
    line-height: 1.2;
}

.access-user-mail {
    font-size: 0.78rem;
    color: var(--text-muted);
}

.access-card .settings-save-bar {
    border: none;
    border-top: 1px solid var(--line);
    border-radius: 0;
}

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

    .role-list {
        border-right: none;
        border-bottom: 1px solid var(--line);
    }
}

.settings-form-card > .setting-row:first-child {
    border-top: none;
}

.access-table-wrap thead th {
    position: sticky;
    top: 0;
    z-index: 2;
}

.access-card .pagination-row {
    justify-content: flex-end;
    padding: var(--space-3) var(--space-4);
    border-top: 1px solid var(--line);
}

.table-actions-col {
    text-align: right;
    white-space: nowrap;
}

.admin-table .table-checks {
    flex-direction: column;
    align-items: flex-start;
    gap: 5px;
}

/* ---------- Recent changes ---------- */

.changes-view {
    max-width: 880px;
    margin: 0 auto;
    padding: var(--space-5);
    display: grid;
    gap: var(--space-4);
}

.changes-header h1 {
    margin: 0;
    color: var(--text-main);
}

.changes-header p {
    margin: var(--space-1) 0 0;
    color: var(--text-muted);
}

.changes-empty {
    min-height: 200px;
    display: grid;
    place-content: center;
    gap: var(--space-2);
    justify-items: center;
    text-align: center;
    color: var(--text-muted);
}

.change-run {
    display: grid;
    gap: var(--space-3);
    padding-top: var(--space-4);
    border-top: 1px solid var(--line);
}

.change-run:first-of-type {
    border-top: 0;
    padding-top: 0;
}

.change-run-head {
    display: flex;
    align-items: center;
    gap: var(--space-3);
    flex-wrap: wrap;
}

.change-run-head h2 {
    margin: 0;
    color: var(--text-main);
}

.run-status {
    font-size: 0.75rem;
    font-weight: 600;
    padding: 2px var(--space-2);
    border-radius: var(--radius-sm);
}

.run-status-succeeded {
    background: var(--accent-soft);
    color: var(--accent-strong);
}

.run-status-running {
    background: var(--surface-muted);
    color: var(--text-muted);
}

.run-status-failed {
    background: var(--danger-soft);
    color: var(--danger);
}

.run-meta {
    font-size: 0.85rem;
    color: var(--text-muted);
}

.run-window {
    margin: 0;
    font-size: 0.8rem;
    color: var(--text-muted);
}

.run-error {
    margin: 0;
    color: var(--danger);
    font-size: 0.85rem;
}

.change-run-loading,
.change-run-empty,
.change-card-loading {
    color: var(--text-muted);
    font-size: 0.85rem;
}

.change-project {
    margin: var(--space-2) 0 0;
    font-size: 0.78rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: var(--text-muted);
}

.change-card {
    display: grid;
    gap: var(--space-3);
    padding: var(--space-4);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    background: var(--surface-main);
}

.change-card-head {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: var(--space-3);
}

.change-breadcrumb {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 4px;
    min-width: 0;
    border: 0;
    background: none;
    padding: 2px var(--space-2);
    margin: -2px calc(-1 * var(--space-2));
    border-radius: var(--radius-sm);
    font: inherit;
    font-size: 0.85rem;
    text-align: left;
    cursor: pointer;
    transition: background 0.12s ease;
}

.change-breadcrumb:hover {
    background: var(--surface-muted);
}

.change-breadcrumb:hover .change-breadcrumb-name {
    text-decoration: underline;
}

.change-breadcrumb-seg {
    color: var(--text-muted);
}

.change-breadcrumb-name {
    font-weight: 600;
    color: var(--text-main);
}

.change-breadcrumb-sep {
    width: 13px;
    height: 13px;
    color: var(--text-muted);
    opacity: 0.7;
}

.change-stats {
    display: flex;
    gap: var(--space-2);
    flex-shrink: 0;
}

.diff-stat {
    font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
    font-size: 0.78rem;
    font-weight: 600;
    padding: 2px var(--space-2);
    border-radius: var(--radius-sm);
}

.diff-stat-added {
    background: var(--accent-soft);
    color: var(--accent-strong);
}

.diff-stat-removed {
    background: var(--danger-soft);
    color: var(--danger);
}

.diff-stat-muted {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    background: var(--surface-muted);
    color: var(--text-muted);
    font-weight: 500;
}

.change-card-foot {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: var(--space-3);
    flex-wrap: wrap;
}

.editor-row {
    display: flex;
    align-items: center;
    gap: var(--space-2);
    min-width: 0;
}

.editor-avatars {
    display: flex;
}

.editor-avatar {
    width: 26px;
    height: 26px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    background: var(--accent-soft);
    color: var(--accent-strong);
    font-size: 0.66rem;
    font-weight: 600;
    border: 2px solid var(--surface-main);
}

.editor-avatar + .editor-avatar {
    margin-left: -8px;
}

.editor-summary {
    font-size: 0.82rem;
    color: var(--text-muted);
}

.diff-toggle {
    min-height: 28px;
    padding: 0 var(--space-3);
    font-size: 0.82rem;
}

.history-stats {
    display: inline-flex;
    gap: var(--space-2);
}

/* ---------- Unified diff ---------- */

.unified-diff {
    border: 1px solid var(--line);
    border-radius: var(--radius-sm);
    overflow: auto;
    font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
    font-size: 0.78rem;
    line-height: 1.6;
}

.unified-diff-empty {
    color: var(--text-muted);
    font-size: 0.82rem;
}

.diff-line {
    padding: 1px var(--space-3);
    white-space: pre-wrap;
    word-break: break-word;
}

.diff-line-header {
    background: var(--surface-muted);
    color: var(--text-muted);
}

.diff-line-added {
    background: var(--accent-soft);
    color: var(--accent-strong);
}

.diff-line-removed {
    background: var(--danger-soft);
    color: var(--danger);
}

.diff-line-context {
    color: var(--text-main);
}

/* ---------- Workspace / Changes switcher ---------- */

.topbar-switch {
    position: absolute;
    left: 50%;
    transform: translateX(-50%);
    display: inline-flex;
    gap: 2px;
    padding: 3px;
    background: var(--surface-muted);
    border-radius: var(--radius-sm);
}

.topbar-switch-item {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 4px 10px;
    border: 0;
    background: none;
    border-radius: calc(var(--radius-sm) - 3px);
    color: var(--text-muted);
    font: inherit;
    font-size: 0.85rem;
    font-weight: 500;
    text-decoration: none;
    white-space: nowrap;
    cursor: pointer;
}

.topbar-switch-item:hover {
    color: var(--text-main);
}

.topbar-switch-item.active {
    background: var(--surface-panel);
    color: var(--text-main);
    box-shadow: var(--shadow-1);
}

.topbar-switch-item .icon {
    width: 15px;
    height: 15px;
}

/* ---------- Clickable document meta ---------- */

.doc-meta-trigger {
    border: 0;
    background: none;
    padding: 2px var(--space-3);
    margin-left: calc(-1 * var(--space-3));
    border-radius: var(--radius-sm);
    cursor: pointer;
    transition: background 0.12s ease, color 0.12s ease;
}

.doc-meta-trigger:hover {
    background: var(--surface-muted);
    color: var(--text-main);
}

.doc-meta-history-icon {
    width: 14px;
    height: 14px;
    opacity: 0.7;
}

/* ---------- Document history dialog ---------- */

.modal-panel-wide {
    width: min(860px, 100%);
}

.history-dialog-loading {
    color: var(--text-muted);
    font-size: 0.85rem;
}

.history-dialog {
    display: grid;
    grid-template-columns: 240px minmax(0, 1fr);
    height: min(70vh, 560px);
}

.history-rev-list {
    display: flex;
    flex-direction: column;
    min-height: 0;
    overflow: auto;
    border-right: 1px solid var(--line);
}

.history-rev {
    display: grid;
    gap: 2px;
    padding: var(--space-3) var(--space-4);
    border: 0;
    border-left: 2px solid transparent;
    background: none;
    text-align: left;
    cursor: pointer;
}

.history-rev:hover {
    background: var(--surface-muted);
}

.history-rev.active {
    border-left-color: var(--accent);
    background: var(--surface-muted);
}

.history-rev-top {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: var(--space-2);
}

.history-rev-time {
    font-size: 0.82rem;
    font-weight: 500;
    color: var(--text-main);
}

.history-rev-actor {
    font-size: 0.78rem;
    color: var(--text-muted);
}

.history-rename {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    margin-top: 4px;
    padding: 2px var(--space-2);
    border-radius: var(--radius-sm);
    background: var(--accent-soft);
    color: var(--accent-strong);
    font-size: 0.74rem;
    line-height: 1.3;
}

.history-rename .icon {
    width: 12px;
    height: 12px;
    flex: none;
}

.history-rename s {
    opacity: 0.7;
}

.history-detail-pane {
    display: flex;
    flex-direction: column;
    min-width: 0;
    min-height: 0;
}

.history-detail-bar {
    flex: none;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: var(--space-3);
    padding: var(--space-3) var(--space-4);
    border-bottom: 1px solid var(--line);
}

.history-detail-content {
    flex: 1 1 auto;
    min-height: 0;
    overflow: auto;
    display: flex;
    flex-direction: column;
    gap: var(--space-3);
    padding: var(--space-4);
}

.history-detail-head {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: var(--space-3);
}

.history-detail-title {
    margin: 0;
    font-weight: 600;
    color: var(--text-main);
}

.history-detail-sub {
    margin: var(--space-1) 0 0;
    font-size: 0.82rem;
    color: var(--text-muted);
}
