:root {
  --bg-primary: #0a0e27;
  --bg-secondary: #141829;
  --bg-tertiary: #1a1f3a;
  --text-primary: #ffffff;
  --text-secondary: #a1a1aa;
  --accent: #6366f1;
  --accent-light: #818cf8;
  --accent-hover: #4f46e5;
  --danger: #ef4444;
  --success: #10b981;
  --border: rgba(99, 102, 241, 0.1);
  --input-bg: rgba(99, 102, 241, 0.05);
  --font-family: 'Outfit', 'Inter', -apple-system, sans-serif;
  --glass: rgba(10, 14, 39, 0.8);
  --glass-border: rgba(99, 102, 241, 0.2);
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html {
  height: 100%;
}

body {
  width: 100%;
  min-width: 320px;
  height: 100%;
  min-height: 0;
  max-height: 100vh;
  background: linear-gradient(135deg, #0a0e27 0%, #141829 50%, #1a1f3a 100%);
  background-attachment: fixed;
  color: var(--text-primary);
  font-family: var(--font-family);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  position: relative;
}

body::before {
  content: '';
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: radial-gradient(circle at 20% 50%, rgba(99, 102, 241, 0.1) 0%, transparent 50%),
              radial-gradient(circle at 80% 80%, rgba(139, 92, 246, 0.05) 0%, transparent 50%);
  pointer-events: none;
  z-index: 0;
}

/* Scrollbar */
::-webkit-scrollbar {
  width: 5px;
}

::-webkit-scrollbar-thumb {
  background: var(--accent);
  border-radius: 10px;
  opacity: 0.6;
}

::-webkit-scrollbar-track {
  background: transparent;
}

/* Header */
.header {
  height: 70px;
  padding: 0 24px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-bottom: 1px solid var(--border);
  background: var(--glass);
  backdrop-filter: blur(20px);
  z-index: 10;
  flex-shrink: 0;
  position: relative;
}

.header::after {
  content: '';
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  height: 1px;
  background: linear-gradient(90deg, transparent, var(--accent), transparent);
  opacity: 0.5;
}

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

.brand h1 {
  display: none;
}

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

.brand-logo {
  font-size: 24px;
  font-weight: 800;
  background: linear-gradient(135deg, var(--accent-light), var(--accent));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  animation: float 3s ease-in-out infinite;
}

.brand-text {
  font-size: 13px;
  font-weight: 700;
  background: linear-gradient(135deg, var(--accent-light), var(--accent));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  letter-spacing: 0.5px;
}

@keyframes float {
  0%, 100% {
    transform: translateY(0px);
  }
  50% {
    transform: translateY(-2px);
  }
}

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

.history-dropdown-wrapper {
  position: relative;
}

.history-list-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  padding: 0;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: rgba(161, 161, 170, 0.08);
  color: var(--text-secondary);
  cursor: pointer;
  transition: color 0.2s, background 0.2s, border-color 0.2s;
}

.history-list-btn:hover {
  color: var(--text);
  background: rgba(99, 102, 241, 0.1);
  border-color: rgba(99, 102, 241, 0.3);
}

.history-list-btn:active {
  transform: scale(0.96);
}

.history-dropdown {
  position: absolute;
  top: calc(100% + 8px);
  right: 0;
  min-width: 220px;
  max-width: 280px;
  max-height: 240px;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  background: var(--glass);
  border: 1px solid var(--border);
  border-radius: 12px;
  box-shadow: 0 10px 40px rgba(0, 0, 0, 0.2);
  backdrop-filter: blur(20px);
  z-index: 100;
}

.history-dropdown-header {
  padding: 10px 12px;
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--text-secondary);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.history-dropdown-list {
  overflow-y: auto;
  padding: 6px 0;
}

.history-dropdown-item {
  padding: 10px 12px;
  font-size: 13px;
  color: var(--text);
  cursor: pointer;
  transition: background 0.15s;
  border: none;
  background: none;
  width: 100%;
  text-align: left;
}

.history-dropdown-item:hover {
  background: rgba(161, 161, 170, 0.12);
}

.history-dropdown-empty {
  padding: 16px 12px;
  font-size: 13px;
  color: var(--text-secondary);
  text-align: center;
}

/* Overlay quando a aba ativa não é Lovable */
.lovable-required-overlay {
  position: absolute;
  top: 70px;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 20;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 24px;
  text-align: center;
  background: var(--glass);
  backdrop-filter: blur(20px);
  border-top: 1px solid var(--border);
}

.lovable-required-text {
  font-size: 15px;
  font-weight: 600;
  color: var(--text-primary);
  margin-bottom: 8px;
}

.lovable-required-hint {
  font-size: 13px;
  color: var(--text-secondary);
}

.clear-history-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  padding: 0;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: rgba(161, 161, 170, 0.08);
  color: var(--text-secondary);
  cursor: pointer;
  transition: color 0.2s, background 0.2s, border-color 0.2s;
}

.clear-history-btn:hover {
  color: var(--text);
  background: rgba(239, 68, 68, 0.1);
  border-color: rgba(239, 68, 68, 0.3);
}

.clear-history-btn:active {
  transform: scale(0.96);
}

.status-badge {
  background: rgba(16, 185, 129, 0.1);
  color: var(--success);
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  padding: 6px 12px;
  border-radius: 20px;
  border: 1px solid rgba(16, 185, 129, 0.3);
  display: flex;
  align-items: center;
  gap: 6px;
  letter-spacing: 0.5px;
  backdrop-filter: blur(10px);
}

.status-dot {
  width: 6px;
  height: 6px;
  background: var(--success);
  border-radius: 50%;
  box-shadow: 0 0 8px var(--success);
  animation: pulse 2s infinite;
}

@keyframes pulse {
  0%, 100% {
    opacity: 1;
    box-shadow: 0 0 8px var(--success);
  }
  50% {
    opacity: 0.5;
    box-shadow: 0 0 4px var(--success);
  }
}

/* Chat Area - scroll interno; input fica fixo embaixo */
.chat-container {
  flex: 1;
  min-height: 0; /* permite o flex item encolher e mostrar scroll interno */
  padding: 20px 16px 12px;
  overflow-y: auto;
  overflow-x: hidden;
  display: flex;
  flex-direction: column;
  gap: 16px;
  scroll-behavior: smooth;
  position: relative;
  z-index: 1;
  -webkit-overflow-scrolling: touch;
}

.message {
  display: flex;
  align-items: flex-start;
  font-size: 14px;
  line-height: 1.6;
  animation: slideUp 0.4s cubic-bezier(0.16, 1, 0.3, 1);
  width: 100%;
}

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

.message-content {
  padding: 12px 16px;
  border-radius: 16px;
  max-width: 90%;
  position: relative;
  word-wrap: break-word;
  overflow-wrap: break-word;
  white-space: pre-wrap;
  overflow: hidden;
  backdrop-filter: blur(10px);
}

.message.user {
  justify-content: flex-end;
}

.message.user .message-content {
  background: linear-gradient(135deg, var(--accent), var(--accent-light));
  color: #fff;
  font-weight: 500;
  border-bottom-right-radius: 4px;
  box-shadow: 0 4px 15px rgba(99, 102, 241, 0.3);
}

.message.assistant {
  justify-content: flex-start;
}

.message.assistant .message-content {
  background: rgba(26, 31, 58, 0.8);
  color: var(--text-primary);
  border-bottom-left-radius: 4px;
  border: 1px solid var(--border);
  box-shadow: 0 4px 15px rgba(99, 102, 241, 0.1);
}

.message.system {
  justify-content: center;
}

.message.system .message-content {
  background: transparent;
  color: var(--text-secondary);
  font-size: 12px;
  border: 1px solid var(--border);
  padding: 6px 14px;
  border-radius: 20px;
}

/* Input Area - fixo no rodapé; só o chat rola */
.input-container {
  padding: 16px 20px 24px;
  background: linear-gradient(to top, var(--bg-secondary) 0%, transparent 100%);
  flex-shrink: 0;
  position: relative;
  z-index: 1;
}

.advanced-input-wrapper {
  display: flex;
  flex-direction: column;
  background: rgba(20, 24, 41, 0.8);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 12px;
  box-shadow: 0 8px 32px rgba(99, 102, 241, 0.1);
  transition: all 0.3s ease;
  pointer-events: auto;
  backdrop-filter: blur(20px);
}

.advanced-input-wrapper:focus-within {
  border-color: var(--accent);
  box-shadow: 0 8px 32px rgba(99, 102, 241, 0.2);
  background: rgba(20, 24, 41, 0.95);
}

/* File Previews */
.file-preview-container {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 8px;
}

.file-preview-chip {
  display: flex;
  align-items: center;
  gap: 8px;
  background-color: rgba(99, 102, 241, 0.1);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 6px 10px;
  font-size: 13px;
  color: var(--text-primary);
}

.file-icon {
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 14px;
  color: var(--accent);
}

.file-name {
  max-width: 150px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.remove-file-btn {
  background: transparent;
  border: none;
  color: var(--text-secondary);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 2px;
  border-radius: 4px;
  transition: all 0.2s;
}

.remove-file-btn:hover {
  background-color: rgba(99, 102, 241, 0.2);
  color: var(--text-primary);
}

/* Text Input */
.input-main-area {
  position: relative;
  display: flex;
  width: 100%;
  align-items: flex-end;
}

#message-input {
  width: 100%;
  min-height: 40px;
  background: transparent;
  border: none;
  resize: none;
  outline: none;
  color: var(--text-primary);
  font-family: inherit;
  font-size: 14px;
  line-height: 1.5;
  padding: 8px 0;
}

#message-input::placeholder {
  color: var(--text-secondary);
}

/* Actions Row */
.input-actions-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-top: 8px;
}

.left-actions {
  display: flex;
  align-items: center;
  gap: 4px;
}

.right-actions {
  display: flex;
  align-items: center;
}

.action-btn {
  background: transparent;
  border: none;
  color: var(--text-secondary);
  cursor: pointer;
  width: 32px;
  height: 32px;
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s;
}

.action-btn:hover {
  color: var(--accent);
  background: rgba(99, 102, 241, 0.1);
}

.action-btn.active {
  color: var(--accent);
  background: rgba(99, 102, 241, 0.15);
}

.send-btn {
  background: linear-gradient(135deg, var(--accent), var(--accent-light));
  color: #fff;
  border: none;
  border-radius: 50%;
  width: 32px;
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: all 0.3s cubic-bezier(0.16, 1, 0.3, 1);
  box-shadow: 0 4px 12px rgba(99, 102, 241, 0.3);
}

.send-btn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
  transform: scale(0.9);
  box-shadow: none;
}

.send-btn:not(:disabled):hover {
  transform: scale(1.08);
  box-shadow: 0 6px 20px rgba(99, 102, 241, 0.5);
}

.send-btn:not(:disabled):active {
  transform: scale(0.95);
}

/* Settings Overlay */
.settings-overlay {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background-color: var(--bg-primary);
  z-index: 20;
  transform: translateY(100%);
  transition: transform 0.5s cubic-bezier(0.16, 1, 0.3, 1);
}

.settings-overlay.open {
  transform: translateY(0);
}

.settings-content {
  padding: 30px 24px;
  height: 100%;
  display: flex;
  flex-direction: column;
}

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

.form-group {
  margin-bottom: 20px;
}

.form-group label {
  display: block;
  font-size: 11px;
  font-weight: 700;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 1px;
  margin-bottom: 8px;
}

.form-group .checkbox-label {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 14px;
  font-weight: 600;
  color: var(--text-primary);
  text-transform: none;
  letter-spacing: 0;
  cursor: pointer;
}

.form-group .checkbox-label input[type="checkbox"] {
  width: 18px;
  height: 18px;
  accent-color: var(--accent);
  cursor: pointer;
}

/* Auth Container */
.auth-container {
  width: 100%;
  height: 100%;
  padding: 40px;
  display: flex;
  flex-direction: column;
  justify-content: center;
  animation: fadeIn 0.6s cubic-bezier(0.16, 1, 0.3, 1);
}

.auth-logo {
  text-align: center;
  margin-bottom: 24px;
  display: flex;
  justify-content: center;
}

.auth-title {
  font-size: 24px;
  font-weight: 800;
  color: var(--text-primary);
  text-align: center;
  margin-bottom: 8px;
  letter-spacing: -0.8px;
  line-height: 1.1;
}

.auth-subtitle {
  font-size: 14px;
  color: var(--text-secondary);
  text-align: center;
  margin-bottom: 40px;
  line-height: 1.6;
  max-width: 280px;
  margin-left: auto;
  margin-right: auto;
}

.auth-button {
  width: 100%;
  padding: 16px;
  background: linear-gradient(135deg, var(--accent), var(--accent-light));
  color: #fff;
  border: none;
  border-radius: 12px;
  font-size: 15px;
  font-weight: 700;
  cursor: pointer;
  transition: all 0.3s cubic-bezier(0.16, 1, 0.3, 1);
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  margin-top: 20px;
  box-shadow: 0 4px 12px rgba(99, 102, 241, 0.3);
}

.auth-button:hover {
  transform: translateY(-2px);
  box-shadow: 0 6px 20px rgba(99, 102, 241, 0.4);
}

.auth-footer {
  margin-top: 40px;
  text-align: center;
  font-size: 11px;
  color: var(--text-secondary);
  letter-spacing: 1px;
  text-transform: uppercase;
  opacity: 0.4;
}

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

.key-input {
  width: 100%;
  background: rgba(99, 102, 241, 0.05);
  border: 1px solid var(--border);
  color: #fff;
  padding: 12px 16px;
  border-radius: 10px;
  font-size: 14px;
  outline: none;
  transition: all 0.3s;
}

.key-input:focus {
  background: rgba(99, 102, 241, 0.1);
  border-color: var(--accent);
}

.key-input-wrapper {
  position: relative;
  width: 100%;
}

.save-btn {
  margin-top: auto;
  background: linear-gradient(135deg, var(--accent), var(--accent-light));
  color: #fff;
  border: none;
  padding: 16px;
  border-radius: 12px;
  font-weight: 700;
  cursor: pointer;
  transition: all 0.3s;
  box-shadow: 0 4px 12px rgba(99, 102, 241, 0.3);
}

.save-btn:hover {
  transform: translateY(-2px);
  box-shadow: 0 6px 20px rgba(99, 102, 241, 0.4);
}

/* Loading Spinner */
.loading-spinner {
  display: none;
  border: 2px solid rgba(99, 102, 241, 0.2);
  border-top: 2px solid var(--accent);
  border-radius: 50%;
  width: 18px;
  height: 18px;
}

.loading-spinner[style*="display: block"] {
  animation: spin 0.8s linear infinite;
}

@keyframes spin {
  0% {
    transform: rotate(0deg);
  }
  100% {
    transform: rotate(360deg);
  }
}

/* Error and Success Messages */
.error-message,
.success-message {
  padding: 12px 16px;
  border-radius: 10px;
  font-size: 13px;
  margin-bottom: 16px;
  display: none;
  animation: slideDown 0.3s ease;
}

.error-message.show,
.success-message.show {
  display: block;
}

.error-message {
  background: rgba(239, 68, 68, 0.1);
  border: 1px solid rgba(239, 68, 68, 0.3);
  color: #fca5a5;
}

.success-message {
  background: rgba(16, 185, 129, 0.1);
  border: 1px solid rgba(16, 185, 129, 0.3);
  color: #86efac;
}

@keyframes slideDown {
  from {
    opacity: 0;
    transform: translateY(-10px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

/* ========== Admin Panel – layout full-width ========== */
/* Sem max-width no conteúdo: top bar e main ocupam a largura útil (max-width só no main, 1600px, no index). */

/* Layout e scroll: topbar fixa, só a área principal rola */
body.admin-page {
  height: 100vh;
  max-height: 100vh;
  overflow: hidden;
  min-height: 0;
}

body.admin-page .admin-topbar {
  flex-shrink: 0;
}

body.admin-page .admin-main {
  flex: 1 1 auto;
  min-height: 0;
  overflow-x: hidden;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior-y: contain;
  scroll-behavior: smooth;
}


body.admin-page .admin-main .license-table tbody tr {
  transition: background 0.12s ease;
}


/* Mobile: padding reduzido; stats 2 colunas; tabela via wrapper (scroll horizontal); touch targets 44px */
@media (max-width: 640px) {
  body.admin-page .admin-topbar {
    padding: 0 16px;
    min-height: 56px;
  }

  body.admin-page .admin-main {
    padding: 20px 16px 48px;
  }

  body.admin-page .admin-main .stats-grid {
    grid-template-columns: repeat(2, 1fr);
    gap: 12px;
  }

  body.admin-page .admin-main .stat-number {
    font-size: 22px;
  }

  body.admin-page .admin-main .admin-table-wrap {
    margin-left: -4px;
    margin-right: -4px;
  }

  body.admin-page .admin-main .license-table th,
  body.admin-page .admin-main .license-table td {
    padding: 10px 12px;
    font-size: 12px;
  }

  body.admin-page .admin-main .action-buttons {
    flex-direction: column;
    gap: 8px;
  }

  body.admin-page .admin-main .action-btn-small {
    width: 100%;
    min-height: 44px;
    padding: 10px 14px;
  }

  body.admin-page .admin-topbar .btn-cta {
    min-height: 44px;
    padding: 12px 20px;
  }
}

/* Tablet: 3 colunas nos stats */
@media (min-width: 641px) and (max-width: 1024px) {
  body.admin-page .admin-main .stats-grid {
    grid-template-columns: repeat(3, 1fr);
    gap: 20px;
  }
}

/* Toggle password (olhinho) */
.input-with-toggle {
  position: relative;
  display: flex;
  align-items: center;
}
.input-with-toggle input {
  flex: 1;
  padding-right: 42px;
}
.toggle-password {
  position: absolute;
  right: 8px;
  top: 50%;
  transform: translateY(-50%);
  background: none;
  border: none;
  cursor: pointer;
  font-size: 16px;
  padding: 4px 6px;
  opacity: 0.5;
  transition: opacity 0.2s;
  line-height: 1;
}
.toggle-password:hover {
  opacity: 1;
}
.toggle-password.active {
  opacity: 1;
}
