* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

:root {
    --color-primary: #0A4A90;
    --color-primary-dark: #073760;
    --color-accent: #f5820a;
    --color-accent-dark: #d96f00;
    --color-green: #27ae60;
    --color-green-dark: #1e8449;
    --color-red: #e74c3c;
    --color-red-dark: #c0392b;
    --color-bg: #eef2f5;
    --color-card: #ffffff;
    --color-border: #d7dee3;
    --color-text: #2c3e50;
    --color-muted: #7f8c9a;
    --header-height: 56px;
}

html, body {
    height: 100%;
}

body {
    font-family: 'Segoe UI', Tahoma, Arial, sans-serif;
    background: var(--color-bg);
    color: var(--color-text);
    font-size: 14px;
}

#admin-app {
    display: flex;
    flex-direction: column;
    min-height: 100vh;
}

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

/* ===================== HEADER ===================== */
.ad-header {
    height: var(--header-height);
    background: linear-gradient(180deg, var(--color-primary) 0%, var(--color-primary-dark) 100%);
    color: #fff;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 16px;
    box-shadow: 0 2px 6px rgba(0,0,0,0.2);
    position: sticky;
    top: 0;
    z-index: 100;
}

.ad-header-left {
    display: flex;
    align-items: center;
    gap: 28px;
}

.ad-logo {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 17px;
    white-space: nowrap;
}

.ad-logo-icon { font-size: 20px; }
.ad-logo-text strong { color: #ffd166; }

.ad-nav {
    display: flex;
    align-items: stretch;
    height: 100%;
}

.ad-nav-item {
    position: relative;
    display: flex;
    align-items: center;
    height: 100%;
}

.ad-nav-link {
    display: flex;
    align-items: center;
    gap: 4px;
    height: 100%;
    padding: 0 14px;
    font-size: 14px;
    font-weight: 500;
    color: rgba(255,255,255,0.88);
    border-bottom: 3px solid transparent;
    transition: background 0.15s, border-color 0.15s;
}

.ad-nav-link:hover,
.ad-nav-item.active .ad-nav-link {
    background: rgba(255,255,255,0.08);
    border-bottom-color: var(--color-accent);
    color: #fff;
}

.caret { font-size: 10px; }

.ad-dropdown {
    display: none;
    position: absolute;
    top: 100%;
    left: 0;
    min-width: 200px;
    background: #fff;
    color: var(--color-text);
    border-radius: 0 0 6px 6px;
    box-shadow: 0 8px 20px rgba(0,0,0,0.18);
    overflow: hidden;
    z-index: 200;
}

.ad-nav-item.has-dropdown:hover .ad-dropdown {
    display: block;
}

.ad-dropdown a {
    display: block;
    padding: 10px 16px;
    font-size: 13px;
    color: var(--color-text);
}

.ad-dropdown a:hover {
    background: #f2f6fa;
    color: var(--color-primary);
}

.ad-header-right {
    display: flex;
    align-items: center;
    gap: 10px;
}

.ad-pos-btn {
    background: var(--color-accent);
    color: #fff;
    padding: 7px 14px;
    border-radius: 5px;
    font-size: 13px;
    font-weight: 600;
    white-space: nowrap;
}

.ad-pos-btn:hover { background: var(--color-accent-dark); }

.ad-icon-btn {
    position: relative;
    background: transparent;
    border: none;
    color: #fff;
    font-size: 17px;
    cursor: pointer;
    padding: 6px;
}

.ad-badge {
    position: absolute;
    top: 0;
    right: 0;
    background: var(--color-red);
    color: #fff;
    font-size: 10px;
    font-weight: 700;
    border-radius: 8px;
    min-width: 16px;
    height: 16px;
    line-height: 16px;
    text-align: center;
    padding: 0 3px;
}

.ad-account {
    position: relative;
}

.ad-account-btn {
    background: transparent;
    border: none;
    color: #fff;
    font-size: 13px;
    font-weight: 500;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 4px;
    padding: 6px 8px;
}

.ad-account-dropdown {
    right: 0;
    left: auto;
    min-width: 140px;
}

/* ===================== BODY LAYOUT ===================== */
.ad-body {
    display: flex;
    flex: 1;
    min-height: calc(100vh - var(--header-height));
}

.ad-sidebar {
    width: 220px;
    flex-shrink: 0;
    background: #fff;
    border-right: 1px solid var(--color-border);
    padding: 14px 0;
}

.ad-sidebar-group-title {
    font-size: 11px;
    font-weight: 700;
    color: var(--color-muted);
    text-transform: uppercase;
    letter-spacing: .04em;
    padding: 6px 18px;
    margin-top: 6px;
}

.ad-sidebar-link {
    display: block;
    padding: 9px 18px;
    font-size: 13.5px;
    color: var(--color-text);
    border-left: 3px solid transparent;
}

.ad-sidebar-link:hover {
    background: #f2f6fa;
}

.ad-sidebar-link.active {
    background: #eaf3ff;
    border-left-color: var(--color-primary);
    color: var(--color-primary);
    font-weight: 600;
}

.ad-content {
    flex: 1;
    padding: 20px 24px 60px;
    min-width: 0;
}

/* ===================== PAGE HEADER ===================== */
.ad-page-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 16px;
    flex-wrap: wrap;
    gap: 10px;
}

.ad-page-title {
    font-size: 20px;
    font-weight: 700;
    color: var(--color-text);
}

/* ===================== BUTTONS ===================== */
.btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    border: none;
    border-radius: 5px;
    padding: 8px 16px;
    font-size: 13.5px;
    font-weight: 600;
    cursor: pointer;
    transition: filter 0.15s;
}

.btn:hover { filter: brightness(0.94); }
.btn:active { filter: brightness(0.88); }

.btn-primary { background: var(--color-primary); color: #fff; }
.btn-accent { background: var(--color-accent); color: #fff; }
.btn-green { background: var(--color-green); color: #fff; }
.btn-red { background: var(--color-red); color: #fff; }
.btn-outline { background: #fff; color: var(--color-text); border: 1px solid var(--color-border); }
.btn-sm { padding: 5px 10px; font-size: 12.5px; }
.btn[disabled] { opacity: 0.5; cursor: not-allowed; }

/* ===================== CARDS ===================== */
.ad-card {
    background: var(--color-card);
    border-radius: 8px;
    box-shadow: 0 1px 3px rgba(0,0,0,0.08);
    padding: 18px;
    margin-bottom: 18px;
}

.ad-stat-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 16px;
    margin-bottom: 18px;
}

.ad-stat-card {
    background: var(--color-card);
    border-radius: 8px;
    box-shadow: 0 1px 3px rgba(0,0,0,0.08);
    padding: 16px 18px;
    display: flex;
    align-items: center;
    gap: 14px;
    border-left: 4px solid var(--color-primary);
}

.ad-stat-card.stat-revenue { border-left-color: var(--color-primary); }
.ad-stat-card.stat-orders { border-left-color: var(--color-accent); }
.ad-stat-card.stat-stock { border-left-color: var(--color-green); }
.ad-stat-card.stat-profit { border-left-color: #8e44ad; }

.ad-stat-icon {
    font-size: 26px;
    width: 46px;
    height: 46px;
    border-radius: 10px;
    background: #f2f6fa;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.ad-stat-label {
    font-size: 12.5px;
    color: var(--color-muted);
    margin-bottom: 4px;
}

.ad-stat-value {
    font-size: 19px;
    font-weight: 700;
    color: var(--color-text);
}

.ad-dashboard-row {
    display: grid;
    grid-template-columns: 1.4fr 1fr;
    gap: 18px;
    align-items: start;
}

.ad-card-title {
    font-size: 15px;
    font-weight: 700;
    margin-bottom: 14px;
    color: var(--color-text);
}

/* ===================== FILTER BAR ===================== */
.ad-filter-bar {
    display: flex;
    align-items: center;
    gap: 10px;
    flex-wrap: wrap;
    margin-bottom: 14px;
}

.ad-input, .ad-select {
    border: 1px solid var(--color-border);
    border-radius: 5px;
    padding: 8px 10px;
    font-size: 13.5px;
    color: var(--color-text);
    background: #fff;
}

.ad-input:focus, .ad-select:focus {
    outline: none;
    border-color: var(--color-primary);
}

.ad-input-search {
    width: 260px;
}

/* ===================== TABLE ===================== */
.ad-table-wrap {
    overflow-x: auto;
}

.ad-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 13.5px;
}

.ad-table th {
    text-align: left;
    background: #f6f8fa;
    color: var(--color-muted);
    font-weight: 700;
    font-size: 12px;
    text-transform: uppercase;
    letter-spacing: .02em;
    padding: 10px 12px;
    border-bottom: 1px solid var(--color-border);
    white-space: nowrap;
}

.ad-table td {
    padding: 10px 12px;
    border-bottom: 1px solid #eef1f4;
    vertical-align: middle;
}

.ad-table tbody tr:hover { background: #f9fbfd; }
.ad-table .num { text-align: right; font-variant-numeric: tabular-nums; }
.ad-table .center { text-align: center; }

.ad-empty-row {
    text-align: center;
    color: var(--color-muted);
    padding: 30px !important;
}

.ad-link-action {
    color: var(--color-primary);
    font-weight: 600;
    cursor: pointer;
}

.ad-link-action:hover { text-decoration: underline; }

/* ===================== BADGES ===================== */
.ad-badge-status {
    display: inline-block;
    padding: 3px 9px;
    border-radius: 12px;
    font-size: 11.5px;
    font-weight: 700;
    white-space: nowrap;
}

.badge-green { background: #e6f7ed; color: var(--color-green-dark); }
.badge-orange { background: #fef1e0; color: var(--color-accent-dark); }
.badge-red { background: #fdeaea; color: var(--color-red-dark); }
.badge-gray { background: #eef1f4; color: var(--color-muted); }
.badge-blue { background: #e8f1fc; color: var(--color-primary-dark); }

/* ===================== PAGINATION ===================== */
.ad-pagination {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 8px;
    margin-top: 14px;
    font-size: 13px;
    color: var(--color-muted);
}

.ad-pagination button {
    border: 1px solid var(--color-border);
    background: #fff;
    border-radius: 4px;
    padding: 5px 10px;
    cursor: pointer;
    font-size: 13px;
}

.ad-pagination button[disabled] { opacity: 0.4; cursor: not-allowed; }

/* ===================== CHART (custom canvas) ===================== */
.ad-chart-canvas-wrap {
    position: relative;
    height: 240px;
}

/* ===================== FORM / MODAL ===================== */
.ad-modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(20,30,40,0.45);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 500;
}

.ad-modal-box {
    background: #fff;
    border-radius: 8px;
    width: 560px;
    max-width: 92vw;
    max-height: 88vh;
    overflow-y: auto;
    box-shadow: 0 12px 40px rgba(0,0,0,0.25);
}

.ad-modal-box.wide { width: 820px; }

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

.ad-modal-header h3 { font-size: 16px; font-weight: 700; }

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

.ad-modal-body { padding: 18px 20px; }

.ad-modal-footer {
    padding: 14px 20px;
    border-top: 1px solid var(--color-border);
    display: flex;
    justify-content: flex-end;
    gap: 10px;
}

.form-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 12px;
    margin-bottom: 12px;
}

.form-group { margin-bottom: 12px; }
.form-group.full { grid-column: 1 / -1; }

.ad-checkbox-label { display: flex; align-items: center; gap: 8px; font-size: 13.5px; font-weight: 500; color: var(--color-text); cursor: pointer; }
.ad-checkbox-label input { width: auto; }

.ad-thumb {
    width: 36px; height: 36px; border-radius: 6px; object-fit: cover;
    border: 1px solid var(--color-border); display: inline-flex; align-items: center; justify-content: center;
}
.ad-thumb-empty { background: #f3f5f7; font-size: 16px; }

.form-group label {
    display: block;
    font-size: 12.5px;
    font-weight: 600;
    color: var(--color-muted);
    margin-bottom: 5px;
}

.form-group input,
.form-group select,
.form-group textarea {
    width: 100%;
    border: 1px solid var(--color-border);
    border-radius: 5px;
    padding: 8px 10px;
    font-size: 13.5px;
    font-family: inherit;
    color: var(--color-text);
}

.form-group input:focus,
.form-group select:focus,
.form-group textarea:focus {
    outline: none;
    border-color: var(--color-primary);
}

/* ===================== INLINE ITEM PICKER (nhap hang / kiem kho) ===================== */
.ad-item-picker {
    position: relative;
    margin-bottom: 12px;
}

.ad-item-picker-results {
    position: absolute;
    top: 100%;
    left: 0;
    right: 0;
    background: #fff;
    border: 1px solid var(--color-border);
    border-radius: 0 0 6px 6px;
    max-height: 220px;
    overflow-y: auto;
    box-shadow: 0 8px 20px rgba(0,0,0,0.15);
    z-index: 50;
}

.ad-item-picker-results div {
    padding: 8px 12px;
    cursor: pointer;
    font-size: 13px;
    display: flex;
    justify-content: space-between;
}

.ad-item-picker-results div:hover { background: #f2f6fa; }

.ad-mini-table input[type="number"] {
    width: 80px;
    padding: 5px 7px;
    border: 1px solid var(--color-border);
    border-radius: 4px;
}

.ad-summary-box {
    background: #f9fbfd;
    border-radius: 6px;
    padding: 12px 16px;
    margin-top: 12px;
}

.ad-summary-row {
    display: flex;
    justify-content: space-between;
    padding: 4px 0;
    font-size: 13.5px;
}

.ad-summary-row.total {
    font-weight: 700;
    font-size: 15px;
    border-top: 1px dashed var(--color-border);
    margin-top: 6px;
    padding-top: 8px;
}

/* ===================== TABS (reports) ===================== */
.ad-tabs {
    display: flex;
    gap: 4px;
    border-bottom: 1px solid var(--color-border);
    margin-bottom: 16px;
}

.ad-tab {
    padding: 9px 16px;
    font-size: 13.5px;
    font-weight: 600;
    color: var(--color-muted);
    cursor: pointer;
    border-bottom: 2px solid transparent;
}

.ad-tab.active {
    color: var(--color-primary);
    border-bottom-color: var(--color-primary);
}

/* ===================== TOAST ===================== */
.ad-toast-container {
    position: fixed;
    top: 70px;
    right: 20px;
    z-index: 999;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.ad-toast {
    background: #2c3e50;
    color: #fff;
    padding: 10px 16px;
    border-radius: 6px;
    font-size: 13.5px;
    box-shadow: 0 4px 14px rgba(0,0,0,0.2);
    min-width: 220px;
    animation: ad-toast-in 0.2s ease-out;
}

.ad-toast.success { background: var(--color-green-dark); }
.ad-toast.error { background: var(--color-red-dark); }

@keyframes ad-toast-in {
    from { transform: translateY(-8px); opacity: 0; }
    to { transform: translateY(0); opacity: 1; }
}

.ad-muted { color: var(--color-muted); }
.ad-empty-state {
    text-align: center;
    padding: 60px 20px;
    color: var(--color-muted);
}

.ad-empty-state .icon { font-size: 40px; margin-bottom: 12px; }

@media (max-width: 1100px) {
    .ad-stat-grid { grid-template-columns: repeat(2, 1fr); }
    .ad-dashboard-row { grid-template-columns: 1fr; }
}

/* ===================== BRANCH SELECTOR (header) ===================== */
.ad-branch-select {
    position: relative;
}

.ad-branch-btn {
    background: rgba(255,255,255,0.12);
    border: 1px solid rgba(255,255,255,0.3);
    color: #fff;
    padding: 6px 12px;
    border-radius: 5px;
    font-size: 12.5px;
    font-weight: 600;
    cursor: pointer;
    white-space: nowrap;
}

.ad-branch-btn:hover { background: rgba(255,255,255,0.22); }

.ad-branch-dropdown {
    right: 0;
    left: auto;
    min-width: 240px;
}

.ad-branch-dropdown a.active {
    color: var(--color-primary);
    font-weight: 700;
    background: #eaf3ff;
}

/* ===================== BARCODE LABEL PRINTING ===================== */
.ad-barcode-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 10px;
    margin-top: 14px;
}

.ad-barcode-label {
    border: 1px dashed var(--color-border);
    border-radius: 4px;
    padding: 8px 6px;
    text-align: center;
}

.ad-barcode-label .lbl-shop { font-size: 10px; color: var(--color-muted); }
.ad-barcode-label .lbl-name {
    font-size: 11px;
    font-weight: 700;
    margin: 2px 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.ad-barcode-label .lbl-price { font-size: 13px; font-weight: 700; color: var(--color-red); margin-bottom: 4px; }

.lbl-bars {
    height: 34px;
    margin: 0 4px;
    display: flex;
    align-items: center;
}
.lbl-bars svg { display: block; width: 100%; height: 100%; }

.lbl-code {
    font-family: 'Consolas', monospace;
    font-size: 11px;
    letter-spacing: 1px;
    margin-top: 2px;
}

@media print {
    #admin-app > *:not(.ad-content),
    .ad-page-header, .ad-card > *:not(.ad-print-area) {
        display: none !important;
    }
    .ad-print-area, .ad-print-area * { visibility: visible; }
    .ad-print-area {
        display: block !important;
        position: absolute;
        left: 0;
        top: 0;
        width: 100%;
    }
}

/* ===================== DROPDOWN GROUP LABEL (nav / header icon menus) ===================== */
.ad-dropdown-label {
    padding: 8px 14px 4px;
    font-size: 11px;
    font-weight: 700;
    text-transform: uppercase;
    color: var(--color-muted);
    letter-spacing: 0.4px;
}

.ad-dropdown-sep {
    height: 1px;
    background: var(--color-border);
    margin: 4px 0;
}

/* ===================== HEADER ICON DROPDOWN (Settings / API) ===================== */
.ad-icon-dropdown-wrap { position: relative; }

.ad-icon-dropdown {
    right: 0;
    left: auto;
    min-width: 230px;
}

/* ===================== TOGGLE SWITCH ===================== */
.ad-toggle {
    display: inline-flex;
    align-items: center;
    gap: 10px;
    cursor: pointer;
    user-select: none;
}

.ad-toggle input { display: none; }

.ad-toggle .track {
    width: 40px;
    height: 22px;
    border-radius: 999px;
    background: #ccd3d9;
    position: relative;
    transition: background 0.15s;
    flex-shrink: 0;
}

.ad-toggle .track::after {
    content: '';
    position: absolute;
    top: 2px;
    left: 2px;
    width: 18px;
    height: 18px;
    border-radius: 50%;
    background: #fff;
    transition: left 0.15s;
    box-shadow: 0 1px 2px rgba(0,0,0,0.3);
}

.ad-toggle input:checked + .track { background: var(--color-green); }
.ad-toggle input:checked + .track::after { left: 20px; }

/* ===================== SETTINGS PAGE LAYOUT ===================== */
.ad-settings-tabs {
    display: flex;
    flex-direction: column;
    gap: 2px;
    min-width: 210px;
}

.ad-settings-tabs a {
    padding: 10px 14px;
    border-radius: 6px;
    font-size: 13.5px;
    font-weight: 600;
    color: var(--color-text);
}

.ad-settings-tabs a:hover { background: #eef2f5; }
.ad-settings-tabs a.active { background: var(--color-primary); color: #fff; }

.ad-settings-layout {
    display: grid;
    grid-template-columns: 220px 1fr;
    gap: 16px;
    align-items: start;
}

/* ===================== API KEY / CODE DISPLAY ===================== */
.ad-code-box {
    background: #1e2b38;
    color: #d7f5e0;
    font-family: 'Consolas', monospace;
    font-size: 13px;
    padding: 12px 14px;
    border-radius: 6px;
    word-break: break-all;
    margin: 8px 0;
}

.ad-kv-pill {
    display: inline-block;
    background: #eef2f5;
    border-radius: 4px;
    padding: 2px 8px;
    font-size: 12px;
    font-family: 'Consolas', monospace;
    margin: 2px 3px 2px 0;
}

/* ===================== API DOCS / TRY-IT PANEL ===================== */
.ad-api-endpoint {
    border: 1px solid var(--color-border);
    border-radius: 8px;
    margin-bottom: 14px;
    overflow: hidden;
}

.ad-api-endpoint-head {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 12px 16px;
    background: #f6f8fa;
    cursor: pointer;
}

.ad-api-method {
    font-weight: 800;
    font-size: 11.5px;
    padding: 3px 9px;
    border-radius: 4px;
    color: #fff;
    min-width: 52px;
    text-align: center;
}

.ad-api-method.get { background: #2f80c9; }
.ad-api-method.post { background: var(--color-green-dark); }

.ad-api-endpoint-path {
    font-family: 'Consolas', monospace;
    font-weight: 700;
    font-size: 13.5px;
}

.ad-api-endpoint-body {
    padding: 14px 16px;
    border-top: 1px solid var(--color-border);
    display: none;
}

.ad-api-endpoint.open .ad-api-endpoint-body { display: block; }

.ad-api-try-result {
    background: #1e2b38;
    color: #d7f5e0;
    font-family: 'Consolas', monospace;
    font-size: 12.5px;
    padding: 12px 14px;
    border-radius: 6px;
    white-space: pre-wrap;
    word-break: break-all;
    max-height: 320px;
    overflow: auto;
    margin-top: 10px;
}

.badge-purple { background: #f1e6fb; color: #6c3483; }

/* ===================== CAI DAT: MA TRAN PHAN QUYEN & NHOM KHACH HANG ===================== */
.perm-check {
    width: 18px;
    height: 18px;
    cursor: pointer;
    accent-color: var(--color-primary);
}

.grp-name, .grp-discount {
    width: 100%;
}
