:root, :root[data-theme="dark"] {
  --bg: #0f172a;
  --panel: #1e293b;
  --panel2: #273449;
  --border: #334155;
  --text: #e2e8f0;
  --muted: #94a3b8;
  --accent: #3b82f6;
  --accent2: #2563eb;
  --green: #22c55e;
  --red: #ef4444;
  --orange: #f59e0b;
}
:root[data-theme="light"] {
  --bg: #f1f5f9;
  --panel: #ffffff;
  --panel2: #e8edf3;
  --border: #d4dce6;
  --text: #0f172a;
  --muted: #5b6b7f;
  --accent: #2563eb;
  --accent2: #1d4ed8;
  --green: #16a34a;
  --red: #dc2626;
  --orange: #d97706;
}
* { box-sizing: border-box; }
body {
  margin: 0;
  font-family: 'Segoe UI', Roboto, system-ui, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 15px;
}
button {
  cursor: pointer;
  border: none;
  border-radius: 8px;
  padding: 10px 16px;
  font-size: 15px;
  background: var(--accent);
  color: white;
  font-weight: 600;
  transition: background .15s;
}
button:hover { background: var(--accent2); }
button.ghost { background: var(--panel2); color: var(--text); }
button.ghost:hover { background: var(--border); }
button.danger { background: var(--red); }
button.green { background: var(--green); }
input, select {
  background: var(--panel2);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 8px;
  padding: 10px 12px;
  font-size: 15px;
  outline: none;
}
input:focus, select:focus { border-color: var(--accent); }
.muted { color: var(--muted); }

/* ---- Login ---- */
.login-page { display: flex; align-items: center; justify-content: center; min-height: 100vh; }
.login-box {
  background: var(--panel); padding: 40px; border-radius: 16px;
  width: 320px; display: flex; flex-direction: column; gap: 14px;
  border: 1px solid var(--border); text-align: center;
}
.login-logo { font-size: 48px; }
.login-box h1 { margin: 0; font-size: 24px; }
.login-box p { margin: 0; }
.login-err { color: var(--red); min-height: 20px; font-size: 14px; }

/* ---- Layout: sol menu (sidebar) ---- */
.app { display: flex; min-height: 100vh; }
.sidebar {
  width: 240px; flex-shrink: 0; display: flex; flex-direction: column;
  background: var(--panel); border-right: 1px solid var(--border);
  position: sticky; top: 0; height: 100vh; overflow-y: auto; z-index: 20;
}
.side-brand { padding: 18px 14px 12px; display: flex; align-items: center; gap: 11px; }
.logo-mark { width: 38px; height: 38px; flex-shrink: 0; }
.logo-text { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.logo-word { font-size: 19px; font-weight: 800; letter-spacing: .3px; color: var(--text); line-height: 1; }
.side-brand-sub { color: var(--muted); font-size: 10.5px; letter-spacing: 1.6px; text-transform: uppercase; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.nav-group {
  font-size: 11px; color: var(--muted); padding: 14px 14px 4px;
  letter-spacing: .5px; text-transform: uppercase;
}
.sidebar nav { display: flex; flex-direction: column; gap: 2px; padding: 0 8px; }
.sidebar nav button {
  display: flex; align-items: center; gap: 12px; width: 100%;
  background: transparent; color: var(--muted); padding: 11px 12px;
  font-weight: 500; font-size: 14.5px; text-align: left; border-radius: 10px;
}
.sidebar nav button:hover { background: var(--panel2); color: var(--text); }
.sidebar nav button.active { background: var(--accent); color: #fff; }
.nav-ico { width: 26px; display: flex; align-items: center; justify-content: center; flex-shrink: 0; }
.nav-ico svg { width: 21px; height: 21px; stroke-width: 1.8; }
.nav-label { flex: 1; white-space: nowrap; overflow: hidden; }
.side-collapse {
  margin: auto 8px 10px; background: transparent; color: var(--muted);
  display: flex; align-items: center; gap: 10px; padding: 9px 10px;
  font-size: 13px; border-radius: 8px;
}
.side-collapse:hover { background: var(--panel2); color: var(--text); }

/* Daraltilmis mod: yalniz ikonlar */
.app.collapsed .sidebar { width: 68px; }
.app.collapsed .nav-label, .app.collapsed .nav-group, .app.collapsed .logo-text { display: none; }
.app.collapsed .side-brand { justify-content: center; padding: 18px 8px 12px; }
.app.collapsed .logo-mark { width: 34px; height: 34px; }
.app.collapsed .sidebar nav button { justify-content: center; padding: 9px 0; }
.app.collapsed .sidebar nav button .badge { display: none; }
.app.collapsed .side-collapse { justify-content: center; }
.app.collapsed .side-collapse .nav-ico { transform: rotate(180deg); }

.main-wrap { flex: 1; min-width: 0; display: flex; flex-direction: column; }
header.topbar {
  display: flex; align-items: center; gap: 12px;
  padding: 12px 20px; background: var(--panel); border-bottom: 1px solid var(--border);
  position: sticky; top: 0; z-index: 10;
}
header.topbar h1 { font-size: 20px; margin: 0; font-weight: 650; letter-spacing: .2px; }
.topbar .hamb { display: none; padding: 8px 12px; }
.sb-overlay { display: none; }

/* Mobil: menu gizli, hamburgerle acilir */
@media (max-width: 860px) {
  main { padding: 14px 12px; }
  header.topbar { padding: 10px 12px; }
  header.topbar h1 { font-size: 17px; }
  .stats { grid-template-columns: repeat(auto-fit, minmax(130px, 1fr)); gap: 10px; }
  .stat { padding: 12px; }
  .stat .v { font-size: 22px; }
  .panel { padding: 14px; border-radius: 10px; }
  th, td { padding: 8px 8px; font-size: 13.5px; }
  .sidebar {
    position: fixed; left: 0; top: 0; transform: translateX(-100%);
    transition: transform .2s ease; box-shadow: 0 0 30px rgba(0,0,0,.5);
  }
  .app.sb-open .sidebar { transform: translateX(0); }
  .app.sb-open .sb-overlay {
    display: block; position: fixed; inset: 0; background: rgba(0,0,0,.5); z-index: 15;
  }
  .topbar .hamb { display: inline-flex; }
  .side-collapse { display: none; }
}

.brand {
  background: linear-gradient(135deg, var(--accent), #06b6d4);
  color: #fff; font-weight: 800; letter-spacing: 1px;
  padding: 4px 10px; border-radius: 7px; font-size: 16px;
  align-self: flex-start;
}
.login-brand { font-size: 30px; font-weight: 800; letter-spacing: .5px; color: var(--text); }
/* ---- Lucide ikonlari ---- */
svg.lucide { vertical-align: -3px; }
/* Ikon tiklamalari her zaman dugmeye gitsin (SVG hedef olmasin) */
button svg, button i[data-lucide] { pointer-events: none; }
.icon-btn { display: inline-flex; align-items: center; justify-content: center; min-width: 30px; min-height: 30px; }
button svg.lucide { width: 17px; height: 17px; stroke-width: 2; }
button.icon-only { display: inline-flex; align-items: center; justify-content: center; padding: 9px 11px; }
.icon-btn svg.lucide { width: 16px; height: 16px; }
.side-brand .brand svg.lucide { width: 18px; height: 18px; vertical-align: -3px; }
.side-collapse .nav-ico svg { width: 17px; height: 17px; }
.app.collapsed .side-collapse .nav-ico { transform: rotate(180deg); }

/* ---- Etiket onizleme ---- */
.label-preview {
  background: #fff; color: #000; border-radius: 8px; padding: 14px;
  display: flex; flex-direction: column; align-items: center; gap: 4px;
  text-align: center; min-height: 90px;
}
.label-preview .lbl-brand { font-weight: 700; font-size: 14px; }
.label-preview .lbl-name { font-size: 13px; }
.label-preview .lbl-price { font-weight: 700; font-size: 18px; }
.label-preview svg { max-width: 100%; }

/* ---- Rapor grafikleri ---- */
.charts { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.chart-box { position: relative; height: 260px; }
.chart-box.wide { grid-column: 1 / -1; }
@media (max-width: 860px) { .charts { grid-template-columns: 1fr; } }

details.adv { margin-top: 12px; }
details.adv summary { color: var(--muted); cursor: pointer; font-size: 13px; user-select: none; }
.bc-row { display: flex; align-items: center; gap: 8px; padding: 4px 0; font-size: 14px; }

/* ---- Ayarlar ---- */
.modal.wide { max-width: 640px; width: 94%; }
.settings-tabs { display: flex; gap: 6px; margin-bottom: 16px; border-bottom: 1px solid var(--border); padding-bottom: 10px; }
.settings-tabs button { background: transparent; color: var(--muted); padding: 7px 14px; font-weight: 500; }
.settings-tabs button.active { background: var(--accent); color: #fff; }
.stab { display: none; }
.stab.active { display: block; }
.mod-row {
  display: flex; align-items: center; gap: 12px;
  padding: 10px 4px; border-bottom: 1px solid var(--border);
}
.mod-row:last-child { border-bottom: none; }
.mod-info { flex: 1; }
.mod-info .t { font-weight: 600; }
.mod-info .s { color: var(--muted); font-size: 13px; }
.switch {
  position: relative; width: 44px; height: 24px; border-radius: 12px;
  background: var(--panel2); border: 1px solid var(--border); cursor: pointer;
  transition: background .15s; flex: none;
}
.switch::after {
  content: ''; position: absolute; top: 2px; left: 2px; width: 18px; height: 18px;
  border-radius: 50%; background: var(--muted); transition: all .15s;
}
.switch.on { background: var(--green, #16a34a); border-color: transparent; }
.switch.on::after { left: 22px; background: #fff; }

.account-name {
  color: var(--muted); font-weight: 600; font-size: 15px; letter-spacing: .5px;
}
.footer-brand {
  text-align: center; color: var(--muted); font-size: 12px;
  padding: 18px 0 28px; letter-spacing: .5px;
}
.footer-brand b { color: var(--text); letter-spacing: 1px; }
.spacer { flex: 1; }
main { padding: 24px 28px; width: 100%; }
.tab { display: none; }
.tab.active { display: block; }

/* ---- Cards / stats ---- */
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 14px; margin-bottom: 20px; }
.stat { background: var(--panel); border: 1px solid var(--border); border-radius: 12px; padding: 16px; }
.stat .v { font-size: 26px; font-weight: 700; letter-spacing: -.3px; }
.stat .l { color: var(--muted); font-size: 11.5px; margin-top: 5px; text-transform: uppercase; letter-spacing: .5px; font-weight: 600; }
.stat.warn .v { color: var(--orange); }
.stat.bad .v { color: var(--red); }

.panel { background: var(--panel); border: 1px solid var(--border); border-radius: 12px; padding: 20px; margin-bottom: 18px; }
.panel h2 {
  margin: 0 0 14px; font-size: 15px; font-weight: 650;
  letter-spacing: .4px; text-transform: uppercase; color: var(--muted);
}
.panel h2 + p.muted { margin-top: -8px; font-size: 13px; text-transform: none; }
.row { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; }
.row > * { flex-shrink: 0; }
.grow { flex: 1; min-width: 120px; }

/* ---- Scan ---- */
.scan-input { font-size: 22px; padding: 16px; text-align: center; letter-spacing: 1px; }
.toggle { display: flex; border: 1px solid var(--border); border-radius: 8px; overflow: hidden; }
.toggle button { border-radius: 0; background: var(--panel2); color: var(--muted); }
.toggle button.active.in { background: var(--green); color: white; }
.toggle button.active.out { background: var(--red); color: white; }
#reader { width: 100%; max-width: 400px; margin: 10px auto 0; border-radius: 10px; overflow: hidden; }

/* ---- Feed ---- */
.feed { display: flex; flex-direction: column; gap: 8px; max-height: 380px; overflow-y: auto; }
.feed-item {
  display: flex; align-items: center; gap: 12px; padding: 12px;
  background: var(--panel2); border-radius: 8px; border-left: 4px solid var(--border);
  animation: pop .2s ease;
}
@keyframes pop { from { transform: scale(.97); opacity: .5; } to { transform: scale(1); opacity: 1; } }
.feed-item.in { border-left-color: var(--green); }
.feed-item.out { border-left-color: var(--accent); }
.feed-item.err { border-left-color: var(--red); }
.feed-item .icon { font-size: 22px; }
.feed-item .info { flex: 1; }
.feed-item .info .t { font-weight: 600; }
.feed-item .info .s { font-size: 13px; color: var(--muted); }
.feed-item .bal { font-size: 20px; font-weight: 700; }
.feed-item.lowstock .bal { color: var(--orange); }

/* ---- Table ---- */
table { width: 100%; border-collapse: collapse; }
th, td { padding: 10px 12px; text-align: left; border-bottom: 1px solid var(--border); }
th { color: var(--muted); font-size: 12px; font-weight: 650; text-transform: uppercase; letter-spacing: .4px; position: sticky; top: 0; background: var(--panel); z-index: 1; }
tbody tr:hover { background: var(--panel2); }
.tbl-wrap { overflow-x: auto; max-height: 70vh; overflow-y: auto; }
.badge { padding: 3px 8px; border-radius: 6px; font-size: 12px; font-weight: 600; }
.badge.low { background: rgba(245,158,11,.18); color: var(--orange); }
.badge.out { background: rgba(239,68,68,.18); color: var(--red); }
.badge.ok { background: rgba(34,197,94,.15); color: var(--green); }
.qty-cell { font-weight: 700; font-size: 16px; }
.icon-btn { background: transparent; color: var(--muted); padding: 4px 8px; }
.icon-btn:hover { background: var(--panel2); color: var(--text); }
.icon-btn.del:hover { color: var(--red); }

/* ---- Modal ---- */
.modal-bg {
  display: none; position: fixed; inset: 0; background: rgba(0,0,0,.6);
  align-items: center; justify-content: center; z-index: 100; padding: 20px;
}
.modal-bg.open { display: flex; }
.modal {
  background: var(--panel); border: 1px solid var(--border); border-radius: 14px;
  padding: 24px; width: 480px; max-width: 100%; max-height: 90vh; overflow-y: auto;
}
.modal h2 { margin: 0 0 16px; }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.form-grid label { display: flex; flex-direction: column; gap: 5px; font-size: 13px; color: var(--muted); }
.form-grid label.full { grid-column: 1 / -1; }
.modal-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 18px; }

/* ---- Toast ---- */
#toast {
  position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%);
  background: var(--panel); border: 1px solid var(--border); padding: 14px 22px;
  border-radius: 10px; font-weight: 600; z-index: 200; display: none; box-shadow: 0 8px 30px rgba(0,0,0,.4);
}
#toast.show { display: block; animation: pop .2s; }
#toast.ok { border-color: var(--green); }
#toast.bad { border-color: var(--red); }

.empty { text-align: center; padding: 40px; color: var(--muted); }
.hint { font-size: 13px; color: var(--muted); margin-top: 6px; }
@media (max-width: 600px) {
  .form-grid { grid-template-columns: 1fr; }
  header { flex-wrap: wrap; }
}

/* Sifre alani goster/gizle */
.pw-wrap { position: relative; display: block; }
.pw-wrap input { width: 100%; padding-right: 34px; box-sizing: border-box; }
.pw-eye { position: absolute; right: 6px; top: 50%; transform: translateY(-50%);
  background: none; border: none; cursor: pointer; padding: 2px 4px; color: var(--muted);
  display: flex; align-items: center; }
.pw-eye:hover { color: inherit; }
.pw-eye svg { width: 17px; height: 17px; }
