:root {
  /* Paystep brand palette (paystep.in): orange #EB5212 accent, dark grey
     #242424 text, #707070 muted, #F5F5F5/#FFFFFF surfaces. */
  --bg: #ffffff;
  --bg-elevated: #f5f5f5;
  --bg-card: #ffffff;
  --border: #e2e2e2;
  --border-soft: #ececec;
  --text: #242424;
  --text-muted: #707070;
  --text-faint: #9a9a9a;
  --accent: #eb5212;
  --accent-soft: rgba(235, 82, 18, 0.1);
  --accent-strong: #c2440d;
  --accent-line: rgba(235, 82, 18, 0.35);
  --radius: 10px;

  --status-applicable: #34c77b;
  --status-partial: #35b7c9;
  --status-conditional: #e0a638;
  --status-notapplicable: #6b7684;
  --status-reference: #8a7dff;
  --status-gap: #e5566b;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  font-size: 14px;
}

#app {
  display: grid;
  grid-template-columns: 280px 1fr;
  height: 100vh;
}

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

#sidebar {
  background: var(--bg-elevated);
  border-right: 1px solid var(--border-soft);
  display: flex;
  flex-direction: column;
  padding: 18px 16px;
  overflow-y: auto;
}

.brand {
  display: flex;
  flex-direction: column;
  gap: 2px;
  margin-bottom: 22px;
}

.brand-logo {
  height: 26px;
  width: auto;
  margin-bottom: 6px;
}

.brand .name {
  font-weight: 650;
  font-size: 15px;
  letter-spacing: 0.2px;
}

.brand .tag {
  font-size: 11.5px;
  color: var(--text-muted);
}

.section-label {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-faint);
  margin: 18px 0 8px;
}

.section-toggle {
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: 100%;
  background: transparent;
  border: none;
  padding: 0;
  margin: 18px 0 8px;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-faint);
  cursor: pointer;
}
.section-toggle:hover { color: var(--text-muted); }
.section-toggle .chevron {
  font-size: 10px;
  transition: transform 0.15s ease;
}
.section-toggle[aria-expanded="false"] .chevron { transform: rotate(-90deg); }

.team-list.collapsed { display: none; }

.team-list {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 5px;
}

.team-btn {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 1px;
  width: 100%;
  min-width: 0;
  text-align: left;
  background: transparent;
  border: 1px solid transparent;
  color: var(--text);
  padding: 7px 8px;
  border-radius: 8px;
  cursor: pointer;
  font-size: 12.5px;
}

.team-btn:hover { background: var(--bg-card); }

.team-btn.active {
  background: var(--accent-soft);
  border-color: var(--accent-line);
}

.team-btn span:first-child {
  overflow-wrap: break-word;
}

.team-btn .desc {
  font-size: 10px;
  line-height: 1.3;
  color: var(--text-muted);
  overflow-wrap: break-word;
}

select, .ghost-btn {
  width: 100%;
  background: var(--bg-card);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 8px;
  padding: 8px 10px;
  font-size: 13px;
}

.ghost-btn {
  cursor: pointer;
  text-align: left;
  margin-top: 6px;
}

.ghost-btn:hover { border-color: var(--accent); }


.conv-list {
  max-height: 180px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.conv-empty {
  font-size: 11px;
  color: var(--text-faint);
  padding: 4px 2px;
}

.conv-item-row {
  display: flex;
  align-items: center;
  gap: 2px;
}

.conv-item {
  display: block;
  flex: 1;
  min-width: 0;
  text-align: left;
  background: transparent;
  border: 1px solid transparent;
  border-radius: 7px;
  padding: 6px 8px;
  color: var(--text);
  font-size: 12px;
  cursor: pointer;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.conv-item:hover { background: var(--bg-card); }
.conv-item.active { background: var(--accent-soft); border-color: var(--accent-line); }

.conv-delete-btn {
  flex-shrink: 0;
  background: transparent;
  border: none;
  color: var(--text-faint);
  border-radius: 6px;
  width: 20px;
  height: 20px;
  font-size: 11px;
  line-height: 1;
  cursor: pointer;
}
.conv-delete-btn:hover { background: var(--status-gap); color: #fff; }

.sidebar-footer {
  margin-top: auto;
  padding-top: 16px;
  border-top: 1px solid var(--border-soft);
}

#corpus-stats {
  font-size: 11.5px;
  color: var(--text-faint);
  line-height: 1.6;
}

#account-bar {
  padding-top: 12px;
  border-top: 1px solid var(--border-soft);
  display: flex;
  flex-direction: column;
  gap: 6px;
}

#account-email {
  font-size: 11.5px;
  color: var(--text-muted);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.account-links {
  display: flex;
  gap: 12px;
}
.account-links .sidebar-link { margin-top: 0; }

/* ---------- Main ---------- */

#main {
  display: flex;
  flex-direction: column;
  min-width: 0;
}

#chat-header {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  padding: 14px 28px 0;
}

.chat-header-actions {
  display: flex;
  gap: 8px;
}

#chat-header .ghost-btn {
  width: auto;
  margin-top: 0;
}

#lang-btn {
  min-width: 44px;
  text-align: center;
  font-weight: 600;
}

#chat-scroll {
  flex: 1;
  overflow-y: auto;
  padding: 28px 0 12px;
}

#chat-log {
  max-width: 860px;
  margin: 0 auto;
  padding: 0 28px;
  display: flex;
  flex-direction: column;
  gap: 18px;
}

.empty-state {
  color: var(--text-muted);
  border: 1px dashed var(--border);
  border-radius: var(--radius);
  padding: 28px;
  text-align: center;
  font-size: 13px;
}

.msg {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.msg-role {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-faint);
}

.msg.user .bubble {
  background: var(--accent-soft);
  border: 1px solid rgba(235, 82, 18, 0.3);
  align-self: flex-end;
  border-radius: var(--radius);
}

.msg.assistant .bubble {
  background: var(--bg-card);
  border: 1px solid var(--border-soft);
  border-radius: var(--radius);
}

.bubble {
  padding: 12px 14px;
  line-height: 1.55;
  white-space: normal;
  word-wrap: break-word;
}

/* ---- shared Markdown rendering (chat bubbles + citation drawer) ---- */

.bubble p, .md-body p { margin: 0 0 8px; }
.bubble p:last-child, .md-body p:last-child { margin-bottom: 0; }

.bubble ul, .bubble ol, .md-body ul, .md-body ol {
  margin: 2px 0 8px;
  padding-left: 20px;
}
.bubble li, .md-body li { margin: 2px 0; }

.bubble strong, .md-body strong { font-weight: 650; }
.bubble em, .md-body em { font-style: italic; }

.bubble code, .md-body code {
  background: var(--bg-elevated);
  border: 1px solid var(--border-soft);
  border-radius: 4px;
  padding: 1px 5px;
  font-size: 0.92em;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}

.bubble .md-h, .md-body .md-h {
  font-weight: 650;
  margin: 10px 0 4px;
}
.bubble .md-h:first-child, .md-body .md-h:first-child { margin-top: 0; }
.md-h1, .md-h2 { font-size: 14.5px; }
.md-h3, .md-h4 { font-size: 13.5px; }
.md-h5, .md-h6 {
  font-size: 12px;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.md-table-wrap {
  overflow-x: auto;
  margin: 4px 0 10px;
  border: 1px solid var(--border-soft);
  border-radius: 8px;
}
.bubble table, .md-body table {
  border-collapse: collapse;
  width: 100%;
  font-size: 12.5px;
}
.bubble th, .bubble td, .md-body th, .md-body td {
  border: 1px solid var(--border-soft);
  padding: 6px 9px;
  text-align: left;
  vertical-align: top;
  white-space: normal;
}
.bubble th, .md-body th {
  background: var(--bg-elevated);
  font-weight: 650;
  color: var(--text);
}
.bubble tr:nth-child(even) td, .md-body tr:nth-child(even) td {
  background: rgba(0, 0, 0, 0.025);
}

.cite-tag {
  display: inline-block;
  background: var(--accent-soft);
  color: var(--accent-strong);
  border: 1px solid rgba(235, 82, 18, 0.4);
  border-radius: 5px;
  padding: 0 4px;
  font-size: 11px;
  font-weight: 600;
  cursor: pointer;
  margin: 0 1px;
}

.cite-tag:hover { background: rgba(235, 82, 18, 0.28); }
.cite-tag.inert { opacity: 0.55; cursor: default; }
.cite-tag.inert:hover { background: var(--accent-soft); }

.fallback-note {
  border-left: 3px solid var(--status-gap);
  padding-left: 10px;
  color: var(--text-muted);
}

.citations {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 2px;
}

.citation-chip {
  display: flex;
  align-items: center;
  gap: 6px;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 4px 10px 4px 8px;
  font-size: 11.5px;
  cursor: pointer;
  max-width: 340px;
}

.citation-chip:hover { border-color: var(--accent); }

.citation-chip .n {
  background: var(--accent);
  color: #fff;
  border-radius: 999px;
  width: 16px;
  height: 16px;
  font-size: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.citation-chip .title {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.status-dot {
  width: 7px;
  height: 7px;
  border-radius: 999px;
  flex-shrink: 0;
}

.status-Applicable { background: var(--status-applicable); }
.status-Partially-applicable { background: var(--status-partial); }
.status-Conditionally-applicable { background: var(--status-conditional); }
.status-Not-applicable { background: var(--status-notapplicable); }
.status-Reference { background: var(--status-reference); }
.status-Source-gap { background: var(--status-gap); }

.thinking {
  display: flex;
  gap: 4px;
  padding: 4px 0;
}
.thinking span {
  width: 6px; height: 6px; border-radius: 999px;
  background: var(--text-faint);
  animation: blink 1.1s infinite ease-in-out;
}
.thinking span:nth-child(2) { animation-delay: 0.15s; }
.thinking span:nth-child(3) { animation-delay: 0.3s; }
@keyframes blink { 0%, 80%, 100% { opacity: 0.25; } 40% { opacity: 1; } }

/* ---------- Composer ---------- */

#composer {
  border-top: 1px solid var(--border-soft);
  background: var(--bg-elevated);
  padding: 14px 28px 18px;
}

#composer-inner {
  max-width: 860px;
  margin: 0 auto;
  display: flex;
  gap: 10px;
  align-items: flex-end;
}

#msg-input {
  flex: 1;
  resize: none;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 10px;
  color: var(--text);
  padding: 10px 12px;
  font-size: 13.5px;
  font-family: inherit;
  max-height: 160px;
  min-height: 42px;
}

#msg-input:focus { outline: none; border-color: var(--accent); }

#send-btn {
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: 10px;
  padding: 10px 16px;
  font-size: 13.5px;
  font-weight: 600;
  cursor: pointer;
}

#send-btn:disabled { opacity: 0.5; cursor: default; }

.disclaimer {
  max-width: 860px;
  margin: 8px auto 0;
  font-size: 10.5px;
  color: var(--text-faint);
  text-align: center;
}

/* ---------- Citation drawer ---------- */

#drawer-backdrop {
  position: fixed; inset: 0;
  background: rgba(0,0,0,0.5);
  display: none;
  z-index: 10;
}

#drawer {
  position: fixed;
  top: 0; right: 0;
  height: 100%;
  width: 460px;
  min-width: 320px;
  max-width: 90vw;
  background: var(--bg-elevated);
  border-left: 1px solid var(--border);
  z-index: 11;
  display: none;
  flex-direction: column;
  padding: 20px 20px 20px 26px;
  overflow-y: auto;
}

#drawer.open, #drawer-backdrop.open { display: flex; }
#drawer-backdrop.open { display: block; }

#drawer-resize-handle {
  position: absolute;
  top: 0;
  left: 0;
  width: 7px;
  height: 100%;
  cursor: ew-resize;
  z-index: 1;
}
#drawer-resize-handle:hover, #drawer-resize-handle.dragging {
  background: var(--accent-soft);
}

#drawer .close-btn {
  align-self: flex-end;
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 18px;
  cursor: pointer;
}

#drawer h3 { margin: 4px 0 2px; font-size: 15px; }
#drawer .meta { color: var(--text-muted); font-size: 12px; margin-bottom: 14px; }
#drawer .md-body {
  white-space: normal;
  word-wrap: break-word;
  background: var(--bg-card);
  border: 1px solid var(--border-soft);
  border-radius: 8px;
  padding: 12px;
  font-size: 12.5px;
  line-height: 1.5;
  font-family: inherit;
}

.badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 3px 9px;
  font-size: 11px;
  margin-right: 6px;
}

/* ---------- Admin page ---------- */

.sidebar-link {
  display: block;
  color: var(--text-muted);
  text-decoration: none;
  font-size: 12px;
  margin-top: 10px;
}
.sidebar-link:hover { color: var(--accent-strong); }

#admin-app {
  max-width: 760px;
  margin: 0 auto;
  padding: 32px 24px 60px;
}

#admin-app h1 { font-size: 18px; margin-bottom: 2px; }
#admin-app .sub { color: var(--text-muted); font-size: 12.5px; margin-bottom: 24px; }

#unlock-panel {
  max-width: 360px;
  margin: 80px auto;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 24px;
  text-align: center;
}
#unlock-panel input {
  width: 100%;
  margin: 14px 0;
  background: var(--bg);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 8px;
  padding: 9px 10px;
  font-size: 13px;
}

.settings-group {
  background: var(--bg-card);
  border: 1px solid var(--border-soft);
  border-radius: var(--radius);
  padding: 16px 18px;
  margin-bottom: 16px;
}

.settings-group h2 {
  font-size: 12.5px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-faint);
  margin: 0 0 12px;
}

.field-row {
  display: grid;
  grid-template-columns: 200px 1fr;
  gap: 14px;
  align-items: start;
  padding: 10px 0;
  border-top: 1px solid var(--border-soft);
}
.field-row:first-of-type { border-top: none; }

.field-label { font-size: 13px; }
.field-help { font-size: 11px; color: var(--text-faint); margin-top: 2px; }

.field-row input[type="text"],
.field-row input[type="number"] {
  width: 100%;
  background: var(--bg);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 7px;
  padding: 7px 9px;
  font-size: 13px;
}
.field-row input:disabled {
  color: var(--text-faint);
  border-color: var(--border-soft);
}

.switch { display: flex; align-items: center; gap: 8px; }

.admin-actions {
  display: flex;
  gap: 10px;
  align-items: center;
  margin-top: 8px;
}

#save-status {
  font-size: 12px;
  color: var(--text-muted);
}
#save-status.error { color: var(--status-gap); }
#save-status.ok { color: var(--status-applicable); }

/* ---------- PDF export (print-only view) ---------- */

#print-root { display: none; }

body.print-mode #app,
body.print-mode #drawer,
body.print-mode #drawer-backdrop {
  display: none !important;
}

body.print-mode #print-root {
  display: block;
  /* The base theme is already light/print-safe (Paystep's own palette), so
     #print-root just inherits the global tokens — no override needed here
     the way a dark base theme would have required. */
  background: var(--bg);
  color: var(--text);
  max-width: 760px;
  margin: 0 auto;
  padding: 24px;
  font-size: 12.5px;
  line-height: 1.55;
}

.export-header h1 { font-size: 18px; margin: 0 0 4px; }
.export-meta { font-size: 11px; color: var(--text-muted); margin-bottom: 20px; }

.export-turn { margin-bottom: 14px; page-break-inside: avoid; }
.export-label {
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-faint);
  margin-bottom: 3px;
}
.export-q-text { font-weight: 650; }

.export-appendix { page-break-before: always; margin-top: 10px; }
.export-appendix h2 { font-size: 15px; margin: 0 0 14px; }

.export-ref {
  margin-bottom: 16px;
  page-break-inside: avoid;
  border-top: 1px solid var(--border-soft);
  padding-top: 10px;
}
.export-ref-head { font-weight: 650; margin-bottom: 4px; }
.export-ref-reg { font-weight: 400; color: var(--text-muted); }
.export-ref-meta { margin-bottom: 6px; }
.export-ref-path {
  font-size: 10.5px;
  color: var(--text-faint);
  margin-bottom: 8px;
  word-break: break-all;
}

.export-footer {
  margin-top: 24px;
  font-size: 10px;
  color: var(--text-faint);
  border-top: 1px solid var(--border-soft);
  padding-top: 10px;
}

@media print {
  @page { margin: 16mm; }
  body.print-mode #print-root { padding: 0; max-width: none; }
}

/* ---------- Utility classes (replace inline style=, needed for a CSP with
   no style-src 'unsafe-inline') ---------- */

.brand-center { align-items: center; }

.btn-inline { width: auto; }

.btn-block {
  display: block;
  width: 100%;
  text-align: center;
  box-sizing: border-box;
}

.text-input {
  width: 100%;
  background: var(--bg);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 7px;
  padding: 7px 9px;
  font-size: 13px;
  box-sizing: border-box;
}

.text-input-flex { flex: 1; min-width: 140px; }

.ml-md { margin-left: 16px; }
.mt-sm { margin-top: 6px; }
.mt-lg { margin-top: 24px; }

.field-row-divider {
  border-top: 1px solid var(--border-soft);
  margin-top: 6px;
  padding-top: 12px;
}

.actions-wrap { flex-wrap: wrap; }

.status-line { font-size: 12px; margin-top: 6px; }
.status-line-muted { font-size: 12px; color: var(--text-muted); }
.error-text { color: var(--status-gap); font-size: 12px; margin-top: 8px; }

/* ---------- Mobile / PWA layout ---------- */

#sidebar-toggle {
  display: none;
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 8px;
  width: 36px;
  height: 36px;
  font-size: 16px;
  cursor: pointer;
}

#sidebar-backdrop {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.5);
  z-index: 19;
}
#sidebar-backdrop.open { display: block; }

@media (max-width: 760px) {
  #app { grid-template-columns: 1fr; }

  #sidebar {
    position: fixed;
    top: 0;
    left: 0;
    height: 100%;
    width: 280px;
    max-width: 85vw;
    z-index: 20;
    transform: translateX(-100%);
    transition: transform 0.2s ease;
  }
  #sidebar.open { transform: translateX(0); }

  #sidebar-toggle { display: inline-flex; align-items: center; justify-content: center; }

  #chat-header { justify-content: space-between; }

  #chat-log { padding: 0 14px; }
  #composer { padding-left: 14px; padding-right: 14px; }
  #composer-inner { flex-wrap: wrap; }

  .msg.user .bubble, .msg.assistant .bubble { max-width: 100%; }

  #drawer { width: 100vw; max-width: 100vw; min-width: 0; }
  #drawer-resize-handle { display: none; }

  #admin-app { padding: 20px 16px 48px; }

  .field-row { grid-template-columns: 1fr; gap: 8px; }

  .admin-actions { flex-wrap: wrap; }
}
