:root {
  --bg: #f3f2ee;
  --surface: #ffffff;
  --surface-2: #f8f7f4;
  --ink: #1a1d21;
  --ink-2: #3d434b;
  --muted: #6c727a;
  --line: #e2e0da;
  --accent: #e2580b;
  --accent-ink: #ffffff;
  --accent-soft: #fdeee4;
  --ok: #2b8a3e;
  --ok-soft: #e6f4ea;
  --bad: #c92a2a;
  --bad-soft: #fdecec;
  --warn: #b7791f;
  --warn-soft: #fdf5e3;
  --bar: #1a1d21;
  --bar-ink: #ffffff;
  --radius: 14px;
  --shadow: 0 1px 2px rgba(0,0,0,.06), 0 4px 14px rgba(0,0,0,.05);
  --mono: ui-monospace, "SF Mono", "Cascadia Mono", "Roboto Mono", Menlo, Consolas, monospace;
  --safe-b: env(safe-area-inset-bottom, 0px);
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #111316;
    --surface: #1b1e22;
    --surface-2: #22262b;
    --ink: #eceef1;
    --ink-2: #c8ccd2;
    --muted: #8e959e;
    --line: #2e3238;
    --accent: #ff7a2e;
    --accent-ink: #1a0d04;
    --accent-soft: #3a2416;
    --ok: #51c46b;
    --ok-soft: #173020;
    --bad: #ff6b6b;
    --bad-soft: #3a1a1a;
    --warn: #f2b84b;
    --warn-soft: #3a2f16;
    --bar: #0b0c0e;
    --shadow: 0 1px 2px rgba(0,0,0,.4);
    color-scheme: dark;
  }
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; padding: 0; }
body {
  background: var(--bg);
  color: var(--ink);
  font: 16px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  min-height: 100dvh;
  overscroll-behavior-y: contain;
}
button, input, select, textarea { font: inherit; color: inherit; }
a { color: inherit; }
.mono { font-family: var(--mono); letter-spacing: -.01em; }
.muted { color: var(--muted); }
.num { font-variant-numeric: tabular-nums; }
.hidden { display: none !important; }

/* ---------- Üst çubuk ---------- */
.appbar {
  position: sticky; top: 0; z-index: 20;
  background: var(--bar); color: var(--bar-ink);
  display: flex; align-items: center; gap: 4px;
  min-height: 56px; padding: 0 6px;
  padding-top: env(safe-area-inset-top, 0px);
}
.appbar h1 {
  flex: 1; margin: 0 6px; font-size: 18px; font-weight: 650;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.appbar h1 small { display: block; font-size: 12px; font-weight: 400; opacity: .7; }
.iconbtn {
  width: 44px; height: 44px; border: 0; background: transparent; border-radius: 12px;
  display: inline-grid; place-items: center; cursor: pointer; color: inherit; flex: none;
}
.iconbtn:active { background: rgba(127,127,127,.2); }
.iconbtn svg { width: 24px; height: 24px; }

main#view { padding: 12px 12px calc(96px + var(--safe-b)); max-width: 720px; margin: 0 auto; }

/* ---------- Kartlar / listeler ---------- */
.card {
  background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow);
  padding: 14px; margin-bottom: 12px;
}
.list { list-style: none; margin: 0; padding: 0; }
.row {
  display: flex; align-items: center; gap: 12px;
  background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow);
  padding: 12px; margin-bottom: 8px; cursor: pointer; text-decoration: none; min-height: 64px;
  border: 0; width: 100%; text-align: left;
}
.row:active { transform: scale(.99); background: var(--surface-2); }
.row .body { flex: 1; min-width: 0; }
.row .title { font-weight: 600; overflow: hidden; text-overflow: ellipsis; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; }
.row .sub { font-size: 13px; color: var(--muted); margin-top: 2px; display: flex; gap: 10px; flex-wrap: wrap; }
.row .right { text-align: right; flex: none; }
.thumb {
  width: 52px; height: 52px; border-radius: 10px; flex: none; object-fit: cover;
  background: var(--surface-2); display: grid; place-items: center; color: var(--muted);
  font-size: 11px; overflow: hidden;
}
.thumb svg { width: 24px; height: 24px; opacity: .5; }

.chip {
  display: inline-flex; align-items: center; gap: 4px;
  padding: 2px 8px; border-radius: 999px; font-size: 12px; font-weight: 600;
  background: var(--surface-2); color: var(--ink-2); white-space: nowrap;
}
.chip.accent { background: var(--accent-soft); color: var(--accent); }
.chip.ok { background: var(--ok-soft); color: var(--ok); }
.chip.bad { background: var(--bad-soft); color: var(--bad); }
.chip.warn { background: var(--warn-soft); color: var(--warn); }

.count-badge { font-size: 20px; font-weight: 700; font-variant-numeric: tabular-nums; line-height: 1.1; }
.count-badge small { display: block; font-size: 11px; font-weight: 500; color: var(--muted); }

.section-title {
  font-size: 13px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted);
  margin: 18px 4px 8px; font-weight: 600; display: flex; justify-content: space-between; align-items: baseline;
}

/* ---------- Arama ---------- */
.searchbar {
  position: sticky; top: 56px; z-index: 15;
  background: var(--bg); padding: 10px 0 8px; margin: -12px 0 6px;
  display: flex; gap: 8px;
}
.searchbar .field { flex: 1; position: relative; }
.searchbar input {
  width: 100%; height: 52px; border-radius: 14px; border: 2px solid var(--line);
  background: var(--surface); padding: 0 44px 0 44px; font-size: 17px; outline: none;
}
.searchbar input:focus { border-color: var(--accent); }
.searchbar .ico { position: absolute; left: 13px; top: 14px; width: 22px; height: 22px; color: var(--muted); pointer-events: none; }
.searchbar .clear { position: absolute; right: 4px; top: 4px; }
.scanbtn {
  width: 56px; height: 52px; border-radius: 14px; border: 0; flex: none;
  background: var(--accent); color: var(--accent-ink); display: grid; place-items: center; cursor: pointer;
}
.scanbtn svg { width: 28px; height: 28px; }
.scanbtn:active { filter: brightness(.9); }

/* ---------- Formlar ---------- */
.form label { display: block; font-size: 13px; font-weight: 600; color: var(--ink-2); margin-bottom: 12px; }
.form input:not([type=checkbox]):not([type=radio]), .form select, .form textarea {
  display: block; width: 100%; margin-top: 6px; height: 48px; padding: 0 12px;
  border-radius: 12px; border: 2px solid var(--line); background: var(--surface); outline: none; font-size: 16px;
}
.form textarea { height: auto; min-height: 80px; padding: 10px 12px; }
.form input:focus, .form select:focus, .form textarea:focus { border-color: var(--accent); }
.form fieldset { border: 1px solid var(--line); border-radius: var(--radius); padding: 10px 14px 4px; margin: 0 0 14px; }
.form legend { font-weight: 700; padding: 0 6px; }
.form .radio, .form .check { display: flex; align-items: center; gap: 10px; font-weight: 500; font-size: 15px; min-height: 40px; }
.form .radio input, .form .check input { width: 20px; height: 20px; accent-color: var(--accent); }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }

.qty-wrap { position: relative; }
.qty-wrap input {
  height: 72px !important; font-size: 34px !important; font-weight: 700; text-align: right;
  padding-right: 76px !important; font-variant-numeric: tabular-nums;
}
.qty-wrap .unit {
  position: absolute; right: 14px; bottom: 22px; font-size: 18px; font-weight: 600; color: var(--muted);
  max-width: 60px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 48px; padding: 0 18px; border-radius: 12px; border: 0; cursor: pointer;
  background: var(--surface-2); color: var(--ink); font-weight: 650; font-size: 16px; text-decoration: none;
}
.btn.primary { background: var(--accent); color: var(--accent-ink); }
.btn.danger { background: var(--bad-soft); color: var(--bad); }
.btn.ghost { background: transparent; }
.btn.block { width: 100%; }
.btn.lg { min-height: 58px; font-size: 18px; }
.btn.sm { min-height: 36px; padding: 0 12px; font-size: 14px; border-radius: 10px; }
.btn:disabled { opacity: .5; cursor: default; }
.btn:active:not(:disabled) { filter: brightness(.93); }
.btn svg { width: 20px; height: 20px; }
.btnrow { display: flex; gap: 10px; }
.btnrow > * { flex: 1; }

.note { padding: 12px 14px; border-radius: 12px; background: var(--surface-2); font-size: 14px; margin: 0 0 12px; }
.note.err { background: var(--bad-soft); color: var(--bad); }
.note.ok { background: var(--ok-soft); color: var(--ok); }
.note.warn { background: var(--warn-soft); color: var(--warn); }

.empty { text-align: center; color: var(--muted); padding: 40px 20px; }
.empty svg { width: 48px; height: 48px; opacity: .4; display: block; margin: 0 auto 10px; }

/* ---------- Stok başlık kartı ---------- */
.stock-head { display: flex; gap: 14px; align-items: flex-start; }
.stock-head .img {
  width: 96px; height: 96px; border-radius: 12px; object-fit: cover; flex: none;
  background: var(--surface-2); display: grid; place-items: center; cursor: zoom-in;
}
.stock-head .img svg { width: 34px; height: 34px; opacity: .4; }
.stock-head h2 { margin: 0 0 4px; font-size: 18px; line-height: 1.25; }
.stock-head .code { font-family: var(--mono); font-size: 15px; font-weight: 600; color: var(--accent); }
.kv { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; }

.total-strip {
  display: flex; justify-content: space-between; align-items: center;
  background: var(--bar); color: var(--bar-ink); border-radius: var(--radius); padding: 12px 16px; margin: 12px 0;
}
.total-strip b { font-size: 26px; font-variant-numeric: tabular-nums; }

/* ---------- Giriş listesi ---------- */
.entry {
  display: grid; grid-template-columns: 1fr auto; gap: 2px 10px; align-items: center;
  padding: 10px 12px; border-bottom: 1px solid var(--line);
}
.entry:last-child { border-bottom: 0; }
.entry .loc { font-weight: 600; }
.entry .qty { font-size: 18px; font-weight: 700; text-align: right; font-variant-numeric: tabular-nums; }
.entry .meta { grid-column: 1 / -1; font-size: 12px; color: var(--muted); }
.entry.mine { cursor: pointer; }
.entry.mine .loc::after { content: "düzenle"; font-size: 11px; font-weight: 600; color: var(--accent); margin-left: 8px; }
.entry.pending { opacity: .65; }
.card.flush { padding: 0; overflow: hidden; }

/* ---------- Reçete ---------- */
details.acc { background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow); margin-bottom: 10px; }
details.acc > summary {
  list-style: none; padding: 14px; font-weight: 650; cursor: pointer; display: flex; justify-content: space-between; align-items: center;
}
details.acc > summary::-webkit-details-marker { display: none; }
details.acc > summary::after { content: "›"; font-size: 22px; transform: rotate(90deg); transition: transform .15s; color: var(--muted); }
details.acc[open] > summary::after { transform: rotate(-90deg); }
.rec-line { display: flex; gap: 10px; padding: 10px 14px; border-top: 1px solid var(--line); align-items: center; cursor: pointer; }
.rec-line .body { flex: 1; min-width: 0; }
.rec-line .q { font-weight: 700; font-variant-numeric: tabular-nums; white-space: nowrap; }

.tree { font-size: 15px; }
.tree .node { display: flex; align-items: center; gap: 8px; padding: 9px 12px 9px 0; border-top: 1px solid var(--line); }
.tree .node .body { flex: 1; min-width: 0; }
.tree .node .q { font-weight: 700; font-variant-numeric: tabular-nums; text-align: right; white-space: nowrap; }
.tree .node .q small { display: block; font-weight: 400; color: var(--muted); font-size: 11px; }
.tree .lvl { flex: none; width: 22px; height: 22px; border-radius: 6px; display: grid; place-items: center; font-size: 11px; font-weight: 700; background: var(--surface-2); color: var(--muted); }
.tree .node.leaf .lvl { background: var(--accent-soft); color: var(--accent); }
.tree .hit { background: var(--warn-soft); }
mark { background: var(--warn-soft); color: inherit; border-radius: 3px; padding: 0 1px; }

.seg { display: flex; background: var(--surface-2); border-radius: 12px; padding: 4px; gap: 4px; margin-bottom: 12px; }
.seg button { flex: 1; border: 0; background: transparent; border-radius: 9px; min-height: 40px; font-weight: 600; cursor: pointer; color: var(--muted); }
.seg button.on { background: var(--surface); color: var(--ink); box-shadow: var(--shadow); }

/* ---------- Alt sayfa (sheet), toast ---------- */
.sheet-back {
  position: fixed; inset: 0; background: rgba(0,0,0,.45); z-index: 50;
  display: flex; align-items: flex-end; justify-content: center; animation: fade .15s;
}
.sheet {
  background: var(--surface); width: 100%; max-width: 560px; border-radius: 20px 20px 0 0;
  padding: 10px 16px calc(16px + var(--safe-b)); max-height: 92dvh; overflow: auto; animation: up .2s ease-out;
}
.sheet::before { content: ""; display: block; width: 40px; height: 5px; border-radius: 3px; background: var(--line); margin: 0 auto 12px; }
.sheet h3 { margin: 0 0 14px; font-size: 18px; }
@media (min-width: 700px) {
  .sheet-back { align-items: center; }
  .sheet { border-radius: 20px; }
}
@keyframes up { from { transform: translateY(40px); opacity: 0; } }
@keyframes fade { from { opacity: 0; } }

#toast {
  position: fixed; left: 50%; bottom: calc(24px + var(--safe-b)); transform: translateX(-50%) translateY(20px);
  background: var(--bar); color: var(--bar-ink); padding: 12px 18px; border-radius: 12px; z-index: 80;
  font-weight: 600; box-shadow: 0 6px 24px rgba(0,0,0,.25); opacity: 0; pointer-events: none; transition: .2s;
  max-width: calc(100vw - 32px); text-align: center;
}
#toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
#toast.ok { background: var(--ok); color: #fff; }
#toast.err { background: var(--bad); color: #fff; }

.outbox {
  position: fixed; left: 12px; right: 12px; bottom: calc(12px + var(--safe-b)); z-index: 30;
  background: var(--warn-soft); color: var(--warn); border-radius: 12px; padding: 10px 14px; font-weight: 600; font-size: 14px;
  display: flex; justify-content: space-between; align-items: center; box-shadow: var(--shadow); max-width: 696px; margin: 0 auto;
}

/* ---------- Tarayıcı ---------- */
.scanner { position: fixed; inset: 0; background: #000; z-index: 90; display: flex; flex-direction: column; }
.scanner video { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; }
.scanner .frame {
  position: absolute; left: 8%; right: 8%; top: 32%; height: 22%;
  border-radius: 16px; box-shadow: 0 0 0 100vmax rgba(0,0,0,.45); border: 3px solid rgba(255,255,255,.85);
}
.scanner .frame::after {
  content: ""; position: absolute; left: 6%; right: 6%; top: 50%; height: 2px; background: var(--accent);
  box-shadow: 0 0 12px var(--accent); animation: scanline 1.6s ease-in-out infinite alternate;
}
@keyframes scanline { from { top: 15%; } to { top: 85%; } }
.scanner .top, .scanner .bottom { position: relative; z-index: 2; display: flex; align-items: center; gap: 8px; padding: 12px; color: #fff; }
.scanner .top { padding-top: calc(12px + env(safe-area-inset-top, 0px)); }
.scanner .top .t { flex: 1; font-weight: 600; }
.scanner .bottom { margin-top: auto; padding-bottom: calc(18px + var(--safe-b)); flex-direction: column; align-items: stretch; }
.scanner .msg { text-align: center; font-size: 14px; opacity: .9; margin-bottom: 8px; }
.scanner .manual { display: flex; gap: 8px; }
.scanner .manual input { flex: 1; height: 48px; border-radius: 12px; border: 0; padding: 0 12px; font-size: 17px; background: rgba(255,255,255,.95); color: #000; }
.scanner .iconbtn { background: rgba(0,0,0,.35); }
.scanner .iconbtn.on { background: var(--accent); }

/* ---------- Giriş / kurulum ---------- */
.login-wrap { min-height: 100dvh; display: grid; place-items: center; padding: 24px 16px; }
.login { width: 100%; max-width: 380px; }
.login .brand { display: flex; align-items: center; gap: 12px; margin-bottom: 24px; }
.login .brand .logo { width: 52px; height: 52px; border-radius: 14px; background: var(--bar); display: grid; place-items: center; }
.login .brand .logo svg { width: 30px; height: 30px; color: var(--accent); }
.login .brand h1 { margin: 0; font-size: 24px; }
.install-box { max-width: 480px; margin: 24px auto; padding: 0 16px 40px; }
.install-box h1 { font-size: 24px; }

.spinner { width: 28px; height: 28px; border: 3px solid var(--line); border-top-color: var(--accent); border-radius: 50%; animation: spin .7s linear infinite; margin: 30px auto; }
@keyframes spin { to { transform: rotate(360deg); } }

.zoom { position: fixed; inset: 0; z-index: 95; background: rgba(0,0,0,.9); display: grid; place-items: center; padding: 16px; }
.zoom img { max-width: 100%; max-height: 100%; border-radius: 8px; }

.menu { position: absolute; right: 8px; top: calc(52px + env(safe-area-inset-top, 0px)); background: var(--surface); color: var(--ink); border-radius: 14px; box-shadow: 0 10px 30px rgba(0,0,0,.25); min-width: 220px; padding: 6px; z-index: 60; }
.menu button, .menu a { display: flex; align-items: center; gap: 10px; width: 100%; min-height: 46px; padding: 0 12px; border: 0; background: transparent; border-radius: 10px; text-decoration: none; cursor: pointer; font-size: 15px; text-align: left; }
.menu button:active, .menu a:active { background: var(--surface-2); }
.menu .who { padding: 10px 12px; font-size: 13px; color: var(--muted); border-bottom: 1px solid var(--line); margin-bottom: 4px; }
.menu svg { width: 20px; height: 20px; color: var(--muted); }

/* ================= ADMIN ================= */
.admin main#view { max-width: 1180px; padding-bottom: 60px; }
.tabs { position: sticky; top: 56px; z-index: 18; background: var(--bar); display: flex; gap: 2px; overflow-x: auto; padding: 0 8px; scrollbar-width: none; }
.tabs::-webkit-scrollbar { display: none; }
.tabs a { color: rgba(255,255,255,.65); text-decoration: none; padding: 12px 14px; font-weight: 600; font-size: 15px; white-space: nowrap; border-bottom: 3px solid transparent; display: flex; gap: 8px; align-items: center; }
.tabs a svg { width: 18px; height: 18px; }
.tabs a.on { color: #fff; border-bottom-color: var(--accent); }
.toolbar { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin: 4px 0 14px; }
.toolbar h2 { margin: 0; flex: 1 1 200px; font-size: 22px; }
.toolbar .search { flex: 1 1 220px; height: 44px; border-radius: 12px; border: 2px solid var(--line); background: var(--surface); padding: 0 12px; outline: none; }
.toolbar .search:focus { border-color: var(--accent); }
.toolbar select { height: 44px; border-radius: 12px; border: 2px solid var(--line); background: var(--surface); padding: 0 10px; }
.tiles { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 10px; margin-bottom: 14px; }
.tile { background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow); padding: 12px 14px; border: 2px solid transparent; text-align: left; cursor: default; }
button.tile { cursor: pointer; font: inherit; color: inherit; }
button.tile.on { border-color: var(--accent); }
.tile .k { font-size: 12px; color: var(--muted); font-weight: 600; text-transform: uppercase; letter-spacing: .04em; }
.tile .v { font-size: 26px; font-weight: 750; font-variant-numeric: tabular-nums; margin-top: 2px; }
.tile .v.ok { color: var(--ok); } .tile .v.bad { color: var(--bad); } .tile .v.warn { color: var(--warn); }
.tblwrap { background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow); overflow: auto; max-height: 70vh; }
table.tbl { width: 100%; border-collapse: collapse; font-size: 14px; }
.tbl th, .tbl td { padding: 9px 10px; border-bottom: 1px solid var(--line); text-align: left; white-space: nowrap; }
.tbl th { position: sticky; top: 0; background: var(--surface-2); font-size: 12px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); cursor: pointer; user-select: none; z-index: 1; }
.tbl th.r, .tbl td.r { text-align: right; font-variant-numeric: tabular-nums; }
.tbl td.wrap { white-space: normal; min-width: 180px; }
.tbl tr.click { cursor: pointer; }
.tbl tr.click:hover td { background: var(--surface-2); }
.tbl .pos { color: var(--ok); font-weight: 700; } .tbl .neg { color: var(--bad); font-weight: 700; }
.tbl th .arrow { color: var(--accent); }
.progress { height: 10px; border-radius: 6px; background: var(--surface-2); overflow: hidden; margin: 10px 0; }
.progress > div { height: 100%; width: 0; background: var(--accent); transition: width .2s; }
.map-grid { display: grid; grid-template-columns: auto 1fr; gap: 8px 12px; align-items: center; margin: 10px 0 14px; font-size: 14px; }
.map-grid select { height: 40px; border-radius: 10px; border: 2px solid var(--line); background: var(--surface); padding: 0 8px; }
.preview { font-size: 12px; }
.userpick { max-height: 260px; overflow: auto; border: 1px solid var(--line); border-radius: 12px; padding: 4px 10px; margin-bottom: 14px; }
.cols2 { display: grid; grid-template-columns: 1fr; gap: 14px; }
@media (min-width: 900px) { .cols2 { grid-template-columns: 1fr 1fr; } }
.sheet.wide { max-width: 760px; }
.dropzone { border: 2px dashed var(--line); border-radius: var(--radius); padding: 22px; text-align: center; color: var(--muted); cursor: pointer; display: block; }
.dropzone:hover, .dropzone.over { border-color: var(--accent); color: var(--accent); }
.dropzone input { display: none; }
input[type=search]::-webkit-search-cancel-button { -webkit-appearance: none; display: none; }
.seg button { white-space: nowrap; padding: 0 12px; }
@media (max-width: 600px) {
  .tiles { grid-template-columns: repeat(3, 1fr); gap: 8px; }
  .tile { padding: 8px 10px; }
  .tile .k { font-size: 10px; }
  .tile .v { font-size: 20px; }
  .toolbar h2 { font-size: 19px; }
}
