/* Ai Chat — alleen lokaal, geen externe CSS-CDN */
:root {
  --bg: #0f0a14;
  --card: #1a1224;
  --card-hover: #241a32;
  --accent: #c084fc;
  --accent-dim: #7c3aed;
  --accent-pink: #f472b6;
  --text: #e5e7eb;
  --muted: #9ca3af;
  --border: rgba(255, 255, 255, 0.1);
  --admin-bg: rgba(30, 27, 75, 0.85);
  --danger: #f87171;
  --amber-bg: rgba(245, 158, 11, 0.15);
  --amber-border: rgba(245, 158, 11, 0.35);
  --red-bg: rgba(239, 68, 68, 0.15);
}

* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; }
body {
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}
a { color: var(--accent); }
a:hover { text-decoration: underline; }
code { font-size: 0.9em; color: var(--muted); }

.layout { display: flex; min-height: 100vh; }
.sidebar {
  width: 14rem;
  flex-shrink: 0;
  border-right: 1px solid var(--border);
  padding: 1rem;
  display: flex;
  flex-direction: column;
  gap: 1.5rem;
  background: var(--card);
}
.sidebar--admin { background: var(--admin-bg); }
.sidebar-brand {
  font-size: 1.125rem;
  font-weight: 700;
  text-decoration: none;
  background: linear-gradient(90deg, var(--accent), var(--accent-pink));
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}
.nav { display: flex; flex-direction: column; gap: 0.25rem; font-size: 0.875rem; }
.nav-label {
  font-size: 0.65rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--muted);
  margin-bottom: 0.25rem;
}
.sidebar--admin .nav-label { color: rgba(165, 180, 252, 0.75); }
.nav-link {
  display: block;
  padding: 0.5rem 0.75rem;
  border-radius: 0.5rem;
  color: #d1d5db;
  text-decoration: none;
}
.nav-link:hover { background: rgba(255,255,255,0.08); }
.nav-link--active { background: rgba(255,255,255,0.1); color: #fff; }
.sidebar-footer { margin-top: auto; font-size: 0.75rem; color: var(--muted); }
.sidebar-footer .email { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sidebar-footer form { margin-top: 0.5rem; }
.sidebar-footer button {
  background: none; border: none; color: var(--accent); cursor: pointer; padding: 0;
  font-size: inherit;
}
.sidebar-footer button:hover { text-decoration: underline; }

.main { flex: 1; padding: 1rem 2rem; overflow-x: hidden; }
@media (max-width: 768px) { .main { padding: 1rem; } }

.page-narrow { max-width: 28rem; margin: 0 auto; padding-top: 4rem; }
.page { max-width: 48rem; margin: 0 auto; }
.page-wide { max-width: 64rem; margin: 0 auto; }
.page-5xl { max-width: 64rem; margin: 0 auto; }

.grid-stats--admin {
  display: grid;
  gap: 1rem;
  margin-bottom: 2.5rem;
  grid-template-columns: 1fr;
}
@media (min-width: 640px) {
  .grid-stats--admin { grid-template-columns: repeat(2, 1fr); }
}
@media (min-width: 1024px) {
  .grid-stats--admin { grid-template-columns: repeat(4, 1fr); }
}

.grid-2 {
  display: grid;
  gap: 1rem;
  grid-template-columns: 1fr;
}
@media (min-width: 640px) {
  .grid-2 { grid-template-columns: repeat(2, 1fr); }
}

.line-clamp-3 {
  display: -webkit-box;
  -webkit-line-clamp: 3;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.inline-block { display: inline-block; }
.inline { display: inline; }
.mb-4 { margin-bottom: 1rem; }
.mt-1 { margin-top: 0.25rem; }
.mt-2 { margin-top: 0.5rem; }
.mt-6 { margin-top: 1.5rem; }
.mb-3 { margin-bottom: 0.75rem; }
.mb-8 { margin-bottom: 2rem; }
.mb-10 { margin-bottom: 2.5rem; }
.py-3 { padding-top: 0.75rem; padding-bottom: 0.75rem; }
.whitespace-nowrap { white-space: nowrap; }
.truncate {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.max-w-md { max-width: 28rem; }
.td-narrow { max-width: 140px; }
.td-mid { max-width: 120px; }
.td-snippet { max-width: 28rem; }
.td-owner { max-width: 200px; }

.alert--success {
  background: rgba(16, 185, 129, 0.15);
  border: 1px solid rgba(34, 197, 94, 0.35);
  color: #a7f3d0;
}

.btn--outline-amber {
  background: transparent;
  border: 1px solid rgba(245, 158, 11, 0.5);
  color: #fde68a;
  font-size: 0.875rem;
  padding: 0.375rem 0.75rem;
}
.btn--outline-amber:hover { background: rgba(245, 158, 11, 0.1); }

.link-admin { color: #a5b4fc; text-decoration: none; }
.link-admin:hover { text-decoration: underline; }

.table-wrap--min600 .table { min-width: 600px; }
.table-wrap--min700 .table { min-width: 700px; }

.input--flex { flex: 1; max-width: 28rem; }

.card-char--inactive { opacity: 0.6; }

.badge--indigo-soft {
  display: inline-block;
  margin-top: 0.25rem;
  font-size: 0.75rem;
  padding: 0.125rem 0.5rem;
  border-radius: 9999px;
  background: rgba(99, 102, 241, 0.3);
  color: #e0e7ff;
}
.badge--gray-soft {
  display: inline-block;
  margin-top: 0.25rem;
  font-size: 0.75rem;
  padding: 0.125rem 0.5rem;
  border-radius: 9999px;
  background: rgba(255, 255, 255, 0.08);
  color: #d1d5db;
}

.copy-btn {
  background: none;
  border: none;
  padding: 0;
  cursor: pointer;
  color: inherit;
  font-size: inherit;
  font-family: inherit;
}
.copy-btn:hover { text-decoration: underline; }

.input:disabled {
  background: rgba(0, 0, 0, 0.2);
  border-color: rgba(255, 255, 255, 0.05);
  color: var(--muted);
  cursor: not-allowed;
}

.form-inline-search { display: flex; gap: 0.5rem; margin-bottom: 1.5rem; flex-wrap: wrap; }
.form-inline-search .input--flex { min-width: 12rem; }

h1 { font-size: 1.5rem; font-weight: 700; color: #fff; margin: 0 0 0.5rem; }
.title-xl {
  font-size: 1.875rem;
  font-weight: 700;
  background: linear-gradient(90deg, var(--accent), var(--accent-pink));
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  margin: 0 0 0.5rem;
}
.subtitle { color: var(--muted); margin: 0 0 2rem; }
.lead { color: var(--muted); font-size: 0.875rem; margin: 0 0 1.5rem; }

.card {
  border-radius: 1rem;
  border: 1px solid var(--border);
  background: var(--card);
  padding: 1.5rem;
}
.card--dashed { border-style: dashed; background: rgba(26, 18, 36, 0.5); text-align: center; padding: 2rem; }

.alert { border-radius: 0.5rem; padding: 0.75rem 1rem; font-size: 0.875rem; margin-bottom: 1rem; }
.alert--warn { background: var(--amber-bg); border: 1px solid var(--amber-border); color: #fde68a; }
.alert--err { background: var(--red-bg); border: 1px solid rgba(239,68,68,0.35); color: #fecaca; }

.form-stack { display: flex; flex-direction: column; gap: 1rem; }
.label { display: block; font-size: 0.875rem; color: var(--muted); margin-bottom: 0.25rem; }
.input, .select, textarea.input {
  width: 100%;
  padding: 0.5rem 0.75rem;
  border-radius: 0.5rem;
  border: 1px solid var(--border);
  background: rgba(0,0,0,0.25);
  color: var(--text);
  font: inherit;
}
.input:focus, .select:focus, textarea.input:focus {
  outline: 2px solid var(--accent);
  outline-offset: 0;
}
textarea.input { resize: vertical; min-height: 6rem; }
textarea.input--mono { font-family: ui-monospace, monospace; font-size: 0.8125rem; }
.hint { font-size: 0.75rem; color: var(--muted); margin-top: 0.25rem; }

.btn {
  display: inline-block;
  padding: 0.5rem 1rem;
  border-radius: 0.5rem;
  font-weight: 600;
  font-size: 0.875rem;
  text-align: center;
  text-decoration: none;
  border: none;
  cursor: pointer;
  font-family: inherit;
}
.btn--primary {
  width: 100%;
  padding: 0.625rem;
  background: linear-gradient(90deg, var(--accent-dim), var(--accent));
  color: #fff;
}
.btn--primary:hover { opacity: 0.92; }
.btn--sm { width: auto; padding: 0.35rem 0.75rem; font-size: 0.8125rem; }
.btn--accent { background: var(--accent); color: #fff; }
.btn--ghost { background: transparent; color: var(--muted); }
.btn--ghost:hover { color: #fff; }
.btn--indigo { background: #4f46e5; color: #fff; }
.btn--indigo:hover { background: #6366f1; }
.btn--outline-indigo {
  background: transparent;
  border: 1px solid rgba(129, 140, 248, 0.4);
  color: #c7d2fe;
}
.btn--outline-indigo:hover { background: rgba(79, 70, 229, 0.25); }
.btn--outline-accent {
  background: transparent;
  border: 1px solid rgba(192, 132, 252, 0.5);
  color: var(--accent);
}
.btn--outline-accent:hover { background: rgba(192, 132, 252, 0.12); }
.btn--soft-accent {
  background: rgba(192, 132, 252, 0.2);
  color: var(--accent);
}
.btn--soft-accent:hover { background: rgba(192, 132, 252, 0.3); }
.btn--danger-text { background: none; color: var(--danger); font-size: 0.75rem; padding: 0; }
.btn--danger-text:hover { text-decoration: underline; }

.row { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 1rem; margin-bottom: 2rem; }
.row--start { justify-content: flex-start; gap: 0.5rem; }
.hidden { display: none !important; }
.flex { display: flex; }
.flex-1 { flex: 1; min-width: 0; }
.gap-2 { gap: 0.5rem; }
.flex-wrap { flex-wrap: wrap; }
.items-center { align-items: center; }
.justify-end { justify-content: flex-end; }
.mt-4 { margin-top: 1rem; }
.text-center { text-align: center; }
.text-muted { color: var(--muted); font-size: 0.875rem; }
.text-sm { font-size: 0.875rem; }
.mb-2 { margin-bottom: 0.5rem; }
.mb-6 { margin-bottom: 1.5rem; }

.chat-list { list-style: none; padding: 0; margin: 0; display: flex; flex-direction: column; gap: 0.5rem; }
.chat-item {
  display: flex;
  align-items: center;
  gap: 1rem;
  padding: 1rem;
  border-radius: 0.75rem;
  border: 1px solid var(--border);
  background: var(--card);
}
.chat-item:hover { border-color: rgba(192, 132, 252, 0.35); }
.chat-item .emoji { font-size: 1.75rem; flex-shrink: 0; }
.chat-item-body { flex: 1; min-width: 0; }
.chat-item-body a { font-weight: 500; color: #fff; text-decoration: none; display: block; }
.chat-item-body a:hover { color: var(--accent); }
.chat-item-meta { font-size: 0.75rem; color: var(--muted); flex-shrink: 0; }
@media (max-width: 640px) { .chat-item-meta { display: none; } }
.chat-item .del-wrap { opacity: 0; transition: opacity 0.15s; }
.chat-item:hover .del-wrap { opacity: 1; }

.modal-overlay {
  position: fixed; inset: 0; z-index: 50;
  display: none; align-items: center; justify-content: center;
  background: rgba(0,0,0,0.7); padding: 1rem;
}
.modal-overlay.is-open { display: flex; }
.modal-box {
  width: 100%; max-width: 28rem;
  border-radius: 1rem; border: 1px solid var(--border);
  background: var(--card); padding: 1.5rem;
  box-shadow: 0 25px 50px rgba(0,0,0,0.5);
}
.modal-actions { display: flex; gap: 0.5rem; justify-content: flex-end; margin-top: 1rem; }

.grid-stats {
  display: grid; gap: 1rem;
  grid-template-columns: repeat(auto-fill, minmax(10rem, 1fr));
  margin-bottom: 2.5rem;
}
.stat-card {
  border-radius: 0.75rem;
  border: 1px solid rgba(99, 102, 241, 0.35);
  background: rgba(30, 27, 75, 0.35);
  padding: 1rem;
}
.stat-card .label { font-size: 0.65rem; text-transform: uppercase; letter-spacing: 0.05em; color: rgba(165, 180, 252, 0.8); margin: 0; }
.stat-card .val { font-size: 1.75rem; font-weight: 700; color: #fff; margin: 0.25rem 0 0; }

.table-wrap { border-radius: 0.75rem; border: 1px solid var(--border); overflow: hidden; overflow-x: auto; }
.table { width: 100%; border-collapse: collapse; font-size: 0.875rem; }
.table th { text-align: left; padding: 0.5rem 1rem; background: rgba(0,0,0,0.25); color: var(--muted); font-weight: 500; }
.table td { padding: 0.5rem 1rem; border-top: 1px solid rgba(255,255,255,0.05); }
.table tr:hover td { background: rgba(255,255,255,0.03); }
.badge { display: inline-block; padding: 0.125rem 0.5rem; border-radius: 9999px; font-size: 0.75rem; }
.badge--admin { background: rgba(99, 102, 241, 0.35); color: #e0e7ff; }
.badge--user { background: rgba(255,255,255,0.08); color: #d1d5db; }

.text-indigo-muted { color: rgba(199, 210, 254, 0.85); font-size: 0.875rem; }

.stat-card-sub {
  font-size: 0.7rem;
  color: rgba(165, 180, 252, 0.65);
  margin: 0.35rem 0 0;
  line-height: 1.35;
}
.usage-h2 { font-size: 1.125rem; color: #fff; margin: 2rem 0 0.75rem; }
.usage-ok { color: #86efac; font-size: 0.75rem; font-weight: 600; }
.usage-fail { color: #fca5a5; font-size: 0.75rem; font-weight: 600; }
.font-mono { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; }

@media (min-width: 640px) {
  .usage-admin-page .grid-stats--admin { grid-template-columns: repeat(2, 1fr); }
}
@media (min-width: 1024px) {
  .usage-admin-page .grid-stats--admin { grid-template-columns: repeat(3, 1fr); }
}

/* Chat */
.chat-page { max-width: 48rem; margin: 0 auto; display: flex; flex-direction: column; padding-bottom: 9rem; }
.chat-top {
  display: flex; align-items: center; gap: 0.75rem;
  margin-bottom: 1rem; padding-bottom: 1rem;
  border-bottom: 1px solid var(--border);
}
.chat-top .emoji { font-size: 1.75rem; }
.chat-top h1 { font-size: 1.25rem; margin: 0; }
.chat-top .back { margin-left: auto; font-size: 0.875rem; }
.msg-scroll {
  flex: 1; overflow-y: auto;
  max-height: min(70vh, calc(100vh - 16rem));
  min-height: 200px;
  padding-right: 0.25rem;
}
.msg-list { display: flex; flex-direction: column; gap: 0.75rem; }
.msg-row { display: flex; animation: msg-in 0.35s ease-out both; }
.msg-row--user { justify-content: flex-end; }
.msg-row--ai { justify-content: flex-start; }
@keyframes msg-in {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}
.bubble {
  max-width: 85%; border-radius: 1rem; padding: 0.5rem 1rem; position: relative;
}
.bubble--user {
  background: linear-gradient(135deg, var(--accent-dim), var(--accent));
  color: #fff;
}
.bubble--ai {
  background: var(--card-hover);
  border: 1px solid var(--border);
}
.bubble-meta {
  display: flex; align-items: center; gap: 0.5rem; margin-top: 0.25rem;
  font-size: 0.75rem; opacity: 0;
  transition: opacity 0.15s;
}
.msg-row:hover .bubble-meta { opacity: 1; }
.bubble-meta--user { color: rgba(255,255,255,0.75); justify-content: flex-end; }
.bubble-meta--ai { color: var(--muted); }
.message-text { white-space: pre-wrap; word-break: break-word; }
.typing-row { margin-bottom: 0.5rem; padding-left: 0.5rem; }
.typing-row.hidden { display: none; }
.typing-dots {
  display: inline-flex; align-items: center; gap: 0.25rem;
  padding: 0.5rem 0.75rem; border-radius: 9999px;
  background: var(--card-hover); border: 1px solid var(--border);
}
.typing-dot {
  width: 6px; height: 6px; border-radius: 50%; background: var(--muted);
  animation: bounce-dots 1.2s ease-in-out infinite;
}
.typing-dot:nth-child(2) { animation-delay: 0.15s; }
.typing-dot:nth-child(3) { animation-delay: 0.3s; }
@keyframes bounce-dots {
  0%, 80%, 100% { opacity: 0.3; transform: translateY(0); }
  40% { opacity: 1; transform: translateY(-4px); }
}
.chat-form-wrap {
  position: fixed; bottom: 0; left: 0; right: 0;
  padding: 1rem;
  background: rgba(15, 10, 20, 0.95);
  border-top: 1px solid var(--border);
  z-index: 40;
}
@media (min-width: 768px) {
  .layout:not(.layout--guest) .chat-form-wrap { left: 14rem; }
}
.chat-form-inner { max-width: 48rem; margin: 0 auto; display: flex; gap: 0.5rem; }
.chat-form-inner textarea {
  flex: 1; min-height: 48px; max-height: 10rem; resize: none;
  padding: 0.75rem 1rem; border-radius: 0.75rem;
  border: 1px solid var(--border); background: var(--card); color: var(--text); font: inherit;
}
.chat-form-inner textarea:focus { outline: 2px solid var(--accent); }
.chat-err { font-size: 0.875rem; color: var(--danger); margin-top: 0.5rem; max-width: 48rem; margin-left: auto; margin-right: auto; }
.chat-err.hidden { display: none; }

.layout--guest .main { width: 100%; }

.admin-stat-grid .stat-card { border-color: rgba(99, 102, 241, 0.35); }
ul.plain { list-style: none; padding: 0; margin: 0; }
.list-row {
  display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between;
  gap: 0.5rem; padding: 0.75rem 1rem;
  border-radius: 0.5rem; border: 1px solid var(--border);
  background: rgba(0,0,0,0.2); margin-bottom: 0.5rem;
}
