:root {
  --bg: #f6f9f7;
  --panel: #ffffff;
  --panel-soft: #f9fcfb;
  --panel-soft-2: #edf7f1;
  --topbar-bg: rgba(246,249,247,0.92);
  --avatar-a: #edf7f1;
  --avatar-b: #d6f0df;
  --highlight-bg: #fff8dc;
  --highlight-ink: #876100;
  --notice-bg: #e7f8ef;
  --notice-ink: #137548;
  --th-ink: #4d5b56;
  --sidebar: #ffffff;
  --sidebar-active: #e6f6ec;
  --ink: #17231d;
  --muted: #7d8d85;
  --line: #e9f0eb;
  --blue: #10b461;
  --blue-soft: #e8f7ef;
  --green: #10b461;
  --orange: #ff7a30;
  --red: #ef4444;
  --shadow: 0 18px 48px rgba(33, 59, 44, 0.08);
  font-family: "Segoe UI", Tahoma, sans-serif;
}

* { box-sizing: border-box; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  transition: background-color 0.2s ease, color 0.2s ease;
}
body[data-theme="dark"] {
  --bg: #1c1c1c;
  --panel: #242424;
  --panel-soft: #202020;
  --panel-soft-2: #2a2a2a;
  --topbar-bg: rgba(35,35,35,0.96);
  --avatar-a: #2f2f2f;
  --avatar-b: #13442b;
  --highlight-bg: #31280f;
  --highlight-ink: #f2cf68;
  --notice-bg: #11231b;
  --notice-ink: #7ce7af;
  --th-ink: #d2d8d5;
  --sidebar: #212121;
  --sidebar-active: #123726;
  --ink: #f7f7f7;
  --muted: #9aa29d;
  --line: #2d2d2d;
  --blue: #0bb362;
  --blue-soft: #133224;
  --green: #0bb362;
  --shadow: 0 20px 48px rgba(0, 0, 0, 0.35);
}
.auth-page { min-height: 100vh; display: grid; place-items: center; padding: 24px; }
.auth-card, .panel, .stat-card, .modal-card { background: var(--panel); border: 1px solid var(--line); border-radius: 24px; box-shadow: var(--shadow); }
.auth-card { width: min(480px, 100%); padding: 32px; }
.soft-separator { border: 0; border-top: 1px solid var(--line); margin: 20px 0; }
.eyebrow { text-transform: uppercase; letter-spacing: 0.16em; color: var(--blue); font-size: 12px; font-weight: 700; }

input, textarea, select, button {
  width: 100%;
  border-radius: 10px;
  border: 1px solid var(--line);
  padding: 12px 14px;
  font: inherit;
  background: var(--panel);
  color: var(--ink);
}

textarea { min-height: 100px; resize: vertical; }
button { background: var(--blue); color: #fff; cursor: pointer; font-weight: 600; border: none; }
.ghost-btn { background: var(--panel-soft-2); color: var(--ink); }
.full { width: 100%; }
.stack { display: grid; gap: 12px; }
.actions { display: flex; gap: 10px; align-items: center; }
.actions button { width: auto; }
.label, .muted { color: var(--muted); }
.hidden { display: none !important; }

.admin-body { min-height: 100vh; }
.app-shell { display: grid; grid-template-columns: 212px 1fr; min-height: 100vh; }
body.sidebar-open {
  overflow: hidden;
}
.app-sidebar {
  background: linear-gradient(180deg, #ffffff 0%, #f8fbf9 100%);
  color: var(--ink);
  padding: 18px 10px;
  display: flex;
  flex-direction: column;
  gap: 18px;
  border-right: 1px solid var(--line);
}
body[data-theme="dark"] .app-sidebar {
  background: linear-gradient(180deg, #212121 0%, #1f1f1f 100%);
}
.sidebar-toggle {
  display: none;
  width: 42px;
  min-width: 42px;
  height: 42px;
  padding: 0;
  border-radius: 12px;
  background: var(--panel-soft-2);
  color: var(--ink);
  font-size: 22px;
  line-height: 1;
  align-items: center;
  justify-content: center;
}
.sidebar-close {
  margin-left: auto;
  background: var(--panel-soft-2);
  color: var(--ink);
}
.sidebar-overlay {
  display: none;
}
.brand { display: flex; align-items: center; gap: 12px; padding: 4px 8px 16px; border-bottom: 1px solid var(--line); }
.brand-mark {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  background: conic-gradient(from 90deg, #f7c948, #10b461, #ffd977);
  color: #0f2516;
  font-weight: 800;
}
.brand small { display: block; color: var(--muted); margin-top: 2px; }
.menu { display: grid; gap: 6px; }
.menu-item {
  text-align: left;
  padding: 12px 14px;
  background: transparent;
  color: var(--muted);
  border-radius: 10px;
  font-weight: 700;
}
.menu-item.active, .menu-item:hover { background: var(--sidebar-active); color: var(--green); }
.sidebar-device {
  margin-top: auto;
  padding: 14px;
  background: var(--panel-soft-2);
  border-radius: 14px;
}
body[data-theme="dark"] .menu-item.active,
body[data-theme="dark"] .menu-item:hover {
  color: #87f0b4;
}

.app-main {
  padding: 0 18px 24px;
  min-width: 0;
  overflow-x: hidden;
}
.topbar {
  position: sticky;
  top: 0;
  z-index: 5;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 20px;
  background: var(--topbar-bg);
  backdrop-filter: blur(10px);
  padding: 14px 0 22px;
  border-bottom: 1px solid rgba(0,0,0,0.02);
}
.topbar-left {
  display: flex;
  align-items: center;
  gap: 12px;
  flex: 1;
  min-width: 0;
}
.searchbar { max-width: 420px; background: var(--panel); border-radius: 999px; border-color: var(--line); box-shadow: inset 0 1px 0 rgba(16, 180, 97, 0.02); }
.topbar-right { display: flex; align-items: center; gap: 14px; }
.theme-btn { width: auto; min-width: 118px; }
.lang { color: var(--muted); }
.avatar {
  width: 38px;
  height: 38px;
  display: grid;
  place-items: center;
  background: linear-gradient(135deg, var(--avatar-a), var(--avatar-b));
  border-radius: 50%;
  font-weight: 700;
}
body[data-theme="dark"] .searchbar {
  background: #171717;
  box-shadow: none;
}

.page-section {
  display: none;
  gap: 18px;
  min-width: 0;
}
.page-section.active { display: grid; }
.stat-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 18px;
  min-width: 0;
}
.stat-card { padding: 22px 22px; }
.stat-card,
.panel {
  width: 100%;
}
.stat-card h3 { margin: 0 0 8px; font-size: 15px; color: var(--muted); }
.stat-card strong { font-size: 34px; display: block; margin-bottom: 6px; }
.stat-card span { color: var(--muted); font-size: 13px; }

.panel {
  padding: 18px;
  min-width: 0;
  overflow: hidden;
}
.panel-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 18px; margin-bottom: 14px; }
.panel-head.compact { align-items: center; }
.panel-head h2, .panel h2, .panel h3 { margin: 0; }
.panel-head p { margin: 6px 0 0; color: var(--muted); }
.table-wrap {
  overflow-x: auto;
  overflow-y: hidden;
  max-width: 100%;
}
table { width: 100%; border-collapse: collapse; min-width: 760px; }
th, td { padding: 12px 10px; border-bottom: 1px solid var(--line); text-align: left; font-size: 14px; }
th { color: var(--th-ink); font-weight: 700; }
.badge {
  display: inline-flex;
  align-items: center;
  padding: 4px 10px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 700;
}
.badge.success { background: #e7f8ef; color: #0d8d44; }
.badge.danger { background: #ffe2e2; color: #cb2c2c; }
.badge.warning { background: #fff1cf; color: #c98600; }
.badge.muted { background: #eef1f6; color: #617086; }
body[data-theme="dark"] .badge.success { background: #113523; color: #7cf0af; }
body[data-theme="dark"] .badge.warning { background: #3b2d10; color: #f3cc63; }
body[data-theme="dark"] .badge.muted { background: #303030; color: #d0d5d2; }
.mini-btn { width: auto; padding: 8px 12px; font-size: 12px; }
.danger-btn { background: var(--red); color: #fff; }

.split-panel, .two-col {
  display: grid;
  grid-template-columns: minmax(280px, 340px) minmax(0, 1fr);
  gap: 18px;
  min-width: 0;
}
.pair-box, .info-box { padding: 8px; }
.highlight-box {
  margin-top: 12px;
  padding: 16px;
  border-radius: 14px;
  background: var(--highlight-bg);
  color: var(--highlight-ink);
  font-weight: 700;
  text-align: center;
  letter-spacing: 0.08em;
}
.output {
  background: #1c2434;
  color: #dff4ff;
  padding: 16px;
  border-radius: 14px;
  min-height: 140px;
  overflow: auto;
  max-width: 100%;
  white-space: pre-wrap;
  word-break: break-word;
  overflow-wrap: anywhere;
}
body[data-theme="dark"] .output {
  background: #171717;
  color: #dbf7e7;
}
.output.slim { min-height: 240px; }
.qr-image {
  margin-top: 16px;
  width: 220px;
  max-width: 100%;
  display: none;
  border: 1px solid var(--line);
  border-radius: 14px;
}

.list-panel {
  display: grid;
  gap: 10px;
  max-height: 520px;
  overflow: auto;
  padding: 8px;
  background: var(--panel-soft);
  border-radius: 16px;
  border: 1px solid var(--line);
}
.list-item {
  display: grid;
  gap: 4px;
  padding: 12px;
  background: var(--panel);
  border-radius: 14px;
  border: 1px solid var(--line);
}
.sync-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 18px;
  min-width: 0;
}
.sync-list {
  min-height: 260px;
}
.mono-text {
  font-family: Consolas, "Courier New", monospace;
  word-break: break-all;
  overflow-wrap: anywhere;
}
.wrap-actions {
  flex-wrap: wrap;
}
.empty-state { padding: 18px; color: var(--muted); }
.card-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); gap: 16px; }
#featureCards.feature-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 18px;
  align-items: stretch;
}
.feature-card {
  display: grid;
  grid-template-columns: 56px minmax(0, 1fr);
  gap: 14px;
  padding: 18px;
  border: 1px solid var(--line);
  border-radius: 20px;
  background: linear-gradient(180deg, var(--panel) 0%, var(--panel-soft) 100%);
}
.feature-icon {
  width: 56px;
  height: 56px;
  display: grid;
  place-items: center;
  border-radius: 18px;
  background: var(--blue-soft);
  color: var(--blue);
  font-weight: 800;
  font-size: 24px;
}
.feature-body h3 {
  font-size: 19px;
  line-height: 1.25;
}
.feature-category {
  display: inline-flex;
  margin-bottom: 8px;
  padding: 4px 10px;
  border-radius: 999px;
  background: var(--panel-soft-2);
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}
.feature-body p {
  margin: 6px 0 0;
  color: var(--muted);
  line-height: 1.6;
}
.feature-card-head {
  margin-bottom: 10px;
}
.plugin-card { padding: 16px; border: 1px solid var(--line); border-radius: 16px; background: var(--panel); }
.notice { margin-bottom: 16px; padding: 16px; border-radius: 14px; background: var(--notice-bg); color: var(--notice-ink); }
.import-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 12px;
}
.import-result {
  margin-top: 12px;
  padding: 12px 14px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: var(--panel-soft);
}
.compact-actions {
  margin-top: 6px;
}

.wizard-steps {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 16px;
  margin: 18px 0 20px;
}
.wizard-step {
    padding: 16px;
    border-radius: 16px;
    background: var(--panel-soft);
    text-align: center;
    color: #7553d8;
    font-weight: 700;
    border: 1px solid var(--line);
    cursor: pointer;
}
.wizard-step span { display: block; margin-top: 4px; font-size: 13px; color: var(--muted); font-weight: 500; }
.wizard-step.active { background: #edf8ea; color: #2f9a34; }
.campaign-step-pane { display: grid; gap: 12px; }

.docs-layout { display: grid; grid-template-columns: 260px 1fr; gap: 18px; }
.docs-nav { display: grid; gap: 8px; align-content: start; }
.docs-link { text-align: left; background: var(--panel-soft); color: var(--ink); }
.docs-content code, .docs-content pre { background: #1c2434; color: #dff4ff; border-radius: 14px; display: block; padding: 16px; overflow: auto; }
.docs-content p code { display: inline-block; padding: 3px 8px; border-radius: 8px; }
body[data-theme="dark"] .docs-content code,
body[data-theme="dark"] .docs-content pre {
  background: #171717;
  color: #e8fff0;
}
.docs-code-block {
  margin-top: 12px;
  min-width: 0;
}
.docs-code-toolbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  margin-bottom: 8px;
  flex-wrap: wrap;
}
.docs-code-label {
  color: var(--muted);
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
}
.docs-copy-btn {
  margin-left: auto;
}
.docs-code-block pre,
.docs-code-block code {
  width: 100%;
  max-width: 100%;
  white-space: pre-wrap;
  word-break: break-word;
  overflow-wrap: anywhere;
  overflow-x: auto;
}
.webchat-layout {
  display: grid;
  grid-template-columns: minmax(280px, 360px) minmax(0, 1fr);
  gap: 18px;
  min-height: 620px;
}
.webchat-sidebar,
.webchat-main {
  border: 1px solid var(--line);
  border-radius: 18px;
  background: var(--panel-soft);
  min-width: 0;
}
.webchat-sidebar {
  padding: 14px;
  display: grid;
  gap: 14px;
  align-content: start;
}
.conversation-list {
  display: grid;
  gap: 10px;
  max-height: 520px;
  overflow: auto;
}
.conversation-item {
  padding: 12px;
  border-radius: 14px;
  background: var(--panel);
  border: 1px solid var(--line);
  cursor: pointer;
}
.conversation-item.active {
  border-color: var(--blue);
  box-shadow: inset 0 0 0 1px var(--blue);
}
.conversation-top,
.conversation-bottom {
  display: flex;
  justify-content: space-between;
  gap: 10px;
}
.conversation-preview {
  color: var(--muted);
  font-size: 13px;
  margin-top: 6px;
}
.webchat-main {
  display: grid;
  grid-template-rows: auto 1fr auto;
  overflow: hidden;
}
.webchat-header {
  padding: 16px 18px;
  border-bottom: 1px solid var(--line);
  background: var(--panel);
}
.chat-message-list {
  padding: 18px;
  display: grid;
  gap: 12px;
  overflow: auto;
  background: linear-gradient(180deg, var(--panel) 0%, var(--panel-soft) 100%);
}
.chat-bubble {
  max-width: min(82%, 620px);
  padding: 12px 14px;
  border-radius: 16px;
  background: var(--panel);
  border: 1px solid var(--line);
}
.chat-bubble.out {
  margin-left: auto;
  background: var(--blue);
  color: #fff;
  border-color: transparent;
}
.chat-meta {
  margin-top: 6px;
  font-size: 12px;
  color: var(--muted);
}
.chat-bubble.out .chat-meta {
  color: rgba(255,255,255,0.82);
}
body[data-theme="dark"] .chat-bubble.out {
  color: #ffffff;
}
.webchat-composer {
  position: relative;
  padding: 16px 18px 18px;
  border-top: 1px solid var(--line);
  background: var(--panel);
  display: grid;
  gap: 12px;
}
.template-suggestions {
  display: grid;
  gap: 8px;
  padding: 10px;
  border: 1px solid var(--line);
  background: var(--panel-soft);
  border-radius: 14px;
}
.helper-text {
  margin: 0;
  padding: 10px 14px;
  border-radius: 12px;
  background: var(--panel-soft);
  color: var(--text-muted);
  border: 1px solid var(--line);
}
.template-suggestion {
  text-align: left;
  padding: 10px 12px;
  border-radius: 12px;
  background: var(--panel);
  border: 1px solid var(--line);
  color: var(--ink);
}
.template-suggestion strong {
  display: block;
  margin-bottom: 4px;
}
.widget-manager {
  align-items: start;
}
.site-widget {
  position: fixed;
  right: 22px;
  bottom: 22px;
  z-index: 40;
}
.site-widget-toggle {
  width: 64px;
  height: 64px;
  border-radius: 999px;
  border: none;
  background: linear-gradient(135deg, #16a34a, #22c55e);
  color: #fff;
  font-weight: 800;
  box-shadow: 0 20px 45px rgba(22, 163, 74, 0.28);
}
.site-widget-panel {
  position: absolute;
  right: 0;
  bottom: 78px;
  width: min(360px, calc(100vw - 24px));
  border-radius: 24px;
  overflow: hidden;
  border: 1px solid var(--line);
  background:
    radial-gradient(circle at top right, rgba(255,255,255,0.28), transparent 28%),
    linear-gradient(180deg, var(--panel) 0%, var(--panel-soft) 100%);
  box-shadow: 0 28px 70px rgba(15, 23, 42, 0.24);
}
.site-widget-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  padding: 18px 18px 16px;
  background:
    radial-gradient(circle at top right, rgba(255,255,255,0.2), transparent 22%),
    linear-gradient(135deg, #16a34a, #22c55e);
  color: #fff;
}
.site-widget-head strong,
.site-widget-head small {
  display: block;
  color: #fff;
}
.site-widget-head strong {
  font-size: 18px;
  line-height: 1.2;
}
.site-widget-head small {
  margin-top: 4px;
  font-size: 13px;
  opacity: 0.94;
}
.site-widget-close {
  width: 38px;
  min-width: 38px;
  height: 38px;
  border: none;
  border-radius: 999px;
  padding: 0;
  display: inline-grid;
  place-items: center;
  align-self: center;
  background: rgba(255,255,255,0.18);
  color: #fff;
  font-size: 24px;
  line-height: 1;
  box-shadow: inset 0 1px 0 rgba(255,255,255,0.16);
}
.site-widget-close:hover {
  background: rgba(255,255,255,0.28);
}
.site-widget-body {
  display: grid;
  gap: 12px;
  padding: 18px;
}
.site-widget-body input,
.site-widget-body textarea {
  border-radius: 16px;
  border: 1px solid var(--line);
  background: rgba(255,255,255,0.82);
  box-shadow: inset 0 1px 0 rgba(255,255,255,0.55);
}
.site-widget-body textarea {
  min-height: 120px;
}
.site-widget-body button {
  min-height: 54px;
  border-radius: 16px;
  font-size: 16px;
  font-weight: 800;
  background: linear-gradient(135deg, #16a34a, #20c05c);
  box-shadow: 0 18px 30px rgba(22, 163, 74, 0.2);
}
body[data-theme="dark"] .site-widget-panel {
  border-color: rgba(255,255,255,0.08);
  background:
    radial-gradient(circle at top right, rgba(255,255,255,0.08), transparent 26%),
    linear-gradient(180deg, #181818 0%, #111111 100%);
}
body[data-theme="dark"] .site-widget-body input,
body[data-theme="dark"] .site-widget-body textarea {
  background: rgba(255,255,255,0.04);
  border-color: rgba(255,255,255,0.08);
  color: #f8fafc;
  box-shadow: none;
}

.modal { border: none; background: transparent; }
.modal::backdrop { background: rgba(17, 24, 39, 0.48); }
.modal-card { width: min(640px, calc(100vw - 28px)); padding: 18px; }
.modal-head { display: flex; justify-content: space-between; align-items: center; }
.modal-close {
  width: 40px;
  min-width: 40px;
  height: 40px;
  padding: 0;
  border-radius: 999px;
  background: var(--panel-soft-2);
  color: var(--ink);
  font-size: 26px;
  line-height: 1;
  display: inline-grid;
  place-items: center;
  border: 1px solid var(--line);
}
.modal-close:hover {
  background: var(--panel-soft);
}
.switch-row { display: flex; align-items: center; gap: 10px; color: var(--ink); }
.switch-row input { width: auto; }
.table-switch {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  white-space: nowrap;
}
.table-switch input {
  width: auto;
  margin: 0;
}

@media (max-width: 1100px) {
  .stat-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .split-panel, .two-col, .docs-layout, .sync-grid, .webchat-layout { grid-template-columns: 1fr; }
  .topbar-right { flex-wrap: wrap; justify-content: flex-end; }
  .import-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .feature-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); }
}

@media (max-width: 980px) {
  .app-shell { grid-template-columns: 1fr; }
  .app-sidebar {
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    width: min(290px, 82vw);
    z-index: 30;
    padding-bottom: 14px;
    transform: translateX(-102%);
    transition: transform 0.22s ease;
    overflow-y: auto;
    box-shadow: 0 22px 60px rgba(0, 0, 0, 0.4);
  }
  body.sidebar-open .app-sidebar { transform: translateX(0); }
  .sidebar-toggle { display: inline-flex; }
  .sidebar-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.45);
    z-index: 20;
  }
  body.sidebar-open .sidebar-overlay { display: block; }
  .menu {
    display: grid;
    overflow-x: visible;
    padding-bottom: 0;
  }
  .menu-item {
    white-space: normal;
    min-width: 0;
  }
  .stat-grid { grid-template-columns: 1fr; }
  .topbar {
    flex-direction: column;
    align-items: stretch;
    gap: 12px;
    padding: 10px 0 14px;
  }
  .topbar-left { width: 100%; }
  .searchbar {
    max-width: 100%;
    min-width: 0;
  }
  .topbar-right {
    justify-content: space-between;
    width: 100%;
  }
  .panel-head { flex-direction: column; }
  .actions { flex-wrap: wrap; }
  .modal-card { width: min(100vw - 18px, 640px); }
  .import-grid { grid-template-columns: 1fr; }
  .feature-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

@media (max-width: 560px) {
  .app-main { padding: 0 10px 18px; }
  .auth-card { padding: 22px; }
  .panel, .stat-card, .modal-card { border-radius: 18px; }
  .panel, .stat-card {
    padding: 16px 14px;
  }
  table { min-width: 640px; }
  .searchbar { max-width: 100%; }
  .sidebar-device { margin-top: 0; }
  .topbar-left,
  .topbar-right {
    gap: 10px;
  }
  .theme-btn {
    min-width: 0;
    padding-inline: 12px;
  }
  .site-widget {
    right: 12px;
    bottom: 12px;
  }
  .lang {
    display: none;
  }
  .avatar {
    width: 34px;
    height: 34px;
    font-size: 13px;
  }
  .stat-card strong {
    font-size: 28px;
  }
  .feature-grid {
    grid-template-columns: 1fr;
  }
  .card-grid {
    grid-template-columns: 1fr;
  }
  .feature-grid {
    grid-template-columns: 1fr;
  }
  .feature-card {
    grid-template-columns: 1fr;
  }
  .wizard-steps {
    grid-template-columns: 1fr;
  }
  .chat-bubble {
    max-width: 100%;
  }
  .docs-code-toolbar {
    align-items: stretch;
  }
  .docs-copy-btn {
    margin-left: 0;
    width: 100%;
  }
}
