/* ============================================
   PocketLedger — Custom Styles
   Mobile-first, native-feel design
   ============================================ */

/* Import Google Fonts */
@import url('https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700;800&display=swap');

/* ============================================
   Root & Reset
   ============================================ */
:root {
    --safe-top: env(safe-area-inset-top, 0px);
    --safe-bottom: env(safe-area-inset-bottom, 0px);
    --nav-height: 64px;
    --header-height: 56px;
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    -webkit-tap-highlight-color: transparent;
}

html {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', system-ui, sans-serif;
    font-size: 16px;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    overflow-x: hidden;
    scroll-behavior: smooth;
}

body {
    background-color: #f8fafc;
    color: #1e293b;
    min-height: 100dvh;
    overscroll-behavior: none;
    -webkit-overflow-scrolling: touch;
    padding-top: var(--safe-top);
    padding-bottom: calc(var(--nav-height) + var(--safe-bottom) + 8px);
    position: relative;
}

/* ============================================
   Native-feel Scrolling
   ============================================ */
.scroll-container {
    -webkit-overflow-scrolling: touch;
    overflow-y: auto;
    overscroll-behavior-y: contain;
}

/* Hide scrollbars but keep scrolling */
.hide-scrollbar::-webkit-scrollbar {
    display: none;
}
.hide-scrollbar {
    -ms-overflow-style: none;
    scrollbar-width: none;
}

/* ============================================
   Page Transitions
   ============================================ */
.view-container {
    min-height: calc(100dvh - var(--nav-height) - var(--safe-top) - var(--safe-bottom));
    animation: fadeSlideIn 0.3s ease-out;
}

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

@keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

@keyframes slideUp {
    from {
        transform: translateY(100%);
        opacity: 0;
    }
    to {
        transform: translateY(0);
        opacity: 1;
    }
}

@keyframes slideDown {
    from {
        transform: translateY(-100%);
        opacity: 0;
    }
    to {
        transform: translateY(0);
        opacity: 1;
    }
}

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

@keyframes pop {
    0% { transform: scale(1); }
    50% { transform: scale(1.05); }
    100% { transform: scale(1); }
}

@keyframes shimmer {
    0% { background-position: -200% 0; }
    100% { background-position: 200% 0; }
}

@keyframes pulse-ring {
    0% { transform: scale(0.95); opacity: 1; }
    50% { transform: scale(1); opacity: 0.7; }
    100% { transform: scale(0.95); opacity: 1; }
}

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

/* ============================================
   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: white;
    border-top: 1px solid #e2e8f0;
    display: flex;
    align-items: center;
    justify-content: space-around;
    z-index: 1000;
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    background: rgba(255, 255, 255, 0.95);
}

.nav-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 2px;
    padding: 6px 12px;
    border-radius: 12px;
    cursor: pointer;
    transition: all 0.2s ease;
    -webkit-user-select: none;
    user-select: none;
    position: relative;
    min-width: 56px;
}

.nav-item span {
    font-size: 10px;
    font-weight: 500;
    color: #94a3b8;
    transition: color 0.2s ease;
}

.nav-item svg {
    width: 22px;
    height: 22px;
    color: #94a3b8;
    transition: all 0.2s ease;
}

.nav-item.active svg {
    color: #10b981;
}

.nav-item.active span {
    color: #10b981;
    font-weight: 600;
}

.nav-item:active {
    transform: scale(0.92);
}

/* FAB (center button) */
.nav-fab {
    position: relative;
    bottom: 12px;
    width: 52px;
    height: 52px;
    background: linear-gradient(135deg, #10b981, #059669);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 4px 15px rgba(16, 185, 129, 0.4);
    cursor: pointer;
    transition: all 0.2s ease;
}

.nav-fab svg {
    width: 26px;
    height: 26px;
    color: white !important;
}

.nav-fab:active {
    transform: scale(0.9);
    box-shadow: 0 2px 8px rgba(16, 185, 129, 0.4);
}

/* ============================================
   Header
   ============================================ */
.app-header {
    position: sticky;
    top: 0;
    z-index: 100;
    background: rgba(255, 255, 255, 0.92);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    padding: 12px 16px;
    border-bottom: 1px solid rgba(226, 232, 240, 0.6);
}

/* ============================================
   Cards
   ============================================ */
.card {
    background: white;
    border-radius: 16px;
    padding: 16px;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.04), 0 1px 2px rgba(0, 0, 0, 0.02);
    border: 1px solid rgba(226, 232, 240, 0.6);
    transition: transform 0.2s ease, box-shadow 0.2s ease;
}

.card:active {
    transform: scale(0.98);
}

.card-gradient {
    background: linear-gradient(135deg, #10b981 0%, #059669 50%, #047857 100%);
    color: white;
    border: none;
    box-shadow: 0 4px 15px rgba(16, 185, 129, 0.3);
}

.card-gradient-blue {
    background: linear-gradient(135deg, #3b82f6 0%, #2563eb 50%, #1d4ed8 100%);
    color: white;
    border: none;
    box-shadow: 0 4px 15px rgba(59, 130, 246, 0.3);
}

.card-gradient-amber {
    background: linear-gradient(135deg, #f59e0b 0%, #d97706 50%, #b45309 100%);
    color: white;
    border: none;
    box-shadow: 0 4px 15px rgba(245, 158, 11, 0.3);
}

.card-gradient-rose {
    background: linear-gradient(135deg, #f43f5e 0%, #e11d48 50%, #be123c 100%);
    color: white;
    border: none;
    box-shadow: 0 4px 15px rgba(244, 63, 94, 0.3);
}

/* ============================================
   Bottom Sheet / Modal
   ============================================ */
.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.4);
    z-index: 2000;
    display: flex;
    align-items: flex-end;
    justify-content: center;
    animation: fadeIn 0.2s ease;
    backdrop-filter: blur(4px);
}

.modal-overlay.hidden {
    display: none;
}

.modal-sheet {
    background: white;
    border-radius: 20px 20px 0 0;
    padding: 8px 20px 20px;
    padding-bottom: calc(20px + var(--safe-bottom));
    width: 100%;
    max-width: 480px;
    max-height: 90dvh;
    overflow-y: auto;
    animation: slideUp 0.3s cubic-bezier(0.32, 0.72, 0, 1);
}

.modal-sheet .sheet-handle {
    width: 36px;
    height: 4px;
    background: #cbd5e1;
    border-radius: 99px;
    margin: 8px auto 16px;
}

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

.modal-center .modal-sheet {
    border-radius: 20px;
    margin: 16px;
    max-height: 85dvh;
    animation: scaleIn 0.3s cubic-bezier(0.32, 0.72, 0, 1);
    padding-bottom: 20px;
}

/* ============================================
   Form Controls
   ============================================ */
.form-input {
    width: 100%;
    padding: 12px 14px;
    border: 1.5px solid #e2e8f0;
    border-radius: 12px;
    font-size: 15px;
    font-family: inherit;
    color: #1e293b;
    background: #f8fafc;
    transition: all 0.2s ease;
    outline: none;
    -webkit-appearance: none;
    appearance: none;
}

.form-input:focus {
    border-color: #10b981;
    box-shadow: 0 0 0 3px rgba(16, 185, 129, 0.12);
    background: white;
}

.form-input::placeholder {
    color: #94a3b8;
}

.form-label {
    display: block;
    font-size: 13px;
    font-weight: 600;
    color: #475569;
    margin-bottom: 6px;
}

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

/* Select */
.form-select {
    width: 100%;
    padding: 12px 14px;
    padding-right: 40px;
    border: 1.5px solid #e2e8f0;
    border-radius: 12px;
    font-size: 15px;
    font-family: inherit;
    color: #1e293b;
    background: #f8fafc url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%2394a3b8' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E") no-repeat right 12px center;
    -webkit-appearance: none;
    appearance: none;
    outline: none;
    transition: all 0.2s ease;
}

.form-select:focus {
    border-color: #10b981;
    box-shadow: 0 0 0 3px rgba(16, 185, 129, 0.12);
}

/* ============================================
   Buttons
   ============================================ */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 12px 24px;
    border: none;
    border-radius: 12px;
    font-size: 15px;
    font-weight: 600;
    font-family: inherit;
    cursor: pointer;
    transition: all 0.2s ease;
    -webkit-user-select: none;
    user-select: none;
}

.btn:active {
    transform: scale(0.96);
}

.btn-primary {
    background: linear-gradient(135deg, #10b981, #059669);
    color: white;
    box-shadow: 0 2px 8px rgba(16, 185, 129, 0.3);
}

.btn-primary:hover {
    box-shadow: 0 4px 12px rgba(16, 185, 129, 0.4);
}

.btn-secondary {
    background: #f1f5f9;
    color: #475569;
}

.btn-danger {
    background: linear-gradient(135deg, #f43f5e, #e11d48);
    color: white;
    box-shadow: 0 2px 8px rgba(244, 63, 94, 0.3);
}

.btn-outline {
    background: transparent;
    color: #10b981;
    border: 1.5px solid #10b981;
}

.btn-sm {
    padding: 8px 16px;
    font-size: 13px;
    border-radius: 10px;
}

.btn-full {
    width: 100%;
}

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

/* ============================================
   Circular Progress Ring
   ============================================ */
.progress-ring {
    position: relative;
    display: flex;
    align-items: center;
    justify-content: center;
}

.progress-ring svg {
    transform: rotate(-90deg);
}

.progress-ring-bg {
    fill: none;
    stroke: rgba(255, 255, 255, 0.2);
}

.progress-ring-fill {
    fill: none;
    stroke: white;
    stroke-linecap: round;
    transition: stroke-dashoffset 1s cubic-bezier(0.32, 0.72, 0, 1);
}

.progress-ring-text {
    position: absolute;
    text-align: center;
}

/* ============================================
   Transaction List Items
   ============================================ */
.tx-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 14px 0;
    border-bottom: 1px solid #f1f5f9;
    animation: fadeSlideIn 0.3s ease-out;
    cursor: pointer;
    transition: background 0.15s ease;
}

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

.tx-item:active {
    background: #f8fafc;
    border-radius: 12px;
    margin: 0 -8px;
    padding: 14px 8px;
}

.tx-icon {
    width: 44px;
    height: 44px;
    border-radius: 14px;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.tx-icon svg {
    width: 20px;
    height: 20px;
}

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

.tx-category {
    font-weight: 600;
    font-size: 14px;
    color: #1e293b;
}

.tx-note {
    font-size: 12px;
    color: #94a3b8;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.tx-amount {
    font-weight: 700;
    font-size: 15px;
    text-align: right;
    white-space: nowrap;
}

.tx-date {
    font-size: 11px;
    color: #94a3b8;
    text-align: right;
}

/* ============================================
   Quick Add Presets
   ============================================ */
.preset-chip {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 8px 14px;
    background: white;
    border: 1.5px solid #e2e8f0;
    border-radius: 99px;
    font-size: 13px;
    font-weight: 500;
    color: #475569;
    cursor: pointer;
    transition: all 0.2s ease;
    white-space: nowrap;
    -webkit-user-select: none;
    user-select: none;
}

.preset-chip:active {
    transform: scale(0.95);
    background: #10b981;
    color: white;
    border-color: #10b981;
}

.preset-chip .chip-amount {
    font-weight: 700;
    color: #10b981;
}

.preset-chip:active .chip-amount {
    color: white;
}

/* ============================================
   Chat UI
   ============================================ */
.chat-container {
    display: flex;
    flex-direction: column;
    height: calc(100dvh - var(--nav-height) - var(--header-height) - var(--safe-top) - var(--safe-bottom));
}

.chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 16px;
    display: flex;
    flex-direction: column;
    gap: 12px;
    -webkit-overflow-scrolling: touch;
}

.chat-bubble {
    max-width: 85%;
    padding: 12px 16px;
    border-radius: 18px;
    font-size: 14px;
    line-height: 1.5;
    animation: scaleIn 0.3s ease;
    word-break: break-word;
}

.chat-bubble.user {
    align-self: flex-end;
    background: linear-gradient(135deg, #10b981, #059669);
    color: white;
    border-bottom-right-radius: 6px;
}

.chat-bubble.assistant {
    align-self: flex-start;
    background: white;
    color: #1e293b;
    border: 1px solid #e2e8f0;
    border-bottom-left-radius: 6px;
    box-shadow: 0 1px 2px rgba(0,0,0,0.04);
}

.chat-input-area {
    padding: 12px 16px;
    background: white;
    border-top: 1px solid #e2e8f0;
    display: flex;
    gap: 8px;
    align-items: flex-end;
}

.chat-input {
    flex: 1;
    padding: 10px 16px;
    border: 1.5px solid #e2e8f0;
    border-radius: 24px;
    font-size: 14px;
    font-family: inherit;
    outline: none;
    resize: none;
    max-height: 100px;
    background: #f8fafc;
    transition: border-color 0.2s;
}

.chat-input:focus {
    border-color: #10b981;
}

.chat-send-btn {
    width: 42px;
    height: 42px;
    border-radius: 50%;
    background: linear-gradient(135deg, #10b981, #059669);
    border: none;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    flex-shrink: 0;
    transition: transform 0.2s;
}

.chat-send-btn:active {
    transform: scale(0.9);
}

.chat-send-btn svg {
    color: white;
    width: 20px;
    height: 20px;
}

/* Typing indicator */
.typing-indicator {
    display: flex;
    gap: 4px;
    padding: 12px 16px;
    align-items: center;
}

.typing-dot {
    width: 7px;
    height: 7px;
    background: #94a3b8;
    border-radius: 50%;
    animation: typing 1.4s infinite;
}

.typing-dot:nth-child(2) { animation-delay: 0.2s; }
.typing-dot:nth-child(3) { animation-delay: 0.4s; }

@keyframes typing {
    0%, 60%, 100% { transform: translateY(0); opacity: 0.4; }
    30% { transform: translateY(-6px); opacity: 1; }
}

/* ============================================
   Category Badge
   ============================================ */
.category-badge {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 4px 10px;
    border-radius: 8px;
    font-size: 12px;
    font-weight: 500;
}

/* ============================================
   Budget Progress Bar
   ============================================ */
.budget-bar-bg {
    height: 6px;
    background: #f1f5f9;
    border-radius: 99px;
    overflow: hidden;
}

.budget-bar-fill {
    height: 100%;
    border-radius: 99px;
    transition: width 0.8s cubic-bezier(0.32, 0.72, 0, 1);
}

/* ============================================
   Skeleton Loading
   ============================================ */
.skeleton {
    background: linear-gradient(90deg, #f1f5f9 25%, #e2e8f0 50%, #f1f5f9 75%);
    background-size: 200% 100%;
    animation: shimmer 1.5s infinite;
    border-radius: 8px;
}

/* ============================================
   Toast Notifications
   ============================================ */
.toast {
    position: fixed;
    top: calc(var(--safe-top) + 16px);
    left: 50%;
    transform: translateX(-50%);
    padding: 12px 20px;
    border-radius: 12px;
    font-size: 14px;
    font-weight: 500;
    color: white;
    z-index: 9999;
    animation: slideDown 0.3s ease, fadeIn 0.3s ease;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
    text-align: center;
    max-width: calc(100% - 32px);
}

.toast-success { background: linear-gradient(135deg, #10b981, #059669); }
.toast-error { background: linear-gradient(135deg, #f43f5e, #e11d48); }
.toast-info { background: linear-gradient(135deg, #3b82f6, #2563eb); }

/* ============================================
   Empty State
   ============================================ */
.empty-state {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 48px 24px;
    text-align: center;
}

.empty-state svg {
    width: 64px;
    height: 64px;
    color: #cbd5e1;
    margin-bottom: 16px;
}

.empty-state h3 {
    font-size: 16px;
    font-weight: 600;
    color: #64748b;
    margin-bottom: 4px;
}

.empty-state p {
    font-size: 13px;
    color: #94a3b8;
}

/* ============================================
   Tabs
   ============================================ */
.tab-bar {
    display: flex;
    gap: 4px;
    padding: 4px;
    background: #f1f5f9;
    border-radius: 12px;
    overflow-x: auto;
}

.tab-item {
    flex: 1;
    padding: 8px 16px;
    border-radius: 10px;
    font-size: 13px;
    font-weight: 500;
    text-align: center;
    color: #64748b;
    cursor: pointer;
    transition: all 0.2s ease;
    white-space: nowrap;
    -webkit-user-select: none;
    user-select: none;
}

.tab-item.active {
    background: white;
    color: #10b981;
    font-weight: 600;
    box-shadow: 0 1px 3px rgba(0,0,0,0.08);
}

/* ============================================
   Swipe to delete (visual hint)
   ============================================ */
.swipe-hint {
    position: relative;
    overflow: hidden;
}

/* ============================================
   Amount Input Large
   ============================================ */
.amount-display {
    font-size: 36px;
    font-weight: 700;
    color: #1e293b;
    text-align: center;
    padding: 16px 0;
}

.amount-display .currency {
    font-size: 24px;
    font-weight: 500;
    color: #64748b;
    margin-right: 4px;
}

/* ============================================
   Toggle Switch
   ============================================ */
.toggle-switch {
    display: flex;
    background: #f1f5f9;
    border-radius: 10px;
    padding: 3px;
    gap: 2px;
}

.toggle-option {
    flex: 1;
    padding: 8px 16px;
    text-align: center;
    border-radius: 8px;
    font-size: 13px;
    font-weight: 500;
    color: #64748b;
    cursor: pointer;
    transition: all 0.2s ease;
    -webkit-user-select: none;
    user-select: none;
}

.toggle-option.active {
    background: white;
    box-shadow: 0 1px 3px rgba(0,0,0,0.1);
}

.toggle-option.active.income {
    color: #10b981;
}

.toggle-option.active.expense {
    color: #f43f5e;
}

/* ============================================
   PWA Install Banner
   ============================================ */
.install-banner {
    position: fixed;
    bottom: calc(var(--nav-height) + var(--safe-bottom) + 12px);
    left: 16px;
    right: 16px;
    background: linear-gradient(135deg, #1e293b, #0f172a);
    color: white;
    padding: 14px 16px;
    border-radius: 16px;
    display: flex;
    align-items: center;
    gap: 12px;
    z-index: 999;
    animation: slideUp 0.4s ease;
    box-shadow: 0 8px 24px rgba(0,0,0,0.2);
}

.install-banner.hidden {
    display: none;
}

/* ============================================
   Horizontal Scroll
   ============================================ */
.h-scroll {
    display: flex;
    gap: 12px;
    overflow-x: auto;
    padding: 0 16px;
    scroll-snap-type: x mandatory;
    -webkit-overflow-scrolling: touch;
}

.h-scroll::-webkit-scrollbar {
    display: none;
}

.h-scroll > * {
    scroll-snap-align: start;
    flex-shrink: 0;
}

/* ============================================
   Badge / Pill
   ============================================ */
.badge {
    display: inline-flex;
    align-items: center;
    padding: 2px 8px;
    border-radius: 99px;
    font-size: 11px;
    font-weight: 600;
}

.badge-danger {
    background: #fef2f2;
    color: #ef4444;
}

.badge-success {
    background: #f0fdf4;
    color: #22c55e;
}

.badge-warning {
    background: #fffbeb;
    color: #f59e0b;
}

/* ============================================
   Responsive (tablet+)
   ============================================ */
@media (min-width: 640px) {
    body {
        max-width: 480px;
        margin: 0 auto;
        box-shadow: 0 0 40px rgba(0,0,0,0.08);
    }
    
    .bottom-nav {
        max-width: 480px;
        left: 50%;
        transform: translateX(-50%);
    }
    
    .toast {
        max-width: 400px;
    }
    
    .install-banner {
        max-width: 448px;
        left: 50%;
        right: auto;
        transform: translateX(-50%);
    }
}
