:root{
    --chat-font: ui-sans-serif, system-ui, -apple-system, Segoe UI, Roboto, Helvetica, Arial;
    --mono: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;

    --bg-main:#ffffff;
    --bg-panel:#f9fafb;
    --bg-hover:#f3f4f6;
    --border:#e5e7eb;
    --text:#343d4f;
    --textdark:#171717;
    --muted:#6b7280;
    --shadow:0 8px 20px rgba(0,0,0,.08);
    --topnav-h:78px;
}

html[data-theme="dark"]{
    --bg-main:#0f1115;
    --bg-panel:#171a21;
    --bg-hover:#20242d;
    --border:#2a3140;
    --text:#e8ecf3;
    --textdark:#ffffff;
    --muted:#97a0af;
    --shadow:0 10px 24px rgba(0,0,0,.35);
}

*{box-sizing:border-box}
html,body{height:100%}
body{
    margin:0;
    background:var(--bg-main);
    color:var(--text);
    font-family:var(--chat-font);
}

a{
    color:inherit;
    text-decoration:none;
}

.topbar{
    position:sticky;
    top:0;
    z-index:50;
    display:flex;
    justify-content:space-between;
    align-items:center;
    gap:12px;
    padding:12px 16px;
    background:var(--bg-panel);
    border-bottom:1px solid var(--border);
    box-shadow:var(--shadow);
}

.topbar-left,
.topbar-right,
.navlinks{
    display:flex;
    align-items:center;
    gap:10px;
    flex-wrap:wrap;
}

.brand{
    display:flex;
    align-items:center;
    gap:10px;
    font-weight:900;
}

.navlinks a{
    padding:8px 12px;
    border-radius:10px;
    font-weight:700;
}

.navlinks a:hover{
    background:var(--bg-hover);
}

.page-wrap{
    padding:16px;
}

.hrow{
    display:flex;
    justify-content:space-between;
    align-items:center;
    gap:12px;
    flex-wrap:wrap;
    margin-bottom:14px;
}

.hrow h1{
    margin:0;
    font-size:22px;
    font-weight:900;
}

.grid{
    display:grid;
    gap:14px;
}

.cards{
    display:grid;
    grid-template-columns:repeat(4,1fr);
    gap:14px;
}

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

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

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

.kpi{
    background:var(--bg-main);
    border:1px solid var(--border);
    border-radius:14px;
    padding:14px;
    display:flex;
    gap:12px;
    align-items:center;
}

.kpi .ico{
    width:42px;
    height:42px;
    border-radius:12px;
    border:1px solid var(--border);
    display:flex;
    align-items:center;
    justify-content:center;
}

.kpi .val{
    font-size:22px;
    font-weight:900;
}

.kpi .lbl{
    font-weight:700;
}

.kpi .hint{
    font-size:.85rem;
    color:var(--muted);
}

.pill,
.badge{
    display:inline-flex;
    align-items:center;
    gap:8px;
    padding:6px 12px;
    border-radius:999px;
    border:1px solid var(--border);
    background:var(--bg-main);
    font-weight:700;
    font-size:.82rem;
}

.badge.ok{background:#ecfdf5;border-color:#bbf7d0;color:#065f46}
.badge.err{background:#fff1f2;border-color:#fecaca;color:#991b1b}
.badge.warn{background:#fff7ed;border-color:#fed7aa;color:#9a3412}

.btn{
    display:inline-flex;
    align-items:center;
    gap:8px;
    padding:9px 12px;
    border-radius:10px;
    border:1px solid var(--border);
    background:var(--bg-main);
    color:var(--text);
    font-weight:700;
    cursor:pointer;
}

.btn:hover{
    background:var(--bg-hover);
}

.btn.primary{
    background:#000;
    color:#fff;
    border-color:#000;
}

.btn.primary:hover{
    background:#111;
}

.btn.small{
    padding:7px 10px;
    font-size:.85rem;
}

.btn.danger{
    border-color:#b91c1c;
    color:#b91c1c;
    background:transparent;
}

.main-form label{
    display:block;
    margin-top:12px;
    font-weight:900;
}

input,
select,
textarea{
    width:100%;
    margin-top:6px;
    padding:11px 12px;
    border-radius:12px;
    border:1px solid var(--border);
    background:var(--bg-main);
    color:var(--text);
    font-family:inherit;
    font-weight:600;
}

textarea{
    min-height:120px;
    resize:vertical;
}

input:focus,
select:focus,
textarea:focus{
    outline:none;
    border-color:#000;
}

.form-row{
    display:grid;
    grid-template-columns:1fr 1fr;
    gap:14px;
}

@media(max-width:900px){
    .form-row{grid-template-columns:1fr}
}

.table-wrap{
    overflow:auto;
    margin-top:14px;
}

table{
    width:100%;
    border-collapse:collapse;
    background:var(--bg-main);
    border:1px solid var(--border);
    border-radius:12px;
    overflow:hidden;
}

th,td{
    padding:10px;
    border-bottom:1px solid var(--border);
    text-align:left;
    vertical-align:top;
}

th{
    background:var(--bg-panel);
    font-weight:900;
}

tr:last-child td{
    border-bottom:0;
}

.alert{
    margin-top:12px;
    padding:10px 12px;
    border-radius:12px;
    font-weight:700;
    border:1px solid var(--border);
}

.alert.ok{
    border-color:#bbf7d0;
    background:#ecfdf5;
    color:#065f46;
}

.alert.error{
    border-color:#fecaca;
    background:#fff1f2;
    color:#991b1b;
}

.sub{
    color:var(--muted);
    font-size:.88rem;
    font-weight:600;
}

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

.shell{
    display:grid;
    grid-template-columns:360px 1fr;
    gap:12px;
    padding:0;
    min-height:calc(100vh - 140px);
}

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

.card.maincol{
    display:flex;
    flex-direction:column;
    min-height:620px;
}

.topbar2{
    display:flex;
    align-items:center;
    justify-content:space-between;
    gap:10px;
    margin-bottom:10px;
    flex-wrap:wrap;
}

.title{
    font-size:18px;
    font-weight:900;
}

.chatbox{
    flex:1;
    min-height:0;
    overflow:auto;
    background:var(--bg-main);
    border:1px solid var(--border);
    border-radius:14px;
    padding:12px;
    margin-bottom:12px;
}

.msg{
    border:1px solid var(--border);
    border-radius:14px;
    padding:10px 12px;
    margin:10px 0;
}

.msg.user{background:var(--bg-main)}
.msg.ai{background:var(--bg-panel)}

.meta{
    display:flex;
    gap:10px;
    align-items:center;
    color:var(--muted);
    font-size:.8rem;
    font-weight:700;
    margin-bottom:6px;
    flex-wrap:wrap;
}

.msg-text{
    line-height:1.6;
    white-space:pre-wrap;
    word-break:break-word;
}

.composer-row{
    margin-top:auto;
}

.composer-wrap{
    position:relative;
    border:1px solid var(--border);
    background:var(--bg-panel);
    border-radius:16px;
    box-shadow:var(--shadow);
    padding:10px;
}

#question{
    width:100%;
    min-height:80px;
    max-height:220px;
    resize:vertical;
    padding:12px 60px 12px 12px;
}

.send-in{
    position:absolute;
    right:16px;
    bottom:16px;
    width:40px;
    height:40px;
    border-radius:999px;
    border:1px solid #000;
    background:#000;
    color:#fff;
    display:inline-flex;
    align-items:center;
    justify-content:center;
    cursor:pointer;
}

.send-in i{color:#fff}

.topbar{
    position:sticky;
    top:0;
    z-index:50;
    background:var(--bg-panel);
    border-bottom:1px solid var(--border);
    box-shadow:var(--shadow);
}

.topbar-main{
    max-width:100%;
    padding:14px 18px;
    display:flex;
    justify-content:space-between;
    align-items:flex-start;
    gap:16px;
}

.topbar-left{
    min-width:0;
    flex:1;
    display:flex;
    flex-direction:column;
    gap:14px;
}

.topbar-right{
    display:flex;
    align-items:center;
    gap:12px;
    flex-wrap:wrap;
    justify-content:flex-end;
}

.brand-link{
    display:inline-flex;
    align-items:center;
    gap:12px;
    text-decoration:none;
    color:var(--text);
    width:max-content;
}

.brand-icon{
    width:42px;
    height:42px;
    border-radius:12px;
    border:1px solid var(--border);
    background:var(--bg-main);
    display:flex;
    align-items:center;
    justify-content:center;
    box-shadow:var(--shadow);
    flex:0 0 auto;
}

.brand-icon i{
    font-size:18px;
}

.brand-text{
    font-size:1.45rem;
    font-weight:900;
    letter-spacing:-0.02em;
    line-height:1;
}

.navlinks{
    display:flex;
    flex-wrap:wrap;
    gap:10px;
    min-width:0;
}

.navlink{
    display:inline-flex;
    align-items:center;
    gap:8px;
    padding:10px 14px;
    border-radius:12px;
    border:1px solid transparent;
    color:var(--text);
    background:transparent;
    font-weight:800;
    font-size:.95rem;
    transition:.15s ease;
}

.navlink i{
    font-size:14px;
    opacity:.9;
}

.navlink:hover{
    background:var(--bg-hover);
    border-color:var(--border);
}

.navlink.active{
    background:var(--bg-main);
    border-color:var(--border);
    box-shadow:var(--shadow);
}

.userchips{
    display:flex;
    align-items:center;
    gap:10px;
    flex-wrap:wrap;
    justify-content:flex-end;
}

.pill{
    display:inline-flex;
    align-items:center;
    gap:8px;
    padding:8px 14px;
    border-radius:999px;
    border:1px solid var(--border);
    background:var(--bg-main);
    font-weight:800;
    font-size:.86rem;
    white-space:nowrap;
}

@media (max-width: 1100px){
    .topbar-main{
        flex-direction:column;
        align-items:stretch;
    }

    .topbar-right{
        justify-content:space-between;
    }
}

@media (max-width: 720px){
    .topbar-main{
        padding:12px;
    }

    .brand-text{
        font-size:1.2rem;
    }

    .navlinks{
        gap:8px;
    }

    .navlink{
        padding:9px 12px;
        font-size:.9rem;
    }

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

    .userchips{
        justify-content:flex-start;
    }
}

.topbar-premium{
    position:sticky;
    top:0;
    z-index:60;
    background:var(--bg-panel);
    border-bottom:1px solid var(--border);
    box-shadow:var(--shadow);
    backdrop-filter:blur(8px);
}

.topbar-row{
    padding-left:18px;
    padding-right:18px;
}

.topbar-row-main{
    display:flex;
    align-items:center;
    justify-content:space-between;
    gap:16px;
    padding-top:14px;
    padding-bottom:12px;
    border-bottom:1px solid var(--border);
}

.topbar-row-nav{
    padding-top:12px;
    padding-bottom:12px;
}

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

.brand-link{
    display:inline-flex;
    align-items:center;
    gap:14px;
    text-decoration:none;
    color:var(--text);
    min-width:0;
}

.brand-mark{
    width:46px;
    height:46px;
    border-radius:14px;
    border:1px solid var(--border);
    background:var(--bg-main);
    display:flex;
    align-items:center;
    justify-content:center;
    box-shadow:var(--shadow);
    flex:0 0 auto;
}

.brand-mark i{
    font-size:18px;
}

.brand-copy{
    display:flex;
    flex-direction:column;
    gap:4px;
    min-width:0;
}

.brand-title{
    font-size:1.3rem;
    font-weight:900;
    letter-spacing:-0.02em;
    line-height:1.1;
}

.brand-sub{
    font-size:.82rem;
    color:var(--muted);
    font-weight:700;
    line-height:1;
}

.topbar-user-wrap{
    display:flex;
    align-items:center;
    justify-content:flex-end;
    gap:12px;
    flex-wrap:wrap;
}

.userchips{
    display:flex;
    align-items:center;
    gap:10px;
    flex-wrap:wrap;
    justify-content:flex-end;
}

.navlinks-premium{
    display:flex;
    flex-wrap:wrap;
    gap:10px;
}

.navlink{
    display:inline-flex;
    align-items:center;
    gap:8px;
    padding:10px 14px;
    border-radius:12px;
    border:1px solid transparent;
    color:var(--text);
    background:transparent;
    font-weight:800;
    font-size:.93rem;
    line-height:1;
    transition:all .15s ease;
}

.navlink i{
    font-size:13px;
    opacity:.9;
}

.navlink:hover{
    background:var(--bg-hover);
    border-color:var(--border);
}

.navlink.active{
    background:var(--bg-main);
    border-color:var(--border);
    box-shadow:var(--shadow);
}

.pill{
    display:inline-flex;
    align-items:center;
    gap:8px;
    padding:8px 14px;
    border-radius:999px;
    border:1px solid var(--border);
    background:var(--bg-main);
    color:var(--text);
    font-weight:800;
    font-size:.84rem;
    white-space:nowrap;
}

@media (max-width: 1100px){
    .topbar-row-main{
        flex-direction:column;
        align-items:flex-start;
    }

    .topbar-user-wrap{
        width:100%;
        justify-content:space-between;
    }

    .userchips{
        justify-content:flex-start;
    }
}

@media (max-width: 720px){
    .topbar-row{
        padding-left:12px;
        padding-right:12px;
    }

    .topbar-row-main{
        padding-top:12px;
        padding-bottom:10px;
    }

    .topbar-row-nav{
        padding-top:10px;
        padding-bottom:10px;
    }

    .brand-mark{
        width:42px;
        height:42px;
    }

    .brand-title{
        font-size:1.08rem;
    }

    .brand-sub{
        font-size:.76rem;
    }

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

    .userchips{
        width:100%;
    }

    .navlinks-premium{
        gap:8px;
    }

    .navlink{
        padding:9px 12px;
        font-size:.88rem;
    }
}

.page-header{
    display:flex;
    align-items:center;
    justify-content:space-between;
    gap:16px;
    margin-bottom:22px;
    padding-bottom:14px;
    border-bottom:1px solid var(--border);
}

.page-header-left{
    display:flex;
    flex-direction:column;
    gap:4px;
}

.page-title{
    margin:0;
    font-size:1.6rem;
    font-weight:900;
    letter-spacing:-0.02em;
}

.page-subtitle{
    font-size:.9rem;
    color:var(--muted);
    font-weight:600;
}

.page-header-actions{
    display:flex;
    align-items:center;
    gap:10px;
    flex-wrap:wrap;
}

@media (max-width:800px){

    .page-header{
        flex-direction:column;
        align-items:flex-start;
        gap:12px;
    }

    .page-header-actions{
        width:100%;
        justify-content:flex-start;
    }

}

.user-panel{
    position:fixed;
    right:20px;
    bottom:20px;
    z-index:120;
    display:flex;
    align-items:center;
    gap:14px;
    padding:12px 14px;
    border:1px solid var(--border);
    border-radius:14px;
    background:var(--bg-panel);
    box-shadow:var(--shadow);
}

.user-panel-info{
    display:flex;
    flex-direction:column;
    gap:4px;
}

.user-panel-name,
.user-panel-role{
    display:flex;
    align-items:center;
    gap:8px;
    font-weight:700;
}

.user-panel-role{
    font-size:.84rem;
    color:var(--muted);
    font-weight:600;
}

.logout-btn{
    white-space:nowrap;
}

@media (max-width: 720px){
    .user-panel{
        left:12px;
        right:12px;
        bottom:12px;
        justify-content:space-between;
        flex-wrap:wrap;
    }
}