:root {
  --green: #2D6A4F; --green-muted: #EBF5ED; --bg: #F9FAFB; --card: #FFFFFF;
  --fg: #374151; --muted: #6B7280; --border: #E5E7EB; --user: #F3F4F6;
}
* { box-sizing: border-box; }
body { margin: 0; font-family: -apple-system, system-ui, 'Segoe UI', sans-serif;
       color: var(--fg); background: var(--bg); height: 100vh; }
button { font: inherit; cursor: pointer; }
.hidden { display: none !important; }

/* ── Login (index.html) ─────────────────────────────────────────────────── */
.login { height: 100vh; display: grid; place-items: center; }
.login-card { background: var(--card); border: 1px solid var(--border); border-radius: 14px;
              padding: 28px; width: 320px; box-shadow: 0 2px 8px rgba(0,0,0,.04); }
.login-card h1 { font-size: 18px; margin: 0 0 14px; }
.login-step p { color: var(--muted); font-size: 13px; margin: 0 0 14px; line-height: 1.4; }
.login-step input { width: 100%; padding: 10px 12px; margin-bottom: 10px; border: 1px solid var(--border);
                    border-radius: 10px; font-size: 14px; }
.phone-field { display: flex; align-items: stretch; margin-bottom: 10px; border: 1px solid var(--border);
               border-radius: 10px; overflow: hidden; }
.phone-field .cc { display: flex; align-items: center; padding: 0 12px; background: var(--bg);
                   color: var(--fg); font-size: 14px; border-right: 1px solid var(--border); }
.phone-field input { flex: 1; width: auto; margin: 0; border: none; border-radius: 0; }
.login-step button[type="submit"] { width: 100%; padding: 11px; background: var(--green); color: #fff;
                    border: none; border-radius: 10px; font-weight: 600; }
.login-step button[type="submit"]:disabled { background: var(--border); }
.login-step .link { display: block; width: 100%; margin-top: 10px; padding: 4px;
                    background: none; border: none; color: var(--muted); font-size: 13px; text-decoration: underline; }
.err { color: #DC2626; font-size: 13px; min-height: 18px; margin-top: 6px; }

/* ── Gate (not-an-agent / error, console.html) ──────────────────────────── */
.gate { height: 100vh; display: grid; place-items: center; }
.gate-card { background: var(--card); border: 1px solid var(--border); border-radius: 14px;
             padding: 28px; width: 360px; text-align: center; box-shadow: 0 2px 8px rgba(0,0,0,.04); }
.gate-card h1 { font-size: 18px; margin: 0 0 8px; }
.gate-card p { color: var(--muted); font-size: 14px; margin: 0 0 18px; line-height: 1.4; }
.gate-card button { padding: 10px 18px; background: var(--green); color: #fff; border: none;
                    border-radius: 10px; font-weight: 600; }

/* ── App shell (console.html) ───────────────────────────────────────────── */
.app { display: grid; grid-template-columns: 320px 1fr; height: 100vh; }
aside { border-right: 1px solid var(--border); background: var(--card);
        display: flex; flex-direction: column; min-width: 0; }
.topbar { padding: 12px 16px; border-bottom: 1px solid var(--border);
          display: flex; align-items: center; justify-content: space-between; }
.topbar b { font-size: 14px; }
.topbar .me { font-size: 11px; color: var(--muted); margin-top: 2px; }
.topbar button { background: none; border: none; color: var(--muted); font-size: 12px; }
.routing { display: flex; align-items: center; gap: 8px; padding: 8px 16px;
           border-bottom: 1px solid var(--border); font-size: 12px; color: var(--muted); }
.routing label { flex: none; }
.routing select { flex: 1; padding: 5px 8px; border: 1px solid var(--border); border-radius: 8px;
                  font-size: 12px; background: var(--card); color: var(--fg); }
/* Open / Resolved thread-list filter. */
.status-tabs { display: flex; gap: 4px; padding: 8px 16px; border-bottom: 1px solid var(--border); }
.status-tab { flex: 1; padding: 6px 0; font-size: 12px; font-weight: 600; color: var(--muted);
              background: var(--bg); border: 1px solid var(--border); border-radius: 8px; }
.status-tab.active { background: var(--green-muted); color: var(--green); border-color: var(--green-muted); }

.threads { overflow-y: auto; flex: 1; }
.thread { display: block; width: 100%; text-align: left; background: none;
          border: none; border-bottom: 1px solid var(--border); padding: 12px 16px; cursor: pointer; }
.thread:hover { background: var(--bg); }
.thread.active { background: var(--green-muted); }
.thread .row { display: flex; align-items: center; justify-content: space-between; }
.thread .who { font-size: 13px; font-weight: 600; color: var(--fg); }
.thread .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--green); flex: none; }
.thread .meta { display: flex; gap: 8px; align-items: center; font-size: 11px; color: var(--muted); margin-top: 4px; }
.thread .badge { background: var(--green-muted); color: var(--green); padding: 1px 7px;
                 border-radius: 999px; font-weight: 600; text-transform: capitalize; }
.empty { padding: 24px 16px; color: var(--muted); font-size: 13px; }

main { display: flex; flex-direction: column; height: 100vh; min-width: 0; }
.head { display: flex; align-items: center; justify-content: space-between; gap: 12px;
        padding: 12px 18px; border-bottom: 1px solid var(--border); background: var(--card); }
.convo-title { font-size: 14px; font-weight: 600; }
.convo-sub { font-size: 11px; color: var(--muted); margin-top: 2px; text-transform: capitalize; }
.rating-badge { display: flex; align-items: center; gap: 6px; margin-top: 3px; font-size: 11px; color: var(--muted); }
.rating-badge .stars { color: #F59E0B; letter-spacing: 1px; font-size: 12px; }
.rating-badge .rnum { font-weight: 600; color: var(--fg); }
.rating-badge .rcomment { font-style: italic; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 280px; }
.thread-mode { display: flex; align-items: center; gap: 6px; flex: none; font-size: 12px; color: var(--muted); }
.thread-mode select { padding: 5px 8px; border: 1px solid var(--border); border-radius: 8px;
                      font-size: 12px; background: var(--card); color: var(--fg); }

.messages { flex: 1; overflow-y: auto; padding: 18px; background: var(--bg);
            display: flex; flex-direction: column; gap: 2px; }
.placeholder { margin: auto; color: var(--muted); font-size: 14px; }

.divider { align-self: center; margin: 14px 0 8px; font-size: 11px; color: var(--muted);
           background: var(--card); border: 1px solid var(--border); padding: 2px 10px; border-radius: 999px; }

.msg { max-width: 72%; padding: 8px 12px; border-radius: 16px; font-size: 14px; line-height: 1.4; }
.msg .text { white-space: pre-wrap; overflow-wrap: anywhere; }
.msg time { display: block; font-size: 10px; opacity: .65; margin-top: 3px; text-align: right; }
.msg.user  { align-self: flex-start; background: var(--user); margin-top: 8px; border-bottom-left-radius: 5px; }
.msg.agent { align-self: flex-end; background: var(--green); color: #fff; margin-top: 8px; border-bottom-right-radius: 5px; }
.msg.grouped { margin-top: 2px; }
.msg.system { align-self: center; background: transparent; color: var(--muted);
              font-size: 12px; text-align: center; max-width: 90%; margin: 4px 0; }
.msg.system .tag { display: block; font-size: 10px; font-weight: 700; letter-spacing: .04em;
                   text-transform: uppercase; color: var(--muted); margin-bottom: 2px; }
/* AI replies: a left bubble in a distinct colour, marked "AI". */
.msg.ai { align-self: flex-start; background: #EEF2FF; color: #3730A3; margin-top: 8px;
          border: 1px solid #E0E7FF; border-bottom-left-radius: 5px; }
.msg.ai .tag { display: block; font-size: 10px; font-weight: 700; letter-spacing: .04em;
               text-transform: uppercase; color: #6366F1; margin-bottom: 2px; }
.msg.ai .text { white-space: pre-wrap; overflow-wrap: anywhere; }
.msg.ai time { display: block; font-size: 10px; margin-top: 3px; text-align: right; color: #4F46E5; opacity: .85; }

/* Chat attachments (image thumbnail / file link). */
.msg .attach.img { display: block; max-width: 220px; max-height: 220px; border-radius: 10px; margin: 2px 0; cursor: zoom-in; }
.msg .attach.file { display: inline-block; color: inherit; text-decoration: underline; word-break: break-all; margin: 2px 0; }

/* "Customer is typing…" presence line (Realtime Broadcast). */
.typing { display: flex; align-items: center; gap: 8px; padding: 6px 18px;
          font-size: 12px; color: var(--muted); background: var(--bg); }
.typing-dots { display: inline-flex; gap: 3px; }
.typing-dots i { width: 5px; height: 5px; border-radius: 50%; background: var(--muted);
                 display: inline-block; animation: typing-bounce 1s infinite ease-in-out; }
.typing-dots i:nth-child(2) { animation-delay: .15s; }
.typing-dots i:nth-child(3) { animation-delay: .3s; }
@keyframes typing-bounce { 0%, 60%, 100% { transform: translateY(0); opacity: .5; }
                           30% { transform: translateY(-3px); opacity: 1; } }

.composer { display: flex; gap: 8px; padding: 12px 16px; border-top: 1px solid var(--border); background: var(--card); }
.composer input { flex: 1; padding: 11px 14px; border: 1.5px solid var(--border); border-radius: 22px; font-size: 14px; }
.composer button { padding: 0 18px; background: var(--green); color: #fff; border: none; border-radius: 22px; font-weight: 600; }
.composer button:disabled { background: var(--border); }
.composer .attach-btn { display: flex; align-items: center; justify-content: center; width: 40px; height: 40px;
                        border: 1.5px solid var(--border); border-radius: 50%; cursor: pointer; font-size: 16px; flex: none; }
.head-actions { display: flex; align-items: center; gap: 10px; flex: none; }
.resolve { padding: 6px 12px; background: var(--card); color: var(--green); border: 1px solid var(--green);
           border-radius: 8px; font-size: 12px; font-weight: 600; cursor: pointer; }
.thread .assignee { font-size: 10px; padding: 1px 6px; border-radius: 999px; background: var(--border); color: var(--muted); }
.thread .assignee.you { background: var(--green-muted); color: var(--green); }
.readonly-note { padding: 14px 16px; border-top: 1px solid var(--border); background: var(--bg);
                 color: var(--muted); font-size: 13px; text-align: center; }

/* ── Business-hours editor ──────────────────────────────────────────────── */
.hours-btn { flex: 1; padding: 5px 8px; border: 1px solid var(--border); border-radius: 8px;
             font-size: 12px; background: var(--card); color: var(--fg); text-align: left; cursor: pointer; }
.hours-btn:hover { background: var(--bg); }
.modal { position: fixed; inset: 0; z-index: 100; display: flex; align-items: center; justify-content: center;
         background: rgba(0,0,0,.45); padding: 24px; }
.modal-card { background: var(--card); border-radius: 14px; padding: 24px; width: 360px; max-width: 100%;
              box-shadow: 0 8px 40px rgba(0,0,0,.18); }
.modal-card h2 { font-size: 16px; margin: 0 0 4px; }
.modal-sub { font-size: 12px; color: var(--muted); margin: 0 0 16px; line-height: 1.4; }
.hours-rows { display: flex; flex-direction: column; gap: 8px; }
.hours-row { display: flex; align-items: center; gap: 8px; }
.hours-day { display: flex; align-items: center; gap: 6px; width: 64px; flex: none; font-size: 13px; color: var(--fg); }
.hours-row input[type="time"] { flex: 1; padding: 5px 8px; border: 1px solid var(--border); border-radius: 8px;
                                font-size: 13px; color: var(--fg); background: var(--card); }
.hours-row .dash { color: var(--muted); }
.modal-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 20px; }
.btn-ghost { padding: 8px 14px; border: 1px solid var(--border); border-radius: 8px; background: var(--card);
             color: var(--muted); font-size: 13px; font-weight: 600; cursor: pointer; }
.btn-primary { padding: 8px 16px; border: none; border-radius: 8px; background: var(--green); color: #fff;
               font-size: 13px; font-weight: 600; cursor: pointer; }
.btn-primary:disabled { background: var(--border); }

/* ── AI assistant modal ─────────────────────────────────────────────────── */
.modal-card.wide { width: 460px; }
.modal-sub.small { font-size: 11px; margin: 0 0 8px; }
.ai-stats { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; margin: 4px 0 18px; }
.ai-stats .stat { background: var(--bg); border: 1px solid var(--border); border-radius: 10px; padding: 10px 8px; text-align: center; }
.ai-stats .num { font-size: 16px; font-weight: 700; color: var(--green); }
.ai-stats .lbl { font-size: 10px; color: var(--muted); margin-top: 2px; }
.ai-label { display: block; font-size: 12px; font-weight: 600; color: var(--fg); margin: 4px 0 6px; }
.ai-rules { width: 100%; box-sizing: border-box; padding: 10px 12px; border: 1px solid var(--border);
            border-radius: 10px; font: inherit; font-size: 13px; color: var(--fg); resize: vertical; line-height: 1.4; }
.ai-toggles { display: flex; flex-direction: column; gap: 8px; margin-bottom: 4px; }
.ai-toggles label { display: flex; align-items: center; gap: 8px; font-size: 13px; color: var(--fg); }
