/* ─── Screens ───────────────────────────────────────────────── */
.screen { display: none; }
.screen.active { display: flex; }

/* ─── Login ─────────────────────────────────────────────────── */
#screen-login {
  min-height: 100dvh;
  align-items: center;
  justify-content: center;
  padding: 24px;
}

.login-card {
  width: 100%;
  max-width: 380px;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 40px 32px;
}

.login-logo {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 32px;
}

.login-logo-icon {
  width: 38px;
  height: 38px;
  background: var(--violet);
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 18px;
}

/* Ícone de marca (Velen) — quadrado já traz o próprio fundo no SVG */
.login-logo-icon.brand, .topbar-icon.brand { background: transparent; overflow: hidden; }
.login-logo-icon img, .topbar-icon img { width: 100%; height: 100%; display: block; }

.login-logo-name {
  font-size: 1.1rem;
  font-weight: 600;
  color: var(--text);
}

.login-logo-sub {
  font-size: 0.7rem;
  color: var(--muted);
  font-weight: 400;
}

.login-title {
  font-size: 1.35rem;
  font-weight: 600;
  margin-bottom: 6px;
}

.login-subtitle {
  color: var(--muted);
  font-size: 0.88rem;
  margin-bottom: 28px;
}

label {
  display: block;
  font-size: 0.8rem;
  font-weight: 500;
  color: var(--muted);
  margin-bottom: 6px;
  letter-spacing: 0.02em;
  text-transform: uppercase;
}

input[type="email"],
input[type="password"],
input[type="text"],
input[type="url"],
input[type="date"] {
  width: 100%;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
  font-family: inherit;
  font-size: 0.95rem;
  padding: 11px 14px;
  outline: none;
  transition: border-color 0.2s;
  margin-bottom: 18px;
}

input:focus, textarea:focus {
  border-color: var(--violet);
}

textarea {
  width: 100%;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
  font-family: inherit;
  font-size: .88rem;
  padding: 11px 14px;
  outline: none;
  resize: vertical;
  transition: border-color .2s;
  margin-bottom: 4px;
}

input::placeholder { color: #4d495e; }

.btn {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  width: 100%;
  padding: 12px;
  background: var(--violet);
  color: #fff;
  border: none;
  border-radius: var(--radius-sm);
  font-family: inherit;
  font-size: 0.95rem;
  font-weight: 500;
  cursor: pointer;
  transition: opacity 0.15s, transform 0.1s;
}

.btn:hover { opacity: 0.88; }
.btn:active { transform: scale(0.98); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }

.btn-ghost {
  background: transparent;
  color: var(--muted);
  border: 1px solid var(--border);
  font-size: 0.85rem;
  padding: 8px 14px;
  width: auto;
}

.error-msg {
  background: #f8717118;
  border: 1px solid #f8717130;
  color: var(--red);
  border-radius: var(--radius-sm);
  padding: 10px 14px;
  font-size: 0.85rem;
  margin-bottom: 16px;
  display: none;
}

.error-msg.visible { display: block; }

/* ─── Dashboard ─────────────────────────────────────────────── */
#screen-dashboard {
  flex-direction: column;
  min-height: 100dvh;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
  background: var(--surface);
  position: sticky;
  top: 0;
  z-index: 10;
}

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

.topbar-icon {
  width: 32px;
  height: 32px;
  background: var(--violet);
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 15px;
}

.topbar-name {
  font-size: 0.95rem;
  font-weight: 600;
}

.topbar-instance {
  font-size: 0.75rem;
  color: var(--muted);
}

.main {
  flex: 1;
  padding: 20px 16px;
  max-width: 480px;
  width: 100%;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

/* ─── Cards ──────────────────────────────────────────────────── */
.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
}

.card-label {
  font-size: 0.72rem;
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--muted);
  margin-bottom: 14px;
}

/* ─── Status Card ────────────────────────────────────────────── */
.status-body {
  display: flex;
  align-items: center;
  gap: 16px;
}

.status-dot-wrap {
  position: relative;
  flex-shrink: 0;
}

.status-dot {
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: var(--muted);
}

.status-dot.connected  { background: var(--green); }
.status-dot.disconnected { background: var(--red); }
.status-dot.connecting { background: var(--amber); }

.status-dot.connected::after {
  content: '';
  position: absolute;
  inset: -4px;
  border-radius: 50%;
  background: var(--green);
  opacity: 0.25;
  animation: pulse 2s ease-in-out infinite;
}

@keyframes pulse {
  0%, 100% { transform: scale(1); opacity: 0.25; }
  50%       { transform: scale(1.6); opacity: 0; }
}

.status-info {}

.status-label {
  font-size: 1.05rem;
  font-weight: 600;
  margin-bottom: 2px;
}

.status-label.connected   { color: var(--green); }
.status-label.disconnected { color: var(--red); }
.status-label.connecting  { color: var(--amber); }

.status-desc {
  font-size: 0.82rem;
  color: var(--muted);
}

/* ─── Refresh bar ────────────────────────────────────────────── */
.refresh-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-top: 16px;
  padding-top: 14px;
  border-top: 1px solid var(--border);
}

.refresh-text {
  font-size: 0.78rem;
  color: var(--muted);
}

.refresh-bar-wrap {
  width: 80px;
  height: 3px;
  background: var(--border);
  border-radius: 99px;
  overflow: hidden;
}

.refresh-bar {
  height: 100%;
  background: var(--violet);
  border-radius: 99px;
  width: 100%;
  transition: width 1s linear;
}

/* ─── QR Code Card ───────────────────────────────────────────── */
#card-qr { display: none; }
#card-qr.visible { display: block; }

.qr-wrap {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 16px;
  padding: 8px 0;
}

.qr-img-frame {
  background: #fff;
  border-radius: 12px;
  padding: 12px;
  display: inline-block;
}

.qr-img-frame img {
  display: block;
  width: 200px;
  height: 200px;
  border-radius: 4px;
}

.qr-instructions {
  font-size: 0.82rem;
  color: var(--muted);
  text-align: center;
  line-height: 1.6;
  max-width: 260px;
}

.qr-instructions strong {
  color: var(--text);
  font-weight: 500;
}

.qr-loading {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  padding: 24px 0;
  color: var(--muted);
  font-size: 0.85rem;
}

.spinner {
  width: 28px;
  height: 28px;
  border: 2px solid var(--border);
  border-top-color: var(--violet);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

@keyframes spin { to { transform: rotate(360deg); } }

/* ─── Loading screen ─────────────────────────────────────────── */
#screen-loading {
  min-height: 100dvh;
  align-items: center;
  justify-content: center;
  flex-direction: column;
  gap: 16px;
}

#screen-loading .spinner { width: 36px; height: 36px; }

/* ─── Admin ─────────────────────────────────────────────────── */
#screen-admin { flex-direction: column; min-height: 100dvh; }
#screen-error-logs { flex-direction: column; min-height: 100dvh; }
#screen-error-logs .admin-main { max-width: 900px; }

.admin-main {
  flex: 1;
  padding: 20px 16px;
  max-width: 600px;
  width: 100%;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

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

.admin-title {
  font-size: 1rem;
  font-weight: 600;
  color: var(--text);
}

.btn-sm {
  padding: 8px 14px;
  font-size: 0.82rem;
  width: auto;
  border-radius: var(--radius-sm);
}

/* Lista de clientes */
.user-list { display: flex; flex-direction: column; gap: 10px; }

.user-card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 16px;
  display: flex;
  align-items: center;
  gap: 14px;
}

.user-avatar {
  width: 40px;
  height: 40px;
  border-radius: 10px;
  background: var(--violet-dim);
  border: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.1rem;
  flex-shrink: 0;
}

.user-info { flex: 1; min-width: 0; }

.user-name {
  font-size: 0.92rem;
  font-weight: 500;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.user-meta {
  font-size: 0.75rem;
  color: var(--muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.user-badges {
  display: flex;
  gap: 6px;
  flex-shrink: 0;
  align-items: center;
}

.badge {
  font-size: 0.68rem;
  font-weight: 500;
  padding: 3px 8px;
  border-radius: 99px;
  white-space: nowrap;
}

.badge-admin        { background: #8b5cf620; color: var(--violet-light); border: 1px solid #8b5cf630; }
.badge-active       { background: #34d39920; color: var(--green);        border: 1px solid #34d39930; }
.badge-inactive     { background: #f8717120; color: var(--red);          border: 1px solid #f8717130; }
.badge-connected    { background: #34d39920; color: var(--green);        border: 1px solid #34d39930; }
.badge-disconnected { background: #f8717120; color: var(--red);          border: 1px solid #f8717130; }
.badge-connecting   { background: #fbbf2420; color: var(--amber);        border: 1px solid #fbbf2430; }
.badge-no-instance  { background: #fbbf2415; color: var(--amber);        border: 1px solid #fbbf2425; }
.badge-expired      { background: #f8717120; color: var(--red);          border: 1px solid #f8717130; }

/* ─── Toast ─────────────────────────────────────────────────── */
.toast {
  position: fixed;
  bottom: 28px;
  left: 50%;
  transform: translateX(-50%) translateY(60px);
  background: var(--green);
  color: #0a2e22;
  padding: 11px 20px;
  border-radius: var(--radius-sm);
  font-size: .88rem;
  font-weight: 500;
  z-index: 300;
  transition: transform .28s cubic-bezier(.34,1.56,.64,1), opacity .28s;
  opacity: 0;
  pointer-events: none;
  white-space: nowrap;
  box-shadow: 0 4px 16px #00000030;
}
.toast.show  { transform: translateX(-50%) translateY(0); opacity: 1; }
.toast.error { background: var(--red); color: #fff; }

.btn-icon {
  width: 34px;
  height: 34px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  font-size: 0.85rem;
  flex-shrink: 0;
  transition: border-color 0.15s;
}

.btn-icon:hover { border-color: var(--violet); }

.empty-state {
  text-align: center;
  padding: 40px 20px;
  color: var(--muted);
  font-size: 0.88rem;
}

/* Modal */
.modal-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: #00000088;
  z-index: 100;
  align-items: flex-end;
  justify-content: center;
  padding: 0;
}

.modal-overlay.open {
  display: flex;
}

.modal {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius) var(--radius) 0 0;
  padding: 0 20px 32px;       /* sem padding-top — o título cuida disso */
  width: 100%;
  max-width: 500px;
  max-height: 92dvh;
  overflow-y: auto;
}

/* Sticky: o X e o título ficam sempre visíveis ao scrollar */
.modal-title {
  position: sticky;
  top: 0;
  z-index: 2;
  background: var(--card);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 20px 0 16px;
  margin-bottom: 4px;
  border-bottom: 1px solid var(--border);
  font-size: 1rem;
  font-weight: 600;
}

.modal-close {
  background: none;
  border: none;
  color: var(--muted);
  font-size: 1.2rem;
  cursor: pointer;
  padding: 0 4px;
}

.modal-actions {
  display: flex;
  gap: 10px;
  margin-top: 20px;
}

.modal-actions .btn { flex: 1; }

/* ── Modo página: edição de cliente ocupa a tela inteira (PC-first) ── */
.modal-overlay.as-page {
  align-items: flex-start;
  background: var(--bg);
  overflow-y: auto;
}
.modal-overlay.as-page .modal {
  max-width: 1100px;
  max-height: none;
  min-height: 100dvh;
  border: none;
  border-radius: 0;
  overflow-y: visible;
  display: grid;
  grid-template-columns: 1fr 1fr;
  column-gap: 28px;
  align-content: start;
  padding-bottom: 48px;
}
.modal-overlay.as-page .modal > .modal-title         { grid-column: 1 / -1; }
.modal-overlay.as-page .modal > #form-user           { grid-column: 1; }
.modal-overlay.as-page .modal > #instance-section    { grid-column: 2; }
.modal-overlay.as-page .modal > #ia-section          { grid-column: 1; }
.modal-overlay.as-page .modal > #cd-analytics-section{ grid-column: 2; }
.modal-overlay.as-page .modal > #cd-logs-section     { grid-column: 1 / -1; }
@media (max-width: 768px) {
  .modal-overlay.as-page .modal {
    grid-template-columns: 1fr;
    padding-left: 16px;
    padding-right: 16px;
  }
  .modal-overlay.as-page .modal > * { grid-column: 1 !important; }
}

.toggle-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 0;
  margin-bottom: 10px;
}

.toggle-label { font-size: 0.88rem; color: var(--text); }

.toggle {
  position: relative;
  width: 42px;
  height: 24px;
}

.toggle input { opacity: 0; width: 0; height: 0; }

.toggle-track {
  position: absolute;
  inset: 0;
  background: var(--border);
  border-radius: 99px;
  cursor: pointer;
  transition: background 0.2s;
}

.toggle input:checked + .toggle-track { background: var(--violet); }

.toggle-track::after {
  content: '';
  position: absolute;
  left: 3px;
  top: 3px;
  width: 18px;
  height: 18px;
  background: #fff;
  border-radius: 50%;
  transition: transform 0.2s;
}

.toggle input:checked + .toggle-track::after { transform: translateX(18px); }

.hint { font-size: 0.75rem; color: var(--muted); margin-top: -12px; margin-bottom: 14px; }

/* ─── Seção instância no modal ──────────────────────────────── */
.field-divider {
  font-size: 0.72rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--violet-light);
  padding: 14px 0 10px;
  margin-bottom: 4px;
  border-top: 1px solid var(--border);
}

.instance-current {
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 10px 14px;
  margin-bottom: 12px;
  font-size: 0.88rem;
  gap: 10px;
}

.instance-current-name {
  color: var(--text);
  font-weight: 500;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.subsection-label {
  font-size: 0.75rem;
  font-weight: 500;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin: 4px 0 8px;
}

.toggle-row { margin-bottom: 4px; }
.toggle-desc { font-size: 0.72rem; color: var(--muted); margin-top: 1px; }

.success-banner {
  background: #34d39918;
  border: 1px solid #34d39930;
  color: var(--green);
  border-radius: var(--radius-sm);
  padding: 10px 14px;
  font-size: 0.85rem;
  margin-bottom: 14px;
  display: none;
}
.success-banner.visible { display: block; }

#screen-change-password {
  min-height: 100dvh;
  align-items: center;
  justify-content: center;
  padding: 24px;
}

/* ─── Tablet/Desktop ─────────────────────────────────────────── */
@media (min-width: 600px) {
  .login-card { padding: 48px 40px; }
  .main { padding: 28px 20px; }
  .modal-overlay { align-items: center; padding: 20px; }
  .modal { border-radius: var(--radius); max-height: 80dvh; }
}
/* Analytics — botão de período ativo */
.stats-pd.active, .client-pd.active, .cd-pd.active {
  background: var(--violet-dim);
  color: var(--violet-light);
  border-color: var(--violet);
}

/* ─── Prompt Builder (wizard) ─────────────────────────────────── */
.bld-progress {
  font-size: .78rem; color: var(--muted); margin-bottom: 14px;
  display: flex; align-items: center; gap: 8px;
}
.bld-bar { flex: 1; height: 4px; background: var(--border); border-radius: 999px; overflow: hidden; }
.bld-bar > span { display: block; height: 100%; background: var(--violet); transition: width .2s; }
.bld-cat-hint { font-size: .82rem; color: var(--muted); margin: -4px 0 16px; }
.bld-result-notice { font-size:.83rem; padding:10px 14px; border-radius:var(--radius-sm); margin-bottom:14px; line-height:1.5; }
.bld-result-notice--ok   { background:#16a34a10; border:1px solid #16a34a30; color:var(--text); }
.bld-result-notice--warn { background:#d9770610; border:1px solid #d9770630; color:var(--text); }
.bld-field { margin-bottom: 16px; }
.bld-field > label { display: block; font-size: .85rem; font-weight: 500; margin-bottom: 6px; }
.bld-field input[type="text"], .bld-field textarea, .bld-field select {
  width: 100%; background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius-sm); color: var(--text); font-family: inherit;
  font-size: .9rem; padding: 10px 12px;
}
.bld-field textarea { resize: vertical; min-height: 64px; }
.bld-opt { display: flex; align-items: center; gap: 8px; padding: 7px 0; font-size: .88rem; cursor: pointer; }
.bld-opt input { accent-color: var(--violet); width: 16px; height: 16px; }
.bld-presets { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-bottom: 8px; }
.bld-preset {
  text-align: left; background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius-sm); color: var(--text); padding: 14px; cursor: pointer;
  font-family: inherit; font-size: .9rem; font-weight: 600; transition: border-color .15s;
}
.bld-preset:hover { border-color: var(--violet); }
.bld-preset.active { border-color: var(--violet); background: var(--violet-dim); color: var(--violet-light); }
.bld-nav { display: flex; gap: 10px; margin-top: 22px; }
.bld-nav .btn { flex: 1; }
@media (max-width: 560px) { .bld-presets { grid-template-columns: 1fr; } }
