/* ===== Core2Control — Shared Design System ===== */

/* --- Fonts (self-hosted, latin subset; v1.3.43) --- */
@font-face { font-family: "IBM Plex Sans"; font-style: normal; font-weight: 400 600; font-display: swap; src: url(/ui/css/fonts/IBMPlexSans-latin.woff2) format("woff2"); }
@font-face { font-family: "IBM Plex Sans Condensed"; font-style: normal; font-weight: 500; font-display: swap; src: url(/ui/css/fonts/IBMPlexSansCondensed-500-latin.woff2) format("woff2"); }
@font-face { font-family: "IBM Plex Sans Condensed"; font-style: normal; font-weight: 600; font-display: swap; src: url(/ui/css/fonts/IBMPlexSansCondensed-600-latin.woff2) format("woff2"); }
@font-face { font-family: "IBM Plex Mono"; font-style: normal; font-weight: 400; font-display: swap; src: url(/ui/css/fonts/IBMPlexMono-400-latin.woff2) format("woff2"); }
@font-face { font-family: "IBM Plex Mono"; font-style: normal; font-weight: 500; font-display: swap; src: url(/ui/css/fonts/IBMPlexMono-500-latin.woff2) format("woff2"); }

/* --- Variables ---
   v1.3.43: the Signal Path palette under the existing token names, so every
   page picks it up without edits. Text colours are checked at 4.5:1 or better
   against both --white-bg and --light-bg in each theme. */
:root {
    color-scheme: light dark;
    --primary: #2a66d8;
    --secondary: #5b6474;
    --success: #177a46;
    --danger: #c8283e;
    --warning: #8f6100;
    --info: #2069c9;
    --light-bg: #f3f5f8;
    --white-bg: #ffffff;
    --medium-gray: #eaeef3;
    --dark-text: #1b2130;
    --text-muted: #5b6474;
    --text-black: #0f1420;
    --border-color: #d7dde6;
    --card-shadow: 0 1px 2px rgba(20,28,45,0.06), 0 6px 20px rgba(20,28,45,0.06);
    --border-radius: 7px;
    --font-sans: "IBM Plex Sans", system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    --font-cond: "IBM Plex Sans Condensed", "IBM Plex Sans", system-ui, sans-serif;
    --font-mono: "IBM Plex Mono", ui-monospace, SFMono-Regular, Menlo, monospace;

    /* Semantic status colors (used in per-page styles) */
    --color-degraded: #8f6100;
    --color-degraded-bg: rgba(255,202,44,0.15);
    --color-origin-wan: #e67e22;
    --color-origin-wan-bg: rgba(230,126,34,0.12);
    --color-status-success-bg: #d4edda;
    --color-status-success-text: #155724;
    --color-status-error-bg: #f8d7da;
    --color-status-error-text: #721c24;
    --color-type-a: #0d6efd;
    --color-type-aaaa: #6610f2;
    --color-type-cname: #20c997;
    --color-type-mx: #fd7e14;
    --color-type-txt: #6c757d;
    --color-update-badge: #b38f00;
    --color-update-badge-bg: rgba(255,202,44,0.2);
    --color-warning-dot: #f0ad4e;
}

[data-theme="dark"] {
    --primary: #5b9bff;
    --secondary: #98a2b3;
    --success: #3ccf7d;
    --danger: #ff6b7d;
    --warning: #f0bb2a;
    --info: #5f9cf0;
    --light-bg: #15181e;
    --white-bg: #1f232b;
    --medium-gray: #282d37;
    --dark-text: #e7eaf0;
    --text-muted: #98a2b3;
    --text-black: #e7eaf0;
    --border-color: #323945;
    --card-shadow: 0 1px 2px rgba(0,0,0,0.4), 0 8px 24px rgba(0,0,0,0.35);

    /* Semantic status colors — dark overrides */
    --color-degraded: #d4a017;
    --color-degraded-bg: rgba(255,202,44,0.1);
    --color-origin-wan: #f0923e;
    --color-origin-wan-bg: rgba(230,126,34,0.08);
    --color-status-success-bg: rgba(61,220,132,0.15);
    --color-status-success-text: #3ddc84;
    --color-status-error-bg: rgba(255,107,107,0.15);
    --color-status-error-text: #ff6b6b;
    --color-type-a: #4d9fff;
    --color-type-aaaa: #9f5fff;
    --color-type-cname: #3ddcaa;
    --color-type-mx: #ff9f47;
    --color-type-txt: #9ca3af;
    --color-update-badge: #d4a017;
    --color-update-badge-bg: rgba(255,202,44,0.12);
    --color-warning-dot: #ffd93d;
}

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

body {
    font-family: var(--font-sans);
    background: var(--light-bg);
    color: var(--dark-text);
    font-size: 14px;
    line-height: 1.6;
    -webkit-font-smoothing: antialiased;
    transition: background-color 0.15s ease-in-out, color 0.15s ease-in-out;
}

code, pre, kbd, .mono { font-family: var(--font-mono); }

/* --- Type scale: clear heading hierarchy (base; component rules may override) --- */
h1 { font-size: 1.5rem; font-weight: 700; line-height: 1.25; }
h2 { font-size: 1.25rem; font-weight: 600; line-height: 1.3; }
h3 { font-size: 1.05rem; font-weight: 600; line-height: 1.35; }

/* --- Sortable table headers (shared; used by connected-clients, channels, tokens, origins, transcoders, edges) --- */
th.sortable { cursor: pointer; user-select: none; white-space: nowrap; }
th.sortable:hover { color: var(--primary); }
th.sortable:focus-visible { outline: 2px solid var(--primary); outline-offset: -2px; }
.sort-ind { font-size: 0.7em; margin-left: 0.25em; opacity: 0.35; }
th[aria-sort="ascending"] .sort-ind, th[aria-sort="descending"] .sort-ind { opacity: 1; color: var(--primary); }

/* --- Header --- */
.app-header {
    background: var(--white-bg);
    padding: 0.6rem 1.1rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-bottom: 1px solid var(--border-color);
}

.header-content h1 {
    font-size: 1.15rem;
    font-weight: 600;
    letter-spacing: -0.01em;
    line-height: 1.25;
    color: var(--dark-text);
    margin-bottom: 0.15rem;
}

.header-content .version {
    font-family: var(--font-mono);
    font-size: 0.72rem;
    font-weight: 500;
    color: var(--text-muted);
    margin-left: 0.35rem;
}

.header-content .node-info {
    font-size: 0.75rem;
    color: var(--text-muted);
}

.header-actions {
    display: flex;
    gap: 0.75rem;
    align-items: center;
}

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

/* --- Navigation --- */
.nav-tabs {
    background: var(--white-bg);
    border-bottom: 1px solid var(--border-color);
    display: flex;
    padding: 0;
    flex-wrap: wrap;
}

.nav-tab {
    padding: 0.55rem 0.85rem;
    text-decoration: none;
    color: var(--text-muted);
    font-size: 0.8rem;
    font-weight: 500;
    white-space: nowrap;
    border-bottom: 2px solid transparent;
    transition: color 0.15s ease-in-out, border-color 0.15s ease-in-out;
}

.nav-tab:hover {
    color: var(--dark-text);
}

.nav-tab.active {
    color: var(--dark-text);
    border-bottom-color: var(--primary);
    font-weight: 600;
}

/* Hamburger toggle — hidden on desktop */
.nav-toggle {
    display: none;
    background: none;
    border: 1px solid var(--border-color);
    border-radius: var(--border-radius);
    padding: 0.4rem 0.6rem;
    font-size: 1.2rem;
    cursor: pointer;
    color: var(--dark-text);
    line-height: 1;
}

/* --- Layout --- */
.container {
    max-width: 100%;
    margin: 0 auto;
    padding: 1rem;
}

/* --- Stats Bar --- */
.stats-bar {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
    gap: 0.5rem;
    margin-bottom: 1rem;
}

.stat-card {
    background: var(--white-bg);
    padding: 0.75rem;
    border-radius: var(--border-radius);
    box-shadow: var(--card-shadow);
    border: 1px solid var(--border-color);
    text-align: center;
}

.stat-label {
    color: var(--text-muted);
    font-family: var(--font-mono);
    font-size: 0.66rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    margin-bottom: 0.3rem;
}

.stat-value {
    font-family: var(--font-cond);
    font-size: 1.4rem;
    font-weight: 600;
    line-height: 1.1;
    font-variant-numeric: tabular-nums;
    color: var(--dark-text);
}

.stat-value.stat-success { color: var(--success); }
.stat-value.stat-danger { color: var(--danger); }

/* --- Cards --- */
.card {
    background: var(--white-bg);
    border-radius: var(--border-radius);
    padding: 1rem;
    margin-bottom: 1rem;
    box-shadow: var(--card-shadow);
    border: 1px solid var(--border-color);
}

.card h2 {
    font-size: 1.05rem;
    font-weight: 600;
    letter-spacing: -0.01em;
    margin-bottom: 0.75rem;
    padding-bottom: 0.5rem;
    border-bottom: 1px solid var(--border-color);
    color: var(--dark-text);
}

/* --- Tables --- */
.table-responsive {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
}

table {
    width: 100%;
    border-collapse: collapse;
}

th, td {
    padding: 0.6rem;
    text-align: left;
    border-bottom: 1px solid var(--border-color);
    font-size: 0.85rem;
}

th {
    background: transparent;
    color: var(--text-muted);
    font-weight: 600;
    font-size: 0.72rem;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    border-bottom: 2px solid var(--border-color);
}

tr:hover {
    background: var(--medium-gray);
}

.cluster-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.8rem;
}

.cluster-table th {
    text-align: left;
    padding: 0.5rem 0.6rem;
    border-bottom: 2px solid var(--border-color);
    color: var(--text-muted);
    font-weight: 600;
    font-size: 0.7rem;
    text-transform: uppercase;
    letter-spacing: 0.03em;
    background: transparent;
}

.cluster-table td {
    padding: 0.5rem 0.6rem;
    border-bottom: 1px solid var(--border-color);
    vertical-align: middle;
}

.cluster-table tr:hover {
    background: rgba(0,0,0,0.02);
}

[data-theme="dark"] .cluster-table tr:hover {
    background: rgba(255,255,255,0.03);
}

/* --- Badges --- */
.status-badge {
    display: inline-block;
    padding: 0.25em 0.6em;
    font-size: 0.75em;
    font-weight: 600;
    border-radius: var(--border-radius);
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.badge-success {
    background: color-mix(in srgb, var(--success) 12%, transparent);
    color: var(--success);
    border: 1px solid color-mix(in srgb, var(--success) 25%, transparent);
}

.badge-danger {
    background: color-mix(in srgb, var(--danger) 12%, transparent);
    color: var(--danger);
    border: 1px solid color-mix(in srgb, var(--danger) 25%, transparent);
}

.badge-warning {
    background: color-mix(in srgb, var(--warning) 14%, transparent);
    color: var(--warning);
    border: 1px solid color-mix(in srgb, var(--warning) 30%, transparent);
}

.badge-follower {
    background: color-mix(in srgb, var(--info) 12%, transparent);
    color: var(--info);
    border: 1px solid color-mix(in srgb, var(--info) 25%, transparent);
}

.role-badge {
    display: inline-block;
    padding: 0.15rem 0.4rem;
    border-radius: 3px;
    font-size: 0.7rem;
    font-weight: 600;
}

.role-leader { background: var(--success); color: white; }
.role-voter { background: var(--info); color: white; }
.role-nonvoter { background: var(--secondary); color: white; }

/* --- Status dots --- */
.status-dot {
    display: inline-block;
    width: 8px;
    height: 8px;
    border-radius: 50%;
    margin-right: 4px;
}

.dot-online { background: var(--success); }
.dot-offline { background: var(--danger); }

/* --- Ping colors --- */
.ping-good { color: var(--success); }
.ping-ok { color: var(--warning); }
.ping-slow { color: var(--danger); }

/* --- Buttons --- */
.btn {
    padding: 0.4rem 0.8rem;
    border: none;
    border-radius: var(--border-radius);
    font-size: 0.8rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.15s ease-in-out;
    text-decoration: none;
    display: inline-block;
}

.btn-primary { background: var(--primary); color: white; }
.btn-primary:hover { filter: brightness(1.1); }
.btn-secondary { background: var(--secondary); color: white; }
.btn-secondary:hover { filter: brightness(1.1); }
.btn-success { background: var(--success); color: white; }
.btn-success:hover { filter: brightness(1.1); }
.btn-danger { background: var(--danger); color: white; }
.btn-danger:hover { filter: brightness(1.1); }
.btn-sm { padding: 0.3rem 0.6rem; font-size: 0.75rem; }

/* --- Theme Switcher (3-way: Light / Auto / Dark) --- */
.theme-switcher {
    display: inline-flex;
    background: var(--medium-gray);
    border-radius: var(--border-radius);
    padding: 2px;
    gap: 1px;
}
.theme-switcher button {
    background: none;
    border: none;
    padding: 0.25rem 0.55rem;
    border-radius: calc(var(--border-radius) - 2px);
    cursor: pointer;
    font-size: 0.7rem;
    font-weight: 500;
    line-height: 1;
    color: var(--text-muted);
    transition: all 0.15s ease-in-out;
    white-space: nowrap;
}
.theme-switcher button.active {
    background: var(--white-bg);
    color: var(--dark-text);
    box-shadow: 0 1px 3px rgba(0,0,0,0.08);
    font-weight: 600;
}
.theme-switcher button:hover:not(.active) {
    color: var(--dark-text);
}

/* --- Loading --- */
.loading {
    text-align: center;
    padding: 2rem;
    color: var(--text-muted);
}

/* --- Health banner --- */
.health-banner {
    padding: 0.6rem 1rem;
    font-size: 0.85rem;
    font-weight: 500;
    text-align: center;
    border-bottom: 1px solid var(--border-color);
}

.health-banner a { color: inherit; font-weight: 600; text-decoration: underline; }
.health-banner.banner-danger { background: color-mix(in srgb, var(--danger) 14%, transparent); color: var(--danger); }
.health-banner.banner-warning { background: color-mix(in srgb, var(--warning) 14%, transparent); color: var(--warning); }

/* --- Forms --- */
input[type="text"],
input[type="password"],
input[type="number"],
input[type="email"],
input[type="search"],
select,
textarea {
    padding: 0.4rem 0.6rem;
    border: 1px solid var(--border-color);
    border-radius: var(--border-radius);
    background: var(--white-bg);
    color: var(--dark-text);
    font-family: var(--font-sans);
    font-size: 0.85rem;
}

input:focus, select:focus, textarea:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px color-mix(in srgb, var(--primary) 22%, transparent);
}

a:focus-visible, button:focus-visible, .nav-tab:focus-visible {
    outline: 2px solid var(--primary);
    outline-offset: 1px;
}

/* ===== Responsive ===== */

/* Tablet */
@media (max-width: 768px) {
    .app-header {
        flex-direction: column;
        align-items: flex-start;
        gap: 0.5rem;
    }

    .header-actions {
        width: 100%;
        justify-content: space-between;
    }

    /* Hamburger visible */
    .nav-toggle {
        display: block;
    }

    /* Nav hidden by default on mobile */
    .nav-tabs {
        display: none;
        flex-direction: column;
    }

    .nav-tabs.open {
        display: flex;
    }

    .nav-tab {
        border-bottom: none;
        border-left: 3px solid transparent;
        padding: 0.6rem 1rem;
    }

    .nav-tab.active {
        border-left-color: var(--primary);
        border-bottom-color: transparent;
    }

    .stats-bar {
        grid-template-columns: repeat(2, 1fr);
    }

    .container {
        padding: 0.75rem;
    }

    .card {
        padding: 0.75rem;
    }
}

/* Small mobile */
@media (max-width: 480px) {
    .stats-bar {
        grid-template-columns: 1fr;
    }

    .btn {
        width: 100%;
        text-align: center;
    }

    input[type="text"],
    input[type="password"],
    input[type="number"],
    input[type="email"],
    input[type="search"],
    select {
        width: 100%;
    }

    .header-content h1 {
        font-size: 1.4rem;
    }
}
