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

.hidden { display: none !important; }

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
    font-size: 13px;
    background: #0d1b3e;
    min-height: 100vh;
}

/* ─── App layout ──────────────────────────────────────────────────────────── */

.app-layout {
    display: flex;
    width: 100vw;
    height: 100vh;
    overflow: hidden;
}

/* ─── Icon Rail ───────────────────────────────────────────────────────────── */

.icon-rail {
    width: 68px;
    overflow-y: auto;
    flex-shrink: 0;
    background: #111827;
    display: flex;
    flex-direction: column;
    align-items: stretch;
    padding: 10px 0;
    gap: 2px;
    border-right: 1px solid rgba(255,255,255,0.05);
}

.rail-btn {
    position: relative;
    min-height: 54px;
    padding: 6px 2px;
    flex-direction: column;
    gap: 3px;
    flex-shrink: 0;
    background: none;
    border: none;
    border-left: 3px solid transparent;
    color: rgba(255,255,255,0.38);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.15s, color 0.15s, border-color 0.15s;
}
.rail-btn svg { width: 22px; height: 22px; flex-shrink: 0; }
.rail-label {
    font-size: 11px;
    line-height: 1.2;
    white-space: nowrap;
    letter-spacing: 0.02em;
}
.rail-btn:hover { background: rgba(255,255,255,0.06); color: rgba(255,255,255,0.7); }
.rail-btn.active {
    background: rgba(102,126,234,0.15);
    color: #a5b4fc;
    border-left-color: #667eea;
}

/* ─── Side Panel ──────────────────────────────────────────────────────────── */

.side-panel {
    width: 220px;
    flex-shrink: 0;
    background: #0d1b3e;
    border-right: 1px solid rgba(255,255,255,0.07);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    transition: width 0.22s ease;
}

.side-panel.collapsed {
    width: 0;
    border-right: none;
}

.panel-view {
    display: flex;
    flex-direction: column;
    height: 100%;
    min-width: 220px; /* prevent content squishing during transition */
}

.panel-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 16px 12px 12px;
    border-bottom: 1px solid rgba(255,255,255,0.07);
    flex-shrink: 0;
}

.panel-title {
    font-size: 14px;
    font-weight: 600;
    color: rgba(255,255,255,0.85);
}

.panel-icon-btn {
    background: none;
    border: none;
    color: rgba(255,255,255,0.25);
    cursor: pointer;
    padding: 4px;
    border-radius: 5px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: color 0.15s, background 0.15s;
}
.panel-icon-btn svg { width: 15px; height: 15px; }
.panel-icon-btn:hover { color: #f87171; background: rgba(248,113,113,0.1); }

.panel-footer {
    padding: 10px 8px;
    border-top: 1px solid rgba(255,255,255,0.07);
    flex-shrink: 0;
}

.panel-new-btn {
    display: flex;
    align-items: center;
    gap: 7px;
    width: 100%;
    padding: 8px 10px;
    background: rgba(102,126,234,0.12);
    border: 1px solid rgba(102,126,234,0.28);
    border-radius: 8px;
    color: #a5b4fc;
    font-size: 12px;
    font-weight: 500;
    cursor: pointer;
    transition: background 0.15s;
    white-space: nowrap;
}
.panel-new-btn svg { width: 13px; height: 13px; flex-shrink: 0; }
.panel-new-btn:hover { background: rgba(102,126,234,0.22); }

/* ─── Session List ────────────────────────────────────────────────────────── */

.session-list {
    flex: 1;
    overflow-y: auto;
    padding: 4px 0;
    min-width: 220px;
}
.session-list::-webkit-scrollbar { width: 3px; }
.session-list::-webkit-scrollbar-thumb { background: rgba(255,255,255,0.1); border-radius: 2px; }

.session-item {
    display: flex;
    flex-direction: column;
    gap: 2px;
    padding: 9px 12px;
    cursor: pointer;
    transition: background 0.12s;
    position: relative;
    border-left: 3px solid transparent;
}
.session-item:hover { background: rgba(255,255,255,0.04); }
.session-item.active {
    background: rgba(102,126,234,0.1);
    border-left-color: #667eea;
}

.session-item-title {
    font-size: 12px;
    color: rgba(255,255,255,0.7);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    font-weight: 500;
    padding-right: 18px;
}
.session-item.active .session-item-title { color: #a5b4fc; }

.session-item-time {
    font-size: 10px;
    color: rgba(255,255,255,0.28);
}

.session-item-del {
    position: absolute;
    right: 8px;
    top: 50%;
    transform: translateY(-50%);
    background: none;
    border: none;
    color: rgba(255,255,255,0.2);
    font-size: 12px;
    cursor: pointer;
    padding: 2px 4px;
    border-radius: 3px;
    opacity: 0;
    transition: opacity 0.15s, color 0.15s;
    line-height: 1;
}
.session-item:hover .session-item-del { opacity: 1; }
/* make-chat-sessions-creator-only: share an own session read-only; the
   sessions others shared with me, in their own section. */
.session-item-share {
    position: absolute;
    right: 30px;
    top: 50%;
    transform: translateY(-50%);
    background: none;
    border: none;
    color: rgba(255,255,255,0.2);
    font-size: 12px;
    cursor: pointer;
    padding: 2px 4px;
    border-radius: 3px;
    opacity: 0;
}
.session-item:hover .session-item-share { opacity: 1; }
.session-item-share:hover { color: #a5b4fc; background: rgba(165,180,252,0.12); }
.session-section {
    padding: 12px 14px 4px;
    font-size: 11px;
    letter-spacing: 0.04em;
    color: rgba(255,255,255,0.35);
    border-top: 1px solid rgba(255,255,255,0.06);
    margin-top: 6px;
}
.session-item.shared .session-item-title { font-style: italic; }
.session-item-del:hover { color: #f87171; background: rgba(248,113,113,0.12); }

.session-empty {
    padding: 20px 14px;
    font-size: 12px;
    color: rgba(255,255,255,0.2);
    text-align: center;
}

/* ─── RAG Panel (inline) ─────────────────────────────────────────────────── */

.panel-body {
    flex: 1;
    overflow-y: auto;
    padding: 14px 12px;
    display: flex;
    flex-direction: column;
    gap: 14px;
    min-width: 220px;
}
.panel-body::-webkit-scrollbar { width: 3px; }
.panel-body::-webkit-scrollbar-thumb { background: rgba(255,255,255,0.1); border-radius: 2px; }

/* ─── RAG side panel nav ─────────────────────────────────────────────────── */

.rag-status-dot {
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: #9ca3af;
    flex-shrink: 0;
    transition: background 0.3s;
}
.rag-status-dot.ok    { background: #10b981; }
.rag-status-dot.error { background: #ef4444; }

.rag-search-wrap {
    position: relative;
    flex-shrink: 0;
    padding: 6px 10px 4px;
}
.rag-search-icon {
    position: absolute;
    left: 18px;
    top: 50%;
    transform: translateY(-50%);
    width: 13px;
    height: 13px;
    color: rgba(255,255,255,0.3);
    pointer-events: none;
}
.rag-search-input {
    width: 100%;
    box-sizing: border-box;
    background: rgba(255,255,255,0.07);
    border: 1px solid rgba(255,255,255,0.1);
    border-radius: 6px;
    padding: 5px 8px 5px 28px;
    font-size: 12px;
    color: rgba(255,255,255,0.8);
    font-family: inherit;
    outline: none;
    transition: border-color 0.2s;
}
.rag-search-input::placeholder { color: rgba(255,255,255,0.25); }
.rag-search-input:focus { border-color: rgba(102,126,234,0.55); }

.rag-domains-list {
    flex: 1;
    overflow-y: auto;
    padding: 4px 8px 8px;
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.rag-domains-empty {
    font-size: 11px;
    color: rgba(255,255,255,0.25);
    font-style: italic;
    padding: 4px 2px;
}

.rag-nav-item {
    padding: 7px 10px;
    border-radius: 6px;
    font-size: 12px;
    font-weight: 500;
    color: rgba(255,255,255,0.6);
    cursor: pointer;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    transition: background 0.13s, color 0.13s;
    border-left: 3px solid transparent;
}
.rag-create-nav-btn {
    display: block;
    width: calc(100% - 16px);
    margin: 8px 8px 0;
    text-align: left;
    background: rgba(102,126,234,0.12);
    border: 1px solid rgba(102,126,234,0.3);
    font-family: inherit;
    color: #a5b4fc;
}
.rag-create-nav-btn:hover { background: rgba(102,126,234,0.22); color: #c7d2fe; }

.rag-nav-item.rag-domain-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 6px;
}
.rag-domain-item-name {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.rag-nav-item:hover { background: rgba(255,255,255,0.06); color: rgba(255,255,255,0.85); }
.rag-nav-item.active {
    background: rgba(102,126,234,0.15);
    color: #a5b4fc;
    border-left-color: #667eea;
}

/* ─── RAG main panel ─────────────────────────────────────────────────────── */

.rag-main {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    background: #f8f9fc;
}

.rag-topbar {
    display: flex;
    align-items: center;
    gap: 16px;
    padding: 14px 28px;
    background: white;
    border-bottom: 1px solid #e5e7eb;
    flex-shrink: 0;
}

.rag-topbar-status {
    display: flex;
    align-items: center;
    gap: 7px;
    font-size: 12px;
    color: #6b7280;
}

#alerts-view-title {
    font-weight: 700;
    font-size: 14px;
    color: #1f2937;
}

.rag-domain-bar {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 12px;
    flex: 1;
    border-left: 1px solid #e5e7eb;
    padding-left: 16px;
}

.rag-selected-name {
    font-size: 14px;
    font-weight: 600;
    color: #1f2937;
}

.rag-topbar-btn {
    display: flex;
    align-items: center;
    gap: 5px;
    padding: 5px 12px;
    border-radius: 6px;
    border: 1px solid #d1d5db;
    background: white;
    color: #374151;
    font-size: 12px;
    font-weight: 500;
    cursor: pointer;
    transition: background 0.15s, border-color 0.15s;
    font-family: inherit;
    white-space: nowrap;
}
.rag-topbar-btn:hover { background: #f3f4f6; border-color: #9ca3af; }
.rag-topbar-btn:disabled { opacity: 0.5; cursor: not-allowed; }
.rag-topbar-btn.danger { color: #dc2626; border-color: #fecaca; }
.rag-topbar-btn.danger:hover { background: #fef2f2; border-color: #dc2626; }
.rag-topbar-btn.primary { background: #667eea; border-color: #667eea; color: white; }
.rag-topbar-btn.primary:hover { background: #5a6fd6; border-color: #5a6fd6; }

.rag-scope-badge {
    font-size: 11px;
    font-weight: 500;
    padding: 2px 8px;
    border-radius: 999px;
    background: #f3f4f6;
    color: #6b7280;
    white-space: nowrap;
}
.rag-scope-badge.scope-private { background: #fef3c7; color: #92400e; }
.rag-scope-badge.scope-group { background: #dbeafe; color: #1e40af; }

.rag-domain-nav-badge {
    font-size: 9px;
    font-weight: 600;
    padding: 1px 5px;
    border-radius: 999px;
    background: rgba(255,255,255,0.1);
    color: rgba(255,255,255,0.5);
    margin-left: 6px;
    flex-shrink: 0;
}
.rag-domain-nav-badge.scope-private { background: rgba(217,119,6,0.25); color: #fbbf24; }
.rag-domain-nav-badge.scope-group { background: rgba(59,130,246,0.25); color: #93c5fd; }

.rag-selected-summary {
    margin: 0 28px;
    padding: 12px 16px;
    background: white;
    border: 1px solid #e5e7eb;
    border-radius: 8px;
    font-size: 13px;
    color: #4b5563;
    line-height: 1.65;
    margin-top: 20px;
}

.rag-empty-state {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    color: #9ca3af;
    font-size: 13px;
    text-align: center;
    padding: 40px;
}

.rag-create-view {
    padding: 20px 28px 28px;
    max-width: 420px;
}

.rag-documents-section {
    margin: 16px 28px 0;
    padding: 12px 16px;
    background: white;
    border: 1px solid #e5e7eb;
    border-radius: 8px;
}
.rag-documents-header {
    font-size: 12px;
    font-weight: 600;
    color: #6b7280;
    margin-bottom: 8px;
}
.rag-documents-list {
    display: flex;
    flex-direction: column;
    gap: 4px;
}
.rag-document-item {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 8px;
    padding: 6px 8px;
    border-radius: 6px;
    font-size: 12.5px;
    color: #374151;
}
.rag-document-item:hover { background: #f9fafb; }
.rag-document-main {
    display: flex;
    flex-direction: column;
    gap: 2px;
    min-width: 40px; /* always show a few characters + ellipsis, even when
                         a long .rag-document-meta value is competing for space */
    overflow: hidden;
}
.rag-document-name {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.rag-document-desc {
    color: #9ca3af;
    font-size: 11px;
    line-height: 1.4;
    /* AI-generated, can run long — wrap instead of truncating to one line
       so the description stays actually readable. */
    white-space: normal;
}
.rag-document-meta {
    color: #9ca3af;
    font-size: 11px;
    /* Was flex-shrink:0 (never shrink) — fine for short values like a file
       size, but a long URL (promquery instance rows) would then claim its
       full content width and squeeze .rag-document-name down to nothing.
       Letting it shrink + truncate keeps both readable regardless of value
       length; max-width caps how much of the row a long value can claim. */
    flex-shrink: 1;
    min-width: 0;
    max-width: 220px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.rag-document-del-btn {
    border: none;
    background: transparent;
    color: #9ca3af;
    cursor: pointer;
    padding: 2px 6px;
    border-radius: 4px;
    flex-shrink: 0;
}
.rag-document-del-btn:hover { color: #dc2626; background: #fef2f2; }

/* Datasource summary/health (add-datasource-summary-and-healthcheck) */
.promquery-instance-wrapper { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.promquery-health-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    flex-shrink: 0;
    background: #d1d5db; /* unknown/never checked */
}
.promquery-health-dot.up { background: #22c55e; }
.promquery-health-dot.down { background: #ef4444; }

/* MCP Broker instance health (mcp-broker-integration-gaps) — same states as
   .promquery-health-dot above, kept as its own class since this panel isn't
   PromQuery-specific. */
.mcp-broker-health-dot {
    display: inline-block;
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: #d1d5db; /* unknown/never checked */
}
.mcp-broker-health-dot.up { background: #22c55e; }
.mcp-broker-health-dot.down { background: #ef4444; }
.mcp-broker-health-dot.disabled { background: transparent; border: 1px solid #9ca3af; box-sizing: border-box; }

/* MCP Broker instance form (adopt-mcp-server-config-schema): one row per
   group of fields inside the wrapping .admin-create-form. */
.mcp-broker-form { flex-direction: column; align-items: stretch; }
.mcp-form-row { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; width: 100%; }
.mcp-form-row > .admin-input { min-width: 140px; }
.mcp-form-row > [data-mcp-auth] { min-width: 240px; }
.mcp-form-label { font-size: 12px; color: #6b7280; min-width: 64px; }
.mcp-form-advanced { display: block; }
.mcp-form-advanced > summary { font-size: 12px; color: #6b7280; cursor: pointer; margin-bottom: 6px; }
.mcp-form-advanced > .admin-input { display: block; width: 100%; box-sizing: border-box; margin-bottom: 6px; }
.admin-badge.mcp-disabled { background: #f3f4f6; color: #6b7280; }
.mcp-tag { display: inline-block; padding: 1px 6px; margin: 1px 2px; border-radius: 4px; background: #f3f4f6; color: #374151; font-size: 11px; }
.promquery-instance-summary-row {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 0 8px 6px 24px; /* left-align under the name, past the health dot */
    font-size: 11px;
    color: #6b7280;
    min-width: 0; /* let the flex row itself shrink to the panel width */
}
.promquery-instance-summary {
    flex: 1;
    min-width: 0; /* flex items default to min-width:auto (content-based), which
                     defeats text-overflow:ellipsis on nowrap text — this lets
                     it actually shrink instead of overflowing the whole panel */
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.promquery-instance-action-btn {
    border: none;
    background: transparent;
    color: #6b7280;
    cursor: pointer;
    font-size: 11px;
    padding: 1px 4px;
    border-radius: 4px;
    flex-shrink: 0;
}
.promquery-instance-action-btn:hover { color: #2563eb; background: #eff6ff; }
.promquery-instance-action-btn:disabled { color: #d1d5db; cursor: default; }

.rag-ops-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 20px;
    padding: 20px 28px 28px;
    overflow-y: auto;
    flex: 1;
}

/* ── PromQuery Dashboard ─────────────────────────────────────────────────── */

#promquery-detail-view {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-height: 0; /* let the child scroll instead of growing past the viewport */
    overflow: hidden;
}

.promquery-panel-grid {
    display: grid;
    grid-template-columns: repeat(24, 1fr);
    grid-auto-rows: 30px;
    gap: 10px;
    padding: 20px 28px 28px;
    overflow-y: auto;
    flex: 1;
    align-content: start;
}
.promquery-panel-card {
    background: white;
    border: 1px solid #e5e7eb;
    border-radius: 8px;
    padding: 10px 14px;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    min-width: 0;
}
.promquery-panel-title {
    font-size: 12px;
    font-weight: 600;
    color: #374151;
    margin-bottom: 6px;
    flex-shrink: 0;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.promquery-panel-body {
    flex: 1;
    display: flex;
    flex-direction: column;
    position: relative;
    min-height: 0;
    overflow: auto;
}
.promquery-panel-body canvas { max-width: 100%; max-height: 100%; }

/* Chart.js's built-in legend draws inside the canvas itself and eats into
   the chart's own space — with many series (many wrapped legend lines) the
   actual chart could get squeezed down to a sliver. Rendering the legend as
   separate scrollable HTML below the canvas instead guarantees the chart
   keeps the majority of the panel's height; the legend only takes what it
   needs, capped at 1/3, with its own scrollbar beyond that. */
.promquery-chart-canvas-wrap {
    flex: 1 1 auto;
    min-height: 0;
    position: relative;
}
.promquery-chart-canvas-wrap canvas {
    position: absolute;
    inset: 0;
    width: 100% !important;
    height: 100% !important;
}
.promquery-chart-legend {
    flex: 0 1 auto;
    max-height: 34%;
    overflow-y: auto;
    display: flex;
    flex-wrap: wrap;
    align-content: flex-start;
    gap: 4px 12px;
    padding-top: 6px;
    font-size: 11px;
    color: #4b5563;
}
.promquery-chart-legend-item {
    display: flex;
    align-items: center;
    gap: 4px;
    white-space: nowrap;
}
.promquery-chart-legend-swatch {
    width: 10px;
    height: 10px;
    border-radius: 2px;
    flex-shrink: 0;
}
.promquery-panel-empty, .promquery-panel-error {
    font-size: 12px;
    color: #9ca3af;
    padding: 8px 0;
}
.promquery-panel-error { color: #dc2626; }

/* Edit mode — drag handle, resize handle, per-panel edit/delete overlay
   (added-to-existing-card layer, promquery-chartlib.js itself is untouched). */
.promquery-panel-card--editing {
    position: relative;
    border-color: #c7d2fe;
    box-shadow: 0 0 0 1px #c7d2fe;
}
.promquery-panel-card--editing .promquery-panel-title {
    cursor: grab;
    user-select: none;
    padding-right: 44px; /* keep clear of the edit/delete controls */
}
.promquery-panel-card--editing .promquery-panel-title:active { cursor: grabbing; }
.promquery-panel-edit-controls {
    position: absolute;
    top: 8px;
    right: 10px;
    display: flex;
    gap: 4px;
    z-index: 2;
}
.promquery-panel-edit-controls button {
    width: 20px;
    height: 20px;
    padding: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    border: 1px solid #d1d5db;
    border-radius: 4px;
    background: white;
    color: #4b5563;
    cursor: pointer;
    font-size: 12px;
    line-height: 1;
}
.promquery-panel-edit-controls button:hover { background: #f3f4f6; border-color: #9ca3af; }
.promquery-panel-edit-controls button.promquery-panel-delete-handle { color: #dc2626; border-color: #fecaca; }
.promquery-panel-edit-controls button.promquery-panel-delete-handle:hover { background: #fef2f2; border-color: #dc2626; }
.promquery-panel-resize-handle {
    position: absolute;
    right: 2px;
    bottom: 2px;
    width: 14px;
    height: 14px;
    cursor: nwse-resize;
    z-index: 2;
}
.promquery-panel-resize-handle::before {
    content: '';
    position: absolute;
    right: 2px;
    bottom: 2px;
    width: 8px;
    height: 8px;
    border-right: 2px solid #9ca3af;
    border-bottom: 2px solid #9ca3af;
}
.promquery-edit-hint {
    font-size: 12px;
    color: #b45309;
}
#promquery-edit-toolbar {
    flex: 0 0 auto;
    border-left: none;
    padding: 10px 28px;
}
.promquery-panel-modal-body { width: min(90vw, 480px); }
.alert-detail-modal-body {
    width: min(92vw, 720px);
    overflow-y: auto;
}
.alert-detail-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
    gap: 10px 16px;
    font-size: 13px;
}
.alert-detail-expr {
    background: #f9fafb;
    border: 1px solid #e5e7eb;
    border-radius: 6px;
    padding: 8px 10px;
    font-size: 12px;
    font-family: monospace;
    white-space: pre-wrap;
    word-break: break-word;
    margin: 0;
}
.alert-detail-kv {
    font-size: 12px;
    font-family: monospace;
    color: #374151;
    background: #f9fafb;
    border: 1px solid #e5e7eb;
    border-radius: 6px;
    padding: 8px 10px;
    white-space: pre-wrap;
    word-break: break-word;
}
.alert-detail-history-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
}
.alert-detail-chart-wrap {
    position: relative;
    height: 200px;
}
.alert-detail-chart-wrap canvas {
    position: absolute;
    inset: 0;
    width: 100% !important;
    height: 100% !important;
}
.promquery-panel-grid--editing { background: #f8fafc; }
.promquery-stat-wrap {
    display: flex;
    flex-direction: column;
    gap: 6px;
    align-items: center;
    justify-content: center;
    height: 100%;
    overflow-y: auto;
}
.promquery-stat-row { display: flex; flex-direction: column; align-items: center; }
.promquery-stat-value { font-size: 28px; font-weight: 700; color: #111827; }
.promquery-stat-label { font-size: 11px; color: #6b7280; }
.promquery-table { width: 100%; border-collapse: collapse; font-size: 11px; }
.promquery-table th, .promquery-table td {
    border-bottom: 1px solid #e5e7eb;
    padding: 4px 6px;
    text-align: left;
}
.promquery-table th { color: #6b7280; font-weight: 600; }

.rag-ops-card {
    background: white;
    border: 1px solid #e5e7eb;
    border-radius: 10px;
    padding: 20px;
    display: flex;
    flex-direction: column;
    gap: 10px;
    min-width: 0; /* grid items (this is a 1fr column of .rag-ops-grid) default to
                     min-width:auto — content-based — same trap as flex items, so
                     unbreakable text inside (e.g. a long datasource summary) still
                     forced the whole column wider than its track without this */
}

.rag-ops-title {
    display: flex;
    align-items: center;
    gap: 7px;
    font-size: 13px;
    font-weight: 600;
    color: #111827;
    padding-bottom: 8px;
    border-bottom: 1px solid #f3f4f6;
}
.rag-ops-title svg { color: #6b7280; }

.rag-ops-input {
    width: 100%;
    border: 1px solid #d1d5db;
    border-radius: 7px;
    padding: 8px 12px;
    font-size: 13px;
    color: #111827;
    font-family: inherit;
    outline: none;
    transition: border-color 0.2s;
    background: white;
    box-sizing: border-box;
}
.rag-ops-input::placeholder { color: #9ca3af; }
.rag-ops-input:focus { border-color: #667eea; box-shadow: 0 0 0 2px rgba(102,126,234,0.1); }

.promquery-explore-row {
    display: flex;
    gap: 12px;
}
.promquery-explore-field {
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
    gap: 4px;
}
.promquery-explore-label {
    font-size: 11px;
    font-weight: 600;
    color: #6b7280;
    text-transform: uppercase;
    letter-spacing: 0.03em;
}

.promquery-explore-query-wrap {
    position: relative;
}
.promquery-explore-suggest {
    position: absolute;
    left: 0;
    right: 0;
    top: 100%;
    margin-top: 4px;
    max-height: 220px;
    overflow-y: auto;
    background: white;
    border: 1px solid #d1d5db;
    border-radius: 7px;
    box-shadow: 0 4px 12px rgba(0,0,0,0.08);
    z-index: 20;
}
.promquery-explore-suggest-item {
    padding: 6px 12px;
    font-size: 12px;
    font-family: monospace;
    color: #111827;
    cursor: pointer;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.promquery-explore-suggest-item:hover,
.promquery-explore-suggest-item.active {
    background: #eef1ff;
}
.promquery-explore-suggest-item mark {
    background: none;
    color: #667eea;
    font-weight: 700;
}

.rag-file-label {
    display: flex;
    align-items: center;
    gap: 8px;
    background: #f9fafb;
    border: 1px dashed #d1d5db;
    border-radius: 7px;
    padding: 9px 12px;
    cursor: pointer;
    transition: background 0.15s, border-color 0.15s;
}
.rag-file-label:hover { background: #f3f4f6; border-color: #667eea; }
.rag-file-label svg { width: 15px; height: 15px; color: #9ca3af; flex-shrink: 0; }
.rag-file-label span { font-size: 12px; color: #6b7280; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.rag-file-label.has-file { border-color: #667eea; }
.rag-file-label.has-file svg { color: #667eea; }
.rag-file-label.has-file span { color: #374151; font-weight: 500; }

.rag-ops-btn {
    padding: 8px 16px;
    border-radius: 7px;
    font-size: 13px;
    font-weight: 500;
    cursor: pointer;
    border: 1px solid #d1d5db;
    background: white;
    color: #374151;
    font-family: inherit;
    transition: background 0.15s;
    width: 100%;
}
.rag-ops-btn:hover { background: #f9fafb; }
.rag-ops-btn:disabled { opacity: 0.5; cursor: not-allowed; }
.rag-ops-btn.primary {
    background: #667eea;
    border-color: #667eea;
    color: white;
}
.rag-ops-btn.primary:hover { background: #5a6fd6; }

.rag-result {
    background: #f9fafb;
    border: 1px solid #e5e7eb;
    border-radius: 7px;
    padding: 10px 12px;
    font-size: 12px;
    color: #4b5563;
    line-height: 1.65;
    max-height: 240px;
    overflow-y: auto;
    white-space: pre-wrap;
}
.rag-result.error {
    border-color: rgba(239,68,68,0.3);
    color: #dc2626;
    background: #fef2f2;
}

.apikey-guide-body { font-size: 12.5px; color: #4b5563; line-height: 1.7; }
.apikey-guide-body p { margin: 0 0 10px; }
.apikey-guide-body p:last-child { margin-bottom: 0; }
.apikey-guide-body code {
    background: #f3f4f6;
    border: 1px solid #e5e7eb;
    border-radius: 4px;
    padding: 1px 5px;
    font-size: 11.5px;
    font-family: 'SF Mono', 'Fira Code', Consolas, monospace;
}
.apikey-guide-body pre {
    background: #1e293b;
    color: #e2e8f0;
    border-radius: 8px;
    padding: 12px 14px;
    overflow-x: auto;
    margin: 0 0 10px;
    font-size: 11.5px;
    line-height: 1.6;
}
.apikey-guide-body pre code { background: none; border: none; padding: 0; color: inherit; }
.apikey-guide-warning {
    background: #fffbeb;
    border: 1px solid #fde68a;
    color: #92400e;
    border-radius: 7px;
    padding: 8px 10px;
}
.apis-service-list {
    margin: 0 0 10px 18px;
    padding: 0;
}
.apis-service-list li { margin: 4px 0; }

.apikey-new-key-row {
    display: flex;
    align-items: center;
    gap: 8px;
    margin: 8px 0;
}
.apikey-new-key-value {
    flex: 1;
    min-width: 0;
    background: #1e293b;
    color: #e2e8f0;
    border-radius: 7px;
    padding: 8px 10px;
    font-size: 12px;
    font-family: 'SF Mono', 'Fira Code', Consolas, monospace;
    overflow-x: auto;
    white-space: nowrap;
    user-select: all;
}
.apikey-copy-new-btn, .apikey-dismiss-btn {
    flex-shrink: 0;
    padding: 7px 12px;
    border-radius: 7px;
    font-size: 12px;
    font-weight: 500;
    cursor: pointer;
    border: 1px solid #d1d5db;
    background: white;
    color: #374151;
    font-family: inherit;
}
.apikey-copy-new-btn:hover, .apikey-dismiss-btn:hover { background: #f9fafb; }
.apikey-dismiss-btn { display: block; margin-top: 4px; }

/* ─── Main content ────────────────────────────────────────────────────────── */

.main-content {
    flex: 1;
    min-width: 0;
    background: white;
    display: flex;
    flex-direction: column;
    height: 100vh;
    overflow: hidden;
}

/* ─── Report viewer page (report.html) ─────────────────────────────────────── */

.report-page {
    display: flex;
    flex-direction: column;
    height: 100vh;
    background: white;
}

.report-body-wrap {
    flex: 1;
    overflow-y: auto;
    display: flex;
    justify-content: center;
}

.report-content {
    width: 100%;
    max-width: 900px;
    padding: 28px 32px 60px;
}

.report-error { color: #dc2626; }

/* ─── Login ─────────────────────────────────────────────────────────────── */

.login-container {
    width: 100%;
    display: flex;
    justify-content: center;
    align-items: center;
    min-height: 100vh;
    background: #0d1b3e;
}

.login-card {
    background: white;
    border-radius: 12px;
    padding: 40px;
    width: 100%;
    max-width: 400px;
    box-shadow: 0 20px 60px rgba(0,0,0,0.4);
}

.login-header { text-align: center; margin-bottom: 32px; }
.login-header h1 {
    font-size: 28px;
    background: linear-gradient(135deg, #667eea, #764ba2);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    margin-bottom: 6px;
}
.login-header p { color: #666; font-size: 13px; }

.login-form .form-group { margin-bottom: 18px; }
.login-form label { display: block; margin-bottom: 6px; color: #444; font-weight: 500; }
.login-form input {
    width: 100%;
    padding: 10px 14px;
    border: 1.5px solid #ddd;
    border-radius: 8px;
    font-size: 14px;
    transition: border-color 0.2s;
}
.login-form input:focus { outline: none; border-color: #667eea; }

.login-error {
    color: #dc2626;
    font-size: 13px;
    margin-bottom: 12px;
    padding: 8px 12px;
    background: #fef2f2;
    border-radius: 6px;
    border: 1px solid #fecaca;
}

.btn-block { width: 100%; }

/* ─── Buttons ──────────────────────────────────────────────────────────────── */

.btn-primary {
    background: linear-gradient(135deg, #667eea, #764ba2);
    color: white;
    border: none;
    padding: 8px 16px;
    border-radius: 6px;
    cursor: pointer;
    font-size: 13px;
    font-weight: 500;
    transition: opacity 0.2s, transform 0.1s;
}
.btn-primary:hover { opacity: 0.9; }
.btn-primary:active { transform: scale(0.97); }
.btn-primary:disabled { opacity: 0.5; cursor: not-allowed; }

.btn-secondary {
    background: rgba(255,255,255,0.2);
    color: white;
    border: 1px solid rgba(255,255,255,0.3);
    padding: 5px 12px;
    border-radius: 6px;
    cursor: pointer;
    font-size: 12px;
    transition: background 0.2s;
}
.btn-secondary:hover { background: rgba(255,255,255,0.3); }

.btn-danger {
    background: #dc2626;
    color: white;
    border: none;
    padding: 8px 14px;
    border-radius: 6px;
    cursor: pointer;
    font-size: 13px;
    transition: opacity 0.2s;
}
.btn-danger:hover { opacity: 0.85; }
.btn-danger:disabled { opacity: 0.4; cursor: not-allowed; }

.btn-logout { background: rgba(220,38,38,0.25); border-color: rgba(220,38,38,0.4); }
.btn-logout:hover { background: rgba(220,38,38,0.4); }

/* ─── Header ──────────────────────────────────────────────────────────────── */

header {
    background: #1f4093;
    color: white;
    padding: 10px 20px;
    flex-shrink: 0;
}

header h1 { font-size: 18px; margin-bottom: 4px; }

.header-info {
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-size: 12px;
    opacity: 0.9;
}

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

.user-info {
    background: rgba(255,255,255,0.2);
    padding: 2px 10px;
    border-radius: 12px;
    font-size: 11px;
}

/* ─── Org selector (add-org-tenant-selector) ─────────────────────────────────
   A GCP-project-style scope switcher: fixed in the header at all times (even
   with only one org, for a consistent switcher affordance), never left in an
   "unselected" state — see app.js's _initOrgSelector for why. */
.org-scope-select {
    background: rgba(255,255,255,0.2);
    color: white;
    border: 1px solid rgba(255,255,255,0.3);
    padding: 4px 8px;
    border-radius: 12px;
    font-size: 11px;
    cursor: pointer;
    max-width: 180px;
}
.org-scope-select:hover { background: rgba(255,255,255,0.3); }
.org-scope-select option { color: #1f2937; }

/* ─── 0-org blocking screen (add-org-tenant-selector) ────────────────────────
   Defensive screen for the (should-never-happen) case of a logged-in account
   with an empty org_ids — never silently falls back to an unfiltered view. */
.org-blocked-overlay {
    position: fixed;
    inset: 0;
    background: #1f4093;
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 9999;
    padding: 24px;
}
.org-blocked-box {
    background: white;
    border-radius: 12px;
    padding: 32px 28px;
    max-width: 400px;
    text-align: center;
    box-shadow: 0 8px 32px rgba(0,0,0,0.25);
}
.org-blocked-box h2 { font-size: 18px; margin-bottom: 12px; color: #1f2937; }
.org-blocked-box p { font-size: 14px; color: #4b5563; line-height: 1.6; margin-bottom: 20px; }

/* ─── Chat ────────────────────────────────────────────────────────────────── */

.chat-container {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-height: 0;
    overflow: hidden;
}

.chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 16px 72px 16px 20px;
    display: flex;
    flex-direction: column;
    gap: 14px;
}

.message {
    display: flex;
    gap: 10px;
    align-items: flex-start;
    animation: msgIn 0.2s ease;
}

@keyframes msgIn { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }

.message.user { flex-direction: row-reverse; }

.message-avatar {
    width: 30px;
    height: 30px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 11px;
    font-weight: 700;
    flex-shrink: 0;
}

.message.user .message-avatar      { background: linear-gradient(135deg, #667eea, #764ba2); color: white; }
.message.assistant .message-avatar { background: #e8eaf6; color: #5c6bc0; }

.message-col { display: flex; flex-direction: column; max-width: 72%; }
.message.user .message-col { align-items: flex-end; }

.message-content {
    background: #f3f4f6;
    border-radius: 12px;
    padding: 10px 14px;
    line-height: 1.55;
    word-break: break-word;
}

.message.user .message-content {
    background: linear-gradient(135deg, #667eea, #764ba2);
    color: white;
    border-radius: 12px 12px 2px 12px;
}

.message.assistant .message-content { border-radius: 2px 12px 12px 12px; }

.message-time {
    font-size: 11px;
    color: #9ca3af;
    margin-top: 3px;
    padding: 0 4px;
}

/* ─── Markdown body ─────────────────────────────────────────────────────── */

.markdown-body { color: #1f2937; }
.markdown-body h1,.markdown-body h2,.markdown-body h3 { margin: 14px 0 6px; font-weight: 700; line-height: 1.3; }
.markdown-body h1 { font-size: 1.25em; }
.markdown-body h2 { font-size: 1.1em; border-bottom: 1px solid #e5e7eb; padding-bottom: 4px; }
.markdown-body h3 { font-size: 1em; color: #4b5563; }
.markdown-body p  { margin: 6px 0; }
.markdown-body strong,.markdown-body b { font-weight: 700; color: #111827; }
.markdown-body em,.markdown-body i { font-style: italic; }
.markdown-body del,.markdown-body s { text-decoration: line-through; opacity: 0.7; }
.markdown-body ul,.markdown-body ol { margin: 6px 0 6px 20px; }
.markdown-body li { margin: 3px 0; }
.markdown-body code {
    background: #f3f4f6;
    border: 1px solid #e5e7eb;
    border-radius: 4px;
    padding: 1px 5px;
    font-size: 12px;
    font-family: 'SF Mono', 'Fira Code', Consolas, monospace;
}
.markdown-body pre {
    background: #1e293b;
    border-radius: 8px;
    padding: 12px 14px;
    overflow-x: auto;
    margin: 8px 0;
}
.markdown-body pre code {
    background: none;
    border: none;
    color: #e2e8f0;
    font-size: 12px;
    padding: 0;
}
.markdown-body blockquote {
    border-left: 3px solid #667eea;
    margin: 8px 0;
    padding: 4px 12px;
    color: #6b7280;
}
.markdown-body table { border-collapse: collapse; width: 100%; margin: 8px 0; font-size: 12px; overflow-x: auto; display: block; }
.markdown-body th,.markdown-body td { border: 1px solid #e5e7eb; padding: 5px 10px; }
.markdown-body th { background: #f9fafb; font-weight: 600; }
.markdown-body a { color: #667eea; }
.markdown-body hr { border: none; border-top: 1px solid #e5e7eb; margin: 12px 0; }

/* ─── Typing indicator ──────────────────────────────────────────────────── */

.typing-indicator { display: flex; gap: 4px; align-items: center; padding: 10px 14px !important; }
.typing-dot {
    width: 7px; height: 7px;
    background: #9ca3af;
    border-radius: 50%;
    animation: bounce 1.4s infinite ease-in-out;
}
.typing-dot:nth-child(1) { animation-delay: 0s; }
.typing-dot:nth-child(2) { animation-delay: 0.2s; }
.typing-dot:nth-child(3) { animation-delay: 0.4s; }
@keyframes bounce { 0%,80%,100% { transform: scale(1); } 40% { transform: scale(1.4); } }

/* ─── Stream cursor ─────────────────────────────────────────────────────── */

.stream-cursor { display: flex; gap: 3px; padding: 4px 0; }
.stream-cursor span {
    width: 5px; height: 5px;
    background: #667eea;
    border-radius: 50%;
    animation: pulse 1.2s infinite ease-in-out;
}
.stream-cursor span:nth-child(1) { animation-delay: 0s; }
.stream-cursor span:nth-child(2) { animation-delay: 0.2s; }
.stream-cursor span:nth-child(3) { animation-delay: 0.4s; }
@keyframes pulse { 0%,100% { opacity: 0.3; transform: scale(0.8); } 50% { opacity: 1; transform: scale(1.2); } }

/* ─── Done badge ─────────────────────────────────────────────────────────── */

.done-badge {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    font-size: 11px;
    color: white;
    background: linear-gradient(135deg, #10b981, #059669);
    padding: 3px 10px;
    border-radius: 12px;
    margin-top: 4px;
}
.done-badge-icon { font-size: 10px; }

/* ─── Aborted notice ────────────────────────────────────────────────────── */

.aborted-notice {
    font-size: 12px;
    color: #92400e;
    background: #fef3c7;
    padding: 4px 10px;
    border-radius: 8px;
    margin-top: 4px;
}

/* ─── Error message ─────────────────────────────────────────────────────── */

.error-message {
    background: #fef2f2;
    color: #dc2626;
    border: 1px solid #fecaca;
    border-radius: 8px;
    padding: 10px 14px;
    font-size: 13px;
    margin: 0 auto;
    max-width: 500px;
}

/* ─── Highlight flash ───────────────────────────────────────────────────── */

@keyframes highlightFlash {
    0%   { background: rgba(102,126,234,0.2); }
    100% { background: transparent; }
}
.highlight-flash { animation: highlightFlash 1.2s ease; border-radius: 8px; }

/* ─── Input area ─────────────────────────────────────────────────────────── */

.input-container {
    display: flex;
    gap: 8px;
    padding: 12px 20px;
    border-top: 1px solid #e5e7eb;
    background: white;
    flex-shrink: 0;
    align-items: flex-end;
}

.input-container textarea {
    flex: 1;
    border: 1.5px solid #e5e7eb;
    border-radius: 10px;
    padding: 9px 13px;
    font-size: 13px;
    font-family: inherit;
    resize: none;
    max-height: 160px;
    overflow-y: auto;
    line-height: 1.5;
    transition: border-color 0.2s;
}
.input-container textarea:focus { outline: none; border-color: #667eea; }

/* ─── Settings ───────────────────────────────────────────────────────────── */

.settings {
    padding: 6px 20px 8px;
    background: #f9fafb;
    border-top: 1px solid #e5e7eb;
    flex-shrink: 0;
}

#toggle-settings {
    background: none;
    color: #6b7280;
    border: none;
    font-size: 11px;
    cursor: pointer;
    padding: 2px 6px;
}
#toggle-settings:hover { color: #374151; }

.settings-panel {
    margin-top: 6px;
    display: flex;
    flex-wrap: wrap;
    gap: 12px;
    padding: 10px 12px;
    background: white;
    border: 1px solid #e5e7eb;
    border-radius: 8px;
}

.setting-item {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 12px;
    color: #374151;
}

.setting-item label { display: flex; align-items: center; gap: 6px; cursor: pointer; }

.setting-item input[type="text"] {
    border: 1px solid #d1d5db;
    border-radius: 6px;
    padding: 4px 8px;
    font-size: 12px;
    width: 140px;
}
.setting-item input[type="text"]:focus { outline: none; border-color: #667eea; }

/* ─── Question navigator ─────────────────────────────────────────────────── */

.question-nav-btn {
    position: fixed;
    right: 18px;
    bottom: 110px;
    width: 42px;
    height: 42px;
    border-radius: 50%;
    background: linear-gradient(135deg, #667eea, #764ba2);
    color: white;
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 3px 12px rgba(102,126,234,0.4);
    z-index: 100;
    transition: transform 0.2s, box-shadow 0.2s;
}
.question-nav-btn:hover { transform: scale(1.08); box-shadow: 0 5px 18px rgba(102,126,234,0.5); }
.question-nav-btn svg { width: 20px; height: 14px; stroke: white; fill: none; stroke-width: 3; stroke-linecap: round; stroke-linejoin: round; }

.question-nav-badge {
    position: absolute;
    top: -4px;
    right: -4px;
    background: #dc2626;
    color: white;
    font-size: 10px;
    font-weight: 700;
    min-width: 18px;
    height: 18px;
    border-radius: 9px;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0 4px;
    border: 2px solid white;
}

.question-nav-popup {
    position: fixed;
    right: 18px;
    bottom: 162px;
    width: 280px;
    max-height: 380px;
    background: white;
    border-radius: 12px;
    box-shadow: 0 8px 30px rgba(0,0,0,0.18);
    z-index: 100;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.question-nav-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 10px 14px;
    border-bottom: 1px solid #e5e7eb;
}
.question-nav-title { font-size: 13px; font-weight: 600; color: #374151; }
.question-nav-close {
    background: none; border: none; cursor: pointer;
    color: #9ca3af; font-size: 18px; line-height: 1; padding: 0 4px;
}
.question-nav-close:hover { color: #374151; }

.question-nav-list {
    list-style: none;
    overflow-y: auto;
    flex: 1;
    padding: 6px 0;
}

.question-nav-item {
    display: flex;
    gap: 8px;
    align-items: flex-start;
    padding: 8px 14px;
    cursor: pointer;
    transition: background 0.15s;
}
.question-nav-item:hover { background: #f3f4f6; }

.question-nav-item-num {
    width: 18px;
    height: 18px;
    background: #667eea;
    color: white;
    border-radius: 50%;
    font-size: 10px;
    font-weight: 700;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    margin-top: 1px;
}

.question-nav-item-text {
    font-size: 12px;
    color: #374151;
    line-height: 1.45;
    word-break: break-word;
    overflow: hidden;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
}

.question-nav-empty {
    padding: 16px 14px;
    font-size: 12px;
    color: #9ca3af;
    text-align: center;
}

/* ─── Admin main panel ───────────────────────────────────────────────────── */

.admin-main {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    background: #f8f9fc;
}

.admin-subpanel {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.admin-subpanel-header {
    display: flex;
    align-items: center;
    gap: 16px;
    padding: 14px 28px;
    background: white;
    border-bottom: 1px solid #e5e7eb;
    font-size: 15px;
    font-weight: 600;
    color: #111827;
    flex-shrink: 0;
}

.admin-groups-layout {
    flex: 1;
    display: flex;
    overflow: hidden;
}

.admin-subpanel-body {
    flex: 1;
    overflow-y: auto;
    padding: 20px 28px;
    display: flex;
    flex-direction: column;
    gap: 16px;
}

.admin-create-form {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-wrap: wrap;
    background: white;
    border: 1px solid #e5e7eb;
    border-radius: 10px;
    padding: 14px 16px;
    flex-shrink: 0;
}

.admin-input {
    flex: 1;
    min-width: 160px;
    border: 1px solid #d1d5db;
    border-radius: 7px;
    padding: 7px 12px;
    font-size: 13px;
    color: #111827;
    font-family: inherit;
    outline: none;
    background: white;
    transition: border-color 0.2s;
}
.admin-input::placeholder { color: #9ca3af; }
.admin-input:focus { border-color: #667eea; box-shadow: 0 0 0 2px rgba(102,126,234,0.1); }

.admin-select {
    border: 1px solid #d1d5db;
    border-radius: 7px;
    padding: 7px 10px;
    font-size: 13px;
    color: #111827;
    font-family: inherit;
    background: white;
    outline: none;
    cursor: pointer;
}
.admin-select:focus { border-color: #667eea; }

.admin-btn {
    padding: 7px 16px;
    border-radius: 7px;
    font-size: 13px;
    font-weight: 500;
    cursor: pointer;
    border: 1px solid #d1d5db;
    background: white;
    color: #374151;
    font-family: inherit;
    white-space: nowrap;
    transition: background 0.15s;
    flex-shrink: 0;
}
.admin-btn:hover { background: #f9fafb; }
.admin-btn.primary { background: #667eea; border-color: #667eea; color: white; }
.admin-btn.primary:hover { background: #5a6fd6; }
.admin-btn.danger { background: white; border-color: #fca5a5; color: #dc2626; }
.admin-btn.danger:hover { background: #fef2f2; }
.admin-btn:disabled { opacity: 0.5; cursor: not-allowed; }

.admin-msg {
    font-size: 12px;
    color: #6b7280;
    flex-shrink: 0;
}
.admin-msg.ok  { color: #059669; }
.admin-msg.err { color: #dc2626; }

.admin-table-wrap {
    background: white;
    border: 1px solid #e5e7eb;
    border-radius: 10px;
    overflow: auto;
    flex-shrink: 0;
}

.admin-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 13px;
}
.admin-table th {
    background: #f9fafb;
    padding: 10px 16px;
    text-align: left;
    font-weight: 600;
    color: #374151;
    border-bottom: 1px solid #e5e7eb;
    white-space: nowrap;
}
.admin-table td {
    padding: 10px 16px;
    color: #4b5563;
    border-bottom: 1px solid #f3f4f6;
    vertical-align: middle;
}
.admin-table tr:last-child td { border-bottom: none; }
.admin-table tr:hover td { background: #fafafa; }
.admin-table td:last-child { width: 1%; white-space: nowrap; }

.admin-empty {
    padding: 20px 16px;
    font-size: 13px;
    color: #9ca3af;
    text-align: center;
}

.admin-name-cell {
    display: flex;
    align-items: center;
    gap: 4px;
}
.admin-name-input {
    font-size: 13px;
    font-family: inherit;
    padding: 3px 6px;
    border: 1px solid #667eea;
    border-radius: 5px;
    width: 160px;
}
.admin-icon-btn {
    border: none;
    background: transparent;
    color: #9ca3af;
    cursor: pointer;
    padding: 2px 5px;
    font-size: 13px;
    line-height: 1;
    border-radius: 4px;
    flex-shrink: 0;
}
.admin-icon-btn:hover { background: #f3f4f6; color: #374151; }
.admin-icon-btn.save { color: #059669; }
.admin-icon-btn.cancel { color: #dc2626; }
.admin-icon-btn:disabled { opacity: 0.5; cursor: not-allowed; }

.admin-badge {
    display: inline-block;
    padding: 2px 8px;
    border-radius: 999px;
    font-size: 11px;
    font-weight: 500;
    background: #e0e7ff;
    color: #4338ca;
}
.admin-badge.role-system_admin { background: #fce7f3; color: #9d174d; }
.admin-badge.role-org_admin    { background: #d1fae5; color: #065f46; }

.admin-toggle-btn {
    padding: 3px 12px;
    border-radius: 20px;
    border: 1.5px solid #d1d5db;
    background: #f9fafb;
    color: #6b7280;
    font-size: 12px;
    font-weight: 500;
    cursor: pointer;
    transition: background 0.15s, color 0.15s, border-color 0.15s;
}
.admin-toggle-btn.on {
    background: #d1fae5;
    color: #065f46;
    border-color: #6ee7b7;
}
.admin-toggle-btn:hover:not(:disabled) {
    border-color: #6366f1;
    color: #4f46e5;
}
.admin-toggle-btn:disabled {
    opacity: 0.4;
    cursor: not-allowed;
}

/* Member side panel */
.admin-member-panel {
    width: 300px;
    flex-shrink: 0;
    border-left: 1px solid #e5e7eb;
    background: white;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}
.admin-member-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 14px 16px;
    border-bottom: 1px solid #e5e7eb;
    flex-shrink: 0;
}
.admin-member-title {
    font-size: 13px;
    font-weight: 600;
    color: #111827;
}
.admin-close-btn {
    background: none;
    border: none;
    color: #9ca3af;
    cursor: pointer;
    font-size: 14px;
    padding: 2px 4px;
    border-radius: 4px;
}
.admin-close-btn:hover { color: #374151; background: #f3f4f6; }
.admin-member-panel .admin-create-form {
    border: none;
    border-bottom: 1px solid #e5e7eb;
    border-radius: 0;
    padding: 10px 12px;
    gap: 6px;
}
.admin-member-panel .admin-table-wrap {
    flex: 1;
    border: none;
    border-radius: 0;
    overflow-y: auto;
}

/* 通用「資源授權管理」面板（add-resource-grants-ui）——一個全域的固定
   overlay，五種資源類型（PromQuery/SQLQuery instance、MCP Broker instance、
   Alertmanager managed-rule/PagerDuty integration、RAG domain）共用同一份
   DOM，不需要各自在自己的面板裡重複一份。 */
.grants-panel-overlay {
    position: fixed;
    inset: 0;
    background: rgba(17, 24, 39, 0.35);
    z-index: 500;
    display: flex;
    justify-content: flex-end;
}
.grants-panel-overlay.hidden { display: none; }
.grants-panel {
    width: 360px;
    max-width: 90vw;
    height: 100%;
    box-shadow: -4px 0 16px rgba(0, 0, 0, 0.12);
}

/* RAG query test history and the assist run viewer
   (separate-assist-runs-from-chat-sessions) */
.rag-test-history-card { margin-top: 12px; }
.rag-test-history-scope { margin-left: auto; font-size: 11px; padding: 2px 6px; }
.rag-test-history-list { display: flex; flex-direction: column; gap: 4px; max-height: 280px; overflow-y: auto; }
.rag-test-history-item {
    display: flex;
    align-items: baseline;
    gap: 8px;
    padding: 6px 8px;
    border: 1px solid #e5e7eb;
    border-radius: 6px;
    background: #fff;
    font-size: 12px;
    color: #374151;
    text-align: left;
    cursor: pointer;
}
.rag-test-history-item:hover { background: #f9fafb; border-color: #667eea; }
.rag-test-history-q { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.rag-test-history-domain { color: #6b7280; font-size: 11px; white-space: nowrap; }
.rag-test-history-time { color: #9ca3af; font-size: 11px; white-space: nowrap; }
.rag-test-history-empty { font-size: 12px; color: #9ca3af; padding: 4px 0; }
.assist-run-panel { width: 560px; display: flex; flex-direction: column; }
.assist-run-meta { padding: 0 12px 8px; font-size: 11px; color: #6b7280; }
.assist-run-messages { flex: 1; overflow-y: auto; padding: 0 12px 12px; display: flex; flex-direction: column; gap: 10px; }
.assist-run-msg { border-radius: 8px; padding: 8px 10px; font-size: 13px; line-height: 1.5; }
.assist-run-msg.user { background: #eef2ff; color: #1f2937; white-space: pre-wrap; }
.assist-run-msg.assistant { background: #f9fafb; border: 1px solid #e5e7eb; }
.assist-run-msg-role { font-size: 11px; font-weight: 600; color: #6b7280; margin-bottom: 4px; }

/* ─── Cron Jobs ───────────────────────────────────────────────────────────── */

.cron-main {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.cron-nav-item {
    display: flex;
    flex-direction: column;
    gap: 2px;
    padding: 8px 14px;
}
.cron-nav-expr {
    font-family: monospace;
    font-size: 11px;
    color: #a5b4fc;
}
.cron-nav-prompt {
    font-size: 11px;
    color: rgba(255,255,255,0.5);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.cron-jobs-table {
    overflow-x: auto;
}

.cron-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 12px;
}
.cron-table th {
    background: #f9fafb;
    color: #6b7280;
    font-weight: 600;
    padding: 8px 10px;
    text-align: left;
    border-bottom: 1px solid #e5e7eb;
    white-space: nowrap;
}
.cron-table td {
    padding: 8px 10px;
    border-bottom: 1px solid #f3f4f6;
    color: #374151;
    vertical-align: top;
}
.cron-table tr:hover td { background: #f9fafb; }
.cron-table code {
    font-family: monospace;
    font-size: 11px;
    background: #f3f4f6;
    padding: 1px 5px;
    border-radius: 3px;
    color: #4f46e5;
}
.cron-td-id {
    font-family: monospace;
    font-size: 11px;
    color: #9ca3af;
    white-space: nowrap;
}
.rule-name-cell {
    white-space: normal;
    word-break: break-word;
    max-width: 160px;
}
.cron-td-prompt {
    max-width: 220px;
    white-space: pre-wrap;
    word-break: break-word;
}
.cron-td-actions {
    white-space: nowrap;
}
.cron-td-actions button + button {
    margin-left: 6px;
}
.cron-del-btn {
    background: none;
    border: 1px solid #fca5a5;
    color: #ef4444;
    border-radius: 4px;
    padding: 2px 8px;
    font-size: 11px;
    cursor: pointer;
    white-space: nowrap;
}
.cron-del-btn:hover { background: #fee2e2; }
.cron-edit-btn,
.cron-share-btn,
.cron-save-btn {
    background: none;
    border: 1px solid #a5b4fc;
    color: #4f46e5;
    border-radius: 4px;
    padding: 2px 8px;
    font-size: 11px;
    cursor: pointer;
    white-space: nowrap;
}
.cron-edit-btn:hover,
.cron-share-btn:hover,
.cron-save-btn:hover { background: #eef2ff; }
.admin-checkbox-label {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 12px;
    color: #6b7280;
    cursor: pointer;
    margin: 4px 0;
}
.report-badge {
    display: inline-block;
    border-radius: 10px;
    padding: 1px 8px;
    font-size: 10px;
    font-weight: 600;
    white-space: nowrap;
}
.report-badge.public  { background: #d1fae5; color: #065f46; }
.report-badge.private { background: #f3f4f6; color: #6b7280; }
.alert-badge {
    display: inline-block;
    border-radius: 10px;
    padding: 1px 8px;
    font-size: 10px;
    font-weight: 600;
    white-space: nowrap;
    background: #f3f4f6;
    color: #6b7280;
}
.alert-badge.critical { background: #fee2e2; color: #991b1b; }
.alert-badge.warning  { background: #fef3c7; color: #92400e; }
.alert-badge.firing   { background: #fee2e2; color: #991b1b; }
.alert-badge.pending  { background: #fef3c7; color: #92400e; }
.alert-badge.inactive { background: #d1fae5; color: #065f46; }
.alert-badge.disabled { background: #e5e7eb; color: #4b5563; }

.alerts-toolbar {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 8px;
    padding: 10px 0;
    margin-bottom: 8px;
    border-bottom: 1px solid #f3f4f6;
}
.alerts-filter-input,
.alerts-filter-select,
.alerts-filter-date {
    border: 1px solid #d1d5db;
    border-radius: 7px;
    padding: 6px 10px;
    font-size: 12px;
    color: #111827;
    font-family: inherit;
    outline: none;
    background: white;
    transition: border-color 0.2s;
}
.alerts-filter-input { width: 160px; }
.alerts-filter-date { width: 90px; }
.alerts-filter-input:focus,
.alerts-filter-select:focus,
.alerts-filter-date:focus { border-color: #667eea; box-shadow: 0 0 0 2px rgba(102,126,234,0.1); }
.alerts-filter-date-sep { color: #9ca3af; font-size: 12px; }
.alerts-toolbar-btn { width: auto; padding: 6px 12px; font-size: 12px; }
.alerts-toolbar-spacer { flex: 1; }
.alerts-filter-status-group {
    display: flex;
    align-items: center;
    gap: 10px;
    border: 1px solid #d1d5db;
    border-radius: 7px;
    padding: 6px 10px;
    background: white;
    font-size: 12px;
    color: #111827;
}
.alerts-filter-status-group label {
    display: flex;
    align-items: center;
    gap: 4px;
    white-space: nowrap;
    cursor: pointer;
}
.alerts-filter-status-group input[type="checkbox"] { cursor: pointer; }

.alert-rule-annotations-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
}
.alert-rule-field-label { font-size: 12px; color: #6b7280; }
.alerts-auto-refresh-label { font-size: 12px; color: #6b7280; white-space: nowrap; }

.reports-pagination {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 12px;
    padding: 10px 0 2px;
}
.reports-page-info { font-size: 12px; color: #6b7280; }
.saved-plan-reports-list { list-style: none; margin: 0; padding: 0; }
.saved-plan-reports-list li {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 8px 0;
    border-bottom: 1px solid #f3f4f6;
}
.saved-plan-reports-list li:last-child { border-bottom: none; }
.saved-plan-reports-list a {
    font-family: 'SF Mono', 'Fira Code', Consolas, monospace;
    font-size: 12px;
    color: #4f46e5;
    text-decoration: none;
}
.saved-plan-reports-list a:hover { text-decoration: underline; }
.cron-cancel-btn {
    background: none;
    border: 1px solid #d1d5db;
    color: #6b7280;
    border-radius: 4px;
    padding: 2px 8px;
    font-size: 11px;
    cursor: pointer;
    white-space: nowrap;
}
.cron-cancel-btn:hover { background: #f3f4f6; }

/* ── Chat chart thumbnails + lightbox modal (add-chat-query-charts) ────────── */
/* .chat-chart-grid wraps every chart belonging to one step (see worker's
   chartGridBlock) — a plain <img> on its own line would each land in its own
   markdown paragraph and stack one per row; the <div> wrapper is what lets
   them lay out as a wrapping grid of small thumbnails instead. */
.chat-chart-grid {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin: 8px 0;
}
.markdown-body img[data-chart-key] {
    display: block;
    flex: 0 0 150px;
    width: 150px;
    height: 86px;
    object-fit: contain;
    padding: 2px;
    box-sizing: border-box;
    border: 1px solid #e5e7eb;
    border-radius: 6px;
    cursor: pointer;
    background: #f9fafb;
}
.markdown-body img[data-chart-key]:hover { border-color: #667eea; }

.chat-chart-modal {
    position: fixed;
    inset: 0;
    z-index: 1000;
    display: flex;
    align-items: center;
    justify-content: center;
}
.chat-chart-modal-backdrop {
    position: absolute;
    inset: 0;
    background: rgba(17, 24, 39, 0.6);
}
.chat-chart-modal-body {
    position: relative;
    z-index: 1;
    background: white;
    border-radius: 12px;
    padding: 20px;
    max-width: min(90vw, 900px);
    max-height: 90vh;
    display: flex;
    flex-direction: column;
    gap: 14px;
    box-shadow: 0 12px 40px rgba(0,0,0,0.25);
}
.chat-chart-modal-close {
    position: absolute;
    top: 8px;
    right: 8px;
    border: none;
    background: none;
    font-size: 22px;
    line-height: 1;
    color: #6b7280;
    cursor: pointer;
    padding: 4px 8px;
}
.chat-chart-modal-close:hover { color: #111827; }
.chat-chart-modal-img {
    max-width: 100%;
    max-height: 70vh;
    object-fit: contain;
    border-radius: 6px;
}
.chat-chart-modal-footer {
    display: flex;
    justify-content: flex-end;
}

/* "建立 Dashboard" button under chart-bearing assistant messages */
.chat-dashboard-builder-btn {
    margin-top: 8px;
    padding: 5px 10px;
    font-size: 12px;
    border: 1px solid #d1d5db;
    border-radius: 6px;
    background: white;
    color: #4b5563;
    cursor: pointer;
}
.chat-dashboard-builder-btn:hover { background: #f3f4f6; border-color: #9ca3af; }

.chat-dashboard-modal {
    position: fixed;
    inset: 0;
    z-index: 1000;
    display: flex;
    align-items: center;
    justify-content: center;
}
.chat-dashboard-modal-backdrop {
    position: absolute;
    inset: 0;
    background: rgba(17, 24, 39, 0.6);
}
.chat-dashboard-modal-body {
    position: relative;
    z-index: 1;
    background: white;
    border-radius: 12px;
    padding: 20px;
    width: min(90vw, 480px);
    max-height: 90vh;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 14px;
    box-shadow: 0 12px 40px rgba(0,0,0,0.25);
}
.chat-dashboard-modal-close {
    position: absolute;
    top: 8px;
    right: 8px;
    border: none;
    background: none;
    font-size: 22px;
    line-height: 1;
    color: #6b7280;
    cursor: pointer;
    padding: 4px 8px;
}
.chat-dashboard-modal-close:hover { color: #111827; }
.chat-dashboard-modal-footer {
    display: flex;
    justify-content: flex-end;
    gap: 8px;
}
.chat-dashboard-chart-list {
    list-style: none;
    margin: 0;
    padding: 0;
    display: flex;
    flex-direction: column;
    gap: 6px;
    max-height: 240px;
    overflow-y: auto;
}
.chat-dashboard-chart-list li {
    border: 1px solid #e5e7eb;
    border-radius: 6px;
    padding: 6px 10px;
    font-size: 12px;
}
.chat-dashboard-chart-list-title {
    font-weight: 600;
    color: #374151;
}
.chat-dashboard-chart-list-query {
    font-family: monospace;
    color: #6b7280;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* ── LLM 用量 (add-llm-observability-tracing) ─────────────────────────── */
.usage-controls { align-items: center; }
.usage-groupby { display: flex; gap: 6px; }
.usage-note { font-size: 12px; color: #6b7280; margin: 6px 0; }
.usage-totals { display: flex; flex-wrap: wrap; gap: 12px; margin: 10px 0; }
.usage-totals .usage-note { flex-basis: 100%; margin: 0; }
.usage-stat { display: flex; flex-direction: column; min-width: 130px; padding: 10px 14px; border: 1px solid #e5e7eb; border-radius: 8px; background: #fafafa; }
.usage-stat span { font-size: 12px; color: #6b7280; }
.usage-stat strong { font-size: 18px; margin-top: 2px; }
.usage-chart-wrap { position: relative; height: 220px; margin: 10px 0; }

/* ── Source tabs and access badges (add-resource-access-source) ───────── */
.source-tabs {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 4px;
    margin: 0 0 8px;
}
.source-tab {
    padding: 3px 10px;
    border: 1px solid #d1d5db;
    border-radius: 999px;
    background: #fff;
    color: #374151;
    font-size: 12px;
    cursor: pointer;
}
.source-tab:hover { background: #f3f4f6; }
.source-tab.active { background: #4338ca; border-color: #4338ca; color: #fff; }
.source-group-select {
    padding: 3px 6px;
    border: 1px solid #d1d5db;
    border-radius: 6px;
    font-size: 12px;
    background: #fff;
}
.access-badges { display: inline-flex; flex-wrap: wrap; gap: 4px; margin-left: 6px; vertical-align: middle; }
.access-badge {
    display: inline-block;
    padding: 1px 7px;
    border-radius: 999px;
    font-size: 10px;
    font-weight: 500;
    background: #f3f4f6;
    color: #4b5563;
    white-space: nowrap;
}
.access-badge.access-self { background: #ecfdf5; color: #065f46; }
.access-badge.access-user { background: #eff6ff; color: #1d4ed8; }
.access-badge.access-group { background: #f5f3ff; color: #6d28d9; }
.access-badge.access-org { background: #fffbeb; color: #92400e; }
.access-badge.access-org_admin { background: #fef2f2; color: #991b1b; }

/* Inside the dark side panel (knowledge bases, dashboards, chat sessions). */
.side-panel .source-tabs { margin: 4px 10px 6px; }
.side-panel .source-tab {
    padding: 2px 8px;
    font-size: 11px;
    border-color: rgba(255,255,255,0.15);
    background: transparent;
    color: rgba(255,255,255,0.65);
}
.side-panel .source-tab:hover { background: rgba(255,255,255,0.08); }
.side-panel .source-tab.active { background: rgba(99,102,241,0.6); border-color: transparent; color: #fff; }
.side-panel .source-group-select {
    width: 100%;
    background: rgba(255,255,255,0.08);
    border-color: rgba(255,255,255,0.15);
    color: #fff;
    font-size: 11px;
}
.access-badges.compact { display: flex; margin: 3px 0 0; flex-basis: 100%; }
.side-panel .access-badge { background: rgba(255,255,255,0.1); color: rgba(255,255,255,0.7); font-size: 9px; }
.rag-domain-item:has(.access-badges.compact) { flex-wrap: wrap; }

/* ─── Loading feedback (loading.js) ─────────────────────────────────────────
   .spinner: an inline ring in the current text color.
   .global-loading: the page-level "載入中…" pill while any request is in flight.
   .is-busy: the button whose click started the request in flight. */

.spinner {
    display: inline-block;
    width: 12px;
    height: 12px;
    margin-right: 6px;
    vertical-align: -2px;
    border: 2px solid currentColor;
    border-right-color: transparent;
    border-radius: 50%;
    opacity: 0.8;
    animation: spin 0.7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.global-loading {
    position: fixed;
    top: 10px;
    left: 50%;
    transform: translateX(-50%);
    z-index: 10000;
    display: flex;
    align-items: center;
    padding: 6px 14px;
    border-radius: 999px;
    background: rgba(17, 24, 39, 0.88);
    color: #fff;
    font-size: 12px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.25);
    pointer-events: none;
}

button.is-busy { cursor: progress; }
button.is-busy::before {
    content: '';
    display: inline-block;
    width: 10px;
    height: 10px;
    margin-right: 6px;
    vertical-align: -1px;
    border: 2px solid currentColor;
    border-right-color: transparent;
    border-radius: 50%;
    animation: spin 0.7s linear infinite;
}

@media (prefers-reduced-motion: reduce) {
    .spinner, button.is-busy::before { animation-duration: 2s; }
}
