:root {
  --bg-primary: #090d16;
  --bg-secondary: #131b2e;
  --bg-card: #1e293b;
  --bg-hover: #334155;
  --text-main: #f8fafc;
  --text-muted: #94a3b8;
  --accent: #0ea5e9;
  --accent-glow: rgba(14, 165, 233, 0.35);
  --success: #10b981;
  --danger: #f43f5e;
  --warning: #f59e0b;
  --border: #334155;
  --radius-lg: 16px;
  --radius-md: 10px;
  --radius-sm: 6px;
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  -webkit-tap-highlight-color: transparent;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background-color: var(--bg-primary);
  color: var(--text-main);
  height: 100vh;
  height: 100dvh;
  overflow: hidden;
  user-select: none;
}

#app {
  height: 100%;
  display: flex;
  flex-direction: column;
}

.view {
  display: none;
  height: 100%;
  width: 100%;
}

.view.active {
  display: flex;
  flex-direction: column;
}

/* ================= Tela de Login ================= */
#login-view {
  justify-content: center;
  align-items: center;
  padding: 24px;
}

.login-card {
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 32px 24px;
  width: 100%;
  max-width: 360px;
  box-shadow: 0 10px 25px -5px rgba(0, 0, 0, 0.5);
  text-align: center;
}

.logo-area {
  margin-bottom: 24px;
}

.logo-icon {
  font-size: 48px;
  margin-bottom: 8px;
}

.logo-area h1 {
  font-size: 24px;
  font-weight: 700;
  letter-spacing: -0.5px;
}

.logo-area p {
  color: var(--text-muted);
  font-size: 14px;
  margin-top: 4px;
}

#login-form {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

#login-form label {
  font-size: 13px;
  font-weight: 500;
  color: var(--text-muted);
  text-align: left;
}

.pin-field-wrapper input {
  width: 100%;
  background: var(--bg-card);
  border: 1px solid var(--border);
  color: var(--text-main);
  padding: 14px;
  border-radius: var(--radius-md);
  font-size: 22px;
  text-align: center;
  letter-spacing: 8px;
  outline: none;
  transition: border-color 0.2s;
}

.pin-field-wrapper input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 2px var(--accent-glow);
}

.btn-primary {
  background: var(--accent);
  color: #fff;
  border: none;
  padding: 14px;
  border-radius: var(--radius-md);
  font-size: 16px;
  font-weight: 600;
  cursor: pointer;
  transition: opacity 0.2s;
}

.btn-primary:active {
  opacity: 0.85;
}

.error-msg {
  color: var(--danger);
  font-size: 13px;
  text-align: left;
}

.hidden {
  display: none !important;
}

/* ================= Cabeçalho do App ================= */
.app-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 12px 16px;
  background: var(--bg-secondary);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
  padding-top: calc(12px + env(safe-area-inset-top));
}

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

.dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  flex-shrink: 0;
}

.dot.online {
  background: var(--success);
  box-shadow: 0 0 8px var(--success);
}

.dot.offline {
  background: var(--danger);
}

.status-info {
  display: flex;
  flex-direction: column;
}

.status-text {
  font-size: 14px;
  font-weight: 600;
}

.workspace-text {
  font-size: 11px;
  color: var(--text-muted);
  max-width: 160px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.header-actions {
  display: flex;
  gap: 8px;
}

.icon-btn,
.icon-toggle {
  background: var(--bg-card);
  border: 1px solid var(--border);
  color: var(--text-main);
  padding: 8px;
  border-radius: var(--radius-md);
  font-size: 16px;
  cursor: pointer;
}

.icon-toggle.active {
  background: var(--bg-hover);
  border-color: var(--accent);
}

/* Banner de Escuta */
.banner {
  background: rgba(16, 185, 129, 0.15);
  border-bottom: 1px solid rgba(16, 185, 129, 0.3);
  padding: 8px 16px;
  font-size: 13px;
  color: var(--success);
  display: flex;
  align-items: center;
  gap: 8px;
}

/* ================= Chat Feed ================= */
.chat-container {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  scroll-behavior: smooth;
}

.welcome-box {
  background: var(--bg-secondary);
  border: 1px dashed var(--border);
  padding: 16px;
  border-radius: var(--radius-md);
  font-size: 14px;
  line-height: 1.5;
}

.welcome-box .sub-text {
  color: var(--text-muted);
  margin-top: 6px;
  font-size: 13px;
}

.msg-bubble {
  max-width: 88%;
  padding: 12px 14px;
  border-radius: var(--radius-md);
  font-size: 14px;
  line-height: 1.45;
  word-break: break-word;
}

.msg-bubble.user {
  align-self: flex-end;
  background: var(--accent);
  color: #fff;
  border-bottom-right-radius: 2px;
}

.msg-bubble.agent {
  align-self: flex-start;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-bottom-left-radius: 2px;
}

.msg-bubble.system {
  align-self: center;
  background: transparent;
  color: var(--text-muted);
  font-size: 12px;
  padding: 4px 8px;
}

/* Card de Confirmação Obrigatória (Protocolo de Voz) */
.confirmation-card {
  align-self: flex-start;
  width: 100%;
  max-width: 95%;
  background: var(--bg-secondary);
  border: 2px solid var(--warning);
  border-radius: var(--radius-lg);
  padding: 16px;
  box-shadow: 0 4px 15px rgba(245, 158, 11, 0.15);
}

.confirm-header {
  display: flex;
  align-items: center;
  gap: 8px;
  font-weight: 700;
  color: var(--warning);
  margin-bottom: 10px;
  font-size: 14px;
}

.confirm-body {
  font-size: 13.5px;
  line-height: 1.5;
  margin-bottom: 16px;
  white-space: pre-wrap;
}

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

.btn-authorize {
  background: var(--success);
  color: #fff;
  border: none;
  padding: 12px;
  border-radius: var(--radius-md);
  font-weight: 700;
  font-size: 14px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
}

.btn-cancel {
  background: var(--bg-card);
  border: 1px solid var(--border);
  color: var(--text-muted);
  padding: 12px;
  border-radius: var(--radius-md);
  font-weight: 600;
  font-size: 14px;
  cursor: pointer;
}

.btn-authorize:active,
.btn-cancel:active {
  opacity: 0.8;
}

/* ================= Barra de Comando (Inferior) ================= */
.command-bar {
  background: var(--bg-secondary);
  border-top: 1px solid var(--border);
  padding: 12px 16px;
  padding-bottom: calc(12px + env(safe-area-inset-bottom));
  display: flex;
  flex-direction: column;
  gap: 10px;
  flex-shrink: 0;
}

.input-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 8px 12px;
}

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

.label-info {
  font-size: 11px;
  color: var(--text-muted);
  font-weight: 500;
}

.auto-send-toggle {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 11px;
  color: var(--text-muted);
  cursor: pointer;
}

.textarea-wrapper {
  position: relative;
  display: flex;
  align-items: center;
}

#command-text {
  width: 100%;
  background: transparent;
  border: none;
  color: var(--text-main);
  font-size: 15px;
  resize: none;
  outline: none;
  font-family: inherit;
  line-height: 1.4;
  padding-right: 28px;
}

.btn-subtle {
  position: absolute;
  right: 0;
  top: 4px;
  background: transparent;
  border: none;
  color: var(--text-muted);
  font-size: 16px;
  cursor: pointer;
}

/* Botões de Ação Inferiores */
.action-buttons-row {
  display: flex;
  justify-content: center;
  align-items: center;
  position: relative;
  height: 64px;
}

.btn-mic {
  position: relative;
  width: 64px;
  height: 64px;
  border-radius: 50%;
  background: var(--accent);
  border: none;
  cursor: pointer;
  display: flex;
  justify-content: center;
  align-items: center;
  box-shadow: 0 4px 15px var(--accent-glow);
  transition: transform 0.15s, background 0.2s;
  z-index: 2;
}

.mic-inner {
  font-size: 28px;
  line-height: 1;
}

.btn-mic:active,
.btn-mic.recording {
  transform: scale(1.08);
  background: var(--danger);
  box-shadow: 0 0 25px rgba(244, 63, 94, 0.6);
}

.btn-mic.recording .mic-ring {
  position: absolute;
  top: -8px;
  left: -8px;
  right: -8px;
  bottom: -8px;
  border-radius: 50%;
  border: 2px solid var(--danger);
  animation: pulse-ring 1.2s infinite cubic-bezier(0.215, 0.61, 0.355, 1);
}

@keyframes pulse-ring {
  0% {
    transform: scale(0.9);
    opacity: 1;
  }

  100% {
    transform: scale(1.4);
    opacity: 0;
  }
}

.btn-send {
  position: absolute;
  right: 8px;
  width: 44px;
  height: 44px;
  border-radius: 50%;
  background: var(--bg-card);
  border: 1px solid var(--border);
  color: var(--accent);
  font-size: 18px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: opacity 0.2s;
}

.btn-send:active {
  opacity: 0.7;
}