/* ─── Variables ──────────────────────────────────────────────────────────── */
:root {
  --bg:       #0f1117;
  --surface:  #1a1d27;
  --surface2: #22263a;
  --border:   #2d3154;
  --accent:   #5b6af0;
  --accent2:  #38bdf8;
  --text:     #e2e8f0;
  --text-dim: #94a3b8;
  --positive: #34d399;
  --negative: #f87171;
  --warning:  #fbbf24;
  --radius:   10px;
  --sidebar-w: 220px;
}

/* ─── Reset ──────────────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; font-family: 'Segoe UI', system-ui, sans-serif;
             background: var(--bg); color: var(--text); font-size: 14px; }
a { color: inherit; text-decoration: none; }

/* ─── Layout ─────────────────────────────────────────────────────────────── */
body { display: flex; }

.sidebar {
  width: var(--sidebar-w);
  min-height: 100vh;
  background: var(--surface);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
  position: sticky;
  top: 0;
  height: 100vh;
  overflow-y: auto;
}

.sidebar-header { padding: 20px 16px 16px; border-bottom: 1px solid var(--border); }
.logo { font-size: 16px; font-weight: 700; letter-spacing: -.3px; }

.sidebar-nav { display: flex; flex-direction: column; padding: 10px 0; flex: 1; }
.nav-item {
  display: block; padding: 10px 16px; border-radius: 6px; margin: 2px 8px;
  color: var(--text-dim); font-size: 13px; transition: all .15s;
}
.nav-item:hover { background: var(--surface2); color: var(--text); }
.nav-item.active { background: var(--accent); color: #fff; }

.sidebar-footer { padding: 16px; border-top: 1px solid var(--border); }

.btn-ingest {
  width: 100%; padding: 8px 12px; border-radius: 6px; border: none;
  background: var(--accent); color: #fff; cursor: pointer; font-size: 12px;
  transition: opacity .15s;
}
.btn-ingest:hover { opacity: .85; }
.ingest-status { display: block; margin-top: 6px; font-size: 11px; color: var(--text-dim); }
.btn-small {
  padding: 4px 10px; border-radius: 4px; border: 1px solid var(--accent);
  background: transparent; color: var(--accent); cursor: pointer; font-size: 12px;
  transition: background .15s, color .15s;
}
.btn-small:hover { background: var(--accent); color: #fff; }

.main {
  flex: 1;
  overflow-y: auto;
  padding: 28px 32px;
  max-width: calc(100vw - var(--sidebar-w));
}

/* ─── Filter bar ─────────────────────────────────────────────────────────── */
.filter-bar {
  display: flex; gap: 16px; align-items: flex-end; margin-bottom: 24px;
  flex-wrap: wrap;
}
.filter-bar label { display: flex; flex-direction: column; gap: 4px;
                    font-size: 12px; color: var(--text-dim); }
.filter-bar select, .filter-bar input {
  background: var(--surface2); border: 1px solid var(--border);
  color: var(--text); border-radius: 6px; padding: 6px 10px; font-size: 13px;
}
.btn-refresh {
  padding: 8px 14px; border-radius: 6px; border: 1px solid var(--border);
  background: var(--surface2); color: var(--text); cursor: pointer; font-size: 13px;
}
.btn-refresh:hover { border-color: var(--accent); color: var(--accent); }

/* ─── Views ──────────────────────────────────────────────────────────────── */
.view { display: none; }
.view.active { display: block; }
.view h1 { font-size: 22px; font-weight: 700; margin-bottom: 6px; }
.subtitle { color: var(--text-dim); margin-bottom: 20px; font-size: 13px; }

/* ─── KPI cards ──────────────────────────────────────────────────────────── */
.kpi-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
            gap: 14px; margin-bottom: 28px; }
.kpi-card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 18px 16px; text-align: center;
}
.kpi-val { font-size: 28px; font-weight: 700; color: var(--accent2); }
.kpi-lbl { font-size: 12px; color: var(--text-dim); margin-top: 4px; }

/* ─── Charts ─────────────────────────────────────────────────────────────── */
.charts-grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 18px; margin-bottom: 24px; }
@media (max-width: 900px) { .charts-grid-2 { grid-template-columns: 1fr; } }

.chart-card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 20px; overflow: hidden;
}
.chart-card h3 { font-size: 14px; color: var(--text-dim); margin-bottom: 14px; }
.chart-card.full-width { margin-bottom: 24px; }
.chart-card canvas { max-height: 320px; }

/* ─── Data tables ────────────────────────────────────────────────────────── */
.data-table-wrap { overflow-x: auto; margin-top: 8px; }
table { width: 100%; border-collapse: collapse; font-size: 13px; }
th { background: var(--surface2); color: var(--text-dim); text-align: left;
     padding: 10px 12px; font-weight: 600; white-space: nowrap; }
td { padding: 9px 12px; border-bottom: 1px solid var(--border); vertical-align: top; }
tr:hover td { background: var(--surface2); }
.badge {
  display: inline-block; padding: 2px 8px; border-radius: 20px; font-size: 11px;
  font-weight: 600; white-space: nowrap;
}
.badge-bug      { background: #7f1d1d; color: #fca5a5; }
.badge-feature  { background: #1e3a5f; color: #7dd3fc; }
.badge-complaint{ background: #451a03; color: #fdba74; }
.badge-question { background: #1e2a3a; color: #93c5fd; }
.badge-praise   { background: #064e3b; color: #6ee7b7; }
.badge-other    { background: #1e2030; color: #94a3b8; }
.badge-positive { background: #064e3b; color: #6ee7b7; }
.badge-neutral  { background: #1e2030; color: #94a3b8; }
.badge-negative { background: #7f1d1d; color: #fca5a5; }

/* ─── AI Assistant ───────────────────────────────────────────────────────── */
.assistant-container { display: flex; flex-direction: column; gap: 16px; }
.chat-controls { display: flex; gap: 16px; flex-wrap: wrap; align-items: flex-end; }
.chat-controls label { display: flex; flex-direction: column; gap: 4px;
                       font-size: 12px; color: var(--text-dim); }
.chat-controls select {
  background: var(--surface2); border: 1px solid var(--border); color: var(--text);
  border-radius: 6px; padding: 6px 10px; font-size: 13px;
}
.toggle-label { flex-direction: row !important; align-items: center; gap: 8px !important; }
.toggle-label input { width: 16px; height: 16px; accent-color: var(--accent); }

.chat-window {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  min-height: 300px; max-height: 480px; overflow-y: auto; padding: 16px;
  display: flex; flex-direction: column; gap: 14px;
}

.msg { display: flex; flex-direction: column; gap: 4px; }
.msg-user .bubble {
  background: var(--accent); color: #fff; align-self: flex-end;
  border-radius: 12px 12px 2px 12px; padding: 10px 14px; max-width: 70%;
  font-size: 13px;
}
.msg-assistant .bubble {
  background: var(--surface2); border: 1px solid var(--border);
  border-radius: 2px 12px 12px 12px; padding: 12px 16px; max-width: 85%;
  font-size: 13px; line-height: 1.6; white-space: pre-wrap;
}
.msg-assistant .citations { margin-top: 8px; font-size: 11px; color: var(--text-dim); }
.msg-assistant .citations a { color: var(--accent2); margin-right: 8px; }

.chat-input-row { display: flex; gap: 10px; }
.chat-input-row textarea, .chat-input-row input {
  flex: 1; background: var(--surface2); border: 1px solid var(--border); color: var(--text);
  border-radius: 8px; padding: 10px 14px; font-size: 13px; resize: vertical;
  font-family: inherit;
}
.chat-input-row textarea:focus, .chat-input-row input:focus {
  outline: none; border-color: var(--accent);
}
.btn-ask {
  padding: 10px 20px; background: var(--accent); color: #fff; border: none;
  border-radius: 8px; cursor: pointer; font-size: 13px; font-weight: 600;
  white-space: nowrap; transition: opacity .15s;
}
.btn-ask:hover { opacity: .85; }
.btn-ask:disabled { opacity: .45; cursor: not-allowed; }

.search-section { margin-top: 8px; }
.search-section h3 { margin-bottom: 12px; font-size: 15px; }
.search-results { display: flex; flex-direction: column; gap: 8px; margin-top: 12px; }
.search-result-card {
  background: var(--surface); border: 1px solid var(--border); border-radius: 8px;
  padding: 12px 16px; font-size: 13px;
}
.search-result-card .result-header {
  display: flex; justify-content: space-between; margin-bottom: 4px;
}
.confidence-bar {
  height: 4px; border-radius: 2px; background: var(--surface2);
  margin-top: 6px; overflow: hidden;
}
.confidence-bar-fill { height: 100%; background: var(--accent); border-radius: 2px; }

/* ─── Loader ─────────────────────────────────────────────────────────────── */
.loader { display: inline-block; width: 16px; height: 16px; border: 2px solid var(--border);
          border-top-color: var(--accent); border-radius: 50%; animation: spin .7s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ─── Scrollbar ──────────────────────────────────────────────────────────── */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }

/* ═══════════════════════════════════════════════════════════════════════════
   AI ASSISTANT — Full-screen ChatGPT-style layout
   ═══════════════════════════════════════════════════════════════════════════ */

/* When the assistant view is active, hide the sidebar and reset main */
body.assistant-mode { overflow: hidden; }
body.assistant-mode .sidebar  { display: none !important; }
body.assistant-mode .main {
  max-width: 100vw !important;
  width: 100vw;
  padding: 0;
  overflow: hidden;
}
body.assistant-mode .filter-bar { display: none; }
body.assistant-mode #view-assistant.active {
  display: flex !important;
  width: 100%;
  height: 100vh;
}

/* ── Root layout ─────────────────────────────────────────────────────────── */
.asst-layout {
  display: flex;
  flex-direction: column;  width: 100%;  height: 100vh;
  overflow: hidden;
  background: var(--bg);
}

/* ── Header bar ──────────────────────────────────────────────────────────── */
.asst-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 24px;
  height: 56px;
  flex-shrink: 0;
  background: rgba(15, 17, 23, 0.92);
  backdrop-filter: blur(16px);
  border-bottom: 1px solid var(--border);
  z-index: 10;
}
.asst-header-left  { display: flex; align-items: center; gap: 12px; }
.asst-header-right { display: flex; align-items: center; gap: 10px; }
.asst-logo { font-size: 15px; font-weight: 700; letter-spacing: -.3px; }

.asst-back-btn {
  background: var(--surface2);
  border: 1px solid var(--border);
  color: var(--text-dim);
  border-radius: 7px;
  padding: 5px 13px;
  font-size: 12px;
  cursor: pointer;
  transition: all .15s;
  font-family: inherit;
}
.asst-back-btn:hover { color: var(--text); border-color: var(--accent); }

.asst-user-badge { font-size: 12px; color: var(--text-dim); }
.asst-countdown  { font-size: 11px; color: #475569; min-width: 44px; }

.asst-logout-btn {
  background: transparent;
  border: 1px solid #f87171;
  border-radius: 7px;
  color: #f87171;
  padding: 5px 13px;
  font-size: 11px;
  cursor: pointer;
  transition: background .15s;
  font-family: inherit;
}
.asst-logout-btn:hover { background: rgba(248,113,113,.12); }

/* ── Scrollable body ─────────────────────────────────────────────────────── */
.asst-body {
  flex: 1;
  overflow-y: auto;
  display: flex;
  flex-direction: column;  align-items: center;
  width: 100%;}

/* ── Welcome hero ────────────────────────────────────────────────────────── */
.asst-welcome {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 48px 24px 32px;
  position: relative;
  animation: asstFadeUp .55s ease both;  width: 100%;
  max-width: 90vw;}
.asst-welcome.hidden { display: none; }

/* Ambient glow blob */
.asst-welcome-glow {
  position: absolute;
  width: 520px;
  height: 520px;
  border-radius: 50%;
  background: radial-gradient(circle, rgba(91,106,240,.13) 0%, transparent 70%);
  pointer-events: none;
  animation: asstPulseGlow 5s ease-in-out infinite;
}
@keyframes asstPulseGlow {
  0%, 100% { transform: scale(1);    opacity: .7; }
  50%       { transform: scale(1.08); opacity: 1;  }
}

.asst-welcome-icon {
  font-size: 52px;
  margin-bottom: 18px;
  position: relative;
  animation: asstFloat 3.5s ease-in-out infinite;
}
@keyframes asstFloat {
  0%, 100% { transform: translateY(0);  }
  50%       { transform: translateY(-9px); }
}

.asst-welcome-title {
  font-size: 34px;
  font-weight: 700;
  background: linear-gradient(135deg, #e2e8f0 0%, #7c8ef7 45%, #38bdf8 100%);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  margin-bottom: 12px;
  position: relative;
}
.asst-welcome-sub {
  color: var(--text-dim);
  font-size: 15px;
  line-height: 1.65;
  margin-bottom: 36px;
  max-width: 460px;
  position: relative;
}

/* Suggestion chips — removed */

/* ── Chat messages ───────────────────────────────────────────────────────── */
.asst-messages {
  padding: 24px 40px 8px;
  display: flex;
  flex-direction: column;
  gap: 16px;
  width: 90vw;
  max-width: 90vw;
  width: 100%;
  align-self: center;
}

/* Animate every new message */
@keyframes asstFadeUp {
  from { opacity: 0; transform: translateY(14px); }
  to   { opacity: 1; transform: translateY(0);    }
}
.msg { animation: asstFadeUp .28s ease both; }

/* Override bubble widths for full-screen layout */
body.assistant-mode .msg-user .bubble { max-width: 65%; }
body.assistant-mode .msg-assistant .bubble {
  max-width: 100%;
  font-size: 14px;
  line-height: 1.7;
}

/* Typing indicator */
.typing-dots { display: flex; gap: 5px; align-items: center; padding: 6px 2px; }
.typing-dots span {
  width: 7px; height: 7px;
  border-radius: 50%;
  background: var(--text-dim);
  animation: typingBounce 1.3s ease-in-out infinite;
}
.typing-dots span:nth-child(2) { animation-delay: .18s; }
.typing-dots span:nth-child(3) { animation-delay: .36s; }
@keyframes typingBounce {
  0%, 60%, 100% { transform: translateY(0);   opacity: .45; }
  30%            { transform: translateY(-5px); opacity: 1;   }
}

/* ── Input zone ──────────────────────────────────────────────────────────── */
.asst-input-zone-wrap {
  flex-shrink: 0;
  padding: 0 24px 22px;
  background: linear-gradient(to top, var(--bg) 78%, transparent);  width: 100%;
  display: flex;
  justify-content: center;}
.asst-input-zone {
  width: 90vw;
  max-width: 90vw;
  margin: 0 auto;
}

.asst-filters-row {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 10px;
  flex-wrap: wrap;
}
.asst-select {
  background: var(--surface2);
  border: 1px solid var(--border);
  color: var(--text-dim);
  border-radius: 7px;
  padding: 5px 10px;
  font-size: 12px;
  cursor: pointer;
  font-family: inherit;
}
.asst-check-label {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  color: var(--text-dim);
  cursor: pointer;
}
.asst-check-label input { accent-color: var(--accent); }
/* Main input bar */
.asst-input-bar {
  display: flex;
  align-items: flex-end;
  gap: 10px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 12px 12px 12px 20px;
  transition: border-color .2s, box-shadow .2s;
}
.asst-input-bar:focus-within {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(91,106,240,.14);
}
.asst-textarea {
  flex: 1;
  background: transparent;
  border: none;
  outline: none;
  color: var(--text);
  font-size: 15px;
  font-family: inherit;
  resize: none;
  max-height: 200px;
  line-height: 1.55;
  overflow-y: auto;
}
.asst-textarea::placeholder { color: #475569; }

.asst-send-btn {
  width: 38px;
  height: 38px;
  border-radius: 10px;
  background: var(--accent);
  border: none;
  color: #fff;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: opacity .15s, transform .1s;
}
.asst-send-btn:hover  { opacity: .85; }
.asst-send-btn:active { transform: scale(.93); }
.asst-send-btn:disabled { opacity: .35; cursor: not-allowed; }

/* ── Rendered markdown inside assistant bubble ───────────────────────────── */
.rendered-md { white-space: normal; }
.rendered-md p { margin: 0 0 10px; line-height: 1.7; }
.rendered-md p:last-child { margin-bottom: 0; }
.rendered-md h2 { font-size: 16px; font-weight: 700; margin: 14px 0 6px; }
.rendered-md h3 { font-size: 15px; font-weight: 700; margin: 12px 0 5px; }
.rendered-md h4 { font-size: 14px; font-weight: 700; margin: 10px 0 4px; }
.rendered-md ul, .rendered-md ol {
  margin: 6px 0 10px 20px;
  display: flex; flex-direction: column; gap: 4px;
}
.rendered-md li  { line-height: 1.6; }
.rendered-md strong { font-weight: 700; color: var(--text); }
.rendered-md em { font-style: italic; color: #c4cde8; }
.rendered-md code {
  background: #1a1d2e; border: 1px solid var(--border);
  border-radius: 4px; padding: 1px 5px; font-size: 12px;
}
.rendered-md a { color: var(--accent2); text-decoration: underline; }
.rendered-md a:hover { opacity: .8; }

/* ── Message action bar (Copy / Translate) ───────────────────────────────── */
.msg-actions {
  display: flex;
  gap: 8px;
  margin-top: 10px;
  flex-wrap: wrap;
}
.msg-action-btn {
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 7px;
  color: var(--text-dim);
  padding: 5px 12px;
  font-size: 12px;
  cursor: pointer;
  transition: all .15s;
  font-family: inherit;
}
.msg-action-btn:hover  { border-color: var(--accent); color: var(--text); }
.msg-action-btn:disabled { opacity: .4; cursor: not-allowed; }
.translate-btn { border-color: #3b4d6e; }
.translate-btn:hover { border-color: var(--accent2); color: var(--accent2); }

/* Separator between copy/translate and feedback buttons */
.msg-actions-sep {
  display: inline-block;
  width: 1px;
  height: 18px;
  background: var(--border);
  margin: 0 4px;
  align-self: center;
}

/* Thumbs up / down */
.rating-btn { font-size: 15px; padding: 3px 9px; }
.rating-active-up   { background: #0f2a1a !important; border-color: #4ade80 !important; color: #4ade80 !important; }
.rating-active-down { background: #2a0f0f !important; border-color: #f87171 !important; color: #f87171 !important; }

/* Edit button */
.edit-btn { border-color: #3a3a5a; }
.save-edit-btn { border-color: var(--accent); color: var(--accent); background: #1a1f3a; }
.save-edit-btn:hover { background: var(--accent); color: #fff; }

/* Inline edit textarea */
.feedback-edit-area {
  width: 100%;
  box-sizing: border-box;
  background: #141828;
  border: 1px solid var(--accent);
  border-radius: 8px;
  color: var(--text);
  font-family: inherit;
  font-size: 14px;
  line-height: 1.65;
  padding: 10px 14px;
  resize: vertical;
  margin-bottom: 10px;
  outline: none;
}
.feedback-edit-area:focus { box-shadow: 0 0 0 2px rgba(91,106,240,.2); }

/* ── Audit log table ─────────────────────────────────────────────────────── */
.audit-table { width: 100%; border-collapse: collapse; font-size: 13px; }
.audit-table th {
  text-align: left; padding: 8px 12px;
  background: var(--surface2); color: var(--text-dim);
  font-weight: 600; font-size: 11px; text-transform: uppercase;
  letter-spacing: .04em; border-bottom: 1px solid var(--border);
}
.audit-table td { padding: 9px 12px; border-bottom: 1px solid #1c1f2e; vertical-align: top; }
.audit-expandable { cursor: pointer; }
.audit-expandable:hover td { background: #141828; }
.audit-row-open td { background: #141828; }
.audit-expand-hint { font-size: 11px; color: var(--accent2); margin-left: 4px; }
.audit-detail-box {
  background: #0f1120; border-radius: 8px; padding: 14px 18px;
  display: flex; flex-direction: column; gap: 8px; font-size: 13px;
  border: 1px solid #2a2f4a;
}
.audit-response {
  background: #1a1d2e; border-radius: 6px; padding: 10px 14px;
  font-family: inherit; font-size: 12px; white-space: pre-wrap;
  word-break: break-word; margin: 0; max-height: 300px; overflow-y: auto;
  border: 1px solid var(--border); color: #c4cde8;
}
.badge-positive { background: #0f2a1a; color: #4ade80; border: 1px solid #166534; }
.badge-negative { background: #2a0f0f; color: #f87171; border: 1px solid #7f1d1d; }

