:root {
    --bg-app: #f2f2f7;
    --card-bg: #ffffff;
    --primary-dark: #0f172a;
    --accent-blue: #007aff;
    --accent-orange: #f59e0b;
    --accent-green: #10b981;
    --danger-red: #ef4444;
    --text-primary: #0f172a;
    --text-secondary: #64748b;
    --text-muted: #94a3b8;
    --border-light: #e2e8f0;
}

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

html, body {
    height: 100%;
    width: 100%;
    overflow: hidden;
    font-family: -apple-system, BlinkMacSystemFont, "SF Pro Display", "Segoe UI", Roboto, sans-serif;
    background-color: var(--bg-app);
    color: var(--text-primary);
    -webkit-font-smoothing: antialiased;
}

/* --- MÀN HÌNH ĐĂNG NHẬP --- */
#loginScreen {
    height: 100%;
    display: flex;
    justify-content: center;
    align-items: center;
    padding: 20px;
    background: #0f172a;
}
.login-box {
    width: 100%;
    max-width: 320px;
    background: #ffffff;
    padding: 26px 20px;
    border-radius: 20px;
    text-align: center;
    box-shadow: 0 10px 30px rgba(0,0,0,0.2);
}
.login-box h2 { font-size: 19px; font-weight: 900; color: #0f172a; }
.login-box p { font-size: 12.5px; color: var(--text-secondary); margin: 4px 0 18px; }
.login-box input {
    width: 100%;
    padding: 12px 14px;
    margin-bottom: 10px;
    border: 1px solid var(--border-light);
    border-radius: 12px;
    font-size: 14px;
    background: #f8fafc;
    outline: none;
}
.login-box button {
    width: 100%;
    padding: 12px;
    background: #0f172a;
    color: #fff;
    border: none;
    border-radius: 12px;
    font-size: 14px;
    font-weight: 700;
    cursor: pointer;
}

/* --- TOÀN BỘ KHUNG GIAO DIỆN --- */
.app-screen {
    height: 100%;
    display: flex;
    flex-direction: column;
}

header {
    background-color: #ffffff;
    padding: 0 16px;
    height: 48px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-bottom: 1px solid var(--border-light);
    flex-shrink: 0;
}
.header-brand { display: flex; align-items: center; gap: 8px; }
.header-brand h2 { font-size: 16px; font-weight: 800; color: #0f172a; }
.live-dot {
    width: 8px;
    height: 8px;
    background-color: var(--accent-green);
    border-radius: 50%;
    box-shadow: 0 0 0 2px rgba(16, 185, 129, 0.25);
}
.header-actions { display: flex; align-items: center; gap: 14px; }
.header-btn { background: transparent; border: none; font-size: 16px; color: var(--accent-blue); cursor: pointer; }
.header-btn.btn-danger { color: var(--danger-red); }

/* MAIN CONTAINER (PADDING 16PX) */
.dashboard-container {
    flex: 1;
    padding: 14px 16px;
    display: flex;
    flex-direction: column;
    gap: 12px;
    min-height: 0;
}

/* BASE CARD STYLE */
.unit-card {
    border-radius: 20px;
    padding: 12px 14px;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
}

/* =======================================================
   1. KHỐI TRÊN: HERO UNIT (TỔNG TIỀN Ở CHÍNH GIỮA)
   ======================================================= */
.unit-hero {
    flex: 0.95;
    background: linear-gradient(145deg, #0b1329 0%, #1e293b 100%);
    color: #ffffff;
    box-shadow: 0 8px 24px rgba(15, 23, 42, 0.22);
    min-height: 0;
    text-align: center;
}

.hero-top-bar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    width: 100%;
}
.hero-live-tag {
    font-size: 10px;
    font-weight: 800;
    color: var(--accent-green);
    letter-spacing: 0.6px;
    display: flex;
    align-items: center;
    gap: 5px;
}
.dot-blink { width: 6px; height: 6px; background-color: var(--accent-green); border-radius: 50%; display: inline-block; }

.pill-btn {
    background: rgba(255, 255, 255, 0.12);
    border: 1px solid rgba(255, 255, 255, 0.18);
    color: #ffffff;
    padding: 4px 10px;
    border-radius: 20px;
    font-size: 11px;
    font-weight: 700;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 5px;
}
.pill-btn:active { background: rgba(255, 255, 255, 0.25); }
.text-orange { color: #fb923c; }
.text-blue { color: #38bdf8; }

.hero-center-revenue {
    margin: 2px 0;
    display: flex;
    flex-direction: column;
    align-items: center;
}
.center-label {
    font-size: 9.5px;
    font-weight: 800;
    letter-spacing: 0.8px;
    opacity: 0.75;
    text-transform: uppercase;
}
.hero-center-revenue h1 {
    font-size: 34px;
    font-weight: 900;
    line-height: 1.05;
    letter-spacing: -0.5px;
    margin: 2px 0;
    color: #ffffff;
}
.hero-meta-badges {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
}
.meta-badge {
    background: rgba(255, 255, 255, 0.12);
    padding: 2px 8px;
    border-radius: 6px;
    font-size: 10.5px;
    font-weight: 600;
}
.meta-badge.badge-cancel {
    background: rgba(239, 68, 68, 0.35);
    color: #fca5a5;
    font-weight: 800;
}

.hero-bottom-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 10px;
    text-align: left;
}
.sub-box {
    background: rgba(255, 255, 255, 0.08);
    border: 1px solid rgba(255, 255, 255, 0.12);
    border-radius: 12px;
    padding: 7px 10px;
    cursor: pointer;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
}
.sub-box:active { background: rgba(255, 255, 255, 0.16); }
.sub-title {
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-size: 10.5px;
    font-weight: 700;
}
.icon-mini { font-size: 9px; opacity: 0.6; }
.sub-lief .sub-title span { color: #fbbf24; }
.sub-abh .sub-title span { color: #34d399; }
.sub-val { font-size: 14.5px; font-weight: 900; margin: 1px 0; }
.sub-meta { font-size: 10px; opacity: 0.75; font-weight: 600; }

/* =======================================================
   2A. KHỐI DƯỚI: CHẾ ĐỘ MINI ADMIN (LIVE ORDERS FEED)
   ======================================================= */
.unit-admin-feed {
    flex: 1.25;
    background: #ffffff;
    border: 1px solid var(--border-light);
    box-shadow: 0 4px 16px rgba(0,0,0,0.03);
    min-height: 0;
    display: flex;
    flex-direction: column;
    padding: 12px 12px 8px;
    gap: 8px;
}

.feed-header-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-shrink: 0;
}
.feed-title {
    font-size: 12.5px;
    font-weight: 800;
    color: var(--primary-dark);
    display: flex;
    align-items: center;
    gap: 6px;
}
.feed-filter-chips {
    display: flex;
    gap: 4px;
}
.chip-btn {
    background: #f1f5f9;
    border: 1px solid var(--border-light);
    border-radius: 14px;
    padding: 3px 8px;
    font-size: 10.5px;
    font-weight: 700;
    color: var(--text-secondary);
    cursor: pointer;
}
.chip-btn.active {
    background: var(--primary-dark);
    color: #ffffff;
    border-color: var(--primary-dark);
}

.feed-orders-scroll {
    flex: 1;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    display: flex;
    flex-direction: column;
    gap: 6px;
    min-height: 0;
}
.feed-orders-scroll::-webkit-scrollbar { width: 3px; }
.feed-orders-scroll::-webkit-scrollbar-thumb { background: #cbd5e1; border-radius: 3px; }

/* Item inside feed */
.feed-order-card {
    background: #f8fafc;
    border: 1px solid var(--border-light);
    border-radius: 12px;
    padding: 8px 10px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    cursor: pointer;
    transition: transform 0.1s, background-color 0.1s;
}
.feed-order-card:active { transform: scale(0.98); background: #f1f5f9; }

.feed-order-left b { font-size: 13px; color: var(--primary-dark); }
.feed-order-left span { font-size: 11px; color: var(--text-secondary); }
.feed-order-price { font-size: 14px; font-weight: 800; color: #16a34a; }

/* =======================================================
   2B. KHỐI DƯỚI: CHẾ ĐỘ ANALYTICS (TÀI CHÍNH)
   ======================================================= */
.unit-analytics {
    flex: 1.25;
    background: #ffffff;
    border: 1px solid var(--border-light);
    box-shadow: 0 4px 16px rgba(0,0,0,0.03);
    min-height: 0;
}

.filter-segmented-bar {
    background: #e2e8f0;
    padding: 3px;
    border-radius: 10px;
    display: flex;
    gap: 3px;
}
.filter-pill {
    flex: 1;
    border: none;
    background: transparent;
    padding: 5px 0;
    font-size: 11.5px;
    font-weight: 700;
    color: var(--text-secondary);
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.2s ease;
}
.filter-pill.active {
    background: #ffffff;
    color: var(--primary-dark);
    box-shadow: 0 1px 3px rgba(0,0,0,0.1);
}

.analytics-metrics-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 10px;
    margin: 4px 0;
}
.metric-block {
    background: #f8fafc;
    border: 1px solid var(--border-light);
    border-radius: 12px;
    padding: 8px 10px;
}
.metric-title {
    font-size: 9px;
    font-weight: 800;
    color: var(--text-muted);
    letter-spacing: 0.3px;
    display: block;
    margin-bottom: 2px;
}
.metric-num { font-size: 15px; font-weight: 900; }
.text-dark { color: var(--primary-dark); }
.text-blue { color: #0284c7; }

.distribution-card {
    background: #f8fafc;
    border: 1px solid var(--border-light);
    border-radius: 12px;
    padding: 8px 10px;
    display: flex;
    flex-direction: column;
    gap: 5px;
}
.dist-header {
    display: flex;
    justify-content: space-between;
    font-size: 10px;
    font-weight: 800;
    color: var(--text-secondary);
}
.dist-tag { color: var(--accent-blue); }

.dist-bar-track {
    width: 100%;
    height: 10px;
    background: #e2e8f0;
    border-radius: 5px;
    display: flex;
    overflow: hidden;
}
.dist-bar { height: 100%; transition: width 0.35s ease; }
.bar-lief { background: var(--accent-orange); }
.bar-abh { background: var(--accent-green); }

.dist-legend {
    display: flex;
    justify-content: space-between;
    font-size: 11px;
    font-weight: 700;
}
.legend-item { display: flex; align-items: center; gap: 4px; }
.legend-dot { width: 7px; height: 7px; border-radius: 50%; display: inline-block; }
.dot-orange { background: var(--accent-orange); }
.dot-green { background: var(--accent-green); }
.legend-item small { font-weight: 600; color: var(--text-secondary); font-size: 10px; }

.btn-history-view {
    width: 100%;
    padding: 9px 12px;
    background: #f1f5f9;
    border: 1px solid var(--border-light);
    border-radius: 12px;
    font-size: 11.5px;
    font-weight: 700;
    color: var(--primary-dark);
    display: flex;
    justify-content: space-between;
    align-items: center;
    cursor: pointer;
}
.btn-history-view:active { background: #e2e8f0; }

/* =======================================================
   3. POPUP DIALOGS CHÍNH GIỮA (CENTER MODAL)
   ======================================================= */
.modal-overlay {
    position: fixed;
    top: 0; left: 0; width: 100%; height: 100%;
    background: rgba(0, 0, 0, 0.55);
    backdrop-filter: blur(6px);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 9999;
    padding: 16px;
}

.modal-dialog {
    background: var(--bg-app);
    width: 100%;
    max-width: 380px;
    max-height: 82vh;
    border-radius: 22px;
    box-shadow: 0 20px 40px rgba(0,0,0,0.3);
    display: flex;
    flex-direction: column;
    animation: popCenter 0.18s cubic-bezier(0.175, 0.885, 0.32, 1.275);
    overflow: hidden;
}

@keyframes popCenter {
    from { transform: scale(0.85); opacity: 0; }
    to { transform: scale(1); opacity: 1; }
}

.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 14px 18px;
    background: #ffffff;
    border-bottom: 1px solid var(--border-light);
    flex-shrink: 0;
}
.modal-header h3 { font-size: 15px; font-weight: 800; color: #0f172a; }
.btn-close {
    background: #f1f5f9;
    border: none;
    width: 28px;
    height: 28px;
    border-radius: 50%;
    font-size: 13px;
    color: var(--text-secondary);
    cursor: pointer;
}
.modal-body { padding: 14px; overflow-y: auto; }

.top-item-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 10px 12px;
    background: #fff;
    border-radius: 12px;
    margin-bottom: 6px;
    border: 1px solid var(--border-light);
    font-size: 13px;
}
.rank-badge {
    width: 20px; height: 20px;
    border-radius: 6px;
    background: #e2e8f0;
    font-weight: 800;
    font-size: 10.5px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    margin-right: 8px;
}

.summary-order-item {
    background: #fff;
    padding: 10px 12px;
    border-radius: 12px;
    margin-bottom: 6px;
    border: 1px solid var(--border-light);
    display: flex;
    justify-content: space-between;
    align-items: center;
    cursor: pointer;
}
.summary-item-left b { font-size: 13px; color: var(--primary-dark); }
.summary-item-left { font-size: 11.5px; color: var(--text-secondary); }
.summary-item-price { font-size: 14px; font-weight: 800; color: #16a34a; }

.badge-type {
    display: inline-block;
    padding: 1px 5px;
    border-radius: 4px;
    font-size: 9.5px;
    font-weight: 700;
    margin-top: 2px;
}
.badge-abholen { background: #e8f5e9; color: #2e7d32; }
.badge-lieferung { background: #fff3e0; color: #e65100; }

/* --- SETTINGS STYLES & SWITCH --- */
.settings-body {
    display: flex;
    flex-direction: column;
    gap: 12px;
}
.setting-row {
    background: #fff;
    padding: 12px 14px;
    border-radius: 14px;
    border: 1px solid var(--border-light);
    display: flex;
    justify-content: space-between;
    align-items: center;
}
.setting-row b { font-size: 13px; color: var(--primary-dark); display: block; }
.setting-row p { font-size: 11px; color: var(--text-secondary); margin-top: 2px; }

.settings-select {
    padding: 6px 10px;
    border-radius: 10px;
    border: 1px solid var(--border-light);
    background: #f8fafc;
    font-size: 13px;
    font-weight: 700;
    color: var(--primary-dark);
    outline: none;
}

.switch {
    position: relative;
    display: inline-block;
    width: 44px;
    height: 26px;
    flex-shrink: 0;
}
.switch input { opacity: 0; width: 0; height: 0; }
.slider {
    position: absolute; cursor: pointer; top: 0; left: 0; right: 0; bottom: 0;
    background-color: #cbd5e1;
    transition: .3s;
    border-radius: 26px;
}
.slider:before {
    position: absolute; content: ""; height: 20px; width: 20px; left: 3px; bottom: 3px;
    background-color: white;
    transition: .3s;
    border-radius: 50%;
    box-shadow: 0 1px 3px rgba(0,0,0,0.2);
}
input:checked + .slider { background-color: var(--accent-green); }
input:checked + .slider:before { transform: translateX(18px); }

/* =======================================================
   TỰ ĐỘNG THÍCH ỨNG DARK MODE THEO HỆ ĐIỀU HÀNH
   ======================================================= */
@media (prefers-color-scheme: dark) {
    :root {
        --bg-app: #000000;
        --card-bg: #1c1c1e;
        --primary-dark: #f8fafc;
        --text-primary: #f8fafc;
        --text-secondary: #a1a1aa;
        --text-muted: #71717a;
        --border-light: #27272a;
    }

    /* Header & Các Card chính */
    header, 
    .unit-admin-feed, 
    .unit-analytics, 
    .modal-dialog, 
    .modal-header,
    .login-box {
        background-color: #18181b !important;
        border-color: #27272a !important;
    }

    /* Header Text */
    .header-brand h2, 
    .modal-header h3, 
    .login-box h2 {
        color: #ffffff !important;
    }

    /* Thẻ con bên trong (Đơn hàng, Top món, Cài đặt) */
    .feed-order-card, 
    .metric-block, 
    .distribution-card, 
    .top-item-row, 
    .summary-order-item, 
    .setting-row,
    .login-box input,
    .settings-select {
        background-color: #27272a !important;
        border-color: #3f3f46 !important;
        color: #f8fafc !important;
    }

    .feed-order-left b,
    .summary-item-left b,
    .setting-row b {
        color: #ffffff !important;
    }

    /* Thanh Segmented Bar & Nút Lọc */
    .filter-segmented-bar, 
    .btn-history-view,
    .chip-btn,
    .rank-badge,
    .btn-close {
        background-color: #27272a !important;
        border-color: #3f3f46 !important;
        color: #a1a1aa !important;
    }

    .filter-pill.active {
        background-color: #3f3f46 !important;
        color: #ffffff !important;
    }

    .chip-btn.active {
        background-color: var(--accent-blue) !important;
        border-color: var(--accent-blue) !important;
        color: #ffffff !important;
    }

    .dist-bar-track {
        background-color: #3f3f46 !important;
    }
}