:root {
  --bg: #F6F3F9;
  --panel: #FFFFFF;
  --panel-2: #F1ECF6;
  --ink: #1D0630;
  --ink-2: #5B4A6B;
  --ink-3: #8F82A0;
  --line: #E4DCEC;
  --brand: #3E1156;
  --brand-ink: #FFFFFF;
  --lime: #BEE014;
  --lime-ink: #1D0630;
  --danger: #C2304A;
  --wa: #128C4B;
  --chat: #5B3FD1;
  --form: #B5651D;
  --bubble-user: #F1ECF6;
  --bubble-bot: #FFFFFF;
  --bubble-mgr: #E9F6C2;
  --shadow: 0 1px 2px rgba(29, 6, 48, .06), 0 6px 20px rgba(29, 6, 48, .06);
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #12041F; --panel: #1D0630; --panel-2: #2A0B41; --ink: #F4EEF9; --ink-2: #C9BBD8; --ink-3: #8F7FA3;
    --line: #3A1A52; --brand: #BEE014; --brand-ink: #1D0630; --bubble-user: #2A0B41; --bubble-bot: #24093A; --bubble-mgr: #34451A;
    --wa: #3CCB7F; --chat: #A493FF; --form: #E6A35C; --danger: #FF6B85; --shadow: 0 1px 2px rgba(0,0,0,.3), 0 8px 24px rgba(0,0,0,.3);
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #12041F; --panel: #1D0630; --panel-2: #2A0B41; --ink: #F4EEF9; --ink-2: #C9BBD8; --ink-3: #8F7FA3;
  --line: #3A1A52; --brand: #BEE014; --brand-ink: #1D0630; --bubble-user: #2A0B41; --bubble-bot: #24093A; --bubble-mgr: #34451A;
  --wa: #3CCB7F; --chat: #A493FF; --form: #E6A35C; --danger: #FF6B85; --shadow: 0 1px 2px rgba(0,0,0,.3), 0 8px 24px rgba(0,0,0,.3);
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body { background: var(--bg); color: var(--ink); font: 14px/1.45 Montserrat, system-ui, sans-serif; -webkit-font-smoothing: antialiased; }
button, input, select, textarea { font: inherit; color: inherit; }
[hidden] { display: none !important; }

.brand { display: flex; align-items: center; gap: 8px; font-weight: 600; letter-spacing: .12em; font-size: 13px; white-space: nowrap; }
.brand b { color: var(--brand); font-weight: 700; }
.dot { width: 10px; height: 10px; border-radius: 50%; background: var(--lime); box-shadow: 0 0 0 3px color-mix(in srgb, var(--lime) 30%, transparent); }

.btn { border: 1px solid var(--line); background: var(--panel); border-radius: 10px; padding: 8px 14px; cursor: pointer; font-weight: 500; transition: background .15s, transform .1s; }
.btn:hover { background: var(--panel-2); }
.btn:active { transform: scale(.97); }
.btn.primary { background: var(--brand); color: var(--brand-ink); border-color: var(--brand); }
.btn.primary:hover { filter: brightness(1.1); }
.btn.ghost { background: transparent; }
.btn.danger { color: var(--danger); }
.btn:disabled { opacity: .5; cursor: default; }

input, select, textarea { background: var(--panel); border: 1px solid var(--line); border-radius: 10px; padding: 8px 10px; outline: none; min-width: 0; }
input:focus, select:focus, textarea:focus { border-color: var(--brand); box-shadow: 0 0 0 3px color-mix(in srgb, var(--brand) 18%, transparent); }
textarea { resize: vertical; }

/* login */
.login { min-height: 100%; display: grid; place-items: center; padding: 16px; }
.login-card { width: min(380px, 100%); background: var(--panel); border: 1px solid var(--line); border-radius: 20px; padding: 28px; display: flex; flex-direction: column; gap: 14px; box-shadow: var(--shadow); }
.login-card .brand { margin-bottom: 6px; }
.login-card label { display: flex; flex-direction: column; gap: 6px; font-size: 12px; color: var(--ink-2); }
.form-err { color: var(--danger); margin: 0; font-size: 13px; }

/* top bar */
.top { position: sticky; top: 0; z-index: 5; display: flex; align-items: center; gap: 16px; padding: 12px 20px; background: var(--panel); border-bottom: 1px solid var(--line); flex-wrap: wrap; }
.views { display: flex; background: var(--panel-2); padding: 3px; border-radius: 10px; }
.views button { border: 0; background: transparent; padding: 6px 12px; border-radius: 8px; cursor: pointer; color: var(--ink-2); font-weight: 500; }
.views button.on { background: var(--panel); color: var(--ink); box-shadow: var(--shadow); }
.tools { display: flex; align-items: center; gap: 8px; margin-left: auto; flex-wrap: wrap; }
#q { width: 260px; }
.me { position: relative; }
.menu { position: absolute; right: 0; top: calc(100% + 6px); background: var(--panel); border: 1px solid var(--line); border-radius: 12px; box-shadow: var(--shadow); padding: 6px; min-width: 220px; display: flex; flex-direction: column; z-index: 20; }
.menu button { border: 0; background: transparent; text-align: left; padding: 8px 10px; border-radius: 8px; cursor: pointer; }
.menu button:hover { background: var(--panel-2); }
.health { padding: 8px 10px; font-size: 12px; color: var(--ink-2); border-bottom: 1px solid var(--line); margin-bottom: 4px; display: grid; gap: 4px; }
.health i { font-style: normal; display: inline-block; width: 8px; height: 8px; border-radius: 50%; margin-right: 6px; background: var(--danger); }
.health i.ok { background: var(--wa); }

.stats { display: flex; gap: 10px; padding: 14px 20px 0; flex-wrap: wrap; }
.stat { background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 8px 14px; font-size: 12px; color: var(--ink-2); }
.stat b { display: block; font-size: 20px; color: var(--ink); font-variant-numeric: tabular-nums; }
.stat.alert b { color: var(--danger); }

/* board */
main { padding: 14px 20px 40px; }
.board { display: grid; grid-auto-flow: column; grid-auto-columns: minmax(260px, 1fr); gap: 12px; overflow-x: auto; padding-bottom: 8px; align-items: start; }
.col { background: var(--panel-2); border-radius: 14px; padding: 10px; min-height: 120px; transition: outline-color .15s; outline: 2px dashed transparent; outline-offset: -2px; }
.col.over { outline-color: var(--brand); }
.col h3 { margin: 2px 4px 10px; font-size: 12px; letter-spacing: .08em; text-transform: uppercase; color: var(--ink-2); display: flex; justify-content: space-between; }
.cards { display: flex; flex-direction: column; gap: 8px; }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 10px 12px; cursor: pointer; box-shadow: var(--shadow); transition: transform .12s, box-shadow .12s; position: relative; }
.card:hover { transform: translateY(-1px); }
.card.dragging { opacity: .5; }
.card .nm { font-weight: 600; padding-right: 26px; overflow-wrap: anywhere; }
.card .sub { color: var(--ink-2); font-size: 12px; margin-top: 2px; overflow-wrap: anywhere; }
.card .snip { color: var(--ink-3); font-size: 12px; margin-top: 6px; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; overflow-wrap: anywhere; }
.card .meta { display: flex; gap: 6px; align-items: center; margin-top: 8px; font-size: 11px; color: var(--ink-3); flex-wrap: wrap; }
.badge { display: inline-flex; align-items: center; gap: 4px; border-radius: 999px; padding: 2px 8px; font-size: 11px; font-weight: 600; background: var(--panel-2); color: var(--ink-2); white-space: nowrap; }
.badge.whatsapp { color: var(--wa); background: color-mix(in srgb, var(--wa) 12%, transparent); }
.badge.site_chat { color: var(--chat); background: color-mix(in srgb, var(--chat) 12%, transparent); }
.badge.site_form { color: var(--form); background: color-mix(in srgb, var(--form) 12%, transparent); }
.badge.hot { color: #fff; background: var(--danger); }
.unread { position: absolute; top: 10px; right: 10px; min-width: 20px; height: 20px; border-radius: 10px; background: var(--lime); color: var(--lime-ink); font-size: 11px; font-weight: 700; display: grid; place-items: center; padding: 0 6px; }
.empty { color: var(--ink-3); font-size: 12px; text-align: center; padding: 16px 4px; }

/* list */
.list table { width: 100%; border-collapse: collapse; background: var(--panel); border-radius: 14px; overflow: hidden; border: 1px solid var(--line); }
.list th, .list td { text-align: left; padding: 10px 12px; border-bottom: 1px solid var(--line); vertical-align: top; }
.list th { font-size: 11px; letter-spacing: .08em; text-transform: uppercase; color: var(--ink-2); background: var(--panel-2); }
.list tr[data-id] { cursor: pointer; }
.list tr[data-id]:hover td { background: var(--panel-2); }
.list td.snip { color: var(--ink-3); max-width: 340px; overflow-wrap: anywhere; }

/* knowledge base */
.kb-bar { display: flex; gap: 8px; margin-bottom: 8px; }
.kb-bar input { flex: 1; }
.kb-hint { color: var(--ink-3); font-size: 12px; margin: 0 0 12px; }
.kb-list { display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: 10px; }
.kb-item { background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 12px; cursor: pointer; box-shadow: var(--shadow); }
.kb-item.off { opacity: .45; }
.kb-item .t { font-weight: 600; font-size: 13px; overflow-wrap: anywhere; }
.kb-item .b { color: var(--ink-2); font-size: 12px; margin-top: 6px; white-space: pre-wrap; display: -webkit-box; -webkit-line-clamp: 4; -webkit-box-orient: vertical; overflow: hidden; overflow-wrap: anywhere; }
.kb-item .meta { display: flex; gap: 6px; margin-top: 8px; flex-wrap: wrap; font-size: 11px; color: var(--ink-3); }
.badge.notion { color: var(--ink-2); }
.badge.manual { color: var(--chat); background: color-mix(in srgb, var(--chat) 12%, transparent); }
.badge.pin { color: var(--lime-ink); background: var(--lime); }
.dlg.wide { width: min(720px, calc(100vw - 32px)); }
.dlg .ro { white-space: pre-wrap; background: var(--panel-2); border-radius: 10px; padding: 10px; max-height: 50vh; overflow: auto; font-size: 13px; overflow-wrap: anywhere; }
.dlg .chk { flex-direction: row; align-items: center; gap: 8px; color: var(--ink); }

/* articles */
.ar-list { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 12px; }
.ar-card { background: var(--panel); border: 1px solid var(--line); border-radius: 14px; overflow: hidden; cursor: pointer; box-shadow: var(--shadow); display: flex; flex-direction: column; text-align: left; padding: 0; color: inherit; font: inherit; }
.ar-card:hover { border-color: var(--brand); }
.ar-card .cv { aspect-ratio: 16 / 8; background: var(--panel-2) center / cover no-repeat; }
.ar-card .in { padding: 12px; display: grid; gap: 6px; }
.ar-card .t { font-weight: 600; font-size: 14px; overflow-wrap: anywhere; }
.ar-card .x { color: var(--ink-2); font-size: 12px; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.ar-card .meta { display: flex; gap: 6px; flex-wrap: wrap; font-size: 11px; color: var(--ink-3); align-items: center; }
.badge.pub { color: var(--lime-ink); background: var(--lime); }
.dlg.editor { width: min(1240px, calc(100vw - 24px)); max-height: calc(100dvh - 24px); }
.dlg.editor form { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); align-items: start; gap: 12px 20px; }
.dlg.editor h3, .dlg.editor .acts, .dlg.editor .full { grid-column: 1 / -1; }
.ed-col { display: grid; gap: 10px; }
.ed-row { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.ed-tools { display: flex; gap: 4px; flex-wrap: wrap; }
.ed-tools button { padding: 4px 9px; font-size: 12px; }
.ed-body { min-height: 340px; font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 13px; line-height: 1.55; }
.ed-cover { display: flex; gap: 8px; align-items: center; }
.ed-cover input[type=url], .ed-cover input[name=cover] { flex: 1; }
.ed-cover img { width: 64px; height: 40px; object-fit: cover; border-radius: 6px; background: var(--panel-2); }
.ed-prev { position: sticky; top: 0; border: 1px solid var(--line); border-radius: 14px; padding: 18px 20px; max-height: 72vh; overflow: auto; background: #FBF8FD; color: #3D2C55; }
.ed-prev .k { font-size: 10px; letter-spacing: .2em; color: #FF4D14; text-transform: uppercase; }
.ed-prev h1 { font-size: 24px; line-height: 1.2; color: #2A0B41; margin: 8px 0 10px; }
.ed-prev h2 { font-size: 19px; color: #2A0B41; margin: 20px 0 8px; }
.ed-prev h3 { font-size: 12px; letter-spacing: .16em; text-transform: uppercase; color: #3E1156; margin: 18px 0 6px; }
.ed-prev p, .ed-prev li { font-size: 14px; line-height: 1.7; }
.ed-prev img { max-width: 100%; border-radius: 12px; display: block; }
.ed-prev figure { margin: 14px 0; } .ed-prev figcaption { font-size: 12px; color: #8A72A6; margin-top: 6px; }
.ed-prev blockquote { border-left: 3px solid #BEE014; margin: 12px 0; padding: 4px 14px; color: #2A0B41; }
.ed-prev a { color: #3E1156; } .ed-prev .md-btn a { display: inline-block; background: #BEE014; color: #1D0630; padding: 8px 16px; border-radius: 999px; text-decoration: none; font-weight: 600; }
.ed-prev .cv { width: 100%; aspect-ratio: 16/8; object-fit: cover; border-radius: 12px; margin-bottom: 12px; }
.ed-help { font-size: 11px; color: var(--ink-3); line-height: 1.5; }
.ed-help code { background: var(--panel-2); padding: 0 4px; border-radius: 4px; }
@media (max-width: 860px) { .dlg.editor form { grid-template-columns: 1fr; } .ed-prev { position: static; max-height: none; } }

/* drawer */
.scrim { position: fixed; inset: 0; background: rgba(14, 3, 24, .35); z-index: 30; }
.drawer { position: fixed; top: 0; right: 0; bottom: 0; width: min(760px, 100vw); background: var(--bg); z-index: 31; box-shadow: -20px 0 60px rgba(0,0,0,.18); animation: slide .22s cubic-bezier(.2,.7,.2,1); }
@keyframes slide { from { transform: translateX(24px); opacity: 0; } }
.drawer-in { height: 100%; display: flex; flex-direction: column; }
.d-head { padding: 16px 20px; background: var(--panel); border-bottom: 1px solid var(--line); display: flex; gap: 12px; align-items: flex-start; flex-wrap: wrap; }
.d-head h2 { margin: 0; font-size: 20px; flex: 1 1 220px; overflow-wrap: anywhere; }
.d-head .row { display: flex; gap: 8px; flex-wrap: wrap; width: 100%; align-items: center; }
.d-body { flex: 1; overflow: auto; padding: 16px 20px 24px; display: grid; gap: 16px; align-content: start; }
.box { background: var(--panel); border: 1px solid var(--line); border-radius: 14px; padding: 14px; }
.box h4 .contact-links a { text-transform: none; letter-spacing: 0; }
.box h4 { margin: 0 0 10px; font-size: 11px; letter-spacing: .1em; text-transform: uppercase; color: var(--ink-2); display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.fields { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 10px; }
.fields label { display: flex; flex-direction: column; gap: 4px; font-size: 11px; color: var(--ink-3); }
.fields label.wide { grid-column: 1 / -1; }
.contact-links { display: flex; gap: 8px; flex-wrap: wrap; }
.contact-links a { color: var(--brand); font-weight: 600; text-decoration: none; font-size: 13px; }
:root[data-theme="dark"] .contact-links a { color: var(--lime); }
.summary { white-space: pre-wrap; color: var(--ink-2); margin: 0; }

.conv-tabs { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 10px; }
.chat { display: flex; flex-direction: column; gap: 8px; max-height: 52vh; overflow: auto; padding: 4px 2px; }
.msg { max-width: 82%; padding: 8px 12px; border-radius: 14px; white-space: pre-wrap; overflow-wrap: anywhere; border: 1px solid var(--line); }
.msg.user { background: var(--bubble-user); align-self: flex-start; border-bottom-left-radius: 4px; }
.msg.assistant { background: var(--bubble-bot); align-self: flex-end; border-bottom-right-radius: 4px; }
.msg.manager { background: var(--bubble-mgr); align-self: flex-end; border-bottom-right-radius: 4px; }
.msg .who { display: block; font-size: 10px; letter-spacing: .06em; text-transform: uppercase; color: var(--ink-3); margin-bottom: 2px; }
.msg .err { display: block; color: var(--danger); font-size: 11px; margin-top: 4px; }
.reply { display: flex; gap: 8px; margin-top: 10px; align-items: flex-end; }
.reply textarea { flex: 1; min-height: 44px; }
.switch { display: inline-flex; align-items: center; gap: 8px; font-size: 12px; color: var(--ink-2); cursor: pointer; text-transform: none; letter-spacing: 0; }
.switch input { width: 34px; height: 20px; appearance: none; border-radius: 10px; background: var(--line); position: relative; cursor: pointer; padding: 0; border: 0; transition: background .15s; }
.switch input::after { content: ""; position: absolute; top: 2px; left: 2px; width: 16px; height: 16px; border-radius: 50%; background: #fff; transition: transform .15s; }
.switch input:checked { background: var(--wa); }
.switch input:checked::after { transform: translateX(14px); }

.timeline { display: grid; gap: 8px; }
.act { display: grid; grid-template-columns: auto 1fr; gap: 10px; font-size: 13px; }
.act time { color: var(--ink-3); font-size: 11px; white-space: nowrap; padding-top: 2px; }
.act .b { white-space: pre-wrap; overflow-wrap: anywhere; }
.act.note .b { background: var(--panel-2); border-radius: 10px; padding: 8px 10px; }
.act .by { color: var(--ink-3); font-size: 11px; }
.note-form { display: flex; gap: 8px; margin-bottom: 12px; }
.note-form textarea { flex: 1; min-height: 40px; }

.dlg { border: 1px solid var(--line); border-radius: 18px; padding: 0; background: var(--panel); color: var(--ink); width: min(460px, calc(100vw - 32px)); box-shadow: var(--shadow); }
.dlg::backdrop { background: rgba(14, 3, 24, .45); }
.dlg form { padding: 22px; display: grid; gap: 12px; }
.dlg h3 { margin: 0 0 4px; }
.dlg label { display: flex; flex-direction: column; gap: 4px; font-size: 12px; color: var(--ink-2); }
.dlg .acts { display: flex; justify-content: flex-end; gap: 8px; margin-top: 6px; }
.team-list { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 10px; }
.team-item .b { -webkit-line-clamp: 1; }
.team-item .you { color: var(--ink-3); font-weight: 400; }
.pw-row { display: flex; gap: 6px; }
.pw-row input { flex: 1; font-family: ui-monospace, Menlo, monospace; }

.toast { position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%); background: var(--ink); color: var(--bg); padding: 10px 16px; border-radius: 12px; z-index: 50; box-shadow: var(--shadow); max-width: calc(100vw - 32px); }
.toast.bad { background: var(--danger); color: #fff; }

@media (max-width: 760px) {
  .top { padding: 10px 16px; gap: 10px; }
  .tools { margin-left: 0; width: 100%; }
  #q { flex: 1 1 100%; width: auto; }
  #source { flex: 1; }
  .stats { padding: 12px 16px 2px; flex-wrap: nowrap; overflow-x: auto; scrollbar-width: none; }
  .stat { flex: none; padding: 6px 12px; }
  .stat b { font-size: 17px; }
  main { padding: 12px 16px 32px; }
  .board { grid-auto-columns: 84vw; scroll-snap-type: x mandatory; }
  .col { scroll-snap-align: start; }
  .list table, .list thead, .list tbody, .list tr, .list td { display: block; }
  .list thead { display: none; }
  .list tr { border-bottom: 1px solid var(--line); padding: 8px 0; }
  .list td { border: 0; padding: 2px 12px; }
  .d-head, .d-body { padding-left: 16px; padding-right: 16px; }
  .msg { max-width: 92%; }
}
@media (prefers-reduced-motion: reduce) { * { animation: none !important; transition: none !important; } }
