@import url('https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700&family=Outfit:wght@400;500;600;700&display=swap');

:root {
    --font-heading: 'Outfit', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    --font-body: 'Inter', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;

    --bg-app: #151515;
    --bg-sidebar: #0b0b0b;
    --bg-sidebar-hover: #202020;
    --bg-sidebar-active: #402311;
    --text-sidebar: #c8c8c8;
    --text-sidebar-muted: #858585;
    --text-sidebar-bright: #f4f4f4;
    --border-sidebar: #242424;

    --bg-card: #1a1a1a;
    --bg-subtle: #202020;
    --bg-header: #151515;
    --text-main: #f1f1f1;
    --text-muted: #8b8b8b;
    --border-color: #303030;

    --primary: #5b8def;
    --primary-hover: #6f9bff;
    --primary-light: #202634;
    --primary-text: #dce7ff;

    --success: #10b981;
    --success-hover: #059669;
    --success-light: #064e3b;
    --success-text: #6ee7b7;

    --warning: #b8692b;
    --warning-hover: #d17b36;
    --warning-light: #402311;
    --warning-text: #f4bd91;

    --danger: #ef4444;
    --danger-light: #7f1d1d;
    --danger-text: #fca5a5;

    /* Semantic accents for workspace item types */
    --accent-database: #94c973;
    --accent-dashboard: #b8692b;
    --accent-calendar: #e05d80;
    --accent-journal: #8f71e8;
    --accent-view: #4fb8c9;

    /* Type scale. Six steps, each a perceptible jump. The stylesheet previously
       used ~35 sizes including eleven inside a single 0.16rem band, which reads
       as misalignment rather than hierarchy. */
    --text-2xs: 0.68rem;
    --text-xs: 0.75rem;
    --text-sm: 0.82rem;
    --text-base: 0.9rem;
    --text-md: 1rem;
    --text-lg: 1.15rem;
    --text-xl: 1.25rem;
    --text-2xl: 1.5rem;

    /* Spacing scale, 4px based. */
    --space-1: 4px;
    --space-2: 8px;
    --space-3: 12px;
    --space-4: 16px;
    --space-5: 24px;
    --space-6: 32px;

    /* Breakpoints are documented here for reference; media queries cannot read
       custom properties. Three widths only:
         640px  phone
         900px  tablet and small laptop
        1200px  narrow desktop
       The stylesheet previously mixed 640/768/800/820/900/1200, and the
       768-820 cluster produced layout jank across a 52px window. */
    --radius-sm: 4px;
    --radius-md: 6px;
    --radius-lg: 10px;
    --radius-full: 999px;

    /* Elevation. sm/md were literally `none`, so the 14 rules referencing them
       rendered flat; these are deliberately subtle to keep the existing look. */
    --shadow-sm: 0 1px 2px rgb(0 0 0 / 0.25);
    --shadow-md: 0 4px 10px -2px rgb(0 0 0 / 0.32);
    --shadow-lg: 0 12px 32px rgb(0 0 0 / 0.38);
    --shadow-xl: 0 20px 60px rgb(0 0 0 / 0.5);

    --ring: 0 0 0 2px rgb(91 141 239 / 0.26);

    /* Scoped rather than `all`: transitioning every animatable property makes
       the browser watch layout properties too, and made a theme switch
       interpolate hundreds of values at once. These are the properties that
       actually change on hover/active/focus here. */
    --transition: background-color 0.18s cubic-bezier(0.4, 0, 0.2, 1),
        border-color 0.18s cubic-bezier(0.4, 0, 0.2, 1),
        color 0.18s cubic-bezier(0.4, 0, 0.2, 1),
        box-shadow 0.18s cubic-bezier(0.4, 0, 0.2, 1),
        opacity 0.18s cubic-bezier(0.4, 0, 0.2, 1);
}

/* :root above IS the dark theme, so [data-theme="dark"] needs no overrides --
   selecting dark simply means the light overrides below do not apply. The block
   that used to live here restated every :root value, and had drifted: :root
   still carried light-mode success/danger tints, so a visitor with no stored
   theme preference saw pale mint and pink badges on the dark UI. */

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

:root {
    /* Matches hub topbar.js slim variant --bar-h */
    --hub-topbar-height: 44px;
}

/* ---------------------------------------------------------------------------
   Focus baseline.

   Every focusable element gets a visible keyboard ring by default. Components
   that want a different treatment override this later in the cascade (they all
   pair `outline: none` with their own box-shadow). Using :focus-visible means
   mouse users never see the ring, only keyboard users.
   --------------------------------------------------------------------------- */
:focus-visible {
    outline: 2px solid var(--primary);
    outline-offset: 2px;
    border-radius: var(--radius-sm);
}

/* Interactive controls get the softer double-ring treatment so the indicator
   reads clearly against both the sidebar and the content background. */
button:focus-visible,
a:focus-visible,
[role="button"]:focus-visible,
[role="tab"]:focus-visible,
summary:focus-visible {
    outline: 2px solid var(--primary);
    outline-offset: 2px;
    box-shadow: var(--ring);
}

/* Respect users who have asked the OS to reduce motion. */
@media (prefers-reduced-motion: reduce) {

    *,
    *::before,
    *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
        scroll-behavior: auto !important;
    }
}

body {
    font-family: var(--font-body);
    background-color: var(--bg-app);
    color: var(--text-main);
    display: flex;
    flex-direction: column;
    height: 100vh;
    height: 100dvh;
    max-height: 100dvh;
    overflow: hidden;
    transition: var(--transition);
}

/* Shared hub topbar (custom element). Keep it out of the flex overflow path. */
trackthat-topbar,
#hub-topbar {
    display: block;
    flex: 0 0 auto;
    width: 100%;
    position: relative;
    z-index: 200;
}

/* Sidebar + main content row under the shared slim hub topbar */
.app-shell {
    display: flex;
    flex-direction: row;
    flex: 1 1 auto;
    min-height: 0;
    min-width: 0;
    width: 100%;
    overflow: hidden;
}

body.auth-page {
    min-height: 100vh;
    height: auto;
    max-height: none;
    display: grid;
    place-items: center;
    padding: 24px;
    overflow: auto;
    background:
        radial-gradient(circle at 20% 12%, rgba(91, 141, 239, 0.18), transparent 32%),
        linear-gradient(145deg, var(--bg-sidebar) 0%, var(--bg-app) 48%, #1d1712 100%);
}

.auth-shell {
    width: min(100%, 440px);
    height: auto;
    display: block;
}

.auth-panel {
    width: 100%;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-lg);
    background: color-mix(in srgb, var(--bg-card) 94%, transparent);
    box-shadow: var(--shadow-xl);
    padding: 28px;
}

.auth-brand {
    display: flex;
    align-items: center;
    gap: 14px;
    margin-bottom: 22px;
}

.auth-logo-mark {
    width: 46px;
    height: 46px;
    border-radius: var(--radius-md);
    background: #fff;
    padding: 3px;
    object-fit: contain;
}

.auth-brand h1 {
    margin: 0 0 4px;
    font-family: var(--font-heading);
    font-size: 1.55rem;
    letter-spacing: 0;
}

.auth-brand p {
    margin: 0;
    color: var(--text-muted);
    font-size: var(--text-base);
}

.auth-alert,
.auth-muted-panel {
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    background: var(--bg-subtle);
    padding: 12px;
    margin-bottom: 16px;
    color: var(--text-main);
    font-size: var(--text-base);
}

.auth-alert {
    border-color: color-mix(in srgb, var(--danger) 45%, var(--border-color));
    color: var(--danger-text);
    background: var(--danger-light);
}

.auth-muted-panel {
    display: flex;
    flex-direction: column;
    gap: 4px;
    color: var(--text-muted);
}

.auth-muted-panel strong {
    color: var(--text-main);
}

.auth-sso-btn,
.auth-google-btn,
.auth-dev-form .btn {
    width: 100%;
}

.auth-sso-btn svg,
.auth-google-btn svg,
.auth-dev-form .btn svg {
    width: 16px;
    height: 16px;
}

.auth-dev-form {
    border-top: 1px solid var(--border-color);
    margin-top: 18px;
    padding-top: 18px;
    display: flex;
    flex-direction: column;
    gap: 12px;
}

/* Scrollbars */
::-webkit-scrollbar {
    width: 6px;
    height: 6px;
}
::-webkit-scrollbar-track {
    background: transparent;
}
::-webkit-scrollbar-thumb {
    background: var(--text-muted);
    opacity: 0.3;
    border-radius: var(--radius-sm);
}
::-webkit-scrollbar-thumb:hover {
    background: var(--primary);
}

/* Navigation Sidebar */
aside {
    width: 280px;
    background-color: var(--bg-sidebar);
    color: var(--text-sidebar);
    display: flex;
    flex-direction: column;
    border-right: 1px solid var(--border-sidebar);
    flex: 0 0 auto;
    align-self: stretch;
    min-height: 0;
    overflow: hidden;
    z-index: 10;
}

.sidebar-header {
    padding: 0.5rem 0.75rem;
    display: flex;
    align-items: center;
    justify-content: flex-start;
    border-bottom: 1px solid var(--border-sidebar);
    min-height: 44px;
    flex-shrink: 0;
}

.theme-toggle {
    background: transparent;
    border: none;
    color: var(--text-sidebar);
    cursor: pointer;
    padding: 0.25rem;
    border-radius: var(--radius-sm);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.2rem;
    transition: var(--transition);
}

.theme-toggle:hover {
    color: var(--text-sidebar-bright);
    background-color: var(--bg-sidebar-hover);
}

.sidebar-scroll {
    flex: 1;
    overflow-y: auto;
    padding: 1rem 0.75rem;
}

.menu-section {
    margin-bottom: 1.5rem;
}

.menu-title {
    font-family: var(--font-heading);
    font-size: var(--text-xs);
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--text-muted);
    padding: 0.5rem 0.75rem;
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.add-btn-icon {
    cursor: pointer;
    font-size: var(--text-md);
    color: var(--text-sidebar);
    border: none;
    background: transparent;
    padding: 0.1rem 0.3rem;
    min-width: 24px;
    min-height: 24px;
    border-radius: var(--radius-sm);
    display: flex;
    align-items: center;
    justify-content: center;
}

.add-btn-icon:hover {
    background: var(--bg-sidebar-hover);
    color: var(--text-sidebar-bright);
}

/* The per-workspace "+" reveals on hover; the section-header "+" stays visible. */
.menu-item .add-btn-icon {
    opacity: 0;
}

.menu-item:hover .add-btn-icon,
.menu-item-wrapper:focus-within .add-btn-icon {
    opacity: 1;
}

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

.menu-item-wrapper {
    margin-bottom: 0.25rem;
}

.menu-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0.6rem 0.75rem;
    border-radius: var(--radius-sm);
    text-decoration: none;
    color: var(--text-sidebar);
    font-size: var(--text-base);
    font-weight: 500;
    cursor: pointer;
    transition: var(--transition);
}

.menu-item:hover {
    background-color: var(--bg-sidebar-hover);
    color: var(--text-sidebar-bright);
}

.menu-item.active {
    background-color: var(--bg-sidebar-active);
    color: var(--text-sidebar-bright);
    font-weight: 600;
    box-shadow: inset 3px 0 0 0 var(--primary);
}

/* The row label is a real <button> so workspace/database navigation is
   reachable by keyboard. The surrounding .menu-item stays a plain flex
   container holding the label plus its sibling action buttons. */
.menu-item-content {
    display: flex;
    align-items: center;
    gap: 0.6rem;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    flex: 1 1 auto;
    min-width: 0;
    align-self: stretch;
    min-height: 24px;
    background: none;
    border: none;
    padding: 0;
    margin: 0;
    font: inherit;
    color: inherit;
    text-align: left;
    cursor: pointer;
}

.menu-item-actions {
    display: flex;
    align-items: center;
    gap: 0.25rem;
    flex-shrink: 0;
}

.menu-item-icon {
    font-size: var(--text-md);
    flex-shrink: 0;
}

/* Single source of truth for sidebar row action glyphs, replacing the
   per-element inline width/height that used to be repeated on each icon. */
.row-action-icon {
    width: 13px;
    height: 13px;
    flex-shrink: 0;
    pointer-events: none;
}

/* ---------------------------------------------------------------------------
   Icon size utilities.

   Lucide renders a 24px SVG by default, so every icon previously carried an
   inline width/height. These five steps cover every size the app actually
   used and keep the sizing in the stylesheet where it can be themed.
   --------------------------------------------------------------------------- */
.icon-2xs {
    width: 10px;
    height: 10px;
    flex-shrink: 0;
}

.icon-xs {
    width: 12px;
    height: 12px;
    flex-shrink: 0;
}

.icon-sm {
    width: 14px;
    height: 14px;
    flex-shrink: 0;
}

.icon-md {
    width: 16px;
    height: 16px;
    flex-shrink: 0;
}

.icon-lg {
    width: 18px;
    height: 18px;
    flex-shrink: 0;
}

.icon-xl {
    width: 24px;
    height: 24px;
    flex-shrink: 0;
}

/* Glyphs inside a rich-text toolbar must not swallow the mousedown that keeps
   the editor selection alive. */
.rich-toolbar-btn svg {
    pointer-events: none;
}

.workspace-icon-inline,
.workspace-menu-icon,
.breadcrumb-workspace-icon,
.journal-linked-record-workspace-icon,
.journal-linked-record-item-icon,
.record-link-workspace-icon,
.record-link-create-workspace-icon,
.record-link-filter-workspace-icon,
.link-dropdown-workspace-icon,
.relation-badge-workspace-icon {
    flex-shrink: 0;
}

.workspace-color-control {
    display: flex;
    align-items: center;
    gap: 0.7rem;
}

.workspace-color-input {
    width: 3rem;
    height: 2.3rem;
    padding: 0.2rem;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    background: var(--bg-subtle);
    cursor: pointer;
}

.workspace-color-preview {
    width: 2.3rem;
    height: 2.3rem;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    background: var(--bg-subtle);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    color: var(--primary);
}

.workspace-icon-picker {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(2.3rem, 1fr));
    gap: 0.45rem;
}

.workspace-icon-option {
    width: 100%;
    aspect-ratio: 1;
    min-height: 2.3rem;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    background: var(--bg-subtle);
    color: var(--text-muted);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: var(--transition);
}

.workspace-icon-option:hover,
.workspace-icon-option.active {
    border-color: var(--primary);
    color: var(--primary);
    background: var(--primary-light);
}

.workspace-icon-option.active {
    box-shadow: var(--ring);
}

.workspace-members-section {
    border-top: 1px solid var(--border-color);
    padding-top: 1rem;
    display: flex;
    flex-direction: column;
    gap: 0.8rem;
}

.workspace-members-header {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 1rem;
}

.workspace-members-header h4 {
    margin: 0 0 0.25rem;
    font-family: var(--font-heading);
    font-size: var(--text-md);
}

.workspace-members-header p {
    margin: 0;
    color: var(--text-muted);
    font-size: var(--text-xs);
    line-height: 1.35;
}

.workspace-role-badge {
    border: 1px solid var(--border-color);
    border-radius: var(--radius-full);
    padding: 3px 8px;
    color: var(--primary-text);
    background: var(--primary-light);
    font-size: var(--text-xs);
    font-weight: 700;
    text-transform: capitalize;
}

.workspace-invite-row {
    display: grid;
    grid-template-columns: minmax(0, 1fr) 112px auto;
    gap: 8px;
    align-items: center;
}

.workspace-members-list {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.workspace-member-row {
    display: grid;
    grid-template-columns: 30px minmax(0, 1fr) 96px auto;
    align-items: center;
    gap: 8px;
    min-height: 40px;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    background: var(--bg-subtle);
    padding: 5px 6px;
}

.workspace-member-row.pending {
    grid-template-columns: 30px minmax(0, 1fr) 96px auto;
    border-style: dashed;
}

.workspace-member-avatar {
    width: 30px;
    height: 30px;
    border-radius: var(--radius-sm);
    background: var(--primary-light);
    color: var(--primary-text);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
    font-size: var(--text-xs);
    font-weight: 800;
}

.workspace-member-avatar img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.workspace-member-main {
    min-width: 0;
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.workspace-member-name,
.workspace-member-email {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.workspace-member-name {
    font-weight: 700;
    font-size: var(--text-sm);
}

.workspace-member-email {
    color: var(--text-muted);
    font-size: var(--text-xs);
}

.workspace-member-role {
    height: 30px;
    padding: 0 8px;
    font-size: var(--text-xs);
}

.workspace-member-action {
    width: 30px;
    height: 30px;
    min-width: 30px;
    padding: 0;
}

.workspace-member-empty {
    color: var(--text-muted);
    font-size: var(--text-xs);
    font-style: italic;
}

.db-list {
    list-style: none;
    padding-left: 1.5rem;
    margin-top: 0.25rem;
}

.db-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.5rem;
    padding: 0.45rem 0.6rem 0.45rem 0.75rem;
    border-radius: var(--radius-sm);
    color: var(--text-sidebar);
    font-size: var(--text-sm);
    cursor: pointer;
    transition: var(--transition);
}

.db-item-label {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    overflow: hidden;
    white-space: nowrap;
    text-overflow: ellipsis;
    min-width: 0;
    flex: 1 1 auto;
    align-self: stretch;
    min-height: 24px;
    background: none;
    border: none;
    padding: 0;
    margin: 0;
    font: inherit;
    color: inherit;
    text-align: left;
    cursor: pointer;
}

.db-item-icon {
    width: 14px;
    height: 14px;
    flex-shrink: 0;
    color: var(--item-accent, var(--text-sidebar-muted));
}

.db-item-actions {
    display: flex;
    align-items: center;
    gap: 0.15rem;
    flex-shrink: 0;
}

.db-item:hover {
    background-color: var(--bg-sidebar-hover);
    color: var(--text-sidebar-bright);
}

.db-item.active {
    background-color: var(--bg-sidebar-hover);
    color: var(--text-sidebar-bright);
    font-weight: 600;
    box-shadow: inset 2px 0 0 0 var(--item-accent, var(--primary));
}

.sidebar-draggable[draggable="true"] {
    cursor: grab;
}

.sidebar-draggable.dragging {
    opacity: 0.45;
}

.sidebar-drop-target,
.sidebar-drag-over {
    outline: 1px dashed var(--primary);
    background-color: var(--bg-sidebar-hover);
}

.sidebar-drag-handle {
    width: 12px;
    height: 12px;
    color: var(--text-sidebar-muted);
    flex-shrink: 0;
}

/* Row action buttons (settings / hide / delete) stay dimmed until the row is
   hovered or focused, keeping the sidebar calm and uncluttered. They meet the
   24x24 minimum target size even though the glyph inside is smaller. */
.row-action-btn {
    opacity: 0;
    background: transparent;
    border: none;
    color: var(--text-sidebar-muted);
    cursor: pointer;
    transition: var(--transition);
    padding: 3px;
    min-width: 24px;
    min-height: 24px;
    border-radius: var(--radius-sm);
    display: inline-flex;
    align-items: center;
    justify-content: center;
}

.menu-item:hover .row-action-btn,
.db-item:hover .row-action-btn,
.menu-item-wrapper:focus-within .row-action-btn,
.db-item:focus-within .row-action-btn {
    opacity: 0.8;
}

/* A keyboard user tabbing onto the control must see it even if the row itself
   was never hovered. */
.row-action-btn:focus-visible {
    opacity: 1;
}

.row-action-btn:hover {
    opacity: 1 !important;
    background: var(--bg-sidebar-hover);
    color: var(--text-sidebar-bright);
}

/* Only genuinely destructive actions get the danger tint. Settings and hide
   controls previously shared this hover state and read as deletions. */
.row-action-btn--danger:hover {
    background: rgba(239, 68, 68, 0.18);
    color: var(--danger);
}

/* Unhide (eye) action gets a success tint on hover. */
.unhide-action-btn:hover {
    background: rgba(16, 185, 129, 0.18);
    color: var(--success);
}

.sidebar-footer {
    padding: 1rem;
    border-top: 1px solid var(--border-sidebar);
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

/* Primary Button */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.45rem;
    padding: 0.55rem 1.1rem;
    font-family: var(--font-body);
    font-size: var(--text-base);
    font-weight: 600;
    line-height: 1;
    white-space: nowrap;
    border-radius: var(--radius-md);
    border: 1px solid transparent;
    cursor: pointer;
    transition: var(--transition);
}

.btn:focus-visible {
    outline: none;
    box-shadow: var(--ring);
}

.btn-primary {
    background-color: var(--primary);
    color: white;
    box-shadow: var(--shadow-sm);
}

.btn-primary:hover {
    background-color: var(--primary-hover);
    box-shadow: 0 4px 14px rgba(99, 102, 241, 0.35);
}

.btn-secondary {
    background-color: var(--bg-card);
    border: 1px solid var(--border-color);
    color: var(--text-main);
}

.btn-secondary:hover {
    background-color: var(--bg-subtle);
    border-color: var(--text-muted);
}

.btn-success {
    background-color: var(--success);
    color: white;
}

.btn-success:hover {
    background-color: var(--success-hover);
}

.btn-warning {
    background-color: var(--warning);
    color: white;
}

.btn-warning:hover {
    background-color: var(--warning-hover);
}

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

.btn-danger:hover {
    background-color: var(--danger);
    color: white;
}

.btn-sm {
    padding: 0.42rem 0.75rem;
    font-size: var(--text-sm);
}

.btn-icon-only {
    padding: 0.42rem;
    aspect-ratio: 1;
}

/* Main Content Layout */
main {
    flex: 1 1 auto;
    display: flex;
    flex-direction: column;
    min-width: 0;
    min-height: 0;
    height: auto;
    overflow: hidden;
}

header {
    background-color: var(--bg-header);
    backdrop-filter: saturate(180%) blur(8px);
    border-bottom: 1px solid var(--border-color);
    padding: 0.65rem 1.25rem;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.75rem;
    min-height: 52px;
    height: auto;
    flex-shrink: 0;
    flex-wrap: wrap;
}

.breadcrumbs {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-family: var(--font-heading);
    font-weight: 600;
    font-size: 1.05rem;
    flex-shrink: 0;
    white-space: nowrap;
}

.breadcrumb-path {
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    min-width: 0;
    max-width: 100%;
}

.breadcrumb-parent {
    color: var(--text-muted);
    display: inline-flex;
    align-items: center;
    gap: 8px;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    font-weight: 700;
}

.breadcrumb-parent svg {
    color: var(--primary);
    flex: 0 0 auto;
}

.breadcrumb-parent-label {
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
}

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

.breadcrumb-active {
    color: var(--primary);
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
}

.breadcrumb-current-label {
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
}

.view-controls {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    min-width: 0;
    flex: 1 1 auto;
    flex-wrap: wrap;
    justify-content: flex-end;
}

.view-tabs {
    display: flex;
    background-color: var(--bg-app);
    padding: 0.25rem;
    border-radius: var(--radius-md);
    border: 1px solid var(--border-color);
}

.view-tab {
    padding: 0.4rem 0.9rem;
    border: none;
    background: transparent;
    font-family: var(--font-body);
    font-size: var(--text-sm);
    font-weight: 500;
    color: var(--text-muted);
    border-radius: var(--radius-sm);
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 0.4rem;
    transition: var(--transition);
}

.view-tab:hover {
    color: var(--text-main);
}

.view-tab.active {
    background-color: var(--bg-card);
    color: var(--primary);
    font-weight: 600;
    box-shadow: var(--shadow-sm);
}

/* Toolbar badge (count indicator on Fields/Filter/Sort buttons) */
.toolbar-badge {
    display: inline-block;
    background: var(--primary);
    color: #fff;
    font-size: var(--text-2xs);
    font-weight: 700;
    border-radius: var(--radius-lg);
    padding: 1px 5px;
    margin-left: 3px;
    vertical-align: middle;
    line-height: 1.4;
}

/* Toolbar dropdown panels */
.toolbar-panel {
    position: fixed;
    z-index: 2000;
    min-width: 240px;
    max-width: 420px;
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-lg);
    overflow: hidden;
}

.toolbar-panel-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 9px 14px;
    border-bottom: 1px solid var(--border-color);
    font-size: var(--text-sm);
    font-weight: 600;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.04em;
}

.toolbar-panel-close {
    background: transparent;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    font-size: var(--text-lg);
    line-height: 1;
    padding: 0 2px;
}

.toolbar-panel-close:hover { color: var(--text-main); }

.toolbar-panel-body {
    max-height: 320px;
    overflow-y: auto;
}

.toolbar-panel-footer {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 14px;
    border-top: 1px solid var(--border-color);
}

.toolbar-panel-row {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 6px 14px;
}

.toolbar-panel-row:hover { background: var(--bg-subtle); }

.filter-row {
    flex-wrap: nowrap;
    gap: 6px;
}

.toolbar-toggle-label {
    display: flex;
    align-items: center;
    gap: 8px;
    cursor: pointer;
    font-size: var(--text-sm);
    color: var(--text-main);
    width: 100%;
}

.toolbar-toggle-label input[type="checkbox"] {
    accent-color: var(--primary);
    width: 14px;
    height: 14px;
    flex-shrink: 0;
}

/* Search Bar */
.search-wrapper {
    position: relative;
    width: 230px;
    min-width: 120px;
    flex-shrink: 1;
}

.search-input {
    width: 100%;
    padding: 0.45rem 1rem 0.45rem 2.2rem;
    font-family: var(--font-body);
    font-size: var(--text-sm);
    border-radius: var(--radius-md);
    border: 1px solid var(--border-color);
    background-color: var(--bg-app);
    color: var(--text-main);
    outline: none;
    transition: var(--transition);
}

.search-input:focus {
    border-color: var(--primary);
    background-color: var(--bg-card);
    box-shadow: var(--ring);
}

.search-icon {
    position: absolute;
    left: 0.8rem;
    top: 50%;
    width: 14px;
    height: 14px;
    transform: translateY(-50%);
    color: var(--text-muted);
    pointer-events: none;
}

/* Page Contents */
.content-body {
    flex: 1 1 auto;
    min-height: 0;
    overflow: auto;
    padding: 1.5rem 2rem;
    position: relative;
}

.global-search-panel {
    min-height: 100%;
    background: var(--bg-app);
    color: var(--text-main);
}

.global-search-shell {
    max-width: none;
    margin: 0;
    min-height: 100%;
    border: 1px solid var(--border-sidebar);
    border-radius: var(--radius-md);
    background: var(--bg-app);
    overflow: hidden;
}

.global-search-input-row {
    height: 50px;
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 0 20px;
    border-bottom: 1px solid var(--border-color);
}

.global-search-icon {
    width: 18px;
    height: 18px;
    color: #a7a7a7;
    flex: 0 0 auto;
}

.global-search-input {
    width: 100%;
    min-width: 0;
    border: 0;
    outline: 0;
    background: transparent;
    color: var(--text-sidebar-bright);
    font: 500 1rem/1.2 var(--font-body);
}

.global-search-input::placeholder {
    color: var(--text-sidebar-muted);
}

.global-search-filters {
    height: 40px;
    display: flex;
    align-items: center;
    gap: 22px;
    padding: 0 22px;
    border-bottom: 1px solid var(--border-sidebar);
}

.global-search-filter {
    border: 0;
    background: transparent;
    color: #b8b8b8;
    display: inline-flex;
    align-items: center;
    gap: 6px;
    height: 28px;
    padding: 0;
    border-radius: var(--radius-sm);
    font: 700 0.74rem/1 var(--font-body);
    cursor: pointer;
}

.global-search-filter:hover,
.global-search-filter.active {
    color: var(--text-main);
}

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

.global-search-section-title {
    display: flex;
    align-items: center;
    gap: 10px;
    color: #7f858d;
    font-size: var(--text-base);
    padding: 18px 22px 10px;
}

.global-search-section-title svg {
    width: 16px;
    height: 16px;
}

.global-search-results {
    padding: 4px 16px 18px;
}

.global-search-result {
    width: 100%;
    min-height: 56px;
    display: grid;
    grid-template-columns: 20px minmax(0, 1fr) auto;
    align-items: center;
    gap: 12px;
    border: 0;
    border-radius: var(--radius-sm);
    background: transparent;
    color: #fff;
    text-align: left;
    padding: 7px 12px;
    cursor: pointer;
}

.global-search-result:hover,
.global-search-result.active {
    background: var(--border-color);
}

.global-search-result-icon {
    width: 18px;
    height: 18px;
    border-radius: var(--radius-sm);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    color: #d6d6d6;
}

.global-search-result-icon svg {
    width: 15px;
    height: 15px;
}

.global-search-result-icon.record {
    background: #cf5b7d;
    color: #fff;
}

.global-search-result-icon.workspace {
    color: var(--primary);
}

.global-search-result-icon.database {
    color: var(--accent-database);
}

.global-search-result-icon.dashboard {
    color: var(--accent-dashboard);
}

.global-search-result-icon.calendar {
    color: var(--accent-calendar);
}

.global-search-result-icon.workspace_view {
    color: var(--accent-view);
}

.global-search-result-body {
    min-width: 0;
    display: flex;
    flex-direction: column;
    gap: 5px;
}

.global-search-result-title {
    color: #fff;
    font-size: var(--text-base);
    font-weight: 800;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.global-search-result-subtitle {
    color: #777;
    font-size: var(--text-xs);
    font-weight: 500;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.global-search-result-id {
    justify-self: end;
    color: #9aa0a6;
    background: #2c2c2c;
    border-radius: var(--radius-sm);
    padding: 2px 5px;
    font-size: var(--text-2xs);
    font-weight: 800;
}

.global-search-empty {
    color: var(--text-sidebar-muted);
    font-size: var(--text-base);
    padding: 24px 12px;
}

.empty-state {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    height: 70%;
    text-align: center;
    color: var(--text-muted);
    padding: 2rem;
}

.empty-icon {
    font-size: 4rem;
    margin-bottom: 1rem;
    background: linear-gradient(135deg, var(--primary-light), #c084fc);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
}

.empty-state-logo {
    width: min(320px, 74vw);
    height: auto;
    border-radius: var(--radius-lg);
    margin-bottom: 1.25rem;
    box-shadow: var(--shadow-lg);
}

.empty-state h3 {
    font-family: var(--font-heading);
    color: var(--text-main);
    margin-bottom: 0.5rem;
    font-size: var(--text-2xl);
}

.empty-state p {
    max-width: 400px;
    margin-bottom: 1.5rem;
}

.workspace-view-container {
    min-height: 100%;
    padding: 1.5rem 1rem 3rem;
}

.workspace-view-layout {
    display: flex;
    flex-direction: column;
    gap: 1.5rem;
}

/* ---- Workspace view (lightweight) data layouts ---- */
@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

.workspace-view-body {
    min-width: 0;
}

.workspace-view-loading {
    display: flex;
    align-items: center;
    gap: 0.6rem;
    color: var(--text-muted);
    font-size: var(--text-base);
    padding: 1.5rem;
}

.workspace-view-loading svg {
    width: 18px;
    height: 18px;
    animation: spin 1s linear infinite;
}

.workspace-view-empty {
    text-align: center;
    padding: 3rem 1.5rem;
    color: var(--text-muted);
}

.workspace-view-empty-mark {
    width: 56px;
    height: 56px;
    margin: 0 auto 1rem;
    border-radius: 14px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    background: color-mix(in srgb, var(--accent-view) 14%, transparent);
    color: var(--accent-view);
}

.workspace-view-empty-mark svg { width: 26px; height: 26px; }
.workspace-view-empty h3 { margin: 0 0 0.4rem; font-family: var(--font-heading); }
.workspace-view-empty p { margin: 0 auto; max-width: 420px; font-size: 0.9rem; }

.workspace-view-field-note {
    display: inline-flex;
    align-items: center;
    gap: 0.45rem;
    margin-bottom: 1rem;
    padding: 0.35rem 0.7rem;
    border-radius: var(--radius-full);
    background: color-mix(in srgb, var(--accent-view) 12%, transparent);
    color: var(--accent-view);
    font-size: var(--text-xs);
    font-weight: 600;
}

.workspace-view-field-note svg { width: 14px; height: 14px; }

.workspace-view-note {
    margin-top: 1rem;
    font-size: var(--text-sm);
    font-style: italic;
    color: var(--text-muted);
}

.workspace-view-count {
    margin-left: auto;
    background: color-mix(in srgb, var(--text-muted) 20%, transparent);
    color: var(--text-secondary, var(--text-muted));
    border-radius: var(--radius-full);
    padding: 0.05rem 0.5rem;
    font-size: var(--text-xs);
    font-weight: 700;
}

.workspace-view-dot {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    flex-shrink: 0;
}

/* Shared record card (board + gallery) */
.workspace-view-card {
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md, 8px);
    padding: 0.85rem;
    cursor: pointer;
    transition: border-color 0.15s, transform 0.15s, box-shadow 0.15s;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.workspace-view-card:hover {
    border-color: var(--accent-view);
    transform: translateY(-1px);
    box-shadow: var(--shadow-sm);
}

.workspace-view-card-title {
    font-weight: 600;
    font-size: var(--text-base);
    overflow-wrap: anywhere;
}

.workspace-view-card-field {
    display: flex;
    flex-direction: column;
    gap: 0.15rem;
    font-size: var(--text-xs);
}

.workspace-view-card-label {
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.03em;
    font-size: var(--text-2xs);
    font-weight: 700;
}

.workspace-view-card-value { overflow-wrap: anywhere; }

/* Board */
.workspace-view-board {
    display: flex;
    gap: 1rem;
    overflow-x: auto;
    padding-bottom: 0.5rem;
    align-items: flex-start;
}

.workspace-view-board-col {
    width: 280px;
    flex-shrink: 0;
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-lg);
}

.workspace-view-board-col-head {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.75rem 0.9rem;
    border-bottom: 1px solid var(--border-color);
    font-weight: 600;
    font-size: var(--text-base);
}

.workspace-view-board-col-name {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.workspace-view-board-col-body {
    padding: 0.75rem;
    display: flex;
    flex-direction: column;
    gap: 0.6rem;
    min-height: 60px;
}

.workspace-view-board-empty {
    color: var(--text-muted);
    font-size: var(--text-sm);
    font-style: italic;
    text-align: center;
    padding: 0.75rem 0;
}

/* Gallery */
.workspace-view-gallery {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
    gap: 1rem;
}

/* List */
.workspace-view-list {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.workspace-view-list-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    flex-wrap: wrap;
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md, 8px);
    padding: 0.7rem 0.9rem;
    cursor: pointer;
    transition: border-color 0.15s;
}

.workspace-view-list-row:hover { border-color: var(--accent-view); }

.workspace-view-list-main {
    display: flex;
    align-items: center;
    gap: 0.55rem;
    min-width: 0;
}

.workspace-view-list-bullet {
    width: 12px;
    height: 12px;
    color: var(--accent-view);
    flex-shrink: 0;
}

.workspace-view-list-title {
    font-weight: 600;
    font-size: var(--text-base);
    overflow-wrap: anywhere;
}

.workspace-view-list-meta {
    display: flex;
    flex-wrap: wrap;
    gap: 0.4rem;
    justify-content: flex-end;
}

.workspace-view-chip {
    display: inline-flex;
    align-items: center;
    gap: 0.35rem;
    font-size: var(--text-xs);
    color: var(--text-secondary, var(--text-muted));
    background: color-mix(in srgb, var(--text-muted) 12%, transparent);
    border-radius: var(--radius-full);
    padding: 0.15rem 0.55rem;
    max-width: 220px;
}

.workspace-view-chip-label {
    color: var(--text-muted);
    font-weight: 700;
    text-transform: uppercase;
    font-size: 0.62rem;
    letter-spacing: 0.03em;
}

/* Feed */
.workspace-view-feed {
    display: flex;
    flex-direction: column;
}

.workspace-view-feed-item {
    display: grid;
    grid-template-columns: 24px minmax(0, 1fr);
    gap: 0.75rem;
    cursor: pointer;
    padding-bottom: 1rem;
}

.workspace-view-feed-rail {
    display: flex;
    flex-direction: column;
    align-items: center;
}

.workspace-view-feed-dot {
    width: 12px;
    height: 12px;
    border-radius: 50%;
    margin-top: 4px;
    background: var(--accent-view);
    flex-shrink: 0;
}

.workspace-view-feed-item:not(:last-child) .workspace-view-feed-rail::after {
    content: '';
    flex: 1;
    width: 2px;
    margin-top: 4px;
    background: var(--border-color);
}

.workspace-view-feed-content {
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md, 8px);
    padding: 0.75rem 0.9rem;
    display: flex;
    flex-direction: column;
    gap: 0.4rem;
}

.workspace-view-feed-item:hover .workspace-view-feed-content { border-color: var(--accent-view); }

.workspace-view-feed-head {
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    gap: 0.75rem;
}

.workspace-view-feed-title { font-weight: 600; font-size: 0.9rem; overflow-wrap: anywhere; }
.workspace-view-feed-time { color: var(--text-muted); font-size: 0.72rem; white-space: nowrap; }

/* Timeline */
.workspace-view-tl-axis {
    display: flex;
    justify-content: space-between;
    color: var(--text-muted);
    font-size: var(--text-xs);
    margin-bottom: 0.5rem;
    padding: 0 0.25rem;
}

.workspace-view-timeline {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.workspace-view-tl-row {
    display: grid;
    grid-template-columns: minmax(120px, 200px) minmax(0, 1fr);
    gap: 0.75rem;
    align-items: center;
    cursor: pointer;
}

.workspace-view-tl-label {
    font-size: var(--text-sm);
    font-weight: 600;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.workspace-view-tl-track {
    position: relative;
    height: 26px;
    background: color-mix(in srgb, var(--text-muted) 10%, transparent);
    border-radius: var(--radius-md);
}

.workspace-view-tl-bar {
    position: absolute;
    top: 3px;
    bottom: 3px;
    min-width: 6px;
    background: var(--accent-view);
    border-radius: var(--radius-md);
    display: flex;
    align-items: center;
    padding: 0 0.5rem;
    overflow: hidden;
}

.workspace-view-tl-bar span {
    color: #fff;
    font-size: var(--text-2xs);
    font-weight: 600;
    white-space: nowrap;
}

.workspace-view-tl-row:hover .workspace-view-tl-bar { filter: brightness(1.1); }

/* Gantt */
.workspace-view-gantt {
    display: flex;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md, 8px);
    background: var(--bg-card);
    overflow: hidden;
}

.workspace-view-gantt-names {
    position: relative;
    flex: 0 0 auto;
    width: 180px;
    border-right: 1px solid var(--border-color);
    background: var(--bg-card);
    z-index: 2;
}

/* Reveal the drag-to-resize bar when hovering the label column (the handle
   itself sits in the column rather than inside a <th>, so it needs its own
   rule alongside the shared body.column-resizing one). */
.workspace-view-gantt-names:hover .workspace-view-gantt-names-handle::after,
.workspace-view-gantt-names-handle:focus-visible::after {
    background: var(--border-color);
}

.workspace-view-gantt-corner {
    display: flex;
    align-items: center;
    padding: 0 0.85rem;
    font-size: var(--text-xs);
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.03em;
    color: var(--text-muted);
    border-bottom: 1px solid var(--border-color);
}

.workspace-view-gantt-name {
    display: flex;
    align-items: center;
    padding: 0 0.85rem;
    font-size: var(--text-sm);
    border-bottom: 1px solid var(--border-color);
    cursor: pointer;
    overflow: hidden;
    white-space: nowrap;
    text-overflow: ellipsis;
}

.workspace-view-gantt-name:hover { background: color-mix(in srgb, var(--accent-view) 8%, transparent); }

.workspace-view-gantt-scroll {
    flex: 1 1 auto;
    overflow-x: auto;
}

.workspace-view-gantt-canvas { position: relative; }

.workspace-view-gantt-axis {
    position: absolute;
    top: 0;
    left: 0;
    border-bottom: 1px solid var(--border-color);
}

.workspace-view-gantt-tick {
    position: absolute;
    top: 0;
    height: 100%;
    display: flex;
    align-items: center;
    padding-left: 4px;
    font-size: var(--text-2xs);
    color: var(--text-muted);
    white-space: nowrap;
    border-left: 1px solid var(--border-color);
}

.workspace-view-gantt-line {
    position: absolute;
    width: 1px;
    background: color-mix(in srgb, var(--border-color) 70%, transparent);
}

.workspace-view-gantt-band {
    position: absolute;
    left: 0;
    right: 0;
}

.workspace-view-gantt-band.odd {
    background: color-mix(in srgb, var(--text-muted) 4%, transparent);
}

.workspace-view-gantt-today {
    position: absolute;
    width: 2px;
    background: var(--accent-view);
    opacity: 0.7;
}

.workspace-view-gantt-bar {
    position: absolute;
    background: var(--accent-view);
    border-radius: var(--radius-sm);
    display: flex;
    align-items: center;
    padding: 0 0.5rem;
    cursor: pointer;
    overflow: hidden;
    box-shadow: var(--shadow-sm);
}

.workspace-view-gantt-bar span {
    color: #fff;
    font-size: var(--text-xs);
    font-weight: 600;
    white-space: nowrap;
}

.workspace-view-gantt-bar:hover { filter: brightness(1.08); }

/* Calendar (agenda) */
.workspace-view-calendar {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
}

.workspace-view-cal-day {
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md, 8px);
    overflow: hidden;
}

.workspace-view-cal-date {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.6rem 0.85rem;
    background: color-mix(in srgb, var(--accent-view) 8%, transparent);
    font-weight: 600;
    font-size: var(--text-sm);
    border-bottom: 1px solid var(--border-color);
}

.workspace-view-cal-date svg { width: 15px; height: 15px; color: var(--accent-view); }

.workspace-view-cal-items {
    display: flex;
    flex-direction: column;
}

.workspace-view-cal-item {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.55rem 0.85rem;
    cursor: pointer;
    font-size: var(--text-base);
}

.workspace-view-cal-item:hover { background: color-mix(in srgb, var(--accent-view) 6%, transparent); }
.workspace-view-cal-item:not(:last-child) { border-bottom: 1px solid var(--border-color); }

.workspace-view-cal-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--accent-view);
    flex-shrink: 0;
}

/* Report */
.workspace-view-report { display: flex; flex-direction: column; gap: 1.5rem; }

.workspace-view-kpis {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
    gap: 1rem;
}

.workspace-view-kpi {
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md, 8px);
    padding: 1.1rem;
}

.workspace-view-kpi-value {
    font-family: var(--font-heading);
    font-size: 1.8rem;
    font-weight: 700;
    color: var(--accent-view);
}

.workspace-view-kpi-label {
    color: var(--text-muted);
    font-size: var(--text-sm);
    margin-top: 0.2rem;
}

.workspace-view-report-section {
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md, 8px);
    padding: 1.1rem;
}

.workspace-view-report-title {
    font-weight: 700;
    font-size: var(--text-xs);
    text-transform: uppercase;
    letter-spacing: 0.03em;
    color: var(--text-muted);
    margin-bottom: 0.85rem;
}

.workspace-view-report-row {
    display: grid;
    grid-template-columns: minmax(90px, 160px) minmax(0, 1fr) 40px;
    align-items: center;
    gap: 0.75rem;
    margin-bottom: 0.55rem;
}

.workspace-view-report-label {
    font-size: var(--text-sm);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.workspace-view-report-track {
    height: 10px;
    border-radius: var(--radius-full);
    background: color-mix(in srgb, var(--text-muted) 12%, transparent);
    overflow: hidden;
}

.workspace-view-report-fill { height: 100%; border-radius: 999px; }

.workspace-view-report-count {
    text-align: right;
    font-weight: 700;
    font-size: var(--text-sm);
}

/* Map (list fallback) */
.workspace-view-map {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.workspace-view-map-row {
    display: flex;
    align-items: center;
    gap: 0.7rem;
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md, 8px);
    padding: 0.7rem 0.9rem;
    cursor: pointer;
    transition: border-color 0.15s;
}

.workspace-view-map-row:hover { border-color: var(--accent-view); }
.workspace-view-map-pin { width: 18px; height: 18px; color: var(--accent-view); flex-shrink: 0; }
.workspace-view-map-main { display: flex; flex-direction: column; min-width: 0; }
.workspace-view-map-title { font-weight: 600; font-size: 0.9rem; overflow-wrap: anywhere; }
.workspace-view-map-addr { font-size: 0.78rem; color: var(--text-muted); }
.workspace-view-map-addr.muted { font-style: italic; }

/* Table */
.workspace-view-table-wrap {
    overflow-x: auto;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md, 8px);
    background: var(--bg-card);
}

.workspace-view-table {
    width: 100%;
    border-collapse: collapse;
    font-size: var(--text-sm);
}

.workspace-view-table th,
.workspace-view-table td {
    text-align: left;
    padding: 0.6rem 0.85rem;
    border-bottom: 1px solid var(--border-color);
    white-space: nowrap;
}

.workspace-view-table th {
    font-size: var(--text-xs);
    text-transform: uppercase;
    letter-spacing: 0.03em;
    color: var(--text-muted);
    font-weight: 700;
    background: color-mix(in srgb, var(--text-muted) 6%, transparent);
    position: sticky;
    top: 0;
}

.workspace-view-table tbody tr { cursor: pointer; }
.workspace-view-table tbody tr:hover { background: color-mix(in srgb, var(--accent-view) 6%, transparent); }
.workspace-view-table tbody tr:last-child td { border-bottom: none; }

/* Header cell wrapper: anchors the drag-to-resize handle and keeps the title
   from sliding under it. */
.workspace-view-table .wsv-th-inner {
    position: relative;
    display: flex;
    align-items: center;
    min-height: 18px;
}

.workspace-view-table .wsv-th-title {
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* Trailing spacer column soaks up leftover width so resized columns keep their
   exact pixel size; it collapses to nothing once the columns overflow. */
.workspace-view-table .wsv-th-spacer,
.workspace-view-table .wsv-td-spacer {
    padding: 0;
    width: auto;
}

/* Inline-editable cells host the shared .td-input controls, which carry their
   own padding; trim the cell padding so the controls fill the cell and the row
   stays compact, matching the database table view's inline editing. */
.workspace-view-table td.wsv-edit-cell {
    padding: 2px 4px;
    vertical-align: middle;
}

/* Data Table Grid */
.grid-container {
    background-color: var(--bg-card);
    border-radius: var(--radius-lg);
    border: 1px solid var(--border-color);
    box-shadow: var(--shadow-md);
    overflow: hidden;
    width: 100%;
}

.grid-toolbar {
    padding: 1rem 1.5rem;
    border-bottom: 1px solid var(--border-color);
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.table-responsive {
    overflow-x: auto;
    width: 100%;
}

table {
    width: 100%;
    border-collapse: collapse;
    text-align: left;
    font-size: var(--text-base);
    table-layout: fixed;
}

th {
    padding: 0.8rem 1.25rem;
    font-family: var(--font-heading);
    font-weight: 600;
    color: var(--text-muted);
    background-color: var(--bg-subtle);
    border-bottom: 1px solid var(--border-color);
    white-space: nowrap;
}

.th-inner {
    position: relative;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.75rem;
    min-height: 22px;
}

.th-content {
    min-width: 0;
    flex: 1 1 auto;
}

.th-title {
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
    min-width: 0;
}

/* Column controls stay hidden until the header cell is hovered. */
.th-actions {
    display: flex;
    flex: 0 0 auto;
    align-items: center;
    gap: 0.15rem;
    opacity: 0;
    transition: var(--transition);
}

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

.column-resize-handle {
    position: absolute;
    top: 0;
    right: -7px;
    width: 14px;
    height: 100%;
    padding: 0;
    border: none;
    background: transparent;
    cursor: col-resize;
    touch-action: none;
    z-index: 2;
}

.column-resize-handle::after {
    content: "";
    position: absolute;
    top: 20%;
    bottom: 20%;
    left: 50%;
    width: 2px;
    transform: translateX(-50%);
    border-radius: var(--radius-full);
    background: transparent;
    transition: var(--transition);
}

th:hover .column-resize-handle::after,
th:focus-within .column-resize-handle::after,
body.column-resizing .column-resize-handle::after {
    background: var(--border-color);
}

body.column-resizing,
body.column-resizing * {
    cursor: col-resize !important;
    user-select: none !important;
}

.header-action-btn {
    background: transparent;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    border-radius: var(--radius-sm);
    padding: 3px;
    min-width: 24px;
    min-height: 24px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    transition: var(--transition);
}

.header-action-btn:hover {
    color: var(--text-main);
    background-color: var(--bg-subtle);
}

/* Keyed off a modifier class rather than the title text, which broke the moment
   the label was reworded or translated. */
.header-action-btn--danger:hover {
    color: var(--danger);
    background-color: var(--danger-light);
}

.col-icon {
    font-size: var(--text-sm);
    opacity: 0.7;
}

td {
    padding: 0.5rem 1.25rem;
    border-bottom: 1px solid var(--border-color);
    color: var(--text-main);
    white-space: nowrap;
    max-width: 280px;
    overflow: hidden;
    text-overflow: ellipsis;
}

tbody tr:last-child td {
    border-bottom: none;
}

.clickable-row:hover td {
    background-color: var(--primary-light);
}

.clickable-row {
    cursor: pointer;
}

.add-field-th {
    padding: 0;
    vertical-align: middle;
}

.add-field-btn {
    width: 100%;
    padding: 0.85rem;
    background: transparent;
    border: none;
    color: var(--primary);
    font-weight: 600;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.25rem;
    transition: var(--transition);
}

.add-field-btn:hover {
    background-color: var(--primary-light);
}

/* Table Inline Input Editor */
.td-input {
    width: 100%;
    border: 1px solid transparent;
    background: transparent;
    color: var(--text-main);
    font-family: var(--font-body);
    font-size: var(--text-base);
    padding: 0.25rem 0.5rem;
    border-radius: var(--radius-sm);
    transition: var(--transition);
}

.td-input:focus {
    border-color: var(--primary);
    background-color: var(--bg-app);
    outline: none;
}

/* Relation Badge Pill */
.relation-badge-container {
    display: flex;
    flex-wrap: wrap;
    gap: 0.25rem;
}

.relation-badge {
    display: inline-flex;
    align-items: center;
    gap: 0.25rem;
    background-color: var(--primary-light);
    color: var(--primary-text);
    padding: 0.2rem 0.6rem;
    border-radius: var(--radius-lg);
    font-size: var(--text-xs);
    font-weight: 600;
}

.relation-badge-remove {
    cursor: pointer;
    border: none;
    background: transparent;
    color: var(--primary-text);
    display: flex;
    align-items: center;
    border-radius: 50%;
    padding: 1px;
}

.relation-badge-remove:hover {
    background-color: rgba(99, 102, 241, 0.2);
}

.relation-badge-add {
    display: inline-flex;
    align-items: center;
    gap: 0.25rem;
    background-color: var(--bg-app);
    border: 1px dashed var(--border-color);
    color: var(--text-muted);
    padding: 0.2rem 0.5rem;
    border-radius: var(--radius-lg);
    font-size: var(--text-xs);
    font-weight: 500;
    cursor: pointer;
}

.relation-badge-add:hover {
    border-color: var(--primary);
    color: var(--primary);
}

/* Add Row Action */
.add-row-tr {
    background-color: var(--bg-app);
}

.add-row-btn {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.75rem 1.25rem;
    width: 100%;
    text-align: left;
    background: transparent;
    border: none;
    color: var(--text-muted);
    font-family: var(--font-body);
    font-weight: 500;
    cursor: pointer;
    transition: var(--transition);
}

.add-row-btn:hover {
    color: var(--primary);
    background-color: rgba(99, 102, 241, 0.05);
}

/* Kanban Board View */
.board-container {
    display: flex;
    gap: 1.5rem;
    padding: 0.5rem 0;
    height: 100%;
    min-height: 500px;
    overflow-x: auto;
}

.board-column {
    width: 320px;
    background-color: var(--bg-card);
    border-radius: var(--radius-lg);
    border: 1px solid var(--border-color);
    display: flex;
    flex-direction: column;
    flex-shrink: 0;
    max-height: 100%;
    box-shadow: var(--shadow-sm);
}

.board-column-header {
    padding: 1rem 1.25rem;
    font-family: var(--font-heading);
    font-weight: 600;
    font-size: var(--text-base);
    display: flex;
    align-items: center;
    justify-content: space-between;
    border-bottom: 1px solid var(--border-color);
}

.board-column-count {
    background-color: var(--bg-app);
    color: var(--text-muted);
    padding: 0.15rem 0.5rem;
    border-radius: var(--radius-lg);
    font-size: var(--text-xs);
}

.board-column-body {
    flex: 1;
    overflow-y: auto;
    padding: 1rem;
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
}

.board-card {
    background-color: var(--bg-app);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    padding: 1rem;
    cursor: pointer;
    box-shadow: var(--shadow-sm);
    transition: var(--transition);
}

.board-card:hover {
    border-color: var(--primary);
    transform: translateY(-2px);
    box-shadow: var(--shadow-md);
}

.board-card-title {
    font-family: var(--font-heading);
    font-weight: 600;
    font-size: var(--text-base);
    margin-bottom: 0.5rem;
}

.board-card-field {
    font-size: var(--text-sm);
    color: var(--text-muted);
    display: flex;
    justify-content: space-between;
    margin-top: 0.25rem;
}

.board-card-field-val {
    color: var(--text-main);
    font-weight: 500;
}

/* Schema View Diagram */
.schema-container {
    position: relative;
    width: 100%;
    min-height: 600px;
    background-color: var(--bg-card);
    border-radius: var(--radius-lg);
    border: 1px solid var(--border-color);
    padding: 2rem;
    overflow: auto;
    box-shadow: var(--shadow-md);
}

.schema-canvas {
    position: relative;
    width: 100%;
    min-height: 500px;
}

.schema-node {
    position: absolute;
    width: 240px;
    background-color: var(--bg-app);
    border: 2px solid var(--border-color);
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-sm);
    z-index: 5;
    transition: border-color 0.2s ease;
}

.schema-node:hover {
    border-color: var(--primary);
}

.schema-node-header {
    background-color: var(--primary-light);
    color: var(--primary-text);
    padding: 0.5rem 0.75rem;
    font-family: var(--font-heading);
    font-weight: 600;
    font-size: var(--text-sm);
    border-top-left-radius: var(--radius-sm);
    border-top-right-radius: var(--radius-sm);
    display: flex;
    align-items: center;
    gap: 0.4rem;
}

.schema-node-body {
    padding: 0.5rem 0.75rem;
}

.schema-node-field {
    display: flex;
    justify-content: space-between;
    gap: 0.75rem;
    font-size: var(--text-xs);
    padding: 0.25rem 0;
    color: var(--text-main);
}

.schema-node-field.relation {
    display: block;
    color: var(--text-main);
    font-weight: 500;
    background: color-mix(in srgb, var(--primary) 8%, transparent);
    border: 1px solid color-mix(in srgb, var(--primary) 24%, var(--border-color));
    border-radius: var(--radius-sm);
    padding: 0.45rem 0.5rem;
    margin: 0.35rem 0;
}

.schema-relation-main,
.schema-relation-meta {
    display: flex;
    align-items: center;
    gap: 0.4rem;
}

.schema-relation-main {
    justify-content: space-between;
}

.schema-relation-name {
    color: var(--primary);
    font-weight: 700;
}

.schema-relation-target {
    color: var(--text-muted);
    font-size: var(--text-2xs);
    white-space: nowrap;
}

.schema-relation-meta {
    align-items: flex-start;
    margin-top: 0.3rem;
}

.schema-relation-chip {
    flex: 0 0 auto;
    border-radius: var(--radius-full);
    background: var(--primary);
    color: var(--primary-text);
    font-size: var(--text-2xs);
    font-weight: 700;
    line-height: 1;
    padding: 0.22rem 0.35rem;
}

.schema-relation-rule {
    color: var(--text-muted);
    font-size: var(--text-2xs);
    line-height: 1.25;
}

.relation-cardinality-help {
    margin-top: 0.45rem;
    color: var(--text-muted);
    font-size: var(--text-xs);
    line-height: 1.35;
}

/* Slide-out Panel (Drawer) */
.drawer-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-color: rgba(15, 23, 42, 0.4);
    backdrop-filter: blur(4px);
    z-index: 50;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.3s ease;
}

.drawer-overlay.open {
    opacity: 1;
    pointer-events: auto;
}

.drawer {
    position: fixed;
    top: 0;
    right: -460px;
    width: 450px;
    height: 100%;
    background-color: var(--bg-card);
    border-left: 1px solid var(--border-color);
    box-shadow: var(--shadow-xl);
    z-index: 60;
    display: flex;
    flex-direction: column;
    transition: right 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

.drawer.open {
    right: 0;
}

.record-window-overlay {
    position: fixed;
    inset: 0;
    background: rgba(15, 23, 42, 0.46);
    backdrop-filter: blur(8px);
    z-index: 120;
    opacity: 0;
    pointer-events: none;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 2rem;
    transition: opacity 0.25s ease;
}

.record-window-overlay.open {
    opacity: 1;
    pointer-events: auto;
}

.record-window {
    width: min(900px, 100%);
    max-height: calc(100vh - 4rem);
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: 22px;
    box-shadow: 0 32px 80px rgba(15, 23, 42, 0.28);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    transform: translateY(20px) scale(0.98);
    transition: transform 0.25s ease;
}

.record-window-overlay.open .record-window {
    transform: translateY(0) scale(1);
}

.drawer-header {
    padding: 1.5rem;
    border-bottom: 1px solid var(--border-color);
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.drawer-title {
    font-family: var(--font-heading);
    font-weight: 700;
    font-size: var(--text-lg);
}

.drawer-close {
    background: transparent;
    border: none;
    font-size: var(--text-2xl);
    color: var(--text-muted);
    cursor: pointer;
    line-height: 1;
    padding: 0.2rem;
    min-width: 32px;
    min-height: 32px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    border-radius: var(--radius-sm);
}

.drawer-close:hover {
    color: var(--text-main);
    background-color: var(--bg-app);
}

.drawer-body {
    flex: 1;
    overflow-y: auto;
    padding: 1.5rem;
    display: flex;
    flex-direction: column;
    gap: 1.5rem;
}

.drawer-section {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.drawer-label {
    font-size: var(--text-xs);
    font-weight: 600;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.drawer-value-input {
    width: 100%;
    padding: 0.6rem 0.8rem;
    font-family: var(--font-body);
    font-size: var(--text-base);
    border-radius: var(--radius-md);
    border: 1px solid var(--border-color);
    background-color: var(--bg-app);
    color: var(--text-main);
    outline: none;
    transition: var(--transition);
}

.drawer-value-input:focus {
    border-color: var(--primary);
    background-color: var(--bg-card);
    box-shadow: var(--ring);
}

.comments-thread {
    display: flex;
    flex-direction: column;
    gap: 0.65rem;
}

.comment-entry {
    padding: 0.7rem 0.8rem;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    background: var(--bg-app);
}

.comment-meta {
    display: flex;
    justify-content: space-between;
    gap: 0.75rem;
    margin-bottom: 0.35rem;
    color: var(--text-muted);
    font-size: var(--text-xs);
}

.comment-body {
    color: var(--text-main);
    font-size: var(--text-base);
    line-height: 1.45;
    white-space: pre-wrap;
}

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

.comment-composer {
    display: flex;
    flex-direction: column;
    gap: 0.55rem;
    margin-top: 0.25rem;
}

/* Dialog Modals */
.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-color: rgba(15, 23, 42, 0.6);
    backdrop-filter: blur(4px);
    z-index: 100;
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.2s ease;
}

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

.modal {
    background-color: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-lg);
    width: 100%;
    max-width: 450px;
    box-shadow: var(--shadow-xl);
    overflow: hidden;
    transform: scale(0.9);
    transition: transform 0.2s ease;
}

.modal-overlay.open .modal {
    transform: scale(1);
}

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

.modal-body {
    padding: 1.5rem;
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

.form-group {
    display: flex;
    flex-direction: column;
    gap: 0.4rem;
}

.form-label {
    font-size: var(--text-sm);
    font-weight: 600;
    color: var(--text-muted);
}

.form-control {
    width: 100%;
    padding: 0.55rem 0.75rem;
    font-family: var(--font-body);
    font-size: var(--text-base);
    border-radius: var(--radius-md);
    border: 1px solid var(--border-color);
    background-color: var(--bg-app);
    color: var(--text-main);
    outline: none;
    transition: var(--transition);
}

.form-control:focus {
    border-color: var(--primary);
    background-color: var(--bg-card);
    box-shadow: var(--ring);
}

.workspace-view-type-list {
    display: grid;
    gap: 2px;
    padding: 4px 0;
}

.workspace-view-type-option {
    width: 100%;
    min-height: 34px;
    border: 0;
    border-radius: var(--radius-sm);
    background: transparent;
    color: var(--text-main);
    display: grid;
    grid-template-columns: 22px minmax(0, 1fr) auto;
    align-items: center;
    gap: 8px;
    padding: 5px 8px;
    font: 600 0.9rem/1.2 var(--font-body);
    text-align: left;
    cursor: pointer;
}

.workspace-view-type-option svg {
    width: 16px;
    height: 16px;
    color: #9c9c9c;
}

.workspace-view-type-option:hover,
.workspace-view-type-option.active {
    background: var(--bg-subtle);
}

.workspace-view-type-option.active svg {
    color: var(--accent-view);
}

.workspace-view-type-option:disabled {
    color: var(--text-muted);
    cursor: not-allowed;
    opacity: 0.58;
}

.workspace-view-pro-badge {
    border: 1px solid color-mix(in srgb, var(--warning) 34%, var(--border-color));
    border-radius: var(--radius-sm);
    color: var(--warning-text);
    background: color-mix(in srgb, var(--warning) 12%, transparent);
    padding: 2px 6px;
    font-size: var(--text-xs);
    font-weight: 700;
}

.modal-footer {
    padding: 1rem 1.5rem;
    background-color: var(--bg-app);
    border-top: 1px solid var(--border-color);
    display: flex;
    justify-content: flex-end;
    gap: 0.75rem;
}

.record-window-footer {
    background: transparent;
    justify-content: space-between;
    align-items: center;
    width: 100%;
}

.automation-modal {
    width: min(920px, calc(100vw - 32px));
    max-width: 920px;
}

.automation-modal .modal-body {
    max-height: min(72vh, 760px);
    overflow-y: auto;
}

@media (max-width: 900px) {
    .record-window-overlay {
        padding: 0.75rem;
        align-items: flex-end;
    }

    .record-window {
        width: 100%;
        max-height: calc(100vh - 1.5rem);
        border-radius: 20px 20px 0 0;
    }
}

.automation-shell {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.automation-section {
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    padding: 12px;
    background: var(--bg-card);
}

.automation-section-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    margin-bottom: 10px;
}

.automation-section-head h4 {
    margin: 0;
    color: var(--text-main);
    font-size: var(--text-base);
    line-height: 1.2;
}

.automation-step-kicker {
    margin-bottom: 3px;
    color: var(--text-muted);
    font-size: var(--text-2xs);
    font-weight: 800;
    letter-spacing: 0.08em;
    text-transform: uppercase;
}

.automation-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 10px;
}

.automation-switch {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    color: var(--text-main);
    font-size: var(--text-sm);
    font-weight: 700;
    cursor: pointer;
}

.automation-switch input {
    width: 16px;
    height: 16px;
    accent-color: var(--primary);
}

.automation-inline-input {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    align-items: center;
    gap: 8px;
}

.automation-inline-input span {
    color: var(--text-muted);
    font-size: var(--text-sm);
}

.automation-rows {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.automation-row {
    display: grid;
    gap: 8px;
    align-items: center;
    padding: 8px;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    background: var(--bg-subtle);
}

.automation-condition-row {
    grid-template-columns: minmax(140px, 1.3fr) minmax(130px, 1fr) minmax(140px, 1.2fr) auto;
}

.automation-action-row {
    grid-template-columns: minmax(130px, 1fr) minmax(130px, 1fr) minmax(140px, 1fr) minmax(140px, 1fr) auto;
}

.automation-empty {
    padding: 9px 10px;
    color: var(--text-muted);
    font-size: var(--text-sm);
    border: 1px dashed var(--border-color);
    border-radius: var(--radius-md);
}

.automation-advanced {
    padding: 0;
    overflow: hidden;
}

.automation-advanced-toggle {
    width: 100%;
    min-height: 42px;
    padding: 0 12px;
    border: 0;
    background: transparent;
    color: var(--text-main);
    display: flex;
    align-items: center;
    justify-content: space-between;
    font: 800 0.78rem/1 var(--font-body);
    cursor: pointer;
}

.automation-advanced-toggle svg {
    width: 15px;
    height: 15px;
    transition: transform 160ms ease;
}

#automation-advanced-panel {
    padding: 0 12px 12px;
}

.automation-json {
    font-family: ui-monospace, SFMono-Regular, Consolas, "Liberation Mono", monospace;
    font-size: var(--text-xs);
    line-height: 1.45;
}

.automation-error {
    padding: 9px 11px;
    border: 1px solid rgba(239, 68, 68, 0.35);
    border-radius: var(--radius-md);
    background: rgba(239, 68, 68, 0.12);
    color: #fca5a5;
    font-size: var(--text-sm);
    font-weight: 700;
}

.automation-preview {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    color: var(--text-muted);
    font-size: var(--text-sm);
    padding: 2px 2px 0;
}

@media (max-width: 900px) {
    .automation-grid,
    .automation-condition-row,
    .automation-action-row {
        grid-template-columns: 1fr;
    }

    .automation-section-head {
        align-items: flex-start;
        flex-direction: column;
    }
}

/* Link Selection Box */
.link-dropdown-menu {
    position: absolute;
    background-color: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-lg);
    width: 280px;
    z-index: 200;
    display: none;
    overflow: hidden;
}

.link-dropdown-menu.open {
    display: block;
}

.link-dropdown-item {
    padding: 0.5rem 1rem;
    cursor: pointer;
    font-size: var(--text-sm);
    display: flex;
    align-items: center;
    gap: 0.55rem;
    min-width: 0;
}

.link-dropdown-item:hover {
    background-color: var(--primary-light);
    color: var(--primary-text);
}

/* Rich Text / Markdown Editor styling */
.rich-editor-container {
    display: flex;
    flex-direction: column;
    width: 100%;
    gap: 0.5rem;
}

.rich-linked-records-panel {
    padding: 0.65rem;
    margin-bottom: 0.1rem;
}

.rich-linked-records-panel .journal-linked-records-header {
    margin-bottom: 0.45rem;
}

.rich-tab-container {
    display: flex;
    gap: 0.25rem;
    margin-bottom: 0.25rem;
}

.rich-tab-btn {
    padding: 0.35rem 0.75rem;
    font-size: var(--text-xs);
    font-weight: 600;
    border: 1px solid var(--border-color);
    background: var(--bg-app);
    color: var(--text-muted);
    cursor: pointer;
    border-radius: var(--radius-sm);
    transition: var(--transition);
}

.rich-tab-btn.active {
    background: var(--bg-card);
    color: var(--primary);
    border-color: var(--primary);
}

.rich-editor-toolbar {
    display: flex;
    align-items: center;
    background-color: var(--bg-app);
    border: 1px solid var(--border-color);
    border-bottom: none;
    padding: 0.35rem 0.5rem;
    border-top-left-radius: var(--radius-md);
    border-top-right-radius: var(--radius-md);
    gap: 0.25rem;
}

.rich-toolbar-btn {
    padding: 2px 6px;
    font-size: var(--text-xs);
    font-weight: bold;
    color: var(--text-main);
    background: transparent;
    border: none;
    cursor: pointer;
    border-radius: var(--radius-sm);
    transition: var(--transition);
}

.rich-toolbar-btn:hover {
    background-color: var(--border-color);
}

.rich-editor-textarea {
    width: 100%;
    min-height: 120px;
    padding: 0.5rem 0.75rem;
    font-family: monospace;
    font-size: var(--text-sm);
    background-color: var(--bg-app);
    color: var(--text-main);
    border: 1px solid var(--border-color);
    border-bottom-left-radius: var(--radius-md);
    border-bottom-right-radius: var(--radius-md);
    outline: none;
    resize: vertical;
    transition: var(--transition);
}

.rich-editor-textarea:focus {
    border-color: var(--primary);
    background-color: var(--bg-card);
}

.rich-editor-preview {
    width: 100%;
    min-height: 120px;
    padding: 0.5rem 0.75rem;
    background-color: var(--bg-app);
    color: var(--text-main);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    overflow-y: auto;
}

.rich-editor-preview h1 {
    font-size: var(--text-xl);
    margin-bottom: 0.5rem;
    font-family: var(--font-heading);
    border-bottom: 1px solid var(--border-color);
}

.rich-editor-preview h2 {
    font-size: var(--text-lg);
    margin-bottom: 0.4rem;
    font-family: var(--font-heading);
}

.rich-editor-preview strong {
    font-weight: bold;
}

.rich-editor-preview em {
    font-style: italic;
}

.rich-editor-preview li {
    margin-left: 1.25rem;
    list-style-type: disc;
}

/* ==========================================
   DASHBOARD GRID & WIDGETS
   ========================================== */
.widget-grid {
    display: grid;
    grid-template-columns: repeat(12, minmax(0, 1fr));
    grid-auto-rows: 30px;
    column-gap: 1rem;
    row-gap: 1rem;
    align-items: stretch;
    margin-top: 1.25rem;
    width: 100%;
}

/* Landing-spot indicator shown while dragging a widget */
.widget-grid-placeholder {
    pointer-events: none;
    border-radius: var(--radius-lg);
    border: 2px dashed var(--accent-dashboard);
    background-color: color-mix(in srgb, var(--accent-dashboard) 12%, transparent);
    z-index: 0;
}

/* Edit-mode canvas: subtle dotted board + dashed frame.
   Uses outline (not border/padding) so column widths stay identical to view
   mode — otherwise widgets would change width when leaving edit mode. */
.widget-grid.dashboard-edit-mode {
    position: relative;
    outline: 1px dashed color-mix(in srgb, var(--accent-dashboard) 45%, var(--border-color));
    outline-offset: 8px;
    border-radius: var(--radius-lg);
    background-color: color-mix(in srgb, var(--accent-dashboard) 4%, transparent);
    background-image: radial-gradient(
        color-mix(in srgb, var(--accent-dashboard) 24%, transparent) 1.3px,
        transparent 1.3px
    );
    background-size: 24px 24px;
    min-height: 560px;
}

.widget-card {
    position: relative;
    display: flex;
    flex-direction: column;
    height: 100%;
    min-width: 0;
    min-height: 0;
    box-sizing: border-box;
    background-color: var(--bg-card);
    background-image: linear-gradient(
        180deg,
        color-mix(in srgb, var(--bg-card) 92%, white 6%),
        var(--bg-card)
    );
    border: 1px solid var(--border-color);
    border-radius: var(--radius-lg);
    box-shadow: 0 1px 2px rgb(0 0 0 / 0.04), 0 10px 24px -18px rgb(0 0 0 / 0.5);
    overflow: hidden;
    transition: border-color 0.18s ease, box-shadow 0.18s ease, transform 0.18s ease;
}

.widget-card:hover {
    border-color: color-mix(in srgb, var(--accent-dashboard) 38%, var(--border-color));
    box-shadow: 0 2px 4px rgb(0 0 0 / 0.06), 0 16px 30px -18px rgb(0 0 0 / 0.55);
}

/* Edit mode: signal the card is interactive */
.widget-card-editing {
    border-style: solid;
    border-color: color-mix(in srgb, var(--accent-dashboard) 30%, var(--border-color));
}

.widget-card-editing:hover {
    border-color: color-mix(in srgb, var(--accent-dashboard) 55%, var(--border-color));
}

/* The card being dragged: lifted, dimmed, ignores pointer so we can hit targets */
.widget-card.dragging {
    opacity: 0.9;
    z-index: 50;
    cursor: grabbing;
    pointer-events: none;
    border-color: var(--accent-dashboard);
    box-shadow: 0 18px 40px -12px rgb(0 0 0 / 0.55), 0 0 0 2px color-mix(in srgb, var(--accent-dashboard) 45%, transparent);
    transform: scale(1.015);
}

.widget-card.resizing {
    border-color: var(--accent-dashboard);
    box-shadow: 0 0 0 2px color-mix(in srgb, var(--accent-dashboard) 35%, transparent);
    user-select: none;
}

body.dashboard-dragging,
body.dashboard-dragging * {
    cursor: grabbing !important;
    user-select: none !important;
}

/* --- Header --- */
.widget-header {
    flex: 0 0 auto;
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 0.5rem;
    padding: 0.85rem 1.1rem;
    border-bottom: 1px solid var(--border-color);
    background-color: color-mix(in srgb, var(--bg-subtle) 50%, transparent);
}

.widget-card-editing .widget-header {
    cursor: grab;
    touch-action: none;
}

.widget-card-editing .widget-header:active {
    cursor: grabbing;
}

.widget-title {
    display: flex;
    align-items: center;
    gap: 0.55rem;
    min-width: 0;
    font-family: var(--font-heading);
    font-weight: 600;
    font-size: var(--text-md);
    color: var(--text-main);
}

.widget-title svg {
    flex: 0 0 auto;
    padding: 4px;
    width: 24px;
    height: 24px;
    border-radius: var(--radius-md);
    color: var(--accent-dashboard);
    background-color: color-mix(in srgb, var(--accent-dashboard) 16%, transparent);
}

.widget-title-text {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.widget-actions {
    display: flex;
    align-items: center;
    gap: 0.2rem;
    flex: 0 0 auto;
    opacity: 1;
    transition: opacity 0.15s ease;
}

.widget-card:hover .widget-actions,
.widget-card-editing .widget-actions {
    opacity: 1;
}

.widget-action-btn,
.widget-delete-btn {
    position: relative;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 28px;
    height: 28px;
    padding: 0;
    background: transparent;
    border: none;
    border-radius: var(--radius-md);
    color: var(--text-muted);
    cursor: pointer;
    transition: background-color 0.15s ease, color 0.15s ease;
}

.widget-action-btn:hover,
.widget-delete-btn:hover {
    color: var(--text-main);
    background-color: var(--bg-subtle);
}

.widget-action-btn.is-active {
    color: var(--accent-dashboard);
    background-color: color-mix(in srgb, var(--accent-dashboard) 14%, transparent);
}

.widget-action-btn.is-danger:hover,
.widget-delete-btn.is-danger:hover {
    color: var(--danger);
    background-color: var(--danger-light);
}

.widget-action-badge {
    position: absolute;
    top: -3px;
    right: -3px;
    min-width: 14px;
    height: 14px;
    padding: 0 4px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border-radius: var(--radius-full);
    background: var(--accent-dashboard);
    color: #fff;
    font-size: 0.58rem;
    font-weight: 800;
    line-height: 1;
}

.widget-action-dot {
    position: absolute;
    top: 4px;
    right: 4px;
    width: 5px;
    height: 5px;
    border-radius: var(--radius-full);
    background: var(--accent-dashboard);
}

.widget-control-popover {
    position: fixed;
    z-index: 2300;
    width: min(380px, calc(100vw - 16px));
    max-height: min(72vh, 520px);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-lg);
}

.widget-control-header {
    min-height: 42px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.75rem;
    padding: 0.55rem 0.65rem 0.55rem 0.9rem;
    border-bottom: 1px solid var(--border-color);
    background: color-mix(in srgb, var(--bg-subtle) 58%, transparent);
}

.widget-control-header span {
    display: inline-flex;
    align-items: center;
    gap: 0.45rem;
    min-width: 0;
    color: var(--text-main);
    font-size: var(--text-sm);
    font-weight: 700;
}

.widget-control-header svg {
    width: 15px;
    height: 15px;
    color: var(--accent-dashboard);
}

.widget-control-body {
    display: flex;
    flex-direction: column;
    gap: 0.65rem;
    padding: 0.85rem;
    overflow: auto;
}

.widget-control-filter-list {
    display: flex;
    flex-direction: column;
    gap: 0.55rem;
}

.widget-control-filter-row {
    display: grid;
    grid-template-columns: minmax(0, 1.2fr) minmax(0, 1fr) minmax(76px, 0.95fr) 28px;
    align-items: center;
    gap: 0.45rem;
}

.widget-control-select,
.widget-control-value,
.widget-control-wide {
    min-width: 0;
    height: 32px;
    padding: 0 0.55rem;
    font-size: var(--text-xs);
}

.widget-control-label {
    margin: 0;
    color: var(--text-muted);
    font-size: var(--text-xs);
    font-weight: 800;
    text-transform: uppercase;
    letter-spacing: 0.04em;
}

.widget-control-empty {
    color: var(--text-muted);
    font-size: var(--text-sm);
    font-style: italic;
    padding: 0.4rem 0;
}

.widget-control-footer {
    display: flex;
    justify-content: flex-end;
    gap: 0.45rem;
    padding: 0.65rem 0.85rem;
    border-top: 1px solid var(--border-color);
    background: color-mix(in srgb, var(--bg-subtle) 34%, transparent);
}

/* --- Body (scroll container) --- */
.widget-body {
    flex: 1 1 auto;
    min-height: 0;
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
    padding: 1.1rem;
    overflow: auto;
}

.widget-body-metric {
    justify-content: center;
    align-items: flex-start;
    gap: 0.35rem;
}

.widget-body-list,
.widget-body-multi_search {
    padding: 0;
}

.widget-data-summary {
    flex: 0 0 auto;
    padding: 0.55rem 0.85rem;
    border-bottom: 1px solid color-mix(in srgb, var(--border-color) 70%, transparent);
    color: var(--text-muted);
    background: color-mix(in srgb, var(--bg-subtle) 34%, transparent);
    font-size: var(--text-xs);
    font-weight: 600;
    line-height: 1.35;
}

/* --- Metric --- */
.widget-metric-value {
    font-family: var(--font-heading);
    font-size: clamp(2.25rem, 1.2rem + 2.4vw, 3.1rem);
    font-weight: 700;
    line-height: 1;
    background: linear-gradient(135deg, var(--text-main), var(--accent-dashboard));
    -webkit-background-clip: text;
    background-clip: text;
    -webkit-text-fill-color: transparent;
    color: var(--accent-dashboard);
}

.widget-metric-sub {
    font-size: var(--text-xs);
    color: var(--text-muted);
    line-height: 1.35;
}

/* --- List --- */
.widget-list-preview {
    flex: 1 1 auto;
    min-height: 0;
    display: flex;
    flex-direction: column;
    overflow: auto;
}

.widget-list-table {
    width: 100%;
    border-collapse: collapse;
    table-layout: fixed;
}

.widget-list-table thead th {
    position: sticky;
    top: 0;
    z-index: 1;
    background-color: var(--bg-subtle);
    color: var(--text-muted);
    font-size: var(--text-2xs);
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    text-align: left;
    padding: 0.6rem 0.85rem;
    border-bottom: 1px solid var(--border-color);
}

.widget-list-resizable-header {
    position: sticky;
    min-width: 70px;
}

.widget-list-header-label {
    display: block;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    padding-right: 0.4rem;
}

.widget-list-column-resize-handle {
    position: absolute;
    top: 0;
    right: -2px;
    width: 11px;
    height: 100%;
    cursor: col-resize;
    touch-action: none;
    z-index: 2;
}

.widget-list-column-resize-handle::after {
    content: "";
    position: absolute;
    top: 22%;
    right: 4px;
    width: 2px;
    height: 56%;
    border-radius: 2px;
    background: var(--accent-dashboard);
    opacity: 0;
    transition: opacity 0.15s ease;
}

.widget-list-column-resize-handle:hover::after,
.widget-list-column-resize-handle:active::after {
    opacity: 0.85;
}

.widget-list-table tbody tr {
    cursor: pointer;
    transition: background-color 0.12s ease;
}

.widget-list-table tbody tr:hover {
    background-color: color-mix(in srgb, var(--accent-dashboard) 8%, transparent);
}

.widget-list-table td {
    padding: 0.6rem 0.85rem;
    font-size: var(--text-sm);
    border-bottom: 1px solid color-mix(in srgb, var(--border-color) 65%, transparent);
    vertical-align: middle;
    color: var(--text-main);
}

.widget-list-table tbody tr:last-child td {
    border-bottom: none;
}

.widget-list-empty {
    color: var(--text-muted);
    font-style: italic;
    padding: 1rem 1.1rem;
    font-size: var(--text-sm);
}

.widget-list-cell {
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.widget-cross-search-table .widget-list-cell:nth-child(2) {
    display: flex;
    align-items: center;
    gap: 0.4rem;
}

.widget-cross-search-record-title {
    font-weight: 600;
}

.widget-cross-search-workspace-icon {
    flex: 0 0 auto;
}

.widget-db-checkbox-list {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
    gap: 0.5rem;
    max-height: 220px;
    overflow: auto;
    padding: 0.25rem;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    background-color: var(--bg-subtle);
}

.widget-db-checkbox {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    min-width: 0;
    padding: 0.45rem 0.55rem;
    border: 1px solid color-mix(in srgb, var(--border-color) 70%, transparent);
    border-radius: var(--radius-sm);
    background: var(--bg-card);
    color: var(--text-main);
    font-size: var(--text-sm);
    cursor: pointer;
}

.widget-db-checkbox input {
    flex: 0 0 auto;
}

.widget-db-checkbox span {
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.widget-search-rule-grid {
    display: grid;
    grid-template-columns: minmax(0, 1.1fr) minmax(140px, 0.75fr) minmax(0, 1fr);
    gap: 0.75rem;
}

.widget-field-pill-list {
    display: flex;
    flex-wrap: nowrap;
    gap: 0.35rem;
    overflow: hidden;
}

.widget-field-pill {
    display: inline-flex;
    align-items: center;
    gap: 0.3rem;
    max-width: 100%;
    padding: 0.16rem 0.55rem;
    border: 1px solid color-mix(in srgb, var(--border-color) 80%, transparent);
    border-radius: var(--radius-full);
    background-color: var(--bg-subtle);
    color: var(--text-main);
    font-size: var(--text-xs);
    font-weight: 600;
    line-height: 1.3;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

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

/* --- Markdown --- */
.widget-markdown {
    font-size: var(--text-base);
    line-height: 1.6;
    color: var(--text-main);
}

.widget-markdown h1,
.widget-markdown h2 {
    font-family: var(--font-heading);
    margin: 0.2rem 0 0.4rem;
}

.widget-markdown h1 { font-size: 1.15rem; }
.widget-markdown h2 { font-size: 1rem; }
.widget-markdown p { margin: 0 0 0.5rem; }
.widget-markdown ul { margin: 0 0 0.5rem 1.1rem; }
.widget-markdown a { color: var(--primary); }

/* --- Resize handle --- */
.widget-resize-handle {
    position: absolute;
    right: 4px;
    bottom: 4px;
    width: 20px;
    height: 20px;
    cursor: nwse-resize;
    border-radius: var(--radius-sm);
    z-index: 3;
    opacity: 0.55;
    background-image:
        linear-gradient(135deg, transparent 0 46%, var(--text-muted) 46% 54%, transparent 54% 100%),
        linear-gradient(135deg, transparent 0 66%, var(--text-muted) 66% 74%, transparent 74% 100%);
    transition: opacity 0.15s ease;
}

.widget-card-editing:hover .widget-resize-handle {
    opacity: 0.9;
}

.widget-resize-handle:hover {
    opacity: 1;
}

body.widget-expanded-open {
    overflow: hidden;
}

body.widget-expanded-open::before {
    content: "";
    position: fixed;
    inset: 0;
    z-index: 2190;
    background: rgb(0 0 0 / 0.58);
    backdrop-filter: blur(2px);
}

.widget-card.widget-expanded {
    position: fixed;
    inset: 28px;
    z-index: 2200;
    height: auto;
    min-height: 0;
    max-height: calc(100dvh - 56px);
    grid-column: auto !important;
    grid-row: auto !important;
    box-shadow: var(--shadow-xl);
    transform: none !important;
}

.widget-card.widget-expanded .widget-actions {
    opacity: 1;
}

.widget-card.widget-expanded .widget-header {
    cursor: default;
}

.widget-card.widget-expanded .widget-body {
    min-height: 0;
    overflow: auto;
}

/* --- Empty state --- */
.widget-dashboard-empty {
    grid-column: 1 / -1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    text-align: center;
    padding: 4rem 2rem;
    border: 1px dashed var(--border-color);
    border-radius: var(--radius-lg);
    background-color: var(--bg-card);
    color: var(--text-muted);
}

.widget-dashboard-empty svg {
    width: 44px;
    height: 44px;
    margin-bottom: 1rem;
    color: var(--accent-dashboard);
    opacity: 0.65;
}

.widget-dashboard-empty h3 {
    color: var(--text-main);
    font-family: var(--font-heading);
    margin-bottom: 0.4rem;
}

.widget-dashboard-empty p {
    max-width: 420px;
}

/* --- Bar charts --- */
.widget-chart-container {
    display: flex;
    flex-direction: column;
    gap: 0.85rem;
}

.widget-chart-row {
    display: flex;
    flex-direction: column;
    gap: 0.3rem;
}

.widget-chart-row-header {
    display: flex;
    justify-content: space-between;
    gap: 0.75rem;
    font-size: var(--text-sm);
    font-weight: 500;
    color: var(--text-main);
}

.widget-chart-row-header span:first-child {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.widget-chart-row-header span:last-child {
    color: var(--text-muted);
    font-variant-numeric: tabular-nums;
}

.widget-chart-bar-track {
    background-color: var(--bg-subtle);
    height: 9px;
    border-radius: var(--radius-full);
    width: 100%;
    overflow: hidden;
}

.widget-chart-bar-fill {
    height: 100%;
    border-radius: var(--radius-full);
    min-width: 3px;
    background: linear-gradient(
        90deg,
        var(--accent-dashboard),
        color-mix(in srgb, var(--accent-dashboard) 55%, var(--primary))
    );
}

@media (max-width: 1200px) {
    .widget-grid {
        grid-template-columns: repeat(8, minmax(0, 1fr));
    }
}

@media (max-width: 900px) {
    .widget-grid {
        grid-template-columns: repeat(1, minmax(0, 1fr));
        grid-auto-rows: auto;
    }

    .widget-card {
        height: auto;
        grid-column: span 1 !important;
        grid-row: auto !important;
    }

    .widget-body {
        overflow: visible;
    }

    .widget-list-preview {
        max-height: 280px;
    }
}

@media (max-width: 640px) {
    .widget-header {
        padding: 0.7rem 0.8rem;
        align-items: flex-start;
    }

    .widget-actions {
        flex-wrap: wrap;
        justify-content: flex-end;
        max-width: 150px;
    }

    .widget-control-popover {
        left: 10px !important;
        right: 10px;
        top: auto !important;
        bottom: 10px;
        width: auto;
        max-height: min(78dvh, 560px);
    }

    .widget-control-filter-row {
        grid-template-columns: 1fr;
        align-items: stretch;
    }

    .widget-search-rule-grid {
        grid-template-columns: 1fr;
    }

    .widget-control-filter-row .widget-action-btn {
        justify-self: flex-end;
    }

    .widget-card.widget-expanded {
        inset: 10px;
        max-height: calc(100dvh - 20px);
    }

    .widget-list-table {
        table-layout: auto;
    }

    .widget-list-table thead {
        display: none;
    }

    .widget-list-table,
    .widget-list-table tbody,
    .widget-list-table tr,
    .widget-list-table td {
        display: block;
        width: 100%;
    }

    .widget-list-table tbody tr {
        padding: 0.35rem 0;
    }

    .widget-list-table td {
        border-bottom: none;
        padding: 0.35rem 0.85rem;
        white-space: normal;
    }
}


/* ==========================================
   CALENDAR VIEW PANEL STYLING
   ========================================== */
.calendar-view-container {
    background-color: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-md);
    padding: 1.5rem;
    display: flex;
    flex-direction: column;
    gap: 1.5rem;
    width: 100%;
}

.calendar-top-controls {
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-bottom: 1px solid var(--border-color);
    padding-bottom: 1rem;
    flex-wrap: wrap;
    gap: 1rem;
}

.calendar-month-nav {
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

.calendar-month-nav h2 {
    font-family: var(--font-heading);
    font-weight: 700;
    font-size: var(--text-xl);
    color: var(--text-main);
    min-width: 160px;
    text-align: center;
}

.calendar-meta-info {
    font-size: var(--text-sm);
    color: var(--text-muted);
    background-color: var(--bg-app);
    padding: 0.4rem 0.8rem;
    border-radius: var(--radius-md);
    border: 1px solid var(--border-color);
    display: flex;
    align-items: center;
    gap: 0.4rem;
}

.calendar-filter-bar {
    background-color: var(--bg-app);
    border: 1px dashed var(--border-color);
    border-radius: var(--radius-md);
    padding: 0.85rem;
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
}

.calendar-grid-header {
    display: grid;
    grid-template-columns: repeat(7, 1fr);
    gap: 4px;
    text-align: center;
    margin-bottom: 4px;
}

.calendar-day-header {
    font-family: var(--font-heading);
    font-weight: 700;
    font-size: var(--text-xs);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--text-muted);
    padding: 0.5rem 0;
    background-color: var(--bg-app);
    border-radius: var(--radius-sm);
    border: 1px solid var(--border-color);
}

.calendar-grid-body {
    display: grid;
    grid-template-columns: repeat(7, 1fr);
    grid-auto-rows: minmax(110px, 1fr);
    gap: 4px;
    background-color: var(--border-color);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    overflow: hidden;
}

.calendar-day-cell {
    background-color: var(--bg-card);
    padding: 1.75rem 0.5rem 0.5rem 0.5rem;
    position: relative;
    display: flex;
    flex-direction: column;
    gap: 0.35rem;
    min-height: 110px;
    cursor: cell;
    transition: background-color 0.2s ease;
}

.calendar-day-cell:hover {
    background-color: rgba(99, 102, 241, 0.02);
}

.calendar-day-cell.other-month {
    background-color: var(--bg-app);
}

.calendar-day-cell.other-month .calendar-day-number {
    color: rgba(148, 163, 184, 0.4);
}

.calendar-day-cell.today {
    background-color: rgba(99, 102, 241, 0.03);
    border: 1px solid var(--primary);
    z-index: 2;
}

.calendar-day-cell.today .calendar-day-number {
    background-color: var(--primary);
    color: white;
    font-weight: bold;
    border-radius: 50%;
    width: 22px;
    height: 22px;
    display: flex;
    align-items: center;
    justify-content: center;
    top: 4px;
    left: 4px;
}

.calendar-day-number {
    position: absolute;
    top: 6px;
    left: 8px;
    font-size: var(--text-sm);
    font-weight: 600;
    color: var(--text-muted);
}

.calendar-record-list {
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
    overflow-y: auto;
    max-height: calc(100% - 10px);
    flex-grow: 1;
}

.calendar-record-badge {
    background-color: var(--primary-light);
    color: var(--primary-text);
    border: 1px solid rgba(99, 102, 241, 0.2);
    border-left: 3px solid var(--primary);
    border-radius: var(--radius-sm);
    padding: 0.2rem 0.4rem;
    font-size: var(--text-xs);
    font-weight: 600;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    cursor: pointer;
    transition: var(--transition);
    max-width: 100%;
}

.calendar-record-badge:hover {
    transform: scale(1.02);
    box-shadow: var(--shadow-sm);
    background-color: rgba(99, 102, 241, 0.15);
}

.calendar-record-badge.date-range-badge {
    background-color: rgba(245, 158, 11, 0.15);
    color: #b45309;
    border: 1px solid rgba(245, 158, 11, 0.2);
    border-left: 3px solid var(--warning);
}

.calendar-record-badge.date-range-badge:hover {
    background-color: rgba(245, 158, 11, 0.22);
}

/* --- Sidebar Calendar Widget --- */
.sidebar-calendar-container {
    padding: 0.75rem;
    border-bottom: 1px solid var(--border-sidebar);
    background-color: rgba(0, 0, 0, 0.15);
    margin-bottom: 0.75rem;
    border-radius: var(--radius-md);
    margin-left: 0.5rem;
    margin-right: 0.5rem;
}

.sidebar-cal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 0.5rem;
}

.sidebar-cal-title {
    font-family: var(--font-heading);
    font-size: var(--text-sm);
    font-weight: 600;
    color: var(--text-sidebar-bright);
}

.sidebar-cal-nav {
    display: flex;
    gap: 0.25rem;
}

.sidebar-cal-btn {
    background: transparent;
    border: none;
    color: var(--text-sidebar);
    cursor: pointer;
    border-radius: var(--radius-sm);
    padding: 2px 4px;
    min-width: 24px;
    min-height: 24px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: var(--transition);
}

.sidebar-cal-btn:hover {
    background-color: var(--bg-sidebar-hover);
    color: var(--text-sidebar-bright);
}

.sidebar-cal-grid {
    display: grid;
    grid-template-columns: repeat(7, 1fr);
    gap: 2px;
    text-align: center;
}

.sidebar-cal-day-hdr {
    font-size: 0.6rem;
    font-weight: 700;
    text-transform: uppercase;
    color: var(--text-muted);
    padding-bottom: 2px;
}

.sidebar-cal-day {
    font-size: var(--text-xs);
    padding: 3px 0;
    cursor: pointer;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    aspect-ratio: 1;
    color: var(--text-sidebar);
    transition: var(--transition);
}

.sidebar-cal-day:hover {
    background-color: var(--bg-sidebar-hover);
    color: var(--text-sidebar-bright);
}

.sidebar-cal-day.active {
    background-color: var(--primary);
    color: white !important;
    font-weight: 700;
}

.sidebar-cal-day.today {
    box-shadow: inset 0 0 0 1px var(--primary);
    color: var(--text-sidebar-bright);
}

.sidebar-cal-day.other-month {
    opacity: 0.3;
}

/* --- Journal Editor View Panel --- */
.journal-container {
    background-color: var(--bg-card);
    border-radius: var(--radius-lg);
    border: 1px solid var(--border-color);
    box-shadow: var(--shadow-md);
    padding: 2rem;
    display: flex;
    flex-direction: column;
    height: 100%;
    /* Account for hub topbar + app chrome (was 100vh - 120px before topbar) */
    min-height: calc(100dvh - var(--hub-topbar-height) - 140px);
}

.journal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-bottom: 1px solid var(--border-color);
    padding-bottom: 0.7rem;
    margin-bottom: 0.65rem;
}

.journal-header-actions {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 0.6rem;
}

.journal-title-wrapper h2 {
    font-family: var(--font-heading);
    font-size: 1.75rem;
    font-weight: 700;
    color: var(--text-main);
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.journal-mobile-date-nav {
    display: none;
    align-items: center;
    gap: 0.5rem;
    margin-top: 0.75rem;
}

.journal-mobile-date-picker {
    position: relative;
    min-width: 0;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.4rem;
    padding: 0.42rem 0.8rem;
    border-radius: var(--radius-md);
    border: 1px solid var(--border-color);
    background: var(--bg-card);
    color: var(--text-main);
    font-size: var(--text-sm);
    font-weight: 600;
    cursor: pointer;
}

.journal-mobile-date-picker input {
    position: absolute;
    inset: 0;
    opacity: 0;
    cursor: pointer;
}

.journal-title-wrapper p {
    font-size: var(--text-base);
    color: var(--text-muted);
    margin-top: 0.25rem;
}

.journal-status-badge {
    font-size: var(--text-xs);
    font-weight: 600;
    color: var(--text-muted);
    background-color: var(--bg-app);
    padding: 0.35rem 0.75rem;
    border-radius: var(--radius-lg);
    display: flex;
    align-items: center;
    gap: 0.35rem;
    transition: opacity 0.3s ease;
}

.journal-status-badge.saving {
    color: var(--warning);
}

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

/* Journal WYSIWYG toolbar */
.journal-wysiwyg-toolbar {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 0.15rem;
    padding: 0.4rem 0.5rem;
    background: var(--bg-app);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md) var(--radius-md) 0 0;
    border-bottom: none;
}

.journal-linked-records-panel {
    margin-top: 0;
    padding: 0.85rem;
    border: 1px solid color-mix(in srgb, var(--accent-journal) 28%, var(--border-color));
    border-radius: var(--radius-md);
    background:
        linear-gradient(135deg, color-mix(in srgb, var(--accent-journal) 10%, transparent), transparent 36%),
        var(--bg-card);
    box-shadow: inset 0 1px 0 color-mix(in srgb, #fff 5%, transparent), var(--shadow-sm);
    display: flex;
    flex-direction: column;
    gap: 0.85rem;
}

.journal-linked-records-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: 1rem;
}

.journal-linked-records-header h3 {
    margin: 0;
    font-size: var(--text-md);
    font-family: var(--font-heading);
    display: flex;
    align-items: center;
    gap: 0.45rem;
    color: var(--text-main);
}

.journal-linked-records-header p {
    margin: 0.2rem 0 0 0;
    color: var(--text-muted);
    font-size: var(--text-xs);
}

.journal-linked-records-count {
    min-width: 1.35rem;
    height: 1.35rem;
    padding: 0 0.4rem;
    border-radius: var(--radius-full);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    background: color-mix(in srgb, var(--accent-journal) 18%, var(--bg-subtle));
    color: color-mix(in srgb, var(--accent-journal) 55%, var(--text-main));
    border: 1px solid color-mix(in srgb, var(--accent-journal) 28%, transparent);
    font-family: var(--font-body);
    font-size: var(--text-xs);
    font-weight: 800;
}

.journal-linked-records-groups {
    display: flex;
    flex-direction: column;
    gap: 0.95rem;
}

.journal-linked-record-group {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.journal-linked-record-group-title {
    font-size: var(--text-xs);
    text-transform: uppercase;
    letter-spacing: 0.055em;
    color: color-mix(in srgb, var(--accent-journal) 48%, var(--text-muted));
    font-weight: 700;
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.journal-linked-record-group-count {
    min-width: 1.2rem;
    height: 1.2rem;
    padding: 0 0.34rem;
    border-radius: var(--radius-full);
    background: var(--bg-subtle);
    border: 1px solid var(--border-color);
    color: var(--text-muted);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-size: var(--text-2xs);
    letter-spacing: 0;
}

.journal-linked-record-list {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(288px, 1fr));
    gap: 0.5rem;
}

.journal-linked-record-item {
    display: flex;
    min-width: 0;
    align-items: stretch;
    border: 1px solid color-mix(in srgb, var(--accent-journal) 24%, var(--border-color));
    border-radius: var(--radius-md);
    overflow: hidden;
    background: color-mix(in srgb, var(--bg-card) 88%, var(--accent-journal));
    transition: var(--transition);
}

.journal-linked-record-item:hover {
    border-color: color-mix(in srgb, var(--accent-journal) 55%, var(--border-color));
    background: color-mix(in srgb, var(--bg-card) 82%, var(--accent-journal));
    transform: translateY(-1px);
}

.journal-linked-record-content {
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
    gap: 0.18rem;
    padding: 0.48rem 0.68rem;
}

.journal-linked-record-open {
    border: 0;
    background: transparent;
    color: inherit;
    width: 100%;
    min-width: 0;
    display: block;
    padding: 0;
    cursor: pointer;
    text-align: left;
}

.journal-linked-record-open:hover .chip-title {
    color: var(--primary-text);
}

.journal-linked-record-copy {
    min-width: 0;
    width: 100%;
    display: block;
}

.journal-linked-record-open .chip-title {
    display: block;
    color: var(--text-main);
    font-weight: 700;
    font-size: var(--text-sm);
    line-height: 1.2;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.journal-linked-record-meta {
    display: flex;
    align-items: center;
    flex-wrap: nowrap;
    gap: 0.32rem;
    min-width: 0;
}

.journal-linked-record-location {
    flex: 0 1 auto;
    min-width: 0;
    border: 0;
    background: transparent;
    color: inherit;
    padding: 0;
    cursor: pointer;
}

.journal-linked-record-meta .chip-db,
.journal-linked-record-meta .chip-field {
    display: block;
    border-radius: var(--radius-full);
    padding: 0.12rem 0.4rem;
    font-size: var(--text-2xs);
    line-height: 1.2;
    font-weight: 700;
}

.journal-linked-record-meta .chip-db {
    flex: 0 1 auto;
    min-width: 0;
    background: color-mix(in srgb, var(--accent-journal) 18%, var(--bg-subtle));
    color: color-mix(in srgb, var(--accent-journal) 60%, var(--text-main));
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.journal-linked-record-location:hover .chip-db {
    color: var(--primary-text);
}

.journal-linked-record-meta .chip-field {
    max-width: 100%;
    background: var(--bg-subtle);
    color: var(--text-muted);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.journal-linked-record-field-chip {
    flex: 0 1 auto;
    max-width: min(180px, 65%);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-full);
    background: var(--bg-subtle);
    color: var(--text-main);
    padding: 0.14rem 0.34rem;
    font-size: 0.62rem;
    line-height: 1.2;
    font-weight: 700;
    display: inline-flex;
    align-items: center;
    gap: 0.2rem;
    min-width: 0;
    white-space: nowrap;
}

.journal-linked-record-field-chip.is-editable {
    cursor: pointer;
    transition: var(--transition);
}

.journal-linked-record-field-chip.is-editable:hover,
.journal-linked-record-field-chip.is-editable:focus-visible {
    border-color: var(--primary);
    color: var(--primary-text);
    background: var(--primary-light);
    outline: none;
}

.journal-linked-record-field-chip.is-empty .linked-record-field-value {
    color: var(--text-muted);
    font-style: italic;
}

.linked-record-field-name {
    color: inherit;
    flex: 0 1 auto;
    min-width: 0;
    max-width: 3.4rem;
    overflow: hidden;
    text-overflow: ellipsis;
    opacity: 0.72;
}

.linked-record-field-value {
    flex: 1 1 auto;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
}

.journal-linked-record-inline-input {
    flex: 0 1 180px;
    min-width: 0;
    border: 1px solid var(--primary);
    border-radius: var(--radius-md);
    background: var(--bg-card);
    color: var(--text-main);
    padding: 0.26rem 0.46rem;
    font-size: var(--text-xs);
    font-family: var(--font-body);
    outline: none;
}

.journal-linked-record-next-day,
.journal-linked-record-remove {
    border: 0;
    border-left: 1px solid color-mix(in srgb, var(--accent-journal) 20%, var(--border-color));
    background: transparent;
    color: var(--text-muted);
    width: 32px;
    flex-shrink: 0;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: var(--transition);
}

.journal-linked-record-next-day:hover {
    color: var(--accent-journal);
    background: color-mix(in srgb, var(--accent-journal) 12%, transparent);
}

.journal-linked-record-next-day.linked {
    color: var(--success);
    background: color-mix(in srgb, var(--success) 14%, transparent);
    cursor: default;
}

.journal-linked-record-drag {
    border: 0;
    border-right: 1px solid color-mix(in srgb, var(--accent-journal) 20%, var(--border-color));
    background: transparent;
    color: color-mix(in srgb, var(--text-muted) 80%, transparent);
    width: 26px;
    flex-shrink: 0;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    cursor: grab;
    touch-action: none;
    transition: var(--transition);
}

.journal-linked-record-drag:hover {
    color: var(--accent-journal);
    background: color-mix(in srgb, var(--accent-journal) 12%, transparent);
}

.journal-linked-record-drag:active {
    cursor: grabbing;
}

.journal-linked-record-item.dragging {
    opacity: 0.45;
}

.journal-linked-record-item.drag-over-before {
    box-shadow: inset 0 2px 0 0 var(--accent-journal);
}

.journal-linked-record-item.drag-over-after {
    box-shadow: inset 0 -2px 0 0 var(--accent-journal);
}

.journal-linked-record-remove:hover {
    color: var(--danger);
    background: color-mix(in srgb, var(--danger) 12%, transparent);
}

.journal-linked-records-empty {
    color: color-mix(in srgb, var(--text-muted) 86%, var(--text-main));
    font-size: var(--text-sm);
    border: 1px dashed color-mix(in srgb, var(--accent-journal) 26%, var(--border-color));
    border-radius: var(--radius-md);
    padding: 0.85rem;
    background: color-mix(in srgb, var(--bg-subtle) 78%, transparent);
}

.journal-toolbar-sep {
    width: 1px;
    height: 18px;
    background: var(--border-color);
    margin: 0 0.2rem;
    display: inline-block;
}

.journal-history-modal {
    max-width: 680px;
}

.journal-history-modal .modal-header h3 {
    margin: 0;
}

.journal-history-subtitle {
    margin: 0.2rem 0 0;
    color: var(--text-muted);
    font-family: var(--font-body);
    font-size: var(--text-xs);
    font-weight: 500;
}

.journal-history-body {
    max-height: min(65vh, 620px);
    overflow-y: auto;
}

.journal-history-item {
    padding: 1rem;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    background: var(--bg-subtle);
}

.journal-history-item.current {
    border-color: color-mix(in srgb, var(--primary) 55%, var(--border-color));
}

.journal-history-item-header {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 1rem;
}

.journal-history-current {
    display: inline-flex;
    margin-left: 0.45rem;
    padding: 0.12rem 0.45rem;
    border-radius: var(--radius-full);
    color: var(--primary);
    background: color-mix(in srgb, var(--primary) 14%, transparent);
    font-size: var(--text-2xs);
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.04em;
}

.journal-history-meta {
    margin-top: 0.25rem;
    color: var(--text-muted);
    font-size: var(--text-xs);
}

.journal-history-preview {
    margin: 0.75rem 0 0;
    color: var(--text-main);
    font-size: var(--text-base);
    line-height: 1.45;
}

.journal-history-empty {
    padding: 2rem 1rem;
    color: var(--text-muted);
    text-align: center;
}

.journal-history-help {
    margin-right: auto;
    color: var(--text-muted);
    font-size: var(--text-xs);
}

/* Journal WYSIWYG editor surface */
.journal-wysiwyg-editor {
    flex: 1;
    width: 100%;
    min-height: 0;
    border: 1px solid var(--border-color);
    border-radius: 0 0 var(--radius-md) var(--radius-md);
    background: transparent;
    color: var(--text-main);
    font-family: var(--font-body);
    font-size: 1.05rem;
    line-height: 1.7;
    outline: none;
    padding: 1rem;
    overflow-y: auto;
    cursor: text;
}

.journal-wysiwyg-editor:focus {
    border-color: var(--primary);
}

.journal-wysiwyg-editor:empty::before,
.journal-wysiwyg-editor.no-visible-content::before {
    content: attr(data-placeholder);
    color: var(--text-muted);
    opacity: 0.6;
    pointer-events: none;
}

.journal-wysiwyg-editor h1 {
    font-size: 1.6rem;
    font-family: var(--font-heading);
    font-weight: 700;
    margin: 0.75rem 0 0.4rem;
    border-bottom: 1px solid var(--border-color);
    padding-bottom: 0.25rem;
}

.journal-wysiwyg-editor h2 {
    font-size: 1.3rem;
    font-family: var(--font-heading);
    font-weight: 600;
    margin: 0.6rem 0 0.3rem;
}

.journal-wysiwyg-editor h3 {
    font-size: var(--text-lg);
    font-family: var(--font-heading);
    font-weight: 600;
    margin: 0.5rem 0 0.25rem;
}

.journal-wysiwyg-editor ul,
.journal-wysiwyg-editor ol {
    padding-left: 1.5rem;
    margin: 0.5rem 0;
}

.journal-wysiwyg-editor li {
    margin: 0.2rem 0;
}

.journal-wysiwyg-editor blockquote {
    border-left: 3px solid var(--primary);
    padding-left: 1rem;
    margin: 0.75rem 0;
    color: var(--text-muted);
    font-style: italic;
}

.journal-wysiwyg-editor a {
    color: var(--primary);
    text-decoration: underline;
}

.journal-wysiwyg-editor img {
    max-width: 100%;
    border-radius: var(--radius-sm);
    margin: 0.5rem 0;
    display: block;
}

/* Relation picker search */
.link-dropdown-search {
    display: block;
    width: 100%;
    padding: 0.5rem 0.75rem;
    font-size: var(--text-sm);
    border: none;
    border-bottom: 1px solid var(--border-color);
    background: var(--bg-card);
    color: var(--text-main);
    outline: none;
    border-radius: var(--radius-md) var(--radius-md) 0 0;
}

.link-dropdown-search::placeholder {
    color: var(--text-muted);
}

.link-dropdown-list {
    max-height: 180px;
    overflow-y: auto;
}

.link-dropdown-item.highlighted {
    background-color: var(--primary-light);
    color: var(--primary-text);
}

.link-dropdown-item mark {
    background: var(--warning-light);
    color: inherit;
    border-radius: 2px;
    padding: 0 1px;
}

.link-dropdown-copy {
    min-width: 0;
    display: flex;
    flex-direction: column;
    gap: 0.16rem;
}

.link-dropdown-title,
.link-dropdown-meta {
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.link-dropdown-title {
    color: var(--text-main);
    font-weight: 650;
}

.link-dropdown-meta {
    color: var(--text-muted);
    font-size: var(--text-xs);
}

/* ── Slash command menu ─────────────────────────────────────────────── */
.slash-menu {
    position: absolute;
    z-index: 9000;
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-xl);
    width: 280px;
    padding: 0.25rem;
    overflow: hidden;
}

.slash-menu-item {
    display: flex;
    align-items: center;
    gap: 0.6rem;
    padding: 0.5rem 0.6rem;
    border-radius: var(--radius-sm);
    cursor: pointer;
    transition: var(--transition);
}

.slash-menu-item:hover,
.slash-menu-item.highlighted {
    background: var(--primary-light);
}

.slash-menu-icon {
    width: 28px;
    height: 28px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--bg-app);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    flex-shrink: 0;
    color: var(--primary);
}

.slash-menu-label {
    font-size: var(--text-sm);
    font-weight: 600;
    color: var(--text-main);
    flex: 1;
}

.slash-menu-hint {
    font-size: var(--text-xs);
    color: var(--text-muted);
    white-space: nowrap;
}

/* ── Record link modal ──────────────────────────────────────────────── */
.record-link-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.35);
    z-index: 9100;
}

.record-link-modal {
    position: fixed;
    top: 20%;
    left: 50%;
    transform: translateX(-50%);
    z-index: 9200;
    width: min(520px, 92vw);
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-xl);
    display: flex;
    flex-direction: column;
    overflow: visible;
}

.record-link-modal-header {
    display: flex;
    align-items: center;
    gap: 0.6rem;
    padding: 0.85rem 1rem;
    border-bottom: 1px solid var(--border-color);
}

.record-link-input {
    flex: 1;
    border: none;
    outline: none;
    background: transparent;
    font-size: var(--text-md);
    color: var(--text-main);
    font-family: var(--font-body);
}

.record-link-input::placeholder {
    color: var(--text-muted);
}

.record-link-close {
    background: none;
    border: none;
    cursor: pointer;
    color: var(--text-muted);
    padding: 2px;
    border-radius: var(--radius-sm);
    display: flex;
    align-items: center;
}

.record-link-close:hover { color: var(--danger); }

.record-link-select {
    flex: 1;
    min-width: 0;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    background: var(--bg-tertiary);
    color: var(--text-main);
    padding: 0.45rem 0.65rem;
    font-size: var(--text-sm);
    font-family: var(--font-body);
}

.record-link-select:disabled {
    opacity: 0.6;
    cursor: not-allowed;
}

.record-link-workspace-filters {
    display: flex;
    align-items: center;
    gap: 0.4rem;
    padding: 0.65rem 1rem;
    border-bottom: 1px solid var(--border-color);
    overflow-x: auto;
}

.record-link-workspace-filter {
    border: 1px solid var(--border-color);
    border-radius: var(--radius-full);
    background: var(--bg-tertiary);
    color: var(--text-muted);
    display: inline-flex;
    align-items: center;
    gap: 0.35rem;
    min-height: 1.9rem;
    padding: 0.28rem 0.65rem;
    font-size: var(--text-xs);
    font-weight: 700;
    white-space: nowrap;
    cursor: pointer;
    transition: var(--transition);
}

.record-link-workspace-filter:hover,
.record-link-workspace-filter.active {
    border-color: color-mix(in srgb, var(--primary) 55%, var(--border-color));
    background: var(--primary-light);
    color: var(--text-main);
}

.record-link-search-controls {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    align-items: center;
    gap: 0.55rem;
    padding: 0.65rem 1rem;
    border-bottom: 1px solid var(--border-color);
}

.record-link-filter-toggle {
    min-height: 2.35rem;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    background: var(--bg-tertiary);
    color: var(--text-muted);
    padding: 0.35rem 0.65rem;
    font-family: var(--font-body);
    font-size: var(--text-sm);
    font-weight: 700;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.4rem;
    cursor: pointer;
    white-space: nowrap;
    transition: var(--transition);
}

.record-link-filter-toggle:hover,
.record-link-filter-toggle.active {
    border-color: color-mix(in srgb, var(--primary) 55%, var(--border-color));
    background: var(--primary-light);
    color: var(--text-main);
}

.record-link-filter-toggle:disabled {
    opacity: 0.55;
    cursor: not-allowed;
    box-shadow: none;
}

.record-link-filter-panel {
    grid-template-columns: minmax(0, 1.4fr) minmax(0, 1fr) minmax(0, 1.2fr);
    gap: 0.5rem;
    padding: 0.65rem 1rem;
    border-bottom: 1px solid var(--border-color);
    background: color-mix(in srgb, var(--bg-card) 86%, var(--bg-subtle));
}

.record-link-db-picker {
    position: relative;
    min-width: 0;
}

.record-link-db-trigger {
    width: 100%;
    min-height: 2.35rem;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    background: var(--bg-tertiary);
    color: var(--text-main);
    padding: 0.35rem 0.55rem;
    font-family: var(--font-body);
    font-size: var(--text-sm);
    display: flex;
    align-items: center;
    gap: 0.5rem;
    cursor: pointer;
    text-align: left;
    transition: var(--transition);
}

.record-link-db-trigger:hover,
.record-link-db-picker.open .record-link-db-trigger {
    border-color: color-mix(in srgb, var(--primary) 55%, var(--border-color));
    box-shadow: var(--ring);
}

.record-link-db-trigger-label {
    color: var(--text-muted);
    flex: 1;
    min-width: 0;
}

.record-link-db-trigger-copy,
.record-link-db-option-copy {
    min-width: 0;
    display: flex;
    flex-direction: column;
    gap: 0.12rem;
    flex: 1;
}

.record-link-db-trigger-name,
.record-link-db-option-name {
    color: var(--text-main);
    font-size: var(--text-sm);
    font-weight: 700;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.record-link-db-trigger-workspace,
.record-link-db-option-workspace {
    color: var(--text-muted);
    font-size: var(--text-2xs);
    font-weight: 600;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.record-link-db-menu {
    position: absolute;
    display: none;
    z-index: 30;
    top: calc(100% + 0.35rem);
    left: 0;
    width: min(22rem, 78vw);
    max-height: 16rem;
    overflow-y: auto;
    padding: 0.35rem;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    background: var(--bg-card);
    box-shadow: var(--shadow-lg);
}

.record-link-db-picker.open .record-link-db-menu {
    display: flex;
    flex-direction: column;
    gap: 0.2rem;
}

.record-link-db-option {
    width: 100%;
    border: 1px solid transparent;
    border-radius: var(--radius-sm);
    background: transparent;
    color: var(--text-main);
    display: flex;
    align-items: center;
    gap: 0.55rem;
    padding: 0.48rem 0.55rem;
    font-family: var(--font-body);
    cursor: pointer;
    text-align: left;
    transition: var(--transition);
}

.record-link-db-option:hover,
.record-link-db-option:focus-visible,
.record-link-db-option.selected {
    outline: none;
    border-color: color-mix(in srgb, var(--primary) 35%, transparent);
    background: var(--primary-light);
}

.record-link-db-option-empty {
    padding: 0.85rem;
    color: var(--text-muted);
    font-size: var(--text-sm);
    text-align: center;
}

.field-options-editor {
    display: flex;
    flex-direction: column;
    gap: 0.65rem;
}

.field-option-setting {
    display: flex;
    align-items: center;
    gap: 0.55rem;
    margin-top: 0.75rem;
    color: var(--text-main);
    font-size: var(--text-sm);
}

.field-option-setting input[type="checkbox"] {
    width: 1rem;
    height: 1rem;
}

.field-option-row {
    display: grid;
    grid-template-columns: 5.5rem minmax(0, 1fr) auto auto;
    gap: 0.65rem;
    align-items: center;
}

.field-option-icon-picker {
    position: relative;
}

.field-option-icon-trigger {
    width: 100%;
    min-height: 2.5rem;
    border: 1px solid var(--border-color);
    border-radius: 0.9rem;
    background:
        linear-gradient(180deg, color-mix(in srgb, var(--bg-card) 88%, white 3%), var(--bg-tertiary));
    color: var(--text-main);
    font-size: var(--text-lg);
    cursor: pointer;
    transition: transform 0.14s ease, border-color 0.14s ease, box-shadow 0.14s ease;
}

.field-option-icon-trigger:hover,
.field-option-icon-picker.open .field-option-icon-trigger {
    border-color: var(--primary);
    box-shadow: 0 0 0 3px color-mix(in srgb, var(--primary) 16%, transparent);
    transform: translateY(-1px);
}

.field-option-icon-placeholder {
    color: var(--text-muted);
    font-size: var(--text-md);
    font-weight: 700;
}

.field-option-icon-menu {
    position: absolute;
    top: calc(100% + 0.45rem);
    left: 0;
    z-index: 30;
    display: none;
    width: 13.5rem;
    padding: 0.55rem;
    border: 1px solid var(--border-color);
    border-radius: 1rem;
    background: color-mix(in srgb, var(--bg-card) 96%, black 4%);
    box-shadow: var(--shadow-lg);
    grid-template-columns: repeat(5, minmax(0, 1fr));
    gap: 0.35rem;
}

.field-option-icon-picker.open .field-option-icon-menu {
    display: grid;
}

.field-option-icon-choice {
    min-height: 2.3rem;
    border: 1px solid transparent;
    border-radius: 0.75rem;
    background: color-mix(in srgb, var(--bg-tertiary) 92%, transparent);
    font-size: var(--text-md);
    cursor: pointer;
    transition: transform 0.12s ease, border-color 0.12s ease, background 0.12s ease;
}

.field-option-icon-choice:hover {
    transform: translateY(-1px);
    border-color: color-mix(in srgb, var(--primary) 45%, transparent);
    background: color-mix(in srgb, var(--primary-light) 72%, transparent);
}

.field-option-icon-clear {
    grid-column: 1 / -1;
    font-size: var(--text-xs);
    font-weight: 700;
    letter-spacing: 0.02em;
    color: var(--text-muted);
}

.field-option-color {
    width: 2.75rem;
    height: 2.5rem;
    padding: 0.2rem;
    border: 1px solid var(--border-color);
    border-radius: 0.7rem;
    background: transparent;
    cursor: pointer;
}

.field-option-add-btn,
.field-option-remove-btn {
    white-space: nowrap;
}

.multi-select-tag-group {
    display: flex;
    flex-wrap: wrap;
    gap: 0.35rem;
    align-items: flex-start;
    min-height: 2.25rem;
}

.multi-select-tag {
    display: inline-flex;
    align-items: center;
    gap: 0.3rem;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-full);
    background: var(--bg-app);
    color: var(--text-muted);
    padding: 0.22rem 0.62rem;
    font-size: var(--text-xs);
    font-weight: 600;
    line-height: 1.2;
    cursor: pointer;
    transition: transform 0.12s ease, border-color 0.12s ease, background 0.12s ease, color 0.12s ease, box-shadow 0.12s ease;
}

.multi-select-tag:hover {
    border-color: var(--primary);
    color: var(--primary);
    transform: translateY(-1px);
}

.multi-select-tag.selected {
    background: var(--primary-light);
    color: var(--primary-text);
    border-color: color-mix(in srgb, var(--primary) 65%, transparent);
    box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.12);
}

.multi-select-tag-empty {
    color: var(--text-muted);
    font-size: var(--text-xs);
    padding: 0.28rem 0;
}

.multi-select-picker-hint {
    color: var(--text-muted);
    font-size: var(--text-xs);
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    margin-left: auto;
    flex-shrink: 0;
}

.single-select-trigger {
    width: 100%;
    display: inline-flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.45rem;
    text-align: left;
    cursor: pointer;
}

.single-select-trigger-label {
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.single-select-placeholder {
    color: var(--text-muted);
}

.link-dropdown-create-item {
    border-top: 1px solid color-mix(in srgb, var(--border-color) 80%, transparent);
}

.record-link-create-panel {
    border-top: 1px solid var(--border-color);
    padding: 0.9rem 1rem 1rem;
    display: flex;
    flex-direction: column;
    gap: 0.65rem;
}

.record-link-create-header {
    font-size: var(--text-xs);
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: var(--text-muted);
}

.record-link-create-form {
    display: grid;
    grid-template-columns: minmax(0, 1fr) minmax(0, 1fr) auto;
    gap: 0.6rem;
    align-items: center;
}

.record-link-create-input {
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    background: var(--bg-tertiary);
    padding: 0.45rem 0.65rem;
}

.record-link-create-help {
    font-size: var(--text-xs);
    color: var(--text-muted);
}

.record-link-results {
    max-height: 320px;
    overflow-y: auto;
    padding: 0.4rem;
}

.record-link-empty {
    padding: 1.5rem;
    text-align: center;
    color: var(--text-muted);
    font-size: var(--text-base);
    font-style: italic;
}

.record-link-result {
    display: flex;
    align-items: center;
    gap: 0.6rem;
    padding: 0.55rem 0.75rem;
    border-radius: var(--radius-sm);
    cursor: pointer;
    transition: var(--transition);
}

.record-link-result:hover,
.record-link-result.highlighted {
    background: var(--primary-light);
}

.record-link-db-badge {
    font-size: var(--text-xs);
    font-weight: 600;
    color: var(--text-muted);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.record-link-title {
    font-size: var(--text-base);
    color: var(--text-main);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.record-link-copy {
    min-width: 0;
    display: flex;
    flex-direction: column;
    gap: 0.16rem;
}

/* ── Journal record chip (inline link) ──────────────────────────────── */
.journal-record-chip {
    display: inline-flex;
    align-items: center;
    gap: 0;
    border-radius: var(--radius-md);
    overflow: hidden;
    border: 1px solid var(--primary);
    font-size: var(--text-sm);
    line-height: 1;
    vertical-align: middle;
    cursor: pointer;
    user-select: none;
}

.journal-record-chip .chip-db {
    background: var(--primary);
    color: #fff;
    padding: 2px 7px;
    font-weight: 600;
    font-size: var(--text-xs);
}

.journal-record-chip .chip-title {
    background: var(--primary-light);
    color: var(--primary-text);
    padding: 2px 8px;
    font-weight: 500;
}

.journal-record-chip .chip-field {
    background: color-mix(in srgb, var(--primary-light) 65%, transparent);
    color: var(--text-main);
    padding: 2px 8px;
    border-left: 1px solid color-mix(in srgb, var(--primary) 25%, transparent);
    max-width: 220px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.journal-linked-record-storage {
    display: none !important;
}

/* TrackThatStuff compact dark workspace */
body {
    font-size: 14px;
}

aside {
    width: 276px;
    background: var(--bg-sidebar);
    transition: width 0.18s ease;
}

.sidebar-header {
    height: auto;
    min-height: 44px;
    padding: 0 10px;
    border-bottom: 1px solid var(--border-sidebar);
}

.theme-toggle {
    width: 30px;
    height: 30px;
    background: var(--warning);
    color: #fff;
    border: 1px solid #d77d43;
}

.sidebar-collapse-toggle {
    width: 30px;
    height: 30px;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    background: var(--bg-app);
    color: var(--text-sidebar);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
}

.sidebar-collapse-toggle:hover {
    background: var(--border-sidebar);
    color: #fff;
}

.sidebar-collapse-toggle svg {
    width: 16px;
    height: 16px;
}

.sidebar-scroll {
    padding: 0 10px 8px;
}

.primary-nav {
    display: grid;
    gap: 2px;
    margin-bottom: 18px;
}

.primary-nav-item {
    height: 28px;
    border: 0;
    border-radius: var(--radius-sm);
    background: transparent;
    color: var(--text-sidebar);
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 0 2px;
    font: 600 0.9rem/1 var(--font-body);
    cursor: pointer;
}

.primary-nav-item svg {
    width: 16px;
    height: 16px;
    color: #a7a7a7;
}

.primary-nav-item:hover {
    background: var(--bg-sidebar-hover);
    color: var(--text-sidebar-bright);
}

.primary-nav-item.active {
    background: var(--bg-sidebar-active);
    color: var(--text-sidebar-bright);
}

.primary-nav-item.active svg {
    color: var(--warning-text);
}

.mobile-journal-toggle,
.mobile-workspaces-toggle {
    display: none;
}

.sidebar-calendar-container {
    display: block;
    margin: 0 0 14px;
    padding: 10px;
    background: var(--bg-app);
    border: 1px solid var(--border-sidebar);
    border-radius: var(--radius-md);
}

.sidebar-calendar-container .sidebar-cal-header {
    margin-bottom: 7px;
}

.sidebar-calendar-container .sidebar-cal-title {
    font-family: var(--font-body);
    font-size: var(--text-xs);
    font-weight: 800;
}

.sidebar-calendar-container .sidebar-cal-grid {
    gap: 3px;
}

.sidebar-calendar-container .sidebar-cal-day-hdr {
    color: #777;
    font-size: 0.58rem;
    padding: 0 0 2px;
}

.sidebar-calendar-container .sidebar-cal-day {
    width: 24px;
    height: 24px;
    padding: 0;
    margin: auto;
    font-size: var(--text-xs);
    border-radius: var(--radius-sm);
}

.sidebar-calendar-container .sidebar-cal-day.active {
    background: #5b3018;
    color: var(--warning-text) !important;
}

.sidebar-calendar-container .sidebar-cal-day.today {
    box-shadow: inset 0 0 0 1px #94c973;
}

.menu-section {
    margin-bottom: 10px;
}

.menu-title {
    padding: 0 0 8px;
    color: var(--text-muted);
    font-family: var(--font-body);
    font-size: var(--text-xs);
    letter-spacing: 0.02em;
    text-transform: none;
}

.menu-item-wrapper {
    margin-bottom: 2px;
}

.menu-item,
.db-item {
    min-height: 28px;
    padding: 4px 8px;
    border-radius: var(--radius-sm);
    font-size: var(--text-base);
    font-weight: 600;
}

.menu-item.active,
.db-item.active {
    background: var(--bg-sidebar-active);
    box-shadow: none;
    color: #fff;
}

.db-list {
    padding-left: 18px;
    margin-top: 2px;
}

.db-list-collapsed {
    display: none;
}

.ws-collapse-btn {
    background: transparent;
    border: none;
    padding: 0;
    cursor: pointer;
    color: var(--text-muted);
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    line-height: 1;
    min-width: 24px;
    min-height: 24px;
    border-radius: var(--radius-sm);
}

.ws-collapse-btn:hover {
    background: var(--bg-sidebar-hover);
    color: var(--text-sidebar-bright);
}

.ws-chevron {
    width: 13px;
    height: 13px;
    flex-shrink: 0;
    transition: transform 0.15s ease;
    transform: rotate(0deg);
}

.ws-chevron-open {
    transform: rotate(90deg);
}

.db-item-icon,
.menu-item-icon {
    width: 15px;
    height: 15px;
}

.sidebar-footer {
    padding: 10px 14px;
    gap: 10px;
    border-top-color: #1d1d1d;
}

.help-link {
    border: 0;
    background: transparent;
    color: var(--text-sidebar-muted);
    display: inline-flex;
    align-items: center;
    gap: 7px;
    font: 700 0.88rem/1 var(--font-body);
    cursor: pointer;
    padding: 6px 0;
    min-height: 24px;
}

.help-link svg {
    width: 15px;
    height: 15px;
}

aside.collapsed {
    width: 58px;
}

aside.collapsed .sidebar-header {
    padding: 0 10px;
    justify-content: center;
}

aside.collapsed .logo span,
aside.collapsed .theme-toggle,
aside.collapsed .primary-nav-item span,
aside.collapsed .sidebar-calendar-container,
aside.collapsed .menu-section,
aside.collapsed .help-link span {
    display: none;
}

aside.collapsed .sidebar-header-actions {
    gap: 0;
}

aside.collapsed .sidebar-scroll {
    padding: 0 8px 8px;
}

aside.collapsed .primary-nav {
    margin-bottom: 0;
}

aside.collapsed .primary-nav-item {
    width: 42px;
    height: 36px;
    justify-content: center;
    padding: 0;
}

aside.collapsed .primary-nav-item svg {
    width: 18px;
    height: 18px;
}

aside.collapsed .sidebar-footer {
    padding: 10px 8px;
    align-items: center;
}

aside.collapsed .help-link {
    width: 42px;
    height: 36px;
    justify-content: center;
    padding: 0;
}

main {
    background: var(--bg-app);
    min-height: 0;
}

.app-topbar {
    height: 35px;
    background: var(--bg-sidebar);
    border-bottom: 1px solid var(--border-sidebar);
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 0 12px;
    flex-shrink: 0;
}

.app-nav-arrows,
.app-topbar-btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
}

.app-nav-arrows button,
.app-topbar-btn {
    width: 24px;
    height: 24px;
    border: 0;
    background: transparent;
    color: #b9b9b9;
    border-radius: var(--radius-sm);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
}

.app-nav-arrows button:hover,
.app-topbar-btn:hover {
    background: var(--border-sidebar);
}

.app-nav-arrows svg,
.app-topbar-btn svg {
    width: 15px;
    height: 15px;
}

.app-tabs {
    display: flex;
    align-items: center;
    gap: 6px;
    min-width: 0;
    flex: 1 1 auto;
    overflow-x: auto;
    scrollbar-width: none;
}

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

.app-tab {
    height: 30px;
    width: 190px;
    border: 1px solid #3a3a3a;
    border-radius: var(--radius-md);
    background: var(--bg-card);
    color: #bdbdbd;
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 0 6px 0 0;
    font-size: var(--text-sm);
    font-weight: 700;
    flex: 0 0 auto;
    position: relative;
    cursor: grab;
}

.app-tab.active {
    background: #2a2a2a;
    color: var(--text-main);
    border-color: #4a4a4a;
}

.app-tab.dragging {
    opacity: 0.5;
}

.app-tab.app-tab-drag-before::before,
.app-tab.app-tab-drag-after::after {
    content: "";
    position: absolute;
    top: 4px;
    bottom: 4px;
    width: 2px;
    border-radius: var(--radius-full);
    background: var(--primary);
}

.app-tab.app-tab-drag-before::before {
    left: -4px;
}

.app-tab.app-tab-drag-after::after {
    right: -4px;
}

.app-tab-main {
    flex: 1 1 auto;
    min-width: 0;
    height: 100%;
    border: 0;
    background: transparent;
    color: inherit;
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 0 4px 0 10px;
    cursor: pointer;
}

.app-tab span {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.app-tab-main svg {
    width: 15px;
    height: 15px;
    color: #4384e8;
}

.app-tab-close {
    width: 24px;
    height: 24px;
    border: 0;
    border-radius: var(--radius-sm);
    background: transparent;
    color: inherit;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    flex: 0 0 auto;
}

.app-tab-close:hover {
    background: rgba(255, 255, 255, 0.08);
    color: #fff;
}

.app-tab-close svg {
    width: 13px;
    height: 13px;
}

.app-tab-add-btn {
    flex: 0 0 auto;
    margin-left: 2px;
}

header {
    min-height: 69px;
    height: auto;
    padding: 10px 14px 8px;
    background: var(--bg-app);
    backdrop-filter: none;
}

.breadcrumbs {
    min-width: 230px;
    flex-direction: column;
    align-items: flex-start;
    gap: 8px;
    font-family: var(--font-body);
}

.breadcrumb-active {
    color: #fff;
    display: inline-flex;
    align-items: center;
    gap: 8px;
    font-size: var(--text-md);
    font-weight: 800;
}

.breadcrumb-active svg {
    color: currentColor;
}

.database-description {
    display: block;
    color: #767676;
    font-size: var(--text-xs);
    font-weight: 500;
}

.view-controls {
    gap: 12px;
    justify-content: flex-end;
    flex-wrap: wrap;
}

.view-tabs {
    background: transparent;
    border: 0;
    padding: 0;
    gap: 12px;
}

.view-tab {
    height: 24px;
    padding: 0;
    color: #bdbdbd;
    border-radius: var(--radius-sm);
    font-size: var(--text-xs);
}

.view-tab.active {
    background: var(--bg-subtle);
    color: #fff;
    padding: 0 7px;
}

.search-wrapper {
    width: 190px;
}

.search-input {
    height: 28px;
    border: 0;
    background: transparent;
    color: #d8d8d8;
    padding-left: 24px;
}

.search-input:focus {
    background: var(--bg-subtle);
    border-color: transparent;
    box-shadow: none;
}

.search-icon {
    left: 4px;
}

.toolbar-btn {
    border: 0;
    background: transparent;
    color: #bdbdbd;
    font: 600 0.75rem/1 var(--font-body);
    display: inline-flex;
    align-items: center;
    gap: 5px;
    height: 28px;
    padding: 0 4px;
    border-radius: var(--radius-sm);
    cursor: pointer;
}

.toolbar-btn:hover {
    background: var(--border-sidebar);
    color: #fff;
}

.toolbar-btn-accent {
    background: #4a2914;
    color: #f3b57e;
    padding: 0 9px;
}

/* ---------------------------------------------------------------------------
   Header toolbar grouping.

   Left-to-right: view tabs, search, data-shaping controls, then a pinned
   actions cluster. The data-shaping group is the only part allowed to scroll
   when space runs out, so the primary action and overflow menu are always
   reachable -- previously Filter and Sort simply fell off the right edge on
   narrow viewports with no way to scroll to them.
   --------------------------------------------------------------------------- */
.toolbar-group {
    display: flex;
    align-items: center;
    gap: 4px;
    min-width: 0;
}

.toolbar-actions {
    display: flex;
    align-items: center;
    gap: 8px;
    flex: 0 0 auto;
    margin-left: auto;
}

/* Square icon-only variant of the toolbar button. */
.toolbar-btn-icon {
    width: 28px;
    padding: 0;
    justify-content: center;
}

/* Consistent glyph sizing for toolbar and button icons, replacing the inline
   width/height that used to be repeated on every <i data-lucide>. */
.toolbar-btn svg,
.view-tab svg,
.btn svg {
    width: 14px;
    height: 14px;
    flex-shrink: 0;
}

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

.toolbar-menu {
    position: absolute;
    top: calc(100% + 6px);
    right: 0;
    z-index: 120;
    min-width: 208px;
    padding: 4px;
    display: flex;
    flex-direction: column;
    gap: 2px;
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-lg);
}

.toolbar-menu[hidden] {
    display: none;
}

.toolbar-menu-item {
    display: flex;
    align-items: center;
    gap: 9px;
    width: 100%;
    min-height: 32px;
    padding: 0 9px;
    border: 0;
    border-radius: var(--radius-sm);
    background: transparent;
    color: var(--text-main);
    font: 500 0.82rem/1 var(--font-body);
    text-align: left;
    cursor: pointer;
    transition: var(--transition);
}

.toolbar-menu-item[hidden] {
    display: none;
}

.toolbar-menu-item svg {
    width: 14px;
    height: 14px;
    flex-shrink: 0;
    color: var(--text-muted);
}

.toolbar-menu-item:hover {
    background: var(--bg-subtle);
}

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

.toolbar-menu-item--danger svg {
    color: var(--danger);
}

.toolbar-menu-item--danger:hover {
    background: rgba(239, 68, 68, 0.14);
}

.toolbar-menu-sep {
    height: 1px;
    margin: 4px 2px;
    background: var(--border-color);
}

.toolbar-menu-sep[hidden] {
    display: none;
}

.btn {
    border-radius: var(--radius-sm);
}

.btn-primary {
    background: #5b3018;
    color: var(--warning-text);
    border-color: #6e3a1c;
}

.btn-primary:hover {
    background: #6e3a1c;
    box-shadow: none;
}

.btn-secondary {
    background: var(--bg-subtle);
    color: #ddd;
    border-color: #3a3a3a;
}

.content-body {
    padding: 0;
    background: var(--bg-app);
    min-height: 0;
}

.grid-container {
    border-radius: 0;
    border-left: 0;
    border-right: 0;
    background: var(--bg-card);
    box-shadow: none;
    min-height: 0;
}

.table-responsive {
    /* Account for hub slim topbar + app topbar + header toolbar */
    min-height: calc(100dvh - var(--hub-topbar-height) - 160px);
    overflow: auto;
}

table {
    font-size: var(--text-base);
}

th {
    height: 36px;
    padding: 0 10px;
    background: var(--bg-card);
    color: var(--text-main);
    border-right: 1px solid var(--border-color);
    font-family: var(--font-body);
    font-weight: 800;
}

td {
    height: 36px;
    padding: 0 10px;
    border-right: 1px solid var(--border-sidebar);
    border-bottom: 1px solid var(--border-sidebar);
    max-width: 360px;
}

tbody tr:last-child td {
    border-bottom: 1px solid var(--border-sidebar);
}

.th-inner {
    min-height: 36px;
}

.th-title {
    display: flex;
    align-items: center;
    gap: 6px;
}

.th-subtext {
    display: block;
    font-size: var(--text-2xs);
    font-weight: 500;
    color: var(--text-sidebar-muted);
}

.col-icon {
    width: 13px;
    height: 13px;
    color: var(--text-muted);
}

.row-number-th,
.row-number-cell {
    color: #777;
    text-align: right;
    font-size: var(--text-xs);
}

.row-number-cell {
    display: table-cell;
    font-variant-numeric: tabular-nums;
}

.row-checkbox,
.row-check-placeholder {
    display: inline-flex;
    width: 14px;
    height: 14px;
    border: 1px solid #666;
    border-radius: var(--radius-sm);
    margin-right: 13px;
    vertical-align: -2px;
    align-items: center;
    justify-content: center;
    font-size: 11px;
    line-height: 1;
}

.row-checkbox {
    padding: 0;
    background: transparent;
    color: transparent;
    cursor: pointer;
    position: relative;
    transition: background 120ms ease, border-color 120ms ease, color 120ms ease;
}

/* The checkbox stays visually 14px, but an invisible overlay grows the hit
   area to the 24x24 minimum so it is comfortably tappable on touch. */
.row-checkbox::after {
    content: "";
    position: absolute;
    top: 50%;
    left: 50%;
    width: 24px;
    height: 24px;
    transform: translate(-50%, -50%);
}

.row-checkbox:hover {
    border-color: #8a8a8a;
}

.row-checkbox.checked {
    background: var(--primary);
    border-color: var(--primary);
    color: #fff;
}

.selected-row td {
    background: rgba(75, 145, 255, 0.12);
}

.clickable-row:hover td {
    background: var(--bg-subtle);
}

.selected-row:hover td {
    background: rgba(75, 145, 255, 0.18);
}

.td-input {
    min-height: 26px;
    padding: 2px 0;
    border-radius: var(--radius-sm);
    color: #e6e6e6;
    font-size: var(--text-base);
}

.td-input:focus {
    background: var(--bg-subtle);
    border-color: #4a4a4a;
    box-shadow: none;
    padding-inline: 6px;
}

td .relation-badge-container {
    flex-wrap: nowrap;
    gap: 4px;
    overflow: hidden;
}

.relation-badge,
.relation-badge-add {
    height: 27px;
    border: 1px solid #3c3c3c;
    border-radius: var(--radius-md);
    background: var(--bg-subtle);
    color: var(--text-main);
    font-size: var(--text-sm);
    padding: 0 8px;
    gap: 6px;
    max-width: 170px;
}

.relation-badge {
    min-width: 0;
}

.relation-badge-add {
    border-style: dashed;
    min-width: 26px;
    justify-content: center;
    flex-shrink: 0;
}

.relation-badge span {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.relation-badge svg:first-child {
    color: #8f71e8;
}

.relation-badge-remove {
    color: var(--text-muted);
}

.add-row-tr {
    background: var(--bg-card);
}

.add-row-btn {
    height: 36px;
    padding: 0 64px;
    color: #92d069;
    font-size: var(--text-base);
}

/* Deliberate green tint matching --accent-database; not a neutral surface. */
.add-row-btn:hover {
    color: color-mix(in srgb, var(--accent-database) 70%, #fff);
    background: color-mix(in srgb, var(--accent-database) 12%, var(--bg-app));
}

.add-field-btn {
    height: 36px;
    padding: 0 10px;
    color: #a8a8a8;
}

.add-field-btn:hover {
    background: var(--border-sidebar);
    color: #fff;
}

.drawer,
.modal,
.record-link-modal,
.link-dropdown-menu,
.slash-menu {
    background: var(--bg-card);
    border-color: var(--border-color);
    border-radius: var(--radius-md);
}

.drawer-header,
.modal-header,
.record-link-modal-header {
    border-color: var(--border-color);
}

.drawer-value-input,
.form-control,
.link-dropdown-search,
.rich-editor-textarea,
.rich-editor-preview,
.journal-wysiwyg-editor {
    background: var(--bg-subtle);
    border-color: #444;
    color: var(--text-main);
    border-radius: var(--radius-md);
}

.drawer-value-input:focus,
.form-control:focus {
    background: var(--bg-subtle);
    border-color: var(--primary);
    box-shadow: none;
}

.board-column,
.schema-container,
.calendar-view-container,
.journal-container {
    background: var(--bg-card);
    border-radius: var(--radius-md);
    box-shadow: none;
}

@media (max-width: 900px) {
    aside {
        width: 236px;
    }

    .app-tab {
        width: 150px;
    }

    header {
        align-items: flex-start;
        flex-direction: column;
    }

    .view-controls {
        width: 100%;
        justify-content: flex-start;
    }
}



/* Settings modal theme toggle pill */
.theme-toggle-pill {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 0.35rem 0.85rem;
    border-radius: 20px;
    border: 1px solid var(--border-color);
    background: var(--bg-subtle);
    color: var(--text-main);
    font-size: var(--text-sm);
    font-weight: 600;
    cursor: pointer;
    transition: var(--transition);
}

.theme-toggle-pill:hover {
    border-color: var(--primary);
    color: var(--primary);
}


/* ==========================================================================
   LIGHT THEME
   Matches the clean white Fibery/Notion-style palette: white surfaces,
   near-black text, subtle gray borders, teal logo + warm-orange accents.
   Redefines the design tokens AND overrides the hardcoded dark hex values
   used throughout the "compact workspace" section above.
   ========================================================================== */
[data-theme="light"] {
    --bg-app: #ffffff;
    --bg-sidebar: #fbfbfa;
    --bg-sidebar-hover: #efefee;
    --bg-sidebar-active: #fbeadd;
    --text-sidebar: #37352f;
    --text-sidebar-muted: #9b9a97;
    --text-sidebar-bright: #1a1a1a;
    --border-sidebar: #ececeb;

    --bg-card: #ffffff;
    --bg-subtle: #f7f7f5;
    --bg-header: #ffffff;
    --text-main: #37352f;
    --text-muted: #787774;
    --border-color: #e8e8e6;

    --primary: #2f80ed;
    --primary-hover: #1b6fd6;
    --primary-light: #e8f0fd;
    --primary-text: #1b4f9c;

    --success: #10b981;
    --success-hover: #059669;
    --success-light: #d1fae5;
    --success-text: #065f46;

    --warning: #bd6630;
    --warning-hover: #a85628;
    --warning-light: #fbeadd;
    --warning-text: #a85628;

    --danger: #ef4444;
    --danger-light: #fee2e2;
    --danger-text: #b91c1c;

    --accent-database: #4f9d69;
    --accent-dashboard: #bd6630;
    --accent-calendar: #d6477a;
    --accent-journal: #7c5cd6;
    --accent-view: #178ca1;

    --shadow-sm: 0 1px 2px rgb(0 0 0 / 0.04);
    --shadow-md: 0 2px 8px rgb(0 0 0 / 0.06);
    --shadow-lg: 0 8px 24px rgb(0 0 0 / 0.1);
    --shadow-xl: 0 18px 44px rgb(0 0 0 / 0.14);
    --ring: 0 0 0 2px rgb(47 128 237 / 0.22);
}

/* --- Sidebar --- */

[data-theme="light"] .sidebar-collapse-toggle {
    border: 1px solid #e3e3e1;
    color: #6b6b6b;
}

[data-theme="light"] .sidebar-collapse-toggle:hover {
    background: #f0f0ef;
    color: #1a1a1a;
}

[data-theme="light"] .sidebar-calendar-container {
    background: #f7f7f5;
    border: 1px solid #ececeb;
}

[data-theme="light"] .sidebar-calendar-container .sidebar-cal-day-hdr {
    color: #9b9a97;
}

[data-theme="light"] .sidebar-calendar-container .sidebar-cal-day.active {
    background: #fbe3d0;
    color: #a85628 !important;
}

[data-theme="light"] .sidebar-calendar-container .sidebar-cal-day.today {
    box-shadow: inset 0 0 0 1px #4f9d69;
}

[data-theme="light"] .menu-title {
    color: #9b9a97;
}

[data-theme="light"] .sidebar-footer {
    border-top-color: #ececeb;
}

[data-theme="light"] .help-link {
    color: #787774;
}

/* Active sidebar items use a hardcoded white text in the compact section,
   which is unreadable on the light peach active background. */
[data-theme="light"] .menu-item.active,
[data-theme="light"] .db-item.active {
    color: #a85628;
}

[data-theme="light"] .primary-nav-item.active {
    color: #a85628;
}


/* --- Top bar / tabs --- */
[data-theme="light"] .app-topbar {
    background: #f7f7f5;
    border-bottom: 1px solid #ececeb;
}

[data-theme="light"] .app-nav-arrows button,
[data-theme="light"] .app-topbar-btn {
    color: #6b6b6b;
}

[data-theme="light"] .app-nav-arrows button:hover,
[data-theme="light"] .app-topbar-btn:hover {
    background: #ececeb;
}

[data-theme="light"] .app-tab {
    border: 1px solid #e3e3e1;
    color: #6b6b6b;
}

[data-theme="light"] .app-tab.active {
    background: #ffffff;
    color: #1a1a1a;
    border-color: #d3d3d1;
}

[data-theme="light"] .app-tab-main svg {
    color: #2f80ed;
}

/* --- Header / view controls --- */

[data-theme="light"] .breadcrumb-active {
    color: #1a1a1a;
}

[data-theme="light"] .database-description {
    color: #9b9a97;
}

[data-theme="light"] .view-tab {
    color: #6b6b6b;
}

[data-theme="light"] .view-tab.active {
    background: #ececeb;
    color: #1a1a1a;
}

[data-theme="light"] .search-input {
    color: #37352f;
}


[data-theme="light"] .toolbar-btn {
    color: #6b6b6b;
}

[data-theme="light"] .toolbar-btn:hover {
    color: #1a1a1a;
}

[data-theme="light"] .toolbar-btn-accent {
    background: #fbeadd;
    color: #a85628;
}

/* --- Buttons --- */
[data-theme="light"] .btn-primary {
    background: #bd6630;
    color: #ffffff;
    border-color: #bd6630;
}

[data-theme="light"] .btn-primary:hover {
    background: #a85628;
    box-shadow: 0 2px 8px rgba(189, 102, 48, 0.28);
}

[data-theme="light"] .btn-secondary {
    background: #ffffff;
    color: #37352f;
    border-color: #e3e3e1;
}

[data-theme="light"] .btn-secondary:hover {
    border-color: #d3d3d1;
}

/* --- Content / table --- */


[data-theme="light"] th {
    background: #f7f7f5;
    border-right: 1px solid #ececeb;
}

[data-theme="light"] td {
    border-right: 1px solid #ececeb;
    border-bottom: 1px solid #ececeb;
}

[data-theme="light"] tbody tr:last-child td {
    border-bottom: 1px solid #ececeb;
}


[data-theme="light"] .col-icon {
    color: #9b9a97;
}

[data-theme="light"] .row-number-th,
[data-theme="light"] .row-number-cell {
    color: #9b9a97;
}

[data-theme="light"] .row-checkbox,
[data-theme="light"] .row-check-placeholder {
    border: 1px solid #c3c3c1;
}

[data-theme="light"] .row-checkbox:hover {
    border-color: #9b9a97;
}


[data-theme="light"] .td-input {
    color: #37352f;
}

[data-theme="light"] .td-input:focus {
    border-color: #d3d3d1;
}

[data-theme="light"] .relation-badge,
[data-theme="light"] .relation-badge-add {
    border: 1px solid #e3e3e1;
    background: #f7f7f5;
    color: #37352f;
}

[data-theme="light"] .relation-badge svg:first-child {
    color: #7c5cd6;
}

[data-theme="light"] .relation-badge-remove {
    color: #9b9a97;
}


[data-theme="light"] .add-row-btn {
    color: #4f9d69;
}

[data-theme="light"] .add-row-btn:hover {
    color: #3d8554;
    background: #f0f7ee;
}

[data-theme="light"] .add-field-btn {
    color: #787774;
}

[data-theme="light"] .add-field-btn:hover {
    color: #1a1a1a;
}

/* --- Drawers / modals / inputs --- */
[data-theme="light"] .drawer,
[data-theme="light"] .record-window,
[data-theme="light"] .modal,
[data-theme="light"] .record-link-modal,
[data-theme="light"] .link-dropdown-menu,
[data-theme="light"] .slash-menu {
    background: #ffffff;
    border-color: #e3e3e1;
}

[data-theme="light"] .drawer-header,
[data-theme="light"] .record-window .drawer-header,
[data-theme="light"] .modal-header,
[data-theme="light"] .record-link-modal-header {
    border-color: #ececeb;
}

[data-theme="light"] .modal-footer {
    background: #fbfbfa;
}

[data-theme="light"] .drawer-value-input,
[data-theme="light"] .form-control,
[data-theme="light"] .link-dropdown-search,
[data-theme="light"] .rich-editor-textarea,
[data-theme="light"] .rich-editor-preview,
[data-theme="light"] .journal-wysiwyg-editor {
    background: #ffffff;
    border-color: #e3e3e1;
    color: #37352f;
}

[data-theme="light"] .drawer-value-input:focus,
[data-theme="light"] .form-control:focus {
    background: #ffffff;
    border-color: #2f80ed;
}

[data-theme="light"] .board-column,
[data-theme="light"] .schema-container,
[data-theme="light"] .calendar-view-container,
[data-theme="light"] .workspace-view-gantt,
[data-theme="light"] .workspace-view-gantt-names,
[data-theme="light"] .workspace-view-card,
[data-theme="light"] .workspace-view-board-col,
[data-theme="light"] .workspace-view-list-row,
[data-theme="light"] .workspace-view-feed-item,
[data-theme="light"] .workspace-view-cal-day,
[data-theme="light"] .workspace-view-kpi,
[data-theme="light"] .workspace-view-table-wrap,
[data-theme="light"] .journal-container {
    background: #ffffff;
}

/* --- Global search palette (otherwise hardcoded dark) --- */

[data-theme="light"] .global-search-shell {
    border-color: #ececeb;
}

[data-theme="light"] .global-search-input-row {
    border-bottom: 1px solid #ececeb;
}

[data-theme="light"] .global-search-icon {
    color: #9b9a97;
}

[data-theme="light"] .global-search-input {
    color: #37352f;
}


[data-theme="light"] .global-search-filters {
    border-bottom: 1px solid #ececeb;
}

[data-theme="light"] .global-search-filter {
    color: #6b6b6b;
}

[data-theme="light"] .global-search-filter:hover,
[data-theme="light"] .global-search-filter.active {
    color: #1a1a1a;
}

[data-theme="light"] .global-search-section-title {
    color: #9b9a97;
}

[data-theme="light"] .global-search-result {
    color: #37352f;
}

[data-theme="light"] .global-search-result:hover,
[data-theme="light"] .global-search-result.active {
    background: #f0f0ef;
}

[data-theme="light"] .global-search-result-title {
    color: #1a1a1a;
}

[data-theme="light"] .global-search-result-subtitle {
    color: #9b9a97;
}

[data-theme="light"] .global-search-result-id {
    color: #6b6b6b;
    background: #ececeb;
}


/* ==========================================================================
   PHONE LAYOUT
   Keeps dense workspace tools usable on narrow screens without requiring JS.
   ========================================================================== */
@media (max-width: 640px) {
    html,
    body {
        width: 100%;
        height: 100%;
        min-width: 0;
    }

    body {
        flex-direction: column;
        height: 100dvh;
        max-height: 100dvh;
        overflow: hidden;
        font-size: 13px;
    }

    trackthat-topbar,
    #hub-topbar {
        flex: 0 0 auto;
    }

    /* Shell is row on desktop; stack sidebar above main on phones */
    .app-shell {
        flex-direction: column;
        flex: 1 1 auto;
        min-height: 0;
        overflow: hidden;
    }

    aside,
    aside.collapsed {
        width: 100% !important;
        height: auto;
        max-height: min(276px, 36dvh);
        min-height: 0;
        border-right: 0;
        border-bottom: 1px solid var(--border-sidebar);
        flex: 0 0 auto;
        align-self: stretch;
    }

    body aside.collapsed {
        width: 100% !important;
        max-height: min(276px, 36dvh);
    }

    main {
        flex: 1 1 auto;
        min-height: 0;
        width: 100%;
    }

    .sidebar-header,
    aside.collapsed .sidebar-header {
        height: 44px;
        min-height: 44px;
        padding: 0 10px;
        justify-content: flex-start;
    }

    .logo {
        min-width: 0;
        letter-spacing: 0;
    }

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

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

    .sidebar-scroll,
    aside.collapsed .sidebar-scroll {
        display: flex;
        flex-direction: column;
        align-items: flex-start;
        gap: 8px;
        padding: 8px 10px 10px;
        overflow-x: hidden;
        overflow-y: auto;
        scrollbar-width: thin;
    }

    body aside.collapsed .sidebar-scroll {
        display: flex !important;
        flex-direction: column !important;
        align-items: stretch;
        overflow-x: hidden;
        overflow-y: auto;
    }

    .primary-nav,
    aside.collapsed .primary-nav {
        display: grid;
        grid-template-columns: 0.78fr 0.92fr 0.92fr 1.38fr;
        gap: 5px;
        margin: 0;
        width: 100%;
        flex: 0 0 auto;
    }

    body aside.collapsed .primary-nav {
        display: grid !important;
        width: 100%;
    }

    .primary-nav-item,
    aside.collapsed .primary-nav-item {
        width: 100%;
        min-width: 0;
        height: 36px;
        justify-content: center;
        padding: 0 4px;
        gap: 4px;
        flex: 1 1 auto;
        font-size: var(--text-xs);
    }

    .mobile-journal-toggle,
    .mobile-workspaces-toggle {
        display: flex;
    }

    .primary-nav-item span {
        min-width: 0;
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
    }

    aside.collapsed .primary-nav-item span,
    aside.collapsed .logo span,
    aside.collapsed .menu-section,
    aside.collapsed .help-link span {
        display: inline;
    }

    .sidebar-calendar-container,
    aside.collapsed .sidebar-calendar-container {
        display: none;
    }

    .menu-section,
    aside.collapsed .menu-section {
        display: none;
        width: 100%;
        flex: 0 0 auto;
        margin: 0;
        border-top: 1px solid color-mix(in srgb, var(--border-sidebar) 76%, transparent);
        padding-top: 8px;
    }

    body aside.collapsed .menu-section {
        display: none !important;
        width: 100%;
    }

    #app-sidebar.mobile-workspaces-open .menu-section,
    body #app-sidebar.collapsed.mobile-workspaces-open .menu-section {
        display: block !important;
    }

    #app-sidebar.mobile-workspaces-open .mobile-workspaces-toggle {
        background: var(--bg-sidebar-active);
        color: var(--text-sidebar-bright);
    }

    #app-sidebar.mobile-workspaces-open .mobile-workspaces-toggle svg {
        color: var(--warning-text);
    }

    .menu-title {
        min-height: 30px;
        padding: 0 2px 6px;
    }

    .menu-list {
        max-height: 126px;
        overflow-y: auto;
        padding-right: 2px;
    }

    .menu-item-wrapper {
        margin-bottom: 3px;
    }

    .menu-item,
    .db-item {
        min-height: 34px;
        padding: 6px 8px;
    }

    .menu-item-content,
    .db-item-label {
        min-width: 0;
    }

    .sidebar-drag-handle {
        display: none;
    }

    .menu-item .add-btn-icon,
    .row-action-btn {
        opacity: 0.65;
    }

    .db-list {
        padding-left: 18px;
    }

    .sidebar-footer,
    aside.collapsed .sidebar-footer {
        display: none;
    }

    main {
        min-width: 0;
        min-height: 0;
        height: auto;
        flex: 1 1 auto;
    }

    .app-topbar {
        height: 40px;
        gap: 8px;
        padding: 0 8px;
    }

    .app-nav-arrows {
        display: none;
    }

    .app-tab {
        width: 132px;
        height: 30px;
        font-size: var(--text-xs);
    }

    .app-tab-main {
        padding-left: 8px;
        gap: 6px;
    }

    header {
        min-height: 0;
        padding: 8px 10px;
        gap: 8px;
        flex-direction: column;
        align-items: stretch;
    }

    .breadcrumbs {
        min-width: 0;
        width: 100%;
        gap: 4px;
    }

    .breadcrumb-active {
        max-width: 100%;
        font-size: var(--text-base);
    }

    .breadcrumb-active span,
    .database-description {
        max-width: 100%;
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
    }

    /* Two rows on mobile. The view switcher, search and the actions cluster stay
       on the first row so the primary action and overflow menu are always
       visible; only the data-shaping controls scroll. Previously the whole
       toolbar was one horizontal scroller, so Filter and Sort sat off-screen
       behind a scrollbar most people never noticed. */
    .view-controls {
        width: 100%;
        min-width: 0;
        display: grid;
        grid-template-columns: auto minmax(0, 1fr) auto;
        grid-template-areas:
            "tabs search actions"
            "data data data";
        align-items: center;
        gap: 8px;
        overflow: visible;
        padding-bottom: 2px;
    }

    .view-tabs {
        grid-area: tabs;
        flex: 0 0 auto;
        gap: 4px;
    }

    .toolbar-group {
        grid-area: data;
        overflow-x: auto;
        overflow-y: hidden;
        scrollbar-width: none;
        gap: 6px;
    }

    .toolbar-group::-webkit-scrollbar {
        display: none;
    }

    .toolbar-group > .toolbar-btn {
        flex: 0 0 auto;
    }

    .toolbar-actions {
        grid-area: actions;
        margin-left: 0;
        gap: 6px;
    }

    .view-tab {
        width: 34px;
        min-width: 34px;
        height: 34px;
        justify-content: center;
        padding: 0;
        font-size: 0;
        gap: 0;
    }

    .view-tab.active {
        padding: 0;
    }

    .view-tab svg {
        width: 16px !important;
        height: 16px !important;
    }

    .search-wrapper {
        grid-area: search;
        width: auto;
        min-width: 0;
    }

    .search-input {
        height: 34px;
        font-size: var(--text-sm);
    }

    .toolbar-btn,
    .btn-sm {
        min-width: 34px;
        height: 34px;
        justify-content: center;
    }

    .toolbar-btn {
        padding: 0 8px;
        font-size: 0;
        gap: 0;
    }

    .toolbar-btn svg,
    .btn-sm svg {
        width: 16px !important;
        height: 16px !important;
    }

    .toolbar-badge {
        margin-left: 4px;
        font-size: 0.62rem;
    }

    #header-primary-label {
        display: none;
    }

    .content-body {
        min-height: 0;
        padding: 0;
        overflow: auto;
        -webkit-overflow-scrolling: touch;
    }

    .empty-state {
        min-height: 100%;
        height: auto;
        padding: 28px 18px;
    }

    .empty-icon {
        margin-bottom: 0.75rem;
    }

    .empty-state h3 {
        font-size: var(--text-xl);
    }

    .empty-state p {
        max-width: 28rem;
        font-size: var(--text-base);
        line-height: 1.45;
    }

    .global-search-shell {
        min-height: 100%;
        border-radius: 0;
        border-left: 0;
        border-right: 0;
    }

    .global-search-input-row {
        height: 46px;
        padding: 0 12px;
    }

    .global-search-filters {
        height: auto;
        gap: 8px;
        padding: 8px 12px;
        overflow-x: auto;
        scrollbar-width: none;
    }

    .global-search-filter {
        min-height: 32px;
        flex: 0 0 auto;
    }

    .global-search-section-title {
        padding: 14px 14px 8px;
    }

    .global-search-results {
        padding: 2px 8px 14px;
    }

    .global-search-result {
        grid-template-columns: 20px minmax(0, 1fr);
        min-height: 54px;
        padding: 8px;
    }

    .global-search-result-id {
        display: none;
    }

    .grid-container {
        min-width: 0;
        border-left: 0;
        border-right: 0;
    }

    .grid-toolbar {
        align-items: stretch;
        flex-direction: column;
        gap: 8px;
        padding: 10px;
    }

    .table-responsive {
        min-height: 100%;
        overflow: auto;
        -webkit-overflow-scrolling: touch;
    }

    table {
        min-width: 720px;
        font-size: var(--text-sm);
    }

    th,
    td {
        height: 38px;
        padding: 0 8px;
    }

    td {
        max-width: 220px;
    }

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

    .board-container {
        gap: 10px;
        min-height: 100%;
        padding: 10px;
        scroll-snap-type: x proximity;
    }

    .board-column {
        width: min(86vw, 300px);
        scroll-snap-align: start;
    }

    .board-column-header,
    .board-column-body,
    .board-card {
        padding: 0.8rem;
    }

    .schema-container {
        min-height: 100%;
        padding: 12px;
        border-left: 0;
        border-right: 0;
        border-radius: 0;
    }

    .schema-canvas {
        min-width: 620px;
    }

    .calendar-view-container {
        min-height: 100%;
        padding: 12px;
        gap: 12px;
        border-left: 0;
        border-right: 0;
        border-radius: 0;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
    }

    .calendar-top-controls {
        align-items: stretch;
        flex-direction: column;
        gap: 10px;
    }

    .calendar-month-nav {
        justify-content: space-between;
        gap: 8px;
    }

    .calendar-month-nav h2 {
        min-width: 0;
        flex: 1 1 auto;
        font-size: var(--text-md);
    }

    .calendar-meta-info {
        width: 100%;
        min-width: 0;
    }

    .calendar-meta-info span {
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
    }

    .calendar-filter-bar {
        min-width: 620px;
    }

    .calendar-filter-bar .filter-row {
        align-items: stretch !important;
        flex-direction: column;
    }

    .calendar-grid-header,
    .calendar-grid-body {
        min-width: 620px;
    }

    .calendar-grid-body {
        grid-auto-rows: minmax(82px, 1fr);
    }

    .calendar-day-cell {
        min-height: 82px;
        padding: 1.5rem 0.35rem 0.35rem;
    }

    .calendar-record-badge {
        font-size: var(--text-2xs);
        padding: 0.15rem 0.3rem;
    }

    .widget-grid {
        gap: 10px;
        margin-top: 0;
        padding: 10px;
    }

    .widget-card {
        padding: 1rem;
    }

    .widget-card.widget-expanded {
        padding: 0;
    }

    .widget-title {
        min-width: 0;
        font-size: var(--text-md);
    }

    .widget-title span {
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
    }

    .widget-metric-value {
        font-size: 2.25rem;
    }

    .journal-container {
        min-height: 100%;
        height: auto;
        padding: 14px;
        border-left: 0;
        border-right: 0;
        border-radius: 0;
    }

    .journal-header,
    .journal-linked-records-header {
        align-items: flex-start;
        flex-direction: column;
        gap: 10px;
    }

    .journal-header-actions {
        width: 100%;
        justify-content: space-between;
    }

    .journal-title-wrapper h2 {
        font-size: var(--text-xl);
    }

    .journal-mobile-date-nav {
        display: flex;
        flex-wrap: nowrap;
    }

    .journal-mobile-date-picker {
        flex: 1;
    }

    .journal-linked-records-panel {
        padding: 0.8rem;
    }

    .journal-linked-record-list {
        grid-template-columns: 1fr;
    }

    .journal-wysiwyg-toolbar {
        flex-wrap: nowrap;
        overflow-x: auto;
        padding: 6px;
        scrollbar-width: thin;
    }

    .rich-toolbar-btn {
        flex: 0 0 32px;
        width: 32px;
        height: 32px;
    }

    .journal-toolbar-sep {
        flex: 0 0 1px;
    }

    .journal-wysiwyg-editor {
        min-height: 45dvh;
        font-size: var(--text-base);
        line-height: 1.55;
        padding: 0.85rem;
    }

    .toolbar-panel {
        left: 10px !important;
        right: 10px;
        top: auto !important;
        bottom: 10px;
        width: auto !important;
        min-width: 0;
        max-width: none;
        max-height: min(72dvh, 520px);
    }

    .toolbar-panel-body {
        max-height: 46dvh;
    }

    .toolbar-panel-footer {
        flex-wrap: wrap;
    }

    .toolbar-panel-row,
    .filter-row {
        flex-wrap: wrap;
    }

    .drawer {
        right: -100vw;
        width: 100vw;
        max-width: 100vw;
        border-left: 0;
    }

    .drawer-header,
    .drawer-body,
    .modal-header,
    .modal-body,
    .modal-footer {
        padding-left: 1rem;
        padding-right: 1rem;
    }

    .drawer-body {
        gap: 1rem;
    }

    .modal-overlay {
        align-items: flex-end;
        padding: 10px;
    }

    .modal {
        max-height: calc(100dvh - 20px);
        border-radius: 12px 12px 0 0;
        transform: translateY(16px);
        display: flex;
        flex-direction: column;
    }

    .modal-overlay.open .modal {
        transform: translateY(0);
    }

    .modal-body {
        overflow-y: auto;
    }

    .modal-footer {
        flex-wrap: wrap;
    }

    .modal-footer .btn {
        flex: 1 1 130px;
    }

    .record-window-overlay {
        padding: 0;
        align-items: flex-end;
    }

    .record-window {
        max-height: 92dvh;
        border-radius: 16px 16px 0 0;
        border-left: 0;
        border-right: 0;
    }

    .record-window-footer {
        align-items: stretch;
        flex-direction: column;
    }

    .record-window-footer .btn {
        width: 100%;
    }

    .record-link-modal {
        top: auto;
        bottom: 0;
        width: 100vw;
        max-height: 88dvh;
        border-radius: 14px 14px 0 0;
        border-left: 0;
        border-right: 0;
    }

    .record-link-search-controls,
    .record-link-filter-panel {
        grid-template-columns: 1fr;
    }

    .record-link-create-form {
        align-items: stretch;
        flex-direction: column;
        display: flex;
    }

    .record-link-results {
        max-height: 44dvh;
    }

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

    .field-option-color,
    .field-option-icon-picker {
        grid-column: span 1;
    }

    .field-option-row .form-control {
        grid-column: 1 / -1;
    }

    .link-dropdown-menu,
    .slash-menu {
        width: min(92vw, 320px);
    }
}

/* Fix record link dropdown menu readability in dark mode */
.record-link-select {
    background-color: var(--bg-subtle) !important;
}
.record-link-select option {
    background-color: var(--bg-card) !important;
    color: var(--text-main) !important;
}

