/* ============================================================
   Kula Dashboard Styles
   ============================================================ */

/* ---- System information page ----
   Inventory and measured values share one grid. Descriptive text sits at a
   0.75rem floor: the previous 0.6rem metadata was unreadable on phones, and the
   contrast work below is only useful if the type is legible in the first place. */

.dashboard.system-info-active .time-controls,
.dashboard.system-info-active .time-custom-section,
.dashboard.system-info-active .chart-search-input,
.dashboard.system-info-active #btn-pause,
.dashboard.system-info-active #btn-focus,
.dashboard.system-info-active #btn-layout {
    display: none !important;
}

.btn-info.system-info-current {
    color: var(--accent-cyan);
    border-color: var(--accent-cyan);
    background: rgba(6, 182, 212, 0.12);
    box-shadow: 0 0 12px rgba(6, 182, 212, 0.12);
}

.system-info-page {
    min-height: calc(100dvh - 4rem);
    padding: clamp(1.25rem, 3vw, 3rem) clamp(1rem, 4vw, 4rem) 4rem;
}

.system-info-shell {
    width: min(1180px, 100%);
    margin: 0 auto;
}

.system-info-back {
    display: inline-flex;
    align-items: center;
    gap: 0.55rem;
    margin: 0;
    padding: 0.45rem 0.15rem;
    color: var(--text-secondary);
    background: transparent;
    border: 0;
    font: inherit;
    font-size: 0.85rem;
    cursor: pointer;
    transition: color 0.15s, transform 0.15s;
}

.system-info-back:hover {
    color: var(--accent-cyan);
    transform: translateX(-2px);
}

[dir="rtl"] .system-info-back:hover {
    transform: translateX(2px);
}

[dir="rtl"] .system-info-back > span:first-child {
    transform: rotate(180deg);
}

#system-info-title:focus {
    outline: none;
}

html.a11y-focus-outline #system-info-title:focus-visible {
    outline: 3px solid var(--accent-yellow);
    outline-offset: 4px;
    border-radius: 2px;
}

.system-info-toolbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.85rem;
    min-height: 2.45rem;
    margin: 0 0 0.75rem;
}

.system-info-update {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    flex-wrap: wrap;
    gap: 0.5rem 0.85rem;
    min-width: 0;
}

.system-info-status {
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    max-width: 28rem;
    color: var(--text-secondary);
    font-size: 0.76rem;
    line-height: 1.4;
    text-align: end;
}

.system-info-status:empty {
    display: none;
}

.system-info-status::before {
    content: '';
    flex: 0 0 auto;
    width: 0.5rem;
    height: 0.5rem;
    background: var(--text-muted);
    border-radius: 50%;
}

.system-info-status.is-live::before {
    background: var(--accent-green);
    box-shadow: 0 0 7px rgba(16, 185, 129, 0.55);
}

.system-info-status.is-loading::before {
    background: var(--accent-blue);
    animation: pulse 1.2s infinite;
}

.system-info-status.is-error {
    color: var(--accent-yellow);
}

.system-info-status.is-error::before {
    background: var(--accent-yellow);
}

.system-info-refresh {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    min-height: 2.45rem;
    padding: 0.55rem 0.9rem;
    color: var(--text-primary);
    background: rgba(59, 130, 246, 0.12);
    border: 1px solid rgba(59, 130, 246, 0.35);
    border-radius: var(--radius-sm);
    font: inherit;
    font-size: 0.8rem;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.15s, border-color 0.15s, transform 0.15s;
}

.system-info-refresh:hover:not(:disabled) {
    background: rgba(59, 130, 246, 0.2);
    border-color: var(--accent-blue);
    transform: translateY(-1px);
}

.system-info-refresh:disabled {
    cursor: wait;
    opacity: 0.68;
}

.system-info-refresh:disabled svg {
    animation: spin 0.9s linear infinite;
}

#system-info-copy {
    color: var(--text-secondary);
    background: transparent;
    border-color: var(--border-color);
}

#system-info-copy:hover:not(:disabled) {
    color: var(--text-primary);
    background: var(--bg-hover);
    border-color: var(--text-muted);
}

.system-info-tabs {
    display: flex;
    gap: 0.4rem;
    overflow-x: auto;
    margin: 0;
    padding: 0.4rem;
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    scrollbar-width: thin;
}

.system-info-tab {
    display: inline-flex;
    flex: 1 0 auto;
    align-items: center;
    justify-content: center;
    gap: 0.45rem;
    min-height: 2.55rem;
    padding: 0.55rem 0.75rem;
    color: var(--text-secondary);
    background: transparent;
    border: 1px solid transparent;
    border-radius: calc(var(--radius-sm) - 2px);
    font: inherit;
    font-size: 0.8rem;
    white-space: nowrap;
    cursor: pointer;
    transition: color 0.15s, background 0.15s, border-color 0.15s;
}

.system-info-tab:hover {
    color: var(--text-primary);
    background: var(--bg-hover);
}

.system-info-tab[aria-selected="true"] {
    color: var(--text-primary);
    background: rgba(59, 130, 246, 0.14);
    border-color: rgba(59, 130, 246, 0.38);
    box-shadow: inset 0 -2px 0 var(--accent-blue);
}

.system-info-tab-icon {
    display: inline-flex;
    color: var(--text-muted);
}

.system-info-tab-icon svg {
    width: 1.1rem;
    height: 1.1rem;
}

.system-info-tab[aria-selected="true"] .system-info-tab-icon {
    color: var(--accent-blue);
}

.system-info-content {
    min-width: 0;
    padding: clamp(1.5rem, 3vw, 2.4rem) 0 0;
    outline: none;
}

.system-info-section {
    min-width: 0;
}

.system-info-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 1rem;
    align-items: start;
}

.system-info-wide {
    grid-column: 1 / -1;
}

.system-info-page :is(button, summary, input):focus-visible,
.system-info-page [data-copy]:focus-visible {
    outline: 2px solid var(--accent-blue);
    outline-offset: 3px;
}

/* ---- identity ---- */
.system-info-profile {
    position: relative;
    display: grid;
    grid-template-columns: minmax(0, 1.4fr) minmax(180px, 0.6fr);
    gap: 1.5rem;
    overflow: hidden;
    padding: clamp(1.25rem, 2.5vw, 1.75rem);
    background: linear-gradient(135deg, rgba(6, 182, 212, 0.09), rgba(59, 130, 246, 0.035) 55%, rgba(139, 92, 246, 0.08));
    border: 1px solid rgba(6, 182, 212, 0.24);
    border-radius: var(--radius);
}

.system-info-profile h3 {
    margin: 0 0 0.35rem;
    font-size: clamp(1.3rem, 2.6vw, 1.85rem);
    overflow-wrap: anywhere;
}

.system-info-profile-description {
    color: var(--text-secondary);
    line-height: 1.5;
}

.system-info-chips {
    display: flex;
    flex-wrap: wrap;
    gap: 0.45rem;
    margin-top: 1rem;
}

.system-info-chip,
.system-info-state {
    display: inline-flex;
    align-items: center;
    width: fit-content;
    padding: 0.27rem 0.55rem;
    color: var(--text-secondary);
    background: var(--bg-hover);
    border: 1px solid var(--border-color);
    border-radius: 999px;
    font-size: 0.75rem;
    line-height: 1.25;
}

.system-info-profile-side {
    align-self: center;
    display: grid;
    grid-template-columns: repeat(2, minmax(0, auto));
    gap: 0.75rem 1.5rem;
    padding-inline-start: 1.5rem;
    border-inline-start: 1px solid var(--border-color);
}

.system-info-profile-fact {
    min-width: 0;
}

.system-info-profile-fact strong {
    display: block;
    margin-top: 0.25rem;
    font-size: 1.15rem;
    overflow-wrap: anywhere;
}

.system-info-profile-fact span {
    color: var(--text-secondary);
    font-size: 0.75rem;
}

/* ---- at a glance ---- */
.system-info-summary-grid {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 0.8rem;
}

.system-info-summary-card {
    display: flex;
    flex-direction: column;
    min-width: 0;
    padding: 1.15rem;
    color: var(--text-primary);
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    font: inherit;
    text-align: start;
    cursor: default;
}

/* Only cards with a destination are interactive. They say so with a chevron and
   a hover lift, so the two kinds of card are never mistaken for each other. */
.system-info-summary-card.is-link {
    cursor: pointer;
    transition: border-color 0.15s, background 0.15s, transform 0.15s;
}

.system-info-summary-card.is-link .system-info-summary-chevron {
    margin-inline-start: auto;
    color: var(--text-muted);
    transition: color 0.15s, transform 0.15s;
}

.system-info-summary-card.is-link .system-info-summary-chevron svg {
    width: 1rem;
    height: 1rem;
}

.system-info-summary-card.is-link:hover {
    background: var(--bg-card-hover);
    border-color: var(--accent-blue);
    transform: translateY(-1px);
}

.system-info-summary-card.is-link:hover .system-info-summary-chevron {
    color: var(--accent-blue);
}

.system-info-summary-top {
    display: flex;
    align-items: center;
    gap: 0.65rem;
    margin-bottom: 0.8rem;
}

.system-info-summary-icon,
.system-info-card-icon {
    display: grid;
    flex: 0 0 auto;
    place-items: center;
    width: 2.15rem;
    height: 2.15rem;
    color: var(--accent-cyan);
    background: rgba(6, 182, 212, 0.1);
    border: 1px solid rgba(6, 182, 212, 0.2);
    border-radius: 0.65rem;
}

.system-info-summary-icon svg,
.system-info-card-icon svg {
    width: 1.2rem;
    height: 1.2rem;
}

.system-info-summary-icon[data-icon="memory"],
.system-info-card-icon[data-icon="memory"],
.system-info-card-icon[data-icon="module"] {
    color: var(--accent-purple);
    background: rgba(139, 92, 246, 0.1);
    border-color: rgba(139, 92, 246, 0.22);
}

.system-info-summary-icon[data-icon="storage"],
.system-info-card-icon[data-icon="storage"],
.system-info-card-icon[data-icon="filesystem"] {
    color: var(--accent-blue);
    background: rgba(59, 130, 246, 0.1);
    border-color: rgba(59, 130, 246, 0.22);
}

.system-info-card-icon[data-icon="activity"],
.system-info-card-icon[data-icon="power"],
.system-info-card-icon[data-icon="bolt"] {
    color: var(--accent-green);
    background: rgba(16, 185, 129, 0.09);
    border-color: rgba(16, 185, 129, 0.22);
}

.system-info-card-icon[data-icon="sensor"] {
    color: var(--accent-orange);
    background: rgba(249, 115, 22, 0.09);
    border-color: rgba(249, 115, 22, 0.23);
}

.system-info-card-icon[data-icon="fan"],
.system-info-card-icon[data-icon="droplet"] {
    color: var(--accent-cyan);
    background: rgba(6, 182, 212, 0.09);
    border-color: rgba(6, 182, 212, 0.22);
}

.system-info-summary-title {
    color: var(--text-secondary);
    font-size: 0.75rem;
    font-weight: 600;
}

.system-info-summary-value {
    display: block;
    min-height: 2.6em;
    font-size: 1rem;
    font-weight: 650;
    line-height: 1.3;
    overflow-wrap: anywhere;
}

.system-info-summary-detail {
    display: block;
    margin-top: 0.35rem;
    color: var(--text-secondary);
    font-size: 0.75rem;
    line-height: 1.35;
    overflow-wrap: anywhere;
}

.system-info-summary-live {
    display: block;
    margin-top: 0.35rem;
    color: var(--text-primary);
    font-size: 0.75rem;
    font-variant-numeric: tabular-nums;
    line-height: 1.4;
}

.system-info-summary-card > .system-info-live,
.system-info-summary-card > .system-info-meter {
    margin-top: auto;
    padding-top: 0.9rem;
}

/* ---- generic card ---- */
.system-info-card {
    min-width: 0;
    padding: 1.2rem;
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
}

.system-info-card-heading {
    display: flex;
    align-items: center;
    gap: 0.7rem;
    margin-bottom: 1rem;
}

.system-info-card-heading > div {
    min-width: 0;
}

.system-info-card-heading h3 {
    margin: 0;
    font-size: 0.95rem;
    line-height: 1.35;
    overflow-wrap: anywhere;
}

.system-info-card-heading p {
    margin-top: 0.16rem;
    color: var(--text-muted);
    font-size: 0.75rem;
    overflow-wrap: anywhere;
}

.system-info-card-heading .system-info-state,
.system-info-card-heading .system-info-chip {
    margin-inline-start: auto;
}

.system-info-card-heading .system-info-state + .system-info-chip {
    margin-inline-start: 0.4rem;
}

/* ---- inventory lists ---- */
.system-info-inventory-list {
    overflow: hidden;
    margin: 0;
    padding: 0;
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    list-style: none;
}

.system-info-inventory-item {
    display: grid;
    grid-template-columns: auto minmax(0, 1fr);
    gap: 0.85rem;
    align-items: start;
    padding: 1rem 1.15rem;
}

.system-info-inventory-item + .system-info-inventory-item {
    border-top: 1px solid var(--border-color);
}

.system-info-inventory-item:nth-child(even) {
    background: var(--bg-hover);
}

.system-info-inventory-body {
    min-width: 0;
}

.system-info-inventory-heading {
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

.system-info-inventory-heading > div {
    min-width: 0;
}

.system-info-inventory-heading h4 {
    margin: 0;
    font-size: 0.9rem;
    overflow-wrap: anywhere;
}

.system-info-inventory-heading p {
    margin-top: 0.18rem;
    color: var(--text-muted);
    font-size: 0.75rem;
    overflow-wrap: anywhere;
}

.system-info-inventory-heading .system-info-state {
    margin-inline-start: auto;
}

.system-info-inventory-item .system-info-facts {
    margin-top: 0.75rem;
}

.system-info-state.is-online {
    color: var(--accent-green);
    background: rgba(16, 185, 129, 0.09);
    border-color: rgba(16, 185, 129, 0.28);
}

.system-info-state.is-offline {
    color: var(--text-muted);
}

.system-info-chip.is-tracking::before {
    content: '';
    width: 0.42rem;
    height: 0.42rem;
    margin-inline-end: 0.4rem;
    background: var(--text-muted);
    border-radius: 50%;
}

.system-info-chip.is-tracking.is-tracked {
    color: var(--accent-green);
    background: rgba(16, 185, 129, 0.09);
    border-color: rgba(16, 185, 129, 0.28);
}

.system-info-chip.is-tracking.is-tracked::before {
    background: var(--accent-green);
}

.system-info-facts {
    display: grid;
    grid-template-columns: minmax(105px, 0.82fr) minmax(0, 1.18fr);
    column-gap: 1.1rem;
    font-size: 0.8rem;
    line-height: 1.45;
}

.system-info-facts dt,
.system-info-facts dd {
    padding: 0.48rem 0;
    border-top: 1px solid var(--border-color);
}

.system-info-facts dt:first-of-type,
.system-info-facts dt:first-of-type + dd {
    padding-top: 0;
    border-top: 0;
}

.system-info-facts dt {
    color: var(--text-secondary);
    overflow-wrap: anywhere;
}

.system-info-facts dd {
    margin: 0;
    font-weight: 520;
    overflow-wrap: anywhere;
    white-space: pre-line;
}

/* ---- expandable groups ---- */
.system-info-expandable {
    margin-top: 0.8rem;
    border-top: 1px solid var(--border-color);
}

.system-info-expandable > summary {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    padding: 0.85rem 0 0;
    color: var(--text-secondary);
    font-size: 0.78rem;
    font-weight: 600;
    list-style: none;
    cursor: pointer;
}

.system-info-expandable > summary::-webkit-details-marker {
    display: none;
}

.system-info-expandable > summary::after {
    content: '+';
    flex: 0 0 auto;
    color: var(--accent-blue);
    font-size: 1rem;
    font-weight: 400;
}

.system-info-expandable[open] > summary::after {
    content: '−';
}

.system-info-expandable[open] > summary {
    margin-bottom: 0.85rem;
}

/* ---- usage meters ---- */
.system-info-meter {
    width: 100%;
    max-width: 32rem;
    min-width: 0;
    margin: 0;
}

.system-info-meter.is-empty {
    max-width: none;
}

.system-info-empty-usage {
    color: var(--text-muted);
    font-size: 0.75rem;
}

.system-info-progress {
    height: 0.48rem;
    overflow: hidden;
    background: var(--gauge-bg);
    border-radius: 999px;
}

.system-info-progress-fill {
    inline-size: var(--meter-value, 0%);
    height: 100%;
    background: linear-gradient(90deg, var(--accent-cyan), var(--accent-blue));
    border-radius: inherit;
    transition: inline-size 0.25s ease;
}

.system-info-progress.is-warning .system-info-progress-fill {
    background: linear-gradient(90deg, var(--accent-yellow), var(--accent-orange));
}

.system-info-progress.is-critical .system-info-progress-fill {
    background: linear-gradient(90deg, var(--accent-orange), var(--accent-red));
}

.system-info-meter-label {
    display: flex;
    flex-wrap: wrap;
    justify-content: space-between;
    gap: 0.2rem 1rem;
    margin-top: 0.5rem;
    font-size: 0.75rem;
    font-variant-numeric: tabular-nums;
    line-height: 1.45;
}

.system-info-meter-label span {
    min-width: 0;
    color: var(--text-secondary);
    overflow-wrap: anywhere;
}

.system-info-meter-label strong {
    font-weight: 600;
    text-align: end;
    overflow-wrap: anywhere;
}

/* ---- storage: drives ---- */
.system-info-drive-mounts {
    margin-top: 0.65rem;
    padding-top: 0.75rem;
    border-top: 1px solid var(--border-color);
}

.system-info-mount-label {
    display: block;
    margin-bottom: 0.45rem;
    color: var(--text-secondary);
    font-size: 0.78rem;
}

.system-info-path-list {
    display: grid;
    gap: 0.35rem;
    margin: 0;
    padding: 0;
    list-style: none;
}

.system-info-path-list li {
    min-width: 0;
    padding: 0.4rem 0.6rem;
    background: var(--bg-hover);
    border-radius: 4px;
}

.system-info-path {
    display: block;
    min-width: 0;
    font-family: var(--font-mono);
    font-size: 0.78rem;
    line-height: 1.55;
    overflow-wrap: anywhere;
    white-space: pre-wrap;
    unicode-bidi: plaintext;
}

.system-info-mount-paths .system-info-expandable {
    margin-top: 0.35rem;
    border-top: 0;
}

.system-info-mount-paths summary {
    padding-top: 0.4rem;
}

/* Stacked devices sit inside their own collapsible group, so the nested grid
   must not inherit the outer two-column split. */
.system-info-stacked {
    display: block;
    padding: 0;
    background: transparent;
    border: 0;
    border-radius: 0;
}

.system-info-stacked > summary {
    padding: 0.9rem 0;
}

.system-info-stacked[open] > summary {
    margin-bottom: 0.35rem;
}

.system-info-stacked .system-info-grid {
    margin-bottom: 0.5rem;
}

/* ---- storage: mounted filesystems ---- */
.system-info-mount-toolbar {
    display: flex;
    align-items: center;
    gap: 1rem;
    margin-bottom: 1rem;
}

.system-info-mount-search {
    flex: 1;
    min-width: 0;
    max-width: 32rem;
}

.system-info-mount-search input {
    width: 100%;
    min-width: 0;
    min-height: 2.75rem;
    padding: 0.6rem 0.85rem;
    color: var(--text-primary);
    background: var(--bg-primary);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    font: inherit;
    font-size: 0.8rem;
}

.system-info-mount-search input::placeholder {
    color: var(--text-muted);
    opacity: 1;
}

.system-info-mount-count {
    margin-inline-start: auto;
    color: var(--text-secondary);
    font-size: 0.75rem;
    font-variant-numeric: tabular-nums;
}

.system-info-filesystems {
    display: grid;
    gap: 0;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    overflow: hidden;
}

.system-info-filesystem {
    display: grid;
    grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
    gap: 0.75rem 1.5rem;
    align-items: center;
    min-width: 0;
    padding: 0.9rem 1.1rem;
}

.system-info-filesystem + .system-info-filesystem {
    border-top: 1px solid var(--border-color);
}

.system-info-filesystem:nth-child(even) {
    background: var(--bg-hover);
}

.system-info-filesystem-identity,
.system-info-filesystem-usage {
    min-width: 0;
}

.system-info-filesystem-head {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 0.45rem;
    font-weight: 650;
}

.system-info-filesystem-head .system-info-path {
    font-size: 0.88rem;
}

.system-info-filesystem-meta {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 0.35rem 0.6rem;
    margin-top: 0.4rem;
    color: var(--text-secondary);
    font-size: 0.75rem;
}

.system-info-filesystem-meta .system-info-device {
    font-size: 0.75rem;
}

.system-info-fs-type {
    padding: 0.15rem 0.4rem;
    border: 1px solid var(--border-color);
    border-radius: 4px;
    font-family: var(--font-mono);
    font-size: 0.75rem;
}

.system-info-runtime-mounts > summary {
    padding-block: 1rem 0.25rem;
}

/* ---- network ---- */
.system-info-interface .system-info-facts dd {
    font-variant-numeric: tabular-nums;
}

/* ---- devices ---- */
.system-info-device-groups {
    display: grid;
    gap: 0.35rem;
}

.system-info-device-group,
.system-info-sensor-group {
    min-width: 0;
}

.system-info-device-group {
    margin-top: 0;
    padding: 0 1.15rem 1.15rem;
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
}

.system-info-device-group > summary {
    padding: 1rem 0 0;
    font-size: 0.82rem;
}

.system-info-device-group[open] > summary {
    margin-bottom: 1rem;
}

.system-info-device-group > summary h3 {
    margin: 0;
    font-size: 0.82rem;
    font-weight: 650;
}

.system-info-device-group .system-info-inventory-list {
    border-radius: var(--radius-sm);
}

.system-info-group-heading {
    display: flex;
    flex-wrap: wrap;
    align-items: baseline;
    gap: 0.5rem;
    margin-bottom: 0.75rem;
    padding-inline-start: 0.15rem;
}

.system-info-group-heading h3 {
    margin: 0;
    font-size: 0.9rem;
    font-weight: 650;
}

.system-info-device-name {
    padding: 0.12rem 0.4rem;
    color: var(--text-muted);
    background: var(--bg-hover);
    border-radius: 4px;
    font-family: var(--font-mono);
    font-size: 0.75rem;
}

/* ---- sensors ---- */
.system-info-sensor-group {
    margin-bottom: 1.1rem;
}

.system-info-sensor-live {
    margin-inline-start: auto;
    font-family: var(--font-mono);
    font-size: 1rem;
    font-weight: 650;
    font-variant-numeric: tabular-nums;
    white-space: nowrap;
}

.system-info-inventory-item.is-warm .system-info-sensor-live {
    color: var(--accent-yellow);
}

.system-info-inventory-item.is-hot .system-info-sensor-live {
    color: var(--accent-orange);
}

.system-info-inventory-item.is-critical .system-info-sensor-live {
    color: var(--accent-red);
}

.system-info-inventory-item.is-hot .system-info-card-icon,
.system-info-inventory-item.is-critical .system-info-card-icon {
    color: var(--accent-red);
    background: rgba(239, 68, 68, 0.1);
    border-color: rgba(239, 68, 68, 0.28);
}

/* ---- notes, empty states, loading ---- */
.system-info-note {
    display: flex;
    flex-direction: column;
    gap: 0.4rem;
    padding: 0.9rem 1rem;
    color: var(--text-secondary);
    background: rgba(59, 130, 246, 0.07);
    border: 1px solid rgba(59, 130, 246, 0.18);
    border-radius: var(--radius-sm);
    font-size: 0.78rem;
    line-height: 1.5;
}

.system-info-note p {
    margin: 0;
    padding-inline-start: 1.9rem;
    position: relative;
}

.system-info-note p:first-child::before {
    content: 'i';
    position: absolute;
    inset-inline-start: 0;
    top: -0.1rem;
    display: grid;
    place-items: center;
    width: 1.25rem;
    height: 1.25rem;
    color: var(--accent-blue);
    border: 1px solid rgba(59, 130, 246, 0.35);
    border-radius: 50%;
    font-family: serif;
    font-size: 0.75rem;
    font-weight: 700;
}

.system-info-note-hint {
    color: var(--text-muted);
    font-size: 0.75rem;
}

.system-info-empty {
    padding: 2.5rem 1rem;
    color: var(--text-secondary);
    text-align: center;
    line-height: 1.6;
}

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

.system-info-skeleton {
    height: 9rem;
    background: linear-gradient(100deg, var(--bg-card) 25%, var(--bg-hover) 45%, var(--bg-card) 65%);
    background-size: 220% 100%;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    animation: system-info-shimmer 1.5s ease-in-out infinite;
}

@keyframes system-info-shimmer {
    to { background-position-x: -220%; }
}

/* ---- copy affordance ---- */
.system-info-copyable,
.system-info-path[data-copy],
.system-info-device[data-copy] {
    cursor: copy;
}

.system-info-page .system-info-path[data-copy]:hover,
.system-info-page .system-info-device[data-copy]:hover {
    color: var(--accent-cyan);
}

/* ---- responsive ---- */
@media (max-width: 900px) {
    .system-info-status {
        text-align: start;
    }

    .system-info-summary-grid {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }

    .system-info-profile {
        grid-template-columns: minmax(0, 1fr);
    }

    .system-info-profile-side {
        padding-inline-start: 0;
        padding-top: 1.1rem;
        border-inline-start: 0;
        border-top: 1px solid var(--border-color);
    }
}

@media (max-width: 640px) {
    .system-info-page {
        padding: clamp(1rem, 4vw, 1.5rem) 0.9rem 3rem;
    }

    .system-info-toolbar {
        flex-wrap: wrap;
    }

    .system-info-update {
        justify-content: flex-start;
    }

    .system-info-refresh {
        min-height: 2.25rem;
        padding: 0.45rem 0.7rem;
        font-size: 0.75rem;
    }

    /* Five tabs never fit a phone. Rather than hiding two of them behind a
       horizontal scroll with no affordance, wrap them into a visible grid. */
    .system-info-tabs {
        display: grid;
        grid-template-columns: repeat(3, minmax(0, 1fr));
        gap: 0.3rem;
        overflow: visible;
    }

    .system-info-tab {
        flex-direction: column;
        gap: 0.25rem;
        min-height: 0;
        padding: 0.5rem 0.35rem;
        font-size: 0.72rem;
        line-height: 1.25;
        text-align: center;
        white-space: normal;
    }

    .system-info-grid,
    .system-info-loading-grid {
        grid-template-columns: minmax(0, 1fr);
    }

    .system-info-summary-grid {
        grid-template-columns: repeat(2, minmax(0, 1fr));
        gap: 0.6rem;
    }

    .system-info-summary-card {
        padding: 0.9rem;
    }

    .system-info-summary-value {
        min-height: 0;
        font-size: 0.92rem;
    }

    .system-info-summary-detail,
    .system-info-summary-live {
        font-size: 0.75rem;
    }

    .system-info-card {
        padding: 1rem;
    }

    .system-info-facts {
        grid-template-columns: minmax(0, 1fr);
        column-gap: 0;
    }

    .system-info-facts dd {
        padding-top: 0;
        border-top: 0;
    }

    .system-info-facts dt {
        padding-bottom: 0;
    }

    .system-info-filesystem {
        grid-template-columns: minmax(0, 1fr);
        align-items: start;
    }

    .system-info-mount-toolbar {
        flex-wrap: wrap;
        gap: 0.5rem;
    }

    .system-info-mount-search {
        max-width: none;
    }

    .system-info-mount-count {
        margin-inline-start: 0;
    }

    .system-info-device-group {
        padding: 0 0.85rem 0.85rem;
    }

    .system-info-inventory-item {
        padding: 0.9rem 0.85rem;
    }
}

@media (max-width: 380px) {
    .system-info-summary-grid {
        grid-template-columns: minmax(0, 1fr);
    }
}


@font-face {
    font-family: 'Inter';
    src: url('fonts/Inter/Inter-VariableFont_opsz,wght.ttf') format('truetype');
    font-weight: normal;
    font-style: normal;
    font-display: swap;
}

/* Dark palette. The text ramp is kept at or above a 7:1 contrast ratio
   against --bg-primary (WCAG AAA for body text) — the dashboard renders a lot
   of small 0.75rem mono labels, and the previous slate tones sat around 4:1,
   which read as grey-on-black. */
:root {
    --bg-primary: #0a0e17;
    --bg-secondary: #111827;
    --bg-card: rgba(17, 24, 39, 0.85);
    --bg-card-hover: rgba(17, 24, 39, 0.95);
    --border-color: rgba(55, 65, 81, 0.5);
    --border-glow: rgba(59, 130, 246, 0.3);
    --text-primary: #f1f5f9;
    --text-secondary: #cbd5e1;
    --text-muted: #94a3b8;
    --accent-blue: #3b82f6;
    --accent-cyan: #06b6d4;
    --accent-green: #10b981;
    --accent-yellow: #f59e0b;
    --accent-orange: #f97316;
    --accent-red: #ef4444;
    --accent-purple: #8b5cf6;
    --accent-pink: #ec4899;
    --gauge-bg: rgba(30, 41, 59, 0.6);
    --shadow-lg: 0 10px 30px rgba(0, 0, 0, 0.4);
    --shadow-glow: 0 0 20px rgba(59, 130, 246, 0.1);
    --radius: 12px;
    --radius-md: 10px;
    --radius-sm: 8px;
    --bg-hover: rgba(148, 163, 184, 0.14);
    --font-sans: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
    --font-mono: 'JetBrains Mono', 'Fira Code', monospace;
    --chart-grid: rgba(55, 65, 81, 0.2);
    --chart-text: #a9b8cd;
    /* Read by settings.js and copied into the Chart.js defaults — the canvas
       cannot resolve custom properties on its own. */
    --chart-tooltip-bg: rgba(17, 24, 39, 0.9);
    --chart-tooltip-text: #f1f5f9;
    --chart-tooltip-border: rgba(55, 65, 81, 0.5);
}

body.light-mode {
    --bg-primary: #f8fafc;
    --bg-secondary: #f1f5f9;
    --bg-card: rgba(255, 255, 255, 0.8);
    --bg-card-hover: rgba(255, 255, 255, 0.95);
    --border-color: rgba(203, 213, 225, 0.8);
    --border-glow: rgba(59, 130, 246, 0.2);
    --text-primary: #1e293b;
    --text-secondary: #475569;
    --text-muted: #526078;
    --gauge-bg: rgba(226, 232, 240, 0.8);
    --bg-hover: rgba(15, 23, 42, 0.07);
    --shadow-lg: 0 10px 25px rgba(0, 0, 0, 0.05);
    --shadow-glow: 0 0 15px rgba(59, 130, 246, 0.05);
    --chart-grid: rgba(203, 213, 225, 0.4);
    --chart-text: #4b5768;
    --chart-tooltip-bg: rgba(255, 255, 255, 0.95);
    --chart-tooltip-text: #1e293b;
    --chart-tooltip-border: rgba(203, 213, 225, 0.8);
}

body.light-mode .hostname,
body.light-mode .sampling-info {
    background: none;
    color: inherit;
}

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

html {
    font-size: 14px;
    scroll-behavior: smooth;
}

body {
    font-family: var(--font-sans);
    background: var(--bg-primary);
    color: var(--text-primary);
    min-height: 100vh;
    overflow-x: hidden;
    background-image:
        radial-gradient(ellipse at 20% 50%, rgba(59, 130, 246, 0.05) 0%, transparent 50%),
        radial-gradient(ellipse at 80% 20%, rgba(139, 92, 246, 0.05) 0%, transparent 50%),
        radial-gradient(ellipse at 50% 80%, rgba(6, 182, 212, 0.04) 0%, transparent 50%);
}

.hidden {
    display: none !important;
}

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

/* ---- Login ---- */
.login-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.8);
    backdrop-filter: blur(12px);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
}

.login-card {
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: var(--radius);
    padding: 3rem;
    text-align: center;
    width: 360px;
    max-width: 90vw;
    box-shadow: var(--shadow-lg), var(--shadow-glow);
    animation: fadeInUp 0.4s ease;
}

@media (max-width: 480px) {
    .login-card {
        padding: 2rem 1.5rem;
    }
}

.login-logo {
    display: flex;
    justify-content: center;
    margin-bottom: 0.5rem;
}

.login-logo img {
    max-width: 100px;
    height: auto;
    object-fit: contain;
    filter: drop-shadow(0 0 0.05rem rgba(0, 237, 250, 0.5));
}

.login-card h1 {
    font-size: 1.5rem;
    font-weight: 600;
    margin-bottom: 0.25rem;
}

.login-card p {
    color: var(--text-muted);
    margin-bottom: 2rem;
}

.login-card input {
    width: 100%;
    padding: 0.75rem 1rem;
    margin-bottom: 1rem;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    background: var(--bg-secondary);
    color: var(--text-primary);
    font-family: var(--font-sans);
    font-size: 0.95rem;
    outline: none;
    transition: border-color 0.2s;
}

.login-card input:focus {
    border-color: var(--accent-blue);
    box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.15);
}

.login-card button {
    width: 100%;
    padding: 0.75rem;
    border: none;
    border-radius: var(--radius-sm);
    background: linear-gradient(135deg, var(--accent-blue), var(--accent-purple));
    color: white;
    font-weight: 600;
    font-size: 1rem;
    cursor: pointer;
    transition: transform 0.15s, box-shadow 0.15s;
}

.login-card button:hover {
    transform: translateY(-1px);
    box-shadow: 0 4px 16px rgba(59, 130, 246, 0.3);
}

.login-error {
    margin-top: 1rem;
    color: var(--accent-red);
    font-size: 0.85rem;
}

@keyframes fadeInUp {
    from {
        opacity: 0;
        transform: translateY(20px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* ---- Sticky topbar (header + time controls) ----
   Keeps the time range / aggregation controls reachable while scrolling
   long dashboards (many application/container charts). */
.sticky-topbar {
    position: sticky;
    top: 0;
    z-index: 100;
    /* Deliberately unpainted: .header and .time-controls are translucent and
       carry their own backdrop-filter, so scrolled content frosts through
       them. An opaque background here would sit between the two and flatten
       the glass into a solid slab. */
    background: transparent;
}

/* ---- Header ---- */
.header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0.75rem 1.5rem;
    background: var(--bg-card);
    border-bottom: 1px solid var(--border-color);
    backdrop-filter: blur(10px);
    /* Sticky is owned by .sticky-topbar so header + time bar move as one unit */
    position: relative;
    z-index: 1;
}

.header-left,
.header-right {
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

.header-right {
    flex-wrap: wrap;
    justify-content: flex-end;
}

.logo {
    font-size: 1.5rem;
}

.logo img {
    width: 2rem;
    height: 2rem;
    object-fit: contain;
    filter: drop-shadow(0 0 0.02rem rgba(0, 237, 250, 0.711));
    vertical-align: middle;
}

.header h1 {
    font-size: 1.1rem;
    font-weight: 600;
    letter-spacing: 0.2em;
}

.header-link {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    text-decoration: none;
    color: inherit;
    transition: opacity 0.15s;
}

.header-link:hover {
    opacity: 0.8;
}

.hostname,
.sys-os,
.sys-kernel,
.sys-arch {
    padding: 0.2rem 0.6rem;
    background: rgba(59, 130, 246, 0.15);
    border: 1px solid rgba(59, 130, 246, 0.3);
    border-radius: 100px;
    font-size: 0.8rem;
    font-family: var(--font-mono);
    color: var(--accent-cyan);
}

.uptime {
    color: var(--text-muted);
    font-size: 0.8rem;
    font-family: var(--font-mono);
}

.clock {
    font-family: var(--font-mono);
    font-size: 0.9rem;
    color: var(--text-secondary);
}

.status-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    display: inline-block;
}

.status-dot.connected {
    background: var(--accent-green);
    box-shadow: 0 0 6px var(--accent-green);
    animation: pulse 2s infinite;
}

.status-dot.disconnected {
    background: var(--accent-red);
    box-shadow: 0 0 6px var(--accent-red);
}

@keyframes pulse {

    0%,
    100% {
        opacity: 1;
    }

    50% {
        opacity: 0.5;
    }
}

.btn-icon {
    background: none;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    color: var(--text-secondary);
    padding: 0.3rem 0.5rem;
    cursor: pointer;
    font-size: 0.85rem;
    line-height: 1;
    height: 1.75rem;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    transition: all 0.15s;
}

.btn-icon:hover {
    border-color: var(--accent-blue);
    color: var(--accent-blue);
}

.btn-icon.paused {
    border-color: var(--accent-yellow);
    color: var(--accent-yellow);
    background: rgba(245, 158, 11, 0.1);
}

.btn-icon.layout-active {
    border-color: var(--accent-cyan);
    color: var(--accent-cyan);
    background: rgba(6, 182, 212, 0.1);
}

.btn-game {
    text-decoration: none;
    display: inline-flex;
    align-items: center;
    justify-content: center;
}

.btn-game:hover {
    border-color: var(--accent-purple);
    color: var(--accent-purple);
    background: rgba(139, 92, 246, 0.1);
    box-shadow: 0 0 10px rgba(139, 92, 246, 0.2);
}

/* ---- Alert System ---- */
.alert-container {
    position: relative;
    display: inline-flex;
}

.btn-alert {
    position: relative;
}

.btn-alert.no-alerts {
    opacity: 0.75;
    filter: grayscale(1);
}

.btn-alert.has-alerts {
    border-color: var(--accent-orange);
    color: var(--accent-orange);
    background: rgba(249, 115, 22, 0.1);
    animation: alertPulse 2s infinite;
}

@keyframes alertPulse {

    0%,
    100% {
        box-shadow: 0 0 0 0 rgba(249, 115, 22, 0.2);
    }

    50% {
        box-shadow: 0 0 8px 2px rgba(249, 115, 22, 0.3);
    }
}

.alert-badge {
    position: absolute;
    top: -5px;
    right: -5px;
    background: var(--accent-red);
    color: white;
    font-size: 0.65rem;
    font-weight: 700;
    width: 16px;
    height: 16px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-family: var(--font-sans);
    line-height: 1;
}

.alert-dropdown {
    position: absolute;
    top: calc(100% + 8px);
    right: 0;
    width: 320px;
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: var(--radius);
    box-shadow: var(--shadow-lg);
    z-index: 200;
    overflow: hidden;
    animation: fadeInUp 0.2s ease;
}

.chart-settings-dropdown {
    position: absolute;
    top: calc(100% + 5px);
    right: 0;
    width: 220px;
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    box-shadow: var(--shadow-lg);
    z-index: 1000;
    padding: 1rem;
    cursor: default;
    text-align: left;
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    animation: fadeInUp 0.15s ease-out;
}

.alert-dropdown-header {
    padding: 0.6rem 1rem;
    font-weight: 600;
    font-size: 0.85rem;
    border-bottom: 1px solid var(--border-color);
    color: var(--text-primary);
}

.alert-list {
    max-height: 240px;
    overflow-y: auto;
}

.alert-item {
    display: flex;
    align-items: flex-start;
    gap: 0.6rem;
    padding: 0.6rem 1rem;
    border-bottom: 1px solid rgba(55, 65, 81, 0.3);
    font-size: 0.8rem;
}

.alert-item:last-child {
    border-bottom: none;
}

.alert-icon {
    font-size: 1rem;
    flex-shrink: 0;
    margin-top: 0.05rem;
}

.alert-item-body {
    flex: 1;
}

.alert-item-title {
    font-weight: 500;
    color: var(--text-primary);
}

.alert-item-detail {
    color: var(--text-muted);
    font-family: var(--font-mono);
    font-size: 0.75rem;
    margin-top: 0.15rem;
}

.alert-empty {
    padding: 1.5rem 1rem;
    text-align: center;
    color: var(--text-muted);
    font-size: 0.85rem;
}

/* ---- Gauges ---- */
.gauges-row {
    display: grid;
    grid-template-columns: repeat(6, 1fr);
    gap: 1rem;
    padding: 1rem 1.5rem;
}

.gauge-card {
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: var(--radius);
    padding: 1rem;
    text-align: center;
    position: relative;
    overflow: hidden;
    transition: border-color 0.3s, box-shadow 0.3s;
}

.gauge-card:hover {
    border-color: var(--border-glow);
    box-shadow: var(--shadow-glow);
}

.gauge-label {
    font-size: 0.75rem;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    margin-top: 0.25rem;
}

.gauge-value {
    font-family: var(--font-mono);
    font-size: 1.3rem;
    font-weight: 600;
    color: var(--text-primary);
    margin-top: 0.15rem;
}

/* ---- Sparkline Background ---- */
.sparkline-canvas {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    z-index: 0;
}

.gauge-card > *:not(.sparkline-canvas) {
    position: relative;
    z-index: 1;
}

/* ---- Bar Gauge (alternative layout) ---- */
.bar-gauge-container {
    width: 100%;
    padding: 0.3rem 0;
}

.bar-gauge-track {
    width: 100%;
    height: 16px;
    background: var(--gauge-bg);
    border-radius: 8px;
    overflow: hidden;
    position: relative;
}

.bar-gauge-fill {
    height: 100%;
    border-radius: 8px;
    transition: width 0.3s ease;
    position: relative;
}

.bar-gauge-fill::after {
    content: '';
    position: absolute;
    inset: 0;
    border-radius: 8px;
    filter: blur(4px);
    opacity: 0.3;
    background: inherit;
}

/* ---- Time Controls ---- */
.time-controls {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0.5rem 1.5rem;
    border-bottom: 1px solid var(--border-color);
    flex-wrap: wrap;
    gap: 0.5rem;
    background: var(--bg-card);
    backdrop-filter: blur(10px);
}

.time-presets {
    display: flex;
    gap: 0.25rem;
    align-items: center;
    position: relative;
}

.btn-time-menu {
    display: none;
    font-size: 1.2rem;
    padding: 0.1rem 0.5rem;
}

.time-presets-list {
    display: flex;
    gap: 0.25rem;
    align-items: center;
    flex-wrap: wrap;
}

.time-divider {
    color: var(--border-color);
    font-size: 0.8rem;
    margin: 0 0.15rem;
}

.viewport-actions {
    display: inline-flex;
    gap: 0.2rem;
    align-items: center;
}

.time-zone-actions {
    display: inline-flex;
    gap: 0.15rem;
    align-items: center;
}

.time-zone-btn {
    min-width: 3.25rem;
    padding-inline: 0.45rem;
}

.viewport-btn {
    min-width: 2rem;
    padding-inline: 0.5rem;
}

.viewport-btn:disabled {
    cursor: not-allowed;
    opacity: 0.4;
}


.time-btn {
    padding: 0.3rem 0.7rem;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    background: transparent;
    color: var(--text-secondary);
    font-family: var(--font-mono);
    font-size: 0.8rem;
    cursor: pointer;
    transition: all 0.15s;
}

.time-btn:hover {
    border-color: var(--accent-blue);
    color: var(--accent-blue);
}

.time-btn.active {
    background: rgba(59, 130, 246, 0.15);
    border-color: var(--accent-blue);
    color: var(--accent-blue);
}

.time-apply {
    background: rgba(16, 185, 129, 0.15);
    border-color: var(--accent-green);
    color: var(--accent-green);
}

.time-apply:hover {
    background: rgba(16, 185, 129, 0.25);
}

.time-custom-section {
    display: grid;
    gap: 0.55rem;
    position: absolute;
    top: 100%;
    right: 1rem;
    width: min(42rem, calc(100vw - 2rem));
    padding: 0.75rem;
    border: 1px solid var(--border-color);
    border-radius: var(--radius);
    background: var(--bg-card);
    backdrop-filter: blur(10px);
    max-height: 65vh;
    max-height: 65dvh;
    overflow-y: auto;
    box-shadow: var(--shadow-lg);
    z-index: 120;
}

.time-custom-header,
.time-custom-footer {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.5rem;
    flex-wrap: wrap;
}

.time-custom-header h3 {
    font-size: 0.9rem;
    font-weight: 600;
}

.time-custom-zone,
.time-custom-summary {
    color: var(--text-muted);
    font-size: 0.8rem;
    overflow-wrap: anywhere;
}

.time-custom-shortcuts,
.time-custom-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 0.3rem;
}

.time-custom-fields {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 0.65rem;
}

.range-calendar {
    display: grid;
    gap: 0.4rem;
}

.range-calendar-nav {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.range-calendar-nav .time-input {
    min-height: 2rem;
    padding-block: 0.3rem;
    font-size: 0.8rem;
}

.range-calendar-year { width: 5.25rem; }
.range-calendar-nav .time-btn {
    min-height: 2rem;
    padding: 0.1rem 0.55rem;
    font-size: 1.1rem;
}

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

.range-calendar-month h4 {
    margin-bottom: 0.3rem;
    font-size: 0.78rem;
    font-weight: 500;
}

.range-calendar-grid {
    display: grid;
    grid-template-columns: repeat(7, minmax(0, 1fr));
    gap: 0.2rem 0;
    text-align: center;
}

.range-calendar-weekday {
    color: var(--text-muted);
    font-size: 0.68rem;
    padding-bottom: 0.25rem;
}

.range-calendar-day {
    background: transparent;
    color: var(--text-primary);
    border: 1px solid transparent;
    min-height: 2rem;
    font: inherit;
    font-size: 0.78rem;
    cursor: pointer;
}

.range-calendar-day:hover { background: var(--bg-hover); }
.range-calendar-day.in-range { background: rgba(59, 130, 246, 0.18); }
.range-calendar-day.range-edge {
    background: #1d4ed8;
    color: #fff;
    border-radius: var(--radius-sm);
}
.range-calendar-day:focus-visible {
    outline: 2px solid var(--text-primary);
    outline-offset: -3px;
}

@media (max-width: 600px) {
    .range-calendar-months { grid-template-columns: minmax(0, 1fr); }
    .range-calendar-month + .range-calendar-month { display: none; }
    .range-calendar-nav { justify-content: space-between; }
    .range-calendar-nav select { min-width: 0; flex: 1; }
}

.time-custom-field {
    display: grid;
    gap: 0.25rem;
    min-width: 0;
    color: var(--text-secondary);
    font-size: 0.8rem;
}

.time-custom-field .time-input {
    width: 100%;
    min-width: 0;
    min-height: 2.25rem;
    padding: 0.4rem 0.6rem;
    font-size: 0.85rem;
}

.time-custom-error {
    color: var(--accent-red);
    font-size: 0.85rem;
}

.time-custom-section .time-btn {
    min-height: 2rem;
}

.time-custom-section .time-btn:focus-visible {
    outline: 2px solid var(--accent-blue);
    outline-offset: 2px;
}

.time-custom-field .time-input[aria-invalid="true"] {
    border-color: var(--accent-red);
}

.time-input {
    padding: 0.3rem 0.5rem;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    background: var(--bg-secondary);
    color: var(--text-primary);
    font-family: var(--font-mono);
    font-size: 0.75rem;
    outline: none;
    transition: border-color 0.2s;
    color-scheme: dark;
}

body.light-mode .time-input {
    color-scheme: light;
}

.time-input:focus {
    border-color: var(--accent-blue);
    box-shadow: 0 0 0 2px rgba(59, 130, 246, 0.15);
}

.time-sep {
    color: var(--text-muted);
    font-size: 0.8rem;
}

.time-info {
    font-size: 0.8rem;
    color: var(--text-muted);
    font-family: var(--font-mono);
}

.pinned-time {
    margin-left: 0.75rem;
    color: var(--text-secondary);
}

.pinned-time.pinned::before {
    content: '📌 ';
}

/* ---- Chart Search (in header) ---- */
.chart-search-input {
    width: 140px;
    padding: 0.3rem 0.6rem;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    background: var(--bg-secondary);
    color: var(--text-primary);
    font-size: 0.75rem;
    font-family: var(--font-mono);
    outline: none;
    transition: border-color 0.2s, box-shadow 0.2s, width 0.2s;
}

.chart-search-input:focus {
    width: 200px;
    border-color: var(--border-glow);
    box-shadow: var(--shadow-glow);
}

.chart-search-input::placeholder {
    color: var(--text-muted);
    opacity: 0.85;
}

.chart-search-hidden {
    display: none !important;
}

/* ---- Sections ---- */
.section-title {
    padding: 1.5rem 1.5rem 0.5rem;
    font-size: 1.25rem;
    font-weight: 600;
    color: var(--text-primary);
    opacity: 0.9;
    letter-spacing: 0.5px;
    animation: fadeInUp 0.5s ease;
}

/* Section head: title + optional controls (e.g. container app filter) */
.section-head {
    display: flex;
    flex-direction: column;
    gap: 0.35rem;
    padding-right: 1.5rem;
}

.section-head-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    flex-wrap: wrap;
    width: 100%;
}

.section-head .section-title {
    padding-right: 0;
    margin: 0;
}

/* Shared color legend under Applications (one place, not per chart) */
.container-app-legend {
    display: flex;
    flex-wrap: wrap;
    gap: 0.35rem 0.85rem;
    padding: 0 0 0.25rem 1.5rem;
    max-width: 100%;
}

.container-app-legend.hidden {
    display: none;
}

.container-app-legend-item {
    display: inline-flex;
    align-items: center;
    gap: 0.35rem;
    max-width: 14rem;
}

.container-app-legend-swatch {
    width: 0.7rem;
    height: 0.7rem;
    border-radius: 2px;
    flex-shrink: 0;
    box-shadow: 0 0 0 1px rgba(0, 0, 0, 0.2);
}

.container-app-legend-name {
    font-family: var(--font-mono);
    font-size: 0.75rem;
    color: var(--text-secondary);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

/* ---- Container application multi-select filter ---- */
.container-app-filter {
    position: relative;
    margin: 1rem 0 0.25rem auto;
}

.container-app-filter-btn {
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
    padding: 0.35rem 0.75rem;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    background: var(--bg-card);
    color: var(--text-secondary);
    font-family: var(--font-sans);
    font-size: 0.8rem;
    cursor: pointer;
    transition: border-color 0.15s, color 0.15s;
}

.container-app-filter-btn:hover {
    border-color: var(--accent-blue);
    color: var(--accent-blue);
}

.container-app-filter-btn-count {
    font-family: var(--font-mono);
    font-size: 0.75rem;
    color: var(--text-muted);
}

.container-app-filter-caret {
    font-size: 0.7rem;
    opacity: 0.7;
}

.container-app-filter-panel {
    position: absolute;
    top: calc(100% + 0.35rem);
    right: 0;
    min-width: 240px;
    max-width: min(360px, 90vw);
    max-height: 360px;
    display: flex;
    flex-direction: column;
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: var(--radius);
    box-shadow: var(--shadow-lg);
    z-index: 120;
    overflow: hidden;
}

.container-app-filter-panel.hidden {
    display: none;
}

.container-app-filter-actions {
    display: flex;
    gap: 0.5rem;
    padding: 0.5rem 0.75rem;
    border-bottom: 1px solid var(--border-color);
}

.container-app-filter-action {
    flex: 1;
    padding: 0.3rem 0.5rem;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    background: transparent;
    color: var(--text-secondary);
    font-size: 0.75rem;
    cursor: pointer;
    transition: border-color 0.15s, color 0.15s;
}

.container-app-filter-action:hover {
    border-color: var(--accent-blue);
    color: var(--accent-blue);
}

.container-app-filter-list {
    overflow-y: auto;
    padding: 0.35rem 0;
    max-height: 300px;
}

.container-app-filter-item {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.4rem 0.75rem;
    cursor: pointer;
    font-size: 0.85rem;
    color: var(--text-primary);
    user-select: none;
}

.container-app-filter-item:hover {
    background: rgba(59, 130, 246, 0.08);
}

.container-app-filter-item input[type="checkbox"] {
    accent-color: var(--accent-blue);
    width: 0.95rem;
    height: 0.95rem;
    cursor: pointer;
    flex-shrink: 0;
}

.container-app-filter-swatch {
    width: 0.75rem;
    height: 0.75rem;
    border-radius: 2px;
    flex-shrink: 0;
    box-shadow: 0 0 0 1px rgba(0, 0, 0, 0.2);
}

.container-app-filter-name {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    font-family: var(--font-mono);
    font-size: 0.8rem;
}

/* Series past the 10th reuse a colour with a dash pattern; mirror that here. */
.container-app-legend-swatch.is-dashed,
.container-app-filter-swatch.is-dashed {
    background-image: repeating-linear-gradient(
        90deg,
        rgba(255, 255, 255, 0.9) 0 2px,
        transparent 2px 5px
    );
}

.container-app-filter-empty {
    padding: 0.75rem;
    color: var(--text-muted);
    font-size: 0.8rem;
    text-align: center;
}

/* ---- Charts Grid ---- */
.charts-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 1rem;
    padding: 1rem 1.5rem;
}

.chart-card {
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: var(--radius);
    overflow: hidden;
    transition: border-color 0.3s, box-shadow 0.3s;
}

.chart-card:hover {
    border-color: var(--border-glow);
    box-shadow: var(--shadow-glow);
}

.chart-card.span-2 {
    grid-column: span 2;
}

.chart-header {
    display: flex;
    justify-content: flex-start;
    align-items: center;
    padding: 0.75rem 1rem;
    border-bottom: 1px solid var(--border-color);
    gap: 0.5rem;
}

.chart-header h3 {
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--text-primary);
}

.chart-subtitle {
    font-size: 0.75rem;
    font-family: var(--font-mono);
    color: var(--text-muted);
}

.chart-header-right {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    margin-left: auto;
}

.btn-ai-chart {
    background: none;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    color: var(--text-secondary);
    padding: 0.15rem 0.35rem;
    cursor: pointer;
    font-size: 0.85rem;
    line-height: 1;
    height: 1.75rem;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    opacity: 0.5;
    transition: opacity 0.15s, border-color 0.15s, color 0.15s;
}

.btn-ai-chart:hover {
    opacity: 1;
    border-color: var(--accent-blue);
    color: var(--accent-blue);
}

.btn-ai-chart--gauge {
    position: absolute;
    top: 5px;
    right: 5px;
}

.chart-selector {
    background: var(--bg-secondary);
    color: var(--text-primary);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    padding: 0.1rem 0.3rem;
    font-size: 0.75rem;
    font-family: var(--font-mono);
    outline: none;
    cursor: pointer;
}

.chart-selector.no-arrow {
    appearance: none;
    -webkit-appearance: none;
    -moz-appearance: none;
    cursor: default;
    pointer-events: none;
}

.chart-body {
    padding: 0.75rem;
    height: 220px;
    position: relative;
}

.chart-body canvas {
    width: 100% !important;
    height: 100% !important;
}

.chart-body canvas:focus-visible,
.btn-chart-data:focus-visible,
.chart-data-download:focus-visible {
    outline: 3px solid var(--accent-yellow);
    outline-offset: 2px;
}

.btn-chart-data,
.chart-data-download {
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    background: var(--bg-secondary);
    color: var(--text-secondary);
    padding: 0.2rem 0.45rem;
    font: 500 0.72rem/1.2 var(--font-mono);
    cursor: pointer;
}

.btn-chart-data:hover,
.btn-chart-data[aria-expanded="true"],
.chart-data-download:hover {
    border-color: var(--accent-cyan);
    color: var(--accent-cyan);
}

.chart-data-panel {
    border-top: 1px solid var(--border-color);
    padding: 0.75rem 1rem 1rem;
    background: var(--bg-secondary);
}

.chart-data-toolbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.75rem;
    margin-bottom: 0.6rem;
}

.chart-data-summary {
    color: var(--text-muted);
    font-size: 0.75rem;
}

.chart-data-scroll {
    max-height: 20rem;
    overflow: auto;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
}

.chart-data-table {
    width: 100%;
    min-width: 36rem;
    border-collapse: collapse;
    background: var(--bg-card);
    color: var(--text-secondary);
    font: 0.72rem/1.35 var(--font-mono);
}

.chart-data-table caption {
    padding: 0.55rem;
    color: var(--text-primary);
    font: 600 0.78rem/1.3 var(--font-sans);
    text-align: left;
}

.chart-data-table th,
.chart-data-table td {
    padding: 0.4rem 0.55rem;
    border-top: 1px solid var(--border-color);
    text-align: left;
    white-space: nowrap;
    vertical-align: top;
}

.chart-data-table thead th {
    position: sticky;
    top: 0;
    z-index: 1;
    background: var(--bg-card);
    color: var(--text-primary);
}

.chart-data-table tbody tr:nth-child(even) {
    background: rgba(148, 163, 184, 0.04);
}


/* ---- Expanded Chart ---- */
.chart-card.chart-expanded {
    grid-column: 1 / -1;
}

.chart-card.chart-expanded .chart-body {
    height: 330px;
    /* 220 * 1.5 = 330 */
}

.layout-list .chart-card.chart-expanded {
    grid-column: 1;
}

.layout-list .chart-card.chart-expanded .chart-body {
    height: 390px;
    /* 260 * 1.5 = 390 */
}

/* ---- Expand button in chart header ---- */
.btn-expand-chart {
    font-size: 0.95rem;
    padding: 0.15rem 0.35rem;
    line-height: 1;
    opacity: 0.5;
    transition: opacity 0.15s, border-color 0.15s, color 0.15s;
    margin-left: auto;
    flex-shrink: 0;
}

.btn-expand-chart:hover {
    opacity: 1;
    border-color: var(--accent-cyan);
    color: var(--accent-cyan);
}

.chart-card.chart-expanded .btn-expand-chart {
    opacity: 1;
    border-color: var(--accent-cyan);
    color: var(--accent-cyan);
    background: rgba(6, 182, 212, 0.1);
}

/* ---- List Layout Mode ---- */
.layout-list .charts-grid {
    grid-template-columns: 1fr;
}

.layout-list .chart-card.span-2 {
    grid-column: span 1;
}

.layout-list .chart-body {
    height: 260px;
}

/* ---- Focus Mode ---- */
.focus-active .chart-card {
    display: none;
}

.focus-active .chart-card.focus-visible:not(.hidden) {
    display: block !important;
}

.focus-selecting .chart-card:not(.hidden) {
    display: block !important;
    cursor: pointer;
    position: relative;
}

.charts-grid.focus-selecting:not(.hidden),
.charts-grid.focus-active:not(.hidden) {
    display: grid !important;
}

.section-title.focus-selecting:not(.hidden) {
    display: block !important;
}

.section-title.focus-active:not(.hidden) {
    display: none !important;
}

.charts-grid.focus-active~.section-title.focus-active+.charts-grid.focus-active {
    padding-top: 0 !important;
}

.focus-hidden {
    display: none !important;
}

/* Focus mode moves container cards into the main grid, but the Applications
   header carries their only colour legend — keep it pinned alongside them.
   Higher specificity than .focus-hidden, still yielding to .hidden / search. */
.section-head.focus-pinned:not(.hidden):not(.chart-search-hidden) {
    display: flex !important;
}

/* The title carries focus-hidden (its own grid is empty once cards move out),
   so pin it back regardless of which focus class it ended up with. */
.section-head.focus-pinned .section-title:not(.hidden) {
    display: block !important;
}

.section-head.focus-pinned .container-app-legend:not(.hidden) {
    display: flex !important;
}

.focus-selecting .chart-card::after {
    content: '';
    position: absolute;
    inset: 0;
    background: rgba(0, 0, 0, 0.5);
    border-radius: var(--radius);
    z-index: 10;
    pointer-events: none;
    transition: background 0.15s;
}

body.light-mode .focus-selecting .chart-card::after {
    background: rgba(255, 255, 255, 0.4);
}

.focus-selecting .chart-card.focus-selected::after {
    background: rgba(59, 130, 246, 0.15);
    border: 2px solid var(--accent-blue);
}

.focus-selecting .chart-card.focus-selected {
    border-color: var(--accent-blue);
    box-shadow: 0 0 12px rgba(59, 130, 246, 0.3);
}

.focus-bar {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.75rem;
    padding: 0.5rem 1.5rem;
    background: rgba(59, 130, 246, 0.1);
    border-bottom: 1px solid var(--accent-blue);
    font-size: 0.85rem;
    color: var(--accent-blue);
}

.focus-bar button {
    padding: 0.3rem 1rem;
    border: 1px solid var(--accent-blue);
    border-radius: var(--radius-sm);
    background: rgba(59, 130, 246, 0.15);
    color: var(--accent-blue);
    cursor: pointer;
    font-size: 0.8rem;
    font-weight: 500;
    transition: all 0.15s;
}

.focus-bar button:hover {
    background: rgba(59, 130, 246, 0.3);
}

.btn-icon.focus-active {
    border-color: var(--accent-blue);
    color: var(--accent-blue);
    background: rgba(59, 130, 246, 0.1);
}

/* ---- Footer ---- */
.sys-footer {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0.75rem 1.5rem;
    border-top: 1px solid var(--border-color);
    font-size: 0.75rem;
    color: var(--text-muted);
    font-family: var(--font-mono);
    flex-wrap: wrap;
    gap: 0.75rem;
}

#sys-info {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 0.25rem 0.75rem;
}

.sys-info-item {
    display: inline-flex;
    white-space: nowrap;
}

.footer-links a {
    color: var(--text-muted);
    text-decoration: none;
    transition: color 0.15s;
}

.footer-sep {
    color: var(--border-color);
    margin: 0 0.5rem;
}

.footer-links a:hover {
    color: var(--accent-blue);
}

.sampling-info {
    margin-left: 0.75rem;
    padding: 0.15rem 0.5rem;
    background: rgba(59, 130, 246, 0.12);
    border: 1px solid rgba(59, 130, 246, 0.25);
    border-radius: 100px;
    font-size: 0.7rem;
    color: var(--accent-cyan);
}

.clock-synced {
    color: var(--accent-green);
}

.clock-not-synced {
    color: var(--accent-red);
}

.loading-spinner {
    display: inline-block;
    margin-left: 0.5rem;
    animation: spin 1s linear infinite;
    font-size: 0.9rem;
}

@keyframes spin {
    100% {
        transform: rotate(360deg);
    }
}

/* ---- Responsive ---- */
@media (max-width: 1400px) {
    .charts-grid {
        grid-template-columns: repeat(2, 1fr);
    }

    .chart-card.span-2 {
        grid-column: span 2;
    }

    .layout-list .charts-grid {
        grid-template-columns: 1fr;
    }

    .layout-list .chart-card.span-2 {
        grid-column: span 1;
    }
}

@media (max-width: 1000px) {
    .gauges-row {
        grid-template-columns: repeat(3, 1fr);
    }

    .charts-grid {
        grid-template-columns: 1fr;
    }

    .chart-card.span-2 {
        grid-column: span 1;
    }

    .alert-dropdown {
        left: -6rem;
    }
}

@media (max-width: 980px) {
    .header {
        flex-direction: column;
        gap: 0.5rem;
    }

    .header-right {
        justify-content: center;
    }

    .sys-footer {
        flex-direction: column;
        text-align: center;
        gap: 0.5rem;
    }

    #sys-info {
        justify-content: center;
    }
}

@media (max-width: 900px) {
    .btn-time-menu {
        display: inline-flex;
        align-items: center;
        justify-content: center;
    }

    .time-presets-list {
        display: none;
        position: absolute;
        top: 100%;
        left: 0;
        background: var(--bg-card);
        border: 1px solid var(--border-color);
        border-radius: var(--radius);
        padding: 0.5rem;
        flex-direction: column;
        /* Above sticky topbar siblings / chart content */
        z-index: 110;
        /* Keep every preset reachable when the sticky topbar consumes much of
           a short mobile/landscape viewport. */
        max-height: 50vh;
        max-height: 50dvh;
        overflow-y: auto;
        box-shadow: var(--shadow-lg);
        margin-top: 0.5rem;
        min-width: 120px;
    }

    #agg-presets-list {
        left: 2.5rem;
    }

    .time-presets-list.open {
        display: flex;
    }

    .time-presets-list .time-btn {
        width: 100%;
        text-align: left;
    }

    .sys-sep.mobile-hidden {
        display: none;
    }

    #agg-desktop-divider {
        display: none;
    }
}

@media (max-width: 600px) {
    .gauges-row {
        grid-template-columns: repeat(2, 1fr);
    }

    .time-info {
        display: flex;
        width: 100%;
        justify-content: space-between;
        gap: 0.5rem;
        flex-wrap: wrap;
        font-size: 0.68rem;
    }

    .sampling-info {
        margin-left: 0;
        max-width: 100%;
        overflow-wrap: anywhere;
    }

    .time-custom-section {
        padding: 0.85rem 1rem;
    }

    .time-custom-fields {
        grid-template-columns: minmax(0, 1fr);
        gap: 0.75rem;
    }

    .time-custom-footer {
        align-items: stretch;
        flex-direction: column;
    }

    .time-custom-actions .time-btn {
        flex: 1;
    }

    .alert-dropdown {
        position: fixed;
        top: 6rem;
        left: 0;
    }
}

/* ---- Scrollbar ---- */
::-webkit-scrollbar {
    width: 6px;
}

::-webkit-scrollbar-track {
    background: var(--bg-primary);
}

::-webkit-scrollbar-thumb {
    background: var(--border-color);
    border-radius: 3px;
}

::-webkit-scrollbar-thumb:hover {
    background: var(--text-muted);
}

/* ---- Language Selector ---- */
.header-lang {
    position: relative;
    margin-left: 0.25rem;
}

.lang-dropdown {
    position: relative;
}

.lang-btn {
    font-size: 1rem;
    padding: 0.4rem;
    background: transparent;
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 0.35rem;
    color: var(--text-secondary);
    transition: opacity 0.2s;
}

.lang-btn:hover {
    opacity: 0.8;
}

.globe-icon {
    display: block;
    flex-shrink: 0;
}

.lang-code {
    font-size: 0.75rem;
    font-weight: 700;
    font-family: var(--font-mono);
    color: var(--text-secondary);
    opacity: 0.9;
}

.lang-menu {
    position: absolute;
    top: 100%;
    right: 0;
    margin-top: 0.5rem;
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-lg);
    z-index: 1000;
    min-width: 140px;
    padding: 0.5rem 0;
    display: flex;
    flex-direction: column;
    max-height: 70vh;
    overflow-y: auto;
    overflow-x: hidden;
}

.lang-menu.hidden {
    display: none;
}

.lang-option {
    background: transparent;
    border: none;
    color: var(--text-primary);
    padding: 0.6rem 1rem;
    text-align: left;
    font-size: 0.9rem;
    font-family: inherit;
    cursor: pointer;
    transition: background 0.15s;
    width: 100%;
}

.lang-option:hover {
    background: var(--bg-hover);
}

.lang-option.active {
    background: rgba(59, 130, 246, 0.15);
    color: var(--accent-blue);
    font-weight: 600;
}

[dir="rtl"] .lang-option {
    text-align: right;
}

@media (max-width: 640px) {
    .header-lang {
        order: 10;
        margin: 0;
    }
}

/* ---- Customization Menu ---- */
.header-settings {
    position: relative;
    display: flex;
    align-items: center;
}

.settings-menu {
    position: absolute;
    top: calc(100% + 0.5rem);
    right: 0;
    /* In rem, not px: the menu holds the text-size stepper, so it has to grow
       with the setting it controls instead of clipping its own contents. */
    width: 18.5rem;
    max-width: calc(100vw - 2rem);
    max-height: 70vh;
    overflow-y: auto;
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: var(--radius);
    box-shadow: var(--shadow-lg);
    z-index: 1000;
    text-align: left;
    animation: fadeInUp 0.15s ease-out;
}

.settings-menu-header {
    padding: 0.6rem 1rem;
    font-weight: 600;
    font-size: 0.85rem;
    color: var(--text-primary);
    border-bottom: 1px solid var(--border-color);
}

.settings-group {
    padding: 0.4rem 0 0.5rem;
    border-bottom: 1px solid var(--border-color);
}

.settings-group-title {
    padding: 0.35rem 1rem;
    font-size: 0.7rem;
    font-weight: 700;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    color: var(--text-muted);
}

.settings-row {
    display: flex;
    align-items: center;
    gap: 0.6rem;
    padding: 0.4rem 1rem;
    font-size: 0.85rem;
    color: var(--text-primary);
    cursor: pointer;
    transition: background 0.15s;
}

.settings-row:hover {
    background: var(--bg-hover);
}

.settings-time-zone {
    justify-content: space-between;
    flex-wrap: wrap;
    cursor: default;
}

.settings-time-zone .time-zone-actions {
    border: 1px solid var(--border-color);
    border-radius: 8px;
    padding: 2px;
    gap: 2px;
}

.settings-time-zone .time-zone-btn {
    font-family: inherit;
    border: 0;
    border-radius: 5px;
}

.range-calendar-day:disabled {
    opacity: 0.3;
    cursor: not-allowed;
    background: transparent;
}

.settings-row-stepper {
    justify-content: space-between;
    cursor: default;
}

.settings-row-stepper:hover {
    background: none;
}

.settings-stepper {
    display: flex;
    align-items: center;
    gap: 0.15rem;
    flex-shrink: 0;
}

.settings-stepper-btn,
.settings-stepper-value {
    background: transparent;
    border: 1px solid var(--border-color);
    color: var(--text-secondary);
    font-family: inherit;
    font-size: 1rem;
    line-height: 1;
    /* Sized as a comfortable pointer and touch target: these are the controls
       someone reaches for precisely when the text is too small to read. */
    min-height: 2.1rem;
    padding: 0.45rem 0;
    width: 2.4rem;
    text-align: center;
    cursor: pointer;
    transition: background 0.15s, color 0.15s, border-color 0.15s;
}

.settings-stepper-btn:first-child {
    border-radius: var(--radius-sm) 0 0 var(--radius-sm);
}

.settings-stepper-btn:last-child {
    border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
    border-left: none;
}

.settings-stepper-value {
    /* Wide enough for the four-character "300%" without reflowing the row. */
    width: 4rem;
    font-family: var(--font-mono);
    border-left: none;
    border-right: none;
    color: var(--text-primary);
}

.settings-stepper-btn:hover:not(:disabled),
.settings-stepper-value:hover {
    background: var(--bg-hover);
    color: var(--text-primary);
}

.settings-stepper-btn:disabled {
    opacity: 0.4;
    cursor: default;
}

[dir="rtl"] .settings-stepper-btn:first-child {
    border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
}

[dir="rtl"] .settings-stepper-btn:last-child {
    border-radius: var(--radius-sm) 0 0 var(--radius-sm);
    border-left: 1px solid var(--border-color);
    border-right: none;
}

.settings-row input[type="checkbox"] {
    width: 1rem;
    height: 1rem;
    flex-shrink: 0;
    accent-color: var(--accent-blue);
    cursor: pointer;
}

.settings-menu-footer {
    padding: 0.6rem 1rem;
}

.settings-reset {
    width: 100%;
    padding: 0.4rem 0.6rem;
    font-family: inherit;
    font-size: 0.8rem;
    color: var(--text-secondary);
    background: transparent;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    cursor: pointer;
    transition: background 0.15s, color 0.15s, border-color 0.15s;
}

.settings-reset:hover {
    color: var(--text-primary);
    border-color: var(--border-glow);
    background: var(--bg-hover);
}

[dir="rtl"] .settings-menu {
    right: auto;
    left: 0;
    text-align: right;
}

@media (max-width: 640px) {
    .header-settings {
        order: 9;
    }
}

/* ---- AI Assistant Panel ---- */
.ai-panel {
    position: fixed;
    bottom: 1.5rem;
    right: 1.5rem;
    width: 420px;
    max-width: calc(100vw - 2rem);
    height: 65vh;
    max-height: 80vh;
    display: flex;
    flex-direction: column;
    background: rgba(13, 18, 30, 0.92);
    border: 1px solid rgba(139, 92, 246, 0.35);
    border-radius: var(--radius);
    box-shadow: 0 8px 40px rgba(0, 0, 0, 0.6), 0 0 0 1px rgba(139, 92, 246, 0.1), inset 0 1px 0 rgba(255,255,255,0.04);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    z-index: 500;
    animation: fadeInUp 0.25s ease;
    overflow: hidden;
}

.ai-panel-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0.65rem 1rem;
    border-bottom: 1px solid rgba(139, 92, 246, 0.2);
    background: rgba(139, 92, 246, 0.08);
    flex-shrink: 0;
    cursor: move;
    user-select: none;
    touch-action: none;
}

#ai-resize-grip {
    position: absolute;
    right: 0;
    bottom: 0;
    width: 16px;
    height: 16px;
    cursor: nwse-resize;
    background: linear-gradient(
        135deg,
        transparent 0,
        transparent 45%,
        rgba(139, 92, 246, 0.55) 45%,
        rgba(139, 92, 246, 0.55) 55%,
        transparent 55%,
        transparent 75%,
        rgba(139, 92, 246, 0.55) 75%,
        rgba(139, 92, 246, 0.55) 85%,
        transparent 85%
    );
    z-index: 2;
    touch-action: none;
}

.ai-status-banner {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.45rem 1rem;
    background: rgba(239, 68, 68, 0.1);
    border-bottom: 1px solid rgba(239, 68, 68, 0.25);
    font-size: 0.78rem;
    color: rgba(239, 68, 68, 0.85);
    flex-shrink: 0;
}

.ai-status-banner.hidden {
    display: none;
}

.ai-status-spinner {
    width: 11px;
    height: 11px;
    border: 2px solid rgba(239, 68, 68, 0.25);
    border-top-color: rgba(239, 68, 68, 0.85);
    border-radius: 50%;
    animation: ai-spin 0.8s linear infinite;
    flex-shrink: 0;
}

@keyframes ai-spin {
    to { transform: rotate(360deg); }
}

.ai-panel-title {
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--accent-purple);
    display: flex;
    align-items: center;
    gap: 0.4rem;
}

.ai-model-select {
    font-family: var(--font-mono);
    font-size: 0.75rem;
    color: var(--text-primary);
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: 3px;
    padding: 0.15rem 0.4rem;
    cursor: pointer;
    max-width: 180px;
    vertical-align: middle;
    appearance: auto; /* keep the native dropdown arrow */
}

.ai-model-select option {
    background: var(--bg-secondary);
    color: var(--text-primary);
}

.ai-model-select:hover {
    border-color: var(--accent-purple);
}

.ai-model-select:focus {
    border-color: var(--accent-purple);
    outline: none;
}

/* Sessions strip below the header. */
.ai-sessions-bar {
    display: flex;
    align-items: center;
    gap: 0.3rem;
    padding: 0.3rem 1rem;
    background: color-mix(in srgb, var(--accent-purple) 8%, transparent);
    border-bottom: 1px solid color-mix(in srgb, var(--accent-purple) 20%, transparent);
    flex-shrink: 0;
}

.ai-session-select {
    flex: 1;
    font-family: var(--font-mono);
    font-size: 0.72rem;
    color: var(--text-primary);
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: 3px;
    padding: 0.15rem 0.4rem;
    cursor: pointer;
    min-width: 0; /* allow shrinking inside flex */
}

.ai-session-select option {
    background: var(--bg-secondary);
    color: var(--text-primary);
}

.btn-ai-icon {
    background: none;
    border: 1px solid rgba(139, 92, 246, 0.25);
    border-radius: var(--radius-sm);
    color: var(--text-muted);
    font-size: 0.9rem;
    line-height: 1;
    width: 1.5rem;
    height: 1.5rem;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all 0.15s;
    flex-shrink: 0;
}

.btn-ai-icon:hover {
    border-color: var(--accent-purple);
    color: var(--accent-purple);
}

.ai-panel-icon {
    font-size: 1rem;
    line-height: 1;
}

.ai-panel-actions {
    display: flex;
    gap: 0.4rem;
}

.btn-ai-action {
    background: none;
    border: 1px solid rgba(139, 92, 246, 0.25);
    border-radius: var(--radius-sm);
    color: var(--text-muted);
    font-size: 0.8rem;
    line-height: 1;
    width: 1.75rem;
    height: 1.75rem;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all 0.15s;
}

.btn-ai-action:hover {
    border-color: var(--accent-purple);
    color: var(--accent-purple);
}

.ai-messages {
    flex: 1;
    overflow-y: auto;
    padding: 0.75rem;
    display: flex;
    flex-direction: column;
    gap: 0.6rem;
    scroll-behavior: smooth;
}

.ai-messages::-webkit-scrollbar {
    width: 4px;
}

.ai-messages::-webkit-scrollbar-track {
    background: transparent;
}

.ai-messages::-webkit-scrollbar-thumb {
    background: rgba(139, 92, 246, 0.3);
    border-radius: 2px;
}

.ai-msg {
    display: flex;
    flex-direction: column;
    gap: 0.2rem;
    animation: fadeInUp 0.15s ease;
}

.ai-welcome {
    display: flex;
    flex-direction: column;
    gap: 0.4rem;
    padding: 0.5rem 0.2rem;
    animation: fadeInUp 0.2s ease;
}

.ai-welcome-hint {
    font-size: 0.75rem;
    color: var(--text-secondary);
    opacity: 0.8;
    margin-bottom: 0.2rem;
}

.ai-welcome-prompt {
    text-align: left;
    font: inherit;
    font-size: 0.82rem;
    color: var(--text-primary);
    background: rgba(139, 92, 246, 0.08);
    border: 1px solid rgba(139, 92, 246, 0.25);
    border-radius: 6px;
    padding: 0.5rem 0.7rem;
    cursor: pointer;
    transition: background 0.12s ease, border-color 0.12s ease, transform 0.08s ease;
}

.ai-welcome-prompt:hover {
    background: rgba(139, 92, 246, 0.18);
    border-color: rgba(139, 92, 246, 0.5);
}

.ai-welcome-prompt:active {
    transform: translateY(1px);
}

.ai-msg-label {
    font-size: 0.7rem;
    font-weight: 600;
    color: var(--text-muted);
    padding: 0 0.5rem;
}

.ai-msg-user .ai-msg-label {
    color: var(--accent-cyan);
    text-align: right;
}

.ai-msg-body {
    padding: 0.55rem 0.75rem;
    border-radius: var(--radius-sm);
    font-size: 0.82rem;
    line-height: 1.55;
    word-break: break-word;
}

.ai-msg-user .ai-msg-body {
    background: rgba(6, 182, 212, 0.12);
    border: 1px solid rgba(6, 182, 212, 0.2);
    color: var(--text-primary);
    align-self: flex-end;
    max-width: 90%;
}

.ai-msg-assistant .ai-msg-body {
    background: rgba(139, 92, 246, 0.08);
    border: 1px solid rgba(139, 92, 246, 0.18);
    color: var(--text-primary);
}

.ai-msg-body code {
    font-family: var(--font-mono);
    background: rgba(0, 0, 0, 0.3);
    padding: 0.1em 0.35em;
    border-radius: 3px;
    font-size: 0.8em;
}

.ai-msg-body pre {
    font-family: var(--font-mono);
    background: rgba(0, 0, 0, 0.35);
    border: 1px solid rgba(139, 92, 246, 0.15);
    border-radius: var(--radius-sm);
    padding: 0.6em 0.75em;
    margin: 0.4em 0;
    font-size: 0.8em;
    overflow-x: auto;
    white-space: pre;
}

.ai-msg-body pre code {
    background: none;
    padding: 0;
    border-radius: 0;
    font-size: 1em;
}

.ai-msg-body hr {
    border: none;
    border-top: 1px solid rgba(139, 92, 246, 0.2);
    margin: 0.5em 0;
}

.ai-table {
    border-collapse: collapse;
    margin: 0.5em 0;
    font-size: 0.85em;
    max-width: 100%;
    display: block;
    overflow-x: auto;
}

.ai-table th,
.ai-table td {
    border: 1px solid rgba(139, 92, 246, 0.25);
    padding: 0.25rem 0.5rem;
    text-align: left;
    white-space: nowrap;
}

.ai-table th {
    background: rgba(139, 92, 246, 0.12);
    color: var(--accent-purple);
    font-weight: 600;
}

.ai-table tr:nth-child(even) td {
    background: rgba(139, 92, 246, 0.04);
}

.ai-think {
    font-style: italic;
    color: var(--text-muted, rgba(255, 255, 255, 0.5));
    border-left: 2px solid rgba(139, 92, 246, 0.5);
    padding: 4px 0 4px 10px;
    margin-bottom: 8px;
    font-size: 0.9em;
    opacity: 0.8;
}

.ai-error {
    color: var(--accent-red);
    font-size: 0.8rem;
}

.ai-tool-call {
    display: inline-block;
    margin-top: 0.4rem;
    font-size: 0.78rem;
    color: var(--text-muted);
    opacity: 0.8;
}

/* Typing cursor */
.ai-typing::after {
    content: '▋';
    color: var(--accent-purple);
    animation: blink 0.8s step-end infinite;
    margin-left: 2px;
}

@keyframes blink {
    0%, 100% { opacity: 1; }
    50% { opacity: 0; }
}

.ai-input-row {
    display: flex;
    gap: 0.5rem;
    padding: 0.6rem 0.75rem;
    border-top: 1px solid rgba(139, 92, 246, 0.2);
    background: rgba(0, 0, 0, 0.2);
    flex-shrink: 0;
}

.ai-input {
    flex: 1;
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid rgba(139, 92, 246, 0.25);
    border-radius: var(--radius-sm);
    color: var(--text-primary);
    font-family: var(--font-sans);
    font-size: 0.82rem;
    padding: 0.45rem 0.65rem;
    resize: none;
    outline: none;
    transition: border-color 0.2s;
    line-height: 1.4;
}

.ai-input:focus {
    border-color: rgba(139, 92, 246, 0.6);
    box-shadow: 0 0 0 2px rgba(139, 92, 246, 0.1);
}

.ai-input::placeholder {
    color: var(--text-muted);
    opacity: 0.6;
}

.btn-ai-send {
    background: linear-gradient(135deg, #7c3aed, #5b21b6);
    border: none;
    border-radius: var(--radius-sm);
    color: white;
    font-size: 0.8rem;
    font-weight: 600;
    padding: 0 0.9rem;
    cursor: pointer;
    transition: all 0.15s;
    flex-shrink: 0;
    white-space: nowrap;
}

.btn-ai-send:hover {
    background: linear-gradient(135deg, #8b5cf6, #6d28d9);
    box-shadow: 0 0 12px rgba(139, 92, 246, 0.4);
}

.btn-ai-send:disabled {
    opacity: 0.5;
    cursor: not-allowed;
    box-shadow: none;
}

body.light-mode .ai-panel {
    background: rgba(248, 250, 252, 0.95);
    border-color: rgba(139, 92, 246, 0.3);
}

body.light-mode .ai-msg-user .ai-msg-body {
    background: rgba(6, 182, 212, 0.08);
    border-color: rgba(6, 182, 212, 0.25);
}

body.light-mode .ai-msg-assistant .ai-msg-body {
    background: rgba(139, 92, 246, 0.06);
    border-color: rgba(139, 92, 246, 0.2);
}

body.light-mode .ai-input {
    background: rgba(255, 255, 255, 0.8);
    color: var(--text-primary);
}

@media (max-width: 480px) {
    .ai-panel {
        bottom: 0;
        right: 0;
        width: 100%;
        max-width: 100%;
        border-radius: var(--radius) var(--radius) 0 0;
        max-height: 80vh;
    }
}

/* ============================================================
   Customization settings (customization menu + web.appearance /
   web.accessibility config defaults).

   Every class lives on <html>, not <body>: anchoring the palette overrides one
   level above `body.light-mode` lets them win in both themes without depending
   on where they sit in this file. Text size is not a class -- settings.js sets
   the root font-size inline, and the rem-based layout scales with it.
   ============================================================ */

/* ---- Appearance ---- */
/* Both appearance settings default to on, so the class is only ever present
   when the visitor (or the config) turned the feature off. */
html.no-sticky-topbar .sticky-topbar {
    position: relative;
}

html.no-gauges .gauges-row {
    display: none !important;
}

/* ---- Accessibility: high contrast ---- */
html.a11y-contrast body:not(.light-mode) {
    --bg-primary: #000000;
    --bg-secondary: #0b1220;
    --bg-card: rgba(6, 10, 20, 0.96);
    --bg-card-hover: rgba(12, 18, 32, 0.98);
    --border-color: rgba(148, 163, 184, 0.9);
    --border-glow: rgba(96, 165, 250, 0.8);
    --text-primary: #ffffff;
    --text-secondary: #e2e8f0;
    --text-muted: #cbd5e1;
    --accent-blue: #60a5fa;
    --accent-cyan: #22d3ee;
    --accent-green: #34d399;
    --accent-yellow: #fbbf24;
    --accent-orange: #fb923c;
    --accent-red: #f87171;
    --accent-purple: #a78bfa;
    --accent-pink: #f472b6;
    --gauge-bg: rgba(51, 65, 85, 0.8);
    --bg-hover: rgba(226, 232, 240, 0.2);
    --chart-grid: rgba(148, 163, 184, 0.45);
    --chart-text: #e2e8f0;
    --chart-tooltip-bg: rgba(0, 0, 0, 0.98);
    --chart-tooltip-text: #ffffff;
    --chart-tooltip-border: rgba(226, 232, 240, 0.9);
}

html.a11y-contrast body.light-mode {
    --bg-primary: #ffffff;
    --bg-secondary: #f1f5f9;
    --bg-card: rgba(255, 255, 255, 0.98);
    --bg-card-hover: #ffffff;
    --border-color: rgba(51, 65, 85, 0.85);
    --border-glow: rgba(29, 78, 216, 0.7);
    --text-primary: #000000;
    --text-secondary: #1e293b;
    --text-muted: #334155;
    --accent-blue: #1d4ed8;
    --accent-cyan: #0e7490;
    --accent-green: #047857;
    --accent-yellow: #a16207;
    --accent-orange: #c2410c;
    --accent-red: #b91c1c;
    --accent-purple: #6d28d9;
    --accent-pink: #be185d;
    --gauge-bg: rgba(203, 213, 225, 0.9);
    --bg-hover: rgba(15, 23, 42, 0.12);
    --chart-grid: rgba(51, 65, 85, 0.35);
    --chart-text: #1e293b;
    --chart-tooltip-bg: #ffffff;
    --chart-tooltip-text: #000000;
    --chart-tooltip-border: rgba(15, 23, 42, 0.9);
}

/* The decorative radial gradients tint the flat background; drop them. */
html.a11y-contrast body {
    background-image: none;
}

/* A lot of chrome is dimmed to 0.5-0.75 opacity by default. Restore it. */
html.a11y-contrast .btn-icon,
html.a11y-contrast .btn-expand-chart,
html.a11y-contrast .btn-ai-chart,
html.a11y-contrast .btn-alert.no-alerts,
html.a11y-contrast .container-app-filter-caret,
html.a11y-contrast .lang-code,
html.a11y-contrast .chart-search-input::placeholder,
html.a11y-contrast .ai-input::placeholder {
    opacity: 1;
}

/* ---- Accessibility: reduced motion ---- */
/* Near-zero durations rather than `animation: none` so animationend still
   fires for anything that waits on it. */
html.a11y-reduce-motion {
    scroll-behavior: auto;
}

html.a11y-reduce-motion *,
html.a11y-reduce-motion *::before,
html.a11y-reduce-motion *::after {
    animation-duration: 0.001ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.001ms !important;
    scroll-behavior: auto !important;
}

/* Honour the OS-level preference too, whatever the setting says. */
@media (prefers-reduced-motion: reduce) {
    html {
        scroll-behavior: auto;
    }

    *,
    *::before,
    *::after {
        animation-duration: 0.001ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.001ms !important;
        scroll-behavior: auto !important;
    }
}

/* ---- Accessibility: underlined links ---- */
/* Icon buttons are anchors too (the game link); underlining them looks broken
   and adds nothing, since they are not prose links. */
html.a11y-underline-links a:not(.btn-icon) {
    text-decoration: underline;
    text-underline-offset: 0.15em;
}

/* ---- Accessibility: strong focus outline ---- */
/* Inputs and selects across the dashboard set `outline: none`, which leaves
   keyboard users with no focus indicator at all; !important is what it takes
   to put one back. */
html.a11y-focus-outline :focus-visible {
    outline: 3px solid var(--accent-yellow) !important;
    outline-offset: 2px;
}
.chart-aggregation-note {
    margin: 0;
    padding: 0.35rem 1rem 0.6rem;
    font-size: 0.75rem;
    color: var(--text-secondary);
}
