/* WhatsApp Sandbox — minimal CSS, no framework */

:root {
  --bg:        #0f1115;
  --panel:    #181b22;
  --panel-2:  #1f232c;
  --border:   #2a2f3a;
  --text:     #e6e9ef;
  --muted:    #8a93a3;
  --accent:   #25d366;          /* WhatsApp green */
  --accent-2: #128c7e;
  --danger:   #ef4444;
  --warn:     #f59e0b;
  --info:     #3b82f6;
  --radius:   10px;
  --mono:     ui-monospace, SFMono-Regular, Menlo, monospace;
}

* { box-sizing: border-box; }

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

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ─── top bar ─── */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 24px;
  background: var(--panel);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 10;
}
.brand { display: flex; align-items: center; gap: 10px; }
.logo {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 28px; height: 28px;
  background: var(--accent);
  color: #0f1115;
  font-weight: 700;
  border-radius: 6px;
  font-size: 12px;
}
.brand .name { font-weight: 600; }
.brand .ver  { color: var(--muted); font-size: 12px; }

.nav { display: flex; gap: 4px; }
.nav-link {
  padding: 6px 12px;
  border-radius: 6px;
  color: var(--muted);
  font-size: 13px;
}
.nav-link:hover { background: var(--panel-2); color: var(--text); text-decoration: none; }
.nav-link.active { background: var(--panel-2); color: var(--text); }

/* ─── layout ─── */
.content {
  max-width: 1100px;
  margin: 24px auto;
  padding: 0 24px;
}
.footer {
  text-align: center;
  color: var(--muted);
  font-size: 12px;
  padding: 24px;
  border-top: 1px solid var(--border);
  margin-top: 40px;
}

h1 { margin: 0 0 16px; font-size: 22px; }
h2 { margin: 0 0 12px; font-size: 16px; }
.muted { color: var(--muted); }
.empty { color: var(--muted); padding: 24px 0; text-align: center; }

/* ─── cards ─── */
.card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  margin-bottom: 20px;
}
.grid.two-col {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 20px;
}
@media (max-width: 760px) {
  .grid.two-col { grid-template-columns: 1fr; }
}

/* ─── buttons ─── */
.btn {
  padding: 8px 16px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--panel-2);
  color: var(--text);
  font-size: 13px;
  cursor: pointer;
  transition: opacity .15s, background .15s;
}
.btn:hover { background: #262b36; }
.btn:disabled { opacity: .4; cursor: not-allowed; }
.btn-primary { background: var(--accent); color: #0f1115; border-color: var(--accent); font-weight: 600; }
.btn-primary:hover { background: #1eb858; }
.btn-danger  { background: transparent; color: var(--danger); border-color: var(--danger); }
.btn-danger:hover  { background: rgba(239, 68, 68, .12); }
.btn-ghost   { background: transparent; }
.button-row { display: flex; gap: 8px; margin-top: 16px; flex-wrap: wrap; }

/* ─── status card ─── */
.status-row { display: flex; align-items: center; gap: 10px; margin-bottom: 6px; }
.dot { width: 12px; height: 12px; border-radius: 50%; background: var(--muted); }
.dot-stopped   { background: var(--muted); }
.dot-launching { background: var(--warn);  animation: pulse 1s infinite; }
.dot-qr        { background: var(--info);  animation: pulse 1s infinite; }
.dot-logged_in { background: var(--accent); }
.dot-error     { background: var(--danger); }
.state-label { font-weight: 600; font-size: 16px; }
.state-detail { color: var(--muted); font-size: 13px; min-height: 1.5em; }

@keyframes pulse {
  0%, 100% { opacity: 1; }
  50%      { opacity: .4; }
}

/* ─── QR card ─── */
.qr-area {
  background: #fff;
  border-radius: 8px;
  min-height: 260px;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  margin-bottom: 12px;
}
.qr-area img { max-width: 240px; max-height: 240px; image-rendering: pixelated; }
.qr-placeholder { color: #888; font-size: 14px; }
.qr-help { color: var(--muted); font-size: 12px; margin: 0; }

/* ─── self-test ─── */
.selftest-result {
  margin-top: 16px;
  border-top: 1px solid var(--border);
  padding-top: 12px;
}
.selftest-result.hidden { display: none; }
.selftest-row {
  display: flex;
  justify-content: space-between;
  padding: 4px 0;
  font-family: var(--mono);
  font-size: 12px;
}
.selftest-row .ok   { color: var(--accent); }
.selftest-row .bad  { color: var(--danger); }

/* ─── stats ─── */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 12px;
}
.stat {
  background: var(--panel-2);
  border-radius: 8px;
  padding: 14px;
  text-align: center;
}
.stat-label { display: block; color: var(--muted); font-size: 11px; text-transform: uppercase; }
.stat-value { display: block; font-size: 22px; font-weight: 700; margin-top: 4px; }

/* ─── tables ─── */
.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}
.data-table th, .data-table td {
  text-align: left;
  padding: 8px 10px;
  border-bottom: 1px solid var(--border);
}
.data-table th {
  color: var(--muted);
  font-weight: 500;
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: .04em;
}
.data-table code { font-family: var(--mono); font-size: 12px; background: var(--panel-2); padding: 1px 5px; border-radius: 3px; }
.log-warn  { color: var(--warn); }
.log-error { color: var(--danger); }

.badge { padding: 1px 6px; border-radius: 4px; font-size: 11px; text-transform: uppercase; }
.badge-info    { background: rgba(59,130,246,.2);  color: var(--info); }
.badge-warn    { background: rgba(245,158,11,.2);  color: var(--warn); }
.badge-error   { background: rgba(239,68,68,.2);   color: var(--danger); }
.badge-success { background: rgba(37,211,102,.2);  color: var(--accent); }

.small { font-size: 11px; }
.mono  { font-family: var(--mono); }

/* ─── runner card ─── */
.runner-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px 16px;
  font-size: 12px;
}
.runner-grid > div { display: flex; justify-content: space-between; padding: 4px 0; border-bottom: 1px solid var(--border); }
.runner-grid .muted { font-size: 11px; }
.runner-action { margin-left: 12px; }
.runner-action.hidden { display: none; }

/* ─── activity feed ─── */
.activity-feed {
  max-height: 320px;
  overflow-y: auto;
  font-size: 13px;
}
.activity-row {
  display: grid;
  grid-template-columns: 80px 24px 140px 1fr;
  gap: 12px;
  padding: 6px 8px;
  border-bottom: 1px solid var(--border);
  align-items: center;
}
.activity-row:hover { background: var(--panel-2); }
.activity-ts { color: var(--muted); font-family: var(--mono); font-size: 11px; }
.activity-dir { font-size: 14px; }
.activity-contact { font-weight: 600; }
.activity-text { color: var(--text); word-break: break-word; }
.activity-in .activity-dir { color: var(--info); }
.activity-out .activity-dir { color: var(--accent); }
.activity-error .activity-dir { color: var(--danger); }
.activity-error .activity-text { color: var(--danger); }

/* ─── logs panel ─── */
.logs-toolbar {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 0 0 12px;
  margin-bottom: 12px;
  border-bottom: 1px solid var(--border);
}
.logs-toolbar label { display: flex; align-items: center; gap: 4px; }
.log-stream {
  max-height: 65vh;
  overflow-y: auto;
  font-family: var(--mono);
  font-size: 12px;
  background: #0c0e12;
  border-radius: 6px;
  padding: 12px;
}
.log-line {
  display: grid;
  grid-template-columns: 80px 60px 140px 1fr;
  gap: 10px;
  padding: 3px 0;
  border-bottom: 1px dashed #1a1d24;
}
.log-ts { color: var(--muted); }
.log-event { color: var(--accent); font-weight: 600; }
.log-payload { color: #c5cad3; word-break: break-word; }
.log-warn  .log-event { color: var(--warn); }
.log-error .log-event { color: var(--danger); }
.log-error .log-payload { color: #fca5a5; }

/* ─── contacts table ─── */
.contacts-table td { vertical-align: top; }
.btn-sm { padding: 4px 10px; font-size: 11px; }

/* ─── modal ─── */
.modal { position: fixed; inset: 0; z-index: 50; display: flex; align-items: center; justify-content: center; }
.modal.hidden { display: none; }
.modal-backdrop { position: absolute; inset: 0; background: rgba(0,0,0,.6); }
.modal-content {
  position: relative;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  width: 90vw;
  max-width: 640px;
  max-height: 80vh;
  display: flex;
  flex-direction: column;
}
.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
}
.modal-body { padding: 16px 20px; overflow-y: auto; }
.history-list { display: flex; flex-direction: column; gap: 10px; }
.history-row { padding: 10px; border-radius: 6px; }
.history-in  { background: rgba(59,130,246,.08); border-left: 3px solid var(--info); }
.history-out { background: rgba(37,211,102,.08); border-left: 3px solid var(--accent); }
.history-meta { display: flex; gap: 8px; align-items: center; margin-bottom: 6px; }
.history-text { word-break: break-word; }

/* ─── Phase 3: engine + forms ─── */
.engine-status-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px 20px;
  margin-bottom: 8px;
}
.engine-status-grid > div {
  display: flex;
  justify-content: space-between;
  padding: 6px 0;
  border-bottom: 1px solid var(--border);
  font-size: 12px;
}
.ok-text  { color: var(--accent); }
.bad-text { color: var(--danger); }

.engine-test-row {
  display: flex;
  gap: 10px;
  margin-bottom: 12px;
}
.text-input {
  flex: 1;
  padding: 8px 12px;
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text);
  font-size: 13px;
  font-family: inherit;
}
.text-input:focus { outline: none; border-color: var(--accent); }
.test-result {
  background: var(--panel-2);
  border-radius: 6px;
  padding: 12px;
  margin-top: 12px;
}
.test-result.hidden { display: none; }
.test-result-row { display: flex; gap: 10px; align-items: center; padding: 4px 0; }
.test-reply { font-weight: 600; word-break: break-word; }
.test-extra { padding-top: 6px; }

.rule-form { display: flex; flex-direction: column; gap: 10px; }
.form-row { display: flex; gap: 12px; flex-wrap: wrap; }
.form-row label { display: flex; flex-direction: column; gap: 4px; }
.form-grow { flex: 1; min-width: 200px; }
.rule-form label { display: flex; flex-direction: column; gap: 4px; }
.rule-form input, .rule-form select, .rule-form textarea {
  padding: 8px 10px;
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text);
  font-size: 13px;
  font-family: inherit;
}
.rule-form input:focus, .rule-form select:focus, .rule-form textarea:focus {
  outline: none; border-color: var(--accent);
}
.rule-form textarea { resize: vertical; min-height: 60px; }

.rules-table td { vertical-align: middle; }
.rule-pattern { font-family: var(--mono); }
.rule-response { color: var(--text); max-width: 300px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; display: inline-block; }

/* ─── toggle switch ─── */
.switch { position: relative; display: inline-block; width: 36px; height: 20px; cursor: pointer; }
.switch input { opacity: 0; width: 0; height: 0; }
.switch-slider {
  position: absolute; inset: 0;
  background: var(--border);
  border-radius: 20px;
  transition: .2s;
}
.switch-slider::before {
  content: ''; position: absolute;
  width: 16px; height: 16px; left: 2px; top: 2px;
  background: var(--text);
  border-radius: 50%;
  transition: .2s;
}
.switch input:checked + .switch-slider { background: var(--accent); }
.switch input:checked + .switch-slider::before { transform: translateX(16px); background: #0f1115; }

/* ─── Phase 4: sending card ─────────────────────────────────────────────── */
.send-badge { display: inline-block; margin-left: 8px; padding: 2px 8px; border-radius: 999px;
              font-size: 12px; font-weight: 600; vertical-align: middle; }
.send-off    { background: var(--muted); color: #fff; }
.send-on     { background: var(--accent); color: #fff; }
.send-warmup { background: var(--warn); color: #000; }
.send-badge.hidden { display: none; }

/* ─── Phase 3.5: knowledge page ─────────────────────────────────────────── */
.kb-prompt { margin-top: 10px; }
.kb-prompt-text { white-space: pre-wrap; font-size: 12px; background: rgba(127,127,127,.08);
                  padding: 10px; border-radius: 6px; margin-top: 6px; }

/* ─── Settings page ─────────────────────────────────────────────────────── */
.prompt-box { width: 100%; font-family: ui-monospace, Consolas, monospace; font-size: 13px; }

/* ─── Human hand-off ────────────────────────────────────────────────────── */
.handoff-card { border-color: var(--warn); }
.handoff-card.hidden { display: none; }
.row-attention td { background: rgba(245,158,11,.08); }
.nowrap { white-space: nowrap; }

/* ─── Multi-user: login, user box ───────────────────────────────────────── */
.userbox { display: flex; align-items: center; gap: 8px; margin-left: auto; }
.inline-form { display: inline; margin: 0; }
.login-body { display: flex; align-items: center; justify-content: center; min-height: 100vh; padding: 16px; }
.login-card { width: 100%; max-width: 380px; }
.login-brand { margin-bottom: 8px; }
.hidden { display: none !important; }
