/**
 * P99 Mobile App - Modern Design System CSS
 * Blue/Yellow theme, mobile-first, supports dark mode
 * Optimized for Android WebView performance
 */

/* =============================================
   CSS VARIABLES
   ============================================= */
:root {
    --blue: #0033CC;
    --blue-dark: #001F8C;
    --blue-light: #1a4fd6;
    --blue-bg: #EEF2FF;
    --yellow: #FFD700;
    --yellow-hover: #FFC400;
    --gold: #FFCC00;
    --white: #ffffff;
    --bg: #F0F4FF;
    --card: #ffffff;
    --text: #1a1a2e;
    --text-sec: #6B7280;
    --text-muted: #9CA3AF;
    --border: #E5E7EB;
    --green: #10b981;
    --green-bg: #D1FAE5;
    --red: #ef4444;
    --red-bg: #FEE2E2;
    --orange: #f59e0b;
    --purple: #8b5cf6;
    --shadow-sm: 0 1px 3px rgba(0,0,0,0.04);
    --shadow-md: 0 4px 12px rgba(0,0,0,0.06);
    --shadow-lg: 0 8px 24px rgba(0,0,0,0.08);
    --shadow-blue: 0 4px 20px rgba(0,51,204,0.08);
    --radius-sm: 8px;
    --radius-md: 12px;
    --radius-lg: 16px;
    --radius-xl: 20px;
    --radius-full: 9999px;
    --safe-top: env(safe-area-inset-top, 0px);
    --safe-bottom: env(safe-area-inset-bottom, 0px);
    --nav-h: 64px;
    --header-h: auto;
    --transition: 0.2s cubic-bezier(0.4, 0, 0.2, 1);
}

/* Dark Mode */
html.dark-mode {
    --bg: #0f172a;
    --card: #1e293b;
    --text: #f1f5f9;
    --text-sec: #94a3b8;
    --text-muted: #64748b;
    --border: #334155;
    --blue-bg: #1e3a5f;
    --green-bg: #064e3b;
    --red-bg: #7f1d1d;
    --shadow-sm: 0 1px 3px rgba(0,0,0,0.2);
    --shadow-md: 0 4px 12px rgba(0,0,0,0.3);
    --shadow-lg: 0 8px 24px rgba(0,0,0,0.4);
    --shadow-blue: 0 4px 20px rgba(0,0,0,0.3);
}

/* =============================================
   RESET & BASE
   ============================================= */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    -webkit-tap-highlight-color: transparent;
}

html, body {
    height: 100%;
    -webkit-text-size-adjust: 100%;
    text-size-adjust: 100%;
}

body {
    font-family: 'Kantumruy Pro', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background: var(--bg);
    color: var(--text);
    min-height: 100vh;
    min-height: 100dvh;
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    overflow-x: hidden;
    padding-bottom: calc(var(--nav-h) + var(--safe-bottom) + 8px);
}

/* Smooth scrolling */
html {
    scroll-behavior: smooth;
}

/* =============================================
   TYPOGRAPHY
   ============================================= */
.text-xs { font-size: 11px; }
.text-sm { font-size: 13px; }
.text-base { font-size: 15px; }
.text-lg { font-size: 17px; }
.text-xl { font-size: 20px; }
.text-2xl { font-size: 24px; }
.text-3xl { font-size: 28px; }

.font-medium { font-weight: 500; }
.font-semibold { font-weight: 600; }
.font-bold { font-weight: 700; }
.font-extrabold { font-weight: 800; }

.text-center { text-align: center; }
.text-right { text-align: right; }
.text-muted { color: var(--text-sec); }

/* =============================================
   APP HEADER
   ============================================= */
.app-header {
    background: linear-gradient(135deg, var(--blue) 0%, var(--blue-light) 100%);
    padding: calc(var(--safe-top) + 12px) 20px 32px;
    color: var(--white);
    position: relative;
    z-index: 10;
}

html.dark-mode .app-header {
    background: linear-gradient(135deg, #001a66 0%, #002db3 100%);
}

.app-header::after {
    content: '';
    position: absolute;
    bottom: -1px;
    left: -10%;
    width: 120%;
    height: 28px;
    background: var(--bg);
    border-radius: 50% 50% 0 0;
}

.app-header-bar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
}

.app-header-left {
    display: flex;
    align-items: center;
    gap: 12px;
}

.app-header-title {
    font-size: 18px;
    font-weight: 700;
    color: var(--white);
}

.app-back-btn {
    width: 38px;
    height: 38px;
    border-radius: var(--radius-md);
    background: rgba(255,255,255,0.12);
    border: none;
    color: var(--white);
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    text-decoration: none;
    transition: background var(--transition);
}

.app-back-btn:active {
    background: rgba(255,255,255,0.22);
}

.app-back-btn svg {
    width: 20px;
    height: 20px;
}

/* =============================================
   CARDS
   ============================================= */
.app-card {
    background: var(--card);
    border-radius: var(--radius-xl);
    padding: 20px;
    box-shadow: var(--shadow-blue);
    position: relative;
    z-index: 2;
}

.app-card-sm {
    padding: 14px 16px;
    border-radius: var(--radius-lg);
}

.app-card-hover {
    transition: transform var(--transition), box-shadow var(--transition);
}

.app-card-hover:active {
    transform: scale(0.98);
}

/* =============================================
   BALANCE BANNER
   ============================================= */
.balance-banner {
    background: var(--card);
    border-radius: var(--radius-xl);
    padding: 24px;
    margin: -10px 16px 20px;
    position: relative;
    z-index: 5;
    box-shadow: var(--shadow-blue);
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.bal-block { display: block; }
.bal-label {
    font-size: 11px;
    color: var(--text-sec);
    font-weight: 500;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.bal-amount {
    font-size: 24px;
    font-weight: 800;
}

.bal-amount.khm { color: var(--blue); }
.bal-amount.usd { color: var(--green); }

/* =============================================
   BUTTONS
   ============================================= */
.app-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 12px 24px;
    border-radius: var(--radius-md);
    font-size: 15px;
    font-weight: 700;
    font-family: inherit;
    cursor: pointer;
    border: none;
    transition: all var(--transition);
    -webkit-user-select: none;
    user-select: none;
    text-decoration: none;
    outline: none;
    position: relative;
    overflow: hidden;
}

.app-btn-primary {
    background: var(--yellow);
    color: #1a1a2e;
    box-shadow: 0 4px 16px rgba(255, 215, 0, 0.3);
}

.app-btn-primary:active {
    transform: translateY(1px);
    box-shadow: 0 2px 8px rgba(255, 215, 0, 0.3);
}

.app-btn-blue {
    background: var(--blue);
    color: var(--white);
    box-shadow: 0 4px 16px rgba(0, 51, 204, 0.2);
}

.app-btn-blue:active {
    background: var(--blue-dark);
}

.app-btn-outline {
    background: transparent;
    border: 2px solid var(--border);
    color: var(--text);
}

.app-btn-outline:active {
    background: var(--bg);
}

.app-btn-sm {
    padding: 8px 16px;
    font-size: 13px;
    border-radius: var(--radius-sm);
}

.app-btn-full {
    width: 100%;
}

.app-btn svg {
    width: 20px;
    height: 20px;
    flex-shrink: 0;
}

/* =============================================
   BOTTOM NAVIGATION
   ============================================= */
.bottom-nav {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    height: calc(var(--nav-h) + var(--safe-bottom));
    background: var(--card);
    border-top: 1px solid var(--border);
    display: flex;
    align-items: flex-start;
    padding-top: 8px;
    padding-bottom: var(--safe-bottom);
    z-index: 100;
    box-shadow: 0 -4px 20px rgba(0,0,0,0.05);
}

html.dark-mode .bottom-nav {
    box-shadow: 0 -4px 20px rgba(0,0,0,0.2);
}

.nav-item {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 3px;
    text-decoration: none;
    color: var(--text-sec);
    font-size: 10px;
    font-weight: 600;
    padding: 4px 0;
    transition: color var(--transition);
}

.nav-item.active {
    color: var(--blue);
}

.nav-item svg {
    width: 24px;
    height: 24px;
    transition: transform var(--transition);
}

.nav-item:active svg {
    transform: scale(0.9);
}

/* =============================================
   FILTER CHIPS
   ============================================= */
.filter-bar {
    display: flex;
    gap: 6px;
    padding: 0 16px;
    overflow-x: auto;
    scrollbar-width: none;
    -webkit-overflow-scrolling: touch;
}

.filter-bar::-webkit-scrollbar { display: none; }

.filter-chip {
    padding: 7px 16px;
    border-radius: var(--radius-full);
    border: 1px solid var(--border);
    background: var(--card);
    font-size: 12px;
    font-weight: 600;
    color: var(--text-sec);
    cursor: pointer;
    white-space: nowrap;
    transition: all var(--transition);
    font-family: inherit;
}

.filter-chip.active {
    background: var(--blue);
    color: var(--white);
    border-color: var(--blue);
}

.filter-chip:active {
    transform: scale(0.95);
}

/* =============================================
   STATUS BADGES
   ============================================= */
.badge {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 3px 10px;
    border-radius: var(--radius-full);
    font-size: 11px;
    font-weight: 600;
}

.badge-pending { background: #FEF3C7; color: #D97706; }
.badge-won { background: var(--green-bg); color: #059669; }
.badge-lost { background: var(--red-bg); color: #DC2626; }
.badge-deleted { background: #F3F4F6; color: #6B7280; }

/* =============================================
   EMPTY STATE
   ============================================= */
.empty-state {
    text-align: center;
    padding: 48px 24px;
    color: var(--text-sec);
}

.empty-state svg {
    width: 56px;
    height: 56px;
    opacity: 0.25;
    margin-bottom: 16px;
}

.empty-state p {
    font-size: 14px;
    font-weight: 500;
}

/* =============================================
   TOAST NOTIFICATION
   ============================================= */
.app-toast {
    position: fixed;
    bottom: calc(var(--nav-h) + var(--safe-bottom) + 16px);
    left: 50%;
    transform: translateX(-50%) translateY(100px);
    background: var(--text);
    color: var(--white);
    padding: 12px 24px;
    border-radius: var(--radius-full);
    font-size: 13px;
    font-weight: 600;
    z-index: 200;
    opacity: 0;
    transition: all 0.3s ease;
    white-space: nowrap;
    box-shadow: var(--shadow-lg);
}

.app-toast.show {
    transform: translateX(-50%) translateY(0);
    opacity: 1;
}

.app-toast.success { background: var(--green); }
.app-toast.error { background: var(--red); }
.app-toast.warning { background: var(--orange); }

/* =============================================
   LOADING SPINNER
   ============================================= */
.app-spinner {
    width: 24px;
    height: 24px;
    border: 3px solid var(--border);
    border-top-color: var(--blue);
    border-radius: 50%;
    animation: app-spin 0.7s linear infinite;
}

@keyframes app-spin {
    to { transform: rotate(360deg); }
}

.app-spinner-sm {
    width: 16px;
    height: 16px;
    border-width: 2px;
}

/* =============================================
   PULL TO REFRESH INDICATOR
   ============================================= */
.pull-indicator {
    position: fixed;
    top: 0;
    left: 50%;
    transform: translateX(-50%) translateY(-48px);
    width: 36px;
    height: 36px;
    border-radius: 50%;
    background: var(--card);
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: var(--shadow-md);
    z-index: 50;
    transition: transform 0.3s ease;
}

.pull-indicator.visible {
    transform: translateX(-50%) translateY(calc(var(--safe-top) + 8px));
}

/* =============================================
   ANIMATIONS
   ============================================= */
@keyframes fadeIn {
    from { opacity: 0; transform: translateY(8px); }
    to { opacity: 1; transform: translateY(0); }
}

@keyframes slideUp {
    from { transform: translateY(100%); }
    to { transform: translateY(0); }
}

@keyframes slideDown {
    from { transform: translateY(-100%); }
    to { transform: translateY(0); }
}

@keyframes scaleIn {
    from { opacity: 0; transform: scale(0.9); }
    to { opacity: 1; transform: scale(1); }
}

.animate-fade-in {
    animation: fadeIn 0.3s ease forwards;
}

.animate-slide-up {
    animation: slideUp 0.3s ease forwards;
}

/* =============================================
   RESPONSIVE
   ============================================= */
@media (min-width: 768px) {
    body {
        max-width: 480px;
        margin: 0 auto;
        box-shadow: -1px 0 0 var(--border), 1px 0 0 var(--border);
    }
    .bottom-nav {
        max-width: 480px;
        left: 50%;
        transform: translateX(-50%);
    }
}

/* =============================================
   UTILITIES
   ============================================= */
.flex { display: flex; }
.flex-col { flex-direction: column; }
.items-center { align-items: center; }
.justify-between { justify-content: space-between; }
.gap-2 { gap: 8px; }
.gap-3 { gap: 12px; }
.gap-4 { gap: 16px; }
.p-4 { padding: 16px; }
.px-4 { padding-left: 16px; padding-right: 16px; }
.py-2 { padding-top: 8px; padding-bottom: 8px; }
.mt-4 { margin-top: 16px; }
.mb-4 { margin-bottom: 16px; }
.w-full { width: 100%; }
.truncate { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.hidden { display: none !important; }
