:root {
  --bg: #0f172a;
  --bg-alt: #f8fafc;
  --panel: #ffffff;
  --panel-dark: #111827;
  --border: #e2e8f0;
  --text: #1e293b;
  --text-muted: #64748b;
  --primary: #4f46e5;
  --primary-dark: #4338ca;
  --success: #16a34a;
  --danger: #dc2626;
  --warning: #d97706;
  --radius: 10px;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg-alt);
  color: var(--text);
  font-size: 14px;
}

a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }

.auth-page {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(135deg, var(--bg) 0%, #1e293b 100%);
}

.auth-box {
  background: var(--panel);
  border-radius: var(--radius);
  padding: 2.5rem;
  width: 100%;
  max-width: 380px;
  box-shadow: 0 20px 50px rgba(0,0,0,.35);
}

.auth-box h1 {
  margin: 0 0 .25rem;
  font-size: 1.4rem;
}

.auth-box .subtitle {
  color: var(--text-muted);
  margin-bottom: 1.5rem;
  font-size: .85rem;
}

.field { margin-bottom: 1rem; }
.field label { display: block; margin-bottom: .35rem; font-weight: 600; font-size: .82rem; }
.field input, .field select, .field textarea {
  width: 100%;
  padding: .6rem .75rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: .9rem;
  font-family: inherit;
}
.field textarea { resize: vertical; }
.field small { color: var(--text-muted); display: block; margin-top: .25rem; }

.btn {
  display: inline-block;
  border: none;
  border-radius: 8px;
  padding: .6rem 1.1rem;
  font-size: .88rem;
  font-weight: 600;
  cursor: pointer;
  background: var(--primary);
  color: #fff;
}
.btn:hover { background: var(--primary-dark); }
.btn.block { width: 100%; }
.btn.secondary { background: #e2e8f0; color: var(--text); }
.btn.secondary:hover { background: #cbd5e1; }
.btn.danger { background: var(--danger); }
.btn.danger:hover { background: #b91c1c; }
.btn.small { padding: .35rem .7rem; font-size: .78rem; }

.alert {
  padding: .7rem 1rem;
  border-radius: 8px;
  margin-bottom: 1rem;
  font-size: .85rem;
}
.alert.error { background: #fee2e2; color: #991b1b; }
.alert.success { background: #dcfce7; color: #166534; }

.app-shell { display: flex; min-height: 100vh; }
.sidebar {
  width: 220px;
  background: var(--panel-dark);
  color: #e2e8f0;
  padding: 1.25rem 1rem;
  flex-shrink: 0;
}
.sidebar h2 { font-size: 1.05rem; margin: 0 0 1.5rem; color: #fff; }
.sidebar nav a {
  display: block;
  padding: .55rem .7rem;
  border-radius: 8px;
  color: #cbd5e1;
  margin-bottom: .2rem;
  font-size: .87rem;
}
.sidebar nav a:hover, .sidebar nav a.active { background: rgba(255,255,255,.08); color: #fff; text-decoration: none; }
.sidebar .user-box { margin-top: 2rem; padding-top: 1rem; border-top: 1px solid rgba(255,255,255,.1); font-size: .8rem; color: #94a3b8; }

.main { flex: 1; padding: 1.75rem 2.25rem; max-width: 1200px; }
.main h1 { margin: 0 0 1.25rem; font-size: 1.4rem; }

.card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.5rem;
  margin-bottom: 1.25rem;
}

.card-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 1rem; }
.card-header h2 { margin: 0; font-size: 1.05rem; }

table { width: 100%; border-collapse: collapse; font-size: .87rem; }
th, td { text-align: left; padding: .6rem .5rem; border-bottom: 1px solid var(--border); }
th { color: var(--text-muted); font-weight: 600; font-size: .78rem; text-transform: uppercase; letter-spacing: .03em; }
tr:last-child td { border-bottom: none; }

.badge {
  display: inline-block;
  padding: .18rem .55rem;
  border-radius: 999px;
  font-size: .72rem;
  font-weight: 700;
}
.badge.ativo { background: #dcfce7; color: #166534; }
.badge.inativo { background: #fee2e2; color: #991b1b; }
.badge.rascunho { background: #fef3c7; color: #92400e; }
.badge.openai { background: #dbeafe; color: #1e40af; }
.badge.anthropic { background: #fce7f3; color: #9d174d; }

.row-actions { display: flex; gap: .4rem; }
.row-actions form { display: inline; }

.stat-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 1rem; margin-bottom: 1.5rem; }
.stat-card { background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius); padding: 1.1rem 1.25rem; }
.stat-card .value { font-size: 1.6rem; font-weight: 700; }
.stat-card .label { color: var(--text-muted); font-size: .8rem; }

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

.playground-chat { display: flex; flex-direction: column; gap: .6rem; max-height: 460px; overflow-y: auto; padding: .5rem 0; }
.msg { max-width: 70%; padding: .55rem .8rem; border-radius: 10px; font-size: .87rem; white-space: pre-wrap; }
.msg.user { align-self: flex-end; background: var(--primary); color: #fff; }
.msg.assistant { align-self: flex-start; background: #f1f5f9; }
.msg.meta { align-self: flex-start; font-size: .72rem; color: var(--text-muted); }

.spinner { display: inline-block; width: 14px; height: 14px; border: 2px solid rgba(255,255,255,.4); border-top-color: #fff; border-radius: 50%; animation: spin .6s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

.code-inline { background: #f1f5f9; padding: .1rem .4rem; border-radius: 4px; font-family: monospace; font-size: .82rem; }

.log-context { background: #0f172a; color: #e2e8f0; padding: .75rem; border-radius: 8px; font-size: .76rem; overflow-x: auto; white-space: pre-wrap; }

.filters { display: flex; gap: .6rem; margin-bottom: 1rem; flex-wrap: wrap; }
.filters select, .filters input { padding: .45rem .6rem; border: 1px solid var(--border); border-radius: 6px; font-size: .82rem; }
