/* ========================================
   CSS Variables & Reset
   ======================================== */
:root {
    --primary: #6C5CE7;
    --primary-light: #A29BFE;
    --primary-dark: #5A4BD1;
    --success: #00B894;
    --success-light: #55EFC4;
    --danger: #E17055;
    --danger-light: #FAB1A0;
    --warning: #FDCB6E;
    --dark: #2D3436;
    --gray-900: #1a1a2e;
    --gray-800: #2d2d44;
    --gray-700: #404060;
    --gray-600: #6c6c8a;
    --gray-500: #9a9ab0;
    --gray-400: #b8b8cc;
    --gray-300: #d1d1e0;
    --gray-200: #e8e8f0;
    --gray-100: #f4f4f8;
    --white: #ffffff;
    --bg: #F0F0F5;
    --card-bg: #FFFFFF;
    --text-primary: #2D3436;
    --text-secondary: #6c6c8a;
    --shadow-sm: 0 1px 3px rgba(0,0,0,0.08);
    --shadow-md: 0 4px 12px rgba(0,0,0,0.1);
    --shadow-lg: 0 8px 30px rgba(0,0,0,0.12);
    --radius-sm: 8px;
    --radius-md: 12px;
    --radius-lg: 16px;
    --radius-xl: 20px;
    --nav-height: 70px;
    --header-height: auto;
}

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

html {
    font-size: 16px;
    scroll-behavior: smooth;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, sans-serif;
    background: var(--bg);
    color: var(--text-primary);
    line-height: 1.5;
    min-height: 100vh;
    overflow-x: hidden;
    padding-bottom: calc(var(--nav-height) + 20px);
}

/* ========================================
   Header & Balance Card
   ======================================== */
.app-header {
    background: linear-gradient(135deg, var(--primary), var(--primary-dark));
    color: white;
    padding: 16px 20px 24px;
    border-radius: 0 0 var(--radius-xl) var(--radius-xl);
    position: sticky;
    top: 0;
    z-index: 100;
    box-shadow: 0 4px 20px rgba(108, 92, 231, 0.3);
}

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

.app-header h1 {
    font-size: 1.4rem;
    font-weight: 700;
}

.icon-btn {
    background: rgba(255,255,255,0.2);
    border: none;
    color: white;
    width: 40px;
    height: 40px;
    border-radius: 50%;
    font-size: 1.2rem;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.2s;
}

.icon-btn:active {
    background: rgba(255,255,255,0.35);
}

.balance-card {
    text-align: center;
}

.balance-label {
    font-size: 0.85rem;
    opacity: 0.85;
    display: block;
    margin-bottom: 4px;
}

.balance-amount {
    font-size: 2.2rem;
    font-weight: 800;
    letter-spacing: -1px;
    display: block;
    margin-bottom: 16px;
}

.balance-row {
    display: flex;
    justify-content: center;
    gap: 30px;
}

.balance-item {
    display: flex;
    align-items: center;
    gap: 8px;
    background: rgba(255,255,255,0.15);
    padding: 8px 16px;
    border-radius: var(--radius-md);
}

.balance-item .balance-icon {
    font-size: 1.3rem;
}

.balance-item small {
    display: block;
    font-size: 0.7rem;
    opacity: 0.85;
}

.balance-item strong {
    font-size: 0.95rem;
}

/* ========================================
   Views & Navigation
   ======================================== */
.app-content {
    padding: 16px;
    max-width: 600px;
    margin: 0 auto;
}

.view {
    display: none;
    animation: fadeIn 0.3s ease;
}

.view.active {
    display: block;
}

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

.view h2 {
    font-size: 1.3rem;
    margin-bottom: 16px;
    color: var(--text-primary);
}

/* ========================================
   Cards
   ======================================== */
.card {
    background: var(--card-bg);
    border-radius: var(--radius-lg);
    padding: 18px;
    margin-bottom: 14px;
    box-shadow: var(--shadow-sm);
    transition: transform 0.2s, box-shadow 0.2s;
}

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

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

.card-header h3 {
    font-size: 1rem;
    font-weight: 600;
}

/* ========================================
   AI Tips Section
   ======================================== */
.ai-tips-section {
    margin-bottom: 14px;
}

.ai-tips-section h3 {
    font-size: 1rem;
    margin-bottom: 10px;
    color: var(--primary);
}

#aiTipsList {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.ai-tip {
    background: linear-gradient(135deg, #F8F7FF, #EDE8FF);
    border-left: 3px solid var(--primary);
    padding: 12px 14px;
    border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
    font-size: 0.85rem;
    line-height: 1.4;
}

.ai-tip .tip-icon {
    margin-right: 6px;
}

/* ========================================
   Budget Progress
   ======================================== */
.budget-card {
    background: linear-gradient(135deg, #6C5CE7, #A29BFE);
    color: white;
}

.budget-card .card-header h3 {
    color: white;
}

.btn-sm {
    background: rgba(255,255,255,0.2);
    border: none;
    color: white;
    padding: 4px 12px;
    border-radius: var(--radius-sm);
    font-size: 0.75rem;
    cursor: pointer;
    transition: background 0.2s;
}

.btn-sm:active {
    background: rgba(255,255,255,0.35);
}

.progress-bar-wrapper {
    width: 100%;
    height: 10px;
    background: rgba(255,255,255,0.25);
    border-radius: 10px;
    overflow: hidden;
    margin-bottom: 8px;
}

.progress-bar {
    height: 100%;
    background: var(--success-light);
    border-radius: 10px;
    transition: width 0.5s ease, background 0.3s;
    min-width: 0;
}

.progress-bar.warning {
    background: var(--warning);
}

.progress-bar.danger {
    background: #FF7675;
}

.budget-info {
    display: flex;
    justify-content: space-between;
    font-size: 0.8rem;
    opacity: 0.9;
}

/* ========================================
   Projection Card
   ======================================== */
.projection-card {
    background: linear-gradient(135deg, #00B894, #55EFC4);
    color: white;
}

.projection-card h3 {
    color: white;
    margin-bottom: 6px;
}

#projectionText {
    font-size: 0.9rem;
    opacity: 0.95;
}

/* ========================================
   Transactions List
   ======================================== */
.transaction-item {
    display: flex;
    align-items: center;
    padding: 12px 0;
    border-bottom: 1px solid var(--gray-200);
    gap: 12px;
}

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

.tx-icon {
    width: 42px;
    height: 42px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.2rem;
    flex-shrink: 0;
}

.tx-icon.income {
    background: #E8FFF5;
}

.tx-icon.expense {
    background: #FFE8E3;
}

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

.tx-desc {
    font-weight: 600;
    font-size: 0.9rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.tx-meta {
    font-size: 0.75rem;
    color: var(--text-secondary);
}

.tx-amount {
    font-weight: 700;
    font-size: 0.95rem;
    white-space: nowrap;
}

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

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

.tx-delete {
    background: none;
    border: none;
    color: var(--gray-500);
    font-size: 1.1rem;
    cursor: pointer;
    padding: 4px 8px;
    opacity: 0.5;
    transition: opacity 0.2s;
}

.tx-delete:hover, .tx-delete:active {
    opacity: 1;
}

/* ========================================
   Savings Goals
   ======================================== */
.goal-item {
    padding: 14px 0;
    border-bottom: 1px solid var(--gray-200);
}

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

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

.goal-name {
    font-weight: 600;
    font-size: 0.9rem;
}

.goal-amounts {
    font-size: 0.75rem;
    color: var(--text-secondary);
}

.goal-progress-bar {
    width: 100%;
    height: 8px;
    background: var(--gray-200);
    border-radius: 10px;
    overflow: hidden;
    margin-bottom: 4px;
}

.goal-progress-fill {
    height: 100%;
    background: linear-gradient(90deg, var(--primary), var(--primary-light));
    border-radius: 10px;
    transition: width 0.5s ease;
}

.goal-percent {
    font-size: 0.75rem;
    color: var(--text-secondary);
    text-align: right;
}

/* ========================================
   Form Elements
   ======================================== */
.type-toggle {
    display: flex;
    background: var(--gray-200);
    border-radius: var(--radius-md);
    padding: 4px;
    margin-bottom: 20px;
}

.toggle-btn {
    flex: 1;
    padding: 12px;
    border: none;
    background: transparent;
    border-radius: var(--radius-sm);
    font-size: 0.95rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s;
    color: var(--text-secondary);
}

.toggle-btn.active {
    background: var(--primary);
    color: white;
    box-shadow: var(--shadow-sm);
}

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

.form-group label {
    display: block;
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--text-secondary);
    margin-bottom: 6px;
}

.form-group input[type="number"],
.form-group input[type="text"],
.form-group input[type="date"],
.form-group select {
    width: 100%;
    padding: 14px 16px;
    border: 2px solid var(--gray-200);
    border-radius: var(--radius-md);
    font-size: 1rem;
    background: var(--white);
    color: var(--text-primary);
    transition: border-color 0.2s, box-shadow 0.2s;
    -webkit-appearance: none;
}

.form-group input:focus,
.form-group select:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(108, 92, 231, 0.15);
}

.checkbox-label {
    display: flex !important;
    align-items: center;
    gap: 10px;
    cursor: pointer;
    font-size: 0.9rem !important;
    color: var(--text-primary) !important;
    padding: 8px 0;
}

.checkbox-label input[type="checkbox"] {
    width: 20px;
    height: 20px;
    accent-color: var(--primary);
}

/* Quick Amount Buttons */
.quick-amounts {
    display: flex;
    gap: 8px;
    margin-bottom: 20px;
    overflow-x: auto;
    padding-bottom: 4px;
    -webkit-overflow-scrolling: touch;
}

.quick-amt-btn {
    flex-shrink: 0;
    padding: 10px 18px;
    border: 2px solid var(--gray-300);
    background: var(--white);
    border-radius: var(--radius-md);
    font-size: 0.9rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s;
}

.quick-amt-btn:active, .quick-amt-btn.active {
    border-color: var(--primary);
    background: var(--primary);
    color: white;
}

/* Buttons */
.btn-primary {
    width: 100%;
    padding: 16px;
    background: linear-gradient(135deg, var(--primary), var(--primary-dark));
    color: white;
    border: none;
    border-radius: var(--radius-md);
    font-size: 1rem;
    font-weight: 700;
    cursor: pointer;
    transition: transform 0.2s, box-shadow 0.2s;
}

.btn-primary:active {
    transform: scale(0.97);
    box-shadow: var(--shadow-sm);
}

.btn-large {
    padding: 18px;
    font-size: 1.05rem;
}

.btn-secondary {
    width: 100%;
    padding: 14px;
    background: var(--gray-200);
    color: var(--text-primary);
    border: none;
    border-radius: var(--radius-md);
    font-size: 0.9rem;
    font-weight: 600;
    cursor: pointer;
    margin-bottom: 10px;
    transition: background 0.2s;
}

.btn-secondary:active {
    background: var(--gray-300);
}

.btn-danger {
    width: 100%;
    padding: 14px;
    background: #FFE8E3;
    color: var(--danger);
    border: none;
    border-radius: var(--radius-md);
    font-size: 0.9rem;
    font-weight: 600;
    cursor: pointer;
    margin-bottom: 10px;
}

.btn-full {
    width: 100%;
}

.btn-small {
    padding: 10px 20px;
    background: var(--primary);
    color: white;
    border: none;
    border-radius: var(--radius-sm);
    font-size: 0.85rem;
    font-weight: 600;
    cursor: pointer;
}

/* ========================================
   Analytics View
   ======================================== */
.period-selector {
    display: flex;
    gap: 6px;
    margin-bottom: 16px;
    background: var(--gray-200);
    padding: 4px;
    border-radius: var(--radius-md);
}

.period-btn {
    flex: 1;
    padding: 10px;
    border: none;
    background: transparent;
    border-radius: var(--radius-sm);
    font-size: 0.85rem;
    font-weight: 600;
    cursor: pointer;
    color: var(--text-secondary);
    transition: all 0.2s;
}

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

.chart-card {
    margin-bottom: 14px;
}

.chart-card canvas {
    max-height: 250px;
}

.breakdown-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 10px 0;
    border-bottom: 1px solid var(--gray-200);
}

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

.breakdown-cat {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 0.9rem;
}

.breakdown-dot {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    flex-shrink: 0;
}

.breakdown-amount {
    font-weight: 700;
    font-size: 0.9rem;
}

.breakdown-percent {
    font-size: 0.75rem;
    color: var(--text-secondary);
    margin-left: 6px;
}

/* AI Analysis Card */
.ai-analysis-card {
    background: linear-gradient(135deg, #F8F7FF, #EDE8FF);
    border: 1px solid rgba(108, 92, 231, 0.15);
}

#aiAnalysisContent p {
    font-size: 0.85rem;
    line-height: 1.6;
    margin-bottom: 8px;
    color: var(--text-primary);
}

/* ========================================
   Settings View
   ======================================== */
.settings-card h3 {
    font-size: 0.95rem;
    margin-bottom: 12px;
}

.settings-card p {
    font-size: 0.85rem;
    color: var(--text-secondary);
    margin-bottom: 4px;
}

/* ========================================
   Bottom Navigation
   ======================================== */
.bottom-nav {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    height: var(--nav-height);
    background: var(--white);
    display: flex;
    justify-content: space-around;
    align-items: center;
    box-shadow: 0 -2px 20px rgba(0,0,0,0.08);
    z-index: 1000;
    padding-bottom: env(safe-area-inset-bottom, 0);
}

.nav-btn {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 2px;
    background: none;
    border: none;
    color: var(--gray-500);
    cursor: pointer;
    padding: 8px 16px;
    transition: all 0.2s;
    position: relative;
}

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

.nav-btn .nav-icon {
    font-size: 1.4rem;
    transition: transform 0.2s;
}

.nav-btn.active .nav-icon {
    transform: scale(1.15);
}

.nav-label {
    font-size: 0.65rem;
    font-weight: 600;
}

/* ========================================
   Modal
   ======================================== */
.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.5);
    z-index: 2000;
    display: none;
    align-items: flex-end;
    justify-content: center;
    animation: fadeInOverlay 0.2s ease;
}

.modal-overlay.active {
    display: flex;
}

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

.modal {
    background: var(--white);
    border-radius: var(--radius-xl) var(--radius-xl) 0 0;
    width: 100%;
    max-width: 600px;
    max-height: 80vh;
    overflow-y: auto;
    padding: 24px;
    animation: slideUp 0.3s ease;
}

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

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

.modal-header h3 {
    font-size: 1.1rem;
}

.modal-close {
    background: var(--gray-200);
    border: none;
    width: 36px;
    height: 36px;
    border-radius: 50%;
    font-size: 1.3rem;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
}

/* ========================================
   Toast Notification
   ======================================== */
.toast {
    position: fixed;
    top: 20px;
    left: 50%;
    transform: translateX(-50%) translateY(-100px);
    background: var(--dark);
    color: white;
    padding: 14px 24px;
    border-radius: var(--radius-md);
    font-size: 0.9rem;
    font-weight: 600;
    z-index: 3000;
    transition: transform 0.3s ease;
    box-shadow: var(--shadow-lg);
    max-width: 90%;
    text-align: center;
}

.toast.show {
    transform: translateX(-50%) translateY(0);
}

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

.empty-state .empty-icon {
    font-size: 3rem;
    margin-bottom: 10px;
}

.empty-state p {
    font-size: 0.9rem;
}

/* ========================================
   Responsive (Desktop)
   ======================================== */
@media (min-width: 768px) {
    .app-content {
        padding: 24px;
    }

    .balance-amount {
        font-size: 2.8rem;
    }

    .modal {
        border-radius: var(--radius-xl);
        margin-bottom: 10vh;
    }
}

/* ========================================
   Scrollbar Styling
   ======================================== */
::-webkit-scrollbar {
    width: 4px;
}

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

::-webkit-scrollbar-thumb {
    background: var(--gray-300);
    border-radius: 10px;
}

/* ========================================
   Animations
   ======================================== */
@keyframes pulse {
    0%, 100% { transform: scale(1); }
    50% { transform: scale(1.05); }
}

.pulse {
    animation: pulse 2s infinite;
}

/* Category colors for breakdown */
.cat-mat { background: #E17055; }
.cat-hyra { background: #6C5CE7; }
.cat-transport { background: #0984E3; }
.cat-nöje { background: #FDCB6E; }
.cat-shopping { background: #E84393; }
.cat-försäkring { background: #00B894; }
.cat-lån { background: #D63031; }
/cat-husgeråd { background: #A29BFE; }
.cat-restaurang { background: #FAB1A0; }
.cat-träning { background: #55EFC4; }
.cat-other { background: #B2BEC3; }

/* Income category */
.income-cat-salary { background: #00B894; }
.income-cat-freelance { background: #0984E3; }
.income-cat-gift { background: #FDCB6E; }
.income-cat-other-income { background: #A29BFE; }

/* No data placeholder */
.no-data-chart {
    display: flex;
    align-items: center;
    justify-content: center;
    height: 200px;
    color: var(--gray-500);
    font-size: 0.9rem;
}
