/* =============================================================================
   DISPATCH — bảng điều khiển forward Zalo
   Token system
   Color   : nền than-xanh (#0C1016), panel #141A23/#1B222D, accent hổ phách
             tín hiệu #FFB020 (đèn "on-air"), phụ #3FC1C9 (waveform), success
             #34D399, danger #F0555F, idle #64748B
   Type    : Space Grotesk (display) + Inter (body) + JetBrains Mono (data/log)
   Layout  : topbar -> dải chỉ số (instrument tiles) -> toolbar -> lưới card
   Signature: mỗi card là 1 "kênh dispatch" (CH·01, CH·02…) với dải màu dọc bên
             trái + đèn LIVE dạng equalizer, log hiện dạng terminal mono.
============================================================================= */

:root {
    --bg: #F3F5F8;
    --bg-grid: #EEF1F5;
    --panel: #FFFFFF;
    --panel-2: #F4F6F9;
    --border: #E1E6ED;
    --border-soft: #EAEDF2;

    --text: #1C2430;
    --text-muted: #5B6B7C;
    --text-faint: #8996A6;

    --accent: #D9880C;
    --accent-dim: #F6E0B4;
    --accent-2: #0E8C93;

    --success: #16A374;
    --warning: #D9880C;
    --danger: #DC3545;
    --idle: #64748B;
    --unknown: #9AA6B6;

    --overlay-soft: rgba(15,23,42,0.04);

    --font-display: 'Space Grotesk', 'Inter', sans-serif;
    --font-body: 'Inter', system-ui, sans-serif;
    --font-mono: 'JetBrains Mono', 'SFMono-Regular', Consolas, monospace;

    --radius-lg: 14px;
    --radius-md: 10px;
    --radius-sm: 6px;

    --shadow-card: 0 1px 0 rgba(255,255,255,0.6) inset, 0 10px 22px -16px rgba(15,23,42,0.18);
}

* { box-sizing: border-box; }

html, body {
    margin: 0;
    padding: 0;
    background:
        radial-gradient(1200px 500px at 15% -10%, rgba(217,136,12,0.07), transparent 60%),
        radial-gradient(900px 500px at 100% 0%, rgba(14,140,147,0.06), transparent 55%),
        var(--bg);
    color: var(--text);
    font-family: var(--font-body);
    -webkit-font-smoothing: antialiased;
}

::selection { background: var(--accent); color: #fff; }

a { color: inherit; }

button, input, textarea, select {
    font-family: inherit;
    color: inherit;
}

:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: 2px;
    border-radius: 4px;
}

code {
    font-family: var(--font-mono);
    background: var(--overlay-soft);
    padding: 0 4px;
    border-radius: 4px;
    font-size: 0.9em;
}

/* ---------------------------------- Topbar --------------------------------- */

.topbar {
    position: sticky;
    top: 0;
    z-index: 20;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 14px 28px;
    background: rgba(255,255,255,0.85);
    backdrop-filter: blur(10px);
    border-bottom: 1px solid var(--border-soft);
}

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

.topbar__mark {
    width: 30px;
    height: 30px;
    border-radius: 8px;
    background: linear-gradient(155deg, var(--accent) 0%, #B9750E 100%);
    position: relative;
    flex-shrink: 0;
}
.topbar__mark::after {
    content: "";
    position: absolute;
    inset: 8px;
    border-radius: 3px;
    background: var(--bg);
    opacity: 0.85;
}

.topbar__title {
    display: flex;
    flex-direction: column;
    line-height: 1.15;
}
.topbar__title strong {
    font-family: var(--font-display);
    font-weight: 700;
    font-size: 17px;
    letter-spacing: 0.01em;
}
.topbar__title span {
    font-size: 12px;
    color: var(--text-muted);
}

.topbar__meta {
    display: flex;
    align-items: center;
    gap: 14px;
}

.service-pill {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 6px 12px;
    border-radius: 999px;
    background: var(--panel);
    border: 1px solid var(--border);
    font-size: 12.5px;
    color: var(--text-muted);
}
.service-pill .dot {
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: var(--danger);
    box-shadow: 0 0 0 3px rgba(240,85,95,0.15);
}
.service-pill[data-ok="1"] .dot {
    background: var(--success);
    box-shadow: 0 0 0 3px rgba(52,211,153,0.15);
}

.clock {
    font-family: var(--font-mono);
    font-size: 13px;
    color: var(--text-muted);
    min-width: 74px;
    text-align: right;
}

.help-btn {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 6px 12px;
    border-radius: 999px;
    background: var(--panel);
    border: 1px solid var(--border);
    font-size: 12.5px;
    font-weight: 600;
    color: var(--text-muted);
    cursor: pointer;
}
.help-btn:hover { border-color: var(--accent); color: var(--accent); }

/* ------------------------------------ Shell --------------------------------- */

.shell {
    max-width: 1360px;
    margin: 0 auto;
    padding: 28px 28px 60px;
}

/* ------------------------------------ Stats ---------------------------------- */

.stats {
    display: grid;
    grid-template-columns: repeat(6, 1fr);
    gap: 12px;
    margin-bottom: 22px;
}

.stat-tile {
    background: var(--panel);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    padding: 14px 16px;
    display: flex;
    flex-direction: column;
    gap: 6px;
}
.stat-tile__label {
    font-size: 11.5px;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: var(--text-faint);
}
.stat-tile__value {
    font-family: var(--font-display);
    font-size: 26px;
    font-weight: 600;
}
.stat-tile--online .stat-tile__value { color: var(--success); }
.stat-tile--idle .stat-tile__value { color: var(--idle); }
.stat-tile--error .stat-tile__value { color: var(--danger); }
.stat-tile--offline .stat-tile__value { color: var(--text-faint); }

/* Tài nguyên máy chủ (CPU/RAM/Disk/OS) */
.stats--sys { grid-template-columns: repeat(4, 1fr); }

.stat-tile__sub {
    font-size: 11.5px;
    color: var(--text-faint);
    margin-top: -4px;
}
.stat-tile__bar {
    height: 4px;
    border-radius: 999px;
    background: var(--panel-2);
    overflow: hidden;
    margin-top: 2px;
}
.stat-tile__bar span {
    display: block;
    height: 100%;
    width: 0%;
    background: var(--accent-2);
    border-radius: 999px;
    transition: width 0.4s ease;
}
.stat-tile--os .stat-tile__value--text {
    font-family: var(--font-body);
    font-size: 15px;
    font-weight: 600;
    line-height: 1.3;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

/* ----------------------------------- Toolbar --------------------------------- */

.toolbar {
    display: flex;
    align-items: center;
    gap: 14px;
    margin-bottom: 20px;
    flex-wrap: wrap;
}

.toolbar__search {
    display: flex;
    align-items: center;
    gap: 8px;
    background: var(--panel);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    padding: 9px 12px;
    flex: 1 1 280px;
    min-width: 220px;
    color: var(--text-faint);
}
.toolbar__search input {
    background: transparent;
    border: none;
    color: var(--text);
    font-size: 13.5px;
    width: 100%;
}
.toolbar__search input::placeholder { color: var(--text-faint); }
.toolbar__search input:focus { outline: none; }

.toolbar__filters {
    display: flex;
    gap: 6px;
}
.filter-btn {
    background: var(--panel);
    border: 1px solid var(--border);
    color: var(--text-muted);
    font-size: 12.5px;
    padding: 8px 13px;
    border-radius: 999px;
    cursor: pointer;
    transition: border-color .15s ease, color .15s ease, background .15s ease;
}
.filter-btn:hover { color: var(--text); border-color: #3A4657; }
.filter-btn.is-active {
    color: #fff;
    background: var(--accent);
    border-color: var(--accent);
    font-weight: 600;
}

.toolbar__pause {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 12.5px;
    color: var(--text-muted);
    cursor: pointer;
    user-select: none;
    margin-left: auto;
}
.toolbar__pause input { accent-color: var(--accent); }

/* ------------------------------------- Grid ----------------------------------- */

.grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(360px, 1fr));
    gap: 16px;
}

.empty-state, .no-results {
    text-align: center;
    padding: 60px 20px;
    color: var(--text-muted);
    border: 1px dashed var(--border);
    border-radius: var(--radius-lg);
}
.empty-state h2 { font-family: var(--font-display); color: var(--text); margin-bottom: 8px; }

/* -------------------------------------- Card ------------------------------------ */

.card {
    display: flex;
    background: var(--panel);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-card);
    overflow: hidden;
    transition: border-color .2s ease, transform .2s ease;
}
.card:hover { border-color: #333F4F; }

.card__strip {
    width: 5px;
    flex-shrink: 0;
    background: var(--unknown);
}
.card[data-state="online"]  .card__strip { background: var(--success); }
.card[data-state="idle"]    .card__strip { background: var(--idle); }
.card[data-state="error"]   .card__strip { background: var(--danger); }
.card[data-state="offline"] .card__strip { background: var(--text-faint); }

.card__body {
    flex: 1;
    padding: 16px 18px 14px;
    display: flex;
    flex-direction: column;
    gap: 12px;
    min-width: 0;
}

.card__head {
    display: flex;
    align-items: flex-start;
    gap: 10px;
}
.card__chno {
    font-family: var(--font-mono);
    font-size: 11px;
    color: var(--text-faint);
    background: var(--panel-2);
    border: 1px solid var(--border-soft);
    padding: 3px 7px;
    border-radius: 5px;
    letter-spacing: 0.04em;
    margin-top: 2px;
    flex-shrink: 0;
}
.card__titles { flex: 1; min-width: 0; }
.card__titles h3 {
    font-family: var(--font-display);
    font-size: 14.5px;
    font-weight: 600;
    margin: 0 0 2px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.card__titles p {
    margin: 0;
    font-size: 12px;
    color: var(--text-muted);
}

.card__status {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 11.5px;
    color: var(--text-muted);
    flex-shrink: 0;
    padding-top: 3px;
}
.pulse-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--unknown);
    position: relative;
}
.pulse-dot::after {
    content: "";
    position: absolute;
    inset: -4px;
    border-radius: 50%;
    background: inherit;
    opacity: 0.35;
}
.card[data-state="online"] .pulse-dot { background: var(--success); animation: pulse 1.8s ease-in-out infinite; }
.card[data-state="error"] .pulse-dot { background: var(--danger); animation: pulse 1.2s ease-in-out infinite; }
.card[data-state="idle"] .pulse-dot { background: var(--idle); }
.card[data-state="offline"] .pulse-dot { background: var(--text-faint); }

@keyframes pulse {
    0%, 100% { box-shadow: 0 0 0 0 rgba(52,211,153,0.35); }
    50% { box-shadow: 0 0 0 5px rgba(52,211,153,0); }
}
.card[data-state="error"] .pulse-dot { animation-name: pulse-danger; }
@keyframes pulse-danger {
    0%, 100% { box-shadow: 0 0 0 0 rgba(240,85,95,0.4); }
    50% { box-shadow: 0 0 0 5px rgba(240,85,95,0); }
}

/* Route: nguồn -> đích */

.card__route {
    display: flex;
    align-items: flex-start;
    gap: 10px;
    background: var(--panel-2);
    border: 1px solid var(--border-soft);
    border-radius: var(--radius-md);
    padding: 10px 12px;
}
.route__group {
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
}
.route__label {
    display: block;
    font-size: 10.5px;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--text-faint);
    margin-bottom: 5px;
}
.route__ids {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 5px;
}
.id-chip {
    font-family: var(--font-mono);
    font-size: 11px;
    line-height: 1.4;
    max-width: 100%;
    background: var(--overlay-soft);
    border: 1px solid var(--border-soft);
    padding: 2px 6px;
    border-radius: 4px;
    color: var(--text-muted);
    white-space: normal;
    overflow-wrap: anywhere;
    word-break: break-word;
}
.route__arrow {
    color: var(--text-faint);
    flex-shrink: 0;
    margin-top: 22px;
}
@media (max-width: 460px) {
    .card__route {
        flex-direction: column;
        align-items: stretch;
    }
    .route__arrow {
        margin: 2px 0;
        transform: rotate(90deg);
    }
}

/* Rule chips (giá / prepend / append) */

.card__rules {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
}
.rule-chip {
    font-size: 11px;
    padding: 4px 9px;
    border-radius: 999px;
    background: rgba(14,140,147,0.08);
    border: 1px solid rgba(14,140,147,0.25);
    color: var(--accent-2);
}
.rule-chip--price {
    background: rgba(217,136,12,0.1);
    border-color: rgba(217,136,12,0.3);
    color: var(--accent);
    font-weight: 600;
}

/* Card cảnh báo thiếu dữ liệu (account/config chưa điền đủ) */
.card__warning {
    font-size: 11.5px;
    line-height: 1.5;
    padding: 8px 10px;
    border-radius: var(--radius-sm);
    background: rgba(217,136,12,0.1);
    border: 1px solid rgba(217,136,12,0.3);
    color: #8A5A05;
}
.card[data-state="incomplete"] .card__strip { background: var(--warning); }
.card[data-state="incomplete"] .pulse-dot { background: var(--warning); }
.card[data-state="incomplete"] .card__status { color: var(--warning); }

/* Console (log realtime) */

.card__console {
    /* Bảng màu riêng cho log — nền terminal tối nên cần tông sáng/bão hoà hơn
       theme sáng chung của trang, chỉ áp dụng trong phạm vi .card__console. */
    --log-source: #7DD3E8;      /* nhóm nguồn */
    --log-target: #6EE7B7;      /* nhóm đích */
    --log-arrow: #4B5768;       /* mũi tên/nối => */
    --log-media: #C4B5FD;       /* [N ảnh] */
    --log-link: #93C5FD;        /* link/search(...) */
    --log-content: #C7D0DC;     /* nội dung tin nhắn thường */
    --log-tag-regex: #FBBF24;   /* [Regex:xxx] */
    --log-price-old: #F87171;   /* giá trước khi Regex chỉnh */
    --log-price-new: #34D399;   /* giá sau khi Regex chỉnh */
    --log-tag-ai: #C792EA;      /* [AI] */
    --log-tag-reload: #60A5FA;  /* 🔄 [tên cấu hình] */
    --log-price-rule: #FBBF24;  /* giá: ... trong dòng nạp cấu hình */
    --log-system: #FCD34D;      /* === Bot khởi động/dừng === */
    --log-success: #34D399;     /* ✅ Đăng nhập thành công */
    --log-uid: #8996A6;         /* UID: ... */

    background: #0A0D12;
    border: 1px solid var(--border-soft);
    border-radius: var(--radius-md);
    overflow: hidden;
    display: flex;
    flex-direction: column;
    flex: 1;
    min-height: 0;
    max-height: 420px; /* chặn card giãn vô hạn khi log tích luỹ nhiều theo thời gian; log dư sẽ tự cuộn */
}

.console__head {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 8px 10px;
    border-bottom: 1px solid var(--border-soft);
    background: rgba(255,255,255,0.015);
}

.live-tag {
    display: flex;
    align-items: center;
    gap: 6px;
    font-family: var(--font-mono);
    font-size: 10.5px;
    letter-spacing: 0.08em;
    color: var(--text-faint);
    flex-shrink: 0;
}
.live-tag .eq {
    display: inline-flex;
    align-items: flex-end;
    gap: 2px;
    height: 10px;
}
.live-tag .eq i {
    width: 2px;
    background: var(--text-faint);
    border-radius: 1px;
    height: 3px;
    display: block;
}
.card[data-state="online"] .live-tag { color: var(--success); }
.card[data-state="online"] .live-tag .eq i { background: var(--success); animation: eq 1s ease-in-out infinite; }
.card[data-state="online"] .live-tag .eq i:nth-child(1) { animation-delay: 0s; }
.card[data-state="online"] .live-tag .eq i:nth-child(2) { animation-delay: .15s; }
.card[data-state="online"] .live-tag .eq i:nth-child(3) { animation-delay: .3s; }
.card[data-state="online"] .live-tag .eq i:nth-child(4) { animation-delay: .45s; }

@keyframes eq {
    0%, 100% { height: 3px; }
    50% { height: 10px; }
}

.console__meta {
    font-size: 11px;
    color: var(--text-faint);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    flex: 1;
}

.console__clear {
    background: none;
    border: 1px solid var(--border-soft);
    color: var(--text-faint);
    font-size: 10.5px;
    padding: 3px 8px;
    border-radius: 5px;
    cursor: pointer;
    flex-shrink: 0;
}
.console__clear:hover { color: var(--text); border-color: #3A4657; }

.console__body {
    font-family: var(--font-mono);
    font-size: 11.5px;
    line-height: 1.65;
    padding: 10px 12px;
    flex: 1;
    min-height: 120px;
    overflow-y: auto;
    color: #C7D0DC;
}

.console__placeholder { color: var(--text-faint); margin: 0; }

.log-line {
    display: flex;
    gap: 8px;
    white-space: pre-wrap;
    word-break: break-word;
    padding: 1px 0;
    animation: fadein .25s ease;
}
@keyframes fadein {
    from { opacity: 0; transform: translateY(-2px); }
    to { opacity: 1; transform: translateY(0); }
}
.log-line__ts { color: var(--text-faint); flex-shrink: 0; font-variant-numeric: tabular-nums; }
.log-line__msg { flex: 1; }
.log-line[data-level="ERROR"] .log-line__msg { color: var(--danger); }
.log-line[data-level="WARNING"] .log-line__msg { color: var(--warning); }
.log-line[data-level="SUCCESS"] .log-line__msg { color: var(--success); }
.log-line[data-level="INFO"] .log-line__msg { color: #C7D0DC; }

/* Tô màu từng phần riêng biệt trong 1 dòng log (nguồn / nội dung / đích / tag...) */
.log-seg--source      { color: var(--log-source); font-weight: 600; }
.log-seg--target      { color: var(--log-target); font-weight: 600; }
.log-seg--arrow        { color: var(--log-arrow); }
.log-seg--media        { color: var(--log-media); font-style: italic; }
.log-seg--link          { color: var(--log-link); text-decoration: underline; text-decoration-style: dotted; text-underline-offset: 2px; }
.log-seg--content      { color: var(--log-content); }
.log-seg--text          { color: var(--log-content); }

.log-seg--tag-regex   { color: var(--log-tag-regex); font-weight: 700; }
.log-seg--price-old   { color: var(--log-price-old); text-decoration: line-through; opacity: .75; }
.log-seg--price-new   { color: var(--log-price-new); font-weight: 700; }

.log-seg--tag-ai        { color: var(--log-tag-ai); font-weight: 700; }

.log-seg--tag-reload  { color: var(--log-tag-reload); font-weight: 600; }
.log-seg--price-rule   { color: var(--log-price-rule); font-weight: 600; }

.log-seg--system        { color: var(--log-system); font-weight: 700; }
.log-seg--success       { color: var(--log-success); font-weight: 600; }
.log-seg--uid            { color: var(--log-uid); }

/* Dòng lỗi (❌), cảnh báo (⚠️) broadcast và dòng bỏ qua tin có SĐT */
.log-seg--tag-error    { color: var(--danger); font-weight: 700; }
.log-seg--error-reason { color: var(--danger); opacity: .9; }
.log-seg--warning       { color: var(--warning); font-weight: 600; }
.log-seg--skip           { color: var(--idle); font-style: italic; }
/* Nhiều giá đổi cùng lúc trong 1 tin, gộp chung 1 khối thay vì tách cũ/mới */
.log-seg--price-change { color: var(--log-price-new); font-weight: 700; }

/* Dòng hệ thống (bot dừng/khởi động) và đăng nhập thành công nổi bật hơn 1 chút,
   phân tách trực quan với log forward tin nhắn thông thường. */
.log-line:has(.log-seg--system) { padding: 3px 0; border-top: 1px dashed rgba(255,255,255,0.08); margin-top: 2px; }

.console__body::-webkit-scrollbar { width: 8px; }
.console__body::-webkit-scrollbar-track { background: transparent; }
.console__body::-webkit-scrollbar-thumb { background: #262F3B; border-radius: 8px; }

/* ------------------------------------ Add Panel (form) -------------------------------- */

.add-panel {
    margin-bottom: 20px;
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    background: var(--panel);
    box-shadow: var(--shadow-card);
    overflow: hidden;
}

.add-panel__toggle {
    width: 100%;
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 14px 18px;
    background: none;
    border: none;
    cursor: pointer;
    font-size: 13.5px;
    font-weight: 600;
    color: var(--text);
    text-align: left;
}
.add-panel__toggle:hover { background: var(--panel-2); }
.add-panel__toggle-icon {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 22px;
    height: 22px;
    border-radius: 6px;
    background: var(--accent);
    color: #fff;
    font-weight: 700;
    flex-shrink: 0;
    transition: transform .2s ease;
}
.add-panel__toggle.is-open .add-panel__toggle-icon { transform: rotate(45deg); }

.add-panel__body {
    padding: 4px 18px 18px;
    border-top: 1px solid var(--border-soft);
}

.add-panel__grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 20px;
    margin-top: 14px;
}

.add-panel__section {
    border: 1px solid var(--border-soft);
    border-radius: var(--radius-md);
    padding: 14px 16px 16px;
    background: var(--panel-2);
    min-width: 0;
}
.add-panel__section legend {
    font-family: var(--font-display);
    font-size: 13px;
    font-weight: 600;
    padding: 0 6px;
    color: var(--text);
}

.field {
    display: block;
    margin-bottom: 12px;
}
.field__label {
    display: block;
    font-size: 12px;
    font-weight: 600;
    color: var(--text-muted);
    margin-bottom: 5px;
}
.field__label small {
    font-weight: 400;
    color: var(--text-faint);
}
.field__hint {
    display: block;
    font-size: 11px;
    color: var(--text-faint);
    margin-top: 4px;
}
.field--split {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 10px;
    margin-bottom: 0;
}
.field--split .field { margin-bottom: 0; }

.field input[type="text"],
.field input[type="number"],
.field textarea {
    width: 100%;
    background: var(--panel);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 8px 10px;
    font-size: 13px;
    color: var(--text);
    resize: vertical;
    font-family: var(--font-mono);
}
.field input[type="text"]:focus,
.field input[type="number"]:focus,
.field textarea:focus {
    outline: none;
    border-color: var(--accent);
}
.field input::placeholder,
.field textarea::placeholder {
    color: var(--text-faint);
    font-family: var(--font-body);
}

.field__row {
    min-height: 16px;
    margin: -4px 0 10px;
}
.resolve-status {
    font-size: 11.5px;
    color: var(--text-faint);
}

.add-panel__actions {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 14px;
    margin-top: 16px;
    padding-top: 14px;
    border-top: 1px solid var(--border-soft);
}
.add-panel__msg {
    font-size: 12.5px;
    white-space: pre-line;
    text-align: right;
    color: var(--text-muted);
}
.add-panel__msg.is-success { color: var(--success); }
.add-panel__msg.is-error { color: var(--danger); }

.btn-save {
    background: var(--accent);
    color: #fff;
    border: none;
    padding: 10px 20px;
    border-radius: var(--radius-md);
    font-size: 13.5px;
    font-weight: 600;
    cursor: pointer;
    flex-shrink: 0;
    transition: filter .15s ease;
}
.btn-save:hover { filter: brightness(1.08); }
.btn-save:disabled { opacity: 0.6; cursor: not-allowed; }

/* ---- Nhóm nguồn/đích: 1 hàng 2 cột ---- */
.field-group-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 14px;
    margin-bottom: 14px;
}
.field-group-row .field-group { margin-bottom: 0; }

/* ---- Prepend / Append / Price: 1 hàng 3 cột ---- */
.field-row-3 {
    display: grid;
    grid-template-columns: 1fr 1fr 1fr;
    gap: 12px;
}
.field-row-3 .field { margin-bottom: 12px; min-width: 0; }

/* ---- Tự động trả lời: textarea + toggle cùng hàng ---- */
.autoreply-row {
    display: flex;
    align-items: flex-start;
    gap: 10px;
}
.autoreply-row textarea {
    flex: 1;
    min-width: 0;
    background: var(--panel);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 8px 10px;
    font-size: 13px;
    color: var(--text);
    resize: vertical;
    font-family: var(--font-mono);
}
.autoreply-row textarea:focus { outline: none; border-color: var(--accent); }
.autoreply-row textarea::placeholder { color: var(--text-faint); font-family: var(--font-body); }

/* ---- Toggle switch (bật/tắt tự động trả lời) ---- */
.switch {
    position: relative;
    display: inline-flex;
    flex-shrink: 0;
    width: 40px;
    height: 22px;
    margin-top: 4px;
    cursor: pointer;
}
.switch input {
    position: absolute;
    inset: 0;
    opacity: 0;
    margin: 0;
    cursor: pointer;
    z-index: 1;
}
.switch__track {
    position: absolute;
    inset: 0;
    background: var(--border);
    border-radius: 999px;
    transition: background .15s ease;
}
.switch__thumb {
    position: absolute;
    top: 2px;
    left: 2px;
    width: 18px;
    height: 18px;
    border-radius: 50%;
    background: #fff;
    box-shadow: 0 1px 2px rgba(15,23,42,0.25);
    transition: transform .15s ease;
}
.switch input:checked ~ .switch__track { background: var(--accent); }
.switch input:checked ~ .switch__track .switch__thumb { transform: translateX(18px); }
.switch input:focus-visible ~ .switch__track { outline: 2px solid var(--accent); outline-offset: 2px; }

@media (max-width: 800px) {
    .add-panel__grid { grid-template-columns: 1fr; }
    .field-group-row { grid-template-columns: 1fr; gap: 0; }
    .field-row-3 { grid-template-columns: 1fr; }
    .account-layout { grid-template-columns: 1fr; }
    .account-layout__col--settings {
        padding-left: 0;
        padding-top: 16px;
        border-left: none;
        border-top: 1px solid var(--border-soft);
    }
}

@media (max-width: 480px) {
    .autoreply-row { flex-direction: column; align-items: stretch; }
    .switch { align-self: flex-end; }
}

/* ------------------------------------ Responsive -------------------------------- */

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

@media (max-width: 640px) {
    html, body { overflow-x: hidden; }

    .topbar {
        flex-wrap: wrap;
        row-gap: 10px;
        padding: 12px 14px;
    }
    .topbar__brand {
        min-width: 0;
        flex: 1 1 auto;
    }
    .topbar__title {
        min-width: 0;
    }
    .topbar__title strong,
    .topbar__title span {
        display: block;
        max-width: 100%;
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
    }
    .topbar__meta {
        width: 100%;
        flex-wrap: wrap;
        gap: 8px;
        justify-content: flex-start;
    }
    .help-btn,
    .bot-pill,
    .service-pill,
    .clock {
        font-size: 11.5px;
        padding: 5px 10px;
    }
    .bot-pill { max-width: 46vw; }
    .service-pill { max-width: 46vw; }
    .clock { min-width: 0; padding: 5px 8px; }

    .shell { padding: 18px 14px 40px; }
    .stats { grid-template-columns: repeat(2, 1fr); }
    .stats--sys { grid-template-columns: repeat(2, 1fr); }
    .grid { grid-template-columns: 1fr; }
    .toolbar__pause { margin-left: 0; }
}

@media (max-width: 400px) {
    .help-btn {
        padding: 5px 8px;
    }
    .bot-pill,
    .service-pill {
        max-width: 42vw;
    }
}

@media (prefers-reduced-motion: reduce) {
    * { animation-duration: 0.001ms !important; animation-iteration-count: 1 !important; transition-duration: 0.001ms !important; }
}

/* =============================================================================
   BỔ SUNG: tài khoản QR, cấu hình dạng "quét nhóm", popup, danh sách nhóm
   ============================================================================= */

/* ---- Bot pill (topbar) — trạng thái tổng của zalo_forward_bot ---- */
.bot-pill {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 6px 12px;
    border-radius: 999px;
    background: var(--panel);
    border: 1px solid var(--border);
    font-size: 12.5px;
    color: var(--text-muted);
    max-width: 220px;
}
.bot-pill span:last-child {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.bot-pill .dot {
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: var(--idle);
    box-shadow: 0 0 0 3px rgba(100,116,139,0.15);
    flex-shrink: 0;
}
.bot-pill[data-state="online"] .dot {
    background: var(--success);
    box-shadow: 0 0 0 3px rgba(52,211,153,0.15);
}
.bot-pill[data-state="idle"] .dot {
    background: var(--idle);
    box-shadow: 0 0 0 3px rgba(100,116,139,0.15);
}
.bot-pill[data-state="error"] .dot {
    background: var(--danger);
    box-shadow: 0 0 0 3px rgba(220,53,69,0.15);
    animation: pulse 1.2s ease-in-out infinite;
}
.bot-pill[data-state="offline"] .dot,
.bot-pill[data-state="unknown"] .dot {
    background: var(--text-faint);
    box-shadow: 0 0 0 3px rgba(100,116,139,0.1);
}

/* ---- Account box (add panel): layout 2 cột — trái identity, phải settings ---- */
.add-panel__section--account { margin-bottom: 18px; }

.account-layout {
    display: grid;
    grid-template-columns: minmax(220px, 300px) 1fr;
    gap: 20px;
    align-items: stretch;
}
.account-layout__col { min-width: 0; }

.account-layout__col--settings {
    display: flex;
    flex-direction: column;
    gap: 14px;
    padding-left: 20px;
    border-left: 1px solid var(--border-soft);
}
.account-layout__col--settings .field { margin-bottom: 0; }

.account-box {
    display: flex;
    flex-direction: column;
    gap: 14px;
    height: 100%;
    padding: 16px;
    border-radius: var(--radius-md);
    background: var(--panel);
    border: 1px solid var(--border);
}
.account-box__top {
    display: flex;
    align-items: center;
    gap: 12px;
}
.account-box__info { min-width: 0; }
.account-box__name {
    font-weight: 600;
    font-size: 13.5px;
    color: var(--text);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.account-box__phone {
    font-size: 12px;
    color: var(--text-muted);
    font-family: var(--font-mono);
    margin-top: 1px;
}
.account-box__empty {
    font-size: 12.5px;
    line-height: 1.5;
    color: var(--text-faint);
}
.account-box__actions {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
    margin-top: auto;
    padding-top: 12px;
    border-top: 1px solid var(--border-soft);
}
.account-box__actions .btn-outline {
    flex: 1 1 auto;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    white-space: nowrap;
}

.btn-outline {
    background: none;
    border: 1px solid var(--border);
    color: var(--text-muted);
    padding: 7px 14px;
    border-radius: var(--radius-sm);
    font-size: 12.5px;
    font-weight: 600;
    cursor: pointer;
    transition: border-color .15s ease, color .15s ease;
}
.btn-outline:hover { border-color: var(--accent); color: var(--accent); }
.btn-outline:disabled { opacity: 0.6; cursor: not-allowed; }

/* ---- Field group: nguồn/đích dạng "log" + nút quét ---- */
.field-group { margin-bottom: 14px; }
.field-group > .field__label {
    display: block;
    font-size: 12px;
    font-weight: 600;
    color: var(--text-muted);
    margin-bottom: 5px;
}
.field-group textarea {
    width: 100%;
    background: var(--panel-2);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 8px 10px;
    font-size: 12.5px;
    font-family: var(--font-mono);
    color: var(--text-muted);
    resize: vertical;
    cursor: default;
}
.field-group textarea:focus { outline: none; }
.field-group__actions {
    display: flex;
    gap: 8px;
    margin-top: 6px;
}

.btn-chip {
    background: var(--panel);
    border: 1px solid var(--border);
    color: var(--text-muted);
    padding: 6px 12px;
    border-radius: 999px;
    font-size: 11.5px;
    font-weight: 600;
    cursor: pointer;
    transition: border-color .15s ease, color .15s ease;
}
.btn-chip:hover { border-color: var(--accent-2); color: var(--accent-2); }

/* ---- Card: nút sửa/xoá ở console head ---- */
.console__edit,
.console__delete {
    background: none;
    border: 1px solid var(--border-soft);
    color: var(--text-faint);
    font-size: 10.5px;
    padding: 3px 8px;
    border-radius: 5px;
    cursor: pointer;
    flex-shrink: 0;
}
.console__edit:hover { color: var(--accent-2); border-color: var(--accent-2); }
.console__delete:hover { color: var(--danger); border-color: var(--danger); }
.console__delete:disabled { opacity: 0.6; cursor: not-allowed; }

/* ---- Modal (overlay chung cho QR popup & group popup) ---- */
.modal-overlay {
    position: fixed;
    inset: 0;
    z-index: 100;
    background: rgba(15,23,42,0.45);
    backdrop-filter: blur(2px);
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
}
.modal-overlay[hidden] { display: none; }

.modal {
    background: var(--panel);
    border-radius: var(--radius-lg);
    border: 1px solid var(--border);
    box-shadow: 0 20px 60px -20px rgba(15,23,42,0.4);
    width: 100%;
    max-width: 420px;
    max-height: 90vh;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}
.modal--lg { max-width: 620px; }
.modal--sm { max-width: 360px; }

.modal__head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 14px 18px;
    border-bottom: 1px solid var(--border-soft);
    flex-shrink: 0;
}
.modal__head h3 {
    margin: 0;
    font-family: var(--font-display);
    font-size: 15px;
    font-weight: 600;
}
.modal__close {
    background: none;
    border: none;
    font-size: 15px;
    color: var(--text-faint);
    cursor: pointer;
    padding: 4px 8px;
    border-radius: 6px;
}
.modal__close:hover { background: var(--overlay-soft); color: var(--text); }

.modal__body {
    padding: 18px;
    overflow-y: auto;
    flex: 1;
}
.modal__foot {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 10px;
    padding: 14px 18px;
    border-top: 1px solid var(--border-soft);
    flex-shrink: 0;
}
.modal__msg {
    font-size: 12px;
    color: var(--text-muted);
    margin: 8px 0 0;
}
.modal__msg.is-error { color: var(--danger); }

/* ---- Nội dung modal hướng dẫn sử dụng ---- */
.help-guide h4 {
    margin: 20px 0 8px;
    font-family: var(--font-display);
    font-size: 13.5px;
    font-weight: 700;
    color: var(--accent-2);
}
.help-guide h4:first-child { margin-top: 0; }
.help-guide ol,
.help-guide ul {
    margin: 0;
    padding-left: 20px;
    display: flex;
    flex-direction: column;
    gap: 6px;
}
.help-guide li {
    font-size: 13px;
    line-height: 1.55;
    color: var(--text-muted);
}
.help-guide li ul {
    margin-top: 6px;
    padding-left: 18px;
}
.help-guide strong { color: var(--text); }
.help-guide code {
    background: var(--panel-2);
    border: 1px solid var(--border-soft);
    border-radius: 4px;
    padding: 1px 5px;
    font-family: var(--font-mono);
    font-size: 12px;
    color: var(--text);
}
.help-guide__note {
    margin: 18px 0 0;
    padding: 10px 12px;
    background: var(--panel-2);
    border: 1px solid var(--border-soft);
    border-radius: var(--radius-sm);
    font-size: 12.5px;
    line-height: 1.55;
    color: var(--text-muted);
}

.modal__actions {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    margin-top: 10px;
}
.modal__loading {
    text-align: center;
    padding: 24px 0;
    color: var(--text-faint);
    font-size: 13px;
}

/* ---- QR box ---- */
.qr-box {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 240px;
    height: 240px;
    margin: 0 auto;
    border-radius: var(--radius-md);
    background: var(--panel-2);
    border: 1px solid var(--border);
    overflow: hidden;
}
.qr-box img { width: 100%; height: 100%; object-fit: contain; }
.qr-box__loading,
.qr-box__error,
.qr-box__success {
    font-size: 12.5px;
    color: var(--text-muted);
    text-align: center;
    padding: 0 16px;
}
.qr-box__success { color: var(--success); font-weight: 600; }
.qr-box__error { color: var(--danger); }
.qr-status {
    text-align: center;
    font-size: 12.5px;
    color: var(--text-muted);
    margin: 14px 0 0;
}

/* ---- Group picker popup ---- */
.group-search {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-bottom: 10px;
    flex-wrap: wrap;
}
.group-search input {
    flex: 1 1 160px;
    min-width: 160px;
    background: var(--panel-2);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 8px 10px;
    font-size: 13px;
}
.group-search input:focus { outline: none; border-color: var(--accent); }
.group-search span {
    font-size: 11.5px;
    color: var(--text-faint);
    flex-shrink: 0;
}
.group-search__total,
#groupSelectedCount {
    padding: 4px 9px;
    border-radius: 999px;
    background: var(--panel-2);
    border: 1px solid var(--border-soft);
    white-space: nowrap;
}
#groupSelectedCount {
    color: var(--accent-2);
    font-weight: 600;
    background: rgba(14,140,147,0.08);
    border-color: rgba(14,140,147,0.25);
}

.group-list {
    max-height: 320px;
    overflow-y: auto;
    border: 1px solid var(--border-soft);
    border-radius: var(--radius-md);
}
.group-list__empty {
    text-align: center;
    padding: 24px 0;
    color: var(--text-faint);
    font-size: 12.5px;
    margin: 0;
}

.group-row {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 9px 12px;
    border-bottom: 1px solid var(--border-soft);
    cursor: pointer;
    font-size: 13px;
}
.group-row:last-child { border-bottom: none; }
.group-row:hover { background: var(--panel-2); }
.group-row input[type="checkbox"] { flex-shrink: 0; }
.group-row__name { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.group-row__id {
    font-family: var(--font-mono);
    font-size: 10.5px;
    color: var(--text-faint);
    flex-shrink: 0;
}

/* ============================================================================
   BỔ SUNG: grid log tối đa 2 card/dòng, overlay loading QR, clamp card__route
   ============================================================================ */

/* ---- Grid log: mặc định tối đa 2 card/dòng; đúng 1 card thì full-width ---- */
#cardGrid.grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
}
#cardGrid.grid.grid--single {
    grid-template-columns: 1fr;
}
@media (max-width: 860px) {
    #cardGrid.grid {
        grid-template-columns: 1fr;
    }
}

/* ---- QR box: làm tối ảnh cũ + spinner khi bấm "Làm mới mã QR" ---- */
.qr-box {
    position: relative;
}
.qr-box__inner {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 100%;
    height: 100%;
}
.qr-box.is-loading .qr-box__inner {
    filter: brightness(0.35) blur(1px);
    transition: filter 0.2s ease;
    pointer-events: none;
}
.qr-box__spinner {
    display: none;
    position: absolute;
    top: 50%;
    left: 50%;
    width: 40px;
    height: 40px;
    margin: -20px 0 0 -20px;
    border-radius: 50%;
    border: 3px solid rgba(0, 0, 0, 0.12);
    border-top-color: var(--accent);
    animation: qrSpin 0.8s linear infinite;
}
.qr-box.is-loading .qr-box__spinner {
    display: block;
}
@keyframes qrSpin {
    to { transform: rotate(360deg); }
}

/* ---- card__route: chỉ hiện 3 id-chip đầu, bấm vào chip "+n" để mở/ẩn hết ---- */
.id-chip.is-hidden {
    display: none;
}
.id-chip--toggle {
    font-weight: 600;
    background: rgba(14, 140, 147, 0.1);
    border-color: rgba(14, 140, 147, 0.3);
    color: var(--accent-2);
    cursor: pointer;
    user-select: none;
    transition: background 0.15s ease, border-color 0.15s ease, transform 0.1s ease;
}
.id-chip--toggle:hover {
    background: rgba(14, 140, 147, 0.18);
    border-color: rgba(14, 140, 147, 0.45);
}
.id-chip--toggle:active {
    transform: scale(0.96);
}
.id-chip--toggle:focus-visible {
    outline: 2px solid var(--accent-2);
    outline-offset: 1px;
}
.route__ids.is-expanded {
    animation: routeIdsExpand 0.15s ease;
}
@keyframes routeIdsExpand {
    from { opacity: 0.6; }
    to { opacity: 1; }
}
.card {
    max-height: 500px;
}
.card__body {
    max-height: 500px;
    overflow: hidden;
}