:root {
  --bg: #0f172a;
  --panel: #111827;
  --panel-2: #1f2937;
  --border: #334155;
  --text: #e5e7eb;
  --muted: #94a3b8;
  --primary: #2563eb;
  --primary-hover: #1d4ed8;
  --success: #059669;
  --user-bg: #1e3a8a;
  --assistant-bg: #374151;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: Inter, system-ui, -apple-system, sans-serif;
  background: linear-gradient(180deg, #0b1220 0%, #111827 100%);
  color: var(--text);
  min-height: 100vh;
  overflow: hidden;
}

#app-root {
  min-height: 100vh;
}

/* Uma vista de cada vez — evita sobrepor login com a app */
.is-hidden {
  display: none !important;
}

.auth-screen {
  min-height: 100vh;
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
}

.auth-card {
  width: 100%;
  max-width: 400px;
  background: rgba(17, 24, 39, 0.95);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 1.5rem;
}

.auth-card h1 {
  margin: 0;
  font-size: 1.35rem;
}

.auth-subtitle {
  color: var(--muted);
  font-size: 0.9rem;
  margin: 0.35rem 0 1rem;
}

.auth-tabs {
  display: flex;
  gap: 0.5rem;
  margin-bottom: 1rem;
}

.auth-tab {
  flex: 1;
  padding: 0.5rem;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: transparent;
  color: var(--text);
  cursor: pointer;
  font: inherit;
}

.auth-tab.active {
  background: rgba(37, 99, 235, 0.2);
  border-color: rgba(37, 99, 235, 0.5);
}

.auth-form {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.auth-error {
  color: #fca5a5;
  font-size: 0.85rem;
  margin: 0.75rem 0 0;
  min-height: 1.2em;
}

.auth-footer {
  margin: 1rem 0 0;
  font-size: 0.9rem;
  color: var(--muted);
  text-align: center;
}

.auth-footer a {
  color: #93c5fd;
  text-decoration: none;
}

.auth-footer a:hover {
  text-decoration: underline;
}

.sidebar-user {
  border-top: 1px solid var(--border);
  padding-top: 0.75rem;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  font-size: 0.8rem;
}

.small-btn {
  padding: 0.4rem 0.6rem !important;
  font-size: 0.8rem !important;
}

.vs-status {
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.vs-status.synced { color: #6ee7b7; }
.vs-status.local { color: #94a3b8; }
.vs-status.syncing { color: #fcd34d; }
.vs-status.error { color: #fca5a5; }

.app-shell {
  display: grid;
  grid-template-columns: 240px 1fr;
  min-height: 100vh;
  width: 100%;
}

.sidebar {
  background: rgba(15, 23, 42, 0.95);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  padding: 1.25rem 1rem;
  gap: 1.25rem;
}

.sidebar-brand h1 {
  margin: 0;
  font-size: 1.15rem;
}

.sidebar-brand p {
  margin: 0.25rem 0 0;
  font-size: 0.75rem;
  color: var(--muted);
}

.sidebar-nav {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  width: 100%;
  text-align: left;
  padding: 0.65rem 0.85rem;
  border-radius: 10px;
  border: 1px solid transparent;
  background: transparent;
  color: var(--text);
  font: inherit;
  cursor: pointer;
}

.nav-item:hover {
  background: rgba(37, 99, 235, 0.12);
}

.nav-item.active {
  background: rgba(37, 99, 235, 0.2);
  border-color: rgba(37, 99, 235, 0.45);
  color: #bfdbfe;
}

.nav-icon {
  font-size: 1rem;
}

.sidebar-agents {
  flex: 1;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  min-height: 0;
  border-top: 1px solid var(--border);
  padding-top: 1rem;
}

.sidebar-agents h2 {
  margin: 0 0 0.5rem;
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--muted);
}

.sidebar-agents-list {
  list-style: none;
  margin: 0;
  padding: 0;
  overflow-y: auto;
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
}

.sidebar-agents-list li button {
  width: 100%;
  text-align: left;
  padding: 0.5rem 0.6rem;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--panel-2);
  color: var(--text);
  font-size: 0.8rem;
  cursor: pointer;
}

.sidebar-agents-list li button strong {
  display: block;
  margin-bottom: 0.15rem;
}

.sidebar-agents-list li button span {
  color: var(--muted);
  font-size: 0.7rem;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.sidebar-empty {
  font-size: 0.75rem;
  color: var(--muted);
  margin: 0;
}

.main-content {
  min-height: 100vh;
  overflow: hidden;
}

.view {
  display: none;
  height: 100vh;
}

.view-active {
  display: block;
}

.layout {
  display: grid;
  grid-template-columns: 1fr 1.2fr;
  gap: 1rem;
  padding: 1rem;
  height: 100vh;
}

.layout-chat {
  grid-template-columns: 1fr;
  max-width: 960px;
  margin: 0 auto;
}

.panel-full {
  min-height: calc(100vh - 2rem);
}

.dashboard-page {
  display: flex;
  flex-direction: column;
  height: 100vh;
  padding: 1rem;
  gap: 1rem;
}

.dashboard-page-header {
  background: rgba(17, 24, 39, 0.92);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 1rem 1.25rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  flex-shrink: 0;
}

.dashboard-page-header h2 {
  margin: 0;
  font-size: 1.1rem;
}

.dashboard-page .dashboard-content {
  flex: 1;
  overflow-y: auto;
  border-radius: 16px;
  min-height: 0;
}

.panel {
  background: rgba(17, 24, 39, 0.92);
  border: 1px solid var(--border);
  border-radius: 16px;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.panel-header {
  padding: 1rem 1.25rem;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
}

.panel-header h1,
.panel-header h2 {
  margin: 0;
  font-size: 1.1rem;
}

.badge {
  font-size: 0.75rem;
  padding: 0.25rem 0.6rem;
  border-radius: 999px;
  background: rgba(37, 99, 235, 0.15);
  color: #93c5fd;
  border: 1px solid rgba(37, 99, 235, 0.35);
}

.chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 1rem;
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.message {
  max-width: 90%;
  padding: 0.85rem 1rem;
  border-radius: 12px;
  line-height: 1.5;
  white-space: pre-wrap;
}

.message.user {
  align-self: flex-end;
  background: var(--user-bg);
}

.message.assistant {
  align-self: flex-start;
  background: var(--assistant-bg);
}

.message-meta {
  font-size: 0.75rem;
  color: var(--muted);
  margin-bottom: 0.35rem;
}

.chat-input-area {
  border-top: 1px solid var(--border);
  padding: 1rem;
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.upload-row {
  display: flex;
  gap: 0.75rem;
  align-items: center;
  flex-wrap: wrap;
}

.file-info {
  font-size: 0.85rem;
  color: var(--muted);
}

textarea {
  width: 100%;
  min-height: 90px;
  resize: vertical;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: var(--panel-2);
  color: var(--text);
  padding: 0.85rem 1rem;
  font: inherit;
}

button,
.file-button {
  border: none;
  border-radius: 10px;
  padding: 0.7rem 1rem;
  font: inherit;
  cursor: pointer;
  background: var(--primary);
  color: white;
}

button:hover,
.file-button:hover {
  background: var(--primary-hover);
}

button:disabled {
  opacity: 0.6;
  cursor: not-allowed;
}

.file-button {
  display: inline-block;
}

input[type="file"] {
  display: none;
}

.actions {
  display: flex;
  justify-content: space-between;
  gap: 0.75rem;
}

.secondary {
  background: var(--panel-2);
  border: 1px solid var(--border);
}

.dashboard-content {
  flex: 1;
  overflow-y: auto;
  padding: 1rem;
}

.summary-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 0.75rem;
  margin-bottom: 1rem;
}

.summary-card {
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 0.9rem;
}

.summary-card .label {
  color: var(--muted);
  font-size: 0.8rem;
}

.summary-card .value {
  font-size: 1.4rem;
  font-weight: 700;
  margin-top: 0.25rem;
}

.charts-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 1rem;
}

.chart-card {
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 1rem;
}

.chart-card h3 {
  margin: 0 0 0.75rem;
  font-size: 0.95rem;
}

.empty-state {
  color: var(--muted);
  text-align: center;
  padding: 3rem 1rem;
}

.agents-page {
  max-width: 720px;
  margin: 0 auto;
  padding: 1.5rem 1.25rem;
  height: 100vh;
  overflow-y: auto;
}

.agents-page-header h2 {
  margin: 0 0 0.5rem;
}

.agents-page-header p {
  margin: 0 0 1.25rem;
  color: var(--muted);
  line-height: 1.5;
  font-size: 0.9rem;
}

.agent-form-card {
  background: rgba(17, 24, 39, 0.92);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 1.25rem;
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.form-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1rem;
}

.form-grid-3 {
  grid-template-columns: 1fr 1fr 1fr;
}

.form-optional {
  border: 1px dashed var(--border);
  border-radius: 10px;
  padding: 0.65rem 0.85rem;
}

.form-optional summary {
  cursor: pointer;
  font-size: 0.85rem;
  color: var(--muted);
}

.field-range {
  width: 100%;
  accent-color: var(--primary);
}

.agent-card-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
  margin-top: 0.35rem;
}

.agent-tag {
  font-size: 0.7rem;
  padding: 0.15rem 0.45rem;
  border-radius: 6px;
  background: rgba(37, 99, 235, 0.15);
  color: #93c5fd;
  border: 1px solid rgba(37, 99, 235, 0.3);
}

.form-field {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
}

.highlight-field {
  padding: 0.85rem;
  border-radius: 12px;
  background: rgba(37, 99, 235, 0.08);
  border: 1px solid rgba(37, 99, 235, 0.25);
}

.field-hint {
  font-size: 0.75rem;
  color: var(--muted);
}

.form-actions {
  display: flex;
  gap: 0.75rem;
  flex-wrap: wrap;
}

.primary-btn {
  background: var(--primary);
  color: white;
  border: none;
  border-radius: 10px;
  padding: 0.7rem 1rem;
  font: inherit;
  cursor: pointer;
}

.primary-btn:hover {
  background: var(--primary-hover);
}

.agents-list-section {
  margin-top: 2rem;
}

.agents-list-section h3 {
  margin: 0 0 0.75rem;
  font-size: 0.95rem;
  color: var(--muted);
}

.empty-state-inline {
  color: var(--muted);
  font-size: 0.85rem;
}

.custom-agents-list.cards {
  gap: 0.75rem;
}

.custom-agents-list.cards > li {
  flex-direction: column;
  align-items: stretch;
}

.custom-agents-list.cards > li .agent-meta {
  width: 100%;
}

.agent-card-task {
  color: var(--muted);
  font-size: 0.85rem;
  margin: 0.35rem 0 0.75rem;
  line-height: 1.45;
}

.agent-card-actions {
  display: flex;
  gap: 0.5rem;
  flex-wrap: wrap;
}

.agent-card-actions button {
  flex: 1;
  min-width: 120px;
}

.chat-agent-select {
  margin-bottom: 0.25rem;
}

.agent-form {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.field-label {
  font-size: 0.8rem;
  color: var(--muted);
}

.field-input,
.field-textarea {
  width: 100%;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--panel-2);
  color: var(--text);
  padding: 0.55rem 0.75rem;
  font: inherit;
}

.field-textarea {
  resize: vertical;
  min-height: 100px;
}

.full-width {
  width: 100%;
  margin-top: 0.35rem;
}

.agent-list-wrap {
  margin-top: 1rem;
  padding-top: 1rem;
  border-top: 1px solid var(--border);
}

.agent-list-title {
  margin: 0 0 0.5rem;
  font-size: 0.85rem;
  color: var(--muted);
  font-weight: 600;
}

.custom-agents-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.custom-agents-list li {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 0.5rem;
  padding: 0.6rem 0.75rem;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--panel-2);
  font-size: 0.85rem;
}

.custom-agents-list .agent-meta {
  flex: 1;
  min-width: 0;
}

.custom-agents-list .agent-meta strong {
  display: block;
  margin-bottom: 0.2rem;
}

.custom-agents-list .agent-meta span {
  color: var(--muted);
  font-size: 0.75rem;
}

.custom-agents-list button {
  flex-shrink: 0;
  padding: 0.35rem 0.55rem;
  font-size: 0.75rem;
  background: transparent;
  border: 1px solid var(--border);
  color: var(--muted);
}

.custom-agents-list button:hover {
  border-color: #b91c1c;
  color: #fecaca;
}

@media (max-width: 1100px) {
  .app-shell {
    grid-template-columns: 1fr;
  }

  .sidebar {
    border-right: none;
    border-bottom: 1px solid var(--border);
    max-height: none;
  }

  .sidebar-agents {
    display: none;
  }

  .layout {
    grid-template-columns: 1fr;
    height: auto;
    min-height: auto;
  }

  .view {
    height: auto;
  }

  .panel {
    min-height: 50vh;
  }

  .summary-grid {
    grid-template-columns: 1fr;
  }

  .form-grid,
  .form-grid-3 {
    grid-template-columns: 1fr;
  }
}
