:root {
  --bg: #f5f3ee;
  --surface: #ffffff;
  --surface-2: #f0ede6;
  --line: #e3dfd5;
  --ink: #1b2420;
  --ink-2: #5b6660;
  --ink-3: #8a938e;
  --brand: #1f5c47;
  --brand-ink: #ffffff;
  --brand-soft: #e3efe9;
  --debt: #b8402a;
  --debt-soft: #fbe9e4;
  --pay: #1d7a4c;
  --pay-soft: #e2f3ea;
  --warn: #a8670a;
  --warn-soft: #fbf0d9;
  --radius: 14px;
  --shadow: 0 1px 2px rgba(20, 30, 25, .06), 0 4px 16px rgba(20, 30, 25, .05);
  --nav-h: 64px;
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #121614; --surface: #1a201d; --surface-2: #222a26; --line: #2d3632;
    --ink: #e9eeeb; --ink-2: #a9b3ae; --ink-3: #7b8580;
    --brand: #4fb48c; --brand-ink: #0d1a14; --brand-soft: #1d3329;
    --debt: #f0806a; --debt-soft: #3a2420; --pay: #5cc98f; --pay-soft: #1b3326;
    --warn: #e5b05a; --warn-soft: #3a2f1c;
    --shadow: none;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  font-family: var(--font); font-size: 15px; line-height: 1.45;
  background: var(--bg); color: var(--ink);
  -webkit-font-smoothing: antialiased; -webkit-tap-highlight-color: transparent;
}
a { color: inherit; text-decoration: none; }
button, input, select, textarea { font: inherit; color: inherit; }
h1, h2, h3 { margin: 0; line-height: 1.2; }
.num { font-variant-numeric: tabular-nums; }
.muted { color: var(--ink-2); }
.faint { color: var(--ink-3); font-size: 13px; }
.debt { color: var(--debt); }
.pay { color: var(--pay); }
.boot { padding: 40vh 0; text-align: center; color: var(--ink-3); }
.hidden { display: none !important; }

/* ---------- Layout ---------- */
.shell { min-height: 100vh; padding-bottom: calc(var(--nav-h) + env(safe-area-inset-bottom) + 16px); }
.topbar {
  position: sticky; top: 0; z-index: 20; display: flex; align-items: center; gap: 10px;
  padding: 12px 16px; padding-top: calc(12px + env(safe-area-inset-top));
  background: color-mix(in srgb, var(--bg) 88%, transparent); backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--line);
}
.topbar h1 { font-size: 18px; flex: 1; min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.topbar .sub { font-size: 12px; color: var(--ink-3); font-weight: 500; display: block; }
.icon-btn {
  width: 40px; height: 40px; border-radius: 12px; border: 1px solid var(--line);
  background: var(--surface); display: inline-grid; place-items: center; cursor: pointer; flex: none;
}
.icon-btn svg { width: 20px; height: 20px; }
.page { padding: 16px; max-width: 980px; margin: 0 auto; }

.nav {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 30;
  display: grid; grid-template-columns: repeat(5, 1fr);
  height: calc(var(--nav-h) + env(safe-area-inset-bottom)); padding-bottom: env(safe-area-inset-bottom);
  background: var(--surface); border-top: 1px solid var(--line);
}
.nav a { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px; font-size: 11px; color: var(--ink-3); font-weight: 600; }
.nav a svg { width: 22px; height: 22px; }
.nav a.on { color: var(--brand); }
.nav .brandline { display: none; }

@media (min-width: 900px) {
  .shell { padding-bottom: 0; padding-left: 232px; }
  .nav {
    top: 0; right: auto; width: 232px; height: auto; display: flex; flex-direction: column; gap: 4px;
    padding: 20px 12px; border-top: 0; border-right: 1px solid var(--line);
  }
  .nav .brandline { display: block; padding: 4px 12px 18px; font-weight: 700; font-size: 16px; }
  .nav .brandline small { display: block; color: var(--ink-3); font-weight: 500; font-size: 12px; }
  .nav a { flex-direction: row; justify-content: flex-start; gap: 12px; font-size: 14px; padding: 10px 12px; border-radius: 10px; }
  .nav a.on { background: var(--brand-soft); }
  .topbar { padding-left: 24px; padding-right: 24px; }
  .page { padding: 24px; }
}

/* ---------- Cards / stats ---------- */
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); }
.card-pad { padding: 16px; }
.section { margin-top: 22px; }
.section-head { display: flex; align-items: baseline; justify-content: space-between; margin: 0 2px 10px; }
.section-head h2 { font-size: 15px; }
.section-head a { font-size: 13px; color: var(--brand); font-weight: 600; }

.hero { padding: 18px; background: var(--brand); color: var(--brand-ink); border: 0; }
.hero .label { font-size: 13px; opacity: .85; }
.hero .big { font-size: 34px; font-weight: 750; letter-spacing: -.5px; margin-top: 2px; }
.hero .meta { font-size: 13px; opacity: .85; margin-top: 6px; }
.stats { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; margin-top: 10px; }
@media (min-width: 700px) { .stats { grid-template-columns: repeat(4, 1fr); } }
.stat { padding: 14px; }
.stat .label { font-size: 12px; color: var(--ink-2); font-weight: 600; }
.stat .val { font-size: 20px; font-weight: 700; margin-top: 4px; }
.stat .meta { font-size: 12px; color: var(--ink-3); }

.quick { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-top: 14px; }

/* ---------- Lists ---------- */
.list { overflow: hidden; }
.row { display: flex; align-items: center; gap: 12px; padding: 13px 14px; border-top: 1px solid var(--line); cursor: pointer; }
.row:first-child { border-top: 0; }
.row:active { background: var(--surface-2); }
.row .main { flex: 1; min-width: 0; }
.row .title { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.row .meta { font-size: 12.5px; color: var(--ink-3); margin-top: 1px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.row .amt { font-weight: 700; text-align: right; white-space: nowrap; }
.avatar {
  width: 40px; height: 40px; border-radius: 12px; flex: none; display: grid; place-items: center;
  background: var(--surface-2); color: var(--ink-2); font-weight: 700; font-size: 14px;
}
.avatar.debt { background: var(--debt-soft); color: var(--debt); }
.avatar.overdue { background: var(--warn-soft); color: var(--warn); }
.empty { padding: 28px 16px; text-align: center; color: var(--ink-3); }

.badge { display: inline-block; font-size: 11px; font-weight: 700; padding: 2px 7px; border-radius: 999px; vertical-align: 1px; }
.badge.warn { background: var(--warn-soft); color: var(--warn); }
.badge.debt { background: var(--debt-soft); color: var(--debt); }
.badge.pay { background: var(--pay-soft); color: var(--pay); }
.badge.gray { background: var(--surface-2); color: var(--ink-2); }

/* ---------- Search / chips ---------- */
.search { position: relative; }
.search svg { position: absolute; left: 12px; top: 50%; transform: translateY(-50%); width: 18px; height: 18px; color: var(--ink-3); }
.search input { padding-left: 38px; }
.chips { display: flex; gap: 8px; overflow-x: auto; padding: 12px 0 2px; scrollbar-width: none; }
.chips::-webkit-scrollbar { display: none; }
.chip {
  flex: none; padding: 7px 13px; border-radius: 999px; border: 1px solid var(--line); background: var(--surface);
  font-size: 13px; font-weight: 600; cursor: pointer; color: var(--ink-2);
}
.chip.on { background: var(--ink); color: var(--bg); border-color: var(--ink); }

/* ---------- Forms ---------- */
input, select, textarea {
  width: 100%; padding: 11px 12px; border-radius: 11px; border: 1px solid var(--line);
  background: var(--surface); outline: none; font-size: 16px;
}
input:focus, select:focus, textarea:focus { border-color: var(--brand); box-shadow: 0 0 0 3px var(--brand-soft); }
textarea { resize: vertical; min-height: 64px; }
label.field { display: block; margin-bottom: 12px; }
label.field > span { display: block; font-size: 13px; font-weight: 600; color: var(--ink-2); margin-bottom: 5px; }
.field-row { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.check { display: flex; align-items: center; gap: 10px; margin-bottom: 12px; font-weight: 600; }
.check input { width: 20px; height: 20px; }
.seg { display: grid; grid-auto-flow: column; grid-auto-columns: 1fr; gap: 4px; background: var(--surface-2); padding: 4px; border-radius: 12px; }
.seg button { border: 0; background: transparent; padding: 9px; border-radius: 9px; font-weight: 600; color: var(--ink-2); cursor: pointer; }
.seg button.on { background: var(--surface); color: var(--ink); box-shadow: var(--shadow); }
.amount-input { font-size: 28px; font-weight: 700; text-align: center; padding: 14px; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  padding: 12px 16px; border-radius: 12px; border: 1px solid var(--line); background: var(--surface);
  font-weight: 650; cursor: pointer; white-space: nowrap;
}
.btn svg { width: 18px; height: 18px; }
.btn.primary { background: var(--brand); color: var(--brand-ink); border-color: var(--brand); }
.btn.debt { background: var(--debt); color: #fff; border-color: var(--debt); }
.btn.pay { background: var(--pay); color: #fff; border-color: var(--pay); }
.btn.ghost { background: transparent; }
.btn.danger { color: var(--debt); }
.btn.block { width: 100%; }
.btn.lg { padding: 15px 16px; font-size: 16px; }
.btn:disabled { opacity: .5; cursor: default; }

/* ---------- Customer detail ---------- */
.balance-card { padding: 18px; text-align: center; }
.balance-card .label { font-size: 13px; color: var(--ink-2); font-weight: 600; }
.balance-card .big { font-size: 38px; font-weight: 780; letter-spacing: -.5px; margin: 2px 0 4px; }
.balance-card .meta { font-size: 13px; color: var(--ink-3); }
.actions2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-top: 14px; }

.txn { padding: 13px 14px; border-top: 1px solid var(--line); }
.txn:first-child { border-top: 0; }
.txn-head { display: flex; align-items: flex-start; gap: 10px; }
.txn-head .main { flex: 1; min-width: 0; }
.txn-head .title { font-weight: 650; }
.txn-head .amt { font-weight: 750; white-space: nowrap; text-align: right; }
.txn-items { margin: 6px 0 0; padding: 0; list-style: none; font-size: 13px; color: var(--ink-2); }
.txn-items li { display: flex; justify-content: space-between; gap: 8px; }
.txn.deleted { opacity: .55; }
.txn.deleted .amt { text-decoration: line-through; }
.dot { width: 10px; height: 10px; border-radius: 50%; margin-top: 6px; flex: none; }
.dot.borc { background: var(--debt); }
.dot.odeme { background: var(--pay); }
.link-btn { border: 0; background: none; padding: 0; color: var(--ink-3); font-size: 12px; font-weight: 600; cursor: pointer; text-decoration: underline; }

/* ---------- Veresiye (menu picker) ---------- */
.pos { display: grid; gap: 16px; }
@media (min-width: 900px) { .pos { grid-template-columns: 1fr 340px; align-items: start; } .cart { position: sticky; top: 84px; } }
.menu-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 8px; margin-top: 12px; }
.menu-btn {
  position: relative; text-align: left; padding: 12px; min-height: 74px; border-radius: 12px;
  border: 1px solid var(--line); background: var(--surface); cursor: pointer; display: flex; flex-direction: column; justify-content: space-between;
}
.menu-btn:active { transform: scale(.98); }
.menu-btn .n { font-weight: 650; font-size: 14px; line-height: 1.25; }
.menu-btn .p { font-size: 13px; color: var(--ink-2); margin-top: 6px; }
.menu-btn.in { border-color: var(--brand); background: var(--brand-soft); }
.menu-btn .q {
  position: absolute; top: -7px; right: -7px; min-width: 24px; height: 24px; padding: 0 6px; border-radius: 999px;
  background: var(--brand); color: var(--brand-ink); font-size: 12px; font-weight: 800; display: grid; place-items: center;
}
.cart-line { display: flex; align-items: center; gap: 8px; padding: 10px 0; border-top: 1px solid var(--line); }
.cart-line:first-child { border-top: 0; }
.cart-line .main { flex: 1; min-width: 0; }
.cart-line .n { font-weight: 600; font-size: 14px; }
.cart-line .p { font-size: 12px; color: var(--ink-3); }
.stepper { display: flex; align-items: center; gap: 2px; background: var(--surface-2); border-radius: 10px; padding: 2px; }
.stepper button { width: 32px; height: 32px; border: 0; border-radius: 8px; background: var(--surface); font-weight: 800; font-size: 16px; cursor: pointer; }
.stepper span { min-width: 30px; text-align: center; font-weight: 700; font-size: 14px; }
.cart-total { display: flex; justify-content: space-between; align-items: baseline; padding-top: 12px; margin-top: 4px; border-top: 2px solid var(--ink); }
.cart-total b { font-size: 22px; }
.savebar {
  position: fixed; left: 0; right: 0; bottom: calc(var(--nav-h) + env(safe-area-inset-bottom)); z-index: 25;
  padding: 10px 16px; background: var(--surface); border-top: 1px solid var(--line);
  display: flex; align-items: center; gap: 12px;
}
.savebar .tot { flex: 1; }
.savebar .tot small { display: block; font-size: 12px; color: var(--ink-3); }
.savebar .tot b { font-size: 20px; }
@media (min-width: 900px) { .savebar { display: none; } }
.pos-page { padding-bottom: 90px; }
@media (min-width: 900px) { .pos-page { padding-bottom: 24px; } }

/* ---------- Tables ---------- */
.tbl { width: 100%; border-collapse: collapse; font-size: 14px; }
.tbl th, .tbl td { padding: 10px 12px; text-align: left; border-top: 1px solid var(--line); }
.tbl th { font-size: 12px; color: var(--ink-3); font-weight: 700; border-top: 0; }
.tbl td.r, .tbl th.r { text-align: right; }

/* ---------- Sheet (modal) ---------- */
.sheet-wrap { position: fixed; inset: 0; z-index: 100; display: flex; align-items: flex-end; justify-content: center; background: rgba(10, 15, 12, .45); animation: fade .15s ease; }
.sheet {
  width: 100%; max-width: 520px; max-height: 92vh; overflow-y: auto; background: var(--bg);
  border-radius: 20px 20px 0 0; padding: 8px 18px calc(18px + env(safe-area-inset-bottom)); animation: up .2s ease;
}
.sheet .grip { width: 40px; height: 5px; border-radius: 9px; background: var(--line); margin: 4px auto 12px; }
.sheet h3 { font-size: 18px; margin-bottom: 4px; }
.sheet .sheet-sub { color: var(--ink-3); font-size: 13px; margin-bottom: 14px; }
.sheet-actions { display: grid; grid-template-columns: 1fr 2fr; gap: 10px; margin-top: 8px; }
@media (min-width: 600px) { .sheet-wrap { align-items: center; } .sheet { border-radius: 20px; } }
@keyframes up { from { transform: translateY(30px); opacity: 0; } }
@keyframes fade { from { opacity: 0; } }
.toast { animation: fade .2s ease; }

#toast-root { position: fixed; left: 50%; transform: translateX(-50%); top: calc(12px + env(safe-area-inset-top)); z-index: 200; display: grid; gap: 8px; width: min(92vw, 420px); }
.toast { padding: 12px 16px; border-radius: 12px; background: var(--ink); color: var(--bg); font-weight: 600; box-shadow: 0 8px 24px rgba(0,0,0,.2); animation: up .2s ease; }
.toast.err { background: var(--debt); color: #fff; }

/* ---------- Auth ---------- */
.auth-body { min-height: 100vh; display: grid; place-items: center; padding: 20px; }
.auth-card { width: 100%; max-width: 380px; background: var(--surface); border: 1px solid var(--line); border-radius: 20px; padding: 28px 22px; box-shadow: var(--shadow); }
.auth-card.wide { max-width: 520px; }
.auth-card h1 { font-size: 22px; margin: 14px 0 4px; }
.auth-card p { color: var(--ink-2); margin: 0 0 18px; }
.auth-card fieldset { border: 1px solid var(--line); border-radius: 14px; padding: 12px 14px 4px; margin: 0 0 14px; }
.auth-card legend { font-size: 13px; font-weight: 700; color: var(--ink-2); padding: 0 6px; }
.auth-card form > label, .auth-card fieldset label { display: block; font-size: 13px; font-weight: 600; color: var(--ink-2); margin-bottom: 10px; }
.auth-card fieldset input { margin-top: 4px; }
.brand-mark { width: 52px; height: 52px; border-radius: 15px; background: var(--brand); color: var(--brand-ink); display: grid; place-items: center; font-weight: 800; font-size: 24px; }
.err-box { background: var(--debt-soft); color: var(--debt); padding: 10px 12px; border-radius: 10px; font-weight: 600; }
.ok-box { background: var(--pay-soft); color: var(--pay); padding: 12px; border-radius: 10px; }

.fab {
  position: fixed; right: 18px; bottom: calc(var(--nav-h) + env(safe-area-inset-bottom) + 16px); z-index: 26;
  height: 52px; padding: 0 20px; border-radius: 16px; border: 0; background: var(--brand); color: var(--brand-ink);
  font-weight: 700; display: inline-flex; align-items: center; gap: 8px; box-shadow: 0 8px 24px rgba(31, 92, 71, .35); cursor: pointer;
}
.fab svg { width: 20px; height: 20px; }
@media (min-width: 900px) { .fab { bottom: 28px; right: 28px; } }

@media print {
  .nav, .topbar .icon-btn, .fab, .savebar, .no-print { display: none !important; }
  .shell { padding: 0 !important; }
  body { background: #fff; }
}
