/* ===== Reset & Base ===== */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
    --bg: #f5f5f7;
    --bg-card: #ffffff;
    --bg-input: #f0f0f2;
    --text: #1a1a1a;
    --text-dim: #888888;
    --accent: #1a1a1a;
    --accent-light: #333333;
    --success: #2ecc71;
    --warning: #f39c12;
    --danger: #e74c3c;
    --info: #3498db;
    --border: #e0e0e0;
    --radius: 12px;
    --safe-top: env(safe-area-inset-top, 0px);
    --safe-bottom: env(safe-area-inset-bottom, 0px);
}

html, body {
    height: 100%;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background: var(--bg);
    color: var(--text);
    -webkit-font-smoothing: antialiased;
    -webkit-tap-highlight-color: transparent;
    overscroll-behavior-y: contain;
}

body { padding-top: var(--safe-top); padding-bottom: var(--safe-bottom); }

#app {
    height: 100vh;
    height: 100dvh;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

/* ===== Header ===== */
.header {
    position: sticky;
    top: 0;
    z-index: 100;
    background: #ffffff;
    padding: 12px 16px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    border-bottom: 1px solid var(--border);
    min-height: 52px;
}
.header-title { font-size: 1.1rem; font-weight: 700; }
.nav-tabs { display: flex; gap: 0; overflow-x: auto; scrollbar-width: none; flex: 1; -webkit-overflow-scrolling: touch; scroll-snap-type: x proximity; -webkit-mask-image: linear-gradient(to right, #000 0, #000 calc(100% - 18px), transparent 100%); mask-image: linear-gradient(to right, #000 0, #000 calc(100% - 18px), transparent 100%); }
.nav-tabs::-webkit-scrollbar { display: none; }
.nav-tab {
    padding: 6px 9px;
    font-size: 0.92rem;
    scroll-snap-align: start;
    font-weight: 700;
    color: var(--text-dim);
    text-decoration: none;
    border-bottom: 2px solid transparent;
    transition: all 0.2s;
    white-space: nowrap;
    flex-shrink: 0;
}
.nav-tab.active { color: var(--text); border-bottom-color: #1a1a1a; }

.header-btn {
    background: none;
    border: none;
    color: #1a1a1a;
    font-size: 1.15rem;
    padding: 6px 8px;
    cursor: pointer;
    line-height: 1;
    flex-shrink: 0;
}
.header-back { font-size: 1.2rem; }
.header-btn-icon { display: inline-flex; align-items: center; justify-content: center; padding: 6px 8px; }
.header-btn-icon svg { display: block; }
.header-btn-icon.is-busy svg { animation: spin 0.8s linear infinite; }
@keyframes spin { from { transform: rotate(0deg); } to { transform: rotate(360deg); } }

/* Scroll-to-hide header */
.header-autohide {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    z-index: 100;
    padding-top: calc(var(--safe-top) + 12px);
    transition: transform 0.3s ease, opacity 0.3s ease;
}
.sub-tabs-autohide {
    position: fixed;
    left: 0;
    right: 0;
    z-index: 99;
    transition: transform 0.3s ease, opacity 0.3s ease;
}
.filter-autohide {
    position: fixed;
    left: 0;
    right: 0;
    z-index: 98;
    background: var(--bg);
    transition: transform 0.3s ease, opacity 0.3s ease;
}
.header-hidden {
    transform: translateY(-100%);
    opacity: 0;
    pointer-events: none;
}
.sub-tabs-hidden {
    transform: translateY(-100%);
    opacity: 0;
    pointer-events: none;
}
.filter-hidden {
    transform: translateY(-200px);
    opacity: 0;
    pointer-events: none;
}

/* ===== Sub Tabs ===== */
.sub-tabs {
    display: flex;
    background: #fff;
    border-bottom: 1px solid var(--border);
    padding: 0 16px;
}
.sub-tab {
    padding: 8px 16px;
    font-size: 0.88rem;
    font-weight: 600;
    color: var(--text-dim);
    text-decoration: none;
    border-bottom: 2px solid transparent;
    transition: all 0.2s;
}
.sub-tab.active { color: var(--text); border-bottom-color: var(--accent); }

/* ===== Buttons ===== */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    padding: 10px 20px;
    border: none;
    border-radius: var(--radius);
    font-size: 0.95rem;
    font-weight: 600;
    cursor: pointer;
    transition: opacity 0.2s, transform 0.1s;
    -webkit-user-select: none;
}
.btn:active { transform: scale(0.97); }
.btn-primary { background: #1a1a1a; color: #fff; }
.btn-primary:disabled { opacity: 0.5; }
.btn-success { background: var(--success); color: #fff; }
.btn-danger { background: var(--danger); color: #fff; }
.btn-outline { background: transparent; border: 1px solid var(--border); color: var(--text); }
.btn-block { width: 100%; }
.btn-sm { padding: 6px 12px; font-size: 0.85rem; }

/* ===== Forms ===== */
.form-group { margin-bottom: 16px; }
.form-label { display: block; font-size: 0.85rem; color: var(--text-dim); margin-bottom: 6px; }
.form-input {
    width: 100%;
    padding: 12px 14px;
    background: var(--bg-input);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    color: var(--text);
    font-size: 1rem;
    outline: none;
    transition: border-color 0.2s;
}
.form-input:focus { border-color: var(--accent); }
.form-input::placeholder { color: var(--text-dim); }

/* ===== Login View ===== */
.login-view {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    padding: 24px;
}
.login-logo { font-size: 2rem; font-weight: 800; color: var(--accent); margin-bottom: 8px; }
.login-subtitle { color: var(--text-dim); margin-bottom: 32px; font-size: 0.9rem; }
.login-form { width: 100%; max-width: 360px; }
.remember-me {
    display: flex; align-items: center; gap: 8px; margin-top: 12px;
    font-size: 0.9rem; color: var(--text-dim); cursor: pointer;
}
.remember-me input[type="checkbox"] {
    width: 18px; height: 18px; accent-color: var(--accent); cursor: pointer;
}

/* ===== Overview View ===== */
.overview-view { flex: 1; display: flex; flex-direction: column; min-height: 0; }

/* ===== Store Cards ===== */
.store-card {
    display: block;
    background: var(--bg-input);
    border-radius: var(--radius);
    padding: 16px;
    margin-bottom: 10px;
    text-decoration: none;
    color: var(--text);
    border: 1px solid var(--border);
    transition: background 0.15s;
}
.store-card:active { background: #e8e8ea; }
.store-card-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 10px;
}
.store-card-name { font-weight: 700; font-size: 1rem; }
.store-card-arrow { color: var(--text-dim); font-size: 1.1rem; }
.store-card-stats { display: flex; gap: 16px; }
.store-card-stat { display: flex; flex-direction: column; }
.store-card-stat-label { font-size: 0.78rem; color: var(--text-dim); }
.store-card-stat-value { font-size: 0.95rem; font-weight: 700; }

/* ===== Source badge (on order cards) ===== */
.source-badge { display: inline-block; margin-left: 8px; padding: 1px 7px; font-size: 0.72rem; font-weight: 500; border-radius: 10px; vertical-align: 1px; }
.source-google-ads   { background: #fef3c7; color: #92400e; }
.source-facebook-ads { background: #dbeafe; color: #1e40af; }
.source-google-organic { background: #dcfce7; color: #166534; }
.source-facebook     { background: #e0e7ff; color: #3730a3; }
.source-instagram    { background: #fce7f3; color: #9d174d; }
.source-pinterest    { background: #fee2e2; color: #991b1b; }
.source-tiktok       { background: #ede9fe; color: #5b21b6; }
.source-direct       { background: var(--bg-input); color: var(--text-dim); }
.source-other        { background: var(--bg-input); color: var(--text-dim); }

/* ===== Order List ===== */
.order-list-view { flex: 1; display: flex; flex-direction: column; min-height: 0; }
.order-list { flex: 1; padding: 8px 12px; overflow-y: auto; -webkit-overflow-scrolling: touch; }

.order-card {
    background: var(--bg-card);
    border-radius: var(--radius);
    padding: 14px 16px;
    margin-bottom: 10px;
    cursor: pointer;
    transition: background 0.15s;
    border: 1px solid var(--border);
}
.order-card:active { background: var(--bg-input); }
.order-card-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 8px; }
.order-number { font-weight: 700; font-size: 1rem; }
.order-card-body { display: flex; justify-content: space-between; align-items: flex-end; }
.order-customer { color: var(--text-dim); font-size: 0.85rem; }
.order-date { color: var(--text-dim); font-size: 0.8rem; }
.order-total { font-weight: 700; font-size: 1.1rem; color: var(--accent-light); }

/* ===== Status Badge ===== */
.status-badge { display: inline-block; padding: 3px 10px; border-radius: 20px; font-size: 0.75rem; font-weight: 600; }
.status-pending { background: rgba(243,156,18,0.15); color: var(--warning); }
.status-processing { background: rgba(52,152,219,0.15); color: var(--info); }
.status-on-hold { background: rgba(243,156,18,0.15); color: var(--warning); }
.status-completed { background: rgba(46,204,113,0.15); color: var(--success); }
.status-cancelled { background: rgba(231,76,60,0.15); color: var(--danger); }
.status-refunded { background: rgba(231,76,60,0.15); color: var(--danger); }
.status-failed { background: rgba(231,76,60,0.15); color: var(--danger); }
.status-trash { background: rgba(136,136,160,0.15); color: var(--text-dim); }

/* ===== Filter Bar ===== */
.filter-bar { display: flex; gap: 8px; padding: 10px 12px; overflow-x: auto; -webkit-overflow-scrolling: touch; scrollbar-width: none; }
.filter-bar::-webkit-scrollbar { display: none; }
.filter-chip {
    flex-shrink: 0; padding: 6px 14px; border-radius: 20px;
    border: 1px solid var(--border); background: transparent;
    color: var(--text-dim); font-size: 0.82rem; cursor: pointer; white-space: nowrap; transition: all 0.2s;
}
.filter-chip.active { background: #1a1a1a; color: #fff; border-color: #1a1a1a; }

/* ===== Order Detail ===== */
.order-detail-view { flex: 1; display: flex; flex-direction: column; min-height: 0; }
.detail-scroll { flex: 1; overflow-y: auto; -webkit-overflow-scrolling: touch; padding: 16px; }

.detail-section {
    background: var(--bg-card);
    border-radius: var(--radius);
    padding: 16px;
    margin-bottom: 12px;
    border: 1px solid var(--border);
}
.detail-section-title { font-size: 0.8rem; color: var(--text-dim); text-transform: uppercase; letter-spacing: 0.5px; margin-bottom: 12px; }
.detail-row { display: flex; justify-content: space-between; align-items: center; padding: 6px 0; }
.detail-row + .detail-row { border-top: 1px solid var(--border); }
.detail-label { color: var(--text-dim); font-size: 0.9rem; }
.detail-value { font-weight: 600; font-size: 0.9rem; }

.line-item-with-img { display: flex; align-items: center; gap: 12px; padding: 10px 0; }
.line-item-with-img + .line-item-with-img { border-top: 1px solid var(--border); }
.line-item-thumb { width: 56px; height: 56px; border-radius: 8px; object-fit: cover; flex-shrink: 0; cursor: pointer; border: 1px solid var(--border); }
.line-item-thumb-empty { width: 56px; height: 56px; border-radius: 8px; background: var(--bg-input); flex-shrink: 0; }
.line-item-info { flex: 1; min-width: 0; }
.line-item-info .line-item-name { font-size: 0.88rem; line-height: 1.3; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.line-item-sku { color: var(--text-dim); font-size: 0.78rem; margin-top: 3px; }
.line-item-attrs { display: flex; flex-wrap: wrap; gap: 4px 8px; margin-top: 3px; }
.line-item-attr { font-size: 0.78rem; color: var(--accent); background: var(--bg-input); padding: 1px 6px; border-radius: 4px; }
.line-item-meta { color: var(--text-dim); font-size: 0.82rem; margin-top: 4px; }

.status-select {
    width: 100%; padding: 10px 14px; background: var(--bg-input);
    border: 1px solid var(--border); border-radius: var(--radius); color: var(--text);
    font-size: 0.95rem; outline: none; appearance: none; -webkit-appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' fill='%238888a0' viewBox='0 0 16 16'%3E%3Cpath d='M8 11L3 6h10z'/%3E%3C/svg%3E");
    background-repeat: no-repeat; background-position: right 12px center;
}
.address-block { font-size: 0.9rem; line-height: 1.6; color: var(--text); }

/* ===== Lightbox ===== */
.lightbox { position: fixed; inset: 0; z-index: 9999; background: #000; display: flex; align-items: center; justify-content: center; overflow: hidden; touch-action: none; animation: fadeIn 0.2s; }
.lightbox-img { max-width: 95vw; max-height: 90vh; object-fit: contain; border-radius: 8px; user-select: none; -webkit-user-drag: none; transform-origin: center center; will-change: transform; backface-visibility: hidden; }
.lightbox-img.animating { transition: transform 0.2s ease-out; }
.lightbox-close { position: fixed; top: calc(env(safe-area-inset-top, 0px) + 12px); right: 18px; color: #fff; font-size: 1.8rem; cursor: pointer; padding: 4px 10px; z-index: 1; }
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }

/* ===== Settings ===== */
.settings-view { flex: 1; display: flex; flex-direction: column; }
.settings-scroll { flex: 1; overflow-y: auto; padding: 16px; }
.settings-section { background: var(--bg-card); border-radius: var(--radius); padding: 16px; margin-bottom: 12px; border: 1px solid var(--border); }
.settings-row { display: flex; justify-content: space-between; align-items: center; padding: 8px 0; }
.settings-info { color: var(--text-dim); font-size: 0.85rem; margin-top: 8px; }

/* ===== Toast ===== */
#toast-container { position: fixed; top: calc(var(--safe-top) + 60px); left: 50%; transform: translateX(-50%); z-index: 9999; display: flex; flex-direction: column; gap: 8px; pointer-events: none; }
.toast { padding: 10px 20px; border-radius: var(--radius); font-size: 0.9rem; font-weight: 500; color: #fff; opacity: 0; transform: translateY(-10px); animation: toastIn 0.3s forwards, toastOut 0.3s 2.5s forwards; pointer-events: auto; text-align: center; max-width: 90vw; }
.toast-success { background: var(--success); }
.toast-error { background: var(--danger); }
.toast-info { background: var(--info); }
@keyframes toastIn { to { opacity: 1; transform: translateY(0); } }
@keyframes toastOut { to { opacity: 0; transform: translateY(-10px); } }

/* ===== Pull to Refresh ===== */
.ptr-indicator { text-align: center; padding: 8px; color: var(--text-dim); font-size: 0.85rem; transition: opacity 0.2s; }

/* ===== Loading / Empty ===== */
.loading-spinner { display: flex; align-items: center; justify-content: center; padding: 40px; color: var(--text-dim); }
.spinner { width: 24px; height: 24px; border: 3px solid var(--border); border-top-color: var(--accent); border-radius: 50%; animation: spin 0.8s linear infinite; margin-right: 10px; }
@keyframes spin { to { transform: rotate(360deg); } }
.load-more-btn { margin: 12px 0 20px; }
.empty-state { text-align: center; padding: 60px 24px; color: var(--text-dim); }
.empty-state-icon { font-size: 3rem; margin-bottom: 12px; }
.empty-state-text { font-size: 0.95rem; }

/* ===== Dashboard ===== */
.dashboard-view { flex: 1; display: flex; flex-direction: column; min-height: 0; }
.dashboard-scroll { flex: 1; overflow-y: auto; -webkit-overflow-scrolling: touch; padding: 12px; }

.dash-cards-row { display: flex; gap: 10px; margin-bottom: 12px; }
.dash-card { flex: 1; background: var(--bg-card); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px; text-align: center; }
.dash-card-label { font-size: 0.82rem; color: var(--text-dim); margin-bottom: 6px; }
.dash-card-value { font-size: 1.6rem; font-weight: 800; }
.dash-card-sub { font-size: 0.9rem; color: var(--text-dim); margin-top: 4px; }

.dash-period-tabs { display: flex; gap: 0; margin-bottom: 14px; border-radius: 8px; overflow: hidden; border: 1px solid var(--border); }
.period-tab, .rank-tab, .views-tab, .country-tab, .source-tab, .events-tab {
    flex: 1; padding: 8px 4px; border: none; background: var(--bg-input);
    color: var(--text-dim); font-size: 0.85rem; font-weight: 500; cursor: pointer; transition: all 0.2s;
    white-space: nowrap; min-width: 0;
}
.period-tab + .period-tab, .rank-tab + .rank-tab, .views-tab + .views-tab, .country-tab + .country-tab, .source-tab + .source-tab, .events-tab + .events-tab { border-left: 1px solid var(--border); }
.period-tab.active, .rank-tab.active, .views-tab.active, .country-tab.active, .source-tab.active, .events-tab.active { background: #1a1a1a; color: #fff; }

/* Live visitors (online now) */
.live-section .detail-section-title { display:flex; align-items:center; gap:8px; }
.live-dot { display:inline-block; width:8px; height:8px; border-radius:50%; background:#0B8A4E; animation:lv-blink 1.4s infinite; flex:0 0 auto; }
@keyframes lv-blink { 0%,100%{opacity:1} 50%{opacity:.3} }
.live-count { background:#0B8A4E; color:#fff; padding:1px 8px; border-radius:9999px; font-size:0.78rem; font-weight:700; }
.lv-mute-btn { margin-left:auto; background:transparent; border:1px solid var(--border); color:var(--text-dim); padding:3px 10px; border-radius:9999px; font-size:0.72rem; cursor:pointer; transition:all .15s; }
.lv-mute-btn:hover { border-color:var(--text); color:var(--text); }
.lv-mute-btn.muted { background:#0B8A4E; color:#fff; border-color:#0B8A4E; }
.lv-mute-btn:disabled { opacity:.5; cursor:wait; }
/* Two-column visitor card: text on left, product thumbnail on right */
.lv-visitor { display:flex; gap:10px; align-items:center; background: var(--bg-input); border-radius: 10px; padding: 8px 10px; margin-bottom: 6px; }
.lv-left { flex: 1; min-width: 0; }
.lv-right { flex: 0 0 auto; }
.lv-head { display:flex; flex-wrap:wrap; align-items:center; gap:5px; font-size:0.78rem; color:var(--text-dim); margin-bottom:3px; line-height:1.3; }
.lv-head strong { color: var(--text); font-weight: 700; }
.lv-head > span { display: inline; }
.lv-flag { font-size:1rem; }
.lv-ref { color: var(--text-dim); font-size: 0.74rem; padding: 1px 6px; background: var(--bg); border-radius: 9999px; }
.lv-last { margin-left:auto; color: var(--text-dim); font-size:0.72rem; }
.lv-sep { opacity: 0.4; }
.lv-current { font-size:0.82rem; color:var(--text); line-height:1.3; display:-webkit-box; -webkit-line-clamp:2; -webkit-box-orient:vertical; overflow:hidden; }
.lv-current a { color: #FF3D6E; text-decoration: none; }
.lv-current a:hover { text-decoration: underline; }
/* Product thumbnail (right column) */
.lv-thumb { position:relative; display:block; width:54px; height:54px; border-radius:8px; overflow:hidden; background: var(--bg); flex-shrink: 0; }
.lv-thumb img { width:100%; height:100%; object-fit:cover; display:block; }
.lv-thumb-blank { width:100%; height:100%; display:flex; align-items:center; justify-content:center; font-size:1.4rem; }
.lv-thumb-more { position:absolute; bottom:2px; right:2px; background:rgba(0,0,0,0.78); color:#fff; font-size:0.65rem; font-weight:700; padding:1px 5px; border-radius:9999px; }
.lv-thumb-empty { width:54px; height:54px; border-radius:8px; background: var(--bg); display:flex; align-items:center; justify-content:center; color:var(--text-dim); font-size:0.82rem; opacity:0.4; }

/* Marketing events feed */
.event-summary { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 10px; }
.event-chip { display: inline-flex; align-items: center; gap: 4px; padding: 4px 10px; background: var(--bg-input); border-radius: 9999px; font-size: 0.78rem; color: var(--text-dim); }
.event-chip strong { color: var(--text); font-weight: 700; }
.event-chip-total { background: #1a1a1a; color: #fff; }
.event-chip-total strong { color: #fff; }
.event-list { display: flex; flex-direction: column; gap: 8px; padding: 4px 2px; }
.event-row { display: flex; gap: 10px; padding: 10px 12px; background: var(--bg-input); border-radius: 10px; align-items: center; }
.event-icon { font-size: 1.2rem; flex: 0 0 auto; width: 28px; text-align: center; }
.event-body { flex: 1; min-width: 0; }
.event-headline { font-size: 0.9rem; font-weight: 600; color: var(--text); }
.event-headline .event-who { font-weight: 500; color: var(--text-dim); font-size: 0.85rem; }
.event-meta { font-size: 0.78rem; color: var(--text-dim); margin-top: 2px; }
.event-amt { color: #0B8A4E; font-weight: 700; }
.event-meta a { color: #FF3D6E; text-decoration: none; }

.device-icon { font-size: 0.85em; margin-left: 4px; opacity: 0.85; }

.trend-wrap { width: 100%; height: 180px; position: relative; }
.trend-wrap canvas { width: 100%; height: 100%; display: block; }
.trend-legend { display: flex; gap: 16px; font-size: 0.78rem; color: var(--text-dim); margin: -4px 0 8px; }
.trend-legend .dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; margin-right: 5px; vertical-align: middle; }

.dash-stats-grid { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 10px; }
.dash-stat { background: var(--bg-input); border-radius: 8px; padding: 12px; text-align: center; }
.dash-stat-label { font-size: 0.78rem; color: var(--text-dim); margin-bottom: 4px; }
.dash-stat-value { font-size: 1rem; font-weight: 700; }

/* Attribution panel */
.attr-list { display: flex; flex-direction: column; gap: 12px; }
.attr-row { padding: 10px 12px; background: var(--bg-input); border-radius: 8px; }
.attr-row-head { display: flex; justify-content: space-between; align-items: center; font-size: 0.85rem; margin-bottom: 6px; }
.attr-src { display: flex; align-items: center; font-weight: 600; }
.attr-src .dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; margin-right: 6px; }
.attr-pct { color: var(--text-dim); font-size: 0.78rem; font-weight: 500; }
.attr-bar { height: 4px; background: rgba(0,0,0,0.06); border-radius: 2px; overflow: hidden; margin-bottom: 6px; }
.attr-bar-fill { height: 100%; transition: width 0.3s; }
.attr-row-stats { display: flex; gap: 12px; font-size: 0.78rem; color: var(--text-dim); }
.attr-row-stats span { flex: 1; text-align: center; }

/* Clickable cards/stats — visual affordance so users see "I can tap this" */
.dash-card.clickable, .dash-stat.clickable {
  cursor: pointer;
  position: relative;
  transition: transform 0.15s ease, box-shadow 0.15s ease, background 0.15s ease, border-color 0.15s ease;
}
/* Always-on chevron in top-right corner */
.dash-card.clickable::after, .dash-stat.clickable::after {
  content: '›';
  position: absolute;
  top: 6px;
  right: 12px;
  color: var(--text-dim);
  font-size: 1.15rem;
  line-height: 1;
  opacity: 0.45;
  transition: opacity 0.15s ease, transform 0.15s ease, color 0.15s ease;
  pointer-events: none;
}
.dash-card.clickable:hover, .dash-stat.clickable:hover {
  background: #fafafb;
  border-color: #d8d8dc;
  transform: translateY(-1px);
  box-shadow: 0 3px 10px rgba(0,0,0,0.06);
}
.dash-card.clickable:hover::after, .dash-stat.clickable:hover::after {
  opacity: 1;
  color: var(--accent, #3498db);
  transform: translateX(2px);
}
.dash-card.clickable:active, .dash-stat.clickable:active {
  transform: translateY(0);
  background: #e8e8ea;
  box-shadow: none;
}

/* Compact inline stat (used inside store cards on overview) */
.store-card-stat.clickable {
  cursor: pointer;
  border-radius: 6px;
  padding: 4px 6px;
  margin: -4px -6px;
  position: relative;
  transition: background 0.15s ease;
}
.store-card-stat.clickable::after {
  content: '›';
  margin-left: 4px;
  color: var(--text-dim);
  opacity: 0.5;
  font-size: 0.95rem;
}
.store-card-stat.clickable:hover { background: #f3f3f5; }
.store-card-stat.clickable:hover::after { opacity: 1; color: var(--accent, #3498db); }
.store-card-stat.clickable:active { background: #d5d5d9; }

/* Bottom sheet */
.sheet-overlay { position: fixed; inset: 0; background: rgba(0,0,0,0.4); z-index: 10000; display: flex; align-items: flex-end; animation: fadeIn 0.15s; }
.sheet { width: 100%; background: var(--bg-card); border-radius: 16px 16px 0 0; padding: 12px 0; max-height: 70vh; overflow-y: auto; animation: slideUp 0.2s; }
.sheet-title { padding: 8px 20px 12px; font-size: 0.88rem; color: var(--text-dim); font-weight: 500; text-align: center; border-bottom: 1px solid var(--border); }
.sheet-item { display: flex; justify-content: space-between; align-items: center; padding: 14px 20px; font-size: 1rem; color: var(--text); text-decoration: none; border-bottom: 1px solid var(--border); }
.sheet-item:active { background: var(--bg-input); }
.sheet-item-sub { font-size: 0.85rem; color: var(--text-dim); }
.sheet-cancel { padding: 14px; text-align: center; color: var(--text-dim); font-size: 0.95rem; cursor: pointer; }
@keyframes fadeIn { from { opacity: 0 } to { opacity: 1 } }
@keyframes slideUp { from { transform: translateY(100%) } to { transform: translateY(0) } }

.top-seller-item { display: flex; align-items: center; gap: 10px; padding: 10px 0; }
.top-seller-item + .top-seller-item { border-top: 1px solid var(--border); }
.top-seller-rank { width: 24px; height: 24px; border-radius: 6px; background: var(--bg-input); display: flex; align-items: center; justify-content: center; font-size: 0.8rem; font-weight: 700; flex-shrink: 0; }
.top-seller-item:nth-child(1) .top-seller-rank { background: #ffd700; color: #000; }
.top-seller-item:nth-child(2) .top-seller-rank { background: #c0c0c0; color: #000; }
.top-seller-item:nth-child(3) .top-seller-rank { background: #cd7f32; color: #fff; }
.top-seller-img { width: 48px; height: 48px; border-radius: 8px; object-fit: cover; flex-shrink: 0; cursor: pointer; border: 1px solid var(--border); }
.top-seller-img-empty { width: 48px; height: 48px; border-radius: 8px; background: var(--bg-input); flex-shrink: 0; }
.top-seller-info { flex: 1; min-width: 0; }
.top-seller-name { font-size: 0.88rem; line-height: 1.3; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.top-seller-qty { font-size: 0.8rem; color: var(--text-dim); margin-top: 2px; }

/* ===== Traffic Analysis ===== */
.traffic-list { padding: 0 2px; }
.traffic-item { display: flex; align-items: center; gap: 8px; padding: 9px 0; }
.traffic-item + .traffic-item { border-top: 1px solid var(--border); }
.traffic-rank { width: 22px; height: 22px; border-radius: 6px; background: var(--bg-input); display: flex; align-items: center; justify-content: center; font-size: 0.75rem; font-weight: 700; flex-shrink: 0; }
.traffic-item:nth-child(1) .traffic-rank { background: #ffd700; color: #000; }
.traffic-item:nth-child(2) .traffic-rank { background: #c0c0c0; color: #000; }
.traffic-item:nth-child(3) .traffic-rank { background: #cd7f32; color: #fff; }
.traffic-flag { font-size: 1.2rem; flex-shrink: 0; width: 28px; text-align: center; }
.traffic-info { flex: 1; min-width: 0; }
.traffic-name { font-size: 0.85rem; font-weight: 500; line-height: 1.3; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.traffic-bar-wrap { height: 4px; background: var(--bg-input); border-radius: 2px; margin-top: 4px; overflow: hidden; }
.traffic-bar { height: 100%; background: var(--info); border-radius: 2px; transition: width 0.3s ease; }
.traffic-bar.source-bar { background: var(--success); }
.traffic-stats { flex-shrink: 0; text-align: right; min-width: 65px; }
.traffic-views { font-size: 0.85rem; font-weight: 600; }
.traffic-pct { font-size: 0.75rem; color: var(--text-dim); margin-left: 4px; }

/* ===== Last Updated ===== */
.last-updated {
    text-align: right;
    font-size: 0.78rem;
    color: var(--text-dim);
    padding: 8px 4px 0;
}

/* ===== Misc ===== */
.divider { height: 1px; background: var(--border); margin: 12px 0; }
.text-center { text-align: center; }
.mt-8 { margin-top: 8px; }
.mt-16 { margin-top: 16px; }
.mb-16 { margin-bottom: 16px; }
::-webkit-scrollbar { width: 0; background: transparent; }

/* Back to top button */
#btn-to-top {
    position: fixed;
    bottom: 24px;
    right: 16px;
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background: var(--text);
    color: #fff;
    font-size: 18px;
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0;
    pointer-events: none;
    transform: translateY(20px);
    transition: opacity 0.25s, transform 0.25s;
    z-index: 200;
    box-shadow: 0 2px 8px rgba(0,0,0,0.2);
    -webkit-tap-highlight-color: transparent;
    cursor: pointer;
}
#btn-to-top.visible {
    opacity: 0.7;
    pointer-events: auto;
    transform: translateY(0);
}
#btn-to-top:active { opacity: 1; transform: scale(0.9); }

/* Chat badge on overview header */
.chat-nav-badge {
    position: absolute; top: -2px; right: -2px;
    background: #e74c3c; color: #fff; font-size: 10px; font-weight: 700;
    min-width: 16px; height: 16px; border-radius: 8px;
    display: flex; align-items: center; justify-content: center;
    padding: 0 3px; line-height: 1;
}

/* ─── Live Chat Admin ──────────────────────────── */
.chat-container {
    position: fixed; top: 0; left: 0; right: 0; bottom: 0;
    overflow: hidden;
}
.chat-layout {
    display: flex; height: 100%;
    padding-top: 52px; /* header height */
}
.chat-sidebar {
    width: 280px; min-width: 280px; border-right: 1px solid var(--border);
    background: var(--card-bg); display: flex; flex-direction: column;
    overflow: hidden;
}
.chat-sidebar-header {
    padding: 12px 14px; border-bottom: 1px solid var(--border);
    display: flex; justify-content: space-between; align-items: center;
    font-size: 14px; font-weight: 600;
}
.chat-filter-select {
    border: 1px solid var(--border); border-radius: 6px;
    padding: 4px 8px; font-size: 12px; background: var(--bg); color: var(--text);
}
.chat-session-list { flex: 1; overflow-y: auto; }
.chat-session-item {
    padding: 12px 14px; border-bottom: 1px solid var(--border);
    cursor: pointer; transition: background 0.15s;
}
.chat-session-item:hover, .chat-session-item:active { background: var(--hover); }
.chat-session-item.active { background: var(--hover); border-left: 3px solid var(--accent); }
.chat-session-top { display: flex; justify-content: space-between; align-items: center; }
.chat-session-name { font-size: 13px; font-weight: 600; display: flex; align-items: center; gap: 6px; }
.chat-dot { width: 8px; height: 8px; border-radius: 50%; display: inline-block; }
.chat-dot.online { background: #4caf50; }
.chat-dot.offline { background: #ccc; }
.chat-unread {
    background: #e74c3c; color: #fff; font-size: 10px; font-weight: 700;
    min-width: 18px; height: 18px; border-radius: 9px;
    display: flex; align-items: center; justify-content: center; padding: 0 4px;
}
.chat-session-meta { font-size: 11px; color: var(--text-dim); margin-top: 3px; }
.chat-session-time { font-size: 10px; color: var(--text-dim); margin-top: 2px; }
.chat-no-sessions { padding: 24px; text-align: center; color: var(--text-dim); font-size: 13px; }

.chat-main {
    flex: 1; display: flex; flex-direction: column;
    background: var(--bg); min-width: 0;
}
.chat-empty-state {
    flex: 1; display: flex; flex-direction: column;
    align-items: center; justify-content: center; color: var(--text-dim);
}
.chat-empty-icon { font-size: 48px; margin-bottom: 12px; }
.chat-empty-state p { font-size: 14px; }

.chat-header {
    padding: 10px 16px; border-bottom: 1px solid var(--border);
    background: var(--card-bg); display: flex; justify-content: space-between; align-items: center;
}
.chat-header-name { font-size: 14px; font-weight: 600; }
.chat-header-details { font-size: 11px; color: var(--text-dim); margin-top: 2px; }
.chat-header-actions { display: flex; gap: 8px; }
.chat-btn-track, .chat-btn-close-session {
    border: 1px solid var(--border); border-radius: 8px; padding: 6px 10px;
    font-size: 12px; background: var(--card-bg); color: var(--text);
    cursor: pointer; transition: background 0.15s;
}
.chat-btn-track:hover, .chat-btn-close-session:hover { background: var(--hover); }

.chat-messages {
    flex: 1; overflow-y: auto; padding: 16px;
    display: flex; flex-direction: column; gap: 10px;
}
.chat-msg {
    max-width: 75%; padding: 10px 14px; border-radius: 14px;
    font-size: 13px; line-height: 1.5; word-break: break-word;
}
.chat-msg.customer {
    align-self: flex-start; background: var(--card-bg);
    border: 1px solid var(--border); border-bottom-left-radius: 4px;
}
.chat-msg.admin {
    align-self: flex-end; background: #2c5282; color: #fff;
    border-bottom-right-radius: 4px;
}
.chat-msg.admin.tracking { background: #276749; }
.chat-msg-sender { font-size: 10px; font-weight: 600; margin-bottom: 4px; opacity: 0.7; }
.chat-msg-time { font-size: 10px; opacity: 0.5; margin-top: 4px; }
.chat-msg a { color: inherit; text-decoration: underline; }

.chat-reply-area {
    padding: 12px 16px; border-top: 1px solid var(--border);
    background: var(--card-bg); display: flex; gap: 8px;
}
.chat-reply-area input {
    flex: 1; border: 1px solid var(--border); border-radius: 20px;
    padding: 10px 16px; font-size: 13px; background: var(--bg);
    color: var(--text); outline: none;
}
.chat-reply-area input:focus { border-color: var(--accent); }
.chat-reply-area button {
    background: var(--accent); color: #fff; border: none; border-radius: 20px;
    padding: 10px 20px; font-size: 13px; font-weight: 600; cursor: pointer;
    transition: opacity 0.15s;
}
.chat-reply-area button:hover { opacity: 0.85; }

.chat-back-btn {
    display: none; background: none; border: none;
    font-size: 15px; font-weight: 500;
    color: var(--accent); cursor: pointer;
    padding: 10px 14px; margin-right: 4px;
    min-width: 60px; min-height: 44px;
    align-items: center; justify-content: center;
    -webkit-tap-highlight-color: rgba(0,0,0,0.1);
    user-select: none; white-space: nowrap;
}

/* Mobile: sidebar becomes full width, toggle with session click */
@media (max-width: 600px) {
    .chat-layout { flex-direction: column; }
    .chat-sidebar { width: 100%; min-width: 100%; }
    .chat-sidebar.hidden { display: none; }
    .chat-main { display: none; position: fixed; top: 52px; left: 0; right: 0; bottom: 0; z-index: 100; background: var(--bg); }
    .chat-main.visible { display: flex; }
    .chat-back-btn { display: flex; }
}
