/* The Digi Monk WhatsApp CRM */
:root {
  --primary: #FE761F;
  --ink: #23272b;
  --ink-2: #454A4E;
  --muted: #6b7280;
  --line: #e6e8eb;
  --bg: #f5f6f8;
  --card: #ffffff;
  --ok: #16a34a;
  --warn: #d97706;
  --bad: #dc2626;
  --info: #2563eb;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(16,24,40,.06), 0 1px 3px rgba(16,24,40,.08);
}
* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body { font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Noto Sans", "Helvetica Neue", Arial, sans-serif; font-size: 14px; color: var(--ink); background: var(--bg); line-height: 1.45; }
a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3, h4 { margin: 0 0 .6em; line-height: 1.25; }
h2 { font-size: 18px; } h3 { font-size: 15px; }
code { background: #f1f2f4; padding: 2px 6px; border-radius: 6px; font-size: 12.5px; word-break: break-all; }
.muted { color: var(--muted); } .small { font-size: 12.5px; }
.right { text-align: right; } .nowrap { white-space: nowrap; }
hr { border: 0; border-top: 1px solid var(--line); margin: 18px 0; }

/* ---------- layout ---------- */
.app { display: flex; min-height: 100vh; }
.sidebar { width: 240px; background: #fff; border-right: 1px solid var(--line); display: flex; flex-direction: column; position: fixed; inset: 0 auto 0 0; z-index: 40; transition: transform .2s; }
.sidebar-brand { padding: 18px 18px 10px; border-bottom: 1px solid var(--line); }
.sidebar-brand img { max-width: 100%; max-height: 48px; display: block; }
.sidebar nav { flex: 1; overflow-y: auto; padding: 8px 10px; }
.nav-head { font-size: 11px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); padding: 12px 10px 4px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.nav-link { display: flex; align-items: center; gap: 10px; padding: 7px 10px; border-radius: 8px; color: var(--ink-2); font-weight: 500; }
.nav-link:hover { background: #f4f5f7; text-decoration: none; }
.nav-link.active { background: color-mix(in srgb, var(--primary) 12%, white); color: var(--ink); }
.nav-link.active .nav-icon { filter: none; }
.nav-icon { width: 20px; text-align: center; }
.nav-badge { margin-left: auto; background: var(--primary); color: #fff; font-size: 11px; font-weight: 700; border-radius: 999px; padding: 1px 7px; }
.sidebar-foot { border-top: 1px solid var(--line); padding: 8px 10px; }
.sidebar-backdrop { display: none; }
.main { flex: 1; margin-left: 240px; min-width: 0; display: flex; flex-direction: column; }
.topbar { height: 60px; background: #fff; border-bottom: 1px solid var(--line); display: flex; align-items: center; gap: 12px; padding: 0 20px; position: sticky; top: 0; z-index: 30; }
.page-title { font-size: 18px; margin: 0; flex: 1; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.menu-btn { display: none; }
.user-chip { display: flex; align-items: center; gap: 8px; }
.user-meta { display: flex; flex-direction: column; line-height: 1.15; }
.user-meta small { color: var(--muted); font-size: 11.5px; }
.content { padding: 20px; flex: 1; min-width: 0; }
.ws-banner { background: #fff7ed; border-bottom: 1px solid #fed7aa; padding: 8px 20px; font-size: 13px; }
.flash-wrap { padding: 0 20px; }
.flash-wrap:empty { display: none; }
.flash-wrap .alert { margin-top: 14px; }

/* ---------- components ---------- */
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); padding: 18px; margin-bottom: 18px; }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 14px; flex-wrap: wrap; }
.card-head h2, .card-head h3 { margin: 0; }
.grid { display: grid; gap: 18px; }
.grid-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.grid-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.stat { background: #fff; border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; box-shadow: var(--shadow); }
.stat .num { font-size: 26px; font-weight: 700; }
.stat .lbl { color: var(--muted); font-size: 13px; }

.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; border: 1px solid var(--line); background: #fff; color: var(--ink); padding: 8px 14px; border-radius: 8px; font-size: 14px; font-weight: 600; cursor: pointer; text-decoration: none; line-height: 1.2; white-space: nowrap; }
.btn:hover { background: #f6f7f9; text-decoration: none; }
.btn-primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn-primary:hover { background: color-mix(in srgb, var(--primary) 88%, black); }
.btn-danger { color: var(--bad); border-color: #fecaca; }
.btn-danger:hover { background: #fef2f2; }
.btn-sm { padding: 5px 10px; font-size: 12.5px; }
.btn-block { width: 100%; }
.btn[disabled] { opacity: .5; cursor: not-allowed; }
.icon-btn { background: none; border: 0; font-size: 20px; cursor: pointer; padding: 6px; border-radius: 8px; color: var(--ink-2); }
.icon-btn:hover { background: #f1f2f4; }
.actions { display: flex; gap: 6px; flex-wrap: wrap; align-items: center; }

label { display: block; font-weight: 600; font-size: 13px; margin-bottom: 12px; color: var(--ink-2); }
input[type=text], input[type=search], input[type=email], input[type=password], input[type=number], input[type=tel], input[type=date], input[type=datetime-local], input[type=url], input:not([type]), select, textarea {
  display: block; width: 100%; margin-top: 5px; padding: 9px 11px; border: 1px solid #d4d7dc; border-radius: 8px; font: inherit; font-weight: 400; color: var(--ink); background: #fff;
}
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px color-mix(in srgb, var(--primary) 18%, transparent); }
input[type=color] { width: 60px; height: 38px; padding: 2px; border: 1px solid #d4d7dc; border-radius: 8px; margin-top: 5px; display: block; }
input[type=checkbox] { width: 16px; height: 16px; vertical-align: middle; margin-right: 6px; }
.check { font-weight: 500; display: flex; align-items: center; }
.hint { font-weight: 400; color: var(--muted); font-size: 12px; margin-top: 4px; display: block; }
.form-row { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 0 14px; }
.inline-form { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.inline-form input, .inline-form select { margin-top: 0; width: auto; }

table { width: 100%; border-collapse: collapse; }
.table-wrap { overflow-x: auto; }
th, td { text-align: left; padding: 10px 10px; border-bottom: 1px solid var(--line); vertical-align: middle; }
th { font-size: 12px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); font-weight: 600; background: #fafbfc; }
tr:hover td { background: #fcfcfd; }

.badge { display: inline-block; padding: 2px 8px; border-radius: 999px; font-size: 11.5px; font-weight: 600; background: #eef0f3; color: var(--ink-2); white-space: nowrap; }
.badge-ok { background: #dcfce7; color: #166534; } .badge-warn { background: #fef3c7; color: #92400e; } .badge-bad { background: #fee2e2; color: #991b1b; } .badge-info { background: #dbeafe; color: #1e40af; }
.tag { display: inline-block; background: #f1f2f4; border-radius: 6px; padding: 1px 7px; font-size: 12px; margin: 1px 2px 1px 0; }

.alert { padding: 11px 14px; border-radius: 8px; margin-bottom: 14px; border: 1px solid; position: relative; padding-right: 34px; }
.alert-success { background: #f0fdf4; border-color: #bbf7d0; color: #14532d; }
.alert-error { background: #fef2f2; border-color: #fecaca; color: #7f1d1d; }
.alert-info { background: #eff6ff; border-color: #bfdbfe; color: #1e3a8a; }
.alert-warn { background: #fffbeb; border-color: #fde68a; color: #78350f; }
.alert-x { position: absolute; right: 8px; top: 6px; border: 0; background: none; font-size: 18px; cursor: pointer; color: inherit; opacity: .6; }

.avatar { width: 38px; height: 38px; border-radius: 50%; background: color-mix(in srgb, var(--primary) 18%, white); color: var(--ink); display: inline-flex; align-items: center; justify-content: center; font-weight: 700; font-size: 13px; flex: none; }
.avatar.sm { width: 30px; height: 30px; font-size: 11.5px; }
.empty { text-align: center; color: var(--muted); padding: 36px 12px; }
.empty .big { font-size: 36px; display: block; margin-bottom: 8px; }
.copy-row { display: flex; gap: 8px; align-items: center; margin: 6px 0 14px; }
.copy-row code { flex: 1; padding: 9px 10px; }
.steps { padding-left: 20px; } .steps li { margin-bottom: 8px; }
.pager { display: flex; gap: 6px; justify-content: flex-end; margin-top: 14px; align-items: center; }

/* modal */
.modal { position: fixed; inset: 0; background: rgba(15,23,42,.45); display: none; align-items: flex-start; justify-content: center; z-index: 100; padding: 6vh 14px; overflow-y: auto; }
.modal.open { display: flex; }
.modal-box { background: #fff; border-radius: 12px; width: 100%; max-width: 520px; padding: 20px; box-shadow: 0 20px 50px rgba(0,0,0,.25); }
.modal-box.wide { max-width: 720px; }
.modal-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 12px; }
.modal-head h3 { margin: 0; }

/* ---------- auth ---------- */
.auth-body { display: flex; align-items: flex-start; justify-content: center; min-height: 100vh; padding: 8vh 14px; background: linear-gradient(160deg, color-mix(in srgb, var(--primary) 10%, white), var(--bg) 50%); }
.auth-card, .install-card { background: #fff; width: 100%; max-width: 400px; border-radius: 14px; padding: 28px; box-shadow: 0 10px 40px rgba(16,24,40,.10); border: 1px solid var(--line); }
.install-card { max-width: 560px; }
.auth-logo { max-width: 240px; max-height: 70px; display: block; margin: 0 auto 18px; }
.auth-card h1, .install-card h1 { font-size: 20px; text-align: center; }
.install-card h3 { margin-top: 22px; }
.checks { list-style: none; padding: 0; margin: 0 0 14px; }
.checks li { padding: 4px 0; } .checks .ok { color: var(--ok); } .checks .bad { color: var(--bad); font-weight: 600; }

/* ---------- inbox ---------- */
.page-inbox .content { padding: 0; }
.inbox { display: grid; grid-template-columns: 330px minmax(0, 1fr) 300px; height: calc(100vh - 60px); background: #fff; }
.has-banner .inbox { height: calc(100vh - 96px); }
.inbox-list { border-right: 1px solid var(--line); display: flex; flex-direction: column; min-height: 0; }
.inbox-tools { padding: 12px; border-bottom: 1px solid var(--line); }
.inbox-tools input { margin-top: 0; }
.filters { display: flex; gap: 4px; margin-top: 8px; flex-wrap: wrap; }
.filters button { border: 1px solid var(--line); background: #fff; border-radius: 999px; padding: 4px 10px; font-size: 12.5px; cursor: pointer; font-weight: 600; color: var(--ink-2); }
.filters button.on { background: var(--primary); color: #fff; border-color: var(--primary); }
.conv-list { flex: 1; overflow-y: auto; }
.conv { display: flex; gap: 10px; padding: 11px 12px; border-bottom: 1px solid #f1f2f4; cursor: pointer; }
.conv:hover { background: #fafafa; }
.conv.active { background: color-mix(in srgb, var(--primary) 9%, white); }
.conv-body { flex: 1; min-width: 0; }
.conv-top { display: flex; justify-content: space-between; gap: 6px; }
.conv-name { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.conv-time { font-size: 11.5px; color: var(--muted); white-space: nowrap; }
.conv-prev { color: var(--muted); font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; display: flex; gap: 6px; justify-content: space-between; }
.conv-prev span:first-child { overflow: hidden; text-overflow: ellipsis; }
.unread { background: var(--ok); color: #fff; border-radius: 999px; font-size: 11px; font-weight: 700; padding: 0 7px; flex: none; }
.chat { display: flex; flex-direction: column; min-height: 0; min-width: 0; background: #efeae2; }
.chat-head { background: #fff; border-bottom: 1px solid var(--line); padding: 10px 14px; display: flex; align-items: center; gap: 10px; }
.chat-head .who { flex: 1; min-width: 0; }
.chat-head .who strong, .chat-head .who span { display: block; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.chat-head select { width: auto; margin: 0; padding: 6px 8px; font-size: 13px; }
.back-btn { display: none; }
.msgs { flex: 1; overflow-y: auto; padding: 16px 6%; }
.msg { max-width: 72%; margin: 4px 0; padding: 7px 10px 5px; border-radius: 9px; background: #fff; box-shadow: 0 1px 1px rgba(0,0,0,.08); word-wrap: break-word; white-space: pre-wrap; position: relative; clear: both; }
.msg.out { background: #d9fdd3; margin-left: auto; }
.msg-row { display: flex; } .msg-row.out { justify-content: flex-end; }
.msg .meta { font-size: 10.5px; color: #667781; text-align: right; margin-top: 2px; white-space: nowrap; }
.msg .meta .tick.read { color: #53bdeb; }
.msg .err { color: var(--bad); font-size: 11.5px; white-space: normal; margin-top: 3px; }
.msg img { max-width: 260px; max-height: 300px; border-radius: 6px; display: block; margin-bottom: 4px; cursor: pointer; }
.msg audio, .msg video { max-width: 260px; display: block; }
.msg .tpl-label { font-size: 11px; color: var(--muted); display: block; margin-bottom: 2px; }
.day-sep { text-align: center; margin: 12px 0; } .day-sep span { background: #fff; font-size: 11.5px; padding: 3px 10px; border-radius: 8px; color: var(--muted); box-shadow: 0 1px 1px rgba(0,0,0,.06); }
.composer { background: #f0f2f5; padding: 10px; border-top: 1px solid var(--line); }
.composer-row { display: flex; gap: 8px; align-items: flex-end; }
.composer textarea { margin: 0; resize: none; min-height: 42px; max-height: 140px; border-radius: 20px; padding: 10px 14px; }
.composer .icon-btn { font-size: 20px; }
.window-note { background: #fff7ed; border: 1px solid #fed7aa; color: #9a3412; padding: 8px 12px; border-radius: 8px; margin-bottom: 8px; font-size: 13px; display: flex; gap: 8px; align-items: center; justify-content: space-between; flex-wrap: wrap; }
.qr-pop { display: none; background: #fff; border: 1px solid var(--line); border-radius: 10px; margin-bottom: 8px; max-height: 200px; overflow-y: auto; }
.qr-pop.open { display: block; }
.qr-pop div { padding: 8px 12px; cursor: pointer; border-bottom: 1px solid #f1f2f4; }
.qr-pop div:hover { background: #fafafa; }
.chat-empty { flex: 1; display: flex; align-items: center; justify-content: center; text-align: center; color: var(--muted); padding: 20px; }
.side { border-left: 1px solid var(--line); overflow-y: auto; padding: 16px; }
.side h4 { font-size: 12px; text-transform: uppercase; color: var(--muted); letter-spacing: .05em; margin: 16px 0 8px; }
.note { background: #fffbeb; border: 1px solid #fde68a; border-radius: 8px; padding: 8px 10px; margin-bottom: 8px; font-size: 13px; white-space: pre-wrap; }
.note small { display: block; color: var(--muted); margin-top: 4px; }

/* ---------- pipeline ---------- */
.kanban { display: flex; gap: 14px; overflow-x: auto; padding-bottom: 10px; align-items: flex-start; }
.kcol { background: #eef0f3; border-radius: 10px; width: 270px; flex: none; display: flex; flex-direction: column; max-height: calc(100vh - 190px); }
.kcol-head { padding: 10px 12px; font-weight: 700; display: flex; align-items: center; gap: 8px; }
.kcol-head .dot { width: 10px; height: 10px; border-radius: 50%; }
.kcol-head .count { margin-left: auto; color: var(--muted); font-weight: 600; font-size: 12.5px; }
.kcol-body { padding: 0 8px 8px; overflow-y: auto; min-height: 60px; flex: 1; }
.kcol.drag-over { outline: 2px dashed var(--primary); }
.kcard { background: #fff; border-radius: 8px; padding: 10px; margin-bottom: 8px; box-shadow: var(--shadow); cursor: grab; border-left: 3px solid transparent; }
.kcard:active { cursor: grabbing; }
.kcard strong { display: block; }
.kcard .row { display: flex; justify-content: space-between; color: var(--muted); font-size: 12px; margin-top: 4px; gap: 6px; }
.kcard.dragging { opacity: .5; }

/* ---------- responsive ---------- */
@media (max-width: 1200px) {
  .inbox { grid-template-columns: 300px minmax(0, 1fr); }
  .side { display: none; }
  .inbox.show-side .side { display: block; position: fixed; right: 0; top: 60px; bottom: 0; width: 300px; background: #fff; z-index: 35; box-shadow: -10px 0 30px rgba(0,0,0,.1); }
}
@media (max-width: 900px) {
  .grid-4 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .grid-3, .grid-2 { grid-template-columns: 1fr; }
}
@media (max-width: 800px) {
  .sidebar { transform: translateX(-100%); }
  .sidebar.open { transform: none; box-shadow: 10px 0 30px rgba(0,0,0,.15); }
  .sidebar-backdrop.open { display: block; position: fixed; inset: 0; background: rgba(0,0,0,.3); z-index: 39; }
  .main { margin-left: 0; }
  .menu-btn { display: inline-block; }
  .user-meta { display: none; }
  .content { padding: 14px; }
  .form-row { grid-template-columns: 1fr; }
  .inbox { grid-template-columns: 1fr; height: calc(100vh - 60px); }
  .inbox .chat { display: none; }
  .inbox.chat-open .inbox-list { display: none; }
  .inbox.chat-open .chat { display: flex; }
  .back-btn { display: inline-block; }
  .msgs { padding: 12px; }
  .msg { max-width: 88%; }
  .chat-head { padding: 8px; gap: 6px; }
  .chat-head select { max-width: 104px; }
  .chat-head .avatar { display: none; }
  .hide-sm { display: none; }
}
