/* ============================================================================
   Minimal RAG Chat UI (No Tailwind) — Token-based themes (2025)
   - Themes: system (default), light, dark, blue
   - Switch by setting: <html data-theme="system|light|dark|blue">
   ============================================================================ */

:root {
  /* Fonts */
  --font-sans: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, Arial, "Noto Sans", "Liberation Sans", sans-serif;
  --font-mono: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace;

  /* Radius */
  --r-sm: 12px;
  --r-md: 18px;
  --r-lg: 28px;

  /* Spacing */
  --s-1: 6px;
  --s-2: 10px;
  --s-3: 14px;
  --s-4: 18px;
  --s-5: 22px;

  /* Layout */
  --shell-max: 1240px;
  --sidebar-w: 290px;

  /* Motion */
  --ease: cubic-bezier(.2, .8, .2, 1);
  --t-1: 140ms;
  --t-2: 220ms;

  /* Shadows (tuned per theme) */
  --sh-1: 0 1px 2px rgba(0, 0, 0, 0.06);
  --sh-2: 0 10px 28px rgba(0, 0, 0, 0.10);
  --sh-3: 0 26px 72px rgba(0, 0, 0, 0.18);

  /* Focus ring */
  --ring: 0 0 0 3px rgba(59, 130, 246, 0.35);

  /* Default theme (light as base; system overrides via media) */
  color-scheme: light;

  --bg: #f6f8fc;
  --surface: #ffffff;
  --surface-2: #f1f5ff;
  --surface-3: rgba(255, 255, 255, 0.72);

  --text: #0f172a;
  --text-2: #1f2a44;
  --muted: #64748b;

  --border: rgba(15, 23, 42, 0.12);
  --border-2: rgba(15, 23, 42, 0.08);

  --accent: #2563eb;      /* blue 600 */
  --accent-2: #3b82f6;    /* blue 500 */
  --accent-ink: #ffffff;

  --danger: #dc2626;
  --warn: #d97706;
  --ok: #16a34a;

  --help-border: #f4c430; /* “sárga” keret */
}

/* --- Explicit themes (manual override) --- */
html[data-theme="light"] {
  color-scheme: light;
}

html[data-theme="dark"] {
  color-scheme: dark;

  --bg: #0b1220;
  --surface: #0f172a;
  --surface-2: #101c33;
  --surface-3: rgba(15, 23, 42, 0.72);

  --text: #e7edf7;
  --text-2: #d3dbe8;
  --muted: #94a3b8;

  --border: rgba(226, 232, 240, 0.16);
  --border-2: rgba(226, 232, 240, 0.12);

  --accent: #60a5fa;
  --accent-2: #93c5fd;
  --accent-ink: #071425;

  --danger: #f87171;
  --warn: #fbbf24;
  --ok: #34d399;

  --sh-1: 0 1px 2px rgba(0, 0, 0, 0.35);
  --sh-2: 0 12px 30px rgba(0, 0, 0, 0.35);
  --sh-3: 0 30px 80px rgba(0, 0, 0, 0.45);
}

html[data-theme="blue"] {
  color-scheme: dark;

  --bg: #061427;
  --surface: #071b34;
  --surface-2: #0a2344;
  --surface-3: rgba(7, 27, 52, 0.72);

  --text: #eaf2ff;
  --text-2: #d3e6ff;
  --muted: #9fb8e8;

  --border: rgba(186, 220, 255, 0.20);
  --border-2: rgba(186, 220, 255, 0.14);

  --accent: #38bdf8;
  --accent-2: #60a5fa;
  --accent-ink: #04203a;

  --danger: #fb7185;
  --warn: #fbbf24;
  --ok: #22c55e;

  --sh-1: 0 1px 2px rgba(0, 0, 0, 0.35);
  --sh-2: 0 12px 32px rgba(0, 0, 0, 0.35);
  --sh-3: 0 30px 88px rgba(0, 0, 0, 0.48);
}

/* --- System theme (default behavior) --- */
@media (prefers-color-scheme: dark) {
  html:not([data-theme]),
  html[data-theme="system"] {
    color-scheme: dark;

    --bg: #0b1220;
    --surface: #0f172a;
    --surface-2: #101c33;
    --surface-3: rgba(15, 23, 42, 0.72);

    --text: #e7edf7;
    --text-2: #d3dbe8;
    --muted: #94a3b8;

    --border: rgba(226, 232, 240, 0.16);
    --border-2: rgba(226, 232, 240, 0.12);

    --accent: #60a5fa;
    --accent-2: #93c5fd;
    --accent-ink: #071425;

    --danger: #f87171;
    --warn: #fbbf24;
    --ok: #34d399;

    --sh-1: 0 1px 2px rgba(0, 0, 0, 0.35);
    --sh-2: 0 12px 30px rgba(0, 0, 0, 0.35);
    --sh-3: 0 30px 80px rgba(0, 0, 0, 0.45);
  }
}

/* ============================================================================
   Global base
   ============================================================================ */

* { box-sizing: border-box; }
html, body { height: 100%; }

body {
  margin: 0;
  font-family: var(--font-sans);
  color: var(--text);
  background:
    radial-gradient(1200px 900px at 15% 0%, rgba(59, 130, 246, 0.10), transparent 55%),
    radial-gradient(900px 700px at 90% 10%, rgba(56, 189, 248, 0.10), transparent 60%),
    var(--bg);
}

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

::selection { background: rgba(59, 130, 246, 0.28); }

.sr-only {
  position: absolute !important;
  width: 1px !important;
  height: 1px !important;
  padding: 0 !important;
  margin: -1px !important;
  overflow: hidden !important;
  clip: rect(0, 0, 0, 0) !important;
  white-space: nowrap !important;
  border: 0 !important;
}

/* ============================================================================
   Layout: shell / sidebar / main
   ============================================================================ */

.shell {
  max-width: var(--shell-max);
  margin: 0 auto;
  min-height: 100vh;
  padding: 16px 14px 22px;

  display: grid;
  grid-template-columns: var(--sidebar-w) minmax(0, 1fr);
  gap: 14px;
}

.sidebar {
  position: sticky;
  top: 16px;
  align-self: start;

  border: 1px solid var(--border-2);
  background: linear-gradient(180deg, rgba(255,255,255,0.06), rgba(255,255,255,0.02)), var(--surface);
  border-radius: var(--r-lg);
  box-shadow: var(--sh-2);
  overflow: hidden;

  max-height: calc(100vh - 32px);
  display: grid;
  grid-template-rows: auto 1fr;
}

.side-top {
  padding: 14px 14px 10px;
  border-bottom: 1px solid var(--border-2);
  background: var(--surface-3);
  backdrop-filter: blur(10px);
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
}

.brand-mark {
  width: 34px;
  height: 34px;
  border-radius: 999px;
  background:
    radial-gradient(14px 14px at 30% 30%, rgba(255,255,255,0.85), transparent 55%),
    linear-gradient(135deg, var(--accent), rgba(56,189,248,0.55));
  box-shadow: var(--sh-1);
  border: 1px solid rgba(59, 130, 246, 0.30);
}

.brand-text { display: grid; gap: 2px; }
.brand-title { font-weight: 800; letter-spacing: 0.2px; font-size: 14px; }
.brand-sub { font-size: 12px; color: var(--muted); }

.side-section {
  padding: 10px;
  overflow: auto;
}

.side-label {
  font-size: 12px;
  color: var(--muted);
  letter-spacing: 0.12em;
  text-transform: uppercase;
  padding: 8px 8px 10px;
}

.side-muted {
  font-size: 13px;
  color: var(--muted);
  padding: 8px;
}

.source-list {
  display: grid;
  gap: 6px;
}

.source-item {
  width: 100%;
  text-align: left;

  display: flex;
  align-items: center;
  gap: 10px;
  overflow: hidden;

  border: 1px solid transparent;
  background: transparent;
  color: var(--text);

  border-radius: var(--r-md);
  padding: 10px 10px;

  cursor: pointer;
  transition: background var(--t-1) var(--ease), border-color var(--t-1) var(--ease), transform var(--t-1) var(--ease);
}

.source-item:hover {
  background: var(--surface-2);
  border-color: var(--border-2);
}

.source-item:active { transform: translateY(1px); }

.source-id {
  display: inline-flex;
  min-width: 46px;
  font-family: var(--font-mono);
  font-size: 12px;
  color: var(--muted);
  flex: 0 0 auto;
}


.source-title {
  font-size: 13px;
  color: var(--text-2);

  flex: 1 1 auto;
  min-width: 0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}


/* Main column */
.main {
  width: 100%;
  max-width: 920px;
  justify-self: center;

  display: grid;
  gap: 12px;
  align-content: start;
}

/* ============================================================================
   Cards
   ============================================================================ */

.card {
  border: 1px solid var(--border-2);
  background: linear-gradient(180deg, rgba(255,255,255,0.05), rgba(255,255,255,0.00)), var(--surface);
  border-radius: var(--r-lg);
  box-shadow: var(--sh-2);
  overflow: hidden;
}

/* ============================================================================
   Header (pastel / “régies” hangulatú háttér)
   ============================================================================ */

.header {
  position: relative;
  overflow: hidden;
  border: 1px solid var(--border-2);
  border-radius: var(--r-lg);
  background: var(--surface-3);
  backdrop-filter: blur(10px);
  box-shadow: var(--sh-2);
}

.header-backdrop {
  position: absolute;
  inset: 0;
  pointer-events: none;
  opacity: 0.9;

  background-image:
    radial-gradient(900px 160px at 10% 10%, rgba(59,130,246,0.18), transparent 60%),
    radial-gradient(800px 140px at 60% 25%, rgba(56,189,248,0.12), transparent 55%),
    radial-gradient(900px 160px at 95% 0%, rgba(147,197,253,0.14), transparent 60%),
    linear-gradient(180deg, rgba(255,255,255,0.10), rgba(255,255,255,0.00));
  filter: saturate(1.05);
}

.header-row {
  position: relative;
  z-index: 1;
  padding: 14px 16px;

  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.header-title {
  font-size: 18px;
  font-weight: 800;
  letter-spacing: 0.2px;
}

.header-meta {
  margin-top: 2px;
  font-size: 12px;
  color: var(--muted);
}

.header-actions {
  display: flex;
  gap: 10px;
  align-items: center;
}

/* Help button: fehér, sárga kerettel */
.help-btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;

  border-radius: 999px;
  padding: 8px 10px;
  border: 1px solid var(--help-border);
  background: var(--surface);
  color: var(--text);

  cursor: pointer;
  transition: background var(--t-1) var(--ease), transform var(--t-1) var(--ease);
  box-shadow: var(--sh-1);
}

.help-btn:hover { background: var(--surface-2); }
.help-btn:active { transform: scale(0.99); }
.help-btn:focus-visible { outline: none; box-shadow: var(--ring); }

.help-icon {
  width: 22px;
  height: 22px;
  border-radius: 999px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-weight: 800;
  background: rgba(244, 196, 48, 0.18);
  border: 1px solid rgba(244, 196, 48, 0.55);
}

.help-label { font-size: 13px; font-weight: 650; }

/* Theme toggle: small icon, subtle */
.theme-btn {
  width: 38px;
  height: 38px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  cursor: pointer;
  box-shadow: var(--sh-1);

  display: inline-flex;
  align-items: center;
  justify-content: center;

  transition: background var(--t-1) var(--ease), border-color var(--t-1) var(--ease), transform var(--t-1) var(--ease);
}

.theme-btn:hover { background: var(--surface-2); border-color: rgba(59,130,246,0.35); }
.theme-btn:active { transform: scale(0.99); }
.theme-btn:focus-visible { outline: none; box-shadow: var(--ring); }

/* ============================================================================
   Chat log + messages
   ============================================================================ */

.chat-card { min-height: 360px; }

.chat-log {
  padding: 16px;
  display: grid;
  gap: 12px;
  overflow: auto;
  max-height: 62vh;
}

.msg {
  display: grid;
  gap: 6px;
  max-width: 78%;
}

.msg-user { justify-self: end; }
.msg-assistant { justify-self: start; }
.msg-system { justify-self: start; max-width: 92%; }

.msg-error .bubble { border-color: rgba(220,38,38,0.40); background: rgba(220,38,38,0.08); }

.bubble {
  border: 1px solid var(--border-2);
  border-radius: 20px;
  padding: 10px 12px;
  background: var(--surface-2);
  box-shadow: var(--sh-1);
  line-height: 1.5;

  white-space: pre-wrap; /* user üzeneteknél a soremelés megmaradjon */
  word-break: break-word;
}

.msg-user .bubble {
  border-color: rgba(59,130,246,0.38);
  background: linear-gradient(180deg, rgba(59,130,246,0.22), rgba(59,130,246,0.10));
}

/* Django linebreaksbr <br> elemeket ad, ezért a bubble-ben jó a normál flow is. */
.bubble br { content: ""; }

/* ============================================================================
   Composer (input)
   ============================================================================ */

.composer-card { overflow: visible; }

.composer {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 10px;
  align-items: end;

  padding: 12px;
}

.composer-input {
  width: 100%;
  min-height: 46px;
  max-height: 170px;
  resize: none;

  border: 1px solid var(--border-2);
  border-radius: 24px;
  background: var(--surface-2);

  padding: 12px 12px;
  font: inherit;
  font-size: 14px;
  color: var(--text);
  line-height: 1.45;

  outline: none;
  transition: border-color var(--t-1) var(--ease), box-shadow var(--t-1) var(--ease), background var(--t-1) var(--ease);
}

.composer-input::placeholder { color: rgba(100, 116, 139, 0.95); }
.composer-input:focus { border-color: rgba(59,130,246,0.45); box-shadow: var(--ring); background: var(--surface); }

.composer-actions {
  display: flex;
  gap: 10px;
  align-items: center;
  padding-bottom: 2px;
}

/* Icon buttons */
.icon-btn {
  width: 40px;
  height: 40px;
  border-radius: 999px;

  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);

  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;

  transition: background var(--t-1) var(--ease), border-color var(--t-1) var(--ease), transform var(--t-1) var(--ease);
  box-shadow: var(--sh-1);
}

.icon-btn:hover { background: var(--surface-2); border-color: rgba(59,130,246,0.35); }
.icon-btn:active { transform: scale(0.99); }
.icon-btn:focus-visible { outline: none; box-shadow: var(--ring); }

.icon-btn.primary {
  background: var(--accent);
  color: var(--accent-ink);
  border-color: rgba(59,130,246,0.55);
}

.icon-btn.primary:hover { background: var(--accent-2); }

/* ============================================================================
   Source panel (below composer)
   ============================================================================ */

.doc-card { margin-top: 2px; }
.doc-hidden { display: none; }

.doc-head {
  padding: 12px 14px;
  border-bottom: 1px solid var(--border-2);
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 10px;
}

.doc-head-left { display: grid; gap: 2px; }

.doc-title { font-weight: 800; letter-spacing: 0.2px; }
.doc-sub { font-size: 12px; color: var(--muted); }
.doc-error { color: var(--danger); }

.doc-body {
  padding: 14px;
  line-height: 1.55;
  white-space: normal;
}

.doc-body pre,
.doc-body code {
  font-family: var(--font-mono);
  background: rgba(15,23,42,0.06);
  border: 1px solid var(--border-2);
  border-radius: var(--r-sm);
  padding: 10px 12px;
  overflow: auto;
}

/* help text partial */
.help-text { white-space: pre-wrap; line-height: 1.55; }

/* ============================================================================
   Modal (Help)
   ============================================================================ */

.modal {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  z-index: 50;
}

.modal-hidden { display: none; }

.modal-scrim {
  position: absolute;
  inset: 0;
  background: rgba(0,0,0,0.45);
}

.modal-card {
  position: relative;
  width: min(640px, 92vw);
  max-height: 70vh;

  border: 1px solid var(--border-2);
  border-radius: var(--r-lg);
  background: var(--surface);
  box-shadow: var(--sh-3);
  overflow: hidden;

  display: grid;
  grid-template-rows: auto 1fr;
}

.modal-head {
  padding: 12px 14px;
  border-bottom: 1px solid var(--border-2);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.modal-title { font-weight: 800; }

.modal-body {
  padding: 14px;
  overflow: auto;
  white-space: pre-wrap; /* rag_chat_help.txt sorok */
  line-height: 1.55;
}

.muted { color: var(--muted); }

/* ============================================================================
   Responsive: stack sidebar on narrow screens
   ============================================================================ */

@media (max-width: 980px) {
  .shell {
    grid-template-columns: 1fr;
  }

  .sidebar {
    position: relative;
    top: 0;
    max-height: none;
  }

  .main {
    max-width: 100%;
    justify-self: stretch;
  }

  .chat-log { max-height: 56vh; }
}
