:root {
    --bg-0: #090b11;
    --bg-1: #13151a;
    --surface-0: rgba(255, 255, 255, 0.03);
    --surface-1: rgba(255, 255, 255, 0.04);
    --surface-2: rgba(255, 255, 255, 0.05);
    --surface-3: rgba(255, 255, 255, 0.06);
    --surface-4: rgba(255, 255, 255, 0.1);

    --text: #ffffff;
    --text-muted-1: #e0e6ed;
    --text-muted-2: #a9b4c2;

    --primary: #7928ca;
    --accent: #ff0080;

    --border-1: rgba(255, 255, 255, 0.08);
    --border-2: rgba(255, 255, 255, 0.12);
    --border-3: rgba(255, 255, 255, 0.16);
    --border-4: rgba(255, 255, 255, 0.24);

    --shadow-glow-1: rgba(192, 219, 255, 0.48);
    --shadow-glow-2: rgba(192, 219, 255, 0.6);
    --shadow-accent: rgba(255, 0, 128, 0.5);
    --card-shadow: rgba(0, 0, 0, 0.35);
    --card-shadow-hover: rgba(0, 0, 0, 0.45);

    --error: #ff4757;
    --error-1: rgba(255, 107, 107, 0.12);
    --error-2: rgba(255, 107, 107, 0.18);
    --error-3: rgba(255, 107, 107, 0.35);
    --error-4: rgba(255, 71, 87, 0.5);
    --error-5: rgba(255, 71, 87, 0.6);
    --error-6: rgba(255, 71, 87, 0.7);
    --error-text-1: #ffd7d7;
    --error-text-2: #ffecec;
    --error-on: #0b0f16;

    --radius-s: 8px;
    --radius-m: 10px;
    --radius-l: 14px;

    --pad-s: 0.5rem;
    --pad-m: 0.75rem;
    --pad-l: 1rem;

    --gradient-primary: linear-gradient(to right, var(--text), var(--primary));
    --gradient-cta: linear-gradient(to right, var(--primary), var(--accent));
    --app-bg: radial-gradient(circle at center, var(--bg-1), var(--bg-0));
}

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

body {
    background: var(--app-bg);
    color: var(--text);
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
    min-height: 100vh;
}

.container {
    padding: 2rem;
    max-width: 1200px;
    margin: 0 auto;
}

.hero {
    margin-bottom: 4rem;
}

h1 {
    font-size: 4.5rem;
    font-weight: 800;
    background: var(--gradient-primary);
    -webkit-background-clip: text;
    background-clip: text;
    color: transparent;
    margin-bottom: 1.5rem;
    text-shadow: 0 0 80px var(--shadow-glow-1);
    animation: glow 4s ease-in-out infinite;
}

.subtitle {
    font-size: 1.5rem;
    color: var(--text-muted-2);
    max-width: 600px;
    margin: 0 auto;
    line-height: 1.6;
}

.cta-button {
    display: inline-block;
    padding: 1rem 2rem;
    margin-top: 2rem;
    font-size: 1.1rem;
    font-weight: 600;
    color: var(--text);
    background: var(--gradient-cta);
    border: none;
    border-radius: var(--radius-s);
    cursor: pointer;
    transition: all 0.3s ease;
    text-decoration: none;
}

.cta-button:hover {
    transform: translateY(-2px);
    box-shadow: 0 0 30px var(--shadow-accent);
}

.features {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
    gap: 2rem;
    margin-top: 4rem;
}

.feature-card {
    background: var(--surface-2);
    padding: 2rem;
}

@keyframes glow {
    0%, 100% {
        text-shadow: 0 0 80px var(--shadow-glow-1);
    }
    50% {
        text-shadow: 0 0 100px var(--shadow-glow-2);
    }
}

/* Top navigation bar */
.topbar {
    width: 100%;
    background: var(--surface-2);
    border-bottom: 1px solid var(--border-1);
    backdrop-filter: blur(6px);
    position: sticky;
    top: 0;
    z-index: 50;
}

.nav {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0.75rem 2rem;
    max-width: 1200px;
    margin: 0 auto;
}

.brand {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    color: var(--text);
    text-decoration: none;
    font-weight: 700;
    letter-spacing: 0.3px;
}

.brand-title {
    font-size: 1.25rem;
    background: var(--gradient-primary);
    -webkit-background-clip: text;
    background-clip: text;
    color: transparent;
}

.nav-links {
    display: flex;
    align-items: center;
    gap: 0.25rem;
}

.nav-link {
    color: var(--text);
    text-decoration: none;
    padding: 0.5rem 0.75rem;
    border-radius: var(--radius-s);
    transition: background 0.2s ease, color 0.2s ease;
}

.nav-link:hover,
.dropdown-item:hover {
    background: var(--surface-3);
    color: var(--text);
}

/* Dropdown */
.dropdown {
    position: relative;
}

.dropdown-toggle::after {
    content: "";
    display: inline-block;
    margin-left: 0.5rem;
    border: 5px solid transparent;
    border-top-color: var(--text-muted-1);
    transform: translateY(2px);
}

.dropdown-menu {
    position: absolute;
    top: calc(100% + 0.25rem);
    left: 0;
    background: var(--surface-2);
    border: 1px solid var(--border-1);
    border-radius: var(--radius-m);
    min-width: 220px;
    padding: 0.5rem;
    display: none;
}

.dropdown:focus-within .dropdown-menu,
.dropdown:hover .dropdown-menu {
    display: block;
}

.dropdown-item {
    display: block;
    color: var(--text-muted-1);
    text-decoration: none;
    padding: 0.5rem 0.75rem;
    border-radius: var(--radius-s);
}

.auth {
    display: flex;
    align-items: center;
    gap: 0.25rem;
}

/* Table styles */
.grid-table {
    width: 100%;
    border-collapse: collapse;
    margin-top: 1rem;
    margin-bottom: 1rem;
    background: var(--surface-2);
    border-radius: var(--radius-s);
    overflow: hidden; /* Ensures the border-radius is applied to the table corners */
}

.grid-table th,
.grid-table td {
    padding: 1rem 1.5rem;
    text-align: left;
    border-bottom: 1px solid var(--border-1);
}

.grid-table thead tr {
    background: var(--surface-0);
}

.grid-table th {
    font-weight: 600;
    color: var(--text-muted-1);
    font-size: 0.85rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.grid-table tbody tr:last-child td {
    border-bottom: none;
}

.grid-table tbody tr:hover {
    background: var(--surface-1);
}

/* Error row highlight for grids */
.grid-table tbody tr.grid-row.row-error {
    /* use design tokens only; subtle emphasis with good contrast on dark bg */
    background: var(--error-6);
    border-left: 3px solid var(--error-3);
}

.grid-table tbody tr.grid-row.row-error:hover {
    background: var(--error-5);
    border-left-color: var(--error-4);
}

/* actions */
.actions {
    display: flex;
    gap: 0.5rem;
    align-items: center;
    flex-wrap: nowrap;
}

.inline-delete {
    display: inline-block;
    margin: 0;
}

/* Form styles */

.select-inline-wrapper {
    position: relative;
    display: inline-block;
    width: auto;
    min-width: 250px;
    margin: 0;
}

.select-wrapper {
    position: relative;
    display: block;
    width: 100%;
    min-width: 250px;
    margin: 0;
}

.select-wrapper::after {
    content: '';
    position: absolute;
    top: 50%;
    right: 1rem;
    transform: translateY(-50%);
    width: 0;
    height: 0;
    border-left: 5px solid transparent;
    border-right: 5px solid transparent;
    border-top: 6px solid var(--text-muted-1);
    pointer-events: none;
}

.form-select {
    width: 100%;
    margin-bottom: 1rem;
    -webkit-appearance: none;
    -moz-appearance: none;
    appearance: none;
    background-color: var(--surface-2);
    border: 1px solid var(--border-1);
    border-radius: var(--radius-s);
    color: var(--text-muted-1);
    padding: 0.65rem 2.25rem 0.65rem 0.9rem;
    cursor: pointer;
    line-height: 1.2;
    background-clip: padding-box; /* ensure rounded corners clip background */
}

.form-select option {
    background: var(--bg-0);
    color: var(--text-muted-1);
}

/* Improve select dropdown visual integration
   - Keep the options list from visually overlapping the rounded select
   - When focused (dropdown typically open), square off bottom corners so the list appears attached
   - Raise stacking context slightly to avoid neighboring overlaps */
.select-wrapper {
    z-index: 1;
}

.select-wrapper:has(.form-select:focus) {
    z-index: 20;
}

.select-wrapper:has(.form-select:focus) .form-select {
    border-bottom-left-radius: 0;
    border-bottom-right-radius: 0;
}

/* If a select is rendered to open upward (some OS/browser behaviors),
   slightly reduce top radii on focus to minimize apparent overlap with the popup list. */
.form-select:focus {
    outline: none;
    border-color: var(--border-3);
    background: var(--surface-3);
    box-shadow: 0 0 0 3px color-mix(in oklab, var(--primary) 25%, transparent);
}

.filter-form {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    margin-top: 1rem;
    margin-bottom: 1.25rem;
    flex-wrap: wrap;
}

/* Two-column filter layout for pages with many filters */
.filter-form.filter-2col {
    display: grid;
    grid-template-columns: 1fr 1fr; /* two equal columns */
    gap: 0.75rem 0.75rem;
    align-items: end; /* align controls to their bottoms for neat rows */
}

.filter-form.filter-2col > * {
    min-width: 0; /* allow children to shrink within columns */
}

/* Place the action buttons in the second column on the last row */
.filter-form.filter-2col .form-group-buttons {
    justify-self: start; /* align with left edge of column */
    align-self: end;
}

@media (max-width: 720px) {
    .filter-form.filter-2col {
        grid-template-columns: 1fr; /* stack on small screens */
    }

    .filter-form.filter-2col .form-group-buttons {
        justify-self: start;
    }
}

/* Form controls */
.form-group {
    margin-bottom: 1rem;
}

label {
    display: inline-block;
    margin-bottom: 0.35rem;
    color: var(--text);
    font-weight: 600;
    font-size: 0.95rem;
}

/* Text inputs */
input[type="text"],
input[type="email"],
input[type="password"],
input[type="search"],
input[type="url"],
input[type="number"],
textarea,
.form-control {
    width: 100%;
    background: var(--surface-2);
    color: var(--text);
    border: 1px solid var(--border-1);
    border-radius: var(--radius-s);
    padding: var(--pad-m) var(--pad-l);
    outline: none;
    transition: border-color 0.15s ease, background 0.15s ease, box-shadow 0.15s ease;
}

input::placeholder,
textarea::placeholder {
    color: var(--text-muted-2);
}

input:focus,
textarea:focus,
.form-control:focus {
    border-color: var(--border-3);
    background: var(--surface-3);
    box-shadow: 0 0 0 3px color-mix(in oklab, var(--primary) 25%, transparent);
}

/* Validation/error state helpers (optional) */
.input-error {
    border-color: var(--error-4) !important;
    background: var(--error-1) !important;
    box-shadow: 0 0 0 3px color-mix(in oklab, var(--error) 25%, transparent) !important;
}

/* Checkbox */
.form-check {
    display: flex;
    align-items: center;
    gap: 0.6rem;
    margin: 0.5rem 0;
}

.form-check-input {
    appearance: none;
    -webkit-appearance: none;
    width: 1.05rem;
    height: 1.05rem;
    margin-bottom: 0.5rem;
    border: 1px solid var(--border-2);
    border-radius: 4px;
    background: var(--surface-2);
    display: inline-grid;
    place-content: center;
    cursor: pointer;
    transition: background 0.15s ease, border-color 0.15s ease, box-shadow 0.15s ease;
    /*margin: 0; !* remove default checkbox bottom offset to align with label *!*/
}

.form-check-input:focus {
    outline: none;
    border-color: var(--border-3);
    box-shadow: 0 0 0 3px color-mix(in oklab, var(--primary) 25%, transparent);
}

.form-check-input:checked {
    border-color: color-mix(in oklab, var(--primary) 60%, transparent);
    background: color-mix(in oklab, var(--primary) 35%, transparent);
}

.form-check-input:checked::after {
    content: "";
    width: 0.5rem;
    height: 0.5rem;
    transform: rotate(45deg);
    border-right: 2px solid var(--text);
    border-bottom: 2px solid var(--text);
    margin-top: -1px;
}

.form-check-label {
    color: var(--text-muted-1);
    cursor: pointer;
    user-select: none;
    margin-bottom: 0.5rem;
    margin-top: 3px;
}

/* buttons */
.form-group-buttons {
    padding-bottom: 1rem;
    display: flex;
    gap: 0.5rem;
    align-self: flex-end;
}

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 0.65rem 1.1rem;
    font-size: 0.95rem;
    font-weight: 600;
    color: var(--text);
    border: 1px solid var(--border-3);
    border-radius: var(--radius-s);
    cursor: pointer;
    transition: background 0.2s ease, border-color 0.2s ease, transform 0.1s ease;
    text-decoration: none;
    background-color: var(--surface-3);
}

.btn:hover {
    background-color: var(--surface-4);
    border-color: var(--border-4);
}

.btn-primary {
    background: color-mix(in oklab, var(--primary) 25%, transparent);
    border-color: color-mix(in oklab, var(--primary) 35%, transparent);
}

.btn-primary:hover {
    background: color-mix(in oklab, var(--primary) 35%, transparent);
    border-color: color-mix(in oklab, var(--primary) 50%, transparent);
    transform: translateY(-1px);
}

.btn-danger {
    background: color-mix(in oklab, var(--error) 25%, transparent);
    border-color: color-mix(in oklab, var(--error) 35%, transparent);
}

.btn-danger:hover {
    background: color-mix(in oklab, var(--error) 35%, transparent);
    border-color: color-mix(in oklab, var(--error) 50%, transparent);
    transform: translateY(-1px);
}

/* Modal */
.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.75);
    backdrop-filter: blur(4px);
    z-index: 1000;
    display: none; /* hidden by default to satisfy strict CSP (no inline styles) */
    align-items: center;
    justify-content: center;
    opacity: 0;
    transition: opacity 0.2s ease;
}

.modal-overlay.open {
    display: flex; /* shown via JS by toggling class, not inline style */
}

.modal-overlay.show {
    opacity: 1;
}

.modal-dialog {
    background: var(--surface-2);
    border: 1px solid var(--border-2);
    border-radius: var(--radius-l);
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.5);
    max-width: 480px;
    width: 90%;
    transform: scale(0.95) translateY(-20px);
    transition: transform 0.2s ease;
}

.modal-overlay.show .modal-dialog {
    transform: scale(1) translateY(0);
}

.modal-header {
    padding: 1.25rem 1.5rem;
    border-bottom: 1px solid var(--border-1);
}

.modal-header h3 {
    font-size: 1.25rem;
    font-weight: 700;
    color: var(--text);
    margin: 0;
    text-transform: none;
}

.modal-body {
    padding: 1.5rem;
}

.modal-body p {
    color: var(--text-muted-1);
    line-height: 1.6;
    margin: 0;
}

.modal-footer {
    padding: 1rem 1.5rem;
    border-top: 1px solid var(--border-1);
    display: flex;
    justify-content: flex-end;
    gap: 0.75rem;
}

/* Dashboard */
section {
    display: grid;
    grid-template-columns: 1fr;
    gap: 1.5rem;
}

.grid {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 1rem;
}

@media (max-width: 1100px) {
    .grid {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }
}

@media (max-width: 640px) {
    .grid {
        grid-template-columns: 1fr;
    }
}

/* Card */
.card {
    position: relative;
    background: var(--surface-2);
    border: 1px solid var(--border-1);
    border-radius: var(--radius-l);
    padding: 1.25rem 1.25rem;
    box-shadow: 0 10px 30px var(--card-shadow);
    backdrop-filter: blur(6px);
    transition: transform 0.2s ease, box-shadow 0.2s ease, border-color 0.2s ease, background 0.2s ease;
}

.card:hover {
    transform: translateY(-2px);
    border-color: var(--border-2);
    background: var(--surface-3);
    box-shadow: 0 16px 40px var(--card-shadow-hover);
}

/* Card header */
.card h3 {
    font-size: 0.95rem;
    font-weight: 700;
    letter-spacing: 0.02em;
    color: var(--text-muted-1);
    text-transform: uppercase;
    margin-bottom: 0.5rem;
}

/* Grid metric item style */
.grid-item p {
    font-size: 2rem;
    font-weight: 800;
    line-height: 1.1;
    background: var(--gradient-primary);
    -webkit-background-clip: text;
    background-clip: text;
    color: transparent;
    text-shadow: 0 0 30px rgba(192, 219, 255, 0.25);
}

/* Accent/error text */
.text-red {
    color: var(--error-3);
}

/* Chart container inside a card */
#latency-chart {
    border-radius: var(--radius-m);
    background: var(--surface-1);
    border: 1px dashed var(--border-1);
}

/* Tables inside cards */
.card table {
    width: 100%;
    border-collapse: collapse;
    margin-top: 0.75rem;
    background: var(--surface-1);
    border-radius: var(--radius-m);
    overflow: hidden;
}

.card thead tr {
    background: var(--surface-2);
}

.card th,
.card td {
    padding: 0.9rem 1rem;
    text-align: left;
    border-bottom: 1px solid var(--border-1);
}

.card th {
    font-weight: 600;
    color: var(--text-muted-2);
    font-size: 0.8rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.card tbody tr:last-child td {
    border-bottom: none;
}

.card tbody tr:hover {
    background: var(--surface-2);
}

/* Error alert */
.alert {
    margin: 1rem 0 1.5rem;
    padding: 0.9rem 1rem;
    border-radius: var(--radius-m);
    border: 1px solid var(--error-3);
    background: var(--error-1);
    color: var(--error-text-1);
    box-shadow: 0 6px 20px var(--error-2);
}

.alert-error {
    border-color: var(--error-4);
    background: linear-gradient(180deg, var(--error-2), color-mix(in oklab, var(--error-2) 55%, transparent));
    color: var(--error-text-2);
}

.alert a {
    color: var(--text);
    text-decoration: underline;
}

.alert-error::before {
    content: "!";
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 1.25rem;
    height: 1.25rem;
    margin-right: 0.5rem;
    border-radius: 50%;
    background: var(--error);
    color: var(--error-on);
    font-weight: 900;
    box-shadow: 0 0 12px var(--error-5);
}

.field-error {
    margin-top: 0.35rem;
    font-size: 0.875rem;
    color: var(--error);
    line-height: 1.4;
}

/* Grid details/expand styles */
.col-expand {
    width: 42px;
    padding-right: 0.75rem;
}

.sr-only {
    position: absolute !important;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}

.btn-icon {
    width: 28px;
    height: 28px;
    padding: 0;
    border-radius: 50%;
    display: inline-flex;
    align-items: center;
    justify-content: center;
}

.btn-toggle {
    background-color: var(--surface-3);
    border: 1px solid var(--border-2);
}

.btn-toggle:hover {
    background-color: var(--surface-4);
    border-color: var(--border-3);
}

.btn-toggle .chevron {
    position: relative;
    width: 0.5rem;
    height: 0.5rem;
    border-right: 2px solid var(--text-muted-1);
    border-bottom: 2px solid var(--text-muted-1);
    transform: rotate(-45deg);
    transition: transform 0.15s ease, border-color 0.15s ease;
}

.btn-toggle.open .chevron {
    transform: rotate(45deg);
    border-color: var(--text);
}

.details-row td {
    padding: 0;
    background: var(--surface-1);
    border-bottom: 1px solid var(--border-1);
}

.details-card {
    margin: 0.75rem 1rem 1rem 3.25rem;
    background: var(--surface-2);
    border: 1px solid var(--border-1);
    border-radius: var(--radius-m);
    box-shadow: 0 10px 24px var(--card-shadow);
}

.details-title {
    padding: 0.65rem 0.9rem;
    font-size: 0.8rem;
    font-weight: 700;
    color: var(--text-muted-2);
    border-bottom: 1px solid var(--border-1);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    background: var(--surface-2);
}

.json-view {
    margin: 0;
    padding: 0.9rem 1rem;
    color: var(--text);
    background: var(--surface-1);
    font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace;
    font-size: 0.875rem;
    line-height: 1.5;
    white-space: pre-wrap;
    word-wrap: break-word;
}

.page-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    margin: 1rem 0;
}

.h-200 { height: 200px; }

/* ----------------------------------------------
   Dashboard utilities (moved from inline styles)
   ---------------------------------------------- */

/* Utility to trim long text in table cells but show full on hover via title */
.truncate {
    display: inline-block;
    max-width: 32rem; /* ~512px, adjust as needed */
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    vertical-align: bottom;
}

/* Keep specific tables to a single visual row per item */
table.single-line-rows {
    table-layout: fixed; /* ensures truncation works predictably */
    width: 100%;
}
table.single-line-rows th,
table.single-line-rows td {
    white-space: nowrap;      /* prevent wrapping to next line */
    overflow: hidden;         /* hide overflowed text */
    text-overflow: ellipsis;  /* show ellipsis when clipped */
    vertical-align: middle;   /* keep content centered vertically */
}

/* Narrow, right-aligned Copy column in Application Errors table */
table.app-errors th.col-copy,
table.app-errors td.col-copy {
    width: 8%;          /* shrink to intrinsic content width */
    min-width: 80px;    /* keep button usable */
}

/* Make the copy button compact within its cell */
table.app-errors .btn-copy {
    padding: 0.2rem 0.5rem;
    font-size: 0.85rem;
}

.sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    border: 0;
}