:root {
    --bg: #f5f6f8;
    --card: #ffffff;
    --border: #e2e5ea;
    --accent: #0b5fff;
    --text: #1b1f24;
    --muted: #5b6370;
}

* { box-sizing: border-box; }

body {
    margin: 0;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    background: var(--bg);
    color: var(--text);
    /* Column flex so .site-footer sits at the bottom of the viewport on short pages
       instead of floating directly under the content. */
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

.site-header {
    background: var(--card);
    border-bottom: 1px solid var(--border);
    padding: 0 24px;
    height: 56px;
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.site-header .brand {
    font-weight: 700;
    color: var(--text);
    text-decoration: none;
    font-size: 1.05rem;
}

.user-menu {
    display: flex;
    align-items: center;
    gap: 16px;
}

.user-name {
    color: var(--muted);
    font-size: 0.9rem;
}

.admin-link {
    color: var(--accent);
    text-decoration: none;
    font-size: 0.9rem;
}

.admin-link:hover {
    text-decoration: underline;
}

.sign-out {
    color: var(--accent);
    text-decoration: none;
    font-size: 0.9rem;
}

.sign-out:hover {
    text-decoration: underline;
}

.icon-button {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    background: none;
    border: none;
    color: var(--accent);
    padding: 0.25rem;
    cursor: pointer;
    border-radius: 4px;
}

.icon-button:hover {
    background: color-mix(in srgb, var(--accent) 15%, transparent);
}

.icon-button-danger {
    color: #c0392b;
}

.icon-button-danger:hover {
    background: color-mix(in srgb, #c0392b 15%, transparent);
}

.inline-form {
    display: inline-block;
}

.form-error {
    color: #c0392b;
    font-size: 0.9rem;
    margin: 0 0 12px;
}

.container {
    max-width: 860px;
    margin: 0 auto;
    padding: 32px 24px;
    /* Absorbs the leftover height so the footer is pushed down, and no further. */
    flex: 1 0 auto;
    width: 100%;
}

.container.utility-full-bleed {
    max-width: none;
    margin: 0;
    padding: 0;
}

/* Opt-in wider container for content-dense admin pages (e.g. the Data Browser grid) that
   need more horizontal room than the framework's default reading-width container, without
   going fully edge-to-edge like .utility-full-bleed. */
.container.container-wide {
    max-width: 1600px;
}

/* Opt-in mid-width container: room for a four-card grid without stretching across a large
   monitor (the home page). */
.container.container-medium {
    max-width: 1200px;
}

/* Opt-in vertical-fill container for a page whose main content should stretch to use the
   remaining viewport height (down to the same bottom buffer .container already gives it via
   its own padding), scrolling internally once it runs out of room, instead of growing the
   whole page and pushing the footer down. Only affects a direct child that itself opts in via
   .data-browser-section (or a similar page-specific class) -- other .container children (e.g.
   pages without this modifier) are unaffected. */
.container.container-fill-height {
    display: flex;
    flex-direction: column;
    min-height: 0;
}

h1 { margin-top: 0; }

.lead { color: var(--muted); }

.category h2 {
    font-size: 0.85rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--muted);
    margin: 28px 0 12px;
}

.utility-list {
    list-style: none;
    margin: 0;
    padding: 0;
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
    grid-auto-rows: auto;
    align-items: stretch;
    gap: 12px;
}

/* Home page: four cards across on wide screens, stepping down on narrower ones. */
.utility-list.utility-list-four {
    grid-template-columns: repeat(4, minmax(0, 1fr));
}

@media (max-width: 1100px) {
    .utility-list.utility-list-four {
        grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
    }
}

.utility-card {
    height: 100%;
}

.utility-card a {
    display: flex;
    align-items: flex-start;
    gap: 12px;
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 16px;
    text-decoration: none;
    color: inherit;
    transition: border-color 0.15s, box-shadow 0.15s;
    height: 100%;
}

.utility-icon {
    flex: 0 0 auto;
    width: 32px;
    height: 32px;
    border-radius: 6px;
}

.utility-text {
    min-width: 0;
}

.utility-card a:hover {
    border-color: var(--accent);
    box-shadow: 0 2px 10px rgba(11, 95, 255, 0.08);
}

.utility-name {
    display: block;
    font-weight: 600;
    margin-bottom: 4px;
}

.utility-desc {
    display: block;
    color: var(--muted);
    font-size: 0.9rem;
}

.empty { color: var(--muted); }

.site-footer {
    border-top: 1px solid var(--border);
    background: var(--card);
    padding: 12px 24px;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    font-size: 0.8rem;
    color: var(--muted);
}

.site-footer a {
    color: var(--muted);
    text-decoration: none;
    font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
    border-bottom: 1px dotted var(--border);
}

.site-footer a:hover {
    color: var(--accent);
}

.footer-separator {
    opacity: 0.6;
}

.sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border-width: 0;
}

.secrets-layout {
    display: flex;
    align-items: flex-start;
    gap: 32px;
}

.secrets-list-panel {
    flex: 1 1 auto;
    min-width: 0;
    max-height: 480px;
    overflow-y: auto;
}

.secrets-list-panel table {
    width: 100%;
}

/* A long, unbroken secret name wraps within its own column instead of forcing the
   row wider and squeezing the actions column into wrapping onto a second line. */
.secrets-list-panel td:first-child {
    word-break: break-all;
    overflow-wrap: anywhere;
}

.secret-actions-cell {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-wrap: nowrap;
}

.secret-save-form {
    display: flex;
    align-items: center;
    gap: 4px;
    min-width: 0;
    flex: 1 1 auto;
}

.secret-save-form input[type="password"] {
    min-width: 0;
    flex: 1 1 auto;
}

.secret-actions-cell .icon-button {
    flex-shrink: 0;
}

.add-secret-panel {
    flex: 0 0 260px;
}

/* Scoped to .admin-section (not a bare `section` selector) -- the launcher page's title
   cards (Index.cshtml) also use <section class="category">, and an unscoped `section`
   rule here bled its border/background/padding onto them too. */
.admin-section {
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 20px;
    margin-bottom: 20px;
}

.admin-section h2 {
    margin-top: 0;
    font-size: 1.1rem;
    margin-bottom: 16px;
}

.admin-section h3 {
    font-size: 1rem;
    margin-top: 16px;
    margin-bottom: 12px;
}

.admin-section .data-browser-results {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

/* Lets the results block (and its panel below) participate in the fill-height layout when
   this section is inside a .container-fill-height container -- a plain .admin-section on other
   admin pages (which don't opt into fill-height) is unaffected, since these rules only trigger
   inside that ancestor. min-height: 0 is required on every link in this flex chain, or a flex
   item's default min-height: auto keeps it (and its overflowing content) from ever shrinking
   below its content size, defeating the inner scrollbar. */
.container-fill-height .data-browser-section {
    display: flex;
    flex-direction: column;
    flex: 1 1 auto;
    min-height: 0;
}

.container-fill-height .data-browser-section .data-browser-results {
    flex: 1 1 auto;
    min-height: 0;
}

.admin-section .data-browser-results-summary {
    display: flex;
    align-items: center;
    gap: 12px;
    color: var(--muted);
    font-size: 0.9rem;
}

.admin-section .data-browser-results-panel {
    min-width: 0;
    overflow-x: auto;
    border: 1px solid var(--border);
    border-radius: 8px;
    background: var(--card);
}

/* Inside the fill-height layout, the panel is the one element that actually grows/shrinks and
   scrolls -- everything else in .data-browser-section (heading, forms, summary, pagination)
   keeps its natural height. */
.container-fill-height .data-browser-section .data-browser-results-panel {
    flex: 1 1 auto;
    min-height: 0;
    overflow-y: auto;
}

.admin-section .data-browser-table {
    width: 100%;
    border-collapse: separate;
    border-spacing: 0;
    min-width: max-content;
}

.admin-section .data-browser-table th,
.admin-section .data-browser-table td {
    padding: 0.75rem 0.9rem;
    text-align: left;
    vertical-align: top;
    border-bottom: 1px solid var(--border);
    white-space: nowrap;
}

.admin-section .data-browser-table thead th {
    position: sticky;
    top: 0;
    z-index: 1;
    background: var(--card);
}

.admin-section .data-browser-table tbody tr:nth-child(even) td {
    background: color-mix(in srgb, var(--bg) 55%, var(--card));
}

.admin-section .data-browser-table tbody tr:last-child td {
    border-bottom: none;
}

.admin-section .data-browser-sort-link {
    display: inline-flex;
    align-items: center;
    gap: 0.35rem;
    color: inherit;
    text-decoration: none;
    font-weight: 600;
}

.admin-section .data-browser-sort-link:hover {
    color: var(--accent);
}

.admin-section .data-browser-sort-link.is-active {
    color: var(--accent);
}

.admin-section .data-browser-sort-indicator {
    font-size: 0.8rem;
    line-height: 1;
}

.admin-section .data-browser-pagination {
    display: flex;
    align-items: center;
    gap: 12px;
    flex-wrap: wrap;
}

.admin-section .data-browser-page-link {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 5.5rem;
    padding: 0.45rem 0.8rem;
    border: 1px solid var(--border);
    border-radius: 999px;
    background: var(--card);
    color: var(--text);
    text-decoration: none;
}

.admin-section .data-browser-page-link:hover {
    border-color: var(--accent);
    color: var(--accent);
}

.admin-section .data-browser-page-link.is-disabled {
    color: var(--muted);
    pointer-events: none;
    background: color-mix(in srgb, var(--bg) 60%, var(--card));
}

.admin-section .data-browser-page-status {
    color: var(--muted);
    font-size: 0.9rem;
}

.admin-section .data-browser-tabs {
    display: flex;
    gap: 0.25rem;
    margin-bottom: 1rem;
    border-bottom: 1px solid var(--border, #ccc);
}

.admin-section .data-browser-tab {
    padding: 0.5rem 1rem;
    text-decoration: none;
    color: var(--muted);
    border-bottom: 2px solid transparent;
    margin-bottom: -1px;
}

.admin-section .data-browser-tab.is-active {
    color: var(--accent);
    border-bottom-color: var(--accent);
    font-weight: 600;
}

.admin-section .data-browser-query {
    margin-top: 0;
}

.admin-section .data-browser-table th button.data-browser-sort-link {
    background: none;
    border: 0;
    padding: 0;
    font: inherit;
    color: inherit;
    cursor: pointer;
}

.admin-section button.data-browser-page-link {
    font: inherit;
    cursor: pointer;
}

.admin-section button.data-browser-page-link:disabled {
    color: var(--muted);
    cursor: default;
}

.admin-section .data-browser-pagination[hidden],
.admin-section .data-browser-table tr[hidden] {
    display: none;
}

.admin-section .data-browser-query-help {
    color: var(--muted);
    font-size: 0.9rem;
}

.admin-section .data-browser-query-text {
    display: block;
    width: 100%;
    box-sizing: border-box;
    margin: 0.25rem 0 0.5rem;
    font-family: ui-monospace, Consolas, monospace;
    font-size: 0.9rem;
}

.null-value {
    color: var(--muted);
    font-style: italic;
}

.admin-section table {
    width: 100%;
    border-collapse: collapse;
}

.admin-section table th,
.admin-section table td {
    text-align: left;
    padding: 8px 12px;
    border-bottom: 1px solid var(--border);
}

.audit-log-search {
    display: flex;
    align-items: center;
    gap: 8px;
    margin: 16px 0;
}

.audit-log-search input[type="search"] {
    flex: 1 1 auto;
    max-width: 320px;
    padding: 6px 10px;
    border: 1px solid var(--border);
    border-radius: 6px;
}

/* Fixed-height scroll panel so a long audit log scrolls within the page instead of
   stretching it -- the header rows (labels + column filters) stay pinned via `sticky`
   so they're always visible while scrolling. Mirrors .secrets-list-panel's pattern. */
.audit-log-table-panel {
    max-height: 480px;
    overflow-y: auto;
    border: 1px solid var(--border);
    border-radius: 6px;
}

.audit-log-table-panel table {
    border-collapse: separate;
    border-spacing: 0;
}

.audit-log-table-panel thead th {
    position: sticky;
    background: var(--card);
    z-index: 1;
}

.audit-log-table-panel thead tr:first-child th {
    top: 0;
}

/* The column-filter row's `top` offset is set inline by wwwroot/js/audit-log.js at runtime
   (measured from the label row's actual height) so it stays correct regardless of font size
   or zoom. */
/* Applied by wwwroot/js/audit-log.js to every header cell of a
   table[data-sortable-searchable] -- clicking toggles sort direction. */
.sortable-column {
    cursor: pointer;
    user-select: none;
    position: relative;
    padding-right: 20px;
}

.sortable-column::after {
    content: "\2195"; /* up-down arrow: neutral, not yet sorted by this column */
    position: absolute;
    right: 6px;
    color: var(--muted);
    opacity: 0.5;
}

.sortable-column.sorted-asc::after {
    content: "\2191"; /* up arrow */
    opacity: 1;
    color: var(--accent);
}

.sortable-column.sorted-desc::after {
    content: "\2193"; /* down arrow */
    opacity: 1;
    color: var(--accent);
}

.column-filters th {
    padding: 4px 8px;
    font-weight: normal;
    /* Cursor/font differ deliberately from .sortable-column above it -- this row filters,
       it never triggers a sort. */
    cursor: default;
}

.column-filter {
    width: 100%;
    padding: 4px 6px;
    font-size: 0.85rem;
    border: 1px solid var(--border);
    border-radius: 4px;
    box-sizing: border-box;
}

.audit-log-pagination {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 16px;
    margin: 16px 0;
    font-size: 0.9rem;
}

.audit-log-pagination-disabled {
    color: var(--muted);
}

/* Administration > Application Insights page. Scoped under .admin-section like the other admin pages;
   the results table reuses the Data Browser's table classes. */
.admin-section .app-insights-query {
    display: block;
    width: 100%;
    box-sizing: border-box;
    margin: 6px 0 12px;
    padding: 8px 10px;
    border: 1px solid var(--border);
    border-radius: 6px;
    font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
    font-size: 0.9rem;
    resize: vertical;
}

.admin-section .app-insights-controls {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 8px;
    margin-bottom: 16px;
}

.admin-section .app-insights-help {
    color: var(--muted);
    font-size: 0.9rem;
}

.admin-section .app-insights-warning {
    margin: 0 0 12px;
    padding: 8px 12px;
    border: 1px solid var(--border);
    border-left: 4px solid #b9770e;
    border-radius: 6px;
    font-size: 0.9rem;
}

.admin-section .app-insights-results-panel {
    max-height: 600px;
    overflow: auto;
}
