/* ================= Nền tảng ================= */
:root {
    --bg: #0a0c11;
    --panel: #12151c;
    --panel-2: #181c25;
    --panel-3: #1f2430;
    --border: #232835;
    --border-2: #2e3443;
    --text: #e8eaf0;
    --text-2: #b4bac7;
    --muted: #7d8597;
    --primary: #3b82f6;
    --primary-2: #6366f1;
    --primary-soft: rgba(59, 130, 246, .14);
    --ok: #22c55e;
    --warn: #f59e0b;
    --err: #ef4444;
    --violet: #a78bfa;
    --radius: 14px;
    --radius-sm: 10px;
    --shadow: 0 1px 0 rgba(255,255,255,.03) inset, 0 8px 24px -12px rgba(0,0,0,.6);
    --ease: cubic-bezier(.2,.8,.2,1);
}
* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
    background:
        radial-gradient(900px 500px at 85% -10%, rgba(99,102,241,.10), transparent 60%),
        radial-gradient(700px 400px at -10% 110%, rgba(59,130,246,.08), transparent 60%),
        var(--bg);
    background-attachment: fixed;
    color: var(--text);
    font: 14px/1.5 "Inter", "Segoe UI Variable Text", "Segoe UI", system-ui, -apple-system, sans-serif;
    -webkit-font-smoothing: antialiased;
}
::selection { background: rgba(59,130,246,.35); }
::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-thumb { background: #262b38; border-radius: 10px; border: 3px solid transparent; background-clip: padding-box; }
::-webkit-scrollbar-thumb:hover { background-color: #333a4b; }
::-webkit-scrollbar-track { background: transparent; }

h1 { font-size: 15px; margin: 0; font-weight: 650; letter-spacing: -.01em; }
h2 { font-size: 14px; margin: 0; font-weight: 600; }
h3 { margin: 0 0 4px; font-size: 18px; font-weight: 650; letter-spacing: -.01em; }
.sub, .muted { color: var(--muted); margin: 0; }
.small { font-size: 12px; }
a { color: #60a5fa; }
.hidden { display: none !important; }

.ico, button svg, .meta svg, .note svg { display: inline-grid; flex: none; }
.ico svg, button svg { width: 16px; height: 16px; }

/* ================= Nút ================= */
button {
    font: inherit; font-weight: 500; border-radius: var(--radius-sm); padding: 8px 14px; cursor: pointer;
    border: 1px solid var(--border-2); background: var(--panel-2); color: var(--text);
    display: inline-flex; align-items: center; justify-content: center; gap: 8px; white-space: nowrap;
    transition: background .15s, border-color .15s, color .15s, transform .1s, box-shadow .15s;
}
button:hover:not(:disabled) { border-color: #3d4558; background: var(--panel-3); }
button:active:not(:disabled) { transform: translateY(1px); }
button:focus-visible { outline: 2px solid var(--primary); outline-offset: 2px; }
button:disabled { opacity: .45; cursor: default; }
button.primary {
    background: linear-gradient(180deg, #4f8ff7, var(--primary));
    border-color: transparent; color: #fff; font-weight: 600;
    box-shadow: 0 1px 0 rgba(255,255,255,.2) inset, 0 6px 16px -6px rgba(59,130,246,.6);
}
button.primary:hover:not(:disabled) { background: linear-gradient(180deg, #62a0ff, #4b8ef8); border-color: transparent; }
button.ghost { background: transparent; border-color: var(--border-2); }
button.ghost:hover:not(:disabled) { background: var(--panel-2); }
button.small { padding: 6px 10px; font-size: 12.5px; gap: 6px; }
button.small svg { width: 14px; height: 14px; }
button.lg { padding: 11px 16px; font-size: 15px; }
button.block { width: 100%; }
button.left { justify-content: flex-start; }
button.danger { color: #f87171; }
button.danger:hover:not(:disabled) { background: rgba(239,68,68,.1); border-color: rgba(239,68,68,.35); }
button.icon-only { padding: 6px 8px; }

/* ================= Khung ứng dụng ================= */
.shell { display: grid; grid-template-columns: 252px 1fr; height: 100vh; }
.sidebar {
    background: rgba(18,21,28,.75); backdrop-filter: blur(12px);
    border-right: 1px solid var(--border);
    display: flex; flex-direction: column; padding: 20px 14px; gap: 22px; min-height: 0;
}
.brand { display: flex; gap: 12px; align-items: center; }
.brand small { font-size: 12px; }
.sidebar .brand { padding: 0 6px; }
.logo {
    width: 38px; height: 38px; border-radius: 11px; flex: none; color: #fff;
    background: linear-gradient(135deg, var(--primary), var(--primary-2) 60%, #8b5cf6);
    display: grid; place-items: center; font-weight: 800; font-size: 19px;
    box-shadow: 0 8px 20px -8px rgba(99,102,241,.8), 0 1px 0 rgba(255,255,255,.25) inset;
}
.nav { display: flex; flex-direction: column; gap: 2px; flex: 1; }
.nav-label { font-size: 11px; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); padding: 0 10px 8px; font-weight: 600; }
.nav a {
    position: relative; display: flex; align-items: center; gap: 10px; padding: 9px 10px; border-radius: var(--radius-sm);
    color: var(--text-2); text-decoration: none; font-weight: 500; transition: background .15s, color .15s;
}
.nav a .ico svg { width: 18px; height: 18px; }
.nav a:hover { background: var(--panel-2); color: var(--text); }
.nav a.active { background: var(--primary-soft); color: #dbe7ff; }
.nav a.active .ico { color: #7aa8ff; }
.nav a.active::before {
    content: ""; position: absolute; left: -14px; top: 8px; bottom: 8px; width: 3px; border-radius: 0 3px 3px 0;
    background: linear-gradient(var(--primary), var(--primary-2));
}
.tag {
    margin-left: auto; font-size: 10.5px; font-weight: 600; padding: 2px 7px; border-radius: 999px;
    background: var(--panel-3); color: var(--muted);
}
.sidebar-foot { display: flex; flex-direction: column; gap: 6px; border-top: 1px solid var(--border); padding-top: 14px; }
.sidebar-foot button { border-color: transparent; color: var(--text-2); }
.sidebar-foot button:hover:not(:disabled) { color: var(--text); }
.conn { display: flex; align-items: center; gap: 8px; font-size: 12px; color: var(--muted); padding: 0 10px 8px; }
.conn i { width: 8px; height: 8px; border-radius: 50%; background: var(--ok); box-shadow: 0 0 0 3px rgba(34,197,94,.18); }
.conn-text::after { content: "Đã kết nối server"; }
body.offline .conn i { background: var(--err); box-shadow: 0 0 0 3px rgba(239,68,68,.2); animation: blink 1.2s infinite; }
body.offline .conn-text::after { content: "Mất kết nối, đang thử lại…"; }
@keyframes blink { 50% { opacity: .35; } }

.view { display: flex; flex-direction: column; min-height: 0; min-width: 0; }
header {
    display: flex; align-items: center; justify-content: space-between; gap: 16px; flex-wrap: wrap;
    padding: 22px 32px 18px; border-bottom: 1px solid var(--border);
    background: rgba(10,12,17,.6); backdrop-filter: blur(12px);
}
.view-title { font-size: 22px; font-weight: 700; letter-spacing: -.02em; margin-bottom: 2px; }
.actions { display: flex; gap: 10px; }
.view-body { flex: 1; overflow: auto; padding: 24px 32px 32px; display: flex; flex-direction: column; gap: 18px; min-height: 0; }
.view-body > * { flex-shrink: 0; }

/* ================= KPI ================= */
.kpis { display: grid; grid-template-columns: repeat(4, 1fr); gap: 14px; }
.kpi {
    display: flex; align-items: center; gap: 14px; padding: 16px 18px;
    background: linear-gradient(180deg, var(--panel-2), var(--panel)); border: 1px solid var(--border);
    border-radius: var(--radius); box-shadow: var(--shadow);
}
.kpi-ico { width: 42px; height: 42px; border-radius: 12px; display: grid; place-items: center; flex: none; }
.kpi-ico svg { width: 20px; height: 20px; }
.kpi small { display: block; color: var(--muted); font-size: 12.5px; }
.kpi b { font-size: 24px; font-weight: 700; letter-spacing: -.02em; line-height: 1.2; font-variant-numeric: tabular-nums; }
.kpi span { margin-left: 8px; font-size: 12px; color: var(--warn); }
.kpi.blue .kpi-ico { background: rgba(59,130,246,.14); color: #7aa8ff; }
.kpi.green .kpi-ico { background: rgba(34,197,94,.13); color: #4ade80; }
.kpi.violet .kpi-ico { background: rgba(167,139,250,.14); color: var(--violet); }
.kpi.amber .kpi-ico { background: rgba(245,158,11,.13); color: #fbbf24; }

.kpi span.err { color: #f87171; }

/* ================= Thanh công cụ ================= */
.toolbar { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; margin-bottom: -4px; }
.search {
    flex-direction: row; align-items: center; gap: 8px; width: 230px; padding: 0 12px;
    background: rgba(10,12,17,.6); border: 1px solid var(--border-2); border-radius: var(--radius-sm);
    transition: border-color .15s, box-shadow .15s;
}
.search:focus-within { border-color: var(--primary); box-shadow: 0 0 0 3px rgba(59,130,246,.22); }
.search .ico svg { width: 15px; height: 15px; color: var(--muted); }
.search input[type=search] { flex: 1; min-width: 0; border: 0; background: transparent; padding: 8px 0; box-shadow: none !important; }
.chips { display: flex; gap: 6px; flex-wrap: wrap; }
.chip {
    padding: 5px 6px 5px 12px; border-radius: 999px; font-size: 12.5px; gap: 8px;
    background: transparent; border-color: var(--border); color: var(--text-2);
}
.chip b {
    min-width: 22px; padding: 1px 6px; border-radius: 999px; font-size: 11px; font-weight: 700;
    background: var(--panel-3); color: var(--text-2); font-variant-numeric: tabular-nums;
}
.chip.active { background: var(--primary-soft); border-color: rgba(59,130,246,.45); color: #dbe7ff; }
.chip.active b { background: var(--primary); color: #fff; }
.chip-paused b { color: #fbbf24; }
.chip-error b { color: #f87171; }
.chip.active.chip-paused b, .chip.active.chip-error b { color: #fff; }
.toolbar-right { display: flex; gap: 8px; margin-left: auto; align-items: center; }
select {
    font: inherit; font-size: 13px; color: var(--text); background: rgba(10,12,17,.6) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%237d8597' stroke-width='2.5'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E") no-repeat right 10px center;
    border: 1px solid var(--border-2); border-radius: var(--radius-sm); padding: 7px 30px 7px 12px; appearance: none; cursor: pointer;
}
select:focus { outline: none; border-color: var(--primary); }
.seg { display: flex; border: 1px solid var(--border-2); border-radius: var(--radius-sm); padding: 2px; gap: 2px; }
.seg button { border: 0; padding: 5px 8px; border-radius: 7px; color: var(--muted); }
.seg button.active { background: var(--panel-3); color: var(--text); }

.bulk {
    position: sticky; top: -24px; z-index: 5; display: flex; align-items: center; gap: 8px; flex-wrap: wrap;
    padding: 8px 8px 8px 16px; border-radius: var(--radius); margin-bottom: -6px;
    background: linear-gradient(90deg, rgba(59,130,246,.18), rgba(99,102,241,.14)), var(--panel);
    border: 1px solid rgba(59,130,246,.4); box-shadow: 0 10px 30px -12px rgba(0,0,0,.6);
    animation: pop .15s var(--ease);
}
.bulk #bulkCount { margin-right: auto; color: var(--text-2); }
.bulk #bulkCount b { color: #fff; }
.bulk button { background: rgba(10,12,17,.4); }
.bulk-close { padding: 6px 8px !important; }

input.pick { width: 16px; height: 16px; margin: 0; accent-color: var(--primary); cursor: pointer; flex: none; }

/* ================= Bảng tài khoản ================= */
.table-wrap {
    background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius);
    overflow-x: auto; box-shadow: var(--shadow);
}
.acc-table { width: 100%; border-collapse: collapse; font-size: 13px; }
.acc-table th {
    position: sticky; top: 0; text-align: left; font-weight: 600; font-size: 11.5px; color: var(--muted);
    text-transform: uppercase; letter-spacing: .05em; padding: 10px 12px; background: var(--panel-2);
    border-bottom: 1px solid var(--border); white-space: nowrap;
}
.acc-table td { padding: 10px 12px; border-bottom: 1px solid var(--border); vertical-align: middle; white-space: nowrap; }
.acc-table tbody tr:last-child td { border-bottom: 0; }
.acc-table tbody tr { transition: background .12s; }
.acc-table tbody tr:hover { background: rgba(255,255,255,.025); }
.acc-table tr.selected { background: rgba(59,130,246,.08); }
.acc-table tr.selected:hover { background: rgba(59,130,246,.12); }
.acc-table tr.disabled td:not(.c-pick):not(.c-toggle):not(.c-actions) { opacity: .5; }
.acc-table .num { text-align: right; font-variant-numeric: tabular-nums; font-weight: 600; }
.acc-table th.num { font-weight: 600; }
.acc-table .c-pick { width: 36px; padding-right: 0; }
.acc-table .c-toggle { width: 56px; }
.acc-table .c-last, .acc-table .c-next { color: var(--text-2); font-variant-numeric: tabular-nums; }
.acc { display: flex; align-items: center; gap: 10px; min-width: 200px; max-width: 320px; }
.acc .avatar { width: 34px; height: 34px; font-size: 14px; }
.acc .avatar .dot { width: 11px; height: 11px; border-width: 2px; border-color: var(--panel); }
.acc .name { font-size: 13.5px; }
.acc .meta { gap: 10px; font-size: 11.5px; margin-top: 0; flex-wrap: nowrap; }
.c-status .badge { font-size: 11.5px; padding: 2px 9px 2px 7px; }
.c-status .badge + .badge { margin-left: 4px; }
.reason { max-width: 200px; overflow: hidden; text-overflow: ellipsis; font-size: 11.5px; margin-top: 3px; }
.reason.warn { color: #fcd34d; }
.reason.err { color: #fca5a5; }
.row-actions { display: flex; gap: 4px; justify-content: flex-end; }
.row-actions button { opacity: .85; padding: 6px 8px; }
.row-actions button span { display: none; } /* bảng chỉ hiện icon, chữ nằm ở tooltip */
.acc-table tr:hover .row-actions button { opacity: 1; }
.table-foot { padding: 10px 14px; font-size: 12px; border-top: 1px solid var(--border); }

.card .pick { margin-right: -2px; }
.card.selected { border-color: rgba(59,130,246,.55); box-shadow: var(--shadow), 0 0 0 1px rgba(59,130,246,.35); }

/* ================= Thẻ tài khoản ================= */
.grid { display: grid; gap: 14px; grid-template-columns: repeat(auto-fill, minmax(330px, 1fr)); align-content: start; }
.empty {
    grid-column: 1 / -1; text-align: center; padding: 56px 16px; margin: 0;
    border: 1px dashed var(--border-2); border-radius: var(--radius); background: rgba(18,21,28,.5);
}
.empty p { margin: 4px 0; }
.empty > p:first-of-type { font-weight: 600; font-size: 15px; }
.empty-ico {
    width: 56px; height: 56px; margin: 0 auto 14px; border-radius: 16px; display: grid; place-items: center;
    background: var(--primary-soft); color: #7aa8ff;
}
.empty-ico svg { width: 26px; height: 26px; }

.card {
    background: linear-gradient(180deg, var(--panel-2), var(--panel)); border: 1px solid var(--border);
    border-radius: var(--radius); padding: 16px; box-shadow: var(--shadow);
    display: flex; flex-direction: column; gap: 12px;
    transition: border-color .2s, transform .2s var(--ease), box-shadow .2s;
}
.card:hover { border-color: var(--border-2); transform: translateY(-2px); box-shadow: var(--shadow), 0 16px 32px -20px rgba(59,130,246,.35); }
.card.disabled { opacity: .55; }
.card.disabled:hover { transform: none; }
.card-top { display: flex; gap: 12px; align-items: center; }
.avatar {
    position: relative; width: 46px; height: 46px; border-radius: 50%; flex: none;
    background: linear-gradient(135deg, #2b3446, #1c2230); display: grid; place-items: center;
    font-weight: 700; font-size: 17px; color: #c7d2fe;
}
.avatar img { width: 100%; height: 100%; object-fit: cover; border-radius: 50%; }
.avatar .dot {
    position: absolute; right: -1px; bottom: -1px; width: 13px; height: 13px; border-radius: 50%;
    background: var(--muted); border: 2.5px solid var(--panel-2);
}
.avatar .dot.ok { background: var(--ok); }
.avatar .dot.warn { background: var(--warn); }
.avatar .dot.err { background: var(--err); }
.who { flex: 1; min-width: 0; }
.name { font-weight: 650; font-size: 15px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.meta { display: flex; gap: 12px; font-size: 12px; color: var(--muted); margin-top: 2px; flex-wrap: wrap; }
.meta span { display: inline-flex; align-items: center; gap: 5px; white-space: nowrap; }
.meta svg { width: 13px; height: 13px; }
.meta-warn { color: #fcd34d; font-weight: 600; }

.status-row { display: flex; gap: 6px; flex-wrap: wrap; }
.badge {
    display: inline-flex; align-items: center; gap: 6px; padding: 3px 10px 3px 8px; border-radius: 999px;
    font-size: 12px; font-weight: 600; background: var(--panel-3); color: var(--text-2);
}
.badge i { width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.badge.ok { background: rgba(34,197,94,.12); color: #4ade80; }
.badge.warn { background: rgba(245,158,11,.12); color: #fbbf24; }
.badge.err { background: rgba(239,68,68,.12); color: #f87171; }
.badge.info { background: var(--primary-soft); color: #7aa8ff; }
.badge.info i, .badge.warn i { animation: blink 1.2s infinite; }

.note {
    display: flex; align-items: center; gap: 8px; padding: 8px 10px; border-radius: var(--radius-sm); font-size: 12.5px;
    white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.note svg { width: 14px; height: 14px; }
.note.warn { background: rgba(245,158,11,.08); color: #fcd34d; border: 1px solid rgba(245,158,11,.18); }
.note.err { background: rgba(239,68,68,.08); color: #fca5a5; border: 1px solid rgba(239,68,68,.18); display: block; }

.stats { display: grid; grid-template-columns: repeat(4, 1fr); border: 1px solid var(--border); border-radius: var(--radius-sm); overflow: hidden; }
.stats div { padding: 9px 10px; background: rgba(10,12,17,.35); }
.stats div + div { border-left: 1px solid var(--border); }
.stats small { display: block; color: var(--muted); font-size: 11px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.stats b { display: block; font-size: 14.5px; font-weight: 650; font-variant-numeric: tabular-nums; white-space: nowrap; }
.card-actions { display: flex; gap: 6px; justify-content: flex-end; }
.card-actions .danger { margin-right: auto; order: -1; }

.switch { position: relative; width: 40px; height: 22px; flex: none; cursor: pointer; }
.switch input { position: absolute; opacity: 0; width: 0; height: 0; }
.switch span { position: absolute; inset: 0; background: #2d3444; border-radius: 22px; transition: background .2s; }
.switch span::before {
    content: ""; position: absolute; width: 16px; height: 16px; left: 3px; top: 3px;
    background: #fff; border-radius: 50%; transition: transform .2s var(--ease); box-shadow: 0 1px 3px rgba(0,0,0,.4);
}
.switch input:checked + span { background: linear-gradient(90deg, var(--primary), var(--primary-2)); }
.switch input:checked + span::before { transform: translateX(18px); }
.switch input:focus-visible + span { outline: 2px solid var(--primary); outline-offset: 2px; }

/* ================= Nhật ký ================= */
.log-panel {
    background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius);
    display: flex; flex-direction: column; height: 320px; flex: none; overflow: hidden; box-shadow: var(--shadow);
}
.log-head { display: flex; justify-content: space-between; align-items: center; padding: 12px 16px; border-bottom: 1px solid var(--border); }
.log-head h2 { display: flex; align-items: center; gap: 8px; }
.log-tools { display: flex; gap: 8px; align-items: center; }
.log-tools input { padding: 6px 10px; font-size: 12.5px; width: 220px; }
.log-head h2 svg { width: 16px; height: 16px; color: var(--muted); }
#logs { list-style: none; margin: 0; padding: 6px 0; overflow: auto; font-size: 12.5px; flex: 1; }
#logs:empty::after { content: "Chưa có hoạt động nào."; display: block; padding: 24px; text-align: center; color: var(--muted); }
#logs li { display: flex; gap: 10px; align-items: baseline; padding: 5px 16px; }
#logs li[hidden] { display: none; } /* quy tắc display ở trên đè mất [hidden] mặc định của trình duyệt */
#logs li:hover { background: rgba(255,255,255,.02); }
#logs li::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: var(--muted); flex: none; transform: translateY(-1px); }
#logs li.success::before { background: var(--ok); }
#logs li.warn::before { background: var(--warn); }
#logs li.error::before { background: var(--err); }
#logs time { color: var(--muted); flex: none; font-family: ui-monospace, Consolas, monospace; font-size: 12px; }
#logs b { color: #93b4ff; flex: none; font-weight: 600; }
#logs span { color: var(--text-2); }
#logs li.success span { color: #86efac; }
#logs li.warn span { color: #fcd34d; }
#logs li.error span { color: #fca5a5; }

/* ================= Hộp thoại ================= */
.modal {
    position: fixed; inset: 0; background: rgba(5,7,10,.65); backdrop-filter: blur(6px);
    display: grid; place-items: center; z-index: 30; padding: 16px; animation: fade .15s ease-out;
}
.dialog {
    background: linear-gradient(180deg, var(--panel-2), var(--panel)); border: 1px solid var(--border-2); border-radius: 18px;
    padding: 24px; width: 400px; max-width: 100%; max-height: calc(100vh - 32px); overflow: auto;
    box-shadow: 0 30px 60px -20px rgba(0,0,0,.7);
}
.modal .dialog { animation: pop .2s var(--ease); }
.dialog.wide { width: 620px; }
.dialog > label { margin-top: 12px; }
.dialog-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 22px; }
@keyframes fade { from { opacity: 0; } }
@keyframes pop { from { opacity: 0; transform: translateY(8px) scale(.98); } }

.qr-box {
    margin-top: 16px; height: 280px; border-radius: 14px; background: #fff;
    display: grid; place-items: center; color: #111; box-shadow: 0 0 0 6px rgba(255,255,255,.04);
}
.qr-box img { width: 248px; height: 248px; image-rendering: pixelated; }
.qr-box .msg { font-weight: 600; text-align: center; padding: 0 16px; }
.qr-box .msg.err { color: #dc2626; }
.qr-box .msg.ok { color: #16a34a; font-size: 16px; }
.scanned { display: flex; flex-direction: column; align-items: center; gap: 10px; }
.scanned .av { width: 76px; height: 76px; border-radius: 50%; box-shadow: 0 0 0 4px #e0e7ff; }

/* ================= Form ================= */
.form-section {
    margin: 20px 0 10px; font-size: 11px; font-weight: 700; letter-spacing: .08em; text-transform: uppercase; color: var(--muted);
    display: flex; align-items: center; gap: 10px;
}
.form-section::after { content: ""; flex: 1; height: 1px; background: var(--border); }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px 14px; }
.form-grid label.full { grid-column: 1 / -1; }
label { display: flex; flex-direction: column; gap: 6px; font-size: 12.5px; color: var(--text-2); font-weight: 500; }
label.check {
    flex-direction: row; align-items: flex-start; gap: 10px; margin: 10px 0 0; color: var(--text); font-weight: 400;
    padding: 10px 12px; border: 1px solid var(--border); border-radius: var(--radius-sm); cursor: pointer; transition: border-color .15s, background .15s;
}
label.check:hover { border-color: var(--border-2); background: rgba(255,255,255,.015); }
label.check input { margin: 2px 0 0; width: 16px; height: 16px; accent-color: var(--primary); flex: none; }
input[type=number], input[type=text], input[type=password], input[type=search] {
    font: inherit; color: var(--text); background: rgba(10,12,17,.6);
    border: 1px solid var(--border-2); border-radius: var(--radius-sm); padding: 9px 12px;
    transition: border-color .15s, box-shadow .15s;
}
input::placeholder { color: #5b6375; }
input:hover { border-color: #3d4558; }
input:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px rgba(59,130,246,.22); }
.form-error { color: #fca5a5; margin: 0; min-height: 1em; font-size: 13px; }

/* ================= Đăng nhập ================= */
.auth { min-height: 100%; display: grid; place-items: center; padding: 16px; }
.auth-card { display: flex; flex-direction: column; gap: 14px; width: 400px; padding: 32px; }
.auth-card > label { margin-top: 0; }
.auth-card .brand { margin-bottom: 4px; }
.auth-card .logo { width: 48px; height: 48px; font-size: 24px; border-radius: 14px; }
.auth-card h1 { font-size: 20px; }
.auth-head { text-align: center; }
.brand.center { justify-content: center; flex-direction: column; gap: 10px; }

/* CSP chặn style="" trong HTML nên lỗi nặng dùng class */
.fatal { padding: 24px; }

.spinner {
    width: 34px; height: 34px; border: 3px solid #e5e7eb; border-top-color: var(--primary);
    border-radius: 50%; animation: spin .9s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ================= Responsive ================= */
@media (max-width: 1400px) {
    .acc-table .c-last { display: none; }
}
@media (max-width: 1100px) {
    .kpis { grid-template-columns: repeat(2, 1fr); }
    .acc-table .c-queue { display: none; }
}
@media (max-width: 900px) {
    .toolbar-right { margin-left: 0; }
    .search { width: 100%; }
    .acc-table .c-next { display: none; }
    .acc-table .acc .meta span + span { display: none; } /* bỏ ngày tạo nick, chỉ giữ số bạn */
}
/* máy tính bảng / cửa sổ hẹp: thanh bên chỉ còn icon để nhường chỗ cho bảng */
@media (min-width: 761px) and (max-width: 1280px) {
    .shell { grid-template-columns: 68px 1fr; }
    .sidebar { padding: 20px 10px; align-items: center; }
    .sidebar .brand { padding: 0; }
    .sidebar .brand > div:not(.logo), .nav-label, .nav .tag, .conn-text { display: none; }
    .nav { width: 100%; }
    .nav a { justify-content: center; padding: 11px 0; font-size: 0; }
    .nav a.active::before { left: -10px; }
    .sidebar-foot { width: 100%; align-items: center; }
    .sidebar-foot button { font-size: 0; justify-content: center; padding: 10px 0; }
    .conn { padding: 0 0 8px; justify-content: center; }
    header, .view-body { padding-left: 24px; padding-right: 24px; }
    .reason { max-width: 150px; }
}
/* ================= Điện thoại ================= */
.tabbar, .title-short, .title-log { display: none; }
@media (hover: none) {
    .card:hover { transform: none; }
}
@media (max-width: 760px) {
    :root { --tabbar-h: calc(62px + env(safe-area-inset-bottom)); }
    body { -webkit-tap-highlight-color: transparent; }
    .shell { grid-template-columns: 1fr; height: 100dvh; }
    .title-full { display: none; }
    .title-short { display: inline; }
    body[data-view=log] .title-short { display: none; }
    body[data-view=log] .title-log { display: inline; }

    /* --- thanh tab dưới đáy --- */
    .tabbar {
        display: grid; grid-template-columns: repeat(4, 1fr); position: fixed; left: 0; right: 0; bottom: 0; z-index: 30;
        height: var(--tabbar-h); padding-bottom: env(safe-area-inset-bottom);
        background: rgba(14,16,22,.88); backdrop-filter: blur(16px) saturate(1.4);
        border-top: 1px solid var(--border);
    }
    .tabbar a, .tabbar button {
        position: relative; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px;
        color: var(--muted); text-decoration: none; font-size: 11px; font-weight: 600;
        background: none; border: 0; border-radius: 0; padding: 0;
    }
    .tabbar .ico svg { width: 22px; height: 22px; }
    .tabbar a.active { color: #7aa8ff; }
    .tabbar a.active::before {
        content: ""; position: absolute; top: 0; left: 30%; right: 30%; height: 2px; border-radius: 0 0 2px 2px;
        background: linear-gradient(90deg, var(--primary), var(--primary-2));
    }
    .tabbar button:hover:not(:disabled) { background: none; }
    body.nav-open #btnMore { color: var(--text); }
    .tab-badge {
        position: absolute; top: 6px; left: calc(50% + 6px); min-width: 17px; height: 17px; padding: 0 5px;
        border-radius: 999px; background: var(--err); color: #fff; font-size: 10px; line-height: 17px; text-align: center;
        box-shadow: 0 0 0 2px var(--bg);
    }

    /* --- bảng "Thêm": trượt lên từ đáy --- */
    .sidebar {
        position: fixed; left: 0; right: 0; bottom: 0; top: auto; z-index: 40; gap: 14px;
        padding: 10px 16px calc(16px + env(safe-area-inset-bottom));
        background: var(--panel); border: 1px solid var(--border-2); border-bottom: 0; border-radius: 22px 22px 0 0;
        transform: translateY(105%); transition: transform .28s var(--ease);
        pointer-events: none; /* đang trượt xuống thì không bấm nhầm được nút bên trong */
    }
    body.nav-open .sidebar { pointer-events: auto; }
    .sidebar::before { content: ""; width: 40px; height: 4px; border-radius: 4px; background: var(--border-2); margin: 0 auto 4px; flex: none; }
    body.nav-open .sidebar { transform: none; box-shadow: 0 0 0 100vmax rgba(0,0,0,.55); }
    .sidebar .nav { display: none; }
    .sidebar-foot { border-top: 0; padding-top: 0; }
    .sidebar-foot button { padding: 12px 14px; font-size: 14px; background: var(--panel-2); border-color: var(--border); }

    /* --- tiêu đề --- */
    header {
        flex-wrap: nowrap; padding: calc(12px + env(safe-area-inset-top)) 16px 12px; gap: 12px;
        /* không dùng backdrop-filter: nó làm nút FAB (position: fixed) bị neo theo header */
        background: var(--bg); backdrop-filter: none;
    }
    .view-title { font-size: 20px; margin: 0; }
    #summary { display: none; }
    header .sub { font-size: 12.5px; }
    .actions { gap: 8px; }
    #btnSettings { width: 40px; height: 40px; padding: 0; border-radius: 12px; }
    #btnSettings span { display: none; }
    #btnSettings svg { width: 18px; height: 18px; }

    /* --- nút thêm nổi (FAB) --- */
    #btnAdd {
        position: fixed; right: 16px; bottom: calc(var(--tabbar-h) + 16px); z-index: 25;
        width: 56px; height: 56px; padding: 0; border-radius: 18px;
        box-shadow: 0 1px 0 rgba(255,255,255,.2) inset, 0 12px 28px -8px rgba(59,130,246,.75);
    }
    #btnAdd span { display: none; }
    #btnAdd svg { width: 24px; height: 24px; stroke-width: 2.5; }
    body[data-view=log] #btnAdd, .view:has(.bulk:not(.hidden)) #btnAdd { display: none; }

    .view-body { padding: 14px 16px calc(var(--tabbar-h) + 88px); gap: 14px; }

    /* --- chỉ số: dải ngang --- */
    .kpis {
        display: flex; gap: 10px; overflow-x: auto; scroll-snap-type: x mandatory;
        margin: 0 -16px; padding: 0 16px; scrollbar-width: none;
    }
    .kpis::-webkit-scrollbar { display: none; }
    .kpi { flex: 0 0 auto; min-width: 138px; padding: 10px 14px 10px 10px; gap: 10px; scroll-snap-align: start; border-radius: 12px; }
    .kpi-ico { width: 34px; height: 34px; border-radius: 10px; }
    .kpi-ico svg { width: 17px; height: 17px; }
    .kpi small { font-size: 11.5px; white-space: nowrap; }
    .kpi b { font-size: 19px; }
    .kpi span { display: block; margin: 0; font-size: 11px; white-space: nowrap; }

    /* --- tìm kiếm + lọc: dính trên cùng khi cuộn --- */
    .toolbar {
        position: sticky; top: -14px; z-index: 6; margin: 0 -16px; padding: 10px 16px;
        display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 10px;
        background: linear-gradient(var(--bg) 85%, rgba(10,12,17,0));
    }
    .search { width: auto; }
    .search input[type=search] { padding: 10px 0; }
    .search { grid-row: 1; grid-column: 1; }
    .toolbar-right { margin: 0; grid-row: 1; grid-column: 2; }
    .toolbar-right select { padding: 10px 28px 10px 10px; width: 150px; }
    .seg { display: none; }
    .chips { grid-row: 2; grid-column: 1 / -1; flex-wrap: nowrap; overflow-x: auto; margin: 0 -16px; padding: 0 16px; scrollbar-width: none; }
    .chips::-webkit-scrollbar { display: none; }
    .chip { flex: none; padding: 7px 7px 7px 13px; }

    /* --- thanh chọn hàng loạt: sát đáy cho dễ bấm --- */
    .bulk {
        position: fixed; left: 10px; right: 10px; top: auto; bottom: calc(var(--tabbar-h) + 10px); z-index: 25; margin: 0;
        display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; padding: 10px;
        background: linear-gradient(90deg, rgba(59,130,246,.22), rgba(99,102,241,.18)), var(--panel-2);
        box-shadow: 0 16px 40px -10px rgba(0,0,0,.8);
    }
    .bulk #bulkCount { grid-column: 1 / -1; font-size: 13px; padding: 0 4px 2px; }
    .bulk button { flex-direction: column; gap: 3px; padding: 8px 4px; font-size: 11.5px; }
    .bulk button svg { width: 17px; height: 17px; }
    .bulk-close { position: absolute; top: 4px; right: 4px; padding: 6px !important; border: 0 !important; background: none !important; }
    .view-body:has(.bulk:not(.hidden)) { padding-bottom: calc(var(--tabbar-h) + 140px); }

    /* --- danh sách tài khoản: mỗi hàng thành 1 khối --- */
    .grid { grid-template-columns: 1fr; }
    .card { padding: 14px; }
    .stats { grid-template-columns: repeat(2, 1fr); }
    .stats div:nth-child(3) { border-left: 0; }
    .stats div:nth-child(n+3) { border-top: 1px solid var(--border); }
    .acc-table thead, .acc-table .c-next, .acc-table .c-last, .acc-table .c-queue { display: none; }
    .acc-table, .acc-table tbody { display: block; }
    .acc-table tr {
        display: grid; grid-template-columns: 20px minmax(0, 1fr) auto; gap: 8px 12px; padding: 14px;
        grid-template-areas: "pick acc toggle" ". status status" ". foot foot";
        border-bottom: 1px solid var(--border);
    }
    .acc-table tbody tr:last-child { border-bottom: 0; }
    .acc-table td { display: block; padding: 0; border: 0; white-space: normal; }
    .acc-table .c-pick { grid-area: pick; width: auto; align-self: center; }
    .acc-table .c-acc { grid-area: acc; min-width: 0; }
    .acc-table .c-toggle { grid-area: toggle; width: auto; align-self: center; }
    .acc-table .c-status { grid-area: status; }
    .acc-table .c-accepted { grid-area: foot; justify-self: start; text-align: left; align-self: center; font-size: 13px; }
    .acc-table .c-accepted::before { content: attr(data-label) " "; color: var(--muted); font-weight: 400; }
    .acc-table .c-actions { grid-area: foot; justify-self: end; }
    .acc { min-width: 0; max-width: none; }
    .acc .avatar { width: 40px; height: 40px; }
    .acc .name { font-size: 14.5px; }
    .acc .meta { flex-wrap: wrap; gap: 2px 10px; }
    .reason { max-width: none; white-space: nowrap; }
    .row-actions { gap: 6px; }
    .row-actions button { width: 38px; height: 38px; padding: 0; opacity: 1; }
    .row-actions button svg { width: 16px; height: 16px; }
    input.pick { width: 18px; height: 18px; }
    .switch { width: 44px; height: 26px; }
    .switch span::before { width: 20px; height: 20px; }

    /* --- nhật ký: tab riêng, chiếm cả màn hình --- */
    body:not([data-view=log]) .log-panel { display: none; }
    body[data-view=log] #view-zalo .view-body { overflow: hidden; padding-bottom: calc(var(--tabbar-h) + 12px); }
    body[data-view=log] #view-zalo .view-body > :not(.log-panel) { display: none; }
    body[data-view=log] .log-panel { flex: 1 1 auto; height: auto; min-height: 0; }
    .log-head { flex-wrap: wrap; gap: 10px; padding: 12px 14px; }
    .log-head h2 { display: none; }
    .log-tools { width: 100%; }
    .log-tools input { flex: 1; width: auto; padding: 9px 12px; }
    #logs li { flex-wrap: wrap; gap: 2px 8px; padding: 9px 14px; border-bottom: 1px solid rgba(255,255,255,.03); }
    #logs span { flex-basis: 100%; padding-left: 14px; }

    /* --- hộp thoại: trượt lên từ đáy --- */
    .modal { place-items: end stretch; padding: 0; }
    .modal .dialog {
        width: 100%; max-width: none; max-height: 92dvh; border-radius: 22px 22px 0 0; border-bottom: 0;
        padding: 12px 18px calc(18px + env(safe-area-inset-bottom)); animation: sheet .28s var(--ease);
    }
    .modal .dialog::before { content: ""; display: block; width: 40px; height: 4px; border-radius: 4px; background: var(--border-2); margin: 0 auto 14px; }
    .modal .dialog-actions { position: sticky; bottom: calc(-18px - env(safe-area-inset-bottom)); margin: 20px -18px calc(-18px - env(safe-area-inset-bottom)); padding: 12px 18px calc(12px + env(safe-area-inset-bottom)); background: var(--panel); border-top: 1px solid var(--border); }
    .modal .dialog-actions button { flex: 1; padding: 12px; }
    .form-grid { grid-template-columns: 1fr; }
    .qr-box { height: auto; aspect-ratio: 1; max-height: 52dvh; }
    .qr-box img { width: min(248px, 80%); height: auto; aspect-ratio: 1; }

    /* chữ trong ô nhập ≥16px để iPhone không tự phóng to khi gõ */
    input[type=number], input[type=text], input[type=password], input[type=search], select { font-size: 16px; }
    .auth-card { padding: 24px; }
}
@keyframes sheet { from { transform: translateY(100%); } }
@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after { animation: none !important; transition: none !important; }
}

/* số duyệt hôm nay */
.today { margin-left: 6px; font-size: 11px; font-weight: 600; color: #4ade80; }
.kpi span.ok { color: #4ade80; }
