* { box-sizing: border-box; margin: 0; padding: 0; }
body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Arial, sans-serif;
    background: #f4f6f8;
    color: #1f2937;
    font-size: 14px;
}

/* ---------- Login ---------- */
.login-body {
    display: flex; align-items: center; justify-content: center;
    min-height: 100vh;
    background: linear-gradient(135deg, #2AABEE, #1c8bc0);
}
.login-box {
    background: #fff; padding: 36px 32px; border-radius: 16px;
    box-shadow: 0 20px 50px rgba(0,0,0,0.2);
    width: 100%; max-width: 340px; text-align: center;
}
.login-box h1 { font-size: 20px; margin-bottom: 4px; }
.login-sub { color: #8a97a3; font-size: 13px; margin-bottom: 20px; }
.login-box input {
    width: 100%; padding: 11px 14px; border: 1.5px solid #e4e8ec; border-radius: 10px;
    font-size: 14px; margin-bottom: 12px; outline: none;
}
.login-box input:focus { border-color: #2AABEE; }
.login-box button {
    width: 100%; padding: 11px; border: none; border-radius: 10px;
    background: linear-gradient(135deg, #2AABEE, #229ED9); color: #fff;
    font-weight: 700; font-size: 14px; cursor: pointer;
}
.alert-error {
    background: #fdecea; color: #b3261e; padding: 10px 12px; border-radius: 8px;
    font-size: 12.5px; margin-bottom: 14px; text-align: left;
}
.alert-success {
    background: #e7f8ee; color: #1e7e42; padding: 10px 12px; border-radius: 8px;
    font-size: 12.5px; margin-bottom: 14px;
}

/* ---------- Sidebar (cố định bên trái, luôn hiện khi cuộn) ---------- */
:root { --sidebar-width: 232px; }

#tcb-sidebar {
    position: fixed;
    top: 0; left: 0; bottom: 0;
    width: var(--sidebar-width);
    background: #fff;
    border-right: 1px solid #e4e8ec;
    display: flex;
    flex-direction: column;
    z-index: 100;
    overflow-y: auto;
}
.sidebar-brand { display: flex; align-items: center; gap: 10px; padding: 20px 18px; border-bottom: 1px solid #f0f2f4; }
.sidebar-brand-icon {
    width: 36px; height: 36px; border-radius: 10px;
    background: linear-gradient(135deg, #2AABEE, #229ED9);
    display: flex; align-items: center; justify-content: center; font-size: 17px; flex-shrink: 0;
}
.sidebar-brand-title { font-weight: 700; font-size: 14px; color: #1f2937; line-height: 1.3; }
.sidebar-brand-sub { font-size: 11.5px; color: #9aa5b1; }

.sidebar-nav { display: flex; flex-direction: column; padding: 12px; gap: 2px; flex: 1; }
.sidebar-nav a {
    display: flex; align-items: center; gap: 10px;
    padding: 10px 12px; border-radius: 9px; text-decoration: none;
    color: #4b5563; font-size: 13.5px; font-weight: 600;
}
.sidebar-nav-icon { font-size: 15px; width: 20px; text-align: center; flex-shrink: 0; }
.sidebar-nav a.active, .sidebar-nav a:hover { background: #eef6fc; color: #229ED9; }

.sidebar-logout {
    display: flex; align-items: center; gap: 8px;
    padding: 14px 18px; border-top: 1px solid #f0f2f4;
    color: #9aa5b1; text-decoration: none; font-size: 13px; font-weight: 600;
}
.sidebar-logout:hover { color: #b3261e; }

#tcb-sidebar-toggle {
    display: none;
    position: fixed; top: 14px; left: 14px; z-index: 101;
    width: 38px; height: 38px; border-radius: 10px;
    background: #fff; border: 1px solid #e4e8ec; box-shadow: 0 2px 8px rgba(0,0,0,0.08);
    font-size: 17px; cursor: pointer;
}
#tcb-sidebar-backdrop { display: none; }

.container { max-width: 1180px; margin: 0 auto; padding: 24px; margin-left: calc(var(--sidebar-width) + 24px); }
h2.page-title { font-size: 19px; margin-bottom: 18px; }

/* ---------- Stat cards ---------- */
.stats-grid {
    display: grid; grid-template-columns: repeat(6, 1fr);
    gap: 12px; margin-bottom: 26px;
}
#bank-select {
    height: 35px;
    width: 100%;
    padding: 2px 5px;
    border: 1.5px solid #e4e8ec;
    border-radius: 8px;
}
@media (max-width: 900px) {
    .stats-grid { grid-template-columns: repeat(2, 1fr); gap: 10px; }
}
.stat-card {
    background: #fff; border-radius: 14px; padding: 14px 16px;
    box-shadow: 0 1px 3px rgba(0,0,0,0.06); border: 1px solid #eef0f2;
    min-width: 0;
}
.stat-card .label { font-size: 12px; color: #8a97a3; font-weight: 600; margin-bottom: 6px; }
.stat-card .value { font-size: 22px; font-weight: 700; color: #1f2937; }
.stat-card .sub { font-size: 11px; color: #9aa5b1; margin-top: 4px; line-height: 1.4; }
.stat-card.accent-blue .value { color: #229ED9; }
.stat-card.accent-green .value { color: #2bab4c; }
.stat-card.accent-orange .value { color: #ff7a45; }
.stat-card.accent-purple .value { color: #6c5ce7; }

/* ---------- Panels / Table ---------- */
.panel {
    background: #fff; border-radius: 14px; border: 1px solid #eef0f2;
    box-shadow: 0 1px 3px rgba(0,0,0,0.06); margin-bottom: 20px; overflow: hidden;
}
.panel-header {
    padding: 16px 20px; border-bottom: 1px solid #f0f2f4;
    font-weight: 700; font-size: 14.5px; display: flex; justify-content: space-between; align-items: center;
}
.panel-body { padding: 16px 20px; }

table { width: 100%; border-collapse: collapse; font-size: 13px; }
th { text-align: left; padding: 10px 12px; color: #8a97a3; font-weight: 600; font-size: 12px; border-bottom: 1px solid #eef0f2; white-space: nowrap; }
td { padding: 10px 12px; border-bottom: 1px solid #f5f6f8; vertical-align: top; }
tr:last-child td { border-bottom: none; }
tr:hover td { background: #fafbfc; }

.badge { display: inline-block; padding: 3px 9px; border-radius: 20px; font-size: 11px; font-weight: 700; }
.badge-open { background: #e7f8ee; color: #1e7e42; }
.badge-closed { background: #f1f2f4; color: #6b7280; }
.badge-pending { background: #fff3cd; color: #92610f; }
.badge-confirmed { background: #e7f8ee; color: #1e7e42; }
.badge-delivered { background: #e6f4ff; color: #1a6fc4; }
.badge-cancelled { background: #fdecea; color: #b3261e; }
.badge-lang { background: #eef2ff; color: #4338ca; }

.bar-row { display: flex; align-items: center; gap: 10px; margin-bottom: 10px; font-size: 13px; }
.bar-row .bar-label { width: 200px; flex-shrink: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.bar-track { flex: 1; background: #f0f2f4; border-radius: 6px; height: 18px; overflow: hidden; }
.bar-fill { background: linear-gradient(135deg, #2AABEE, #229ED9); height: 100%; border-radius: 6px; }
.bar-count { width: 34px; text-align: right; flex-shrink: 0; font-weight: 700; color: #4b5563; }

.btn { display: inline-block; padding: 6px 12px; border-radius: 7px; font-size: 12.5px; font-weight: 600; text-decoration: none; cursor: pointer; border: none; }
.btn-view { background: #eef6fc; color: #229ED9; }
.btn-view:hover { background: #dcf0fb; }
.btn-delete { background: #fdecea; color: #b3261e; }
.btn-delete:hover { background: #fbdcd9; }
.btn-primary { background: linear-gradient(135deg, #2AABEE, #229ED9); color: #fff; }

.empty-state { text-align: center; color: #9aa5b1; padding: 30px; font-size: 13px; }

.filters { display: flex; gap: 8px; margin-bottom: 16px; flex-wrap: wrap; }
.filters input, .filters select {
    padding: 8px 12px; border: 1.5px solid #e4e8ec; border-radius: 8px; font-size: 13px;
}
.filters button { padding: 8px 16px; border: none; border-radius: 8px; background: #229ED9; color: #fff; font-weight: 600; cursor: pointer; font-size: 13px; }

.pagination { display: flex; gap: 6px; justify-content: center; margin-top: 16px; }
.pagination a, .pagination span {
    padding: 6px 12px; border-radius: 7px; font-size: 12.5px; text-decoration: none; color: #4b5563; background: #f4f6f8;
}
.pagination a:hover { background: #eef6fc; color: #229ED9; }
.pagination .current { background: #229ED9; color: #fff; font-weight: 700; }

.msg-thread { max-height: 60vh; overflow-y: auto; padding: 4px; }
.msg-item { margin-bottom: 12px; padding: 10px 14px; border-radius: 10px; max-width: 75%; font-size: 13px; white-space: pre-wrap; }
.msg-user { background: #eef6fc; margin-left: auto; }
.msg-admin { background: #fff3cd; }
.msg-ai { background: #f1f2f4; }
.msg-meta { font-size: 10.5px; color: #9aa5b1; margin-bottom: 3px; font-weight: 600; }

/* ---------- Form sản phẩm ---------- */
.product-form .form-row { margin-bottom: 14px; }
.product-form .form-row-group { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.product-form .form-row-group-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.product-form .form-row-group-3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 14px; }
.product-form .form-row-group-4 { display: grid; grid-template-columns: 1fr 1fr 1fr 1fr; gap: 14px; }
.product-form label { display: block; font-size: 12.5px; font-weight: 600; color: #4b5563; margin-bottom: 5px; }
.product-form input[type=text],
.product-form input[type=number],
.product-form input[type=password],
.product-form input[type=email],
.product-form input[type=url],
.product-form input[type=tel],
.product-form input[type=search],
.product-form select,
.product-form textarea {
    width: 100%; padding: 9px 12px; border: 1.5px solid #e4e8ec; border-radius: 8px; font-size: 13.5px;
    font-family: inherit; outline: none; background: #fff; color: #1f2937; box-sizing: border-box;
}
.product-form select { appearance: none; background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'%3E%3Cpath d='M1 1l5 5 5-5' stroke='%239aa5b1' stroke-width='1.5' fill='none' stroke-linecap='round'/%3E%3C/svg%3E"); background-repeat: no-repeat; background-position: right 12px center; padding-right: 32px; cursor: pointer; }
.product-form input:focus, .product-form select:focus, .product-form textarea:focus { border-color: #2AABEE; }
.product-form input[readonly] { background: #f4f6f8; color: #6b7280; cursor: default; }
.product-form textarea { resize: vertical; }
.product-form .form-hint { display: block; font-size: 11px; color: #9aa5b1; margin-top: 4px; }
.product-form .form-checkbox label { display: flex; align-items: center; gap: 7px; font-weight: 500; cursor: pointer; }
.product-form .form-checkbox input { width: auto; }

.product-form .current-image { display: flex; align-items: center; gap: 10px; margin-bottom: 8px; }
.product-form .current-image img { width: 56px; height: 56px; object-fit: cover; border-radius: 8px; border: 1px solid #eef0f2; }
.product-form .remove-image-label { display: flex !important; align-items: center; gap: 5px; font-size: 12px; color: #b3261e; font-weight: 500; cursor: pointer; margin: 0 !important; }
.product-form .remove-image-label input { width: auto; }

@media (max-width: 600px) {
    .product-form .form-row-group { grid-template-columns: 1fr; }
    .product-form .form-row-group-3 { grid-template-columns: 1fr; }
    .quota-grid { grid-template-columns: 1fr !important; }
}

@media (max-width: 700px) {
    .container { padding: 16px 14px 24px; margin-left: 0; margin-top: 56px; }
    .bar-row .bar-label { width: 110px; }

    #tcb-sidebar {
        transform: translateX(-100%);
        transition: transform 0.2s ease;
        box-shadow: 0 0 30px rgba(0,0,0,0.15);
    }
    #tcb-sidebar.sidebar-open { transform: translateX(0); }

    #tcb-sidebar-toggle { display: flex; align-items: center; justify-content: center; }

    #tcb-sidebar-backdrop {
        position: fixed; inset: 0; background: rgba(15,23,32,0.4);
        z-index: 99; opacity: 0; pointer-events: none; transition: opacity 0.2s ease;
    }
    #tcb-sidebar-backdrop.sidebar-open { display: block; opacity: 1; pointer-events: auto; }
}

/* ==========================================================
   OMNICHANNEL UI
   Shared visual system for Inbox, Channels, Contacts and Ops.
   ========================================================== */
.omni-page { padding-top: 30px; }
.omni-page-head {
    display: flex; align-items: flex-start; justify-content: space-between; gap: 20px;
    margin-bottom: 22px; padding: 22px 24px; border-radius: 18px;
    background:
        radial-gradient(circle at 88% 12%, rgba(42,171,238,.14), transparent 32%),
        linear-gradient(135deg, #fff 0%, #f8fcff 100%);
    border: 1px solid #e5f0f7; box-shadow: 0 8px 30px rgba(34,158,217,.07);
}
.omni-page-head h2.page-title { margin: 3px 0 6px; font-size: 24px; letter-spacing: -.35px; }
.omni-page-head p { color: #667582; font-size: 13.5px; line-height: 1.55; }
.omni-eyebrow {
    display: inline-block; color: #168bc3; font-size: 10.5px; font-weight: 800;
    letter-spacing: 1.3px;
}
.omni-security-pill {
    flex-shrink: 0; padding: 8px 12px; border: 1px solid #dcecf5; border-radius: 20px;
    background: rgba(255,255,255,.82); color: #44606f; font-size: 11.5px; font-weight: 700;
    box-shadow: 0 2px 8px rgba(34,158,217,.06);
}
.panel-count {
    padding: 4px 10px; border-radius: 14px; background: #f1f7fb;
    color: #587080; font-size: 11px; font-weight: 700;
}
.omni-table-wrap { padding: 0; overflow-x: auto; }
.omni-table-wrap table { min-width: 780px; }
.omni-table-wrap tbody tr { transition: background .15s ease; }
.omni-table-wrap tbody tr:hover { background: #f9fcfe; }

/* Channel account cards */
.channel-grid {
    display: grid; grid-template-columns: repeat(auto-fit,minmax(340px,1fr));
    gap: 18px; align-items: start;
}
.channel-card {
    position: relative; overflow: hidden; padding: 0 !important;
    border-radius: 16px !important; border: 1px solid #e8edf1 !important;
    box-shadow: 0 8px 26px rgba(31,41,55,.06);
    transition: transform .2s ease, box-shadow .2s ease;
}
.channel-card:hover { transform: translateY(-2px); box-shadow: 0 14px 34px rgba(31,41,55,.09); }
.channel-card::before { content: ""; display: block; height: 4px; background: #229ED9; }
.channel-card.channel-zalo::before { background: linear-gradient(90deg,#0068ff,#2a8cff); }
.channel-card.channel-messenger::before { background: linear-gradient(90deg,#8b5cf6,#ec4899,#229ED9); }
.channel-card > .form-row, .channel-card > .form-checkbox, .channel-card > .form-hint,
.channel-card > .alert-error, .channel-card > .channel-save-btn { margin-left: 20px; margin-right: 20px; }
.channel-card-head {
    display: flex; justify-content: space-between; align-items: center;
    padding: 18px 20px 15px; margin-bottom: 2px; border-bottom: 1px solid #f0f3f5;
}
.channel-title-wrap { display: flex; align-items: center; gap: 12px; }
.channel-title-wrap h3 { font-size: 15px; margin: 0 0 2px; }
.channel-title-wrap small { color: #96a2ad; font-size: 11px; }
.channel-logo {
    width: 40px; height: 40px; display: grid; place-items: center; border-radius: 12px;
    background: linear-gradient(135deg,#eef8ff,#dcefff); color: #0768e8; font-weight: 900;
    box-shadow: inset 0 0 0 1px rgba(0,104,255,.08);
}
.channel-messenger .channel-logo { background: linear-gradient(135deg,#f2eaff,#e8f4ff); color: #8b5cf6; }
.channel-status { display: inline-flex; align-items: center; gap: 5px; font-weight: 700; }
.channel-on { background: #e7f8ee; color: #1e7e42; }
.channel-off { background: #f1f2f4; color: #6b7280; }
.channel-status::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.channel-card .form-row { margin-top: 14px; margin-bottom: 0; }
.channel-card .form-checkbox { margin-top: 16px; }
.channel-save-btn { width: calc(100% - 40px); margin-top: 16px; margin-bottom: 20px; padding: 10px 16px; }

/* Unified inbox channel/status badges */
.channel-badge, .omni-status {
    display: inline-flex; align-items: center; justify-content: center;
    padding: 4px 9px; border-radius: 20px; font-size: 10.5px; font-weight: 800;
    white-space: nowrap;
}
.channel-badge-website { background: #e8f5fd; color: #167fae; }
.channel-badge-zalo { background: #e8f1ff; color: #075fd8; }
.channel-badge-messenger { background: #f2eafe; color: #7c3fc5; }
.status-pending, .status-received, .status-queued { background: #fff5d9; color: #936510; }
.status-processing, .status-retry { background: #fff0e6; color: #b65718; }
.status-sent, .status-delivered, .status-read, .status-processed { background: #e7f8ee; color: #197441; }
.status-failed { background: #fdecea; color: #b3261e; }
.status-ignored { background: #f1f2f4; color: #68727d; }

/* Contacts */
.merge-panel { border-color: #e5edf3; }
.merge-panel .panel-header small { color: #8d9aa5; font-size: 11px; font-weight: 500; }
.merge-form {
    display: grid; grid-template-columns: minmax(190px,1fr) minmax(190px,1fr) auto;
    gap: 14px; align-items: end;
}
.merge-form .form-row { margin: 0; }
.merge-form .btn { min-height: 38px; padding: 9px 16px; }
.contact-cell { display: flex; align-items: center; gap: 9px; min-width: 150px; }
.contact-avatar {
    width: 30px; height: 30px; border-radius: 10px; display: grid; place-items: center;
    color: #177da9; background: linear-gradient(135deg,#e7f6fd,#dceef7);
    font-size: 12px; font-weight: 800; flex-shrink: 0;
}
.contact-id { color: #768692; font-size: 11px; font-family: ui-monospace,SFMono-Regular,Menlo,monospace; }

/* Better filters on omnichannel screens */
.omni-page .filters {
    padding: 12px; border-radius: 12px; background: rgba(255,255,255,.75);
    border: 1px solid #e9eef2; box-shadow: 0 2px 10px rgba(31,41,55,.03);
}
.omni-page .filters input { min-width: 240px; flex: 1; }
.omni-page .filters input:focus, .omni-page .filters select:focus {
    border-color: #2AABEE; outline: none; box-shadow: 0 0 0 3px rgba(42,171,238,.1);
}

@media (max-width: 900px) {
    .omni-page-head { padding: 18px; }
    .merge-form { grid-template-columns: 1fr 1fr; }
    .merge-form .btn { grid-column: 1 / -1; }
}
@media (max-width: 600px) {
    .omni-page { padding-top: 8px; }
    .omni-page-head { flex-direction: column; gap: 12px; border-radius: 14px; padding: 16px; }
    .omni-page-head h2.page-title { font-size: 21px; }
    .omni-security-pill { align-self: flex-start; }
    .channel-grid { grid-template-columns: 1fr !important; }
    .channel-card { min-width: 0; }
    .channel-card-head { padding: 15px 16px; }
    .channel-card > .form-row, .channel-card > .form-checkbox, .channel-card > .form-hint,
    .channel-card > .alert-error, .channel-card > .channel-save-btn { margin-left: 16px; margin-right: 16px; }
    .channel-save-btn { width: calc(100% - 32px); }
    .merge-form { grid-template-columns: 1fr; }
    .merge-form .btn { grid-column: auto; width: 100%; }
    .omni-page .filters { flex-direction: column; }
    .omni-page .filters input, .omni-page .filters select, .omni-page .filters button { width: 100%; min-width: 0; }
}
