/* Bổ sung nhỏ cho Bootstrap 5 — mọi màu lấy từ biến của theme đang chọn */
:root { --topbar-h: 56px; --sidebar-w: 248px; }
html, body { height: 100%; }
body { overflow-x: hidden; }
.mono { font-family: var(--bs-font-monospace); font-size: .86em; }
.min-w-0 { min-width: 0; }
.cursor-pointer { cursor: pointer; }

/* ---------- đăng nhập ---------- */
.auth { min-height: 100vh; min-height: 100dvh; display: flex; flex-direction: column; align-items: center; justify-content: center; padding: 24px 14px; background: var(--bs-tertiary-bg); }
.auth-card { width: 100%; max-width: 420px; }
.auth-card.wide { max-width: 540px; }
.auth-logo { width: 54px; height: 54px; border-radius: 14px; display: inline-flex; align-items: center; justify-content: center; font-size: 28px; background: var(--bs-primary); color: #fff; margin-bottom: 10px; }
.otp-input { letter-spacing: .45em; font-size: 1.6rem; text-align: center; font-family: var(--bs-font-monospace); }
.qr-box { background: #fff; padding: 10px; border-radius: 8px; display: inline-block; border: 1px solid var(--bs-border-color); }
.qr-box svg { width: 200px; height: 200px; display: block; }
.codes { display: grid; grid-template-columns: repeat(2, 1fr); gap: 6px; font-family: var(--bs-font-monospace); }
.codes span { background: var(--bs-tertiary-bg); border: 1px solid var(--bs-border-color); border-radius: 6px; padding: 6px; text-align: center; }

/* ---------- khung ---------- */
.topbar { height: var(--topbar-h); z-index: 1030; flex-wrap: nowrap; }
.layout { display: flex; min-height: calc(100vh - var(--topbar-h)); }
.sidebar { width: var(--sidebar-w); flex-shrink: 0; background: var(--bs-tertiary-bg); }
@media (min-width: 992px) {
  .sidebar { position: sticky; top: var(--topbar-h); height: calc(100vh - var(--topbar-h)); overflow-y: auto; }
}
.sidebar .nav-link { color: var(--bs-body-color); display: flex; align-items: center; gap: 10px; padding: .5rem .75rem; }
.sidebar .nav-link i { font-size: 1.05rem; width: 20px; text-align: center; opacity: .8; }
.sidebar .nav-link.active { color: var(--bs-nav-pills-link-active-color, #fff); }
.sidebar .nav-link.active i { opacity: 1; }
.sidebar .nav-link:not(.active):hover { background: var(--bs-secondary-bg); }
.sidebar .nav-sec { font-size: .72rem; text-transform: uppercase; letter-spacing: .08em; color: var(--bs-secondary-color); padding: .9rem .75rem .25rem; font-weight: 600; }
#view { flex: 1; min-width: 0; padding: 1rem; }
@media (min-width: 992px) { #view { padding: 1.5rem; } }
#view.flush { padding: 0; }

.page-head { display: flex; flex-wrap: wrap; gap: .75rem; align-items: flex-end; justify-content: space-between; margin-bottom: 1.25rem; }
.page-head h1 { font-size: 1.45rem; margin: 0; }
.page-head p { margin: .25rem 0 0; color: var(--bs-secondary-color); }

/* ---------- thẻ số liệu ---------- */
.kpi .card-body { padding: .9rem 1rem; }
.kpi .kpi-ic { width: 40px; height: 40px; border-radius: 10px; display: flex; align-items: center; justify-content: center; font-size: 1.2rem; flex-shrink: 0; }
.kpi .kpi-v { font-size: 1.45rem; font-weight: 700; line-height: 1.15; }
.kpi .kpi-l { font-size: .74rem; color: var(--bs-secondary-color); text-transform: uppercase; letter-spacing: .03em; }
.kpi .kpi-s { font-size: .76rem; color: var(--bs-secondary-color); }
.card-header h6 { margin: 0; font-weight: 600; }

/* ---------- avatar ---------- */
.avatar { width: 32px; height: 32px; border-radius: 50%; display: inline-flex; align-items: center; justify-content: center; font-weight: 700; font-size: .78rem; flex-shrink: 0; position: relative; }
.avatar.lg { width: 56px; height: 56px; font-size: 1.15rem; }
.avatar.sm { width: 24px; height: 24px; font-size: .65rem; }
.avatar .on { position: absolute; right: -1px; bottom: -1px; width: 11px; height: 11px; border-radius: 50%; background: var(--bs-success); border: 2px solid var(--bs-body-bg); }
.avatar.lg .on { width: 15px; height: 15px; }
.dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; background: var(--bs-secondary-color); flex-shrink: 0; }
.dot.on { background: var(--bs-success); box-shadow: 0 0 0 3px rgba(var(--bs-success-rgb), .2); }
.dot.run { background: var(--bs-warning); animation: pulse 1.2s infinite; }
@keyframes pulse { 50% { opacity: .35; } }

/* ---------- biểu đồ ---------- */
.chart { width: 100%; height: auto; display: block; }
.chart text { font-size: 10px; fill: var(--bs-secondary-color); }
.chart .grid { stroke: var(--bs-border-color); stroke-width: 1; }
.chart .b1 { fill: var(--bs-primary); }
.chart .b2 { fill: var(--bs-success); }
.chart .b3 { fill: var(--bs-info); }
.chart .ln { fill: none; stroke: var(--bs-warning); stroke-width: 2; stroke-linejoin: round; }
.chart .ar { fill: var(--bs-warning); opacity: .12; }
.chart .pt { fill: var(--bs-warning); }
.legend { display: flex; gap: 12px; flex-wrap: wrap; font-size: .78rem; color: var(--bs-secondary-color); }
.legend i { display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-right: 4px; vertical-align: -1px; }
.heat { display: grid; grid-template-columns: repeat(24, 1fr); gap: 3px; }
.heat div { aspect-ratio: 1; border-radius: 3px; background: var(--bs-primary); }
.heat-l { display: grid; grid-template-columns: repeat(24, 1fr); gap: 3px; font-size: .62rem; color: var(--bs-secondary-color); text-align: center; }

/* ---------- danh sách hoạt động ---------- */
.feed .list-group-item { display: flex; gap: .7rem; align-items: flex-start; }
.feed .fi { width: 30px; height: 30px; border-radius: 8px; display: flex; align-items: center; justify-content: center; flex-shrink: 0; }
.feed .ft { flex: 1; min-width: 0; }
.feed .ft .sub { font-size: .8rem; color: var(--bs-secondary-color); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.feed .fd { font-size: .75rem; color: var(--bs-secondary-color); white-space: nowrap; }
.table td, .table th { vertical-align: middle; }
.table-click tbody tr { cursor: pointer; }
.chip { display: inline-block; font-size: .74rem; padding: .08rem .5rem; border-radius: 999px; background: var(--bs-secondary-bg); border: 1px solid var(--bs-border-color); margin: 1px 3px 1px 0; white-space: nowrap; }

/* ---------- phiên làm việc / chat ---------- */
.ses { display: flex; height: calc(100vh - var(--topbar-h)); height: calc(100dvh - var(--topbar-h)); }
.ses-list { width: 300px; flex-shrink: 0; border-right: 1px solid var(--bs-border-color); display: flex; flex-direction: column; background: var(--bs-body-bg); }
.ses-list .items { overflow-y: auto; flex: 1; }
.ses-list .grp { font-size: .7rem; text-transform: uppercase; letter-spacing: .06em; color: var(--bs-secondary-color); padding: .75rem 1rem .25rem; font-weight: 600; }
.ses-list .list-group-item { border-left: 0; border-right: 0; }
.chat { flex: 1; min-width: 0; display: flex; flex-direction: column; background: var(--bs-tertiary-bg); }
.chat-top { display: flex; align-items: center; gap: .6rem; padding: .6rem 1rem; border-bottom: 1px solid var(--bs-border-color); background: var(--bs-body-bg); flex-wrap: wrap; }
.chat-top .ti { flex: 1; min-width: 160px; }
.chat-top h2 { font-size: 1.02rem; margin: 0; font-weight: 600; }
.msgs { flex: 1; overflow-y: auto; padding: 1rem; display: flex; flex-direction: column; gap: .7rem; }
.msgs > * { max-width: 900px; width: 100%; margin-left: auto; margin-right: auto; }
.msgs > .msg-user { align-self: flex-end; width: auto; max-width: min(720px, 88%); margin-right: max(0px, calc((100% - 900px) / 2)); background: var(--bs-primary); color: #fff; padding: .6rem .85rem; border-radius: 14px 14px 4px 14px; white-space: pre-wrap; word-break: break-word; }
.msg-user .meta { font-size: .72rem; opacity: .8; margin-top: 4px; }
.msg-text { background: var(--bs-body-bg); border: 1px solid var(--bs-border-color); padding: .7rem .95rem; border-radius: 12px; word-break: break-word; }
.msg-text p { margin: 0 0 .5rem; } .msg-text p:last-child, .msg-text ul:last-child, .msg-text ol:last-child { margin-bottom: 0; }
.msg-text pre, .tool pre, .think pre, .steps pre, pre.box { background: var(--bs-secondary-bg); color: var(--bs-body-color); border-radius: 8px; padding: .6rem .75rem; font-size: .8rem; max-height: 420px; overflow: auto; white-space: pre-wrap; word-break: break-word; margin: .4rem 0; }
.msg-text h4 { font-size: 1rem; margin: .6rem 0 .35rem; }
.tool, .think { background: var(--bs-body-bg); border: 1px solid var(--bs-border-color); border-radius: 10px; font-size: .86rem; }
.tool summary, .think summary { padding: .45rem .75rem; cursor: pointer; display: flex; gap: .5rem; align-items: center; list-style: none; }
.tool summary::-webkit-details-marker, .think summary::-webkit-details-marker { display: none; }
.tool .nm { font-weight: 600; }
.tool .sm { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--bs-secondary-color); font-family: var(--bs-font-monospace); font-size: .78rem; }
.tool pre, .think pre { margin: 0 .6rem .6rem; }
.tool pre.out.bad { color: var(--bs-danger); }
.result-line { font-size: .8rem; color: var(--bs-secondary-color); display: flex; gap: .9rem; flex-wrap: wrap; padding: 0 .25rem; }
.working { color: var(--bs-secondary-color); font-size: .88rem; display: flex; align-items: center; gap: .5rem; }
.composer { border-top: 1px solid var(--bs-border-color); background: var(--bs-body-bg); padding: .65rem .8rem calc(.65rem + env(safe-area-inset-bottom)); }
.composer textarea { resize: none; max-height: 40vh; }
.composer .opts { display: flex; gap: .6rem; align-items: center; flex-wrap: wrap; font-size: .8rem; color: var(--bs-secondary-color); margin-top: .45rem; }
.composer .opts .form-select { width: auto; }
@media (max-width: 991.98px) {
  .ses-list { width: 100%; border-right: 0; }
  .ses.has-chat .ses-list { display: none; }
  .ses:not(.has-chat) .chat { display: none; }
}

/* ---------- diff / bước triển khai ---------- */
.diff { font-family: var(--bs-font-monospace); font-size: .78rem; white-space: pre; max-height: 600px; overflow: auto; border: 1px solid var(--bs-border-color); border-radius: 8px; background: var(--bs-body-bg); }
.diff div { padding: 0 .75rem; min-height: 1.25em; }
.diff .a { background: rgba(var(--bs-success-rgb), .15); }
.diff .d { background: rgba(var(--bs-danger-rgb), .15); }
.diff .h { color: var(--bs-info); }
.diff .f { font-weight: 700; background: var(--bs-secondary-bg); padding-top: .3rem; padding-bottom: .3rem; }
.steps .stp { display: flex; gap: .6rem; padding: .5rem 0; border-bottom: 1px dashed var(--bs-border-color); }
.steps .stp:last-child { border-bottom: 0; }
.steps .si { width: 24px; height: 24px; border-radius: 50%; display: flex; align-items: center; justify-content: center; flex-shrink: 0; font-size: .8rem; }
.steps details { flex: 1; min-width: 0; }
.steps summary { display: flex; justify-content: space-between; gap: .5rem; cursor: pointer; }

/* ---------- chọn giao diện ---------- */
.theme-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: .75rem; }
.theme-opt { border: 2px solid var(--bs-border-color); border-radius: 10px; padding: .55rem; cursor: pointer; background: var(--bs-body-bg); text-align: left; color: var(--bs-body-color); }
.theme-opt.active { border-color: var(--bs-primary); box-shadow: 0 0 0 3px rgba(var(--bs-primary-rgb), .2); }
.theme-opt .sw { height: 46px; border-radius: 6px; display: flex; overflow: hidden; margin-bottom: .4rem; border: 1px solid var(--bs-border-color); }
.theme-opt .sw span { flex: 1; }
.theme-opt .nm { font-weight: 600; font-size: .88rem; }
.theme-opt .ds { font-size: .72rem; color: var(--bs-secondary-color); }
.sw-dot { width: 14px; height: 14px; border-radius: 4px; display: inline-block; margin-right: 8px; vertical-align: -2px; border: 1px solid rgba(0,0,0,.15); }

.featpick { display: grid; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: .25rem .75rem; max-height: 260px; overflow: auto; border: 1px solid var(--bs-border-color); border-radius: var(--bs-border-radius); padding: .5rem .75rem; }
.secret-box { font-family: var(--bs-font-monospace); white-space: pre-wrap; word-break: break-all; background: var(--bs-tertiary-bg); border: 1px dashed var(--bs-border-color); border-radius: 8px; padding: .75rem; user-select: all; }
.progress.thin { height: 6px; }
.nav-tabs.scroll { flex-wrap: nowrap; overflow-x: auto; overflow-y: hidden; }
.nav-tabs.scroll .nav-link { white-space: nowrap; }
.stat-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: .75rem; }
.stat { border: 1px solid var(--bs-border-color); border-radius: var(--bs-border-radius); padding: .6rem .8rem; background: var(--bs-body-bg); }
.stat .l { font-size: .72rem; color: var(--bs-secondary-color); text-transform: uppercase; letter-spacing: .03em; }
.stat .v { font-size: 1.2rem; font-weight: 700; }
.stat .s { font-size: .74rem; color: var(--bs-secondary-color); }

.topbar .navbar-brand { color: var(--bs-emphasis-color); }
