:root {
  --ink: #0a0a0a;
  --ink-soft: #404040;
  --muted: #737373;
  --line: #e5e5e5;
  --line-2: #f0f0f0;
  --soft: #f5f5f5;
  --app-bg: #fafafa;
  --panel: #ffffff;
  --accent: #0a0a0a;
  --danger: #dc2626;
  --radius: 12px;
  --radius-sm: 8px;
  --shadow: 0 1px 2px rgba(0,0,0,.04), 0 1px 3px rgba(0,0,0,.06);
  --shadow-lg: 0 10px 40px -12px rgba(0,0,0,.18);
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  font-family: 'Inter', system-ui, -apple-system, sans-serif;
  color: var(--ink);
  background: var(--app-bg);
  -webkit-font-smoothing: antialiased;
  font-size: 14px;
}
.hidden { display: none !important; }
.muted { color: var(--muted); }
.err { color: var(--danger); font-size: 13px; min-height: 18px; margin-top: 8px; }
code { background: var(--soft); padding: 2px 7px; border-radius: 5px; font-size: 12.5px; color: var(--ink); border: 1px solid var(--line); }

/* Inputs & buttons */
.input, textarea.input, select.input {
  width: 100%; padding: 9px 12px; border: 1px solid var(--line);
  border-radius: var(--radius-sm); font: inherit; background: #fff; color: var(--ink);
  outline: none; transition: border-color .15s, box-shadow .15s;
}
.input:focus { border-color: var(--ink); box-shadow: 0 0 0 3px rgba(10,10,10,.08); }
textarea.input { resize: vertical; min-height: 84px; }
label { display: block; font-size: 13px; font-weight: 600; margin: 14px 0 6px; color: var(--ink-soft); }
.btn {
  display: inline-flex; align-items: center; gap: 8px; justify-content: center;
  padding: 9px 16px; border-radius: var(--radius-sm); border: 1px solid var(--line);
  background: #fff; color: var(--ink); font: inherit; font-weight: 600; font-size: 14px;
  cursor: pointer; transition: background .15s, border-color .15s, opacity .15s;
}
.btn:hover { background: var(--soft); }
.btn-primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn-primary:hover { background: #262626; }
.btn-danger { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn-ghost { border-color: transparent; background: transparent; }
.btn-sm { padding: 6px 11px; font-size: 13px; }
.btn-block { width: 100%; margin-top: 18px; }

/* Login */
.login-wrap { min-height: 100vh; display: grid; place-items: center; background: var(--app-bg); padding: 20px; }
.login-card { background: #fff; padding: 36px 32px; border-radius: 16px; width: 100%; max-width: 360px; border: 1px solid var(--line); box-shadow: var(--shadow); }
.login-card .brand { font-size: 22px; margin-bottom: 2px; }
.login-card .muted { margin-top: 4px; margin-bottom: 6px; font-size: 13px; }

/* Brand */
.brand { font-weight: 700; font-size: 19px; display: flex; align-items: center; gap: 10px; letter-spacing: -.02em; color: var(--ink); }
.brand .logo { width: 30px; height: 30px; border-radius: 8px; background: var(--ink); display: grid; place-items: center; color: #fff; font-size: 14px; }

/* App layout */
.app { display: grid; grid-template-columns: 240px 1fr; height: 100vh; }
.sidebar { background: #fff; border-right: 1px solid var(--line); display: flex; flex-direction: column; padding: 18px 12px; }
.sidebar .brand { padding: 6px 10px 20px; }
.nav { display: flex; flex-direction: column; gap: 2px; flex: 1; }
.nav-item {
  display: flex; align-items: center; gap: 12px; padding: 9px 12px; border-radius: var(--radius-sm);
  color: var(--ink-soft); text-decoration: none; font-weight: 500; cursor: pointer; font-size: 14px;
  transition: background .12s, color .12s;
}
.nav-item i { width: 17px; text-align: center; font-size: 14px; color: var(--muted); }
.nav-item:hover { background: var(--soft); color: var(--ink); }
.nav-item.active { background: var(--ink); color: #fff; }
.nav-item.active i { color: #fff; }
.sidebar-foot { display: flex; align-items: center; gap: 8px; padding: 12px 10px 4px; border-top: 1px solid var(--line); font-size: 13px; margin-top: 6px; }
.dot { width: 8px; height: 8px; border-radius: 50%; display: inline-block; }
.dot-on { background: #16a34a; }
.dot-off { background: #a3a3a3; }
.dot-wait { background: #d97706; }
.badge { margin-left: auto; background: var(--ink); color: #fff; border-radius: 999px; font-size: 11px; padding: 1px 7px; font-weight: 700; }

.main { overflow: auto; }
.view { padding: 32px; max-width: 1080px; margin: 0 auto; }

/* Headings & cards */
.page-title { font-size: 24px; font-weight: 700; margin: 0 0 4px; letter-spacing: -.02em; }
.page-sub { color: var(--muted); margin: 0 0 26px; font-size: 14px; }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 22px; box-shadow: var(--shadow); margin-bottom: 16px; }
.card h3 { margin: 0 0 4px; font-size: 15px; font-weight: 700; }
.card .hint { color: var(--muted); font-size: 13px; margin: 0 0 14px; }
.row { display: flex; gap: 14px; flex-wrap: wrap; }
.row > * { flex: 1; min-width: 200px; }

/* Stats */
.stats { display: grid; grid-template-columns: repeat(4, 1fr); gap: 14px; margin-bottom: 20px; }
.stat { background: #fff; border: 1px solid var(--line); border-radius: var(--radius); padding: 18px; box-shadow: var(--shadow); }
.stat .n { font-size: 28px; font-weight: 700; letter-spacing: -.03em; }
.stat .l { color: var(--muted); font-size: 13px; margin-top: 2px; }

/* Toggle switch */
.switch { position: relative; display: inline-block; width: 42px; height: 24px; }
.switch input { display: none; }
.slider { position: absolute; inset: 0; background: #d4d4d4; border-radius: 999px; transition: .2s; cursor: pointer; }
.slider::before { content: ""; position: absolute; height: 18px; width: 18px; left: 3px; top: 3px; background: #fff; border-radius: 50%; transition: .2s; box-shadow: 0 1px 2px rgba(0,0,0,.25); }
.switch input:checked + .slider { background: var(--ink); }
.switch input:checked + .slider::before { transform: translateX(18px); }
.field-inline { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 10px 0; }

/* QR */
.qr-box { display: flex; flex-direction: column; align-items: center; gap: 12px; padding: 12px; }
.qr-box img { width: 250px; height: 250px; border: 1px solid var(--line); border-radius: 12px; background: #fff; padding: 8px; }
.status-pill { display: inline-flex; align-items: center; gap: 8px; padding: 6px 13px; border-radius: 999px; font-size: 13px; font-weight: 600; border: 1px solid var(--line); }
.pill-on { background: #f0fdf4; color: #15803d; border-color: #bbf7d0; }
.pill-off { background: var(--soft); color: var(--muted); }
.pill-wait { background: #fffbeb; color: #b45309; border-color: #fde68a; }

/* Conversations */
.conv { display: grid; grid-template-columns: 320px 1fr; height: calc(100vh - 64px); background: #fff; border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; box-shadow: var(--shadow); }
.conv-list { border-right: 1px solid var(--line); overflow-y: auto; }
.conv-item { display: flex; gap: 12px; padding: 13px 14px; border-bottom: 1px solid var(--line-2); cursor: pointer; transition: background .12s; }
.conv-item:hover { background: var(--soft); }
.conv-item.active { background: var(--soft); box-shadow: inset 2px 0 0 var(--ink); }
.conv-av { width: 40px; height: 40px; border-radius: 50%; background: var(--ink); color: #fff; display: grid; place-items: center; font-weight: 600; flex-shrink: 0; font-size: 14px; }
.conv-meta { min-width: 0; flex: 1; }
.conv-name { font-weight: 600; font-size: 14px; display: flex; justify-content: space-between; gap: 8px; align-items: center; }
.conv-last { color: var(--muted); font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; margin-top: 2px; }
.tag { font-size: 11px; font-weight: 600; padding: 2px 9px; border-radius: 999px; border: 1px solid var(--line); background: #fff; color: var(--ink-soft); }
.tag-bot { background: var(--soft); color: var(--muted); }
.tag-humano { background: var(--ink); color: #fff; border-color: var(--ink); }
.tag-resolvido { background: #fff; color: var(--muted); }

.chat { display: flex; flex-direction: column; height: 100%; }
.chat-head { display: flex; align-items: center; gap: 12px; padding: 12px 16px; border-bottom: 1px solid var(--line); background: #fff; }
.chat-head .grow { flex: 1; min-width: 0; }
.chat-msgs { flex: 1; overflow-y: auto; padding: 20px; background: var(--app-bg); display: flex; flex-direction: column; gap: 8px; }
.msg { max-width: 70%; padding: 9px 13px; border-radius: 12px; font-size: 14px; line-height: 1.45; white-space: pre-wrap; word-wrap: break-word; }
.msg-customer { align-self: flex-start; background: #fff; border: 1px solid var(--line); border-bottom-left-radius: 3px; }
.msg-ai, .msg-bot { align-self: flex-end; background: var(--ink); color: #fff; border-bottom-right-radius: 3px; }
.msg-agent { align-self: flex-end; background: #fff; border: 1px solid var(--ink); color: var(--ink); border-bottom-right-radius: 3px; }
.msg .who { font-size: 10px; font-weight: 700; opacity: .55; text-transform: uppercase; margin-bottom: 3px; letter-spacing: .04em; }
.chat-input { display: flex; gap: 8px; padding: 12px; border-top: 1px solid var(--line); background: #fff; }
.chat-empty { display: grid; place-items: center; height: 100%; color: var(--muted); text-align: center; }

.toast { position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%); background: var(--ink); color: #fff; padding: 11px 20px; border-radius: 999px; font-size: 14px; font-weight: 500; box-shadow: var(--shadow-lg); z-index: 200; }
.toast.err { background: var(--danger); }

/* Modal */
.modal-overlay { position: fixed; inset: 0; background: rgba(10,10,10,.45); display: grid; place-items: center; z-index: 100; padding: 20px; animation: fadeIn .12s ease; }
.modal { background: #fff; border-radius: 16px; width: 100%; max-width: 540px; max-height: 90vh; display: flex; flex-direction: column; box-shadow: var(--shadow-lg); animation: pop .15s ease; overflow: hidden; }
.modal-head { display: flex; align-items: center; justify-content: space-between; padding: 18px 22px; border-bottom: 1px solid var(--line); }
.modal-head h3 { margin: 0; font-size: 17px; font-weight: 700; }
.modal-close { border: none; background: var(--soft); width: 32px; height: 32px; border-radius: 8px; cursor: pointer; color: var(--muted); font-size: 15px; transition: .12s; }
.modal-close:hover { background: #e5e5e5; color: var(--ink); }
.modal-body { padding: 18px 22px; overflow-y: auto; }
.modal-body label:first-child { margin-top: 0; }
.modal-foot { display: flex; gap: 10px; justify-content: flex-end; padding: 14px 22px; border-top: 1px solid var(--line); background: var(--app-bg); }
.msg-row { display: flex; gap: 8px; margin-bottom: 8px; align-items: flex-start; }
.msg-row .num { width: 22px; height: 38px; display: grid; place-items: center; color: var(--muted); font-weight: 700; font-size: 13px; }
.msg-row textarea { min-height: 54px; }
.icon-btn { border: 1px solid var(--line); background: #fff; width: 38px; height: 38px; border-radius: 8px; cursor: pointer; color: var(--muted); flex-shrink: 0; transition: .12s; }
.icon-btn:hover { background: var(--soft); color: var(--ink); }
.link-add { display: inline-flex; align-items: center; gap: 8px; background: #fff; color: var(--ink); border: 1px dashed #d4d4d4; padding: 10px 14px; border-radius: 8px; font-weight: 600; font-size: 13px; cursor: pointer; width: 100%; justify-content: center; margin-top: 4px; }
.link-add:hover { background: var(--soft); }
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
@keyframes pop { from { opacity: 0; transform: translateY(8px) scale(.98); } to { opacity: 1; transform: none; } }

/* Flow list */
.flow-row { display: flex; align-items: center; gap: 14px; }
.flow-row .grow { flex: 1; min-width: 0; }
.flow-actions { display: flex; align-items: center; gap: 10px; }

@media (max-width: 820px) {
  .app { grid-template-columns: 1fr; }
  .sidebar { flex-direction: row; align-items: center; overflow-x: auto; border-right: none; border-bottom: 1px solid var(--line); }
  .sidebar .brand { padding: 0 10px 0 4px; }
  .nav { flex-direction: row; }
  .sidebar-foot { display: none; }
  .stats { grid-template-columns: repeat(2, 1fr); }
  .conv { grid-template-columns: 1fr; height: auto; }
  .view { padding: 20px; }
}
