:root {
  --bg: #0f0f0f;
  --surface: #1a1a1a;
  --border: #2a2a2a;
  --text: #e0e0e0;
  --muted: #888;
  --primary: #7c6af7;
  --primary-hover: #6b5ae5;
  --success: #22c55e;
  --danger: #ef4444;
  --radius: 8px;
}

* { margin: 0; padding: 0; box-sizing: border-box; }
html, body { height: 100%; font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif; background: var(--bg); color: var(--text); font-size: 15px; }
body.chat-page { overflow: hidden; }

/* Navbar */
.navbar { display: flex; align-items: center; justify-content: space-between; padding: 0.75rem 1.5rem; background: var(--surface); border-bottom: 1px solid var(--border); flex-shrink: 0; z-index: 100; }
.nav-brand { font-weight: 700; font-size: 1.1rem; }
.nav-links { display: flex; gap: 1.25rem; }
.nav-links a { color: var(--muted); text-decoration: none; font-size: 0.9rem; transition: color .2s; }
.nav-links a:hover { color: var(--text); }

/* Container */
.container { max-width: 1100px; margin: 0 auto; padding: 2rem 1.5rem; }

/* Buttons */
.btn { display: inline-flex; align-items: center; padding: 0.5rem 1rem; border-radius: var(--radius); border: none; cursor: pointer; font-size: 0.9rem; font-weight: 500; text-decoration: none; transition: background .2s; }
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-hover); }
.btn-secondary { background: var(--surface); color: var(--text); border: 1px solid var(--border); }
.btn-secondary:hover { background: #222; }
.btn-success { background: var(--success); color: #fff; }
.btn-danger { background: var(--danger); color: #fff; }
.btn-sm { padding: 0.3rem 0.7rem; font-size: 0.8rem; }
.btn-full { width: 100%; justify-content: center; }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }

/* Cards */
.card-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 1rem; }
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; display: flex; flex-direction: column; }
.card-link { text-decoration: none; color: inherit; transition: border-color .2s, transform .2s; }
.card-link:hover { border-color: var(--primary); transform: translateY(-2px); }
.card-body { padding: 1.25rem; flex: 1; }
.card-icon { font-size: 2rem; margin-bottom: 0.75rem; }
.card-title { font-size: 1.1rem; font-weight: 600; margin-bottom: 0.4rem; }
.card-desc { color: var(--muted); font-size: 0.88rem; }
.card-footer { padding: 0.75rem 1.25rem; border-top: 1px solid var(--border); }

/* Page header */
.page-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 1.5rem; }
.page-header h1 { font-size: 1.5rem; }

/* Forms */
.form-group { margin-bottom: 1rem; }
.form-group label { display: block; margin-bottom: 0.4rem; font-size: 0.88rem; color: var(--muted); }
.form-control { width: 100%; padding: 0.55rem 0.8rem; background: var(--bg); border: 1px solid var(--border); border-radius: var(--radius); color: var(--text); font-size: 0.9rem; }
.form-control:focus { outline: none; border-color: var(--primary); }
textarea.form-control { resize: vertical; font-family: monospace; }
.form-check { display: flex; align-items: center; gap: 0.5rem; }
.form-check input { width: auto; }
.inline-form { display: flex; gap: 0.5rem; flex-wrap: wrap; align-items: flex-end; }
.inline-form .form-control { width: auto; flex: 1; min-width: 120px; }

/* Login */
.login-body { display: flex; align-items: center; justify-content: center; min-height: 100vh; }
.login-card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 2.5rem; width: 100%; max-width: 380px; }
.login-logo { font-size: 3rem; text-align: center; margin-bottom: 0.5rem; }
.login-card h1 { text-align: center; margin-bottom: 1.5rem; font-size: 1.4rem; }
.login-card .form-group { margin-bottom: 0.75rem; }

/* Alerts */
.alert { padding: 0.75rem 1rem; border-radius: var(--radius); margin-bottom: 1rem; }
.alert-error { background: #3b1111; border: 1px solid #7f1d1d; color: #fca5a5; }
.alert-success { background: #14532d; border: 1px solid #166534; color: #86efac; }

/* Badges */
.badge { display: inline-block; padding: 0.2rem 0.5rem; border-radius: 4px; font-size: 0.75rem; font-weight: 600; }
.badge-green { background: #14532d; color: #86efac; }
.badge-red { background: #3b0f0f; color: #fca5a5; }
.badge-blue { background: #1e1b4b; color: #a5b4fc; }
.badge-grey { background: #1f1f1f; color: #888; }

/* Tables */
.admin-table { width: 100%; border-collapse: collapse; margin-top: 0.75rem; }
.admin-table th, .admin-table td { padding: 0.65rem 0.9rem; text-align: left; border-bottom: 1px solid var(--border); font-size: 0.88rem; }
.admin-table th { background: var(--surface); color: var(--muted); font-weight: 600; }
.admin-table tr:hover td { background: #151515; }
.admin-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 2rem; }
.section-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 0.5rem; }
.section-header h2 { font-size: 1.1rem; }

/* Chat */
/* Chat — fixed header+input, scrollable messages between */
.chat-main { padding: 0; }
.chat-layout { display: flex; flex-direction: column; max-width: 800px; width: 100%; margin: 0 auto; padding: 0 1rem; }
.chat-header { display: flex; align-items: center; gap: 1rem; padding: 0.75rem 0; border-bottom: 1px solid var(--border); }
.chat-header h2 { font-size: 1.1rem; }
.chat-messages { padding: 1rem 0; display: flex; flex-direction: column; gap: 1rem; min-height: 10px; max-height: 60vh; overflow-y: auto; }
.message { display: flex; }
.message-user { justify-content: flex-end; }
.message-assistant { justify-content: flex-start; }
.message-bubble { max-width: 75%; padding: 0.75rem 1rem; border-radius: var(--radius); font-size: 0.92rem; line-height: 1.6; }
.message-user .message-bubble { background: var(--primary); color: #fff; border-bottom-right-radius: 2px; }
.message-assistant .message-bubble { background: var(--surface); border: 1px solid var(--border); border-bottom-left-radius: 2px; }
.message-assistant .message-bubble h1, .message-assistant .message-bubble h2, .message-assistant .message-bubble h3 { margin: 0.75rem 0 0.4rem; }
.message-assistant .message-bubble p { margin-bottom: 0.5rem; }
.message-assistant .message-bubble ul, .message-assistant .message-bubble ol { padding-left: 1.2rem; margin-bottom: 0.5rem; }
.message-assistant .message-bubble code { background: #111; padding: 0.1em 0.35em; border-radius: 3px; font-size: 0.87em; }
.message-assistant .message-bubble pre { background: #111; padding: 0.75rem; border-radius: var(--radius); overflow-x: auto; margin: 0.5rem 0; }
.message-assistant .message-bubble pre code { background: none; padding: 0; }
.chat-input-area { padding: 0.75rem 0 1rem; border-top: 1px solid var(--border); background: var(--bg); }
.chat-input-wrap { display: flex; gap: 0.5rem; align-items: flex-end; }
.chat-input { flex: 1; resize: none; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); color: var(--text); padding: 0.65rem 0.9rem; font-size: 0.92rem; font-family: inherit; overflow-y: hidden; }
.chat-input:focus { outline: none; border-color: var(--primary); }

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

@media (max-width: 640px) {
  .admin-grid { grid-template-columns: 1fr; }
  .message-bubble { max-width: 90%; }
}
