:root {
  --brand: #16a34a;
  --bg: #f4f5f7;
  --panel: #ffffff;
  --line: #e5e7eb;
  --text: #111827;
  --muted: #6b7280;
  --in: #ffffff;
  --out: #dcfce7;
  --ai: #ede9fe;
  --radius: 10px;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  color: var(--text);
}
* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); height: 100vh; overflow: hidden; }
button { font: inherit; cursor: pointer; border: 1px solid var(--line); background: #fff; border-radius: 8px; padding: 7px 12px; }
button.primary { background: var(--brand); color: #fff; border-color: var(--brand); }
button.ghost { border-color: transparent; background: transparent; }
button.danger { color: #dc2626; }
button:disabled { opacity: .5; cursor: default; }
input, textarea, select { font: inherit; border: 1px solid var(--line); border-radius: 8px; padding: 8px 10px; width: 100%; background: #fff; }
textarea { resize: vertical; }
label { font-size: 13px; color: var(--muted); display: block; margin: 10px 0 4px; }
h2 { font-size: 18px; margin: 0 0 12px; }
h3 { font-size: 15px; margin: 18px 0 8px; }
.muted { color: var(--muted); font-size: 13px; }
.row { display: flex; gap: 8px; align-items: center; }
.grow { flex: 1; min-width: 0; }

/* login */
.login { height: 100vh; display: grid; place-items: center; background: linear-gradient(135deg, var(--brand), #0f172a); }
.login form { background: #fff; padding: 32px; border-radius: 16px; width: 340px; box-shadow: 0 20px 50px rgba(0,0,0,.25); }
.login h1 { margin: 0 0 4px; font-size: 22px; }
.login button { width: 100%; margin-top: 18px; padding: 10px; }

/* layout */
.shell { display: grid; grid-template-columns: 64px 1fr; height: 100vh; }
.nav { background: #0f172a; display: flex; flex-direction: column; align-items: center; padding: 12px 0; gap: 6px; }
.nav .logo { width: 40px; height: 40px; border-radius: 12px; background: var(--brand); color: #fff; display: grid; place-items: center; font-weight: 700; margin-bottom: 14px; }
.nav a { width: 44px; height: 44px; border-radius: 10px; display: grid; place-items: center; color: #94a3b8; text-decoration: none; font-size: 20px; position: relative; }
.nav a.active, .nav a:hover { background: #1e293b; color: #fff; }
.nav a[data-tip]:hover::after { content: attr(data-tip); position: absolute; left: 52px; background: #111; color: #fff; font-size: 12px; padding: 4px 8px; border-radius: 6px; white-space: nowrap; z-index: 10; }
.nav .spacer { flex: 1; }
.main { overflow: hidden; height: 100vh; }

/* inbox */
.inbox { display: grid; grid-template-columns: 330px 1fr 300px; height: 100%; }
.list { background: var(--panel); border-right: 1px solid var(--line); display: flex; flex-direction: column; min-height: 0; }
.list-head { padding: 12px; border-bottom: 1px solid var(--line); }
.tabs { display: flex; gap: 4px; flex-wrap: wrap; margin-top: 10px; }
.tabs button { font-size: 12px; padding: 5px 8px; border-radius: 20px; }
.tabs button.on { background: var(--brand); color: #fff; border-color: var(--brand); }
.tabs .n { background: rgba(0,0,0,.12); border-radius: 10px; padding: 0 6px; margin-left: 4px; }
.items { overflow-y: auto; flex: 1; }
.item { padding: 11px 12px; border-bottom: 1px solid #f1f2f4; cursor: pointer; display: flex; gap: 10px; }
.item:hover { background: #f9fafb; }
.item.on { background: #f0fdf4; }
.avatar { width: 40px; height: 40px; border-radius: 50%; background: #cbd5e1; color: #fff; display: grid; place-items: center; font-weight: 600; flex-shrink: 0; }
.item .name { font-weight: 600; font-size: 14px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.item .last { font-size: 13px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.item .time { font-size: 11px; color: var(--muted); }
.badge { background: var(--brand); color: #fff; font-size: 11px; border-radius: 10px; padding: 1px 7px; }
.pill { font-size: 11px; padding: 1px 8px; border-radius: 10px; background: #f1f5f9; color: #475569; }
.pill.bot { background: var(--ai); color: #6d28d9; }
.pill.waiting { background: #fef3c7; color: #b45309; }
.pill.open { background: #dcfce7; color: #15803d; }
.pill.closed { background: #f1f5f9; color: #64748b; }

.chat { display: flex; flex-direction: column; min-height: 0; background: #efeae2; }
.chat-head { background: var(--panel); padding: 10px 14px; border-bottom: 1px solid var(--line); display: flex; gap: 10px; align-items: center; }
.msgs { flex: 1; overflow-y: auto; padding: 16px 6%; display: flex; flex-direction: column; gap: 6px; }
.msg { max-width: 70%; padding: 7px 10px 4px; border-radius: 8px; font-size: 14px; word-wrap: break-word; box-shadow: 0 1px 1px rgba(0,0,0,.08); }
.msg.in { background: var(--in); align-self: flex-start; }
.msg.out { background: var(--out); align-self: flex-end; }
.msg.ai { background: var(--ai); align-self: flex-end; }
.msg .b { white-space: pre-wrap; }
.msg .meta { font-size: 11px; color: var(--muted); text-align: right; margin-top: 2px; }
.msg .who { font-size: 11px; font-weight: 600; color: #6d28d9; }
.msg.failed { border: 1px solid #fca5a5; }
.msg .err { color: #dc2626; font-size: 11px; }
.sys { align-self: center; background: #fff8; font-size: 12px; color: #475569; padding: 3px 10px; border-radius: 8px; max-width: 80%; text-align: center; }
.composer { background: var(--panel); padding: 10px; border-top: 1px solid var(--line); position: relative; }
.composer textarea { min-height: 44px; max-height: 160px; }
.composer .warn { font-size: 12px; color: #b45309; margin-bottom: 6px; }
.qr-pop { position: absolute; bottom: 100%; left: 10px; right: 10px; background: #fff; border: 1px solid var(--line); border-radius: 8px; max-height: 200px; overflow: auto; box-shadow: 0 -6px 20px rgba(0,0,0,.08); }
.qr-pop div { padding: 8px 10px; cursor: pointer; font-size: 13px; }
.qr-pop div:hover { background: #f0fdf4; }
.empty { flex: 1; display: grid; place-items: center; color: var(--muted); text-align: center; padding: 20px; }

.side { background: var(--panel); border-left: 1px solid var(--line); overflow-y: auto; padding: 14px; }
.side .card { border: 1px solid var(--line); border-radius: var(--radius); padding: 12px; margin-bottom: 12px; }
.stage-select { display: flex; flex-direction: column; gap: 4px; }
.stage-select button { text-align: left; display: flex; align-items: center; gap: 8px; font-size: 13px; }
.stage-select button.on { font-weight: 600; border-width: 2px; }
.dot { width: 10px; height: 10px; border-radius: 50%; display: inline-block; flex-shrink: 0; }
.summary { white-space: pre-wrap; font-size: 13px; background: #faf5ff; border-radius: 8px; padding: 8px; }

/* kanban */
.board-wrap { height: 100%; display: flex; flex-direction: column; }
.board-head { padding: 14px 18px; display: flex; align-items: center; gap: 12px; background: var(--panel); border-bottom: 1px solid var(--line); }
.board { flex: 1; display: flex; gap: 12px; padding: 16px; overflow-x: auto; align-items: flex-start; }
.col { background: #e9ebef; border-radius: var(--radius); width: 270px; flex-shrink: 0; display: flex; flex-direction: column; max-height: 100%; }
.col-head { padding: 10px 12px; font-weight: 600; font-size: 14px; display: flex; align-items: center; gap: 8px; }
.col-head .sum { margin-left: auto; font-weight: 400; font-size: 12px; color: var(--muted); }
.col-body { padding: 0 8px 8px; overflow-y: auto; min-height: 60px; display: flex; flex-direction: column; gap: 8px; }
.col.drop { outline: 2px dashed var(--brand); }
.deal { background: #fff; border-radius: 8px; padding: 10px; box-shadow: 0 1px 2px rgba(0,0,0,.08); cursor: grab; font-size: 13px; }
.deal .t { font-weight: 600; font-size: 14px; }
.deal .v { color: #15803d; font-weight: 600; }

/* páginas simples */
.page { padding: 22px 28px; overflow-y: auto; height: 100%; max-width: 1000px; }
.section { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px; margin-bottom: 16px; }
table { width: 100%; border-collapse: collapse; font-size: 14px; }
th, td { text-align: left; padding: 8px; border-bottom: 1px solid var(--line); }
th { color: var(--muted); font-weight: 500; font-size: 12px; text-transform: uppercase; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 0 16px; }
code { background: #f1f5f9; padding: 2px 6px; border-radius: 4px; font-size: 13px; word-break: break-all; }
.status-ok { color: #15803d; font-weight: 600; }
.status-off { color: #b45309; font-weight: 600; }

/* modal & toast */
.modal-bg { position: fixed; inset: 0; background: rgba(15,23,42,.45); display: grid; place-items: center; z-index: 50; }
.modal { background: #fff; border-radius: 14px; padding: 22px; width: 420px; max-width: 92vw; }
.modal .actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 18px; }
#toast { position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%); background: #111827; color: #fff; padding: 10px 16px; border-radius: 8px; font-size: 14px; opacity: 0; transition: opacity .2s; pointer-events: none; z-index: 60; }
#toast.show { opacity: 1; }

@media (max-width: 1100px) { .inbox { grid-template-columns: 300px 1fr; } .side { display: none; } }
