:root {
    --bg: #f4f6f9;
    --surface: #ffffff;
    --border: #e2e6ed;
    --text: #1f2430;
    --text-muted: #6b7280;
    --primary: #2563eb;
    --primary-dark: #1d4ed8;
    --danger: #dc2626;
    --danger-bg: #fef2f2;
    --success: #16a34a;
    --success-bg: #f0fdf4;
    --sidebar-bg: #111827;
    --sidebar-text: #cbd5e1;
    --sidebar-active: #1f2937;
    --radius: 10px;
    --shadow: 0 1px 2px rgba(16, 24, 40, .05), 0 1px 3px rgba(16, 24, 40, .06);
}

* { box-sizing: border-box; }

body {
    margin: 0;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    background: var(--bg);
    color: var(--text);
    font-size: 14px;
}

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

/* ---------- Auth pages ---------- */
.auth-wrap {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    background: linear-gradient(160deg, #111827 0%, #1e293b 45%, #0f172a 100%);
    padding: 20px;
}

.auth-card {
    width: 100%;
    max-width: 380px;
    background: var(--surface);
    border-radius: 16px;
    padding: 36px 32px;
    box-shadow: 0 20px 50px rgba(0, 0, 0, .35);
}

.auth-logo {
    text-align: center;
    margin-bottom: 24px;
}

.auth-logo .badge {
    display: inline-flex;
    width: 48px;
    height: 48px;
    border-radius: 12px;
    background: var(--primary);
    color: #fff;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    font-size: 18px;
    margin-bottom: 12px;
}

.auth-logo h1 {
    font-size: 18px;
    margin: 0 0 4px;
}

.auth-logo p {
    margin: 0;
    color: var(--text-muted);
    font-size: 13px;
}

.field {
    margin-bottom: 16px;
}

.field label {
    display: block;
    font-size: 13px;
    font-weight: 600;
    margin-bottom: 6px;
    color: var(--text);
}

.field input, .field select {
    width: 100%;
    padding: 10px 12px;
    border: 1px solid var(--border);
    border-radius: 8px;
    /* >=16px — dưới mức này Safari/Chrome mobile tự động zoom vào khi focus ô nhập. */
    font-size: 16px;
    background: #fff;
    color: var(--text);
}

.field input:focus, .field select:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(37, 99, 235, .15);
}

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    padding: 10px 16px;
    border-radius: 8px;
    border: 1px solid transparent;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    transition: background .15s ease;
}

.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-dark); }
.btn-block { width: 100%; }
.btn-secondary { background: #fff; color: var(--text); border-color: var(--border); }
.btn-secondary:hover { background: #f3f4f6; }
.btn-danger { background: var(--danger-bg); color: var(--danger); border-color: #fecaca; }
.btn-danger:hover { background: #fee2e2; }
.btn-sm { padding: 6px 10px; font-size: 13px; }
.btn:disabled { opacity: .6; cursor: not-allowed; }

.alert {
    padding: 10px 12px;
    border-radius: 8px;
    font-size: 13px;
    margin-bottom: 16px;
}
.alert-error { background: var(--danger-bg); color: var(--danger); border: 1px solid #fecaca; }
.alert-success { background: var(--success-bg); color: var(--success); border: 1px solid #bbf7d0; }
.hidden { display: none !important; }

/* ---------- App shell ---------- */
.app-shell {
    display: flex;
    min-height: 100vh;
}

.sidebar {
    width: 240px;
    flex-shrink: 0;
    background: var(--sidebar-bg);
    color: var(--sidebar-text);
    display: flex;
    flex-direction: column;
    padding: 20px 0;
}

.sidebar-brand {
    padding: 0 20px 20px;
    border-bottom: 1px solid rgba(255,255,255,.08);
    margin-bottom: 16px;
}

.sidebar-brand .badge {
    display: inline-flex;
    width: 34px;
    height: 34px;
    border-radius: 9px;
    background: var(--primary);
    color: #fff;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    font-size: 15px;
    margin-bottom: 8px;
}

.sidebar-brand h1 {
    font-size: 15px;
    color: #fff;
    margin: 0;
}

.sidebar-brand p {
    font-size: 12px;
    color: #94a3b8;
    margin: 2px 0 0;
}

.nav-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 20px;
    font-size: 13.5px;
    font-weight: 500;
    color: var(--sidebar-text);
    border-left: 3px solid transparent;
}

.nav-item:hover { background: rgba(255,255,255,.04); color: #fff; }
.nav-item.active { background: var(--sidebar-active); color: #fff; border-left-color: var(--primary); }

.sidebar-footer {
    margin-top: auto;
    padding: 16px 20px 0;
    border-top: 1px solid rgba(255,255,255,.08);
}

.main {
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
}

.topbar {
    height: 60px;
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 24px;
}

.topbar h2 {
    font-size: 16px;
    margin: 0;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.menu-toggle-btn {
    display: none;
    background: none;
    border: none;
    font-size: 20px;
    line-height: 1;
    cursor: pointer;
    padding: 4px 6px;
    flex-shrink: 0;
    color: var(--text);
}

.sidebar-backdrop {
    display: none;
}

.user-chip {
    display: flex;
    align-items: center;
    gap: 10px;
}

.user-chip .avatar {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    background: var(--primary);
    color: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    font-size: 13px;
}

.user-chip .role {
    font-size: 11px;
    color: var(--text-muted);
}

.content {
    padding: 24px;
    flex: 1;
}

.card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
}

.card-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px 20px;
    border-bottom: 1px solid var(--border);
}

.card-header h3 {
    margin: 0;
    font-size: 15px;
}

.card-body { padding: 20px; }

table { width: 100%; border-collapse: collapse; }
thead th {
    text-align: left;
    font-size: 12px;
    text-transform: uppercase;
    letter-spacing: .03em;
    color: var(--text-muted);
    padding: 10px 20px;
    border-bottom: 1px solid var(--border);
}
tbody td {
    padding: 12px 20px;
    border-bottom: 1px solid var(--border);
    font-size: 13.5px;
}
tbody tr:last-child td { border-bottom: none; }
tbody tr:hover { background: #fafbfc; }

.pill {
    display: inline-flex;
    align-items: center;
    padding: 3px 10px;
    border-radius: 999px;
    font-size: 12px;
    font-weight: 600;
}
.pill-super { background: #ede9fe; color: #6d28d9; }
.pill-admin { background: #dbeafe; color: #1d4ed8; }
.pill-none { background: #f3f4f6; color: var(--text-muted); }

.pill-pending { background: #fef3c7; color: #92400e; }
.pill-processing { background: #dbeafe; color: #1d4ed8; }
.pill-completed { background: #dcfce7; color: #15803d; }
.pill-cancelled { background: #fee2e2; color: #b91c1c; }

.pill-lg { padding: 5px 14px; font-size: 13px; }

.filter-bar {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-wrap: wrap;
}

.filter-tab {
    padding: 7px 14px;
    border-radius: 8px;
    border: 1px solid var(--border);
    background: #fff;
    font-size: 13px;
    font-weight: 600;
    color: var(--text-muted);
    cursor: pointer;
}

.filter-tab.active { background: var(--primary); border-color: var(--primary); color: #fff; }
.filter-tab:hover:not(.active) { background: #f3f4f6; }

.search-input {
    padding: 7px 12px;
    border: 1px solid var(--border);
    border-radius: 8px;
    /* >=16px — dưới mức này Safari/Chrome mobile tự động zoom vào khi focus ô nhập. */
    font-size: 16px;
    min-width: 220px;
}
.search-input:focus { outline: none; border-color: var(--primary); }

.pagination {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 14px 20px;
    border-top: 1px solid var(--border);
    font-size: 13px;
    color: var(--text-muted);
}

.pagination .btns { display: flex; gap: 6px; }

.mono { font-variant-numeric: tabular-nums; font-family: ui-monospace, SFMono-Regular, Menlo, monospace; }

.history-item {
    display: flex;
    gap: 10px;
    padding: 10px 0;
    border-bottom: 1px solid var(--border);
    font-size: 13px;
}
.history-item:last-child { border-bottom: none; }
.history-item .time { color: var(--text-muted); font-size: 12px; min-width: 130px; }

.row-actions { display: flex; gap: 6px; }

.empty-state {
    text-align: center;
    padding: 40px 20px;
    color: var(--text-muted);
    font-size: 13.5px;
}

/* ---------- Modal ---------- */
.modal-backdrop {
    position: fixed;
    inset: 0;
    background: rgba(15, 23, 42, .5);
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
    z-index: 50;
    overscroll-behavior: contain;
}

/* Khoá scroll trang nền trong lúc có modal mở — chặn việc lướt trong modal kéo luôn page đằng sau. */
body.body-scroll-locked {
    overflow: hidden;
}

.modal {
    width: 100%;
    max-width: 420px;
    background: var(--surface);
    border-radius: var(--radius);
    box-shadow: 0 20px 60px rgba(0,0,0,.25);
    max-height: 90vh;
    overflow-y: auto;
}

.modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px 20px;
    border-bottom: 1px solid var(--border);
}

.modal-header h3 { margin: 0; font-size: 15px; }

.chat-header-meta {
    margin-top: 3px;
    font-size: 12px;
    color: var(--text-muted);
    overflow-wrap: break-word;
}

.modal-close {
    background: none;
    border: none;
    font-size: 18px;
    cursor: pointer;
    color: var(--text-muted);
    line-height: 1;
}

.modal-body { padding: 20px; }
.modal-footer {
    display: flex;
    justify-content: flex-end;
    gap: 8px;
    padding: 16px 20px;
    border-top: 1px solid var(--border);
}

.hint { font-size: 12px; color: var(--text-muted); margin-top: 4px; }

.stat-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
    gap: 16px;
    margin-bottom: 24px;
}

.stat-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 18px 20px;
    box-shadow: var(--shadow);
}

.stat-card .label {
    font-size: 12.5px;
    color: var(--text-muted);
    margin-bottom: 6px;
}

.stat-card .value {
    font-size: 24px;
    font-weight: 700;
}

/* ---------- Table cuộn ngang thay vì bị bóp méo ---------- */
.table-scroll {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
}
.table-scroll table { min-width: 640px; }

/* ---------- Mobile: sidebar thành drawer, layout xếp dọc ---------- */
@media (max-width: 860px) {
    .sidebar {
        position: fixed;
        top: 0;
        left: 0;
        bottom: 0;
        z-index: 110;
        transform: translateX(-100%);
        transition: transform .22s ease;
        box-shadow: 6px 0 30px rgba(0,0,0,.3);
        width: 260px;
    }
    .sidebar.open { transform: translateX(0); }

    .sidebar-backdrop {
        display: block;
        position: fixed;
        inset: 0;
        background: rgba(15, 23, 42, .45);
        z-index: 100;
        opacity: 0;
        pointer-events: none;
        transition: opacity .22s ease;
    }
    .sidebar-backdrop.open { opacity: 1; pointer-events: auto; }

    .menu-toggle-btn { display: inline-flex; align-items: center; }

    .topbar { padding: 0 14px; gap: 8px; }
    .topbar h2 { font-size: 14.5px; }
    .user-chip { gap: 6px; }
    .user-chip .role { display: none; }
    .user-chip > div:first-child { display: none; }

    .content { padding: 14px; }

    .stat-grid { grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: 10px; }
    .stat-card { padding: 14px; }
    .stat-card .value { font-size: 20px; }

    .card-header {
        flex-direction: column;
        align-items: stretch;
        gap: 10px;
    }
    .card-header > div {
        display: flex;
        flex-wrap: wrap;
        gap: 8px;
    }
    .card-header .search-input,
    .card-header select.search-input {
        flex: 1;
        min-width: 140px;
    }

    .modal { max-width: 94vw; }

    .row-actions { flex-wrap: wrap; }
}

/* ---------- Store / Wildberries ---------- */
.pill-ok { background: #dcfce7; color: #15803d; }
.pill-warn { background: #fef3c7; color: #92400e; }
.pill-danger { background: #fee2e2; color: #b91c1c; }
.pill-info { background: #dbeafe; color: #1d4ed8; }

.pill-row { display: flex; flex-wrap: wrap; gap: 6px; }

.kv-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
    gap: 14px 24px;
}
.kv .k { font-size: 12px; color: var(--text-muted); margin-bottom: 3px; }
.kv .v { font-weight: 600; word-break: break-word; }

.toolbar { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }

.banner {
    padding: 12px 16px;
    border-radius: var(--radius);
    margin-bottom: 16px;
    font-size: 13.5px;
    border: 1px solid transparent;
}
.banner-danger { background: var(--danger-bg); border-color: #fecaca; color: #991b1b; }
.banner-warn { background: #fffbeb; border-color: #fde68a; color: #92400e; }

.thumb {
    width: 40px; height: 52px; object-fit: cover;
    border-radius: 6px; background: #f3f4f6; display: block;
}

tr.clickable { cursor: pointer; }

.modal-wide { max-width: 760px; width: 100%; }
textarea.token-input {
    width: 100%; min-height: 96px; padding: 10px 12px; font-family: ui-monospace, Menlo, monospace;
    font-size: 12.5px; border: 1px solid var(--border); border-radius: 8px; resize: vertical;
}
textarea.token-input:focus { outline: none; border-color: var(--primary); }

.steps { margin: 6px 0 0; padding-left: 18px; color: var(--text-muted); font-size: 12.5px; line-height: 1.6; }

.detail-list { margin: 0; padding: 0; list-style: none; font-size: 13px; }
.detail-list li { display: flex; gap: 12px; padding: 6px 0; border-bottom: 1px solid var(--border); }
.detail-list li:last-child { border-bottom: none; }
.detail-list .dk { width: 40%; color: var(--text-muted); }
