* {
    box-sizing: border-box;
}

:root {
    color-scheme: dark;
    --bg: #0b0f14;
    --panel: #111720;
    --panel-2: #151c26;
    --border: #25303d;
    --text: #eef3f8;
    --muted: #8e9aaa;
    --accent: #38bdf8;
    --green: #34d399;
    --red: #fb7185;
    --yellow: #fbbf24;
    --shadow: 0 18px 45px rgba(0, 0, 0, .22);
}

html, body {
    margin: 0;
    min-height: 100%;
    background: var(--bg);
    color: var(--text);
    font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

body {
    min-height: 100vh;
}

button {
    font: inherit;
}

.app {
    min-height: 100vh;
    display: flex;
}

.sidebar {
    width: 250px;
    min-height: 100vh;
    position: fixed;
    left: 0;
    top: 0;
    bottom: 0;
    background: #0d1219;
    border-right: 1px solid var(--border);
    padding: 24px 16px;
    display: flex;
    flex-direction: column;
}

.brand {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 4px 8px 30px;
}

.brand-mark {
    width: 42px;
    height: 42px;
    border-radius: 12px;
    display: grid;
    place-items: center;
    background: linear-gradient(145deg, #38bdf8, #2563eb);
    color: white;
    font-weight: 900;
    font-size: 20px;
    box-shadow: 0 10px 25px rgba(37, 99, 235, .28);
}

.brand strong {
    display: block;
    letter-spacing: .13em;
    font-size: 14px;
}

.brand span {
    display: block;
    color: var(--muted);
    font-size: 12px;
    margin-top: 2px;
}

.nav {
    display: grid;
    gap: 6px;
}

.nav-item {
    color: var(--muted);
    text-decoration: none;
    border-radius: 10px;
    padding: 12px 13px;
    display: flex;
    align-items: center;
    gap: 11px;
    font-size: 14px;
    font-weight: 600;
}

.nav-item:hover,
.nav-item.active {
    background: #17202b;
    color: var(--text);
}

.nav-item.active {
    box-shadow: inset 3px 0 0 var(--accent);
}

.nav-icon {
    width: 20px;
    text-align: center;
}

.sidebar-bottom {
    margin-top: auto;
    border-top: 1px solid var(--border);
    padding: 18px 8px 4px;
}

.api-state {
    color: #b8c3d0;
    font-size: 12px;
    display: flex;
    align-items: center;
    gap: 8px;
}

.sidebar-bottom small {
    color: #687586;
    display: block;
    margin-top: 7px;
    font-size: 11px;
}

.pulse {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--green);
    box-shadow: 0 0 0 4px rgba(52, 211, 153, .10);
}

.main {
    margin-left: 250px;
    width: calc(100% - 250px);
    padding: 36px clamp(20px, 4vw, 54px);
    max-width: 1500px;
}

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

.eyebrow,
.modal-eyebrow {
    color: var(--accent);
    font-size: 10px;
    font-weight: 800;
    letter-spacing: .15em;
}

h1 {
    margin: 6px 0 5px;
    font-size: clamp(27px, 3vw, 38px);
    letter-spacing: -.03em;
}

.topbar p,
.section-heading p {
    color: var(--muted);
    margin: 0;
    font-size: 14px;
}

.refresh-btn {
    border: 1px solid var(--border);
    background: var(--panel);
    color: var(--text);
    border-radius: 10px;
    padding: 10px 15px;
    cursor: pointer;
    font-weight: 700;
}

.refresh-btn:hover {
    border-color: #3b4a5c;
    background: var(--panel-2);
}

.refresh-btn span {
    font-size: 18px;
    vertical-align: -1px;
    margin-right: 4px;
}

.alert {
    border-radius: 12px;
    padding: 14px 16px;
    margin-bottom: 24px;
    border: 1px solid;
    display: flex;
    flex-direction: column;
    gap: 4px;
    font-size: 13px;
}

.alert-error {
    background: rgba(251, 113, 133, .07);
    border-color: rgba(251, 113, 133, .25);
    color: #fecdd3;
}

.stats {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 14px;
    margin-bottom: 36px;
}

.stat-card {
    background: var(--panel);
    border: 1px solid var(--border);
    border-radius: 14px;
    padding: 17px;
    display: flex;
    align-items: center;
    gap: 13px;
}

.stat-icon {
    width: 40px;
    height: 40px;
    border-radius: 10px;
    background: #18212c;
    display: grid;
    place-items: center;
    font-size: 18px;
}

.stat-card span {
    color: var(--muted);
    display: block;
    font-size: 12px;
    margin-bottom: 3px;
}

.stat-card strong {
    font-size: 22px;
}

.section-heading {
    display: flex;
    justify-content: space-between;
    align-items: end;
    margin-bottom: 14px;
}

.section-heading h2 {
    font-size: 18px;
    margin: 0 0 5px;
}

.bot-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 16px;
}

.bot-card {
    background: var(--panel);
    border: 1px solid var(--border);
    border-radius: 16px;
    padding: 20px;
    box-shadow: var(--shadow);
}

.bot-card-top {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: 15px;
}

.bot-identity {
    display: flex;
    align-items: center;
    gap: 12px;
}

.bot-avatar {
    width: 46px;
    height: 46px;
    border-radius: 13px;
    display: grid;
    place-items: center;
    background: #182331;
    color: #bdeaff;
    font-weight: 900;
    font-size: 17px;
    border: 1px solid #263748;
}

.bot-identity h3 {
    margin: 0 0 4px;
    font-size: 17px;
}

.subnet {
    color: var(--muted);
    font-size: 12px;
}

.status {
    display: inline-flex;
    align-items: center;
    gap: 7px;
    border-radius: 999px;
    padding: 6px 9px;
    font-size: 11px;
    font-weight: 800;
    white-space: nowrap;
}

.status i {
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: currentColor;
}

.status-connected {
    color: var(--green);
    background: rgba(52, 211, 153, .08);
}

.status-disconnected,
.status-error {
    color: var(--red);
    background: rgba(251, 113, 133, .08);
}

.status-connecting,
.status-qr {
    color: var(--yellow);
    background: rgba(251, 191, 36, .08);
}

.bot-details {
    margin-top: 20px;
    padding: 14px 0;
    border-top: 1px solid var(--border);
    border-bottom: 1px solid var(--border);
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 15px 25px;
}

.detail span {
    display: block;
    color: #718093;
    font-size: 10px;
    text-transform: uppercase;
    letter-spacing: .07em;
    margin-bottom: 5px;
}

.detail strong {
    font-size: 13px;
    color: #dce4ec;
    overflow-wrap: anywhere;
}

.bot-actions {
    display: flex;
    gap: 9px;
    margin-top: 16px;
}

.btn {
    border: 1px solid var(--border);
    border-radius: 9px;
    padding: 9px 13px;
    cursor: pointer;
    font-size: 12px;
    font-weight: 800;
}

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

.btn-secondary {
    background: #171e27;
    color: #d8e0e8;
}

.btn-primary {
    background: #168ac0;
    border-color: #168ac0;
    color: white;
}

.btn:not(:disabled):hover {
    filter: brightness(1.1);
}

.empty-state {
    background: var(--panel);
    border: 1px dashed #344253;
    border-radius: 16px;
    padding: 60px 25px;
    text-align: center;
}

.empty-icon {
    font-size: 36px;
    margin-bottom: 10px;
}

.empty-state h3 {
    margin: 0 0 7px;
}

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

code {
    background: #1a222c;
    padding: 2px 5px;
    border-radius: 5px;
}

footer {
    color: #596777;
    text-align: center;
    font-size: 11px;
    padding: 36px 0 10px;
}

.modal-backdrop {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, .65);
    backdrop-filter: blur(5px);
    display: none;
    align-items: center;
    justify-content: center;
    padding: 20px;
    z-index: 100;
}

.modal-backdrop.show {
    display: flex;
}

.modal {
    width: min(560px, 100%);
    max-height: 90vh;
    overflow: auto;
    background: #111820;
    border: 1px solid #2b3745;
    border-radius: 17px;
    padding: 25px;
    position: relative;
    box-shadow: 0 30px 80px rgba(0, 0, 0, .45);
}

.modal-close {
    position: absolute;
    right: 13px;
    top: 10px;
    border: 0;
    background: transparent;
    color: #8592a2;
    font-size: 28px;
    cursor: pointer;
}

.modal h2 {
    margin: 7px 0 20px;
    font-size: 24px;
}

.modal-loading,
.qr-loading {
    color: var(--muted);
    padding: 30px 0;
    text-align: center;
}

.modal-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 12px;
}

.modal-grid > div {
    background: #171f28;
    border: 1px solid #25303c;
    border-radius: 10px;
    padding: 13px;
}

.modal-grid span {
    display: block;
    color: #718093;
    font-size: 10px;
    text-transform: uppercase;
    margin-bottom: 5px;
}

.modal-grid strong {
    font-size: 13px;
}

.qr-placeholder {
    border: 1px dashed #3c4b5c;
    border-radius: 12px;
    padding: 28px 18px;
    text-align: center;
}

.qr-symbol {
    font-size: 55px;
    line-height: 1;
    margin-bottom: 12px;
}

.qr-placeholder p,
.modal-note {
    color: var(--muted);
    font-size: 12px;
    line-height: 1.6;
}

.qr-payload {
    width: 100%;
    min-height: 110px;
    margin-top: 15px;
    background: #0b1016;
    color: #aebdcc;
    border: 1px solid #293746;
    border-radius: 9px;
    padding: 10px;
    resize: vertical;
    font: 11px/1.4 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}

.modal-error {
    border-radius: 10px;
    padding: 14px;
    background: rgba(251, 113, 133, .08);
    border: 1px solid rgba(251, 113, 133, .22);
    color: #fecdd3;
}

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

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

@media (max-width: 720px) {
    .sidebar {
        width: 70px;
        padding: 15px 10px;
    }

    .brand {
        justify-content: center;
        padding: 3px 0 25px;
    }

    .brand > div:last-child,
    .nav-item:not(.active)::after,
    .nav-item {
        font-size: 0;
    }

    .nav-item {
        justify-content: center;
        padding: 12px 8px;
    }

    .nav-icon {
        font-size: 17px;
    }

    .sidebar-bottom {
        display: none;
    }

    .main {
        margin-left: 70px;
        width: calc(100% - 70px);
        padding: 25px 16px;
    }

    .topbar {
        align-items: stretch;
        flex-direction: column;
    }

    .refresh-btn {
        align-self: flex-start;
    }

    .stats {
        grid-template-columns: 1fr 1fr;
        gap: 9px;
    }

    .stat-card {
        padding: 13px;
    }

    .stat-icon {
        width: 34px;
        height: 34px;
        font-size: 15px;
    }

    .stat-card strong {
        font-size: 19px;
    }

    .bot-card {
        padding: 16px;
    }

    .bot-card-top {
        flex-direction: column;
    }

    .bot-details {
        grid-template-columns: 1fr;
    }

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

.qr-box {
    margin: 24px auto;
    width: 320px;
    min-height: 320px;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
    background: #ffffff;
    border-radius: 18px;
    box-sizing: border-box;
}

#qrCode {
    width: 280px;
    height: 280px;
    display: flex;
    align-items: center;
    justify-content: center;
}

#qrCode img {
    display: block;
    width: 280px;
    height: 280px;
}

.qr-loading {
    color: #111827;
    text-align: center;
    font-size: 14px;
}

.qr-status {
    text-align: center;
    margin-top: 14px;
    color: #4ade80;
    font-size: 14px;
}

@media (max-width: 600px) {
    .qr-box {
        width: 290px;
        min-height: 290px;
        padding: 15px;
    }

    #qrCode,
    #qrCode img {
        width: 260px;
        height: 260px;
    }
}

/* Login */
.login-page {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 24px;
    box-sizing: border-box;
}

.login-shell {
    width: 100%;
    max-width: 460px;
}

.login-card {
    background: var(--card, #111923);
    border: 1px solid var(--border, #253242);
    border-radius: 22px;
    padding: 34px;
    box-shadow: 0 24px 70px rgba(0, 0, 0, .35);
}

.login-brand {
    display: flex;
    align-items: center;
    gap: 13px;
    margin-bottom: 38px;
}

.login-brand > div:last-child {
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.login-brand strong {
    letter-spacing: 2px;
    font-size: 15px;
}

.login-brand span {
    color: #8ea0b7;
    font-size: 13px;
}

.login-heading {
    margin-bottom: 24px;
}

.login-heading h1 {
    margin: 7px 0 8px;
    font-size: 34px;
}

.login-heading p {
    margin: 0;
    color: #8ea0b7;
    line-height: 1.6;
}

.login-form {
    display: grid;
    gap: 17px;
}

.login-form label {
    display: grid;
    gap: 8px;
}

.login-form label > span {
    font-size: 13px;
    color: #aab9cb;
}

.login-form input {
    width: 100%;
    box-sizing: border-box;
    padding: 13px 14px;
    border: 1px solid #2b394a;
    border-radius: 11px;
    background: #0b1118;
    color: #f4f7fb;
    outline: none;
    font: inherit;
    transition: border-color .18s ease, box-shadow .18s ease;
}

.login-form input:focus {
    border-color: #28b9f5;
    box-shadow: 0 0 0 3px rgba(40, 185, 245, .12);
}

.login-submit {
    margin-top: 5px;
    width: 100%;
    border: 0;
    border-radius: 11px;
    padding: 14px 16px;
    background: #159bd2;
    color: #fff;
    font: inherit;
    font-weight: 700;
    cursor: pointer;
    transition: transform .15s ease, filter .15s ease;
}

.login-submit:hover {
    filter: brightness(1.08);
    transform: translateY(-1px);
}

.login-alert {
    margin-bottom: 18px;
}

.alert-success {
    border-color: rgba(52, 211, 153, .25);
    background: rgba(52, 211, 153, .08);
    color: #8ff0c7;
}

.login-footer {
    margin-top: 25px;
    padding-top: 18px;
    border-top: 1px solid #253242;
    color: #64758a;
    font-size: 12px;
    text-align: center;
}

@media (max-width: 520px) {
    .login-page {
        padding: 14px;
    }

    .login-card {
        padding: 25px 20px;
        border-radius: 18px;
    }
}


/* ============================================================
   BOT CONTROL + QR
   ============================================================ */
.btn-warning {
    border: 1px solid rgba(245, 158, 11, 0.45);
    background: rgba(245, 158, 11, 0.12);
    color: #fbbf24;
}
.btn-danger {
    border: 1px solid rgba(239, 68, 68, 0.45);
    background: rgba(239, 68, 68, 0.12);
    color: #f87171;
}
.qr-box {
    margin: 24px auto;
    width: 320px;
    min-height: 320px;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
    background: #ffffff;
    border-radius: 18px;
    box-sizing: border-box;
}
#qrCode {
    width: 280px;
    height: 280px;
    display: flex;
    align-items: center;
    justify-content: center;
}
#qrCode img, #qrCode canvas {
    display: block;
    width: 280px;
    height: 280px;
}
.qr-loading {
    color: #111827;
    text-align: center;
    font-size: 14px;
}
.qr-status {
    text-align: center;
    margin-top: 14px;
    color: #4ade80;
    font-size: 14px;
}
.modal-success {
    padding: 16px;
    border-radius: 12px;
    background: rgba(34, 197, 94, 0.10);
    border: 1px solid rgba(34, 197, 94, 0.25);
    color: #86efac;
}
@media (max-width: 600px) {
    .qr-box { width: 290px; min-height: 290px; padding: 15px; }
    #qrCode, #qrCode img, #qrCode canvas { width: 260px; height: 260px; }
}
