:root {
  --bg: #f4f5f2;
  --surface: #ffffff;
  --surface-2: #eef1ec;
  --text: #1c2119;
  --muted: #5d6658;
  --line: #d9ded4;
  --primary: #166534;
  --primary-ink: #ffffff;
  --primary-soft: #dcfce7;
  --accent: #b45309;
  --danger: #b91c1c;
  --danger-soft: #fee2e2;
  --warn-soft: #fef3c7;
  --warn-ink: #78350f;
  --info-soft: #e0f2fe;
  --info-ink: #0c4a6e;
  --radius: 14px;
  --shadow: 0 1px 2px rgba(0, 0, 0, .06), 0 2px 8px rgba(0, 0, 0, .04);
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #111410;
    --surface: #1b1f19;
    --surface-2: #242a22;
    --text: #eef1ea;
    --muted: #a3ad9c;
    --line: #333b30;
    --primary: #22a355;
    --primary-ink: #04140a;
    --primary-soft: #143322;
    --accent: #f59e0b;
    --danger: #f87171;
    --danger-soft: #3b1515;
    --warn-soft: #3a2c0b;
    --warn-ink: #fcd34d;
    --info-soft: #0c2a3d;
    --info-ink: #bae6fd;
    --shadow: none;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 17px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, "Noto Sans", sans-serif;
  padding-bottom: env(safe-area-inset-bottom);
}
img { max-width: 100%; }
a { color: var(--primary); }
h1, h2, h3 { line-height: 1.2; margin: 0 0 .5rem; }
h1 { font-size: 1.45rem; }
h2 { font-size: 1.15rem; }
main { max-width: 860px; margin: 0 auto; padding: 16px 16px 48px; outline: none; }
.loading { color: var(--muted); text-align: center; padding: 3rem 0; }
[hidden] { display: none !important; }

/* Üst çubuk */
.topbar {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: center; gap: 12px;
  padding: calc(10px + env(safe-area-inset-top)) 16px 10px;
  background: var(--primary); color: var(--primary-ink);
}
.brand { display: flex; align-items: center; gap: 10px; color: inherit; text-decoration: none; font-weight: 700; font-size: 1.1rem; }
.brand img { border-radius: 8px; }
.topbar-link { margin-left: auto; color: inherit; text-decoration: none; font-weight: 600; padding: 8px 12px; border-radius: 10px; background: rgba(255,255,255,.15); }
.net { font-size: .8rem; font-weight: 700; padding: 3px 8px; border-radius: 999px; background: var(--warn-soft); color: var(--warn-ink); }
.banner { padding: 10px 16px; font-size: .95rem; }
.banner.warn { background: var(--warn-soft); color: var(--warn-ink); }

/* Butonlar */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 48px; padding: 10px 18px;
  border: 1px solid var(--line); border-radius: 12px;
  background: var(--surface); color: var(--text);
  font: inherit; font-weight: 600; text-decoration: none; cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: .55; cursor: not-allowed; }
.btn.primary { background: var(--primary); color: var(--primary-ink); border-color: var(--primary); }
.btn.danger { background: var(--danger); color: #fff; border-color: var(--danger); }
.btn.ghost-danger { color: var(--danger); }
.btn.big { min-height: 64px; font-size: 1.2rem; border-radius: 16px; }
.btn.block { width: 100%; }
.btn.small { min-height: 38px; padding: 6px 12px; font-size: .9rem; }
.btn-row { display: flex; gap: 10px; flex-wrap: wrap; }
.btn-row > .btn { flex: 1 1 140px; }
.icon { font-size: 1.3em; line-height: 1; }

/* Kartlar */
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; box-shadow: var(--shadow); margin-bottom: 14px; }
.section-title { display: flex; align-items: baseline; justify-content: space-between; margin: 20px 0 8px; }
.section-title h2 { margin: 0; }
.muted { color: var(--muted); }
.small { font-size: .88rem; }
.notice { border-radius: 12px; padding: 12px 14px; margin-bottom: 14px; font-size: .97rem; }
.notice.warn { background: var(--warn-soft); color: var(--warn-ink); }
.notice.info { background: var(--info-soft); color: var(--info-ink); }
.notice.ok { background: var(--primary-soft); color: var(--text); }
.notice.error { background: var(--danger-soft); color: var(--danger); }
.notice strong { display: block; margin-bottom: 2px; }

/* Panel */
.home-actions { display: grid; grid-template-columns: 2fr 1fr; gap: 10px; margin-bottom: 14px; }
.stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; margin-bottom: 14px; }
.stat { background: var(--surface); border: 1px solid var(--line); border-radius: 12px; padding: 10px 12px; text-align: left; font: inherit; color: inherit; cursor: pointer; }
.stat b { display: block; font-size: 1.5rem; }
.stat span { color: var(--muted); font-size: .85rem; }
.stat.alert b { color: var(--accent); }
.search { position: relative; margin-bottom: 10px; }
.search input { padding-left: 44px; }
.search .icon { position: absolute; left: 14px; top: 50%; transform: translateY(-50%); color: var(--muted); }
.chips { display: flex; gap: 8px; overflow-x: auto; padding: 2px 0 10px; scrollbar-width: none; }
.chips::-webkit-scrollbar { display: none; }
.chip { flex: 0 0 auto; border: 1px solid var(--line); background: var(--surface); color: var(--text); border-radius: 999px; padding: 8px 14px; font: inherit; font-size: .92rem; cursor: pointer; white-space: nowrap; }
.chip[aria-pressed="true"] { background: var(--primary); border-color: var(--primary); color: var(--primary-ink); }

/* Ürün listesi */
.plist { list-style: none; margin: 0; padding: 0; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; }
.plist li + li { border-top: 1px solid var(--line); }
.prow { display: grid; grid-template-columns: 56px 1fr auto; gap: 12px; align-items: center; padding: 10px 12px; color: inherit; text-decoration: none; }
.prow:active { background: var(--surface-2); }
.thumb { width: 56px; height: 56px; border-radius: 10px; object-fit: contain; background: var(--surface-2); display: grid; place-items: center; color: var(--muted); font-size: 1.4rem; overflow: hidden; }
.thumb img { width: 100%; height: 100%; object-fit: contain; }
.prow-name { font-weight: 600; overflow: hidden; text-overflow: ellipsis; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; }
.prow-meta { color: var(--muted); font-size: .85rem; font-variant-numeric: tabular-nums; overflow-wrap: anywhere; }
.price { font-weight: 800; font-size: 1.15rem; font-variant-numeric: tabular-nums; white-space: nowrap; }
.price.none { color: var(--accent); font-size: .9rem; font-weight: 700; }
.badge { display: inline-block; font-size: .75rem; font-weight: 700; padding: 1px 7px; border-radius: 999px; background: var(--surface-2); color: var(--muted); }
.recent { display: flex; gap: 10px; overflow-x: auto; padding-bottom: 6px; }
.recent a { flex: 0 0 150px; background: var(--surface); border: 1px solid var(--line); border-radius: 12px; padding: 10px; color: inherit; text-decoration: none; }
.recent .r-name { font-size: .9rem; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.empty { text-align: center; padding: 28px 16px; color: var(--muted); }

/* Ürün detayı */
.pdetail { display: grid; grid-template-columns: 1fr; gap: 14px; }
.pimage { width: 100%; max-height: 260px; aspect-ratio: 4 / 3; object-fit: contain; background: var(--surface-2); border-radius: 12px; display: grid; place-items: center; font-size: 3rem; color: var(--muted); }
.pimage img { max-height: 260px; width: 100%; object-fit: contain; }
.kv { display: grid; grid-template-columns: auto 1fr; gap: 4px 12px; font-size: .95rem; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; overflow-wrap: anywhere; }
.big-price { font-size: 2.4rem; font-weight: 800; font-variant-numeric: tabular-nums; line-height: 1.1; }
.big-price.none { font-size: 1.3rem; color: var(--accent); }
.price-form { display: grid; gap: 10px; margin-top: 12px; }
.price-input { display: flex; gap: 10px; }
.price-input input { font-size: 1.6rem; font-weight: 700; text-align: right; }
.price-input .btn { flex: 0 0 auto; min-width: 110px; }
.quick { display: flex; gap: 6px; flex-wrap: wrap; }
.quick .btn { min-height: 44px; padding: 6px 4px; flex: 1 1 60px; font-size: .92rem; white-space: nowrap; }
.profit { font-size: .95rem; }
.profit .pos { color: var(--primary); font-weight: 700; }
.profit .neg { color: var(--danger); font-weight: 700; }
.history { list-style: none; padding: 0; margin: 0; font-size: .92rem; }
.history li { display: flex; justify-content: space-between; gap: 10px; padding: 8px 0; border-top: 1px solid var(--line); font-variant-numeric: tabular-nums; }
@media (min-width: 720px) {
  .pdetail { grid-template-columns: 280px 1fr; align-items: start; }
}

/* Formlar */
label { display: block; font-weight: 600; margin-bottom: 4px; }
.field { margin-bottom: 14px; }
.field .hint { font-weight: 400; color: var(--muted); font-size: .85rem; }
input, select, textarea {
  width: 100%; min-height: 50px; padding: 10px 14px;
  border: 1px solid var(--line); border-radius: 12px;
  background: var(--surface); color: var(--text); font: inherit;
}
textarea { min-height: 80px; resize: vertical; }
input:focus, select:focus, textarea:focus, .btn:focus-visible, .chip:focus-visible { outline: 3px solid color-mix(in srgb, var(--primary) 45%, transparent); outline-offset: 1px; }
.field.invalid input { border-color: var(--danger); }
.field-error { color: var(--danger); font-size: .88rem; margin-top: 4px; }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.img-pick { display: flex; align-items: center; gap: 12px; }
.img-pick .thumb { width: 88px; height: 88px; }
.sticky-actions { position: sticky; bottom: 0; background: linear-gradient(transparent, var(--bg) 30%); padding: 18px 0 calc(8px + env(safe-area-inset-bottom)); }

/* Tarayıcı (kamera) */
.scanner { position: relative; background: #000; border-radius: var(--radius); overflow: hidden; min-height: 260px; }
.scanner video { width: 100% !important; display: block; }
#reader { width: 100%; }
#reader img[alt="Info icon"], #reader__dashboard { display: none !important; }
.manual { margin-top: 14px; }
.manual form { display: flex; gap: 10px; }
.manual input { font-size: 1.25rem; letter-spacing: .04em; font-variant-numeric: tabular-nums; }
.manual .btn { flex: 0 0 auto; }

/* İçe aktarma */
.table-wrap { overflow-x: auto; border: 1px solid var(--line); border-radius: 12px; max-height: 420px; }
table { border-collapse: collapse; width: 100%; font-size: .88rem; background: var(--surface); }
th, td { padding: 6px 10px; border-bottom: 1px solid var(--line); text-align: left; vertical-align: top; }
th { position: sticky; top: 0; background: var(--surface-2); }
tr.err td { background: var(--danger-soft); }
tr.skip td { color: var(--muted); }
.map-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px 14px; }

/* Bildirim ve onay penceresi */
.toast {
  position: fixed; left: 50%; bottom: calc(20px + env(safe-area-inset-bottom)); transform: translateX(-50%);
  max-width: min(92vw, 520px); padding: 12px 18px; border-radius: 12px; z-index: 50;
  background: #1f2937; color: #fff; font-weight: 600; box-shadow: 0 6px 20px rgba(0,0,0,.25);
}
.toast.error { background: var(--danger); }
.toast.ok { background: #166534; }
.dialog { border: none; border-radius: 16px; padding: 20px; max-width: min(92vw, 420px); background: var(--surface); color: var(--text); }
.dialog::backdrop { background: rgba(0, 0, 0, .45); }
.dialog p { font-size: 1.05rem; margin-top: 0; white-space: pre-line; }
.dialog-actions { display: flex; gap: 10px; }
.dialog-actions .btn { flex: 1; }
.login { max-width: 380px; margin: 10vh auto 0; }

@media (max-width: 480px) {
  body { font-size: 16px; }
  .home-actions { grid-template-columns: 1fr; }
  .stats { gap: 8px; }
  .stat b { font-size: 1.3rem; }
  .grid-2, .map-grid { grid-template-columns: 1fr; }
  .big-price { font-size: 2rem; }
}
