/* SolveCX Chat — agent app */
:root {
  --navy: #0B1F33;
  --navy-2: #13293F;
  --navy-line: #2B4561;
  --green: #0E9F6E;
  --green-hover: #0B8A5F;
  --green-text: #0B7A55;
  --green-bright: #3DDC97;
  --green-soft: #E7F6F0;
  --ink: #0B1F33;
  --ink-2: #33465A;
  --muted: #5B6878;
  --soft: #F5F7FA;
  --line: #E3E8EF;
  --danger: #C2362B;
  --font-display: "Sora", system-ui, sans-serif;
  --font-body: "Inter", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

*, *::before, *::after { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0; background: var(--soft); color: var(--ink);
  font-family: var(--font-body); font-size: 16px; line-height: 1.5;
  -webkit-font-smoothing: antialiased; -webkit-tap-highlight-color: transparent;
  overscroll-behavior-y: none;
}
[hidden] { display: none !important; }
button { font: inherit; color: inherit; cursor: pointer; }
:focus-visible { outline: 3px solid var(--green-bright); outline-offset: 2px; border-radius: 6px; }
h1 { margin: 0; }

.wordmark { font-family: var(--font-display); font-weight: 600; letter-spacing: -0.02em; }
.wordmark span { color: var(--green-bright); font-weight: 700; }

.btn { display: inline-flex; align-items: center; justify-content: center; min-height: 48px; padding: 0 20px; border-radius: 12px; border: 0; font-weight: 600; }
.btn-primary { background: var(--green); color: #fff; }
.btn-primary:hover { background: var(--green-hover); }
.btn-primary:disabled { opacity: .6; }
.btn-sm { min-height: 40px; padding: 0 16px; font-size: .9rem; }
.btn-block { width: 100%; }

.view { min-height: 100%; display: flex; flex-direction: column; }

/* ---------- Login ---------- */
.login { background: var(--navy); color: #fff; justify-content: center; align-items: center; padding: 24px 16px; }
.login-card { width: 100%; max-width: 360px; text-align: center; }
.login-logo { border-radius: 18px; box-shadow: 0 10px 30px rgba(0,0,0,.35); }
.login h1 { font-size: 1.6rem; margin-top: 18px; }
.login-sub { color: #C9D3DF; margin: 6px 0 28px; }
.login form { text-align: left; }
.login label { display: block; font-size: .9rem; font-weight: 500; margin-bottom: 6px; color: #E3E8EF; }
.login input {
  width: 100%; min-height: 50px; padding: 0 14px; border-radius: 12px; font-size: 1rem;
  border: 1px solid var(--navy-line); background: var(--navy-2); color: #fff;
}
.login input:focus { outline: none; border-color: var(--green-bright); }
.form-error { min-height: 1.5em; margin: 8px 0; color: #FF9B8F; font-size: .9rem; }

/* ---------- Top bar ---------- */
.topbar {
  position: sticky; top: 0; z-index: 10; display: flex; align-items: center; gap: 10px;
  padding: calc(10px + var(--safe-top)) 8px 10px 16px; min-height: 60px;
  background: var(--navy); color: #fff;
}
.brand { display: flex; align-items: center; gap: 10px; font-size: 1.15rem; }
.brand img { border-radius: 8px; }
.icon-btn { display: inline-grid; place-items: center; width: 44px; height: 44px; border-radius: 10px; border: 0; background: none; color: #fff; fill: currentColor; }
.icon-btn:hover { background: #1A3048; }
.conn { margin-left: auto; display: inline-flex; align-items: center; gap: 6px; font-size: .8rem; color: #C9D3DF; }
.conn .dot { width: 8px; height: 8px; border-radius: 50%; background: #F5C98A; }
.conn.online .dot { background: var(--green-bright); }
.conn.offline .dot { background: #FF7A6B; }

.menu {
  position: absolute; right: 8px; top: calc(100% - 4px); min-width: 220px; padding: 6px;
  background: #fff; color: var(--ink); border-radius: 14px; box-shadow: 0 16px 40px rgba(11,31,51,.25);
}
.menu button { display: block; width: 100%; text-align: left; padding: 12px 14px; border: 0; background: none; border-radius: 10px; font-size: .95rem; }
.menu button:hover { background: var(--soft); }
.menu .danger { color: var(--danger); }

/* ---------- Notifications banner ---------- */
.banner {
  display: flex; align-items: center; gap: 12px; margin: 12px 12px 0; padding: 14px;
  background: var(--green-soft); border: 1px solid #BFE6D6; border-radius: 14px; font-size: .9rem;
}
.banner strong { display: block; }
.banner span { color: var(--ink-2); }
.banner .btn { flex-shrink: 0; }
.banner.warn { background: #FFF4E5; border-color: #F5C98A; }
.banner.warn span { color: #5C3300; }

/* ---------- Tabs ---------- */
.tabs { display: flex; gap: 6px; padding: 12px 12px 4px; }
.tab { flex: 1; min-height: 40px; border: 1px solid var(--line); background: #fff; border-radius: 10px; font-weight: 600; font-size: .9rem; color: var(--muted); }
.tab[aria-selected="true"] { background: var(--navy); border-color: var(--navy); color: #fff; }
.count:not(:empty) { display: inline-block; min-width: 20px; padding: 0 6px; margin-left: 4px; border-radius: 10px; background: var(--green); color: #fff; font-size: .75rem; line-height: 20px; }

/* ---------- Conversation list ---------- */
.conv-list { list-style: none; margin: 0; padding: 8px 12px calc(16px + var(--safe-bottom)); }
.conv {
  display: flex; gap: 12px; width: 100%; padding: 14px; margin-bottom: 8px; text-align: left;
  background: #fff; border: 1px solid var(--line); border-radius: 14px;
}
.conv:hover { border-color: #C9D3DF; }
.avatar {
  flex-shrink: 0; width: 44px; height: 44px; border-radius: 50%; display: grid; place-items: center;
  background: var(--navy); color: #fff; font-family: var(--font-display); font-weight: 600;
}
.conv-body { flex: 1; min-width: 0; }
.conv-top { display: flex; align-items: baseline; gap: 8px; }
.conv-name { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.conv-time { margin-left: auto; flex-shrink: 0; font-size: .78rem; color: var(--muted); }
.conv-last { display: flex; align-items: center; gap: 8px; margin-top: 2px; color: var(--muted); font-size: .9rem; }
.conv-last .text { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.conv.unread .conv-last .text { color: var(--ink); font-weight: 600; }
.badge { flex-shrink: 0; min-width: 22px; padding: 0 7px; border-radius: 11px; background: var(--green); color: #fff; font-size: .75rem; font-weight: 600; line-height: 22px; text-align: center; }
.empty { text-align: center; color: var(--muted); padding: 48px 24px; }
.empty img { filter: invert(1) opacity(.25); }

/* ---------- Chat ---------- */
.view.chat { height: 100vh; height: 100dvh; min-height: 0; }
.chat-who { flex: 1; min-width: 0; line-height: 1.25; }
.chat-who strong { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chat-who a { color: var(--green-bright); font-size: .85rem; text-decoration: none; display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chat-page { margin: 0; padding: 6px 16px; font-size: .78rem; color: var(--muted); background: #fff; border-bottom: 1px solid var(--line); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chat-page:empty { display: none; }
.messages { flex: 1; overflow-y: auto; padding: 16px 12px; display: flex; flex-direction: column; gap: 6px; }
.msg { max-width: 82%; padding: 10px 14px; border-radius: 16px; white-space: pre-wrap; word-wrap: break-word; font-size: .95rem; }
.msg a { color: inherit; }
.msg.visitor { align-self: flex-start; background: #fff; border: 1px solid var(--line); border-bottom-left-radius: 6px; }
.msg.agent { align-self: flex-end; background: var(--green); color: #fff; border-bottom-right-radius: 6px; }
.msg.pending { opacity: .6; }
.msg-time { font-size: .72rem; color: var(--muted); margin: 0 4px 6px; }
.msg-time.agent { align-self: flex-end; }
.day { align-self: center; margin: 10px 0 4px; font-size: .75rem; font-weight: 600; color: var(--muted); }
.closed-note { margin: 0; padding: 8px 16px; text-align: center; font-size: .85rem; background: #FFF4E5; color: #5C3300; }
.composer {
  display: flex; align-items: flex-end; gap: 8px; padding: 10px 10px calc(10px + var(--safe-bottom));
  background: #fff; border-top: 1px solid var(--line);
}
.composer textarea {
  flex: 1; resize: none; max-height: 140px; min-height: 46px; padding: 11px 14px;
  border: 1px solid var(--line); border-radius: 23px; font: inherit; color: var(--ink); background: var(--soft);
}
.composer textarea:focus { outline: none; border-color: var(--green); background: #fff; }
.send { width: 46px; height: 46px; flex-shrink: 0; border-radius: 50%; border: 0; background: var(--green); color: #fff; display: grid; place-items: center; }
.send:hover { background: var(--green-hover); }

.toast {
  position: fixed; left: 50%; bottom: calc(84px + var(--safe-bottom)); transform: translateX(-50%); z-index: 50;
  max-width: calc(100% - 32px); padding: 10px 16px; border-radius: 12px; background: var(--navy); color: #fff; font-size: .9rem;
  box-shadow: 0 10px 30px rgba(11,31,51,.3);
}

@media (min-width: 720px) {
  .view:not(.login) { max-width: 720px; margin: 0 auto; width: 100%; background: var(--soft); box-shadow: 0 0 0 1px var(--line); }
}
