/* Import color palette first - @import must be before all other rules.
   Absolute path: a relative 'colors.css' was being re-resolved against the PAGE URL in some
   context (server logs showed stray GET /colors.css and /admin/colors.css 404s). */
@import url('/static/css/colors.css');

/* Base Styles */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

:root {
    --header-height: 56px;
    --sidebar-width: 250px;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, sans-serif;
    background: var(--bg-page);
    color: var(--text-primary);
    height: 100vh;
    overflow: hidden;
}

/* App Container */
.app-container {
    display: flex;
    flex-direction: column;
    height: 100vh;
}

/* Header */
.header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0 20px;
    height: var(--header-height);
    background: var(--gray-900);
    color: white;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}

.header-left {
    display: flex;
    align-items: center;
}

.brand-lockup {
    display: inline-flex;
    align-items: center;
    gap: 10px;
    color: inherit;
    text-decoration: none;
}

.logo {
    font-size: 20px;
    font-weight: 700;
}

.site-logo {
    height: 32px;
    width: auto;
    display: block;
}

.logo-wordmark {
    height: 20px;
    width: auto;
    display: block;
}

.header .site-logo {
    height: 40px;
    width: auto;
    cursor: pointer;
    transition: opacity 0.2s;
}

/* Inline-SVG lockup (partials/logo.html). The app header keeps a dark surface on BOTH
   theme sides (background: var(--gray-900)), so the wordmark stays near-white here —
   pages whose header follows the theme size/color it via shared.css instead. */
.header .site-logo-lockup {
    height: 40px;
    width: auto;
    display: block;
    color: #F1F5F9;
}

.header .site-logo:hover,
.header .logo:hover {
    opacity: 0.8;
}

.header .logo {
    height: 36px;
    width: auto;
    cursor: pointer;
    transition: opacity 0.2s;
}

.header-right {
    display: flex;
    align-items: center;
    gap: 10px;
}

.user-info {
    margin-left: 10px;
    color: #aaa;
    font-size: 14px;
    display: inline-flex;
    align-items: center;
    gap: 6px;
}

.user-info svg {
    width: 16px;
    height: 16px;
}

/* Buttons */
.btn {
    padding: 8px 16px;
    border: none;
    border-radius: 6px;
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s;
    display: inline-flex;
    align-items: center;
    gap: 6px;
}

.btn svg {
    width: 16px;
    height: 16px;
}

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

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

.btn-primary:hover:not(:disabled) {
    background: var(--primary-dark);
}

.btn-success {
    background: var(--success);
    color: var(--text-on-primary);
}

.btn-success:hover:not(:disabled) {
    background: var(--success);
    filter: brightness(0.92);
}

.btn-secondary {
    background: var(--gray-600);
    color: white;
}

.btn-secondary:hover:not(:disabled) {
    background: var(--gray-700);
}

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

.btn-danger:hover:not(:disabled) {
    background: var(--danger-dark);
}

/* Base links — themed accent instead of the browser-default blue.
   More specific link styles (.btn, .legal-footer a, .auth-link a, …) still win. */
a {
    color: var(--link);
}

a:hover {
    color: var(--link-hover);
}

.btn-link {
    background: none;
    color: var(--gray-400);
    text-decoration: none;
    padding: 8px 12px;
}

.btn-link:hover {
    color: white;
}

.btn-small {
    padding: 4px 8px;
    font-size: 16px;
    font-weight: bold;
    background: var(--primary);
    color: var(--text-on-primary);
}

.btn-small svg {
    width: 16px;
    height: 16px;
}

.btn-small:hover {
    background: var(--primary-dark);
}

.btn-sm {
    padding: 6px 12px;
    font-size: 12px;
}

.btn-sm svg {
    width: 14px;
    height: 14px;
}

/* Dropdown */
.dropdown {
    position: relative;
}

.dropdown-menu {
    display: none;
    position: absolute;
    top: 100%;
    right: 0;
    background: var(--bg-surface);
    border: 1px solid var(--border-light);
    border-radius: 6px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
    min-width: 180px;
    z-index: 1000;
    overflow: hidden;
}

.dropdown-menu.show {
    display: block;
}

.dropdown-menu button {
    display: flex;
    align-items: center;
    gap: 8px;
    width: 100%;
    padding: 10px 16px;
    text-align: left;
    border: none;
    background: none;
    cursor: pointer;
    font-size: 14px;
    color: var(--text-primary);
}

.dropdown-menu button svg {
    width: 16px;
    height: 16px;
}

.dropdown-menu button:hover {
    background: var(--bg-hover);
    color: var(--text-primary);
}

.dropdown-menu button:disabled {
    color: var(--text-tertiary);
    cursor: not-allowed;
    background: none;
}

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

.dropdown-menu button.menu-danger:hover:not(:disabled) {
    background: rgba(248, 113, 113, 0.12);
    color: var(--danger);
}

/* Main Content */
.main-content {
    display: flex;
    flex: 1;
    overflow: hidden;
    position: relative;
}

/* Resize Handles */
.resize-handle {
    position: relative;
    z-index: 10;
}

.resize-handle-vertical {
    width: 4px;
    cursor: col-resize;
    background: transparent;
    transition: background-color 0.2s;
    flex-shrink: 0;
}

.resize-handle-vertical:hover {
    background: var(--primary);
}

.resize-handle-vertical:active {
    background: var(--primary-dark);
}

/* Sidebar */
.sidebar {
    width: var(--sidebar-width);
    background: var(--bg-surface);
    border-right: 1px solid var(--border-light);
    display: flex;
    flex-direction: column;
}

.sidebar-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 15px;
    border-bottom: 1px solid var(--border-light);
}

.sidebar-header h2 {
    font-size: 14px;
    font-weight: 600;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

/* Sidebar Hint */
.sidebar-hint {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 15px;
    background: var(--bg-hover);
    border-bottom: 1px solid var(--border-light);
    font-size: 12px;
    color: var(--text-tertiary);
}

.sidebar-hint svg {
    width: 14px;
    height: 14px;
    flex-shrink: 0;
}

/* Sidebar Search */
.sidebar-search {
    padding: 10px 15px;
    border-bottom: 1px solid var(--border-light);
}

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

.search-input-wrapper > i {
    position: absolute;
    left: 10px;
    width: 16px;
    height: 16px;
    color: var(--text-tertiary);
    pointer-events: none;
}

.search-input-wrapper input {
    width: 100%;
    padding: 8px 32px 8px 36px;
    border: 1px solid var(--border-light);
    border-radius: 6px;
    font-size: 13px;
    background: var(--bg-page);
    color: var(--text-primary);
    transition: border-color 0.2s, box-shadow 0.2s;
}

.search-input-wrapper input:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 2px var(--primary-light);
}

.search-input-wrapper input::placeholder {
    color: var(--text-tertiary);
}

.search-clear {
    position: absolute;
    right: 4px;
    padding: 4px;
    background: none;
    border: none;
    cursor: pointer;
    color: var(--text-tertiary);
    border-radius: 4px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.search-clear:hover {
    background: var(--bg-hover);
    color: var(--text-primary);
}

.search-clear svg {
    width: 14px;
    height: 14px;
}

/* Tree View */
.tree-view {
    flex: 1;
    overflow-y: auto;
    padding: 10px;
    position: relative;
}

.tree-item {
    cursor: pointer;
    user-select: none;
}

.tree-item-content {
    display: flex;
    align-items: center;
    padding: 6px 8px;
    border-radius: 4px;
    gap: 6px;
    color: var(--text-primary);
    position: relative;
}

.tree-item-content:hover {
    background: var(--bg-hover);
}

.tree-item-content.selected {
    background: var(--bg-selected);
    color: var(--text-on-primary);
    font-weight: 500;
}

.tree-icon {
    font-size: 12px;
    width: 16px;
    text-align: center;
    flex-shrink: 0;
    color: var(--gray-500);
    font-weight: bold;
    transition: transform 0.2s ease;
}

.tree-item-content.selected .tree-icon {
    color: var(--text-on-primary);
}

.tree-name {
    font-size: 14px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    flex: 1;
}

.tree-children {
    margin-left: 16px;
    display: none;
    padding-left: 8px;
    border-left: 1px solid var(--border-light);
}

.tree-children.expanded {
    display: block;
}

/* Make directory items more obvious */
.tree-item[data-type="directory"] > .tree-item-content {
    font-weight: 500;
}

.tree-item[data-type="directory"] > .tree-item-content:hover {
    background: var(--bg-hover);
}

/* Search filtering */
.tree-item.hidden {
    display: none !important;
}

.tree-item.search-match .tree-name {
    background: var(--primary-light);
    border-radius: 3px;
    padding: 2px 4px;
    margin: -2px -4px;
}

/* Drag and drop */
.tree-item-content[draggable="true"] {
    cursor: grab;
}

.tree-item-content[draggable="true"]:active {
    cursor: grabbing;
}

.tree-item-content.dragging {
    opacity: 0.4;
    transform: scale(0.95);
}

/* Add subtle indicator that files are draggable */
.tree-item[data-type="file"] .tree-item-content:hover::after {
    content: '⋮⋮';
    position: absolute;
    right: 8px;
    color: var(--text-tertiary);
    font-size: 10px;
    letter-spacing: -2px;
}

.tree-item-content.drag-over {
    background: var(--primary-light);
    border-left: 3px solid var(--primary);
    padding-left: 5px;
}

.tree-view.drag-over-root {
    background: var(--primary-light);
    border: 2px dashed var(--primary);
    border-radius: 6px;
}

.tree-view.drag-over-root::before {
    content: 'Drop here to move to root';
    display: flex;
    align-items: center;
    justify-content: center;
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    background: var(--bg-surface);
    padding: 12px 20px;
    border-radius: 6px;
    color: var(--primary);
    font-weight: 600;
    font-size: 13px;
    pointer-events: none;
    z-index: 10;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
}

/* Editor View Container */
.editor-view {
    display: flex;
    flex: 1;
    min-width: 0;
}

/* Dashboard View */
.dashboard-view {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow-y: auto;
    background: var(--bg-page);
    min-width: 0;
}

.dashboard-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 20px 24px 0;
    flex-shrink: 0;
}

.dashboard-header-left {
    display: flex;
    align-items: center;
    gap: 12px;
}

.dashboard-title {
    font-size: 20px;
    font-weight: 600;
    color: var(--text-primary);
}

.dashboard-usage {
    font-size: 13px;
    color: var(--text-secondary);
    background: var(--bg-surface);
    padding: 4px 12px;
    border-radius: 12px;
    border: 1px solid var(--border-light);
}

.dashboard-usage.at-limit {
    color: var(--danger);
    border-color: var(--danger);
}

.dashboard-view-toggle {
    display: flex;
    gap: 2px;
    background: var(--bg-surface);
    border: 1px solid var(--border-light);
    border-radius: 6px;
    padding: 2px;
}

.dashboard-view-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 6px 10px;
    background: none;
    border: none;
    border-radius: 4px;
    cursor: pointer;
    color: var(--text-secondary);
    transition: all 0.2s;
}

.dashboard-view-btn:hover {
    color: var(--text-primary);
    background: var(--bg-hover);
}

.dashboard-view-btn.active {
    background: var(--primary);
    color: var(--text-on-primary);
}

.dashboard-view-btn svg {
    width: 16px;
    height: 16px;
}

.dashboard-grid {
    padding: 20px 24px;
    flex: 1;
}

.dashboard-cards {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
    gap: 16px;
}

.diagram-card {
    background: var(--bg-surface);
    border: 1px solid var(--border-light);
    border-radius: 8px;
    overflow: hidden;
    cursor: pointer;
    transition: all 0.2s;
}

.diagram-card:hover {
    border-color: var(--primary);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
    transform: translateY(-2px);
}

.diagram-thumbnail {
    height: 160px;
    overflow: hidden;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--bg-page);
    border-bottom: 1px solid var(--border-light);
    padding: 8px;
}

.diagram-thumbnail svg {
    max-width: 100%;
    max-height: 100%;
    width: auto;
    height: auto;
}

.thumbnail-placeholder {
    color: var(--gray-400);
    display: flex;
    align-items: center;
    justify-content: center;
}

.thumbnail-placeholder svg {
    width: 32px;
    height: 32px;
}

.thumbnail-error {
    color: var(--gray-400);
    display: flex;
    align-items: center;
    justify-content: center;
}

.thumbnail-error svg {
    width: 24px;
    height: 24px;
}

.diagram-card-info {
    padding: 12px;
}

.diagram-card-name-row {
    display: flex;
    align-items: center;
    gap: 4px;
}

.diagram-card-name {
    font-size: 14px;
    font-weight: 500;
    color: var(--text-primary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    flex: 1;
    min-width: 0;
}

.diagram-card-language {
    font-size: 10px;
    text-transform: uppercase;
    letter-spacing: 0.4px;
    padding: 2px 6px;
    border-radius: 10px;
    background: var(--bg-hover);
    color: var(--text-tertiary);
    border: 1px solid var(--border-light);
    flex-shrink: 0;
}

.diagram-card-clone {
    flex-shrink: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 28px;
    height: 28px;
    padding: 0;
    background: none;
    border: 1px solid transparent;
    border-radius: 4px;
    cursor: pointer;
    color: var(--text-tertiary);
    transition: all 0.2s;
}

.diagram-card-clone:hover {
    background: var(--bg-hover);
    border-color: var(--border-light);
    color: var(--primary);
}

.diagram-card-clone svg {
    width: 14px;
    height: 14px;
}

.diagram-card-path {
    font-size: 12px;
    color: var(--text-tertiary);
    margin-top: 4px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.dashboard-folder-group {
    margin-bottom: 24px;
}

.dashboard-folder-header {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 12px;
    font-size: 15px;
    font-weight: 600;
    color: var(--text-primary);
}

.dashboard-folder-header:hover {
    color: var(--primary);
}

.dashboard-folder-header svg {
    width: 18px;
    height: 18px;
    color: var(--text-secondary);
}

.dashboard-folder-header:hover svg {
    color: var(--primary);
}

.dashboard-folder-count {
    font-size: 12px;
    font-weight: 400;
    color: var(--text-tertiary);
    background: var(--bg-hover);
    padding: 2px 8px;
    border-radius: 10px;
}

.dashboard-welcome {
    position: relative;
    display: flex;
    align-items: flex-start;
    gap: 18px;
    padding: 26px 30px;
    margin-bottom: 28px;
    background:
        radial-gradient(120% 140% at 0% 0%, rgba(34, 211, 238, 0.10), transparent 60%),
        var(--bg-surface);
    border: 1px solid var(--border-light);
    border-radius: 14px;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.18);
    overflow: hidden;
}

/* Accent bar down the left edge */
.dashboard-welcome::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    bottom: 0;
    width: 4px;
    background: linear-gradient(180deg, var(--primary-light), var(--primary-glow));
}

.dashboard-welcome-icon {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 52px;
    height: 52px;
    flex-shrink: 0;
    border-radius: 14px;
    background: var(--bg-hover);
    border: 1px solid var(--border-light);
}

.dashboard-welcome-icon > i,
.dashboard-welcome-icon > svg {
    width: 28px;
    height: 28px;
    color: var(--primary-light);
}

.dashboard-welcome-body {
    flex: 1;
    min-width: 0;
}

.dashboard-welcome h2 {
    font-size: 20px;
    font-weight: 700;
    color: var(--text-primary);
    margin: 2px 0 8px;
}

.dashboard-welcome p {
    font-size: 14px;
    color: var(--text-secondary);
    margin: 0 0 18px;
    line-height: 1.6;
    max-width: 64ch;
}

.dashboard-welcome-actions {
    display: flex;
    gap: 10px;
    flex-wrap: wrap;
}

.dashboard-welcome-actions .btn {
    display: inline-flex;
    align-items: center;
    gap: 7px;
}

.dashboard-welcome-actions .btn > i,
.dashboard-welcome-actions .btn > svg {
    width: 16px;
    height: 16px;
}

.dashboard-welcome-close {
    position: absolute;
    top: 12px;
    right: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 30px;
    height: 30px;
    padding: 0;
    border: none;
    border-radius: 8px;
    background: transparent;
    color: var(--text-tertiary);
    cursor: pointer;
    transition: background 0.15s ease, color 0.15s ease;
}

.dashboard-welcome-close:hover {
    background: var(--bg-hover);
    color: var(--text-primary);
}

.dashboard-welcome-close > i,
.dashboard-welcome-close > svg {
    width: 18px;
    height: 18px;
}

.dashboard-folder-empty-message {
    font-size: 13px;
    font-style: italic;
    color: var(--text-tertiary);
    padding: 12px 16px;
    background: var(--bg-surface);
    border: 1px dashed var(--border-light);
    border-radius: 6px;
}

.dashboard-empty {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 60px 20px;
    text-align: center;
    color: var(--text-secondary);
    gap: 12px;
}

.dashboard-empty h3 {
    font-size: 18px;
    font-weight: 600;
    color: var(--text-primary);
}

.dashboard-empty p {
    font-size: 14px;
    color: var(--text-secondary);
}

.dashboard-loading {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 60px 20px;
    gap: 12px;
    color: var(--text-secondary);
}

/* Editor Panel */
.editor-panel {
    flex: 0 0 35%;
    display: flex;
    flex-direction: column;
    border-right: 1px solid var(--border-light);
    min-width: 300px;
}

.panel-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 10px 15px;
    background: var(--bg-surface);
    border-bottom: 1px solid var(--border-light);
}

.panel-header-left {
    display: flex;
    flex-direction: column;
    gap: 4px;
    flex: 1;
    min-width: 0;
}

/* Inline title row: a leading control sitting beside the panel's h3 (e.g. the
   show/hide-code toggle at the editor/preview boundary). */
.panel-header-title {
    display: flex;
    align-items: center;
    gap: 6px;
    min-width: 0;
}

.panel-header h3 {
    font-size: 14px;
    font-weight: 600;
    color: var(--text-secondary);
}

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

.btn-icon {
    background: none;
    border: none;
    padding: 6px;
    cursor: pointer;
    color: var(--text-secondary);
    border-radius: 4px;
    transition: all 0.2s;
    display: flex;
    align-items: center;
    justify-content: center;
}

.btn-icon:hover {
    background: var(--bg-hover);
    color: var(--primary);
}

.btn-icon svg {
    width: 18px;
    height: 18px;
}

.btn-icon-small {
    background: none;
    border: none;
    padding: 4px;
    cursor: pointer;
    color: var(--text-secondary);
    border-radius: 4px;
    transition: all 0.2s;
}

.btn-icon-small:hover {
    background: var(--bg-hover);
}

.btn-icon-small svg {
    width: 16px;
    height: 16px;
}

/* Breadcrumb Navigation Bar — the document's own row: path trail on the left,
   document-scoped actions (Save/Export/…) on the right. Global chrome stays in
   the app header above. */
.breadcrumb-bar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    height: 40px;
    padding: 0 16px;
    background: var(--bg-surface);
    border-bottom: 1px solid var(--border-light);
    font-size: 13px;
    color: var(--text-secondary);
    gap: 12px;
    flex-shrink: 0;
}

.breadcrumb-trail {
    display: flex;
    align-items: center;
    gap: 0;
    overflow-x: auto;
    white-space: nowrap;
    min-width: 0;
    flex: 1;
}

.doc-actions {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-shrink: 0;
}

.breadcrumb-home {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 4px 8px;
    background: none;
    border: none;
    cursor: pointer;
    color: var(--text-secondary);
    border-radius: 4px;
    transition: all 0.2s;
    flex-shrink: 0;
}

.breadcrumb-home:hover {
    background: var(--bg-hover);
    color: var(--primary);
}

.breadcrumb-home svg {
    width: 16px;
    height: 16px;
}

.breadcrumb-separator {
    color: var(--gray-400);
    padding: 0 6px;
    font-size: 12px;
    flex-shrink: 0;
    user-select: none;
}

.breadcrumb-folder {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 2px 8px;
    background: none;
    border: none;
    cursor: pointer;
    color: var(--text-secondary);
    font-size: 13px;
    border-radius: 4px;
    transition: all 0.2s;
    flex-shrink: 0;
}

.breadcrumb-folder:hover {
    background: var(--bg-hover);
    color: var(--primary);
}

.breadcrumb-folder svg {
    width: 14px;
    height: 14px;
}

.breadcrumb-current {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 2px 8px;
    color: var(--text-primary);
    font-weight: 500;
    font-size: 13px;
    flex-shrink: 0;
}

.breadcrumb-current svg {
    width: 14px;
    height: 14px;
}

.breadcrumb-delete-folder {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 4px;
    margin-left: 4px;
    background: none;
    border: none;
    cursor: pointer;
    color: var(--text-tertiary);
    border-radius: 4px;
    transition: all 0.2s;
    flex-shrink: 0;
}

.breadcrumb-delete-folder:hover {
    background: rgba(248, 113, 113, 0.15);
    color: var(--danger);
}

.breadcrumb-delete-folder svg {
    width: 14px;
    height: 14px;
}

.status {
    font-size: 12px;
    color: var(--text-secondary);
}

.status.modified {
    color: var(--warning);
}

.status.saved {
    color: var(--success);
}

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

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

#editor {
    flex: 1;
    padding: 15px;
    border: none;
    resize: none;
    font-family: 'Monaco', 'Menlo', 'Ubuntu Mono', 'Consolas', monospace;
    font-size: 14px;
    line-height: 1.5;
    background: var(--bg-code);
    color: var(--text-code);
}

#editor:focus {
    outline: none;
}

#editor:disabled {
    background: var(--bg-code-disabled);
    color: var(--text-code-disabled);
}

.validation-status.invalid {
    color: var(--danger);
}

.validation-errors {
    margin-top: 10px;
    padding-top: 10px;
    border-top: 1px solid var(--border-light);
}

.validation-error {
    padding: 8px;
    margin-top: 6px;
    background: var(--danger-light);
    border-left: 3px solid var(--danger);
    border-radius: 4px;
    font-size: 12px;
    font-family: monospace;
    color: var(--danger);
}

/* Preview Panel */
.preview-panel {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-width: 300px;
    background: var(--bg-surface);
}

.zoom-controls {
    display: flex;
    align-items: center;
    gap: 4px;
    padding-right: 10px;
    border-right: 1px solid var(--border-light);
}

/* Theme cluster — all theming lives in one compact group at the header's right
   edge: an icon-only light/dark toggle + the diagram-theme select. The header
   surface is dark on BOTH sides (var(--gray-900)), so these are styled for a
   dark backdrop explicitly, not via theme vars. */
.theme-cluster {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    margin-left: 4px;
    padding-left: 12px;
    border-left: 1px solid rgba(255, 255, 255, 0.12);
}

.theme-side-toggle {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    background: none;
    border: none;
    padding: 7px;
    border-radius: 6px;
    color: var(--gray-400);
    cursor: pointer;
    transition: all 0.2s;
}

.theme-side-toggle:hover {
    color: white;
    background: rgba(255, 255, 255, 0.08);
}

.theme-side-toggle svg {
    width: 16px;
    height: 16px;
}

.theme-cluster select {
    background: transparent;
    color: var(--gray-300);
    border: 1px solid rgba(255, 255, 255, 0.15);
    border-radius: 6px;
    padding: 4px 6px;
    font-size: 12px;
    max-width: 140px;
    cursor: pointer;
    /* The header is dark on both theme sides; without this the NATIVE option
       popup renders light-on-light and the theme names are unreadable. */
    color-scheme: dark;
}

.theme-cluster select option {
    background: var(--gray-900);
    color: var(--gray-100);
}

.theme-cluster select:hover {
    color: white;
    border-color: rgba(255, 255, 255, 0.3);
}

/* Icon-only secondary nav in the header (Teams/Settings/Admin/Logout). */
.header-icon-btn {
    padding: 8px;
}

.header-icon-btn svg {
    width: 17px;
    height: 17px;
}

.theme-selector {
    display: flex;
    align-items: center;
    gap: 8px;
}

.theme-selector label {
    font-size: 12px;
    color: var(--text-secondary);
}

.theme-selector select {
    padding: 4px 8px;
    border: 1px solid var(--border-light);
    border-radius: 4px;
    font-size: 12px;
    background: var(--bg-surface);
    color: var(--text-primary);
}

/* Contextual notice shown above the preview only when the open diagram carries
   its own embedded theme (replaces the always-visible Normalize button). */
.normalize-banner {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 8px 14px;
    background: var(--bg-hover);
    border-bottom: 1px solid var(--border-light);
    color: var(--text-secondary);
    font-size: 13px;
}
.normalize-banner[hidden] { display: none; }
.normalize-banner-icon { width: 16px; height: 16px; flex-shrink: 0; }
.normalize-banner-text { flex: 1; }
.normalize-banner-dismiss {
    background: none;
    border: none;
    color: var(--text-secondary);
    font-size: 18px;
    line-height: 1;
    cursor: pointer;
    padding: 0 4px;
}
.normalize-banner-dismiss:hover { color: var(--text-primary); }

/* Collapse the code editor → the preview takes the full width. */
.editor-view.editor-collapsed .editor-panel { display: none; }
.editor-view.editor-collapsed .resize-handle[data-target="editor"] { display: none; }

/* True fullscreen preview (browser Fullscreen API on the preview panel). */
.preview-panel:fullscreen {
    background: var(--bg-page);
    padding: 0;
}
.preview-panel:fullscreen .preview-container { height: 100%; }

/* Click the diagram name in the breadcrumb to rename it. */
.breadcrumb-rename { cursor: pointer; }
.breadcrumb-rename .breadcrumb-rename-icon {
    width: 13px;
    height: 13px;
    margin-left: 4px;
    opacity: 0;
    transition: opacity 0.15s;
}
.breadcrumb-rename:hover { color: var(--text-primary); }
.breadcrumb-rename:hover .breadcrumb-rename-icon { opacity: 0.7; }

.preview-container {
    flex: 1;
    overflow: hidden;
    padding: 20px;
    display: flex;
    justify-content: center;
    align-items: flex-start;
    position: relative;
}

.preview-placeholder {
    color: var(--text-tertiary, var(--text-secondary));
    font-size: 13px;
    text-align: center;
    padding: 40px;
    width: 100%;
    height: 100%;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 8px;
    opacity: 0.5;
    user-select: none;
}

.preview-placeholder-icon {
    width: 32px;
    height: 32px;
}

.empty-state {
    max-width: 400px;
    margin: 0 auto;
}

.empty-state-icon {
    width: 64px;
    height: 64px;
    color: var(--gray-400);
    margin-bottom: 20px;
}

.empty-state h3 {
    font-size: 18px;
    font-weight: 600;
    color: var(--text-primary);
    margin-bottom: 8px;
}

.empty-state p {
    color: var(--text-secondary);
    margin-bottom: 24px;
    line-height: 1.5;
}

.empty-state-tips {
    background: var(--gray-50);
    border: 1px solid var(--border-light);
    border-radius: 8px;
    padding: 16px;
    text-align: left;
}

.empty-state-tips strong {
    display: block;
    margin-bottom: 8px;
    color: var(--text-primary);
    font-size: 13px;
}

.empty-state-tips ul {
    list-style: none;
    margin: 0;
    padding: 0;
}

.empty-state-tips li {
    padding: 4px 0;
    font-size: 13px;
    color: var(--text-secondary);
}

.empty-state-tips kbd {
    display: inline-block;
    padding: 2px 6px;
    font-family: monospace;
    font-size: 11px;
    background: var(--bg-surface);
    border: 1px solid var(--border-medium);
    border-radius: 3px;
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.05);
    margin-right: 8px;
    min-width: 60px;
    text-align: center;
}

.preview-error {
    color: var(--danger);
    font-size: 14px;
    padding: 20px;
    background: var(--danger-light);
    border: 1px solid var(--danger);
    border-radius: 6px;
    white-space: pre-wrap;
    font-family: monospace;
}

/* Mermaid diagram container */
#preview .mermaid {
    max-width: 100%;
}

#preview svg {
    max-width: none;
    height: auto;
    transition: transform 0.1s ease-out;
}

/* Modal */
.modal {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.5);
    justify-content: center;
    align-items: center;
    z-index: 2000;
}

.modal.show {
    display: flex;
}

.modal-content {
    background: var(--bg-surface);
    padding: 30px;
    border-radius: 12px;
    width: 100%;
    max-width: 400px;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.2);
}

.modal-content h3 {
    margin-bottom: 20px;
    font-size: 18px;
    color: var(--text-primary);
}

.form-group {
    margin-bottom: 15px;
}

.form-group label {
    display: block;
    margin-bottom: 6px;
    font-size: 14px;
    font-weight: 500;
    color: var(--text-secondary);
}

.form-group input,
.form-group select {
    width: 100%;
    padding: 10px 12px;
    border: 1px solid var(--border-light);
    border-radius: 6px;
    font-size: 14px;
    background: var(--bg-surface);
    color: var(--text-primary);
    transition: border-color 0.2s, box-shadow 0.2s;
}

.form-group input:focus,
.form-group select:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px var(--primary-light);
}

.form-group input.error {
    border-color: var(--danger);
}

.form-group input.error:focus {
    box-shadow: 0 0 0 3px var(--danger-light);
}

.form-error {
    display: block;
    color: var(--danger);
    font-size: 12px;
    margin-top: 4px;
    min-height: 16px;
}

.checkbox-label {
    display: flex;
    align-items: center;
    gap: 8px;
    cursor: pointer;
    font-size: 14px;
    color: var(--text-primary);
}

.checkbox-label input[type="checkbox"] {
    width: auto;
    cursor: pointer;
}

.modal-actions {
    display: flex;
    justify-content: flex-end;
    gap: 10px;
    margin-top: 20px;
}

/* Confirmation Modal */
.modal-confirm {
    text-align: center;
    max-width: 420px;
}

.confirm-icon {
    width: 64px;
    height: 64px;
    margin: 0 auto 20px;
    background: var(--danger-light);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
}

.confirm-icon svg {
    width: 32px;
    height: 32px;
    color: var(--danger);
}

.modal-confirm h3 {
    font-size: 20px;
    margin-bottom: 12px;
}

.modal-confirm p {
    color: var(--text-secondary);
    margin-bottom: 24px;
    font-size: 14px;
}

.modal-confirm .modal-actions {
    justify-content: center;
}

/* AI Create Wizard */
.ai-wizard-steps {
    display: flex;
    gap: 4px;
    margin-bottom: 24px;
}

.ai-step {
    flex: 1;
    text-align: center;
    padding: 8px 4px;
    font-size: 13px;
    font-weight: 600;
    color: var(--text-tertiary);
    border-bottom: 3px solid var(--border-light);
    transition: all 0.2s;
}

.ai-step.active {
    color: var(--primary-light);
    border-bottom-color: var(--primary);
}

.ai-wizard-panel h3 {
    margin-bottom: 8px;
}

.ai-wizard-panel textarea {
    font-family: inherit;
    font-size: 14px;
    padding: 12px;
    background: var(--bg-hover);
    color: var(--text-primary);
    border: 1px solid var(--border-medium);
    border-radius: 6px;
}

.ai-wizard-panel textarea:focus {
    outline: none;
    border-color: var(--primary);
}

#ai-questions .form-group {
    margin-bottom: 16px;
}

#ai-questions label {
    font-size: 14px;
    font-weight: 500;
    margin-bottom: 6px;
    display: block;
    color: var(--text-primary);
}

#ai-questions input {
    width: 100%;
}

.ai-spinner {
    width: 40px;
    height: 40px;
    border: 3px solid var(--border-light);
    border-top-color: var(--primary);
    border-radius: 50%;
    animation: ai-spin 0.8s linear infinite;
    margin: 0 auto;
}

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

#ai-preview svg {
    max-width: 100%;
    height: auto;
}

/* Upgrade Modal */
.modal-upgrade {
    max-width: 480px;
    text-align: center;
    position: relative;
}

.modal-upgrade h3 {
    font-size: 22px;
    margin-bottom: 4px;
}

.upgrade-close {
    position: absolute;
    top: 12px;
    right: 16px;
    background: none;
    border: none;
    color: var(--text-secondary);
    font-size: 24px;
    cursor: pointer;
    line-height: 1;
}

.upgrade-close:hover {
    color: var(--text-primary);
}

.upgrade-subtitle {
    color: var(--text-secondary);
    margin-bottom: 20px;
    font-size: 14px;
}

.upgrade-plan-toggle {
    display: inline-flex;
    background: var(--bg-page);
    border-radius: 8px;
    padding: 3px;
    margin-bottom: 20px;
}

.upgrade-plan-toggle button {
    padding: 8px 20px;
    border: none;
    background: none;
    color: var(--text-secondary);
    cursor: pointer;
    border-radius: 6px;
    font-size: 14px;
    font-weight: 500;
    transition: background 0.2s, color 0.2s;
}

.upgrade-plan-toggle button.active {
    background: var(--primary);
    color: var(--text-on-primary);
}

.upgrade-price {
    margin-bottom: 24px;
}

.upgrade-price-amount {
    font-size: 40px;
    font-weight: 700;
    color: var(--text-primary);
}

.upgrade-price-period {
    font-size: 16px;
    color: var(--text-secondary);
}

.upgrade-save-badge {
    display: inline-block;
    background: var(--success);
    color: #fff;
    font-size: 12px;
    font-weight: 600;
    padding: 2px 8px;
    border-radius: 10px;
    margin-left: 8px;
    vertical-align: super;
}

.upgrade-features {
    text-align: left;
    margin-bottom: 24px;
    border: 1px solid var(--border-light);
    border-radius: 8px;
    overflow: hidden;
}

.upgrade-feature-row {
    display: grid;
    grid-template-columns: 1fr 80px 100px;
    padding: 10px 16px;
    border-bottom: 1px solid var(--border-light);
    font-size: 14px;
    align-items: center;
}

.upgrade-feature-row:last-child {
    border-bottom: none;
}

.upgrade-free {
    text-align: center;
    color: var(--text-tertiary);
}

.upgrade-pro {
    text-align: center;
    color: var(--primary-light);
    font-weight: 600;
}

.upgrade-cta {
    width: 100%;
    padding: 14px;
    font-size: 16px;
    font-weight: 600;
}

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

/* ARL automatic-renewal disclosure + consent (California ARL / AB 2863) */
.upgrade-arl {
    border: 1px solid var(--border-medium);
    border-radius: 8px;
    padding: 12px 14px;
    margin: 16px 0 12px;
    background: var(--bg-hover);
}

.upgrade-arl-text {
    font-size: 13px;
    line-height: 1.5;
    color: var(--text-secondary);
    margin: 0 0 10px;
}

.upgrade-consent-label {
    display: flex;
    align-items: flex-start;
    gap: 8px;
    font-size: 13px;
    color: var(--text-primary);
    cursor: pointer;
}

.upgrade-consent-label input {
    margin-top: 2px;
    flex-shrink: 0;
}

/* Pro Badge — quiet outline treatment; a label, not a button. */
.pro-badge {
    display: inline-block;
    background: transparent;
    color: var(--primary-light);
    border: 1px solid var(--primary-dark);
    font-size: 9px;
    font-weight: 700;
    padding: 1px 5px;
    border-radius: 3px;
    letter-spacing: 0.5px;
    margin-left: 4px;
    vertical-align: middle;
}

/* Context Menu */
.context-menu {
    position: fixed;
    display: none;
    background: var(--bg-surface);
    border: 1px solid var(--border-light);
    border-radius: 6px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
    min-width: 160px;
    z-index: 2500;
    overflow: hidden;
}

.context-menu.show {
    display: block;
}

.context-menu button {
    display: flex;
    align-items: center;
    gap: 8px;
    width: 100%;
    padding: 10px 16px;
    border: none;
    background: none;
    text-align: left;
    cursor: pointer;
    font-size: 14px;
    color: var(--text-primary);
    transition: background-color 0.2s;
}

.context-menu button svg {
    width: 16px;
    height: 16px;
}

.context-menu button:hover {
    background: var(--bg-hover);
}

.context-menu-danger {
    color: var(--danger) !important;
}

.context-menu-danger:hover {
    background: var(--danger-light) !important;
}

.context-menu-separator {
    height: 1px;
    background: var(--border-light);
    margin: 4px 0;
}

.context-menu-item-file,
.context-menu-item-folder {
    display: flex;
}

.context-menu.show-file .context-menu-item-folder {
    display: none;
}

.context-menu.show-folder .context-menu-item-file {
    display: none;
}

.context-menu.protected-folder .context-menu-danger,
.context-menu.protected-folder .context-menu-separator,
.context-menu.protected-file .context-menu-danger,
.context-menu.protected-file .context-menu-item-file {
    display: none;
}

/* Toast Notifications */
.toast-container {
    position: fixed;
    bottom: 20px;
    right: 20px;
    z-index: 3000;
}

.toast {
    padding: 12px 20px;
    border-radius: 6px;
    margin-top: 10px;
    color: white;
    font-size: 14px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
    animation: slideIn 0.3s ease;
}

.toast.success {
    background: var(--success);
}

.toast.error {
    background: var(--danger);
}

.toast.info {
    background: var(--primary);
}

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

/* Loading Spinner */
.loading {
    display: inline-block;
    width: 20px;
    height: 20px;
    border: 2px solid var(--gray-200);
    border-top: 2px solid var(--primary);
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

/* Responsive */
@media (max-width: 900px) {
    .site-logo {
        height: 24px !important;
    }

    .logo-wordmark {
        display: none;
    }

    .main-content {
        flex-direction: column;
    }

    .sidebar {
        width: 100%;
        height: 200px;
        border-right: none;
        border-bottom: 1px solid var(--border-light);
    }

    .editor-view {
        flex-direction: column;
    }

    .editor-panel,
    .preview-panel {
        min-width: auto;
    }

    .dashboard-cards {
        grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
    }
}

/* Phone layout: the SPA used to render ~1224px wide at 390px (12-item toolbar in one
   non-wrapping row) and scroll sideways. Compact the toolbar to icon-only + wrap, stop
   the page from scrolling horizontally, and give the stacked editor/preview real height. */
@media (max-width: 640px) {
    /* Relax the desktop 100vh/overflow:hidden shell: the stacked panes exceed one viewport,
       so the page must scroll vertically or the preview's bottom is clipped and unreachable.
       overflow-x uses `clip` (not hidden) so it never turns the container into a scroller
       and wide tables on teams/admin stay reachable via their own .table-scroll wrappers. */
    body { height: auto; min-height: 100vh; overflow: auto; }
    .app-container { height: auto; min-height: 100vh; overflow-x: clip; max-width: 100vw; }
    .main-content { overflow: visible; }

    .header { flex-wrap: wrap; height: auto; gap: 8px; padding: 8px 12px; }
    .header-right { flex-wrap: wrap; gap: 6px; row-gap: 6px; }
    /* Icon-only buttons on phones — every one already carries a title= for the label. */
    .header-right .btn span,
    .user-info { display: none; }
    .header-right .btn { padding: 8px; }
    .theme-cluster { padding-left: 8px; }
    .theme-cluster select { max-width: 96px; }

    .breadcrumb-bar { height: auto; min-height: 40px; padding: 4px 12px; }
    .doc-actions .btn span { display: none; }
    .doc-actions .btn { padding: 8px; }

    .sidebar { height: 160px; }
    .editor-panel, .preview-panel { min-height: 44vh; }
    .preview-container { min-height: 40vh; }

    /* Modals fit the viewport with room to breathe. */
    .modal-content { width: calc(100vw - 32px); max-width: calc(100vw - 32px); }
}

/* Login Page Styles */
.login-container {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    padding: 20px;
}

.login-container .logo {
    display: flex;
    flex-direction: column;
    align-items: center;
    margin-bottom: 2rem;
    gap: 0.75rem;
    color: var(--text-primary);
}

.login-container .logo img {
    width: auto;
    height: 40px;
    margin-bottom: 0;
}

.login-container .logo .site-logo {
    height: 40px;
    width: auto;
}

.login-container .logo .logo-wordmark {
    height: 26px;
}

.login-container .logo p {
    font-size: 1.2rem;
    font-weight: 600;
}

.login-container form {
    width: 100%;
    max-width: 360px;
    padding: 2rem;
    background: var(--bg-surface);
    border: 1px solid var(--border-light);
    border-radius: 12px;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.05);
}

.login-container form .form-group {
    margin-bottom: 1.5rem;
}

.login-container form label {
    font-weight: 600;
    color: var(--text-secondary);
}

.login-container form input {
    background: var(--bg-page);
}

.login-container form button[type="submit"] {
    width: 100%;
    padding: 12px;
    font-size: 1rem;
    background: var(--primary);
    color: var(--text-on-primary);
    border: none;
    border-radius: 6px;
    cursor: pointer;
    transition: background-color 0.2s;
}

.login-container form button[type="submit"]:hover {
    background: var(--primary-dark);
}

.auth-link {
    margin-top: 1.5rem;
    text-align: center;
    color: var(--text-secondary);
    font-size: 0.9rem;
}

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

.auth-link a:hover {
    text-decoration: underline;
}

/* Flash Messages */
.flash-messages {
    width: 100%;
    max-width: 360px;
    margin-bottom: 1rem;
}

.flash-message {
    padding: 1rem;
    border-radius: 6px;
    text-align: center;
    font-weight: 500;
}

.flash-message.error {
    background: var(--danger-light);
    color: var(--danger-dark);
    border: 1px solid var(--danger);
}

/* ----------------------------------------------------------------------- */
/* AI diagram assistant (floating, editor page)                            */
/* ----------------------------------------------------------------------- */
.aia-widget { position: fixed; bottom: 20px; right: 20px; z-index: 1500; }
.aia-launcher {
    width: 52px; height: 52px; border-radius: 50%; border: none;
    background: var(--primary); color: var(--text-on-primary); cursor: pointer;
    box-shadow: 0 4px 14px rgba(0, 0, 0, 0.3);
    display: flex; align-items: center; justify-content: center;
}
.aia-launcher:hover { background: var(--primary-dark); }
.aia-widget.open .aia-launcher { display: none; }
.aia-panel {
    display: none; flex-direction: column;
    width: 380px; max-width: calc(100vw - 40px);
    height: 520px; max-height: calc(100vh - 100px);
    background: var(--bg-surface); border: 1px solid var(--border-light);
    border-radius: 12px; box-shadow: 0 8px 30px rgba(0, 0, 0, 0.4); overflow: hidden;
}
.aia-widget.open .aia-panel { display: flex; }
.aia-header {
    display: flex; align-items: center; justify-content: space-between;
    padding: 12px 14px; border-bottom: 1px solid var(--border-light); background: var(--bg-page);
}
.aia-title { font-weight: 600; display: inline-flex; align-items: center; gap: 8px; }
.aia-min { background: none; border: none; color: var(--text-secondary); font-size: 22px; line-height: 1; cursor: pointer; }
.aia-min:hover { color: var(--text-primary); }
.aia-keywarn { padding: 10px 14px; background: rgba(251, 191, 36, 0.12); color: var(--warning); font-size: 13px; }
.aia-keywarn a { color: var(--primary-light); }
.aia-messages { flex: 1; overflow-y: auto; padding: 14px; display: flex; flex-direction: column; gap: 10px; }
.aia-msg { display: flex; flex-direction: column; gap: 6px; }
.aia-user { align-items: flex-end; }
.aia-bubble {
    padding: 9px 12px; border-radius: 10px; font-size: 14px; line-height: 1.4;
    white-space: pre-wrap; word-wrap: break-word; max-width: 90%;
}
.aia-user .aia-bubble { background: var(--primary); color: var(--text-on-primary); }
.aia-assistant .aia-bubble { background: var(--bg-hover); color: var(--text-primary); }
.aia-apply { align-self: flex-start; }
.aia-inputrow { display: flex; gap: 8px; padding: 12px 14px; border-top: 1px solid var(--border-light); }
.aia-input {
    flex: 1; resize: none; padding: 8px 10px; border: 1px solid var(--border-medium);
    border-radius: 6px; background: var(--bg-page); color: var(--text-primary); font: inherit;
}

/* ── UX polish pass (ux-pass-1) ─────────────────────────────────────────────── */

/* Visible keyboard focus ring everywhere (was browser-default only, low-contrast
   on dark teal). Mouse users are unaffected thanks to :focus-visible. */
:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: 2px;
}
.diagram-card:focus-visible,
.tree-item:focus-visible,
.btn:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: 2px;
}
/* Make scrollable regions keyboard-reachable (arrow/space scroll needs focus). */
[tabindex="0"]:focus-visible { outline: 2px solid var(--accent); outline-offset: -2px; }

/* Dashboard load-error state — distinct from the empty state, with a retry. */
.dashboard-error {
    display: flex; flex-direction: column; align-items: center; justify-content: center;
    gap: 12px; padding: 48px 24px; text-align: center; color: var(--text-secondary);
}
.dashboard-error h3 { margin: 0; color: var(--text-primary); }
.dashboard-error p { margin: 0; }
.dashboard-error .btn { margin-top: 4px; }

/* Read-only example cards should not masquerade as the user's own diagrams. */
.diagram-card-badge {
    font-size: 11px; font-weight: 500; line-height: 1;
    padding: 3px 7px; border-radius: 999px;
    color: var(--text-tertiary);
    background: var(--bg-hover);
    border: 1px solid var(--border-light);
    white-space: nowrap;
}
.diagram-card.is-example .diagram-thumbnail { opacity: 0.85; }

/* Keep the AI FAB clear of the preview toolbar / scrollbars (safe-area aware). */
.aia-widget {
    bottom: calc(20px + env(safe-area-inset-bottom, 0px));
    right: calc(20px + env(safe-area-inset-right, 0px));
}
@media (max-width: 900px) {
    .aia-widget { bottom: 14px; right: 14px; }
}

/* First-run hero: "what do you want to diagram?" prompt row. */
.dashboard-welcome-prompt {
    display: flex; gap: 10px; margin: 16px 0 10px; max-width: 640px;
}
.dashboard-welcome-prompt #welcome-idea {
    flex: 1; padding: 10px 14px; border-radius: 8px;
    border: 1px solid var(--border-medium); background: var(--bg-page);
    color: var(--text-primary); font: inherit;
}
.dashboard-welcome-prompt #welcome-idea:focus-visible {
    outline: 2px solid var(--accent); outline-offset: 1px; border-color: var(--accent);
}
.dashboard-welcome-prompt .btn { white-space: nowrap; }
@media (max-width: 640px) {
    .dashboard-welcome-prompt { flex-direction: column; }
}

/* Friendlier Mermaid render-error panel: plain summary + collapsible raw detail. */
.preview-error-title { font-weight: 600; color: var(--text-primary); margin-bottom: 6px; }
.preview-error-hint { color: var(--text-secondary); font-size: 14px; margin-bottom: 12px; }
.preview-error-details summary {
    cursor: pointer; color: var(--text-tertiary); font-size: 13px; user-select: none;
}
.preview-error-details pre {
    margin-top: 8px; padding: 10px 12px; background: var(--bg-page);
    border: 1px solid var(--border-light); border-radius: 6px;
    font-size: 12px; white-space: pre-wrap; overflow-x: auto; color: var(--text-secondary);
}

/* Horizontal scroll container for wide tables (teams members, admin users) so no
   column becomes unreachable on narrow viewports. */
.table-scroll { overflow-x: auto; -webkit-overflow-scrolling: touch; }

/* Retryable thumbnail-error tile */
.thumbnail-error { cursor: pointer; display: flex; flex-direction: column; align-items: center;
                   justify-content: center; gap: 6px; height: 100%; color: var(--warning); }
.thumbnail-error-hint { font-size: 11px; color: var(--text-tertiary); }
.thumbnail-error:hover .thumbnail-error-hint { color: var(--text-secondary); }

/* Honor the OS "reduce motion" preference (WCAG 2.3.3). */
@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after {
        animation-duration: 0.001ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.001ms !important;
        scroll-behavior: auto !important;
    }
}
.aia-input:focus { outline: none; border-color: var(--primary); }
