:root {
  --bg: #f6f6fa;
  --card: #ffffff;
  --ink: #191c28;
  --muted: #6b7186;
  --line: #e7e8f0;
  --accent: #7c3aed;
  --accent-dark: #6d28d9;
  --accent-soft: #f3eeff;
  --grad: linear-gradient(120deg, #7c3aed, #db2777);
  --ok: #16a34a;
  --ok-soft: #e8f7ee;
  --warn: #d97706;
  --warn-soft: #fdf3e3;
  --err: #dc2626;
  --err-soft: #fdeeee;
  --radius: 16px;
  --shadow-sm: 0 1px 2px rgba(20, 22, 40, .05), 0 2px 8px rgba(20, 22, 40, .05);
  --shadow-md: 0 2px 6px rgba(20, 22, 40, .06), 0 12px 32px rgba(20, 22, 40, .09);
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
html { -webkit-text-size-adjust: 100%; }
body {
  font-family: 'Noto Sans Hebrew', 'Segoe UI', Arial, sans-serif;
  background: var(--bg);
  color: var(--ink);
  min-height: 100vh;
  font-size: 15px;
  line-height: 1.55;
}

.boot { text-align: center; padding-top: 30vh; color: var(--muted); font-size: 17px; }
.hidden { display: none !important; }
button { font-family: inherit; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 6px; }

/* ---------- buttons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 7px;
  border: 1px solid var(--line); background: var(--card); color: var(--ink);
  padding: 10px 16px; border-radius: 12px; font-size: 14px; font-weight: 600;
  cursor: pointer; text-decoration: none; transition: border-color .15s, background .15s, box-shadow .15s, transform .1s;
  white-space: nowrap; min-height: 42px;
}
.btn:hover { border-color: #cfd3e4; box-shadow: var(--shadow-sm); }
.btn:active { transform: scale(.98); }
.btn:disabled { opacity: .45; cursor: not-allowed; box-shadow: none; transform: none; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:hover { background: var(--accent-dark); border-color: var(--accent-dark); }
.btn.danger { color: var(--err); border-color: #f2ccd0; }
.btn.danger:hover { background: var(--err-soft); border-color: #eab6bc; }
.btn.sm { padding: 7px 13px; font-size: 13px; border-radius: 10px; min-height: 34px; }
.btn.ghost { border-color: transparent; background: transparent; }
.btn.ghost:hover { background: #eef0f7; box-shadow: none; }

/* ---------- topbar ---------- */
.topbar {
  background: rgba(255, 255, 255, .92); backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--line);
  padding: 0 22px; height: 60px; display: flex; align-items: center; gap: 12px;
  position: sticky; top: 0; z-index: 20;
}
.topbar .logo {
  font-weight: 900; font-size: 23px; letter-spacing: -.5px; text-decoration: none;
  background: var(--grad); -webkit-background-clip: text; background-clip: text; color: transparent;
  direction: ltr;
}
.topbar .spacer { flex: 1; }
.topbar .who {
  color: var(--muted); font-size: 13px; max-width: 40vw;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}

.page { max-width: 1240px; margin: 0 auto; padding: 26px 20px 90px; }

/* ---------- login ---------- */
.login-wrap { display: flex; justify-content: center; padding: 10vh 16px 0; }
.login-card {
  background: var(--card); border-radius: 20px; box-shadow: var(--shadow-md);
  padding: 40px 34px; width: 100%; max-width: 410px; border-top: 4px solid transparent;
  border-image: linear-gradient(120deg, #7c3aed, #db2777) 1;
  border-top: 4px solid;
}
.login-card .brand {
  font-weight: 900; font-size: 34px; letter-spacing: -1px; direction: ltr; text-align: center;
  background: var(--grad); -webkit-background-clip: text; background-clip: text; color: transparent;
  margin: 0 0 2px;
}
.login-card h1 { margin: 0 0 4px; font-size: 20px; text-align: center; }
.login-card p { color: var(--muted); margin: 0 0 26px; font-size: 14px; text-align: center; }
.field { margin-bottom: 16px; }
.field label { display: block; font-size: 13.5px; font-weight: 600; margin-bottom: 6px; }
.field input[type=text], .field input[type=email], .field input[type=password], .field textarea, .field input[type=tel] {
  width: 100%; padding: 11px 14px; border: 1.5px solid var(--line); border-radius: 12px;
  font-family: inherit; font-size: 15px; background: #fafbfe; transition: border-color .15s;
}
.field input:focus, .field textarea:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px rgba(124, 58, 237, .12); }
.form-err { color: var(--err); font-size: 13px; min-height: 18px; margin: 4px 0 10px; }

/* ---------- projects list ---------- */
.page-head { display: flex; align-items: center; gap: 14px; flex-wrap: wrap; margin-bottom: 22px; }
.page-head h1 { margin: 0; font-size: 24px; font-weight: 800; flex: 1; }
.projects-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(290px, 1fr)); gap: 16px; }
.project-card {
  background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow-sm);
  padding: 20px; display: flex; flex-direction: column; gap: 10px; cursor: pointer;
  border: 1px solid var(--line); transition: transform .15s, box-shadow .15s, border-color .15s;
}
.project-card:hover { border-color: #d5c8f5; box-shadow: var(--shadow-md); transform: translateY(-2px); }
.project-card h3 { margin: 0; font-size: 17px; font-weight: 700; }
.project-card .sub { color: var(--muted); font-size: 13px; }
.pc-stats { display: flex; gap: 12px; font-size: 13px; color: var(--muted); flex-wrap: wrap; }
.pc-stats b { color: var(--ink); font-weight: 700; }
.progress { background: #ecedf4; height: 9px; border-radius: 99px; overflow: hidden; }
.progress > div { background: var(--grad); height: 100%; border-radius: 99px; transition: width .5s; }
.empty { text-align: center; color: var(--muted); padding: 70px 16px; font-size: 15px; }

/* ---------- project page ---------- */
.proj-head { background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow-sm); border: 1px solid var(--line); padding: 20px 22px; margin-bottom: 18px; }
.proj-title-row { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.proj-title-row h1 { margin: 0; font-size: 21px; font-weight: 800; flex: 1; min-width: 180px; }
.proj-sub { color: var(--muted); font-size: 13px; margin-top: 4px; }
.proj-progress-row { display: flex; align-items: center; gap: 14px; margin-top: 16px; }
.proj-progress-row .progress { flex: 1; }
.proj-progress-row .pct { font-weight: 800; font-size: 16px; min-width: 44px; }
.counts { display: flex; gap: 8px; margin-top: 12px; flex-wrap: wrap; }
.count-chip { background: #f2f3f9; border-radius: 99px; padding: 5px 13px; font-size: 12.5px; color: var(--muted); }
.count-chip b { color: var(--ink); }

.toolbar { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; margin-bottom: 18px; }
.filters {
  display: flex; gap: 4px; background: var(--card); padding: 4px; border-radius: 12px;
  border: 1px solid var(--line); overflow-x: auto; max-width: 100%;
  -webkit-overflow-scrolling: touch; scrollbar-width: none;
}
.filters::-webkit-scrollbar { display: none; }
.filters button {
  border: 0; background: transparent; padding: 8px 14px; border-radius: 9px;
  font-size: 13.5px; cursor: pointer; color: var(--muted); font-weight: 600; white-space: nowrap;
  transition: background .15s, color .15s;
}
.filters button.active { background: var(--accent); color: #fff; }
.search { flex: 1; min-width: 180px; }
.search input {
  width: 100%; padding: 11px 16px; border: 1px solid var(--line); border-radius: 12px;
  font-family: inherit; font-size: 14px; background: var(--card);
}
.search input:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px rgba(124, 58, 237, .12); }

/* ---------- image cards ---------- */
.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(330px, 1fr)); gap: 16px; }
.card {
  background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow-sm);
  border: 1px solid var(--line); padding: 14px; display: flex; flex-direction: column; gap: 10px;
}
.card-head { display: flex; align-items: center; gap: 6px; min-height: 34px; }
.card-head .name { font-weight: 700; font-size: 15px; flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; unicode-bidi: plaintext; }
.card-head input { flex: 1; font-family: inherit; font-size: 14px; padding: 6px 10px; border: 1.5px solid var(--accent); border-radius: 9px; min-width: 0; }
.pair { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.pair figure { margin: 0; min-width: 0; }
.pair .imgbox {
  aspect-ratio: 3 / 4; border-radius: 12px; overflow: hidden; background: #eef0f6;
  display: flex; align-items: center; justify-content: center; position: relative; cursor: zoom-in;
}
.pair img { width: 100%; height: 100%; object-fit: cover; display: block; }
.pair figcaption { text-align: center; font-size: 12px; color: var(--muted); margin-top: 6px; font-weight: 500; }
.placeholder { display: flex; flex-direction: column; gap: 8px; align-items: center; color: var(--muted); font-size: 12.5px; padding: 8px; text-align: center; }
.spinner { width: 26px; height: 26px; border: 3px solid #e2e5f0; border-top-color: var(--accent); border-radius: 50%; animation: spin 1s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.skeleton { position: absolute; inset: 0; background: linear-gradient(100deg, #eef0f6 40%, #f7f8fc 50%, #eef0f6 60%); background-size: 200% 100%; animation: shimmer 1.3s infinite; }
@keyframes shimmer { to { background-position: -200% 0; } }

.meta-row { display: flex; align-items: center; gap: 8px; font-size: 12.5px; color: var(--muted); flex-wrap: wrap; }
.chip { border-radius: 99px; padding: 4px 12px; font-size: 12px; font-weight: 700; }
.st-completed { background: var(--ok-soft); color: var(--ok); }
.st-processing, .st-queued, .st-uploaded, .st-regenerating { background: var(--accent-soft); color: var(--accent); }
.st-failed { background: var(--err-soft); color: var(--err); }
.st-retrying { background: var(--warn-soft); color: var(--warn); }
.card .err-msg { background: var(--err-soft); color: var(--err); font-size: 12.5px; border-radius: 10px; padding: 8px 12px; }
.card .regen-req { background: var(--warn-soft); color: #91600b; font-size: 12.5px; border-radius: 10px; padding: 8px 12px; border: 1px solid #f2e0bb; }
.card-actions { display: flex; gap: 8px; flex-wrap: wrap; margin-top: auto; }

/* ---------- modal ---------- */
.modal-overlay {
  position: fixed; inset: 0; background: rgba(16, 18, 32, .55); z-index: 50;
  display: flex; align-items: center; justify-content: center; padding: 18px;
  animation: fade-in .15s;
}
@keyframes fade-in { from { opacity: 0; } }
.modal {
  background: var(--card); border-radius: 18px; box-shadow: 0 24px 70px rgba(0, 0, 0, .3);
  width: 100%; max-width: 560px; max-height: 88vh; overflow: auto; padding: 24px;
  animation: modal-in .18s ease-out;
}
@keyframes modal-in { from { opacity: 0; transform: translateY(14px) scale(.98); } }
.modal h2 { margin: 0 0 16px; font-size: 19px; font-weight: 800; }
.modal .modal-actions { display: flex; gap: 10px; justify-content: flex-start; margin-top: 20px; flex-wrap: wrap; }
.modal.wide { max-width: 720px; }

/* ---------- upload ---------- */
.dropzone {
  border: 2px dashed #cfd3e6; border-radius: 14px; padding: 36px 20px; text-align: center;
  color: var(--muted); cursor: pointer; transition: .15s; font-size: 14.5px; background: #fafbff;
}
.dropzone.drag { border-color: var(--accent); background: var(--accent-soft); }
.upload-list { margin-top: 14px; max-height: 320px; overflow: auto; display: flex; flex-direction: column; gap: 8px; }
.up-row { display: flex; align-items: center; gap: 10px; font-size: 13px; background: #f6f7fb; padding: 9px 12px; border-radius: 10px; }
.up-row .fname { flex: 1; direction: ltr; text-align: right; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.up-row .fstate { color: var(--muted); white-space: nowrap; }
.up-row .fstate.ok { color: var(--ok); }
.up-row .fstate.bad { color: var(--err); }
.up-prog { width: 80px; height: 6px; border-radius: 99px; background: #e6e8f2; overflow: hidden; flex-shrink: 0; }
.up-prog > div { height: 100%; background: var(--grad); transition: width .2s; }
.upload-summary { margin-top: 12px; font-size: 13.5px; color: var(--muted); }

/* ---------- share ---------- */
.share-link { display: flex; gap: 8px; flex-wrap: wrap; }
.share-link input { flex: 1; min-width: 200px; padding: 11px 12px; border: 1px solid var(--line); border-radius: 12px; font-size: 13px; direction: ltr; background: #f8f9fd; }

/* ---------- toasts ---------- */
#toasts { position: fixed; bottom: 20px; right: 16px; left: 16px; z-index: 100; display: flex; flex-direction: column; gap: 8px; align-items: center; pointer-events: none; }
.toast {
  background: #232842; color: #fff; padding: 12px 22px; border-radius: 13px;
  font-size: 14px; font-weight: 500; box-shadow: 0 10px 34px rgba(0, 0, 0, .3); max-width: 480px;
  animation: toast-in .25s;
}
.toast.err { background: #b91c1c; }
.toast.ok { background: #15803d; }
@keyframes toast-in { from { opacity: 0; transform: translateY(12px); } }

/* ---------- lightbox ---------- */
.lightbox { position: fixed; inset: 0; background: rgba(9, 11, 20, .93); z-index: 80; display: flex; align-items: center; justify-content: center; padding: 20px; }
.lightbox img { max-width: 96%; max-height: 92vh; border-radius: 10px; box-shadow: 0 10px 60px rgba(0, 0, 0, .6); }
.lb-close { position: absolute; top: 14px; left: 16px; background: rgba(255,255,255,.12); color: #fff; border: 0; font-size: 20px; cursor: pointer; width: 42px; height: 42px; border-radius: 50%; }

/* ---------- mobile ---------- */
@media (max-width: 680px) {
  body { font-size: 14.5px; }
  .page { padding: 16px 12px 80px; }
  .topbar { padding: 0 14px; height: 54px; }
  .topbar .logo { font-size: 20px; }
  .btn { min-height: 44px; }
  .btn.sm { min-height: 38px; }

  .page-head h1 { font-size: 20px; }
  .projects-grid { grid-template-columns: 1fr; }

  .proj-head { padding: 16px; }
  .proj-title-row h1 { font-size: 18px; flex-basis: 100%; order: -1; }
  .proj-title-row { gap: 8px; }
  .proj-title-row .btn { flex: 1 1 calc(50% - 4px); font-size: 13px; padding: 10px 8px; }
  .proj-title-row .btn.ghost { flex: 0 0 auto; }
  .counts { overflow-x: auto; flex-wrap: nowrap; scrollbar-width: none; padding-bottom: 2px; }
  .counts::-webkit-scrollbar { display: none; }
  .count-chip { white-space: nowrap; flex-shrink: 0; }

  .toolbar { gap: 8px; }
  .filters { order: 2; width: 100%; }
  .search { order: 1; width: 100%; }
  .search input { min-height: 44px; }

  .cards { grid-template-columns: 1fr; gap: 14px; }
  .card-actions .btn { flex: 1; }

  .modal-overlay { padding: 0; align-items: flex-end; }
  .modal { border-radius: 20px 20px 0 0; max-height: 92vh; padding: 22px 18px calc(22px + env(safe-area-inset-bottom)); animation: sheet-in .22s ease-out; }
  .modal.wide { max-width: 100%; }
  @keyframes sheet-in { from { transform: translateY(40px); opacity: .6; } }

  #toasts { bottom: 14px; }
}

@media (min-width: 681px) and (max-width: 1000px) {
  .cards { grid-template-columns: repeat(2, 1fr); }
}
