/* מפעל הסוכנים. עיצוב ממשק. עברית, RTL, נייד קודם. */

:root {
  --bg: #f4f5f8;
  --panel: #ffffff;
  --soft: #f7f8fa;
  --text: #151a21;
  --muted: #667085;
  --line: #e6e8ec;
  --line-strong: #d3d8e0;

  --accent: #2f5bea;
  --accent-soft: #eef3ff;
  --accent-line: #c9d8fd;

  --ok: #10774a;
  --ok-soft: #edfaf2;
  --ok-line: #bfe6d1;

  --wait: #9c5a08;
  --wait-soft: #fff7ea;
  --wait-line: #f2daaf;

  --bad: #bf3a31;
  --bad-soft: #fdf2f1;
  --bad-line: #f2c9c5;

  --r-s: 10px;
  --r-m: 14px;
  --r-l: 18px;

  --shadow: 0 1px 2px rgba(16, 24, 40, .05);
  --shadow-lift: 0 4px 14px rgba(16, 24, 40, .08);

  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --nav-space: calc(78px + var(--safe-bottom));

  font-family: "Heebo", "Segoe UI", "Arial Hebrew", Tahoma, Arial, sans-serif;
  font-size: 16px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
}

body {
  -webkit-tap-highlight-color: transparent;
  line-height: 1.45;
}

button, input, textarea, select { font-family: inherit; }

:focus-visible {
  outline: 3px solid var(--accent-line);
  outline-offset: 2px;
}

.app {
  max-width: 560px;
  margin: 0 auto;
  min-height: 100dvh;
  display: grid;
  grid-template-rows: auto 1fr auto;
}

/* ===== כותרת עליונה ===== */
.top {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 16px;
  background: rgba(255, 255, 255, .92);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--line);
  position: sticky;
  top: 0;
  z-index: 5;
}

.mark {
  width: 38px;
  height: 38px;
  flex: 0 0 38px;
  border-radius: 12px;
  background: linear-gradient(140deg, #3d68ef, #2543b8);
  color: #fff;
  display: grid;
  place-items: center;
  font-size: 17px;
  font-weight: 800;
  letter-spacing: -.5px;
}

.titles { min-width: 0; flex: 1; }
.brand { font-size: 12px; color: var(--muted); letter-spacing: .2px; }
.sub {
  font-size: 19px;
  font-weight: 800;
  letter-spacing: -.3px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.back {
  border: 1px solid var(--line);
  background: var(--soft);
  color: var(--text);
  width: 42px;
  height: 42px;
  flex: 0 0 42px;
  border-radius: 12px;
  font-size: 20px;
  line-height: 1;
  cursor: pointer;
}
.back:hover { background: #eef0f4; }
.back.hidden { display: none; }

/* פס טעינה דק מתחת לכותרת */
.load-bar {
  position: fixed;
  top: 0;
  inset-inline: 0;
  height: 3px;
  z-index: 20;
  opacity: 0;
  transition: opacity .15s ease;
  pointer-events: none;
}
.load-bar::after {
  content: "";
  display: block;
  height: 100%;
  width: 34%;
  background: var(--accent);
  border-radius: 999px;
  animation: slide 1.1s ease-in-out infinite;
}
body.loading .load-bar { opacity: 1; }
@keyframes slide {
  0%   { margin-inline-start: -34%; }
  100% { margin-inline-start: 100%; }
}

/* ===== תוכן ומסכים ===== */
.content { padding: 16px 16px var(--nav-space); }
.screen { display: none; }
.screen.active { display: block; }

.section-title {
  font-size: 13px;
  color: var(--muted);
  margin: 22px 0 10px;
  font-weight: 700;
  letter-spacing: .2px;
}

.stack { display: grid; gap: 10px; }

/* ===== כפתורים ===== */
.btn {
  border: 1px solid var(--line-strong);
  background: #fff;
  color: var(--text);
  border-radius: var(--r-m);
  padding: 12px 16px;
  font-size: 15px;
  font-weight: 600;
  min-height: 46px;
  cursor: pointer;
  transition: background .12s ease, border-color .12s ease, transform .06s ease;
}
.btn:hover { background: var(--soft); border-color: var(--line-strong); }
.btn:active { transform: translateY(1px); }

.btn.primary {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
  font-weight: 700;
}
.btn.primary:hover { background: #2a51d2; border-color: #2a51d2; }

.btn.ghost { background: #fff; color: var(--text); }
.btn.ghost:hover { background: var(--soft); }

.btn.big {
  padding: 16px;
  font-size: 16px;
  font-weight: 700;
  min-height: 54px;
}
.btn.full { width: 100%; margin-top: 12px; }

.btn.danger { color: var(--bad); border-color: var(--bad-line); background: var(--bad-soft); }
.btn.danger:hover { background: #fbe7e5; }
.btn.warn { color: var(--wait); border-color: var(--wait-line); background: var(--wait-soft); }
.btn.warn:hover { background: #fdf0da; }

.btn:disabled,
.btn.disabled {
  opacity: .5;
  cursor: not-allowed;
  pointer-events: none;
}

.btn.go-live {
  background: var(--ok);
  border-color: var(--ok);
  color: #fff;
  font-weight: 800;
}
.btn.go-live:disabled,
.btn.go-live.disabled {
  background: #a9b0bb;
  border-color: #a9b0bb;
  color: #fff;
  opacity: 1;
  pointer-events: none;
}

/* ===== סרגל חיפוש ===== */
.toolbar {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 8px;
  margin-bottom: 14px;
}
input[type="search"] {
  width: 100%;
  border: 1px solid var(--line-strong);
  background: #fff;
  color: var(--text);
  border-radius: var(--r-m);
  padding: 13px 14px;
  font-size: 16px;
  min-height: 46px;
}
input[type="search"]::placeholder { color: #98a1af; }
input[type="search"]:focus { border-color: var(--accent); }

/* ===== כרטיסים ===== */
.card, .row-card, .status-block {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--r-l);
  padding: 16px;
  text-align: right;
  color: inherit;
  width: 100%;
  box-shadow: var(--shadow);
}
.card {
  cursor: pointer;
  display: grid;
  gap: 10px;
  transition: border-color .12s ease, box-shadow .12s ease, transform .06s ease;
}
.card:hover { border-color: var(--accent-line); box-shadow: var(--shadow-lift); }
.card:active { transform: translateY(1px); }

.card-title {
  font-size: 18px;
  font-weight: 800;
  letter-spacing: -.3px;
}
.card-note { font-size: 13px; color: var(--muted); }

.meta { display: flex; gap: 6px; align-items: center; flex-wrap: wrap; }

.pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  font-weight: 600;
  padding: 5px 10px;
  border-radius: 999px;
  background: var(--soft);
  border: 1px solid var(--line);
  color: var(--muted);
}
.pill.on { background: var(--ok-soft); border-color: var(--ok-line); color: var(--ok); }
.pill.off { background: var(--bad-soft); border-color: var(--bad-line); color: var(--bad); }
.pill.wait { background: var(--wait-soft); border-color: var(--wait-line); color: var(--wait); }

.dot { width: 8px; height: 8px; border-radius: 50%; flex: 0 0 8px; }
.dot.ok { background: var(--ok); }
.dot.bad { background: var(--bad); }
.dot.wait { background: var(--wait); }

.metrics { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.metric {
  background: var(--soft);
  border: 1px solid var(--line);
  border-radius: var(--r-s);
  padding: 10px 6px;
  text-align: center;
}
.metric b { display: block; font-size: 19px; font-weight: 800; }
.metric span { font-size: 12px; color: var(--muted); }

.big-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin: 14px 0 4px;
}
.big-actions .btn.big { min-height: 58px; }

/* ===== צ'יפים ===== */
.filters {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  margin-bottom: 14px;
  padding-bottom: 2px;
  scrollbar-width: none;
}
.filters::-webkit-scrollbar { display: none; }
.chip {
  border: 1px solid var(--line-strong);
  background: #fff;
  color: var(--muted);
  border-radius: 999px;
  padding: 9px 16px;
  white-space: nowrap;
  font-size: 14px;
  font-weight: 600;
  min-height: 42px;
  cursor: pointer;
}
.chip:hover { background: var(--soft); }
.chip.active {
  background: var(--accent-soft);
  color: var(--accent);
  border-color: var(--accent-line);
  font-weight: 700;
}

/* ===== שורות ===== */
.row-card { display: grid; gap: 6px; }
.row-top { display: flex; justify-content: space-between; align-items: flex-start; gap: 10px; }
.row-main { font-weight: 700; }
.row-sub { color: var(--muted); font-size: 13px; }
.row-actions { display: flex; gap: 8px; margin-top: 10px; }
.row-actions .btn { flex: 1; padding: 10px; font-size: 13px; min-height: 44px; }

.tag {
  font-size: 12px;
  padding: 4px 10px;
  border-radius: 999px;
  font-weight: 700;
  white-space: nowrap;
  border: 1px solid transparent;
}
.tag.new, .tag.wait { background: var(--wait-soft); color: var(--wait); border-color: var(--wait-line); }
.tag.open { background: var(--accent-soft); color: var(--accent); border-color: var(--accent-line); }
.tag.closed, .tag.done, .tag.approved { background: var(--ok-soft); color: var(--ok); border-color: var(--ok-line); }
.tag.cancelled { background: var(--bad-soft); color: var(--bad); border-color: var(--bad-line); }

/* ===== סיכום ===== */
.stats {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 10px;
  margin-bottom: 4px;
}
.stat {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--r-l);
  padding: 16px;
  box-shadow: var(--shadow);
}
.stat b { display: block; font-size: 28px; font-weight: 800; letter-spacing: -1px; }
.stat span { color: var(--muted); font-size: 13px; }

.agent {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--r-m);
  padding: 12px 14px;
  box-shadow: var(--shadow);
}

/* ===== ניווט תחתון ===== */
.bottom {
  position: fixed;
  bottom: calc(10px + var(--safe-bottom));
  inset-inline: 0;
  margin: 0 auto;
  width: min(520px, calc(100% - 24px));
  display: grid;
  gap: 4px;
  padding: 6px;
  background: rgba(255, 255, 255, .96);
  backdrop-filter: blur(10px);
  border: 1px solid var(--line);
  border-radius: 999px;
  box-shadow: var(--shadow-lift);
  z-index: 6;
}
.bottom:empty { display: none; }
.bottom.one { grid-template-columns: 1fr; }
.bottom.four { grid-template-columns: repeat(4, 1fr); }
.nav {
  border: 0;
  background: transparent;
  color: var(--muted);
  padding: 10px 4px;
  font-size: 14px;
  font-weight: 600;
  border-radius: 999px;
  min-height: 46px;
  cursor: pointer;
}
.nav:hover { background: var(--soft); }
.nav.active { color: var(--accent); background: var(--accent-soft); font-weight: 700; }

/* ===== מצב ריק ===== */
.empty {
  color: var(--muted);
  padding: 26px 16px;
  text-align: center;
  font-size: 14px;
  background: var(--panel);
  border: 1px dashed var(--line-strong);
  border-radius: var(--r-l);
}

/* ===== הודעה צפה ===== */
.toast {
  position: fixed;
  bottom: calc(var(--nav-space) + 12px);
  inset-inline: 0;
  margin: 0 auto;
  width: min(440px, calc(100% - 28px));
  background: #1b2330;
  color: #fff;
  padding: 14px 16px;
  border-radius: var(--r-m);
  font-size: 14px;
  line-height: 1.5;
  white-space: pre-line;
  box-shadow: var(--shadow-lift);
  z-index: 30;
  opacity: 0;
  transform: translateY(10px);
  transition: opacity .18s ease, transform .18s ease;
  pointer-events: none;
}
.toast.show { opacity: 1; transform: translateY(0); }
.toast.ok { background: #10593a; }
.toast.bad { background: #8f2f27; }

/* ===== כניסה ===== */
.login-wrap {
  max-width: 380px;
  margin: 8vh auto 0;
  display: grid;
  gap: 12px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--r-l);
  padding: 26px 22px;
  box-shadow: var(--shadow);
  text-align: center;
}
.login-wrap .mark { margin: 0 auto 4px; width: 46px; height: 46px; flex: none; font-size: 19px; }
.login-wrap h1 { font-size: 22px; margin: 0; letter-spacing: -.4px; }
.login-wrap .muted { color: var(--muted); font-size: 14px; margin: 0; }
.login-wrap input[type="password"] {
  width: 100%;
  border: 1px solid var(--line-strong);
  background: #fff;
  color: var(--text);
  border-radius: var(--r-m);
  padding: 15px 14px;
  font-size: 17px;
  min-height: 54px;
  text-align: center;
}
.login-wrap input[type="password"]:focus { border-color: var(--accent); }
.login-wrap .btn.full { margin-top: 0; }
.login-error { color: var(--bad); font-size: 14px; min-height: 1.3em; margin: 0; font-weight: 600; }

.sr-only {
  position: absolute;
  width: 1px; height: 1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
}

/* ===== אימון סוכן ===== */
.training-header {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--r-l);
  padding: 16px;
  margin-bottom: 12px;
  box-shadow: var(--shadow);
}
.training-header .biz-name { font-size: 18px; font-weight: 800; letter-spacing: -.3px; }
.training-header .agent-name { color: var(--muted); font-size: 14px; margin-top: 4px; }

.steps-strip {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  margin-bottom: 14px;
}
.step {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--r-m);
  padding: 10px 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  font-size: 13px;
  color: var(--muted);
  font-weight: 600;
  box-shadow: var(--shadow);
}
.step .step-num {
  display: grid;
  place-items: center;
  width: 22px;
  height: 22px;
  flex: 0 0 22px;
  border-radius: 50%;
  background: var(--soft);
  border: 1px solid var(--line-strong);
  font-size: 12px;
  font-weight: 700;
}
.step.done {
  background: var(--ok-soft);
  border-color: var(--ok-line);
  color: var(--ok);
}
.step.done .step-num { background: var(--ok); border-color: var(--ok); color: #fff; }
.step.current {
  background: var(--accent-soft);
  border-color: var(--accent-line);
  color: var(--accent);
  font-weight: 800;
}
.step.current .step-num { background: var(--accent); border-color: var(--accent); color: #fff; }
.step.todo { opacity: .8; }

.training-focus {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--r-l);
  padding: 20px 16px;
  text-align: center;
  box-shadow: var(--shadow);
  margin-bottom: 12px;
}
.training-pass-line { font-size: 15px; font-weight: 700; margin-bottom: 4px; }
.training-score {
  font-size: 58px;
  font-weight: 800;
  line-height: 1;
  letter-spacing: -3px;
  margin: 6px 0 2px;
}
.training-score.failed { color: var(--bad); }
.training-score.in_progress { color: var(--wait); }
.training-score.passed { color: var(--ok); }
.training-target { font-size: 14px; color: var(--muted); margin-bottom: 14px; }

.training-progress {
  height: 8px;
  background: var(--soft);
  border: 1px solid var(--line);
  border-radius: 999px;
  overflow: hidden;
  margin: 0 auto 14px;
  max-width: 300px;
}
.training-progress > span {
  display: block;
  height: 100%;
  background: var(--accent);
  border-radius: 999px;
  transition: width .25s ease;
}
.training-progress.failed > span { background: var(--bad); }
.training-progress.passed > span { background: var(--ok); }
.training-progress.in_progress > span { background: var(--wait); }

.training-status-tag {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 13px;
  font-weight: 700;
  padding: 6px 14px;
  border-radius: 999px;
  margin: 2px 0 12px;
}
.training-status-tag.in_progress { background: var(--wait-soft); color: var(--wait); border: 1px solid var(--wait-line); }
.training-status-tag.failed { background: var(--bad-soft); color: var(--bad); border: 1px solid var(--bad-line); }
.training-status-tag.passed { background: var(--ok-soft); color: var(--ok); border: 1px solid var(--ok-line); }

.training-counts {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
}
.training-counts .metric b { font-size: 20px; }
.training-counts .metric.pass b { color: var(--ok); }
.training-counts .metric.fail b { color: var(--bad); }

.training-engine-line,
.training-next-line {
  margin-top: 6px;
  font-size: 13px;
  color: var(--muted);
}

.training-failed-title {
  font-size: 13px;
  font-weight: 700;
  color: var(--bad);
  margin-top: 16px;
  text-align: right;
}
.training-failed-list {
  list-style: none;
  margin: 8px 0 0;
  padding: 10px 12px;
  text-align: right;
  background: var(--bad-soft);
  border: 1px solid var(--bad-line);
  border-radius: var(--r-s);
  display: grid;
  gap: 4px;
}
.training-failed-list li { font-size: 13px; color: var(--bad); }
.training-failed-list li::before { content: "• "; }

.training-actions { display: grid; gap: 10px; }
.training-actions .btn.full { margin-top: 0; }
.training-why {
  font-size: 13px;
  color: var(--muted);
  text-align: center;
  margin: 0 0 2px;
  min-height: 1.3em;
}
.training-why.blocked { color: var(--bad); font-weight: 600; }
.training-why.ready { color: var(--ok); font-weight: 600; }

.training-lower { display: grid; gap: 14px; margin-top: 14px; align-items: start; }

/* ===== השיטה הרשמית והצופה ===== */
.method-block {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--r-l);
  padding: 18px 16px;
  text-align: right;
  box-shadow: var(--shadow);
}
.method-title {
  font-size: 19px;
  font-weight: 800;
  letter-spacing: -.3px;
  margin: 0 0 12px;
}
.method-steps {
  margin: 0;
  padding-inline-start: 1.3em;
  display: grid;
  gap: 10px;
}
.method-steps li { font-size: 15px; line-height: 1.4; }
.method-steps li b { font-weight: 700; }
.method-steps .line {
  display: block;
  margin-top: 2px;
  font-size: 14px;
  color: var(--muted);
  font-weight: 400;
}
.method-notes {
  list-style: none;
  margin: 14px 0 0;
  padding: 12px 14px;
  background: var(--soft);
  border: 1px solid var(--line);
  border-radius: var(--r-m);
  display: grid;
  gap: 6px;
}
.method-notes li { font-size: 14px; line-height: 1.45; }
.method-switch { margin: 16px 0 12px; }
.method-panel {
  border-top: 1px solid var(--line);
  padding-top: 4px;
}
.method-group { margin-top: 14px; }
.method-group h3 { font-size: 16px; font-weight: 800; margin: 0 0 6px; }
.method-label { font-size: 14px; font-weight: 700; margin: 10px 0 4px; }
.method-check { list-style: none; margin: 0; padding: 0; }
.method-check li { font-size: 15px; line-height: 1.5; padding: 2px 0; }
.method-check li::before { content: "☐ "; color: var(--muted); }
.method-scenarios li::before { content: "• "; color: var(--accent); }
.method-foot {
  font-size: 14px;
  line-height: 1.45;
  color: var(--muted);
  margin: 12px 0 0;
}

.observer-block textarea {
  width: 100%;
  border: 1px solid var(--line-strong);
  background: #fff;
  color: var(--text);
  border-radius: var(--r-m);
  padding: 14px;
  font-size: 16px;
  min-height: 120px;
  resize: vertical;
  line-height: 1.5;
  margin-top: 10px;
}
.observer-block textarea:focus { border-color: var(--accent); }
.observer-lead { font-size: 14px; line-height: 1.5; margin: 0; color: var(--muted); }
.observer-floor {
  font-size: 13px;
  color: var(--muted);
  line-height: 1.5;
  margin: 12px 0 0;
  padding: 10px 12px;
  background: var(--soft);
  border: 1px solid var(--line);
  border-radius: var(--r-s);
}
.observer-list { list-style: none; margin: 8px 0 0; padding: 0; display: grid; gap: 8px; }
.observer-lesson {
  background: var(--soft);
  border: 1px solid var(--line);
  border-radius: var(--r-m);
  padding: 12px;
  display: grid;
  gap: 6px;
  text-align: right;
}
.observer-kind { font-weight: 800; font-size: 13px; }
.observer-wait { font-size: 13px; color: var(--wait); font-weight: 700; }
.observer-note { font-size: 15px; line-height: 1.45; }
.observer-msg { min-height: 1.3em; font-size: 14px; color: var(--muted); margin: 10px 0 0; }
.observer-lesson .btn { width: auto; justify-self: start; min-height: 44px; padding: 8px 18px; }
.observer-empty { color: var(--muted); font-size: 14px; }

/* ===== טופס עסק חדש ===== */
.form-stack {
  display: grid;
  gap: 16px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--r-l);
  padding: 18px 16px;
  box-shadow: var(--shadow);
}
.field { display: grid; gap: 6px; }
.field > span { font-size: 14px; font-weight: 700; }
.field > span em { color: var(--bad); font-style: normal; }
.field input[type="text"],
.field textarea {
  width: 100%;
  border: 1px solid var(--line-strong);
  background: #fff;
  color: var(--text);
  border-radius: var(--r-m);
  padding: 13px 14px;
  font-size: 16px;
  min-height: 50px;
}
.field textarea { min-height: 88px; resize: vertical; line-height: 1.5; }
.field input:focus,
.field textarea:focus { border-color: var(--accent); }
.hint { font-size: 12px; color: var(--muted); line-height: 1.4; }
.form-error {
  color: var(--bad);
  font-size: 14px;
  min-height: 1.3em;
  margin: 0;
  text-align: center;
  font-weight: 600;
}
.form-stack .btn.full { margin-top: 0; }

/* ===== מסך רחב ===== */
@media (min-width: 900px) {
  .app { max-width: 1040px; }
  .content { padding: 24px 24px var(--nav-space); }
  .top { padding: 14px 24px; }
  .sub { font-size: 21px; }

  #biz-list, #summary-list { grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); }
  .stats { grid-template-columns: repeat(4, 1fr); }
  .big-actions { grid-template-columns: repeat(4, 1fr); }
  .training-lower { grid-template-columns: 1fr 1fr; }
  .form-stack { max-width: 620px; }
  .toolbar { max-width: 620px; }
  #btn-factory-summary, #btn-settings, #btn-cancel-new-biz { max-width: 620px; }
}

@media (min-width: 620px) {
  .training-top { display: grid; grid-template-columns: 1.1fr 1fr; gap: 14px; align-items: start; }
  .training-top .training-focus { margin-bottom: 0; }
}

/* ===== מסך צר מאוד ===== */
@media (max-width: 360px) {
  .content { padding: 14px 12px var(--nav-space); }
  .big-actions { grid-template-columns: 1fr; }
  .metric span { font-size: 10px; }
}

@media (prefers-reduced-motion: reduce) {
  * { animation-duration: .01ms !important; transition-duration: .01ms !important; }
}
