:root {
  color-scheme: light dark;
  --bg: #f6f2ea;
  --surface: #fffdf8;
  --ink: #221d16;
  --muted: #6f6658;
  --line: #e2dacb;
  --accent: #c8501e;
  --accent-ink: #ffffff;
  --gain: #1c7a4a;
  --loss: #b3261e;
  --danger-bg: #fbe9e7;
  --shadow: 0 1px 2px rgb(60 45 20 / 8%);
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #16130f;
    --surface: #221e18;
    --ink: #f3ede2;
    --muted: #a89e8d;
    --line: #38322a;
    --accent: #e8703a;
    --accent-ink: #1b0f07;
    --gain: #57c98d;
    --loss: #f2857c;
    --danger-bg: #3a1f1c;
    --shadow: none;
  }
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

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

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 16px/1.4 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  -webkit-tap-highlight-color: transparent;
}

main {
  max-width: 560px;
  margin: 0 auto;
  padding:
    calc(env(safe-area-inset-top) + 16px)
    calc(env(safe-area-inset-right) + 16px)
    calc(env(safe-area-inset-bottom) + 32px)
    calc(env(safe-area-inset-left) + 16px);
}

h1 { font-size: 22px; line-height: 1.2; margin: 0; letter-spacing: -0.01em; }
h2 { font-size: 16px; margin: 0 0 8px; }
p { margin: 0; }

a { color: inherit; }

.topbar { display: flex; align-items: center; gap: 8px; min-height: 44px; margin-bottom: 16px; }
.topbar h1 { flex: 1; }
.icon-link {
  display: inline-flex; align-items: center; justify-content: center;
  width: 44px; height: 44px; margin-left: -10px;
  color: var(--ink); text-decoration: none; font-size: 26px; line-height: 1;
}
.topbar .text-link { color: var(--muted); font-size: 15px; padding: 10px 0 10px 10px; text-decoration: none; }

/* Özet */
.profit { padding: 8px 0 20px; }
.profit .label { color: var(--muted); font-size: 15px; }
.profit .value {
  font-size: clamp(38px, 12vw, 52px); font-weight: 700; line-height: 1.1;
  letter-spacing: -0.02em; font-variant-numeric: tabular-nums; overflow-wrap: anywhere;
}
.gain { color: var(--gain); }
.loss { color: var(--loss); }

.tiles { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-bottom: 24px; }
.tile {
  display: block; padding: 14px; text-decoration: none;
  background: var(--surface); border: 1px solid var(--line); border-radius: 14px; box-shadow: var(--shadow);
}
.tile .label { color: var(--muted); font-size: 14px; }
.tile .value { font-size: 20px; font-weight: 650; font-variant-numeric: tabular-nums; overflow-wrap: anywhere; }
.tile .count { color: var(--muted); font-size: 13px; }

/* Ana menü */
.actions { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.action {
  display: flex; align-items: center; justify-content: center; min-height: 72px; padding: 12px;
  border-radius: 14px; border: 1px solid var(--line); background: var(--surface);
  font-size: 17px; font-weight: 600; text-align: center; text-decoration: none; box-shadow: var(--shadow);
}
.action.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.action:active, .btn:active, .tile:active { opacity: .75; }

/* Form */
.field { display: block; margin-bottom: 14px; }
.field > span { display: block; margin-bottom: 5px; font-size: 14px; font-weight: 600; }
.field small { color: var(--muted); font-weight: 400; }
input {
  width: 100%; height: 48px; padding: 0 12px;
  font: inherit; font-size: 17px; color: var(--ink);
  background: var(--surface); border: 1px solid var(--line); border-radius: 10px;
  appearance: none; -webkit-appearance: none;
}
input:focus { outline: 2px solid var(--accent); outline-offset: -1px; border-color: transparent; }
input[type="date"] { min-width: 0; }
.invalid { border-color: var(--loss); }
.two { display: grid; grid-template-columns: 1fr 1.6fr; gap: 10px; }

.btn {
  display: block; width: 100%; min-height: 50px; padding: 12px;
  font: inherit; font-size: 17px; font-weight: 600; text-align: center; text-decoration: none;
  color: var(--ink); background: var(--surface); border: 1px solid var(--line); border-radius: 12px; cursor: pointer;
}
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.danger { color: var(--loss); background: var(--danger-bg); border-color: transparent; }
.btn:disabled { opacity: .55; }
.btn + .btn { margin-top: 10px; }
.error { color: var(--loss); font-size: 15px; margin-bottom: 12px; }
.muted { color: var(--muted); font-size: 14px; }

.segment {
  display: grid; grid-auto-flow: column; grid-auto-columns: 1fr; gap: 3px; padding: 3px; margin-bottom: 16px;
  background: var(--line); border-radius: 11px;
}
.segment button {
  min-height: 38px; font: inherit; font-size: 15px; font-weight: 600; color: var(--ink);
  background: transparent; border: 0; border-radius: 8px; cursor: pointer;
}
.segment button[aria-pressed="true"] { background: var(--surface); box-shadow: var(--shadow); }

/* Toplu giriş */
.bulk-row {
  display: grid; grid-template-columns: 1fr 64px 104px 36px; gap: 6px; margin-bottom: 8px; align-items: center;
}
.bulk-head { color: var(--muted); font-size: 13px; font-weight: 600; margin-bottom: 4px; }
.bulk-row input { padding: 0 9px; font-size: 16px; }
.remove {
  width: 36px; height: 48px; padding: 0; font-size: 22px; color: var(--muted);
  background: none; border: 0; cursor: pointer;
}
.bulk-total { display: flex; justify-content: space-between; gap: 12px; margin: 14px 0; font-weight: 600; font-variant-numeric: tabular-nums; }

/* Maliyet */
.result { margin-top: 8px; padding: 16px; background: var(--surface); border: 1px solid var(--line); border-radius: 14px; }
.result .line { display: flex; justify-content: space-between; gap: 12px; padding: 3px 0; color: var(--muted); font-variant-numeric: tabular-nums; }
.result .big { margin-top: 10px; padding-top: 12px; border-top: 1px solid var(--line); }
.result .big .label { color: var(--muted); font-size: 14px; }
.result .big .value { font-size: 40px; font-weight: 700; letter-spacing: -0.02em; font-variant-numeric: tabular-nums; }
.note { margin-top: 12px; }
.note a { color: var(--accent); }

/* Kayıtlar */
.search { margin-bottom: 12px; }
.totals { margin-bottom: 8px; padding: 10px 12px; font-size: 15px; font-weight: 600; font-variant-numeric: tabular-nums; background: var(--surface); border: 1px solid var(--line); border-radius: 10px; }
.record { display: flex; align-items: center; gap: 8px; border-bottom: 1px solid var(--line); }
.record-main {
  display: flex; flex: 1; align-items: center; justify-content: space-between; gap: 12px; min-width: 0; padding: 12px 2px;
  font: inherit; color: inherit; text-align: left; background: none; border: 0; cursor: pointer;
}
.record-del {
  flex: none; min-width: 44px; min-height: 44px; padding: 0 8px; font: inherit; font-size: 14px; font-weight: 600;
  color: var(--loss); background: var(--danger-bg); border: 0; border-radius: 8px; cursor: pointer;
}
.check { display: flex; align-items: center; gap: 8px; min-height: 36px; margin-bottom: 14px; font-size: 15px; font-weight: 600; }
.check input { width: 20px; height: 20px; appearance: auto; -webkit-appearance: auto; accent-color: var(--accent); }
.bulk-row .check { grid-column: 1 / -1; margin: -2px 0 6px; font-size: 14px; font-weight: 400; }
.bulk-row .check input { width: 20px; height: 20px; padding: 0; }
.profit-sub { margin-top: 10px; }
.profit .profit-sub .value { font-size: clamp(26px, 8vw, 34px); }
.record .name { font-weight: 600; overflow-wrap: anywhere; }
.record .amount { flex: none; font-weight: 650; font-variant-numeric: tabular-nums; }
.empty { padding: 32px 0; color: var(--muted); text-align: center; }
.more { margin-top: 14px; }

dialog {
  width: min(100vw - 32px, 460px); padding: 18px; color: var(--ink);
  background: var(--bg); border: 1px solid var(--line); border-radius: 16px;
}
dialog::backdrop { background: rgb(0 0 0 / 45%); }

/* Ana ekrana ekle */
.install { margin-bottom: 20px; padding: 14px; background: var(--surface); border: 1px solid var(--line); border-radius: 14px; }
.install ol { margin: 0 0 4px; padding-left: 20px; }
.install li { margin-bottom: 4px; }
.install .close { padding: 8px 0 0; font: inherit; font-size: 14px; color: var(--muted); background: none; border: 0; text-decoration: underline; cursor: pointer; }

.section { margin-top: 28px; }

.login { padding-top: 12vh; }
.login h1 { margin-bottom: 4px; }
.login p { margin-bottom: 20px; }

#toast {
  position: fixed; left: 50%; bottom: calc(env(safe-area-inset-bottom) + 20px); transform: translateX(-50%);
  max-width: calc(100vw - 32px); padding: 10px 16px; font-size: 15px; font-weight: 600;
  color: var(--bg); background: var(--ink); border-radius: 999px; z-index: 10;
}
