/* =====================================================================
   Masraf Yonetimi - stil
   Harici hicbir kaynak kullanilmaz (CSP: default-src 'self').
   Mobil once (mobile-first): temel duzen telefon icin, genis ekranlar
   media query ile genisletilir.
   ===================================================================== */

/* ---------------------------------------------------------------------
   TEMA
   Renklerin tamami degisken; acik tema varsayilan, koyu tema yalnizca
   degiskenleri yeniden tanimlar. Uc durum var:
     1) :root                       -> acik tema (varsayilan)
     2) prefers-color-scheme: dark  -> kullanici secim yapmadiysa sistem
     3) [data-theme="dark"]         -> kullanicinin acik secimi (her zaman kazanir)
   data-theme niteligi sunucuda cerezden yaziliyor; boylece sayfa
   acilirken yanlis tema ile "parlama" (flash) olmuyor.
   --------------------------------------------------------------------- */

:root {
  --bg: #f6f7f9;
  --surface: #ffffff;
  --surface-2: #f2f4f7;
  --border: #e2e5ea;
  --text: #16191d;
  --muted: #62697a;
  --primary: #2563eb;
  --primary-dark: #1d4ed8;
  --on-primary: #ffffff;
  --danger: #dc2626;
  --danger-bg: #fef2f2;
  --danger-border: #fecaca;
  --danger-text: #991b1b;
  --success: #15803d;
  --success-bg: #f0fdf4;
  --success-border: #bbf7d0;
  --success-text: #166534;
  --radius: 12px;
  --shadow: 0 1px 2px rgba(16, 24, 40, .06), 0 1px 3px rgba(16, 24, 40, .1);
  --overlay: rgba(16, 24, 40, .45);
  /* Telefonlarda centik/alt cubuk guvenli alani */
  --safe-b: env(safe-area-inset-bottom, 0px);
  color-scheme: light;

  /* Istatistik karti renkleri (acik tema) */
  --stat-green-bg: #f0fdf4;  --stat-green-fg: #15803d;
  --stat-blue-bg: #eff6ff;   --stat-blue-fg: #1d4ed8;
  --stat-purple-bg: #faf5ff; --stat-purple-fg: #7e22ce;
  --stat-indigo-bg: #eef2ff; --stat-indigo-fg: #4338ca;
  --stat-amber-bg: #fffbeb;  --stat-amber-fg: #b45309;
  --stat-rose-bg: #fff1f2;   --stat-rose-fg: #be123c;
}

/* Koyu tema degerleri tek yerde tutulup iki secicide kullanilir. */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0f1115;
    --surface: #181b21;
    --surface-2: #22262e;
    --border: #2d323b;
    --text: #e8eaed;
    --muted: #9aa2af;
    --primary: #4f8cf7;
    --primary-dark: #3b78e0;
    --on-primary: #0b1220;
    --danger: #f2665c;
    --danger-bg: #2a1718;
    --danger-border: #5a2a29;
    --danger-text: #ffb4ad;
    --success: #4ade80;
    --success-bg: #12241a;
    --success-border: #24512f;
    --success-text: #9ff0bb;
    --shadow: 0 1px 2px rgba(0, 0, 0, .5), 0 1px 3px rgba(0, 0, 0, .4);
    --overlay: rgba(0, 0, 0, .6);
    color-scheme: dark;

    --stat-green-bg: #12241a;  --stat-green-fg: #6ee7a0;
    --stat-blue-bg: #121c2e;   --stat-blue-fg: #7cb0ff;
    --stat-purple-bg: #1f1630; --stat-purple-fg: #c79cf5;
    --stat-indigo-bg: #171a35; --stat-indigo-fg: #9aa8ff;
    --stat-amber-bg: #2a2113;  --stat-amber-fg: #f0bf6a;
    --stat-rose-bg: #2b1519;   --stat-rose-fg: #f79ab0;
  }
}

:root[data-theme="dark"] {
  --bg: #0f1115;
  --surface: #181b21;
  --surface-2: #22262e;
  --border: #2d323b;
  --text: #e8eaed;
  --muted: #9aa2af;
  --primary: #4f8cf7;
  --primary-dark: #3b78e0;
  --on-primary: #0b1220;
  --danger: #f2665c;
  --danger-bg: #2a1718;
  --danger-border: #5a2a29;
  --danger-text: #ffb4ad;
  --success: #4ade80;
  --success-bg: #12241a;
  --success-border: #24512f;
  --success-text: #9ff0bb;
  --shadow: 0 1px 2px rgba(0, 0, 0, .5), 0 1px 3px rgba(0, 0, 0, .4);
  --overlay: rgba(0, 0, 0, .6);
  color-scheme: dark;

  --stat-green-bg: #12241a;  --stat-green-fg: #6ee7a0;
  --stat-blue-bg: #121c2e;   --stat-blue-fg: #7cb0ff;
  --stat-purple-bg: #1f1630; --stat-purple-fg: #c79cf5;
  --stat-indigo-bg: #171a35; --stat-indigo-fg: #9aa8ff;
  --stat-amber-bg: #2a2113;  --stat-amber-fg: #f0bf6a;
  --stat-rose-bg: #2b1519;   --stat-rose-fg: #f79ab0;
}

*, *::before, *::after { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.55 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto,
        "Helvetica Neue", Arial, sans-serif;
  /* Yatay tasma telefonda en sik gorulen bozukluk */
  overflow-x: hidden;
}

h1 { font-size: 1.4rem; margin: 0 0 1rem; }
h2 { font-size: 1.05rem; margin: 0 0 .75rem; }
p  { margin: 0 0 .5rem; }
a  { color: var(--primary); }

.muted { color: var(--muted); }
.strong { font-weight: 600; }

.container {
  width: 100%;
  max-width: 1140px;
  margin: 0 auto;
  padding: 1rem .85rem calc(2.5rem + var(--safe-b));
}
@media (min-width: 640px) {
  .container { padding: 1.5rem 1rem 3rem; }
  h1 { font-size: 1.6rem; }
  h2 { font-size: 1.15rem; }
}
.container.narrow { max-width: 820px; }

.skip-link {
  position: absolute; left: -9999px;
  background: var(--primary); color: var(--on-primary);
  padding: .6rem 1rem; border-radius: 0 0 var(--radius) 0; z-index: 100;
}
.skip-link:focus { left: 0; top: 0; }

/* --------------------------------- ust bar --------------------------------- */

.site-header {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  position: sticky; top: 0; z-index: 20;
}
.header-inner {
  display: flex; align-items: center; justify-content: space-between;
  gap: .75rem; padding: .6rem .85rem;
  max-width: 1140px; margin: 0 auto;
}
@media (min-width: 640px) { .header-inner { padding: .75rem 1rem; } }

.brand {
  display: flex; align-items: center; gap: .5rem;
  text-decoration: none; color: inherit; min-width: 0;
  /* Dokunmatik hedef yuksekligi */
  min-height: 44px;
}
.brand-mark {
  display: inline-grid; place-items: center; flex-shrink: 0;
  width: 32px; height: 32px; border-radius: 8px;
  background: var(--primary); color: var(--on-primary); font-weight: 700;
}
.brand-mark-lg { width: 48px; height: 48px; border-radius: 12px; font-size: 1.3rem; }
.brand-name {
  font-weight: 700; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.header-user { display: flex; align-items: center; gap: .6rem; flex-shrink: 0; }
.username {
  color: var(--muted); font-size: .9rem;
  max-width: 9rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
/* Dar ekranda kullanici adi yer kaplamasin */
@media (max-width: 479px) { .username { display: none; } }

/* --------------------------------- menu --------------------------------- */

/*
 * Menu <details> ile kuruldu: JavaScript olmadan da acilip kapaniyor.
 * app.js yalnizca disari tiklayinca / Esc ile kapatma gibi kolayliklar ekler.
 */
.menu { position: relative; }

.menu > summary {
  list-style: none; cursor: pointer;
  display: inline-grid; place-items: center;
  width: 44px; height: 44px; border-radius: 10px;
  border: 1px solid var(--border); background: var(--surface);
  color: var(--text); touch-action: manipulation;
}
.menu > summary::-webkit-details-marker { display: none; }
.menu > summary:hover { background: var(--surface-2); }
.menu-icon { width: 22px; height: 22px; display: block; }

/* Acikken arkaya karartma: disari tiklayinca kapanmasi icin de kullanilir */
.menu[open] > summary + .menu-backdrop { display: block; }
.menu-backdrop {
  display: none; position: fixed; inset: 0;
  background: var(--overlay); z-index: 40; border: 0; padding: 0;
  cursor: default;
}

.menu-panel {
  position: absolute; right: 0; top: calc(100% + .5rem);
  z-index: 50; min-width: 250px;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); box-shadow: 0 8px 24px rgba(0, 0, 0, .18);
  padding: .4rem;
}

.menu-head {
  padding: .6rem .7rem .5rem;
  border-bottom: 1px solid var(--border); margin-bottom: .35rem;
}
.menu-head-name { font-weight: 600; }
.menu-head-sub { font-size: .82rem; color: var(--muted); }

/* Menu ogeleri: link, buton ve form butonu ayni gorunsun */
.menu-item {
  display: flex; align-items: center; gap: .65rem; width: 100%;
  min-height: 44px; padding: .55rem .7rem;
  border: 0; border-radius: 8px; background: none;
  font: inherit; color: var(--text); text-align: left;
  text-decoration: none; cursor: pointer; touch-action: manipulation;
}
.menu-item:hover { background: var(--surface-2); }
.menu-item:focus-visible { outline: 2px solid var(--primary); outline-offset: -2px; }
.menu-item-danger { color: var(--danger); }
.menu-item-danger:hover { background: var(--danger-bg); }
.menu-icon-sm { width: 18px; height: 18px; flex-shrink: 0; }
.menu-sep { height: 1px; background: var(--border); margin: .35rem .2rem; }
.menu-badge {
  margin-left: auto; font-size: .78rem; color: var(--muted);
  background: var(--surface-2); border-radius: 999px; padding: .1rem .5rem;
}
.menu-form { margin: 0; display: block; }

/* --------------------------------- bilesenler --------------------------------- */

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 1rem;
  margin-bottom: 1rem;
}
@media (min-width: 640px) { .card { padding: 1.25rem; margin-bottom: 1.25rem; } }

.btn {
  display: inline-block; cursor: pointer;
  /* Dokunmatik hedef en az ~44px yuksekliginde olmali */
  min-height: 44px; padding: .65rem 1.1rem;
  border-radius: 10px; border: 1px solid transparent;
  font: inherit; font-weight: 500; line-height: 1.3;
  text-decoration: none; text-align: center;
  touch-action: manipulation;
}
.btn:focus-visible, .btn-icon:focus-visible,
input:focus-visible, select:focus-visible, a:focus-visible, summary:focus-visible {
  outline: 2px solid var(--primary); outline-offset: 2px;
}
.btn-primary { background: var(--primary); color: var(--on-primary); }
.btn-primary:hover { background: var(--primary-dark); }
.btn-outline { background: var(--surface); border-color: var(--border); color: var(--text); }
.btn-outline:hover { background: var(--surface-2); }
.btn-danger { background: var(--danger); color: var(--on-primary); }
.btn-danger:hover { filter: brightness(.93); }
.btn-block { width: 100%; }
.btn[disabled] { opacity: .6; cursor: not-allowed; }

.btn-icon {
  cursor: pointer; background: none; border: 1px solid transparent;
  border-radius: 10px; font: inherit; color: var(--muted);
  min-width: 44px; min-height: 44px; padding: .5rem;
  display: inline-grid; place-items: center;
  touch-action: manipulation;
}
.btn-danger-ghost:hover { background: var(--danger-bg); color: var(--danger); }

/* Telefonda butonlar alt alta ve tam genislik */
.btn-row { display: flex; flex-direction: column; gap: .6rem; margin-top: 1rem; }
.btn-row .btn { width: 100%; }
@media (min-width: 480px) {
  .btn-row { flex-direction: row; }
  .btn-row .btn { flex: 1; width: auto; }
}
.inline-form { display: inline; margin: 0; }

.alert {
  border-radius: var(--radius); padding: .75rem .9rem;
  margin-bottom: .6rem; border: 1px solid;
}
.alert-error   { background: var(--danger-bg);  border-color: var(--danger-border);  color: var(--danger-text); }
.alert-success { background: var(--success-bg); border-color: var(--success-border); color: var(--success-text); }
.flash-area { padding-top: .85rem; padding-bottom: 0; }

.divider {
  display: flex; align-items: center; gap: .75rem;
  margin: 1.25rem 0; color: var(--muted); font-size: .85rem;
}
.divider::before, .divider::after {
  content: ""; flex: 1; height: 1px; background: var(--border);
}

/* --------------------------------- formlar --------------------------------- */

.field { margin-bottom: .9rem; }
.field label { display: block; font-size: .88rem; font-weight: 500; margin-bottom: .35rem; }

.field-row { display: grid; grid-template-columns: 1fr 1fr; gap: .6rem; }

input[type="text"], input[type="password"], input[type="search"],
input[type="date"], input[type="number"], input[type="file"] {
  width: 100%; padding: .7rem .75rem;
  border: 1px solid var(--border); border-radius: 10px;
  background: var(--surface); color: var(--text);
  font-family: inherit;
  /* 16px alti yazi tipi iOS Safari'de otomatik yakinlastirmaya yol acar */
  font-size: 16px;
  min-height: 44px;
}
input::placeholder { color: var(--muted); opacity: .75; }
/* Tarih ve sayi alanlari iOS'ta tasmasin */
input[type="date"] { -webkit-appearance: none; appearance: none; }

/* --------------------------------- giris --------------------------------- */

.auth-wrap {
  min-height: 100vh; min-height: 100dvh;
  display: grid; place-items: center;
  padding: 1.5rem .85rem calc(1.5rem + var(--safe-b));
}
.auth-card {
  width: 100%; max-width: 400px; background: var(--surface);
  border: 1px solid var(--border); border-radius: 16px;
  box-shadow: var(--shadow); padding: 1.5rem;
}
@media (min-width: 480px) { .auth-card { padding: 2rem; } }
.auth-head { text-align: center; margin-bottom: 1.25rem; }
.auth-head h1 { font-size: 1.3rem; margin: .75rem 0 .25rem; }

/* --------------------------------- parmak izi --------------------------------- */

.passkey-btn {
  display: flex; align-items: center; justify-content: center; gap: .55rem;
}
.passkey-icon { width: 22px; height: 22px; flex-shrink: 0; }

.device-list { list-style: none; margin: .5rem 0 0; padding: 0; }
.device-item {
  display: flex; align-items: center; gap: .75rem;
  padding: .7rem 0; border-bottom: 1px solid var(--border);
}
.device-item:last-child { border-bottom: 0; }
.device-info { flex: 1; min-width: 0; }
.device-name { font-weight: 500; }
.device-meta { font-size: .82rem; color: var(--muted); }

/* <summary> varsayilan olarak kucuk bir satir; dokunmatik hedef yapiliyor */
details.settings > summary,
details.filter-box > summary {
  cursor: pointer; font-weight: 600;
  padding: .6rem 0; min-height: 44px;
  list-style: none; display: flex; align-items: center; gap: .5rem;
  touch-action: manipulation;
}
details.settings > summary::-webkit-details-marker,
details.filter-box > summary::-webkit-details-marker { display: none; }
details.settings > summary::before,
details.filter-box > summary::before {
  content: "\25B8"; transition: transform .15s; color: var(--muted);
}
details.settings[open] > summary::before,
details.filter-box[open] > summary::before { transform: rotate(90deg); }

/* --------------------------------- istatistik --------------------------------- */

.stat-grid {
  display: grid; gap: .6rem; margin-bottom: 1.5rem;
  /* Telefonda iki sutun; kartlar tek sutunda cok uzun gorunuyordu */
  grid-template-columns: repeat(2, minmax(0, 1fr));
}
@media (min-width: 640px) {
  .stat-grid { gap: .85rem; grid-template-columns: repeat(3, minmax(0, 1fr)); }
}
@media (min-width: 1024px) {
  .stat-grid { grid-template-columns: repeat(6, minmax(0, 1fr)); }
}
.stat-card {
  border: 1px solid var(--border); border-radius: var(--radius);
  padding: .7rem .8rem; background: var(--surface); min-width: 0;
}
.stat-label {
  font-size: .78rem; color: var(--muted); margin: 0 0 .15rem;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.stat-value {
  font-size: 1.02rem; font-weight: 600; margin: 0;
  font-variant-numeric: tabular-nums;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
@media (min-width: 640px) { .stat-value { font-size: 1.15rem; } }
.stat-green  { background: var(--stat-green-bg); }
.stat-green  .stat-value { color: var(--stat-green-fg); }
.stat-blue   { background: var(--stat-blue-bg); }
.stat-blue   .stat-value { color: var(--stat-blue-fg); }
.stat-purple { background: var(--stat-purple-bg); }
.stat-purple .stat-value { color: var(--stat-purple-fg); }
.stat-indigo { background: var(--stat-indigo-bg); }
.stat-indigo .stat-value { color: var(--stat-indigo-fg); }
.stat-amber  { background: var(--stat-amber-bg); }
.stat-amber  .stat-value { color: var(--stat-amber-fg); }
.stat-rose   { background: var(--stat-rose-bg); }
.stat-rose   .stat-value { color: var(--stat-rose-fg); }

/* --------------------------------- yukleme --------------------------------- */

.dropzone { border: 2px dashed var(--border); box-shadow: none; }
.dropzone.is-dragging { border-color: var(--primary); background: var(--surface-2); }
.dropzone-inner { text-align: center; padding: .75rem .25rem; }
@media (min-width: 640px) { .dropzone-inner { padding: 1.25rem .5rem; } }
.dropzone-title { font-weight: 600; margin-bottom: .2rem; }
.dropzone input[type="file"] { max-width: 420px; margin: 1rem auto .5rem; }

/*
 * CSP (style-src 'self') satir ici style ozniteliklerini engelliyor;
 * gizleme/bosluk gibi kucuk duzenlemeler de sinifla yapilmali.
 */
.is-hidden { display: none !important; }
.mt-sm { margin-top: .5rem; }
.mt-md { margin-top: .75rem; }
.hint { font-size: .82rem; color: var(--muted); margin-bottom: 1rem; }
.upload-busy { margin-top: .9rem; color: var(--primary); font-weight: 500; }

/* Telefonda dogrudan kamera ile cekim */
.camera-row { display: flex; flex-direction: column; gap: .6rem; margin-bottom: .75rem; }
@media (min-width: 480px) { .camera-row { flex-direction: row; justify-content: center; } }

/* --------------------------------- yerlesim --------------------------------- */

.layout-split { display: grid; gap: 1.25rem; grid-template-columns: 1fr; }
@media (min-width: 900px) {
  .layout-split { grid-template-columns: 320px 1fr; align-items: start; gap: 1.5rem; }
}

/* Telefonda filtreler varsayilan kapali: liste hemen gorunsun */
.filter-box > summary { cursor: pointer; }
@media (min-width: 900px) {
  /* Genis ekranda filtreler her zaman acik: baslik satiri gizlenir */
  details.filter-box > summary { display: none; }
  .filter-box { display: block; }
}

/* --------------------------------- fis listesi --------------------------------- */

.receipt-list { list-style: none; margin: 0; padding: 0; }
.receipt-item {
  display: flex; align-items: center; gap: .5rem;
  padding: .75rem .85rem; margin-bottom: .6rem;
}
.receipt-main {
  flex: 1; text-decoration: none; color: inherit; min-width: 0;
  display: block; padding: .15rem 0;
}
.receipt-top {
  display: flex; justify-content: space-between; gap: .5rem;
  margin-bottom: .15rem; align-items: baseline;
}
.receipt-no {
  font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.receipt-total {
  font-weight: 600; color: var(--success); white-space: nowrap;
  font-variant-numeric: tabular-nums;
}
.receipt-meta {
  font-size: .85rem; color: var(--muted);
  display: flex; gap: .35rem; flex-wrap: wrap;
}

.empty { text-align: center; padding: 2rem 1rem; }
.empty-title { font-weight: 600; margin-bottom: .35rem; }
.error-code { font-size: 2.5rem; font-weight: 700; color: var(--muted); margin: 0 0 .5rem; }

/* --------------------------------- detay --------------------------------- */

.detail-actions {
  display: flex; justify-content: space-between; align-items: center;
  gap: .6rem; margin-bottom: 1rem;
}
.detail-grid { display: grid; gap: 1.25rem; grid-template-columns: 1fr; }
@media (min-width: 700px) { .detail-grid { grid-template-columns: 1fr 1fr; } }
.detail-grid dl { margin: 0; }
.detail-grid dt { font-size: .82rem; color: var(--muted); margin-top: .75rem; }
.detail-grid dt:first-child { margin-top: 0; }
.detail-grid dd { margin: .15rem 0 0; font-weight: 500; }
.amount-lg { font-size: 1.3rem; font-weight: 700; font-variant-numeric: tabular-nums; }

.receipt-image {
  max-width: 100%; height: auto; border: 1px solid var(--border);
  border-radius: var(--radius); display: block;
}

/* Telefonda tablo yerine kart listesi gosterilir */
.table-scroll { display: none; }
@media (min-width: 700px) { .table-scroll { display: block; overflow-x: auto; } }

.items-table { width: 100%; border-collapse: collapse; }
.items-table th, .items-table td {
  padding: .55rem .5rem; border-bottom: 1px solid var(--border); text-align: left;
}
.items-table th { font-size: .82rem; color: var(--muted); font-weight: 600; }
.items-table .num {
  text-align: right; white-space: nowrap; font-variant-numeric: tabular-nums;
}

.item-cards { display: grid; gap: .6rem; }
@media (min-width: 700px) { .item-cards { display: none; } }
.item-card {
  border: 1px solid var(--border); border-radius: 10px; padding: .7rem .8rem;
  background: var(--surface);
}
.item-card-name { font-weight: 600; margin-bottom: .4rem; }
.item-card-grid {
  display: grid; grid-template-columns: 1fr 1fr; gap: .3rem .75rem; font-size: .88rem;
}
.item-card-grid span:nth-child(odd) { color: var(--muted); }
.item-card-grid span:nth-child(even) {
  text-align: right; font-variant-numeric: tabular-nums;
}

.summary { margin: 1.25rem 0 0; border-top: 1px solid var(--border); padding-top: .9rem; }
.summary > div { display: flex; justify-content: space-between; gap: 1rem; padding: .2rem 0; }
.summary dt { color: var(--muted); font-size: .9rem; margin: 0; }
.summary dd { margin: 0; font-weight: 500; font-variant-numeric: tabular-nums; }
.summary-total {
  border-top: 1px solid var(--border); margin-top: .5rem;
  padding-top: .6rem; font-size: 1.05rem;
}
.summary-total dt, .summary-total dd { font-weight: 700; color: var(--text); }
