/* Replyo Console — עיצוב
   מותג: פטרול #1E3C47, זהב #F9B522
   ⛔ הזהב תמיד עם טקסט כהה. זהב עם לבן נכשל בניגודיות — נמדד בעבר.
   ⛔ אין אימוג'ים בממשק. אייקונים = SVG inline עם currentColor.        */

:root {
  --petrol:       #1E3C47;
  --petrol-700:   #162E36;
  --petrol-300:   #3D6373;
  --gold:         #F9B522;
  --gold-700:     #C98D0E;

  --bg:           #F4F6F7;
  --surface:      #FFFFFF;
  --surface-2:    #EDF1F2;
  --line:         #D6DEE1;
  --text:         #14262D;
  --text-muted:   #4E6672;      /* נמדד 6.06:1 מול --surface, 5.59:1 מול --bg */
  --text-on-dark: #FFFFFF;

  --ok:           #0E7A4B;
  --ok-bg:        #E3F5EC;
  --warn:         #9A5B00;
  --warn-bg:      #FFF2D9;
  --danger:       #B3261E;
  --danger-bg:    #FBE7E6;

  --bubble-in:    #FFFFFF;
  --bubble-out:   #DCF0DA;
  --radius:       14px;
  --shadow:       0 1px 3px rgba(20,38,45,.10), 0 4px 16px rgba(20,38,45,.06);
  --font:         "Assistant", "Heebo", -apple-system, "Segoe UI", system-ui, sans-serif;
}

:root:not([data-theme="light"]) { }
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg:         #0E1A1F;
    --surface:    #16262D;
    --surface-2:  #1E323B;
    --line:       #2C4650;
    --text:       #E8EFF1;
    --text-muted: #9DB2BB;      /* נמדד 7.06:1 מול --surface הכהה */
    --bubble-in:  #1E323B;
    --bubble-out: #14453A;
    --ok-bg:      #10301F;
    --warn-bg:    #3A2A05;
    --danger-bg:  #3A1614;
    --ok:         #6BD9A0;
    --warn:       #F6C453;
    --danger:     #FF9A93;
    --shadow:     0 1px 3px rgba(0,0,0,.4);
  }
}
:root[data-theme="dark"] {
  --bg:#0E1A1F; --surface:#16262D; --surface-2:#1E323B; --line:#2C4650;
  --text:#E8EFF1; --text-muted:#9DB2BB; --bubble-in:#1E323B; --bubble-out:#14453A;
  --ok-bg:#10301F; --warn-bg:#3A2A05; --danger-bg:#3A1614;
  --ok:#6BD9A0; --warn:#F6C453; --danger:#FF9A93;
  --shadow:0 1px 3px rgba(0,0,0,.4);
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0; direction: rtl; font-family: var(--font);
  background: var(--bg); color: var(--text);
  -webkit-font-smoothing: antialiased;
  /* ⛔ בלי זה iOS גולל את כל הדף מתחת למקלדת */
  overscroll-behavior: none;
}
button, input, textarea, select { font: inherit; color: inherit; }
/* ⛔ מתחת ל-16px ספארי מזום פנימה על כל שדה. נמדד ותועד. */
input, textarea { font-size: 16px; }

.icon { width: 20px; height: 20px; stroke: currentColor; fill: none;
        stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; flex: none; }
.icon-sm { width: 16px; height: 16px; }

/* ══ מסך הזדהות ══ */
.auth-wrap { min-height: 100dvh; display: grid; place-items: center; padding: 24px;
             background: linear-gradient(160deg, var(--petrol) 0%, var(--petrol-700) 100%); }
.auth-card { width: min(420px, 100%); background: var(--surface); border-radius: 20px;
             padding: 32px 28px; box-shadow: 0 12px 40px rgba(0,0,0,.28); }
.auth-logo { display: flex; align-items: center; gap: 10px; margin-bottom: 22px; }
.auth-logo b { font-size: 22px; letter-spacing: -.3px; }
.auth-card h1 { font-size: 19px; margin: 0 0 6px; }
.auth-card p  { margin: 0 0 20px; color: var(--text-muted); font-size: 14px; line-height: 1.5; }
.field { display: block; margin-bottom: 14px; }
.field span { display: block; font-size: 13px; font-weight: 600; margin-bottom: 6px; }
.field input { width: 100%; padding: 12px 14px; border: 1.5px solid var(--line);
               border-radius: 10px; background: var(--surface); }
.field input:focus { outline: none; border-color: var(--petrol-300);
                     box-shadow: 0 0 0 3px rgba(61,99,115,.22); }
.code-input { letter-spacing: .5em; text-align: center; font-weight: 700; font-size: 22px !important; }

.btn { display: inline-flex; align-items: center; justify-content: center; gap: 8px;
       padding: 12px 18px; border: 0; border-radius: 10px; font-weight: 700;
       cursor: pointer; width: 100%; }
.btn-primary { background: var(--petrol); color: #fff; }
.btn-primary:hover { background: var(--petrol-700); }
/* ⛔ זהב = רקע מלא עם טקסט כהה. לבן על זהב נכשל בניגודיות. */
.btn-gold { background: var(--gold); color: var(--petrol-700); }
.btn-gold:hover { background: var(--gold-700); color: #fff; }
.btn-ghost { background: transparent; color: var(--text-muted); width: auto; padding: 8px 10px; }
.btn:disabled { opacity: .55; cursor: not-allowed; }

.msg-error { background: var(--danger-bg); color: var(--danger); padding: 10px 12px;
             border-radius: 9px; font-size: 14px; margin-bottom: 14px; font-weight: 600; }
.msg-ok    { background: var(--ok-bg); color: var(--ok); padding: 10px 12px;
             border-radius: 9px; font-size: 14px; margin-bottom: 14px; font-weight: 600; }

/* ══ מבנה האפליקציה ══ */
/* ⛔ minmax(0,1fr) ולא 1fr. ב-Grid, `1fr` = `minmax(auto,1fr)`, ו-auto לא
      נותן לעמודה לרדת מתחת לרוחב התוכן — טבלה רחבה מותחת את כל המסך
      במקום לגלול בתוך עצמה. נמדד: 915px על חלון 390px. */
.app { display: grid; grid-template-columns: 360px minmax(0, 1fr); height: 100dvh; }
.pane-list { background: var(--surface); border-inline-start: 1px solid var(--line);
             display: flex; flex-direction: column; min-height: 0; }
.pane-chat { display: flex; flex-direction: column; min-height: 0; min-width: 0; background: var(--bg); }

.topbar { background: var(--petrol); color: #fff; padding: 12px 16px;
          display: flex; align-items: center; gap: 10px; flex: none; }
.topbar b { font-size: 16px; }
.topbar .sub { font-size: 12px; opacity: .8; }
.topbar .spacer { margin-inline-start: auto; }
/* ⛔ אזור נגיעה מינימלי 44px. נמדד 34x30 ותוקן — אצבע לא פוגעת ב-30px. */
.topbar button { background: rgba(255,255,255,.14); color: #fff; border: 0;
                 border-radius: 10px; cursor: pointer; display: grid; place-items: center;
                 min-width: 44px; min-height: 44px; }
.topbar button:hover { background: rgba(255,255,255,.26); }

.search { padding: 10px 12px; border-bottom: 1px solid var(--line); flex: none; }
.search input { width: 100%; padding: 9px 12px; border: 1.5px solid var(--line);
                border-radius: 20px; background: var(--surface-2); }

.conv-list { overflow-y: auto; flex: 1; min-height: 0; }
.conv { display: flex; gap: 11px; padding: 12px 14px; cursor: pointer;
        border-bottom: 1px solid var(--line); align-items: flex-start; }
.conv:hover { background: var(--surface-2); }
.conv.active { background: var(--surface-2); box-shadow: inset 3px 0 0 var(--gold); }
.avatar { width: 42px; height: 42px; border-radius: 50%; background: var(--petrol-300);
          color: #fff; display: grid; place-items: center; font-weight: 700; flex: none; font-size: 15px; }
.conv-main { flex: 1; min-width: 0; }
.conv-top { display: flex; align-items: baseline; gap: 8px; }
.conv-name { font-weight: 700; font-size: 15px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.conv-time { font-size: 11px; color: var(--text-muted); margin-inline-start: auto; flex: none; }
.conv-prev { font-size: 13px; color: var(--text-muted); overflow: hidden;
             text-overflow: ellipsis; white-space: nowrap; margin-top: 2px; }
.badge { background: var(--gold); color: var(--petrol-700); border-radius: 11px;
         min-width: 21px; height: 21px; padding: 0 6px; font-size: 12px; font-weight: 800;
         display: grid; place-items: center; flex: none; }

/* ══ מחוון חלון 24 השעות — הדבר הכי חשוב במסך ══ */
.win { display: inline-flex; align-items: center; gap: 5px; font-size: 11px;
       font-weight: 700; padding: 2px 8px; border-radius: 20px; margin-top: 5px; }
.win-open         { background: var(--ok-bg);     color: var(--ok); }
.win-closing_soon { background: var(--warn-bg);   color: var(--warn); }
.win-expired,
.win-never_replied,
.win-bad_timestamp{ background: var(--danger-bg); color: var(--danger); }

.chat-head { background: var(--surface); border-bottom: 1px solid var(--line);
             padding: 10px 16px; display: flex; align-items: center; gap: 11px; flex: none; }
.chat-head .who b { display: block; font-size: 15px; }
.chat-head .who small { color: var(--text-muted); font-size: 12px; }
.back-btn { display: none; }

.thread { flex: 1; overflow-y: auto; overflow-x: hidden; min-width: 0; padding: 18px 16px; display: flex;
          flex-direction: column; gap: 6px; min-height: 0; }
.bubble { max-width: min(560px, 78%); padding: 8px 12px 6px; border-radius: 12px;
          box-shadow: var(--shadow); position: relative; word-break: break-word;
          white-space: pre-wrap; line-height: 1.45; font-size: 14.5px; }
.bubble.in  { background: var(--bubble-in);  align-self: flex-start; border-start-start-radius: 4px; }
.bubble.out { background: var(--bubble-out); align-self: flex-end;   border-start-end-radius: 4px; }
.bubble .meta { display: flex; align-items: center; gap: 4px; justify-content: flex-end;
                font-size: 10.5px; color: var(--text-muted); margin-top: 3px; }
.bubble.failed { border: 1.5px solid var(--danger); }
.bubble .err { color: var(--danger); font-size: 11.5px; font-weight: 700; margin-top: 3px; }
.bubble img, .bubble video { max-width: 100%; border-radius: 8px; display: block; }
.chip { display: inline-flex; align-items: center; gap: 5px; background: var(--surface-2);
        border: 1px solid var(--line); border-radius: 8px; padding: 4px 8px;
        font-size: 12px; font-weight: 600; margin-top: 4px; }
.day-sep { align-self: center; background: var(--surface-2); color: var(--text-muted);
           font-size: 11.5px; font-weight: 700; padding: 3px 12px; border-radius: 20px; margin: 8px 0; }

.composer { flex: none; border-top: 1px solid var(--line); background: var(--surface); padding: 10px 12px; }
.composer-row { display: flex; gap: 8px; align-items: flex-end; }
.composer textarea { flex: 1; resize: none; border: 1.5px solid var(--line); border-radius: 20px;
                     padding: 10px 14px; max-height: 130px; background: var(--surface-2); }
.composer textarea:focus { outline: none; border-color: var(--petrol-300); }
.send-btn { width: 44px; height: 44px; border-radius: 50%; border: 0; background: var(--petrol);
            color: #fff; display: grid; place-items: center; cursor: pointer; flex: none; }
.send-btn:disabled { background: var(--line); color: var(--text-muted); cursor: not-allowed; }
.composer-lock { background: var(--danger-bg); color: var(--danger); border-radius: 10px;
                 padding: 11px 13px; font-size: 13.5px; font-weight: 600; line-height: 1.5; }

.empty { flex: 1; display: grid; place-items: center; color: var(--text-muted);
         text-align: center; padding: 30px; }
.empty svg { width: 52px; height: 52px; opacity: .35; margin-bottom: 12px; }

/* ══ מודל — ⛔ לא משתמשים ב-confirm/alert של הדפדפן ══ */
.modal-back { position: fixed; inset: 0; background: rgba(10,22,27,.55);
              display: grid; place-items: center; padding: 20px; z-index: 50; }
.modal { background: var(--surface); border-radius: 16px; padding: 22px;
         width: min(400px, 100%); box-shadow: 0 16px 48px rgba(0,0,0,.3); }
.modal h3 { margin: 0 0 8px; font-size: 17px; }
.modal p  { margin: 0 0 18px; color: var(--text-muted); font-size: 14px; line-height: 1.55; }
.modal-actions { display: flex; gap: 9px; }
.modal-actions .btn { width: auto; flex: 1; }

/* ══ נייד ══ */
@media (max-width: 860px) {
  .app { grid-template-columns: minmax(0, 1fr); }
  .pane-list { border: 0; }
  .app[data-view="chat"] .pane-list { display: none; }
  .app[data-view="list"] .pane-chat { display: none; }
  .back-btn { display: grid; place-items: center; background: transparent; border: 0;
              color: var(--text); cursor: pointer; min-width: 44px; min-height: 44px; }
  .bubble { max-width: 86%; }
}
/* בתוך אפליקציה מותקנת — מרווח לסרגל המערכת */
@media (display-mode: standalone) {
  .topbar { padding-top: max(12px, env(safe-area-inset-top)); }
  .composer { padding-bottom: max(10px, env(safe-area-inset-bottom)); }
}

/* ══ הגרלות ══ */
.topbar button.on { background: var(--gold); color: var(--petrol-700); }

.st { font-size: 11px; font-weight: 800; padding: 2px 9px; border-radius: 20px; flex: none; }
.st-draft  { background: var(--surface-2); color: var(--text-muted); }
.st-live   { background: var(--ok-bg);     color: var(--ok); }
.st-paused { background: var(--warn-bg);   color: var(--warn); }
.st-ended  { background: var(--danger-bg); color: var(--danger); }

.card { min-width: 0; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
        padding: 16px; margin-bottom: 14px; }
.card h4 { margin: 0 0 8px; font-size: 15px; }
.hint { color: var(--text-muted); font-size: 12.5px; line-height: 1.5; margin: 6px 0 0; display: block; }

.linkbox { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; margin-top: 10px; }
.linkbox code { flex: 1; min-width: 200px; background: var(--surface-2); border: 1px solid var(--line);
                border-radius: 8px; padding: 9px 11px; font-size: 12.5px; direction: ltr;
                text-align: left; overflow-x: auto; white-space: nowrap; }

.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(90px, 1fr)); gap: 10px; }
.stats > div { background: var(--surface-2); border-radius: 10px; padding: 12px 10px; text-align: center; }
.stats b { display: block; font-size: 22px; color: var(--petrol); }
.stats span { font-size: 11.5px; color: var(--text-muted); }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) .stats b { color: var(--gold); } }
:root[data-theme="dark"] .stats b { color: var(--gold); }

.row-btns { display: flex; gap: 8px; flex-wrap: wrap; }

/* ⛔ טבלה חייבת לגלול בתוך עצמה — אחרת גוף הדף גולש אופקית */
.tbl { width: 100%; border-collapse: collapse; font-size: 13px; display: block; overflow-x: auto; }
.tbl th, .tbl td { padding: 8px 10px; text-align: right; border-bottom: 1px solid var(--line); white-space: nowrap; }
.tbl th { color: var(--text-muted); font-size: 11.5px; font-weight: 700; }
.tbl tbody tr:hover { background: var(--surface-2); }

/* טופס בתוך מודל */
.modal .field textarea:focus, .modal .field input:focus { outline: none; border-color: var(--petrol-300); }

/* ══ טולטיפ במעבר עכבר — הדפוס מהדשבורד של CHROMESYNC ══ */
.wtip { position: relative; }
.wtip::after {
  content: attr(data-tip);
  position: absolute; top: calc(100% + 7px); right: 50%; transform: translateX(50%);
  background: var(--petrol-700); color: #fff;
  font-size: 12px; font-weight: 600; padding: 5px 10px; border-radius: 7px;
  white-space: nowrap; opacity: 0; pointer-events: none;
  transition: opacity .14s; z-index: 999;
}
.wtip:hover::after, .wtip:focus-visible::after { opacity: 1; }
/* טולטיפ שנפתח כלפי מטה מהסרגל העליון ייחתך — שם פותחים למטה בכל מקרה */
.topbar .wtip::after { top: calc(100% + 6px); }
/* ⛔ במסך מגע אין ריחוף. טולטיפ שנתקע פתוח אחרי נגיעה מסתיר תוכן. */
@media (hover: none) { .wtip::after { display: none; } }

/* ══ תיבת קוד מחולקת — אותו דפוס כמו בלומדים ══ */
.code-boxes { direction: ltr; display: flex; gap: 8px; justify-content: center; margin-bottom: 4px; }
.code-boxes input {
  width: 100%; max-width: 52px; aspect-ratio: 1 / 1.15;
  border: 1.5px solid var(--line); border-radius: 10px;
  background: var(--surface); color: var(--text);
  font-size: 24px; font-weight: 800; text-align: center; padding: 0;
}
.code-boxes input:focus-visible { outline: 2px solid var(--petrol-300); outline-offset: 1px;
                                  border-color: var(--petrol-300); }
.code-boxes.bad input { border-color: var(--danger); }
@media (max-width: 420px) { .code-boxes { gap: 6px; } }

/* ══ צירוף קובץ בתיבת הכתיבה ══ */
.attach-btn { width: 44px; height: 44px; border-radius: 50%; border: 0; background: var(--surface-2);
              color: var(--text-muted); display: grid; place-items: center; cursor: pointer; flex: none; }
.attach-btn:hover { background: var(--line); color: var(--text); }
.preview { display: flex; gap: 10px; align-items: center; background: var(--surface-2);
           border: 1px solid var(--line); border-radius: 10px; padding: 8px 10px; margin-bottom: 8px; }
.preview img, .preview video { width: 52px; height: 52px; object-fit: cover; border-radius: 7px; flex: none; }
.preview .nm { flex: 1; min-width: 0; font-size: 13px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.preview button { background: transparent; border: 0; color: var(--danger); cursor: pointer;
                  min-width: 40px; min-height: 40px; display: grid; place-items: center; }

/* ══ גלריית העלאות ══ */
.grid-up { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 12px; }
.up-card { background: var(--surface); border: 1px solid var(--line); border-radius: 12px;
           overflow: hidden; display: flex; flex-direction: column; }
.up-card .thumb { aspect-ratio: 1; background: var(--surface-2); display: grid; place-items: center;
                  overflow: hidden; cursor: pointer; }
.up-card .thumb img, .up-card .thumb video { width: 100%; height: 100%; object-fit: cover; }
.up-card .who { padding: 8px 10px; font-size: 12px; }
.up-card .who b { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.up-card .who span { color: var(--text-muted); font-size: 11px; }

/* ══ נכסי קמפיין ══ */
.asset-row { display: flex; gap: 10px; align-items: flex-start; background: var(--surface-2);
             border: 1px solid var(--line); border-radius: 10px; padding: 10px; margin-bottom: 8px; }
.asset-row img, .asset-row video { width: 64px; height: 64px; object-fit: cover; border-radius: 8px; flex: none; }
.asset-row .body { flex: 1; min-width: 0; }
.asset-row textarea { width: 100%; border: 1px solid var(--line); border-radius: 8px;
                      background: var(--surface); padding: 7px 9px; resize: vertical; font-size: 13px; }
.drop { border: 2px dashed var(--line); border-radius: 12px; padding: 18px; text-align: center;
        color: var(--text-muted); font-size: 13.5px; cursor: pointer; }
.drop:hover, .drop.over { border-color: var(--petrol-300); color: var(--text); background: var(--surface-2); }

.lightbox { position: fixed; inset: 0; background: rgba(8,18,22,.92); display: grid; place-items: center;
            z-index: 60; padding: 20px; }
.lightbox img, .lightbox video { max-width: 100%; max-height: 88dvh; border-radius: 10px; }
.lightbox .cap { position: absolute; bottom: 16px; inset-inline: 20px; color: #fff; text-align: center;
                 font-size: 13px; background: rgba(0,0,0,.5); padding: 8px 12px; border-radius: 8px; }
