/* ============================================
   Finanse — HabitOS Design System
   ============================================ */

:root {
    --text-main: #1A1A1A;
    --text-muted: #666666;
    --card-bg: #FFFFFF;
    --border-color: rgba(0,0,0,0.06);
    --safe-top: env(safe-area-inset-top);
    --safe-bottom: env(safe-area-inset-bottom);

    /* Category colors */
    --cat-potrzebne: #0d7c66;
    --cat-zachcianki: #e8a838;
    --cat-niepotrzebne: #d94452;
    --cat-zdrowie: #3b82f6;
    --cat-samochod: #8b5cf6;
    --cat-podroze: #f97316;
    --cat-subskrypcje: #ec4899;
    --cat-jedzenie: #10b981;
    --cat-agatka: #e11d48;
    --cat-inne: #6b7280;
}

*, *::before, *::after {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    max-width: 100%;
    overflow-wrap: anywhere;
    word-break: break-word;
}
/* Elements that need their own width (progress bars etc.) */
.cat-bar-fill, .savings-progress-fill, [style*="width:"], input[type="range"] { max-width: none; }

/* === HORIZONTAL LOCK === */
html {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    overflow: hidden;
    overscroll-behavior: none;
    touch-action: pan-y;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    background: linear-gradient(135deg, #EFE8D6 0%, #D5D1EC 100%);
    background-attachment: fixed;
    color: var(--text-main);
    margin: 0;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    height: 100dvh;
    overflow: hidden;
    overscroll-behavior: none;
    -webkit-font-smoothing: antialiased;
    -webkit-tap-highlight-color: transparent;
}

/* --- BACKGROUND NOISE --- */
.noise-overlay {
    position: fixed;
    inset: 0;
    pointer-events: none;
    z-index: 50;
    opacity: 0.05;
    background-image: url("data:image/svg+xml,%3Csvg viewBox='0 0 200 200' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='noiseFilter'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.8' numOctaves='3' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23noiseFilter)'/%3E%3C/svg%3E");
}

#app-container {
    display: flex;
    width: 100%;
    height: 100%;
    position: relative;
    z-index: 1;
    overflow: hidden;
}

/* --- CARDS --- */
.raw-card {
    background: var(--card-bg);
    border: 1px solid var(--border-color);
    border-radius: 14px;
    box-shadow: 0 2px 8px rgba(0,0,0,0.02);
    transition: box-shadow 0.2s ease, border-color 0.2s ease;
    overflow: hidden;
    min-width: 0;
}

.raw-card:hover {
    box-shadow: 0 4px 12px rgba(0,0,0,0.04);
    border-color: rgba(0,0,0,0.1);
}

/* --- SIDEBAR --- */
.sidebar {
    background: rgba(255,255,255,0.4);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    border-right: 1px solid rgba(0,0,0,0.08);
}

.sidebar-link {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 10px 14px;
    border-radius: 8px;
    color: var(--text-muted);
    font-weight: 500;
    font-size: 14px;
    transition: all 0.15s ease;
    cursor: pointer;
}

.sidebar-link:hover { color: var(--text-main); background: rgba(0,0,0,0.03); }
.sidebar-link.active { background: #FFFFFF; color: black; font-weight: 600; box-shadow: 0 2px 4px rgba(0,0,0,0.03); }

/* --- NAV PILL (Mobile) --- */
.nav-pill-container {
    position: fixed;
    bottom: 16px;
    left: 0;
    right: 0;
    display: flex;
    justify-content: center;
    z-index: 100;
    pointer-events: none;
    padding-bottom: var(--safe-bottom);
    padding-left: 8px;
    padding-right: 8px;
}

.nav-pill {
    background: rgba(255, 255, 255, 0.85);
    backdrop-filter: blur(16px);
    -webkit-backdrop-filter: blur(16px);
    border: 1px solid rgba(255, 255, 255, 0.6);
    border-radius: 999px;
    padding: 5px 6px;
    display: flex;
    gap: 2px;
    box-shadow: 0 4px 6px -1px rgba(0,0,0,0.05), 0 10px 15px -3px rgba(0,0,0,0.05), 0 0 0 1px rgba(0,0,0,0.02);
    pointer-events: auto;
}

.nav-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    width: 38px;
    height: 38px;
    border-radius: 50%;
    color: #9CA3AF;
    transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
    cursor: pointer;
    flex-shrink: 0;
}

.nav-item.active {
    color: #1A1A1A;
    background: #FFFFFF;
    box-shadow: 0 2px 8px rgba(0,0,0,0.08);
}

.nav-item i { transition: transform 0.2s; }
.nav-item.active i { transform: scale(1.1); stroke-width: 2.5px; }

/* --- SCROLL & LAYOUT --- */
.scroll-area {
    flex: 1;
    width: 100%;
    max-width: 100%;
    overflow-y: auto;
    overflow-x: hidden;
    overscroll-behavior-x: none;
    touch-action: pan-y;
    scrollbar-width: none;
    -ms-overflow-style: none;
    -webkit-overflow-scrolling: touch;
}
.scroll-area::-webkit-scrollbar { display: none; }

.content-pad {
    width: 100%;
    max-width: 100%;
    padding-bottom: calc(90px + var(--safe-bottom));
    padding-left: 1rem;
    padding-right: 1rem;
    overflow: hidden;
    word-break: break-word;
}

@media (min-width: 768px) {
    .content-pad {
        padding-left: 3rem;
        padding-right: 3rem;
        padding-bottom: 3rem;
        max-width: 900px;
        margin: 0 auto;
    }
    .raw-card {
        border-radius: 20px;
    }
}

/* --- TYPOGRAPHY --- */
.text-header { font-weight: 600; letter-spacing: -0.02em; }
.text-label { font-size: 11px; text-transform: uppercase; letter-spacing: 0.04em; color: var(--text-muted); font-weight: 600; }

/* --- FAB --- */
.fab-btn {
    position: fixed;
    bottom: calc(80px + var(--safe-bottom));
    right: 16px;
    width: 48px;
    height: 48px;
    border-radius: 50%;
    background-color: #1A1A1A;
    color: white;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 4px 12px rgba(0,0,0,0.15);
    transition: transform 0.2s;
    cursor: pointer;
    z-index: 90;
}
.fab-btn:active { transform: scale(0.95); }

/* --- ANIMATIONS --- */
.fade-in { animation: fadeIn 0.4s cubic-bezier(0.2, 0.8, 0.2, 1) forwards; opacity: 0; }
@keyframes fadeIn { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: translateY(0); } }

.view-section { display: none; overflow: hidden; width: 100%; max-width: 100%; }
.view-section.active { display: block; }

/* --- HERO LEFT BADGE --- */
.hero-left-positive { color: #0d7c66; background: rgba(13,124,102,0.1); }
.hero-left-negative { color: #d94452; background: rgba(217,68,82,0.1); }

/* --- CATEGORY BARS --- */
.cat-bar-track {
    flex: 1;
    height: 6px;
    background: rgba(0,0,0,0.05);
    border-radius: 3px;
    overflow: hidden;
    min-width: 0;
}

.cat-bar-fill {
    height: 100%;
    border-radius: 3px;
    transition: width 0.6s cubic-bezier(0.16, 1, 0.3, 1);
    min-width: 2px;
}

.cat-bar-fill[data-cat="potrzebne"]    { background: var(--cat-potrzebne); }
.cat-bar-fill[data-cat="zachcianki"]   { background: var(--cat-zachcianki); }
.cat-bar-fill[data-cat="niepotrzebne"] { background: var(--cat-niepotrzebne); }
.cat-bar-fill[data-cat="zdrowie"]      { background: var(--cat-zdrowie); }
.cat-bar-fill[data-cat="samochod"]     { background: var(--cat-samochod); }
.cat-bar-fill[data-cat="podroze"]      { background: var(--cat-podroze); }
.cat-bar-fill[data-cat="subskrypcje"]  { background: var(--cat-subskrypcje); }
.cat-bar-fill[data-cat="jedzenie"]     { background: var(--cat-jedzenie); }
.cat-bar-fill[data-cat="agatka"]       { background: var(--cat-agatka); }
.cat-bar-fill[data-cat="inne"]         { background: var(--cat-inne); }

/* Category dot colors */
.cat-dot[data-cat="potrzebne"]    { background: var(--cat-potrzebne); }
.cat-dot[data-cat="zachcianki"]   { background: var(--cat-zachcianki); }
.cat-dot[data-cat="niepotrzebne"] { background: var(--cat-niepotrzebne); }
.cat-dot[data-cat="zdrowie"]      { background: var(--cat-zdrowie); }
.cat-dot[data-cat="samochod"]     { background: var(--cat-samochod); }
.cat-dot[data-cat="podroze"]      { background: var(--cat-podroze); }
.cat-dot[data-cat="subskrypcje"]  { background: var(--cat-subskrypcje); }
.cat-dot[data-cat="jedzenie"]     { background: var(--cat-jedzenie); }
.cat-dot[data-cat="agatka"]       { background: var(--cat-agatka); }
.cat-dot[data-cat="inne"]         { background: var(--cat-inne); }

/* --- FILTERS --- */
.filter-select, .filter-search {
    background: rgba(255,255,255,0.7);
    border: 1px solid rgba(0,0,0,0.06);
    border-radius: 10px;
    color: var(--text-main);
    padding: 7px 10px;
    font-size: 13px;
    font-weight: 500;
    outline: none;
    transition: border-color 0.2s, background 0.2s;
    -webkit-appearance: none;
}
.filter-select:focus, .filter-search:focus { border-color: rgba(0,0,0,0.15); background: #fff; }
.filter-select { flex-shrink: 0; }
.filter-search { flex: 1; min-width: 0; }
.filter-search::placeholder { color: #aaa; }

/* --- DEBT TABS --- */
.debt-tab {
    flex: 1;
    background: transparent;
    border: none;
    border-radius: 10px;
    color: var(--text-muted);
    padding: 8px;
    font-size: 13px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s;
}
.debt-tab:hover { color: var(--text-main); }
.debt-tab.active { color: var(--text-main); background: #FFFFFF; font-weight: 600; box-shadow: 0 2px 4px rgba(0,0,0,0.03); }

/* --- MODAL OVERLAY --- */
.modal-overlay-wrap {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.4);
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    z-index: 150;
    flex-direction: column;
    justify-content: flex-end;
    align-items: center;
    opacity: 0;
    transition: opacity 0.2s ease;
}

.modal-overlay-wrap.open {
    display: flex;
    opacity: 1;
}

@media (min-width: 768px) {
    .modal-overlay-wrap {
        justify-content: center;
    }
}

/* --- EMPTY STATE --- */
.empty-state {
    text-align: center;
    color: #aaa;
    padding: 2rem 1rem;
    font-size: 13px;
    font-weight: 500;
}

/* --- FORM (inside modal) --- */
.form-group { margin-bottom: 1rem; }

.form-label {
    display: block;
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: var(--text-muted);
    font-weight: 600;
    margin-bottom: 6px;
}

.form-input {
    width: 100%;
    background: #f8f8f8;
    border: 1px solid rgba(0,0,0,0.08);
    border-radius: 12px;
    color: var(--text-main);
    padding: 12px 14px;
    font-size: 16px; /* 16px prevents iOS zoom on focus */
    font-weight: 500;
    outline: none;
    transition: border-color 0.2s, background 0.2s;
}
.form-input:focus { border-color: rgba(0,0,0,0.2); background: #fff; }
.form-input::placeholder { color: #bbb; }

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

.cat-pills {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
}

.cat-pill {
    background: #f5f5f5;
    border: 1.5px solid rgba(0,0,0,0.06);
    border-radius: 20px;
    color: var(--text-muted);
    padding: 8px 14px;
    font-size: 13px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s;
}
.cat-pill:hover { border-color: rgba(0,0,0,0.15); color: var(--text-main); }
.cat-pill.active { border-color: #1A1A1A; color: #1A1A1A; background: rgba(26,26,26,0.05); font-weight: 600; }

.form-checkbox {
    display: flex;
    align-items: center;
    gap: 8px;
    padding-top: 1.5rem;
}
.form-checkbox input { accent-color: #1A1A1A; width: 18px; height: 18px; }
.form-checkbox label { font-size: 13px; color: var(--text-muted); font-weight: 500; }

.form-submit {
    width: 100%;
    margin-top: 8px;
    padding: 14px;
    background: #1A1A1A;
    color: white;
    border: none;
    border-radius: 16px;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    transition: opacity 0.2s, transform 0.1s;
    box-shadow: 0 2px 8px rgba(0,0,0,0.1);
}
.form-submit:hover { opacity: 0.9; }
.form-submit:active { transform: scale(0.98); }

.dir-pills { display: flex; gap: 6px; }
.dir-pill {
    flex: 1;
    background: #f5f5f5;
    border: 1.5px solid rgba(0,0,0,0.06);
    border-radius: 12px;
    color: var(--text-muted);
    padding: 10px;
    font-size: 13px;
    font-weight: 500;
    cursor: pointer;
    text-align: center;
    transition: all 0.2s;
    min-width: 0;
}
.dir-pill:hover { border-color: rgba(0,0,0,0.15); }
.dir-pill.active { border-color: #1A1A1A; color: #1A1A1A; background: rgba(26,26,26,0.05); font-weight: 600; }

/* --- COMPARISON WIDGET --- */
.comparison-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 6px;
}
.comparison-item {
    text-align: center;
    padding: 10px 6px;
    border-radius: 10px;
    background: #f8f8f8;
    min-width: 0;
    overflow: hidden;
}
.comparison-value { font-size: 14px; font-weight: 700; word-break: break-all; }
.comparison-label { font-size: 10px; color: var(--text-muted); margin-top: 2px; }
.comparison-change { font-size: 11px; font-weight: 600; margin-top: 4px; }
.comparison-up { color: #d94452; }
.comparison-down { color: #0d7c66; }
.comparison-neutral { color: var(--text-muted); }

/* --- WEEKLY TREND --- */
.trend-chart {
    display: flex;
    align-items: flex-end;
    gap: 2px;
    height: 70px;
    padding-top: 8px;
}
.trend-bar-wrap {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    height: 100%;
    justify-content: flex-end;
    min-width: 0;
}
.trend-bar {
    width: 100%;
    max-width: 24px;
    border-radius: 3px 3px 0 0;
    background: #1A1A1A;
    transition: height 0.4s cubic-bezier(0.16, 1, 0.3, 1);
    min-height: 2px;
}
.trend-bar.today { background: #3b82f6; }
.trend-bar-label {
    font-size: 8px;
    color: var(--text-muted);
    margin-top: 3px;
    font-weight: 500;
}

/* --- SAVINGS GOAL --- */
.savings-progress-track {
    width: 100%;
    height: 6px;
    background: rgba(0,0,0,0.05);
    border-radius: 3px;
    overflow: hidden;
}
.savings-progress-fill {
    height: 100%;
    border-radius: 3px;
    background: linear-gradient(90deg, #0d7c66, #10b981);
    transition: width 0.6s cubic-bezier(0.16, 1, 0.3, 1);
}

/* --- ANNUAL HEATMAP --- */
.heatmap-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 3px;
}
.heatmap-cell {
    aspect-ratio: 1.2;
    border-radius: 6px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    font-size: 10px;
    font-weight: 600;
    cursor: default;
    position: relative;
    overflow: hidden;
}
.heatmap-month-label { font-size: 8px; color: var(--text-muted); font-weight: 500; }
.heatmap-amount { font-size: 8px; font-weight: 700; margin-top: 1px; word-break: break-all; }

/* --- RECURRING BADGE --- */
.badge-recurring {
    display: inline-flex;
    align-items: center;
    gap: 2px;
    font-size: 9px;
    text-transform: uppercase;
    letter-spacing: 0.03em;
    padding: 1px 5px;
    border-radius: 5px;
    background: rgba(59,130,246,0.1);
    color: #3b82f6;
    font-weight: 600;
}

/* --- SPLIT BADGE --- */
.badge-split {
    display: inline-flex;
    align-items: center;
    gap: 2px;
    font-size: 9px;
    text-transform: uppercase;
    letter-spacing: 0.03em;
    padding: 1px 5px;
    border-radius: 5px;
    background: rgba(139,92,246,0.1);
    color: #8b5cf6;
    font-weight: 600;
}

/* --- ICON PICKER --- */
.icon-picker-grid {
    display: grid;
    grid-template-columns: repeat(6, 1fr);
    gap: 6px;
    max-height: 200px;
    overflow-y: auto;
    padding: 4px;
}
.icon-pick-btn {
    width: 100%;
    aspect-ratio: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 12px;
    background: #f5f5f5;
    border: 1.5px solid rgba(0,0,0,0.04);
    color: var(--text-muted);
    cursor: pointer;
    transition: all 0.15s;
}
.icon-pick-btn:hover { border-color: rgba(0,0,0,0.15); color: var(--text-main); }
.icon-pick-btn.active { border-color: #1A1A1A; color: #1A1A1A; background: rgba(26,26,26,0.06); }

/* --- RECURRING DASHBOARD --- */
.recurring-summary-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 4px;
}
.recurring-summary-item {
    text-align: center;
    padding: 8px 3px;
    border-radius: 10px;
    background: #f8f8f8;
    min-width: 0;
    overflow: hidden;
}
.recurring-summary-value { font-size: 11px; font-weight: 700; color: var(--text-main); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
@media (min-width: 768px) { .recurring-summary-value { font-size: 16px; } }
.recurring-summary-label { font-size: 8px; color: var(--text-muted); margin-top: 2px; text-transform: uppercase; letter-spacing: 0.03em; font-weight: 600; }

/* --- UPCOMING PAYMENTS --- */
.upcoming-overdue {
    background: rgba(217, 68, 82, 0.04);
    border-radius: 10px;
    padding-left: 6px;
    padding-right: 6px;
}

/* --- LOGIN SCREEN --- */
.login-screen {
    display: flex;
    align-items: center;
    justify-content: center;
    height: 100vh;
    height: 100dvh;
    padding: 16px;
    overflow: hidden;
}
.login-screen.hidden { display: none; }
.login-card {
    background: var(--card-bg);
    border: 1px solid var(--border-color);
    border-radius: 24px;
    box-shadow: 0 8px 32px rgba(0,0,0,0.08);
    padding: 32px 24px;
    width: 100%;
    max-width: 380px;
}

/* === RESPONSIVE === */

/* Small phones (< 380px) */
@media (max-width: 379px) {
    .content-pad { padding-left: 0.75rem; padding-right: 0.75rem; }
    .nav-pill { padding: 3px; gap: 1px; }
    .nav-item { width: 32px; height: 32px; }
    .recurring-summary-grid { grid-template-columns: 1fr 1fr; }
    .heatmap-grid { grid-template-columns: repeat(3, 1fr); }
    .login-card { padding: 24px 16px; }
    .raw-card { border-radius: 12px; }
}

/* Desktop */
@media (min-width: 768px) {
    .heatmap-grid { grid-template-columns: repeat(6, 1fr); }
    .nav-item { width: 44px; height: 44px; }
    .savings-progress-track { height: 8px; }
    .trend-chart { height: 80px; }
}

/* Large desktop */
@media (min-width: 1024px) {
    .heatmap-grid { grid-template-columns: repeat(12, 1fr); }
}

/* Prevent blue highlight on mobile */
* { -webkit-tap-highlight-color: transparent; }
