/* ── VARIABLES & RESET ───────────────────────────────────────────────────── */
:root {
  --bg: #0f1117;
  --surface: #1a1d27;
  --surface2: #222636;
  --border: #2a2e42;
  --accent: #7c6ef7;
  --accent2: #5b4de8;
  --text: #e4e6f0;
  --text-muted: #7a7d94;
  --success: #22c55e;
  --success-bg: #0d2e1a;
  --warning: #f59e0b;
  --warning-bg: #2a1f03;
  --danger: #ef4444;
  --danger-bg: #2e0d0d;
  --info: #38bdf8;
  --sidebar-w: 220px;
  --radius: 12px;
}

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
body { font-family: 'Inter', sans-serif; background: var(--bg); color: var(--text); display: flex; height: 100vh; overflow: hidden; font-size: 14px; }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ── SIDEBAR ─────────────────────────────────────────────────────────────── */
.sidebar {
  width: var(--sidebar-w); background: var(--surface); border-right: 1px solid var(--border);
  display: flex; flex-direction: column; flex-shrink: 0; padding: 20px 0;
}
.logo { display: flex; align-items: center; gap: 10px; padding: 0 20px 24px; font-size: 18px; font-weight: 700; color: var(--text); }
.logo-icon { width: 34px; height: 34px; background: linear-gradient(135deg, var(--accent), var(--accent2)); border-radius: 8px; display: flex; align-items: center; justify-content: center; font-size: 16px; }
nav { flex: 1; display: flex; flex-direction: column; gap: 2px; padding: 0 10px; }
.nav-item { display: flex; align-items: center; gap: 10px; padding: 10px 12px; border-radius: 8px; color: var(--text-muted); font-weight: 500; transition: all 0.15s; cursor: pointer; font-size: 13.5px; }
.nav-item:hover { background: var(--surface2); color: var(--text); text-decoration: none; }
.nav-item.active { background: linear-gradient(135deg, rgba(124,110,247,.2), rgba(91,77,232,.1)); color: var(--accent); }
.nav-icon { font-size: 15px; width: 20px; text-align: center; }
.sidebar-footer { padding: 16px 20px; display: flex; align-items: center; gap: 8px; color: var(--text-muted); font-size: 12px; border-top: 1px solid var(--border); margin-top: auto; }
.status-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--text-muted); }
.status-dot.online { background: var(--success); box-shadow: 0 0 6px var(--success); }

/* ── MAIN ────────────────────────────────────────────────────────────────── */
.main { flex: 1; overflow-y: auto; padding: 32px; }
.section { display: none; }
.section.active { display: block; }

/* ── SECTION HEADER ──────────────────────────────────────────────────────── */
.section-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 24px; flex-wrap: wrap; gap: 12px; }
.section-header h1 { font-size: 22px; font-weight: 700; color: var(--text); }
.section-header p { color: var(--text-muted); font-size: 13px; margin-top: 2px; }
.header-actions { display: flex; align-items: center; gap: 10px; }
.section-sub-header { display: flex; align-items: center; justify-content: space-between; margin: 32px 0 14px; }
.section-sub-header h2 { font-size: 16px; font-weight: 600; color: var(--text); }

/* ── BUTTONS ─────────────────────────────────────────────────────────────── */
.btn { padding: 8px 16px; border: none; border-radius: 8px; font-size: 13px; font-weight: 500; cursor: pointer; transition: all 0.15s; font-family: 'Inter', sans-serif; }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn-primary { background: linear-gradient(135deg, var(--accent), var(--accent2)); color: #fff; }
.btn-primary:hover:not(:disabled) { transform: translateY(-1px); box-shadow: 0 4px 12px rgba(124,110,247,.4); }
.btn-secondary { background: var(--surface2); color: var(--text); border: 1px solid var(--border); }
.btn-secondary:hover { background: var(--border); }
.btn-danger { background: rgba(239,68,68,.15); color: var(--danger); border: 1px solid rgba(239,68,68,.3); }
.btn-danger:hover { background: rgba(239,68,68,.25); }
.btn-sm { padding: 6px 12px; font-size: 12px; }
.btn-link { background: none; border: none; color: var(--accent); font-size: 12px; cursor: pointer; font-family: 'Inter', sans-serif; padding: 0; }
.btn-link:hover { text-decoration: underline; }
.btn-icon { background: var(--surface2); border: 1px solid var(--border); border-radius: 6px; padding: 6px 10px; cursor: pointer; font-size: 14px; color: var(--text-muted); transition: all 0.15s; }
.btn-icon:hover { color: var(--text); }
.btn-close { background: none; border: none; font-size: 18px; color: var(--text-muted); cursor: pointer; padding: 4px 8px; border-radius: 6px; }
.btn-close:hover { background: var(--surface2); color: var(--text); }

/* ── SEARCH ──────────────────────────────────────────────────────────────── */
.search-input { background: var(--surface2); border: 1px solid var(--border); color: var(--text); padding: 8px 14px; border-radius: 8px; font-size: 13px; font-family: 'Inter', sans-serif; outline: none; min-width: 220px; }
.search-input:focus { border-color: var(--accent); }
.search-input::placeholder { color: var(--text-muted); }

/* ── STATS ───────────────────────────────────────────────────────────────── */
.stats-bar { display: flex; gap: 16px; margin-bottom: 20px; flex-wrap: wrap; }
.stat-card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px 24px; display: flex; flex-direction: column; gap: 4px; min-width: 140px; }
.stat-value { font-size: 28px; font-weight: 700; color: var(--accent); }
.stat-label { font-size: 12px; color: var(--text-muted); }

/* ── TABLE ───────────────────────────────────────────────────────────────── */
.table-container { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); overflow: auto; }
table { width: 100%; border-collapse: collapse; }
th { background: var(--surface2); padding: 12px 16px; text-align: left; font-size: 12px; font-weight: 600; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.5px; border-bottom: 1px solid var(--border); }
td { padding: 12px 16px; border-bottom: 1px solid var(--border); vertical-align: middle; }
tr:last-child td { border-bottom: none; }
tr:hover td { background: rgba(255,255,255,.02); }
td.loading, td.empty { color: var(--text-muted); text-align: center; padding: 40px; font-size: 14px; }
.contact-name { font-weight: 500; color: var(--text); }
.badge-jid { font-size: 11px; background: var(--surface2); border: 1px solid var(--border); border-radius: 4px; padding: 2px 7px; color: var(--text-muted); font-family: monospace; }
.msg-content { display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; max-width: 340px; color: var(--text-muted); }

/* ── FORMS ───────────────────────────────────────────────────────────────── */
.form-group { margin-bottom: 16px; }
.form-group label { display: block; font-size: 12px; font-weight: 600; color: var(--text-muted); margin-bottom: 6px; text-transform: uppercase; letter-spacing: 0.5px; }
.form-input { width: 100%; background: var(--surface2); border: 1px solid var(--border); color: var(--text); padding: 10px 14px; border-radius: 8px; font-size: 13px; font-family: 'Inter', sans-serif; outline: none; transition: border 0.15s; }
.form-input:focus { border-color: var(--accent); }
.form-input::placeholder { color: var(--text-muted); }
.form-select { cursor: pointer; }
.form-textarea { resize: vertical; font-family: 'JetBrains Mono', 'Fira Code', 'Courier New', monospace; font-size: 12.5px; line-height: 1.6; min-height: 280px; }
.input-with-toggle { display: flex; gap: 8px; align-items: center; }
.input-with-toggle .form-input { flex: 1; }
.prompt-actions { margin-top: 8px; }
.hint { color: var(--text-muted); font-size: 12px; margin-top: 8px; }

/* ── CONFIG GRID ─────────────────────────────────────────────────────────── */
.config-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(340px, 1fr)); gap: 20px; }
.config-card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 24px; }
.config-card-wide { grid-column: span 2; }
@media (max-width: 900px) { .config-card-wide { grid-column: span 1; } }
.config-card h2 { font-size: 15px; font-weight: 600; color: var(--text); margin-bottom: 10px; }
.config-card p { color: var(--text-muted); font-size: 13px; line-height: 1.5; margin-bottom: 16px; }
.url-box { display: flex; align-items: center; justify-content: space-between; background: var(--surface2); border: 1px solid var(--border); border-radius: 8px; padding: 10px 14px; font-family: monospace; font-size: 12px; color: var(--accent); gap: 10px; margin-bottom: 10px; }
.btn-copy { background: none; border: none; cursor: pointer; font-size: 16px; color: var(--text-muted); transition: color 0.15s; }
.btn-copy:hover { color: var(--text); }
.test-result { margin-top: 12px; padding: 10px 14px; border-radius: 8px; font-size: 13px; }
.test-result.success { background: var(--success-bg); color: var(--success); }
.test-result.error { background: var(--danger-bg); color: var(--danger); }

/* ── STATUS CARD ─────────────────────────────────────────────────────────── */
.info-row { display: flex; justify-content: space-between; align-items: center; padding: 10px 0; border-bottom: 1px solid var(--border); }
.info-row:last-child { border-bottom: none; }
.info-label { color: var(--text-muted); font-size: 13px; }
.info-value { font-weight: 600; color: var(--text); }
.info-value.ok { color: var(--success); }

/* ── TOAST ───────────────────────────────────────────────────────────────── */
.toast { position: fixed; bottom: 24px; right: 24px; background: var(--surface2); border: 1px solid var(--border); color: var(--text); padding: 12px 20px; border-radius: 10px; font-size: 13px; font-weight: 500; box-shadow: 0 8px 30px rgba(0,0,0,.4); z-index: 9999; transition: opacity 0.3s; }
.toast.hidden { opacity: 0; pointer-events: none; }

/* ── MODAL ───────────────────────────────────────────────────────────────── */
.modal-backdrop { position: fixed; inset: 0; background: rgba(0,0,0,.7); display: flex; align-items: center; justify-content: center; z-index: 9990; }
.modal-backdrop.hidden { display: none; }
.modal { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 28px; max-width: 420px; width: 90%; }
.modal h3 { font-size: 16px; font-weight: 700; margin-bottom: 10px; }
.modal p { color: var(--text-muted); font-size: 13px; line-height: 1.5; margin-bottom: 20px; }
.modal-actions { display: flex; gap: 10px; justify-content: flex-end; }
.modal-large { max-width: 760px; max-height: 85vh; overflow-y: auto; padding: 0; }
.modal-header { display: flex; justify-content: space-between; align-items: center; padding: 20px 24px; border-bottom: 1px solid var(--border); position: sticky; top: 0; background: var(--surface); border-radius: var(--radius) var(--radius) 0 0; }
.modal-header h3 { font-size: 15px; font-weight: 600; }
.report-modal-body { padding: 20px 24px; }

/* ── AUDIT LAYOUT ────────────────────────────────────────────────────────── */
.audit-layout { display: grid; grid-template-columns: 280px 1fr; gap: 20px; margin-bottom: 12px; }
@media (max-width: 860px) { .audit-layout { grid-template-columns: 1fr; } }

/* ── CONTACTS CHECKLIST ──────────────────────────────────────────────────── */
.audit-contacts-panel { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); display: flex; flex-direction: column; overflow: hidden; }
.panel-header { display: flex; justify-content: space-between; align-items: center; padding: 14px 16px; border-bottom: 1px solid var(--border); font-size: 13px; font-weight: 600; }
.select-actions { display: flex; align-items: center; gap: 6px; color: var(--text-muted); font-size: 12px; }
.audit-contacts-panel .search-input { border-radius: 0; border-left: none; border-right: none; border-top: none; border-bottom: 1px solid var(--border); min-width: auto; }
.contacts-checklist { flex: 1; overflow-y: auto; max-height: 380px; }
.contact-check-item { display: flex; align-items: center; gap: 12px; padding: 10px 16px; border-bottom: 1px solid var(--border); cursor: pointer; transition: background 0.1s; }
.contact-check-item:last-child { border-bottom: none; }
.contact-check-item:hover { background: var(--surface2); }
.contact-check-item input[type="checkbox"] { width: 16px; height: 16px; accent-color: var(--accent); cursor: pointer; flex-shrink: 0; }
.contact-check-info { flex: 1; overflow: hidden; }
.contact-check-name { display: block; font-weight: 500; font-size: 13px; color: var(--text); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.contact-check-jid { display: block; font-size: 11px; color: var(--text-muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.contact-check-count { font-size: 11px; color: var(--text-muted); background: var(--surface2); border: 1px solid var(--border); padding: 2px 7px; border-radius: 20px; white-space: nowrap; flex-shrink: 0; }
.selected-count { padding: 10px 16px; font-size: 12px; font-weight: 600; color: var(--accent); background: var(--surface2); border-top: 1px solid var(--border); text-align: center; }

/* ── AUDIT RESULTS PANEL ─────────────────────────────────────────────────── */
.audit-results-panel { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); min-height: 300px; display: flex; flex-direction: column; }
.audit-idle-state { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; padding: 48px; text-align: center; color: var(--text-muted); }
.idle-icon { font-size: 48px; margin-bottom: 16px; opacity: 0.5; }
.audit-loading { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 16px; color: var(--text-muted); padding: 48px; }
.spinner { width: 36px; height: 36px; border: 3px solid var(--border); border-top-color: var(--accent); border-radius: 50%; animation: spin 0.8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.audit-results-list { flex: 1; overflow-y: auto; padding: 16px; display: flex; flex-direction: column; gap: 16px; }

/* ── REPORT CARD ─────────────────────────────────────────────────────────── */
.report-card { background: var(--surface2); border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; }
.report-card-error { border-color: rgba(239,68,68,.4); }
.report-card-header { display: flex; align-items: center; justify-content: space-between; padding: 16px 20px; border-bottom: 1px solid var(--border); }
.report-contact { font-size: 15px; font-weight: 700; color: var(--text); display: block; }
.report-jid { font-size: 11px; color: var(--text-muted); margin-top: 2px; display: block; font-family: monospace; }
.report-error { color: var(--danger); padding: 16px 20px; }
.report-nota { display: flex; align-items: baseline; gap: 2px; font-size: 28px; font-weight: 800; }
.report-nota span { font-size: 13px; font-weight: 400; color: var(--text-muted); }
.nota-good { color: var(--success); }
.nota-mid { color: var(--warning); }
.nota-bad { color: var(--danger); }
.nota-sm { font-size: 20px; }
.report-sections { display: flex; flex-direction: column; gap: 0; }
.report-section { padding: 14px 20px; border-bottom: 1px solid var(--border); }
.report-section ul { padding-left: 18px; margin-top: 8px; display: flex; flex-direction: column; gap: 4px; }
.report-section li { font-size: 13px; line-height: 1.5; color: var(--text-muted); }
.report-section-title { font-size: 12px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.5px; }
.report-success .report-section-title { color: var(--success); }
.report-warning .report-section-title { color: var(--warning); }
.report-danger .report-section-title { color: var(--danger); }
.report-success { background: rgba(34,197,94,.04); }
.report-warning { background: rgba(245,158,11,.04); }
.report-danger { background: rgba(239,68,68,.04); }
.report-conversation { display: grid; grid-template-columns: 1fr 1fr; gap: 0; border-top: 1px solid var(--border); }
.conv-block { padding: 14px 20px; }
.conv-block:first-child { border-right: 1px solid var(--border); }
.conv-label { font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.5px; color: var(--text-muted); margin-bottom: 8px; }
.conv-text { font-size: 13px; color: var(--text-muted); line-height: 1.6; white-space: pre-wrap; }
.conv-text.suggested { color: rgba(124,110,247,.9); background: rgba(124,110,247,.06); padding: 8px 10px; border-radius: 6px; border-left: 2px solid var(--accent); }

/* ── AUDIT HISTORY ───────────────────────────────────────────────────────── */
.audit-history { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; }
.history-item { display: flex; align-items: center; justify-content: space-between; padding: 12px 20px; border-bottom: 1px solid var(--border); cursor: pointer; transition: background 0.1s; }
.history-item:last-child { border-bottom: none; }
.history-item:hover { background: var(--surface2); }
.history-name { font-weight: 500; font-size: 14px; display: block; }
.history-date { font-size: 12px; color: var(--text-muted); }
.loading-state, .empty-state { color: var(--text-muted); text-align: center; padding: 32px; font-size: 13px; }

/* ── HIDDEN ──────────────────────────────────────────────────────────────── */
.hidden { display: none !important; }
