/* ============================================
   XPENS PWA — Styles
   Mobile-first, modern CSS with variables
   Lighter Red with Apple Dark Grey Theme
   ============================================ */

/* CSS Variables */
:root {
    /* Brand Colors (overridable via settings) */
    --primary: #EF4444;
    --primary-dark: #DC2626;
    --primary-light: #FEF2F2;
    --secondary: #1e3a5f;
    --secondary-dark: #162d4a;
    --secondary-light: #e8f0fe;
    --accent: #ca8a04;
    --accent-dark: #a16207;
    --accent-light: #fef08a;

    --success: #10B981;
    --warning: #FBBF24;
    --danger: #DC2626;
    --info: #3B82F6;

    /* Apple Grey Tones */
    --slate-50: #F5F5F7;
    --slate-100: #E8E8ED;
    --slate-200: #D2D2D7;
    --slate-300: #AEAEB2;
    --slate-400: #8E8E93;
    --slate-500: #636366;
    --slate-600: #48484A;
    --slate-700: #3A3A3C;
    --slate-800: #2C2C2E;
    --slate-900: #1D1D1F;

    --bg: #FFFFFF;
    --bg-secondary: var(--slate-50);
    --text: var(--slate-800);
    --text-secondary: var(--slate-500);
    --border: var(--slate-200);

    --radius: 16px;
    --radius-sm: 8px;
    --radius-lg: 24px;

    --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.05);
    --shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06);
    --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.1), 0 4px 6px -2px rgba(0, 0, 0, 0.05);

    --header-height: 56px;
    --nav-height: 64px;
    --safe-bottom: env(safe-area-inset-bottom, 0px);
}

/* Dark Mode */
.dark {
    --bg: var(--slate-900);
    --bg-secondary: var(--slate-800);
    --text: var(--slate-100);
    --text-secondary: var(--slate-400);
    --border: var(--slate-700);
    --primary-light: color-mix(in srgb, var(--primary) 20%, transparent);
    --secondary-light: color-mix(in srgb, var(--secondary) 20%, transparent);
    --accent-light: color-mix(in srgb, var(--accent) 20%, transparent);
}

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

/* Base */
html {
    font-size: 16px;
    -webkit-text-size-adjust: 100%;
}

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
    background: var(--bg);
    color: var(--text);
    line-height: 1.5;
    overflow-x: hidden;
    min-height: 100vh;
    min-height: 100dvh;
}

/* Splash Screen */
.splash-screen {
    position: fixed;
    inset: 0;
    background: linear-gradient(135deg, var(--primary) 0%, var(--primary-dark) 100%);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 9999;
    transition: opacity 0.5s ease;
}

.splash-screen.fade-out {
    opacity: 0;
    pointer-events: none;
}

.splash-content {
    text-align: center;
}

.splash-icon {
    width: 80px;
    height: 80px;
    background: rgba(255, 255, 255, 0.2);
    border-radius: 24px;
    display: flex;
    align-items: center;
    justify-content: center;
    margin: 0 auto 16px;
}

.splash-icon i {
    font-size: 40px;
    color: white;
}

.splash-title {
    font-size: 28px;
    font-weight: 800;
    color: white;
    margin-bottom: 4px;
}

.splash-subtitle {
    font-size: 14px;
    color: rgba(255, 255, 255, 0.8);
    margin-bottom: 24px;
}

.splash-loader {
    width: 32px;
    height: 32px;
    border: 3px solid rgba(255, 255, 255, 0.3);
    border-top-color: white;
    border-radius: 50%;
    margin: 0 auto;
    animation: spin 1s linear infinite;
}

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

/* Auth Screen */
.auth-container {
    min-height: 100vh;
    min-height: 100dvh;
    display: flex;
    flex-direction: column;
    justify-content: center;
    padding: 24px 20px;
    background: linear-gradient(180deg, var(--primary-light) 0%, var(--bg) 50%);
}

.auth-header {
    text-align: center;
    margin-bottom: 32px;
}

.auth-logo {
    width: 72px;
    height: 72px;
    background: var(--primary);
    border-radius: 20px;
    display: flex;
    align-items: center;
    justify-content: center;
    margin: 0 auto 16px;
    box-shadow: 0 8px 24px rgba(239, 68, 68, 0.3);
}

.auth-logo i {
    font-size: 36px;
    color: white;
}

.auth-title {
    font-size: 28px;
    font-weight: 800;
    color: var(--text);
}

.auth-subtitle {
    font-size: 14px;
    color: var(--text-secondary);
    margin-top: 4px;
}

.auth-form {
    background: var(--bg);
    border-radius: var(--radius-lg);
    padding: 24px;
    box-shadow: var(--shadow-lg);
}

.auth-footer {
    text-align: center;
    margin-top: 24px;
}

/* Header */
.header {
    height: var(--header-height);
    padding: 0 20px;
    display: flex;
    align-items: center;
    background: var(--bg);
    border-bottom: 1px solid var(--border);
    position: sticky;
    top: 0;
    z-index: 100;
}

.header-btn {
    width: 40px;
    height: 40px;
    border: none;
    background: none;
    border-radius: var(--radius-sm);
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    color: var(--text-secondary);
    transition: all 0.2s;
}

.header-btn:hover {
    background: var(--bg-secondary);
    color: var(--text);
}

.header-title {
    flex: 1;
    font-size: 18px;
    font-weight: 700;
    color: var(--text);
    margin-left: 8px;
}

.header-actions {
    display: flex;
    gap: 8px;
}

/* Main App */
.main-app {
    display: flex;
    flex-direction: column;
    min-height: 100vh;
    min-height: 100dvh;
}

/* Content */
.content {
    flex: 1;
    overflow-y: auto;
    padding-bottom: calc(var(--nav-height) + var(--safe-bottom) + 16px);
}

/* Bottom Navigation */
.bottom-nav {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    height: calc(var(--nav-height) + var(--safe-bottom));
    padding-bottom: var(--safe-bottom);
    background: var(--bg);
    border-top: 1px solid var(--border);
    display: flex;
    z-index: 100;
}

.nav-item {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 4px;
    padding: 8px;
    border: none;
    background: none;
    cursor: pointer;
    color: var(--text-secondary);
    transition: all 0.2s;
}

.nav-item i {
    font-size: 24px;
}

.nav-item span {
    font-size: 10px;
    font-weight: 600;
}

.nav-item.active {
    color: var(--primary);
}

.nav-item:hover:not(.active) {
    color: var(--text);
}

/* Cards */
.card {
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 16px;
    margin-bottom: 12px;
    transition: all 0.2s;
}

.card:hover {
    border-color: var(--slate-300);
}

/* Forms */
.form-group {
    margin-bottom: 16px;
}

.form-label {
    display: block;
    font-size: 12px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--text-secondary);
    margin-bottom: 8px;
}

.form-input,
.form-select,
.form-textarea {
    width: 100%;
    padding: 12px 16px;
    font-size: 16px;
    border: 2px solid var(--border);
    border-radius: var(--radius-sm);
    background: var(--bg);
    color: var(--text);
    transition: all 0.2s;
}

.form-input:focus,
.form-select:focus,
.form-textarea:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(239, 68, 68, 0.1);
}

.form-input::placeholder {
    color: var(--slate-400);
}

.form-error {
    background: #FEF2F2;
    color: var(--danger);
    padding: 12px;
    border-radius: var(--radius-sm);
    font-size: 14px;
    margin-bottom: 16px;
}

.input-icon-wrapper {
    position: relative;
}

.input-icon {
    position: absolute;
    left: 14px;
    top: 50%;
    transform: translateY(-50%);
    color: var(--text-secondary);
    font-size: 18px;
}

.input-icon-wrapper .form-input {
    padding-left: 44px;
}

/* Buttons */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 12px 20px;
    font-size: 14px;
    font-weight: 600;
    border: none;
    border-radius: var(--radius-sm);
    cursor: pointer;
    transition: all 0.2s;
}

.btn-primary {
    background: var(--primary);
    color: white;
}

.btn-primary:hover {
    background: var(--primary-dark);
}

.btn-secondary {
    background: var(--bg-secondary);
    color: var(--text);
}

.btn-secondary:hover {
    background: var(--border);
}

.btn-danger {
    background: var(--danger);
    color: white;
}

.btn-danger:hover {
    background: #B91C1C;
}

.btn-block {
    width: 100%;
}

.btn-lg {
    padding: 16px 24px;
    font-size: 16px;
}

.btn-sm {
    padding: 8px 12px;
    font-size: 12px;
}

.btn-icon {
    width: 40px;
    height: 40px;
    padding: 0;
}

/* Avatar */
.avatar {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background: var(--primary-light);
    color: var(--primary);
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    font-size: 16px;
}

/* Page Header */
.page-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0 4px;
    margin-bottom: 16px;
}

.page-title {
    font-size: 20px;
    font-weight: 800;
    color: var(--text);
}

/* Side Menu */
.side-menu {
    position: fixed;
    inset: 0;
    z-index: 200;
    background: rgba(0, 0, 0, 0.5);
    opacity: 0;
    visibility: hidden;
    transition: all 0.3s;
}

.side-menu.open {
    opacity: 1;
    visibility: visible;
}

.side-menu-content {
    position: absolute;
    right: 0;
    top: 0;
    bottom: 0;
    width: 280px;
    max-width: 80%;
    background: var(--bg);
    transform: translateX(100%);
    transition: transform 0.3s;
}

.side-menu.open .side-menu-content {
    transform: translateX(0);
}

.side-menu-header {
    padding: 24px 20px;
    background: var(--primary);
    color: white;
}

.side-menu-nav {
    padding: 16px 20px;
}

.side-menu-nav button {
    display: flex;
    align-items: center;
    gap: 12px;
    width: 100%;
    padding: 12px;
    border: none;
    background: none;
    color: var(--text);
    font-size: 14px;
    font-weight: 500;
    border-radius: var(--radius-sm);
    cursor: pointer;
    text-align: left;
    transition: background 0.2s;
}

.side-menu-nav button:hover {
    background: var(--bg-secondary);
}

.side-menu-nav button i {
    font-size: 20px;
    color: var(--text-secondary);
}

.divider {
    height: 1px;
    background: var(--border);
    margin: 12px 0;
}

/* Modal */
.modal-container {
    position: fixed;
    inset: 0;
    z-index: 300;
    display: flex;
    align-items: flex-end;
    justify-content: center;
    background: rgba(0, 0, 0, 0.5);
}

.modal-content {
    background: var(--bg);
    border-radius: var(--radius-lg) var(--radius-lg) 0 0;
    width: 100%;
    max-width: 480px;
    max-height: 90vh;
    overflow-y: auto;
}

.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 16px 20px;
    border-bottom: 1px solid var(--border);
}

.modal-title {
    font-size: 18px;
    font-weight: 700;
}

/* Toast */
.toast-container {
    position: fixed;
    top: calc(var(--header-height) + 16px);
    left: 20px;
    right: 20px;
    z-index: 400;
    display: flex;
    flex-direction: column;
    gap: 8px;
    pointer-events: none;
}

.toast {
    background: var(--slate-800);
    color: white;
    padding: 12px 16px;
    border-radius: var(--radius-sm);
    font-size: 14px;
    font-weight: 500;
    display: flex;
    align-items: center;
    gap: 8px;
    animation: slideIn 0.3s ease;
    pointer-events: auto;
}

.toast.success {
    background: var(--success);
}

.toast.warning {
    background: var(--warning);
    color: var(--slate-800);
}

.toast.error {
    background: var(--danger);
}

@keyframes slideIn {
    from {
        opacity: 0;
        transform: translateY(-10px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* Loading Spinner */
.loading-spinner {
    width: 32px;
    height: 32px;
    border: 3px solid var(--border);
    border-top-color: var(--primary);
    border-radius: 50%;
    margin: 24px auto;
    animation: spin 1s linear infinite;
}

/* Balance Card */
.balance-card {
    border-radius: var(--radius-lg);
    overflow: hidden;
    margin-bottom: 16px;
    box-shadow: var(--shadow-lg);
}

.balance-top {
    background: linear-gradient(135deg, var(--primary) 0%, var(--primary-dark) 100%);
    padding: 24px 20px;
    color: white;
}

.balance-label {
    font-size: 12px;
    font-weight: 600;
    text-transform: uppercase;
    opacity: 0.8;
    margin-bottom: 4px;
}

.balance-amount {
    font-size: 36px;
    font-weight: 800;
    letter-spacing: -0.02em;
}

.balance-meta {
    display: flex;
    background: white;
    padding: 16px 20px;
}

.balance-meta-item {
    flex: 1;
    text-align: center;
}

.balance-meta-item:first-child {
    border-right: 1px solid var(--border);
}

.balance-meta-label {
    font-size: 10px;
    color: var(--text-secondary);
    text-transform: uppercase;
    font-weight: 600;
}

.balance-meta-value {
    font-size: 18px;
    font-weight: 700;
    margin-top: 4px;
}

.dark .balance-meta {
    background: var(--slate-800);
}

/* Transaction Item */
.txn-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px;
    background: var(--bg);
    border-radius: var(--radius-sm);
    border: 1px solid var(--border);
    margin-bottom: 8px;
    cursor: pointer;
    transition: all 0.2s;
}

.txn-item:hover {
    border-color: var(--slate-300);
}

.txn-icon {
    width: 44px;
    height: 44px;
    border-radius: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 20px;
    flex-shrink: 0;
}

.txn-details {
    flex: 1;
    min-width: 0;
}

.txn-name {
    font-weight: 600;
    font-size: 14px;
    color: var(--text);
}

.txn-category {
    font-size: 12px;
    color: var(--text-secondary);
}

.txn-amount {
    font-weight: 700;
    font-size: 14px;
}

.txn-amount.expense {
    color: var(--danger);
}

.txn-amount.income {
    color: var(--success);
}

/* Category Pills */
.category-grid {
    display: grid;
    grid-template-columns: repeat(5, 1fr);
    gap: 8px;
}

.category-pill {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 12px 8px;
    border: 2px solid transparent;
    border-radius: var(--radius-sm);
    background: var(--bg);
    cursor: pointer;
    transition: all 0.2s;
}

.category-pill:hover {
    border-color: var(--border);
}

.category-pill.selected {
    border-color: var(--primary);
    background: var(--primary-light);
}

.category-pill .emoji {
    font-size: 24px;
    margin-bottom: 4px;
}

.category-pill .label {
    font-size: 10px;
    font-weight: 600;
    color: var(--text-secondary);
}

.category-pill.selected .label {
    color: var(--primary);
}

/* Grid Stats */
.grid-stats {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 12px;
    margin-bottom: 16px;
}

.grid-stat {
    padding: 16px;
    border-radius: var(--radius);
    cursor: pointer;
    transition: all 0.2s;
}

.grid-stat:hover {
    transform: translateY(-2px);
}

.grid-stat-label {
    font-size: 10px;
    font-weight: 600;
    text-transform: uppercase;
}

.grid-stat-value {
    font-size: 24px;
    font-weight: 800;
    margin-top: 4px;
}

/* Empty State */
.empty-state {
    text-align: center;
    padding: 48px 24px;
    color: var(--text-secondary);
}

.empty-state i {
    font-size: 48px;
    opacity: 0.3;
    margin-bottom: 16px;
}

.empty-state p {
    font-size: 14px;
    margin-bottom: 16px;
}

/* Utilities */
.hidden {
    display: none !important;
}

.flex {
    display: flex;
}

.items-center {
    align-items: center;
}

.justify-between {
    justify-content: space-between;
}

.gap-2 {
    gap: 8px;
}

.gap-3 {
    gap: 12px;
}

.gap-4 {
    gap: 16px;
}

.flex-1 {
    flex: 1;
}

.min-w-0 {
    min-width: 0;
}

.truncate {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.font-bold {
    font-weight: 700;
}

.text-xs {
    font-size: 12px;
}

.text-sm {
    font-size: 14px;
}

.text-slate-400 {
    color: var(--slate-400);
}

.text-slate-500 {
    color: var(--slate-500);
}

.text-slate-800 {
    color: var(--slate-800);
}

.text-red-400 {
    color: #F87171;
}

.text-red-500 {
    color: var(--danger);
}

.text-green-500 {
    color: var(--success);
}

.bg-red-50 {
    background: #FEF2F2;
}

.border-red-200 {
    border-color: #FECACA;
}

.uppercase {
    text-transform: uppercase;
}

.p-4 {
    padding: 20px;
}

.mb-2 {
    margin-bottom: 8px;
}

.mb-3 {
    margin-bottom: 12px;
}

.mb-4 {
    margin-bottom: 16px;
}

.mt-2 {
    margin-top: 8px;
}

.space-y-3>*+* {
    margin-top: 12px;
}

.space-y-4>*+* {
    margin-top: 16px;
}

.space-y-5>*+* {
    margin-top: 20px;
}

.cursor-pointer {
    cursor: pointer;
}

/* Animations */
.anim-fade {
    animation: fadeIn 0.3s ease;
}

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

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* Safe Areas */
@supports (padding: env(safe-area-inset-bottom)) {
    .content {
        padding-bottom: calc(var(--nav-height) + env(safe-area-inset-bottom) + 16px);
    }
}

/* ============================================
   OFFLINE STATUS BADGE
   ============================================ */
.offline-badge {
    display: inline-block;
    padding: 4px 12px;
    border-radius: 999px;
    font-size: 11px;
    font-weight: 600;
    letter-spacing: 0.01em;
    transition: all 0.3s ease;
    position: absolute;
    right: 60px;
    top: 50%;
    transform: translateY(-50%);
    z-index: 10;
}

.badge--ready {
    background: rgba(22, 163, 74, 0.15);
    color: #14532d;
    border: 1px solid rgba(22, 163, 74, 0.3);
}

.badge--caching {
    background: rgba(59, 130, 246, 0.15);
    color: #1e3a5f;
    border: 1px solid rgba(59, 130, 246, 0.3);
    animation: pulse 1.5s ease-in-out infinite;
}

.badge--offline {
    background: rgba(245, 158, 11, 0.15);
    color: #78350f;
    border: 1px solid rgba(245, 158, 11, 0.3);
}

.badge--error {
    background: rgba(220, 38, 38, 0.15);
    color: #7f1d1d;
    border: 1px solid rgba(220, 38, 38, 0.3);
}

@keyframes pulse {

    0%,
    100% {
        opacity: 1;
    }

    50% {
        opacity: 0.6;
    }
}

/* Dark mode badge */
.dark .badge--ready {
    background: rgba(22, 163, 74, 0.25);
    color: #86efac;
}

.dark .badge--caching {
    background: rgba(59, 130, 246, 0.25);
    color: #93c5fd;
}

.dark .badge--offline {
    background: rgba(245, 158, 11, 0.25);
    color: #fcd34d;
}

.dark .badge--error {
    background: rgba(220, 38, 38, 0.25);
    color: #fca5a5;
}

/* ============================================
   INLINE ICON SYSTEM
   ============================================ */
.icon {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 1em;
    height: 1em;
    vertical-align: -0.125em;
    flex-shrink: 0;
}

.icon svg {
    width: 100%;
    height: 100%;
}

.icon-sm {
    width: 0.875rem;
    height: 0.875rem;
}

.icon-lg {
    width: 1.5rem;
    height: 1.5rem;
}

.icon-xl {
    width: 2rem;
    height: 2rem;
}