/* Dark control-center styling, in the spirit of the AI Studio demo: flat cards on a
   deep background, one accent color, generous spacing.

   Note on direction: the chrome is LTR (English labels), but message bodies and
   group names are Hebrew — those get dir="auto" in the markup so each block picks
   its own direction rather than forcing RTL on the whole page. */

:root {
  --bg: #0b0f14;
  --surface: #141a22;
  --surface-2: #1b232d;
  --border: #26313d;
  --text: #e6edf3;
  --muted: #8b98a5;
  --accent: #25d366; /* WhatsApp green — the one accent */
  --accent-dim: #1a7f45;
  --blue: #4c9aff;
  --amber: #f5a623;
  --red: #f4574e;
  --radius: 10px;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 14px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

/* --- top bar --- */
.topbar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 22px; border-bottom: 1px solid var(--border); background: var(--surface);
}
.brand { display: flex; align-items: center; gap: 12px; }
.logo {
  width: 36px; height: 36px; border-radius: 9px; background: var(--accent-dim);
  color: #fff; font-weight: 700; display: grid; place-items: center; letter-spacing: .5px;
}
.topbar h1 { font-size: 16px; margin: 0; font-weight: 600; }
.sub { margin: 0; color: var(--muted); font-size: 12px; }

.conn {
  display: flex; align-items: center; gap: 8px; font-size: 13px;
  background: var(--surface-2); border: 1px solid var(--border);
  padding: 6px 12px; border-radius: 999px;
}
.dot { width: 8px; height: 8px; border-radius: 50%; background: var(--muted); }
.dot.connected { background: var(--accent); box-shadow: 0 0 0 3px rgba(37, 211, 102, .15); }
.dot.connecting, .dot.awaiting_pairing { background: var(--amber); }
.dot.logged_out, .dot.error { background: var(--red); }

/* --- tabs --- */
.tabs { display: flex; gap: 4px; padding: 0 18px; border-bottom: 1px solid var(--border); background: var(--surface); }
.tab {
  background: none; border: none; color: var(--muted); font-size: 13px; font-weight: 500;
  padding: 12px 14px; cursor: pointer; border-bottom: 2px solid transparent;
}
.tab:hover { color: var(--text); }
.tab.active { color: var(--text); border-bottom-color: var(--accent); }

main { padding: 22px; max-width: 1180px; margin: 0 auto; }
.hidden { display: none !important; }

/* --- cards --- */
.card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 18px; margin-bottom: 18px;
}
.card h2 {
  font-size: 14px; margin: 0 0 14px; font-weight: 600;
  display: flex; align-items: center; gap: 10px;
}
.hint { color: var(--muted); font-weight: 400; font-size: 12px; }
.two-col { display: grid; grid-template-columns: 1fr 1fr; gap: 18px; }
@media (max-width: 820px) { .two-col { grid-template-columns: 1fr; } }

/* --- stats --- */
.stat-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 14px; margin-bottom: 18px; }
.stat {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 16px;
}
.stat .n { font-size: 26px; font-weight: 600; line-height: 1.1; }
.stat .l { color: var(--muted); font-size: 12px; margin-top: 4px; }
.stat.good .n { color: var(--accent); }
.stat.warn .n { color: var(--amber); }
.stat.bad .n { color: var(--red); }

.mini-table { display: flex; flex-direction: column; gap: 8px; }
.mini-row {
  display: flex; justify-content: space-between; gap: 12px; align-items: center;
  padding: 8px 10px; background: var(--surface-2); border-radius: 7px; font-size: 13px;
}
.mini-row .val { color: var(--muted); font-variant-numeric: tabular-nums; white-space: nowrap; }
.mini-row .name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* --- feed / lists --- */
.feed { max-height: 320px; overflow-y: auto; display: flex; flex-direction: column; gap: 6px; }
.feed-row {
  display: flex; gap: 10px; align-items: baseline; padding: 7px 10px;
  background: var(--surface-2); border-radius: 7px; font-size: 13px;
}
.feed-row .who { color: var(--muted); white-space: nowrap; font-size: 12px; }
.feed-row .txt { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.empty { color: var(--muted); font-size: 13px; text-align: center; padding: 18px; }

.badge {
  font-size: 11px; padding: 2px 8px; border-radius: 999px; white-space: nowrap;
  border: 1px solid var(--border); color: var(--muted); background: var(--surface);
}
.badge.kept, .badge.created { color: var(--accent); border-color: var(--accent-dim); }
.badge.dropped { color: var(--muted); }
.badge.updated { color: var(--blue); border-color: #2b5a99; }
.badge.canceled, .badge.error { color: var(--red); border-color: #7a2f2b; }
.badge.unmatched, .badge.force_failed { color: var(--amber); border-color: #7a5a1c; }
.badge.forced { color: var(--blue); border-color: #2b5a99; }
.log-row.forced { opacity: 1; }

/* --- calendars (calendar-centric routing) --- */
.cal-card {
  background: var(--surface-2); border: 1px solid var(--border);
  border-radius: 9px; padding: 14px; margin-bottom: 12px;
}
.cal-head { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.cal-title { display: flex; align-items: center; gap: 8px; flex: 1; min-width: 0; flex-wrap: wrap; }
.cal-name { font-weight: 600; font-size: 14px; }
.cal-id {
  color: var(--muted); font-size: 11px; margin-top: 4px; word-break: break-all;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
}
.cal-actions { display: flex; gap: 6px; }
.cal-actions .btn.small { margin-left: 0; }
.cal-error {
  background: #2a1614; border: 1px solid #5c2b28; color: #ffb4af;
  border-radius: 7px; padding: 9px 11px; font-size: 12px; margin: 10px 0 0;
}

.source-list {
  margin-top: 12px; padding-top: 12px; border-top: 1px solid var(--border);
  display: flex; flex-direction: column; gap: 2px;
}
.source-row {
  display: flex; align-items: center; gap: 11px; padding: 9px 8px;
  border-radius: 7px; cursor: pointer;
}
.source-row:hover { background: var(--surface); }
.source-row input[type="checkbox"] {
  width: 17px; height: 17px; flex: none; accent-color: var(--accent); cursor: pointer;
}
.source-row .g-main { flex: 1; min-width: 0; }
.source-row .g-name { font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.source-row .g-jid { color: var(--muted); font-size: 11px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.hint.block { display: block; margin: -6px 0 14px; }
.mode-select {
  flex: none; font-size: 11px; padding: 4px 7px; border-radius: 6px;
  background: var(--bg); border: 1px solid var(--border); color: var(--muted);
}
@media (max-width: 640px) { .source-row { flex-wrap: wrap; } .mode-select { margin-left: 28px; } }
.wide-input { width: 100%; margin-bottom: 14px; }

/* --- events --- */
.event-list { display: flex; flex-direction: column; gap: 8px; }
.event-row {
  display: flex; align-items: center; gap: 12px; padding: 12px;
  background: var(--surface-2); border: 1px solid var(--border);
  border-radius: 8px; cursor: pointer;
}
.event-row:hover { border-color: var(--accent-dim); }
.event-row.canceled { opacity: .55; }
.event-row.canceled .e-title { text-decoration: line-through; }
.event-row .swatch { width: 4px; align-self: stretch; border-radius: 2px; background: var(--muted); }
.event-row .e-main { flex: 1; min-width: 0; }
.event-row .e-title { font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.event-row .e-meta { color: var(--muted); font-size: 12px; margin-top: 2px; }

/* --- log --- */
.log-list { display: flex; flex-direction: column; gap: 6px; max-height: 640px; overflow-y: auto; }
.log-row {
  display: flex; align-items: center; gap: 10px; padding: 10px 12px;
  background: var(--surface-2); border: 1px solid var(--border);
  border-radius: 8px; cursor: pointer; font-size: 13px;
}
.log-row:hover { border-color: var(--accent-dim); }
.log-row.dropped { opacity: .62; }
.log-row .l-time { color: var(--muted); font-size: 11px; white-space: nowrap; font-variant-numeric: tabular-nums; }
.log-row .l-sender { color: var(--muted); font-size: 12px; white-space: nowrap; max-width: 130px; overflow: hidden; text-overflow: ellipsis; }
.log-row .l-body { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* --- controls --- */
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; margin-top: 14px; }
.filters { display: flex; gap: 10px; flex-wrap: wrap; margin-bottom: 14px; }
select, .search, #phone-input {
  background: var(--bg); border: 1px solid var(--border); color: var(--text);
  border-radius: 7px; padding: 8px 11px; font-size: 13px; font-family: inherit;
}
.search { flex: 1; min-width: 180px; }
#phone-input { flex: 1; min-width: 240px; }

.btn {
  background: var(--surface-2); border: 1px solid var(--border); color: var(--text);
  border-radius: 7px; padding: 8px 14px; font-size: 13px; cursor: pointer; font-family: inherit;
}
.btn:hover { border-color: var(--muted); }
.btn.primary { background: var(--accent-dim); border-color: var(--accent-dim); color: #fff; }
.btn.primary:hover { background: var(--accent); border-color: var(--accent); }
.btn.danger { color: var(--red); border-color: #5c2b28; }
.btn.danger:hover { background: #2a1614; }
.btn.small { padding: 4px 10px; font-size: 12px; margin-left: auto; font-weight: 400; }
.btn:disabled { opacity: .45; cursor: not-allowed; }

.switch { position: relative; display: inline-block; width: 38px; height: 21px; flex: none; }
.switch input { opacity: 0; width: 0; height: 0; }
.slider {
  position: absolute; inset: 0; background: var(--border); border-radius: 999px;
  cursor: pointer; transition: background .15s;
}
.slider::before {
  content: ""; position: absolute; height: 15px; width: 15px; left: 3px; top: 3px;
  background: #fff; border-radius: 50%; transition: transform .15s;
}
.switch input:checked + .slider { background: var(--accent-dim); }
.switch input:checked + .slider::before { transform: translateX(17px); }

/* --- pairing --- */
.pairing {
  background: var(--surface-2); border: 1px solid var(--accent-dim);
  border-radius: 8px; padding: 18px; text-align: center; margin: 14px 0;
}
.pairing-label { color: var(--muted); font-size: 12px; margin: 0 0 8px; }
.pairing-code {
  font-size: 30px; font-weight: 600; letter-spacing: 5px; color: var(--accent);
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
}
.pairing-steps { color: var(--muted); font-size: 12px; margin: 10px 0 0; }
.warn-note { color: var(--muted); font-size: 12px; margin: 10px 0 0; }

.kv { display: grid; grid-template-columns: max-content 1fr; gap: 8px 18px; margin: 0; font-size: 13px; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; word-break: break-all; }

/* --- modal --- */
.modal { position: fixed; inset: 0; background: rgba(0, 0, 0, .65); display: grid; place-items: center; padding: 22px; z-index: 50; }
.modal-body {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 24px; max-width: 760px; width: 100%; max-height: 85vh; overflow-y: auto; position: relative;
}
.modal-close {
  position: absolute; top: 12px; right: 14px; background: none; border: none;
  color: var(--muted); font-size: 24px; cursor: pointer; line-height: 1;
}
.modal h3 { margin: 0 0 6px; font-size: 16px; }
.modal h4 { margin: 20px 0 8px; font-size: 12px; color: var(--muted); text-transform: uppercase; letter-spacing: .5px; }
pre {
  background: var(--bg); border: 1px solid var(--border); border-radius: 7px;
  padding: 12px; overflow-x: auto; font-size: 12px; margin: 0;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
}
.quote {
  background: var(--bg); border-left: 3px solid var(--border); border-radius: 0 7px 7px 0;
  padding: 12px; white-space: pre-wrap; font-size: 13px; margin: 0;
}
.reason { background: var(--bg); border: 1px solid var(--border); border-radius: 7px; padding: 12px; font-size: 13px; }

/* --- toast --- */
.toast {
  position: fixed; bottom: 22px; left: 50%; transform: translateX(-50%);
  background: var(--surface-2); border: 1px solid var(--border); color: var(--text);
  padding: 11px 18px; border-radius: 8px; font-size: 13px; z-index: 60;
  box-shadow: 0 8px 24px rgba(0, 0, 0, .4);
}
.toast.err { border-color: #7a2f2b; color: #ffb4af; }

/* --- login --- */
.login-body { display: grid; place-items: center; min-height: 100vh; padding: 22px; }
.login-card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 28px; width: 100%; max-width: 380px;
}
.login-brand { display: flex; align-items: center; gap: 12px; margin-bottom: 22px; }
.login-brand h1 { font-size: 16px; margin: 0; font-weight: 600; }
.field { display: block; margin-bottom: 14px; }
.field span { display: block; color: var(--muted); font-size: 12px; margin-bottom: 6px; }
.field input {
  width: 100%; background: var(--bg); border: 1px solid var(--border); color: var(--text);
  border-radius: 7px; padding: 10px 12px; font-size: 15px; font-family: inherit;
}
.btn.wide { width: 100%; padding: 11px; font-size: 14px; margin-top: 4px; }
.login-error {
  background: #2a1614; border: 1px solid #5c2b28; color: #ffb4af;
  border-radius: 7px; padding: 10px 12px; font-size: 13px; margin: 14px 0 0;
}
.login-note { color: var(--muted); font-size: 12px; margin: 14px 0 0; }
.danger-note { color: #ffb4af; }

.topbar-right { display: flex; align-items: center; gap: 10px; }
.topbar-right .btn.small { margin-left: 0; }

/* --- mobile ---
   This dashboard is meant to be usable from a phone, so the layouts that assume
   horizontal room (the top bar, filter rows, calendar card headers, wide log rows)
   collapse to stacked blocks rather than scrolling sideways. */
@media (max-width: 640px) {
  .topbar { flex-direction: column; align-items: flex-start; gap: 10px; padding: 12px 16px; }
  .topbar-right { width: 100%; justify-content: space-between; }
  .tabs { overflow-x: auto; padding: 0 10px; -webkit-overflow-scrolling: touch; }
  .tab { padding: 12px 11px; white-space: nowrap; }
  main { padding: 14px; }
  .card { padding: 14px; }
  .stat-grid { grid-template-columns: 1fr 1fr; gap: 10px; }
  .filters { flex-direction: column; }
  .filters select, .filters .search { width: 100%; }
  .row { flex-direction: column; align-items: stretch; }
  .row .btn, .row input { width: 100%; }
  .cal-head { flex-direction: column; align-items: flex-start; }
  .cal-actions { width: 100%; }
  .cal-actions .btn { flex: 1; }
  /* Timestamp and sender are the first things worth losing when a log row has to
     fit a phone — the message text and its outcome badge are the payload. */
  .log-row .l-time, .log-row .l-sender { display: none; }
  .event-row { flex-wrap: wrap; }
  .pairing-code { font-size: 24px; letter-spacing: 3px; }
  .modal { padding: 0; }
  .modal-body { max-height: 100vh; border-radius: 0; border: none; padding: 20px; }
  .kv { grid-template-columns: 1fr; gap: 2px 0; }
  .kv dt { margin-top: 8px; }
}
