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

:root {
    --bg: #f5f5f7;
    --surf: #fff;
    --b: #e5e5e7;
    --a: #EE2455;
    --g: #16a34a;
    --r: #dc2626;
    --y: #d97706;
    --t: #1d1d1f;
    --m: #6e6e73;
    --s: #f5f5f7;
}

/* ── Login ──────────────────────────────────────── */
body.login-page {
    background: var(--bg);
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    font-family: 'Inter', sans-serif;
    color: var(--t);
}

.login-box {
    background: var(--surf);
    border: 1px solid var(--b);
    border-radius: 16px;
    padding: 44px 40px;
    width: 100%;
    max-width: 360px;
    box-shadow: 0 2px 12px rgba(0, 0, 0, .06);
}

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

.login-brand a {
    display: flex;
    align-items: center;
    text-decoration: none
}

.login-sub {
    color: var(--m);
    font-size: 11px;
    letter-spacing: .08em;
    text-transform: uppercase;
    margin-bottom: 32px;
    font-weight: 500
}

.login-box label {
    display: block;
    color: var(--m);
    font-size: 11px;
    letter-spacing: .06em;
    text-transform: uppercase;
    font-weight: 600;
    margin-bottom: 6px
}

.login-box input {
    width: 100%;
    background: var(--s);
    border: 1px solid var(--b);
    border-radius: 8px;
    padding: 11px 14px;
    color: var(--t);
    font-family: 'Inter', sans-serif;
    font-size: 14px;
    outline: none;
    margin-bottom: 16px;
    transition: border .15s;
}

.login-box input:focus {
    border-color: var(--a);
    background: var(--surf)
}

.login-box button {
    width: 100%;
    background: var(--a);
    border: none;
    border-radius: 8px;
    padding: 12px;
    color: #fff;
    font-family: 'Inter', sans-serif;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    transition: all .15s;
    letter-spacing: .01em;
}

.login-box button:hover {
    background: #d41e4a;
    box-shadow: 0 4px 16px rgba(238, 36, 85, .25)
}

.login-err {
    background: #fff5f7;
    border: 1px solid #fecdd7;
    border-radius: 8px;
    padding: 10px 14px;
    color: #be123c;
    font-size: 12px;
    margin-bottom: 16px
}

.login-foot {
    margin-top: 32px;
    color: #aeaeb2;
    font-size: 11px;
    text-align: center
}

.login-foot a {
    color: #aeaeb2;
    text-decoration: none
}

.login-foot a:hover {
    color: var(--a)
}

/* ── Dashboard body ─────────────────────────────── */
body {
    background: var(--bg);
    color: var(--t);
    font-family: 'Inter', sans-serif;
    min-height: 100vh
}

/* ── Topbar (mobile only) ───────────────────────── */
.topbar {
    display: none;
    align-items: center;
    justify-content: space-between;
    padding: 12px 16px;
    background: var(--surf);
    border-bottom: 1px solid var(--b);
    position: sticky;
    top: 0;
    z-index: 100;
}

.topbar a {
    display: flex;
    align-items: center;
    text-decoration: none
}

.topbar-spacer {
    width: 34px
}

.hamburger {
    background: none;
    border: none;
    cursor: pointer;
    padding: 6px;
    display: flex;
    flex-direction: column;
    gap: 5px;
}

.hamburger span {
    display: block;
    width: 22px;
    height: 2px;
    background: var(--t);
    border-radius: 2px;
    transition: all .2s
}

.hamburger.open span:nth-child(1) {
    transform: translateY(7px) rotate(45deg)
}

.hamburger.open span:nth-child(2) {
    opacity: 0
}

.hamburger.open span:nth-child(3) {
    transform: translateY(-7px) rotate(-45deg)
}

/* ── Overlay ────────────────────────────────────── */
.overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, .3);
    z-index: 150;
    backdrop-filter: blur(2px)
}

.overlay.show {
    display: block
}

/* ── Layout ─────────────────────────────────────── */
.layout {
    display: grid;
    grid-template-columns: 220px 1fr;
    min-height: 100vh
}

/* ── Sidebar ─────────────────────────────────────── */
.sidebar {
    background: var(--surf);
    border-right: 1px solid var(--b);
    padding: 24px 16px;
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.brand {
    display: flex;
    align-items: center;
    padding: 4px 8px;
    margin-bottom: 8px
}

.brand a {
    display: flex;
    align-items: center;
    text-decoration: none
}

.bot-label {
    font-size: 11px;
    color: var(--m);
    letter-spacing: .06em;
    text-transform: uppercase;
    font-weight: 600;
    padding: 8px 8px 4px;
    margin-top: 8px;
    margin-bottom: 2px;
}

.nav {
    padding: 9px 12px;
    border-radius: 8px;
    cursor: pointer;
    font-size: 13px;
    color: var(--m);
    transition: all .15s;
    font-weight: 500;
    border: none;
    background: none;
    width: 100%;
    text-align: left;
}

.nav:hover {
    background: var(--s);
    color: var(--t)
}

.nav.on {
    background: #fff0f3;
    color: var(--a);
    font-weight: 600
}

.nav-tg {
    padding: 9px 12px;
    border-radius: 8px;
    font-size: 13px;
    color: var(--m);
    font-weight: 500;
    text-decoration: none;
    display: block;
    transition: all .15s;
}

.nav-tg:hover {
    background: var(--s);
    color: var(--a)
}

.sidebar-foot {
    margin-top: auto;
    padding-top: 16px;
    border-top: 1px solid var(--b)
}

.foot-link {
    display: block;
    text-align: center;
    color: var(--m);
    font-size: 11px;
    text-decoration: none;
    padding: 6px
}

.foot-link:hover {
    color: var(--a)
}

.logout {
    padding: 9px 12px;
    border-radius: 8px;
    font-size: 13px;
    color: var(--m);
    cursor: pointer;
    font-weight: 500;
    border: none;
    background: none;
    width: 100%;
    text-align: left;
    transition: all .15s;
    margin-bottom: 8px;
}

.logout:hover {
    color: var(--r);
    background: #fff5f5
}

/* ── Main content ────────────────────────────────── */
.main {
    padding: 40px 44px;
    overflow: auto;
    display: flex;
    flex-direction: column;
    min-height: 100vh
}

.page {
    display: none
}

.page.on {
    display: block
}

.ptitle {
    font-size: 22px;
    font-weight: 700;
    color: var(--t);
    margin-bottom: 2px;
    letter-spacing: -.02em
}

.psub {
    color: var(--m);
    font-size: 12px;
    margin-bottom: 28px;
    font-weight: 400
}

/* ── Cards ───────────────────────────────────────── */
.cards {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(190px, 1fr));
    gap: 12px;
    margin-bottom: 28px
}

.card {
    background: var(--surf);
    border: 1px solid var(--b);
    border-radius: 12px;
    padding: 18px 20px
}

.clabel {
    font-size: 10px;
    color: var(--m);
    letter-spacing: .06em;
    text-transform: uppercase;
    font-weight: 600;
    margin-bottom: 8px
}

.cval {
    font-size: 18px;
    font-weight: 700;
    color: var(--t)
}

.cval.g {
    color: var(--g)
}

.cval.r {
    color: var(--r)
}

.cval.s {
    font-size: 13px;
    font-weight: 600
}

/* ── Action buttons ──────────────────────────────── */
.btns {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
    margin-bottom: 28px
}

.btn {
    padding: 9px 18px;
    border-radius: 8px;
    font-family: 'Inter', sans-serif;
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
    border: none;
    transition: all .15s
}

.btn-g {
    background: #f0fdf4;
    color: var(--g);
    border: 1px solid #bbf7d0
}

.btn-g:hover {
    background: #dcfce7
}

.btn-r {
    background: #fff5f5;
    color: var(--r);
    border: 1px solid #fecaca
}

.btn-r:hover {
    background: #fee2e2
}

.btn-y {
    background: #fffbeb;
    color: var(--y);
    border: 1px solid #fde68a
}

.btn-y:hover {
    background: #fef3c7
}

.btn-a {
    background: var(--a);
    color: #fff
}

.btn-a:hover {
    background: #d41e4a
}

/* ── Logs ────────────────────────────────────────── */
.logwrap {
    background: #1a1a1a;
    border: 1px solid #2a2a2a;
    border-radius: 12px;
    overflow: hidden
}

.loghead {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 14px 18px;
    border-bottom: 1px solid #2a2a2a;
    background: #111
}

.logtitle {
    font-size: 13px;
    font-weight: 600;
    color: #e5e5e7
}

.logbody {
    padding: 16px 18px;
    font-size: 11.5px;
    line-height: 1.8;
    max-height: 480px;
    overflow-y: auto;
    color: #6b7280;
    font-family: 'SF Mono', 'Fira Code', monospace
}

.logbody .le {
    color: #f87171
}

.logbody .li {
    color: #60a5fa
}

.logbody .lg {
    color: #4ade80
}

.logbody .lw {
    color: #fbbf24
}

/* ── Config ──────────────────────────────────────── */
.cfgrid {
    display: grid;
    gap: 12px
}

.cfcard {
    background: var(--surf);
    border: 1px solid var(--b);
    border-radius: 12px;
    padding: 18px 20px
}

.cfkey {
    font-size: 10px;
    color: var(--a);
    letter-spacing: .06em;
    text-transform: uppercase;
    font-weight: 700;
    margin-bottom: 8px
}

.cfinput {
    width: 100%;
    background: var(--s);
    border: 1px solid var(--b);
    border-radius: 8px;
    padding: 10px 14px;
    color: var(--t);
    font-family: 'Inter', sans-serif;
    font-size: 13px;
    outline: none;
    transition: border .15s;
    resize: vertical;
}

.cfinput:focus {
    border-color: var(--a);
    background: #fff
}

/* ── Toast ───────────────────────────────────────── */
.toast {
    position: fixed;
    bottom: 24px;
    right: 24px;
    background: var(--surf);
    border: 1px solid var(--b);
    border-radius: 10px;
    padding: 12px 18px;
    font-size: 12px;
    font-weight: 500;
    z-index: 300;
    transform: translateY(60px);
    opacity: 0;
    transition: all .25s;
    box-shadow: 0 4px 20px rgba(0, 0, 0, .1);
}

.toast.show {
    transform: translateY(0);
    opacity: 1
}

.toast.ok {
    border-color: #bbf7d0;
    color: var(--g)
}

.toast.err {
    border-color: #fecaca;
    color: var(--r)
}

/* ── Main footer ─────────────────────────────────── */
.main-footer {
    margin-top: auto;
    padding-top: 32px;
    padding-bottom: 8px;
    color: #aeaeb2;
    font-size: 11px;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 4px
}

.main-footer a {
    color: #aeaeb2;
    text-decoration: none
}

.main-footer a:hover {
    color: var(--a)
}

.cfg-save {
    margin-top: 16px
}

.cfg-apilinks {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 8px;
    padding: 10px 14px;
    background: var(--s);
    border: 1px solid var(--b);
    border-radius: 8px;
    margin-bottom: 16px;
    font-size: 12px;
}

.cfg-apilinks-title {
    color: var(--m);
    font-weight: 600;
    margin-right: 4px;
}

.cfg-apilinks a {
    color: var(--a);
    text-decoration: none;
    padding: 2px 8px;
    border-radius: 20px;
    border: 1px solid var(--b);
    background: var(--surf);
    transition: background .12s;
    white-space: nowrap;
}

.cfg-apilinks a:hover {
    background: var(--b);
}

.cfkey-link {
    display: inline-block;
    margin-top: 5px;
    font-size: 11px;
    color: var(--a);
    text-decoration: none;
}

.cfkey-link:hover {
    text-decoration: underline;
}

/* ── Misc ────────────────────────────────────────── */
.dot {
    width: 7px;
    height: 7px;
    border-radius: 50%;
    display: inline-block;
    margin-right: 6px;
    vertical-align: middle
}

.dot-g {
    background: var(--g)
}

.dot-r {
    background: var(--r)
}

.dot-y {
    background: var(--y)
}

.rbtn {
    font-size: 11px;
    color: var(--m);
    cursor: pointer;
    background: none;
    border: 1px solid var(--b);
    border-radius: 6px;
    padding: 5px 12px;
    font-family: 'Inter', sans-serif;
    font-weight: 500;
    transition: all .15s;
}

.rbtn:hover {
    border-color: var(--a);
    color: var(--a)
}

/* ── Responsive ──────────────────────────────────── */
@media(max-width:768px) {
    .topbar {
        display: flex
    }

    .layout {
        display: block
    }

    .sidebar {
        position: fixed;
        top: 0;
        left: -240px;
        width: 240px;
        height: 100vh;
        z-index: 200;
        transition: left .25s ease;
        overflow-y: auto;
        padding-top: 20px;
    }

    .sidebar.open {
        left: 0;
        box-shadow: 4px 0 24px rgba(0, 0, 0, .12)
    }

    .main {
        padding: 24px 16px
    }

    .cards {
        grid-template-columns: repeat(auto-fill, minmax(140px, 1fr))
    }

    .btns {
        gap: 6px
    }

    .btn {
        padding: 8px 14px;
        font-size: 12px
    }

    .logbody {
        max-height: 340px
    }

    .toast {
        bottom: 16px;
        right: 16px;
        left: 16px
    }
}

@media(max-width:480px) {
    .cards {
        grid-template-columns: 1fr 1fr
    }

    .ptitle {
        font-size: 18px
    }

    .main {
        padding: 20px 14px
    }

    .login-box {
        padding: 32px 20px;
        border-radius: 12px
    }
}
}

/* ── Health Alerts ───────────────────────────────────── */
.health-alerts {
    display: flex;
    flex-direction: column;
    gap: 8px;
    margin-bottom: 20px
}

.health-alert {
    display: flex;
    align-items: flex-start;
    gap: 12px;
    padding: 12px 16px;
    border-radius: 10px;
    border: 1px solid transparent;
    font-size: 12px
}

.health-alert.health-quota {
    background: #fffbeb;
    border-color: #fde68a;
    color: #92400e
}

.health-alert.health-safety {
    background: #faf5ff;
    border-color: #e9d5ff;
    color: #6b21a8
}

.health-alert.health-auth,
.health-alert.health-server,
.health-alert.health-crash {
    background: #fff5f5;
    border-color: #fecaca;
    color: #991b1b
}

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

.alert-title {
    font-weight: 600;
    margin-bottom: 2px
}

.alert-line {
    font-size: 10.5px;
    opacity: .65;
    font-family: 'SF Mono', 'Fira Code', monospace;
    word-break: break-all;
    margin-top: 3px
}

/* ── Chat ────────────────────────────────────────────── */
.chat-wrap {
    background: var(--surf);
    border: 1px solid var(--b);
    border-radius: 12px;
    overflow: hidden;
    display: flex;
    flex-direction: column;
    height: 480px;
    margin-bottom: 16px
}

.chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 20px;
    display: flex;
    flex-direction: column;
    gap: 12px
}

.chat-empty {
    color: var(--m);
    font-size: 13px;
    text-align: center;
    margin: auto
}

.chat-msg {
    display: flex;
    max-width: 82%
}

.chat-msg.user {
    align-self: flex-end
}

.chat-msg.ai {
    align-self: flex-start
}

.chat-bubble {
    padding: 10px 14px;
    border-radius: 12px;
    font-size: 13px;
    line-height: 1.65;
    word-break: break-word
}

.chat-bubble code {
    background: rgba(0, 0, 0, .07);
    padding: 1px 5px;
    border-radius: 4px;
    font-size: 11.5px;
    font-family: 'SF Mono', 'Fira Code', monospace
}

.chat-msg.user .chat-bubble {
    background: var(--a);
    color: #fff;
    border-bottom-right-radius: 3px
}

.chat-msg.ai .chat-bubble {
    background: var(--s);
    border: 1px solid var(--b);
    color: var(--t);
    border-bottom-left-radius: 3px
}

.chat-bubble.thinking {
    color: var(--m);
    letter-spacing: 5px;
    font-size: 20px;
    padding: 6px 16px
}

.chat-bubble.chat-err {
    color: var(--r);
    background: #fff5f5;
    border-color: #fecaca
}

.chat-bar {
    display: flex;
    align-items: flex-end;
    gap: 10px;
    padding: 12px 16px;
    border-top: 1px solid var(--b);
    background: var(--surf)
}

.chat-input {
    flex: 1;
    background: var(--s);
    border: 1px solid var(--b);
    border-radius: 8px;
    padding: 9px 12px;
    font-family: 'Inter', sans-serif;
    font-size: 13px;
    color: var(--t);
    outline: none;
    resize: none;
    max-height: 120px;
    line-height: 1.5;
    transition: border .15s
}

.chat-input:focus {
    border-color: var(--a);
    background: #fff
}

.chat-send {
    width: 36px;
    height: 36px;
    background: var(--a);
    border: none;
    border-radius: 8px;
    cursor: pointer;
    color: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    transition: all .15s
}

.chat-send:hover {
    background: #d41e4a
}

.chat-send:disabled {
    background: var(--b);
    cursor: not-allowed
}

.chat-actions {
    display: flex;
    gap: 8px;
    margin-bottom: 16px;
    flex-wrap: wrap
}

.models-panel {
    background: var(--surf);
    border: 1px solid var(--b);
    border-radius: 12px;
    padding: 16px 20px;
    margin-top: 8px
}

.models-title {
    font-size: 12px;
    font-weight: 700;
    color: var(--t);
    margin-bottom: 12px
}

.model-group {
    margin-bottom: 14px
}

.model-provider {
    font-size: 10px;
    text-transform: uppercase;
    letter-spacing: .08em;
    font-weight: 700;
    color: var(--m);
    margin-bottom: 6px;
    padding-bottom: 4px;
    border-bottom: 1px solid var(--b)
}

.model-row {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 7px 8px;
    border-radius: 8px;
    cursor: pointer;
    transition: background .12s;
    flex-wrap: wrap
}

.model-row:hover {
    background: var(--s)
}

.model-name {
    font-size: 13px;
    font-weight: 600;
    color: var(--t);
    min-width: 160px
}

.model-badge {
    font-size: 10px;
    font-weight: 700;
    padding: 2px 7px;
    border-radius: 20px;
    flex-shrink: 0;
    white-space: nowrap
}

.model-badge.free {
    background: #f0fdf4;
    color: var(--g);
    border: 1px solid #bbf7d0
}

.model-badge.paid {
    background: #fff0f3;
    color: var(--a);
    border: 1px solid #fecdd3
}

.model-note {
    font-size: 11.5px;
    color: var(--m)
}

@media(max-width:768px) {
    .chat-wrap {
        height: 360px
    }

    .chat-msg {
        max-width: 92%
    }

    .model-name {
        min-width: auto
    }
}