/* ═══════════════════════════════════════════════════════════════
   AI Workspace — industrial dashboard system
   Style mirrored from /opt/rfp-monitor: JetBrains Mono headers,
   DM Sans body, deep navy + blue accent, tight panels, mono labels.
   ═══════════════════════════════════════════════════════════════ */

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

:root{
  --radius:    8px;
  --radius-sm: 6px;
  --radius-xs: 4px;
  --radius-lg: 10px;

  --header-h:  56px;
  --sources-w: 600px;

  --mono: 'JetBrains Mono', ui-monospace, 'SF Mono', Menlo, monospace;
  --sans: 'DM Sans', system-ui, -apple-system, sans-serif;
}

/* ── Dark theme (default) ── */
[data-theme="dark"], :root {
  --bg:        #0a0c10;          /* page (--bg-0) */
  --paper:     #12151c;          /* panels (--bg-1) */
  --surface:   #12151c;
  --surface-2: #1a1e28;          /* panel headers, hover (--bg-2) */
  --surface-3: #232836;          /* deeper element (--bg-3) */
  --border:    #2d3348;
  --border-strong: #3d4358;
  --hairline:  #1f2330;

  --ink:       #e8eaf0;          /* primary (--text-0) */
  --ink-soft:  #c0c4d0;
  --ink-dim:   #a0a6b8;          /* muted (--text-1) */
  --ink-faint: #6b7280;          /* faint (--text-2) */

  --accent:        #3b82f6;       /* blue */
  --accent-warm:   #2563eb;
  --accent-hover:  #60a5fa;
  --accent-soft:   rgba(59,130,246,.12);
  --accent-line:   rgba(59,130,246,.30);
  --accent-glow:   rgba(59,130,246,.20);
  --accent-on:     #ffffff;       /* text color on accent fills */
  --accent-dim:    #1e3a5f;

  --green:     #22c55e;
  --green-dim: #14532d;
  --amber:     #f59e0b;
  --amber-dim: #5c3d0a;
  --red:       #ef4444;
  --red-dim:   #5c1a1a;

  --shadow-1: 0 1px 2px rgba(0,0,0,.4);
  --shadow-2: 0 12px 32px rgba(0,0,0,.55), 0 2px 6px rgba(0,0,0,.3);
}

/* ── Light theme ── */
[data-theme="light"] {
  --bg:        #f4f5f7;
  --paper:     #ffffff;
  --surface:   #ffffff;
  --surface-2: #f0f1f4;
  --surface-3: #e4e6eb;
  --border:    #d1d5db;
  --border-strong: #b1b5be;
  --hairline:  #e6e8ec;

  --ink:       #111827;
  --ink-soft:  #2b3340;
  --ink-dim:   #4b5563;
  --ink-faint: #9ca3af;

  --accent:        #2563eb;
  --accent-warm:   #1d4ed8;
  --accent-hover:  #1e40af;
  --accent-soft:   rgba(37,99,235,.10);
  --accent-line:   rgba(37,99,235,.25);
  --accent-glow:   rgba(37,99,235,.16);
  --accent-on:     #ffffff;
  --accent-dim:    #dbeafe;

  --green:     #16a34a;
  --green-dim: #dcfce7;
  --amber:     #d97706;
  --amber-dim: #fef3c7;
  --red:       #dc2626;
  --red-dim:   #fee2e2;

  --shadow-1: 0 1px 2px rgba(17,24,39,.06);
  --shadow-2: 0 12px 28px rgba(17,24,39,.10), 0 2px 4px rgba(17,24,39,.04);
}

html, body{
  height: 100%;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--sans);
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

.mono { font-family: var(--mono); }

a { color: var(--accent); text-decoration: none; transition: color .12s; }
a:hover { color: var(--accent-hover); }
button { font-family: inherit; cursor: pointer; }
input, textarea, select { font-family: inherit; color: var(--ink); }

/* ═══════════ TOP BAR ═══════════ */
.topbar{
  height: var(--header-h);
  display: grid;
  grid-template-columns: auto 1fr auto;
  gap: 18px;
  align-items: center;
  padding: 0 16px;
  background: var(--paper);
  border-bottom: 1px solid var(--border);
  position: sticky; top: 0; z-index: 50;
}

.brand{
  display: flex; align-items: center; gap: 9px;
  color: var(--ink);
  padding-right: 8px;
}
.brand-mark{
  width: 22px; height: 22px;
  color: var(--accent);
  flex-shrink: 0;
}
.brand-name{
  font-family: var(--mono);
  font-size: 14px;
  font-weight: 700;
  letter-spacing: -0.5px;
  line-height: 1;
  color: var(--ink);
}

.topnav{
  display: flex; align-items: center; gap: 2px;
  justify-content: flex-start;
}
.navtab{
  display: inline-flex; align-items: center;
  height: 36px;
  padding: 0 12px;
  font-size: 13px;
  font-weight: 500;
  color: var(--ink-dim);
  letter-spacing: 0;
  border-radius: var(--radius-sm);
  transition: color .12s, background .12s;
}
.navtab:hover { color: var(--ink); background: var(--surface-2); }
.navtab.active{
  color: var(--accent);
  background: var(--accent-dim);
}
.navtab.admin{ font-size: 12px; }
.navsep{
  width: 1px; height: 22px;
  background: var(--border);
  margin: 0 6px;
}

.topright{ display: flex; align-items: center; gap: 4px; }

.iconbtn{
  width: 30px; height: 30px;
  display: inline-flex; align-items: center; justify-content: center;
  background: transparent; border: none; border-radius: var(--radius-sm);
  color: var(--ink-dim); transition: all .12s;
}
.iconbtn:hover { background: var(--surface-2); color: var(--ink); }

.usermenu{ position: relative; }
.usermenu summary{
  list-style: none; cursor: pointer;
  display: flex; align-items: center; padding: 3px;
  border-radius: 999px;
  transition: background .12s;
}
.usermenu summary::-webkit-details-marker { display: none; }
.usermenu summary:hover { background: var(--surface-2); }

.useravatar{
  width: 26px; height: 26px;
  border-radius: 50%;
  background: var(--accent);
  color: var(--accent-on);
  display: flex; align-items: center; justify-content: center;
  font-size: 11px;
  font-weight: 700;
  font-family: var(--mono);
  letter-spacing: 0;
}

.usermenu-panel{
  position: absolute; right: 0; top: calc(100% + 6px);
  min-width: 220px;
  background: var(--paper);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-2);
  padding: 5px;
  z-index: 100;
}
.usermenu-head{
  padding: 10px 12px 9px;
  border-bottom: 1px solid var(--hairline);
  margin-bottom: 4px;
}
.usermenu-name{
  font-size: 13px; font-weight: 600;
  display: flex; align-items: center; gap: 6px;
}
.usermenu-email{
  font-size: 11px;
  color: var(--ink-faint);
  margin-top: 2px;
  font-family: var(--mono);
}
.usermenu-item{
  display: block;
  padding: 8px 11px;
  font-size: 13px; color: var(--ink-dim);
  border-radius: var(--radius-xs);
  transition: background .12s;
}
.usermenu-item:hover { background: var(--surface-2); color: var(--ink); }
.usermenu-item.active { color: var(--accent); background: var(--accent-soft); }

.usermenu-section-label{
  font-family: var(--mono);
  font-size: 9.5px;
  font-weight: 600;
  letter-spacing: 1px;
  text-transform: uppercase;
  color: var(--ink-faint);
  padding: 8px 11px 4px;
}
.usermenu-divider{
  height: 1px;
  background: var(--hairline);
  margin: 5px 4px;
}

.role-tag{
  font-family: var(--mono);
  font-size: 9px;
  font-weight: 700;
  letter-spacing: .8px;
  text-transform: uppercase;
  padding: 1.5px 5px;
  border-radius: 3px;
  background: var(--accent);
  color: var(--accent-on);
}

/* ═══════════ CONTENT ═══════════ */
.content{
  min-height: calc(100vh - var(--header-h));
  display: flex; flex-direction: column;
}
/* Lock content area to viewport when chat workspace is present */
.content:has(.chat-workspace){
  height: calc(100vh - var(--header-h));
  min-height: 0;
  overflow: hidden;
}

.page-head{
  padding: 18px 24px 14px;
  display: flex; align-items: center; gap: 16px;
  border-bottom: 1px solid var(--hairline);
  flex-shrink: 0;
}
.page-title{
  font-family: var(--mono);
  font-size: 20px;
  font-weight: 700;
  letter-spacing: -0.5px;
  color: var(--ink);
  line-height: 1;
}
.page-sub{
  font-size: 12.5px;
  color: var(--ink-dim);
}
.page-head .right{ margin-left: auto; display: flex; align-items: center; gap: 6px; }

.status-pill{
  display: inline-flex; align-items: center; gap: 6px;
  font-size: 11px;
  color: var(--ink-dim);
  padding: 4px 10px;
  border-radius: 99px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  font-weight: 500;
  font-family: var(--mono);
}
.status-pill .dot{ width: 6px; height: 6px; border-radius: 50%; background: var(--ink-faint); }
.status-pill.ok .dot{ background: var(--green); }
.status-pill.warn .dot{ background: var(--amber); }
.status-pill.err .dot{ background: var(--red); }

/* ═══════════ BUTTONS ═══════════ */
.btn{
  display: inline-flex; align-items: center; gap: 6px;
  padding: 7px 14px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--ink);
  font-size: 13px;
  font-weight: 500;
  letter-spacing: 0;
  transition: all .12s;
  white-space: nowrap;
  font-family: var(--sans);
}
.btn:hover { background: var(--surface-2); border-color: var(--border-strong); }
.btn.primary{
  background: var(--accent); color: var(--accent-on);
  border-color: var(--accent);
  font-weight: 600;
}
.btn.primary:hover{
  background: var(--accent-warm);
  border-color: var(--accent-warm);
}
.btn.danger{ color: var(--red); border-color: var(--border); }
.btn.danger:hover { background: var(--red-dim); border-color: var(--red); color: var(--red); }
.btn.ghost { background: transparent; border-color: transparent; color: var(--ink-dim); }
.btn.ghost:hover { background: var(--surface-2); color: var(--ink); }
.btn:disabled{ opacity: .4; cursor: not-allowed; }
.btn.sm{ padding: 4px 10px; font-size: 12px; gap: 4px; height: 28px; }
.btn.lg{ padding: 9px 18px; font-size: 13.5px; }

/* ═══════════ INPUTS ═══════════ */
.input, .textarea, .select{
  width: 100%;
  background: var(--bg);
  color: var(--ink);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 9px 12px;
  font-size: 13px;
  letter-spacing: 0;
  transition: border-color .12s, box-shadow .12s;
  font-family: var(--sans);
}
.input:focus, .textarea:focus, .select:focus{
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}
.textarea{ resize: vertical; min-height: 70px; line-height: 1.5; }
.select, .repo-select{
  cursor: pointer;
  background: var(--surface);
  color: var(--ink);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 6px 11px;
  font-size: 13px;
  font-family: inherit;
  min-width: 160px;
  height: 30px;
}
.select:focus, .repo-select:focus { outline: none; border-color: var(--accent); }
.input.mono { font-family: var(--mono); font-size: 12.5px; }

.field-label{
  display: block;
  font-family: var(--mono);
  font-size: 10px;
  font-weight: 600;
  color: var(--ink-faint);
  margin-bottom: 6px;
  text-transform: uppercase;
  letter-spacing: 1px;
}
.field { margin-bottom: 14px; }
.field-hint { font-size: 11.5px; color: var(--ink-faint); margin-top: 5px; line-height: 1.5; }

kbd{
  display: inline-block;
  padding: 1px 6px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 4px;
  font-family: var(--mono);
  font-size: 10.5px;
  font-weight: 500;
  color: var(--ink-dim);
}

/* ═══════════ LOGIN ═══════════ */
.login-wrap{
  min-height: 100vh;
  display: flex; align-items: center; justify-content: center;
  padding: 32px;
  background: var(--bg);
}
.login-card{
  background: var(--paper);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 38px 36px;
  width: 100%;
  max-width: 400px;
  box-shadow: var(--shadow-2);
}
.login-logo{
  width: 44px; height: 44px;
  display: flex; align-items: center; justify-content: center;
  margin: 0 auto 22px;
  color: var(--accent);
}
.login-card h1{
  font-family: var(--mono);
  font-weight: 700;
  font-size: 22px;
  text-align: center;
  margin-bottom: 4px;
  letter-spacing: -0.5px;
  color: var(--ink);
}
.login-card .subtitle{
  text-align: center;
  font-size: 13px;
  color: var(--ink-dim);
  margin-bottom: 26px;
}
.code-input{
  width: 100%; text-align: center;
  font-family: var(--mono);
  font-size: 24px; font-weight: 600;
  letter-spacing: 10px;
  padding: 14px 12px;
}
.alert{
  padding: 10px 13px;
  margin-bottom: 16px;
  border-radius: var(--radius-sm);
  font-size: 12.5px;
  border: 1px solid var(--border);
  background: var(--surface-2);
}
.alert.error{ background: var(--red-dim); border-color: var(--red); color: var(--red); }
.alert.success{ background: var(--green-dim); border-color: var(--green); color: var(--green); }
.alert.info{ background: var(--accent-soft); border-color: var(--accent-line); color: var(--accent); }

/* ═══════════ TABLES ═══════════ */
.table-wrap{
  background: var(--paper);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}
table.table{ width: 100%; border-collapse: collapse; }
.table th{
  text-align: left;
  padding: 11px 16px;
  font-family: var(--mono);
  font-size: 10.5px;
  font-weight: 600;
  color: var(--ink-faint);
  text-transform: uppercase;
  letter-spacing: 1px;
  border-bottom: 1px solid var(--border);
  background: var(--surface-2);
  position: sticky; top: 0;
}
.table td{ padding: 11px 16px; font-size: 13px; border-bottom: 1px solid var(--hairline); }
.table tr:last-child td{ border-bottom: none; }
.table tr:hover td{ background: var(--surface-2); }

/* ═══════════ ENTITLEMENTS MATRIX ═══════════ */
.matrix-wrap{ overflow-x: auto; padding: 0 24px 24px; }
.matrix{
  width: 100%; border-collapse: separate; border-spacing: 0;
  background: var(--paper);
  border-radius: var(--radius);
  overflow: hidden;
  border: 1px solid var(--border);
}
.matrix th{
  background: var(--surface-2);
  position: sticky; top: 0; z-index: 2;
  padding: 11px 14px;
  font-family: var(--mono);
  font-size: 10.5px;
  font-weight: 600;
  color: var(--ink-faint);
  text-transform: uppercase;
  letter-spacing: 1px;
  border-bottom: 1px solid var(--border);
  text-align: left;
}
.matrix th:first-child{ position: sticky; left: 0; z-index: 3; min-width: 220px; }
.matrix td{ padding: 11px 14px; font-size: 13px; border-bottom: 1px solid var(--hairline); }
.matrix tr:last-child td{ border-bottom: none; }
.matrix td:first-child{
  position: sticky; left: 0; z-index: 1;
  background: var(--paper);
  border-right: 1px solid var(--hairline);
  min-width: 220px;
}
.matrix .module-col{ text-align: center; width: 110px; }
.matrix .access-cell{ text-align: center; }

.access-pill{
  display: inline-flex; align-items: center;
  padding: 2px 10px;
  border-radius: 99px;
  font-family: var(--mono);
  font-size: 10.5px; font-weight: 600;
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--ink-faint);
  cursor: pointer;
  transition: all .12s;
  min-width: 60px;
  justify-content: center;
  letter-spacing: .5px;
  text-transform: uppercase;
}
.access-pill[data-state="user"]{
  background: var(--accent-soft);
  border-color: var(--accent-line);
  color: var(--accent);
}
.access-pill[data-state="admin"]{
  background: var(--accent);
  border-color: var(--accent);
  color: var(--accent-on);
}

.add-user-row{
  display: flex; gap: 8px;
  padding: 12px 16px;
  background: var(--surface-2);
  border-bottom: 1px solid var(--border);
  align-items: center;
}
.add-user-row .input{ flex: 1; max-width: 280px; }

/* ═══════════ MODALS ═══════════ */
.modal-overlay{
  position: fixed; inset: 0;
  background: rgba(10,12,16,.75);
  display: none; align-items: center; justify-content: center;
  z-index: 1000; padding: 24px;
  backdrop-filter: blur(4px);
  animation: fade-in .15s ease-out;
}
[data-theme="light"] .modal-overlay { background: rgba(17,24,39,.45); }
.modal-overlay.open{ display: flex; }
.modal{
  background: var(--paper);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 24px;
  width: 100%; max-width: 460px;
  box-shadow: var(--shadow-2);
}
.modal h3{
  font-family: var(--mono);
  font-size: 14px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-bottom: 18px;
  color: var(--ink);
}
.modal-actions{ display: flex; gap: 6px; justify-content: flex-end; margin-top: 22px; }

@keyframes fade-in { from { opacity: 0; } }

/* ═══════════ TOAST ═══════════ */
.toast{
  position: fixed; bottom: 24px; left: 50%;
  transform: translateX(-50%) translateY(80px);
  background: var(--ink); color: var(--bg);
  padding: 10px 18px;
  border-radius: var(--radius-sm);
  font-size: 12.5px; font-weight: 500;
  font-family: var(--mono);
  box-shadow: var(--shadow-2);
  opacity: 0; transition: all .2s;
  z-index: 2000; pointer-events: none;
}
.toast.show{ transform: translateX(-50%) translateY(0); opacity: 1; }
.toast.error{ background: var(--red); color: #fff; }
.toast.success{ background: var(--green); color: #fff; }

/* ═══════════ COMMAND PALETTE ═══════════ */
.palette{
  position: fixed; inset: 0; display: none;
  z-index: 3000; padding: 100px 24px 24px;
  justify-content: center;
}
.palette.open{ display: flex; animation: fade-in .15s; }
.palette-bg{
  position: absolute; inset: 0;
  background: rgba(10,12,16,.7); backdrop-filter: blur(6px);
}
.palette-box{
  position: relative; width: 100%; max-width: 540px;
  background: var(--paper); border: 1px solid var(--border);
  border-radius: var(--radius); box-shadow: var(--shadow-2);
  display: flex; flex-direction: column; max-height: 460px;
}
#paletteInput{
  width: 100%; padding: 16px 18px;
  background: transparent; color: var(--ink);
  border: none; border-bottom: 1px solid var(--border);
  font-size: 15px; outline: none;
  font-family: var(--sans);
}
.palette-list{ flex: 1; overflow-y: auto; padding: 5px; }
.palette-item{
  display: flex; align-items: center; gap: 10px;
  padding: 9px 12px; border-radius: var(--radius-sm);
  cursor: pointer; font-size: 13px;
  color: var(--ink-dim);
}
.palette-item.selected{ background: var(--accent-dim); color: var(--ink); }
.palette-foot{
  display: flex; gap: 16px; padding: 9px 16px;
  border-top: 1px solid var(--border);
  font-size: 11px; color: var(--ink-faint);
  font-family: var(--mono);
}

/* ═══════════ CHAT WORKSPACE ═══════════ */
.chat-workspace{
  flex: 1;
  display: grid;
  grid-template-columns: 1fr;
  min-height: 0;
  background: var(--bg);
  position: relative;
  transition: grid-template-columns .25s ease-out;
}
.chat-workspace.show-sources{
  grid-template-columns: 1fr var(--sources-w);
}

.chat-pane{
  display: flex; flex-direction: column;
  min-height: 0;
  border-right: 1px solid var(--hairline);
  background: var(--bg);
}

.chat-meta{
  padding: 8px 24px;
  display: flex; align-items: center; gap: 8px;
  border-bottom: 1px solid var(--hairline);
  background: var(--paper);
  flex-wrap: wrap;
  flex-shrink: 0;
  min-height: 44px;
}

.messages{
  flex: 1;
  overflow-y: auto;
  padding: 28px 24px 18px;
  display: flex; flex-direction: column;
}

.msg{
  max-width: 760px;
  width: 100%;
  margin: 0 auto 20px;
  position: relative;
  animation: msg-in .25s ease-out;
}
.msg:last-child { margin-bottom: 0; }

@keyframes msg-in { from { opacity: 0; transform: translateY(4px); } }

/* User message: clean compact bubble */
.msg.user{
  text-align: right;
  padding-left: 80px;
  margin-bottom: 14px;
}
.msg.user .msg-bubble{
  display: inline-block;
  text-align: left;
  background: var(--accent);
  color: var(--accent-on);
  padding: 8px 14px;
  border-radius: 10px 10px 2px 10px;
  font-size: 13.5px;
  line-height: 1.5;
  max-width: 100%;
  font-weight: 500;
}

/* Assistant: clean prose, no decoration */
.msg.assistant .msg-bubble{
  font-family: var(--sans);
  font-size: 14px;
  line-height: 1.55;
  color: var(--ink);
}

.msg-bubble p{ margin-bottom: .55em; }
.msg-bubble p:last-child{ margin-bottom: 0; }
.msg-bubble h1, .msg-bubble h2, .msg-bubble h3{
  font-family: var(--mono);
  font-weight: 700;
  margin: .85em 0 .3em;
  letter-spacing: -0.3px;
  line-height: 1.25;
}
.msg-bubble h1{ font-size: 1.15em; }
.msg-bubble h2{ font-size: 1.07em; }
.msg-bubble h3{ font-size: 1em; text-transform: uppercase; letter-spacing: 0.5px; font-size: 0.85em; color: var(--ink-dim); }

.msg-bubble ul, .msg-bubble ol{
  margin: .35em 0 .55em 1.2em;
  padding: 0;
}
.msg-bubble ul li, .msg-bubble ol li {
  margin-bottom: .15em;
  line-height: 1.5;
}
.msg-bubble ul li::marker, .msg-bubble ol li::marker {
  color: var(--accent);
}
.msg-bubble ul ul, .msg-bubble ol ol, .msg-bubble ul ol, .msg-bubble ol ul {
  margin: .15em 0 .15em 1em;
}

.msg-bubble code{
  font-family: var(--mono);
  background: var(--surface-2);
  padding: 1px 6px;
  border-radius: 4px;
  font-size: .85em;
  color: var(--accent);
  border: 1px solid var(--hairline);
}
.msg-bubble pre{
  background: var(--surface);
  padding: 12px 14px;
  border-radius: var(--radius-sm);
  overflow-x: auto;
  margin: .5em 0;
  border: 1px solid var(--border);
  font-size: 12.5px;
}
.msg-bubble pre code{ background: none; padding: 0; font-size: 12.5px; color: var(--ink); border: none; }
.msg-bubble strong{ font-weight: 600; color: var(--ink); }
.msg-bubble em{ font-style: italic; }
.msg-bubble blockquote{
  border-left: 2px solid var(--accent);
  padding-left: 14px;
  margin: .5em 0;
  color: var(--ink-dim);
}

/* Inline citation: small monospace footnote-style number */
.cite{
  display: inline-block;
  font-family: var(--mono);
  font-size: 0.72em;
  font-weight: 700;
  color: var(--accent);
  vertical-align: super;
  line-height: 0;
  padding: 0 1px;
  cursor: pointer;
  text-decoration: none;
  position: relative;
  top: -1px;
  transition: color .12s;
}
.cite:hover{
  color: var(--accent-hover);
  text-decoration: underline;
}

/* Thinking indicator */
.thinking{
  display: inline-flex; align-items: center; gap: 8px;
  font-size: 13.5px;
  color: var(--ink-dim);
  font-family: var(--mono);
}
.thinking::after{
  content: '';
  display: inline-block;
  width: 7px; height: 14px;
  background: var(--accent);
  animation: cursor-blink 1.1s ease-in-out infinite;
  vertical-align: text-bottom;
  margin-left: 2px;
}
@keyframes cursor-blink {
  0%, 100% { opacity: 0; }
  50%      { opacity: 1; }
}
.thinking-dots{
  display: inline-flex; gap: 3px;
  margin-left: 2px;
}
.thinking-dots span{
  width: 4px; height: 4px;
  border-radius: 50%;
  background: var(--ink-dim);
  animation: dot-pulse 1.4s ease-in-out infinite;
}
.thinking-dots span:nth-child(2){ animation-delay: .15s; }
.thinking-dots span:nth-child(3){ animation-delay: .3s; }
@keyframes dot-pulse {
  0%, 60%, 100% { opacity: .3; transform: scale(.8); }
  30%           { opacity: 1;  transform: scale(1); }
}

/* ═══════════ COMPOSER ═══════════ */
.composer{
  border-top: 1px solid var(--hairline);
  padding: 14px 24px 16px;
  background: var(--paper);
  flex-shrink: 0;
}
.composer-row{
  display: flex; gap: 6px; align-items: flex-end;
  max-width: 760px; margin: 0 auto;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 4px 4px 4px 0;
  transition: border-color .12s, box-shadow .12s;
}
.composer-row:focus-within{
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}
.composer textarea{
  flex: 1;
  min-height: 32px; max-height: 220px;
  background: transparent; color: var(--ink);
  border: none; border-radius: var(--radius-sm);
  padding: 8px 4px 8px 14px;
  font-size: 13.5px;
  resize: none;
  font-family: var(--sans);
  line-height: 1.5;
}
.composer textarea:focus{ outline: none; }
.composer textarea::placeholder { color: var(--ink-faint); }
.send-btn{
  width: 32px; height: 32px;
  background: var(--accent); color: var(--accent-on);
  border: none; border-radius: var(--radius-sm);
  display: flex; align-items: center; justify-content: center;
  transition: all .12s; flex-shrink: 0;
}
.send-btn:hover:not(:disabled){
  background: var(--accent-warm);
}
.send-btn:disabled{ opacity: .35; cursor: not-allowed; }

/* Smaller secondary action button next to send (e.g. "Search on Web") */
.composer-action{
  width: 32px; height: 32px;
  background: transparent;
  color: var(--ink-dim);
  border: none;
  border-radius: var(--radius-sm);
  display: flex; align-items: center; justify-content: center;
  transition: all .12s; flex-shrink: 0;
  cursor: pointer;
}
.composer-action:hover{
  background: var(--surface-2);
  color: var(--accent);
}
.composer-action svg{ display: block; }

.composer-hint{
  text-align: center;
  font-size: 10.5px;
  color: var(--ink-faint);
  margin-top: 8px;
  font-family: var(--mono);
  letter-spacing: .3px;
}

/* ═══════════ SOURCES PANEL ═══════════ */
.sources-panel{
  background: var(--paper);
  border-left: 1px solid var(--border);
  display: flex; flex-direction: column;
  min-width: 0;
  overflow: hidden;
  position: relative;
}
.sources-panel[hidden]{ display: none; }

.sources-head{
  padding: 14px 14px 12px 18px;
  border-bottom: 1px solid var(--border);
  display: flex; align-items: center; justify-content: space-between;
  gap: 10px;
  flex-shrink: 0;
  background: var(--surface-2);
}
.sources-head h3{
  font-family: var(--mono);
  font-size: 13px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  flex: 1;
  color: var(--ink);
}
.sources-count{
  font-family: var(--mono);
  font-size: 10.5px;
  font-weight: 700;
  letter-spacing: 0.5px;
  text-transform: uppercase;
  color: var(--accent);
  padding: 2px 8px;
  background: var(--accent-soft);
  border: 1px solid var(--accent-line);
  border-radius: 99px;
}
.sources-close{
  width: 26px; height: 26px;
  background: transparent; border: none;
  color: var(--ink-dim); cursor: pointer;
  border-radius: var(--radius-sm);
  display: flex; align-items: center; justify-content: center;
  transition: all .12s;
  flex-shrink: 0;
}
.sources-close:hover{ background: var(--surface-3); color: var(--ink); }
.sources-close svg { width: 15px; height: 15px; }

.sources-list{
  flex: 1;
  overflow-y: auto;
  padding: 8px 10px 18px;
}
.sources-empty{
  padding: 50px 24px;
  text-align: center;
  color: var(--ink-faint);
  font-size: 12.5px;
  line-height: 1.5;
}
.source-item{
  padding: 12px 12px;
  margin-bottom: 4px;
  border-radius: var(--radius-sm);
  border: 1px solid transparent;
  cursor: pointer;
  transition: all .12s;
  position: relative;
}
.source-item:hover{
  background: var(--surface-2);
  border-color: var(--border);
}
.source-item:hover .source-num {
  background: var(--accent);
  color: var(--accent-on);
}
.source-item-head{
  display: flex; align-items: flex-start; gap: 9px;
  margin-bottom: 5px;
}
.source-num{
  flex-shrink: 0;
  width: 22px; height: 22px;
  border-radius: var(--radius-xs);
  background: var(--accent-soft);
  color: var(--accent);
  display: flex; align-items: center; justify-content: center;
  font-family: var(--mono);
  font-size: 11px;
  font-weight: 700;
  border: 1px solid var(--accent-line);
  transition: all .12s;
}
.source-name{
  flex: 1;
  font-size: 12.5px;
  font-weight: 600;
  color: var(--ink);
  word-break: break-word;
  line-height: 1.35;
}
.source-page{
  font-family: var(--mono);
  font-size: 10.5px;
  color: var(--ink-faint);
  margin-top: 3px;
  letter-spacing: .2px;
}
.source-preview{
  font-size: 12px;
  color: var(--ink-dim);
  line-height: 1.5;
  padding-left: 31px;
  margin-top: 3px;
  display: -webkit-box;
  -webkit-line-clamp: 3;
  -webkit-box-orient: vertical;
  overflow: hidden;
}
.source-action{
  position: absolute;
  top: 12px;
  right: 12px;
  font-family: var(--mono);
  font-size: 9.5px;
  font-weight: 600;
  letter-spacing: 0.5px;
  text-transform: uppercase;
  color: var(--ink-faint);
  opacity: 0;
  transition: opacity .12s;
}
.source-item:hover .source-action{ opacity: 1; color: var(--accent); }

/* Per-message sources trigger pill */
.sources-trigger{
  display: inline-flex; align-items: center; gap: 6px;
  margin-top: 12px;
  padding: 4px 11px;
  font-family: var(--mono);
  font-size: 11px;
  font-weight: 600;
  color: var(--accent);
  background: var(--accent-soft);
  border: 1px solid var(--accent-line);
  border-radius: 99px;
  cursor: pointer;
  transition: all .12s;
  letter-spacing: .3px;
  text-transform: uppercase;
  user-select: none;
}
.sources-trigger:hover{
  background: var(--accent);
  color: var(--accent-on);
  border-color: var(--accent);
}
.sources-trigger.active{
  background: var(--accent);
  color: var(--accent-on);
  border-color: var(--accent);
}

/* Welcome / empty state */
.welcome{
  flex: 1; display: flex; flex-direction: column;
  align-items: center; justify-content: center;
  padding: 30px 28px;
  text-align: center;
  max-width: 680px; margin: 0 auto;
}
.welcome-greeting{
  font-family: var(--mono);
  font-size: 28px;
  font-weight: 700;
  letter-spacing: -0.6px;
  line-height: 1.2;
  margin-bottom: 12px;
  color: var(--ink);
}
.welcome-greeting em{
  color: var(--accent);
  font-style: normal;
}
.welcome-sub{
  font-size: 13.5px;
  color: var(--ink-dim);
  margin-bottom: 30px;
  max-width: 460px;
  line-height: 1.55;
}
.chip-grid{
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 8px;
  width: 100%;
  max-width: 580px;
}
.chip{
  padding: 11px 14px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 12.5px;
  color: var(--ink-dim);
  text-align: left;
  cursor: pointer;
  transition: all .15s;
  font-family: inherit;
  line-height: 1.45;
}
.chip:hover{
  border-color: var(--accent);
  background: var(--surface-2);
  color: var(--ink);
}

/* ═══════════ REPOSITORY GRID ═══════════ */
.repo-grid{
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(290px, 1fr));
  gap: 12px;
  padding: 22px 24px;
}

.repo-card{
  background: var(--paper);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px;
  transition: all .15s;
  cursor: pointer;
  display: flex; flex-direction: column;
  position: relative;
  overflow: hidden;
}
.repo-card:hover{
  border-color: var(--accent);
  box-shadow: var(--shadow-1);
}
.repo-card-name{
  font-family: var(--mono);
  font-size: 15px;
  font-weight: 700;
  letter-spacing: -0.3px;
  margin-bottom: 6px;
  color: var(--ink);
  line-height: 1.25;
  padding-right: 60px;
}
.repo-card-desc{
  font-size: 12.5px;
  color: var(--ink-dim);
  margin-bottom: 14px;
  line-height: 1.5;
  min-height: 32px;
}
.repo-card-meta{
  display: flex; gap: 6px;
  font-family: var(--mono);
  font-size: 10.5px;
  color: var(--ink-faint);
  margin-top: auto;
  align-items: center;
  flex-wrap: wrap;
}
.repo-meta-tag{
  padding: 2px 8px;
  border-radius: 4px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  font-weight: 500;
  font-size: 10.5px;
}
.visibility-tag{
  position: absolute;
  top: 16px; right: 16px;
  font-family: var(--mono);
  font-size: 9.5px;
  font-weight: 700;
  letter-spacing: 0.6px;
  text-transform: uppercase;
  padding: 2px 7px;
  border-radius: 3px;
}
.visibility-tag.private{
  background: var(--surface-2);
  color: var(--ink-faint);
  border: 1px solid var(--border);
}
.visibility-tag.shared{
  background: var(--accent);
  color: var(--accent-on);
  border: 1px solid var(--accent);
}

/* Documents list */
.docs-list{ padding: 14px 24px; }
.doc-row{
  display: flex; align-items: center; gap: 12px;
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  transition: background .12s;
}
.doc-row:hover{ background: var(--surface-2); }
.doc-icon{
  width: 32px; height: 32px;
  flex-shrink: 0;
  background: var(--surface-2);
  border-radius: var(--radius-xs);
  display: flex; align-items: center; justify-content: center;
  font-family: var(--mono);
  font-size: 9.5px;
  font-weight: 700;
  color: var(--accent);
  letter-spacing: 0.5px;
  border: 1px solid var(--border);
}
.doc-meta{ flex: 1; min-width: 0; }
.doc-name{
  font-size: 13px; font-weight: 500;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.doc-sub{
  font-family: var(--mono);
  font-size: 11px;
  color: var(--ink-faint);
  margin-top: 2px;
}

.status-tag{
  font-family: var(--mono);
  font-size: 9.5px;
  font-weight: 700;
  padding: 2px 8px;
  border-radius: 3px;
  text-transform: uppercase;
  letter-spacing: 0.6px;
}
.status-tag.indexed{ background: var(--green-dim); color: var(--green); border: 1px solid var(--green); }
.status-tag.processing{ background: var(--accent-soft); color: var(--accent); border: 1px solid var(--accent-line); }
.status-tag.error{ background: var(--red-dim); color: var(--red); border: 1px solid var(--red); }
.status-tag.uploaded{ background: var(--surface-2); color: var(--ink-dim); border: 1px solid var(--border); }

/* Drop zone */
.drop-zone{
  margin: 16px 24px;
  padding: 30px;
  border: 1.5px dashed var(--border-strong);
  border-radius: var(--radius);
  text-align: center;
  color: var(--ink-dim);
  transition: all .15s;
  cursor: pointer;
  background: var(--paper);
}
.drop-zone:hover{ border-color: var(--accent); color: var(--ink); background: var(--surface-2); }
.drop-zone.drag-over{
  border-color: var(--accent);
  background: var(--accent-soft);
  color: var(--ink);
}

/* Spinners */
.spinner{
  display: inline-block; width: 12px; height: 12px;
  border: 2px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin .8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* Scrollbars */
*::-webkit-scrollbar{ width: 7px; height: 7px; }
*::-webkit-scrollbar-track{ background: transparent; }
*::-webkit-scrollbar-thumb{ background: var(--surface-3); border-radius: 4px; }
*::-webkit-scrollbar-thumb:hover{ background: var(--border-strong); }

/* Visibility radio cards */
.vis-options{ display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.vis-option{
  padding: 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: all .12s;
  background: var(--surface);
}
.vis-option:hover{ border-color: var(--border-strong); }
.vis-option input{ display: none; }
.vis-option.selected{
  border-color: var(--accent);
  background: var(--accent-soft);
}
.vis-option .vis-name{
  font-family: var(--mono);
  font-weight: 600;
  font-size: 12.5px;
  margin-bottom: 4px;
  color: var(--ink);
}
.vis-option .vis-desc{
  font-size: 11px;
  color: var(--ink-dim);
  line-height: 1.4;
}

/* Provider pills (Web module source picker) */
.provider-pills{
  display: inline-flex;
  gap: 2px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 2px;
}
.provider-pills .pill{
  padding: 4px 12px;
  font-family: var(--mono);
  font-size: 11px;
  font-weight: 600;
  color: var(--ink-dim);
  background: transparent;
  border: none;
  border-radius: var(--radius-xs);
  cursor: pointer;
  transition: all .12s;
  letter-spacing: 0.3px;
  text-transform: uppercase;
}
.provider-pills .pill:hover:not(.disabled):not(.active){
  color: var(--ink);
  background: var(--surface-2);
}
.provider-pills .pill.active{
  background: var(--accent);
  color: var(--accent-on);
}
.provider-pills .pill.disabled{
  color: var(--ink-faint);
  opacity: .5;
  cursor: not-allowed;
}

/* Mobile FAB */
.sources-fab{ display: none; }

/* Responsive */
@media (max-width: 1440px){
  :root { --sources-w: 480px; }
}
@media (max-width: 1200px){
  :root { --sources-w: 380px; }
}
@media (max-width: 900px){
  :root { --sources-w: 320px; }
  .topbar{ padding: 0 12px; gap: 10px; }
  .brand-name{ display: none; }
}
@media (max-width: 768px){
  .chat-workspace{ grid-template-columns: 1fr; }
  .sources-panel{
    position: fixed;
    top: var(--header-h);
    bottom: 0;
    right: 0;
    width: 100%;
    max-width: 360px;
    z-index: 40;
    transform: translateX(100%);
    transition: transform .25s ease-out;
    box-shadow: -8px 0 20px rgba(0,0,0,.3);
  }
  .sources-panel.open{ transform: translateX(0); }
  .topnav{ overflow-x: auto; }
  .navtab{ padding: 0 9px; font-size: 12.5px; }
  .messages{ padding: 22px 14px; }
  .repo-grid{ padding: 18px 14px; }
  .composer{ padding: 12px 14px; }
  .sources-fab{
    display: flex;
    position: fixed;
    bottom: 80px; right: 16px;
    width: 44px; height: 44px;
    background: var(--accent); color: var(--accent-on);
    border: none; border-radius: 50%;
    align-items: center; justify-content: center;
    box-shadow: 0 4px 14px rgba(59,130,246,.4);
    z-index: 30;
    font-family: var(--mono);
    font-weight: 700;
  }
}
