:root {
    --bg: #f4f6fb;
    --surface: #ffffff;
    --surface-2: #f8fafc;
    --border: #e6e9f0;
    --text: #1b2333;
    --muted: #6b7488;
    --primary: #4f46e5;
    --primary-soft: #eef2ff;
    --income: #16a34a;
    --income-soft: #ecfdf3;
    --expense: #dc2626;
    --expense-soft: #fef2f2;
    --warn: #d97706;
    --shadow: 0 1px 3px rgba(16, 24, 40, .06), 0 8px 24px rgba(16, 24, 40, .05);
    --radius: 16px;
    --radius-sm: 10px;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

html { -webkit-text-size-adjust: 100%; }

body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    background: var(--bg);
    color: var(--text);
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
    font-size: 15px;
}

button { font-family: inherit; cursor: pointer; border: none; background: none; }
input, select { font-family: inherit; font-size: 15px; }
a { color: inherit; }

.hidden { display: none !important; }

/* ---------- Auth ekranı ---------- */
.auth-wrap {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
    background: linear-gradient(135deg, #4f46e5 0%, #7c3aed 100%);
}
.auth-card {
    background: var(--surface);
    border-radius: 20px;
    padding: 36px 30px;
    width: 100%;
    max-width: 400px;
    box-shadow: 0 20px 60px rgba(0, 0, 0, .25);
}
.auth-card .brand {
    text-align: center;
    margin-bottom: 24px;
}
.auth-card .brand h1 { font-size: 22px; font-weight: 700; }
.auth-card .brand p { color: var(--muted); font-size: 13px; margin-top: 4px; }

.field { margin-bottom: 14px; }
.field label { display: block; font-size: 13px; color: var(--muted); margin-bottom: 6px; font-weight: 500; }
.field input, .field select {
    width: 100%;
    padding: 12px 14px;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    background: var(--surface-2);
    color: var(--text);
    transition: border-color .15s, box-shadow .15s;
}
.field input:focus, .field select:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px var(--primary-soft);
    background: #fff;
}

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 12px 18px;
    border-radius: var(--radius-sm);
    font-weight: 600;
    font-size: 15px;
    transition: transform .05s, filter .15s, background .15s;
    white-space: nowrap;
}
.btn:active { transform: translateY(1px); }
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { filter: brightness(1.05); }
.btn-block { width: 100%; }
.btn-ghost { background: var(--surface-2); color: var(--text); border: 1px solid var(--border); }
.btn-ghost:hover { background: #eef1f6; }
.btn-danger { background: var(--expense-soft); color: var(--expense); }
.btn-sm { padding: 7px 12px; font-size: 13px; }

.auth-switch { text-align: center; margin-top: 16px; font-size: 14px; color: var(--muted); }
.auth-switch button { color: var(--primary); font-weight: 600; }
.form-error {
    background: var(--expense-soft);
    color: var(--expense);
    padding: 10px 12px;
    border-radius: var(--radius-sm);
    font-size: 13px;
    margin-bottom: 14px;
}

/* ---------- App shell ---------- */
.app { display: flex; min-height: 100vh; }

.sidebar {
    width: 230px;
    background: var(--surface);
    border-right: 1px solid var(--border);
    padding: 22px 14px;
    position: fixed;
    top: 0; bottom: 0; left: 0;
    display: flex;
    flex-direction: column;
    z-index: 40;
}
.sidebar .logo { font-size: 18px; font-weight: 700; padding: 0 10px 20px; }
.sidebar .logo span { color: var(--primary); }
.nav { display: flex; flex-direction: column; gap: 4px; flex: 1; }
.nav button {
    display: flex; align-items: center; gap: 12px;
    padding: 11px 12px;
    border-radius: var(--radius-sm);
    color: var(--muted);
    font-weight: 500;
    text-align: left;
    width: 100%;
    transition: background .12s, color .12s;
}
.nav button:hover { background: var(--surface-2); color: var(--text); }
.nav button.active { background: var(--primary-soft); color: var(--primary); font-weight: 600; }
.nav button svg { width: 19px; height: 19px; flex: none; }
.sidebar .user-box {
    border-top: 1px solid var(--border);
    padding-top: 14px;
    display: flex; align-items: center; gap: 10px;
}
.avatar {
    width: 36px; height: 36px; border-radius: 50%;
    background: var(--primary); color: #fff;
    display: flex; align-items: center; justify-content: center;
    font-weight: 600; font-size: 14px; flex: none;
}
.user-box .meta { overflow: hidden; flex: 1; }
.user-box .meta b { display: block; font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.user-box .meta small { color: var(--muted); font-size: 11px; }

.main {
    flex: 1;
    min-width: 0;
    margin-left: 230px;
    padding: 24px 32px 60px;
}

.topbar {
    display: flex; align-items: center; justify-content: space-between;
    gap: 12px; margin-bottom: 22px; flex-wrap: wrap;
}
.topbar h2 { font-size: 22px; font-weight: 700; }
.topbar .actions { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }

.month-picker { display: flex; align-items: center; gap: 6px; }
.month-picker input {
    padding: 9px 12px; border: 1px solid var(--border);
    border-radius: var(--radius-sm); background: var(--surface);
}

/* dönem filtresi (Ay / Yıl) */
.period-filter { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.period-filter input, .period-filter select {
    padding: 8px 12px; border: 1px solid var(--border);
    border-radius: var(--radius-sm); background: var(--surface); color: var(--text);
}
.seg-sm button { padding: 6px 14px; font-size: 13px; }
.range-inputs { display: inline-flex; align-items: center; gap: 6px; }
.range-sep { color: var(--muted); }

/* maaş grubu */
.panel-head h3 { display: flex; align-items: center; }
.sal-ava {
    display: inline-flex; width: 26px; height: 26px; border-radius: 7px;
    background: var(--primary-soft); color: var(--primary);
    align-items: center; justify-content: center;
    font-size: 11px; font-weight: 700; margin-right: 9px;
}
.sal-ava-none { background: var(--surface-2); color: var(--muted); }
.sal-count { color: var(--muted); font-weight: 400; font-size: 12px; margin-left: 8px; }

/* mobil üst bar */
.mobile-bar {
    display: none;
    align-items: center; justify-content: space-between;
    padding: 14px 16px;
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    position: sticky; top: 0; z-index: 30;
}
.mobile-bar .logo { font-weight: 700; }
.mobile-bar .logo span { color: var(--primary); }
.hamburger { width: 40px; height: 40px; display: flex; align-items: center; justify-content: center; border-radius: 10px; }
.hamburger:hover { background: var(--surface-2); }
.backdrop { display: none; }

/* ---------- Kartlar ---------- */
.cards {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 16px;
    margin-bottom: 24px;
}
.card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 18px;
    box-shadow: var(--shadow);
}
.card .label { color: var(--muted); font-size: 13px; font-weight: 500; display: flex; align-items: center; gap: 7px; }
.card .value { font-size: 26px; font-weight: 700; margin-top: 8px; letter-spacing: -.5px; }
.card .value.pos { color: var(--income); }
.card .value.neg { color: var(--expense); }
.dot { width: 9px; height: 9px; border-radius: 50%; display: inline-block; }

.panel {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    margin-bottom: 22px;
    overflow: hidden;
}
.panel-head {
    display: flex; align-items: center; justify-content: space-between;
    padding: 16px 18px; border-bottom: 1px solid var(--border);
}
.panel-head h3 { font-size: 16px; font-weight: 700; }
.panel-body { padding: 6px 0; }
.panel-pad { padding: 18px; }

/* rapor düzeni */
.report-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(320px, 1fr));
    gap: 18px;
    margin-bottom: 22px;
}
.mini-cards { grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); }
.card .value.sm { font-size: 19px; }
.usd-line { font-size: 13px; font-weight: 600; color: var(--text); margin-top: 3px; }
.usd-line span { font-size: 11px; font-weight: 400; color: var(--muted); }

/* donut grafik */
.donut-wrap { display: flex; align-items: center; gap: 20px; flex-wrap: wrap; }
.donut { width: 168px; height: 168px; flex: none; }
.donut-num { font-size: 17px; font-weight: 700; fill: var(--text); }
.donut-lbl { font-size: 11px; fill: var(--muted); }
.donut-legend { flex: 1; min-width: 150px; display: flex; flex-direction: column; gap: 9px; }
.legend-row { display: flex; align-items: center; gap: 9px; font-size: 13px; }
.legend-dot { width: 11px; height: 11px; border-radius: 3px; flex: none; }
.legend-name { flex: 1; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.legend-pct { font-weight: 600; color: var(--muted); }

/* çubuk grafik */
.bar-chart-wrap { width: 100%; }
.bar-chart { width: 100%; height: auto; max-height: 240px; overflow: visible; }
.bar-lbl { font-size: 10px; fill: var(--muted); }
.inline-legend { display: flex; justify-content: center; gap: 20px; margin-top: 10px; font-size: 13px; color: var(--muted); }
.inline-legend span { display: inline-flex; align-items: center; gap: 6px; }

/* kategori detay tablosu */
.cat-table { padding: 6px 0; }
.cat-item { border-bottom: 1px solid var(--border); }
.cat-item:last-child { border-bottom: none; }
.cat-row {
    display: grid;
    grid-template-columns: 14px 1fr auto auto 18px;
    align-items: center; gap: 10px;
    padding: 11px 18px;
}
.cat-row-btn { width: 100%; text-align: left; background: none; border: none; cursor: pointer; font: inherit; color: inherit; transition: background .1s; }
.cat-row-btn:hover { background: var(--surface-2); }
.cat-swatch { width: 12px; height: 12px; border-radius: 3px; }
.cat-name { font-weight: 600; font-size: 13.5px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.cat-name small { color: var(--muted); font-weight: 400; }
.cat-amt { font-weight: 700; font-size: 13.5px; white-space: nowrap; }
.cat-pct { color: var(--muted); font-size: 12.5px; min-width: 48px; text-align: right; }
.cat-caret { color: var(--muted); display: flex; transition: transform .18s; }
.cat-caret svg { width: 16px; height: 16px; }
.cat-row-btn.open .cat-caret { transform: rotate(180deg); }
.cat-row-btn.open { background: var(--surface-2); }

/* kategori accordion içeriği */
.cat-acc { background: var(--surface-2); border-top: 1px solid var(--border); }
.acc-row {
    display: grid; grid-template-columns: auto 1fr auto auto; align-items: center; gap: 10px;
    padding: 9px 18px 9px 32px; border-bottom: 1px solid var(--border);
    font-size: 13px;
}
.acc-row:last-child { border-bottom: none; }
.acc-date { color: var(--muted); font-size: 12px; white-space: nowrap; }
.acc-desc { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.acc-amt { font-weight: 600; white-space: nowrap; }
.acc-amt.expense { color: var(--expense); }
.acc-amt.income { color: var(--income); }
.li-receipt.sm { width: 28px; height: 28px; }

/* özet altı borç/alacak mini liste */
.head-sub { font-size: 13px; font-weight: 700; margin-left: 8px; }
.head-sub.pos { color: var(--income); }
.head-sub.neg { color: var(--expense); }
.debt-mini-list { padding: 4px 0; }
.debt-mini {
    display: flex; align-items: center; gap: 12px;
    padding: 11px 18px; border-bottom: 1px solid var(--border);
}
.debt-mini:last-child { border-bottom: none; }
.debt-mini-ava {
    width: 36px; height: 36px; border-radius: 10px; flex: none;
    display: flex; align-items: center; justify-content: center;
    font-weight: 700; font-size: 13px;
}
.debt-mini-main { flex: 1; min-width: 0; }
.debt-mini-main b { display: block; font-weight: 600; font-size: 14px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.debt-mini-main small { color: var(--muted); font-size: 12px; }
.debt-mini-amt { font-weight: 700; font-size: 14.5px; white-space: nowrap; }
.debt-mini-amt.pos { color: var(--income); }
.debt-mini-amt.neg { color: var(--expense); }

/* kategori bar grafiği */
.catbar { padding: 12px 18px; }
.catbar-row { margin-bottom: 12px; }
.catbar-row:last-child { margin-bottom: 0; }
.catbar-top { display: flex; justify-content: space-between; font-size: 13px; margin-bottom: 5px; }
.catbar-top b { font-weight: 600; }
.catbar-track { height: 8px; background: var(--surface-2); border-radius: 6px; overflow: hidden; }
.catbar-fill { height: 100%; border-radius: 6px; transition: width .4s; }

/* ---------- Liste / işlemler ---------- */
.list-item {
    display: flex; align-items: center; gap: 14px;
    padding: 13px 18px;
    border-bottom: 1px solid var(--border);
    transition: background .1s;
}
.list-item:last-child { border-bottom: none; }
.list-item:hover { background: var(--surface-2); }
.li-icon {
    width: 40px; height: 40px; border-radius: 11px; flex: none;
    display: flex; align-items: center; justify-content: center;
    font-weight: 600;
}
.li-main { flex: 1; min-width: 0; }
.li-main b { font-weight: 600; display: block; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.li-main small { color: var(--muted); font-size: 12.5px; }
.li-amount { font-weight: 700; font-size: 15px; white-space: nowrap; }
.li-amount.income { color: var(--income); }
.li-amount.expense { color: var(--expense); }
.li-actions { display: flex; gap: 6px; opacity: 0; transition: opacity .12s; }
.list-item:hover .li-actions { opacity: 1; }
.icon-btn {
    width: 32px; height: 32px; border-radius: 8px;
    display: flex; align-items: center; justify-content: center;
    color: var(--muted);
}
.icon-btn:hover { background: #eef1f6; color: var(--text); }
.icon-btn svg { width: 16px; height: 16px; }

.badge {
    display: inline-block; padding: 2px 9px; border-radius: 20px;
    font-size: 11.5px; font-weight: 600;
}
.badge-payable { background: var(--expense-soft); color: var(--expense); }
.badge-receivable { background: var(--income-soft); color: var(--income); }
.badge-settled { background: var(--surface-2); color: var(--muted); }
.badge-due { background: #fff7ed; color: var(--warn); }

.empty { text-align: center; padding: 46px 20px; color: var(--muted); }
.empty svg { width: 44px; height: 44px; opacity: .4; margin-bottom: 12px; }

.filters { display: flex; gap: 10px; padding: 12px 18px; flex-wrap: wrap; border-bottom: 1px solid var(--border); }
.filters select, .filters input {
    padding: 8px 11px; border: 1px solid var(--border);
    border-radius: var(--radius-sm); background: var(--surface);
}
.filters input[type=search] { flex: 1; min-width: 140px; }

.seg { display: inline-flex; background: var(--surface-2); border-radius: var(--radius-sm); padding: 3px; }
.seg button { padding: 7px 14px; border-radius: 8px; font-weight: 600; font-size: 13px; color: var(--muted); }
.seg button.active { background: #fff; color: var(--primary); box-shadow: 0 1px 3px rgba(0,0,0,.08); }

/* ---------- Modal ---------- */
.modal-overlay {
    position: fixed; inset: 0; background: rgba(16, 24, 40, .5);
    display: flex; align-items: flex-end; justify-content: center;
    z-index: 60; padding: 0;
    animation: fade .15s;
}
@keyframes fade { from { opacity: 0; } }
.modal {
    background: var(--surface);
    border-radius: 20px 20px 0 0;
    width: 100%; max-width: 460px;
    max-height: 92vh; overflow-y: auto;
    padding: 22px;
    animation: slideup .22s cubic-bezier(.2,.8,.2,1);
}
@keyframes slideup { from { transform: translateY(40px); opacity: .6; } }
.modal-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 18px; }
.modal-head h3 { font-size: 18px; font-weight: 700; }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.modal-actions { display: flex; gap: 10px; margin-top: 8px; }
.modal-actions .btn { flex: 1; }

.type-toggle { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-bottom: 16px; }
.type-toggle button {
    padding: 12px; border-radius: var(--radius-sm); font-weight: 600;
    border: 1.5px solid var(--border); color: var(--muted); background: var(--surface-2);
}
.type-toggle button.act-income { border-color: var(--income); background: var(--income-soft); color: var(--income); }
.type-toggle button.act-expense { border-color: var(--expense); background: var(--expense-soft); color: var(--expense); }

/* toast */
.toast {
    position: fixed; bottom: 22px; left: 50%; transform: translateX(-50%);
    background: #1b2333; color: #fff; padding: 12px 20px; border-radius: 12px;
    font-size: 14px; z-index: 90; box-shadow: 0 8px 30px rgba(0,0,0,.3);
    animation: fade .2s;
}

/* fab (mobil) */
.fab {
    display: none;
    position: fixed; bottom: 22px; right: 22px;
    width: 58px; height: 58px; border-radius: 50%;
    background: var(--primary); color: #fff;
    align-items: center; justify-content: center;
    box-shadow: 0 8px 24px rgba(79, 70, 229, .45);
    z-index: 35;
}
.fab svg { width: 26px; height: 26px; }

.color-swatches { display: flex; gap: 8px; flex-wrap: wrap; }
.color-swatches button { width: 30px; height: 30px; border-radius: 50%; border: 2px solid transparent; }
.color-swatches button.sel { border-color: var(--text); }

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

/* ---------- Fiş fotoğrafı ---------- */
.receipt-box { margin-top: 2px; }
.receipt-add {
    display: inline-flex; align-items: center; gap: 8px;
    padding: 11px 16px; width: 100%;
    border: 1.5px dashed var(--border); border-radius: var(--radius-sm);
    background: var(--surface-2); color: var(--muted);
    font-weight: 600; font-size: 14px;
    transition: border-color .15s, color .15s;
}
.receipt-add:hover { border-color: var(--primary); color: var(--primary); }
.receipt-add svg { width: 19px; height: 19px; }
.receipt-thumb { position: relative; display: inline-block; }
.receipt-thumb img {
    width: 100%; max-height: 220px; object-fit: cover;
    border-radius: var(--radius-sm); border: 1px solid var(--border);
    cursor: zoom-in; display: block;
}
.receipt-remove {
    position: absolute; top: 8px; right: 8px;
    width: 30px; height: 30px; border-radius: 50%;
    background: rgba(16,24,40,.65); color: #fff;
    display: flex; align-items: center; justify-content: center;
}
.receipt-remove svg { width: 16px; height: 16px; }
.receipt-loading { padding: 18px; text-align: center; color: var(--muted); font-size: 14px; border: 1px solid var(--border); border-radius: var(--radius-sm); }

.li-receipt {
    width: 38px; height: 38px; flex: none;
    object-fit: cover; border-radius: 8px;
    border: 1px solid var(--border); cursor: zoom-in;
}

.img-viewer {
    position: fixed; inset: 0; z-index: 100;
    background: rgba(0,0,0,.88);
    display: flex; align-items: center; justify-content: center;
    padding: 24px; cursor: zoom-out;
    animation: fade .15s;
}
.img-viewer img { max-width: 100%; max-height: 100%; border-radius: 8px; }
.img-viewer-close {
    position: fixed; top: 18px; right: 18px;
    width: 44px; height: 44px; border-radius: 50%;
    background: rgba(255,255,255,.15); color: #fff;
    display: flex; align-items: center; justify-content: center;
}
.img-viewer-close svg { width: 22px; height: 22px; }

/* ---------- Responsive ---------- */
@media (max-width: 860px) {
    .app { display: block; }
    .sidebar {
        width: min(280px, 82vw);
        transform: translateX(-100%);
        transition: transform .25s ease;
        box-shadow: 0 0 40px rgba(0,0,0,.2);
    }
    .sidebar.open { transform: translateX(0); }
    .backdrop.show { display: block; position: fixed; inset: 0; background: rgba(0,0,0,.4); z-index: 39; }
    .main { margin-left: 0; padding: 16px 16px 90px; }
    .mobile-bar { display: flex; }
    .fab { display: flex; }
    .topbar h2 { display: none; }
    .modal { border-radius: 20px; margin: auto; }
    .modal-overlay { align-items: center; padding: 16px; }
}

@media (min-width: 861px) {
    .modal-overlay { align-items: center; }
    .modal { border-radius: 20px; }
}

@media (max-width: 460px) {
    .grid-2 { grid-template-columns: 1fr; }
    .card .value { font-size: 22px; }
    .li-actions { opacity: 1; }
}
