/* AgentBridge console — dark modern theme */
:root {
  --bg: #0e1016; --panel: #151823; --panel2: #1b1f2e; --line: #262b3d;
  --ink: #e8eaf2; --muted: #8a90a6; --brand: #4f7cff; --brand2: #7c5cff;
  --ok: #2fbf71; --warn: #ffb224; --err: #e5484d;
}
* { box-sizing: border-box; margin: 0; }
body { font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif; background: var(--bg); color: var(--ink); font-size: 14px; }
a { color: var(--brand); text-decoration: none; }
code { background: var(--panel2); padding: 1px 6px; border-radius: 5px; font-size: 12.5px; }

/* layout */
.layout { display: flex; min-height: 100vh; }
.side { width: 220px; background: var(--panel); border-right: 1px solid var(--line); display: flex; flex-direction: column; padding: 18px 12px; position: sticky; top: 0; height: 100vh; }
.side-brand { font-weight: 800; font-size: 17px; padding: 6px 10px 22px; letter-spacing: .3px; }
.side-link { display: block; padding: 10px 12px; border-radius: 10px; color: var(--muted); margin-bottom: 2px; font-weight: 500; }
.side-link:hover { background: var(--panel2); color: var(--ink); }
.side-link.active { background: linear-gradient(90deg, rgba(79,124,255,.18), rgba(124,92,255,.10)); color: #fff; border: 1px solid rgba(79,124,255,.35); }
.side-foot { margin-top: auto; }
.side-me { padding: 10px; border-top: 1px solid var(--line); margin-bottom: 8px; }
.side-me-name { font-weight: 700; font-size: 13.5px; }
.side-me-role { color: var(--muted); font-size: 11.5px; text-transform: capitalize; margin-bottom: 6px; }
.main { flex: 1; min-width: 0; padding: 22px 26px 60px; }
.topbar { display: flex; align-items: center; justify-content: space-between; margin-bottom: 20px; }
.topbar h1 { font-size: 21px; letter-spacing: -.3px; }
.topbar-right { display: flex; align-items: center; gap: 14px; }
.view { max-width: 1240px; }
.view-head { display: flex; align-items: center; gap: 12px; margin-bottom: 16px; flex-wrap: wrap; }
.hint { color: var(--muted); font-size: 13px; }
.tiny { font-size: 11.5px; } .muted { color: var(--muted); } .strong { font-weight: 700; }
.mt8 { margin-top: 10px; } .grow { flex: 1; }

/* cards & grid */
.card { background: var(--panel); border: 1px solid var(--line); border-radius: 14px; padding: 16px; margin-bottom: 16px; }
.card-title { font-size: 14.5px; margin-bottom: 12px; }
.two-col { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.metric-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); gap: 12px; margin-bottom: 16px; }
.metric { display: flex; gap: 12px; align-items: center; padding: 14px; margin: 0; }
.metric-ico { font-size: 22px; }
.metric-val { font-size: 21px; font-weight: 800; letter-spacing: -.5px; }
.metric-label { font-size: 11.5px; }
.chart-wrap { overflow-x: auto; }
.chart { width: 100%; height: auto; }

/* chips */
.chip { display: inline-flex; align-items: center; padding: 2px 9px; border-radius: 99px; font-size: 11px; font-weight: 600; white-space: nowrap; }
.chip.plain { background: var(--panel2); color: var(--muted); border: 1px solid var(--line); }
.g-low { background: rgba(138,144,166,.15); color: #aab1c7; }
.g-med { background: rgba(255,178,36,.14); color: #ffc75d; }
.g-high { background: rgba(47,191,113,.15); color: #52d987; }
.g-human { background: rgba(79,124,255,.16); color: #85a7ff; }
.g-conv { background: rgba(124,92,255,.2); color: #b7a4ff; }
.g-unq { background: rgba(229,72,77,.14); color: #ff8a8d; }
.s-bot { background: rgba(138,144,166,.12); color: var(--muted); }
.s-wait { background: rgba(255,178,36,.16); color: #ffc75d; }
.s-human { background: rgba(47,191,113,.16); color: #52d987; }
.s-closed { background: rgba(138,144,166,.1); color: #7c8296; }
.pill { border-radius: 99px; padding: 1px 8px; font-size: 10.5px; background: var(--panel2); border: 1px solid var(--line); color: var(--muted); }
.tag-cloud { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; }

/* tables */
.table-wrap { padding: 6px 0; }
.trow { display: grid; grid-template-columns: 1.2fr 1fr 1.4fr 1.2fr .7fr 1fr 1fr .8fr; gap: 8px; padding: 10px 16px; border-bottom: 1px solid var(--line); cursor: pointer; align-items: center; }
.trow:last-child { border-bottom: none; }
.trow:hover { background: var(--panel2); }
.trow.thead { color: var(--muted); font-size: 11.5px; text-transform: uppercase; letter-spacing: .5px; cursor: default; }
.trow.thead:hover { background: none; }

/* inbox */
.inbox { display: grid; grid-template-columns: 340px 1fr; gap: 16px; align-items: start; }
.inbox-list { padding: 10px; position: sticky; top: 80px; max-height: calc(100vh - 110px); display: flex; flex-direction: column; }
.inbox-list-head { display: flex; gap: 8px; padding: 6px 6px 10px; }
.inbox-list-body { overflow-y: auto; }
.conv-item { padding: 11px 12px; border-radius: 10px; cursor: pointer; border: 1px solid transparent; margin-bottom: 4px; }
.conv-item:hover { background: var(--panel2); }
.conv-item.active { background: var(--panel2); border-color: rgba(79,124,255,.4); }
.conv-item.pulse { animation: pulse 1.6s infinite; }
@keyframes pulse { 0%,100% { box-shadow: 0 0 0 0 rgba(255,178,36,0); } 50% { box-shadow: 0 0 0 3px rgba(255,178,36,.25); } }
.conv-item-top { display: flex; justify-content: space-between; gap: 8px; }
.conv-item-preview { color: var(--muted); font-size: 12.5px; margin: 3px 0 6px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.conv-item-tags { display: flex; gap: 6px; flex-wrap: wrap; }
.inbox-detail { min-height: 420px; }
.detail-head { display: flex; justify-content: space-between; align-items: center; gap: 10px; flex-wrap: wrap; margin-bottom: 14px; }
.detail-actions { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.detail-cols { display: grid; grid-template-columns: 1fr 280px; gap: 18px; }
.detail-main { display: flex; flex-direction: column; min-height: 380px; }
.detail-side { display: flex; flex-direction: column; gap: 14px; }
.side-block h4 { margin-bottom: 8px; font-size: 13px; }
.transcript { flex: 1; overflow-y: auto; max-height: 460px; padding-right: 6px; }
.msg { margin-bottom: 12px; }
.msg-text { padding: 9px 13px; border-radius: 13px; line-height: 1.5; max-width: 78%; white-space: pre-wrap; word-wrap: break-word; }
.from-visitor .msg-text { background: var(--panel2); border: 1px solid var(--line); }
.from-ai .msg-text { background: rgba(124,92,255,.13); border: 1px solid rgba(124,92,255,.3); }
.from-agent .msg-text { background: rgba(79,124,255,.18); border: 1px solid rgba(79,124,255,.4); }
.from-system .msg-text { background: transparent; border: 1px dashed var(--line); color: var(--muted); font-size: 12px; text-align: center; margin: 0 auto; }
.msg-who { margin-bottom: 3px; }
.cite { margin-top: 5px; }
.typing { min-height: 18px; margin-bottom: 4px; }
.send-row { display: flex; gap: 8px; margin-top: 10px; }
.chat-input { flex: 1; background: var(--panel2); border: 1px solid var(--line); border-radius: 10px; color: var(--ink); padding: 10px 12px; font-family: inherit; font-size: 13.5px; resize: vertical; }
.chat-input:focus, .filter-input:focus { outline: none; border-color: var(--brand); }
.lead-panel { background: var(--panel2); border: 1px solid var(--line); border-radius: 12px; padding: 12px; }
.lead-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 8px; }
.lead-score { font-weight: 800; color: var(--warn); font-size: 13px; }
.lead-reasons { max-height: 130px; overflow-y: auto; font-size: 11.5px; line-height: 1.7; }
.lead-actions { display: flex; gap: 6px; margin-top: 10px; }
.detail-meta { background: var(--panel2); border: 1px solid var(--line); border-radius: 12px; padding: 12px; font-size: 12px; }
.meta-item { margin-bottom: 7px; }
.meta-k { display: block; text-transform: uppercase; letter-spacing: .5px; font-size: 10px; }
.notes-list { max-height: 160px; overflow-y: auto; }
.note { font-size: 12px; padding: 6px 0; border-bottom: 1px dashed var(--line); }

/* funnel */
.funnel-row { display: grid; grid-template-columns: 110px 1fr 46px; gap: 10px; align-items: center; margin-bottom: 8px; }
.funnel-name { font-size: 12px; color: var(--muted); }
.funnel-bar-wrap { background: var(--panel2); border-radius: 6px; height: 16px; overflow: hidden; }
.funnel-bar { height: 100%; background: linear-gradient(90deg, var(--brand), var(--brand2)); border-radius: 6px; transition: width .5s; }
.funnel-val { font-weight: 700; font-size: 12.5px; text-align: right; }

/* forms */
.filter-input, .filter-select, .login-input, .status-select { background: var(--panel2); border: 1px solid var(--line); border-radius: 9px; color: var(--ink); padding: 8px 11px; font-size: 13px; font-family: inherit; }
.filter-input.grow { flex: 1; }
.filter-input.tiny, .filter-select.tiny, .status-select { padding: 5px 8px; font-size: 12px; }
.filters { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.field { display: block; margin-bottom: 12px; }
.field-label { display: block; font-size: 12px; color: var(--muted); margin-bottom: 5px; }
.check-row { display: flex; align-items: center; gap: 9px; padding: 7px 0; cursor: pointer; }
.check-row input[type=checkbox] { accent-color: var(--brand); width: 15px; height: 15px; }
.tabs { display: flex; gap: 4px; flex-wrap: wrap; margin-bottom: 14px; }
.tab { background: none; border: 1px solid transparent; color: var(--muted); padding: 7px 14px; border-radius: 9px; cursor: pointer; font-family: inherit; font-size: 13px; font-weight: 600; }
.tab.active { background: var(--panel2); border-color: var(--line); color: var(--ink); }

/* buttons */
.btn { border-radius: 10px; border: 1px solid transparent; cursor: pointer; font-family: inherit; font-weight: 600; padding: 9px 16px; font-size: 13.5px; }
.btn.primary { background: var(--brand); color: #fff; }
.btn.primary:hover { filter: brightness(1.1); }
.btn.ghost { background: transparent; border-color: var(--line); color: var(--ink); }
.btn.ghost:hover { border-color: var(--brand); }
.btn.danger { background: transparent; border-color: rgba(229,72,77,.4); color: #ff8a8d; }
.btn.danger:hover { background: rgba(229,72,77,.1); }
.btn.small { padding: 6px 12px; font-size: 12.5px; }
.btn.tiny { padding: 3px 9px; font-size: 11.5px; }
.btn.wide { width: 100%; }
.btn:disabled { opacity: .5; cursor: default; }

/* agents */
.agent-row { display: flex; gap: 12px; align-items: center; padding: 10px 0; border-bottom: 1px solid var(--line); }
.agent-row:last-child { border: none; }
.avatar { width: 36px; height: 36px; border-radius: 50%; display: flex; align-items: center; justify-content: center; font-weight: 800; font-size: 12.5px; color: #fff; flex: none; }

/* knowledge */
.source-item { padding: 10px 12px; border-radius: 10px; cursor: pointer; border: 1px solid transparent; margin-bottom: 4px; }
.source-item:hover { background: var(--panel2); }
.source-item.active { background: var(--panel2); border-color: rgba(79,124,255,.4); }
.kb-hit { padding: 10px 12px; border: 1px solid var(--line); border-radius: 10px; margin-bottom: 8px; background: var(--panel2); }

/* login */
.login-wrap { min-height: 100vh; display: flex; align-items: center; justify-content: center; background: radial-gradient(1200px 600px at 20% -10%, rgba(124,92,255,.18), transparent), var(--bg); }
.login-card { width: 340px; background: var(--panel); border: 1px solid var(--line); border-radius: 18px; padding: 34px 30px; display: flex; flex-direction: column; gap: 12px; }
.login-logo { font-size: 38px; text-align: center; }
.login-card h2 { text-align: center; letter-spacing: -.3px; }
.login-sub { text-align: center; color: var(--muted); font-size: 12.5px; margin-bottom: 6px; }
.login-input { padding: 11px 13px; }
.login-err { color: #ff8a8d; font-size: 12.5px; min-height: 15px; }
.login-hint { text-align: center; color: var(--muted); font-size: 11.5px; }

/* conn badge, bell, toasts */
.conn { font-size: 11.5px; font-weight: 700; }
.conn.on { color: var(--ok); } .conn.off { color: var(--warn); }
.bell-wrap { position: relative; }
.bell { background: var(--panel2); border: 1px solid var(--line); border-radius: 9px; color: var(--ink); font-size: 15px; cursor: pointer; padding: 6px 10px; position: relative; }
.bell-dot { position: absolute; top: 3px; right: 3px; width: 8px; height: 8px; border-radius: 50%; background: var(--err); display: none; }
.bell-dot.show { display: block; }
.bell-list { position: absolute; right: 0; top: 36px; width: 300px; background: var(--panel); border: 1px solid var(--line); border-radius: 12px; display: none; z-index: 50; max-height: 380px; overflow-y: auto; }
.bell-list.open { display: block; }
.bell-item { padding: 10px 14px; border-bottom: 1px solid var(--line); }
.bell-item:last-child { border: none; }
.bell-title { font-weight: 700; font-size: 12.5px; }
.bell-body { color: var(--muted); font-size: 12px; margin-top: 2px; }
.bell-time { color: var(--muted); font-size: 10.5px; margin-top: 3px; }
.bell-empty { padding: 18px; color: var(--muted); text-align: center; font-size: 12.5px; }
.toasts { position: fixed; bottom: 18px; right: 18px; z-index: 999; display: flex; flex-direction: column; gap: 8px; }
.toast { background: var(--panel2); border: 1px solid var(--line); border-left: 3px solid var(--brand); color: var(--ink); border-radius: 10px; padding: 10px 16px; font-size: 13px; opacity: 0; transform: translateX(20px); transition: all .25s; max-width: 340px; }
.toast.show { opacity: 1; transform: none; }
.toast.err { border-left-color: var(--err); }
.toast.ok { border-left-color: var(--ok); }
.toast.notify { border-left-color: var(--warn); }

/* empty states */
.empty { padding: 50px 20px; text-align: center; color: var(--muted); }
.empty.small { padding: 24px; }
.empty-ico { font-size: 34px; margin-bottom: 10px; }
.empty .btn { margin-top: 12px; display: inline-block; }

@media (max-width: 1100px) {
  .inbox { grid-template-columns: 1fr; }
  .two-col { grid-template-columns: 1fr; }
  .detail-cols { grid-template-columns: 1fr; }
}
@media (max-width: 760px) {
  .side { width: 62px; padding: 14px 6px; }
  .side-brand, .side-me, .side-link span { display: none; }
  .main { padding: 16px 12px 40px; }
}
