:root {
  --red: #1f4e8c;
  --red-dark: #173b6a;
  --black: #111;
  --bg: #f4f4f5;
  --card: #fff;
  --text: #1c1c1e;
  --muted: #6b6b70;
  --border: #e2e2e6;
  --green: #1a7f37;
  --amber: #b26a00;
  --blue: #1f5fbf;
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
body {
  margin: 0; background: var(--bg); color: var(--text);
  font-family: "Segoe UI", Arial, "Noto Sans Hebrew", sans-serif; font-size: 15px;
}
a { color: var(--red); }
.topbar {
  display: flex; align-items: center; gap: 24px; flex-wrap: wrap;
  background: var(--black); color: #fff; padding: 0 20px; min-height: 60px;
}
.brand { display: flex; align-items: center; gap: 10px; color: #fff; text-decoration: none; font-weight: 600; }
.brand img { height: 40px; width: auto; max-width: 160px; object-fit: contain; }
nav { display: flex; gap: 4px; flex-wrap: wrap; }
nav a { color: #ddd; text-decoration: none; padding: 8px 12px; border-radius: 6px; }
nav a:hover { background: #2a2a2a; color: #fff; }
nav a.active { background: var(--red); color: #fff; }
main { max-width: 1100px; margin: 0 auto; padding: 24px 16px 60px; }
h1 { font-size: 22px; margin: 0; }
h2 { font-size: 17px; margin: 0 0 12px; }
.page-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 18px; flex-wrap: wrap; }
.card { background: var(--card); border: 1px solid var(--border); border-radius: 10px; padding: 18px; margin-bottom: 16px; }
.grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 12px 16px; }
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 12px; margin-bottom: 16px; }
.stat { background: var(--card); border: 1px solid var(--border); border-radius: 10px; padding: 14px 16px; border-top: 3px solid var(--red); }
.stat .label { color: var(--muted); font-size: 13px; }
.stat .value { font-size: 22px; font-weight: 700; margin-top: 4px; }
.stat .sub { color: var(--muted); font-size: 13px; }
label { display: flex; flex-direction: column; gap: 4px; font-size: 13px; color: var(--muted); }
input, select, textarea {
  font: inherit; color: var(--text); padding: 8px 10px; border: 1px solid #cfcfd4; border-radius: 6px; background: #fff; width: 100%;
}
textarea { min-height: 80px; resize: vertical; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--red); outline-offset: -1px; border-color: var(--red); }
.btn {
  display: inline-flex; align-items: center; gap: 6px; font: inherit; font-weight: 600; cursor: pointer;
  border: 1px solid var(--border); background: #fff; color: var(--text); padding: 8px 14px; border-radius: 6px; text-decoration: none; white-space: nowrap;
}
.btn:hover { background: #f0f0f2; }
.btn.primary { background: var(--red); border-color: var(--red); color: #fff; }
.btn.primary:hover { background: var(--red-dark); }
.btn.dark { background: var(--black); border-color: var(--black); color: #fff; }
.btn.small { padding: 4px 10px; font-size: 13px; font-weight: 500; }
.btn.danger { color: var(--red); }
.btn.whatsapp { background: #25d366; border-color: #25d366; color: #fff; }
.btn.whatsapp:hover { background: #1ebe5a; }
.btn:disabled { opacity: .5; cursor: default; }
.actions { display: flex; gap: 8px; flex-wrap: wrap; }
table { width: 100%; border-collapse: collapse; }
th, td { text-align: right; padding: 10px 8px; border-bottom: 1px solid var(--border); vertical-align: middle; }
th { font-size: 13px; color: var(--muted); font-weight: 600; }
tr.clickable { cursor: pointer; }
tr.clickable:hover td { background: #fafafa; }
.num { text-align: left; direction: ltr; white-space: nowrap; }
.muted { color: var(--muted); }
.empty { text-align: center; color: var(--muted); padding: 30px; }
.search { max-width: 280px; }
.table-wrap { overflow-x: auto; }
.badge { display: inline-block; padding: 2px 10px; border-radius: 999px; font-size: 12px; font-weight: 600; }
.badge.draft { background: #ececef; color: #444; }
.badge.sent { background: #e5efff; color: var(--blue); }
.badge.approved { background: #e3f6e8; color: var(--green); }
.badge.rejected { background: #fde8e8; color: var(--red); }
.badge.invoiced { background: #111; color: #fff; }
.items td { padding: 6px 4px; }
.items input { padding: 6px 8px; }
.items textarea { min-height: 0; padding: 6px 8px; line-height: 1.5; }
.items td { vertical-align: top; }
.keep-lines { white-space: pre-wrap; }
.items .col-qty { width: 80px; }
.items .col-price { width: 120px; }
.items .col-total { width: 110px; }
.items .col-opt { width: 70px; text-align: center; }
.items .col-del { width: 40px; }
.items tr.optional td { background: #fffaf0; }
.design-layout { display: grid; grid-template-columns: minmax(0, 1fr) 360px; gap: 16px; align-items: start; }
.design-preview { position: sticky; top: 12px; }
.preview-frame { width: 360px; height: 509px; overflow: hidden; border: 1px solid var(--border); border-radius: 8px; background: #fff; }
.preview-frame iframe { width: 794px; height: 1123px; border: 0; transform: scale(.4534); transform-origin: top right; }
label.btn { flex-direction: row; color: var(--text); }
label.radio { flex-direction: row; align-items: flex-start; gap: 8px; color: var(--text); font-size: 14px; margin-bottom: 10px; cursor: pointer; }
label.radio input { width: auto; margin-top: 3px; }
.asset-row { display: flex; gap: 14px; align-items: center; flex-wrap: wrap; }
.asset-preview { border: 1px dashed #ccc; border-radius: 8px; display: grid; place-items: center; background: #fafafa; overflow: hidden; }
.logo-preview { width: 200px; height: 90px; }
.logo-preview img { max-width: 190px; max-height: 80px; }
.letterhead-preview { width: 106px; height: 150px; }
.letterhead-preview img { width: 100%; height: 100%; object-fit: cover; }
.asset-preview .muted { font-size: 12px; text-align: center; padding: 6px; }
input[type=color] { height: 38px; padding: 2px; }
.margins { grid-template-columns: repeat(3, 1fr); }
@media (max-width: 900px) {
  .design-layout { grid-template-columns: 1fr; }
  .design-preview { position: static; }
  .preview-frame { margin: 0 auto; }
}
.totals { margin-inline-start: auto; width: min(320px, 100%); }
.totals div { display: flex; justify-content: space-between; padding: 4px 0; }
.totals .grand { font-weight: 700; font-size: 18px; border-top: 2px solid var(--black); margin-top: 6px; padding-top: 8px; }
.hint { font-size: 12px; color: var(--muted); }
#toast {
  position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%); background: var(--black); color: #fff;
  padding: 10px 18px; border-radius: 8px; opacity: 0; pointer-events: none; transition: opacity .2s; z-index: 10;
}
#toast.show { opacity: 1; }
#toast.error { background: var(--red); }
dialog { border: none; border-radius: 12px; padding: 0; width: min(560px, calc(100vw - 32px)); }
dialog::backdrop { background: rgba(0, 0, 0, .4); }
dialog form { padding: 20px; }
dialog .actions { justify-content: flex-start; margin-top: 16px; }
.span-2 { grid-column: 1 / -1; }
nav a.logout { color: #999; }
.admin-only { display: none; }
body.is-admin .admin-only { display: revert; }
.role-badge { display: inline-block; padding: 1px 8px; border-radius: 999px; font-size: 12px; background: #ececef; }
.role-badge.admin { background: var(--black); color: #fff; }
body.auth-mode nav { display: none; }
.auth-box { max-width: 400px; margin: 40px auto; text-align: center; padding: 28px; }
.auth-logo { max-width: 220px; max-height: 90px; margin-bottom: 8px; }
.auth-box h1 { margin-bottom: 6px; }
.auth-form { display: flex; flex-direction: column; gap: 14px; text-align: right; margin-top: 18px; }
.auth-form .btn { justify-content: center; padding: 10px; }
.auth-links { display: flex; gap: 8px; justify-content: center; flex-wrap: wrap; margin-top: 16px; }
.code-input { font-size: 24px; letter-spacing: 6px; text-align: center; direction: ltr; }
.qr { width: 200px; margin: 12px auto; }
.qr svg { width: 100%; height: auto; }
.secret { display: block; direction: ltr; font-size: 15px; background: #f3f3f5; padding: 8px; border-radius: 6px; margin-top: 6px; word-break: break-all; }
.menu-btn { display: none; }
.topbar { padding-top: env(safe-area-inset-top); }
@media (max-width: 640px) {
  .topbar { padding: calc(6px + env(safe-area-inset-top)) 12px 6px; gap: 8px; justify-content: space-between; position: sticky; top: 0; z-index: 5; }
  .brand span { display: inline; font-size: 14px; }
  .brand img { height: 36px; width: auto; max-width: 110px; }
  .menu-btn {
    display: block; background: none; border: 1px solid #444; color: #fff; font-size: 22px; line-height: 1;
    padding: 6px 12px; border-radius: 6px; cursor: pointer;
  }
  nav { display: none; flex-direction: column; width: 100%; padding-bottom: 8px; }
  body.menu-open nav { display: flex; }
  body.auth-mode .menu-btn { display: none; }
  nav a { padding: 12px; font-size: 16px; }
  main { padding: 16px 12px 40px; }
  .hide-sm { display: none; }
  h1 { font-size: 20px; }
  .card { padding: 14px; }
  /* מונע הגדלה אוטומטית של המסך באייפון כשנכנסים לשדה */
  input, select, textarea { font-size: 16px; }
  .btn { min-height: 40px; }
  .btn.small { min-height: 34px; }
  .page-head .actions { width: 100%; }
  .page-head select { width: 100% !important; max-width: 100%; }
  .page-head .actions .search, .page-head .actions input:not([type=checkbox]) { max-width: none; flex: 1 1 100%; }
  th, td { padding: 8px 5px; }
  td.actions { flex-direction: column; align-items: stretch; }
  .stats { grid-template-columns: 1fr 1fr; }
  .stat .value { font-size: 19px; }
  .grid { grid-template-columns: 1fr; }
  .totals { width: 100%; }
  dialog { width: calc(100vw - 16px); max-height: calc(100dvh - 16px); }
  dialog form { padding: 16px; }
  #toast { width: max-content; max-width: calc(100vw - 24px); text-align: center; }
  .preview-frame { width: 300px; height: 424px; }
  .preview-frame iframe { transform: scale(.3778); }
}
@media (max-width: 760px) {
  /* שורות ההצעה בעורך: כרטיס לכל שורה במקום טבלה רחבה (גם בטלפון לרוחב) */
  .items thead { display: none; }
  .items, .items tbody { display: block; }
  .items tr {
    display: grid; grid-template-columns: 1fr 1fr; gap: 8px 10px; position: relative;
    border: 1px solid var(--border); border-radius: 8px; padding: 10px; margin-bottom: 10px;
  }
  .items tr.optional { background: #fffaf0; }
  .items td { display: block; padding: 0; border: 0; width: auto !important; background: none !important; }
  .items td[data-label]::before { content: attr(data-label); display: block; font-size: 12px; color: var(--muted); margin-bottom: 2px; }
  .items td.col-desc { grid-column: 1 / -1; padding-left: 40px; }
  .items td.col-opt { text-align: right; }
  .items td.col-opt input { width: 22px !important; height: 22px; }
  .items td.num { text-align: right; font-weight: 600; align-self: end; padding-bottom: 6px; }
  .items td.col-del { position: absolute; top: 8px; left: 8px; }
  .items td.col-desc textarea { min-height: 96px; }
}
/* כתובת עם הצעות מ-Google Maps */
.field { display: flex; flex-direction: column; gap: 4px; }
.field-label { font-size: 13px; color: var(--muted); }
.place-box { position: relative; }
.place-list {
  position: absolute; top: calc(100% + 2px); inset-inline: 0; z-index: 20; background: #fff; border: 1px solid var(--border);
  border-radius: 8px; box-shadow: 0 6px 18px rgba(0, 0, 0, .12); max-height: 280px; overflow-y: auto;
}
.place-list button {
  display: block; width: 100%; text-align: right; padding: 8px 12px; border: 0; background: none; font: inherit; cursor: pointer;
}
.place-list button small { display: block; color: var(--muted); font-size: 12px; }
.place-list button:hover, .place-list button.active { background: #f0f0f2; }
.place-credit { font-size: 11px; color: var(--muted); text-align: left; padding: 4px 10px; direction: ltr; }
