:root {
    /* Surfaces */
    --bg:        #f4f6fa;
    --panel:     #ffffff;
    --panel-2:   #f8fafc;
    --panel-3:   #eef2f7;

    /* Text */
    --text:      #1e293b;
    --text-2:    #475569;
    --muted:     #64748b;
    --muted-2:   #94a3b8;

    /* Brand / accents (matches sibling RDPMS) */
    --brand:     #2563eb;
    --brand-2:   #1d4ed8;
    --brand-soft:#dbeafe;
    --brand-fg:  #ffffff;

    /* Status palette */
    --ok:        #16a34a;
    --ok-soft:   #dcfce7;
    --warn:      #d97706;
    --warn-soft: #fef3c7;
    --err:       #dc2626;
    --err-soft:  #fee2e2;
    --info:      #0891b2;

    /* Borders + elevation */
    --border:    #e2e8f0;
    --border-2:  #cbd5e1;
    --shadow-sm: 0 1px 2px rgba(15,23,42,0.04);
    --shadow:    0 4px 12px -4px rgba(15,23,42,0.08), 0 1px 2px rgba(15,23,42,0.04);
    --shadow-lg: 0 20px 40px -16px rgba(15,23,42,0.12);

    --radius:    10px;
    --radius-sm: 6px;

    --sidebar-w: 240px;
    --sidebar-w-collapsed: 64px;
    --topbar-h:  56px;
}

* { box-sizing: border-box; }

html, body {
    margin: 0; padding: 0;
    font-family: "Inter", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
    background: var(--bg);
    color: var(--text);
    line-height: 1.55;
    min-height: 100vh;
    font-size: 15.5px;
}

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

/* ============================================================
   SHELL: sidebar + topbar + main
   ============================================================ */
.shell {
    display: grid;
    grid-template-columns: var(--sidebar-w) 1fr;
    grid-template-rows: var(--topbar-h) 1fr;
    grid-template-areas:
        "sidebar topbar"
        "sidebar main";
    min-height: 100vh;
    transition: grid-template-columns 200ms ease;
}
.shell.sidebar-collapsed {
    grid-template-columns: var(--sidebar-w-collapsed) 1fr;
}

/* ---------- sidebar ---------- */
.sidebar {
    grid-area: sidebar;
    background: var(--panel);
    border-right: 1px solid var(--border);
    display: flex; flex-direction: column;
    position: sticky; top: 0;
    height: 100vh;
    overflow-y: auto;
    overflow-x: hidden;
}

.sidebar-brand {
    height: var(--topbar-h);
    display: flex; align-items: center; gap: 0.6rem;
    padding: 0 1rem;
    border-bottom: 1px solid var(--border);
    flex-shrink: 0;
}
.sidebar-brand .logo {
    width: 28px; height: 28px;
    border-radius: 7px;
    background: linear-gradient(135deg, var(--brand) 0%, var(--brand-2) 100%);
    display: grid; place-items: center;
    color: white; font-weight: 700; font-size: 0.85rem;
    box-shadow: 0 2px 6px rgba(37,99,235,0.3);
    flex-shrink: 0;
}
.sidebar-brand .name {
    font-weight: 700; color: var(--brand); font-size: 1.05rem;
    white-space: nowrap;
}
.shell.sidebar-collapsed .sidebar-brand .name { display: none; }

.sidebar-nav { padding: 0.75rem 0.5rem; flex: 1; }
.sidebar-nav .group-label {
    padding: 0.85rem 0.8rem 0.4rem;
    font-size: 0.7rem;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: var(--muted-2);
    font-weight: 600;
}
.shell.sidebar-collapsed .sidebar-nav .group-label { display: none; }

.nav-link {
    display: flex; align-items: center; gap: 0.7rem;
    padding: 0.55rem 0.8rem;
    margin: 0.1rem 0;
    border-radius: 8px;
    color: var(--text-2);
    font-size: 0.9rem;
    font-weight: 500;
    transition: background 120ms, color 120ms;
    white-space: nowrap;
}
.nav-link:hover { background: var(--panel-3); color: var(--text); text-decoration: none; }
.nav-link.active { background: var(--brand); color: white; box-shadow: 0 2px 6px rgba(37,99,235,0.25); }
.nav-link .icon { width: 18px; height: 18px; flex-shrink: 0; opacity: 0.85; }
.shell.sidebar-collapsed .nav-link { justify-content: center; padding: 0.6rem; }
.shell.sidebar-collapsed .nav-link .text { display: none; }

.sidebar-footer {
    padding: 0.75rem 1rem;
    border-top: 1px solid var(--border);
    font-size: 0.72rem;
    color: var(--muted);
    flex-shrink: 0;
}
.shell.sidebar-collapsed .sidebar-footer { text-align: center; }
.shell.sidebar-collapsed .sidebar-footer .ts { display: none; }

/* ---------- top bar ---------- */
.topbar {
    grid-area: topbar;
    background: var(--panel);
    border-bottom: 1px solid var(--border);
    display: flex; align-items: center; gap: 1rem;
    padding: 0 1.25rem;
    position: sticky; top: 0; z-index: 20;
}
.topbar .icon-btn {
    background: transparent; border: 1px solid var(--border);
    width: 34px; height: 34px;
    display: grid; place-items: center;
    border-radius: 8px;
    color: var(--text-2);
    cursor: pointer;
    padding: 0;
    transition: background 120ms;
}
.topbar .icon-btn:hover { background: var(--panel-3); }
.topbar .page-title {
    font-size: 1rem; font-weight: 600; color: var(--text);
    margin: 0;
}
.topbar .spacer { flex: 1; }

.pill {
    display: inline-flex; align-items: center; gap: 0.4rem;
    padding: 0.25rem 0.65rem;
    border-radius: 999px;
    background: var(--panel-3);
    border: 1px solid var(--border);
    font-size: 0.74rem;
    color: var(--text-2);
    font-weight: 500;
}
.pill .pill-dot {
    width: 6px; height: 6px; border-radius: 50%;
    background: var(--muted);
}
.pill.ok   { color: var(--ok);   background: var(--ok-soft);   border-color: transparent; }
.pill.ok   .pill-dot { background: var(--ok); box-shadow: 0 0 0 3px rgba(22,163,74,0.18); }
.pill.warn { color: var(--warn); background: var(--warn-soft); border-color: transparent; }
.pill.warn .pill-dot { background: var(--warn); }
.pill.err  { color: var(--err);  background: var(--err-soft);  border-color: transparent; }
.pill.err  .pill-dot { background: var(--err); }

.user-chip {
    display: flex; align-items: center; gap: 0.5rem;
    padding: 0.25rem 0.6rem 0.25rem 0.25rem;
    border-radius: 999px;
    border: 1px solid var(--border);
    background: var(--panel);
}
.user-chip .avatar {
    width: 28px; height: 28px; border-radius: 50%;
    background: linear-gradient(135deg, var(--brand), var(--brand-2));
    color: white; display: grid; place-items: center;
    font-size: 0.75rem; font-weight: 700;
}
.user-chip .who { font-size: 0.8rem; color: var(--text-2); }

.badge {
    display: inline-block;
    background: var(--brand-soft); color: var(--brand-2);
    border-radius: 4px;
    padding: 0.1rem 0.5rem; font-size: 0.7rem; font-weight: 600;
    text-transform: uppercase; letter-spacing: 0.04em;
}

/* ---------- main ---------- */
main {
    grid-area: main;
    padding: 1.25rem 1.75rem 2rem;
    /* full width of available column; readable line-lengths come from
       individual content widths (table-wrap caps, lead p caps), not a
       single hard ceiling — keeps charts breathing on wide monitors */
    width: 100%;
    min-width: 0;
}
@media (min-width: 1700px) {
    main { padding: 1.5rem 2.25rem 2rem; }
}

.page-head {
    display: flex; align-items: baseline; gap: 1rem;
    flex-wrap: wrap;
    margin: 0.25rem 0 1.25rem;
}
.page-head h1 { font-size: 1.4rem; margin: 0; letter-spacing: -0.01em; }
.page-head .lead { color: var(--muted); font-size: 0.92rem; margin: 0; }

/* ---------- card / panel ---------- */
.card {
    background: var(--panel);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 1.1rem 1.25rem;
    box-shadow: var(--shadow-sm);
    transition: box-shadow 160ms ease;
}
.card:hover { box-shadow: var(--shadow); }
.card h2 { margin: 0 0 0.75rem; font-size: 1rem; font-weight: 600; letter-spacing: -0.01em; }
.card h3 { margin: 1rem 0 0.5rem; font-size: 0.85rem; color: var(--muted);
           text-transform: uppercase; letter-spacing: 0.06em; font-weight: 600; }

.layout {
    display: grid; grid-template-columns: 280px 1fr; gap: 1.1rem;
}
@media (min-width: 1500px) {
    .layout { grid-template-columns: 300px 1fr; gap: 1.25rem; }
}
@media (max-width: 900px) { .layout { grid-template-columns: 1fr; } }

.content { display: grid; gap: 1rem; min-width: 0; }

/* ---------- KPI tile ---------- */
.kpis {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
    gap: 1rem;
}
.kpi {
    background: var(--panel);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 1rem 1.1rem;
    display: flex; flex-direction: column; gap: 0.35rem;
    box-shadow: var(--shadow-sm);
    transition: box-shadow 160ms;
}
.kpi:hover { box-shadow: var(--shadow); }
.kpi .label {
    color: var(--muted); font-size: 0.72rem;
    text-transform: uppercase; letter-spacing: 0.06em; font-weight: 600;
}
.kpi strong { font-size: 1.6rem; line-height: 1.1; color: var(--text); font-weight: 600; }

/* ---------- forms ---------- */
.filters { align-self: start; position: sticky; top: calc(var(--topbar-h) + 1rem); }
.filters label, .form-label {
    display: block; font-size: 0.72rem; color: var(--muted);
    margin: 0.85rem 0 0.3rem;
    text-transform: uppercase; letter-spacing: 0.05em; font-weight: 600;
}
.filters select, .filters input[type=text], select.control, input.control {
    width: 100%;
    background: var(--panel);
    color: var(--text);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 0.55rem 0.7rem;
    font: inherit;
    transition: border-color 120ms, box-shadow 120ms;
}
.filters select:focus, .filters input:focus,
select.control:focus, input.control:focus {
    outline: none;
    border-color: var(--brand);
    box-shadow: 0 0 0 3px rgba(37,99,235,0.15);
}

.btn-row { display: flex; gap: 0.5rem; flex-wrap: wrap; margin-top: 0.85rem; }
button, .btn {
    background: var(--brand); color: var(--brand-fg); border: 0;
    padding: 0.55rem 0.95rem;
    border-radius: 8px;
    font: inherit; font-weight: 600; cursor: pointer;
    transition: filter 120ms, transform 80ms, box-shadow 120ms;
    box-shadow: 0 1px 2px rgba(37,99,235,0.12);
}
button:hover, .btn:hover { filter: brightness(1.08); box-shadow: 0 2px 6px rgba(37,99,235,0.22); }
button:active, .btn:active { transform: translateY(1px); }
button.ghost, .btn.ghost {
    background: var(--panel); color: var(--text-2);
    border: 1px solid var(--border); font-weight: 500;
    box-shadow: none;
}
button.ghost:hover { background: var(--panel-3); color: var(--text); }
button:disabled { opacity: 0.5; cursor: not-allowed; }

/* ---------- misc text ---------- */
.muted  { color: var(--muted); }
.small  { font-size: 0.78rem; }
.status { font-size: 0.85rem; }
.status.error { color: var(--err); }
.status.ok    { color: var(--ok); }
code {
    font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
    background: var(--panel-3);
    padding: 0.05rem 0.4rem;
    border-radius: 4px;
    font-size: 0.85em;
    color: var(--brand-2);
}

/* ---------- events list ---------- */
.events { list-style: none; padding: 0; margin: 0; display: grid; gap: 0.4rem; }
.events li {
    background: var(--panel);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 0.55rem 0.8rem;
    font-size: 0.9rem;
    transition: border-color 120ms, transform 120ms;
}
.events li:hover { border-color: var(--border-2); transform: translateX(2px); }
.events li a { color: var(--text); display: grid;
               grid-template-columns: 1fr auto auto auto;
               gap: 0.7rem; align-items: center; text-decoration: none; }
.events li a:hover { text-decoration: none; }
.events .peak { color: var(--warn); font-variant-numeric: tabular-nums; font-weight: 600; }

.badge.open    { background: var(--err-soft);  color: var(--err); }
.badge.acked   { background: var(--warn-soft); color: var(--warn); }
.badge.cleared { background: var(--ok-soft);   color: var(--ok); }

/* ---------- tables ---------- */
.table { width: 100%; border-collapse: separate; border-spacing: 0; font-size: 0.88rem; }
.table th, .table td {
    text-align: left; padding: 0.65rem 0.85rem;
    border-bottom: 1px solid var(--border);
}
.table th {
    color: var(--muted); font-weight: 600;
    text-transform: uppercase; letter-spacing: 0.04em; font-size: 0.7rem;
    background: var(--panel-2);
    position: sticky; top: 0;
}
.table tbody tr { transition: background 100ms; }
.table tbody tr:hover td { background: var(--panel-2); }
.table td.num { text-align: right; font-variant-numeric: tabular-nums; }
.table-wrap {
    max-height: 580px; overflow: auto;
    border: 1px solid var(--border); border-radius: var(--radius);
    background: var(--panel);
}

/* ---------- sparkline grid ---------- */
.spark-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));
    gap: 0.9rem;
}
.spark-card {
    background: var(--panel); border: 1px solid var(--border);
    border-radius: var(--radius); padding: 0.7rem 0.85rem 0.55rem;
    cursor: pointer; transition: border-color 120ms, transform 120ms, box-shadow 160ms;
    box-shadow: var(--shadow-sm);
}
.spark-card:hover { border-color: var(--brand); transform: translateY(-1px); box-shadow: var(--shadow); }
.spark-card .spark-title { font-size: 0.85rem; line-height: 1.3; color: var(--text); }
.spark-card .spark-sub { color: var(--muted); font-size: 0.72rem; }
.spark-card .spark { height: 64px; margin-top: 0.4rem; }

/* ---------- deep-link banner ---------- */
.deeplink {
    background: var(--brand-soft);
    border-color: transparent;
    border-left: 3px solid var(--brand);
    padding: 0.7rem 1rem;
}
.deeplink strong { color: var(--brand-2); }

/* ---------- toast ---------- */
#toast-host {
    position: fixed; bottom: 1.25rem; right: 1.25rem;
    display: flex; flex-direction: column; gap: 0.5rem; z-index: 100;
}
.toast {
    background: var(--panel); color: var(--text);
    border: 1px solid var(--border); border-left: 4px solid var(--brand);
    padding: 0.7rem 0.95rem; border-radius: 8px;
    box-shadow: var(--shadow-lg);
    font-size: 0.88rem; max-width: 400px;
    transition: opacity 280ms, transform 280ms;
}
.toast.hide { opacity: 0; transform: translateY(8px); }
.toast.success { border-left-color: var(--ok); }
.toast.error   { border-left-color: var(--err); }
.toast.warn    { border-left-color: var(--warn); }

/* ---------- about page (flow diagram + job list) ---------- */
.flow {
    display: grid; gap: 0.7rem;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
}
.flow .node {
    background: var(--panel-2); border: 1px solid var(--border);
    border-radius: var(--radius); padding: 0.9rem 1.05rem;
}
.flow .node strong { display: block; margin-bottom: 0.3rem; color: var(--text); }
.flow .node .meta { color: var(--muted); font-size: 0.8rem; line-height: 1.5; }

.job-list { display: grid; gap: 0.6rem; }
.job-row {
    display: grid;
    grid-template-columns: 1.3fr 1fr auto auto;
    gap: 0.85rem; align-items: center;
    padding: 0.75rem 0.9rem;
    background: var(--panel-2); border: 1px solid var(--border);
    border-radius: var(--radius);
}
.job-row .name { font-weight: 600; color: var(--text); }
.job-row .desc { color: var(--muted); font-size: 0.82rem; }
.job-row .cadence {
    color: var(--brand); font-size: 0.78rem;
    font-variant-numeric: tabular-nums; font-weight: 600;
    background: var(--brand-soft); padding: 0.2rem 0.6rem; border-radius: 999px;
}

.row { display: flex; gap: 0.6rem; flex-wrap: wrap; align-items: center; }
.row > * { flex: 0 0 auto; }
.spacer { flex: 1 1 auto; }

/* ============================================================
   Info button + help dialog (per-page popup)
   ============================================================ */
.info-btn {
    width: 26px; height: 26px;
    border-radius: 50%;
    border: 1px solid var(--border-2);
    background: var(--panel);
    color: var(--brand);
    font-family: "Inter", serif;
    font-style: italic; font-weight: 700; font-size: 0.85rem;
    line-height: 1; cursor: pointer;
    display: inline-flex; align-items: center; justify-content: center;
    margin-left: 0.55rem;
    transition: background 120ms, border-color 120ms;
}
.info-btn:hover { background: var(--brand-soft); border-color: var(--brand); }
.info-btn:focus-visible {
    outline: 2px solid var(--brand); outline-offset: 2px;
}

.help-dialog {
    width: min(640px, calc(100vw - 2rem));
    max-height: calc(100vh - 2rem);
    padding: 0;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow-lg);
    background: var(--panel);
    color: var(--text);
}
.help-dialog::backdrop {
    background: rgba(15, 23, 42, 0.45);
    backdrop-filter: blur(2px);
}
.help-dialog .help-head {
    display: flex; align-items: center; gap: 0.5rem;
    padding: 0.9rem 1.1rem;
    border-bottom: 1px solid var(--border);
    background: var(--panel-2);
    border-top-left-radius: var(--radius);
    border-top-right-radius: var(--radius);
    margin: 0;
}
.help-dialog .help-head h3 {
    margin: 0; font-size: 1rem; flex: 1 1 auto; color: var(--text);
}
.help-dialog .help-head .icon-btn {
    border: none; background: transparent; cursor: pointer;
    color: var(--muted); font-size: 1rem; padding: 0.2rem 0.5rem;
    border-radius: var(--radius-sm);
}
.help-dialog .help-head .icon-btn:hover { background: var(--panel-3); color: var(--text); }

.help-body {
    padding: 1rem 1.2rem 1.3rem;
    overflow: auto;
    max-height: calc(100vh - 8rem);
    font-size: 0.92rem; line-height: 1.55;
}
.help-body h4 {
    margin: 1.1rem 0 0.4rem; font-size: 0.92rem;
    color: var(--text); font-weight: 600;
}
.help-body h4:first-child { margin-top: 0; }
.help-body p { margin: 0.4rem 0; color: var(--text-2); }
.help-body ul { margin: 0.4rem 0; padding-left: 1.2rem; color: var(--text-2); }
.help-body li { margin: 0.2rem 0; }
.help-body code {
    background: var(--panel-3); padding: 0.05rem 0.35rem; border-radius: 4px;
    font-size: 0.85em;
}
.help-body .pill { vertical-align: baseline; }

/* ============================================================
   Management section — filter row, badges, chips
   ============================================================ */
.mgmt-filters {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
    gap: 0.75rem;
    align-items: end;
    margin-bottom: 1rem;
}
.mgmt-filters .field {
    display: flex; flex-direction: column; gap: 0.35rem;
    min-width: 0; /* let the grid item shrink instead of overflowing */
}
.mgmt-filters .field label {
    font-size: 0.72rem;
    text-transform: uppercase; letter-spacing: 0.05em; font-weight: 600;
    color: var(--muted);
}

/* Use the same control look as the rest of the app:
   brand focus ring, hover border, consistent height. */
.mgmt-filters select,
.mgmt-filters input[type=text] {
    width: 100%;
    height: 38px;                         /* keeps text + select aligned */
    background: var(--panel);
    color: var(--text);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 0 0.7rem;
    font: inherit;
    line-height: 1.2;
    transition: border-color 120ms, box-shadow 120ms, background 120ms;
}
.mgmt-filters select:hover,
.mgmt-filters input[type=text]:hover { border-color: var(--border-2); }
.mgmt-filters select:focus,
.mgmt-filters input[type=text]:focus {
    outline: none;
    border-color: var(--brand);
    box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.15);
}
.mgmt-filters input[type=text]::placeholder { color: var(--muted-2); }

/* Custom chevron — native arrows look different on every OS. */
.mgmt-filters select {
    appearance: none;
    -webkit-appearance: none;
    -moz-appearance: none;
    padding-right: 2rem;
    background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 12 12' fill='none' stroke='%2364748b' stroke-width='1.6' stroke-linecap='round' stroke-linejoin='round'><polyline points='3 5 6 8 9 5'/></svg>");
    background-repeat: no-repeat;
    background-position: right 0.65rem center;
    background-size: 12px 12px;
    cursor: pointer;
}
.mgmt-filters select:focus { background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 12 12' fill='none' stroke='%232563eb' stroke-width='1.8' stroke-linecap='round' stroke-linejoin='round'><polyline points='3 5 6 8 9 5'/></svg>"); }
.mgmt-filters select option { color: var(--text); background: var(--panel); }

/* Clear button — sits in the same row, same height as the inputs. */
.mgmt-filters .btn-clear {
    align-self: end;
    height: 38px;
    padding: 0 0.9rem;
    font: inherit; font-weight: 500;
    color: var(--text-2);
    background: var(--panel-2);
    border: 1px solid var(--border);
    border-radius: 8px;
    cursor: pointer;
    transition: background 120ms, border-color 120ms, color 120ms;
}
.mgmt-filters .btn-clear:hover {
    background: var(--panel-3);
    border-color: var(--border-2);
    color: var(--text);
}
.mgmt-filters .btn-clear:focus-visible {
    outline: none;
    border-color: var(--brand);
    box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.15);
}

.chip {
    display: inline-block;
    padding: 0.1rem 0.5rem;
    border-radius: 999px;
    font-size: 0.74rem; font-weight: 600;
    background: var(--panel-3); color: var(--text-2);
    border: 1px solid var(--border);
}
.chip.smooth       { background: #e0f2fe; color: #0369a1; border-color: transparent; }
.chip.event_driven { background: #fef3c7; color: #92400e; border-color: transparent; }
.chip.sparse       { background: #f1f5f9; color: #475569; border-color: transparent; }
.chip.digital      { background: #fae8ff; color: #86198f; border-color: transparent; }
.chip.auto         { background: var(--brand-soft); color: var(--brand-2); border-color: transparent; }
.chip.manual       { background: var(--warn-soft); color: var(--warn); border-color: transparent; }
.chip.numeric      { background: #ecfeff; color: #155e75; border-color: transparent; }
.chip.string       { background: #f5f5f4; color: #57534e; border-color: transparent; }

.path-cell {
    color: var(--muted); font-size: 0.78rem;
    font-variant-numeric: tabular-nums;
}
.count-pill { font-size: 0.78rem; }

/* Management — action bar / bulk-select states */
.action-bar {
    display: flex; align-items: center; gap: 0.55rem;
    padding: 0.55rem 0.7rem;
    margin-bottom: 0.7rem;
    background: var(--panel-2);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
}
.action-bar .ghost {
    padding: 0.4rem 0.8rem; font-size: 0.86rem;
    background: var(--panel); border: 1px solid var(--border);
    border-radius: var(--radius-sm); cursor: pointer;
}
.action-bar .ghost:hover:not(:disabled) { background: var(--panel-3); }
.action-bar .ghost:disabled { opacity: 0.5; cursor: not-allowed; }
.action-bar .ghost.danger { color: var(--err); }
.action-bar .ghost.danger:hover:not(:disabled) { background: var(--err-soft); }

.table tr.row-dim td { color: var(--muted-2); }
.table tr.row-dim td:first-child,
.table tr.row-dim td:nth-child(2) { color: inherit; }

/* Per-row navigation actions (Assets page → Forecasts / Health / Profile / Thresholds) */
.row-actions { display: flex; flex-wrap: wrap; gap: 0.3rem; }
.row-actions a {
    display: inline-block;
    padding: 0.25rem 0.55rem;
    font-size: 0.78rem; font-weight: 500;
    white-space: nowrap; text-decoration: none;
    color: var(--text-2);
    background: var(--panel-2);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    transition: background 120ms, border-color 120ms, color 120ms;
}
.row-actions a:hover {
    background: var(--panel-3);
    border-color: var(--border-2);
    color: var(--brand);
}
.table tr.row-dim .row-actions a { opacity: 0.85; }

.help-dialog .help-body .btn-row .ghost {
    padding: 0.45rem 0.9rem; font-size: 0.88rem;
    background: var(--panel); border: 1px solid var(--border);
    border-radius: var(--radius-sm); cursor: pointer;
}
.help-dialog .help-body .btn-row .ghost.danger {
    background: var(--err); color: #fff; border-color: var(--err);
}
.help-dialog .help-body .btn-row .ghost.danger:hover { background: #b91c1c; }

/* =========================================================================
   Assistant chat drawer (LLM LLD §12.4)
   ========================================================================= */
.assistant-fab {
    position: fixed;
    right: 1.25rem;
    bottom: 1.25rem;
    width: 52px;
    height: 52px;
    border-radius: 999px;
    background: var(--brand);
    color: #fff;
    border: none;
    box-shadow: 0 10px 25px rgba(37, 99, 235, 0.35);
    cursor: pointer;
    z-index: 80;
    display: grid;
    place-items: center;
}
.assistant-fab:hover { background: var(--brand-2); }
.assistant-fab svg  { width: 24px; height: 24px; }

.assistant-drawer {
    position: fixed;
    top: 0;
    right: 0;
    height: 100vh;
    width: min(420px, 95vw);
    background: var(--panel);
    border-left: 1px solid var(--panel-3);
    box-shadow: -12px 0 40px rgba(15, 23, 42, 0.08);
    transform: translateX(100%);
    transition: transform 220ms ease;
    z-index: 90;
    display: flex;
    flex-direction: column;
}
.assistant-drawer.open { transform: translateX(0); }
.assistant-drawer .chat-head {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.85rem 1rem;
    border-bottom: 1px solid var(--panel-3);
}
.assistant-drawer .chat-head h3 {
    margin: 0;
    font-size: 0.95rem;
    flex: 1;
}
.assistant-drawer .chat-head .icon-btn {
    background: transparent;
    border: 1px solid var(--panel-3);
    border-radius: 6px;
    width: 28px;
    height: 28px;
    cursor: pointer;
    color: var(--text-2);
}
.assistant-drawer .chat-head .icon-btn:hover { background: var(--panel-3); }

.assistant-drawer .chat-msgs {
    flex: 1;
    overflow-y: auto;
    padding: 0.85rem 1rem;
    display: flex;
    flex-direction: column;
    gap: 0.55rem;
}
.chat-empty {
    color: var(--muted);
    font-size: 0.88rem;
    margin-top: 1rem;
}
.chat-examples {
    list-style: none;
    padding: 0;
    margin: 0.5rem 0 0 0;
    display: grid;
    gap: 0.35rem;
}
.chat-examples button {
    width: 100%;
    text-align: left;
    background: var(--panel-2);
    border: 1px solid var(--panel-3);
    border-radius: 6px;
    padding: 0.45rem 0.6rem;
    cursor: pointer;
    color: var(--text);
    font-size: 0.85rem;
}
.chat-examples button:hover { background: var(--brand-soft); }

.chat-msg {
    display: flex;
    align-items: flex-start;
}
.chat-msg .chat-body {
    max-width: 88%;
    padding: 0.55rem 0.75rem;
    border-radius: 10px;
    line-height: 1.45;
    font-size: 0.9rem;
    white-space: pre-wrap;
    word-wrap: break-word;
}
.chat-user { justify-content: flex-end; }
.chat-user  .chat-body { background: var(--brand); color: var(--brand-fg); }
.chat-assistant .chat-body { background: var(--panel-2); border: 1px solid var(--panel-3); }
.chat-pending .chat-body {
    background: #fffbeb;
    border: 1px solid #fcd34d;
    width: 100%;
    max-width: 100%;
}
.chat-pending .pending-head { font-weight: 600; margin-bottom: 0.35rem; }
.chat-pending .pending-args {
    background: rgba(0,0,0,0.05);
    border-radius: 6px;
    padding: 0.4rem 0.55rem;
    font-size: 0.78rem;
    overflow-x: auto;
    margin: 0 0 0.5rem 0;
}
.chat-pending .pending-actions {
    display: flex;
    gap: 0.4rem;
}
.chat-pending .btn-confirm,
.chat-pending .btn-reject {
    border: none;
    border-radius: 6px;
    padding: 0.35rem 0.7rem;
    font-size: 0.82rem;
    cursor: pointer;
}
.chat-pending .btn-confirm { background: var(--ok); color: #fff; }
.chat-pending .btn-confirm:hover { background: #15803d; }
.chat-pending .btn-reject { background: var(--panel-3); color: var(--text); }
.chat-pending .pending-status { margin-top: 0.4rem; font-size: 0.82rem; }
.chat-pending .ok-text  { color: var(--ok); font-weight: 600; }
.chat-pending .err-text { color: var(--err); font-weight: 600; }

.chat-status {
    padding: 0.35rem 1rem;
    font-size: 0.78rem;
    color: var(--muted);
    border-top: 1px solid var(--panel-3);
    min-height: 1.3em;
}
.chat-status.ok   { color: var(--ok); }
.chat-status.err  { color: var(--err); }
.chat-status.info { color: var(--brand); }

.chat-input-row {
    display: flex;
    gap: 0.5rem;
    padding: 0.6rem 1rem 0.85rem;
    border-top: 1px solid var(--panel-3);
}
.chat-input-row textarea {
    flex: 1;
    resize: none;
    min-height: 38px;
    max-height: 120px;
    padding: 0.5rem 0.6rem;
    border: 1px solid var(--panel-3);
    border-radius: 8px;
    font-family: inherit;
    font-size: 0.9rem;
    background: var(--panel-2);
    color: var(--text);
}
.chat-input-row textarea:focus { outline: 2px solid var(--brand-soft); border-color: var(--brand); }
.chat-input-row button {
    background: var(--brand);
    color: var(--brand-fg);
    border: none;
    border-radius: 8px;
    padding: 0 0.95rem;
    cursor: pointer;
    font-weight: 600;
}
.chat-input-row button:hover:not(:disabled) { background: var(--brand-2); }
.chat-input-row button:disabled { opacity: 0.5; cursor: not-allowed; }

/* AI summary block on event-detail page */
.ai-summary-card {
    margin: 0.5rem 0 1rem;
    padding: 0.8rem 1rem;
    background: var(--brand-soft);
    border: 1px solid #c7d8fd;
    border-radius: 8px;
    color: var(--text);
}
.ai-summary-card .ai-head {
    display: flex;
    align-items: center;
    gap: 0.45rem;
    font-size: 0.78rem;
    color: var(--brand-2);
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    margin-bottom: 0.35rem;
}
.ai-summary-card .ai-body { line-height: 1.55; font-size: 0.92rem; }
.ai-summary-card .ai-foot {
    margin-top: 0.45rem;
    font-size: 0.75rem;
    color: var(--muted);
    display: flex;
    gap: 0.6rem;
    align-items: center;
}
.ai-summary-card .ai-foot button {
    background: transparent;
    color: var(--brand);
    border: none;
    cursor: pointer;
    padding: 0;
    text-decoration: underline;
}

/* Morning brief banner on the dashboard */
.morning-brief {
    margin-bottom: 1rem;
    padding: 0.85rem 1.1rem;
    background: var(--panel);
    border: 1px solid var(--panel-3);
    border-left: 4px solid var(--brand);
    border-radius: 8px;
}
.morning-brief .mb-head {
    display: flex;
    gap: 0.55rem;
    align-items: center;
    font-weight: 600;
    color: var(--brand-2);
    margin-bottom: 0.35rem;
}
.morning-brief .mb-body { line-height: 1.5; color: var(--text); }
.morning-brief .mb-foot { color: var(--muted); font-size: 0.78rem; margin-top: 0.35rem; }

/* =========================================================================
   Markdown rendering — applied to LLM output (chat bubbles, AI summaries,
   morning-brief banner). The `.markdown` class is added by the JS helpers
   in assistant.js, event_detail.html, dashboard.html.
   ========================================================================= */
.markdown p {
    margin: 0 0 0.55em 0;
    line-height: 1.5;
}
.markdown p:last-child { margin-bottom: 0; }

.markdown h1, .markdown h2, .markdown h3,
.markdown h4, .markdown h5, .markdown h6 {
    margin: 0.6em 0 0.35em;
    line-height: 1.25;
    font-weight: 600;
}
.markdown h1 { font-size: 1.05em; }
.markdown h2 { font-size: 1.00em; }
.markdown h3, .markdown h4, .markdown h5, .markdown h6 { font-size: 0.95em; }

.markdown ul, .markdown ol {
    margin: 0 0 0.55em 0;
    padding-left: 1.25rem;
}
.markdown li { margin: 0.1em 0; }
.markdown li > p { margin: 0; }

.markdown strong { font-weight: 600; }
.markdown em     { font-style: italic; }

.markdown code {
    background: rgba(15, 23, 42, 0.07);
    padding: 0.05em 0.35em;
    border-radius: 4px;
    font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
    font-size: 0.85em;
}
.markdown pre {
    background: var(--panel-3);
    border: 1px solid #d6dce4;
    border-radius: 6px;
    padding: 0.55em 0.7em;
    overflow-x: auto;
    margin: 0 0 0.55em 0;
    font-size: 0.82em;
    line-height: 1.45;
}
.markdown pre code {
    background: transparent;
    padding: 0;
    border-radius: 0;
    font-size: inherit;
}

.markdown blockquote {
    margin: 0 0 0.55em 0;
    padding: 0.15em 0.75em;
    border-left: 3px solid var(--panel-3);
    color: var(--text-2);
}

.markdown a {
    color: var(--brand);
    text-decoration: underline;
    text-underline-offset: 2px;
}

.markdown hr {
    border: 0;
    border-top: 1px solid var(--panel-3);
    margin: 0.6em 0;
}

.markdown table {
    border-collapse: collapse;
    margin: 0 0 0.55em 0;
    font-size: 0.85em;
    width: 100%;
}
.markdown th, .markdown td {
    border: 1px solid var(--panel-3);
    padding: 0.25em 0.5em;
    text-align: left;
}
.markdown th { background: var(--panel-2); font-weight: 600; }

/* Inside user bubbles (brand-coloured background) inline code needs a
   lighter contrast — but user bubbles aren't markdown-rendered, so this
   only kicks in if we ever change that. Keep as a safety net. */
.chat-user .markdown code,
.chat-user .markdown pre {
    background: rgba(255, 255, 255, 0.18);
    border-color: rgba(255, 255, 255, 0.25);
    color: inherit;
}
