@import url('https://fonts.googleapis.com/css2?family=Fraunces:wght@500;600;700&family=Inter:wght@400;500;600;700&display=swap');

:root {
  --bg-solid: #0d1211;
  --panel: #171d1c;
  --panel-2: #1c2321;
  --sidebar-bg: #121716;
  --border: #262d2c;
  --border-soft: #1f2624;
  --text: #f1f3f1;
  --muted: #8d9995;
  --muted-dim: #5c6664;
  --accent: #24c789;
  --accent-dark: #1a9c6c;
  --accent-soft: rgba(36, 199, 137, 0.14);
  --out-bubble: #1e3a30;
  --in-bubble: #1d2322;
  --danger: #e2685a;
  --danger-soft: rgba(226, 104, 90, 0.13);
  --warn: #e0b23c;
  --warn-soft: rgba(224, 178, 60, 0.13);
  --radius: 12px;
  --radius-sm: 8px;
  --shadow-lg: 0 20px 45px rgba(0,0,0,0.35);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
  background: var(--bg-solid);
  color: var(--text);
  height: 100vh;
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
}

.hidden { display: none !important; }
.muted { color: var(--muted); }
.small { font-size: 12.5px; }
code {
  background: rgba(255,255,255,0.06);
  padding: 1px 5px;
  border-radius: 4px;
  font-size: 0.92em;
}

/* ---------- LOGIN ---------- */
.login-screen {
  height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background:
    radial-gradient(circle at 15% 15%, rgba(36,199,137,0.14), transparent 45%),
    radial-gradient(circle at 85% 85%, rgba(36,199,137,0.08), transparent 40%),
    var(--bg-solid);
}
.login-card {
  width: 380px;
  padding: 44px 36px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 16px;
  text-align: left;
  box-shadow: var(--shadow-lg);
}
.login-mark {
  font-family: 'Fraunces', serif;
  font-size: 13px;
  font-weight: 600;
  letter-spacing: 0.14em;
  color: var(--accent);
  margin-bottom: 18px;
}
.login-card h1 {
  font-family: 'Fraunces', serif;
  font-weight: 600;
  font-size: 27px;
  margin: 0 0 6px;
}
.login-sub {
  color: var(--muted);
  font-size: 14px;
  margin: 0 0 26px;
}
.login-card input {
  width: 100%;
  padding: 13px 14px;
  background: #0a0f0e;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
  font-size: 14px;
  margin-bottom: 16px;
  font-family: inherit;
}
.login-card input:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.login-card button {
  width: 100%;
  padding: 13px;
  background: var(--accent);
  color: #06120c;
  border: none;
  border-radius: var(--radius-sm);
  font-weight: 700;
  font-size: 14px;
  cursor: pointer;
  transition: transform 0.08s ease, opacity 0.15s ease;
}
.login-card button:hover { opacity: 0.92; }
.login-card button:active { transform: scale(0.98); }
.login-error {
  color: var(--danger);
  font-size: 13px;
  min-height: 18px;
  margin: 10px 0 0;
}

/* ---------- APP LAYOUT ---------- */
.app {
  display: grid;
  grid-template-columns: 280px 1fr;
  grid-template-rows: auto 1fr;
  height: 100vh;
}

.sidebar {
  background: var(--sidebar-bg);
  border-right: 1px solid var(--border);
  padding: 20px 16px;
  display: flex;
  flex-direction: column;
  min-height: 0;
  grid-row: 1 / span 2;
}

.brand {
  display: flex;
  align-items: center;
  gap: 11px;
  margin-bottom: 20px;
  padding: 0 4px;
}
.brand-mark {
  width: 34px; height: 34px;
  background: linear-gradient(135deg, var(--accent), var(--accent-dark));
  color: #06120c;
  border-radius: 9px;
  display: flex; align-items: center; justify-content: center;
  font-family: 'Fraunces', serif;
  font-weight: 700;
  font-size: 16px;
  flex-shrink: 0;
}
.brand-name {
  font-family: 'Fraunces', serif;
  font-size: 17px;
  font-weight: 600;
  display: block;
  line-height: 1.2;
}
.brand-sub {
  font-size: 11px;
  color: var(--muted-dim);
  display: block;
  line-height: 1.2;
}

.status-block {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px 14px;
  margin-bottom: 16px;
}
.status-row { display: flex; align-items: center; gap: 8px; font-size: 13px; font-weight: 500; }
.dot { width: 8px; height: 8px; border-radius: 50%; background: var(--muted-dim); flex-shrink: 0; }
.dot.online { background: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.dot.offline { background: var(--danger); box-shadow: 0 0 0 3px var(--danger-soft); }
.status-detail { color: var(--muted); font-size: 11.5px; margin-top: 6px; }

.conv-list-label {
  font-size: 11px;
  color: var(--muted-dim);
  text-transform: uppercase;
  letter-spacing: 0.07em;
  font-weight: 600;
  margin-bottom: 8px;
  margin-top: 4px;
}
.conv-search {
  width: 100%;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 8px 11px;
  color: var(--text);
  font-size: 12.5px;
  margin-bottom: 10px;
  font-family: inherit;
}
.conv-search:focus { outline: none; border-color: var(--accent); }
.conv-list { overflow-y: auto; flex: 1; margin: 0 -16px; padding: 0 16px; min-height: 80px; }

.conv-item {
  padding: 10px 10px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  margin-bottom: 2px;
  transition: background 0.1s ease;
}
.conv-item:hover { background: var(--panel); }
.conv-item.active { background: var(--accent-soft); }
.conv-item-top { display: flex; justify-content: space-between; align-items: center; gap: 6px; font-size: 13.5px; font-weight: 600; }
.conv-item-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.conv-item-time { font-size: 10.5px; color: var(--muted-dim); font-weight: 500; flex-shrink: 0; }
.conv-item-msg { font-size: 12.5px; color: var(--muted); margin-top: 3px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.unread-badge {
  background: var(--accent);
  color: #06120c;
  font-size: 10.5px;
  font-weight: 700;
  padding: 1px 6px;
  border-radius: 10px;
  flex-shrink: 0;
}
.empty-list { color: var(--muted-dim); font-size: 13px; padding: 20px 4px; text-align: center; }

.sidebar-foot {
  padding-top: 12px;
  margin-top: 8px;
  border-top: 1px solid var(--border-soft);
}
.text-btn {
  background: none;
  border: none;
  color: var(--muted);
  font-size: 12.5px;
  cursor: pointer;
  padding: 4px 2px;
}
.text-btn:hover { color: var(--text); }

/* ---------- QUICKBAR (always-visible actions) ---------- */
.quickbar {
  grid-column: 2;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 28px;
  border-bottom: 1px solid var(--border);
  background: var(--panel);
}
.qa-btn {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  border: 1px solid var(--border);
  background: var(--panel-2);
  color: var(--text);
  padding: 8px 15px;
  border-radius: 999px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: border-color 0.12s ease, background 0.12s ease;
}
.qa-btn:hover { border-color: var(--accent); }
.qa-primary { background: var(--accent); color: #06120c; border-color: var(--accent); }
.qa-primary:hover { opacity: 0.92; }
.qa-icon { font-size: 13px; }
.quickbar-spacer { flex: 1; }
.quickbar-clock { font-size: 12px; color: var(--muted-dim); font-variant-numeric: tabular-nums; }

/* ---------- MAIN ---------- */
.main { display: flex; flex-direction: column; min-height: 0; grid-column: 2; }
.main-header {
  padding: 20px 28px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}
.main-header h2 { margin: 0; font-size: 18px; font-weight: 700; font-family: 'Fraunces', serif; }
.main-header .muted { font-size: 12.5px; }

.secondary-btn, .primary-btn {
  border: 1px solid var(--border);
  background: var(--panel-2);
  color: var(--text);
  padding: 9px 16px;
  border-radius: var(--radius-sm);
  font-size: 13.5px;
  font-weight: 600;
  cursor: pointer;
  transition: border-color 0.12s ease, opacity 0.12s ease;
  white-space: nowrap;
}
.secondary-btn:hover { border-color: var(--accent); }
.secondary-btn.small { padding: 6px 12px; font-size: 12.5px; }
.primary-btn { background: var(--accent); color: #06120c; border-color: var(--accent); font-weight: 700; }
.primary-btn:hover { opacity: 0.92; }
.primary-btn:disabled, .secondary-btn:disabled { opacity: 0.5; cursor: not-allowed; }

.thread {
  flex: 1;
  overflow-y: auto;
  padding: 24px 28px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  background:
    radial-gradient(circle at 50% 0%, rgba(36,199,137,0.03), transparent 60%);
}
.empty-state {
  margin: auto;
  text-align: center;
  max-width: 340px;
}
.empty-state-icon { font-size: 34px; margin-bottom: 12px; opacity: 0.7; }
.empty-state p { font-size: 15.5px; margin-bottom: 6px; font-weight: 600; }

.bubble-row { display: flex; }
.bubble-row.out { justify-content: flex-end; }
.bubble {
  max-width: 60%;
  padding: 10px 13px;
  border-radius: 13px;
  font-size: 14px;
  line-height: 1.48;
  word-wrap: break-word;
}
.bubble.in { background: var(--in-bubble); border-top-left-radius: 3px; border: 1px solid var(--border-soft); }
.bubble.out { background: var(--out-bubble); border-top-right-radius: 3px; }
.bubble-meta { font-size: 10.5px; color: var(--muted-dim); margin-top: 4px; text-align: right; display: flex; gap: 4px; justify-content: flex-end; align-items: center; }
.status-tick { font-size: 11px; }
.status-tick.read { color: var(--accent); }
.status-tick.failed { color: var(--danger); }

.reply-form {
  display: flex;
  gap: 10px;
  padding: 16px 28px;
  border-top: 1px solid var(--border);
}
.reply-form input {
  flex: 1;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 12px 14px;
  color: var(--text);
  font-size: 14px;
  font-family: inherit;
}
.reply-form input:focus { outline: none; border-color: var(--accent); }
.reply-form button {
  background: var(--accent);
  color: #06120c;
  border: none;
  padding: 0 22px;
  border-radius: var(--radius-sm);
  font-weight: 700;
  cursor: pointer;
}
.reply-form button:hover { opacity: 0.92; }

.window-closed-notice {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  padding: 12px 28px;
  background: var(--warn-soft);
  border-top: 1px solid rgba(224,178,60,0.3);
  font-size: 13px;
  color: #f0d38a;
}

/* ---------- MODAL ---------- */
.modal-overlay {
  position: fixed; inset: 0;
  background: rgba(6, 10, 9, 0.7);
  display: flex; align-items: center; justify-content: center;
  z-index: 50;
  backdrop-filter: blur(2px);
}
.modal {
  width: 460px;
  max-height: 88vh;
  display: flex;
  flex-direction: column;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 14px;
  overflow: hidden;
  box-shadow: var(--shadow-lg);
}
.modal-head {
  display: flex; justify-content: space-between; align-items: center;
  padding: 17px 20px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}
.modal-head h3 { margin: 0; font-size: 16px; font-weight: 700; font-family: 'Fraunces', serif; }
.icon-btn { background: none; border: none; color: var(--muted); font-size: 20px; cursor: pointer; line-height: 1; padding: 2px 6px; border-radius: 6px; }
.icon-btn:hover { color: var(--text); background: var(--panel-2); }
.modal-body { padding: 18px 20px; display: flex; flex-direction: column; gap: 4px; overflow-y: auto; }
.modal-body label { font-size: 12.5px; color: var(--muted); font-weight: 600; margin-top: 12px; margin-bottom: 5px; }
.modal-body input, .modal-body textarea, .modal-body select {
  background: #0a0f0e;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 10px 12px;
  color: var(--text);
  font-size: 14px;
  font-family: inherit;
  resize: vertical;
  width: 100%;
}
.modal-body input:focus, .modal-body textarea:focus, .modal-body select:focus { outline: none; border-color: var(--accent); }
.modal-foot {
  display: flex; justify-content: flex-end; gap: 10px;
  padding: 16px 20px;
  border-top: 1px solid var(--border);
  flex-shrink: 0;
}

.template-preview {
  background: #0a0f0e;
  border: 1px dashed var(--border);
  border-radius: var(--radius-sm);
  padding: 10px 12px;
  font-size: 13px;
  color: var(--muted);
  margin-top: 8px;
  white-space: pre-wrap;
  line-height: 1.5;
}
.template-var-row { margin-top: 10px; }
.template-var-row label { margin-top: 0; }

.tip-box {
  background: var(--accent-soft);
  border: 1px solid rgba(36,199,137,0.25);
  border-radius: var(--radius-sm);
  padding: 12px 14px;
  font-size: 12.5px;
  color: #b9e8d3;
  margin-top: 14px;
}
.tip-box strong { color: var(--text); display: block; margin-bottom: 4px; }
.tip-box ul { margin: 4px 0 0; padding-left: 18px; }
.tip-box li { margin-bottom: 3px; }

.info-banner {
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-left: 3px solid var(--accent);
  border-radius: var(--radius-sm);
  padding: 12px 16px;
  font-size: 13px;
  color: var(--muted);
  margin-bottom: 18px;
  line-height: 1.5;
}
.info-banner strong { color: var(--text); }

.file-drop {
  position: relative;
  border: 1.5px dashed var(--border);
  border-radius: var(--radius-sm);
  padding: 24px 16px;
  text-align: center;
  margin-top: 8px;
  cursor: pointer;
  transition: border-color 0.12s ease, background 0.12s ease;
}
.file-drop:hover, .file-drop.drag-over { border-color: var(--accent); background: var(--accent-soft); }
.file-drop input { position: absolute; inset: 0; opacity: 0; cursor: pointer; }
#csv-file-label { font-size: 13px; color: var(--muted); }

.progress-wrap { padding: 6px 0 14px; }
.progress-bar {
  width: 100%;
  height: 10px;
  background: var(--panel-2);
  border-radius: 999px;
  overflow: hidden;
  border: 1px solid var(--border);
}
.progress-fill {
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, var(--accent-dark), var(--accent));
  transition: width 0.25s ease;
}
#broadcast-progress-text { margin-top: 8px; }

/* ---------- TOAST ---------- */
.toast {
  position: fixed;
  bottom: 24px; left: 50%;
  transform: translateX(-50%);
  background: var(--panel);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 13px 22px;
  border-radius: var(--radius-sm);
  font-size: 13.5px;
  z-index: 100;
  box-shadow: var(--shadow-lg);
  font-weight: 500;
}
.toast.error { border-color: var(--danger); color: #ffb3a7; }
.toast.success { border-color: var(--accent); }

@media (max-width: 860px) {
  .app { grid-template-columns: 1fr; }
  .sidebar { display: none; }
  .quickbar, .main { grid-column: 1; }
}

/* ---------- NAV TABS ---------- */
.nav-tabs {
  display: flex;
  flex-direction: column;
  gap: 2px;
  margin-bottom: 18px;
}
.nav-tab {
  display: flex;
  align-items: center;
  gap: 9px;
  background: none;
  border: none;
  color: var(--muted);
  text-align: left;
  padding: 9px 10px;
  border-radius: var(--radius-sm);
  font-size: 13.5px;
  font-weight: 600;
  cursor: pointer;
  font-family: inherit;
}
.nav-icon { font-size: 14px; width: 18px; text-align: center; }
.nav-tab:hover { background: var(--panel); color: var(--text); }
.nav-tab.active { background: var(--accent-soft); color: var(--accent); }

.section { }
.section.hidden { display: none; }

.header-actions { display: flex; gap: 10px; flex-shrink: 0; }

.panel-body { padding: 22px 28px; overflow-y: auto; flex: 1; }
.toolbar-row { display: flex; gap: 12px; margin-bottom: 18px; flex-wrap: wrap; }

.search-input {
  flex: 1;
  min-width: 220px;
  max-width: 340px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 10px 14px;
  color: var(--text);
  font-size: 13.5px;
  font-family: inherit;
}
.search-input:focus { outline: none; border-color: var(--accent); }
.filter-select {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 10px 14px;
  color: var(--text);
  font-size: 13.5px;
  font-family: inherit;
}

/* ---------- DATA TABLE (contacts / templates / broadcasts) ---------- */
.data-table {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}
.dt-row {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 13px 16px;
  border-bottom: 1px solid var(--border);
  font-size: 13.5px;
  transition: background 0.1s ease;
}
.dt-row:not(.dt-head):hover { background: var(--panel-2); }
.dt-row:last-child { border-bottom: none; }
.dt-row.dt-head { background: var(--panel); color: var(--muted); font-size: 11.5px; text-transform: uppercase; letter-spacing: 0.05em; font-weight: 700; }
.dt-col-main { flex: 1; min-width: 0; }
.dt-col { width: 130px; flex-shrink: 0; color: var(--muted); }
.dt-name { font-weight: 600; }
.dt-sub { color: var(--muted); font-size: 12px; margin-top: 2px; }
.dt-actions { display: flex; gap: 6px; flex-shrink: 0; }
.dt-tag {
  display: inline-block;
  background: var(--accent-soft);
  color: var(--accent);
  font-size: 11px;
  font-weight: 600;
  padding: 2px 8px;
  border-radius: 10px;
  margin-right: 4px;
}
.icon-action {
  background: var(--panel-2); border: 1px solid var(--border); color: var(--muted);
  cursor: pointer; font-size: 12px; padding: 6px 10px; border-radius: 6px;
  font-weight: 600;
}
.icon-action:hover { border-color: var(--accent); color: var(--text); }
.icon-action.danger:hover { border-color: var(--danger); color: var(--danger); }
.empty-cell { padding: 40px 16px; text-align: center; color: var(--muted-dim); font-size: 13.5px; }
.empty-cell-icon { font-size: 26px; display: block; margin-bottom: 10px; opacity: 0.6; }

/* Status badges (template approval, message delivery) */
.badge {
  display: inline-block;
  font-size: 10.5px;
  font-weight: 700;
  padding: 3px 9px;
  border-radius: 20px;
  text-transform: uppercase;
  letter-spacing: 0.03em;
}
.badge-approved { background: rgba(36,199,137,0.15); color: var(--accent); }
.badge-pending { background: var(--warn-soft); color: var(--warn); }
.badge-rejected { background: var(--danger-soft); color: var(--danger); }
.badge-running { background: var(--warn-soft); color: var(--warn); }
.badge-completed { background: rgba(36,199,137,0.15); color: var(--accent); }
.badge-in_appeal, .badge-paused, .badge-disabled { background: var(--panel-2); color: var(--muted); }

.import-result {
  margin-top: 14px;
  background: #0a0f0e;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 13px 15px;
  font-size: 13px;
}
.import-result .ir-line { margin-bottom: 5px; }
.import-result .ir-dupes { max-height: 140px; overflow-y: auto; margin-top: 8px; font-size: 12px; color: var(--muted); border-top: 1px solid var(--border-soft); padding-top: 8px; }

.duplicate-warning {
  background: var(--warn-soft);
  border: 1px solid rgba(224,178,60,0.3);
  color: var(--warn);
  border-radius: var(--radius-sm);
  padding: 10px 12px;
  font-size: 13px;
  margin-top: 10px;
}

/* ---------- STAT GRID (analytics) ---------- */
.stat-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 14px;
}
.stat-card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px 22px;
  transition: border-color 0.15s ease;
}
.stat-card:hover { border-color: var(--border-soft); }
.stat-value {
  font-family: 'Fraunces', serif;
  font-size: 32px;
  font-weight: 700;
  color: var(--text);
}
.stat-label { color: var(--muted); font-size: 12.5px; margin-top: 6px; font-weight: 500; }

/* ---------- ACTIVITY LOG ---------- */
.log-list { display: flex; flex-direction: column; gap: 8px; }
.log-entry {
  display: flex;
  gap: 12px;
  padding: 12px 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--panel);
  font-size: 13px;
}
.log-entry.level-error { border-left: 3px solid var(--danger); }
.log-entry.level-info { border-left: 3px solid var(--accent); }
.log-entry-icon { font-size: 14px; flex-shrink: 0; margin-top: 1px; }
.log-entry-body { flex: 1; min-width: 0; }
.log-entry-msg { font-weight: 600; }
.log-entry-context { color: var(--muted); font-size: 12px; margin-top: 3px; font-family: monospace; word-break: break-word; }
.log-entry-time { color: var(--muted-dim); font-size: 11px; flex-shrink: 0; white-space: nowrap; }
