/* ============================================
   Admin CSS - eTicket
   ============================================ */

/* ============================================
   THEME VARIABLES (Light / Dark)
   ============================================ */
:root {
    --bg-primary: #ffffff;
    --bg-secondary: #f1f5f9;
    --text-primary: #0f172a;
    --text-secondary: #475569;
    --border-color: #e2e8f0;
    --card-bg: rgba(255, 255, 255, 0.8);
    --color-primary: #2563eb;
    --color-primary-dark: #1d4ed8;

    /* Thang slate dạng "R G B" cho Tailwind (_Layout). Light = đúng giá trị Tailwind mặc định */
    --slate-50: 248 250 252;
    --slate-100: 241 245 249;
    --slate-200: 226 232 240;
    --slate-300: 203 213 225;
    --slate-400: 148 163 184;
    --slate-500: 100 116 139;
    --slate-600: 71 85 105;
    --slate-700: 51 65 85;
    --slate-800: 30 41 59;
    --slate-900: 15 23 42;
    --slate-950: 2 6 23;
    --bg-dark-rgb: 2 6 23;
}

/* Dark: nền bớt đen tuyệt đối, thẻ sáng hơn nền 1 bậc để tách lớp;
   chữ phụ (slate-400/500) sáng lên để đạt tương phản WCAG AA (≥ 4.5:1) trên nền thẻ */
.dark {
    /* Control gốc của trình duyệt (icon lịch ô ngày, danh sách select, thanh cuộn) dùng bản tối */
    color-scheme: dark;
    --bg-primary: #0f1622;
    --bg-secondary: #131c2a;
    --text-primary: #f1f5f9;
    --text-secondary: #b6c1cf;
    --border-color: #364459;
    --card-bg: rgba(27, 38, 55, 0.9);

    --slate-200: 232 237 243;
    --slate-300: 214 222 232;
    --slate-400: 182 193 207;
    --slate-500: 148 161 179;
    --slate-600: 92 107 128;
    --slate-700: 54 68 89;
    --slate-800: 27 38 55;
    --slate-900: 19 28 42;
    --slate-950: 12 18 28;
    --bg-dark-rgb: 15 22 34;
}

/* Dark: link/chữ màu primary (#2563eb) quá tối trên nền tối → dùng xanh sáng hơn.
   Chỉ đổi màu chữ; nền bg-primary giữ nguyên để chữ trắng trên nút vẫn đủ tương phản */
.dark .text-primary,
.dark .hover\:text-primary:hover { color: #7aa7f7; }
.dark .bg-primary\/5 { background-color: rgb(122 167 247 / 0.08); }

/* Dark: badge/nhãn chỉ khai màu light (text-*-600 + bg-*-50, thường sinh từ JS) → bản tối dễ đọc.
   Phần tử đã có dark:* riêng vẫn ưu tiên class dark của Tailwind (khai sau, cùng độ ưu tiên) */
.dark .text-green-600 { color: #6fdc9b; }
.dark .text-blue-600 { color: #8db8fa; }
.dark .text-purple-600 { color: #c4a5fb; }
.dark .text-amber-600 { color: #f6c35b; }
.dark .text-orange-600 { color: #f9a86b; }
.dark .text-red-600 { color: #f89a9a; }
.dark .bg-green-50 { background-color: rgb(34 197 94 / 0.16); }
.dark .bg-blue-50 { background-color: rgb(59 130 246 / 0.18); }
.dark .bg-purple-50 { background-color: rgb(168 85 247 / 0.18); }
.dark .bg-amber-50 { background-color: rgb(245 158 11 / 0.16); }
.dark .bg-orange-50 { background-color: rgb(249 115 22 / 0.16); }
.dark .bg-red-50 { background-color: rgb(239 68 68 / 0.16); }
.dark .bg-slate-50 { background-color: rgb(148 161 179 / 0.14); }

/* Base Styles */
body {
    font-family: 'Inter', 'Segoe UI', Arial, sans-serif;
    /* Safe area cho iPhone notch/Dynamic Island — 0px trên thiết bị bình thường */
    padding-left: env(safe-area-inset-left);
    padding-right: env(safe-area-inset-right);
}

/* PWA standalone mode: thêm padding top cho status bar */
@media all and (display-mode: standalone) {
    body {
        padding-top: env(safe-area-inset-top);
        padding-bottom: env(safe-area-inset-bottom);
    }
}


/* ============================================
   reCAPTCHA — Ẩn badge, hiện text notice
   ============================================ */
.grecaptcha-badge { visibility: hidden !important; }

.recaptcha-notice {
    font-size: 0.7rem;
    color: #9ca3af;
    text-align: center;
    margin-top: 0.5rem;
}
.recaptcha-notice a {
    color: #6b7280;
    text-decoration: underline;
}
.dark .recaptcha-notice { color: #6b7280; }
.dark .recaptcha-notice a { color: #9ca3af; }

/* ============================================
   SKELETON LOADER — Inline loading (non-blocking)
   ============================================ */
.skeleton-loader {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 2rem;
    color: var(--text-secondary);
    font-size: 0.875rem;
}

.skeleton-line {
    height: 1rem;
    border-radius: 0.25rem;
    background: linear-gradient(90deg, var(--border-color) 25%, transparent 50%, var(--border-color) 75%);
    background-size: 200% 100%;
    animation: skeleton-shimmer 1.5s infinite;
}

@keyframes skeleton-shimmer {
    0% { background-position: 200% 0; }
    100% { background-position: -200% 0; }
}

/* Custom Scrollbar */
.custom-scrollbar::-webkit-scrollbar {
    width: 6px;
    height: 6px;
}

.custom-scrollbar::-webkit-scrollbar-track {
    background: transparent;
}

.custom-scrollbar::-webkit-scrollbar-thumb {
    background-color: rgba(43, 85, 133, 0.2);
    border-radius: 20px;
}

.scrolling-touch {
    -webkit-overflow-scrolling: touch;
}

/* Sidebar mobile overlay */
.sidebar-overlay {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-color: rgba(0, 0, 0, 0.5);
    z-index: 9998 !important;
}

.sidebar-overlay.active {
    display: block;
}

/* ============================================
   SHARED FORM COMPONENTS (dùng chung cho mọi view)
   ============================================ */
.lbl {
    display: block;
    font-size: 0.8125rem;
    font-weight: 500;
    color: #64748b;
    margin-bottom: 0.375rem;
}
.dark .lbl { color: #94a3b8; }

.inp {
    display: block;
    width: 100%;
    padding: 0.5rem 0.75rem;
    font-size: 0.875rem;
    border-radius: 0.5rem;
    border: 1px solid #e2e8f0;
    background: #fff;
    color: #1e293b;
    transition: all 0.15s;
}
.inp:focus {
    outline: none;
    border-color: #2563eb;
    box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.1);
}
.dark .inp {
    background: #0f172a;
    border-color: #334155;
    color: #e2e8f0;
}
.dark .inp:focus {
    border-color: #2563eb;
    box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.2);
}
select.inp { appearance: auto; }
textarea.inp { resize: vertical; }

.btn-primary {
    padding: 0.5rem 1.25rem;
    font-size: 0.875rem;
    font-weight: 600;
    color: #fff;
    background: #2563eb;
    border-radius: 0.5rem;
    transition: all 0.15s;
}
.btn-primary:hover { background: #1d4ed8; }

.btn-primary-sm {
    padding: 0.375rem 0.875rem;
    font-size: 0.8125rem;
    font-weight: 500;
    color: #fff;
    background: #2563eb;
    border-radius: 0.375rem;
    display: inline-flex;
    align-items: center;
    transition: all 0.15s;
    white-space: nowrap;
}
.btn-primary-sm:hover { background: #1d4ed8; }

.btn-secondary {
    padding: 0.5rem 1.25rem;
    font-size: 0.875rem;
    font-weight: 500;
    color: #64748b;
    background: #fff;
    border: 1px solid #e2e8f0;
    border-radius: 0.5rem;
    transition: all 0.15s;
}
.btn-secondary:hover { background: #f8fafc; }
.dark .btn-secondary {
    background: #1e293b;
    border-color: #334155;
    color: #94a3b8;
}

.btn-secondary-sm {
    padding: 0.375rem 0.875rem;
    font-size: 0.8125rem;
    font-weight: 500;
    color: #64748b;
    background: #fff;
    border: 1px solid #e2e8f0;
    border-radius: 0.375rem;
    display: inline-flex;
    align-items: center;
    transition: all 0.15s;
    white-space: nowrap;
}
.btn-secondary-sm:hover { background: #f8fafc; }
.dark .btn-secondary-sm {
    background: #1e293b;
    border-color: #334155;
    color: #94a3b8;
}

/* Tab active state (Settings, etc.) */
.tab-active {
    border-color: #2563eb !important;
    color: #2563eb !important;
    font-weight: 600;
}
.dark .tab-active {
    color: #60a5fa !important;
    border-color: #60a5fa !important;
}

/* ============================================
   SIDEBAR — Desktop Collapsible + Mobile Slide
   ============================================ */

/* Desktop: smooth width transition */
@media (min-width: 1024px) {
    .admin-sidebar {
        transition: width 0.2s ease;
    }

    /* Collapsed state: icon-only */
    .admin-sidebar.collapsed {
        width: 4rem !important; /* 64px */
        min-width: 4rem;
    }

    .admin-sidebar.collapsed .sidebar-label,
    .admin-sidebar.collapsed .sidebar-section-title,
    .admin-sidebar.collapsed .sidebar-logout-label {
        display: none;
    }

    .admin-sidebar.collapsed .sidebar-badge {
        position: absolute;
        top: 4px;
        right: 4px;
        font-size: 0;
        width: 8px;
        height: 8px;
        padding: 0;
        min-width: unset;
    }

    .admin-sidebar.collapsed nav a {
        justify-content: center;
        padding-left: 0;
        padding-right: 0;
        position: relative;
    }

    .admin-sidebar.collapsed nav a .material-symbols-outlined {
        margin: 0;
    }

    .admin-sidebar.collapsed .sidebar-bottom {
        justify-content: center;
    }

    .admin-sidebar.collapsed .sidebar-bottom a {
        justify-content: center;
        padding-left: 0;
        padding-right: 0;
    }

    /* Tooltip on hover when collapsed */
    .admin-sidebar.collapsed nav a::after {
        content: attr(data-tooltip);
        position: absolute;
        left: calc(100% + 8px);
        top: 50%;
        transform: translateY(-50%);
        background: #1e293b;
        color: #f1f5f9;
        font-size: 0.75rem;
        padding: 0.25rem 0.625rem;
        border-radius: 0.375rem;
        white-space: nowrap;
        opacity: 0;
        pointer-events: none;
        transition: opacity 0.15s;
        z-index: 100;
        box-shadow: 0 4px 6px -1px rgba(0,0,0,0.1);
    }

    .admin-sidebar.collapsed nav a:hover::after {
        opacity: 1;
    }
}

/* Mobile sidebar */
@media (max-width: 1023px) {
    .admin-sidebar {
        display: none;
        transform: translateX(-100%);
        transition: transform 0.3s ease-in-out;
        position: fixed;
        top: 56px;
        left: 0;
        height: calc(100vh - 56px);
        height: calc(100dvh - 56px);
        z-index: 9999 !important;
        flex-direction: column;
    }

    .admin-sidebar.active {
        display: flex;
        transform: translateX(0);
        pointer-events: auto;
    }

    .admin-sidebar.active * {
        pointer-events: auto;
    }

    .admin-sidebar.active a {
        position: relative;
        z-index: 51;
        cursor: pointer;
    }
}

/* ============================================
   MOBILE RESPONSIVE — Global + POS
   Chỉ áp dụng < 768px, desktop không ảnh hưởng
   ============================================ */
@media (max-width: 767px) {
    /* Chống iOS Safari auto-zoom khi focus input < 16px */
    input, select, textarea { font-size: 1rem !important; }

    /* Giảm padding container trên mobile */
    .container { padding-top: 0.5rem !important; padding-bottom: 1rem !important; }

    /* POS: tăng touch target cho inputs nhỏ */
    .pos-inp {
        font-size: 0.875rem !important;
        padding: 0.5rem 0.625rem !important;
    }

    /* POS: ẩn phần tử phụ trên mobile */
    .pos-mobile-hide { display: none !important; }

    /* POS: form row → 2 cột, ẩn label (placeholder đủ rõ) */
    .pos-form-row {
        grid-template-columns: 1fr 1fr !important;
    }
    .pos-form-row > label {
        display: none !important;
    }
    .pos-form-row > div {
        grid-column: span 1 !important;
    }
}

/* ============================================
   ACCESS QR — Tem ngang theo PaperWidth × 50 mm, đồng bộ ticket_label.html của PosWPF
   ============================================ */
.access-qr-ticket-preview {
    width: var(--access-qr-ticket-preview-width, 120mm);
    height: var(--access-qr-ticket-preview-height, 75mm);
    max-width: 100%;
    overflow: hidden;
}
.access-qr-ticket-preview > .access-qr-ticket {
    max-width: none;
    transform: scale(var(--access-qr-ticket-preview-scale, 1.5));
    transform-origin: top left;
}
.access-qr-ticket {
    box-sizing: border-box;
    width: var(--access-qr-ticket-width, 80mm);
    height: var(--access-qr-ticket-height, 50mm);
    max-width: 100%;
    padding: 1.5mm 2mm 1.2mm;
    overflow: hidden;
    border: 1px solid #cbd5e1;
    border-radius: 0.35rem;
    box-shadow: 0 12px 30px rgba(15, 23, 42, 0.25);
    font-family: Tahoma, Arial, Helvetica, sans-serif;
    text-align: center;
    color: #000;
    background: #fff;
}
.access-qr-ticket,
.access-qr-ticket * {
    box-sizing: border-box;
}
.access-qr-ticket p,
.access-qr-ticket h2,
.access-qr-ticket section,
.access-qr-ticket footer {
    margin: 0;
}
.access-qr-ticket-header {
    height: 7.2mm;
    overflow: hidden;
}
.access-qr-ticket-title {
    font-size: 15px;
    font-weight: 900;
    line-height: 1.05;
    text-transform: uppercase;
    white-space: nowrap;
}
.access-qr-ticket-company {
    max-height: 3.6mm;
    margin-top: 0.5mm !important;
    overflow: hidden;
    font-size: 7.5px;
    font-weight: 600;
    line-height: 1.15;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.access-qr-ticket-company:empty {
    display: none;
}
.access-qr-ticket-middle {
    display: grid;
    grid-template-columns: 31% 36% 33%;
    align-items: center;
    width: 100%;
    height: 34.5mm;
}
.access-qr-ticket-column {
    min-width: 0;
    text-align: center;
}
.access-qr-ticket-column-left {
    padding-right: 1.2mm;
}
.access-qr-ticket-column-right {
    padding-left: 1.2mm;
}
.access-qr-ticket-field {
    margin-bottom: 1.4mm;
    overflow: hidden;
}
.access-qr-ticket-field:last-child {
    margin-bottom: 0;
}
.access-qr-ticket-field > span {
    display: block;
    font-size: 7.5px;
    line-height: 1.05;
}
.access-qr-ticket-field > strong {
    display: block;
    margin-top: 0.3mm;
    overflow-wrap: anywhere;
    font-size: 9px;
    font-weight: 800;
    line-height: 1.08;
}
.access-qr-ticket-field-name > strong,
.access-qr-ticket-field-reference > strong {
    display: -webkit-box;
    overflow: hidden;
    -webkit-box-orient: vertical;
    -webkit-line-clamp: 2;
}
.access-qr-ticket-field-name > strong {
    text-transform: uppercase;
}
.access-qr-ticket-qr {
    min-width: 0;
    text-align: center;
}
.access-qr-ticket-code {
    display: block;
    width: 27mm;
    height: 27mm;
    margin: 0 auto;
    image-rendering: pixelated;
}
.access-qr-ticket-token {
    margin-top: 0.6mm !important;
    overflow: hidden;
    font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
    font-size: 6.5px;
    font-weight: 700;
    line-height: 1;
    white-space: nowrap;
}
.access-qr-ticket-print-meta > span {
    font-weight: 700;
}
.access-qr-ticket-print-meta > strong {
    font-size: 8px;
}
.access-qr-ticket-note {
    height: 4.1mm;
    padding-top: 0.8mm;
    overflow: hidden;
    border-top: 1px dashed #111827;
    font-size: 7px;
    font-weight: 700;
    line-height: 1.15;
    text-align: center;
}

@media (max-width: 520px) {
    .access-qr-ticket-preview {
        width: var(--access-qr-ticket-width, 80mm);
        height: var(--access-qr-ticket-height, 50mm);
        overflow-x: auto;
    }
    .access-qr-ticket-preview > .access-qr-ticket {
        transform: none;
    }
}

/* ============================================
   FreeTicket (service ngoài) — khung iframe Admin
   ============================================ */
.freeticket-frame-wrap {
    height: calc(100vh - 7.5rem);
    min-height: 580px;
}

@media (max-width: 640px) {
    .freeticket-frame-wrap {
        height: calc(100vh - 6rem);
    }
}


/* ============================================
   Phân tích kết quả kinh doanh (Report/BusinessAnalysis)
   ============================================ */
.ba-chips { display: flex; flex-wrap: wrap; gap: 6px; }
.ba-chip {
    min-height: 36px; display: inline-flex; align-items: center; gap: 4px;
    padding: 4px 12px; border-radius: 999px; font-size: 13px; cursor: pointer; user-select: none;
    border: 1px solid #cbd5e1; background: #fff; color: #334155;
}
.ba-chip:hover { border-color: var(--color-primary); }
.ba-chip.on { background: #eff6ff; border-color: var(--color-primary); color: #1d4ed8; font-weight: 600; }
.ba-chip.ba-chip-all { border-style: dashed; }
.dark .ba-chip { background: #1e293b; border-color: #475569; color: #cbd5e1; }
.dark .ba-chip.on { background: rgb(122 167 247 / 0.16); border-color: #7aa7f7; color: #bfd4fb; }

.ba-seg { display: inline-flex; border: 1px solid #cbd5e1; border-radius: 8px; overflow: hidden; }
.ba-seg button { min-height: 36px; padding: 4px 12px; font-size: 13px; background: #fff; color: #334155; border-left: 1px solid #cbd5e1; }
.ba-seg button:first-child { border-left: none; }
.ba-seg button.on { background: var(--color-primary); color: #fff; font-weight: 600; }
.dark .ba-seg { border-color: #475569; }
.dark .ba-seg button { background: #1e293b; color: #cbd5e1; border-left-color: #475569; }
.dark .ba-seg button.on { background: var(--color-primary); color: #fff; }

.ba-chart { position: relative; height: 300px; }
.ba-chart.tall { height: 340px; }
.ba-table-wrap { overflow: auto; max-height: 440px; }
.ba-table { width: 100%; border-collapse: collapse; font-size: 13px; font-variant-numeric: tabular-nums; }
.ba-table th, .ba-table td { padding: 7px 10px; border-bottom: 1px solid #e2e8f0; text-align: right; white-space: nowrap; }
.ba-table th { position: sticky; top: 0; z-index: 1; background: #f1f5f9; color: #2563eb; font-size: 12px; font-weight: 600; }
.ba-table th.l, .ba-table td.l { text-align: left; }
.ba-table tfoot td { font-weight: 700; border-top: 2px solid #cbd5e1; }
.ba-table tbody tr:hover { background: rgb(37 99 235 / 0.04); }
.dark .ba-table th { background: #1e293b; color: #7aa7f7; }
.dark .ba-table th, .dark .ba-table td { border-bottom-color: #334155; }
.dark .ba-table tfoot td { border-top-color: #475569; }
.dark .ba-table tbody tr:hover { background: rgb(122 167 247 / 0.06); }

.ba-side { border-radius: 12px; padding: 14px 16px; border: 1px solid; }
.ba-side.before { background: #f5f9ff; border-color: #bfdbfe; }
.ba-side.after { background: #fffbeb; border-color: #fde68a; }
.dark .ba-side.before { background: rgb(37 99 235 / 0.10); border-color: rgb(96 165 250 / 0.35); }
.dark .ba-side.after { background: rgb(217 119 6 / 0.10); border-color: rgb(251 191 36 / 0.35); }
.ba-side dl { display: grid; grid-template-columns: auto 1fr; gap: 3px 12px; margin: 8px 0 0; font-size: 13px; }
.ba-side dd { margin: 0; text-align: right; font-weight: 600; font-variant-numeric: tabular-nums; }
.ba-up { color: #15803d; font-weight: 600; }
.ba-down { color: #b91c1c; font-weight: 600; }
.dark .ba-up { color: #6fdc9b; }
.dark .ba-down { color: #fca5a5; }

@media (max-width: 640px) {
    .ba-chart, .ba-chart.tall { height: 260px; }
    .ba-table-wrap { max-height: none; }
    .ba-table { font-size: 12px; }
    .ba-table th, .ba-table td { padding: 6px; }
    .ba-table .sticky1 { position: sticky; left: 0; background: inherit; }
    .ba-seg { display: flex; width: 100%; }
    .ba-seg button { flex: 1; padding: 4px 6px; }
}
