:root {
  --bg: #f6f5fb;
  --panel: #ffffff;
  --border: #e7e5f0;
  --text: #1f1b2e;
  --text-dim: #6b6779;
  --accent: #7c3aed;
  --accent-soft: #f0e9ff;
  --danger: #e0553f;
  --online: #22c55e;
  --offline: #a1a1aa;
  --shadow: 0 1px 2px rgba(31, 27, 46, 0.04), 0 4px 16px rgba(31, 27, 46, 0.05);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 24px;
  background: var(--panel);
  border-bottom: 1px solid var(--border);
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  font-weight: 700;
  font-size: 16px;
}
.brand-icon {
  width: 30px;
  height: 30px;
  border-radius: 9px;
  background: var(--accent);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 14px;
  font-weight: 700;
}
.role-badge {
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--accent);
  background: var(--accent-soft);
  padding: 3px 8px;
  border-radius: 6px;
  margin-left: 8px;
}

.topbar-right {
  display: flex;
  align-items: center;
  gap: 14px;
  font-size: 13px;
  color: var(--text-dim);
}

.container {
  max-width: 1240px;
  margin: 32px auto;
  padding: 0 20px;
  display: flex;
  flex-direction: column;
  gap: 24px;
}

.card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 22px;
  box-shadow: var(--shadow);
}

.card h2 {
  margin: 0 0 16px;
  font-size: 16px;
}

.flash {
  position: fixed;
  top: 20px;
  right: 20px;
  z-index: 1000;
  max-width: 380px;
  background: var(--panel);
  color: var(--text);
  border-left: 4px solid var(--accent);
  border-radius: 10px;
  padding: 12px 16px;
  font-size: 13.5px;
  font-weight: 600;
  box-shadow: var(--shadow), 0 8px 24px rgba(31, 27, 46, 0.14);
  animation: toast-in 0.25s ease;
}
.flash.hide {
  animation: toast-out 0.25s ease forwards;
}
@keyframes toast-in {
  from { transform: translateX(24px); opacity: 0; }
  to { transform: translateX(0); opacity: 1; }
}
@keyframes toast-out {
  from { transform: translateX(0); opacity: 1; }
  to { transform: translateX(24px); opacity: 0; }
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13.5px;
}
th {
  text-align: left;
  color: var(--text-dim);
  font-weight: 600;
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  padding: 8px 10px;
  border-bottom: 1px solid var(--border);
}
td {
  padding: 10px;
  border-bottom: 1px solid var(--border);
  vertical-align: top;
}
tr:last-child td { border-bottom: none; }

.empty-row td {
  color: var(--text-dim);
  text-align: center;
  padding: 20px;
}

.status-pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  font-weight: 600;
  padding: 3px 9px;
  border-radius: 999px;
  background: var(--bg);
}
.status-dot { width: 7px; height: 7px; border-radius: 50%; }
.status-dot.on { background: var(--online); }
.status-dot.off { background: var(--offline); }

.status-toggle {
  border: 1px solid transparent;
  cursor: pointer;
  color: var(--text);
  font-family: inherit;
}
.status-toggle:hover {
  border-color: var(--border);
  background: var(--hover, var(--accent-soft));
}

.form-row {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  align-items: flex-end;
}
.field {
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-size: 12.5px;
  font-weight: 600;
  color: var(--text-dim);
}
.field input:not([type="checkbox"]), .field select {
  border: 1px solid var(--border);
  background: var(--bg);
  border-radius: 9px;
  padding: 9px 12px;
  font-size: 14px;
  color: var(--text);
  font-family: inherit;
  min-width: 220px;
}
.field input:not([type="checkbox"]):focus, .field select:focus {
  outline: none;
  border-color: var(--accent);
}

.btn {
  border: none;
  border-radius: 9px;
  padding: 9px 16px;
  font-size: 13.5px;
  font-weight: 600;
  cursor: pointer;
  font-family: inherit;
}
.btn-primary { background: var(--accent); color: #fff; }
.btn-primary:hover { opacity: 0.92; }
.btn-ghost { background: var(--bg); color: var(--text); border: 1px solid var(--border); }
.btn-ghost:hover { background: var(--accent-soft); color: var(--accent); }
.btn-danger { background: #fbeae7; color: var(--danger); }
.btn-danger:hover { opacity: 0.85; }
.btn-sm { padding: 6px 10px; font-size: 12.5px; }
.btn-icon {
  padding: 7px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  line-height: 0;
}

.link { color: var(--accent); text-decoration: none; font-weight: 600; font-size: 13px; }
.link:hover { text-decoration: underline; }

.actions { display: flex; gap: 4px; flex-wrap: nowrap; }

.inline-edit { display: flex; gap: 4px; align-items: center; flex-wrap: nowrap; }
.inline-edit-input {
  border: 1px solid transparent;
  background: transparent;
  border-radius: 7px;
  padding: 5px 7px;
  font-size: 13.5px;
  color: var(--text);
  font-family: inherit;
  width: 130px;
  flex-shrink: 1;
  min-width: 0;
}
.inline-edit-input.wide { width: 170px; }
.inline-edit-input:hover { border-color: var(--border); }
.inline-edit-input:focus {
  outline: none;
  border-color: var(--accent);
  background: var(--bg);
}

.domain-status {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  font-size: 11px;
  font-weight: 700;
  flex-shrink: 0;
}
.domain-status.live { background: #dcfce7; color: #16a34a; }
.domain-status.pending { background: var(--bg); color: var(--text-dim); border: 1px solid var(--border); }
.domain-status.failed { background: #fbeae7; color: var(--danger); }

.login-wrap {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
}
.login-card {
  width: 340px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 28px;
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
  gap: 16px;
}
.login-card h1 {
  margin: 0;
  font-size: 18px;
  text-align: center;
}
.login-card form {
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.login-card label {
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-size: 12.5px;
  font-weight: 600;
  color: var(--text-dim);
}
.login-card input {
  border: 1px solid var(--border);
  background: var(--bg);
  border-radius: 9px;
  padding: 10px 12px;
  font-size: 14px;
  color: var(--text);
  font-family: inherit;
}

.muted { color: var(--text-dim); font-size: 12.5px; }
.mono { font-family: ui-monospace, "SF Mono", Consolas, monospace; font-size: 12.5px; white-space: nowrap; }

.snippet-row {
  display: flex;
  gap: 8px;
  align-items: stretch;
  margin: 14px 0;
}
.snippet-box {
  flex: 1;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 12px 14px;
  font-family: ui-monospace, "SF Mono", Consolas, monospace;
  font-size: 12.5px;
  color: var(--text);
  overflow-x: auto;
  white-space: pre;
}

.table-scroll {
  overflow-x: auto;
}

.voice-checklist {
  display: flex;
  flex-wrap: wrap;
  gap: 10px 24px;
}
.voice-check {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 13.5px;
  font-weight: 400;
  color: var(--text);
  cursor: pointer;
  white-space: nowrap;
}
.voice-check input {
  cursor: pointer;
  flex-shrink: 0;
}

.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(15, 17, 21, 0.5);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 50;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.15s ease;
}
.modal-overlay.open {
  opacity: 1;
  pointer-events: auto;
}
.modal-card {
  background: var(--panel);
  border-radius: 16px;
  padding: 24px;
  width: 420px;
  max-width: calc(100vw - 32px);
  max-height: calc(100vh - 64px);
  overflow-y: auto;
  box-shadow: var(--shadow);
  position: relative;
}
.modal-card h3 {
  margin: 0 0 16px;
  font-size: 15px;
}
.modal-close {
  position: absolute;
  top: 14px;
  right: 14px;
  background: none;
  border: none;
  color: var(--text-dim);
  cursor: pointer;
  width: 28px;
  height: 28px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 8px;
}
.modal-close:hover { background: var(--accent-soft); color: var(--accent); }

.agent-count {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13.5px;
}

.messages-body {
  display: flex;
  flex-direction: column;
  gap: 10px;
  max-height: 60vh;
  overflow-y: auto;
}
.msg-row {
  display: flex;
  flex-direction: column;
  gap: 3px;
  padding: 10px 12px;
  border-radius: 10px;
  font-size: 13.5px;
  line-height: 1.4;
}
.msg-row.msg-user { background: var(--bg); align-self: flex-end; max-width: 85%; }
.msg-row.msg-assistant { background: var(--accent-soft); align-self: flex-start; max-width: 85%; }
.msg-row-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 2px;
}
.msg-role {
  font-size: 10.5px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-dim);
}
.msg-time {
  font-size: 10.5px;
  color: var(--text-dim);
  font-family: ui-monospace, "SF Mono", Consolas, monospace;
  white-space: nowrap;
}
.msg-content { color: var(--text); white-space: pre-wrap; word-break: break-word; }

.landing-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
  gap: 16px;
  margin-top: 8px;
}
.landing-card {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 10px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 22px;
  text-decoration: none;
  color: inherit;
  box-shadow: var(--shadow);
  transition: border-color 0.15s ease;
}
.landing-card:hover { border-color: var(--accent); }
.landing-icon {
  width: 48px;
  height: 48px;
  border-radius: 12px;
  background: var(--accent-soft);
  color: var(--accent);
  display: flex;
  align-items: center;
  justify-content: center;
}
.landing-title { font-size: 16px; font-weight: 700; color: var(--text); }
.landing-desc { font-size: 13px; color: var(--text-dim); line-height: 1.4; }

.spinner {
  display: inline-block;
  width: 13px;
  height: 13px;
  border: 2px solid currentColor;
  border-right-color: transparent;
  border-radius: 50%;
  animation: spin 0.6s linear infinite;
  vertical-align: middle;
}
@keyframes spin {
  to { transform: rotate(360deg); }
}
