/* Workspace rework styles: palette, context menus, relationships, chips,
   overview page, density modes. Loaded after editor.css; builds exclusively
   on its tokens. */

/* [hidden] must always win: several components below set an explicit
   display, which would otherwise override the UA's hidden rule — the exact
   bug that kept the palette on screen after closing. */
[hidden] { display: none !important; }

/* Screen-reader-only text (the shell's h1 lives off-screen: the explorer is
   an app surface with no visible page title). */
.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: -1px;
  padding: 0;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
  border: 0;
}

/* --- Density ------------------------------------------------------------ */

[data-density="compact"] .member-row { padding-top: 0.28rem; padding-bottom: 0.28rem; }
[data-density="compact"] .member-row .member-identity strong { font-size: 0.78rem; }
[data-density="compact"] .symbol-item { padding-top: 0.3rem; padding-bottom: 0.3rem; }
[data-density="compact"] .argument-row { padding-top: 0.2rem; padding-bottom: 0.2rem; }

/* --- Toast -------------------------------------------------------------- */

.dump-toast {
    position: fixed;
    bottom: 3.4rem;
    left: 50%;
    transform: translate(-50%, 8px);
    z-index: 90;
    padding: 0.45rem 0.9rem;
    border: 1px solid var(--border-default);
    border-radius: 8px;
    background: var(--surface-raised);
    color: var(--text-primary);
    font-size: 0.8rem;
    opacity: 0;
    pointer-events: none;
    transition: opacity 120ms ease, transform 120ms ease;
}

.dump-toast.visible { opacity: 1; transform: translate(-50%, 0); }

/* --- Sidebar sections (favorites / recent) ------------------------------ */

.list-section { display: contents; }

.list-section-head {
    position: sticky;
    top: 0;
    z-index: 2;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0.4rem 0.9rem 0.3rem;
    background: var(--surface-panel);
    color: var(--text-muted);
    font-size: 0.68rem;
    font-weight: 600;
    letter-spacing: 0.09em;
    text-transform: uppercase;
}

.fav-mark {
    margin-left: 0.35rem;
    color: var(--accent);
    font-size: 0.7rem;
}

.symbol-item mark, .palette-row mark {
    background: none;
    color: var(--accent-hover);
    font-weight: 700;
}

.bp-icon { color: #c9a86a; }
.struct-icon { color: #7ea6d9; }

/* --- Header: favorite + copy menu --------------------------------------- */

.favorite-toggle.active span { color: var(--accent); }

.copy-wrap { position: relative; }

.copy-menu, .type-filter-menu {
    position: absolute;
    top: calc(100% + 6px);
    right: 0;
    z-index: 40;
    min-width: 200px;
    padding: 0.3rem;
    border: 1px solid var(--border-default);
    border-radius: 10px;
    background: var(--surface-raised);
    box-shadow: 0 18px 40px rgba(0, 0, 0, 0.45);
}

.copy-menu button {
    display: block;
    width: 100%;
    padding: 0.42rem 0.6rem;
    border: 0;
    border-radius: 6px;
    background: none;
    color: var(--text-primary);
    font-size: 0.8rem;
    text-align: left;
    cursor: pointer;
}

.copy-menu button:hover, .copy-menu button:focus-visible { background: var(--surface-hover); }

.header-counts { color: var(--text-muted); font-size: 0.78rem; }

.inheritance .chain-sep { color: var(--text-disabled); }

.unresolved-type {
    color: var(--text-secondary);
    border-bottom: 1px dotted var(--text-disabled);
    cursor: help;
}

.crumb-link {
    border: 0;
    padding: 0;
    background: none;
    color: inherit;
    font: inherit;
    cursor: pointer;
}

.crumb-link:hover { color: var(--text-primary); text-decoration: underline; }

.fn-signature {
    display: block;
    color: var(--text-muted);
    font-family: var(--font-mono, ui-monospace, monospace);
    font-size: 0.72rem;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

/* --- Type filter + chips ------------------------------------------------- */

.type-filter-wrap { position: relative; }

.type-filter-menu {
    left: 0;
    right: auto;
    max-height: 300px;
    overflow: auto;
    min-width: 230px;
}

.type-filter-menu label {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.32rem 0.5rem;
    border-radius: 6px;
    font-size: 0.78rem;
    cursor: pointer;
}

.type-filter-menu label:hover { background: var(--surface-hover); }
.type-filter-menu label small { margin-left: auto; color: var(--text-muted); }

.filter-chips {
    display: flex;
    flex-wrap: wrap;
    gap: 0.35rem;
    width: 100%;
    padding-top: 0.4rem;
}

.filter-chip {
    display: inline-flex;
    align-items: center;
    gap: 0.35rem;
    padding: 0.18rem 0.55rem;
    border: 1px solid var(--border-default);
    border-radius: 999px;
    background: var(--surface-raised);
    color: var(--text-secondary);
    font-size: 0.72rem;
    cursor: pointer;
}

.filter-chip:hover { border-color: var(--border-strong); color: var(--text-primary); }
.filter-chip.clear-chip { border-style: dashed; color: var(--text-muted); }

/* --- Outline panel: search + relationship groups ------------------------ */

.member-outline { display: flex; flex-direction: column; min-height: 0; }

.outline-search { margin: 0.5rem 0.6rem 0.35rem; }

.outline-scroll { overflow: auto; min-height: 0; flex: 1; padding-bottom: 0.75rem; }

.relation-group {
    margin: 0.5rem 0.6rem 0;
    border: 1px solid var(--border-subtle);
    border-radius: 8px;
    background: var(--surface-panel);
}

.relation-group summary {
    padding: 0.45rem 0.65rem;
    color: var(--text-secondary);
    font-size: 0.74rem;
    font-weight: 600;
    letter-spacing: 0.07em;
    text-transform: uppercase;
    cursor: pointer;
    user-select: none;
}

.relation-group[open] summary { border-bottom: 1px solid var(--border-subtle); }

.relation-body { padding: 0.35rem; }

.relation-heading {
    padding: 0.4rem 0.4rem 0.2rem;
    color: var(--text-muted);
    font-size: 0.7rem;
    font-weight: 600;
    letter-spacing: 0.08em;
    text-transform: uppercase;
}

.relation-list { display: flex; flex-direction: column; }

.relation-row {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.32rem 0.45rem;
    border-radius: 6px;
    color: var(--text-primary);
    font-size: 0.78rem;
    text-decoration: none;
    min-width: 0;
}

.relation-row span:nth-child(2) {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.relation-row small { margin-left: auto; color: var(--text-muted); font-size: 0.7rem; white-space: nowrap; }
.relation-row:hover { background: var(--surface-hover); }
.relation-row.is-static { color: var(--text-secondary); }

.relation-glyph { color: var(--accent); font-size: 0.72rem; width: 0.9rem; text-align: center; }

.relation-empty, .relation-more {
    display: block;
    padding: 0.4rem 0.5rem;
    color: var(--text-muted);
    font-size: 0.75rem;
}

/* --- Context menu -------------------------------------------------------- */

.context-menu {
    position: fixed;
    z-index: 95;
    min-width: 220px;
    padding: 0.3rem;
    border: 1px solid var(--border-default);
    border-radius: 10px;
    background: var(--surface-raised);
    box-shadow: 0 18px 40px rgba(0, 0, 0, 0.5);
}

.context-menu button {
    display: block;
    width: 100%;
    padding: 0.42rem 0.6rem;
    border: 0;
    border-radius: 6px;
    background: none;
    color: var(--text-primary);
    font-size: 0.8rem;
    text-align: left;
    cursor: pointer;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.context-menu button:hover, .context-menu button:focus-visible { background: var(--surface-hover); outline: none; }

.context-menu hr {
    margin: 0.3rem 0.4rem;
    border: 0;
    border-top: 1px solid var(--border-subtle);
}

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

.palette-backdrop {
    position: fixed;
    inset: 0;
    z-index: 80;
    display: flex;
    justify-content: center;
    align-items: flex-start;
    padding: 12vh 1rem 2rem;
    background: rgba(5, 5, 9, 0.6);
}

.palette {
    width: min(640px, 100%);
    max-height: 70vh;
    display: flex;
    flex-direction: column;
    border: 1px solid var(--border-default);
    border-radius: 14px;
    background: var(--surface-panel);
    box-shadow: 0 30px 90px rgba(0, 0, 0, 0.6);
    overflow: hidden;
}

.palette-input { margin: 0.65rem 0.65rem 0.25rem; }

.palette-hint {
    padding: 0 1rem 0.5rem;
    color: var(--text-muted);
    font-size: 0.72rem;
}

.palette-hint code {
    padding: 0.05rem 0.3rem;
    border: 1px solid var(--border-subtle);
    border-radius: 5px;
    background: var(--surface-raised);
    font-size: 0.7rem;
}

.palette-results { overflow: auto; padding: 0.25rem 0.4rem 0.5rem; }

.palette-section {
    padding: 0.5rem 0.6rem 0.25rem;
    color: var(--text-muted);
    font-size: 0.68rem;
    font-weight: 600;
    letter-spacing: 0.09em;
    text-transform: uppercase;
}

.palette-row {
    display: flex;
    align-items: center;
    gap: 0.65rem;
    width: 100%;
    padding: 0.45rem 0.6rem;
    border: 0;
    border-radius: 8px;
    background: none;
    color: var(--text-primary);
    text-align: left;
    cursor: pointer;
}

.palette-row.active { background: var(--surface-hover); }

.palette-copy { min-width: 0; display: flex; flex-direction: column; }

.palette-copy strong { font-size: 0.84rem; font-weight: 600; }
.palette-copy small {
    color: var(--text-muted);
    font-size: 0.7rem;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.palette-sep { color: var(--text-disabled); }

.palette-meta { margin-left: auto; color: var(--text-muted); font-size: 0.72rem; white-space: nowrap; }

.palette-note {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.7rem 0.8rem;
    color: var(--text-muted);
    font-size: 0.78rem;
}

.member-glyph { color: var(--accent); }

/* --- Overview page -------------------------------------------------------- */

.overview {
    max-width: 1250px;
    margin: 0 auto;
    padding: clamp(1.5rem, 4vw, 3rem);
    overflow: auto;
    height: 100%;
}

.overview-head h1 { margin: 0 0 0.35rem; font-size: 1.6rem; }
.overview-head p { margin: 0; color: var(--text-secondary); font-size: 0.9rem; }
.overview-head kbd {
    padding: 0.1rem 0.4rem;
    border: 1px solid var(--border-default);
    border-radius: 5px;
    background: var(--surface-raised);
    font-size: 0.75rem;
}

.overview-stats {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(130px, 1fr));
    gap: 0.7rem;
    margin: 1.5rem 0;
}

.overview-stat {
    display: flex;
    flex-direction: column;
    gap: 0.1rem;
    padding: 0.85rem 1rem;
    border: 1px solid var(--border-subtle);
    border-radius: 10px;
    background: var(--surface-panel);
    color: var(--text-primary);
    text-align: left;
    cursor: pointer;
}

.overview-stat:hover { border-color: var(--border-strong); background: var(--surface-hover); }
.overview-stat strong { font-size: 1.25rem; font-variant-numeric: tabular-nums; }
.overview-stat span { color: var(--text-muted); font-size: 0.73rem; text-transform: uppercase; letter-spacing: 0.07em; }

.overview-meta {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
    gap: 0.4rem 1.5rem;
    margin: 0 0 1.5rem;
}

.overview-meta > div { display: flex; justify-content: space-between; gap: 1rem; font-size: 0.82rem; }
.overview-meta dt { color: var(--text-muted); }
.overview-meta dd { margin: 0; color: var(--text-secondary); font-family: var(--font-mono, ui-monospace, monospace); font-size: 0.78rem; text-align: right; overflow: hidden; text-overflow: ellipsis; }

.overview-section h2 {
    margin: 1.25rem 0 0.5rem;
    color: var(--text-muted);
    font-size: 0.72rem;
    font-weight: 600;
    letter-spacing: 0.09em;
    text-transform: uppercase;
}

.overview-symbols { display: flex; flex-wrap: wrap; gap: 0.45rem; }

.overview-symbol {
    display: inline-flex;
    align-items: center;
    gap: 0.45rem;
    padding: 0.32rem 0.7rem;
    border: 1px solid var(--border-subtle);
    border-radius: 999px;
    background: var(--surface-panel);
    color: var(--text-primary);
    font-size: 0.8rem;
    text-decoration: none;
}

.overview-symbol:hover { border-color: var(--border-strong); background: var(--surface-hover); }

.overview-hint { margin-top: 2rem; color: var(--text-muted); font-size: 0.75rem; }
.overview-hint code {
    padding: 0.05rem 0.3rem;
    border: 1px solid var(--border-subtle);
    border-radius: 5px;
    background: var(--surface-raised);
    font-size: 0.7rem;
}

/* --- Motion restraint ----------------------------------------------------- */

@media (prefers-reduced-motion: reduce) {
    .dump-toast { transition: none; }
}

.palette-close {
    border: 0;
    padding: 0;
    background: none;
    cursor: pointer;
}

.palette-close kbd {
    padding: 0.15rem 0.45rem;
    border: 1px solid var(--border-default);
    border-radius: 5px;
    background: var(--surface-raised);
    color: var(--text-muted);
    font-size: 0.7rem;
}

.palette-close:hover kbd, .palette-close:focus-visible kbd {
    color: var(--text-primary);
    border-color: var(--border-strong);
}

/* --- Layout corrections over editor.css (loads later, wins the cascade) --- */

/* Toolbar: one coherent wrapping row. The old sheet's responsive rules gave
   the search a full-width basis and pushed every extra control onto its own
   line once the new buttons joined; this pins a consistent flow instead. */

.editor-tools {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 8px;
    row-gap: 6px;
}

.editor-tools .member-search {
    flex: 1 1 200px;
    max-width: 320px;
    order: 0;
}

.editor-tools .outline-toggle,
.editor-tools .member-tabs,
.editor-tools .member-count {
    order: 0;
}

.editor-tools .segmented-control,
.editor-tools .segmented-control button {
    min-height: 36px;
    box-sizing: border-box;
}

.editor-tools .segmented-control button {
    padding-top: 4px;
    padding-bottom: 4px;
}

.editor-tools .toolbar-button {
    min-height: 36px;
}

@media (max-width: 1100px) {
    .editor-tools .member-search {
        flex-basis: 100%;
        max-width: none;
    }
}

/* Argument rows: a stable five-column grid; the old sheet's narrow-viewport
   overrides collapsed it to a single column with the new markup. */

.function-body .argument-row {
    display: grid;
    grid-template-columns: minmax(110px, 0.9fr) minmax(120px, 1.1fr) 70px minmax(100px, auto) minmax(60px, auto);
    align-items: center;
    gap: 10px;
}

@media (max-width: 1400px) {
    .function-body .argument-row {
        grid-template-columns: minmax(100px, 0.9fr) minmax(110px, 1.1fr) 65px minmax(90px, auto);
    }

    .function-body .argument-technical {
        display: none;
    }
}

@media (max-width: 900px) {
    .function-body .argument-row {
        grid-template-columns: minmax(90px, 0.9fr) minmax(100px, 1.1fr) 58px;
    }

    .function-body .argument-row > .property-badge {
        display: none;
    }
}

/* Header meta strip: clear rhythm between badge, chain and counts. */

.header-metadata {
    gap: 8px 14px;
}

.inheritance {
    display: inline-flex;
    align-items: baseline;
    flex-wrap: wrap;
    gap: 0 6px;
    color: var(--text-secondary);
    font-size: 0.8rem;
}

.inheritance .chain-sep {
    padding: 0 1px;
}

/* The field-row grid places .property-badge via a named area; inside the
   argument grid that name does not exist, so the browser invented implicit
   tracks and pushed the badge onto its own line. Reset it here. */
.function-body .argument-row > .property-badge {
    grid-area: auto;
    justify-self: start;
}

/* --- Wide-screen column discipline -------------------------------------- */

/* editor.css sizes the name and type columns in fr units, so on a wide
   monitor a 20-character field name gets a 500px column and the type sits
   hundreds of pixels away from it. Cap both, and give the slack its own
   track so the offset/badge/size cluster stays right-aligned and vertically
   scannable. Only the wide layout is touched; the narrower breakpoints in
   editor.css have no surplus space to mismanage. */

@media (min-width: 1281px) {
    /* Every row is its own grid, so `auto` tracks size to that row's content
       and the columns stop lining up vertically — a long badge like
       MulticastSparseDelegateProperty shifted its whole row sideways. Fixed
       tracks make all rows agree; the badge truncates and keeps its tooltip. */
    .field-row {
        grid-template-columns:
            28px
            minmax(150px, 22rem)
            minmax(110px, 17rem)
            minmax(0, 1fr)
            74px
            168px
            96px
            36px;
        grid-template-areas: "icon name type gap offset property technical link";
    }

    .function-row > summary {
        grid-template-columns:
            28px
            minmax(180px, 39rem)
            minmax(0, 1fr)
            168px
            96px
            36px;
        grid-template-areas: "icon name gap property technical link";
    }

    .field-row > .property-badge,
    .function-row > summary > .property-badge {
        max-width: 100%;
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
        display: block;
        line-height: 20px;
    }
}
