:root {
  --bg: #0f172a;
  --bg-2: #1e293b;
  --panel: #ffffff;
  --border: #e2e8f0;
  --text: #0f172a;
  --muted: #64748b;
  --primary: #4f46e5;
  --primary-dark: #4338ca;
  --danger: #ef4444;
  --success: #22c55e;
  --shadow: 0 1px 3px rgba(0,0,0,.1), 0 1px 2px rgba(0,0,0,.06);
}

* { box-sizing: border-box; }
body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: #f1f5f9;
  color: var(--text);
  font-size: 14px;
}
.hidden { display: none !important; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
code { background: #eef2ff; padding: 1px 5px; border-radius: 4px; font-size: 12px; }

/* ---------- Botões ---------- */
.btn {
  border: none; border-radius: 8px; padding: 9px 16px; font-size: 14px;
  cursor: pointer; font-weight: 500; transition: .15s; font-family: inherit;
}
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-dark); }
.btn-secondary { background: #e0e7ff; color: var(--primary-dark); }
.btn-secondary:hover { background: #c7d2fe; }
.btn-ghost { background: transparent; color: var(--muted); border: 1px solid var(--border); }
.btn-ghost:hover { background: #f8fafc; }
.btn-danger { background: var(--danger); color: #fff; }
.btn-danger:hover { background: #dc2626; }
.btn-block { width: 100%; }

/* ---------- Login ---------- */
.login-wrap {
  min-height: 100vh; display: flex; align-items: center; justify-content: center;
  background: linear-gradient(135deg, #4f46e5 0%, #0f172a 100%);
}
.login-card {
  background: #fff; padding: 40px; border-radius: 16px; width: 360px;
  box-shadow: 0 20px 60px rgba(0,0,0,.3); text-align: center;
}
.login-logo { font-size: 48px; }
.login-card h1 { font-size: 20px; margin: 10px 0 4px; }
.login-card label { display: block; text-align: left; margin: 14px 0 4px; font-weight: 500; }
.login-card input {
  width: 100%; padding: 11px; border: 1px solid var(--border); border-radius: 8px; font-size: 14px;
}
.login-card button { margin-top: 22px; }
.error-msg { color: var(--danger); margin-top: 12px; font-size: 13px; min-height: 18px; }

/* ---------- Layout App ---------- */
.app { display: flex; min-height: 100vh; }
.sidebar {
  width: 240px; background: var(--bg); color: #cbd5e1; display: flex; flex-direction: column;
  position: fixed; height: 100vh;
}
.brand { font-size: 18px; font-weight: 700; color: #fff; padding: 20px; display: flex; gap: 8px; align-items: center; }
.brand span { font-size: 16px; }
.sidebar nav { flex: 1; padding: 8px; }
.nav-item {
  display: block; padding: 11px 14px; border-radius: 8px; color: #cbd5e1;
  cursor: pointer; text-decoration: none; margin-bottom: 2px; font-size: 14px;
}
.nav-item:hover { background: var(--bg-2); color: #fff; }
.nav-item.active { background: var(--primary); color: #fff; }
.sidebar-footer { padding: 14px; border-top: 1px solid var(--bg-2); }
.user-badge { display: flex; gap: 10px; align-items: center; margin-bottom: 10px; }
.avatar {
  width: 38px; height: 38px; border-radius: 50%; background: var(--primary);
  color: #fff; display: flex; align-items: center; justify-content: center; font-weight: 600;
}
.user-name { color: #fff; font-weight: 500; }

.content { flex: 1; margin-left: 240px; display: flex; flex-direction: column; }
.topbar {
  background: #fff; padding: 16px 28px; display: flex; justify-content: space-between;
  align-items: center; border-bottom: 1px solid var(--border); position: sticky; top: 0; z-index: 5;
}
.topbar h2 { margin: 0; font-size: 20px; }
.view { padding: 24px 28px; }

/* ---------- Filtros ---------- */
.filters { display: flex; gap: 12px; align-items: center; margin-bottom: 18px; flex-wrap: wrap; }
.filters input, .filters select {
  padding: 9px 12px; border: 1px solid var(--border); border-radius: 8px; font-size: 14px; font-family: inherit;
}
.filters input[type="search"] { min-width: 280px; }
.filters label { display: flex; gap: 6px; align-items: center; font-size: 13px; color: var(--muted); }

/* ---------- KPI Cards ---------- */
.cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 16px; margin-bottom: 20px; }
.card {
  background: #fff; border-radius: 12px; padding: 18px; box-shadow: var(--shadow); border: 1px solid var(--border);
}
.card .k-label { color: var(--muted); font-size: 13px; }
.card .k-value { font-size: 26px; font-weight: 700; margin-top: 6px; }
.card .k-sub { font-size: 12px; margin-top: 4px; }

/* ---------- Panels / Grid ---------- */
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; margin-bottom: 16px; }
.panel { background: #fff; border-radius: 12px; padding: 20px; box-shadow: var(--shadow); border: 1px solid var(--border); }
.panel h3 { margin: 0 0 16px; font-size: 15px; }
.panel h4 { margin: 20px 0 8px; font-size: 14px; }

/* ---------- Tabelas ---------- */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 13px; }
th, td { text-align: left; padding: 11px 12px; border-bottom: 1px solid var(--border); }
th { color: var(--muted); font-weight: 600; font-size: 12px; text-transform: uppercase; letter-spacing: .03em; }
tbody tr { cursor: pointer; }
tbody tr:hover { background: #f8fafc; }
.badge { display: inline-block; padding: 3px 10px; border-radius: 20px; font-size: 12px; color: #fff; font-weight: 500; }
.tag { display: inline-block; padding: 2px 8px; border-radius: 6px; font-size: 12px; background: #eef2ff; color: var(--primary-dark); }

/* ---------- Kanban ---------- */
.kanban { display: flex; gap: 14px; overflow-x: auto; padding-bottom: 20px; align-items: flex-start; }
.kcol { background: #eef1f6; border-radius: 12px; min-width: 270px; width: 270px; flex-shrink: 0; }
.kcol-head { padding: 12px 14px; font-weight: 600; display: flex; justify-content: space-between; align-items: center; border-top: 3px solid; border-radius: 12px 12px 0 0; }
.kcol-count { background: rgba(0,0,0,.08); border-radius: 20px; padding: 1px 9px; font-size: 12px; }
.kcol-body { padding: 8px; min-height: 120px; display: flex; flex-direction: column; gap: 8px; }
.kcol-body.dragover { background: #dbeafe; }
.kcard {
  background: #fff; border-radius: 10px; padding: 12px; box-shadow: var(--shadow); cursor: grab;
  border: 1px solid var(--border);
}
.kcard:active { cursor: grabbing; }
.kcard .kc-name { font-weight: 600; }
.kcard .kc-meta { color: var(--muted); font-size: 12px; margin-top: 4px; }
.kcard .kc-foot { display: flex; justify-content: space-between; align-items: center; margin-top: 8px; }
.kcard .kc-value { font-weight: 600; color: var(--success); font-size: 13px; }
.kcol-value { padding: 0 14px 12px; font-size: 12px; color: var(--muted); }

/* ---------- Modal ---------- */
.modal { position: fixed; inset: 0; background: rgba(15,23,42,.55); display: flex; align-items: flex-start; justify-content: center; z-index: 50; overflow-y: auto; padding: 40px 16px; }
.modal-box { background: #fff; border-radius: 16px; padding: 28px; width: 720px; max-width: 100%; position: relative; box-shadow: 0 20px 60px rgba(0,0,0,.3); }
.modal-box.small { width: 420px; }
.modal-close { position: absolute; top: 16px; right: 16px; background: none; border: none; font-size: 20px; cursor: pointer; color: var(--muted); }
.modal-box h3 { margin: 0 0 18px; }
.modal-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 20px; }
.modal-box label { display: block; margin: 12px 0 4px; font-weight: 500; font-size: 13px; }
.modal-box input, .modal-box select, .modal-box textarea {
  width: 100%; padding: 9px 11px; border: 1px solid var(--border); border-radius: 8px; font-size: 14px; font-family: inherit;
}
.modal-box .row { display: flex; gap: 10px; }
.modal-box .row > div { flex: 1; }
.modal-actions { display: flex; gap: 10px; margin-top: 22px; align-items: center; }
.modal-actions .spacer { flex: 1; }
.check { display: flex !important; align-items: center; gap: 8px; margin-top: 14px !important; }
.check input { width: auto !important; }

/* ---------- Timeline ---------- */
.timeline-wrap { margin-top: 24px; border-top: 1px solid var(--border); padding-top: 18px; }
.add-activity { display: flex; gap: 8px; margin-bottom: 14px; }
.add-activity select { width: 130px; }
.add-activity input { flex: 1; }
.timeline { display: flex; flex-direction: column; gap: 10px; max-height: 260px; overflow-y: auto; }
.tl-item { display: flex; gap: 10px; font-size: 13px; }
.tl-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--primary); margin-top: 5px; flex-shrink: 0; }
.tl-body { flex: 1; }
.tl-meta { color: var(--muted); font-size: 11px; }

/* ---------- Toast ---------- */
.toast {
  position: fixed; bottom: 24px; right: 24px; background: var(--bg); color: #fff;
  padding: 14px 20px; border-radius: 10px; box-shadow: 0 10px 30px rgba(0,0,0,.3); z-index: 100;
  font-size: 14px;
}
.toast.err { background: var(--danger); }
.toast.ok { background: var(--success); }

pre { background: #0f172a; color: #e2e8f0; padding: 16px; border-radius: 10px; overflow-x: auto; font-size: 12.5px; line-height: 1.5; }

/* ---------- Atendimento / Chat ---------- */
.nav-badge { background: #ef4444; color: #fff; border-radius: 20px; padding: 1px 7px; font-size: 11px; font-weight: 700; margin-left: 4px; }
#view-atendimento { padding: 0; height: calc(100vh - 65px); }
.chat-wrap { display: flex; height: 100%; }
.chat-list { width: 320px; border-right: 1px solid var(--border); background: #fff; display: flex; flex-direction: column; }
.chat-list-head { padding: 12px; border-bottom: 1px solid var(--border); }
.chat-list-head input { width: 100%; padding: 9px 12px; border: 1px solid var(--border); border-radius: 8px; font-size: 14px; }
.conv-list { overflow-y: auto; flex: 1; }
.conv-item { padding: 12px 14px; border-bottom: 1px solid #f1f5f9; cursor: pointer; display: flex; gap: 10px; align-items: flex-start; }
.conv-item:hover { background: #f8fafc; }
.conv-item.active { background: #eef2ff; }
.conv-avatar { width: 42px; height: 42px; border-radius: 50%; background: #cbd5e1; color: #fff; display: flex; align-items: center; justify-content: center; font-weight: 600; flex-shrink: 0; }
.conv-body { flex: 1; min-width: 0; }
.conv-top { display: flex; justify-content: space-between; align-items: baseline; }
.conv-name { font-weight: 600; font-size: 14px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.conv-time { font-size: 11px; color: var(--muted); flex-shrink: 0; margin-left: 6px; }
.conv-preview { color: var(--muted); font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.conv-unread { background: #22c55e; color: #fff; border-radius: 20px; padding: 0 7px; font-size: 11px; font-weight: 700; margin-left: 6px; }

.chat-main { flex: 1; display: flex; flex-direction: column; background: #f0f2f5; min-width: 0; }
.chat-empty { flex: 1; display: flex; align-items: center; justify-content: center; color: var(--muted); text-align: center; }
.chat-empty-icon { font-size: 48px; margin-bottom: 10px; }
.chat-thread { flex: 1; display: flex; flex-direction: column; min-height: 0; }
.chat-header { background: #fff; padding: 12px 18px; border-bottom: 1px solid var(--border); display: flex; justify-content: space-between; align-items: center; }
.chat-name { font-weight: 600; font-size: 15px; }
.chat-header-actions { display: flex; gap: 8px; align-items: center; }
.chat-messages { flex: 1; overflow-y: auto; padding: 20px; display: flex; flex-direction: column; gap: 8px; }
.msg { max-width: 65%; padding: 8px 12px; border-radius: 10px; font-size: 14px; position: relative; word-wrap: break-word; }
.msg.in { background: #fff; align-self: flex-start; border-top-left-radius: 2px; }
.msg.out { background: #d9fdd3; align-self: flex-end; border-top-right-radius: 2px; }
.msg .msg-meta { font-size: 10px; color: var(--muted); margin-top: 3px; text-align: right; }
.msg img { max-width: 240px; border-radius: 8px; display: block; cursor: pointer; }
.msg audio { max-width: 240px; }
.msg .msg-doc { display: flex; align-items: center; gap: 6px; color: var(--primary-dark); text-decoration: none; }
.msg.error { border: 1px solid var(--danger); }
.chat-composer { background: #fff; padding: 10px 14px; border-top: 1px solid var(--border); display: flex; gap: 8px; align-items: center; }
.chat-composer input[type="text"] { flex: 1; padding: 11px 14px; border: 1px solid var(--border); border-radius: 20px; font-size: 14px; }
.chat-attach { font-size: 22px; cursor: pointer; padding: 0 4px; }
.day-sep { text-align: center; color: var(--muted); font-size: 12px; margin: 6px 0; }

/* ---------- Personalização / branding ---------- */
.brand-logo { height: 28px; max-width: 150px; object-fit: contain; vertical-align: middle; }
.login-logo img { max-height: 60px; max-width: 200px; object-fit: contain; }
.logo-box { display: flex; align-items: center; gap: 12px; margin-top: 6px; }
.logo-preview { height: 48px; max-width: 160px; object-fit: contain; border: 1px solid var(--border); border-radius: 8px; padding: 4px; background: #fff; }

/* ---------- Conexão WhatsApp ---------- */
.conn-panel { max-width: 560px; }
.conn-status { display: flex; gap: 10px; align-items: center; margin: 18px 0; font-size: 15px; }
.conn-box { margin-top: 16px; padding: 18px; border: 1px solid var(--border); border-radius: 12px; background: #f8fafc; }
.conn-ok { color: var(--success); font-weight: 600; font-size: 16px; margin-bottom: 14px; }
.qr-area { margin: 18px 0; text-align: center; }
.qr-area img { width: 260px; height: 260px; border: 1px solid var(--border); border-radius: 12px; background: #fff; padding: 8px; }
.qr-area .muted { margin-top: 10px; }

/* ---------- Respostas rápidas ---------- */
.qr-wrap { position: relative; }
.quick-popup {
  position: absolute; bottom: 44px; left: 0; width: 320px; max-height: 320px; overflow-y: auto;
  background: #fff; border: 1px solid var(--border); border-radius: 10px; box-shadow: 0 10px 30px rgba(0,0,0,.2); z-index: 20;
}
.quick-item { padding: 10px 12px; border-bottom: 1px solid #f1f5f9; cursor: pointer; }
.quick-item:hover { background: #eef2ff; }
.quick-item .qi-title { font-weight: 600; font-size: 13px; }
.quick-item .qi-text { color: var(--muted); font-size: 12px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.quick-manage { padding: 10px 12px; text-align: center; color: var(--primary); cursor: pointer; font-size: 13px; font-weight: 600; position: sticky; bottom: 0; background: #fff; border-top: 1px solid var(--border); }
.qr-form { display: flex; flex-direction: column; gap: 8px; margin-top: 14px; border-top: 1px solid var(--border); padding-top: 14px; }
.qr-form input, .qr-form textarea { width: 100%; padding: 9px 11px; border: 1px solid var(--border); border-radius: 8px; font-family: inherit; font-size: 14px; }
.qr-row { display: flex; justify-content: space-between; align-items: flex-start; gap: 10px; padding: 10px 0; border-bottom: 1px solid #f1f5f9; }
.qr-row .qr-actions { display: flex; gap: 6px; flex-shrink: 0; }
.fu-overdue { color: var(--danger); font-weight: 600; }
.fu-today { color: #f59e0b; font-weight: 600; }

@media (max-width: 900px) {
  .grid-2 { grid-template-columns: 1fr; }
  .modal-grid { grid-template-columns: 1fr; }
  .sidebar { width: 64px; }
  .brand span, .nav-item span, .user-name, .sidebar-footer .btn, .user-badge > div:last-child { display: none; }
  .content { margin-left: 64px; }
}
