/* ═══════════════════════════════════════════════════════════════════
   FinanzApp – Stylesheet
   Mobile-First, Dark Theme
═══════════════════════════════════════════════════════════════════ */

/* ─── Variablen ─────────────────────────────────────────────────── */
:root {
    --bg:           #0f172a;
    --bg2:          #1e293b;
    --bg3:          #334155;
    --primary:      #6366f1;
    --primary-dark: #4f46e5;
    --success:      #10b981;
    --warning:      #f59e0b;
    --danger:       #ef4444;
    --text:         #f1f5f9;
    --text2:        #94a3b8;
    --text3:        #64748b;
    --border:       #334155;
    --radius:       12px;
    --radius-sm:    8px;
    --shadow:       0 4px 24px rgba(0,0,0,.4);
    --nav-height:   64px;
    --header-height:56px;
    --safe-bottom:  env(safe-area-inset-bottom, 0px);
}

/* ─── Reset ─────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html, body {
    height: 100%;
    background: var(--bg);
    color: var(--text);
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    font-size: 16px;
    line-height: 1.5;
    -webkit-tap-highlight-color: transparent;
    overscroll-behavior: none;
}

#app {
    height: 100%;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

/* ─── Lade-Overlay ───────────────────────────────────────────────── */
.loading-overlay {
    position: fixed; inset: 0; z-index: 9999;
    background: var(--bg);
    display: flex; flex-direction: column;
    align-items: center; justify-content: center; gap: 20px;
}
.logo-mark { font-size: 56px; }

.spinner {
    width: 36px; height: 36px;
    border: 3px solid var(--bg3);
    border-top-color: var(--primary);
    border-radius: 50%;
    animation: spin .8s linear infinite;
}
.spinner-sm {
    width: 20px; height: 20px;
    border: 2px solid var(--bg3);
    border-top-color: var(--primary);
    border-radius: 50%;
    animation: spin .8s linear infinite;
    display: inline-block;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ─── Auth-Screen ────────────────────────────────────────────────── */
.view-auth {
    height: 100%;
    display: flex; align-items: center; justify-content: center;
    padding: 24px;
    background: var(--bg);
    overflow-y: auto;
}
.auth-container {
    width: 100%; max-width: 400px;
    text-align: center;
}
.auth-logo   { font-size: 64px; margin-bottom: 12px; }
.auth-title  { font-size: 28px; font-weight: 700; margin-bottom: 4px; }
.auth-sub    { color: var(--text2); margin-bottom: 32px; font-size: 14px; }

.auth-tabs {
    display: flex; gap: 4px;
    background: var(--bg2);
    border-radius: var(--radius);
    padding: 4px;
    margin-bottom: 24px;
}
.auth-tab {
    flex: 1; padding: 10px;
    border: none; border-radius: var(--radius-sm);
    background: transparent; color: var(--text2);
    font-size: 14px; font-weight: 500; cursor: pointer;
    transition: background .2s, color .2s;
}
.auth-tab.active {
    background: var(--primary);
    color: #fff;
}

/* ─── App Header ─────────────────────────────────────────────────── */
.app-header {
    height: var(--header-height);
    background: var(--bg2);
    border-bottom: 1px solid var(--border);
    display: flex; align-items: center;
    padding: 0 16px;
    gap: 8px;
    position: sticky; top: 0; z-index: 100;
    flex-shrink: 0;
}
.header-title { font-size: 18px; font-weight: 600; flex: 1; }
.header-user  { font-size: 13px; color: var(--text2); }

/* ─── Bottom Navigation ──────────────────────────────────────────── */
.bottom-nav {
    height: calc(var(--nav-height) + var(--safe-bottom));
    padding-bottom: var(--safe-bottom);
    background: var(--bg2);
    border-top: 1px solid var(--border);
    display: flex; align-items: stretch;
    flex-shrink: 0;
}
.nav-item {
    flex: 1; display: flex; flex-direction: column;
    align-items: center; justify-content: center;
    border: none; background: none;
    color: var(--text3); cursor: pointer;
    padding: 8px 4px;
    transition: color .2s;
    gap: 2px;
}
.nav-item.active { color: var(--primary); }
.nav-icon  { font-size: 22px; }
.nav-label { font-size: 11px; font-weight: 500; }

/* ─── Haupt-Content ─────────────────────────────────────────────── */
.main-content {
    flex: 1; overflow-y: auto;
    padding: 16px;
    background: var(--bg);
    -webkit-overflow-scrolling: touch;
}

/* ─── Karten ─────────────────────────────────────────────────────── */
.card {
    background: var(--bg2);
    border-radius: var(--radius);
    padding: 16px;
    margin-bottom: 14px;
    border: 1px solid var(--border);
}
.card-title {
    font-size: 14px; font-weight: 600;
    color: var(--text2); text-transform: uppercase;
    letter-spacing: .05em; margin-bottom: 14px;
}

/* ─── Hero-Karte ─────────────────────────────────────────────────── */
.hero-card {
    background: linear-gradient(135deg, var(--primary) 0%, var(--primary-dark) 100%);
    border-radius: var(--radius);
    padding: 24px 20px;
    margin-bottom: 14px;
    text-align: center;
}
.hero-label  { font-size: 13px; opacity: .8; margin-bottom: 6px; }
.hero-amount { font-size: 38px; font-weight: 700; letter-spacing: -.02em; }
.hero-count  { font-size: 13px; opacity: .7; margin-top: 4px; }

/* ─── Monats-Navigation ──────────────────────────────────────────── */
.month-nav {
    display: flex; align-items: center; justify-content: space-between;
    padding: 10px 4px; margin-bottom: 14px;
}
.month-label { font-size: 17px; font-weight: 600; }

/* ─── Ausgaben-Liste ─────────────────────────────────────────────── */
.date-group    { margin-bottom: 10px; }
.date-header   {
    display: flex; justify-content: space-between;
    font-size: 12px; font-weight: 600; color: var(--text3);
    text-transform: uppercase; padding: 4px 2px 8px;
    border-bottom: 1px solid var(--border); margin-bottom: 6px;
}
.expense-item {
    display: flex; align-items: center; gap: 12px;
    padding: 12px 8px;
    border-radius: var(--radius-sm);
    cursor: pointer;
    transition: background .15s;
}
.expense-item:hover, .expense-item:active { background: var(--bg3); }
.expense-cat-icon {
    width: 40px; height: 40px;
    border-radius: 10px;
    display: flex; align-items: center; justify-content: center;
    font-size: 20px; flex-shrink: 0;
}
.expense-info     { flex: 1; min-width: 0; }
.expense-merchant { font-size: 15px; font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.expense-date     { font-size: 12px; color: var(--text2); margin-top: 1px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.expense-amount   { font-size: 15px; font-weight: 600; flex-shrink: 0; }

.expenses-total {
    font-size: 15px; color: var(--text2);
    margin-bottom: 16px; padding: 0 2px;
}

/* ─── Kategorie-Balken ───────────────────────────────────────────── */
.cat-bar-item    { margin-bottom: 12px; }
.cat-bar-header  { display: flex; justify-content: space-between; font-size: 13px; margin-bottom: 5px; }
.progress-bar    { height: 6px; background: var(--bg3); border-radius: 99px; overflow: hidden; }
.progress-fill   { height: 100%; border-radius: 99px; transition: width .4s ease; }

/* ─── Scan-View ──────────────────────────────────────────────────── */
.scan-view { padding-bottom: 20px; }

.upload-area {
    background: var(--bg2);
    border: 2px dashed var(--primary);
    border-radius: var(--radius);
    padding: 48px 24px;
    text-align: center;
    cursor: pointer;
    transition: background .2s, border-color .2s;
    margin-bottom: 16px;
}
.upload-area:hover, .upload-area:active { background: #6366f115; }
.upload-area.uploading { opacity: .6; pointer-events: none; }
.upload-icon     { font-size: 52px; margin-bottom: 12px; }
.upload-title    { font-size: 17px; font-weight: 600; margin-bottom: 6px; }
.upload-subtitle { font-size: 13px; color: var(--text2); }

.upload-options {
    display: flex; gap: 10px;
    margin-bottom: 20px;
}
.upload-options .btn { flex: 1; }

.scan-loading {
    display: flex; align-items: center; justify-content: center; gap: 12px;
    padding: 24px; color: var(--text2);
}

.divider {
    text-align: center;
    color: var(--text3);
    font-size: 13px;
    margin: 16px 0;
    position: relative;
}
.divider::before, .divider::after {
    content: '';
    position: absolute;
    top: 50%; width: calc(50% - 28px);
    height: 1px; background: var(--border);
}
.divider::before { left: 0; }
.divider::after  { right: 0; }

/* ─── OCR-Ergebnis ───────────────────────────────────────────────── */
.ocr-card { margin-top: 0; }
.receipt-thumb {
    width: 100%; max-height: 200px;
    object-fit: cover;
    border-radius: var(--radius-sm);
    margin-bottom: 14px;
    cursor: pointer;
}
.pdf-icon {
    background: var(--bg3); border-radius: var(--radius-sm);
    padding: 24px; text-align: center;
    font-size: 32px; margin-bottom: 14px;
}
.receipt-full {
    width: 100%; border-radius: var(--radius-sm);
    cursor: zoom-in; margin-bottom: 14px;
}

/* ─── Statistik ──────────────────────────────────────────────────── */
.stats-view { padding-bottom: 20px; }
.stat-row {
    display: flex; align-items: center; gap: 8px;
    padding: 8px 0;
    border-bottom: 1px solid var(--border);
    font-size: 14px;
}
.stat-row:last-child { border-bottom: none; }
.stat-count  { color: var(--text2); font-size: 12px; margin-left: auto; }
.stat-amount { font-weight: 600; font-size: 13px; }

/* ─── Formulare ──────────────────────────────────────────────────── */
.form-group        { margin-bottom: 14px; }
.form-group label  { display: block; font-size: 13px; color: var(--text2); margin-bottom: 6px; font-weight: 500; }

.input {
    width: 100%; padding: 12px 14px;
    background: var(--bg3);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    color: var(--text);
    font-size: 16px; /* prevent iOS zoom */
    font-family: inherit;
    outline: none;
    transition: border-color .2s;
    -webkit-appearance: none;
}
.input:focus       { border-color: var(--primary); }
.input::placeholder { color: var(--text3); }
textarea.input      { resize: vertical; min-height: 70px; }
select.input        { cursor: pointer; }

/* ─── Buttons ────────────────────────────────────────────────────── */
.btn {
    padding: 13px 20px;
    border-radius: var(--radius-sm);
    border: none; cursor: pointer;
    font-size: 15px; font-weight: 600;
    font-family: inherit;
    transition: opacity .15s, transform .1s;
    display: inline-flex; align-items: center; justify-content: center; gap: 6px;
}
.btn:active { transform: scale(.97); }
.btn-primary   { background: var(--primary); color: #fff; }
.btn-secondary { background: var(--bg3); color: var(--text); border: 1px solid var(--border); }
.btn-danger    { background: #ef44441a; color: var(--danger); border: 1px solid #ef444440; }
.btn-icon {
    background: none; border: none; cursor: pointer;
    font-size: 18px; padding: 8px; border-radius: 8px;
    color: var(--text2);
    transition: background .15s;
    line-height: 1;
}
.btn-icon:hover { background: var(--bg3); }
.w-full { width: 100%; }
.btn:disabled { opacity: .5; pointer-events: none; }

/* ─── FAB ────────────────────────────────────────────────────────── */
.fab {
    position: fixed; bottom: calc(var(--nav-height) + 16px + var(--safe-bottom));
    right: 20px; z-index: 50;
    width: 56px; height: 56px;
    background: var(--primary); color: #fff;
    border: none; border-radius: 50%;
    font-size: 28px; cursor: pointer;
    box-shadow: 0 4px 20px #6366f155;
    display: flex; align-items: center; justify-content: center;
    transition: transform .15s, box-shadow .15s;
}
.fab:active { transform: scale(.92); box-shadow: none; }

/* ─── Modal ──────────────────────────────────────────────────────── */
.modal-overlay {
    position: fixed; inset: 0; z-index: 200;
    background: rgba(0,0,0,.7);
    display: flex; align-items: flex-end; justify-content: center;
    backdrop-filter: blur(4px);
}
.modal-box {
    background: var(--bg2);
    border-radius: var(--radius) var(--radius) 0 0;
    width: 100%; max-width: 600px;
    max-height: 92vh;
    overflow-y: auto;
    padding: 20px 20px calc(20px + var(--safe-bottom));
    animation: slideUp .25s ease;
}
@keyframes slideUp {
    from { transform: translateY(100%); }
    to   { transform: translateY(0); }
}
.modal-header {
    display: flex; align-items: center; justify-content: space-between;
    margin-bottom: 18px;
}
.modal-header h2 { font-size: 18px; font-weight: 700; }
.modal-actions {
    display: flex; gap: 10px; margin-top: 18px;
}
.modal-actions .btn { flex: 1; }

/* ─── Toast ──────────────────────────────────────────────────────── */
.toast {
    position: fixed; bottom: calc(var(--nav-height) + 12px + var(--safe-bottom));
    left: 50%; transform: translateX(-50%) translateY(20px);
    background: var(--bg3); color: var(--text);
    padding: 12px 20px; border-radius: 99px;
    font-size: 14px; font-weight: 500;
    z-index: 300; pointer-events: none;
    opacity: 0; transition: opacity .25s, transform .25s;
    white-space: nowrap; max-width: 90vw;
    box-shadow: var(--shadow);
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
.toast.success { background: var(--success); color: #fff; }
.toast.error   { background: var(--danger);  color: #fff; }

/* ─── Sonstiges ──────────────────────────────────────────────────── */
.loading-card {
    display: flex; align-items: center; justify-content: center;
    padding: 48px;
}
.error-card {
    background: #ef444415; border: 1px solid #ef444440;
    border-radius: var(--radius); padding: 16px;
    color: var(--danger); font-size: 14px;
}
.empty-text {
    text-align: center; color: var(--text3);
    font-size: 14px; padding: 20px 0;
}
.receipt-preview { margin-bottom: 16px; }

/* ─── Desktop ────────────────────────────────────────────────────── */
@media (min-width: 600px) {
    .main-content { padding: 24px; max-width: 600px; margin: 0 auto; }
    .modal-overlay { align-items: center; }
    .modal-box {
        border-radius: var(--radius);
        max-height: 88vh;
        padding-bottom: 20px;
    }
    .fab { bottom: calc(var(--nav-height) + 24px); right: calc(50% - 280px); }
}
