/* ===== Chat Admin Inbox ===== */
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; }
body {
  font-family: "Segoe UI", system-ui, -apple-system, Arial, sans-serif;
  background: #eef2f8;
  color: #142d57;
  min-height: 100vh;
}
body.admin-gate-body {
  background: linear-gradient(160deg, #081c47 0%, #0e2b6b 42%, #123a86 70%, #1b4a8f 100%);
  color: #fff;
}

/* ---------- Topbar ---------- */
.ai-topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 0.9rem 1.4rem;
  background: linear-gradient(135deg, #16397a, #0f2c5f);
  color: #fff;
  box-shadow: 0 6px 24px -10px rgba(15, 44, 95, 0.5);
}
.ai-topbar-in { display: flex; align-items: center; gap: 1.2rem; flex: 1; min-width: 0; }
.ai-topbar h1 { margin: 0; font-size: 1.15rem; }
.ai-topbar p { margin: 2px 0 0; font-size: 0.78rem; color: rgba(255,255,255,0.75); }
.ai-nav { display: flex; gap: 0.35rem; background: rgba(255,255,255,0.09); border-radius: 12px; padding: 0.25rem; }
.ai-nav-btn {
  border: none; background: transparent; color: rgba(255,255,255,0.72);
  font-size: 0.82rem; font-weight: 700; padding: 0.45rem 0.9rem; border-radius: 9px; cursor: pointer;
  transition: background 0.18s, color 0.18s;
}
.ai-nav-btn:hover { color: #fff; }
.ai-nav-btn.active { background: #fff; color: #142d57; }
.ai-live {
  display: inline-flex; align-items: center; gap: 7px;
  font-size: 0.72rem; font-weight: 700; letter-spacing: 0.08em; text-transform: uppercase;
  color: #a7f0c8;
  background: rgba(255,255,255,0.1);
  padding: 0.4rem 0.8rem;
  border-radius: 99px;
}
.ai-dot { width: 9px; height: 9px; border-radius: 50%; background: #35d07f; animation: aiBlink 1.5s ease-in-out infinite; }
@keyframes aiBlink { 0%,100% { opacity: 1; } 50% { opacity: 0.35; } }

/* ---------- Buttons ---------- */
.ai-btn {
  border: none;
  border-radius: 10px;
  cursor: pointer;
  font-size: 0.86rem;
  font-weight: 600;
  padding: 0.55rem 1rem;
  transition: transform 0.15s, box-shadow 0.2s, background 0.2s;
}
.ai-btn:hover { transform: translateY(-1px); }
.ai-btn:active { transform: scale(0.97); }
.ai-btn-primary {
  background: linear-gradient(135deg, #1b4a8f, #0f2c5f);
  color: #fff;
  box-shadow: 0 8px 18px -8px rgba(27, 74, 143, 0.7);
}
.ai-btn-ghost {
  background: rgba(255,255,255,0.12);
  color: #fff;
}
.ai-btn-ghost:hover { background: rgba(255,255,255,0.22); }
.ai-btn-plain {
  background: #eef3fb;
  color: #1b4a8f;
  border: 1px solid rgba(27, 74, 143, 0.18);
}
.ai-btn-plain:hover { background: #e2ecfa; }
.ai-btn-danger {
  background: #d10f1f;
  color: #fff;
  box-shadow: 0 8px 18px -8px rgba(209, 15, 31, 0.6);
}
.ai-btn-danger:disabled { opacity: 0.45; cursor: not-allowed; transform: none; box-shadow: none; }

/* ---------- Layout ---------- */
.ai-main {
  display: grid;
  grid-template-columns: 340px 1fr;
  gap: 1.2rem;
  max-width: 1280px;
  margin: 1.4rem auto;
  padding: 0 1.4rem;
  align-items: start;
}

.ai-list-pane, .ai-thread-pane {
  background: #fff;
  border-radius: 16px;
  box-shadow: 0 14px 40px -22px rgba(15, 44, 95, 0.35);
  overflow: hidden;
  border: 1px solid rgba(15, 44, 95, 0.08);
}
.ai-list-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 1rem 1.1rem;
  border-bottom: 1px solid rgba(15, 44, 95, 0.08);
}
.ai-list-head h2 { margin: 0; font-size: 1rem; }
.ai-count {
  font-size: 0.72rem; font-weight: 700;
  background: #eaf4ff; color: #1b4a8f;
  border-radius: 99px; padding: 0.25rem 0.6rem;
}
.ai-list { max-height: calc(100vh - 290px); overflow-y: auto; }
.ai-empty { padding: 1.4rem; color: #7c8aa6; font-size: 0.88rem; text-align: center; }

/* ---------- Toolbar ---------- */
.ai-toolbar { padding: 0.75rem 1rem; border-bottom: 1px solid rgba(15, 44, 95, 0.08); display: flex; flex-direction: column; gap: 0.55rem; }
#ai-search {
  width: 100%;
  border: 1px solid rgba(15, 44, 95, 0.18);
  border-radius: 10px;
  padding: 0.5rem 0.75rem;
  font-size: 0.84rem;
  font-family: inherit;
  outline: none;
  color: #142d57;
  background: #f7fafd;
}
#ai-search:focus { border-color: #1b4a8f; box-shadow: 0 0 0 3px rgba(27, 74, 143, 0.14); }
.ai-filters, .ai-color-filters { display: flex; flex-wrap: wrap; gap: 0.35rem; align-items: center; }
.ai-filter {
  border: 1px solid rgba(27, 74, 143, 0.22);
  background: #fff;
  color: #23508f;
  font-size: 0.72rem; font-weight: 700;
  padding: 0.3rem 0.7rem; border-radius: 99px; cursor: pointer;
  transition: background 0.18s, color 0.18s;
}
.ai-filter:hover { background: #eaf4ff; }
.ai-filter.active { background: #1b4a8f; color: #fff; border-color: #1b4a8f; }
.cf-chip {
  border: 1px solid rgba(27, 74, 143, 0.22);
  background: #fff;
  color: #23508f;
  font-size: 0.7rem; font-weight: 700;
  padding: 0.28rem 0.6rem; border-radius: 99px; cursor: pointer;
}
.cf-chip.active { background: #1b4a8f; color: #fff; border-color: #1b4a8f; }
.cf-swatch { width: 22px; height: 22px; padding: 0; border: 2px solid #fff; box-shadow: 0 0 0 1px rgba(15, 44, 95, 0.2); border-radius: 6px; }
.cf-swatch.active { box-shadow: 0 0 0 2px #1b4a8f; }
.ai-toolbar-row { display: flex; align-items: center; gap: 0.5rem; flex-wrap: wrap; }
.ai-sel-info { font-size: 0.74rem; color: #5b6b85; margin-left: 0.3rem; }

/* ---------- List items ---------- */
.ai-chat-item {
  width: 100%;
  text-align: left;
  border: none;
  border-bottom: 1px solid rgba(15, 44, 95, 0.06);
  background: #fff;
  padding: 0.85rem 1.1rem;
  cursor: pointer;
  position: relative;
  display: flex;
  gap: 0.5rem;
  transition: background 0.18s;
}
.ai-chat-item:hover { background: #f5f9ff; }
.ai-chat-item.active { background: #eaf4ff; box-shadow: inset 3px 0 0 #1b4a8f; }
.ai-chat-item.sel { background: #eef9ff; box-shadow: inset 3px 0 0 #28b6d6; }
.ai-chat-item .ci-body { flex: 1; min-width: 0; }
.ai-chat-item .ci-colorbar { flex: 0 0 5px; border-radius: 4px; align-self: stretch; }
.ai-chat-item .ci-check {
  flex: 0 0 22px;
  width: 22px; height: 22px;
  margin-top: 1px;
  border: 2px solid #a7b6cf;
  border-radius: 6px;
  background: #fff;
  display: inline-flex; align-items: center; justify-content: center;
  font-size: 0.8rem; font-weight: 800; color: #fff;
}
.ai-chat-item .ci-check.on { background: #1b4a8f; border-color: #1b4a8f; }
.ai-chat-item .ci-head { display: flex; align-items: center; gap: 0.5rem; }
.ai-chat-item .ci-name { font-weight: 700; font-size: 0.9rem; flex: 1; min-width: 0; }
.ai-chat-item .ci-time { font-size: 0.7rem; color: #8a99b5; }
.ai-chat-item .ci-last { font-size: 0.8rem; color: #5b6b85; margin-top: 3px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.ai-chat-item .ci-sub { font-size: 0.76rem; color: #94a3bd; margin-top: 2px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.ai-chat-item .ci-badge {
  position: absolute; top: 12px; right: 12px;
  min-width: 20px; height: 20px;
  display: flex; align-items: center; justify-content: center;
  border-radius: 99px;
  background: linear-gradient(135deg, #ff3b3b, #d10f1f);
  color: #fff; font-size: 11px; font-weight: 800;
  animation: aiPulse 1.3s ease-in-out infinite;
}
.ai-chat-item .ci-palette { display: flex; gap: 4px; flex-wrap: wrap; margin-top: 7px; }
.ai-chat-item .ci-dot, .ai-thread-palette .ci-dot {
  width: 17px; height: 17px;
  border-radius: 50%;
  border: 2px solid #fff;
  box-shadow: 0 0 0 1px rgba(15, 44, 95, 0.25);
  cursor: pointer;
  padding: 0;
  transition: transform 0.12s;
}
.ai-chat-item .ci-dot:hover, .ai-thread-palette .ci-dot:hover { transform: scale(1.18); }
.ai-chat-item .ci-dot.on, .ai-thread-palette .ci-dot.on { box-shadow: 0 0 0 2px #1b4a8f; }
.ai-chat-item .ci-dot-clear, .ai-thread-palette .ci-dot-clear {
  border-color: #e3e8f0;
  background: #f4f7fb;
  color: #8a99b5;
  font-size: 0.62rem;
  display: inline-flex; align-items: center; justify-content: center;
}
@keyframes aiPulse { 0%,100% { transform: scale(1); } 40% { transform: scale(1.25); } }
.ai-tag {
  display: inline-block;
  font-size: 0.62rem; font-weight: 700; text-transform: uppercase; letter-spacing: 0.06em;
  padding: 0.16rem 0.5rem; border-radius: 99px;
  background: #eaf4ff; color: #1b4a8f;
}
.ai-tag.human { background: #fff3e0; color: #b4571a; }
.ai-tag.closed { background: #eceff4; color: #6b7893; }

/* ---------- Thread ---------- */
.ai-thread-pane { display: flex; flex-direction: column; min-height: calc(100vh - 160px); }
.ai-thread-head {
  display: flex; align-items: center; gap: 0.8rem;
  padding: 0.9rem 1.2rem;
  border-bottom: 1px solid rgba(15, 44, 95, 0.08);
}
.ai-thread-head > div { flex: 1; min-width: 0; }
.ai-thread-head h3 { margin: 0; font-size: 1rem; }
.ai-thread-head p { margin: 2px 0 0; font-size: 0.74rem; color: #5b6b85; }
.ai-back { display: none; }
.ai-thread-color {
  flex: 0 0 22px;
  width: 22px; height: 22px;
  border-radius: 50%;
  border: 3px solid transparent;
  box-shadow: 0 0 0 1px rgba(15, 44, 95, 0.25);
}
.ai-thread-palette { display: flex; gap: 4px; flex-wrap: wrap; align-items: center; max-width: 220px; }

.ai-messages {
  flex: 1;
  overflow-y: auto;
  padding: 1.1rem 1.2rem;
  display: flex; flex-direction: column; gap: 0.5rem;
  background:
    radial-gradient(circle at 90% 8%, rgba(78, 200, 224, 0.06), transparent 40%),
    radial-gradient(circle at 8% 92%, rgba(27, 74, 143, 0.06), transparent 42%),
    #f4f7fb;
  max-height: calc(100vh - 320px);
}
.ai-msg {
  max-width: 78%;
  padding: 0.6rem 0.85rem;
  border-radius: 14px;
  font-size: 0.9rem;
  line-height: 1.5;
  color: #17315f;
  background: #fff;
  border: 1px solid rgba(15, 44, 95, 0.08);
  box-shadow: 0 2px 8px rgba(15, 44, 95, 0.06);
  word-wrap: break-word;
}
.ai-msg client, .ai-msg-client { align-self: flex-end; background: linear-gradient(135deg, #1b4a8f, #0f2c5f); color: #fff; border: none; border-bottom-right-radius: 4px; }
.ai-msg-bot { align-self: flex-start; background: #eaf4ff; border-bottom-left-radius: 4px; }
.ai-msg-admin { align-self: flex-start; background: #fff; }
.ai-msg-meta { display: block; font-size: 0.62rem; opacity: 0.75; margin-top: 4px; }

.ai-quick { display: flex; flex-wrap: wrap; gap: 0.45rem; padding: 0.6rem 1.2rem; }
.ai-quick button {
  border: 1px solid rgba(27, 74, 143, 0.25);
  background: #fff;
  color: #1a3e7a;
  font-size: 0.76rem;
  font-weight: 600;
  padding: 0.35rem 0.7rem;
  border-radius: 99px;
  cursor: pointer;
  transition: background 0.18s;
}
.ai-quick button:hover { background: #eaf4ff; }

.ai-reply {
  display: flex;
  align-items: flex-end;
  gap: 0.6rem;
  padding: 0.8rem 1.2rem;
  border-top: 1px solid rgba(15, 44, 95, 0.08);
}
.ai-reply textarea {
  flex: 1;
  resize: vertical;
  min-height: 46px;
  max-height: 150px;
  border: 1px solid rgba(15, 44, 95, 0.18);
  border-radius: 12px;
  padding: 0.6rem 0.85rem;
  font-size: 0.9rem;
  font-family: inherit;
  outline: none;
  color: #142d57;
  background: #f7fafd;
}
.ai-reply textarea:focus { border-color: #1b4a8f; box-shadow: 0 0 0 3px rgba(27, 74, 143, 0.14); }

/* ---------- Analytics ---------- */
.ai-dash { max-width: 1080px; margin: 1.4rem auto; padding: 0 1.4rem; }
.ai-dash-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 1rem; }
.ai-dash-head h2 { margin: 0; font-size: 1.25rem; color: #142d57; }
.ai-cards {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
  gap: 0.9rem;
  margin-bottom: 1.2rem;
}
.ai-card {
  background: #fff;
  border-radius: 14px;
  border: 1px solid rgba(15, 44, 95, 0.08);
  box-shadow: 0 12px 30px -20px rgba(15, 44, 95, 0.4);
  padding: 1rem 1.1rem;
}
.ai-card-num { font-size: 1.7rem; font-weight: 800; color: #142d57; line-height: 1.1; }
.ai-card-lbl { font-size: 0.76rem; color: #5b6b85; margin-top: 3px; }
.ai-dash-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 1.2rem; align-items: start; }
.ai-card-panel {
  background: #fff;
  border-radius: 16px;
  border: 1px solid rgba(15, 44, 95, 0.08);
  box-shadow: 0 14px 40px -22px rgba(15, 44, 95, 0.35);
  padding: 1.1rem 1.2rem;
}
.ai-card-panel h3 { margin: 0 0 0.8rem; font-size: 0.95rem; color: #142d57; }
.ai-bars { display: flex; flex-direction: column; gap: 0.55rem; }
.ai-bar-row { display: grid; grid-template-columns: 150px 1fr 40px; align-items: center; gap: 0.6rem; }
.ai-bar-name { font-size: 0.78rem; color: #142d57; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.ai-bar-track { height: 10px; border-radius: 99px; background: #eef2f8; overflow: hidden; }
.ai-bar-fill { height: 100%; border-radius: 99px; background: linear-gradient(90deg, #1b4a8f, #4ec8e0); transition: width 0.4s ease; }
.ai-bar-count { font-size: 0.74rem; font-weight: 700; color: #142d57; text-align: right; }

/* ---------- Gate ---------- */
#ai-gate {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  padding: 1rem;
  overflow: hidden;
}
#ai-gate::before {
  content: "";
  position: absolute;
  width: 520px; height: 520px;
  border-radius: 50%;
  top: -160px; right: -140px;
  background: radial-gradient(circle, rgba(78, 200, 224, 0.35), transparent 65%);
  filter: blur(2px);
}
#ai-gate::after {
  content: "";
  position: absolute;
  width: 460px; height: 460px;
  border-radius: 50%;
  bottom: -150px; left: -120px;
  background: radial-gradient(circle, rgba(255, 255, 255, 0.14), transparent 62%);
}
.ai-gate-card {
  position: relative;
  z-index: 1;
  width: 360px;
  max-width: 92vw;
  background: rgba(255, 255, 255, 0.08);
  -webkit-backdrop-filter: blur(18px);
  backdrop-filter: blur(18px);
  border: 1px solid rgba(255, 255, 255, 0.18);
  border-radius: 20px;
  padding: 2.1rem 2rem 2.2rem;
  text-align: center;
  box-shadow: 0 30px 80px -28px rgba(2, 10, 35, 0.85), inset 0 1px 0 rgba(255, 255, 255, 0.12);
}
.ai-gate-logo {
  width: 132px;
  height: 82px;
  margin: 0 auto 1rem;
  border-radius: 16px;
  background: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 8px 10px;
  box-shadow: 0 14px 34px -14px rgba(2, 10, 35, 0.55);
}
.ai-gate-logo img {
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
  display: block;
}
.ai-gate-card h1 { margin: 0 0 0.25rem; font-size: 1.4rem; color: #fff; letter-spacing: 0.01em; }
.ai-gate-card p { margin: 0 0 1.1rem; font-size: 0.86rem; color: rgba(255, 255, 255, 0.72); }
.ai-gate-card input {
  width: 100%;
  padding: 0.75rem 0.95rem;
  border: 1px solid rgba(255, 255, 255, 0.28);
  border-radius: 12px;
  font-size: 0.92rem;
  outline: none;
  margin-bottom: 0.7rem;
  box-sizing: border-box;
  background: rgba(255, 255, 255, 0.1);
  color: #fff;
  transition: border-color .25s ease, background .25s ease, box-shadow .25s ease;
}
.ai-gate-card input::placeholder { color: rgba(255, 255, 255, 0.55); }
.ai-gate-card input:last-of-type { margin-bottom: 0.15rem; }
.ai-gate-card input:focus {
  border-color: #7fd8ea;
  background: rgba(255, 255, 255, 0.16);
  box-shadow: 0 0 0 3px rgba(78, 200, 224, 0.28);
}
.ai-gate-err { color: #ffb3b9; font-weight: 600; font-size: 0.8rem; margin-top: 0.5rem; text-shadow: 0 1px 2px rgba(0, 0, 0, 0.2); }
.ai-gate-ok { color: #baf3c0; font-weight: 700; font-size: 0.82rem; margin-top: 0.55rem; }
.ai-gate-link {
  background: none;
  border: none;
  color: #8fd0f2;
  font: inherit;
  font-weight: 700;
  font-size: 0.82rem;
  letter-spacing: 0.02em;
  cursor: pointer;
  margin-top: 0.9rem;
  padding: 0.2rem 0.4rem;
  transition: color 0.2s;
}
.ai-gate-link:hover { color: #ffffff; }
.ai-gate-link:disabled { opacity: 0.55; cursor: default; }
.ai-gate-btn { width: 100%; margin-top: 1rem; padding: 0.75rem; }

/* ---------- Responsive ---------- */
@media (max-width: 820px) {
  .ai-main { grid-template-columns: 1fr; padding: 0 1rem; }
  .ai-list-pane { display: none; }
  .ai-list-pane.active { display: block; }
  .ai-thread-pane { min-height: calc(100vh - 130px); }
  .ai-back { display: inline-flex; }
  .ai-topbar { padding: 0.7rem 1rem; flex-wrap: wrap; }
  .ai-topbar h1 { font-size: 1rem; }
  .ai-dash-grid { grid-template-columns: 1fr; }
  .ai-bar-row { grid-template-columns: 110px 1fr 36px; }
}
/* ---------- Blog Manager ---------- */
.ai-blog-list { max-height: calc(100vh - 290px); overflow-y: auto; }
.ai-blog-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.9rem;
  padding: 0.85rem 1rem;
  border-bottom: 1px solid rgba(15, 44, 95, 0.08);
  transition: background 0.15s ease;
}
.ai-blog-item:hover { background: #f6f9ff; }
.ai-blog-main { min-width: 0; }
.ai-blog-title { font-weight: 700; color: #142d57; font-size: 0.95rem; }
.ai-blog-meta { font-size: 0.78rem; color: #5b6b85; margin-top: 0.25rem; display: flex; align-items: center; gap: 0.3rem; flex-wrap: wrap; }
.ai-blog-status { font-size: 0.68rem; font-weight: 800; letter-spacing: 0.05em; padding: 0.18rem 0.55rem; border-radius: 99px; text-transform: uppercase; }
.ai-blog-status.is-pub { background: #e4f5e9; color: #1f7a3d; }
.ai-blog-status.is-draft { background: #fdf1da; color: #9a6b12; }
.ai-blog-actions { display: flex; gap: 0.4rem; flex-shrink: 0; flex-wrap: wrap; }

#view-blog { position: relative; }

.ai-blog-editor {
  position: absolute;
  inset: 0;
  z-index: 60;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(6, 18, 40, 0.55);
  padding: 1rem;
}
.ai-blog-form {
  width: 100%;
  max-width: 560px;
  max-height: calc(100vh - 2rem);
  overflow-y: auto;
  background: #fff;
  border-radius: 16px;
  padding: 1.25rem;
  box-shadow: 0 24px 70px -20px rgba(4, 11, 24, 0.6);
  display: flex;
  flex-direction: column;
  gap: 0.7rem;
}
.ai-blog-form h3 { margin: 0; color: #142d57; font-size: 1.1rem; }
.ai-blog-form input[type="text"],
.ai-blog-form textarea {
  width: 100%;
  border: 1px solid rgba(15, 44, 95, 0.18);
  border-radius: 10px;
  padding: 0.6rem 0.7rem;
  font: inherit;
  color: #142d57;
  background: #fbfdff;
  resize: vertical;
}
.ai-blog-form input:focus,
.ai-blog-form textarea:focus { outline: none; border-color: #1b4a8f; box-shadow: 0 0 0 3px rgba(27, 74, 143, 0.14); }
.ai-blog-form textarea { line-height: 1.5; }
.ai-form-err { margin: 0; color: #c62828; font-size: 0.8rem; font-weight: 600; }
.ai-check { display: flex; align-items: center; gap: 0.45rem; font-size: 0.86rem; color: #33507d; font-weight: 600; }
.ai-check input { accent-color: #1b4a8f; width: 16px; height: 16px; }
.ai-blog-form-actions { display: flex; justify-content: flex-end; gap: 0.5rem; margin-top: 0.3rem; }

.ai-blog-frame {
  background: #fff;
  border: 1px solid rgba(15, 44, 95, 0.08);
  border-radius: 14px;
  box-shadow: 0 12px 34px -22px rgba(4, 11, 24, 0.35);
  overflow: hidden;
}
