/* BASIC — עיצוב הפאנל. RTL, עברית, בהיר בקביעות (בכוונה — לא עוקב אחרי
   prefers-color-scheme). פלטה בהשראת WhatsApp: טורקיז-ירוק המותג
   (#00A884/#008069), בועת "יוצאת" הירוקה-בהירה האמיתית (#D9FDD3),
   ורקע לבן-אפרפר נקי במקום כרטיסים כהים. */

:root {
  --bg: #f0f2f5;
  --surface: #ffffff;
  --surface-2: #f7f8fa;
  --border: #e9edef;
  --text: #111b21;
  --muted: #5b6b74;
  /* #00A884 (הירוק הבהיר של WhatsApp עצמו) נכשל בניגודיות עם טקסט לבן
     (3.03:1, מתחת לסף 4.5:1) — לכן --brand הוא הטורקיז הכהה יותר
     שהמותג עצמו משתמש בו לכותרות (#008069), ו---brand-dark כהה עוד
     יותר לריאקציה/hover. --brand-soft נשאר הירוק הבהיר האמיתי של
     בועת "יוצאת" ב-WhatsApp — רקע בלבד, לא טקסט. */
  --brand: #008069;
  --brand-dark: #006c56;
  --brand-soft: #d9fdd3;
  --danger: #dc2626;
  --danger-soft: #fee2e2;
  --warn: #d97706;
  --warn-soft: #fef3c7;
  --info: #2563eb;
  --info-soft: #dbeafe;
  --radius: 14px;
  --shadow: 0 1px 2px rgba(17, 27, 33, .06), 0 4px 14px rgba(17, 27, 33, .05);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: "Segoe UI", "Noto Sans Hebrew", "Rubik", Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 15px;
  line-height: 1.6;
}

a { color: var(--brand-dark); }

/* ------------------------------------------------------------ פריסה */
.shell { display: flex; min-height: 100vh; }

.sidebar {
  width: 250px;
  flex: 0 0 250px;
  background: var(--surface);
  border-inline-start: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  padding: 20px 14px;
  position: sticky;
  top: 0;
  height: 100vh;
}

.brand { display: flex; gap: 10px; align-items: center; margin-bottom: 22px; padding: 0 6px; }
.brand-mark {
  width: 38px; height: 38px; border-radius: 11px;
  background: linear-gradient(135deg, var(--brand), var(--brand-dark));
  color: #fff; display: grid; place-items: center; font-weight: 700; font-size: 19px;
  box-shadow: 0 2px 6px rgba(0, 128, 105, .35);
}
.brand strong { display: block; font-size: 17px; }
.brand small { color: var(--muted); font-size: 12px; }

nav { display: flex; flex-direction: column; gap: 2px; flex: 1; }
nav a {
  display: flex; align-items: center; gap: 10px;
  padding: 9px 12px; border-radius: 9px;
  color: var(--text); text-decoration: none; font-size: 14.5px;
}
nav a:hover { background: var(--surface-2); }
nav a.active { background: var(--brand-soft); color: var(--brand-dark); font-weight: 600; }
nav .ico { width: 20px; text-align: center; opacity: .8; }
.nav-sep { height: 1px; background: var(--border); margin: 10px 4px; }

.logout { border-top: 1px solid var(--border); padding-top: 12px; }
.who { font-size: 12.5px; color: var(--muted); margin-bottom: 8px; text-align: center; }

.content { flex: 1; padding: 24px 30px 60px; min-width: 0; }

.topbar {
  display: flex; justify-content: space-between; align-items: center;
  gap: 16px; margin-bottom: 20px; flex-wrap: wrap;
}
.topbar h1 { margin: 0; font-size: 24px; }
.topbar-actions { display: flex; gap: 8px; flex-wrap: wrap; }

/* ------------------------------------------------------------ כרטיסים */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 18px;
  margin-bottom: 18px;
}
.card > h2, .card > h3 { margin-top: 0; font-size: 17px; }
.card-head { display: flex; justify-content: space-between; align-items: center; gap: 12px; margin-bottom: 14px; flex-wrap: wrap; }
.card-head h2, .card-head h3 { margin: 0; font-size: 17px; }

.grid { display: grid; gap: 16px; }
.grid-2 { grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); }
.grid-3 { grid-template-columns: repeat(auto-fit, minmax(230px, 1fr)); }
.grid-stats { grid-template-columns: repeat(auto-fit, minmax(165px, 1fr)); }

.stat { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 15px 16px; box-shadow: var(--shadow); }
.stat .value { font-size: 27px; font-weight: 700; line-height: 1.2; }
.stat .label { color: var(--muted); font-size: 13px; }
.stat.ok .value { color: var(--brand); }
.stat.danger .value { color: var(--danger); }

/* ------------------------------------------------------------ תגיות */
.badge {
  display: inline-flex; align-items: center; gap: 5px;
  padding: 3px 10px; border-radius: 999px;
  font-size: 12.5px; font-weight: 600; white-space: nowrap;
}
.badge.ok { background: var(--brand-soft); color: var(--brand-dark); }
.badge.warn { background: var(--warn-soft); color: var(--warn); }
.badge.danger { background: var(--danger-soft); color: var(--danger); }
.badge.info { background: var(--info-soft); color: var(--info); }
.badge.muted { background: var(--surface-2); color: var(--muted); border: 1px solid var(--border); }
.badge .dot { width: 7px; height: 7px; border-radius: 50%; background: currentColor; }

/* ------------------------------------------------------------ כפתורים */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  padding: 8px 16px; border-radius: 9px; border: 1px solid transparent;
  background: var(--brand); color: #fff;
  font-size: 14px; font-weight: 600; font-family: inherit;
  cursor: pointer; text-decoration: none;
}
.btn:hover { background: var(--brand-dark); }
.btn-ghost { background: transparent; color: var(--text); border-color: var(--border); }
.btn-ghost:hover { background: var(--surface-2); }
.btn-danger { background: var(--danger); }
.btn-danger:hover { background: #b91c1c; }
.btn-sm { padding: 5px 11px; font-size: 13px; }
.btn-block { width: 100%; }
.btn-row { display: flex; gap: 8px; flex-wrap: wrap; }

/* ------------------------------------------------------------ טפסים */
.field { margin-bottom: 14px; }
.field label { display: block; font-weight: 600; font-size: 13.5px; margin-bottom: 5px; }
.field .hint { color: var(--muted); font-size: 12.5px; margin-top: 4px; }

input[type=text], input[type=password], input[type=search], input[type=email],
select, textarea {
  width: 100%; padding: 9px 12px;
  border: 1px solid var(--border); border-radius: 9px;
  background: var(--surface-2); color: var(--text);
  font-family: inherit; font-size: 14.5px;
}
input:focus, select:focus, textarea:focus {
  outline: none; border-color: var(--brand);
  box-shadow: 0 0 0 3px var(--brand-soft);
}
textarea { min-height: 110px; resize: vertical; line-height: 1.65; }

.inline-form { display: flex; gap: 8px; flex-wrap: wrap; align-items: flex-end; }
.inline-form .field { margin: 0; flex: 1 1 180px; }

/* ------------------------------------------------------------ טבלאות */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 14px; }
th, td { padding: 10px 12px; text-align: right; border-bottom: 1px solid var(--border); vertical-align: middle; }
th { color: var(--muted); font-size: 12.5px; font-weight: 600; text-transform: none; background: var(--surface-2); position: sticky; top: 0; }
tbody tr:hover { background: var(--surface-2); }
td.num, th.num { font-variant-numeric: tabular-nums; direction: ltr; text-align: right; }
.ltr { direction: ltr; text-align: right; unicode-bidi: isolate; }

.empty { text-align: center; color: var(--muted); padding: 34px 12px; }
.empty .big { font-size: 34px; display: block; margin-bottom: 6px; opacity: .5; }

/* ------------------------------------------------------------ הודעות מערכת */
.flash-stack { display: flex; flex-direction: column; gap: 8px; margin-bottom: 18px; }
.flash { padding: 11px 15px; border-radius: 9px; border: 1px solid; font-size: 14px; }
.flash-success { background: var(--brand-soft); border-color: var(--brand); color: var(--brand-dark); }
.flash-error { background: var(--danger-soft); border-color: var(--danger); color: var(--danger); }
.flash-warning { background: var(--warn-soft); border-color: var(--warn); color: var(--warn); }
.flash-info, .flash-debug { background: var(--info-soft); border-color: var(--info); color: var(--info); }

/* ------------------------------------------------------------ QR */
.qr-box { text-align: center; padding: 10px; }
.qr-box img { width: 262px; height: 262px; background: #fff; padding: 10px; border-radius: 12px; border: 1px solid var(--border); }
.qr-steps { counter-reset: step; list-style: none; padding: 0; margin: 16px 0 0; text-align: right; }
.qr-steps li { counter-increment: step; padding: 5px 0 5px 0; color: var(--muted); font-size: 13.5px; }
.qr-steps li::before { content: counter(step); display: inline-grid; place-items: center; width: 21px; height: 21px; border-radius: 50%; background: var(--brand-soft); color: var(--brand-dark); font-weight: 700; font-size: 12px; margin-left: 8px; }

/* ------------------------------------------------------------ בועות הודעה */
.bubble-list { display: flex; flex-direction: column; gap: 8px; max-height: 460px; overflow-y: auto; padding: 10px; background: var(--bg); border-radius: 10px; }
.bubble { max-width: 78%; padding: 7px 9px 8px; border-radius: 8px; font-size: 14px; box-shadow: 0 1px 1px rgba(17, 27, 33, .08); }
.bubble .meta { font-size: 11px; color: var(--muted); margin-top: 3px; }
.bubble.in { background: var(--surface); align-self: flex-start; border-start-start-radius: 2px; }
.bubble.out { background: var(--brand-soft); color: var(--text); align-self: flex-end; border-start-end-radius: 2px; }

/* ------------------------------------------------------------ קוד */
code, pre, .mono { font-family: "Cascadia Code", Consolas, monospace; font-size: 13px; }
.codebox {
  background: var(--surface-2); border: 1px solid var(--border);
  border-radius: 9px; padding: 10px 12px;
  direction: ltr; text-align: left; overflow-x: auto; white-space: pre-wrap; word-break: break-all;
}

/* ------------------------------------------------------------ דף התחברות */
.login-page { min-height: 100vh; display: grid; place-items: center; padding: 20px;
  background: linear-gradient(160deg, #e7f8f3 0%, var(--bg) 60%); }
.login-card { width: 100%; max-width: 390px; background: var(--surface);
  border-radius: 18px; padding: 32px 30px; box-shadow: 0 12px 40px rgba(17, 27, 33, .1); }
.login-card .brand { justify-content: center; margin-bottom: 6px; }
.login-sub { text-align: center; color: var(--muted); font-size: 13.5px; margin-bottom: 22px; }
.login-error { background: var(--danger-soft); color: var(--danger); border-radius: 9px; padding: 10px 13px; font-size: 13.5px; margin-bottom: 14px; }
.login-foot { text-align: center; color: var(--muted); font-size: 12px; margin-top: 18px; }

/* ------------------------------------------------------------ שיחות (WhatsApp Web) */
.chat-shell {
  display: grid; grid-template-columns: 320px 1fr 280px;
  height: calc(100vh - 150px); min-height: 480px;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: var(--shadow); overflow: hidden;
}
.chat-col { min-width: 0; display: flex; flex-direction: column; overflow: hidden; }
.chat-list-col { border-inline-start: 1px solid var(--border); }
.chat-info-col { border-inline-start: 1px solid var(--border); padding: 16px; overflow-y: auto; }
.chat-list-head { padding: 12px; border-bottom: 1px solid var(--border); display: flex; flex-direction: column; gap: 8px; }
.chat-list { flex: 1; overflow-y: auto; }
.chat-item {
  display: flex; align-items: center; gap: 10px; padding: 10px 12px; cursor: pointer;
  border-bottom: 1px solid var(--border); min-width: 0;
}
.chat-item:hover { background: var(--surface-2); }
.chat-item.active { background: var(--brand-soft); }
.chat-item .avatar {
  width: 38px; height: 38px; border-radius: 50%; background: var(--surface-2);
  display: flex; align-items: center; justify-content: center; font-size: 16px; flex-shrink: 0;
}
.chat-item .info { min-width: 0; flex: 1; }
.chat-item .name-row { display: flex; justify-content: space-between; gap: 6px; }
.chat-item .name { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chat-item .name.unread { font-weight: 800; }
.chat-item .preview { color: var(--muted); font-size: 12.5px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chat-item .unread-badge {
  background: var(--brand); color: #fff; border-radius: 999px; min-width: 19px; height: 19px;
  font-size: 11px; display: flex; align-items: center; justify-content: center; padding: 0 5px;
}
.chat-item .session-tag { font-size: 10.5px; color: var(--muted); }

.chat-thread-head { padding: 12px 16px; border-bottom: 1px solid var(--border); display: flex; align-items: center; gap: 10px; min-width: 0; }
.chat-thread-head .name { font-weight: 700; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chat-messages { flex: 1; overflow-y: auto; padding: 14px; display: flex; flex-direction: column; gap: 8px; background: var(--bg); }
.chat-composer { border-top: 1px solid var(--border); padding: 10px 12px; }
.reply-strip {
  display: none; align-items: center; gap: 8px; background: var(--surface-2); border-inline-start: 3px solid var(--brand);
  border-radius: 8px; padding: 6px 10px; margin-bottom: 8px; font-size: 12.5px; min-width: 0;
}
.reply-strip .text { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-width: 0; }
.reply-strip.visible { display: flex; }
.chat-composer-row { display: flex; gap: 8px; align-items: flex-end; }
.chat-composer-row textarea { min-height: 40px; max-height: 140px; resize: none; }

.bubble { position: relative; }
.bubble .quote {
  display: block; border-inline-start: 3px solid var(--brand); background: rgba(0,0,0,.04);
  border-radius: 6px; padding: 4px 8px; margin-bottom: 5px; font-size: 12px; color: var(--muted);
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 100%; cursor: pointer;
}
.bubble .sender-name { display: block; font-size: 11.5px; font-weight: 700; color: var(--brand-dark); margin-bottom: 2px; }
.bubble .reactions { margin-top: 4px; font-size: 13px; }
.bubble .bubble-menu-btn { position: absolute; top: 2px; left: -22px; opacity: 0; cursor: pointer; font-size: 13px; color: var(--muted); }
.bubble:hover .bubble-menu-btn { opacity: 1; }
.bubble img.media, .bubble video.media { max-width: 240px; border-radius: 8px; display: block; margin-bottom: 4px; }
.bubble.highlight { outline: 2px solid var(--brand); }

/* ------------------------------------------------------------ לוח שנה (תזכורות) */
.cal-grid { display: grid; grid-template-columns: repeat(7, 1fr); gap: 6px; }
.cal-head { text-align: center; font-size: 12px; color: var(--muted); font-weight: 600; padding-bottom: 4px; }
.cal-day {
  min-height: 64px; border: 1px solid var(--border); border-radius: 9px;
  padding: 6px; background: var(--surface-2);
}
.cal-day.out { opacity: .4; }
.cal-day.today { border-color: var(--brand); border-width: 2px; }
.cal-date { font-size: 12.5px; font-weight: 600; margin-bottom: 4px; }
.cal-badge { display: block; width: fit-content; }

/* ------------------------------------------------------------ שדה נמען לתזכורת */
.recipient-row, .option-row { display: flex; gap: 6px; margin-bottom: 6px; }
.recipient-row input, .option-row input { flex: 1; }
.poll-checklist { max-height: 220px; overflow-y: auto; display: flex; flex-direction: column; gap: 6px; padding: 4px 0; }

/* ------------------------------------------------------------ נייד */
@media (max-width: 860px) {
  .shell { flex-direction: column; }
  .sidebar { width: auto; flex: none; height: auto; position: static; border-inline-start: none; border-bottom: 1px solid var(--border); }
  nav { flex-direction: row; flex-wrap: wrap; }
  nav a { flex: 1 1 auto; justify-content: center; }
  .content { padding: 18px 15px 40px; }
  .bubble { max-width: 92%; }
  .chat-shell { grid-template-columns: 1fr; height: auto; }
  .chat-info-col, .chat-list-col { display: none; }
  .cal-grid { gap: 3px; }
  .cal-day { min-height: 44px; padding: 4px; }
  .cal-badge { font-size: 10px; padding: 2px 6px; }
}
