/* ========== 全局樣式 ========== */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Microsoft JhengHei', sans-serif;
    background: linear-gradient(135deg, #a8d5d8 0%, #c5b8d4 50%, #d4b8c5 100%);
    min-height: 100vh;
    color: #2d3436;
}

.app {
    display: flex;
    min-height: 100vh;
    padding: 24px;
    gap: 20px;
}

/* ========== Modal ========== */
.modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.4);
    backdrop-filter: blur(8px);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
}

.modal-content {
    background: rgba(255, 255, 255, 0.9);
    backdrop-filter: blur(20px);
    border-radius: 20px;
    padding: 32px;
    width: 90%;
    max-width: 400px;
    position: relative;
    border: 1px solid rgba(255, 255, 255, 0.5);
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.2);
}

.modal-content.modal-large {
    max-width: 700px;
    max-height: 90vh;
    overflow-y: auto;
}

.modal-close {
    position: absolute;
    top: 16px;
    right: 16px;
    background: none;
    border: none;
    font-size: 1.5rem;
    cursor: pointer;
    color: #636e72;
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 8px;
    transition: background 0.2s;
}

.modal-close:hover {
    background: rgba(0, 0, 0, 0.05);
}

.modal-content h2 {
    margin-bottom: 20px;
    font-size: 1.3rem;
    color: #2d3436;
}

.modal-switch {
    text-align: center;
    margin-top: 16px;
    font-size: 0.9rem;
    color: #636e72;
}

.modal-switch a {
    color: #00a8a8;
    text-decoration: none;
    font-weight: 600;
}

/* ========== OCR Modal ========== */
.ocr-preview {
    margin-bottom: 20px;
    border-radius: 12px;
    overflow: hidden;
    background: rgba(0, 0, 0, 0.05);
    text-align: center;
}

.ocr-preview img {
    max-width: 100%;
    max-height: 300px;
    object-fit: contain;
}

.ocr-status {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    padding: 20px;
    color: #636e72;
}

.loading-spinner {
    width: 20px;
    height: 20px;
    border: 2px solid #e0e0e0;
    border-top-color: #00a8a8;
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

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

.ocr-transactions {
    display: flex;
    flex-direction: column;
    gap: 12px;
    margin-bottom: 20px;
}

.ocr-transaction-item {
    display: grid;
    grid-template-columns: 1fr 1fr 1fr 100px 120px;
    gap: 10px;
    align-items: center;
    padding: 12px;
    background: rgba(255, 255, 255, 0.5);
    border-radius: 10px;
    border: 1px solid rgba(0, 0, 0, 0.05);
}

.ocr-transaction-item input,
.ocr-transaction-item select {
    padding: 8px 10px;
    border: 1px solid rgba(0, 0, 0, 0.1);
    border-radius: 8px;
    font-size: 0.85rem;
    background: white;
    font-family: inherit;
}

.ocr-transaction-item input:focus,
.ocr-transaction-item select:focus {
    outline: none;
    border-color: #00a8a8;
}

.ocr-learned-badge {
    font-size: 0.7rem;
    padding: 2px 8px;
    border-radius: 10px;
    background: rgba(0, 168, 168, 0.1);
    color: #00a8a8;
    font-weight: 600;
}

.ocr-actions {
    display: flex;
    justify-content: flex-end;
    gap: 10px;
}

/* ========== 認證按鈕 ========== */
.btn-outline {
    padding: 10px 20px;
    background: transparent;
    border: 1.5px solid #00a8a8;
    color: #00a8a8;
    border-radius: 12px;
    font-size: 0.9rem;
    font-weight: 600;
    cursor: pointer;
    font-family: inherit;
    transition: all 0.2s;
}

.btn-outline:hover {
    background: rgba(0, 168, 168, 0.1);
}

.btn-primary {
    padding: 10px 20px;
    background: #00a8a8;
    border: none;
    color: white;
    border-radius: 12px;
    font-size: 0.9rem;
    font-weight: 600;
    cursor: pointer;
    font-family: inherit;
    transition: all 0.2s;
}

.btn-primary:hover {
    background: #008b8b;
    transform: translateY(-1px);
}

/* ========== 側邊欄 ========== */
.sidebar {
    width: 240px;
    background: rgba(255, 255, 255, 0.25);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    border-radius: 24px;
    border: 1px solid rgba(255, 255, 255, 0.3);
    padding: 28px 20px;
    display: flex;
    flex-direction: column;
    flex-shrink: 0;
}

.sidebar-brand {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-bottom: 32px;
    padding: 0 8px;
}

.brand-icon {
    font-size: 1.4rem;
}

.brand-name {
    font-size: 1.1rem;
    font-weight: 700;
    color: #2d3436;
}

.sidebar-nav {
    display: flex;
    flex-direction: column;
    gap: 4px;
    flex: 1;
}

.nav-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 16px;
    border-radius: 14px;
    color: #636e72;
    text-decoration: none;
    font-size: 0.9rem;
    font-weight: 500;
    transition: all 0.2s;
}

.nav-item:hover {
    background: rgba(255, 255, 255, 0.3);
    color: #2d3436;
}

.nav-item.active {
    background: #00a8a8;
    color: white;
    box-shadow: 0 4px 15px rgba(0, 168, 168, 0.3);
}

.nav-divider {
    height: 1px;
    background: rgba(0, 0, 0, 0.08);
    margin: 12px 8px;
}

/* ========== 主內容 ========== */
.main {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow-y: auto;
}

.main-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 28px;
    padding: 0 4px;
}

.welcome-sub {
    font-size: 0.85rem;
    color: #636e72;
    margin-bottom: 4px;
}

.welcome h1 {
    font-size: 1.8rem;
    font-weight: 700;
    color: #2d3436;
}

.header-actions {
    display: flex;
    align-items: center;
    gap: 12px;
}

.icon-btn {
    width: 40px;
    height: 40px;
    border-radius: 12px;
    border: 1px solid rgba(255, 255, 255, 0.4);
    background: rgba(255, 255, 255, 0.2);
    backdrop-filter: blur(10px);
    color: #636e72;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s;
}

.icon-btn:hover {
    background: rgba(255, 255, 255, 0.4);
}

.user-profile {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 6px 14px 6px 6px;
    background: rgba(255, 255, 255, 0.25);
    backdrop-filter: blur(10px);
    border-radius: 14px;
    border: 1px solid rgba(255, 255, 255, 0.3);
}

.user-avatar {
    width: 32px;
    height: 32px;
    border-radius: 10px;
    background: linear-gradient(135deg, #00a8a8, #74b9ff);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.85rem;
    color: white;
    font-weight: 600;
}

.user-name {
    font-size: 0.85rem;
    font-weight: 600;
    color: #2d3436;
}

/* ========== Dashboard Grid ========== */
.dashboard-grid {
    display: grid;
    grid-template-columns: 1.2fr 1fr;
    grid-template-rows: auto auto auto;
    gap: 20px;
}

.card {
    background: rgba(255, 255, 255, 0.35);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    border-radius: 20px;
    border: 1px solid rgba(255, 255, 255, 0.4);
    padding: 24px;
}

.card-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 20px;
}

.card-header h2 {
    font-size: 1rem;
    font-weight: 600;
    color: #2d3436;
}

.link-text {
    font-size: 0.8rem;
    color: #00a8a8;
    text-decoration: none;
    font-weight: 500;
    transition: opacity 0.2s;
}

.link-text:hover {
    opacity: 0.8;
}

.badge-beta {
    font-size: 0.7rem;
    padding: 3px 10px;
    border-radius: 20px;
    background: rgba(255, 165, 2, 0.15);
    color: #ffa502;
    font-weight: 600;
}

/* ========== 上傳區域 ========== */
.upload-card {
    grid-row: span 1;
}

.upload-zone {
    border: 2px dashed rgba(0, 168, 168, 0.3);
    border-radius: 16px;
    padding: 40px 20px;
    text-align: center;
    cursor: pointer;
    transition: all 0.2s;
    background: rgba(0, 168, 168, 0.03);
}

.upload-zone:hover {
    border-color: #00a8a8;
    background: rgba(0, 168, 168, 0.06);
}

.upload-zone.dragover {
    border-color: #00a8a8;
    background: rgba(0, 168, 168, 0.1);
}

.upload-placeholder svg {
    color: #00a8a8;
    margin-bottom: 12px;
}

.upload-placeholder p {
    color: #2d3436;
    font-size: 0.95rem;
    margin-bottom: 6px;
}

.upload-link {
    color: #00a8a8;
    font-weight: 600;
    cursor: pointer;
}

.upload-hint {
    font-size: 0.8rem;
    color: #b2bec3;
}

.upload-progress {
    margin-top: 16px;
}

.progress-bar {
    height: 6px;
    background: rgba(0, 0, 0, 0.06);
    border-radius: 3px;
    overflow: hidden;
    margin-bottom: 8px;
}

.progress-fill {
    height: 100%;
    background: #00a8a8;
    border-radius: 3px;
    transition: width 0.3s;
    width: 0%;
}

.progress-text {
    font-size: 0.8rem;
    color: #636e72;
}

/* ========== 表單卡片 ========== */
.form-card {
    grid-row: span 1;
}

.form-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 14px;
}

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

.form-group label {
    display: block;
    font-size: 0.8rem;
    color: #636e72;
    margin-bottom: 6px;
    font-weight: 500;
}

.form-group input,
.form-group select {
    width: 100%;
    padding: 11px 14px;
    border: 1px solid rgba(0, 0, 0, 0.08);
    border-radius: 12px;
    font-size: 0.9rem;
    background: rgba(255, 255, 255, 0.5);
    font-family: inherit;
    transition: all 0.2s;
    color: #2d3436;
}

.form-group input:focus,
.form-group select:focus {
    outline: none;
    border-color: #00a8a8;
    background: rgba(255, 255, 255, 0.7);
}

.form-group input::placeholder {
    color: #b2bec3;
}

.btn-submit {
    width: 100%;
    padding: 13px;
    background: #00a8a8;
    color: white;
    border: none;
    border-radius: 12px;
    font-size: 0.95rem;
    font-weight: 600;
    cursor: pointer;
    font-family: inherit;
    transition: all 0.2s;
    margin-top: 4px;
}

.btn-submit:hover {
    background: #008b8b;
    transform: translateY(-1px);
    box-shadow: 0 4px 15px rgba(0, 168, 168, 0.3);
}

/* ========== 統計卡片 ========== */
.stats-card {
    display: flex;
    flex-direction: column;
}

.stats-bar {
    height: 8px;
    background: rgba(0, 0, 0, 0.06);
    border-radius: 4px;
    overflow: hidden;
    margin-bottom: 16px;
}

.stats-bar-fill {
    height: 100%;
    background: linear-gradient(90deg, #00a8a8 0%, #ff6b81 100%);
    border-radius: 4px;
    transition: width 0.5s ease;
}

.stats-legend {
    display: flex;
    justify-content: space-around;
    gap: 20px;
}

.legend-item {
    display: flex;
    align-items: center;
    gap: 8px;
}

.legend-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
}

.income-dot {
    background: #00a8a8;
}

.expense-dot {
    background: #ff6b81;
}

.legend-label {
    font-size: 0.8rem;
    color: #636e72;
}

.legend-value {
    font-size: 0.9rem;
    font-weight: 700;
    color: #2d3436;
    margin-left: auto;
}

/* ========== 交易記錄卡片 ========== */
.transactions-card {
    grid-row: span 2;
}

.transactions-table-header {
    display: grid;
    grid-template-columns: 30px 1fr 90px 90px 80px 30px;
    gap: 10px;
    padding: 10px 12px;
    font-size: 0.75rem;
    color: #b2bec3;
    font-weight: 500;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.transactions-list {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.transaction-item {
    display: grid;
    grid-template-columns: 30px 1fr 90px 90px 80px 30px;
    gap: 10px;
    align-items: center;
    padding: 12px;
    border-radius: 12px;
    background: rgba(255, 255, 255, 0.3);
    transition: all 0.2s;
}

.transaction-item:hover {
    background: rgba(255, 255, 255, 0.5);
    transform: translateX(3px);
}

.transaction-rank {
    font-size: 0.85rem;
    font-weight: 600;
    color: #b2bec3;
    text-align: center;
}

.transaction-info {
    display: flex;
    align-items: center;
    gap: 10px;
    min-width: 0;
}

.transaction-icon {
    width: 32px;
    height: 32px;
    border-radius: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.9rem;
    flex-shrink: 0;
}

.transaction-description {
    font-weight: 600;
    font-size: 0.9rem;
    color: #2d3436;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.transaction-category {
    font-size: 0.8rem;
    color: #636e72;
}

.transaction-date {
    font-size: 0.8rem;
    color: #b2bec3;
}

.transaction-amount {
    font-weight: 700;
    font-size: 0.9rem;
    text-align: right;
}

.transaction-amount.income {
    color: #00a8a8;
}

.transaction-amount.expense {
    color: #ff6b81;
}

.btn-delete {
    background: rgba(255, 107, 129, 0.15);
    color: #ff6b81;
    border: none;
    width: 24px;
    height: 24px;
    border-radius: 6px;
    cursor: pointer;
    font-size: 0.75rem;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s;
}

.btn-delete:hover {
    background: rgba(255, 107, 129, 0.3);
}

.empty-state {
    text-align: center;
    color: #b2bec3;
    padding: 40px 0;
    font-size: 0.9rem;
}

/* ========== 數據網格 ========== */
.stats-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 14px;
}

.stat-card {
    background: rgba(255, 255, 255, 0.35);
    backdrop-filter: blur(20px);
    border-radius: 16px;
    border: 1px solid rgba(255, 255, 255, 0.4);
    padding: 18px;
    display: flex;
    align-items: center;
    gap: 14px;
    transition: transform 0.2s;
}

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

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

.stat-info {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.stat-label {
    font-size: 0.75rem;
    color: #636e72;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    font-weight: 500;
}

.stat-value {
    font-size: 1.1rem;
    font-weight: 700;
    color: #2d3436;
}

/* ========== 提醒卡片 ========== */
.reminder-card {
    grid-column: span 1;
    background: linear-gradient(135deg, #00a8a8 0%, #008b8b 100%);
    border: none;
}

.reminder-content {
    display: flex;
    justify-content: space-between;
    align-items: center;
    height: 100%;
}

.reminder-text {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.reminder-label {
    font-size: 0.7rem;
    color: rgba(255, 255, 255, 0.7);
    text-transform: uppercase;
    letter-spacing: 1px;
    font-weight: 500;
}

.reminder-text h3 {
    font-size: 1.1rem;
    color: white;
    font-weight: 600;
    line-height: 1.4;
}

.btn-reminder {
    padding: 8px 16px;
    background: rgba(255, 255, 255, 0.2);
    color: white;
    border: 1px solid rgba(255, 255, 255, 0.3);
    border-radius: 10px;
    font-size: 0.8rem;
    font-weight: 500;
    cursor: pointer;
    font-family: inherit;
    transition: all 0.2s;
    width: fit-content;
}

.btn-reminder:hover {
    background: rgba(255, 255, 255, 0.3);
}

.reminder-decoration {
    font-size: 3rem;
    opacity: 0.3;
}

/* ========== 響應式設計 ========== */
@media (max-width: 1100px) {
    .app {
        flex-direction: column;
        padding: 16px;
    }

    .sidebar {
        width: 100%;
        flex-direction: row;
        padding: 16px 20px;
        align-items: center;
    }

    .sidebar-brand {
        margin-bottom: 0;
        margin-right: 20px;
    }

    .sidebar-nav {
        flex-direction: row;
        flex-wrap: wrap;
        gap: 4px;
    }

    .nav-item span {
        display: none;
    }

    .nav-divider {
        display: none;
    }

    .dashboard-grid {
        grid-template-columns: 1fr;
    }

    .transactions-card {
        grid-row: span 1;
    }

    .stats-grid {
        grid-template-columns: 1fr 1fr;
    }

    .ocr-transaction-item {
        grid-template-columns: 1fr 1fr;
    }
}

@media (max-width: 600px) {
    .main-header {
        flex-direction: column;
        align-items: flex-start;
        gap: 16px;
    }

    .form-row {
        grid-template-columns: 1fr;
    }

    .transactions-table-header,
    .transaction-item {
        grid-template-columns: 1fr 80px 70px;
    }

    .transactions-table-header span:nth-child(1),
    .transaction-item .transaction-rank,
    .transactions-table-header span:nth-child(3),
    .transaction-item .transaction-category,
    .transactions-table-header span:nth-child(6),
    .transaction-item .btn-delete {
        display: none;
    }

    .stats-grid {
        grid-template-columns: 1fr;
    }

    .modal-content {
        padding: 24px;
        width: 95%;
    }

    .ocr-transaction-item {
        grid-template-columns: 1fr;
    }
}
