/* ========================================
   SMART BUDGET — Mobile-First CSS
   ======================================== */

/* --- CSS Variables --- */
:root {
    --bg-primary: #0f1117;
    --bg-secondary: #1a1d2e;
    --bg-card: #222640;
    --bg-input: #2a2f4a;
    --text-primary: #ffffff;
    --text-secondary: #8b90a8;
    --text-muted: #5c6178;
    --accent-green: #00d4aa;
    --accent-green-dim: rgba(0, 212, 170, 0.15);
    --accent-red: #ff6b8a;
    --accent-red-dim: rgba(255, 107, 138, 0.15);
    --accent-blue: #4dabf7;
    --accent-blue-dim: rgba(77, 171, 247, 0.15);
    --accent-purple: #b197fc;
    --accent-orange: #ffa94d;
    --accent-yellow: #ffd43b;
    --border-color: rgba(255, 255, 255, 0.06);
    --shadow-sm: 0 2px 8px rgba(0, 0, 0, 0.2);
    --shadow-md: 0 4px 16px rgba(0, 0, 0, 0.3);
    --shadow-lg: 0 8px 32px rgba(0, 0, 0, 0.4);
    --radius-sm: 10px;
    --radius-md: 14px;
    --radius-lg: 20px;
    --nav-height: 72px;
    --header-height: auto;
}

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

html {
    font-size: 16px;
    -webkit-tap-highlight-color: transparent;
    scroll-behavior: smooth;
}

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

/* --- Scrollbar --- */
::-webkit-scrollbar { width: 4px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--text-muted); border-radius: 4px; }

/* ===== HEADER ===== */
.app-header {
    padding: 16px 20px 8px;
    position: sticky;
    top: 0;
    z-index: 50;
    background: linear-gradient(180deg, var(--bg-primary) 70%, transparent);
}

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

.app-header h1 {
    font-size: 1.4rem;
    font-weight: 700;
    letter-spacing: -0.5px;
}

.icon-btn {
    background: var(--bg-card);
    border: none;
    color: var(--text-secondary);
    width: 42px;
    height: 42px;
    border-radius: 12px;
    font-size: 1.3rem;
    cursor: pointer;
    transition: all 0.2s ease;
}

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

/* --- Balance Card --- */
.balance-card {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    border-radius: var(--radius-lg);
    padding: 24px;
    box-shadow: var(--shadow-md), 0 0 40px rgba(102, 126, 234, 0.15);
    position: relative;
    overflow: hidden;
}

.balance-card::before {
    content: '';
    position: absolute;
    top: -50%;
    right: -30%;
    width: 200px;
    height: 200px;
    background: rgba(255, 255, 255, 0.08);
    border-radius: 50%;
}

.balance-card::after {
    content: '';
    position: absolute;
    bottom: -40%;
    left: -20%;
    width: 160px;
    height: 160px;
    background: rgba(255, 255, 255, 0.05);
    border-radius: 50%;
}

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

.balance-card .amount {
    font-size: 2.2rem;
    font-weight: 800;
    letter-spacing: -1px;
    display: block;
    position: relative;
    z-index: 1;
}

.balance-row {
    display: flex;
    justify-content: space-between;
    margin-top: 20px;
    padding-top: 16px;
    border-top: 1px solid rgba(255, 255, 255, 0.15);
    position: relative;
    z-index: 1;
}

.income-box, .expense-box {
    flex: 1;
    text-align: center;
}

.mini-label {
    font-size: 0.72rem;
    opacity: 0.75;
    display: block;
    margin-bottom: 2px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.mini-amount {
    font-size: 1.05rem;
    font-weight: 700;
}

.income-text { color: #69f0ae; }
.expense-text { color: #ff8a80; }

.divider {
    width: 1px;
    background: rgba(255, 255, 255, 0.15);
    margin: 0 16px;
}

/* ===== BOTTOM NAVIGATION ===== */
.bottom-nav {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    height: var(--nav-height);
    background: rgba(26, 29, 46, 0.95);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    border-top: 1px solid var(--border-color);
    display: flex;
    justify-content: space-around;
    align-items: center;
    z-index: 100;
    padding-bottom: env(safe-area-inset-bottom, 0);
}

.nav-btn {
    background: none;
    border: none;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 3px;
    cursor: pointer;
    padding: 8px 12px;
    transition: all 0.25s ease;
    position: relative;
    -webkit-tap-highlight-color: transparent;
}

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

.nav-btn .nav-label {
    font-size: 0.65rem;
    color: var(--text-muted);
    font-weight: 500;
    transition: color 0.25s ease;
}

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

.nav-btn.active .nav-label {
    color: var(--accent-blue);
    font-weight: 700;
}

.nav-btn.active::before {
    content: '';
    position: absolute;
    top: -1px;
    left: 50%;
    transform: translateX(-50%);
    width: 24px;
    height: 3px;
    background: var(--accent-blue);
    border-radius: 0 0 4px 4px;
}

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

/* ===== MAIN CONTENT & TABS ===== */
#mainContent {
    padding: 12px 16px;
    max-width: 600px;
    margin: 0 auto;
}

.tab-content {
    display: none;
    animation: fadeInUp 0.35s ease;
}

.tab-content.active {
    display: block;
}

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

/* ===== CARDS ===== */
.card {
    background: var(--bg-card);
    border-radius: var(--radius-md);
    padding: 20px;
    margin-bottom: 14px;
    box-shadow: var(--shadow-sm);
    border: 1px solid var(--border-color);
}

.card h3 {
    font-size: 1rem;
    font-weight: 700;
    margin-bottom: 14px;
    display: flex;
    align-items: center;
    gap: 8px;
}

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

/* --- Forecast Card --- */
.forecast-card {
    background: linear-gradient(135deg, rgba(77, 171, 247, 0.12), rgba(177, 151, 252, 0.12));
    border-color: rgba(77, 171, 247, 0.2);
}

.forecast-card h3 { color: var(--accent-blue); }

#forecastText {
    font-size: 0.9rem;
    color: var(--text-secondary);
    margin-bottom: 10px;
}

.forecast-details {
    display: flex;
    gap: 12px;
    flex-wrap: wrap;
}

.forecast-item {
    background: rgba(255, 255, 255, 0.06);
    border-radius: var(--radius-sm);
    padding: 10px 14px;
    flex: 1;
    min-width: 100px;
}

.forecast-item .fi-label {
    font-size: 0.7rem;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.forecast-item .fi-value {
    font-size: 1.1rem;
    font-weight: 700;
    margin-top: 2px;
}

/* --- Chart Card --- */
.chart-card canvas {
    max-height: 260px;
    width: 100% !important;
}

/* --- Transactions List --- */
.transaction-item {
    display: flex;
    align-items: center;
    padding: 14px 0;
    border-bottom: 1px solid var(--border-color);
    animation: slideIn 0.3s ease;
    gap: 12px;
}

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

@keyframes slideIn {
    from { opacity: 0; transform: translateX(-20px); }
    to   { opacity: 1; transform: translateX(0); }
}

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

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

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

.tx-meta {
    font-size: 0.75rem;
    color: var(--text-muted);
    margin-top: 2px;
}

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

.tx-amount.income { color: var(--accent-green); }
.tx-amount.expense { color: var(--accent-red); }

.tx-delete {
    background: none;
    border: none;
    color: var(--text-muted);
    font-size: 1.2rem;
    cursor: pointer;
    padding: 8px;
    opacity: 0.5;
    transition: all 0.2s ease;
}

.tx-delete:hover, .tx-delete:active {
    opacity: 1;
    color: var(--accent-red);
}

.empty-state {
    text-align: center;
    padding: 40px 20px;
    color: var(--text-muted);
}

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

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

/* --- Monthly Selector --- */
.month-select {
    background: var(--bg-input);
    border: 1px solid var(--border-color);
    color: var(--text-primary);
    padding: 8px 12px;
    border-radius: var(--radius-sm);
    font-size: 0.9rem;
    margin-bottom: 14px;
    width: 100%;
}

.month-summary-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 10px;
}

.ms-item {
    background: rgba(255, 255, 255, 0.04);
    border-radius: var(--radius-sm);
    padding: 12px;
    text-align: center;
}

.ms-label {
    font-size: 0.7rem;
    color: var(--text-muted);
    text-transform: uppercase;
}

.ms-value {
    font-size: 1.15rem;
    font-weight: 700;
    margin-top: 4px;
}

/* ===== ADD TRANSACTION TAB ===== */
.type-toggle {
    display: flex;
    background: var(--bg-input);
    border-radius: var(--radius-sm);
    padding: 4px;
    margin-bottom: 20px;
}

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

.toggle-btn.active {
    background: var(--accent-blue);
    color: #fff;
    box-shadow: 0 2px 10px rgba(77, 171, 247, 0.3);
}

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

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

.form-group input,
.form-group select {
    width: 100%;
    padding: 14px 16px;
    background: var(--bg-input);
    border: 2px solid transparent;
    border-radius: var(--radius-sm);
    color: var(--text-primary);
    font-size: 1rem;
    transition: all 0.2s ease;
    -webkit-appearance: none;
}

.form-group input:focus,
.form-group select:focus {
    outline: none;
    border-color: var(--accent-blue);
    background: rgba(77, 171, 247, 0.08);
}

.form-group input::placeholder {
    color: var(--text-muted);
}

/* --- Quick Add Buttons --- */
.quick-add {
    margin-bottom: 20px;
}

.quick-label {
    font-size: 0.8rem;
    color: var(--text-secondary);
    display: block;
    margin-bottom: 8px;
}

.quick-buttons {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
}

.quick-btn {
    padding: 10px 16px;
    border: 1px solid var(--border-color);
    background: rgba(255, 255, 255, 0.04);
    color: var(--text-secondary);
    border-radius: 20px;
    font-size: 0.82rem;
    cursor: pointer;
    transition: all 0.2s ease;
}

.quick-btn:hover, .quick-btn:active {
    background: rgba(77, 171, 247, 0.15);
    border-color: var(--accent-blue);
    color: var(--accent-blue);
}

/* --- Buttons --- */
.btn-primary {
    width: 100%;
    padding: 16px;
    background: linear-gradient(135deg, #4dabf7, #339af0);
    border: none;
    color: #fff;
    font-size: 1rem;
    font-weight: 700;
    border-radius: var(--radius-sm);
    cursor: pointer;
    transition: all 0.2s ease;
    box-shadow: 0 4px 15px rgba(77, 171, 247, 0.3);
}

.btn-primary:active {
    transform: scale(0.97);
    box-shadow: 0 2px 8px rgba(77, 171, 247, 0.2);
}

.btn-secondary {
    width: 100%;
    padding: 16px;
    background: var(--bg-input);
    border: 1px solid var(--border-color);
    color: var(--text-primary);
    font-size: 1rem;
    font-weight: 600;
    border-radius: var(--radius-sm);
    cursor: pointer;
    transition: all 0.2s ease;
}

.btn-secondary:active { transform: scale(0.97); }

.btn-large { margin-top: 8px; }

.btn-small {
    padding: 10px 20px;
    width: auto;
    font-size: 0.85rem;
}

.small-btn {
    padding: 6px 14px;
    border-radius: 8px;
    border: none;
    font-size: 0.78rem;
    cursor: pointer;
    font-weight: 600;
    transition: all 0.2s ease;
}

.small-btn.danger {
    background: var(--accent-red-dim);
    color: var(--accent-red);
}

/* --- AI Card --- */
.ai-card {
    background: linear-gradient(135deg, rgba(177, 151, 252, 0.1), rgba(77, 171, 247, 0.1));
    border-color: rgba(177, 151, 252, 0.2);
}

.ai-card h3 { color: var(--accent-purple); }

.ai-form {
    display: flex;
    gap: 8px;
    margin-top: 12px;
}

.ai-form input {
    flex: 1;
    padding: 12px 14px;
    background: var(--bg-input);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    color: var(--text-primary);
    font-size: 0.9rem;
}

.ai-form input:focus {
    outline: none;
    border-color: var(--accent-purple);
}

#aiResult {
    margin-top: 12px;
    padding: 14px;
    background: rgba(255, 255, 255, 0.05);
    border-radius: var(--radius-sm);
    font-size: 0.88rem;
    display: none;
}

#aiResult.show { display: block; animation: fadeInUp 0.3s ease; }

/* ===== BUDGET TAB ===== */
.budget-form .btn-primary { margin-top: 12px; }

.category-budget-item {
    padding: 14px 0;
    border-bottom: 1px solid var(--border-color);
}

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

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

.cbi-name {
    font-weight: 600;
    font-size: 0.92rem;
    display: flex;
    align-items: center;
    gap: 8px;
}

.cbi-amounts {
    text-align: right;
}

.cbi-spent {
    font-weight: 700;
    font-size: 0.95rem;
}

.cbi-budget {
    font-size: 0.72rem;
    color: var(--text-muted);
}

.progress-bar-bg {
    width: 100%;
    height: 8px;
    background: rgba(255, 255, 255, 0.06);
    border-radius: 4px;
    overflow: hidden;
}

.progress-bar-fill {
    height: 100%;
    border-radius: 4px;
    transition: width 0.6s ease;
    min-width: 0;
}

.cbi-input-row {
    display: flex;
    gap: 8px;
    margin-top: 8px;
    align-items: center;
}

.cbi-input-row input {
    width: 100px;
    padding: 6px 10px;
    background: var(--bg-input);
    border: 1px solid var(--border-color);
    border-radius: 6px;
    color: var(--text-primary);
    font-size: 0.85rem;
}

.cbi-input-row input:focus {
    outline: none;
    border-color: var(--accent-blue);
}

.cbi-save-btn {
    padding: 6px 12px;
    background: var(--accent-blue-dim);
    color: var(--accent-blue);
    border: none;
    border-radius: 6px;
    font-size: 0.78rem;
    cursor: pointer;
    font-weight: 600;
}

/* --- Budget Chart --- */
.budget-overview-card canvas {
    max-height: 240px;
}

#budgetSummary {
    margin-top: 14px;
}

.bs-item {
    display: flex;
    justify-content: space-between;
    padding: 8px 0;
    font-size: 0.88rem;
    border-bottom: 1px solid var(--border-color);
}

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

/* ===== GOALS TAB ===== */
.goal-form .btn-primary { margin-top: 12px; }

.goal-item {
    background: var(--bg-card);
    border-radius: var(--radius-md);
    padding: 20px;
    margin-bottom: 14px;
    box-shadow: var(--shadow-sm);
    border: 1px solid var(--border-color);
}

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

.goal-name {
    font-weight: 700;
    font-size: 1.05rem;
    display: flex;
    align-items: center;
    gap: 8px;
}

.goal-delete-btn {
    background: none;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    font-size: 1.1rem;
    padding: 4px;
}

.goal-progress-text {
    display: flex;
    justify-content: space-between;
    font-size: 0.82rem;
    color: var(--text-secondary);
    margin-bottom: 8px;
}

.goal-progress-bar-bg {
    width: 100%;
    height: 12px;
    background: rgba(255, 255, 255, 0.06);
    border-radius: 6px;
    overflow: hidden;
    margin-bottom: 14px;
}

.goal-progress-bar-fill {
    height: 100%;
    border-radius: 6px;
    transition: width 0.8s ease;
    background: linear-gradient(90deg, var(--accent-green), #69f0ae);
}

.goal-add-row {
    display: flex;
    gap: 8px;
}

.goal-add-row input {
    flex: 1;
    padding: 10px 14px;
    background: var(--bg-input);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    color: var(--text-primary);
    font-size: 0.9rem;
}

.goal-add-row input:focus {
    outline: none;
    border-color: var(--accent-green);
}

.goal-add-btn {
    padding: 10px 20px;
    background: var(--accent-green-dim);
    color: var(--accent-green);
    border: none;
    border-radius: var(--radius-sm);
    font-weight: 700;
    cursor: pointer;
    transition: all 0.2s ease;
}

.goal-add-btn:active { transform: scale(0.95); }

/* ===== TIPS TAB ===== */
.tips-card p {
    color: var(--text-secondary);
    font-size: 0.88rem;
    margin-bottom: 14px;
}

.tip-item {
    background: rgba(255, 255, 255, 0.04);
    border-radius: var(--radius-sm);
    padding: 16px;
    margin-bottom: 10px;
    border-left: 3px solid var(--accent-blue);
}

.tip-item.warning { border-left-color: var(--accent-orange); }
.tip-item.danger  { border-left-color: var(--accent-red); }
.tip-item.success { border-left-color: var(--accent-green); }

.tip-title {
    font-weight: 700;
    font-size: 0.92rem;
    margin-bottom: 4px;
}

.tip-desc {
    font-size: 0.82rem;
    color: var(--text-secondary);
    line-height: 1.5;
}

/* --- Stats Card --- */
.stats-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 10px;
}

.stat-item {
    background: rgba(255, 255, 255, 0.04);
    border-radius: var(--radius-sm);
    padding: 16px 12px;
    text-align: center;
}

.stat-value {
    font-size: 1.3rem;
    font-weight: 800;
}

.stat-label {
    font-size: 0.72rem;
    color: var(--text-muted);
    margin-top: 4px;
    text-transform: uppercase;
}

/* ===== MODAL ===== */
.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.7);
    backdrop-filter: blur(8px);
    z-index: 200;
    display: none;
    align-items: flex-end;
    justify-content: center;
}

.modal-overlay.show {
    display: flex;
    animation: fadeIn 0.25s ease;
}

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

.modal-content {
    background: var(--bg-secondary);
    border-radius: var(--radius-lg) var(--radius-lg) 0 0;
    padding: 24px 20px 36px;
    width: 100%;
    max-width: 500px;
    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; }

.close-btn {
    background: var(--bg-input);
    border: none;
    color: var(--text-secondary);
    width: 36px;
    height: 36px;
    border-radius: 50%;
    font-size: 1.2rem;
    cursor: pointer;
}

/* --- Toast Notification --- */
.toast {
    position: fixed;
    top: 20px;
    left: 50%;
    transform: translateX(-50%) translateY(-100px);
    background: var(--bg-card);
    color: var(--text-primary);
    padding: 14px 24px;
    border-radius: var(--radius-sm);
    box-shadow: var(--shadow-lg);
    z-index: 300;
    font-size: 0.9rem;
    font-weight: 600;
    transition: transform 0.4s cubic-bezier(0.175, 0.885, 0.32, 1.275);
    border: 1px solid var(--border-color);
}

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

.toast.success { border-left: 4px solid var(--accent-green); }
.toast.error   { border-left: 4px solid var(--accent-red); }

/* --- Responsive Tweaks --- */
@media (min-width: 600px) {
    #mainContent { padding: 20px; }
    .card { padding: 24px; }
}

/* --- Category Colors --- */
.cat-mat       { background: rgba(255, 179, 71, 0.15); }
.cat-hyra      { background: rgba(77, 171, 247, 0.15); }
.cat-transport { background: rgba(177, 151, 252, 0.15); }
.cat-nöje      { background: rgba(255, 107, 138, 0.15); }
.cat-shopping  { background: rgba(255, 212, 59, 0.15); }
/cat-hus       { background: rgba(129, 230, 217, 0.15); }
.cat-försäkring{ background: rgba(161, 196, 253, 0.15); }
.cat-sparande  { background: rgba(0, 212, 170, 0.15); }
.cat-lön       { background: rgba(0, 212, 170, 0.15); }
.cat-frikort   { background: rgba(255, 183, 77, 0.15); }
.cat-other     { background: rgba(143, 144, 168, 0.15); }

/* Category progress bar colors */
.pb-green  { background: var(--accent-green); }
.pb-blue   { background: var(--accent-blue); }
.pb-purple { background: var(--accent-purple); }
.pb-orange { background: var(--accent-orange); }
.pb-red    { background: var(--accent-red); }
