:root {
  --bg: #f4f6fa;
  --panel: #ffffff;
  --line: #e4e8f0;
  --text: #1a2233;
  --muted: #7a8699;
  --brand: #f27a1a;
  --brand-dark: #d9660b;
  --green: #12a150;
  --red: #dc2626;
  --amber: #d97706;
  --blue: #2563eb;
  --radius: 10px;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 14px/1.45 "Segoe UI", system-ui, -apple-system, Arial, sans-serif;
}

/* ---------- Login ---------- */
.login-wrap { min-height: 100vh; display: flex; align-items: center; justify-content: center; }
.login-card {
  background: #fff; padding: 32px; border-radius: 14px; width: 320px;
  box-shadow: 0 10px 40px rgba(20,30,60,.12); text-align: center;
}
.login-card h1 { margin: 0; font-size: 26px; }
.login-card input { width: 100%; margin: 18px 0 12px; }
.err { color: var(--red); margin-top: 10px; font-size: 13px; }

/* ---------- Topbar ---------- */
.topbar {
  background: #fff; border-bottom: 1px solid var(--line);
  padding: 0 22px; display: flex; align-items: center; gap: 30px;
  position: sticky; top: 0; z-index: 40;
}
.brand { display: flex; align-items: center; gap: 11px; padding: 12px 0; }
.logo {
  width: 34px; height: 34px; border-radius: 9px; background: var(--brand);
  color: #fff; display: grid; place-items: center; font-weight: 700; font-size: 17px;
}
.brand strong { display: block; font-size: 15px; line-height: 1.1; }
.brand small { color: var(--muted); font-size: 11.5px; }

.tabs { display: flex; gap: 2px; }
.tab {
  background: none; border: 0; border-bottom: 2px solid transparent;
  padding: 18px 14px; font-size: 14px; color: var(--muted); cursor: pointer; font-family: inherit;
}
.tab:hover { color: var(--text); }
.tab.active { color: var(--brand); border-bottom-color: var(--brand); font-weight: 600; }

main { padding: 20px; max-width: 1560px; margin: 0 auto; }
.page { display: none; }
.page.active { display: block; }

/* ---------- Cards ---------- */
.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); gap: 12px; margin-bottom: 18px; }
.card {
  background: #fff; border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px;
}
.card .v { font-size: 26px; font-weight: 700; line-height: 1.1; }
.card .l { color: var(--muted); font-size: 12.5px; margin-top: 4px; }
.card.warn .v { color: var(--amber); }
.card.bad .v { color: var(--red); }
.card.good .v { color: var(--green); }

/* ---------- Panel ---------- */
.panel {
  background: var(--panel); border: 1px solid var(--line);
  border-radius: var(--radius); margin-bottom: 18px; overflow: hidden;
}
.panel-head {
  display: flex; align-items: center; justify-content: space-between; gap: 14px;
  padding: 14px 16px; border-bottom: 1px solid var(--line); flex-wrap: wrap;
}
.panel-head h2 { margin: 0; font-size: 15px; }
.head-actions { display: flex; gap: 8px; align-items: center; }

/* Tablo satırındaki aksiyon butonları: alt alta kaymasın, yan yana kalsın */
.row-actions { display: flex; gap: 6px; align-items: center; flex-wrap: nowrap; }
.row-actions .btn { white-space: nowrap; }

/* Üst çubuğun sağ ucu: kullanıcı adı + Çıkış */
.topbar-right { margin-left: auto; display: flex; align-items: center; gap: 10px; }
.topbar-right #whoami { font-size: 13px; }

.actions { padding: 16px; display: flex; gap: 10px; flex-wrap: wrap; }
.filters { padding: 12px 16px; display: flex; gap: 10px; align-items: center; border-bottom: 1px solid var(--line); flex-wrap: wrap; }
.filters input[type=search] { width: 340px; }

/* ---------- Buttons / inputs ---------- */
.btn {
  border: 1px solid var(--line); background: #fff; color: var(--text);
  padding: 8px 14px; border-radius: 8px; cursor: pointer; font-size: 13.5px; font-family: inherit;
  white-space: nowrap;
}
.btn:hover { background: #f7f9fc; }
.btn.primary { background: var(--brand); border-color: var(--brand); color: #fff; font-weight: 600; }
.btn.primary:hover { background: var(--brand-dark); }
.btn.ghost { background: #f7f9fc; }
.btn.small { padding: 5px 10px; font-size: 12.5px; }
.btn.danger { color: var(--red); border-color: #f6cfcf; }
.btn:disabled { opacity: .55; cursor: not-allowed; }

input, select {
  border: 1px solid var(--line); border-radius: 8px; padding: 8px 10px;
  font-size: 13.5px; font-family: inherit; background: #fff; color: var(--text);
}
input:focus, select:focus { outline: 2px solid #ffd9b8; border-color: var(--brand); }
input[type=number] { width: 84px; }

/* ---------- Tables ---------- */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th {
  text-align: left; font-size: 11.5px; text-transform: uppercase; letter-spacing: .4px;
  color: var(--muted); font-weight: 600; padding: 10px 12px; border-bottom: 1px solid var(--line);
  background: #fafbfd; white-space: nowrap;
}
td { padding: 10px 12px; border-bottom: 1px solid #f0f2f7; vertical-align: middle; }
tr:hover td { background: #fcfdff; }
td.c, th.c { text-align: center; }
.thumb { width: 40px; height: 40px; object-fit: cover; border-radius: 6px; background: #eef1f6; display: block; }
.ptitle { font-weight: 500; max-width: 380px; }
.ptitle a { color: inherit; text-decoration: none; }
.ptitle a:hover { color: var(--brand); }
.psub { color: var(--muted); font-size: 12px; margin-top: 2px; }
code, .mono { font-family: "Consolas", "Courier New", monospace; font-size: 12.5px; }

/* ---------- Badges / chips ---------- */
.badge {
  display: inline-block; padding: 2px 8px; border-radius: 20px;
  font-size: 11.5px; font-weight: 600; white-space: nowrap;
}
.b-gray { background: #eef1f6; color: #64748b; }
.b-green { background: #e3f7ec; color: #0d7a3e; }
.b-red { background: #fdeaea; color: #b91c1c; }
.b-amber { background: #fef3e2; color: #b45309; }
.b-blue { background: #e8f0fe; color: #1d4ed8; }

.chip {
  display: inline-flex; align-items: center; gap: 5px; background: #f2f5fa;
  border: 1px solid var(--line); border-radius: 6px; padding: 2px 8px;
  font-size: 12px; margin: 2px 4px 2px 0;
}
.chip b { font-weight: 700; }
.chip .x-qty { color: var(--brand); font-weight: 700; }
.chip .avail { color: var(--muted); }

/* ---------- Reçete sayfası ---------- */
.rc-target { display: flex; align-items: center; gap: 12px; padding: 14px 16px; border-bottom: 1px solid var(--line); }
.rc-target img { width: 54px; height: 54px; object-fit: cover; border-radius: 8px; flex: 0 0 54px; }
.rc-target .thumb { width: 54px; height: 54px; flex: 0 0 54px; }
.rc-target .t { font-weight: 600; }
.rc-help { padding: 12px 16px; font-size: 13px; color: var(--muted); line-height: 1.55; }

.rc-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; align-items: start; }
@media (max-width: 1100px) { .rc-grid { grid-template-columns: 1fr; } }

.rc-rows { padding: 10px 16px 4px; min-height: 90px; }
.rc-row { display: flex; align-items: center; gap: 11px; padding: 9px 0; border-bottom: 1px solid var(--line); }
.rc-row:last-child { border-bottom: 0; }
.rc-row img { width: 42px; height: 42px; object-fit: cover; border-radius: 6px; flex: 0 0 42px; background: #eef1f6; }
.rc-row .thumb { width: 42px; height: 42px; flex: 0 0 42px; }
.rc-row .info { flex: 1 1 auto; min-width: 0; }
.rc-row .info .t { font-weight: 600; font-size: 13.5px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.rc-row .info .s { font-size: 12px; color: var(--muted); }
.rc-row input[type=number] { width: 68px; text-align: center; }
.rc-row .yield { font-size: 12px; color: var(--muted); white-space: nowrap; min-width: 74px; text-align: right; }
.rc-row .del { border: 0; background: transparent; cursor: pointer; color: var(--muted); font-size: 20px; line-height: 1; padding: 0 2px; }
.rc-row .del:hover { color: var(--red); }
.rc-empty { padding: 22px 4px; color: var(--muted); }

.rc-picker { max-height: 560px; overflow-y: auto; padding: 6px 16px 14px; }
.rc-item { display: flex; align-items: center; gap: 11px; padding: 8px 0; border-bottom: 1px solid var(--line); }
.rc-item:last-child { border-bottom: 0; }
.rc-item img { width: 40px; height: 40px; object-fit: cover; border-radius: 6px; flex: 0 0 40px; background: #eef1f6; }
.rc-item .thumb { width: 40px; height: 40px; flex: 0 0 40px; }
.rc-item .info { flex: 1 1 auto; min-width: 0; }
.rc-item .info .t { font-size: 13px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.rc-item .info .s { font-size: 11.5px; color: var(--muted); }
.rc-item .qty { font-size: 12px; color: var(--muted); white-space: nowrap; }
.rc-more { padding: 12px 4px; color: var(--muted); font-size: 12.5px; }

/* Chip içindeki "havuzdan çıkar" düğmesi */
.chip-x {
  border: 0; background: transparent; cursor: pointer; padding: 0 0 0 3px;
  color: var(--muted); font-size: 15px; line-height: 1; font-weight: 700;
}
.chip-x:hover { color: var(--red); }

.num { font-weight: 700; font-size: 15px; }
.num.zero { color: var(--red); }
.num.low { color: var(--amber); }

/* ---------- Misc ---------- */
.muted { color: var(--muted); font-size: 12.5px; }
.pager { padding: 12px 16px; display: flex; gap: 8px; align-items: center; }
.runlog {
  margin: 0 16px 16px; background: #101827; color: #cbd5e1; border-radius: 8px;
  padding: 12px 14px; font-family: Consolas, monospace; font-size: 12.5px;
  max-height: 220px; overflow-y: auto; display: none; white-space: pre-wrap;
}
.runlog.on { display: block; }
.form-grid { padding: 16px; display: flex; flex-direction: column; gap: 16px; max-width: 560px; }
.form-grid label { display: flex; flex-direction: column; gap: 6px; }
.form-grid label > span { font-size: 13px; font-weight: 600; }
.switch-row { flex-direction: row !important; align-items: center; gap: 9px !important; }
.kv { padding: 16px; display: grid; grid-template-columns: 220px 1fr; gap: 8px 16px; font-size: 13.5px; }
.kv div:nth-child(odd) { color: var(--muted); }
.help { padding: 16px; font-size: 13.5px; line-height: 1.7; }
.help code { background: #f2f5fa; padding: 1px 6px; border-radius: 4px; }
.help ul { margin: 6px 0; }
.warn { color: var(--amber); font-size: 12.5px; }

/* ---------- Toast ---------- */
.toast {
  position: fixed; right: 20px; bottom: 20px; z-index: 100;
  background: #101827; color: #fff; padding: 12px 18px; border-radius: 10px;
  box-shadow: 0 8px 30px rgba(0,0,0,.25); display: none; max-width: 460px; font-size: 13.5px;
}
.toast.on { display: block; }
.toast.ok { background: #0d7a3e; }
.toast.bad { background: #b91c1c; }

/* ---------- Modal ---------- */
.modal-back {
  position: fixed; inset: 0; background: rgba(15,23,42,.45); z-index: 90;
  display: none; align-items: center; justify-content: center; padding: 20px;
}
.modal-back.on { display: flex; }
.modal {
  background: #fff; border-radius: 12px; width: 720px; max-width: 100%;
  max-height: 90vh; display: flex; flex-direction: column;
  box-shadow: 0 20px 60px rgba(0,0,0,.2);
}
.modal.small { width: 440px; }
.modal-head { padding: 16px 20px; border-bottom: 1px solid var(--line); display: flex; justify-content: space-between; align-items: center; }
.modal-head h3 { margin: 0; font-size: 16px; }
.modal-head .x { border: 0; background: none; font-size: 26px; line-height: 1; cursor: pointer; color: var(--muted); }
.modal-body { padding: 20px; overflow-y: auto; display: flex; flex-direction: column; gap: 12px; }
.modal-body label { display: flex; flex-direction: column; gap: 6px; }
.modal-body label > span { font-size: 13px; font-weight: 600; }
.modal-foot { padding: 14px 20px; border-top: 1px solid var(--line); display: flex; justify-content: flex-end; gap: 10px; }

.listing-info { display: flex; gap: 12px; align-items: center; background: #f7f9fc; padding: 12px; border-radius: 8px; }
.listing-info img { width: 52px; height: 52px; object-fit: cover; border-radius: 6px; }

.rrow { display: grid; grid-template-columns: 1fr 110px 90px 36px; gap: 8px; align-items: center; margin-bottom: 8px; }
.rrow .stat { font-size: 12px; color: var(--muted); text-align: center; }
.rrow .del { border: 0; background: none; color: var(--red); font-size: 19px; cursor: pointer; }
.calc {
  background: #f0fdf4; border: 1px solid #bbf7d0; color: #14532d;
  padding: 11px 14px; border-radius: 8px; font-size: 13.5px;
}
.calc.empty { background: #fff7ed; border-color: #fed7aa; color: #9a3412; }

.stock-ops { display: flex; gap: 6px; align-items: center; }
.stock-ops input { width: 76px; }

/* ---------- Toplu seçim ---------- */
.bulkbar {
  display: none; align-items: center; gap: 10px;
  padding: 11px 16px; background: #fff7ed; border-bottom: 1px solid #fed7aa;
  font-size: 13.5px; position: sticky; top: 58px; z-index: 20;
}
.bulkbar.on { display: flex; }
.bulkbar b { font-size: 16px; color: var(--brand); }
tr.sel td { background: #fff9f2 !important; }

.linkchips { margin-top: 4px; }
.linkchips .chip { font-size: 11.5px; padding: 1px 6px; }

/* ---------- Bağlama modalı ---------- */
.modal.wide { width: 900px; }
.linklist {
  max-height: 180px; overflow-y: auto; border: 1px solid var(--line);
  border-radius: 8px; padding: 8px;
}
.lk-row { display: flex; gap: 10px; align-items: center; padding: 5px 4px; }
.lk-row img, .lk-row .thumb { width: 34px; height: 34px; object-fit: cover; border-radius: 5px; flex: 0 0 34px; }
.lk-row > div { font-size: 13px; line-height: 1.35; }

/* ---------- Gruplama modalı ---------- */
.gm-summary {
  display: flex; gap: 18px; flex-wrap: wrap; background: #f7f9fc;
  border: 1px solid var(--line); border-radius: 8px; padding: 11px 14px; font-size: 13px;
}
.gm-summary b { font-size: 16px; color: var(--brand); }
.gm-tools { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.gm-list { max-height: 46vh; overflow-y: auto; }
.gm-item {
  border: 1px solid var(--line); border-radius: 9px; overflow: hidden;
  margin-bottom: 8px; flex: 0 0 auto;
}
.gm-item.on { border-color: var(--brand); background: #fffaf5; }
.gm-head {
  display: flex; gap: 11px; align-items: center; padding: 10px 12px; cursor: pointer;
  flex-direction: row !important;
}
.gm-head img, .gm-head .thumb { width: 40px; height: 40px; object-fit: cover; border-radius: 6px; flex: 0 0 40px; }
.gm-title { flex: 1; font-size: 13.5px; display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }
.gm-title > div { flex-basis: 100%; }
.gm-qty { display: flex; flex-direction: column; gap: 3px; align-items: center; }
.gm-qty .muted { font-size: 11px; }
.gm-qty input { width: 74px; text-align: center; font-weight: 700; }
.gm-barcodes { padding: 0 12px 10px 63px; }
.modal-foot .muted { margin-right: auto; }

/* ---------- Kurulum yardımcısı ---------- */
.step {
  border: 1px solid var(--line); border-radius: 9px; padding: 14px;
  display: flex; flex-direction: column; gap: 9px; align-items: flex-start;
  flex: 0 0 auto;
}
.modal-body > .gm-summary,
.modal-body > #gmDupes { flex: 0 0 auto; }
.linklist { flex: 0 0 auto; }
.step > b { font-size: 14px; }
.step p { margin: 0; }
.step .gm-tools { width: 100%; }
.step .gm-tools input[type=search] { flex: 1; min-width: 200px; }
.step .gm-list { width: 100%; max-height: 40vh; }

.fam-body { padding: 0 12px 10px; }
.fam-sec { margin-top: 6px; }
.fam-lbl {
  display: block; font-size: 11px; text-transform: uppercase; letter-spacing: .4px;
  color: var(--muted); font-weight: 600; margin: 6px 0 3px;
}
.fam-row {
  display: flex; align-items: center; gap: 9px; padding: 5px 8px;
  border: 1px solid var(--line); border-radius: 7px; margin-bottom: 5px; background: #fff;
}
.fam-row.ok { border-color: #bbf7d0; background: #f7fdf9; }
.fam-row img, .fam-row .thumb { width: 32px; height: 32px; object-fit: cover; border-radius: 5px; flex: 0 0 32px; }
.fam-info { flex: 1; display: flex; flex-wrap: wrap; gap: 6px; align-items: center; font-size: 12.5px; }
