:root {
  --bg: #f3eee6;
  --surface: #ffffff;
  --surface-alt: #f9f6f1;
  --ink: #0c1211;
  --muted: #5b6360;
  --border: #e2dacd;
  --accent: #f08a24;
  --accent-hover: #d97614;
  --accent-soft: #fdf0e2;
  --success: #1b7a4b;
  --success-soft: #e6f4ec;
  --danger: #b42318;
  --danger-soft: #fef3f2;
  --warning: #b54708;
  --warning-soft: #fffaeb;
  --radius: 12px;
  --shadow: 0 6px 24px rgba(12, 18, 17, 0.08);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
  background: var(--bg);
  color: var(--ink);
  line-height: 1.45;
}

h1, h2, h3 {
  margin: 0 0 6px;
  font-family: 'Instrument Serif', Georgia, serif;
  font-weight: 400;
  letter-spacing: -0.01em;
}

h1 { font-size: 2rem; }
h2 { font-size: 1.55rem; }
h3 { font-size: 1.2rem; }

.hidden { display: none !important; }
.muted { color: var(--muted); }
.small { font-size: 0.82rem; }

/* Buttons & Inputs */
button, input, select, textarea {
  font-family: inherit;
  font-size: 0.92rem;
}

input, select, textarea {
  width: 100%;
  padding: 9px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
  color: var(--ink);
}

input:focus, select:focus, textarea:focus {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}

.btn {
  border: 1px solid transparent;
  border-radius: 8px;
  padding: 8px 14px;
  font-weight: 500;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  transition: background 0.15s, border-color 0.15s;
}

.btn-sm { padding: 6px 10px; font-size: 0.82rem; }
.btn-full { width: 100%; justify-content: center; }

.btn-primary {
  background: var(--accent);
  color: #fff;
}
.btn-primary:hover { background: var(--accent-hover); }

.btn-secondary {
  background: var(--surface);
  border-color: var(--border);
  color: var(--ink);
}
.btn-secondary:hover { background: var(--surface-alt); }

.btn-ghost {
  background: transparent;
  color: var(--ink);
}
.btn-ghost:hover { background: rgba(12, 18, 17, 0.06); }

.btn-danger-outline {
  background: transparent;
  border-color: #f3c4c0;
  color: var(--danger);
}
.btn-danger-outline:hover { background: var(--danger-soft); }

.btn-link {
  background: none;
  border: none;
  color: var(--accent-hover);
  cursor: pointer;
  font-size: 0.85rem;
  font-weight: 500;
}

/* Login */
.login-screen {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}

.login-card {
  width: 100%;
  max-width: 420px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 32px;
  box-shadow: var(--shadow);
}

.brand-mark {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 12px;
}

.brand-dot {
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: var(--accent);
  flex-shrink: 0;
}

.brand-eyebrow {
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  color: var(--muted);
}

.login-desc {
  color: var(--muted);
  font-size: 0.9rem;
  margin-bottom: 20px;
}

#login-form label {
  display: block;
  font-size: 0.85rem;
  font-weight: 500;
  margin-bottom: 6px;
}

#login-form input {
  margin-bottom: 14px;
}

.error-msg {
  margin-top: 10px;
  color: var(--danger);
  background: var(--danger-soft);
  padding: 8px 10px;
  border-radius: 8px;
  font-size: 0.85rem;
}

/* Topbar */
.topbar {
  background: var(--ink);
  color: #fff;
  padding: 10px 20px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
}

.topbar-left, .topbar-right {
  display: flex;
  align-items: center;
  gap: 14px;
  flex-wrap: wrap;
}

.brand-inline {
  display: flex;
  align-items: center;
  gap: 10px;
}

.brand-title {
  display: block;
  font-family: 'Instrument Serif', Georgia, serif;
  font-size: 1.3rem;
  line-height: 1.1;
}

.brand-sub {
  display: block;
  font-size: 0.72rem;
  color: #b5bdb9;
}

.tabs {
  display: flex;
  gap: 4px;
  margin-left: 10px;
}

.tab-btn {
  background: transparent;
  border: none;
  color: #c8cfcc;
  padding: 7px 12px;
  border-radius: 8px;
  cursor: pointer;
  font-weight: 500;
}

.tab-btn:hover { background: rgba(255, 255, 255, 0.08); color: #fff; }
.tab-btn.active { background: var(--accent); color: #fff; }

.topbar .btn-ghost { color: #e5e8e6; }
.topbar .btn-ghost:hover { background: rgba(255, 255, 255, 0.1); }

.status-pill {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 5px 11px;
  border-radius: 999px;
  font-size: 0.8rem;
  font-weight: 500;
  background: rgba(255, 255, 255, 0.09);
}

.pill-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #f04438;
}

.status-online .pill-dot { background: #12b76a; }
.status-connecting .pill-dot { background: var(--accent); }

.badge {
  background: var(--accent);
  color: #fff;
  font-size: 0.74rem;
  font-weight: 700;
  padding: 1px 6px;
  border-radius: 999px;
}

/* Main */
.main-content {
  padding: 18px 20px 36px;
  max-width: 1600px;
  margin: 0 auto;
}

.tab-panel { display: none; }
.tab-panel.active { display: block; }

.toolbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 14px;
  margin-bottom: 16px;
  flex-wrap: wrap;
}

.filters {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  flex: 1;
}

.filters input { max-width: 280px; }
.filters select { max-width: 200px; }

.summary-kpis {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
}

.kpi-chip {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 6px 12px;
  font-size: 0.82rem;
}

/* Kanban */
.kanban-board {
  display: grid;
  grid-template-columns: repeat(4, minmax(260px, 1fr));
  gap: 14px;
  align-items: start;
}

@media (max-width: 1120px) {
  .kanban-board {
    grid-template-columns: repeat(2, minmax(260px, 1fr));
  }
}

@media (max-width: 680px) {
  .kanban-board {
    grid-template-columns: 1fr;
  }
}

.kanban-col {
  background: var(--surface-alt);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px;
  min-height: 460px;
  transition: border-color 0.15s, background 0.15s;
}

.kanban-col.drag-over {
  border-color: var(--accent);
  background: var(--accent-soft);
}

.kanban-col-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 10px;
  padding-bottom: 8px;
  border-bottom: 1px solid var(--border);
}

.kanban-col-title {
  font-weight: 600;
  font-size: 0.92rem;
}

.col-count {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 2px 8px;
  font-size: 0.78rem;
  font-weight: 600;
}

.kanban-cards {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.lead-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 11px 12px;
  cursor: pointer;
  transition: transform 0.1s, box-shadow 0.15s;
}

.lead-card:hover {
  transform: translateY(-1px);
  box-shadow: 0 4px 14px rgba(12, 18, 17, 0.08);
}

.lead-card-top {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 8px;
  margin-bottom: 4px;
}

.lead-name {
  font-weight: 600;
  font-size: 0.94rem;
}

.lead-meta {
  font-size: 0.8rem;
  color: var(--muted);
  margin-bottom: 6px;
}

.tag-row {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  margin-top: 6px;
}

.lead-card-footer {
  margin-top: 9px;
  padding-top: 8px;
  border-top: 1px solid var(--border);
  display: flex;
  justify-content: flex-start;
}

.wa-card-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 5px 10px;
  border-radius: 999px;
  font-size: 0.78rem;
  font-weight: 600;
  text-decoration: none;
  background: var(--success-soft);
  color: var(--success);
  border: 1px solid #abefc6;
  transition: background 0.15s, border-color 0.15s;
}

.wa-card-btn:hover {
  background: #d1f0df;
  border-color: #75d8a2;
}

.wa-drawer-link {
  color: var(--success);
  font-weight: 600;
  text-decoration: none;
}

.wa-drawer-link:hover {
  text-decoration: underline;
}

.tag {
  display: inline-block;
  padding: 2px 7px;
  border-radius: 999px;
  font-size: 0.73rem;
  font-weight: 500;
  background: var(--surface-alt);
  border: 1px solid var(--border);
  color: var(--ink);
}

.tag-accent { background: var(--accent-soft); border-color: #f7c796; color: #9a4f06; }
.tag-success { background: var(--success-soft); border-color: #abefc6; color: var(--success); }
.tag-danger { background: var(--danger-soft); border-color: #fecdca; color: var(--danger); }
.tag-warning { background: var(--warning-soft); border-color: #fedf89; color: var(--warning); }

/* Cards & Grids */
.grid-2 {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 18px;
}

@media (max-width: 900px) {
  .grid-2 { grid-template-columns: 1fr; }
}

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
}

.card-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 12px;
  margin-bottom: 14px;
}

.wa-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  margin: 12px 0;
}

.qr-box {
  margin-top: 14px;
  border: 1px dashed var(--border);
  border-radius: 10px;
  min-height: 240px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 18px;
  text-align: center;
  background: var(--surface-alt);
}

.qr-box img {
  max-width: 240px;
  border-radius: 8px;
  background: #fff;
  padding: 8px;
}

.group-current {
  background: var(--surface-alt);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px 12px;
}

.groups-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
  max-height: 300px;
  overflow-y: auto;
}

.group-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  padding: 9px 11px;
  border: 1px solid var(--border);
  border-radius: 8px;
}

/* Settings */
.settings-form {
  display: flex;
  flex-direction: column;
  gap: 12px;
  margin-top: 14px;
}

.toggle-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 14px;
  padding: 12px;
  border: 1px solid var(--border);
  border-radius: 10px;
  cursor: pointer;
}

.toggle-row input[type="checkbox"] {
  width: 20px;
  height: 20px;
  accent-color: var(--accent);
  flex-shrink: 0;
}

.quiet-hours-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

.saved-badge {
  color: var(--success);
  font-size: 0.86rem;
  font-weight: 600;
}

.timeline {
  display: flex;
  flex-direction: column;
  gap: 14px;
  margin-top: 12px;
}

.timeline-item {
  display: flex;
  gap: 12px;
  align-items: flex-start;
}

.timeline-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--accent);
  margin-top: 6px;
  flex-shrink: 0;
}

.divider {
  border: none;
  border-top: 1px solid var(--border);
  margin: 18px 0;
}

/* Funnel Grid */
.funnel-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: 12px;
}

.funnel-card {
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 12px;
  background: var(--surface-alt);
}

.funnel-card-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 6px;
  margin-bottom: 6px;
}

.funnel-card p {
  margin: 0;
  font-size: 0.83rem;
  color: var(--muted);
  white-space: pre-wrap;
}

/* Notifications */
.notif-popover {
  position: fixed;
  top: 58px;
  right: 20px;
  width: 360px;
  max-width: calc(100vw - 32px);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  z-index: 60;
  overflow: hidden;
}

.notif-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 12px 14px;
  border-bottom: 1px solid var(--border);
}

.notif-list {
  max-height: 360px;
  overflow-y: auto;
}

.notif-item {
  padding: 10px 14px;
  border-bottom: 1px solid var(--border);
  font-size: 0.85rem;
}

.notif-item.unread {
  background: var(--accent-soft);
}

/* Drawer & Modal */
.drawer-backdrop, .modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(12, 18, 17, 0.5);
  z-index: 80;
  display: flex;
  justify-content: flex-end;
}

.modal-backdrop {
  justify-content: center;
  align-items: center;
  padding: 20px;
}

.modal-card {
  background: var(--surface);
  border-radius: var(--radius);
  width: 100%;
  max-width: 480px;
  padding: 22px;
  box-shadow: var(--shadow);
}

.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 14px;
}

.drawer {
  width: 100%;
  max-width: 980px;
  background: var(--surface);
  height: 100%;
  display: flex;
  flex-direction: column;
  box-shadow: var(--shadow);
}

.drawer-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  padding: 16px 22px;
  border-bottom: 1px solid var(--border);
  background: var(--surface-alt);
}

.drawer-body {
  flex: 1;
  overflow: hidden;
  display: grid;
  grid-template-columns: 1fr 1fr;
}

@media (max-width: 820px) {
  .drawer-body {
    grid-template-columns: 1fr;
    overflow-y: auto;
  }
}

.drawer-col-info {
  padding: 18px 20px;
  overflow-y: auto;
  border-right: 1px solid var(--border);
}

.drawer-col-chat {
  display: flex;
  flex-direction: column;
  overflow: hidden;
  background: var(--surface-alt);
}

.bot-controls-card {
  background: var(--surface-alt);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 12px;
  margin-bottom: 16px;
}

.bot-status-line {
  display: flex;
  justify-content: space-between;
  margin-bottom: 4px;
}

.bot-btn-group {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 10px;
}

.edit-form {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.edit-form label {
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-size: 0.83rem;
  font-weight: 500;
}

.form-row-2 {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.form-actions {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  margin-top: 6px;
}

.dados-box {
  background: var(--surface-alt);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px;
  font-size: 0.8rem;
}

.dados-box pre {
  margin: 6px 0 0;
  white-space: pre-wrap;
  word-break: break-word;
}

.chat-header {
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
  background: var(--surface);
  display: flex;
  flex-direction: column;
}

.chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 14px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.msg-bubble {
  max-width: 85%;
  padding: 9px 12px;
  border-radius: 10px;
  font-size: 0.88rem;
  white-space: pre-wrap;
}

.msg-in {
  align-self: flex-start;
  background: var(--surface);
  border: 1px solid var(--border);
}

.msg-out {
  align-self: flex-end;
  background: #0c1211;
  color: #fff;
}

.msg-out.msg-human {
  background: #1b5e3c;
}

.msg-meta {
  font-size: 0.72rem;
  opacity: 0.72;
  margin-top: 4px;
}

.chat-send-form {
  padding: 12px;
  background: var(--surface);
  border-top: 1px solid var(--border);
  display: flex;
  gap: 8px;
  align-items: flex-end;
}

.chat-send-form textarea {
  resize: none;
}
