:root {
    --bg: #0f172a;
    --panel: #1e293b;
    --panel2: #334155;
    --accent: #3b82f6;
    --green: #22c55e;
    --yellow: #f59e0b;
    --red: #ef4444;
    --text: #f8fafc;
    --muted: #94a3b8;
}

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

body {
    font-family: Inter, Arial, sans-serif;
    background: var(--bg);
    color: var(--text);
    display: flex;
    min-height: 100vh;
}

.sidebar {
    width: 240px;
    flex: 0 0 240px;
    display: flex;
    flex-direction: column;
    position: sticky;
    top: 0;
    height: 100vh;
    overflow-y: auto;
    background: #111827;
    padding: 24px;
    border-right: 1px solid #1f2937;
}

.brand {
    display: flex;
    align-items: center;
    gap: 15px;
    margin-bottom: 28px;
    flex: 0 0 auto;
}

.logo {
    width: 50px;
    height: 50px;
    background: var(--accent);
    border-radius: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 28px;
    font-weight: bold;
}

.logo.brand-logo {
    overflow: hidden;
    background: transparent;
}

.brand-logo img {
    display: block;
    width: 100%;
    height: 100%;
    object-fit: contain;
}

.brand-copy {
    flex: 1;
    min-width: 0;
}

.brand-copy h1 {
    overflow: hidden;
    overflow-wrap: normal;
    text-overflow: ellipsis;
    white-space: nowrap;
    line-height: 1.1;
}

.brand h1 {
    font-size: 20px;
}

.brand p {
    color: var(--muted);
    font-size: 13px;
}

/* ===========================
   Sidebar Navigation
=========================== */

.sidebar nav {
    display: flex;
    flex-direction: column;
    flex: 1;
    gap: 17px;
    min-height: 0;
}

.sidebar-group {
    display: grid;
    gap: 5px;
}

.sidebar-group-label {
    padding: 0 13px;
    color: #64748b;
    font-size: 10px;
    font-weight: 750;
    letter-spacing: .105em;
    line-height: 1.4;
    text-transform: uppercase;
}

.sidebar-group-links {
    display: grid;
    gap: 4px;
}

.sidebar-nav-cluster {
    display: grid;
    gap: 0;
}

.sidebar-cluster-header {
    display: grid;
    grid-template-columns: minmax(0, 1fr) 34px;
    align-items: center;
}

.sidebar-cluster-header > a {
    min-width: 0;
}

.sidebar-cluster-toggle {
    width: 32px;
    height: 32px;
    display: inline-grid;
    place-items: center;
    padding: 0;
    color: #64748b;
    background: transparent;
    border: 0;
    border-radius: 9px;
    cursor: pointer;
}

.sidebar-cluster-toggle:hover,
.sidebar-cluster-toggle:focus-visible {
    color: var(--text);
    background: rgba(148, 163, 184, .09);
    outline: none;
}

.sidebar-cluster-toggle svg {
    width: 16px;
    height: 16px;
    transition: transform .18s ease;
}

.sidebar-nav-cluster.is-expanded .sidebar-cluster-toggle svg {
    transform: rotate(180deg);
}

.sidebar-subnav {
    position: relative;
    display: grid;
    gap: 2px;
    margin: 0 0 3px 24px;
    padding-left: 13px;
}

.sidebar-subnav[hidden] {
    display: none !important;
}

.sidebar-subnav::before {
    content: "";
    position: absolute;
    inset: 5px auto 5px 0;
    width: 1px;
    background: rgba(148, 163, 184, .18);
}

.sidebar nav .sidebar-subnav a {
    min-height: 34px;
    gap: 9px;
    padding: 5px 9px;
    border-radius: 9px;
    font-size: 12px;
}

.sidebar nav a.has-active-child {
    color: var(--text);
}

.sidebar nav a.has-active-child .sidebar-icon {
    color: var(--accent);
}

.sidebar-nav-cluster.is-expanded > .sidebar-subnav {
    margin-top: 2px;
}

.sidebar-subnav-icon {
    width: 16px;
    height: 16px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    flex: 0 0 16px;
}

.sidebar-subnav-icon svg {
    width: 15px;
    height: 15px;
}

.sidebar-terminal-group {
    margin-top: auto;
    padding-top: 15px;
    border-top: 1px solid rgba(148, 163, 184, 0.14);
}

.sidebar nav a {
    display: flex;
    align-items: center;
    gap: 12px;

    min-height: 42px;
    padding: 8px 13px;

    color: var(--muted);
    text-decoration: none;

    border-radius: 12px;

    transition:
        background .18s ease,
        color .18s ease,
        transform .18s ease;
}

.sidebar nav a:hover {
    background: #1e293b;
    color: var(--text);
    transform: translateX(2px);
}

.sidebar nav a.active {
    background: rgba(59,130,246,.14);
    color: white;
}

.sidebar-icon {
    width: 22px;
    height: 22px;

    display: flex;
    align-items: center;
    justify-content: center;

    flex-shrink: 0;
}

.sidebar-icon svg {
    display: block;
    width: 20px;
    height: 20px;
    flex-shrink: 0;
}

.sidebar nav a:hover .sidebar-icon,
.sidebar nav a.active .sidebar-icon {
    color: var(--accent);
}

.sidebar-brand img {
    filter: brightness(0) saturate(100%) invert(69%) sepia(9%) saturate(559%) hue-rotate(183deg) brightness(91%) contrast(90%);
}

.sidebar nav a:hover .sidebar-brand img,
.sidebar nav a.active .sidebar-brand img {
    filter: brightness(0) saturate(100%) invert(57%) sepia(99%) saturate(1748%) hue-rotate(201deg) brightness(100%) contrast(98%);
}

.app {
    flex: 1;
    min-width: 0;
    padding: 30px;
}

.topbar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 30px;
}

.topbar-heading {
    display: flex;
    align-items: center;
    gap: 12px;
    min-width: 0;
}

.topbar-heading > div:last-child {
    min-width: 0;
}

.topbar-heading h2 {
    overflow-wrap: anywhere;
}

.mobile-nav-toggle,
.sidebar-close,
.sidebar-backdrop,
.terminal-mobile-menu {
    display: none;
}

.top-status {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 8px;

    padding: 0;
    background: transparent;
    border: none;
    border-radius: 0;
    box-shadow: none;
}

.topbar-actions {
    display: flex;
    align-items: center;
    gap: 18px;
}

.topbar-pending-requests {
    min-height: 38px;
    padding: 7px 9px 7px 11px;
    display: inline-flex;
    align-items: center;
    gap: 8px;
    color: #fde68a;
    background: rgba(120, 53, 15, 0.38);
    border: 1px solid rgba(245, 158, 11, 0.42);
    border-radius: 10px;
    font-size: 12px;
    font-weight: 700;
    text-decoration: none;
}

.topbar-pending-requests:hover {
    color: #fef3c7;
    border-color: rgba(245, 158, 11, 0.7);
    background: rgba(120, 53, 15, 0.55);
}

.topbar-pending-requests svg {
    width: 16px;
    height: 16px;
}

.topbar-pending-requests strong {
    min-width: 22px;
    height: 22px;
    padding: 0 6px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    color: #451a03;
    background: #fbbf24;
    border-radius: 999px;
    font-size: 10px;
}

.logout-form {
    display: flex;
}

.topbar-logout,
.topbar-account {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    min-height: 38px;
    padding: 8px 11px;
    border: 1px solid rgba(148, 163, 184, 0.16);
    border-radius: 10px;
    background: rgba(30, 41, 59, 0.72);
    color: var(--muted);
    font: inherit;
    font-size: 13px;
    cursor: pointer;
    text-decoration: none;
}

.topbar-logout:hover,
.topbar-account:hover {
    border-color: rgba(148, 163, 184, 0.28);
    color: var(--text);
}

.topbar-logout svg,
.topbar-account svg {
    width: 16px;
    height: 16px;
}

.overview {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
    gap: 20px;
    margin-bottom: 30px;
}

.overview-card {
    background: var(--panel);
    padding: 20px;
    border-radius: 14px;
}

.overview-card span {
    color: var(--muted);
    font-size: 13px;
}

.overview-card strong {
    display: block;
    font-size: 34px;
    margin: 8px 0;
}

.health-ok {
    border-left: 5px solid var(--green);
}

.grid {
    display: grid;
    grid-template-columns: 2fr 1fr;
    gap: 20px;
}

.card {
    background: var(--panel);
    border-radius: 14px;
    padding: 20px;
}

.card h2 {
    margin-bottom: 20px;
}

.client,
.row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 12px 0;
    border-bottom: 1px solid #374151;
}

.client:last-child,
.row:last-child {
    border-bottom: none;
}

.client p,
.row p {
    color: var(--muted);
    font-size: 13px;
}

.status-online {
    color: var(--green);
    font-weight: bold;
}

.status-offline {
    color: var(--red);
    font-weight: bold;
}

@media (max-width: 900px) {
    body {
        display: block;
        overflow-x: hidden;
    }

    body.sidebar-open {
        overflow: hidden;
    }

    .sidebar {
        position: fixed;
        z-index: 1000;
        inset: 0 auto 0 0;
        width: min(calc(100vw - 16px), 420px);
        height: 100dvh;
        padding: 20px;
        transform: translateX(-102%);
        transition: transform .22s ease;
        box-shadow: 18px 0 50px rgba(0, 0, 0, .32);
    }

    .sidebar.is-open {
        transform: translateX(0);
    }

    .sidebar .brand {
        gap: 12px;
        margin-bottom: 22px;
    }

    .sidebar nav {
        gap: 19px;
    }

    .sidebar-group-label {
        padding-left: 15px;
    }

    .sidebar-group-links a {
        min-height: 44px;
        padding-left: 15px;
    }

    .sidebar-subnav {
        margin-left: 28px;
        padding-left: 14px;
    }

    .sidebar-group-links .sidebar-subnav a {
        min-height: 40px;
        padding-left: 10px;
    }

    .sidebar-cluster-header {
        grid-template-columns: minmax(0, 1fr) 42px;
    }

    .sidebar-cluster-toggle {
        width: 40px;
        height: 40px;
    }

    .sidebar-close {
        width: 42px;
        height: 42px;
        display: inline-flex;
        align-items: center;
        justify-content: center;
        flex: 0 0 42px;
        margin-left: auto;
        color: var(--muted);
        background: #1e293b;
        border: 1px solid #334155;
        border-radius: 11px;
        cursor: pointer;
    }

    .sidebar-close:hover {
        color: var(--text);
        border-color: #475569;
    }

    .sidebar-close svg {
        width: 19px;
        height: 19px;
    }

    .mobile-nav-toggle,
    .terminal-mobile-menu {
        width: 44px;
        height: 44px;
        flex: 0 0 44px;
        align-items: center;
        justify-content: center;
        color: var(--text);
        background: #1e293b;
        border: 1px solid #334155;
        border-radius: 11px;
        cursor: pointer;
    }

    .mobile-nav-toggle {
        display: inline-flex;
    }

    .mobile-nav-toggle svg,
    .terminal-mobile-menu svg {
        width: 20px;
        height: 20px;
    }

    .sidebar-backdrop {
        position: fixed;
        z-index: 990;
        inset: 0;
        width: 100%;
        height: 100%;
        padding: 0;
        background: rgba(2, 6, 23, .72);
        border: 0;
        opacity: 0;
        pointer-events: none;
        transition: opacity .22s ease;
    }

    body.sidebar-open .sidebar-backdrop {
        display: block;
        opacity: 1;
        pointer-events: auto;
    }

    .app {
        width: 100%;
        padding: 20px;
    }

    .topbar {
        gap: 16px;
        margin-bottom: 22px;
    }

    .topbar-heading h2 {
        font-size: 19px;
    }

    .topbar-heading p {
        margin-top: 2px;
        font-size: 12px;
        color: var(--muted);
    }

    .terminal-mobile-menu {
        display: inline-flex;
        margin: 4px 0 4px 4px;
        align-self: center;
    }
}

@media (max-width: 620px) {
    .app {
        padding: 14px;
    }

    .topbar {
        display: grid;
        grid-template-columns: 44px minmax(0, 1fr);
        grid-template-rows: auto minmax(44px, auto);
        column-gap: 10px;
        row-gap: 12px;
    }

    .topbar-heading {
        display: contents;
    }

    .topbar-heading > div:last-child {
        grid-column: 1 / -1;
        grid-row: 1;
    }

    .topbar-heading h2 {
        overflow: hidden;
        overflow-wrap: normal;
        text-overflow: ellipsis;
        white-space: nowrap;
    }

    .topbar-heading p {
        display: none;
    }

    .mobile-nav-toggle {
        grid-column: 1;
        grid-row: 2;
    }

    .topbar-actions {
        grid-column: 2;
        grid-row: 2;
        min-width: 0;
        justify-content: flex-end;
        flex-wrap: wrap;
        gap: 8px;
    }

    .top-date,
    .top-status-separator,
    .top-status,
    .topbar-logout span,
    .topbar-account span {
        display: none;
    }

    .topbar-pending-requests span {
        display: none;
    }

    .topbar-logout,
    .topbar-account {
        width: 44px;
        height: 44px;
        padding: 0;
        justify-content: center;
    }

    .topbar-pending-requests {
        min-height: 44px;
        flex: 0 0 auto;
    }

    .topbar-actions .global-transfer-state {
        width: 44px;
        height: 44px;
        padding: 0;
        flex: 0 0 44px;
        justify-content: center;
    }

    .topbar-actions .global-transfer-state span {
        display: none;
    }
}

@media (max-width: 420px) {
    .topbar-heading p {
        display: none;
    }

    .topbar-heading h2 {
        font-size: 16px;
    }

    .top-status {
        display: none;
    }
}

/* Global notification menu */
.notification-menu { position: relative; }
.topbar-notification-button {
    position: relative;
    width: 40px;
    height: 40px;
    display: grid;
    place-items: center;
    color: var(--muted);
    background: #172033;
    border: 1px solid #334155;
    border-radius: 10px;
    cursor: pointer;
}
.topbar-notification-button:hover,
.topbar-notification-button[aria-expanded="true"] { color: var(--text); border-color: #3b82f6; }
.topbar-notification-button svg { width: 18px; height: 18px; }
.notification-unread-badge {
    position: absolute;
    top: -5px;
    right: -5px;
    min-width: 18px;
    height: 18px;
    padding: 0 5px;
    display: inline-grid;
    place-items: center;
    color: #172033;
    background: #fbbf24;
    border: 2px solid #0f172a;
    border-radius: 999px;
    font-size: 8px;
    font-weight: 900;
}
.notification-unread-badge.is-critical { color: #fff; background: var(--red); }
.notification-popover {
    position: absolute;
    z-index: 1200;
    top: calc(100% + 9px);
    right: 0;
    width: min(380px, calc(100vw - 28px));
    overflow: hidden;
    background: #111827;
    border: 1px solid #334155;
    border-radius: 13px;
    box-shadow: 0 18px 50px rgba(0, 0, 0, .42);
}
.notification-popover[hidden] { display: none; }
.notification-popover-header {
    padding: 11px 12px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    border-bottom: 1px solid #334155;
}
.notification-popover-header strong { font-size: 12px; }
.notification-popover-header a { color: #93c5fd; font-size: 10px; font-weight: 800; text-decoration: none; }
.notification-popover-list { max-height: 360px; overflow: auto; }
.notification-popover-list > p { padding: 22px 14px; color: var(--muted); font-size: 11px; text-align: center; }
.notification-popover-list > a {
    padding: 10px 11px;
    display: flex;
    align-items: flex-start;
    gap: 9px;
    color: inherit;
    text-decoration: none;
    border-top: 1px solid rgba(71, 85, 105, .52);
}
.notification-popover-list > a:first-child { border-top: 0; }
.notification-popover-list > a:hover { background: rgba(30, 41, 59, .72); }
.notification-popover-list > a.is-read { opacity: .72; }
.notification-preview-icon { width: 30px; height: 30px; flex: 0 0 auto; display: grid; place-items: center; color: #93c5fd; background: #172033; border-radius: 8px; }
.notification-preview-icon.level-warning { color: #fbbf24; }
.notification-preview-icon.level-critical { color: #fca5a5; }
.notification-preview-icon svg { width: 14px; height: 14px; }
.notification-popover-list > a > span:last-child { min-width: 0; }
.notification-popover-list strong,
.notification-popover-list small { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.notification-popover-list strong { font-size: 10px; }
.notification-popover-list small { margin-top: 3px; color: var(--muted); font-size: 9px; }
.notification-preview-heading { min-width: 0; display: flex; align-items: center; gap: 7px; }
.notification-preview-heading strong { min-width: 0; flex: 1; }
.notification-preview-heading em { padding: 2px 5px; color: #bfdbfe; background: rgba(59, 130, 246, .14); border-radius: 999px; font-size: 7px; font-style: normal; font-weight: 900; text-transform: uppercase; }
.notification-popover-list > a.is-read .notification-preview-heading em { color: var(--muted); background: #1e293b; }

@media (max-width: 620px) {
    .topbar-notification-button { width: 44px; height: 44px; }
    .notification-popover { position: fixed; top: 108px; right: 14px; }
}
