:root {
  --bg: #f7f7f7;
  --surface: #ffffff;
  --surface-2: #efefef;
  --text: #1a1a1a;
  --muted: #767676;
  --line: #e2e2e2;
  --accent: #1a1a1a;
  --accent-soft: #ededed;
  --danger: #8a2a22;
  --shadow: 0 1px 2px rgba(0, 0, 0, .06), 0 4px 12px rgba(0, 0, 0, .04);
  --radius: 14px;
  --tap: 48px;
}

/* מצב בהיר בלבד. color-scheme מונע מהדפדפן להפוך שדות טופס
   לכהים כשהמערכת במצב לילה. */
:root { color-scheme: light; }

* { box-sizing: border-box; }

/* display של מחלקה גובר על [hidden] של הדפדפן - זה מחזיר את הסדר */
[hidden] { display: none !important; }

html, body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: "Segoe UI", Rubik, Arial, system-ui, sans-serif;
  font-size: 16px;
  -webkit-text-size-adjust: 100%;
  overscroll-behavior-y: contain;
}

h1, h2, h3 { margin: 0 0 .5rem; font-weight: 600; line-height: 1.25; }
h1 { font-size: 1.15rem; }
h2 { font-size: 1.05rem; }
h3 { font-size: .95rem; }

.muted { color: var(--muted); }
.small { font-size: .85rem; }
.spacer { flex: 1; }

/* ---------- סרגל עליון ---------- */
.topbar {
  position: sticky; top: 0; z-index: 30;
  display: flex; align-items: center; gap: .75rem;
  padding: max(.7rem, env(safe-area-inset-top)) 1rem .7rem;
  background: var(--surface);
  border-bottom: 1px solid var(--line);
}

.sync { display: flex; align-items: center; gap: .4rem; font-size: .78rem; color: var(--muted); }
.sync .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--muted); flex: none; }
.sync[data-s="idle"]    .dot { background: var(--accent); }
.sync[data-s="syncing"] .dot { background: var(--muted); animation: pulse 1s infinite; }
.sync[data-s="offline"] .dot { background: var(--muted); }
.sync[data-s="error"]   .dot { background: var(--danger); }
@keyframes pulse { 50% { opacity: .3; } }

/* ---------- טאבים ---------- */
.tabs {
  position: sticky; top: 0; z-index: 25;
  display: flex; background: var(--surface);
  border-bottom: 1px solid var(--line);
}
.tab {
  flex: 1; min-height: var(--tap);
  border: 0; background: none; color: var(--muted);
  font: inherit; font-size: .92rem; cursor: pointer;
  border-bottom: 2.5px solid transparent;
}
.tab.is-active { color: var(--accent); border-bottom-color: var(--accent); font-weight: 600; }

.view { display: none; }
.view.is-active { display: block; }
.pad { padding: 1rem; max-width: 780px; margin: 0 auto; }

/* ---------- חיפוש ---------- */
.searchwrap { position: relative; }

input[type="search"], input[type="text"], input[type="number"], select, textarea {
  width: 100%; min-height: var(--tap);
  padding: .6rem .85rem;
  font: inherit; color: var(--text);
  background: var(--surface);
  border: 1px solid var(--line); border-radius: var(--radius);
  outline: none;
}
input:focus, select:focus, textarea:focus { border-color: var(--accent); }
textarea { min-height: 7rem; resize: vertical; font-size: .9rem; }

.col-search { position: sticky; top: 48px; z-index: 20; background: var(--bg); padding: .75rem 1rem .25rem; }

/* בקצה הסופי של השדה, כדי שלא יישב על תחילת הטקסט */
.qclear {
  position: absolute; inset-inline-end: .5rem; top: 50%; transform: translateY(-50%);
  width: 30px; height: 30px; border: 0; border-radius: 50%;
  background: var(--surface-2); color: var(--muted); cursor: pointer; font-size: .8rem;
}

/* ---------- תוצאות חיפוש ---------- */
.results { list-style: none; margin: .5rem 0 0; padding: 0; }
.results:empty { display: none; }

.results li {
  display: flex; align-items: center; gap: .75rem;
  min-height: var(--tap); padding: .5rem .85rem;
  background: var(--surface);
  border: 1px solid var(--line); border-radius: var(--radius);
  margin-bottom: .4rem; cursor: pointer;
}
.results li.sel { border-color: var(--accent); background: var(--accent-soft); }
.results li .icon { font-size: 1.1rem; }
.results li .nm { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.results li .meta { font-size: .78rem; color: var(--muted); flex: none; }
.results li.new { border-style: dashed; color: var(--accent); }

/* ---------- הרשימה ---------- */
.col-list { padding: .5rem 1rem 6rem; max-width: 780px; margin: 0 auto; }

/* ---------- מסנן חנויות ---------- */
.stores {
  display: flex; gap: .35rem; margin: .1rem 0 .2rem;
  overflow-x: auto; scrollbar-width: none;
}
.stores::-webkit-scrollbar { display: none; }
.stores button {
  flex: none; min-height: 34px; padding: .3rem .85rem;
  font: inherit; font-size: .85rem; cursor: pointer;
  border: 1px solid var(--line); border-radius: 999px;
  background: var(--surface); color: var(--muted);
  white-space: nowrap;
}
.stores button.on {
  background: var(--accent); border-color: var(--accent);
  color: var(--surface); font-weight: 600;
}
.stores button .n { font-size: .75rem; opacity: .7; margin-inline-start: .3rem; }

.cat-head {
  font-size: .72rem; font-weight: 600; color: var(--muted);
  padding: .55rem .3rem .22rem; letter-spacing: .02em;
}
.cat-head:first-child { padding-top: .2rem; }

/* תווית החנות על שורה, כשמציגים הכל */
.store-tag {
  flex: none; font-size: .68rem; color: var(--muted);
  background: var(--surface-2); border-radius: 5px;
  padding: .1rem .35rem; cursor: pointer;
}

/* רשימה אחת רציפה, לא בועה נפרדת לכל פריט */
.list {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  overflow: hidden;
  box-shadow: var(--shadow);
}

.item {
  display: flex; align-items: center; gap: .4rem;
  min-height: 40px; padding: .15rem .5rem;
  border-bottom: 1px solid var(--line);
}
.item:last-child { border-bottom: 0; }
.item.done { opacity: .5; }
.item.done .nm { text-decoration: line-through; }

.check {
  width: 24px; height: 24px; flex: none;
  border: 2px solid var(--line); border-radius: 50%;
  background: none; cursor: pointer;
  display: grid; place-items: center;
  color: transparent; font-size: .75rem; line-height: 1;
}
.item.done .check { background: var(--accent); border-color: var(--accent); color: var(--surface); }

.icon {
  flex: none; width: 22px; text-align: center;
  font-size: 1.05rem; line-height: 1;
  font-family: "Segoe UI Emoji", "Apple Color Emoji", "Noto Color Emoji", sans-serif;
}

.store-name {
  flex: 1; min-width: 0; min-height: 34px; height: 34px;
  padding: .2rem .5rem; font-size: .9rem; border-radius: 8px;
}

.item .nm { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.qty { display: flex; align-items: center; gap: .1rem; flex: none; }
.qty button {
  width: 26px; height: 26px; flex: none;
  border: 1px solid var(--line); border-radius: 7px;
  background: var(--surface-2); color: var(--text);
  font-size: .95rem; line-height: 1; cursor: pointer;
  display: grid; place-items: center;
}
.qty button:active { background: var(--accent-soft); }
.qty input {
  width: 34px; min-height: 26px; height: 26px;
  padding: 0; text-align: center; border-radius: 7px;
  font-size: .85rem; -moz-appearance: textfield;
}
.qty input::-webkit-outer-spin-button,
.qty input::-webkit-inner-spin-button { -webkit-appearance: none; margin: 0; }
.qty .u { font-size: .68rem; color: var(--muted); min-width: 2.1em; text-align: start; }

.empty { text-align: center; padding: 3.5rem 1rem; color: var(--muted); }
.empty .sub { font-size: .88rem; }

/* ---------- פס תחתון ---------- */
.bottombar {
  position: fixed; inset-inline: 0; bottom: 0; z-index: 30;
  display: flex; align-items: center; gap: .75rem;
  padding: .7rem 1rem calc(.7rem + env(safe-area-inset-bottom));
  background: var(--surface); border-top: 1px solid var(--line);
  font-size: .85rem; color: var(--muted);
}

/* ---------- כפתורים ---------- */
.btn, .btn-ghost {
  min-height: var(--tap); padding: .55rem 1.1rem;
  font: inherit; font-size: .9rem; cursor: pointer;
  border-radius: var(--radius);
  border: 1px solid var(--line); background: var(--surface); color: var(--text);
  display: inline-flex; align-items: center; justify-content: center;
}
.btn-primary { background: var(--accent); border-color: var(--accent); color: var(--surface); font-weight: 600; }
.btn-ghost { border-color: transparent; background: none; color: var(--muted); }
.btn-ghost.danger { color: var(--danger); }
.rowline { display: flex; align-items: center; gap: .75rem; flex-wrap: wrap; margin: .85rem 0; }

/* ---------- קטלוג ---------- */
.catalog { margin-top: .5rem; }
.prow {
  display: flex; align-items: center; gap: .7rem;
  min-height: 54px; padding: .5rem .8rem;
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--radius); margin-bottom: .4rem; cursor: pointer;
}
.prow .nm { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.prow .tag { font-size: .72rem; color: var(--muted); background: var(--surface-2); padding: .2rem .5rem; border-radius: 6px; flex: none; }
.prow.arch { opacity: .45; }

/* ---------- ייבוא ---------- */
.mapgrid { display: grid; grid-template-columns: 1fr 1fr; gap: .6rem; margin: .75rem 0; }
.mapgrid label { font-size: .8rem; color: var(--muted); display: grid; gap: .25rem; }
.chk { display: flex; align-items: center; gap: .5rem; font-size: .88rem; margin: .5rem 0; }
.chk input { width: auto; min-height: auto; }
.stats { display: flex; gap: 1.25rem; font-size: .85rem; margin: .5rem 0; flex-wrap: wrap; }
.stats b { color: var(--accent); }
.tablewrap { overflow-x: auto; border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface); }
table { border-collapse: collapse; width: 100%; font-size: .82rem; }
th, td { padding: .45rem .6rem; text-align: start; border-bottom: 1px solid var(--line); white-space: nowrap; }
th { background: var(--surface-2); font-weight: 600; position: sticky; top: 0; }
tr.dup td { color: var(--muted); font-style: italic; }
.notice { padding: .85rem 1rem; border-radius: var(--radius); background: var(--accent-soft); color: var(--accent); margin: 1rem 0; }

/* ---------- דיאלוג ---------- */
dialog {
  border: 0; border-radius: var(--radius); padding: 0;
  background: var(--surface); color: var(--text);
  width: min(440px, calc(100vw - 2rem)); box-shadow: var(--shadow);
}
dialog::backdrop { background: rgba(0, 0, 0, .45); }
.dlg { padding: 1.25rem; display: grid; gap: .8rem; }
.dlg label { display: grid; gap: .3rem; font-size: .82rem; color: var(--muted); }
.dlg .two { display: grid; grid-template-columns: 1fr 1fr; gap: .8rem; }
.dlg .hint { font-size: .72rem; }
.dlg menu { display: flex; align-items: center; gap: .5rem; margin: .5rem 0 0; padding: 0; }

/* ---------- טוסט ---------- */
.toast {
  position: fixed; inset-inline: 1rem; bottom: calc(4.5rem + env(safe-area-inset-bottom));
  z-index: 60; padding: .8rem 1rem; border-radius: var(--radius);
  background: var(--text); color: var(--bg);
  font-size: .88rem; text-align: center; box-shadow: var(--shadow);
}

/* ---------- מחשב: שתי עמודות ---------- */
@media (min-width: 900px) {
  .cols {
    display: grid; grid-template-columns: 360px 1fr; gap: 1.5rem;
    max-width: 1100px; margin: 0 auto; padding: 1rem;
    align-items: start;
  }
  .col-search { position: sticky; top: 108px; padding: 0; background: none; }
  /* margin:0 מהסגנון הנייד חייב להתאפס: שוליים אוטומטיים בתוך grid
     מבטלים את המתיחה, והעמודה מתכווצת לרוחב התוכן במקום למלא את המסלול */
  .col-list { padding: 0 0 4rem; max-width: none; margin: 0; min-width: 0; }
  .results { max-height: calc(100vh - 220px); overflow-y: auto; }
  .bottombar { position: static; max-width: 1100px; margin: 0 auto; border: 0; }
  .tabs { max-width: 1100px; margin: 0 auto; border-radius: 0; }
}
