:root {
  --bg-main: #0d1117;
  --bg-sidebar: #161b22;
  --bg-card: #1f242c;
  --bg-input: #161b22;
  --border-color: #30363d;
  --text-main: #f0f6fc;
  --text-muted: #8b949e;
  --primary: #58a6ff;
  --primary-hover: #79c0ff;
  --accent-purple: #bc8cff;
  --accent-green: #3fb950;
  --accent-orange: #d29922;
  --accent-red: #f85149;
  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 18px;
  --shadow: 0 4px 16px rgba(0, 0, 0, 0.35);
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  font-family: var(--font);
  -webkit-tap-highlight-color: transparent;
}

body, html {
  height: 100%;
  background-color: var(--bg-main);
  color: var(--text-main);
  overflow: hidden;
}

/* Container Principal */
.app-container {
  display: flex;
  height: 100vh;
  width: 100vw;
  position: relative;
  overflow: hidden;
}

/* ================================================= */
/* Sidebar Retrátil / Mobile Drawer                  */
/* ================================================= */
.sidebar {
  width: 300px;
  height: 100%;
  background-color: var(--bg-sidebar);
  border-right: 1px solid var(--border-color);
  display: flex;
  flex-direction: column;
  z-index: 100;
  transition: transform 0.25s cubic-bezier(0.4, 0, 0.2, 1);
}

.sidebar-header {
  padding: 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-bottom: 1px solid var(--border-color);
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
}

.brand-icon {
  font-size: 26px;
}

.brand-info h2 {
  font-size: 17px;
  font-weight: 700;
  color: var(--text-main);
  line-height: 1.2;
}

.brand-sub {
  font-size: 11px;
  color: var(--accent-purple);
  font-weight: 600;
  letter-spacing: 0.5px;
}

/* Cartão do Morador */
.user-profile-card {
  margin: 12px 16px;
  padding: 10px 14px;
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  display: flex;
  align-items: center;
  gap: 10px;
}

.user-avatar {
  width: 38px;
  height: 38px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.user-avatar-badge {
  width: 38px;
  height: 38px;
  border-radius: 50%;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: #ffffff;
  font-weight: 700;
  font-size: 15px;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.35);
  text-transform: uppercase;
  flex-shrink: 0;
  user-select: none;
}

.icon-btn svg, .switch-user-btn svg, .icon-btn-mini svg, .btn-call svg, .msg-action-btn svg, .live-control-btn svg {
  display: inline-block;
  vertical-align: middle;
  pointer-events: none;
}

.user-details {
  flex: 1;
  display: flex;
  flex-direction: column;
}

.user-name {
  font-size: 14px;
  font-weight: 600;
}

.user-role {
  font-size: 11px;
  color: var(--text-muted);
}

.switch-user-btn {
  background: transparent;
  border: 1px solid var(--border-color);
  color: var(--text-muted);
  width: 28px;
  height: 28px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 14px;
  transition: all 0.2s;
}

.switch-user-btn:hover {
  background: var(--border-color);
  color: var(--text-main);
}

/* Ações */
.sidebar-actions {
  padding: 0 16px 12px;
}

.new-chat-btn {
  width: 100%;
  padding: 10px;
  border-radius: var(--radius-md);
  font-size: 14px;
  font-weight: 600;
  background: #238636;
  border: 1px solid rgba(240, 246, 252, 0.1);
  color: #fff;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  transition: background 0.2s;
}

.new-chat-btn:hover {
  background: #2ea043;
}

.sidebar-section {
  padding: 10px 16px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.section-label {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--text-muted);
  font-weight: 700;
}

.section-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.model-select {
  width: 100%;
  padding: 8px 10px;
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  color: var(--text-main);
  font-size: 13px;
  outline: none;
}

/* Listas com Scroll */
.projects-list, .conv-list {
  display: flex;
  flex-direction: column;
  gap: 4px;
  max-height: 180px;
  overflow-y: auto;
}

.conv-section {
  flex: 1;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

.conv-list {
  flex: 1;
  max-height: none;
}

.item-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 10px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  font-size: 13px;
  color: var(--text-muted);
  transition: all 0.15s;
}

.item-row:hover, .item-row.active {
  background: var(--bg-card);
  color: var(--text-main);
}

.item-row.active {
  border-left: 3px solid var(--primary);
  font-weight: 600;
}

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

.item-del-btn {
  background: transparent;
  border: none;
  color: var(--text-muted);
  font-size: 12px;
  cursor: pointer;
  opacity: 0;
  transition: opacity 0.2s;
}

.item-row:hover .item-del-btn {
  opacity: 1;
}

/* Rodapé Sidebar */
.sidebar-footer {
  padding: 12px 16px;
  border-top: 1px solid var(--border-color);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.status-indicator {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 12px;
  color: var(--text-muted);
}

.status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--accent-green);
  box-shadow: 0 0 6px var(--accent-green);
}

/* ================================================= */
/* Conteúdo Principal / Topbar                       */
/* ================================================= */
.main-content {
  flex: 1;
  display: flex;
  flex-direction: column;
  height: 100%;
  position: relative;
  background: var(--bg-main);
}

.topbar {
  height: 56px;
  padding: 0 16px;
  border-bottom: 1px solid var(--border-color);
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: rgba(22, 27, 34, 0.85);
  backdrop-filter: blur(8px);
}

.topbar-left {
  display: flex;
  align-items: center;
  gap: 12px;
  overflow: hidden;
}

.chat-header-info {
  display: flex;
  align-items: center;
  gap: 8px;
  overflow: hidden;
}

.chat-title {
  font-size: 15px;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.project-badge {
  font-size: 11px;
  padding: 2px 8px;
  border-radius: 12px;
  background: rgba(188, 140, 255, 0.15);
  color: var(--accent-purple);
  border: 1px solid rgba(188, 140, 255, 0.3);
  white-space: nowrap;
}

/* Botão Chamada ao Vivo */
.btn-call {
  background: linear-gradient(135deg, #1f6feb 0%, #8957e5 100%);
  border: none;
  color: #fff;
  padding: 8px 14px;
  border-radius: 20px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 6px;
  box-shadow: 0 2px 8px rgba(137, 87, 229, 0.3);
  transition: all 0.2s;
}

.btn-call:hover {
  transform: translateY(-1px);
  box-shadow: 0 4px 12px rgba(137, 87, 229, 0.45);
}

/* ================================================= */
/* Mensagens & Chat Scroll                           */
/* ================================================= */
.messages-scroll {
  flex: 1;
  overflow-y: auto;
  padding: 20px 16px;
  display: flex;
  flex-direction: column;
}

.messages-container {
  max-width: 800px;
  width: 100%;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

/* Welcome Hero */
.welcome-hero {
  margin: auto;
  text-align: center;
  padding: 40px 16px;
  max-width: 480px;
}

.hero-icon {
  font-size: 48px;
  margin-bottom: 12px;
}

.welcome-hero h2 {
  font-size: 22px;
  font-weight: 700;
  margin-bottom: 8px;
}

.welcome-hero p {
  color: var(--text-muted);
  font-size: 14px;
  line-height: 1.5;
  margin-bottom: 24px;
}

.quick-prompts {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.prompt-chip {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  color: var(--text-main);
  padding: 10px 14px;
  border-radius: var(--radius-md);
  font-size: 13px;
  text-align: left;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 6px;
  transition: all 0.2s;
}

.prompt-chip:hover {
  border-color: var(--primary);
  background: rgba(88, 166, 255, 0.08);
}

/* Balões de Mensagem */
.message {
  display: flex;
  flex-direction: column;
  max-width: 85%;
  animation: fadeIn 0.2s ease-out;
}

@keyframes fadeIn {
  from { opacity: 0; transform: translateY(6px); }
  to { opacity: 1; transform: translateY(0); }
}

.message.user {
  align-self: flex-end;
}

.message.assistant {
  align-self: flex-start;
  width: 100%;
  max-width: 100%;
}

.message-bubble {
  padding: 12px 16px;
  border-radius: var(--radius-lg);
  font-size: 14.5px;
  line-height: 1.6;
  position: relative;
  word-break: break-word;
}

.message.user .message-bubble {
  background: #1f6feb;
  color: #ffffff;
  border-bottom-right-radius: 4px;
}

.message.assistant .message-bubble {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  color: var(--text-main);
  border-bottom-left-radius: 4px;
}

/* Badges de Motor e Ações */
.message-meta {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 6px;
  font-size: 11px;
  color: var(--text-muted);
}

.engine-badge {
  padding: 2px 6px;
  border-radius: 6px;
  font-weight: 600;
  font-size: 10.5px;
}

.engine-badge.local {
  background: rgba(63, 185, 80, 0.15);
  color: var(--accent-green);
  border: 1px solid rgba(63, 185, 80, 0.3);
}

.engine-badge.cloud {
  background: rgba(88, 166, 255, 0.15);
  color: var(--primary);
  border: 1px solid rgba(88, 166, 255, 0.3);
}

.msg-action-btn {
  background: transparent;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  padding: 2px 6px;
  border-radius: 4px;
  font-size: 12px;
  transition: all 0.2s;
}

.msg-action-btn:hover {
  background: rgba(255, 255, 255, 0.08);
  color: var(--text-main);
}

.btn-deepen {
  color: var(--accent-purple);
  border: 1px solid rgba(188, 140, 255, 0.3);
  border-radius: 6px;
  padding: 2px 8px;
}

.btn-deepen:hover {
  background: rgba(188, 140, 255, 0.15);
}

/* Blocos de Código em Markdown */
.message-bubble pre {
  margin: 10px 0;
  border-radius: var(--radius-sm);
  background: #0d1117 !important;
  border: 1px solid var(--border-color);
  overflow-x: auto;
  padding: 12px;
}

.message-bubble code {
  font-family: ui-monospace, SFMono-Regular, Consolas, monospace;
  font-size: 13px;
}

.message-bubble p {
  margin-bottom: 8px;
}

.message-bubble p:last-child {
  margin-bottom: 0;
}

/* ================================================= */
/* Barra Inferior de Digitação                       */
/* ================================================= */
.input-footer {
  padding: 12px 16px;
  background: var(--bg-main);
  border-top: 1px solid var(--border-color);
}

.input-bar-container {
  max-width: 800px;
  margin: 0 auto;
  display: flex;
  align-items: flex-end;
  background: var(--bg-input);
  border: 1px solid var(--border-color);
  border-radius: 24px;
  padding: 6px 10px;
  gap: 8px;
  transition: border-color 0.2s;
}

.input-bar-container:focus-within {
  border-color: var(--primary);
}

.chat-input {
  flex: 1;
  background: transparent;
  border: none;
  color: var(--text-main);
  font-size: 14.5px;
  line-height: 1.4;
  padding: 8px 4px;
  resize: none;
  max-height: 120px;
  outline: none;
}

.icon-btn {
  background: transparent;
  border: none;
  color: var(--text-muted);
  width: 38px;
  height: 38px;
  border-radius: 50%;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 18px;
  transition: all 0.2s;
}

.icon-btn:hover {
  background: rgba(255, 255, 255, 0.08);
  color: var(--text-main);
}

.icon-btn-mini {
  background: transparent;
  border: none;
  color: var(--text-muted);
  width: 24px;
  height: 24px;
  border-radius: 4px;
  cursor: pointer;
  font-size: 16px;
}

.send-btn {
  background: var(--primary);
  color: #fff;
}

.send-btn:hover {
  background: var(--primary-hover);
  color: #fff;
}

.ptt-btn {
  color: var(--primary);
}

.ptt-btn.active {
  background: rgba(248, 81, 73, 0.2);
  color: var(--accent-red);
  animation: pulse 1s infinite;
}

@keyframes pulse {
  0% { transform: scale(1); }
  50% { transform: scale(1.1); }
  100% { transform: scale(1); }
}

.ptt-indicator {
  max-width: 800px;
  margin: 6px auto 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: rgba(248, 81, 73, 0.15);
  border: 1px solid rgba(248, 81, 73, 0.3);
  padding: 6px 14px;
  border-radius: 20px;
  font-size: 12px;
}

.ptt-cancel-btn {
  background: transparent;
  border: none;
  color: var(--accent-red);
  font-weight: 600;
  cursor: pointer;
}

/* Preview de Anexos */
.attachments-preview-bar {
  max-width: 800px;
  margin: 0 auto;
  padding: 6px 16px;
}

.preview-items {
  display: flex;
  gap: 8px;
}

.preview-badge {
  display: flex;
  align-items: center;
  gap: 6px;
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  padding: 4px 10px;
  border-radius: var(--radius-sm);
  font-size: 12px;
}

/* ================================================= */
/* MODAL: Chamada ao Vivo (Live Mode)                */
/* ================================================= */
.live-modal {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
}

.live-modal-backdrop {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(13, 17, 23, 0.95);
  backdrop-filter: blur(20px);
}

.live-modal-content {
  position: relative;
  width: 100%;
  max-width: 440px;
  height: 100%;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  padding: 32px 24px;
  z-index: 2;
}

.live-modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.live-status-pill {
  display: flex;
  align-items: center;
  gap: 8px;
  background: rgba(63, 185, 80, 0.15);
  border: 1px solid rgba(63, 185, 80, 0.3);
  padding: 6px 14px;
  border-radius: 20px;
  font-size: 13px;
  color: var(--accent-green);
}

.live-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--accent-green);
  box-shadow: 0 0 8px var(--accent-green);
  animation: pulse 1.5s infinite;
}

.live-timer {
  font-size: 14px;
  color: var(--text-muted);
  font-variant-numeric: tabular-nums;
}

/* Esfera Visualizadora Reativa */
.live-visualizer-wrap {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 32px;
}

.voice-orb {
  width: 140px;
  height: 140px;
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
}

.orb-core {
  width: 80px;
  height: 80px;
  border-radius: 50%;
  background: linear-gradient(135deg, #1f6feb 0%, #8957e5 100%);
  box-shadow: 0 0 35px rgba(137, 87, 229, 0.6);
  transition: transform 0.15s ease-out;
}

.voice-orb.speaking .orb-core {
  animation: orbPulse 1.2s infinite alternate;
}

@keyframes orbPulse {
  0% { transform: scale(0.95); box-shadow: 0 0 25px rgba(137, 87, 229, 0.5); }
  100% { transform: scale(1.15); box-shadow: 0 0 55px rgba(88, 166, 255, 0.8); }
}

.orb-ring {
  position: absolute;
  border-radius: 50%;
  border: 2px solid rgba(137, 87, 229, 0.25);
  pointer-events: none;
}

.ring-1 { width: 110px; height: 110px; }
.ring-2 { width: 140px; height: 140px; }
.ring-3 { width: 170px; height: 170px; }

.live-prompt-hint {
  font-size: 15px;
  color: var(--text-muted);
  text-align: center;
}

.live-transcript {
  max-height: 100px;
  overflow-y: auto;
  text-align: center;
  font-size: 14px;
  color: var(--text-main);
  padding: 0 10px;
}

.live-controls {
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 24px;
}

.live-control-btn {
  width: 58px;
  height: 58px;
  border-radius: 50%;
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 22px;
  transition: transform 0.15s;
}

.live-control-btn:hover {
  transform: scale(1.05);
}

.mute-btn {
  background: var(--bg-card);
  color: var(--text-main);
  border: 1px solid var(--border-color);
}

.interrupt-btn {
  background: rgba(210, 153, 34, 0.2);
  color: var(--accent-orange);
  border: 1px solid rgba(210, 153, 34, 0.4);
}

.end-call-btn {
  background: var(--accent-red);
  color: #fff;
  box-shadow: 0 4px 16px rgba(248, 81, 73, 0.4);
}

/* ================================================= */
/* MODAIS GENÉRICOS (Morador, Projetos, Settings)    */
/* ================================================= */
.modal {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 500;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
}

.modal-backdrop {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.7);
}

.modal-dialog {
  position: relative;
  background: var(--bg-sidebar);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  width: 100%;
  max-width: 420px;
  padding: 20px;
  z-index: 2;
  box-shadow: var(--shadow);
}

.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 16px;
}

.modal-header h3 {
  font-size: 16px;
}

.user-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

.user-grid-item {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 14px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  cursor: pointer;
  transition: all 0.2s;
}

.user-grid-item:hover {
  border-color: var(--primary);
  background: rgba(88, 166, 255, 0.08);
}

.user-grid-item .u-avatar {
  font-size: 32px;
}

.user-grid-item .u-name {
  font-size: 14px;
  font-weight: 600;
}

.form-group {
  margin-bottom: 14px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.form-group label {
  font-size: 12px;
  color: var(--text-muted);
}

.form-group input, .form-group textarea {
  background: var(--bg-main);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  color: var(--text-main);
  padding: 10px;
  font-size: 14px;
  outline: none;
}

.form-group input:focus, .form-group textarea:focus {
  border-color: var(--primary);
}

.form-help {
  font-size: 11px;
  color: var(--text-muted);
}

.form-help a {
  color: var(--primary);
  text-decoration: none;
}

.btn-primary {
  background: var(--primary);
  color: #fff;
  border: none;
  padding: 10px 16px;
  border-radius: var(--radius-sm);
  font-weight: 600;
  font-size: 14px;
  cursor: pointer;
}

.system-diagnostic-box {
  margin-top: 14px;
  background: var(--bg-main);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  padding: 12px;
  font-size: 12px;
  color: var(--text-muted);
  line-height: 1.5;
}

/* ================================================= */
/* RESPONSIVIDADE MOBILE FIRST                       */
/* ================================================= */
.menu-btn {
  display: none;
}

.close-sidebar-btn {
  display: none;
}

.sidebar-overlay {
  display: none;
}

@media (max-width: 768px) {
  .menu-btn {
    display: flex;
  }

  .close-sidebar-btn {
    display: flex;
  }

  .sidebar {
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    transform: translateX(-100%);
    box-shadow: 4px 0 24px rgba(0, 0, 0, 0.5);
  }

  .sidebar.open {
    transform: translateX(0);
  }

  .sidebar-overlay.active {
    display: block;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.6);
    z-index: 99;
  }
}

/* Kiwix RAG Offline Badge */
.rag-badge-offline {
  display: inline-flex;
  align-items: center;
  margin-top: 6px;
  margin-bottom: 2px;
}

.rag-badge-offline a {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: rgba(56, 189, 248, 0.12);
  border: 1px solid rgba(56, 189, 248, 0.3);
  color: #38bdf8;
  font-size: 11.5px;
  font-weight: 600;
  padding: 3px 9px;
  border-radius: 6px;
  text-decoration: none;
  transition: all 0.15s ease;
}

.rag-badge-offline a:hover {
  background: rgba(56, 189, 248, 0.22);
  border-color: #38bdf8;
  box-shadow: 0 2px 8px rgba(56, 189, 248, 0.2);
}

