/* =====================================================================
   Municipal AI Advisor — Frontend CSS  v2.2.1
   Claude-like sidebar layout — full viewport height fixes
   ===================================================================== */

/* ---------- Reset & full-height anchoring ---------- */
html, body {
  height: 100%;
}

/* Make the WP page wrapper stretch — targets common WP themes */
.maiui-app-wrap,
.entry-content,
.page-content,
.post-content,
.site-main,
main.site-main {
  height: 100%;
  padding: 0 !important;
  margin: 0 !important;
}

/* ---------- App shell ---------- */
.maiui-app {
  display: flex;
  width: 100%;
  height: 100vh;
  min-height: 520px;
  font-family: inherit;
  color: #0f172a;
  background: #f8fafc;
  overflow: hidden;
  position: fixed;
  top: 0;
  left: 0;
  z-index: 9999;
}

/* ---------- Sidebar ---------- */
.maiui-sidebar {
  width: 260px;
  flex-shrink: 0;
  background: #0f172a;
  color: #e2e8f0;
  display: flex;
  flex-direction: column;
  transition: transform .25s ease;
  height: 100%;
  overflow: hidden;
}

.maiui-sidebar-header {
  padding: 20px 16px 14px;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 14px;
  border-bottom: 1px solid rgba(255,255,255,.07);
  flex-shrink: 0;
}

.maiui-sidebar-logo {
  width: 100%;
  max-width: 100%;
  max-height: 56px;
  height: auto;
  object-fit: contain;
  object-position: left center;
  display: block;
}

.maiui-sidebar-logo-fb {
  width: 44px;
  height: 44px;
  border-radius: 10px;
  background: linear-gradient(135deg,#1e40af,#7c3aed);
  display: grid;
  place-items: center;
  font-size: 18px;
  font-weight: 700;
  color: #fff;
  flex-shrink: 0;
}

.maiui-new-chat-btn {
  display: flex;
  align-items: center;
  gap: 8px;
  background: rgba(255,255,255,.08);
  border: 1px solid rgba(255,255,255,.12);
  color: #e2e8f0;
  border-radius: 10px;
  padding: 9px 14px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: background .15s ease;
  width: 100%;
  box-sizing: border-box;
}

.maiui-new-chat-btn:hover {
  background: rgba(255,255,255,.14);
}

/* Conversation list */
.maiui-sidebar-body {
  flex: 1;
  overflow-y: auto;
  padding: 10px 6px;
  min-height: 0;
}

.maiui-convlist-label {
  font-size: 11px;
  font-weight: 600;
  color: #64748b;
  letter-spacing: .06em;
  text-transform: uppercase;
  padding: 4px 10px 8px;
}

.maiui-convlist {
  list-style: none;
  padding: 0;
  margin: 0;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.maiui-convlist-loading {
  font-size: 12px;
  color: #475569;
  padding: 6px 10px;
}

.maiui-convlist li.maiui-conv-item {
  display: flex;
  align-items: center;
  gap: 6px;
  border-radius: 8px;
  padding: 8px 10px;
  font-size: 13px;
  cursor: pointer;
  transition: background .15s ease;
  color: #cbd5e1;
  line-height: 1.4;
}

.maiui-convlist li.maiui-conv-item:hover {
  background: rgba(255,255,255,.08);
}

.maiui-convlist li.maiui-conv-item.is-active {
  background: rgba(255,255,255,.12);
  color: #fff;
}

.maiui-conv-title {
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.maiui-conv-del {
  background: none;
  border: none;
  color: #475569;
  cursor: pointer;
  padding: 2px 4px;
  border-radius: 4px;
  font-size: 14px;
  line-height: 1;
  flex-shrink: 0;
  transition: color .15s;
  display: none;
}

.maiui-conv-item:hover .maiui-conv-del {
  display: inline-block;
}

.maiui-conv-del:hover { color: #f87171; }

.maiui-sidebar-anon {
  padding: 12px 10px;
  font-size: 13px;
  color: #475569;
}

/* Sidebar footer */
.maiui-sidebar-footer {
  border-top: 1px solid rgba(255,255,255,.07);
  padding: 14px 16px;
  flex-shrink: 0;
}

.maiui-user-row {
  display: flex;
  align-items: center;
  gap: 10px;
}

.maiui-user-avatar {
  width: 32px;
  height: 32px;
  border-radius: 8px;
  background: linear-gradient(135deg,#0073aa,#334155);
  display: grid;
  place-items: center;
  font-size: 13px;
  font-weight: 700;
  color: #fff;
  flex-shrink: 0;
}

.maiui-user-name {
  font-size: 13px;
  color: #cbd5e1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.maiui-auth-btns {
  display: flex;
  gap: 8px;
}

.maiui-btn-login,
.maiui-btn-register {
  flex: 1;
  text-align: center;
  padding: 8px 10px;
  border-radius: 8px;
  font-size: 13px;
  font-weight: 600;
  text-decoration: none;
  transition: all .15s ease;
}

.maiui-btn-login {
  background: #fff;
  color: #0f172a;
}

.maiui-btn-login:hover {
  background: #e2e8f0;
  text-decoration: none;
  color: #0f172a;
}

.maiui-btn-register {
  background: rgba(255,255,255,.1);
  color: #e2e8f0;
  border: 1px solid rgba(255,255,255,.12);
}

.maiui-btn-register:hover {
  background: rgba(255,255,255,.16);
  text-decoration: none;
  color: #fff;
}

/* ---------- Mobile sidebar toggle ---------- */
.maiui-sidebar-toggle {
  display: none;
  position: fixed;
  top: 14px;
  left: 14px;
  z-index: 10001;
  background: #0f172a;
  border: none;
  color: #e2e8f0;
  border-radius: 8px;
  width: 36px;
  height: 36px;
  cursor: pointer;
  align-items: center;
  justify-content: center;
}

/* ---------- Main area ---------- */
.maiui-main {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
  background: #fff;
  height: 100%;
  overflow: hidden;
}

/* Top bar — municipality + lang */
.maiui-topbar {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 18px;
  border-bottom: 1px solid #f1f5f9;
  flex-shrink: 0;
  flex-wrap: wrap;
}

.maiui-topbar .maiui-field-select {
  flex: 1;
  min-width: 160px;
}

.maiui-topbar .maiui-field-select select {
  width: 100%;
  border: 1px solid #e2e8f0;
  border-radius: 10px;
  padding: 8px 14px;
  font-size: 14px;
  background: #f8fafc;
  color: #0f172a;
  outline: none;
  cursor: pointer;
  box-sizing: border-box;
}

.maiui-topbar .maiui-field-select select:focus {
  border-color: #94a3b8;
  box-shadow: 0 0 0 3px rgba(148,163,184,.18);
}

.maiui-lang-switch {
  display: inline-flex;
  gap: 4px;
  background: #f8fafc;
  border: 1px solid #e2e8f0;
  border-radius: 999px;
  padding: 4px;
  flex-shrink: 0;
}

.maiui-lang-btn {
  appearance: none;
  border: 0;
  background: transparent;
  color: #64748b;
  padding: 5px 11px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 700;
  letter-spacing: .04em;
  cursor: pointer;
  transition: all .15s ease;
}

.maiui-lang-btn:hover { background: #e2e8f0; color: #0f172a; }
.maiui-lang-btn.is-active { background: #0f172a; color: #fff; }

/* ---------- Welcome screen ---------- */
.maiui-welcome {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 32px 24px;
  text-align: center;
  overflow-y: auto;
}

.maiui-welcome-inner {
  max-width: 500px;
  width: 100%;
}

.maiui-welcome-logo {
  width: 300px;
  max-width: 80%;
  height: auto;
  object-fit: contain;
  border-radius: 16px;
  margin: 0 auto 24px;
  display: block;
}

.maiui-welcome-logo-fb {
  width: 80px;
  height: 80px;
  border-radius: 22px;
  background: linear-gradient(135deg,#0f172a,#334155);
  display: grid;
  place-items: center;
  margin: 0 auto 22px;
  font-size: 30px;
  font-weight: 700;
  color: #fff;
}

.maiui-welcome h1 {
  font-size: clamp(20px, 3vw, 30px);
  font-weight: 700;
  letter-spacing: -.02em;
  margin: 0 0 10px;
  color: #0f172a;
}

.maiui-welcome p {
  color: #64748b;
  font-size: 15px;
  line-height: 1.6;
  margin: 0;
}

/* ---------- Thread ---------- */
.maiui-thread {
  flex: 1;
  overflow-y: auto;
  padding: 20px 20px 10px;
  display: none;
  flex-direction: column;
  gap: 18px;
  min-height: 0;
}

.maiui-thread.has-messages {
  display: flex;
}

/* Message bubbles */
.maiui-msg {
  display: flex;
  gap: 12px;
  max-width: 100%;
}

.maiui-msg-user {
  flex-direction: row-reverse;
}

.maiui-msg-avatar {
  width: 32px;
  height: 32px;
  border-radius: 8px;
  flex-shrink: 0;
  display: grid;
  place-items: center;
  font-size: 14px;
  font-weight: 700;
  margin-top: 2px;
}

.maiui-msg-user .maiui-msg-avatar {
  background: #0f172a;
  color: #fff;
}

.maiui-msg-ai .maiui-msg-avatar {
  background: linear-gradient(135deg,#0073aa,#334155);
  color: #fff;
  font-size: 12px;
}

.maiui-msg-bubble {
  flex: 1;
  min-width: 0;
}

.maiui-msg-user .maiui-msg-bubble {
  background: #0f172a;
  color: #f1f5f9;
  border-radius: 18px 4px 18px 18px;
  padding: 12px 16px;
  font-size: 15px;
  line-height: 1.6;
  max-width: 72%;
  margin-left: auto;
}

.maiui-msg-ai .maiui-msg-bubble {
  background: #f8fafc;
  border: 1px solid #e2e8f0;
  border-radius: 4px 18px 18px 18px;
  padding: 0;
  overflow: hidden;
  max-width: 92%;
}

/* AI answer card inside thread */
.maiui-card {
  background: transparent;
  padding: 16px 18px;
  border: 0;
  border-radius: 0;
  box-shadow: none;
}

.maiui-card h3 { margin: 0 0 10px; font-size: 17px; line-height: 1.3; }
.maiui-card h4 { margin: 14px 0 6px; font-size: 14px; color: #0f172a; }
.maiui-card p { margin: 0 0 8px; line-height: 1.65; }
.maiui-card ul, .maiui-card ol { margin: 0; padding-left: 18px; }
.maiui-card li { margin: 0 0 6px; line-height: 1.6; }

.maiui-answer {
  font-size: 15px;
  font-weight: 500;
  background: #fff;
  padding: 12px 14px;
  border-radius: 10px;
  border-left: 3px solid #0f172a;
  margin-bottom: 10px;
}

.maiui-badge {
  display: inline-flex;
  align-items: center;
  padding: 4px 9px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 700;
  background: #eee;
  margin-left: 8px;
  vertical-align: middle;
}

.maiui-badge.ok { background: #dcfce7; color: #166534; }
.maiui-badge.partial { background: #fef3c7; color: #92400e; }
.maiui-badge.no { background: #fee2e2; color: #991b1b; }

.maiui-alt { background: #f8fafc; border-left: 3px solid #cbd5e1; padding: 10px 12px; border-radius: 10px; margin-top: 8px; }
.maiui-alt-official { border-left-color: #0073aa; background: #eff6ff; }
.maiui-alt strong { display: block; margin-bottom: 6px; line-height: 1.35; }
.maiui-snippet { margin-top: 8px; color: #334155; font-size: 14px; line-height: 1.6; }
.maiui-snippet p { margin: 0 0 8px; }

/* Loading */
.maiui-loading { display: flex; align-items: center; gap: 10px; color: #475569; padding: 16px 18px; }
.maiui-loading-dot { width: 8px; height: 8px; border-radius: 999px; background: #94a3b8; animation: maiuiPulse 1.2s infinite ease-in-out; }
.maiui-loading-dot:nth-child(2) { animation-delay: .15s; }
.maiui-loading-dot:nth-child(3) { animation-delay: .3s; }
@keyframes maiuiPulse { 0%,80%,100%{transform:scale(.75);opacity:.4} 40%{transform:scale(1);opacity:1} }

/* Sources */
.maiui-sources { display: grid; grid-template-columns: repeat(auto-fill,minmax(210px,1fr)); gap: 8px; margin: 6px 0 10px; }
.maiui-source-card { display: flex; align-items: center; gap: 10px; padding: 10px 12px; background: #fff; border: 1px solid #e2e8f0; border-radius: 12px; text-decoration: none; color: #0f172a; transition: all .18s ease; }
.maiui-source-card:hover { border-color: #0f172a; transform: translateY(-1px); box-shadow: 0 4px 14px rgba(15,23,42,.1); text-decoration: none; }
.maiui-source-card.maiui-source-nolink { cursor: default; opacity: .75; }
.maiui-source-card.maiui-source-nolink:hover { transform: none; border-color: #e2e8f0; box-shadow: none; }
.maiui-source-icon { font-size: 20px; flex-shrink: 0; }
.maiui-source-body { display: flex; flex-direction: column; gap: 2px; min-width: 0; flex: 1; }
.maiui-source-title { font-size: 13px; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.maiui-source-meta { font-size: 11px; color: #64748b; }
.maiui-source-arrow { color: #94a3b8; font-size: 13px; flex-shrink: 0; transition: transform .18s; }
.maiui-source-card:hover .maiui-source-arrow { color: #0f172a; transform: translate(2px,-2px); }

/* Citations */
.maiui-citations-list { list-style: none; padding-left: 0; margin: 6px 0; }
.maiui-citations-list li { padding: 9px 12px; margin: 5px 0; background: #f8fafc; border-left: 3px solid #94a3b8; border-radius: 7px; font-size: 13px; line-height: 1.5; }
.maiui-cite-quote { color: #334155; font-style: italic; }
.maiui-cite-source { color: #64748b; font-size: 11px; display: block; margin-top: 3px; font-style: normal; }
.maiui-cite-source a { color: #0073aa; text-decoration: none; }

/* Details collapsible */
.maiui-details { margin-top: 12px; background: #fff; border: 1px solid #e2e8f0; border-radius: 10px; overflow: hidden; }
.maiui-details summary { cursor: pointer; padding: 9px 12px; font-size: 12px; font-weight: 600; color: #475569; background: #f8fafc; border-bottom: 1px solid transparent; list-style: none; user-select: none; }
.maiui-details summary::-webkit-details-marker { display: none; }
.maiui-details summary::before { content: '▸'; display: inline-block; margin-right: 8px; transition: transform .15s; color: #94a3b8; }
.maiui-details[open] summary { border-bottom-color: #e2e8f0; }
.maiui-details[open] summary::before { transform: rotate(90deg); }
.maiui-details > .maiui-alt { margin: 12px; }

/* Feedback */
.maiui-footer { margin-top: 10px; padding-top: 8px; border-top: 1px dashed #e2e8f0; }
.maiui-feedback { display: flex; align-items: center; gap: 8px; font-size: 12px; color: #64748b; }
.maiui-fb-btn { appearance: none; border: 1px solid #dbe2ea; background: #fff; width: 32px; height: 32px; border-radius: 8px; cursor: pointer; font-size: 14px; transition: all .15s; }
.maiui-fb-btn:hover { background: #f1f5f9; transform: translateY(-1px); }
.maiui-followup-hint { margin-top: 8px; font-size: 12px; color: #64748b; font-style: italic; }
.maiui-error { border-left: 4px solid #d63638; color: #991b1b; padding: 14px 16px; }

/* ---------- Composer ---------- */
.maiui-composer-area {
  border-top: 1px solid #f1f5f9;
  padding: 16px 24px 20px;
  flex-shrink: 0;
  background: #fff;
  display: flex;
  justify-content: center;
}

.maiui-composer-inner {
  width: 100%;
  max-width: 720px;
}

.maiui-composer-wrap {
  position: relative;
  border: 1.5px solid #1e293b;
  border-radius: 18px;
  background: #fff;
  padding: 12px 56px 12px 16px;
  transition: border-color .2s, box-shadow .2s, background .2s;
  box-shadow: 0 4px 24px rgba(15,23,42,.13), 0 1px 4px rgba(15,23,42,.08);
}

.maiui-composer-wrap:focus-within {
  background: #fff;
  border-color: #0f172a;
  box-shadow: 0 6px 32px rgba(15,23,42,.18), 0 1px 4px rgba(15,23,42,.10);
}

#maiui_description {
  display: block;
  width: 100%;
  border: 0;
  outline: none;
  background: transparent;
  resize: none;
  min-height: 26px;
  max-height: 160px;
  overflow: auto;
  font-size: 15px;
  line-height: 1.6;
  color: #0f172a;
  padding: 0;
  margin: 0;
  box-sizing: border-box;
  font-family: inherit;
}

#maiui_description::placeholder { color: #94a3b8; }

.maiui-send {
  position: absolute;
  right: 10px;
  bottom: 10px;
  width: 38px;
  height: 38px;
  border: 0;
  border-radius: 12px;
  background: #0f172a;
  color: #fff;
  display: grid;
  place-items: center;
  cursor: pointer;
  box-shadow: 0 6px 14px rgba(15,23,42,.16);
  transition: transform .15s, background .15s;
}

.maiui-send:hover { background: #1e293b; transform: translateY(-1px); }
.maiui-send:active { transform: translateY(0); }

.maiui-composer-hint {
  font-size: 11px;
  color: #94a3b8;
  margin-top: 7px;
  padding-left: 2px;
  text-align: center;
}

/* Login wall */
.maiui-login-wall {
  background: #f8fafc;
  border: 1px solid #e2e8f0;
  border-radius: 14px;
  padding: 18px 20px;
  text-align: center;
  font-size: 14px;
  color: #475569;
}

.maiui-login-wall a { color: #0073aa; font-weight: 600; text-decoration: none; }
.maiui-login-wall a:hover { text-decoration: underline; }

/* ---------- Streaming cursor ---------- */
.maiui-cursor {
  display: inline-block;
  animation: maiuiBlink .7s step-end infinite;
  color: #94a3b8;
}
@keyframes maiuiBlink { 0%,100%{opacity:1} 50%{opacity:0} }

/* ---------- Responsive ---------- */
@media (max-width: 700px) {
  .maiui-sidebar {
    position: fixed;
    top: 0;
    left: 0;
    height: 100%;
    z-index: 10000;
    transform: translateX(-100%);
  }

  .maiui-sidebar.is-open {
    transform: translateX(0);
    box-shadow: 4px 0 24px rgba(0,0,0,.3);
  }

  .maiui-sidebar-toggle {
    display: flex;
  }

  .maiui-topbar {
    padding-left: 62px;
  }

  .maiui-msg-user .maiui-msg-bubble {
    max-width: 88%;
  }

  .maiui-welcome-logo {
    width: 200px;
  }
}

/* ---------- Welcome municipality selector ---------- */
.maiui-welcome-mun {
  margin-top: 22px;
}

.maiui-mun-select-welcome {
  width: 100%;
  max-width: 340px;
  border: 1.5px solid #e2e8f0;
  border-radius: 14px;
  padding: 12px 18px;
  font-size: 15px;
  background: #fff;
  color: #0f172a;
  outline: none;
  cursor: pointer;
  box-shadow: 0 4px 14px rgba(15,23,42,.07);
  transition: border-color .2s, box-shadow .2s;
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%2364748b' stroke-width='2.5'%3E%3Cpath d='M6 9l6 6 6-6'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 14px center;
  padding-right: 38px;
  box-sizing: border-box;
}

.maiui-mun-select-welcome:focus {
  border-color: #94a3b8;
  box-shadow: 0 0 0 3px rgba(148,163,184,.18);
}
