/* ===== 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 {
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

/* ===== Typography ===== */
h1 { font-size: 1.5rem; font-weight: 700; }
h2 { font-size: 1.2rem; font-weight: 600; }
h3 { font-size: 1rem; font-weight: 600; }

/* ===== 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; }
.nav-tab {
    padding: 6px 16px;
    font-size: 1rem;
    font-weight: 700;
    color: var(--text-dim);
    text-decoration: none;
    border-bottom: 2px solid transparent;
    transition: all 0.2s;
}
.nav-tab.active { color: var(--text); border-bottom-color: #1a1a1a; }

.header-btn {
    background: none;
    border: none;
    color: #1a1a1a;
    font-size: 1.4rem;
    padding: 4px 8px;
    cursor: pointer;
    line-height: 1;
}
.header-back { font-size: 1.2rem; }

/* ===== 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; }

/* ===== Order List ===== */
.order-list-view { flex: 1; display: flex; flex-direction: column; }
.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;
    text-transform: capitalize;
}
.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; }
.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 {
    display: flex;
    justify-content: space-between;
    padding: 8px 0;
}
.line-item + .line-item { border-top: 1px solid var(--border); }
.line-item-name { flex: 1; font-size: 0.9rem; }
.line-item-qty { color: var(--text-dim); font-size: 0.85rem; margin: 0 12px; }
.line-item-total { font-weight: 600; font-size: 0.9rem; white-space: nowrap; }

.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-meta {
    color: var(--text-dim);
    font-size: 0.82rem;
    margin-top: 4px;
}

/* ===== Lightbox ===== */
.lightbox {
    position: fixed;
    inset: 0;
    z-index: 9999;
    background: rgba(0,0,0,0.92);
    display: flex;
    align-items: center;
    justify-content: center;
    animation: fadeIn 0.2s;
}
.lightbox-wrap { position: relative; max-width: 95vw; max-height: 90vh; }
.lightbox-img {
    max-width: 95vw;
    max-height: 90vh;
    object-fit: contain;
    border-radius: 8px;
}
.lightbox-close {
    position: absolute;
    top: -36px;
    right: 0;
    color: #fff;
    font-size: 1.5rem;
    cursor: pointer;
    padding: 4px 8px;
}
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }

.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);
}

/* ===== 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; }
.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 {
    flex: 1;
    padding: 8px 0;
    border: none;
    background: var(--bg-input);
    color: var(--text-dim);
    font-size: 0.85rem;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s;
}
.period-tab + .period-tab, .rank-tab + .rank-tab { border-left: 1px solid var(--border); }
.period-tab.active, .rank-tab.active { background: #1a1a1a; color: #fff; }

.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; }

.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; }

/* ===== 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; }

/* ===== Scrollbar ===== */
::-webkit-scrollbar { width: 0; background: transparent; }
