// =============================================================================
// GRID / TREE DESIGN SYSTEM
//
// Shared presentation primitives for every data grid (`p-table`) and tree
// (`p-tree`) in the app, so a row reads the same wherever it appears.
//
// Rules of the system:
//   1. A row is ONE line tall. Nothing here wraps — cells that outgrow their
//      column ellipsise instead (pair them with a `title` for the full value).
//   2. Colour carries meaning: green = ok/secured, amber = caution/public,
//      red = danger/blocked, blue = informational, violet = hooks/sandbox.
//   3. Actions are icon buttons of one fixed size; when a header collects more
//      than ~4 of them they move into a `.g-more` three-dot menu.
//
// The global palette in root-styles.css is dark-only, so every token is
// re-declared under html.LIGHT.
// =============================================================================

$g-mono: "JetBrains Mono", SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace;

:root {
    --g-strong: #e6ebf2;
    --g-muted: #8ea3bd;
    --g-faint: #6d8099;
    --g-line: rgba(97, 175, 239, 0.18);
    --g-fill: rgba(97, 175, 239, 0.09);
    --g-blue: #61afef;
    --g-green: #3ecf8e;
    --g-amber: #ffc04d;
    --g-red: #ff8d94;
    --g-violet: #bc8cf2;
    --g-teal: #4fd1c5;
}

html.LIGHT {
    --g-strong: #1b2330;
    --g-muted: #5b6b80;
    --g-faint: #7a8899;
    --g-line: rgba(12, 83, 164, 0.20);
    --g-fill: rgba(12, 83, 164, 0.06);
    --g-blue: #0c53a4;
    --g-green: #00893f;
    --g-amber: #8a5d00;
    --g-red: #c0392b;
    --g-violet: #6b3fa0;
    --g-teal: #0f766e;
}

// ── Card header ──────────────────────────────────────────────────────────────
// Count pill beside the card title. Shows "selected/total" while a selection is
// active, so the header answers "how many?" without a status bar.
.g-count {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 1.6em;
    padding: 0 0.5em;
    margin-left: 0.45rem;
    border: 1px solid var(--g-line);
    border-radius: 999px;
    background: var(--g-fill);
    color: var(--g-muted);
    font-size: 0.66rem;
    font-weight: 600;
    line-height: 1.5;
    vertical-align: middle;
}

.g-count--selected {
    color: var(--g-blue);
    border-color: var(--g-blue);
    background: transparent;
}

// Three-dot overflow menu for headers carrying many actions. Uses the same
// Bootstrap dropdown the rest of the app uses, so behaviour is unchanged.
.g-more .dropdown-menu {
    min-width: 11rem;
}

.g-more .dropdown-item {
    padding: 0.3rem 0.9rem;
    font-size: 0.8rem;
}

.g-more .dropdown-item i,
.g-more .dropdown-item img {
    width: 1.1rem;
    margin-right: 0.35rem;
}

.g-more .dropdown-divider {
    margin: 0.25rem 0;
}

// ── HTTP method pill ─────────────────────────────────────────────────────────
.g-method {
    display: inline-block;
    flex: 0 0 auto;
    min-width: 58px;
    padding: 0 5px;
    border: 1px solid transparent;
    border-radius: 3px;
    font-family: $g-mono;
    font-size: 0.63rem;
    font-weight: 700;
    letter-spacing: 0.05em;
    line-height: 1.6;
    text-align: center;
    white-space: nowrap;
}

.g-method--GET {
    color: var(--g-green);
    background: rgba(38, 180, 127, 0.13);
    border-color: rgba(38, 180, 127, 0.40);
}

.g-method--POST {
    color: var(--g-amber);
    background: rgba(255, 180, 0, 0.14);
    border-color: rgba(255, 180, 0, 0.42);
}

.g-method--PUT {
    color: var(--g-blue);
    background: rgba(97, 175, 239, 0.13);
    border-color: rgba(97, 175, 239, 0.42);
}

.g-method--PATCH {
    color: var(--g-violet);
    background: rgba(188, 140, 242, 0.13);
    border-color: rgba(188, 140, 242, 0.42);
}

.g-method--DELETE {
    color: var(--g-red);
    background: rgba(237, 75, 72, 0.13);
    border-color: rgba(237, 75, 72, 0.42);
}

// ── One-line cell ────────────────────────────────────────────────────────────
.g-cell {
    display: flex;
    align-items: center;
    flex-wrap: nowrap;
    gap: 0.3rem;
    min-width: 0;
    overflow: hidden;
}

// Narrow panels (the 40% splitter half) cannot fit a long name and its path on
// one line — both ellipsise into uselessness. Stacking them lets the row grow
// taller instead, so each keeps its own full-width line.
.g-cell--stack {
    flex-direction: column;
    align-items: flex-start;
    gap: 0;
    overflow: visible;

    > * {
        flex: 0 0 auto;
        max-width: 100%;
    }
}

.g-name {
    flex: 0 1 auto;
    min-width: 0;
    color: var(--g-strong);
    font-weight: 400;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.g-sub,
.g-path {
    flex: 0 1 auto;
    min-width: 0;
    color: var(--g-muted);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.g-path {
    font-family: $g-mono;
    font-size: 0.7rem;
}

.g-sub {
    font-size: 0.75rem;
}

.g-mono {
    font-family: $g-mono;
    font-size: 0.7rem;
}

.g-num {
    color: var(--g-muted);
    font-size: 0.72rem;
    font-variant-numeric: tabular-nums;
    white-space: nowrap;
}

.g-index,
.g-dash {
    color: var(--g-faint);
    font-size: 0.7rem;
    font-variant-numeric: tabular-nums;
}

.g-date {
    color: var(--g-muted);
    font-size: 0.7rem;
    white-space: nowrap;
    font-variant-numeric: tabular-nums;
}

// A → B → C breadcrumb (instance → database → collection and friends).
.g-trail {
    display: flex;
    align-items: center;
    flex-wrap: nowrap;
    gap: 0.3rem;
    min-width: 0;
    overflow: hidden;
    color: var(--g-muted);
    font-size: 0.75rem;
    white-space: nowrap;
}

.g-trail-sep {
    color: var(--g-faint);
    font-size: 0.6rem;
    flex: 0 0 auto;
}

.g-trail > span:last-child {
    color: var(--g-strong);
}

// Copy affordance: hidden until the row is hovered — a convenience, not
// information, and one per cell on every row is pure noise.
.g-copy {
    flex: 0 0 auto;
    opacity: 0;
    color: var(--g-faint);
    cursor: pointer;
    font-size: 0.68rem;
    transition: opacity 0.15s ease, color 0.15s ease;
}

tr:hover .g-copy,
.g-node:hover .g-copy,
.g-copy:focus {
    opacity: 1;
}

.g-copy:hover {
    color: var(--g-blue);
}

// ── Chips ────────────────────────────────────────────────────────────────────
.g-chips {
    display: flex;
    align-items: center;
    flex-wrap: nowrap;
    flex: 0 1 auto;
    gap: 3px;
    min-width: 0;
    overflow: hidden;
}

.g-chip {
    display: inline-flex;
    align-items: center;
    flex: 0 0 auto;
    gap: 3px;
    padding: 0 5px;
    border: 1px solid transparent;
    border-radius: 3px;
    font-size: 0.6rem;
    font-weight: 600;
    letter-spacing: 0.04em;
    line-height: 1.6;
    white-space: nowrap;

    i {
        font-size: 0.58rem;
    }
}

.g-chip--danger {
    color: var(--g-red);
    background: rgba(237, 75, 72, 0.12);
    border-color: rgba(237, 75, 72, 0.35);
}

.g-chip--warn {
    color: var(--g-amber);
    background: rgba(255, 180, 0, 0.12);
    border-color: rgba(255, 180, 0, 0.35);
}

.g-chip--info {
    color: var(--g-blue);
    background: rgba(97, 175, 239, 0.12);
    border-color: rgba(97, 175, 239, 0.32);
}

.g-chip--violet {
    color: var(--g-violet);
    background: rgba(188, 140, 242, 0.12);
    border-color: rgba(188, 140, 242, 0.32);
}

.g-chip--success {
    color: var(--g-green);
    background: rgba(38, 180, 127, 0.12);
    border-color: rgba(38, 180, 127, 0.32);
}

.g-chip--teal {
    color: var(--g-teal);
    background: rgba(79, 209, 197, 0.12);
    border-color: rgba(79, 209, 197, 0.32);
}

.g-chip--muted {
    color: var(--g-muted);
    background: var(--g-fill);
    border-color: var(--g-line);
}

// ── Access / authorization tokens ────────────────────────────────────────────
.g-access {
    display: flex;
    align-items: center;
    flex-wrap: nowrap;
    gap: 3px;
    min-width: 0;
    overflow: hidden;
}

.g-auth {
    display: inline-block;
    flex: 0 0 auto;
    padding: 0 5px;
    border: 1px solid transparent;
    border-radius: 3px;
    font-family: $g-mono;
    font-size: 0.6rem;
    font-weight: 600;
    line-height: 1.6;
    white-space: nowrap;
}

.g-auth--public {
    color: var(--g-amber);
    background: rgba(255, 180, 0, 0.12);
    border-color: rgba(255, 180, 0, 0.35);
}

.g-auth--none {
    color: var(--g-red);
    background: rgba(237, 75, 72, 0.12);
    border-color: rgba(237, 75, 72, 0.35);
}

.g-auth--secured {
    color: var(--g-green);
    background: rgba(38, 180, 127, 0.12);
    border-color: rgba(38, 180, 127, 0.32);
}

.g-auth--am {
    color: var(--g-blue);
    background: rgba(97, 175, 239, 0.12);
    border-color: rgba(97, 175, 239, 0.32);
}

// ── Inline stats (versions, hooks, counts, timeout …) ────────────────────────
.g-meta {
    display: flex;
    align-items: center;
    flex-wrap: nowrap;
    gap: 0.55rem;
    min-width: 0;
    overflow: hidden;
}

.g-meta-item {
    display: inline-flex;
    align-items: center;
    flex: 0 0 auto;
    gap: 0.25rem;
    color: var(--g-muted);
    font-size: 0.7rem;
    line-height: 1.5;
    white-space: nowrap;
    font-variant-numeric: tabular-nums;

    i {
        font-size: 0.66rem;
        opacity: 0.75;
    }
}

.g-meta-item--hooks {
    color: var(--g-violet);
}

.g-meta-item--on {
    color: var(--g-green);
}

.g-meta-item--off {
    color: var(--g-faint);
}

// Pre/post hook counters. Zero is deliberately dimmed rather than hidden so the
// pair always occupies the same width and the column stays scannable.
.g-hooks {
    display: inline-flex;
    align-items: center;
    gap: 2px;
    font-size: 0.7rem;
    font-variant-numeric: tabular-nums;
}

.g-hooks-n {
    min-width: 1.1em;
    text-align: center;
    color: var(--g-violet);
}

.g-hooks-n--zero {
    color: var(--g-faint);
    opacity: 0.7;
}

// ── State dot (active / inactive) ────────────────────────────────────────────
.g-dot {
    display: inline-block;
    width: 7px;
    height: 7px;
    flex: 0 0 auto;
    border-radius: 50%;
    background: var(--g-faint);
}

.g-dot--on {
    background: var(--g-green);
    box-shadow: 0 0 0 2px rgba(38, 180, 127, 0.18);
}

.g-dot--off {
    background: var(--g-faint);
}

.g-dot--warn {
    background: var(--g-amber);
    box-shadow: 0 0 0 2px rgba(255, 180, 0, 0.18);
}

.g-dot--danger {
    background: var(--g-red);
    box-shadow: 0 0 0 2px rgba(237, 75, 72, 0.18);
}

// ── Row actions ──────────────────────────────────────────────────────────────
// A flex wrapper, never `text-center`: an inline-block button taller than the
// text strut drags a baseline gap into the line box and silently grows the row.
.g-actions {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.3rem;
}

.g-actions--end {
    justify-content: flex-end;
}

.g-action {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    flex: 0 0 auto;
    width: 26px;
    height: 21px;
    padding: 0;
    border: 1px solid var(--g-line);
    border-radius: 4px;
    background: var(--g-fill);
    color: var(--g-blue);
    line-height: 1;
    transition: border-color 0.15s ease, background 0.15s ease;

    &:hover {
        border-color: var(--g-blue);
        background: rgba(97, 175, 239, 0.18);
        color: var(--g-blue);
        text-decoration: none;
    }

    i {
        font-size: 0.72rem;
    }
}

// Disabled keeps its slot: an action column that only sometimes renders a button
// makes the remaining one drift, and the column stops reading as a column.
.g-action:disabled,
.g-action[disabled] {
    opacity: 0.3;
    cursor: default;
    pointer-events: none;
}

.g-action--danger {
    color: var(--g-red);

    &:hover {
        border-color: var(--g-red);
        background: rgba(237, 75, 72, 0.16);
        color: var(--g-red);
    }
}

.g-action--success {
    color: var(--g-green);

    &:hover {
        border-color: var(--g-green);
        background: rgba(38, 180, 127, 0.16);
        color: var(--g-green);
    }
}

.g-action--muted {
    color: var(--g-muted);

    &:hover {
        border-color: var(--g-muted);
        color: var(--g-strong);
    }
}

// ── Log-profile "log response" toggle ────────────────────────────────────────
// Grids and trees embedded in the log-profile picker grow one extra column
// holding this checkbox. Its label is longer than the column the pane can
// spare, so on its own it wraps to two or three lines and drags the whole row
// taller — breaking rule 1. The column is pinned to a width the label fits on
// one line, and the label is toned down to caption weight: the checkbox is the
// control, the words are only there to say which one it is.
.g-lpm {
    width: 9rem;
}

.g-lpm-toggle {
    display: flex;
    align-items: center;
    flex: 0 0 auto;
    margin: 0;
    white-space: nowrap;

    .p-checkbox-label {
        margin: 0 0 0 0.4rem;
        color: var(--g-muted);
        font-size: 0.7rem;
        line-height: 1.1;
        white-space: nowrap;
    }
}

// ── Empty / informational states ─────────────────────────────────────────────
.g-empty {
    padding: 2.25rem 1rem;
    text-align: center;
    color: var(--g-faint);
    font-size: 0.8rem;
}

.g-note {
    padding: 0.75rem;
    text-align: center;
    font-size: 0.8rem;
}

.g-note--success {
    color: var(--g-green);
}

// ── Table chrome ─────────────────────────────────────────────────────────────
.g-table {
    .p-datatable-thead > tr > th {
        color: var(--g-muted);
        font-size: 0.66rem;
        font-weight: 600;
        letter-spacing: 0.07em;
        text-transform: uppercase;
        white-space: nowrap;
    }

    .p-datatable-tbody > tr > td {
        vertical-align: middle;
        overflow: hidden;
    }

    // The sort affordance (icon + multi-sort badge) is sized app-wide in
    // primeng-theme-overrides.scss. It is an <svg> with hard-coded width/height
    // attributes, so it only answers to width/height — the `font-size` rule that
    // used to live here never did anything. Nothing grid-specific is needed.

    // Per-column filter row: an input strip under the labels, not a second row of
    // full-height form controls.
    .p-column-filter,
    .p-column-filter-element,
    .p-column-filter-element .p-inputtext {
        width: 100%;
    }

    .p-column-filter-element .p-inputtext {
        padding: 0.15rem 0.4rem;
        font-size: 0.72rem;
        font-weight: 400;
        letter-spacing: 0;
        text-transform: none;
    }

    .p-datatable-thead > tr:not(:first-child) > th {
        padding-top: 0.15rem;
        padding-bottom: 0.3rem;
    }
}

// Fixed layout pins the sized columns exactly as declared and makes the free
// columns ellipsise instead of widening the table. `width` is restated because
// PrimeNG only sets it from inside @layer primeng, and fixed layout needs a
// definite width to do anything. Apply it only where the table has room to
// divide — a narrow embedded picker is better off with the auto layout.
.g-table--fixed .p-datatable-table {
    width: 100%;
    table-layout: fixed;
}

// ── Workspace panes ──────────────────────────────────────────────────────────
// The multi-pane console screens (log profile, group permissions, scanning
// periods) are one horizontal strip of cards. The strip owns the page height;
// each pane declares either a fixed reading width or `--fill` to soak up the
// remainder — so the last card always ends at the viewport edge instead of
// being sized by a hand-maintained `calc(100vw - …)`.
.g-panes {
    display: flex;
    align-items: stretch;
    gap: 0.25rem;
    height: calc(100vh - 62px);
    overflow-x: auto;
    overflow-y: hidden;
}

.g-pane {
    display: flex;
    flex-direction: column;
    flex: 0 0 auto;
    min-width: 0;
    height: 100%;
}

.g-pane--fill {
    flex: 1 1 0;
    min-width: 28rem;
}

// Every pane body stretches to the strip height. The explicit `height: 100%` is
// what makes the height definite for the card inside it — Angular component hosts
// are inline by default and would otherwise collapse.
.g-pane-body {
    flex: 1 1 auto;
    min-height: 0;
    height: 100%;
    overflow: hidden;

    > * {
        display: block;
        height: 100%;
        min-height: 0;
    }
}

// Placeholder shown in the elastic pane before anything upstream is selected.
.g-placeholder {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 0.6rem;
    height: 100%;
    padding: 2rem;
    border: 1px dashed var(--g-line);
    border-radius: 6px;
    color: var(--g-faint);
    text-align: center;

    i {
        font-size: 1.6rem;
        opacity: 0.55;
    }
}

// Restated at pane-child specificity: `.g-pane-body > *` blockifies component
// hosts, and the placeholder is the one child that must stay a flex box.
.g-pane-body > .g-placeholder {
    display: flex;
}

.g-placeholder-title {
    color: var(--g-muted);
    font-size: 0.92rem;
}

.g-placeholder-hint {
    font-size: 0.78rem;
}

// ── Tree rows ────────────────────────────────────────────────────────────────
.g-node {
    display: flex;
    align-items: center;
    flex-wrap: nowrap;
    gap: 0.5rem;
    width: 100%;
    min-width: 0;
    padding-right: 0.25rem;
}

// Trailing columns are pinned to the right edge so they line up even though
// tree indentation shifts the start of every nested row.
.g-node-right {
    display: flex;
    align-items: center;
    flex-wrap: nowrap;
    gap: 0.9rem;
    flex: 0 0 auto;
    margin-left: auto;
}

.g-node-col {
    justify-content: flex-end;
}

// Free-width columns inside a tree row (name + path share the space that the
// pinned right-hand columns leave over).
.g-node-name {
    flex: 1 1 42%;
    min-width: 0;
}

.g-node-path {
    flex: 1 1 30%;
    min-width: 0;
}

.g-folder {
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
    color: var(--g-strong);
    font-weight: 400;

    i {
        color: var(--g-blue);
        opacity: 0.8;
        font-size: 0.8rem;
    }
}

.g-folder-count {
    padding: 0 0.45em;
    border: 1px solid var(--g-line);
    border-radius: 999px;
    background: var(--g-fill);
    color: var(--g-muted);
    font-size: 0.6rem;
    font-weight: 600;
    line-height: 1.6;
}

.g-tree .p-treenode-label {
    min-width: 0;
}
