/* WEICAR Saha Satış CRM — mobil öncelikli arayüz */

:root {
  --red: #e30613;
  --red-dark: #b30510;
  --red-soft: #fdecec;
  --ink: #14171a;
  --ink-2: #3d444d;
  --muted: #6b7480;
  --line: #e4e7ec;
  --bg: #f4f6f8;
  --card: #ffffff;
  --ok: #0f9d58;
  --ok-soft: #e7f6ee;
  --warn: #c77700;
  --warn-soft: #fdf3e2;
  --info: #1565c0;
  --info-soft: #e8f1fc;
  --radius: 14px;
  --shadow: 0 1px 2px rgba(16, 24, 40, .06), 0 4px 14px rgba(16, 24, 40, .05);
  --safe-b: env(safe-area-inset-bottom, 0px);
  --nav-h: calc(60px + var(--safe-b));
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  font-size: 15px;
  line-height: 1.45;
  -webkit-text-size-adjust: 100%;
}

body.no-scroll { overflow: hidden; }

h1, h2, h3, h4 { margin: 0 0 .5rem; line-height: 1.25; font-weight: 700; letter-spacing: -.01em; }
h1 { font-size: 1.3rem; }
h2 { font-size: 1.1rem; }
h3 { font-size: 1rem; }
p { margin: 0 0 .75rem; }
a { color: var(--red); text-decoration: none; }
small { font-size: .8rem; }

/* ---------- layout ---------- */

.app { min-height: 100vh; display: flex; flex-direction: column; }

.topbar {
  position: sticky; top: 0; z-index: 40;
  background: var(--ink); color: #fff;
  display: flex; align-items: center; gap: .6rem;
  padding: .7rem .9rem; padding-top: calc(.7rem + env(safe-area-inset-top, 0px));
  box-shadow: 0 1px 0 rgba(255,255,255,.06);
}
.topbar .brand { display: flex; align-items: center; gap: .5rem; font-weight: 800; letter-spacing: .04em; }
.topbar .brand .mark { width: 10px; height: 22px; border-radius: 2px; background: var(--red); display: inline-block; }
.topbar .title { font-size: 1rem; font-weight: 700; flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.topbar .icon-btn { background: rgba(255,255,255,.1); color: #fff; border: 0; width: 38px; height: 38px; border-radius: 10px; font-size: 1.1rem; display: grid; place-items: center; cursor: pointer; }
.topbar .icon-btn:active { background: rgba(255,255,255,.22); }
.topbar .rate { font-size: .72rem; opacity: .75; white-space: nowrap; }

main { flex: 1; padding: .9rem; padding-bottom: calc(var(--nav-h) + 1rem); max-width: 1200px; width: 100%; margin: 0 auto; }

/* ---------- bottom nav ---------- */

.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 45;
  background: #fff; border-top: 1px solid var(--line);
  display: grid; grid-template-columns: repeat(5, 1fr);
  padding-bottom: var(--safe-b);
}
.tabbar button {
  background: none; border: 0; padding: .45rem .2rem .5rem; cursor: pointer;
  display: flex; flex-direction: column; align-items: center; gap: 2px;
  color: var(--muted); font-size: .68rem; font-weight: 600; position: relative;
}
.tabbar button .ic { font-size: 1.25rem; line-height: 1; }
.tabbar button.active { color: var(--red); }
.tabbar .badge {
  position: absolute; top: 2px; right: calc(50% - 22px);
  background: var(--red); color: #fff; border-radius: 10px;
  font-size: .62rem; min-width: 17px; height: 17px; padding: 0 4px;
  display: grid; place-items: center; font-weight: 700;
}

/* ---------- cards & lists ---------- */

.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); padding: .9rem; margin-bottom: .8rem; }
.card.tight { padding: .7rem .8rem; }
.card-h { display: flex; align-items: center; justify-content: space-between; gap: .5rem; margin-bottom: .6rem; }
.card-h h2, .card-h h3 { margin: 0; }

.list { display: flex; flex-direction: column; gap: .6rem; }
.row { display: flex; align-items: center; gap: .7rem; }
.row.between { justify-content: space-between; }
.row.wrap { flex-wrap: wrap; }
.grow { flex: 1; min-width: 0; }
.muted { color: var(--muted); }
.right { text-align: right; }
.nowrap { white-space: nowrap; }
.ellipsis { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.mt { margin-top: .8rem; }
.mb { margin-bottom: .8rem; }
.center { text-align: center; }

.stat-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: .7rem; margin-bottom: .8rem; }
.stat { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: .8rem; box-shadow: var(--shadow); }
.stat .label { font-size: .72rem; color: var(--muted); font-weight: 600; text-transform: uppercase; letter-spacing: .03em; }
.stat .value { font-size: 1.25rem; font-weight: 800; margin-top: .15rem; letter-spacing: -.02em; }
.stat .sub { font-size: .75rem; color: var(--muted); }

/* ---------- buttons ---------- */

.btn {
  appearance: none; border: 1px solid var(--line); background: #fff; color: var(--ink);
  border-radius: 11px; padding: .62rem .9rem; font-size: .92rem; font-weight: 600;
  cursor: pointer; display: inline-flex; align-items: center; justify-content: center; gap: .4rem;
  min-height: 44px; transition: background .12s, border-color .12s;
}
.btn:active { background: #f1f3f5; }
.btn.primary { background: var(--red); border-color: var(--red); color: #fff; }
.btn.primary:active { background: var(--red-dark); }
.btn.dark { background: var(--ink); border-color: var(--ink); color: #fff; }
.btn.ghost { background: transparent; border-color: transparent; color: var(--ink-2); }
.btn.danger { color: var(--red); border-color: #f3c9cc; background: var(--red-soft); }
.btn.sm { min-height: 36px; padding: .35rem .65rem; font-size: .82rem; border-radius: 9px; }
.btn.block { width: 100%; }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn-row { display: flex; gap: .5rem; flex-wrap: wrap; }

/* ---------- forms ---------- */

.field { margin-bottom: .7rem; }
.field label { display: block; font-size: .78rem; font-weight: 700; color: var(--ink-2); margin-bottom: .25rem; }
input[type=text], input[type=email], input[type=password], input[type=number], input[type=date], input[type=tel], select, textarea {
  width: 100%; padding: .65rem .7rem; font-size: 16px; /* iOS zoom engelleme */
  border: 1px solid var(--line); border-radius: 11px; background: #fff; color: var(--ink);
  font-family: inherit; min-height: 44px;
}
textarea { min-height: 84px; resize: vertical; }
input:focus, select:focus, textarea:focus { outline: 2px solid rgba(227,6,19,.25); outline-offset: 1px; border-color: var(--red); }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: .6rem; }
.search { position: relative; margin-bottom: .8rem; }
.search input { padding-left: 2.2rem; }
.search::before { content: "🔍"; position: absolute; left: .7rem; top: 50%; transform: translateY(-50%); font-size: .95rem; opacity: .6; }

.chips { display: flex; gap: .4rem; overflow-x: auto; padding-bottom: .4rem; margin-bottom: .7rem; scrollbar-width: none; }
.chips::-webkit-scrollbar { display: none; }
.chip {
  flex: 0 0 auto; border: 1px solid var(--line); background: #fff; color: var(--ink-2);
  border-radius: 999px; padding: .38rem .8rem; font-size: .82rem; font-weight: 600; cursor: pointer; white-space: nowrap;
}
.chip.active { background: var(--ink); border-color: var(--ink); color: #fff; }

/* ---------- product grid ---------- */

.prod-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: .7rem; }
.prod {
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
  overflow: hidden; box-shadow: var(--shadow); display: flex; flex-direction: column;
}
.prod .thumb { position: relative; aspect-ratio: 1/1; background: #fff; display: grid; place-items: center; overflow: hidden; border-bottom: 1px solid var(--line); }
/* Not: .thumb aspect-ratio kullandigi icin yuzde max-height calismaz.
   Resmi mutlak konumlandirip object-fit ile sigdiriyoruz — uzun/dar
   fotograflar (orn. 276x900) da kutunun icinde kalir. */
.prod .thumb img { position: absolute; top: 6px; right: 6px; bottom: 6px; left: 6px; width: calc(100% - 12px); height: calc(100% - 12px); object-fit: contain; display: block; }
.prod .thumb .ph { font-size: 1.8rem; opacity: .25; }
.prod .body { padding: .55rem .6rem .6rem; display: flex; flex-direction: column; gap: .2rem; flex: 1; }
.prod .name { font-weight: 700; font-size: .86rem; line-height: 1.25; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.prod .sku { font-size: .68rem; color: var(--muted); letter-spacing: .02em; }
.prod .price { font-weight: 800; font-size: .98rem; margin-top: .15rem; }
.prod .price small { font-weight: 600; color: var(--muted); font-size: .7rem; display: block; }
.prod .foot { margin-top: auto; padding-top: .45rem; display: flex; align-items: center; justify-content: space-between; gap: .4rem; }

.stock-pill { font-size: .68rem; font-weight: 700; padding: .15rem .45rem; border-radius: 6px; background: var(--ok-soft); color: var(--ok); white-space: nowrap; }
.stock-pill.low { background: var(--warn-soft); color: var(--warn); }
.stock-pill.out { background: var(--red-soft); color: var(--red); }

.qty { display: inline-flex; align-items: center; border: 1px solid var(--line); border-radius: 10px; overflow: hidden; background: #fff; }
.qty button { width: 34px; height: 34px; border: 0; background: #fff; font-size: 1.1rem; font-weight: 700; color: var(--ink); cursor: pointer; }
.qty button:active { background: #eee; }
.qty input { width: 42px; text-align: center; border: 0; border-left: 1px solid var(--line); border-right: 1px solid var(--line); min-height: 34px; height: 34px; padding: 0; border-radius: 0; font-size: .9rem; font-weight: 700; }
.qty input:focus { outline: none; }

.add-btn { width: 36px; height: 36px; border-radius: 10px; border: 0; background: var(--red); color: #fff; font-size: 1.25rem; font-weight: 700; cursor: pointer; display: grid; place-items: center; line-height: 1; }
.add-btn:disabled { background: #cfd4da; }

/* ---------- badges ---------- */

.badge-s { display: inline-block; font-size: .7rem; font-weight: 700; padding: .18rem .5rem; border-radius: 999px; white-space: nowrap; }
.s-yeni { background: var(--info-soft); color: var(--info); }
.s-onaylandi { background: var(--warn-soft); color: var(--warn); }
.s-teslim { background: #eef0f3; color: var(--ink-2); }
.s-faturalandi { background: var(--ok-soft); color: var(--ok); }
.s-iptal { background: var(--red-soft); color: var(--red); }
.s-odendi { background: var(--ok-soft); color: var(--ok); }
.s-odenmedi { background: var(--warn-soft); color: var(--warn); }

/* ---------- item rows ---------- */

.item {
  display: flex; gap: .7rem; align-items: center; background: var(--card);
  border: 1px solid var(--line); border-radius: 12px; padding: .6rem .7rem; box-shadow: var(--shadow);
}
/* .ithumb her yerde kullanilir (liste satiri, urun duzenleme, urun detayi) —
   .item icine kisitlanmamali, yoksa disarida kalan resimler dogal boyutunda tasar */
.ithumb { width: 48px; height: 48px; border-radius: 9px; background: #f5f6f8; display: flex; align-items: center; justify-content: center; overflow: hidden; flex: 0 0 auto; }
.ithumb img { max-width: 100%; max-height: 100%; width: auto; height: auto; object-fit: contain; display: block; }
.item.link { cursor: pointer; }
.item.link:active { background: #fafbfc; }

/* Toplu secim cubugu (Urunler ve stok > Sec / sil) */
#secbar > .row { background: var(--info-soft); border: 1px solid #cfe1f8; border-radius: 10px; padding: .5rem .65rem; }
#secbar .btn[disabled] { opacity: .45; pointer-events: none; }

.kv { display: flex; justify-content: space-between; gap: 1rem; padding: .32rem 0; border-bottom: 1px dashed var(--line); font-size: .88rem; }
.kv:last-child { border-bottom: 0; }
.kv .k { color: var(--muted); }
.kv .v { font-weight: 600; text-align: right; }
.kv.total { font-size: 1.05rem; padding-top: .55rem; border-top: 2px solid var(--ink); border-bottom: 0; margin-top: .3rem; }
.kv.total .v { font-weight: 800; }

table.tbl { width: 100%; border-collapse: collapse; font-size: .85rem; }
table.tbl th, table.tbl td { padding: .5rem .4rem; text-align: left; border-bottom: 1px solid var(--line); }
table.tbl th { font-size: .72rem; text-transform: uppercase; letter-spacing: .03em; color: var(--muted); }
table.tbl td.num, table.tbl th.num { text-align: right; white-space: nowrap; }
.scroll-x { overflow-x: auto; -webkit-overflow-scrolling: touch; }

/* ---------- sheet / modal ---------- */

.overlay { position: fixed; inset: 0; background: rgba(12, 16, 20, .45); z-index: 60; display: flex; align-items: flex-end; justify-content: center; }
.sheet {
  background: #fff; width: 100%; max-width: 620px; max-height: 92vh; overflow-y: auto;
  border-radius: 18px 18px 0 0; padding: 1rem 1rem calc(1rem + var(--safe-b));
  animation: up .2s ease-out;
}
@keyframes up { from { transform: translateY(22px); opacity: .6; } to { transform: none; opacity: 1; } }
.sheet .handle { width: 40px; height: 4px; border-radius: 4px; background: var(--line); margin: 0 auto .8rem; }

.toast {
  position: fixed; left: 50%; transform: translateX(-50%);
  bottom: calc(var(--nav-h) + 12px); z-index: 90;
  background: var(--ink); color: #fff; padding: .65rem 1rem; border-radius: 11px;
  font-size: .88rem; font-weight: 600; box-shadow: 0 8px 24px rgba(0,0,0,.25); max-width: 92vw; text-align: center;
}
.toast.err { background: var(--red); }
.toast.ok { background: var(--ok); }

.empty { text-align: center; padding: 2.2rem 1rem; color: var(--muted); }
.empty .ic { font-size: 2.4rem; opacity: .35; display: block; margin-bottom: .4rem; }

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

.bar { height: 7px; background: #eef0f3; border-radius: 4px; overflow: hidden; }
.bar > i { display: block; height: 100%; background: var(--red); }

/* ---------- login ---------- */

.login-wrap { min-height: 100vh; display: grid; place-items: center; padding: 1.2rem; background: linear-gradient(160deg, #16191d 0%, #24282e 55%, #2c3036 100%); }
.login-card { width: 100%; max-width: 380px; background: #fff; border-radius: 18px; padding: 1.6rem 1.3rem; box-shadow: 0 20px 50px rgba(0,0,0,.35); }
.login-card .logo { display: flex; align-items: center; gap: .55rem; justify-content: center; margin-bottom: .3rem; }
.login-card .logo .mark { width: 12px; height: 30px; background: var(--red); border-radius: 3px; }
.login-card .logo span { font-size: 1.5rem; font-weight: 800; letter-spacing: .08em; }
.login-card .sub { text-align: center; color: var(--muted); font-size: .84rem; margin-bottom: 1.2rem; }
.alert { background: var(--red-soft); color: var(--red-dark); border: 1px solid #f3c9cc; border-radius: 10px; padding: .55rem .7rem; font-size: .84rem; font-weight: 600; margin-bottom: .7rem; }
.alert.info { background: var(--info-soft); color: var(--info); border-color: #cfe1f8; }
.alert.warn { background: var(--warn-soft); color: var(--warn); border-color: #f3e0bd; }

/* ---------- cart summary bar ---------- */

.cartbar {
  position: fixed; left: 0; right: 0; bottom: var(--nav-h); z-index: 44;
  background: var(--ink); color: #fff; padding: .6rem .9rem;
  display: flex; align-items: center; justify-content: space-between; gap: .7rem;
  box-shadow: 0 -4px 18px rgba(0,0,0,.18);
}
.cartbar .info { font-size: .8rem; opacity: .85; }
.cartbar .amount { font-size: 1.05rem; font-weight: 800; }

/* ---------- desktop ---------- */

@media (min-width: 760px) {
  .prod-grid { grid-template-columns: repeat(3, 1fr); }
  .stat-grid { grid-template-columns: repeat(4, 1fr); }
  main { padding: 1.2rem; }
}

@media (min-width: 1000px) {
  .prod-grid { grid-template-columns: repeat(4, 1fr); }
  .tabbar { grid-template-columns: repeat(5, 1fr); max-width: 620px; left: 50%; transform: translateX(-50%); border-radius: 14px 14px 0 0; border: 1px solid var(--line); border-bottom: 0; }
  .cartbar { max-width: 620px; left: 50%; transform: translateX(-50%); border-radius: 12px 12px 0 0; }
}

/* ---------- print (fatura) ---------- */

.invoice-sheet { background: #fff; padding: 1.1rem; border-radius: var(--radius); border: 1px solid var(--line); }
.inv-head { display: flex; justify-content: space-between; gap: 1rem; flex-wrap: wrap; border-bottom: 3px solid var(--red); padding-bottom: .7rem; margin-bottom: .9rem; }
.inv-head .co { font-size: 1.4rem; font-weight: 800; letter-spacing: .06em; }
.inv-meta { font-size: .82rem; }
.inv-parties { display: grid; grid-template-columns: 1fr; gap: .8rem; margin-bottom: 1rem; }
@media (min-width: 640px) { .inv-parties { grid-template-columns: 1fr 1fr; } }
.inv-box { border: 1px solid var(--line); border-radius: 10px; padding: .6rem .7rem; font-size: .84rem; }
.inv-box .h { font-size: .68rem; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); font-weight: 700; margin-bottom: .25rem; }
.inv-totals { margin-left: auto; max-width: 320px; margin-top: .8rem; }

@media print {
  @page { size: A4; margin: 12mm; }
  .topbar, .tabbar, .cartbar, .no-print, .btn { display: none !important; }
  body, main { background: #fff !important; padding: 0 !important; }
  main { padding-bottom: 0 !important; max-width: none; }
  .invoice-sheet { border: 0; box-shadow: none; padding: 0; border-radius: 0; }
  .card { box-shadow: none; border: 0; padding: 0; }
  table.tbl { font-size: 11px; }
  table.tbl th, table.tbl td { padding: 5px 4px; }
}
