/* Design System + Shared Styles for /admin/* pages and chatbot.html
   Version: 2026-06-17 */

/* ---- Design Tokens --------------------------------------------------- */

:root {
  /* Palette */
  --c-primary: #667eea;
  --c-primary-dark: #4f66d6;
  --c-primary-text: white;
  --c-accent: #764ba2;
  --c-success: #16a34a;
  --c-success-bg: #dcfce7;
  --c-danger: #dc2626;
  --c-danger-bg: #fee2e2;
  --c-warning: #92400e;
  --c-warning-bg: #fef3c7;
  --c-info: #2563eb;

  /* Surface */
  --c-surface: white;
  --c-surface-dim: #f8f9fa;
  --c-surface-muted: #f9fafb;
  --c-border: #e5e7eb;
  --c-border-light: #f0f0f0;
  --c-text: #1f2937;
  --c-text-secondary: #6b7280;
  --c-text-muted: #9ca3af;

  /* Thinking / reasoning */
  --c-think-bg: #f4f6ff;
  --c-think-border: #e4e7ff;
  --c-think-text: #4b5bbf;

  /* Tool matching */
  --c-tool-match-bg: #f0f7ee;
  --c-tool-match-border: #d5e8d0;
  --c-tool-match-text: #4a7a3a;
  --c-tool-match-label: #5a8a4a;

  /* Sidebar */
  --c-sidebar-bg: #2d2d3a;
  --c-sidebar-hover: #3d3d4a;
  --c-sidebar-active: #4d4d5a;
  --c-sidebar-text: #d4d4dc;

  /* Gradient */
  --gradient-primary: linear-gradient(135deg, var(--c-primary) 0%, var(--c-accent) 100%);

  /* Radii */
  --r-sm: 8px;
  --r-md: 12px;
  --r-lg: 18px;
  --r-pill: 999px;

  /* Shadows */
  --s-sm: 0 1px 3px rgba(0,0,0,.05);
  --s-md: 0 2px 8px rgba(0,0,0,.1);
  --s-lg: 0 8px 24px rgba(0,0,0,.06);
  --s-xl: 0 20px 48px rgba(15,23,42,.16);

  /* Spacing */
  --sp-xs: 4px;
  --sp-sm: 8px;
  --sp-md: 12px;
  --sp-lg: 16px;
  --sp-xl: 20px;
  --sp-2xl: 24px;

  /* Font sizes */
  --fs-xs: 11px;
  --fs-sm: 12px;
  --fs-base: 13px;
  --fs-md: 14px;
  --fs-lg: 16px;
  --fs-xl: 18px;
  --fs-2xl: 22px;

  /* Transition */
  --t-fast: 0.15s ease;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background: var(--c-surface-dim);
  color: var(--c-text);
}

.app-layout {
  display: flex;
  min-height: 100vh;
}

/* ---- Sidebar ---------------------------------------------------------- */

.sidebar {
  width: 240px;
  flex-shrink: 0;
  background: var(--c-sidebar-bg);
  color: var(--c-sidebar-text);
  display: flex;
  flex-direction: column;
  position: sticky;
  top: 0;
  height: 100vh;
}

.sidebar-header {
  padding: 16px 18px;
  border-bottom: 1px solid #1f1f28;
}

.sidebar-brand {
  font-size: 15px;
  font-weight: 700;
  color: white;
  letter-spacing: 0.5px;
}

.sidebar-list {
  flex: 1;
  overflow-y: auto;
  padding: var(--sp-sm);
}

.sidebar-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px var(--sp-md);
  border-radius: var(--r-sm);
  margin-bottom: var(--sp-xs);
  font-size: var(--fs-base);
  color: var(--c-sidebar-text);
  text-decoration: none;
  transition: background var(--t-fast);
  cursor: pointer;
}

.sidebar-item:hover {
  background: var(--c-sidebar-hover);
  color: white;
}

.sidebar-item.active {
  background: var(--c-sidebar-active);
  color: white;
  font-weight: 600;
}

.sidebar-footer {
  padding: var(--sp-md);
  border-top: 1px solid #1f1f28;
  font-size: var(--fs-base);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--sp-sm);
}

.sidebar-footer .username {
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* ---- Content area ------------------------------------------------------ */

.content {
  flex: 1;
  padding: var(--sp-2xl) 32px;
  max-width: 1180px;
  width: 100%;
  margin: 0 auto;
}

.content h1 {
  margin: 0 0 6px;
  font-size: var(--fs-2xl);
}

.content > .muted {
  margin-bottom: var(--sp-xl);
}

/* ---- Cards / forms ---------------------------------------------------- */

.card {
  background: var(--c-surface);
  border: 1px solid var(--c-border);
  border-radius: var(--r-md);
  padding: 18px;
  margin-bottom: 18px;
  box-shadow: var(--s-sm);
}

.card h2 {
  margin: 0 0 var(--sp-md);
  font-size: var(--fs-lg);
}

.card-title {
  font-size: var(--fs-lg);
  font-weight: 600;
  margin: 0 0 var(--sp-md);
}

.grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 18px;
}

label {
  display: block;
  font-weight: 600;
  margin: 10px 0 6px;
  font-size: var(--fs-base);
}

input[type=text], input[type=password], input:not([type]),
textarea, select {
  width: 100%;
  box-sizing: border-box;
  border: 1px solid #d1d5db;
  border-radius: var(--r-sm);
  padding: 10px;
  font: inherit;
  background: var(--c-surface);
}

textarea {
  min-height: 180px;
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
  font-size: var(--fs-base);
  line-height: 1.5;
}

button {
  border: 0;
  border-radius: var(--r-sm);
  padding: 10px 14px;
  cursor: pointer;
  background: var(--c-info);
  color: white;
  font-weight: 600;
  margin: 6px 6px 6px 0;
  font: inherit;
}
button:hover { filter: brightness(1.05); }
button:disabled { opacity: 0.5; cursor: not-allowed; }

button.secondary { background: var(--c-text-secondary); }
button.danger { background: var(--c-danger); }
button.success { background: var(--c-success); }
button.link {
  background: transparent;
  color: var(--c-info);
  padding: var(--sp-xs) 0;
  margin: 0;
  text-decoration: underline;
}

pre {
  background: #111827;
  color: #f9fafb;
  padding: var(--sp-md);
  border-radius: var(--r-sm);
  overflow: auto;
  max-height: 320px;
  font-size: var(--fs-sm);
}

pre.detail {
  background: #f5f5f5;
  color: var(--c-text);
  padding: var(--sp-sm);
  max-height: 300px;
  font-size: var(--fs-base);
  white-space: pre-wrap;
}

/* ---- Tables / data ---------------------------------------------------- */

table {
  width: 100%;
  border-collapse: collapse;
}
th, td {
  text-align: left;
  padding: 10px;
  border-bottom: 1px solid var(--c-border);
  vertical-align: top;
  font-size: var(--fs-base);
}
th { font-weight: 600; background: var(--c-surface-muted); }

.hidden { display: none; }

/* ---- Status / badges -------------------------------------------------- */

.badge {
  display: inline-block;
  padding: 3px var(--sp-sm);
  border-radius: var(--r-pill);
  font-size: var(--fs-sm);
  background: var(--c-border);
  color: #374151;
}
.badge.active   { background: var(--c-success-bg); color: #166534; }
.badge.disabled { background: var(--c-border); color: #4b5563; }

.muted { color: var(--c-text-secondary); font-size: var(--fs-base); }
.error { color: var(--c-danger); white-space: pre-wrap; }
.ok    { color: var(--c-success); white-space: pre-wrap; }

/* ---- Detail / back link ---------------------------------------------- */

.detail-back {
  display: inline-block;
  margin-bottom: var(--sp-md);
  color: var(--c-info);
  cursor: pointer;
  text-decoration: none;
  font-size: var(--fs-base);
}
.detail-back:hover { text-decoration: underline; }

/* ---- Auth (login.html) ----------------------------------------------- */

.auth-wrap {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: var(--sp-2xl);
}

.auth-card {
  background: var(--c-surface);
  border: 1px solid var(--c-border);
  border-radius: var(--r-md);
  padding: 28px;
  width: 100%;
  max-width: 380px;
  box-shadow: var(--s-lg);
}

.auth-card h2 {
  margin: 0 0 6px;
  font-size: var(--fs-xl);
}

.auth-card .muted {
  margin-bottom: 18px;
}

.auth-card button {
  width: 100%;
  margin-top: 6px;
}

/* ================================================================== */
/* SHARED CHAT COMPONENTS                                              */
/* Used in: prompts.html, tools.html, conversations.html, chatbot.html */
/* ================================================================== */

/* ---- Chat message layout --------------------------------------------- */

.chat-messages {
  background: var(--c-surface-dim);
  border-radius: var(--r-md);
  padding: var(--sp-xl);
}

.chat-msg {
  margin-bottom: var(--sp-md);
  display: flex;
  flex-direction: column;
}
.chat-msg.user   { align-items: flex-end; }
.chat-msg.asst   { align-items: flex-start; }

.chat-msg-label {
  font-size: var(--fs-sm);
  color: #666;
  margin-bottom: var(--sp-xs);
  padding: 0 var(--sp-sm);
}

/* ---- User bubble ----------------------------------------------------- */

.chat-bubble-user {
  max-width: 80%;
  padding: var(--sp-md) var(--sp-lg);
  border-radius: var(--r-lg);
  border-bottom-right-radius: var(--sp-xs);
  background: var(--gradient-primary);
  color: white;
  line-height: 1.5;
  white-space: pre-wrap;
  word-break: break-word;
}

/* ---- Assistant card --------------------------------------------------- */

.chat-asst-card {
  max-width: 80%;
  background: var(--c-surface);
  color: #333;
  border-radius: var(--r-lg);
  border-bottom-left-radius: var(--sp-xs);
  box-shadow: var(--s-md);
  overflow: hidden;
}

/* ---- Thinking panel -------------------------------------------------- */

.chat-think {
  padding: var(--sp-md) var(--sp-lg);
  background: var(--c-think-bg);
  border-bottom: 1px solid var(--c-think-border);
  color: var(--c-think-text);
  font-size: var(--fs-base);
}
.chat-think summary {
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: var(--sp-sm);
  font-weight: 600;
  list-style: none;
}
.chat-think summary::-webkit-details-marker { display: none; }
.chat-think-dot {
  width: 8px; height: 8px;
  background: var(--c-primary);
  border-radius: 50%;
  animation: pulse 1.2s infinite ease-in-out;
}
.chat-think-dot.done {
  animation: none;
  opacity: .5;
}
.chat-think-body {
  margin-top: var(--sp-sm);
  padding: var(--sp-sm) 10px;
  background: rgba(255,255,255,.72);
  border: 1px solid var(--c-think-border);
  border-radius: var(--r-sm);
  color: var(--c-text-secondary);
  font-size: var(--fs-sm);
  line-height: 1.45;
  white-space: pre-wrap;
  word-break: break-word;
}

/* ---- Tool matching --------------------------------------------------- */

.chat-tool-match {
  padding: 10px var(--sp-lg);
  border-bottom: 1px solid var(--c-think-border);
  background: var(--c-tool-match-bg);
}
.chat-tool-match-title {
  font-size: var(--fs-xs);
  color: var(--c-tool-match-label);
  font-weight: 600;
  margin-bottom: 6px;
}
.chat-tool-match-item {
  margin-bottom: var(--sp-sm);
  padding: 6px 10px;
  background: rgba(255,255,255,.8);
  border: 1px solid var(--c-tool-match-border);
  border-radius: var(--r-sm);
}
.chat-tool-match-name {
  font-size: var(--fs-base);
  font-weight: 600;
  color: var(--c-tool-match-text);
}
.chat-tool-match-desc {
  font-size: var(--fs-xs);
  color: var(--c-text-secondary);
  margin-top: 2px;
  line-height: 1.4;
}
.chat-tool-match-args {
  font-size: var(--fs-xs);
  color: #8b9a7f;
  margin-top: var(--sp-xs);
  font-family: monospace;
  white-space: pre-wrap;
  max-height: 60px;
  overflow-y: auto;
}

/* ---- Tool call badges ------------------------------------------------ */

.chat-tool-calls {
  padding: var(--sp-sm) var(--sp-lg);
  border-bottom: 1px solid var(--c-think-border);
  background: #eef0fb;
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  align-items: center;
}
.chat-tool-calls-label {
  font-size: var(--fs-xs);
  color: #8b8fc7;
  font-weight: 600;
  margin-right: 2px;
}
.chat-tool-badge {
  display: inline-flex;
  align-items: center;
  gap: var(--sp-xs);
  background: var(--c-primary);
  color: white;
  font-size: var(--fs-xs);
  padding: 3px 10px;
  border-radius: var(--r-pill);
  font-weight: 500;
}
.chat-tool-badge .chat-tool-badge-args {
  font-size: 10px;
  opacity: .72;
  max-width: 120px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* ---- Answer panel ---------------------------------------------------- */

.chat-answer {
  padding: var(--sp-md) var(--sp-lg);
  line-height: 1.5;
  word-break: break-word;
}
.chat-answer-title {
  font-size: var(--fs-sm);
  color: #777;
  margin-bottom: 6px;
  font-weight: 600;
}
.answer-text {
  white-space: pre-wrap;
  word-break: break-word;
}

/* ---- Debug link (conversations → prompts) ---------------------------- */

.chat-debug-link {
  display: inline-flex;
  align-items: center;
  gap: var(--sp-xs);
  margin: var(--sp-sm) var(--sp-lg) var(--sp-xs);
  padding: 5px var(--sp-md);
  border-radius: var(--r-sm);
  background: #eef0fb;
  color: var(--c-primary);
  font-size: var(--fs-sm);
  font-weight: 500;
  text-decoration: none;
  border: 1px solid #d4d8f7;
  cursor: pointer;
  transition: background var(--t-fast), color var(--t-fast);
}
.chat-debug-link:hover {
  background: var(--c-primary);
  color: white;
}

/* ---- Comparison columns (prompts debug) ------------------------------- */

.cmp-cols {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: var(--sp-md);
}
.cmp-col {
  border-radius: var(--r-md);
  overflow: hidden;
  background: var(--c-surface);
  box-shadow: 0 1px 4px rgba(0,0,0,.08);
}
.cmp-col-label {
  font-size: var(--fs-xs);
  font-weight: 600;
  padding: 6px var(--sp-md);
  border-bottom: 1px solid var(--c-border-light);
}
.cmp-col-label.original { background: var(--c-surface-muted); color: var(--c-text-secondary); }
.cmp-col-label.new { background: #eff6ff; color: var(--c-info); }
.cmp-col-label.streaming {
  background: #eff6ff; color: var(--c-info);
  display: flex; align-items: center; gap: 6px;
}
.cmp-col-label.streaming::after {
  content: ""; width: 6px; height: 6px;
  background: var(--c-info); border-radius: 50%;
  animation: pulse 1.2s infinite ease-in-out;
}
.cmp-col-body {
  padding: var(--sp-md);
  font-size: var(--fs-base);
  line-height: 1.5;
  white-space: pre-wrap;
  word-break: break-word;
}

/* ---- Regen button (prompts comparison) ------------------------------- */

.regen-btn {
  display: inline-flex;
  align-items: center;
  gap: var(--sp-xs);
  background: #eef0fb;
  color: var(--c-primary);
  border: 1px solid #d4d8f7;
  padding: 5px 10px;
  border-radius: var(--r-sm);
  font-size: var(--fs-sm);
  cursor: pointer;
  white-space: nowrap;
  margin: 0;
}
.regen-btn:hover { background: var(--c-primary); color: white; }
.regen-btn:disabled { opacity: .5; cursor: not-allowed; }

/* ---- Animation ------------------------------------------------------- */

@keyframes pulse {
  0%, 100% { opacity: 1; transform: scale(1); }
  50% { opacity: .45; transform: scale(.86); }
}

/* ---- Responsive ------------------------------------------------------- */

@media (max-width: 720px) {
  .app-layout { flex-direction: column; }
  .sidebar {
    width: 100%;
    height: auto;
    position: static;
  }
  .sidebar-list { display: flex; overflow-x: auto; }
  .sidebar-item { white-space: nowrap; flex-shrink: 0; margin-bottom: 0; }
  .sidebar-footer { display: none; }
  .content { padding: var(--sp-md); }
  .grid { grid-template-columns: 1fr; }
  .cmp-cols { grid-template-columns: 1fr; }
}
