:root {
  --bg: transparent;
  --surface: rgba(255,255,255,0.7);
  --surface2: rgba(255,255,255,0.5);
  --text: #191c1e;
  --text2: #4a4455;
  --muted: #888;
  --border: rgba(0,0,0,0.05);
  --primary: #7c3aed;
  --primary-hover: #6d28d9;
  --primary-glass: rgba(124, 58, 237, 0.1);
  --green: #22c55e;
  --red: #ef4444;
  --radius-lg: 16px;
}
* { box-sizing: border-box; margin: 0; padding: 0; }
body {
  font-family: 'Plus Jakarta Sans', system-ui, sans-serif;
  background: #f1f5f9;
  color: var(--text);
  height: 100vh;
  width: 100vw;
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
}
html { scroll-behavior: smooth; }

@keyframes modalIn { from { opacity: 0; transform: scale(.95) translateY(10px); } to { opacity: 1; transform: scale(1) translateY(0); } }
@keyframes fadeUp { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: translateY(0); } }
@keyframes shake { 0%,100%{transform:translateX(0)} 25%{transform:translateX(-5px)} 75%{transform:translateX(5px)} }
.shake { animation: shake .3s ease; }

/* ============================================================
   LOGIN — Site Sofia style, adaptado para Sophie
   ============================================================ */

#loginScreen {
  display: flex; align-items: center; justify-content: center;
  height: 100vh; width: 100vw;
  position: fixed; top: 0; left: 0; z-index: 100;
  background: linear-gradient(135deg, #f5f3ff 0%, #ede9fe 25%, #faf9ff 50%, #f3f0ff 75%, #f8f7ff 100%);
}
#loginScreen::before, #loginScreen::after {
  content: ''; position: fixed; border-radius: 50%;
  pointer-events: none; z-index: 0; filter: blur(90px);
}
#loginScreen::before {
  width: 600px; height: 600px; top: -150px; left: -100px;
  background: radial-gradient(circle, rgba(124,58,237,.12) 0%, transparent 70%);
}
#loginScreen::after {
  width: 500px; height: 500px; bottom: -120px; right: -80px;
  background: radial-gradient(circle, rgba(139,92,246,.08) 0%, transparent 70%);
}

.login-grid-bg {
  position: fixed; inset: 0; z-index: 0; pointer-events: none;
  background-image:
    linear-gradient(rgba(124,58,237,.03) 1px, transparent 1px),
    linear-gradient(90deg, rgba(124,58,237,.03) 1px, transparent 1px);
  background-size: 56px 56px;
}

.login-wrap {
  position: relative; z-index: 1;
  width: 100%; max-width: 420px;
  padding: 20px;
}

.login-card {
  background: rgba(255,255,255,.82);
  backdrop-filter: blur(24px) saturate(180%);
  -webkit-backdrop-filter: blur(24px) saturate(180%);
  border: 1px solid rgba(255,255,255,.85);
  border-radius: 24px;
  padding: 44px 40px;
  box-shadow: 0 24px 64px rgba(10,20,40,.1), inset 0 1px 0 rgba(255,255,255,.6);
  position: relative; overflow: hidden;
  animation: cardIn .6s cubic-bezier(.16,1,.3,1) both;
}
@keyframes cardIn {
  from { opacity: 0; transform: translateY(28px) scale(.97); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}
.login-card.shake { animation: shake .3s ease, cardIn .6s cubic-bezier(.16,1,.3,1) both; }

.login-accent {
  position: absolute; top: 0; left: 20%; right: 20%; height: 1px;
  background: linear-gradient(90deg, transparent, var(--primary), transparent);
  display: block;
}

.login-logo-row {
  display: flex; align-items: center; justify-content: center; gap: 10px;
  margin-bottom: 28px;
}
.login-logo-mark {
  width: 44px; height: 44px; border-radius: 12px;
  background: linear-gradient(135deg, var(--primary), #4c1d95);
  display: flex; align-items: center; justify-content: center;
  box-shadow: 0 4px 16px rgba(124,58,237,.35);
  flex-shrink: 0;
}
.login-logo-mark span {
  color: #fff; font-weight: 800; font-size: 1.2rem; font-family: serif;
}
.login-wordmark {
  font-size: 1.2rem; font-weight: 700; letter-spacing: -.4px;
  color: #1a1a2e;
}

.login-title {
  font-size: 1.4rem; font-weight: 300; letter-spacing: -.035em;
  color: #0F172A; text-align: center; margin-bottom: 6px;
}
.login-title strong { font-weight: 700; }
.login-subtitle {
  font-size: .82rem; font-weight: 400; color: #64748B;
  text-align: center; margin-bottom: 28px; line-height: 1.5;
}

.login-error {
  background: rgba(239,68,68,.06); border: 1px solid rgba(239,68,68,.2);
  border-radius: 8px; padding: 10px 14px;
  font-size: .8rem; color: #EF4444; font-weight: 500;
  margin-bottom: 16px; display: none; text-align: center;
}

/* Form */
.form-group {
  display: flex; flex-direction: column; gap: 6px;
  margin-bottom: 16px;
}
.form-group label {
  font-size: .72rem; font-weight: 600; letter-spacing: .04em;
  text-transform: uppercase; color: #1E293B;
}
.form-group input {
  background: #f5f3ff;
  border: 1.5px solid #e0d8f5;
  border-radius: 10px; padding: 12px 16px;
  font-size: .9rem; font-family: 'Plus Jakarta Sans', system-ui, sans-serif;
  color: #0F172A; outline: none;
  transition: border-color .2s, background .2s, box-shadow .2s;
  width: 100%;
}
.form-group input::placeholder { color: #94A3B8; }
.form-group input:focus {
  border-color: var(--primary);
  background: #f0ebff;
  box-shadow: 0 0 0 3px rgba(124,58,237,.1);
}

.pass-wrap { position: relative; }
.pass-wrap input { padding-right: 44px; }
.pass-toggle {
  position: absolute; right: 10px; top: 50%; transform: translateY(-50%);
  background: none; border: none; cursor: pointer; font-size: 1rem;
  padding: 6px; line-height: 1; opacity: .5; transition: opacity .15s;
}
.pass-toggle:hover { opacity: 1; }

.btn-login {
  width: 100%; background: linear-gradient(135deg, var(--primary), #4c1d95);
  color: #fff; border: none;
  padding: 13px; border-radius: 10px;
  font-size: .9rem; font-weight: 600; cursor: pointer;
  font-family: 'Plus Jakarta Sans', system-ui, sans-serif; letter-spacing: .01em;
  transition: background .2s, transform .15s, box-shadow .2s;
  box-shadow: 0 4px 16px rgba(124,58,237,.3);
  display: flex; align-items: center; justify-content: center; gap: 8px;
}
.btn-login:hover {
  background: linear-gradient(135deg, var(--primary-hover), #3b1076);
  transform: translateY(-1px);
  box-shadow: 0 6px 24px rgba(124,58,237,.4);
}
.btn-login:disabled { opacity: .65; cursor: not-allowed; transform: none; }

/* App Container */
#app {
  display: none;
  width: 100vw; height: 100vh;
  position: relative; z-index: 10;
}
#app.active { display: flex; }
#app-overlay {
  display: none;
  position: fixed; top: 0; left: 0;
  width: 100vw; height: 100vh;
  z-index: 40; background: rgba(0,0,0,0.15);
  backdrop-filter: blur(2px);
}
#app-overlay.active { display: block; }

/* Sidebar Flutuante */
.sidebar {
  position: absolute;
  top: 20px; bottom: 20px; left: 20px;
  width: 280px;
  background: rgba(255,255,255,0.85);
  backdrop-filter: blur(24px);
  border-radius: 24px;
  display: flex; flex-direction: column;
  z-index: 50;
  box-shadow: 0 12px 40px rgba(0,0,0,0.1);
  transform: translateX(-120%);
  transition: transform 0.4s cubic-bezier(0.16, 1, 0.3, 1);
}
.sidebar.open { transform: translateX(0); }
.sidebar-header {
  padding: 1.5rem;
  display: flex; align-items: center; gap: .75rem;
}
.sidebar-header .logo-mark {
  width: 36px; height: 36px; border-radius: 10px;
  background: #1a1a2e;
  display: flex; align-items: center; justify-content: center;
  color: #a855f7; font-family: serif; font-weight: bold; font-size: 1.2rem;
  position: relative;
}
.status-dot-logo {
  width: 10px; height: 10px; background: var(--green);
  border-radius: 50%; position: absolute; bottom: -2px; right: -2px;
  border: 2px solid #fff;
}
.sidebar-header h2 { font-size: 1.1rem; font-weight: 600; }
.sidebar-close {
  margin-left: auto; background: none; border: none;
  cursor: pointer; color: #888; font-size: 1.2rem;
  padding: 4px; border-radius: 8px; transition: background .15s;
}
.sidebar-close:hover { background: rgba(0,0,0,0.05); }

.sidebar-nav { flex: 1; padding: 0.5rem 1.2rem; overflow-y: auto; }
.sidebar-nav::-webkit-scrollbar { width: 3px; }
.sidebar-nav::-webkit-scrollbar-thumb { background: rgba(0,0,0,0.1); border-radius: 3px; }
.sidebar-nav button {
  display: flex; align-items: center; gap: .75rem; width: 100%;
  background: none; border: none; color: var(--text2);
  padding: .75rem 1rem; border-radius: 12px;
  font-size: .85rem; font-weight: 500;
  cursor: pointer; text-align: left; margin-bottom: .2rem;
  transition: 0.2s; font-family: inherit;
}
.sidebar-nav button:hover { background: rgba(0,0,0,0.03); }
.sidebar-nav button.active {
  background: rgba(0,0,0,0.05); color: #111; font-weight: 600;
}
.sidebar-nav .nav-icon { font-size: 1.2rem; width: 24px; text-align: center; }
.sidebar-nav .nav-label {
  color: var(--muted); font-size: .65rem; font-weight: 600;
  text-transform: uppercase; padding: 1.5rem 1rem .5rem; letter-spacing: .05em;
}

.sidebar-footer {
  padding: 1.5rem; display: flex; align-items: center; gap: .75rem;
  border-top: 1px solid rgba(0,0,0,0.05);
}
.sidebar-footer .avatar {
  width: 32px; height: 32px; border-radius: 50%; background: #e5e7eb;
  display: flex; align-items: center; justify-content: center;
  color: #888; font-weight: bold;
}
.sidebar-footer .username { font-size: .85rem; font-weight: 500; }
.sidebar-footer button {
  background: none; border: none; color: var(--red);
  font-size: .85rem; cursor: pointer; margin-left: auto;
  font-weight: 500; font-family: inherit; padding: 4px 8px;
  border-radius: 8px; transition: background .15s;
}
.sidebar-footer button:hover { background: rgba(239,68,68,0.08); }

/* Main (Transparente com blur) */
.main {
  flex: 1; display: flex; flex-direction: column; overflow: hidden;
  background: rgba(255,255,255,0.1);
  backdrop-filter: blur(8px);
  width: 100%;
}
.tab-content { display: none; flex: 1; flex-direction: column; overflow: hidden; position: relative; }
.tab-content.active { display: flex; }

/* Top Bar */
.top-bar {
  display: flex; align-items: center; padding: 20px; gap: 15px;
}
.menu-toggle {
  width: 44px; height: 44px; border-radius: 14px;
  background: rgba(255,255,255,0.7); backdrop-filter: blur(12px);
  border: 1px solid rgba(255,255,255,0.8);
  display: flex; align-items: center; justify-content: center;
  cursor: pointer; color: #333;
  box-shadow: 0 4px 12px rgba(0,0,0,0.03);
  transition: 0.2s;
}
.menu-toggle:hover { background: #fff; }
.chat-header {
  background: rgba(255,255,255,0.7); backdrop-filter: blur(12px);
  border: 1px solid rgba(255,255,255,0.8); border-radius: 16px;
  padding: 10px 20px;
  display: inline-flex; align-items: center; gap: .5rem;
  font-weight: 500; font-size: .85rem; color: #111;
  box-shadow: 0 4px 12px rgba(0,0,0,0.02);
}

/* Chat Messages */
.chat-messages {
  flex: 1; overflow-y: auto; padding: 0 20px;
  display: flex; flex-direction: column; gap: 1rem;
  scroll-behavior: smooth;
}
.chat-messages::-webkit-scrollbar { width: 4px; }
.chat-messages::-webkit-scrollbar-thumb { background: rgba(0,0,0,0.1); border-radius: 4px; }
.empty-state {
  flex: 1; display: flex; flex-direction: column; align-items: center;
  justify-content: center; color: #444; font-size: 1rem;
  font-weight: 500; text-align: center; gap: 15px;
}

/* Message Bubbles */
.msg { display: flex; gap: .6rem; max-width: 78%; animation: fadeUp .3s ease both; }
.msg.user { align-self: flex-end; flex-direction: row-reverse; }
.msg.assistant { align-self: flex-start; }
.msg .avatar {
  width: 32px; height: 32px; border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-size: .8rem; font-weight: 700; flex-shrink: 0;
  background: var(--primary); color: #fff;
}
.msg.assistant .avatar { background: #1a1a2e; }
.msg .bubble {
  padding: 12px 16px; border-radius: var(--radius-lg);
  font-size: .9rem; line-height: 1.5;
  background: rgba(255,255,255,0.85); color: var(--text);
  box-shadow: 0 4px 16px rgba(0,0,0,0.04); backdrop-filter: blur(10px);
}
.msg.user .bubble { background: var(--primary); color: #fff; }

/* Typing Indicator */
.typing-indicator { display: none; align-self: flex-start; padding: .5rem 1rem; }
.typing-indicator.active { display: flex; gap: 3px; align-items: center; }
.typing-dot { width: 5px; height: 5px; border-radius: 50%; background: #888; animation: bounce 1.4s infinite both; }
.typing-dot:nth-child(2) { animation-delay: .2s; }
.typing-dot:nth-child(3) { animation-delay: .4s; }
@keyframes bounce { 0%,80%,100% { transform: scale(0); } 40% { transform: scale(1); } }

/* Input Area */
.chat-input-area {
  background: rgba(255,255,255,0.85); backdrop-filter: blur(24px);
  border: 1px solid rgba(255,255,255,1); border-radius: 30px;
  padding: 10px 10px 10px 20px; margin: 20px;
  display: flex; gap: 12px; align-items: center;
  box-shadow: 0 12px 40px rgba(0,0,0,0.06);
}
.chat-input-area textarea {
  flex: 1; background: transparent; border: none; outline: none;
  color: var(--text); font-size: .9rem; resize: none;
  min-height: 24px; max-height: 100px; font-family: inherit;
}
.chat-input-area .input-icon {
  color: #888; cursor: pointer; font-size: 1.2rem;
  user-select: none; transition: color .15s;
  font-variation-settings: 'FILL' 0;
}
.chat-input-area .input-icon:hover { color: #555; }
.chat-input-area button {
  width: 40px; height: 40px; border-radius: 50%;
  background: linear-gradient(135deg, var(--primary), #4c1d95);
  color: #fff; border: none; cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  box-shadow: 0 4px 12px rgba(124,58,237,0.3);
  transition: 0.2s; flex-shrink: 0;
}
.chat-input-area button:hover { transform: scale(1.05); }
.chat-input-area button:disabled { opacity: .4; cursor: not-allowed; transform: none; }

/* Data Tables */
.data-header {
  padding: 20px;
  display: flex; align-items: center; justify-content: space-between;
  font-weight: 600; font-size: 1.2rem; color: #111;
}
.btn-refresh {
  background: rgba(255,255,255,0.7); border: 1px solid rgba(255,255,255,0.9);
  border-radius: 12px; padding: 8px 16px; font-size: .85rem; font-weight: 600;
  cursor: pointer; display: flex; align-items: center; gap: 8px;
  backdrop-filter: blur(10px); box-shadow: 0 4px 12px rgba(0,0,0,0.03);
  font-family: inherit; color: var(--text2);
  transition: background .15s;
}
.btn-refresh:hover { background: rgba(255,255,255,0.9); }
.data-wrap { flex: 1; overflow-y: auto; padding: 0 20px 20px; }
.data-wrap::-webkit-scrollbar { width: 4px; }
.data-wrap::-webkit-scrollbar-thumb { background: rgba(0,0,0,0.1); border-radius: 4px; }
table {
  width: 100%; border-collapse: collapse; font-size: .85rem;
  background: rgba(255,255,255,0.6); border-radius: 16px; overflow: hidden;
  backdrop-filter: blur(12px); box-shadow: 0 8px 32px rgba(0,0,0,0.04);
}
th, td { text-align: left; padding: 14px 18px; border-bottom: 1px solid rgba(0,0,0,0.04); }
th { font-weight: 700; color: var(--text2); font-size: .75rem; text-transform: uppercase; }

.badge {
  display: inline-block; padding: 2px 8px; border-radius: 8px;
  font-size: .7rem; font-weight: 600;
}
.badge-in { background: rgba(124,58,237,.1); color: #7c3aed; }
.badge-out { background: rgba(34,197,94,.1); color: #16a34a; }
.badge-pendente { background: rgba(245,158,11,.1); color: #d97706; }
.badge-concluida { background: rgba(34,197,94,.1); color: #16a34a; }
.badge-telegram { background: rgba(59,130,246,.1); color: #3b82f6; }
.badge-cron { background: rgba(139,148,158,.1); color: #6b7280; }
.badge-pensamento { background: rgba(139,92,246,.1); color: #8b5cf6; }

.config-card {
  background: rgba(255,255,255,0.6); backdrop-filter: blur(12px);
  border: 1px solid rgba(255,255,255,0.8); border-radius: 16px;
  padding: 1.2rem; margin-bottom: 1rem;
  box-shadow: 0 4px 12px rgba(0,0,0,0.02);
}
.config-card h3 { font-size: .9rem; font-weight: 600; margin-bottom: .5rem; }
.config-card textarea {
  width: 100%; background: rgba(255,255,255,0.7); border: 1px solid rgba(0,0,0,0.05);
  border-radius: 12px; color: var(--text); font-family: 'JetBrains Mono', monospace;
  font-size: .75rem; padding: .6rem .8rem; min-height: 80px;
  resize: vertical; outline: none; transition: border .15s;
}
.config-card textarea:focus { border-color: var(--primary); }
.config-card button {
  margin-top: .5rem; background: var(--primary); color: #fff; border: none;
  border-radius: 10px; padding: .4rem .9rem; font-size: .75rem; font-weight: 600;
  cursor: pointer; font-family: inherit; transition: background .15s;
}
.config-card button:hover { background: var(--primary-hover); }
