/* Typography: Pretendard - Financial App Optimized */
@import url("https://cdn.jsdelivr.net/gh/orioncactus/pretendard@v1.3.9/dist/web/static/pretendard-dynamic-subset.css");

:root {
    /* WooPay Color Palette */
    --brand-blue: #4A90E2;
    --brand-blue-hover: #3A7BC8;
    --amount-orange: #FF8C42;
    --button-pink: #FF3B7C;
    --button-pink-hover: #E6286B;

    /* Stats Card Colors */
    --stat-blue: #5B9FED;
    --stat-pink: #FFB4D5;
    --stat-green: #50E3C2;

    /* Legacy colors for compatibility */
    --primary-color: #4A90E2;
    --primary-hover: #3A7BC8;
    --secondary-color: #FF3B7C;

    --bg-color: #F5F7FA;
    --surface-bg: #FFFFFF;

    --text-primary: #1F2937;
    --text-secondary: #6B7280;

    --danger-color: #EF4444;
    --success-color: #10B981;
    --warning-color: #F59E0B;

    /* Effects */
    --shadow-sm: 0 1px 2px 0 rgb(0 0 0 / 0.05);
    --shadow-md: 0 4px 6px -1px rgb(0 0 0 / 0.1), 0 2px 4px -2px rgb(0 0 0 / 0.1);
    --shadow-card: 0 2px 8px rgba(0, 0, 0, 0.08);
    --shadow-float: 0 4px 12px rgba(74, 144, 226, 0.15);

    --radius-pill: 50px;
    --radius-card: 16px;

    /* Gradients */
    --gradient-cherry: linear-gradient(135deg, #4A90E2 0%, #50E3C2 100%);

    /* Bootstrap Overrides */
    --bs-primary: #4A90E2;
    --bs-primary-rgb: 74, 144, 226;
    --bs-btn-bg: #4A90E2;
    --bs-btn-border-color: #4A90E2;
    --bs-btn-hover-bg: #3A7BC8;
    --bs-btn-hover-border-color: #3A7BC8;
    --bs-btn-active-bg: #3A7BC8;

    /* --- Mobile Design Tokens --- */
    --touch-target-min: 48px;
    --spacing-mobile: 16px;
    --fab-bottom: 24px;
}

body {
    font-family: "Pretendard Variable", Pretendard, -apple-system, BlinkMacSystemFont, system-ui, Roboto, "Helvetica Neue", "Segoe UI", "Apple SD Gothic Neo", "Noto Sans KR", "Malgun Gothic", "Apple Color Emoji", "Segoe UI Emoji", "Segoe UI Symbol", sans-serif;
    background-color: var(--bg-color);
    color: var(--text-primary);
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    letter-spacing: -0.01em;
    padding-bottom: 60px;
    font-size: 17px;
    /* Increased base font size */
    line-height: 1.6;
}

/* Global Typography for Financial App */
*,
*::before,
*::after {
    font-family: inherit;
}

input,
button,
textarea,
select {
    font-family: "Pretendard Variable", Pretendard, -apple-system, BlinkMacSystemFont, system-ui, Roboto, "Helvetica Neue", "Segoe UI", sans-serif;
}

/* Tabular Figures for Numbers (Equal-width digits) */
.amount-xl,
.stat-value,
#remainingBudget,
#totalBudget,
#totalSpent,
#totalPlanned,
.fw-bold,
[id*="Budget"],
[id*="total"],
[class*="amount"] {
    font-feature-settings: "tnum";
    font-variant-numeric: tabular-nums;
}

/* Common Layout */
.container {
    max-width: 768px;
    margin-top: 24px;
}

/* Card Styling */
.card {
    background: var(--surface-bg);
    border: none;
    border-radius: var(--radius-card);
    box-shadow: var(--shadow-sm);
    margin-bottom: 24px;
    transition: transform 0.2s ease, box-shadow 0.2s ease;
    overflow: hidden;
}

/* Hero Card: White BG, Deep Shadow */
.card-hero {
    background: white;
    border-radius: 20px;
    box-shadow: var(--shadow-float);
    border: none;
}

.card-hero .card-title,
.card-hero .text-muted {
    color: var(--text-primary);
}

/* Navbar */
.header-nav {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 12px;
    padding: 10px 0;
    gap: 8px;
}

.brand-logo {
    font-size: 1.5rem;
    font-weight: 800;
    background: linear-gradient(135deg, #4A90E2, #8B5CF6);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    letter-spacing: -0.03em;
}

/* Navigation Icons (Clean Style) - Mobile Optimized */
.btn-nav {
    background: transparent;
    color: #4A90E2;
    border: none;
    border-radius: 50%;
    width: 48px;
    height: 48px;
    min-width: 48px;
    min-height: 48px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s;
    text-decoration: none;
    font-size: 1.4rem;
}

.btn-nav:hover {
    background-color: rgba(74, 144, 226, 0.1);
    color: #3A7BC8;
    transform: scale(1.1);
}

/* Buttons */
.btn {
    border-radius: 1rem;
    font-weight: 600;
    padding: 0.6rem 1.2rem;
    transition: all 0.2s;
    border: none;
}

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

.btn-primary:hover {
    background-color: var(--primary-hover) !important;
    transform: translateY(-1px);
}

.btn-outline-primary {
    color: var(--primary-color);
    border: 1px solid var(--primary-color);
    background: transparent;
}

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

/* Smart Input Wrapper - Mobile Optimized */
.smart-input-wrapper {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

/* Smart Input Area */
.smart-input-area {
    background: linear-gradient(135deg, #ffffff 0%, #f8f9fa 100%);
    border: 2px solid #e9ecef;
    border-radius: 16px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.08), 0 2px 4px rgba(0, 0, 0, 0.04);
    padding: 12px 16px;
    transition: all 0.3s ease;
}

.smart-input-area:hover {
    border-color: #4A90E2;
    box-shadow: 0 6px 16px rgba(74, 144, 226, 0.15), 0 3px 6px rgba(74, 144, 226, 0.08);
    transform: translateY(-1px);
}

.smart-input-area:focus-within {
    border-color: #4A90E2;
    box-shadow: 0 6px 20px rgba(74, 144, 226, 0.2), 0 0 0 3px rgba(74, 144, 226, 0.1);
    transform: translateY(-1px);
}

.smart-input-area .form-control {
    border: none;
    background: transparent;
    padding: 12px 6px;
    box-shadow: none;
    font-size: 1.1rem;
    color: var(--text-primary);
    line-height: 1.5;
}

.smart-input-area .form-control:focus {
    outline: none;
    box-shadow: none;
}

.smart-input-area .form-control::placeholder {
    color: #9ca3af;
    font-weight: 400;
}

/* Smart Input Actions - Button Grid */
.smart-input-actions {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
}

.smart-input-actions .btn {
    border-radius: 12px;
    padding: 14px 18px;
    font-weight: 600;
    font-size: 1.05rem;
    transition: all 0.2s ease;
    flex: 1 1 auto;
    min-width: 0;
}

.smart-input-actions .btn-primary {
    background: linear-gradient(135deg, #4A90E2 0%, #357ABD 100%);
    border: none;
    box-shadow: 0 2px 8px rgba(74, 144, 226, 0.3);
}

.smart-input-actions .btn-primary:hover {
    background: linear-gradient(135deg, #357ABD 0%, #2868A8 100%);
    box-shadow: 0 4px 12px rgba(74, 144, 226, 0.4);
    transform: translateY(-2px);
}

.smart-input-actions .btn-light {
    background: #f8f9fa;
    border: 1px solid #dee2e6;
    color: #495057;
}

.smart-input-actions .btn-light:hover {
    background: #e9ecef;
    border-color: #adb5bd;
    transform: translateY(-2px);
}

/* Mobile: Stack buttons vertically on very small screens */
@media (max-width: 400px) {
    .smart-input-actions {
        flex-direction: column;
    }

    .smart-input-actions .btn {
        width: 100%;
    }
}

/* Desktop: Adjust layout for larger screens */
@media (min-width: 768px) {
    .smart-input-wrapper {
        flex-direction: row;
        align-items: stretch;
    }

    .smart-input-area {
        flex: 1;
    }

    .smart-input-actions {
        flex: 0 0 auto;
        align-items: center;
    }

    .smart-input-actions .btn {
        flex: 0 0 auto;
        white-space: nowrap;
    }
}

/* Progress Bar */
.progress {
    height: 1.2rem !important;
    background-color: #E5E7EB;
    border-radius: 50px;
    overflow: hidden;
}

.progress-bar {
    background-color: var(--secondary-color);
    border-radius: 50px;
}

/* Utilities */
.text-cherry {
    color: var(--primary-color) !important;
}

.text-rose {
    color: var(--secondary-color) !important;
}

/* Background Utilities */
.bg-cherry {
    background: var(--primary-color) !important;
    border-color: var(--primary-color) !important;
}

.bg-rose {
    background: var(--secondary-color) !important;
}

.amount-xl {
    font-size: 2.8rem;
    letter-spacing: -0.05em;
    font-weight: 800;
    color: var(--amount-orange);
    font-feature-settings: "tnum";
    font-variant-numeric: tabular-nums;
}

/* WooPay Specific Styles */
.btn-detail {
    background-color: var(--button-pink);
    color: white;
    border: none;
    border-radius: 20px;
    padding: 8px 16px;
    /* Slightly reduced padding */
    font-size: 0.85rem;
    font-weight: 600;
    transition: all 0.2s;
    text-decoration: none;
    display: inline-block;
    white-space: nowrap;
    /* CRITICAL: Prevent wrapping */
}

.btn-detail:hover {
    background-color: var(--button-pink-hover);
    color: white;
    transform: translateY(-1px);
    box-shadow: 0 4px 8px rgba(255, 59, 124, 0.3);
}

.stat-box {
    border-radius: 12px;
    padding: 16px 12px;
    text-align: center;
    color: white;
    transition: transform 0.2s;
}

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

.stat-box-blue {
    background-color: #E3F2FD;
    color: #1976D2;
}

.stat-box-pink {
    background-color: #FCE4EC;
    color: #E53935;
}

.stat-box-green {
    background-color: #E8F5E9;
    color: #2E7D32;
}

.stat-label {
    font-size: 0.95rem;
    font-weight: 600;
    opacity: 0.95;
    margin-bottom: 4px;
}

.stat-value {
    font-size: 1.1rem;
    font-weight: 800;
    letter-spacing: -0.02em;
    font-feature-settings: "tnum";
    font-variant-numeric: tabular-nums;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* Floating Action Button (FAB) - Liquid Style - Mobile Optimized */
.btn-fab {
    position: fixed;
    bottom: var(--fab-bottom);
    right: 20px;
    padding: 14px 24px;
    border-radius: 50px;
    background: linear-gradient(135deg, #FF3B7C, #FF6B9D);
    color: white;
    font-size: 16px;
    font-weight: 700;
    box-shadow: 0 8px 24px rgba(255, 59, 124, 0.4);
    display: flex;
    align-items: center;
    gap: 8px;
    z-index: 1050;
    border: none;
    text-decoration: none;
    cursor: pointer;
    transition: all 0.4s cubic-bezier(0.34, 1.56, 0.64, 1);
    animation: floatBounce 3s ease-in-out infinite;
}

/* FAB Mobile Optimization - Thumb Zone */
@media (max-width: 576px) {
    .btn-fab {
        bottom: 32px;
        right: 16px;
    }
}

.btn-fab:hover {
    background: linear-gradient(135deg, #E6286B, #FF5A8F);
    color: white;
    transform: translateY(-4px) scale(1.05);
    box-shadow: 0 12px 32px rgba(255, 59, 124, 0.5);
    animation: jellyWobble 0.6s ease-in-out;
}

.btn-fab:active {
    transform: translateY(-2px) scale(0.98);
    animation: liquidSplash 0.5s ease-out;
}

/* Liquid Animations */
@keyframes floatBounce {

    0%,
    100% {
        transform: translateY(0px);
    }

    50% {
        transform: translateY(-8px);
    }
}

@keyframes jellyWobble {

    0%,
    100% {
        transform: translateY(-4px) scale(1.05);
    }

    25% {
        transform: translateY(-4px) scale(1.08, 0.95);
    }

    50% {
        transform: translateY(-4px) scale(0.95, 1.08);
    }

    75% {
        transform: translateY(-4px) scale(1.05, 0.98);
    }
}

@keyframes liquidSplash {
    0% {
        transform: translateY(-2px) scale(0.98);
    }

    30% {
        transform: translateY(-2px) scale(1.1, 0.9);
    }

    50% {
        transform: translateY(-2px) scale(0.9, 1.1);
    }

    70% {
        transform: translateY(-2px) scale(1.05, 0.95);
    }

    100% {
        transform: translateY(-2px) scale(1);
    }
}

/* Category Select - Enhanced Design */
.category-select {
    font-size: 1.1rem !important;
    padding: 14px 16px !important;
    border: 2px solid #e9ecef !important;
    border-radius: 12px !important;
    background-color: #f8f9fa !important;
    transition: all 0.3s ease !important;
    font-weight: 500 !important;
    color: var(--text-primary) !important;
}

.category-select:hover {
    border-color: #4A90E2 !important;
    background-color: white !important;
}

.category-select:focus {
    border-color: #4A90E2 !important;
    box-shadow: 0 0 0 3px rgba(74, 144, 226, 0.1) !important;
    background-color: white !important;
}

.category-select option {
    padding: 16px 12px;
    font-size: 1.1rem;
    line-height: 2;
    min-height: 48px;
}

/* Modal Improvements */
.modal-content {
    border-radius: 20px !important;
    border: none !important;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.15) !important;
}

.modal-header {
    border-bottom: 2px solid #f1f3f5 !important;
    padding: 20px 24px !important;
    background: linear-gradient(135deg, #f8f9fa 0%, #ffffff 100%) !important;
    border-radius: 20px 20px 0 0 !important;
}

.modal-title {
    color: var(--primary-color) !important;
    font-size: 1.3rem !important;
}

.modal-body {
    padding: 24px !important;
}

.modal-footer {
    border-top: 2px solid #f1f3f5 !important;
    padding: 16px 24px !important;
    background-color: #f8f9fa !important;
}

/* Form Labels */
.form-label {
    font-weight: 600 !important;
    color: var(--text-secondary) !important;
    margin-bottom: 8px !important;
    font-size: 1.1rem !important;
}

/* Form Controls */
.form-control,
.form-select {
    border: 2px solid #e9ecef !important;
    border-radius: 12px !important;
    padding: 14px 16px !important;
    font-size: 1.1rem !important;
    transition: all 0.2s ease !important;
}

.form-control:focus,
.form-select:focus {
    border-color: #4A90E2 !important;
    box-shadow: 0 0 0 3px rgba(74, 144, 226, 0.1) !important;
}

/* Button Group Improvements */
.btn-group .btn {
    padding: 12px 20px !important;
    font-weight: 600 !important;
    font-size: 1.1rem !important;
}

.btn-group .btn-check:checked+.btn {
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.15) !important;
}

/* Animation */
.fade-in {
    animation: fadeIn 0.5s ease-out forwards;
}

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

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

/* ===== 금액 입력/표시 - 큰 금액 대응 ===== */

/* 금액 입력 필드 - 모달 내 */
#amount {
    font-size: 1.5rem !important;
    font-weight: 700 !important;
    font-feature-settings: "tnum";
    font-variant-numeric: tabular-nums;
    text-align: right;
    letter-spacing: -0.02em;
}

/* 모바일에서 큰 금액 대응 */
@media (max-width: 576px) {
    #amount {
        font-size: 1.25rem !important;
    }

    /* 모달 내 금액 표시 반응형 */
    .amount-display {
        font-size: clamp(1rem, 5vw, 1.5rem);
        word-break: break-word;
    }

    /* 거래 목록의 금액 */
    .card-body .fw-bold[class*="text-"] {
        font-size: 0.95rem;
        white-space: nowrap;
    }
}

/* 아주 작은 화면 (소형 모바일) */
@media (max-width: 375px) {
    #amount {
        font-size: 1.1rem !important;
    }

    /* 대시보드 큰 금액 */
    .amount-xl {
        font-size: 2rem !important;
    }

    /* 통계 박스 금액 */
    .stat-value {
        font-size: 1rem !important;
    }
}

/* 금액 포맷팅 - 천만원 이상 */
.amount-formatted {
    font-feature-settings: "tnum";
    font-variant-numeric: tabular-nums;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 100%;
}

/* 거래 카드 내 금액 표시 개선 */
.card-body .d-flex.justify-content-between {
    gap: 12px;
}

.card-body .d-flex.justify-content-between>div:last-child {
    flex-shrink: 0;
    text-align: right;
    min-width: 80px;
    max-width: 45%;
}

/* 모달 내 btn-group 반응형 */
@media (max-width: 400px) {
    .modal-body .btn-group {
        flex-direction: column;
    }

    .modal-body .btn-group .btn {
        border-radius: 8px !important;
        margin-bottom: 4px;
    }

    .modal-body .btn-group .btn:first-child {
        border-radius: 8px !important;
    }

    .modal-body .btn-group .btn:last-child {
        border-radius: 8px !important;
        margin-bottom: 0;
    }
}

/* ===== Statement Parsing Cards (Mobile Optimized) ===== */
.statement-card {
    border: 1px solid #e9ecef;
    border-radius: 12px;
    transition: all 0.2s ease;
    margin-bottom: 12px !important;
}

.statement-card:hover {
    border-color: #4A90E2;
    box-shadow: 0 2px 8px rgba(74, 144, 226, 0.15);
}

.statement-card .form-control,
.statement-card .form-select {
    padding: 10px 12px !important;
    font-size: 1rem !important;
    border-radius: 8px !important;
}

.statement-card .form-control:focus,
.statement-card .form-select:focus {
    border-color: #4A90E2 !important;
    box-shadow: 0 0 0 2px rgba(74, 144, 226, 0.1) !important;
}

/* Statement Modal - Mobile Full Height */
@media (max-width: 576px) {
    #statementModal .modal-dialog {
        margin: 0;
        max-width: 100%;
        min-height: 100vh;
    }

    #statementModal .modal-content {
        min-height: 100vh;
        border-radius: 0 !important;
    }

    #statementModal .modal-body {
        padding: 16px !important;
    }

    .statement-card .card-body {
        padding: 16px !important;
    }
}

/* ===== Global Mobile Touch Target Optimization ===== */
button,
.btn,
.nav-link,
a.btn-nav,
select.form-select,
input[type="radio"]+label,
input[type="checkbox"]+label {
    min-height: var(--touch-target-min);
    font-size: 16px !important;
}

input.form-control,
textarea.form-control {
    font-size: 16px !important;
}

/* ===== Mobile Full-Screen Modals ===== */
@media (max-width: 576px) {
    .modal-dialog {
        margin: 0 !important;
        max-width: 100% !important;
        height: 100vh !important;
        display: flex !important;
        flex-direction: column !important;
    }

    .modal-content {
        height: 100% !important;
        border-radius: 0 !important;
        border: none !important;
    }

    .modal-body {
        overflow-y: auto !important;
        padding-bottom: 80px !important;
    }

    .modal-footer {
        position: sticky !important;
        bottom: 0 !important;
        background: white !important;
        z-index: 10 !important;
        border-top: 1px solid #eee !important;
    }
}

/* ===== Smart Input Mobile Optimization ===== */
@media (max-width: 576px) {
    .smart-input-button-group {
        display: flex !important;
        flex-direction: column !important;
        gap: 8px !important;
    }

    .smart-input-button-group .btn {
        width: 100% !important;
    }
}

/* ===== Filter Tabs Mobile Optimization ===== */
#txFilterGroup {
    display: flex;
    flex-wrap: wrap;
}

#txFilterGroup .btn {
    flex: 1 1 auto;
    min-width: 80px;
    padding: 12px 8px !important;
    font-size: 0.95rem !important;
}

@media (max-width: 400px) {
    #txFilterGroup {
        flex-direction: column;
    }

    #txFilterGroup .btn {
        width: 100%;
        border-radius: 8px !important;
        margin-bottom: 4px;
    }

    #txFilterGroup .btn:first-child {
        border-radius: 8px !important;
    }

    #txFilterGroup .btn:last-child {
        border-radius: 8px !important;
        margin-bottom: 0;
    }
}

/* ===== Stat Boxes Mobile Responsive ===== */
@media (max-width: 576px) {
    .stat-box {
        padding: 12px 8px !important;
    }

    .stat-label {
        font-size: 0.85rem !important;
    }

    .stat-value {
        font-size: 1rem !important;
    }
}

/* ===== Enhanced Touch Spacing ===== */
@media (max-width: 576px) {
    .header-nav {
        gap: 4px;
    }

    .d-flex.gap-1 {
        gap: 4px !important;
    }

    .card {
        margin-bottom: var(--spacing-mobile) !important;
    }

    .container {
        margin-top: 12px !important;
    }
}

/* ===== Recent Transactions Mobile Collapse ===== */
.mobile-collapse-toggle {
    display: none;
}

.mobile-collapse-toggle .collapse-icon {
    font-size: 0.75rem;
    color: var(--text-secondary);
    transition: transform 0.3s ease;
}

.mobile-collapse-toggle[aria-expanded="false"] .collapse-icon {
    transform: rotate(-90deg);
}

.mobile-collapse-toggle:hover {
    color: var(--primary-color) !important;
}

/* Desktop: Always show, no collapse functionality */
@media (min-width: 769px) {
    .mobile-collapse-toggle {
        pointer-events: none;
    }
    
    .mobile-collapse-toggle .collapse-icon {
        display: none;
    }
    
    #recentTransactionsCollapse {
        display: block !important;
    }
}

/* Mobile: Show collapse toggle and enable collapsing */
@media (max-width: 768px) {
    .mobile-collapse-toggle {
        display: flex !important;
    }
    
    .recent-transactions-section {
        background: white;
        border-radius: 12px;
        padding: 12px;
        margin-bottom: 16px;
        box-shadow: var(--shadow-sm);
    }
    
    .recent-transactions-section .d-flex.justify-content-between {
        margin-bottom: 8px !important;
    }
    
    #recentTransactionsCollapse {
        transition: height 0.3s ease;
    }
    
    #recentTransactionsCollapse.collapsing {
        transition: height 0.3s ease;
    }
}

/* Enhanced mobile collapse animation */
@media (max-width: 768px) {
    .recent-transactions-section {
        transition: all 0.3s ease;
    }
    
    .mobile-collapse-toggle h6 {
        color: var(--text-primary);
        font-size: 1rem;
    }
    
    .mobile-collapse-toggle:hover h6 {
        color: var(--primary-color);
    }
}