/* ============================================================
   QUỸ ĂN CHƠI - Premium Design System
   Inspired by the original Next.js app with Tailwind v4
   ============================================================ */

/* --- CSS Custom Properties / Theme Tokens --- */
:root {
    /* Fonts */
    --font-sans: 'Be Vietnam Pro', system-ui, -apple-system, sans-serif;
    --font-mono: 'Geist Mono', 'SF Mono', ui-monospace, monospace;
    
    /* Core Colors */
    --background: #ffffff;
    --foreground: #0f172a;
    --card: #ffffff;
    --card-foreground: #0f172a;
    --popover: #ffffff;
    --popover-foreground: #0f172a;
    --primary: #10b981;
    --primary-foreground: #ffffff;
    --secondary: #f1f5f9;
    --secondary-foreground: #1e293b;
    --muted: #f1f5f9;
    --muted-foreground: #64748b;
    --accent: #f1f5f9;
    --accent-foreground: #1e293b;
    --destructive: #ef4444;
    --border: #e2e8f0;
    --input: #e2e8f0;
    --ring: #94a3b8;
    
    /* Radius */
    --radius: 12px;
    
    /* Slate colors */
    --color-slate-50: #f8fafc;
    --color-slate-100: #f1f5f9;
    --color-slate-200: #e2e8f0;
    --color-slate-300: #cbd5e1;
    --color-slate-400: #94a3b8;
    --color-slate-500: #64748b;
    --color-slate-600: #475569;
    --color-slate-700: #334155;
    --color-slate-800: #1e293b;
    --color-slate-900: #0f172a;
    --color-slate-950: #020617;
}

/* Dark mode */
@media (prefers-color-scheme: dark) {
    :root {
        --background: #020617;
        --foreground: #f1f5f9;
        --card: #0f172a;
        --card-foreground: #f1f5f9;
        --popover: #0f172a;
        --popover-foreground: #f1f5f9;
        --primary: #34d399;
        --primary-foreground: #020617;
        --secondary: #1e293b;
        --secondary-foreground: #f1f5f9;
        --muted: #1e293b;
        --muted-foreground: #94a3b8;
        --accent: #1e293b;
        --accent-foreground: #f1f5f9;
        --border: #1e293b;
        --input: #1e293b;
        --ring: #334155;
        --destructive: #f87171;
    }
}

[data-theme="dark"] {
    --background: #020617;
    --foreground: #f1f5f9;
    --card: #0f172a;
    --card-foreground: #f1f5f9;
    --popover: #0f172a;
    --popover-foreground: #f1f5f9;
    --primary: #34d399;
    --primary-foreground: #020617;
    --secondary: #1e293b;
    --secondary-foreground: #f1f5f9;
    --muted: #1e293b;
    --muted-foreground: #94a3b8;
    --accent: #1e293b;
    --accent-foreground: #f1f5f9;
    --border: #1e293b;
    --input: #1e293b;
    --ring: #334155;
    --destructive: #f87171;
}

/* Theme color schemes */
.theme-emerald {
    --theme-from: linear-gradient(135deg, rgba(52,211,153,0.9), rgba(45,212,191,0.7));
    --theme-blob1: rgba(6,150,103,0.5);
    --theme-blob2: rgba(14,165,233,0.5);
    --theme-hex: #10b981;
}
.theme-blue {
    --theme-from: linear-gradient(135deg, rgba(96,165,250,0.9), rgba(34,211,238,0.7));
    --theme-blob1: rgba(37,99,235,0.5);
    --theme-blob2: rgba(6,182,212,0.5);
    --theme-hex: #3b82f6;
}
.theme-purple {
    --theme-from: linear-gradient(135deg, rgba(192,132,252,0.9), rgba(217,70,239,0.7));
    --theme-blob1: rgba(147,51,234,0.5);
    --theme-blob2: rgba(168,85,247,0.5);
    --theme-hex: #8b5cf6;
}
.theme-rose {
    --theme-from: linear-gradient(135deg, rgba(251,113,133,0.9), rgba(244,114,182,0.7));
    --theme-blob1: rgba(225,29,72,0.5);
    --theme-blob2: rgba(236,72,153,0.5);
    --theme-hex: #f43f5e;
}
.theme-orange {
    --theme-from: linear-gradient(135deg, rgba(251,146,60,0.9), rgba(251,191,36,0.7));
    --theme-blob1: rgba(234,88,12,0.5);
    --theme-blob2: rgba(245,158,11,0.5);
    --theme-hex: #f97316;
}
.theme-indigo {
    --theme-from: linear-gradient(135deg, rgba(129,140,248,0.9), rgba(196,181,253,0.7));
    --theme-blob1: rgba(79,70,229,0.5);
    --theme-blob2: rgba(139,92,246,0.5);
    --theme-hex: #6366f1;
}
.theme-slate {
    --theme-from: linear-gradient(135deg, rgba(100,116,139,0.9), rgba(148,163,184,0.7));
    --theme-blob1: rgba(51,65,85,0.5);
    --theme-blob2: rgba(75,85,99,0.5);
    --theme-hex: #64748b;
}
.theme-red {
    --theme-from: linear-gradient(135deg, rgba(248,113,113,0.9), rgba(251,146,60,0.7));
    --theme-blob1: rgba(220,38,38,0.5);
    --theme-blob2: rgba(249,115,22,0.5);
    --theme-hex: #ef4444;
}
.theme-amber {
    --theme-from: linear-gradient(135deg, rgba(251,191,36,0.9), rgba(253,224,71,0.7));
    --theme-blob1: rgba(217,119,6,0.5);
    --theme-blob2: rgba(234,179,8,0.5);
    --theme-hex: #f59e0b;
}
.theme-lime {
    --theme-from: linear-gradient(135deg, rgba(163,230,53,0.9), rgba(74,222,128,0.7));
    --theme-blob1: rgba(101,163,13,0.5);
    --theme-blob2: rgba(34,197,94,0.5);
    --theme-hex: #84cc16;
}

/* ============================================================
   RESET & BASE
   ============================================================ */
*, *::before, *::after {
    box-sizing: border-box;
    border: 0 solid;
    margin: 0;
    padding: 0;
}

html {
    -webkit-text-size-adjust: 100%;
    tab-size: 4;
    line-height: 1.5;
    font-family: var(--font-sans);
    -webkit-tap-highlight-color: transparent;
}

body {
    background-color: var(--background);
    color: var(--foreground);
    min-height: 100%;
}

img, video {
    max-width: 100%;
    height: auto;
    display: block;
}

button {
    cursor: pointer;
    font: inherit;
    letter-spacing: inherit;
    color: inherit;
    background: transparent;
}

a { color: inherit; text-decoration: inherit; }

/* ============================================================
   UTILITY CLASSES
   ============================================================ */
.hidden { display: none !important; }
.flex { display: flex; }
.flex-col { flex-direction: column; }
.items-center { align-items: center; }
.justify-center { justify-content: center; }
.text-center { text-align: center; }

.animate-spin {
    animation: spin 1s linear infinite;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

@keyframes fadeIn {
    from { opacity: 0; transform: translateY(8px); }
    to { opacity: 1; transform: translateY(0); }
}

@keyframes slideInFromTop {
    from { opacity: 0; transform: translateY(-8px); }
    to { opacity: 1; transform: translateY(0); }
}

@keyframes scaleIn {
    from { opacity: 0; transform: scale(0.95); }
    to { opacity: 1; transform: scale(1); }
}

@keyframes pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.5; }
}

.animate-in {
    animation: fadeIn 0.15s ease-out;
}

.fade-in-0 { opacity: 0; }
.fade-in-to-1 { opacity: 1; }
.slide-in-from-top-2 { animation: slideInFromTop 0.15s ease-out; }
.zoom-in-95 { animation: scaleIn 0.15s ease-out; }

/* Toggle Checkbox Styling */
.toggle-checkbox {
    appearance: none;
    width: 36px;
    height: 20px;
    background: var(--color-slate-300);
    border-radius: 9999px;
    position: relative;
    cursor: pointer;
    transition: background 0.2s;
    flex-shrink: 0;
}

.toggle-checkbox::after {
    content: '';
    position: absolute;
    top: 2px;
    left: 2px;
    width: 16px;
    height: 16px;
    background: white;
    border-radius: 50%;
    transition: transform 0.2s;
    box-shadow: 0 1px 3px rgba(0,0,0,0.2);
}

.toggle-checkbox:checked {
    background: var(--primary);
}

.toggle-checkbox:checked::after {
    transform: translateX(16px);
}

/* Scrollbar */
::-webkit-scrollbar {
    width: 6px;
}

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

::-webkit-scrollbar-thumb {
    background: var(--color-slate-300);
    border-radius: 3px;
}

/* Loading spinner */
.loading-spinner {
    animation: spin 1s linear infinite;
    border-radius: 9999px;
    border: 2px solid transparent;
    border-bottom-color: var(--primary);
    width: 32px;
    height: 32px;
}

/* ============================================================
   COMPONENT STYLES
   ============================================================ */

/* --- Header Background Blobs --- */
.blob-layer {
    position: absolute;
    inset: 0;
    z-index: 0;
    pointer-events: none;
    overflow: hidden;
    transition: all 1s;
}

.blob-gradient {
    position: absolute;
    top: -10%;
    left: -20%;
    width: 140%;
    height: 350px;
    border-radius: 0 0 100% 100%;
    transition: all 1s;
}

.blob-circle-1 {
    position: absolute;
    top: -50px;
    right: -10%;
    width: 250px;
    height: 250px;
    border-radius: 9999px;
    filter: blur(64px);
    transition: all 1s;
}

.blob-circle-2 {
    position: absolute;
    top: 50px;
    left: -10%;
    width: 200px;
    height: 200px;
    border-radius: 9999px;
    filter: blur(64px);
    transition: all 1s;
}

/* --- Member Card --- */
.member-card {
    display: flex;
    align-items: center;
    background: var(--card);
    border: 1px solid var(--color-slate-100);
    border-radius: 16px;
    padding: 16px;
    box-shadow: 0 1px 2px rgba(0,0,0,0.04);
    transition: box-shadow 0.2s, border-color 0.2s;
}

@media (prefers-color-scheme: dark) {
    .member-card {
        border-color: var(--color-slate-800);
    }
}

.member-card.deficit {
    cursor: pointer;
}

.member-card.deficit:hover {
    border-color: #fca5a5;
}

.member-card.deleted {
    opacity: 0.8;
    filter: grayscale(1);
}

.member-avatar {
    width: 48px;
    height: 48px;
    border-radius: 9999px;
    display: flex;
    align-items: center;
    justify-content: center;
    color: white;
    font-weight: 700;
    font-size: 1.125rem;
    flex-shrink: 0;
    margin-right: 16px;
}

.member-info {
    flex: 1;
    min-width: 0;
}

.member-name {
    font-weight: 700;
    font-size: 1rem;
    margin-bottom: 4px;
    color: var(--color-slate-800);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

@media (prefers-color-scheme: dark) {
    .member-name { color: var(--color-slate-200); }
}

.member-stats {
    font-size: 11px;
    color: var(--color-slate-500);
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.member-stats span {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.member-balance {
    text-align: right;
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    justify-content: center;
    margin-left: 8px;
    flex-shrink: 0;
}

.balance-badge {
    font-size: 10px;
    font-weight: 600;
    padding: 2px 8px;
    border-radius: 4px;
    margin-bottom: 4px;
    display: inline-block;
}

.badge-positive {
    background: var(--color-green-50, #ecfdf5);
    color: var(--color-green-600, #059669);
}

.badge-negative {
    background: #fef2f2;
    color: #dc2626;
}

.badge-neutral {
    background: var(--color-slate-50);
    color: var(--color-slate-500);
}

.balance-amount {
    font-weight: 700;
    font-size: 0.875rem;
}

.balance-amount.positive { color: #059669; }
.balance-amount.negative { color: #dc2626; display: flex; align-items: center; gap: 2px; }
.balance-amount.neutral { color: var(--color-slate-500); }

/* Compact member card */
.members-compact .member-card {
    padding: 6px 8px;
}

.members-compact .member-avatar {
    width: 28px;
    height: 28px;
    font-size: 11px;
    margin-right: 6px;
}

@media (min-width: 365px) {
    .members-compact .member-avatar {
        display: flex;
    }
}

.members-compact .member-name {
    font-size: 0.875rem;
    margin-bottom: 2px;
}

.members-compact .member-stats {
    display: none;
}

.members-compact .balance-badge {
    display: none;
}

.members-compact .balance-amount {
    font-size: 0.75rem;
}

/* --- Transaction History --- */
.history-item {
    position: relative;
}

/* Timeline style */
.history-timeline-dot {
    position: absolute;
    left: -28px;
    margin-top: 4px;
    width: 16px;
    height: 16px;
    border-radius: 9999px;
    border: 2px solid white;
    z-index: 1;
}

@media (prefers-color-scheme: dark) {
    .history-timeline-dot {
        border-color: var(--color-slate-950);
    }
}

.history-timeline-dot.income { background: #22c55e; }
.history-timeline-dot.expense { background: #ef4444; }

.history-card {
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 12px;
    box-shadow: 0 1px 2px rgba(0,0,0,0.04);
}

.history-card-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    margin-bottom: 4px;
}

.history-card-title {
    font-weight: 500;
    font-size: 0.875rem;
}

.history-card-amount {
    font-weight: 700;
    font-size: 0.875rem;
    flex-shrink: 0;
}

.history-card-amount.income { color: #16a34a; }
.history-card-amount.expense { color: #dc2626; }

.history-card-note {
    font-size: 0.75rem;
    color: var(--muted-foreground);
    margin-bottom: 8px;
    display: flex;
    align-items: center;
    gap: 4px;
}

.history-card-date {
    font-size: 10px;
    color: var(--muted-foreground);
    font-family: var(--font-mono);
}

/* Compact history style */
.history-compact-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 8px 4px;
    border-bottom: 1px solid var(--border);
}

.history-compact-item:last-child {
    border-bottom: none;
}

.history-compact-info {
    flex: 1;
    min-width: 0;
    padding-right: 8px;
}

.history-compact-title {
    font-size: 0.75rem;
    font-weight: 500;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.history-compact-meta {
    font-size: 10px;
    color: var(--muted-foreground);
}

.history-compact-amount {
    font-size: 0.75rem;
    font-weight: 700;
    white-space: nowrap;
    flex-shrink: 0;
}

.history-compact-amount.income { color: #16a34a; }
.history-compact-amount.expense { color: #dc2626; }

/* ============================================================
   RESPONSIVE ADJUSTMENTS
   ============================================================ */
@media (max-width: 400px) {
    .member-card { padding: 12px; }
    .member-avatar { width: 40px; height: 40px; font-size: 1rem; margin-right: 12px; }
    .member-name { font-size: 0.875rem; }
    .balance-amount { font-size: 0.8125rem; }
}
