:root {
  --bg: #0d0d14;
  --bg2: #13131f;
  --bg3: #1a1a2e;
  --card: #16162a;
  --accent: #7c6cfc;
  --accent2: #a78bfa;
  --text: #e2e2f0;
  --muted: #8888aa;
  --border: #2a2a45;
  --green: #4ade80;
  --red: #f87171;
  --yellow: #fbbf24;
  --r: 10px;
}

* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

body {
  background: var(--bg);
  color: var(--text);
  font-family: system-ui, sans-serif;
  font-size: 14px;
}

button,
input,
textarea,
select {
  font: inherit;
}

button {
  cursor: pointer;
}

.top-bar {
  display: flex;
  align-items: center;
  gap: 0;
  background: var(--bg2);
  border-bottom: 1px solid var(--border);
  padding: 0 24px;
  height: 52px;
}

.logo {
  font-weight: 700;
  color: var(--accent2);
  font-size: 15px;
  margin-right: 32px;
}

.tab-btn {
  padding: 14px 20px;
  border: none;
  background: none;
  color: var(--muted);
  border-bottom: 2px solid transparent;
  margin-bottom: -1px;
  transition: 0.2s;
}

.tab-btn.active,
.tab-btn:hover {
  color: var(--text);
}

.tab-btn.active {
  border-bottom-color: var(--accent);
}

.tab-pane {
  display: none;
}

.tab-pane.active {
  display: block;
}

.client-demo {
  min-height: calc(100vh - 52px);
  background: #f0f4f8;
  position: relative;
  overflow: hidden;
}

.demo-site {
  padding: 40px;
  max-width: 900px;
  margin: 0 auto;
}

.demo-nav {
  background: #fff;
  padding: 16px 24px;
  border-radius: var(--r);
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.08);
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 24px;
}

.dn-logo {
  font-weight: 700;
  color: #1a1a2e;
  font-size: 16px;
}

.dn-links {
  display: flex;
  gap: 20px;
  list-style: none;
}

.dn-links a {
  color: #555;
  text-decoration: none;
  font-size: 13px;
}

.demo-hero {
  background: linear-gradient(135deg, #667eea, #764ba2);
  color: #fff;
  padding: 48px;
  border-radius: var(--r);
  text-align: center;
}

.demo-hero h1 {
  font-size: 28px;
  margin-bottom: 12px;
}

.demo-hero p {
  opacity: 0.85;
  font-size: 15px;
}

.demo-badge {
  display: inline-block;
  background: rgba(255, 255, 255, 0.15);
  border: 1px solid rgba(255, 255, 255, 0.3);
  padding: 6px 16px;
  border-radius: 20px;
  font-size: 12px;
  margin-top: 16px;
}

.chat-bubble {
  position: fixed;
  bottom: 28px;
  right: 28px;
  width: 52px;
  height: 52px;
  background: var(--accent);
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 4px 20px rgba(124, 108, 252, 0.5);
  font-size: 22px;
  z-index: 1000;
  border: none;
  transition: 0.2s;
}

.chat-bubble:hover {
  transform: scale(1.08);
}

.chat-window {
  position: fixed;
  bottom: 92px;
  right: 28px;
  width: 340px;
  height: 480px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 16px;
  display: flex;
  flex-direction: column;
  z-index: 999;
  box-shadow: 0 8px 40px rgba(0, 0, 0, 0.4);
  overflow: hidden;
  transition: 0.2s;
  transform-origin: bottom right;
}

.chat-window.hidden {
  display: none;
}

.cw-head {
  background: var(--bg2);
  padding: 14px 16px;
  display: flex;
  align-items: center;
  gap: 10px;
  border-bottom: 1px solid var(--border);
}

.cw-avatar {
  width: 36px;
  height: 36px;
  background: var(--accent);
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 18px;
  flex-shrink: 0;
  overflow: hidden;
}

.cw-avatar img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.cw-title {
  font-weight: 600;
  font-size: 13px;
}

.cw-status {
  font-size: 11px;
  color: var(--muted);
  display: flex;
  align-items: center;
  gap: 4px;
}

.cw-status::before {
  content: "";
  width: 6px;
  height: 6px;
  background: var(--green);
  border-radius: 50%;
  display: inline-block;
}

.cw-close {
  margin-left: auto;
  background: none;
  border: none;
  color: var(--muted);
  font-size: 18px;
  line-height: 1;
}

.cw-msgs,
.sd-msgs,
.content,
.sess-list {
  scrollbar-width: thin;
  scrollbar-color: var(--border) transparent;
}

.cw-msgs {
  flex: 1;
  overflow-y: auto;
  padding: 14px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.msg {
  max-width: 80%;
  padding: 9px 12px;
  border-radius: 12px;
  font-size: 13px;
  line-height: 1.5;
}

.msg.bot {
  background: var(--card);
  border: 1px solid var(--border);
  align-self: flex-start;
  border-bottom-left-radius: 4px;
}

.msg.user {
  background: var(--accent);
  color: #fff;
  align-self: flex-end;
  border-bottom-right-radius: 4px;
}

.msg.typing {
  color: var(--muted);
}

.cw-input-row {
  display: flex;
  gap: 8px;
  padding: 12px;
  border-top: 1px solid var(--border);
}

.cw-input,
.toolbar input,
.qa-form input,
.field input,
.field select,
.field textarea {
  outline: none;
}

.cw-input {
  flex: 1;
  background: var(--bg3);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 9px 12px;
  border-radius: 8px;
}

.cw-input:focus,
.toolbar input:focus,
.qa-form input:focus,
.field input:focus,
.field select:focus,
.field textarea:focus {
  border-color: var(--accent);
}

.cw-send,
.btn-primary {
  background: var(--accent);
  color: #fff;
}

.cw-send {
  border: none;
  padding: 9px 14px;
  border-radius: 8px;
  font-weight: 600;
}

.admin {
  display: flex;
  height: calc(100vh - 52px);
}

.sidebar {
  width: 200px;
  background: var(--bg2);
  border-right: 1px solid var(--border);
  padding: 20px 0;
  flex-shrink: 0;
}

.sidebar h3 {
  font-size: 11px;
  color: var(--muted);
  font-weight: 600;
  letter-spacing: 1.5px;
  text-transform: uppercase;
  padding: 0 16px;
  margin-bottom: 8px;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 16px;
  color: var(--muted);
  transition: 0.15s;
  border-left: 3px solid transparent;
  font-size: 13px;
}

.nav-item:hover,
.nav-item.active {
  color: var(--text);
}

.nav-item:hover {
  background: rgba(255, 255, 255, 0.03);
}

.nav-item.active {
  border-left-color: var(--accent);
  background: rgba(124, 108, 252, 0.08);
}

.ni {
  font-size: 16px;
}

.content {
  flex: 1;
  overflow-y: auto;
  padding: 28px;
}

.panel {
  display: none;
}

.panel.active {
  display: block;
}

.page-title {
  font-size: 18px;
  font-weight: 700;
  margin-bottom: 6px;
}

.page-sub {
  color: var(--muted);
  font-size: 13px;
  margin-bottom: 24px;
}

.stat-row {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 16px;
  margin-bottom: 28px;
}

.stat-card,
.chart-card,
.qa-section,
.sess-list,
.sess-detail,
.form-group,
.doc-item {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--r);
}

.stat-card {
  padding: 20px;
}

.sc-val {
  font-size: 28px;
  font-weight: 800;
  color: var(--accent2);
}

.sc-green {
  color: var(--green);
}

.sc-yellow {
  color: var(--yellow);
}

.sc-label {
  font-size: 12px;
  color: var(--muted);
  margin-top: 4px;
}

.sc-change {
  font-size: 11px;
  color: var(--green);
  margin-top: 8px;
}

.charts-row {
  display: grid;
  grid-template-columns: 2fr 1fr;
  gap: 16px;
  margin-bottom: 28px;
}

.span-2 {
  grid-column: 1 / -1;
}

.chart-card {
  padding: 20px;
}

.chart-card h4,
.qa-section h4 {
  font-size: 13px;
  font-weight: 600;
  margin-bottom: 16px;
  color: var(--muted);
}

svg text {
  fill: var(--muted);
}

.tbl {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}

.tbl th {
  text-align: left;
  padding: 10px 12px;
  color: var(--muted);
  font-weight: 600;
  border-bottom: 1px solid var(--border);
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.tbl td {
  padding: 11px 12px;
  border-bottom: 1px solid rgba(42, 42, 69, 0.5);
}

.tbl tr:hover td {
  background: rgba(124, 108, 252, 0.04);
}

.badge {
  display: inline-block;
  padding: 3px 10px;
  border-radius: 20px;
  font-size: 11px;
  font-weight: 600;
}

.badge.ai {
  background: rgba(124, 108, 252, 0.15);
  color: var(--accent2);
}

.badge.human {
  background: rgba(251, 191, 36, 0.15);
  color: var(--yellow);
}

.badge.done {
  background: rgba(74, 222, 128, 0.15);
  color: var(--green);
}

.toolbar {
  display: flex;
  gap: 12px;
  margin-bottom: 20px;
  align-items: center;
}

.toolbar input {
  flex: 1;
  background: var(--card);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 9px 14px;
  border-radius: 8px;
}

.btn {
  padding: 9px 18px;
  border-radius: 8px;
  border: none;
  font-weight: 600;
  transition: 0.15s;
}

.btn:hover {
  opacity: 0.9;
}

.btn-ghost {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text);
}

.btn-sm {
  padding: 5px 12px;
  font-size: 12px;
}

.btn-danger {
  background: rgba(248, 113, 113, 0.15);
  color: var(--red);
  border: 1px solid rgba(248, 113, 113, 0.2);
}

.doc-list,
.qa-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.doc-list {
  margin-bottom: 28px;
}

.doc-item {
  padding: 14px 16px;
  display: flex;
  align-items: center;
  gap: 12px;
}

.doc-icon {
  font-size: 22px;
  flex-shrink: 0;
}

.doc-info {
  flex: 1;
}

.doc-name {
  font-weight: 600;
  font-size: 13px;
}

.doc-meta {
  color: var(--muted);
  font-size: 12px;
  margin-top: 2px;
}

.qa-section {
  padding: 20px;
}

.qa-form {
  display: grid;
  grid-template-columns: 1fr 1fr auto;
  gap: 10px;
  margin-bottom: 16px;
}

.qa-form input,
.field input,
.field select,
.field textarea {
  background: var(--bg3);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 9px 12px;
  border-radius: 8px;
}

.qa-item {
  background: var(--bg3);
  border-radius: 8px;
  padding: 10px 14px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  font-size: 13px;
}

.qa-item .q {
  color: var(--accent2);
  font-weight: 600;
  flex: 1;
}

.qa-item .a {
  color: var(--muted);
  flex: 2;
}

.session-layout {
  display: grid;
  grid-template-columns: 280px 1fr;
  gap: 16px;
  height: calc(100vh - 180px);
}

.sess-list {
  overflow-y: auto;
}

.sess-item {
  padding: 14px 16px;
  border-bottom: 1px solid rgba(42, 42, 69, 0.5);
  transition: 0.15s;
}

.sess-item:hover,
.sess-item.active {
  background: rgba(124, 108, 252, 0.08);
}

.si-name {
  font-weight: 600;
  font-size: 13px;
  display: flex;
  justify-content: space-between;
  gap: 8px;
}

.si-last {
  color: var(--muted);
  font-size: 12px;
  margin-top: 3px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.sess-time {
  font-size: 11px;
  color: var(--muted);
  margin-top: 3px;
}

.sess-detail {
  display: flex;
  flex-direction: column;
}

.sd-head {
  padding: 14px 16px;
  border-bottom: 1px solid var(--border);
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.sd-msgs {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.sd-foot {
  padding: 12px 16px;
  border-top: 1px solid var(--border);
  display: flex;
  justify-content: flex-end;
}

.settings-form {
  display: flex;
  flex-direction: column;
  gap: 20px;
  max-width: 600px;
}

.form-group {
  padding: 20px;
}

.form-group h4 {
  font-size: 13px;
  font-weight: 700;
  margin-bottom: 16px;
  color: var(--accent2);
}

.field {
  margin-bottom: 14px;
}

.field label {
  display: block;
  font-size: 12px;
  color: var(--muted);
  margin-bottom: 6px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.field textarea {
  resize: vertical;
  min-height: 72px;
}

.field-inline-value {
  color: var(--accent2);
  margin-left: 8px;
}

.toggle-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.toggle {
  position: relative;
  width: 44px;
  height: 24px;
}

.toggle input {
  opacity: 0;
  width: 0;
  height: 0;
}

.toggle-slider {
  position: absolute;
  inset: 0;
  background: var(--border);
  border-radius: 12px;
  cursor: pointer;
  transition: 0.2s;
}

.toggle-slider::before {
  content: "";
  position: absolute;
  height: 18px;
  width: 18px;
  left: 3px;
  bottom: 3px;
  background: #fff;
  border-radius: 50%;
  transition: 0.2s;
}

.toggle input:checked + .toggle-slider {
  background: var(--accent);
}

.toggle input:checked + .toggle-slider::before {
  transform: translateX(20px);
}

.save-btn-row {
  display: flex;
  align-items: center;
  gap: 12px;
}

.save-ok {
  color: var(--green);
  font-size: 13px;
  font-weight: 600;
  display: none;
}

.empty-state {
  color: var(--muted);
  font-size: 13px;
  padding: 18px;
  border: 1px dashed var(--border);
  border-radius: var(--r);
  text-align: center;
}

.hidden-input {
  display: none;
}

@media (max-width: 960px) {
  .stat-row,
  .charts-row {
    grid-template-columns: 1fr 1fr;
  }

  .span-2 {
    grid-column: auto;
  }
}

@media (max-width: 768px) {
  .top-bar {
    padding: 0 12px;
  }

  .logo {
    margin-right: 12px;
  }

  .tab-btn {
    padding: 14px 12px;
  }

  .demo-site,
  .content {
    padding: 16px;
  }

  .demo-nav {
    flex-direction: column;
    gap: 12px;
  }

  .demo-hero {
    padding: 28px 20px;
  }

  .demo-hero h1 {
    font-size: 22px;
  }

  .chat-window {
    right: 12px;
    left: 12px;
    bottom: 84px;
    width: auto;
    height: 60vh;
  }

  .chat-bubble {
    right: 12px;
    bottom: 16px;
  }

  .admin {
    flex-direction: column;
    height: auto;
  }

  .sidebar {
    width: 100%;
    border-right: none;
    border-bottom: 1px solid var(--border);
    padding: 12px 0;
  }

  .stat-row,
  .charts-row,
  .session-layout,
  .qa-form {
    grid-template-columns: 1fr;
  }

  .session-layout {
    height: auto;
  }

  .sess-list {
    max-height: 280px;
  }

  .tbl {
    display: block;
    overflow-x: auto;
  }
}
