:root {
    --bg-base: #0d1117;
    --bg-card: #161b22;
    --bg-card2: #1c2330;
    --border: #30363d;
    --accent: #2f81f7;
    --accent-glow: #2f81f740;
    --success: #3fb950;
    --warning: #d29922;
    --danger: #f85149;
    --muted: #8b949e;
    --text: #e6edf3;
    --mono: 'JetBrains Mono', monospace;
    --sans: 'Manrope', sans-serif;
}

body {
    background: var(--bg-base);
    color: var(--text);
    font-family: var(--sans);
    min-height: 100vh;
}

#sidebar {
    width: 240px;
    min-height: 100vh;
    background: var(--bg-card);
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    position: fixed;
    top: 0;
    left: 0;
    z-index: 100;
}

#sidebar .brand {
    padding: 1.25rem;
    border-bottom: 1px solid var(--border);
}

#sidebar .brand span:last-child {
    font-size: .7rem;
    letter-spacing: .18em;
    color: var(--muted);
    text-transform: uppercase;
}

#sidebar .nav-link {
    color: var(--muted);
    border-radius: .5rem;
    margin: .1rem .75rem;
    padding: .55rem .9rem;
    font-size: .88rem;
    font-weight: 500;
    display: flex;
    align-items: center;
    gap: .6rem;
}

#sidebar .nav-link:hover {
    background: var(--bg-card2);
    color: var(--text);
}

#sidebar .nav-link.active {
    background: var(--accent-glow);
    color: var(--accent);
    border: 1px solid #2f81f730;
}

#sidebar .section-label {
    font-size: .68rem;
    letter-spacing: .14em;
    color: var(--muted);
    text-transform: uppercase;
    padding: .8rem 1.5rem .3rem;
}

.sidebar-user {
    padding: 1rem;
    border-top: 1px solid var(--border);
}

.user-avatar {
    width: 30px;
    height: 30px;
    border-radius: 50%;
    background: var(--accent);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: .8rem;
    font-weight: 700;
    color: #fff;
}

.user-name {
    font-size: .8rem;
    font-weight: 600;
}

.user-role {
    font-size: .7rem;
    color: var(--muted);
}

#main {
    margin-left: 240px;
    padding: 1.75rem 2rem;
}

@media (max-width: 768px) {
    #sidebar {
        display: none;
    }

    #main {
        margin-left: 0;
        padding: 1rem;
    }
}

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

.topbar h1 {
    font-size: 1.35rem;
    font-weight: 800;
    margin: 0;
}

.page-subtitle {
    font-size: .75rem;
    color: var(--muted);
    font-family: var(--mono);
    margin-bottom: .2rem;
}

.live-badge {
    font-family: var(--mono);
    font-size: .7rem;
    background: #3fb95018;
    color: var(--success);
    border: 1px solid #3fb95050;
    padding: .2rem .65rem;
    border-radius: 2rem;
    display: flex;
    align-items: center;
    gap: .4rem;
}

.live-dot {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: var(--success);
    animation: pulse 1.5s infinite;
}

@keyframes pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: .3; }
}

.stat-card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: 1rem;
    padding: 1.25rem 1.4rem;
}

.stat-card .label {
    font-size: .73rem;
    color: var(--muted);
    letter-spacing: .06em;
    text-transform: uppercase;
    margin-bottom: .4rem;
}

.stat-card .value {
    font-size: 2rem;
    font-weight: 800;
    line-height: 1;
    color: var(--text);
}

.stat-card .sub {
    font-size: .78rem;
    color: var(--muted);
    margin-top: .35rem;
}

.section-card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: 1rem;
    overflow: hidden;
}

.section-card .card-head {
    padding: 1rem 1.4rem;
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: space-between;
    font-weight: 700;
    font-size: .95rem;
}

.custom-table {
    width: 100%;
    font-size: .83rem;
}

.custom-table thead th {
    color: var(--muted);
    font-size: .7rem;
    text-transform: uppercase;
    letter-spacing: .1em;
    padding: .75rem 1.4rem;
    border-bottom: 1px solid var(--border);
    font-weight: 600;
}

.custom-table tbody td {
    padding: .8rem 1.4rem;
    border-bottom: 1px solid #30363d60;
    vertical-align: middle;
}

.custom-table tbody tr:hover td {
    background: var(--bg-card2);
}

.device-meta {
    font-size: .75rem;
    color: var(--muted);
    font-family: var(--mono);
}

.mono {
    font-family: var(--mono);
    font-size: .8rem;
}

.dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    display: inline-block;
    margin-right: .4rem;
}

.dot-online {
    background: var(--success);
    box-shadow: 0 0 6px var(--success);
}

.dot-warning {
    background: var(--warning);
    box-shadow: 0 0 6px var(--warning);
}

.dot-offline {
    background: var(--danger);
    box-shadow: 0 0 6px var(--danger);
}

.login-body {
    background:
        radial-gradient(circle at top left, #2f81f725, transparent 35%),
        radial-gradient(circle at bottom right, #3fb95018, transparent 35%),
        var(--bg-base);
}

.login-page {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 1.5rem;
}

.login-card {
    width: 100%;
    max-width: 420px;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: 1.25rem;
    padding: 1.5rem;
    box-shadow: 0 24px 80px rgba(0, 0, 0, .35);
}

.login-brand {
    display: flex;
    align-items: center;
    gap: .9rem;
    padding-bottom: 1.25rem;
    border-bottom: 1px solid var(--border);
}

.login-logo {
    width: 46px;
    height: 46px;
    border-radius: .9rem;
    background: var(--accent-glow);
    color: var(--accent);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.35rem;
    border: 1px solid #2f81f750;
}

.login-brand h1 {
    font-size: 1.15rem;
    font-weight: 800;
    margin: 0;
}

.login-brand p {
    margin: .15rem 0 0;
    font-size: .72rem;
    color: var(--muted);
    letter-spacing: .12em;
    text-transform: uppercase;
}

.login-title {
    margin: 1.5rem 0 1.25rem;
}

.login-title h2 {
    font-size: 1.25rem;
    font-weight: 800;
    margin-bottom: .25rem;
}

.login-title p {
    font-size: .82rem;
    color: var(--muted);
    margin: 0;
}

.login-card .form-label {
    font-size: .78rem;
    font-weight: 600;
    color: var(--muted);
}

.input-wrap {
    position: relative;
}

.input-wrap i {
    position: absolute;
    left: .9rem;
    top: 50%;
    transform: translateY(-50%);
    color: var(--muted);
    font-size: .95rem;
}

.input-wrap .form-control {
    background: var(--bg-base);
    border: 1px solid var(--border);
    color: var(--text);
    padding-left: 2.45rem;
    height: 44px;
    border-radius: .7rem;
    font-size: .9rem;
}

.input-wrap .form-control:focus {
    background: var(--bg-base);
    border-color: var(--accent);
    color: var(--text);
    box-shadow: 0 0 0 .2rem var(--accent-glow);
}

.input-wrap .form-control::placeholder {
    color: #6e7681;
}

.login-btn {
    height: 44px;
    border-radius: .7rem;
    font-weight: 700;
    margin-top: .25rem;
}

.login-footer {
    margin-top: 1.25rem;
    padding-top: 1rem;
    border-top: 1px solid var(--border);
    text-align: center;
    color: var(--muted);
    font-size: .72rem;
    font-family: var(--mono);
}

.icon-wrap {
    width: 42px;
    height: 42px;
    border-radius: 14px;
    background: rgba(47, 129, 247, 0.12);
    color: var(--primary);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.25rem;
}

.stat-card .value {
    margin-top: 14px;
}

.value {
    font-size: 3rem;
    font-weight: 700;
}

.value-tail {
    font-size: 1.2rem;
    font-weight: 500;
}

.value-sm {
    font-size: 1.6rem;
    font-weight: 800;
    line-height: 1;
    letter-spacing: -0.03em;
}

/* ── Detail panel / right sidebar ── */
#detailPanel {
    position: fixed;
    top: 0;
    right: -420px;
    width: 400px;
    max-width: 100vw;
    height: 100vh;
    background: var(--bg-card);
    border-left: 1px solid var(--border);
    z-index: 200;
    transition: right .3s ease;
    display: flex;
    flex-direction: column;
    overflow-y: auto;
}

#detailPanel.open {
    right: 0;
}

#detailPanel .panel-head {
    padding: 1.25rem 1.4rem;
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: space-between;
    font-weight: 700;
}

#detailPanel .panel-body {
    padding: 1.25rem 1.4rem;
    flex: 1;
}

#overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: #00000060;
    z-index: 190;
}

.kv-row {
    display: flex;
    justify-content: space-between;
    gap: 1rem;
    padding: .5rem 0;
    border-bottom: 1px solid #30363d50;
    font-size: .84rem;
}

.kv-row .k {
    color: var(--muted);
}

.kv-row .v {
    font-weight: 600;
    font-family: var(--mono);
    font-size: .8rem;
    text-align: right;
}

.device-row {
    display: flex;
    align-items: center;
    padding: .85rem 1.4rem;
    border-bottom: 1px solid #30363d90;
    gap: .75rem;
    transition: background .12s;
    cursor: pointer;
}

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

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

.device-icon {
    width: 36px;
    height: 36px;
    border-radius: .6rem;
    background: var(--bg-base);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1rem;
    flex-shrink: 0;
}

.device-name {
    font-weight: 600;
    font-size: .88rem;
}

.result-count {
    font-family: var(--mono);
    font-size: .82rem;
    font-weight: 600;
    color: var(--accent);
    margin-left: auto;
    white-space: nowrap;
}

.tag {
    font-size: .68rem;
    padding: .2rem .5rem;
    border-radius: .3rem;
    font-family: var(--mono);
    font-weight: 600;
}

.tag-lis {
    background: #2f81f720;
    color: var(--accent);
    border: 1px solid #2f81f740;
}

.tag-his {
    background: #3fb95020;
    color: var(--success);
    border: 1px solid #3fb95040;
}

.tag-pacs {
    background: #d2992220;
    color: var(--warning);
    border: 1px solid #d2992240;
}

@media (max-width: 576px) {
    #detailPanel {
        width: 100vw;
        right: -100vw;
    }
}
