*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --primary: #6c3fcc;
  --primary-dark: #5a32b0;
  --primary-light: #ede9fe;
  --sidebar-bg: #111111;
  --sidebar-hover: #1e1e1e;
  --sidebar-active: #1e1e1e;
  --sidebar-text: #a1a1aa;
  --sidebar-text-active: #ffffff;
  --sidebar-border: #2a2a2a;
  --bg: #f9fafb;
  --surface: #ffffff;
  --border: #e5e7eb;
  --text: #111827;
  --text-muted: #6b7280;
  --success: #16a34a;
  --danger: #dc2626;
  --sidebar-w: 220px;
  --list-w: 320px;
}

body { font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif; background: var(--bg); color: var(--text); height: 100vh; overflow: hidden; font-size: 14px; }
.hidden { display: none !important; }

/* ══ LOGIN ══════════════════════════════════════════════════════════════════ */
#login-screen { display: flex; align-items: center; justify-content: center; min-height: 100vh; background: var(--bg); }
.login-wrap { width: 100%; max-width: 420px; padding: 1rem; }
.login-box { background: var(--surface); border-radius: 16px; padding: 2.5rem; box-shadow: 0 1px 3px rgba(0,0,0,.08), 0 8px 32px rgba(0,0,0,.06); }
.login-logo { height: 40px; margin-bottom: 1.5rem; display: block; }
.login-box h1 { font-size: 1.5rem; font-weight: 700; margin-bottom: .3rem; }
.login-sub { color: var(--text-muted); font-size: .875rem; margin-bottom: 1.5rem; }
.login-box label { display: block; font-size: .8rem; font-weight: 600; color: var(--text-muted); margin-bottom: .3rem; margin-top: 1rem; text-transform: uppercase; letter-spacing: .04em; }
.login-box input { width: 100%; padding: .6rem .85rem; border: 1.5px solid var(--border); border-radius: 8px; font-size: .95rem; outline: none; transition: border-color .15s; background: var(--bg); }
.login-box input:focus { border-color: var(--primary); background: #fff; }
.login-box button[type=submit] { width: 100%; margin-top: 1.5rem; padding: .7rem; background: var(--primary); color: #fff; border: none; border-radius: 8px; font-size: .95rem; font-weight: 600; cursor: pointer; transition: background .15s; }
.login-box button[type=submit]:hover { background: var(--primary-dark); }
.login-box button[type=submit]:disabled { opacity: .55; cursor: not-allowed; }
.login-error { margin-top: .75rem; padding: .6rem .9rem; background: #fef2f2; border: 1px solid #fecaca; color: var(--danger); border-radius: 8px; font-size: .85rem; }
.login-footer { margin-top: 1.5rem; text-align: center; font-size: .8rem; }
.login-footer a { color: var(--text-muted); text-decoration: none; }
.login-footer a:hover { color: var(--primary); }
.login-footer span { margin: 0 .4rem; color: var(--border); }

/* ══ DASHBOARD LAYOUT ═══════════════════════════════════════════════════════ */
#dashboard { display: flex; height: 100vh; overflow: hidden; }

/* ── Sidebar ── */
#sidebar {
  width: var(--sidebar-w);
  min-width: var(--sidebar-w);
  background: var(--sidebar-bg);
  display: flex;
  flex-direction: column;
  border-right: 1px solid var(--sidebar-border);
  overflow: hidden;
}
.sb-logo { padding: 1rem 1rem .75rem; border-bottom: 1px solid var(--sidebar-border); }
.sb-logo img { height: 28px; filter: brightness(0) invert(1); }
.sb-section { padding: .75rem 1rem .5rem; }
.sb-label { font-size: .65rem; font-weight: 700; text-transform: uppercase; letter-spacing: .08em; color: #52525b; padding: .5rem 1rem .25rem; }
.bot-selector select { width: 100%; background: #1e1e1e; border: 1px solid var(--sidebar-border); color: var(--sidebar-text-active); border-radius: 7px; padding: .45rem .6rem; font-size: .82rem; outline: none; cursor: pointer; }
.bot-selector select:focus { border-color: var(--primary); }
.sb-nav { flex: 1; overflow-y: auto; padding: .25rem 0; }
.nav-item { display: flex; align-items: center; gap: .55rem; padding: .5rem 1rem; color: var(--sidebar-text); text-decoration: none; border-radius: 6px; margin: .1rem .5rem; font-size: .85rem; transition: background .1s, color .1s; cursor: pointer; }
.nav-item svg { width: 16px; height: 16px; flex-shrink: 0; }
.nav-item:hover { background: var(--sidebar-hover); color: #d4d4d8; }
.nav-item.active { background: var(--sidebar-active); color: var(--sidebar-text-active); }
.sb-bottom { padding: .75rem 1rem; border-top: 1px solid var(--sidebar-border); display: flex; align-items: center; gap: .6rem; }
.sb-user { display: flex; align-items: center; gap: .6rem; flex: 1; min-width: 0; }
.sb-avatar { width: 28px; height: 28px; border-radius: 50%; background: var(--primary); color: #fff; font-size: .75rem; font-weight: 700; display: flex; align-items: center; justify-content: center; flex-shrink: 0; }
.sb-username { font-size: .82rem; color: #d4d4d8; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.sb-role { font-size: .7rem; color: #52525b; }
.sb-logout { background: none; border: none; color: #52525b; cursor: pointer; padding: .3rem; border-radius: 5px; display: flex; }
.sb-logout:hover { background: var(--sidebar-hover); color: #d4d4d8; }
.sb-logout svg { width: 16px; height: 16px; }
.sb-legal { padding: .5rem 1rem .75rem; border-top: 1px solid var(--sidebar-border); display: flex; gap: .5rem; align-items: center; }
.sb-legal a { font-size: .7rem; color: #52525b; text-decoration: none; }
.sb-legal a:hover { color: var(--sidebar-text); }
.sb-legal span { color: #333; font-size: .7rem; }

/* ── Conversation List (middle) ── */
#conv-panel { width: var(--list-w); min-width: var(--list-w); border-right: 1px solid var(--border); display: flex; flex-direction: column; background: var(--surface); overflow: hidden; }
.conv-panel-header { padding: 1rem 1rem .75rem; border-bottom: 1px solid var(--border); }
.conv-panel-header h2 { font-size: 1rem; font-weight: 700; }
.conv-filters { padding: .6rem .75rem; border-bottom: 1px solid var(--border); display: flex; flex-direction: column; gap: .4rem; }
.search-wrap { position: relative; }
.search-icon { position: absolute; left: .6rem; top: 50%; transform: translateY(-50%); width: 14px; height: 14px; color: var(--text-muted); }
#search-input { width: 100%; padding: .45rem .7rem .45rem 2rem; border: 1.5px solid var(--border); border-radius: 7px; font-size: .82rem; outline: none; background: var(--bg); }
#search-input:focus { border-color: var(--primary); background: #fff; }
.date-filters { display: flex; align-items: center; gap: .35rem; }
.date-filters input[type=date] { flex: 1; padding: .35rem .4rem; border: 1.5px solid var(--border); border-radius: 6px; font-size: .75rem; outline: none; }
.date-filters input[type=date]:focus { border-color: var(--primary); }
.date-filters span { color: var(--text-muted); font-size: .75rem; }
.btn-filter { padding: .35rem .65rem; background: var(--primary); color: #fff; border: none; border-radius: 6px; font-size: .75rem; font-weight: 600; cursor: pointer; white-space: nowrap; }
.btn-filter:hover { background: var(--primary-dark); }
#conv-list { flex: 1; overflow-y: auto; }
.conv-item { padding: .85rem 1rem; border-bottom: 1px solid var(--border); cursor: pointer; transition: background .1s; }
.conv-item:hover { background: var(--bg); }
.conv-item.active { background: var(--primary-light); border-left: 3px solid var(--primary); }
.conv-item-top { display: flex; justify-content: space-between; align-items: flex-start; gap: .5rem; margin-bottom: .3rem; }
.conv-time { font-size: .72rem; color: var(--text-muted); white-space: nowrap; flex-shrink: 0; }
.conv-preview { font-size: .83rem; color: var(--text); line-height: 1.4; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.conv-badges { display: flex; gap: .3rem; margin-top: .35rem; }
.badge { padding: .1rem .45rem; border-radius: 20px; font-size: .68rem; font-weight: 600; }
.badge-source { background: #f3f4f6; color: var(--text-muted); }
.badge-up { background: #dcfce7; color: #15803d; }
.badge-down { background: #fee2e2; color: #b91c1c; }
.conv-pagination { padding: .6rem 1rem; border-top: 1px solid var(--border); display: flex; align-items: center; gap: .75rem; justify-content: center; }
.conv-pagination button { width: 28px; height: 28px; border: 1.5px solid var(--border); background: var(--surface); border-radius: 6px; cursor: pointer; font-size: .9rem; display: flex; align-items: center; justify-content: center; }
.conv-pagination button:disabled { opacity: .4; cursor: not-allowed; }
#page-info { font-size: .78rem; color: var(--text-muted); }
.conv-loading { padding: 2rem 1rem; text-align: center; color: var(--text-muted); font-size: .85rem; }

/* ── Detail Panel (right) ── */
#detail-panel { flex: 1; display: flex; flex-direction: column; overflow: hidden; background: var(--bg); }
.detail-empty { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 1rem; color: var(--text-muted); }
.detail-empty svg { width: 64px; height: 64px; }
.detail-empty p { font-size: .9rem; }
#detail-content { flex: 1; display: flex; flex-direction: column; overflow: hidden; }
.detail-header { padding: 1rem 1.25rem .75rem; border-bottom: 1px solid var(--border); background: var(--surface); display: flex; justify-content: space-between; align-items: flex-start; gap: 1rem; }
.detail-title { font-size: .95rem; font-weight: 700; }
.detail-meta { font-size: .75rem; color: var(--text-muted); margin-top: .2rem; }
.detail-tabs { display: flex; gap: .25rem; flex-shrink: 0; }
.tab-btn { padding: .3rem .75rem; border: 1.5px solid var(--border); background: none; border-radius: 6px; font-size: .8rem; cursor: pointer; color: var(--text-muted); transition: all .15s; }
.tab-btn.active { background: var(--primary); color: #fff; border-color: var(--primary); }
.tab-content { flex: 1; overflow-y: auto; }
#messages-container { padding: 1rem 1.25rem; display: flex; flex-direction: column; gap: .75rem; }
.msg { max-width: 78%; }
.msg.user { align-self: flex-end; }
.msg.assistant { align-self: flex-start; }
.msg-bubble { padding: .7rem 1rem; border-radius: 12px; font-size: .875rem; line-height: 1.55; }
.msg.user .msg-bubble { background: var(--primary); color: #fff; border-bottom-right-radius: 3px; }
.msg.assistant .msg-bubble { background: var(--surface); border: 1px solid var(--border); color: var(--text); border-bottom-left-radius: 3px; position: relative; }
.msg-role { font-size: .68rem; font-weight: 700; color: var(--text-muted); margin-bottom: .25rem; text-transform: uppercase; letter-spacing: .04em; }
.msg.user .msg-role { text-align: right; }
.revise-btn { display: none; align-items: center; gap: .3rem; margin-top: .4rem; padding: .25rem .6rem; font-size: .75rem; color: var(--text-muted); background: var(--bg); border: 1px solid var(--border); border-radius: 5px; cursor: pointer; transition: all .15s; }
.revise-btn svg { width: 12px; height: 12px; }
.msg.assistant:hover .revise-btn { display: inline-flex; }
.revise-btn:hover { background: var(--primary-light); color: var(--primary); border-color: var(--primary); }
.details-grid { padding: 1.25rem; display: flex; flex-direction: column; gap: .75rem; }
.detail-row { display: flex; gap: .75rem; padding: .6rem .75rem; background: var(--surface); border: 1px solid var(--border); border-radius: 8px; }
.detail-row-key { font-size: .78rem; font-weight: 600; color: var(--text-muted); min-width: 120px; }
.detail-row-val { font-size: .82rem; color: var(--text); word-break: break-all; }

/* ── Feedback Bar ── */
.feedback-bar { border-top: 1px solid var(--border); background: var(--surface); padding: .85rem 1.25rem; display: flex; flex-direction: column; gap: .6rem; }
.feedback-rating { display: flex; align-items: center; gap: .6rem; }
.feedback-label { font-size: .78rem; font-weight: 600; color: var(--text-muted); }
.thumb-btn { font-size: 1.1rem; padding: .2rem .5rem; border: 1.5px solid var(--border); border-radius: 7px; background: none; cursor: pointer; transition: all .15s; line-height: 1; }
.thumb-btn.active-up { border-color: #16a34a; background: #dcfce7; }
.thumb-btn.active-down { border-color: var(--danger); background: #fee2e2; }
#rating-label { font-size: .78rem; color: var(--text-muted); }
#feedback-note { width: 100%; padding: .5rem .75rem; border: 1.5px solid var(--border); border-radius: 8px; font-family: inherit; font-size: .85rem; resize: vertical; outline: none; }
#feedback-note:focus { border-color: var(--primary); }
.feedback-actions { display: flex; align-items: center; gap: .75rem; }
.btn-save { padding: .4rem .9rem; background: var(--primary); color: #fff; border: none; border-radius: 7px; font-size: .82rem; font-weight: 600; cursor: pointer; }
.btn-save:hover { background: var(--primary-dark); }
#feedback-status, #improve-status { font-size: .78rem; }
.improve-section { background: #fefce8; border: 1px solid #fde68a; border-radius: 9px; padding: .75rem; display: flex; flex-direction: column; gap: .5rem; }
.improve-header { display: flex; align-items: center; gap: .4rem; font-size: .8rem; font-weight: 700; color: #92400e; }
.improve-header svg { width: 14px; height: 14px; }
.improve-context { font-weight: 400; color: #b45309; font-size: .76rem; }
#improve-text { width: 100%; padding: .5rem .75rem; border: 1.5px solid #fde68a; border-radius: 7px; font-family: inherit; font-size: .85rem; resize: vertical; outline: none; background: #fff; }
#improve-text:focus { border-color: #f59e0b; }

/* ══ FULL PANELS (Analytics, Flagged) ═══════════════════════════════════════ */
.full-panel { position: absolute; top: 0; left: var(--sidebar-w); right: 0; bottom: 0; background: var(--bg); overflow-y: auto; padding: 2rem; z-index: 10; }
.full-panel-header { margin-bottom: 1.5rem; }
.full-panel-header h2 { font-size: 1.25rem; font-weight: 700; }
.stats-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 1rem; margin-bottom: 2rem; }
.stat-card { background: var(--surface); border: 1px solid var(--border); border-radius: 12px; padding: 1.25rem; }
.stat-icon { font-size: 1.5rem; margin-bottom: .5rem; }
.stat-val { font-size: 2rem; font-weight: 800; color: var(--primary); line-height: 1; margin-bottom: .3rem; }
.stat-label { font-size: .8rem; color: var(--text-muted); }
.chart-section { background: var(--surface); border: 1px solid var(--border); border-radius: 12px; padding: 1.25rem; margin-bottom: 1.5rem; }
.chart-section h3 { font-size: .9rem; font-weight: 600; color: var(--text-muted); margin-bottom: 1rem; }
.chart-wrap { display: flex; align-items: flex-end; gap: 6px; height: 100px; }
.chart-bar-g { flex: 1; display: flex; flex-direction: column; align-items: center; height: 100%; justify-content: flex-end; }
.chart-bar { width: 100%; background: var(--primary); border-radius: 4px 4px 0 0; min-height: 3px; opacity: .85; }
.chart-day { font-size: .65rem; color: var(--text-muted); margin-top: 4px; }
.btn-primary { padding: .6rem 1.25rem; background: var(--primary); color: #fff; border: none; border-radius: 8px; font-size: .9rem; font-weight: 600; cursor: pointer; }
.btn-primary:hover { background: var(--primary-dark); }

/* Flagged list */
.flagged-card { background: var(--surface); border: 1px solid var(--border); border-radius: 10px; padding: 1rem 1.25rem; margin-bottom: .65rem; }
.flagged-card-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: .4rem; }
.flagged-id { font-size: .75rem; color: var(--text-muted); font-family: monospace; }
.flagged-meta { font-size: .78rem; color: var(--text-muted); }
.flagged-note { font-size: .85rem; color: var(--text); margin-top: .4rem; padding: .4rem .6rem; background: var(--bg); border-radius: 6px; }

/* Empty states */
.empty-state { padding: 3rem 1rem; text-align: center; color: var(--text-muted); font-size: .88rem; }
