/* ============================================================
   GitHub-Inspired Design System — XML Editor
   ============================================================ */

/* ── CSS Custom Properties ─────────────────────────────────── */
:root {
    /* GitHub palette */
    --color-header-bg: #24292e;
    --color-header-text: #ffffff;
    --color-header-hover: #57606a;
    --color-bg-primary: #ffffff;
    --color-bg-secondary: #f6f8fa;
    --color-bg-tertiary: #eef1f5;
    --color-border: #d0d7de;
    --color-border-muted: #d8dee4;
    --color-text-primary: #1f2328;
    --color-text-secondary: #656d76;
    --color-text-muted: #8b949e;
    --color-link: #0969da;
    --color-accent-fg: #0969da;
    --color-success: #1a7f37;
    --color-success-bg: #dafbe1;
    --color-danger: #cf222e;
    --color-danger-bg: #ffebe9;
    --color-warning: #9a6700;
    --color-warning-bg: #fff8c5;
    --color-info-bg: #ddf4ff;

    /* Spacing */
    --space-1: 4px;
    --space-2: 8px;
    --space-3: 16px;
    --space-4: 24px;
    --space-5: 32px;
    --space-6: 40px;

    /* Typography */
    --font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Noto Sans", Helvetica, Arial, sans-serif;
    --font-mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, "Liberation Mono", monospace;
    --font-size-sm: 12px;
    --font-size-md: 14px;
    --font-size-lg: 16px;
    --font-size-xl: 20px;
    --font-size-xxl: 24px;

    /* Borders */
    --border-radius: 6px;
    --border-radius-sm: 4px;
    --border-radius-lg: 8px;

    /* Shadows */
    --shadow-sm: 0 1px 0 rgba(31, 35, 40, 0.04);
    --shadow-md: 0 3px 6px rgba(140, 149, 159, 0.15);
    --shadow-lg: 0 8px 24px rgba(140, 149, 159, 0.2);
}

/* ── Reset & Base ──────────────────────────────────────────── */
*, *::before, *::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

html, body {
    height: 100%;
    font-family: var(--font-family);
    font-size: var(--font-size-md);
    line-height: 1.5;
    color: var(--color-text-primary);
    background: var(--color-bg-secondary);
    -webkit-font-smoothing: antialiased;
}

a {
    color: var(--color-link);
    text-decoration: none;
}
a:hover {
    text-decoration: underline;
}

/* ── Header ────────────────────────────────────────────────── */
.app-header {
    background: var(--color-header-bg);
    height: 64px;
    display: flex;
    align-items: center;
    padding: 0 var(--space-4);
    position: sticky;
    top: 0;
    z-index: 1000;
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.3);
}

.header-logo {
    display: flex;
    align-items: center;
    gap: var(--space-2);
    color: var(--color-header-text);
    font-size: var(--font-size-xl);
    font-weight: 600;
    text-decoration: none;
    margin-right: var(--space-5);
}
.header-logo:hover {
    text-decoration: none;
    opacity: 0.85;
}

.header-logo svg {
    width: 32px;
    height: 32px;
    fill: var(--color-header-text);
}

.header-nav {
    display: flex;
    gap: var(--space-1);
    flex: 1;
}

.header-nav a {
    color: rgba(255, 255, 255, 0.85);
    padding: var(--space-2) var(--space-3);
    border-radius: var(--border-radius);
    font-size: var(--font-size-md);
    font-weight: 500;
    transition: all 0.15s ease;
    text-decoration: none;
}
.header-nav a:hover {
    background: rgba(255, 255, 255, 0.12);
    color: #fff;
    text-decoration: none;
}
.header-nav a.active {
    background: rgba(255, 255, 255, 0.15);
    color: #fff;
    font-weight: 600;
}

/* ── Sub-header (breadcrumb bar) ───────────────────────────── */
.sub-header {
    background: var(--color-bg-primary);
    border-bottom: 1px solid var(--color-border);
    padding: var(--space-3) var(--space-4);
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.breadcrumb {
    display: flex;
    align-items: center;
    gap: var(--space-2);
    font-size: var(--font-size-md);
    color: var(--color-text-secondary);
}

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

.breadcrumb-current {
    font-weight: 600;
    color: var(--color-text-primary);
}

/* ── Main content ──────────────────────────────────────────── */
.main-content {
    max-width: 1280px;
    margin: 0 auto;
    padding: var(--space-4);
    min-height: calc(100vh - 64px);
}

.main-content.full-width {
    max-width: 100%;
    padding: 0;
}

/* ── Buttons ───────────────────────────────────────────────── */
.btn {
    display: inline-flex;
    align-items: center;
    gap: var(--space-2);
    padding: 5px 16px;
    font-size: var(--font-size-md);
    font-weight: 500;
    font-family: var(--font-family);
    line-height: 20px;
    white-space: nowrap;
    cursor: pointer;
    border: 1px solid;
    border-radius: var(--border-radius);
    transition: all 0.2s cubic-bezier(0.3, 0, 0.5, 1);
    appearance: none;
    user-select: none;
}

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

.btn-primary {
    background: #1a7f37;
    border-color: rgba(27, 31, 36, 0.15);
    color: #fff;
    box-shadow: 0 1px 0 rgba(27, 31, 36, 0.04), inset 0 1px 0 rgba(255, 255, 255, 0.25);
}
.btn-primary:hover:not(:disabled) {
    background: #188636;
}

.btn-outline {
    background: var(--color-bg-secondary);
    border-color: var(--color-border);
    color: var(--color-text-primary);
    box-shadow: var(--shadow-sm);
}
.btn-outline:hover:not(:disabled) {
    background: var(--color-bg-tertiary);
}

.btn-danger {
    background: var(--color-danger);
    border-color: rgba(27, 31, 36, 0.15);
    color: #fff;
}
.btn-danger:hover:not(:disabled) {
    background: #a40e26;
}

.btn-sm {
    padding: 3px 12px;
    font-size: var(--font-size-sm);
}

.btn-icon {
    padding: 5px 8px;
}

.editor-layout-toggle {
    width: 32px;
    height: 28px;
    justify-content: center;
}

.editor-layout-toggle svg {
    width: 16px;
    height: 16px;
    display: block;
    fill: none;
    stroke: currentColor;
    stroke-width: 1.8;
}

/* ── Shared React UI primitives ────────────────────────────── */
.ui-button {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: var(--space-2);
    min-height: 32px;
    padding: 5px 12px;
    border: 1px solid var(--color-border);
    border-radius: var(--border-radius-sm);
    background: var(--color-bg-primary);
    color: var(--color-text-primary);
    font-family: var(--font-family);
    font-size: var(--font-size-md);
    font-weight: 600;
    line-height: 1.25;
    white-space: nowrap;
    cursor: pointer;
    appearance: none;
    user-select: none;
}

.ui-button:hover:not(:disabled),
.ui-button:focus {
    background: var(--color-bg-tertiary);
    outline: none;
}

.ui-button:focus-visible {
    border-color: var(--color-accent-fg);
    box-shadow: 0 0 0 2px rgba(9, 105, 218, 0.16);
}

.ui-button:disabled {
    opacity: 0.55;
    cursor: not-allowed;
}

.ui-button-sm {
    min-height: 30px;
    padding: 4px 9px;
    font-size: var(--font-size-sm);
}

.ui-button-primary {
    border-color: var(--color-accent-fg);
    background: var(--color-accent-fg);
    color: #fff;
}

.ui-button-primary:hover:not(:disabled),
.ui-button-primary:focus {
    background: #0550ae;
}

.ui-button-danger {
    border-color: var(--color-danger);
    color: var(--color-danger);
}

.ui-button-danger:hover:not(:disabled),
.ui-button-danger:focus {
    background: var(--color-danger-bg);
    color: var(--color-danger);
}

.ui-button-ghost {
    border-color: transparent;
    background: transparent;
}

.ui-icon-button {
    width: 32px;
    padding-inline: 0;
}

.ui-popover {
    position: fixed;
    z-index: 3900;
    background: var(--color-bg-primary);
    border: 1px solid var(--color-border);
    border-radius: var(--border-radius);
    box-shadow: var(--shadow-lg);
    box-sizing: border-box;
}

.ui-menu {
    z-index: 4000;
    display: flex;
    flex-direction: column;
    min-width: 220px;
    max-width: min(320px, calc(100vw - 16px));
    max-height: min(420px, calc(100vh - 16px));
    padding: 4px;
    overflow-y: auto;
    overscroll-behavior: contain;
}

.ui-menu-item {
    display: flex;
    align-items: center;
    width: 100%;
    min-height: 32px;
    padding: 6px 10px;
    border: 0;
    border-radius: var(--border-radius-sm);
    background: transparent;
    color: var(--color-text-primary);
    font: inherit;
    font-size: 13px;
    line-height: 1.25;
    text-align: left;
    cursor: pointer;
}

.ui-menu-item:hover,
.ui-menu-item:focus {
    background: var(--color-info-bg);
    color: var(--color-accent-fg);
    outline: none;
}

.ui-menu-item.is-destructive {
    color: var(--color-danger);
}

.ui-menu-item.is-destructive:hover,
.ui-menu-item.is-destructive:focus {
    background: var(--color-danger-bg);
    color: var(--color-danger);
}

.ui-toolbar {
    display: flex;
    align-items: center;
    gap: 4px;
    max-width: min(440px, calc(100vw - 16px));
    padding: 4px;
    overflow-x: auto;
}

.ui-toolbar-button {
    flex: 0 0 auto;
    max-width: 132px;
    overflow: hidden;
    text-overflow: ellipsis;
}

.ui-form-popover {
    z-index: 4100;
    display: grid;
    grid-template-columns: 1fr;
    gap: 8px;
    width: min(300px, calc(100vw - 16px));
    padding: 10px;
}

.ui-field {
    display: grid;
    gap: 6px;
}

.ui-field-label {
    display: block;
    overflow: hidden;
    color: var(--color-text-secondary);
    font-size: var(--font-size-sm);
    font-weight: 700;
    line-height: 1.2;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.ui-field-control {
    width: 100%;
    min-height: 32px;
    padding: 5px 8px;
    border: 1px solid var(--color-border);
    border-radius: var(--border-radius-sm);
    background: var(--color-bg-primary);
    color: var(--color-text-primary);
    font: inherit;
    font-size: 13px;
    line-height: 1.3;
}

.ui-field-control:focus {
    border-color: var(--color-accent-fg);
    box-shadow: 0 0 0 2px rgba(9, 105, 218, 0.16);
    outline: none;
}

.ui-dialog-backdrop {
    position: fixed;
    inset: 0;
    z-index: 5000;
    display: grid;
    place-items: center;
    padding: var(--space-3);
    background: rgba(31, 35, 40, 0.42);
}

.ui-dialog {
    width: min(520px, 100%);
    max-height: min(720px, calc(100vh - 32px));
    overflow: auto;
    background: var(--color-bg-primary);
    border: 1px solid var(--color-border);
    border-radius: var(--border-radius-lg);
    box-shadow: var(--shadow-lg);
}

.ui-tabs {
    display: inline-flex;
    align-items: center;
    gap: 2px;
    padding: 2px;
    border: 1px solid var(--color-border);
    border-radius: var(--border-radius);
    background: var(--color-bg-secondary);
}

.ui-tab {
    min-height: 28px;
    padding: 4px 10px;
    border: 0;
    border-radius: var(--border-radius-sm);
    background: transparent;
    color: var(--color-text-secondary);
    font: inherit;
    font-size: var(--font-size-sm);
    font-weight: 600;
    cursor: pointer;
}

.ui-tab[aria-selected="true"] {
    background: var(--color-bg-primary);
    color: var(--color-text-primary);
    box-shadow: var(--shadow-sm);
}

.ui-badge {
    display: inline-flex;
    align-items: center;
    min-height: 20px;
    padding: 1px 7px;
    border: 1px solid var(--color-border);
    border-radius: 999px;
    background: var(--color-bg-secondary);
    color: var(--color-text-secondary);
    font-size: var(--font-size-sm);
    font-weight: 700;
    line-height: 1.2;
}

.ui-badge-primary {
    border-color: rgba(9, 105, 218, 0.32);
    background: var(--color-info-bg);
    color: var(--color-accent-fg);
}

.ui-badge-danger {
    border-color: rgba(207, 34, 46, 0.32);
    background: var(--color-danger-bg);
    color: var(--color-danger);
}

.ui-toast {
    padding: var(--space-2) var(--space-3);
    border: 1px solid var(--color-border);
    border-radius: var(--border-radius);
    background: var(--color-bg-primary);
    box-shadow: var(--shadow-lg);
    color: var(--color-text-primary);
    font-size: var(--font-size-sm);
    font-weight: 600;
}

.ui-toast-success {
    border-color: var(--color-success);
    background: var(--color-success-bg);
    color: var(--color-success);
}

.ui-toast-error {
    border-color: var(--color-danger);
    background: var(--color-danger-bg);
    color: var(--color-danger);
}

.ui-toast-warning {
    border-color: var(--color-warning);
    background: var(--color-warning-bg);
    color: var(--color-warning);
}

.ui-toast-info {
    border-color: rgba(9, 105, 218, 0.28);
    background: var(--color-info-bg);
    color: var(--color-accent-fg);
}

.ui-element-handle,
.ui-table-row-handle {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 18px;
    height: 18px;
    padding: 0 5px;
    border: 1px solid var(--color-border);
    border-radius: var(--border-radius-sm);
    background: var(--color-bg-secondary);
    color: var(--color-text-secondary);
    font-family: var(--font-mono);
    font-size: 11px;
    font-weight: 700;
    line-height: 1;
}

/* ── Toolbar ───────────────────────────────────────────────── */
.toolbar {
    background: var(--color-bg-secondary);
    border: 1px solid var(--color-border);
    border-radius: var(--border-radius-lg) var(--border-radius-lg) 0 0;
    padding: var(--space-2) var(--space-3);
    display: flex;
    align-items: center;
    gap: var(--space-2);
    flex-wrap: wrap;
}

.toolbar-separator {
    width: 1px;
    height: 20px;
    background: var(--color-border);
    margin: 0 var(--space-2);
}

.toolbar-status {
    margin-left: auto;
    font-size: var(--font-size-sm);
    color: var(--color-text-muted);
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: var(--space-2);
    min-width: 0;
    flex: 1 1 auto;
}

.schema-badge {
    display: inline-flex;
    align-items: center;
    min-width: 0;
    max-width: none;
    height: 28px;
    border: 1px solid var(--color-border);
    border-radius: var(--border-radius);
    background: var(--color-bg-primary);
    color: var(--color-text-primary);
    font-size: var(--font-size-sm);
    overflow: hidden;
    position: relative;
}

.schema-badge-label {
    flex: 0 0 auto;
    align-self: stretch;
    display: inline-flex;
    align-items: center;
    padding: 0 var(--space-2);
    background: var(--color-info-bg);
    color: var(--color-accent-fg);
    border-right: 1px solid var(--color-border);
    font-weight: 600;
}

.schema-badge-name {
    position: absolute;
    width: 1px;
    height: 1px;
    margin: -1px;
    padding: 0;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}

.schema-badge.empty .schema-badge-label {
    background: var(--color-warning-bg);
    color: var(--color-warning);
}

.schema-badge.empty .schema-badge-name {
    color: var(--color-text-muted);
    font-family: var(--font-family);
}

.editor-resource-badges {
    display: inline-flex;
    align-items: center;
    gap: var(--space-1);
    min-width: 0;
    flex: 0 1 auto;
}

.schema-badge-compact {
    max-width: none;
}

#active-schema-badge.schema-badge-compact {
    max-width: none;
}

#active-document-badge.schema-badge-compact {
    max-width: none;
}

.toolbar-status-message {
    display: inline-flex;
    align-items: center;
    gap: var(--space-2);
    flex: 0 0 auto;
    min-width: 0;
}

/* ── Editor container ──────────────────────────────────────── */
.editor-wrapper {
    display: flex;
    height: calc(100vh - 64px);
    overflow: hidden;
}

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

.editor-main-panel {
    padding: 0 16px 16px 16px;
}

.editor-container {
    position: relative;
    flex: 1;
    overflow: auto;
    background: var(--color-bg-primary);
    border: 1px solid var(--color-border);
    border-top: none;
    border-radius: 0 0 var(--border-radius-lg) var(--border-radius-lg);
    padding: var(--space-3);
}

.editor-shell .toolbar {
    position: relative;
    z-index: 2000;
    align-items: center;
    flex-wrap: nowrap;
    overflow: visible;
    white-space: nowrap;
}

.editor-shell .dropdown-menu {
    z-index: 2100;
}

.editor-view-dropdown {
    flex: 0 0 auto;
}

.editor-view-menu {
    min-width: 180px;
}

.editor-view-menu-item.active {
    background: var(--color-info-bg);
    color: var(--color-accent-fg);
    font-weight: 700;
}

.editor-view-menu-item:disabled {
    color: var(--color-text-muted);
    cursor: not-allowed;
    opacity: 0.65;
}

.editor-view-menu-item:disabled:hover {
    background: transparent;
}

.editor-view-select-native {
    position: absolute;
    width: 1px;
    height: 1px;
    margin: -1px;
    padding: 0;
    border: 0;
    opacity: 0;
    pointer-events: none;
}

.editor-shell-panels {
    position: relative;
    z-index: 1;
    flex: 1;
    min-height: 0;
    display: flex;
    background: var(--color-bg-primary);
    border: 1px solid var(--color-border);
    border-top: none;
    border-radius: 0 0 var(--border-radius-lg) var(--border-radius-lg);
    overflow: hidden;
}

.editor-shell-panel {
    min-width: 0;
    display: flex;
    flex: 1 1 auto;
    flex-direction: column;
    overflow: hidden;
    background: var(--color-bg-primary);
}

.editor-shell-panel.active {
    box-shadow: inset 0 0 0 2px rgba(9, 105, 218, 0.28);
}

.editor-panel-header {
    min-height: 32px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: var(--space-2);
    padding: 5px var(--space-3);
    border-bottom: 1px solid var(--color-border);
    background: var(--color-bg-secondary);
    color: var(--color-text-secondary);
    font-size: var(--font-size-sm);
}

.editor-panel-header strong {
    color: var(--color-text-primary);
    font-weight: 700;
}

.editor-legacy-host,
.authentic-view-host {
    min-height: 0;
    display: flex;
    flex: 1;
    flex-direction: column;
}

.editor-shell .editor-container {
    border: none;
    border-radius: 0;
}

.editor-splitter {
    flex: 0 0 6px;
    background: var(--color-border-muted);
    border-left: 1px solid var(--color-border);
    border-right: 1px solid var(--color-border);
    cursor: col-resize;
}

.editor-splitter:focus-visible {
    outline: 2px solid var(--color-accent-fg);
    outline-offset: -2px;
}

.editor-placeholder-view {
    flex: 1;
    display: flex;
    flex-direction: column;
    justify-content: center;
    padding: var(--space-5);
    background: var(--color-bg-primary);
    color: var(--color-text-secondary);
}

.editor-placeholder-view h3 {
    margin: 0 0 var(--space-2);
    color: var(--color-text-primary);
    font-size: var(--font-size-xl);
}

.editor-placeholder-view p {
    max-width: 52ch;
}

.editor-html-preview-view {
    flex: 1;
    min-height: 0;
    display: flex;
    flex-direction: column;
    background: var(--color-bg-primary);
}

.editor-html-preview-view .preview-body {
    padding: var(--space-2);
}

.editor-html-preview-view .preview-body > *,
.editor-html-preview-view .preview-body .page {
    width: 100% !important;
    max-width: none !important;
    margin-left: 0 !important;
    margin-right: 0 !important;
    box-shadow: none !important;
}

.editor-html-preview-view .preview-body .page {
    min-height: auto !important;
}

.editor-html-preview-view .preview-body table {
    max-width: 100%;
}

.editor-html-preview-view .preview-body > .editor-view-loading {
    width: max-content !important;
    max-width: calc(100% - var(--space-4)) !important;
    margin: var(--space-4) auto !important;
}

.editor-raw-xml-view {
    flex: 1;
    min-height: 0;
    overflow: auto;
    background: var(--color-bg-primary);
}

.raw-xml-source {
    min-height: 100%;
    margin: 0;
    padding: var(--space-3);
    color: var(--color-text-primary);
    font-family: var(--font-mono);
    font-size: var(--font-size-sm);
    line-height: 1.55;
    white-space: pre;
    tab-size: 2;
}

.editor-loading {
    position: absolute;
    inset: 0;
    z-index: 20;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(255, 255, 255, 0.82);
    backdrop-filter: blur(1px);
}

.editor-loading-panel {
    display: flex;
    align-items: center;
    gap: var(--space-2);
    padding: var(--space-3) var(--space-4);
    border: 1px solid var(--color-border);
    border-radius: var(--border-radius);
    background: var(--color-bg-primary);
    box-shadow: var(--shadow-md);
    color: var(--color-text-secondary);
    font-size: var(--font-size-md);
    font-weight: 600;
}

.editor-view-loading {
    width: max-content;
    max-width: calc(100% - var(--space-4));
    margin: var(--space-4) auto;
}

/* ── Preview panel ─────────────────────────────────────────── */
.preview-panel {
    width: 0;
    overflow: hidden;
    border-left: 1px solid var(--color-border);
    background: var(--color-bg-primary);
    transition: width 0.3s ease;
    display: flex;
    flex-direction: column;
}

.preview-panel.open {
    width: 50%;
    min-width: 400px;
}

.preview-header {
    background: var(--color-bg-secondary);
    border-bottom: 1px solid var(--color-border);
    padding: var(--space-2) var(--space-3);
    display: flex;
    align-items: center;
    justify-content: space-between;
    font-size: var(--font-size-sm);
    font-weight: 600;
    color: var(--color-text-secondary);
}

.preview-body {
    flex: 1;
    overflow: auto;
    padding: var(--space-4);
}

.preview-body iframe {
    width: 100%;
    height: 100%;
    border: none;
}

/* ── Settings layout ───────────────────────────────────────── */
.settings-layout {
    display: flex;
    gap: var(--space-5);
    max-width: 1012px;
    margin: 0 auto;
    padding: var(--space-4) var(--space-4);
}

.settings-sidebar {
    width: 220px;
    flex-shrink: 0;
}

.settings-sidebar a {
    display: flex;
    align-items: center;
    gap: var(--space-2);
    padding: var(--space-2) var(--space-3);
    border-radius: var(--border-radius);
    color: var(--color-text-primary);
    font-size: var(--font-size-md);
    text-decoration: none;
    margin-bottom: 2px;
    transition: background 0.15s ease;
}
.settings-sidebar a:hover {
    background: var(--color-bg-tertiary);
    text-decoration: none;
}
.settings-sidebar a.active {
    background: var(--color-bg-tertiary);
    font-weight: 600;
}

.settings-nav-icon {
    width: 55px;
    color: var(--color-text-muted);
    font-family: var(--font-mono);
    font-size: 11px;
    font-weight: 700;
}

.settings-main {
    flex: 1;
    min-width: 0;
}

.settings-section {
    padding-bottom: var(--space-5);
    margin-bottom: var(--space-5);
    border-bottom: 1px solid var(--color-border);
}

.settings-section:last-child {
    border-bottom: none;
}

.settings-section h2 {
    font-size: var(--font-size-xl);
    font-weight: 600;
    margin-bottom: var(--space-2);
}

.settings-section h3 {
    font-size: var(--font-size-lg);
    font-weight: 600;
    margin-bottom: var(--space-2);
    margin-top: var(--space-4);
}

.settings-section p {
    color: var(--color-text-secondary);
    margin-bottom: var(--space-3);
    font-size: var(--font-size-md);
}

.settings-card-spacing {
    margin-bottom: var(--space-4);
}

.settings-empty-compact {
    padding: var(--space-3);
}

.settings-empty-compact .spinner {
    margin: 0 auto var(--space-2);
}

/* ── Cards ─────────────────────────────────────────────────── */
.card {
    background: var(--color-bg-primary);
    border: 1px solid var(--color-border);
    border-radius: var(--border-radius-lg);
    overflow: hidden;
}

.card-header {
    background: var(--color-bg-secondary);
    border-bottom: 1px solid var(--color-border);
    padding: var(--space-3) var(--space-4);
    font-weight: 600;
    font-size: var(--font-size-md);
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.card-body {
    padding: var(--space-4);
}

/* ── Upload zone ───────────────────────────────────────────── */
.upload-zone {
    border: 2px dashed var(--color-border);
    border-radius: var(--border-radius-lg);
    padding: var(--space-6);
    text-align: center;
    cursor: pointer;
    transition: all 0.2s ease;
    background: var(--color-bg-secondary);
}

.upload-zone:hover {
    border-color: var(--color-accent-fg);
    background: var(--color-info-bg);
}

.upload-zone.drag-over {
    border-color: var(--color-accent-fg);
    background: var(--color-info-bg);
    box-shadow: 0 0 0 3px rgba(9, 105, 218, 0.15);
}

.upload-zone-icon {
    font-size: 48px;
    color: var(--color-text-muted);
    margin-bottom: var(--space-3);
}

.upload-zone-text {
    font-size: var(--font-size-md);
    color: var(--color-text-secondary);
}

.upload-zone-text strong {
    color: var(--color-accent-fg);
}

.upload-zone.busy {
    pointer-events: none;
    opacity: 0.8;
    border-color: var(--color-accent-fg);
    background: var(--color-info-bg);
}

.upload-zone.busy .upload-zone-icon {
    display: inline-block;
    animation: spin 1s linear infinite;
}

.upload-zone.busy .upload-zone-text::after {
    content: " — Processing...";
    font-weight: 600;
    color: var(--color-accent-fg);
}

/* ── File info ─────────────────────────────────────────────── */
.file-info {
    display: flex;
    align-items: center;
    gap: var(--space-3);
    padding: var(--space-3);
    background: var(--color-bg-secondary);
    border: 1px solid var(--color-border);
    border-radius: var(--border-radius);
}

.file-info-icon {
    width: 40px;
    height: 40px;
    background: var(--color-success-bg);
    border-radius: var(--border-radius);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 18px;
    color: var(--color-success);
}

.file-info-details {
    flex: 1;
}

.file-info-name {
    font-weight: 600;
    font-size: var(--font-size-md);
}

.file-info-meta {
    font-size: var(--font-size-sm);
    color: var(--color-text-muted);
}

/* ── Toast Notifications ───────────────────────────────────── */
.toast-container {
    position: fixed;
    top: 76px;
    right: var(--space-4);
    z-index: 2000;
    display: flex;
    flex-direction: column;
    gap: var(--space-2);
}

.toast {
    padding: var(--space-3) var(--space-4);
    border-radius: var(--border-radius);
    font-size: var(--font-size-md);
    font-weight: 500;
    box-shadow: var(--shadow-lg);
    min-width: 300px;
    max-width: 450px;
    display: flex;
    align-items: center;
    gap: var(--space-2);
    animation: slideIn 0.3s ease, fadeOut 0.3s ease 3s forwards;
    border: 1px solid;
}

.toast-success {
    background: var(--color-success-bg);
    color: var(--color-success);
    border-color: #aae4b3;
}

.toast-error {
    background: var(--color-danger-bg);
    color: var(--color-danger);
    border-color: #ffc8c8;
}

.toast-warning {
    background: var(--color-warning-bg);
    color: var(--color-warning);
    border-color: #eed07d;
}

.toast-info {
    background: var(--color-info-bg);
    color: var(--color-accent-fg);
    border-color: #9ec8f5;
}

@keyframes slideIn {
    from { transform: translateX(100%); opacity: 0; }
    to { transform: translateX(0); opacity: 1; }
}

@keyframes fadeOut {
    to { opacity: 0; transform: translateX(50%); }
}

/* ── Modal ─────────────────────────────────────────────────── */
.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.5);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 3000;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.2s ease;
}

.modal-overlay.visible {
    opacity: 1;
    pointer-events: auto;
}

.modal {
    background: var(--color-bg-primary);
    border-radius: var(--border-radius-lg);
    box-shadow: var(--shadow-lg);
    width: 440px;
    max-width: 90vw;
    animation: modalSlideUp 0.2s ease;
}

.modal-header {
    padding: var(--space-3) var(--space-4);
    border-bottom: 1px solid var(--color-border);
    display: flex;
    align-items: center;
    justify-content: space-between;
    font-weight: 600;
    font-size: var(--font-size-lg);
}

.modal-body {
    padding: var(--space-4);
}

.modal-footer {
    padding: var(--space-3) var(--space-4);
    border-top: 1px solid var(--color-border);
    display: flex;
    justify-content: flex-end;
    gap: var(--space-2);
}

@keyframes modalSlideUp {
    from { transform: translateY(20px); opacity: 0; }
    to { transform: translateY(0); opacity: 1; }
}

/* ── Form elements ─────────────────────────────────────────── */
.form-group {
    margin-bottom: var(--space-3);
}

.form-label {
    display: block;
    font-size: var(--font-size-md);
    font-weight: 600;
    margin-bottom: var(--space-1);
    color: var(--color-text-primary);
}

.form-input {
    width: 100%;
    padding: 5px 12px;
    font-size: var(--font-size-md);
    font-family: var(--font-family);
    line-height: 20px;
    color: var(--color-text-primary);
    background: var(--color-bg-primary);
    border: 1px solid var(--color-border);
    border-radius: var(--border-radius);
    transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

.form-input:focus {
    outline: none;
    border-color: var(--color-accent-fg);
    box-shadow: 0 0 0 3px rgba(9, 105, 218, 0.15);
}

/* ── Dropdown ──────────────────────────────────────────────── */
.dropdown {
    position: relative;
    display: inline-block;
}

.dropdown-menu {
    position: absolute;
    top: 100%;
    left: 0;
    margin-top: var(--space-1);
    background: var(--color-bg-primary);
    border: 1px solid var(--color-border);
    border-radius: var(--border-radius-lg);
    box-shadow: var(--shadow-lg);
    min-width: 220px;
    z-index: 1100;
    display: none;
    overflow: hidden;
}

.dropdown-menu.show {
    display: block;
    animation: modalSlideUp 0.15s ease;
}

.dropdown-item {
    display: block;
    padding: var(--space-2) var(--space-3);
    font-size: var(--font-size-md);
    color: var(--color-text-primary);
    text-decoration: none;
    cursor: pointer;
    border: none;
    background: none;
    width: 100%;
    text-align: left;
    font-family: var(--font-family);
    transition: background 0.1s ease;
}

.dropdown-item:hover {
    background: var(--color-bg-secondary);
    text-decoration: none;
}

.dropdown-document-item {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    align-items: stretch;
}

.dropdown-document-open {
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.dropdown-document-delete {
    min-width: 64px;
    padding: var(--space-2) var(--space-3);
    border: 0;
    border-left: 1px solid var(--color-border);
    background: transparent;
    color: var(--color-danger);
    cursor: pointer;
    font-family: var(--font-family);
    font-size: var(--font-size-sm);
    font-weight: 700;
}

.dropdown-document-delete:hover,
.dropdown-document-delete:focus-visible {
    background: var(--color-danger-bg);
    outline: none;
}

.dropdown-divider {
    height: 1px;
    background: var(--color-border);
    margin: var(--space-1) 0;
}

.dropdown-header {
    padding: var(--space-2) var(--space-3);
    font-size: var(--font-size-sm);
    font-weight: 600;
    color: var(--color-text-muted);
}

/* ── Status indicators ─────────────────────────────────────── */
.status-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    display: inline-block;
}

.status-dot.success { background: var(--color-success); }
.status-dot.danger { background: var(--color-danger); }
.status-dot.warning { background: var(--color-warning); }
.status-dot.muted { background: var(--color-text-muted); }

/* ── Empty state ───────────────────────────────────────────── */
.empty-state {
    text-align: center;
    padding: var(--space-6);
    color: var(--color-text-muted);
}

.empty-state-icon {
    font-size: 64px;
    margin-bottom: var(--space-3);
    opacity: 0.5;
}

.empty-state h3 {
    font-size: var(--font-size-xl);
    color: var(--color-text-primary);
    margin-bottom: var(--space-2);
}

.empty-state p {
    max-width: 400px;
    margin: 0 auto var(--space-4);
}

/* ── Validation panel ──────────────────────────────────────── */
.validation-errors {
    flex: 0 0 auto;
    max-height: min(260px, 28vh);
    overflow: hidden;
    background: var(--color-danger-bg);
    border: 1px solid #ffc8c8;
    border-radius: var(--border-radius);
    padding: var(--space-3);
    margin-top: var(--space-3);
}

.validation-errors h4 {
    color: var(--color-danger);
    font-size: var(--font-size-md);
    margin-bottom: var(--space-2);
}

#validation-error-list {
    max-height: min(208px, calc(28vh - 44px));
    overflow-y: auto;
    overscroll-behavior: contain;
    padding-right: var(--space-1);
}

.validation-error-item {
    display: block;
    width: 100%;
    font-size: var(--font-size-sm);
    padding: var(--space-1) 0;
    border: 0;
    background: transparent;
    font-family: var(--font-mono);
    color: var(--color-danger);
    border-bottom: 1px solid rgba(207, 34, 46, 0.1);
    text-align: left;
    -webkit-user-select: text;
    user-select: text;
}

.validation-error-item:last-child {
    border-bottom: none;
}

.validation-error-button {
    cursor: pointer;
}

.validation-error-button:hover,
.validation-error-button:focus-visible {
    color: #a40e26;
    text-decoration: underline;
    outline: none;
}

.validation-warning {
    color: #7d4e00;
}

/* ── Xonomy overrides ──────────────────────────────────────── */
.xonomy .element {
    font-family: var(--font-mono);
}

#xonomy-editor.xonomy.nerd {
    line-height: 1.25;
}

#xonomy-editor.xonomy.nerd .element {
    margin-top: 1px;
    margin-bottom: 1px;
    padding-left: 34px;
}

#xonomy-editor.xonomy.nerd .element .connector {
    width: 32px;
}

#xonomy-editor.xonomy.nerd .element .children {
    padding-top: 0;
    padding-bottom: 0;
}

#xonomy-editor.xonomy.nerd .element .children .textnode {
    margin-top: 1px;
    margin-bottom: 1px;
}

#xonomy-editor.xonomy.nerd .element.hasText .children {
    padding-top: 1px;
    padding-bottom: 1px;
}

#xonomy-editor.xonomy.nerd .element > .connector > .plusminus {
    left: -6px;
    z-index: 30;
}

#xonomy-editor.xonomy.nerd .connector > .draghandle {
    left: 16px;
    right: auto;
    z-index: 20;
}

#xonomy-editor.xonomy.laic {
    line-height: 1.25;
    padding: var(--space-2);
    padding-left: 26px;
}

#xonomy-editor.xonomy.laic .element {
    margin-top: 1px;
    margin-bottom: 1px;
    padding-top: 0;
}

#xonomy-editor.xonomy.laic .element > .children {
    padding-left: 18px;
}

#xonomy-editor.xonomy.laic .element > .children > .textnode {
    margin-top: 1px;
    margin-bottom: 1px;
}

#xonomy-editor.xonomy.laic .element > .children > .textnode.whitespace {
    display: none;
}

#xonomy-editor.xonomy.laic .element > .children > .textnode > .value {
    padding-top: 1px;
    padding-bottom: 1px;
}

#xonomy-editor.xonomy.laic .element > .tag {
    padding-top: 1px;
    padding-bottom: 1px;
}

#xonomy-editor.xonomy.laic .element > .children,
#xonomy-editor.xonomy.laic .element.hasText .children {
    padding-top: 1px;
    padding-bottom: 1px;
}

#xonomy-editor.xonomy.laic .element > .connector > .plusminus {
    left: -18px;
    top: 5px;
    z-index: 30;
}

#xonomy-editor.xonomy.laic .connector > .draghandle {
    left: 5px;
    right: auto;
    top: 5px;
    z-index: 20;
}

#xonomy-editor.xonomy.laic .element.draggable > .tag {
    padding-left: 24px;
}

#xonomy-editor.xonomy.laic .element.collapsed:not(.oneliner) > .tag {
    display: inline-block;
    max-width: calc(100% - 48px);
}

#xonomy-editor.xonomy.laic .element.collapsed:not(.oneliner) > .childrenCollapsed {
    display: inline-block;
    margin-top: 0;
    margin-left: 6px;
    padding: 0 6px;
    line-height: 1.25;
    vertical-align: middle;
}

#xonomy-editor.xonomy.laic .element.oneliner {
    padding-top: 1px;
}

#xonomy-editor.xonomy.laic .element.oneliner > .tag.opening {
    min-width: 120px;
    margin-right: 6px;
    padding: 1px 6px 1px 24px;
    line-height: 1.4;
}

#xonomy-editor.xonomy.laic .element.oneliner > .connector > .draghandle {
    left: 5px;
    top: 4px;
}

#xonomy-editor.xonomy.laic .element.oneliner > .children {
    padding-left: 0;
}

#xonomy-editor.xonomy.laic .element.hasInlineMenu.hasText > .children {
    padding: 2px 6px 0 18px;
    line-height: 1.4;
}

#xonomy-editor.xonomy.laic .element.hasInlineMenu.hasText .textnode .value,
#xonomy-editor.xonomy.laic .element.hasInlineMenu.hasText .element .textnode .value {
    padding-top: 1px;
    padding-bottom: 1px;
}

/* ── Spinner ───────────────────────────────────────────────── */
.spinner {
    width: 16px;
    height: 16px;
    border: 2px solid var(--color-border);
    border-top-color: var(--color-accent-fg);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

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

/* ── Responsive ────────────────────────────────────────────── */
@media (max-width: 768px) {
    .app-header {
        height: auto;
        min-height: 64px;
        flex-wrap: wrap;
        gap: var(--space-2);
        padding: var(--space-2) var(--space-3);
    }

    .header-logo {
        margin-right: 0;
        font-size: var(--font-size-lg);
    }

    .header-logo svg {
        width: 28px;
        height: 28px;
    }

    .header-nav {
        order: 3;
        flex: 1 0 100%;
        overflow-x: auto;
    }

    .settings-layout {
        flex-direction: column;
    }

    .settings-sidebar {
        width: 100%;
    }

    .preview-panel.open {
        width: 100%;
        min-width: unset;
        position: fixed;
        inset: 64px 0 0 0;
        z-index: 900;
    }

    .editor-wrapper {
        height: auto;
        min-height: calc(100vh - 64px);
        flex-direction: column;
        overflow: visible;
    }

    .editor-main-panel {
        min-height: calc(100vh - 64px);
        padding: 0 var(--space-2) var(--space-2);
    }

    .editor-shell .toolbar {
        flex-wrap: wrap;
        overflow-x: visible;
        margin-top: var(--space-2) !important;
    }

    .toolbar-separator {
        display: none;
    }

    .toolbar-status {
        order: 2;
        flex-basis: 100%;
        margin-left: 0;
        justify-content: flex-start;
    }

    .editor-resource-badges {
        flex-wrap: wrap;
    }

    .editor-shell-panels {
        min-height: 460px;
    }

    .editor-shell-panels[data-layout="split"] {
        flex-direction: column;
        overflow: auto;
    }

    .editor-shell-panels[data-layout="split"] .editor-shell-panel {
        flex-basis: auto !important;
        min-height: 420px;
    }

    .editor-splitter {
        display: none;
    }

    .toast-container {
        right: var(--space-2);
        left: var(--space-2);
    }

    .toast {
        min-width: 0;
        max-width: none;
    }
}

@media (max-width: 520px) {
    .btn {
        white-space: normal;
    }

    .schema-badge,
    .schema-badge-compact,
    #active-schema-badge.schema-badge-compact,
    #active-document-badge.schema-badge-compact {
        max-width: 100%;
    }

    .toolbar-status-message {
        width: 100%;
    }
}

/* ── Hidden utility ────────────────────────────────────────── */
.hidden {
    display: none !important;
}

.visually-hidden {
    position: absolute;
    width: 1px;
    height: 1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
}

/* ── Header User Info ─────────────────────────────────────── */
.header-user {
    display: flex;
    align-items: center;
    margin-left: auto;
    color: var(--color-header-text);
    font-size: var(--font-size-md);
    gap: var(--space-2);
}

.header-user a.btn {
    color: var(--color-header-text);
    border-color: rgba(255,255,255,0.3);
    font-size: var(--font-size-sm);
}

.header-user a.btn:hover {
    background: rgba(255,255,255,0.1);
    border-color: rgba(255,255,255,0.5);
}

/* ── Read-Only Badge ──────────────────────────────────────── */
.readonly-badge {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 3px 10px;
    border-radius: var(--border-radius);
    background: var(--color-warning-bg);
    color: var(--color-warning);
    font-size: var(--font-size-sm);
    font-weight: 600;
    border: 1px solid rgba(154, 103, 0, 0.2);
}

/* ── Comment Panel ────────────────────────────────────────── */
.comment-panel {
    width: 340px;
    min-width: 280px;
    background: var(--color-bg-primary);
    border-left: 1px solid var(--color-border);
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.comment-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: var(--space-2) var(--space-3);
    background: var(--color-bg-secondary);
    border-bottom: 1px solid var(--color-border);
    font-weight: 600;
    font-size: var(--font-size-md);
}

.comment-context {
    padding: var(--space-2) var(--space-3);
    background: var(--color-info-bg);
    border-bottom: 1px solid var(--color-border);
    font-size: var(--font-size-sm);
}

.comment-context-label {
    color: var(--color-text-secondary);
}

.comment-list {
    flex: 1;
    overflow-y: auto;
    padding: var(--space-2) var(--space-3);
}

.comment-empty {
    text-align: center;
    color: var(--color-text-muted);
    padding: var(--space-4) 0;
    font-size: var(--font-size-md);
}

.comment-card {
    background: var(--color-bg-secondary);
    border: 1px solid var(--color-border);
    border-radius: var(--border-radius);
    padding: var(--space-2) var(--space-3);
    margin-bottom: var(--space-2);
    font-size: var(--font-size-sm);
}

.comment-meta {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 4px;
}

.comment-meta strong {
    color: var(--color-text-primary);
}

.comment-time {
    color: var(--color-text-muted);
    font-size: var(--font-size-sm);
}

.comment-xpath {
    color: var(--color-accent-fg);
    font-family: var(--font-mono);
    font-size: 11px;
    margin-bottom: 4px;
    word-break: break-all;
}

.comment-body {
    color: var(--color-text-primary);
    line-height: 1.4;
    margin-bottom: 6px;
    white-space: pre-wrap;
}

.comment-actions {
    display: flex;
    gap: var(--space-1);
}

.comment-actions .btn {
    font-size: 11px;
    padding: 2px 6px;
}

.comment-form {
    border-top: 1px solid var(--color-border);
    padding: var(--space-2) var(--space-3);
}

.comment-input {
    width: 100%;
    margin-bottom: var(--space-1);
    resize: vertical;
    min-height: 60px;
    font-family: var(--font-family);
    font-size: var(--font-size-sm);
}

.comment-form-actions {
    display: flex;
    justify-content: flex-end;
}

@media (max-width: 768px) {
    .header-user {
        margin-left: auto;
    }

    .comment-panel {
        width: 100%;
        min-width: 0;
        max-height: 320px;
        border-top: 1px solid var(--color-border);
        border-left: none;
    }
}

@media (max-width: 520px) {
    .header-user {
        width: 100%;
        margin-left: 0;
        justify-content: space-between;
    }
}
