/* CSG brand: deep purple #2F1C73, logo purple #7B4FD6, gold #E2B94A, Manrope. */
:root {
  --brand-deep: #2F1C73;
  --brand-purple: #7B4FD6;
  --brand-gold: #E2B94A;
  --bg: #f6f5fb;
  --surface: #ffffff;
  --text: #1c1638;
  --muted: #645f7a;
  --border: #e4e1ef;
  --accent: #5b34c4;
  --accent-text: #ffffff;
  --danger: #c93636;
  --ok: #1f8a4c;
  --warn: #a8690f;
  --chip: #f0edf9;
  --shadow: 0 1px 2px rgba(47, 28, 115, 0.06), 0 1px 3px rgba(47, 28, 115, 0.08);
  --radius: 12px;
  --sidebar-w: 248px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #110d22;
    --surface: #1a1532;
    --text: #ebe8f5;
    --muted: #a29cbc;
    --border: #2e2750;
    --accent: #a98bf0;
    --accent-text: #160f33;
    --danger: #ff7a7a;
    --ok: #4cc38a;
    --warn: #f0b44c;
    --chip: #262046;
    --shadow: none;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 14px/1.5 Manrope, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
a { color: var(--accent); }
h1 { font-size: 24px; margin: 0; font-weight: 800; letter-spacing: -0.01em; }
h2 { font-size: 16px; margin: 0 0 12px; font-weight: 700; }
.muted { color: var(--muted); }
.small { font-size: 12px; }

/* ---------- Layout: left sidebar + content ---------- */
.layout { display: flex; min-height: 100vh; }
.main-col { flex: 1; min-width: 0; }
.sidebar {
  position: sticky; top: 0; height: 100vh; width: var(--sidebar-w); flex: none;
  display: flex; flex-direction: column; gap: 8px; padding: 18px 14px;
  background: linear-gradient(180deg, #2F1C73 0%, #24155b 60%, #1b1046 100%);
  color: #ece7ff; overflow-y: auto; z-index: 20;
}
.brand { display: flex; align-items: center; gap: 10px; text-decoration: none; color: #fff; padding: 4px 6px 16px; border-bottom: 1px solid rgba(255, 255, 255, 0.12); margin-bottom: 8px; }
.brand-logo { display: inline-flex; align-items: center; justify-content: center; background: #fff; border-radius: 10px; padding: 6px 8px; box-shadow: 0 2px 8px rgba(0, 0, 0, 0.2); }
.brand-logo img { display: block; height: 26px; width: auto; }
.brand-text { display: flex; flex-direction: column; line-height: 1.15; }
.brand-name { font-weight: 800; font-size: 16px; letter-spacing: -0.01em; }
.brand-sub { font-size: 11px; color: #c9bff0; }

.sidenav { display: flex; flex-direction: column; gap: 2px; flex: 1; }
.sidenav a {
  display: flex; align-items: center; gap: 10px; padding: 9px 12px; border-radius: 10px;
  color: #d9d1fb; text-decoration: none; font-weight: 600; position: relative;
}
.sidenav a svg { width: 18px; height: 18px; flex: none; opacity: 0.9; }
.sidenav a:hover { background: rgba(255, 255, 255, 0.08); color: #fff; }
.sidenav a.active { background: rgba(255, 255, 255, 0.14); color: #fff; }
.sidenav a.active::before { content: ""; position: absolute; left: -14px; top: 8px; bottom: 8px; width: 4px; border-radius: 0 4px 4px 0; background: var(--brand-gold); }

.sidebar-foot { border-top: 1px solid rgba(255, 255, 255, 0.12); padding-top: 12px; display: flex; flex-direction: column; gap: 8px; font-size: 13px; }
.user-card { display: flex; align-items: center; gap: 10px; }
.avatar { width: 34px; height: 34px; border-radius: 50%; flex: none; display: grid; place-items: center; font-weight: 800; color: var(--brand-deep); background: var(--brand-gold); }
.user-meta { min-width: 0; display: flex; flex-direction: column; }
.user-name { font-weight: 700; color: #fff; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.user-email { font-size: 11px; color: #c9bff0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sidebar-foot .chip.role { align-self: flex-start; }
.signout { color: #c9bff0; font-size: 12px; text-decoration: none; }
.signout:hover { color: #fff; text-decoration: underline; }

.mobilebar { display: none; }
.scrim { position: fixed; inset: 0; background: rgba(10, 6, 30, 0.45); z-index: 15; }

@media (max-width: 900px) {
  .sidebar { position: fixed; left: 0; top: 0; transform: translateX(-100%); transition: transform 0.2s ease; box-shadow: 0 0 30px rgba(0, 0, 0, 0.3); }
  .sidebar.open { transform: none; }
  .mobilebar {
    display: flex; align-items: center; gap: 10px; padding: 10px 16px; position: sticky; top: 0; z-index: 10;
    background: var(--brand-deep); color: #fff;
  }
  .mobilebar img { background: #fff; border-radius: 6px; padding: 3px 5px; height: 26px; }
  .mobile-title { font-weight: 800; }
  .menu-btn { background: none; border: 0; color: #fff; padding: 4px; cursor: pointer; display: grid; place-items: center; border-radius: 8px; }
  .menu-btn:focus-visible { outline: 2px solid var(--brand-gold); }
}
@media (prefers-reduced-motion: reduce) { .sidebar { transition: none; } }

.chip.role { font-weight: 700; }
.role-owner { color: #6d28d9; }
.role-admin { color: var(--accent); }
.role-editor { color: var(--ok); }
.role-viewer { color: var(--muted); }
.role-sales { color: var(--warn); }
.sidebar .chip.role { background: rgba(255, 255, 255, 0.14); color: var(--brand-gold); }
.dev-switch { display: flex; gap: 4px; align-items: center; border: 1px dashed var(--brand-gold); border-radius: 8px; padding: 4px 6px; flex-wrap: wrap; }
.dev-switch .dev-label { font-size: 10px; font-weight: 800; color: var(--brand-gold); letter-spacing: 0.06em; }
.dev-switch .dev-as { flex: 1; min-width: 0; padding: 3px 6px; font-size: 12px; }
fieldset.plain { border: 0; padding: 0; margin: 0; min-width: 0; }
fieldset.plain:disabled { opacity: 0.6; }
.check-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 6px; margin-top: 6px; }
label.check { display: flex; align-items: center; gap: 6px; font-weight: 400; margin: 0; }
.filter-input { margin-bottom: 12px; }

.container { max-width: 1160px; margin: 0 auto; padding: 28px 32px; }
.page-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 20px; flex-wrap: wrap; }
.crumbs { font-size: 13px; color: var(--muted); margin-bottom: 4px; }
.crumbs a { color: var(--muted); }

.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); padding: 20px; margin-bottom: 16px; }
.grid { display: grid; gap: 16px; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); }
.bot-card { display: flex; flex-direction: column; gap: 10px; text-decoration: none; color: inherit; }
.bot-card:hover { border-color: var(--accent); }
.bot-card .swatch { width: 28px; height: 28px; border-radius: 50%; flex: none; }
.bot-card .row { display: flex; gap: 10px; align-items: center; }
.stats { display: flex; gap: 18px; flex-wrap: wrap; }
.stat b { display: block; font-size: 16px; }
.stat span { color: var(--muted); font-size: 12px; }

.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--border); margin-bottom: 20px; overflow-x: auto; scrollbar-width: none; }
.tabs::-webkit-scrollbar { display: none; }
.tabs a { padding: 10px 14px; color: var(--muted); text-decoration: none; border-bottom: 2px solid transparent; white-space: nowrap; }
.tabs a.active { color: var(--text); border-bottom-color: var(--accent); font-weight: 600; }

.btn {
  display: inline-flex; align-items: center; gap: 6px; border: 1px solid var(--border); background: var(--surface);
  color: var(--text); border-radius: 8px; padding: 8px 14px; font: inherit; cursor: pointer; text-decoration: none;
}
.btn:hover { border-color: var(--accent); }
.btn.primary { background: linear-gradient(135deg, var(--brand-purple), var(--brand-deep)); border-color: transparent; color: #fff; font-weight: 700; }
.btn.primary:hover { filter: brightness(1.08); border-color: transparent; }
@media (prefers-color-scheme: dark) { .btn.primary { background: linear-gradient(135deg, #9b74ef, #6b45d6); } }
.btn.danger { color: var(--danger); }
.btn.small { padding: 4px 10px; font-size: 13px; }
.btn:disabled { opacity: 0.6; cursor: default; }
.actions { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.actions select, td select { width: auto; }

form .field { margin-bottom: 14px; }
label { display: block; font-weight: 600; margin-bottom: 4px; }
label > input, label > select, label > textarea { display: block; margin-top: 4px; font-weight: 400; }
.hint { color: var(--muted); font-size: 12px; margin-top: 3px; font-weight: 400; }
input[type=text], input[type=email], input[type=url], input[type=number], textarea, select {
  width: 100%; padding: 8px 10px; border: 1px solid var(--border); border-radius: 8px;
  background: var(--surface); color: var(--text); font: inherit;
}
textarea { min-height: 120px; resize: vertical; }
input[type=color] { width: 56px; height: 36px; border: 1px solid var(--border); border-radius: 8px; padding: 2px; background: var(--surface); }
.two { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
@media (max-width: 720px) { .two { grid-template-columns: 1fr; } .container { padding: 16px; } }

table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 10px 8px; border-bottom: 1px solid var(--border); vertical-align: top; }
th { font-size: 12px; color: var(--muted); font-weight: 600; text-transform: uppercase; letter-spacing: 0.03em; }
tr.clickable { cursor: pointer; }
tr.clickable:hover td { background: var(--chip); }
.table-wrap { overflow-x: auto; }

.chip { display: inline-block; padding: 2px 8px; border-radius: 999px; background: var(--chip); font-size: 12px; white-space: nowrap; }
.chip.ok { color: var(--ok); }
.chip.err { color: var(--danger); }
.chip.warn { color: var(--warn); }

.meter { height: 8px; background: var(--chip); border-radius: 999px; overflow: hidden; margin: 6px 0; }
.meter > div { height: 100%; background: var(--accent); }
.meter.over > div { background: var(--danger); }

.dropzone { border: 2px dashed var(--border); border-radius: var(--radius); padding: 24px; text-align: center; color: var(--muted); }
.dropzone.drag { border-color: var(--accent); color: var(--text); }

pre.code { background: var(--chip); padding: 12px; border-radius: 8px; overflow-x: auto; font-size: 13px; white-space: pre-wrap; word-break: break-all; }

.transcript { display: flex; flex-direction: column; gap: 8px; }
.msg { max-width: 80%; padding: 8px 12px; border-radius: 12px; white-space: pre-wrap; }
.msg.user { align-self: flex-end; background: var(--accent); color: var(--accent-text); }
.msg.assistant { align-self: flex-start; background: var(--chip); }
.msg .meta { display: block; font-size: 11px; opacity: 0.75; margin-top: 4px; }

.preview { position: relative; height: 380px; border: 1px solid var(--border); border-radius: var(--radius); background: repeating-linear-gradient(45deg, var(--bg), var(--bg) 10px, var(--surface) 10px, var(--surface) 20px); overflow: hidden; }
.preview { height: 470px; }
.preview .pv-win { position: absolute; bottom: 76px; width: 270px; background: #fff; color: #1b2132; border-radius: 14px; box-shadow: 0 8px 24px rgba(0,0,0,.2); overflow: hidden; font-size: 12.5px; font-family: system-ui, sans-serif; }
.preview .pv-head { color: #fff; padding: 10px 12px; font-weight: 700; display: flex; align-items: center; gap: 8px; }
.preview .pv-avatar img { width: 26px; height: 26px; border-radius: 50%; object-fit: cover; background: #fff; display: block; }
.preview .pv-dot { display: block; width: 8px; height: 8px; border-radius: 50%; background: #5ce08b; }
.preview .pv-body { padding: 10px 12px; background: #f5f7fb; display: flex; flex-direction: column; gap: 6px; }
.preview .pv-bubble { background: #fff; border: 1px solid #e3e7ef; border-radius: 10px; padding: 7px 10px; align-self: flex-start; max-width: 88%; }
.preview .pv-user { color: #fff; border-radius: 10px; padding: 7px 10px; align-self: flex-end; max-width: 80%; }
.preview .pv-link { text-decoration: underline; }
.preview .pv-input { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 8px 10px; border-top: 1px solid #e3e7ef; color: #8a93a6; }
.preview .pv-send { color: #fff; border-radius: 8px; width: 28px; height: 28px; display: grid; place-items: center; font-size: 12px; }
.preview .pv-foot { font-size: 10.5px; color: #7a8396; text-align: center; padding: 0 8px 8px; }
.preview .pv-btn { position: absolute; bottom: 16px; width: 52px; height: 52px; border-radius: 50%; box-shadow: 0 4px 12px rgba(0,0,0,.25); border: 3px solid transparent; overflow: hidden; }
.preview .pv-btn img { width: 100%; height: 100%; object-fit: cover; background: #fff; display: block; }
.custom-purpose { border-left: 3px solid var(--brand-purple); padding: 4px 0 4px 14px; margin: 4px 0 16px; display: flex; flex-direction: column; gap: 8px; }
.icon-row { display: flex; align-items: center; gap: 14px; flex-wrap: wrap; }
.icon-preview { width: 64px; height: 64px; border-radius: 50%; border: 1px dashed var(--border); display: grid; place-items: center; overflow: hidden; background: var(--chip); text-align: center; font-size: 10px; }
.icon-preview img { width: 100%; height: 100%; object-fit: cover; background: #fff; }

.chart { width: 100%; height: 200px; }
.chart rect.bar { fill: var(--accent); }
.chart text { fill: var(--muted); font-size: 10px; }

.bot-card { cursor: pointer; }
.bot-card:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.link-bar { display: flex; gap: 8px; align-items: center; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 8px 10px; margin-bottom: 16px; cursor: default; }
.link-bar.compact { margin: 4px 0 0; padding: 6px 8px; background: var(--bg); }
.link-label { font-weight: 600; font-size: 13px; white-space: nowrap; }
.link-bar .link-input { flex: 1; min-width: 0; padding: 5px 8px; font-size: 12px; font-family: ui-monospace, Consolas, monospace; background: var(--bg); }
.link-bar .btn { flex: none; }

.test-layout { display: grid; grid-template-columns: 400px 1fr; gap: 16px; align-items: start; }
.test-frame-wrap { border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; box-shadow: var(--shadow); background: var(--surface); }
.test-frame { display: block; width: 100%; height: 640px; border: 0; }
@media (max-width: 860px) { .test-layout { grid-template-columns: 1fr; } }

.toast { position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%); background: var(--text); color: var(--surface); padding: 10px 16px; border-radius: 8px; box-shadow: var(--shadow); z-index: 10; max-width: calc(100vw - 32px); }
.toast.error { background: var(--danger); color: #fff; }
.empty { text-align: center; padding: 40px 20px; color: var(--muted); }
