:root {
  --bg: #f4f6f9;
  --surface: #ffffff;
  --surface-soft: #f9fafb;
  --text: #172033;
  --muted: #677489;
  --line: #dfe5ec;
  --primary: #2456a6;
  --primary-dark: #173d79;
  --danger-bg: #fff1f1;
  --danger-text: #9a2f2f;
  --sidebar: #162235;
  --sidebar-muted: #aeb9c8;
  --shadow: 0 10px 30px rgba(22, 34, 53, 0.08);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; background: var(--bg); color: var(--text); }
a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }
button, input { font: inherit; }

.login-body {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
  background: linear-gradient(135deg, #eef3f9 0%, #f8fafc 100%);
}

.login-card, .login-panel {
  width: min(100%, 440px);
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 16px;
  box-shadow: var(--shadow);
  padding: 32px;
}

.login-brand { display: flex; gap: 16px; align-items: center; margin-bottom: 12px; }
.login-brand h1 { margin: 4px 0 0; font-size: 24px; }
.login-note { font-size: 12px; color: var(--muted); margin: 20px 0 0; line-height: 1.5; }

.brand-mark {
  width: 38px;
  height: 38px;
  border-radius: 10px;
  display: inline-grid;
  place-items: center;
  font-weight: 800;
  background: #e8effa;
  color: var(--primary);
}
.brand-mark.large { width: 50px; height: 50px; font-size: 18px; }

.eyebrow { color: var(--primary); font-size: 12px; font-weight: 800; letter-spacing: .08em; text-transform: uppercase; }
.muted { color: var(--muted); }

.alert {
  margin: 18px 0;
  padding: 12px 14px;
  border: 1px solid #f0c9c9;
  border-radius: 8px;
  background: var(--danger-bg);
  color: var(--danger-text);
  font-size: 14px;
}

.form-stack { display: grid; gap: 16px; margin-top: 22px; }
.form-stack label { display: grid; gap: 7px; font-size: 14px; font-weight: 600; }
input {
  width: 100%;
  border: 1px solid #cfd7e2;
  border-radius: 8px;
  padding: 10px 12px;
  background: #fff;
  color: var(--text);
}
input:focus { outline: 2px solid #c9daf5; border-color: var(--primary); }

.button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: 1px solid var(--primary);
  background: var(--primary);
  color: #fff;
  border-radius: 8px;
  padding: 9px 14px;
  cursor: pointer;
  font-weight: 700;
  font-size: 14px;
  text-decoration: none;
}
.button:hover { background: var(--primary-dark); text-decoration: none; }
.button.full { width: 100%; }
.button-small { padding: 7px 10px; font-size: 12px; white-space: nowrap; }
.button-ghost { background: transparent; color: var(--primary); border-color: #b8c8df; }
.button-ghost:hover { background: #eef4fc; }

.app-shell { min-height: 100vh; display: grid; grid-template-columns: 240px minmax(0, 1fr); }
.sidebar {
  background: var(--sidebar);
  color: #fff;
  padding: 20px 16px;
  display: flex;
  flex-direction: column;
  position: sticky;
  top: 0;
  height: 100vh;
}
.brand { display: flex; gap: 12px; align-items: center; padding: 4px 4px 20px; border-bottom: 1px solid rgba(255,255,255,.1); }
.brand strong, .brand small { display: block; }
.brand small { color: var(--sidebar-muted); margin-top: 3px; }
.side-nav { display: grid; gap: 6px; padding-top: 18px; }
.side-nav a { color: var(--sidebar-muted); padding: 10px 12px; border-radius: 8px; font-weight: 650; }
.side-nav a:hover, .side-nav a.active { background: rgba(255,255,255,.1); color: #fff; text-decoration: none; }
.sidebar-logout { margin-top: auto; }
.sidebar-logout .button { width: 100%; color: #fff; border-color: rgba(255,255,255,.25); }
.sidebar-logout .button:hover { background: rgba(255,255,255,.1); }

.main-column { min-width: 0; }
.topbar {
  height: 68px;
  padding: 0 28px;
  display: flex;
  align-items: center;
  gap: 16px;
  justify-content: space-between;
  background: var(--surface);
  border-bottom: 1px solid var(--line);
  position: sticky;
  top: 0;
  z-index: 5;
}
.topbar strong { display: block; }
.topbar-subtitle { color: var(--muted); font-size: 12px; }
.admin-chip { max-width: 280px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 13px; background: #f0f3f7; padding: 7px 10px; border-radius: 999px; }
.mobile-menu { display: none; }
.content { padding: 28px; max-width: 1500px; margin: 0 auto; }

.page-header { margin-bottom: 18px; }
.page-header h1 { margin: 5px 0 5px; font-size: 26px; }
.page-header p { margin: 0; }
.split-header { display: flex; align-items: end; justify-content: space-between; gap: 16px; }
.back-link { display: inline-block; margin-bottom: 14px; font-size: 13px; }
.stat-card { background: var(--surface); border: 1px solid var(--line); border-radius: 10px; padding: 12px 16px; min-width: 120px; text-align: center; margin-bottom: 10px;}
.stat-card strong, .stat-card span { display: block; }
.stat-card strong { font-size: 22px; }
.stat-card span { color: var(--muted); font-size: 12px; }

.card { background: var(--surface); border: 1px solid var(--line); border-radius: 12px; box-shadow: 0 4px 12px rgba(22,34,53,.03); padding: 18px; margin-bottom: 18px; }
.narrow-card { max-width: 640px; }
.search-form { display: flex; gap: 10px; }
.search-form input { max-width: 460px; }
.table-card { padding: 0; overflow: hidden; }
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th, td { padding: 13px 16px; border-bottom: 1px solid var(--line); text-align: left; vertical-align: middle; font-size: 14px; }
th { background: var(--surface-soft); color: #4a5870; font-size: 12px; text-transform: uppercase; letter-spacing: .04em; }
tbody tr:last-child td { border-bottom: 0; }
tbody tr:hover { background: #fafbfd; }
.action-col { text-align: right; }
.empty-state { text-align: center; color: var(--muted); padding: 36px 16px; }
.pagination { display: flex; justify-content: center; align-items: center; gap: 12px; padding: 16px; border-top: 1px solid var(--line); font-size: 13px; }

.conversation-stream { display: grid; gap: 14px; }
.message-card { background: var(--surface); border: 1px solid var(--line); border-radius: 12px; overflow: hidden; box-shadow: 0 4px 12px rgba(22,34,53,.03); }
.message-user { border-left: 4px solid #2456a6; }
.message-ai { border-left: 4px solid #79889d; }
.message-header { padding: 11px 14px; display: flex; align-items: center; justify-content: space-between; gap: 14px; background: var(--surface-soft); border-bottom: 1px solid var(--line); }
.message-header strong { font-size: 12px; letter-spacing: .08em; }
.message-meta { display: flex; flex-wrap: wrap; gap: 8px 14px; color: var(--muted); font-size: 12px; justify-content: flex-end; }
.message-text { padding: 16px; white-space: pre-wrap; overflow-wrap: anywhere; line-height: 1.55; font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 13px; }
.dot-separator::before { content: " / "; padding: 0 7px; color: #a0aabb; }

@media (max-width: 860px) {
  .app-shell { grid-template-columns: 1fr; }
  .sidebar { position: fixed; left: -260px; width: 240px; z-index: 20; transition: left .2s ease; }
  .sidebar.sidebar-open { left: 0; }
  .mobile-menu { display: inline-flex; border: 1px solid var(--line); background: #fff; border-radius: 7px; padding: 7px 9px; }
  .topbar { padding: 0 16px; justify-content: flex-start; }
  .topbar > div:nth-child(2) { flex: 1; }
  .topbar-subtitle, .admin-chip { display: none; }
  .content { padding: 18px; }
  .split-header { align-items: start; flex-direction: column; }
  .search-form { flex-wrap: wrap; }
  .search-form input { max-width: none; flex-basis: 100%; }
}

.back-link {
  display: inline-block;
  margin-bottom: 16px;
  text-decoration: none;
}

.conversation-user {
  display: flex;
  align-items: baseline;
  gap: 8px;
  margin-bottom: 16px;
}

.conversation-user-name {
  font-weight: 600;
}

.conversation-user-email {
  font-size: 0.875rem;
  color: #6b7280;
}

.conversation-title {
  margin-top: 4px;
  margin-bottom: 8px;
}

.conversation-meta {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}
