:root {
  --bg: #f4f6fb;
  --surface: #ffffff;
  --text: #1a2233;
  --text-muted: #6b7280;
  --border: #e5e9f2;
  --primary: #2563eb;
  --primary-dark: #1d4ed8;
  --green: #16a34a;
  --red: #dc2626;
  --orange: #ea580c;
  --purple: #7c3aed;
  --radius: 12px;
  --shadow: 0 1px 3px rgba(16, 24, 40, .08), 0 1px 2px rgba(16, 24, 40, .04);
}

/* Karanlık tema: kullanıcı seçimi yoksa sistem tercihine uyulur,
   ☀️/🌙 butonu data-theme özniteliğiyle bunu geçersiz kılar */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0f1522;
    --surface: #1a2233;
    --text: #eef1f7;
    --text-muted: #97a0b3;
    --border: #2a3447;
    --shadow: 0 1px 3px rgba(0, 0, 0, .4);
  }
}

:root[data-theme="dark"] {
  --bg: #0f1522;
  --surface: #1a2233;
  --text: #eef1f7;
  --text-muted: #97a0b3;
  --border: #2a3447;
  --shadow: 0 1px 3px rgba(0, 0, 0, .4);
}

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

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

/* ---------- Üst bar ---------- */
.topbar {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 50;
}

.topbar-inner {
  max-width: 1100px;
  margin: 0 auto;
  padding: 14px 20px 8px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 8px;
}

.topbar h1 { font-size: 1.3rem; }

.topbar-actions { display: flex; gap: 6px; flex-wrap: wrap; }

.tabs {
  max-width: 1100px;
  margin: 0 auto;
  padding: 0 20px;
  display: flex;
  gap: 4px;
  overflow-x: auto;
}

.tab {
  background: none;
  border: none;
  padding: 10px 14px;
  font-size: .92rem;
  color: var(--text-muted);
  cursor: pointer;
  border-bottom: 2px solid transparent;
  white-space: nowrap;
  font-family: inherit;
}

.tab:hover { color: var(--text); }

.tab.active {
  color: var(--primary);
  border-bottom-color: var(--primary);
  font-weight: 600;
}

/* ---------- Ana içerik ---------- */
main {
  max-width: 1100px;
  margin: 0 auto;
  padding: 24px 20px 60px;
}

.tab-panel { display: none; }
.tab-panel.active { display: block; }

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

.panel-header-actions { display: flex; gap: 8px; flex-wrap: wrap; }

.hint {
  color: var(--text-muted);
  font-size: .88rem;
  margin-bottom: 14px;
}

/* ---------- Ay gezinme ---------- */
.month-nav {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 16px;
  margin-bottom: 20px;
}

.month-nav h2 { font-size: 1.15rem; min-width: 180px; text-align: center; }

.month-nav .btn { font-size: 1.3rem; padding: 4px 14px; }

/* ---------- Kartlar ---------- */
.cards {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 14px;
  margin-bottom: 20px;
}

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px;
  box-shadow: var(--shadow);
}

.card h3 { font-size: 1rem; margin-bottom: 12px; }

.stat-card { display: flex; flex-direction: column; gap: 4px; }
.stat-label { font-size: .82rem; color: var(--text-muted); }
.stat-value { font-size: 1.4rem; font-weight: 700; }
.stat-card.income .stat-value { color: var(--green); }
.stat-card.expense .stat-value { color: var(--red); }
.stat-card.debt .stat-value { color: var(--orange); }

.grid-2 {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 14px;
}

@media (max-width: 720px) {
  .grid-2 { grid-template-columns: 1fr; }
}

/* ---------- Yaklaşan ödemeler ---------- */
.upcoming-list { display: flex; flex-direction: column; gap: 8px; }

.upcoming-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 10px 12px;
  border-radius: 8px;
  background: var(--bg);
  font-size: .9rem;
}

.upcoming-item .u-title { font-weight: 600; }
.upcoming-item .u-sub { color: var(--text-muted); font-size: .8rem; }
.upcoming-item .u-amount { font-weight: 700; white-space: nowrap; }

.upcoming-item.overdue { border-left: 3px solid var(--red); }
.upcoming-item.soon { border-left: 3px solid var(--orange); }
.upcoming-item.later { border-left: 3px solid var(--primary); }

.badge {
  display: inline-block;
  font-size: .72rem;
  padding: 2px 8px;
  border-radius: 20px;
  font-weight: 600;
}

.badge.overdue { background: rgba(220, 38, 38, .12); color: var(--red); }
.badge.soon { background: rgba(234, 88, 12, .12); color: var(--orange); }
.badge.later { background: rgba(37, 99, 235, .12); color: var(--primary); }
.badge.paid { background: rgba(22, 163, 74, .12); color: var(--green); }

/* ---------- Kategori grafiği ---------- */
.category-chart { display: flex; flex-direction: column; gap: 10px; }

.cat-row { font-size: .88rem; }

.cat-row .cat-head {
  display: flex;
  justify-content: space-between;
  margin-bottom: 3px;
}

.cat-bar {
  height: 8px;
  border-radius: 6px;
  background: var(--bg);
  overflow: hidden;
}

.cat-bar-fill {
  height: 100%;
  border-radius: 6px;
}

/* ---------- Liste öğeleri ---------- */
.item-list { display: flex; flex-direction: column; gap: 10px; }

.item {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  box-shadow: var(--shadow);
  flex-wrap: wrap;
}

.item-info { flex: 1; min-width: 180px; }
.item-title { font-weight: 600; }
.item-sub { color: var(--text-muted); font-size: .84rem; }

.item-amount { font-size: 1.05rem; font-weight: 700; white-space: nowrap; }
.item-amount.pos { color: var(--green); }
.item-amount.neg { color: var(--red); }

.item-actions { display: flex; gap: 6px; }

.progress {
  height: 8px;
  border-radius: 6px;
  background: var(--bg);
  overflow: hidden;
  margin-top: 8px;
}

.progress-fill {
  height: 100%;
  background: var(--green);
  border-radius: 6px;
  transition: width .3s;
}

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

/* ---------- Butonlar ---------- */
.btn {
  font-family: inherit;
  font-size: .88rem;
  padding: 8px 14px;
  border-radius: 8px;
  border: 1px solid transparent;
  cursor: pointer;
  transition: background .15s;
}

.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-dark); }

.btn-ghost {
  background: transparent;
  color: var(--text-muted);
  border-color: var(--border);
}
.btn-ghost:hover { background: var(--bg); color: var(--text); }

.btn-danger { background: transparent; color: var(--red); border-color: transparent; }
.btn-danger:hover { background: rgba(220, 38, 38, .1); }

.btn-small { padding: 5px 10px; font-size: .8rem; }

.btn-success { background: var(--green); color: #fff; }
.btn-success:hover { filter: brightness(1.1); }

.btn-danger-solid { background: var(--red); color: #fff; width: 100%; }
.btn-danger-solid:hover { filter: brightness(1.08); }

.danger-card { border-color: rgba(220, 38, 38, .35); }
.danger-card h3 { color: var(--red); }

/* ---------- Modal ---------- */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(10, 15, 30, .5);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  padding: 20px;
}

.modal-overlay.hidden { display: none; }

.modal {
  background: var(--surface);
  border-radius: var(--radius);
  width: 100%;
  max-width: 440px;
  max-height: 90vh;
  overflow-y: auto;
  padding: 20px;
}

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

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

.form-group label {
  display: block;
  font-size: .84rem;
  font-weight: 600;
  margin-bottom: 5px;
}

.input, .modal input, .modal select, .modal textarea {
  width: 100%;
  padding: 9px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: .9rem;
  font-family: inherit;
  background: var(--bg);
  color: var(--text);
}

.input { width: auto; }

.modal input:focus, .modal select:focus {
  outline: 2px solid var(--primary);
  outline-offset: -1px;
}

.checkbox-group {
  display: flex;
  align-items: center;
  gap: 8px;
}

.checkbox-group input { width: auto; }
.checkbox-group label { margin: 0; font-weight: 400; font-size: .88rem; }

.modal .btn-primary { width: 100%; padding: 11px; font-size: .95rem; margin-top: 6px; }

/* ---------- Toast ---------- */
.toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--text);
  color: var(--surface);
  padding: 10px 20px;
  border-radius: 8px;
  font-size: .9rem;
  z-index: 200;
  box-shadow: 0 4px 12px rgba(0, 0, 0, .2);
}

.toast.hidden { display: none; }

/* ---------- Giriş ekranı ---------- */
.hidden { display: none !important; }

.auth-screen {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}

.auth-box {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 32px 28px;
  width: 100%;
  max-width: 380px;
  text-align: center;
}

.auth-box h1 { margin-bottom: 6px; }

.auth-sub {
  color: var(--text-muted);
  font-size: .88rem;
  margin-bottom: 22px;
}

.auth-box form { text-align: left; }

.auth-box input {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: .92rem;
  font-family: inherit;
  background: var(--bg);
  color: var(--text);
}

.auth-box .btn-primary { width: 100%; padding: 11px; font-size: .95rem; }

.auth-alt { width: 100%; margin-top: 8px; }

.auth-error {
  background: rgba(220, 38, 38, .1);
  color: var(--red);
  font-size: .85rem;
  padding: 9px 12px;
  border-radius: 8px;
  margin-bottom: 12px;
}

.auth-info {
  background: rgba(22, 163, 74, .1);
  color: var(--green);
}

/* ---------- Yükleniyor ---------- */
.loading {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg);
  z-index: 300;
  font-size: 1.05rem;
  color: var(--text-muted);
}

/* ---------- Giriş ekranı ek ---------- */
.auth-top-actions {
  display: flex;
  justify-content: flex-end;
  gap: 6px;
  margin-bottom: 4px;
}

.mfa-input {
  text-align: center;
  font-size: 1.5rem !important;
  letter-spacing: .4em;
  font-variant-numeric: tabular-nums;
}

/* ---------- MFA / Güvenlik ---------- */
.mfa-qr {
  display: flex;
  justify-content: center;
  margin: 12px 0;
  background: #fff;
  border-radius: 8px;
  padding: 10px;
}

.mfa-qr svg { width: 180px; height: 180px; }

.mfa-secret {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: .8rem;
  background: var(--bg);
  border: 1px dashed var(--border);
  border-radius: 8px;
  padding: 8px 10px;
  word-break: break-all;
  margin-bottom: 12px;
  user-select: all;
}

.mfa-status {
  font-size: .9rem;
  padding: 10px 12px;
  border-radius: 8px;
  margin-bottom: 14px;
}

.mfa-status.on { background: rgba(22, 163, 74, .12); color: var(--green); }
.mfa-status.off { background: rgba(234, 88, 12, .12); color: var(--orange); }

/* ---------- Raporlar ---------- */
.checkbox-inline {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: .88rem;
  color: var(--text-muted);
  cursor: pointer;
}

.report-section { margin-bottom: 16px; }

.trend-chart {
  display: grid;
  grid-auto-flow: column;
  grid-auto-columns: 1fr;
  gap: 6px;
  align-items: end;
  height: 160px;
  padding-top: 8px;
}

.trend-col {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
  height: 100%;
  justify-content: flex-end;
  min-width: 0;
}

.trend-bars {
  display: flex;
  gap: 2px;
  align-items: flex-end;
  height: 100%;
  width: 100%;
  justify-content: center;
}

.trend-bar {
  width: 45%;
  max-width: 16px;
  border-radius: 3px 3px 0 0;
  min-height: 2px;
}

.trend-bar.income { background: var(--green); }
.trend-bar.expense { background: var(--red); }

.trend-label {
  font-size: .68rem;
  color: var(--text-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 100%;
}

.trend-legend {
  display: flex;
  gap: 14px;
  font-size: .8rem;
  color: var(--text-muted);
  margin-top: 10px;
}

.legend-dot {
  display: inline-block;
  width: 10px;
  height: 10px;
  border-radius: 3px;
  margin-right: 4px;
  vertical-align: baseline;
}

.table-wrap { overflow-x: auto; }

.report-table {
  width: 100%;
  border-collapse: collapse;
  font-size: .87rem;
}

.report-table th {
  text-align: left;
  color: var(--text-muted);
  font-weight: 600;
  font-size: .78rem;
  padding: 8px 10px;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}

.report-table td {
  padding: 8px 10px;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}

.report-table tr:last-child td { border-bottom: none; }

.report-table td.num, .report-table th.num { text-align: right; }

.report-table tfoot td { font-weight: 700; border-top: 2px solid var(--border); }

.mini-bar {
  height: 6px;
  border-radius: 4px;
  background: var(--bg);
  overflow: hidden;
  min-width: 70px;
}

.mini-bar-fill { height: 100%; border-radius: 4px; background: var(--green); }

/* ---------- Hesabım ---------- */
.account-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
  gap: 14px;
  align-items: start;
}

.account-grid .card { display: flex; flex-direction: column; gap: 12px; }

.acc-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  font-size: .9rem;
}
.acc-row span { color: var(--text-muted); }
.acc-row strong { word-break: break-all; text-align: right; }

.acc-field { display: flex; flex-direction: column; gap: 6px; }
.acc-field label { font-size: .84rem; font-weight: 600; }
.acc-input { width: 100%; }

.acc-btn { width: 100%; }

.acc-mfa { display: flex; flex-direction: column; gap: 10px; }

/* Segmented control */
.segmented {
  display: flex;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 3px;
  gap: 3px;
}

.segmented button {
  flex: 1;
  border: none;
  background: transparent;
  color: var(--text-muted);
  font-family: inherit;
  font-size: .84rem;
  padding: 7px 8px;
  border-radius: 6px;
  cursor: pointer;
  white-space: nowrap;
}

.segmented button.active {
  background: var(--surface);
  color: var(--primary);
  font-weight: 600;
  box-shadow: var(--shadow);
}

/* ---------- Mobil alt gezinme ---------- */
.bottom-nav { display: none; }

.bnav-badge {
  position: absolute;
  top: 4px;
  right: 50%;
  transform: translateX(14px);
  background: var(--red);
  color: #fff;
  font-size: .62rem;
  font-weight: 700;
  min-width: 16px;
  height: 16px;
  line-height: 16px;
  text-align: center;
  border-radius: 10px;
  padding: 0 4px;
}

/* ---------- Daha (alt sayfa) ---------- */
.sheet-overlay {
  position: fixed;
  inset: 0;
  background: rgba(10, 15, 30, .5);
  z-index: 120;
  display: flex;
  align-items: flex-end;
}
.sheet-overlay.hidden { display: none; }

.sheet {
  background: var(--surface);
  width: 100%;
  border-radius: 18px 18px 0 0;
  padding: 8px 12px calc(16px + env(safe-area-inset-bottom));
  animation: sheet-up .2s ease;
}

@keyframes sheet-up { from { transform: translateY(100%); } to { transform: translateY(0); } }

.sheet-handle {
  width: 40px;
  height: 4px;
  background: var(--border);
  border-radius: 3px;
  margin: 8px auto 12px;
}

.sheet-item {
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  background: none;
  border: none;
  border-radius: 10px;
  padding: 14px 12px;
  font-family: inherit;
  font-size: 1rem;
  color: var(--text);
  cursor: pointer;
  text-align: left;
}
.sheet-item:hover, .sheet-item:active { background: var(--bg); }
.sheet-item span:first-child { font-size: 1.2rem; }

/* ---------- Mobil uyumluluk ---------- */
@media (max-width: 640px) {
  .topbar { position: sticky; top: 0; }
  .topbar-inner { padding: 12px 16px; }
  .topbar h1 { font-size: 1.15rem; }

  /* Yatay kaydırmalı üst sekmeler mobilde gizli — yerine alt gezinme */
  .tabs { display: none; }

  /* Alt gezinme çubuğu için altta boşluk bırak */
  main { padding: 16px 14px calc(80px + env(safe-area-inset-bottom)); }

  .cards { grid-template-columns: 1fr 1fr; gap: 10px; }
  .card { padding: 15px; }
  .stat-value { font-size: 1.2rem; }

  .panel-header { flex-direction: column; align-items: stretch; }
  .panel-header .btn-primary { width: 100%; padding: 12px; }
  .panel-header-actions { flex-direction: column; }
  .panel-header-actions .input { width: 100%; }

  /* Liste öğeleri dikey dizilir, butonlar büyür */
  .item { flex-direction: column; align-items: stretch; gap: 8px; }
  .item-amount { text-align: right; }
  .item-actions { justify-content: stretch; }
  .item-actions .btn { flex: 1; padding: 10px 8px; font-size: .85rem; }

  .month-nav .btn { padding: 8px 18px; }
  .month-nav h2 { min-width: 0; font-size: 1.05rem; }

  /* Modal alt sayfa gibi açılır */
  .modal-overlay { align-items: flex-end; padding: 0; }
  .modal {
    max-width: 100%;
    max-height: 92vh;
    border-radius: 16px 16px 0 0;
    padding: 18px 16px calc(18px + env(safe-area-inset-bottom));
  }
  .modal input, .modal select { padding: 12px; font-size: 16px; } /* iOS zoom engelleme */
  .btn { min-height: 40px; }

  .trend-chart { height: 120px; }
  .trend-label { font-size: .6rem; }

  .account-grid { grid-template-columns: 1fr; }

  /* Alt gezinme çubuğunu göster */
  .bottom-nav {
    display: flex;
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 90;
    background: var(--surface);
    border-top: 1px solid var(--border);
    padding-bottom: env(safe-area-inset-bottom);
    box-shadow: 0 -1px 8px rgba(16, 24, 40, .06);
  }

  .bnav {
    flex: 1;
    position: relative;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 2px;
    background: none;
    border: none;
    padding: 8px 2px 6px;
    color: var(--text-muted);
    font-family: inherit;
    cursor: pointer;
  }

  .bnav-ico { font-size: 1.25rem; line-height: 1; filter: grayscale(.4); opacity: .7; }
  .bnav-lbl { font-size: .68rem; }

  .bnav.active { color: var(--primary); }
  .bnav.active .bnav-ico { filter: none; opacity: 1; }
  .bnav.active .bnav-lbl { font-weight: 600; }
}

/* Alt gezinme yalnızca mobilde; geniş ekranda gizli kalır */
@media (min-width: 641px) {
  .bottom-nav, .sheet-overlay { display: none !important; }
}
