/* ── Reset & Base ─────────────────────────────────────────────────────────── */

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
[hidden] { display: none !important; }

:root {
  --sidebar-w:        260px;
  --sidebar-bg:       #1c1c1e;
  --sidebar-border:   #2c2c2e;
  --sidebar-text:     #98989f;
  --sidebar-hover:    #2c2c2e;
  --sidebar-active:   #3a3a3c;
  --sidebar-accent:   #ffffff;

  --main-bg:          #f2f2f7;

  --msg-user-bg:      #e5e5ea;
  --msg-ai-bg:        #ffffff;

  --input-bg:         #ffffff;
  --input-border:     #c7c7cc;
  --input-shadow:     0 2px 16px rgba(0,0,0,.08), 0 0 0 1px rgba(0,0,0,.06);

  --accent:           #007aff;
  --accent-h:         #0056cc;
  --danger:           #ff3b30;

  --text:             #1c1c1e;
  --text-muted:       #6c6c70;
  --text-faint:       #aeaeb2;

  --radius:           12px;
  --radius-sm:        8px;
  --radius-lg:        18px;
  --radius-pill:      999px;

  --transition:       0.22s cubic-bezier(.4,0,.2,1);

  /* Attachment chips (PDF / prior-art / pasted text) — neutral greys. The
     document TYPE is conveyed by the icon or the TXT/TEXT badge, not by colour. */
  --chip-bg:          rgba(0,0,0,.055);
  --chip-bg-hover:    rgba(0,0,0,.09);
  --chip-badge:       #8e8e93;
  --chip-del-bg:      rgba(0,0,0,.08);
  --chip-del-hover:   rgba(0,0,0,.16);
}

html, body {
  height: 100%;
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  font-size: 14px;
  line-height: 1.5;
  color: var(--text);
  background: var(--main-bg);
  -webkit-font-smoothing: antialiased;
}

button { cursor: pointer; border: none; background: none; font-family: inherit; font-size: inherit; }
input, textarea, select { font-family: inherit; font-size: inherit; }
a { color: var(--accent); }

/* ── Layout ───────────────────────────────────────────────────────────────── */

.app {
  display: flex;
  height: 100vh;
  overflow: hidden;
  position: relative;
}

/* Hide the working area until boot() decides whether to show login or the app —
   prevents a flash of the app before the login screen appears. */
body.booting .app { visibility: hidden; }

/* ── Sidebar ──────────────────────────────────────────────────────────────── */

.sidebar {
  width: var(--sidebar-w);
  flex-shrink: 0;
  background: var(--sidebar-bg);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  transition: width var(--transition);
  position: relative;
  z-index: 10;
}

.app.sidebar-collapsed .sidebar {
  width: 0;
}

.sidebar-inner {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
  padding: 14px 10px 8px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  scrollbar-width: thin;
  scrollbar-color: #3a3a3c transparent;
  min-width: var(--sidebar-w);
}

.sidebar-inner::-webkit-scrollbar { width: 3px; }
.sidebar-inner::-webkit-scrollbar-thumb { background: #3a3a3c; border-radius: 3px; }

.sidebar-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 2px 4px 10px;
  border-bottom: 1px solid var(--sidebar-border);
}

.sidebar-brand {
  display: flex;
  align-items: center;
  gap: 8px;
  color: #e5e5ea;
  font-size: 13.5px;
  font-weight: 600;
  letter-spacing: -.01em;
}

.sidebar-collapse-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 26px;
  height: 26px;
  border-radius: 6px;
  color: var(--sidebar-text);
  transition: background var(--transition), color var(--transition);
}
.sidebar-collapse-btn:hover { background: var(--sidebar-hover); color: #e5e5ea; }

/* Expand button — floats at left edge when sidebar is hidden */
.sidebar-expand-btn {
  display: none;
  position: fixed;
  left: 0;
  top: 20px;
  z-index: 20;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 40px;
  background: var(--sidebar-bg);
  color: var(--sidebar-text);
  border-radius: 0 8px 8px 0;
  box-shadow: 2px 0 8px rgba(0,0,0,.2);
  transition: color var(--transition);
}
.sidebar-expand-btn:hover { color: #e5e5ea; }
.app.sidebar-collapsed .sidebar-expand-btn { display: flex; }

.btn-new-session {
  display: flex;
  align-items: center;
  gap: 6px;
  width: 100%;
  padding: 7px 10px;
  background: rgba(255,255,255,.06);
  color: #e5e5ea;
  border: 1px solid rgba(255,255,255,.08);
  border-radius: var(--radius-sm);
  font-size: 13px;
  font-weight: 500;
  transition: background var(--transition);
  white-space: nowrap;
}
.btn-new-session:hover { background: rgba(255,255,255,.1); }

.sidebar-section {
  display: flex;
  flex-direction: column;
  gap: 3px;
}
.sidebar-section-templates { flex: 1; }

.section-label {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 10px;
  font-weight: 600;
  letter-spacing: .07em;
  text-transform: uppercase;
  color: var(--sidebar-text);
  padding: 0 4px 4px;
  opacity: .6;
}

.label-action {
  font-size: 11px;
  font-weight: 500;
  text-transform: none;
  letter-spacing: 0;
  color: #6c6c70;
  opacity: 1;
  transition: color var(--transition);
}
.label-action:hover { color: #98989f; }

.sidebar-list { display: flex; flex-direction: column; gap: 1px; }

.empty-list {
  font-size: 12px;
  color: var(--sidebar-text);
  opacity: .4;
  padding: 4px 6px;
}

/* Session items */
.session-item {
  display: flex;
  align-items: center;
  border-radius: var(--radius-sm);
  transition: background var(--transition);
  min-width: 0;
}
.session-item:hover { background: var(--sidebar-hover); }
.session-item.active { background: var(--sidebar-active); }

.session-item-info {
  flex: 1;
  padding: 6px 8px;
  min-width: 0;
  cursor: pointer;
}

.session-item-name {
  font-size: 12.5px;
  font-weight: 500;
  color: #d1d1d6;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.session-item-meta {
  font-size: 11px;
  color: var(--sidebar-text);
  margin-top: 1px;
  opacity: .7;
}

/* Inline name editing on active session */
.session-name-edit {
  flex: 1;
  background: none;
  border: none;
  color: #e5e5ea;
  font-size: 12.5px;
  font-weight: 500;
  padding: 6px 8px;
  width: 100%;
  min-width: 0;
  cursor: default;
  outline: none;
}
.session-name-edit::placeholder { color: #636366; font-weight: 400; }
.session-name-edit:focus { cursor: text; }
.session-item.active:focus-within { background: #444446; }

.session-item-del {
  padding: 4px 7px;
  color: var(--sidebar-text);
  opacity: 0;
  font-size: 16px;
  border-radius: 4px;
  line-height: 1;
  transition: opacity var(--transition), color var(--transition);
  flex-shrink: 0;
}
.session-item:hover .session-item-del { opacity: 1; }
.session-item-del:hover { color: #ff453a; }

/* ── Client group hierarchy ───────────────────────────────────────────────── */

.client-group-header {
  display: flex;
  align-items: center;
  gap: 5px;
  padding: 9px 6px 3px;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: .03em;
  color: #b6b6bd;
  cursor: pointer;
  border-radius: 4px;
  user-select: none;
  transition: color var(--transition);
}
.client-group-header:hover { color: #e5e5ea; }

/* ── Session search ───────────────────────────────────────────────────────── */

.sidebar-section-sessions { flex: 1; min-height: 0; }

.session-search {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 5px 9px;
  margin-bottom: 6px;
  background: rgba(255,255,255,.06);
  border: 1px solid rgba(255,255,255,.08);
  border-radius: 7px;
  color: #6c6c70;
}
.session-search:focus-within { border-color: rgba(0,122,255,.5); color: #98989f; }
.session-search svg { flex-shrink: 0; opacity: .8; }
.session-search input {
  flex: 1;
  min-width: 0;
  background: none;
  border: none;
  outline: none;
  color: #e5e5ea;
  font-size: 12.5px;
}
.session-search input::placeholder { color: #6c6c70; }
.session-search-clear {
  flex-shrink: 0;
  color: #98989f;
  font-size: 15px;
  line-height: 1;
  padding: 0 2px;
  border-radius: 3px;
}
.session-search-clear:hover { color: #e5e5ea; }

.client-arrow {
  flex-shrink: 0;
  display: inline-flex;
  transition: transform .2s;
  opacity: .7;
}
.client-arrow.collapsed { transform: rotate(-90deg); }

.client-name {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.client-add-case {
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 20px;
  height: 20px;
  border-radius: 5px;
  color: var(--sidebar-text);
  opacity: 0;
  transition: opacity var(--transition), background var(--transition), color var(--transition);
}
.client-group-header:hover .client-add-case { opacity: .8; }
.client-add-case:hover { opacity: 1 !important; background: rgba(255,255,255,.1); color: #e5e5ea; }

.new-case-form { margin-left: 12px; padding-top: 6px; }

.session-indented {
  margin-left: 12px;
  width: calc(100% - 12px);
}

/* ── New session inline form ──────────────────────────────────────────────── */

.new-session-form {
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding: 4px 0 10px;
  border-bottom: 1px solid var(--sidebar-border);
  margin-bottom: 4px;
}

.new-session-input {
  width: 100%;
  background: rgba(255,255,255,.07);
  border: 1px solid rgba(255,255,255,.1);
  border-radius: 6px;
  color: #e5e5ea;
  font-size: 12.5px;
  padding: 6px 9px;
  outline: none;
  transition: border-color var(--transition), background var(--transition);
}
.new-session-input::placeholder { color: #4a4a4e; font-weight: 400; }
.new-session-input:focus {
  border-color: rgba(0,122,255,.5);
  background: rgba(255,255,255,.1);
}

/* Template items */
.template-item { border-radius: var(--radius-sm); }

.template-btn {
  display: block;
  width: 100%;
  text-align: left;
  padding: 6px 10px;
  font-size: 12.5px;
  color: #636366;
  border-radius: var(--radius-sm);
  transition: background var(--transition), color var(--transition);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.template-btn:hover { background: var(--sidebar-hover); color: #98989f; }

/* Sidebar footer */
.sidebar-footer {
  padding: 8px 10px 12px;
  border-top: 1px solid var(--sidebar-border);
  min-width: var(--sidebar-w);
}

.sidebar-settings-btn {
  display: flex;
  align-items: center;
  gap: 7px;
  width: 100%;
  padding: 7px 10px;
  color: var(--sidebar-text);
  border-radius: var(--radius-sm);
  font-size: 13px;
  transition: background var(--transition), color var(--transition);
}
.sidebar-settings-btn:hover { background: var(--sidebar-hover); color: #98989f; }

/* ── Main ─────────────────────────────────────────────────────────────────── */

.main {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  background: var(--main-bg);
  min-width: 0;
  transition: padding-left var(--transition);
  position: relative;
}

/* Drag-and-drop overlay over the chat area */
.drop-overlay {
  position: absolute;
  inset: 0;
  z-index: 50;
  display: none;
  align-items: center;
  justify-content: center;
  background: rgba(0,122,255,.06);
  backdrop-filter: blur(1px);
  -webkit-backdrop-filter: blur(1px);
}
.drop-overlay.show { display: flex; }
.drop-overlay-inner {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  padding: 28px 44px;
  border: 2px dashed var(--accent);
  border-radius: var(--radius-lg);
  background: #fff;
  color: var(--accent);
  font-size: 15px;
  font-weight: 600;
  box-shadow: var(--shadow-md);
  pointer-events: none;
}

/* Messages */
.messages {
  flex: 1;
  overflow-y: auto;
  padding: 32px 0 16px;
  scroll-behavior: smooth;
}
.messages::-webkit-scrollbar { width: 5px; }
.messages::-webkit-scrollbar-thumb { background: #d1d1d6; border-radius: 4px; }

.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  height: 100%;
  gap: 14px;
  color: var(--text-muted);
  text-align: center;
  padding: 40px;
}
.empty-state-icon { font-size: 36px; line-height: 1; opacity: .5; }
.empty-state-mark { color: var(--text-faint); opacity: .7; margin-bottom: 2px; }
.empty-state h2 { font-size: 20px; font-weight: 600; color: var(--text); opacity: .5; letter-spacing: -.02em; }
.empty-state p { font-size: 14px; max-width: 360px; line-height: 1.6; opacity: .7; }

/* Message bubbles */
.message {
  display: flex;
  gap: 12px;
  padding: 4px 24px;
  max-width: 820px;
  margin: 0 auto;
  width: 100%;
  flex-direction: column;
}

.message-row {
  display: flex;
  gap: 12px;
  align-items: flex-start;
}

.message-avatar {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 11px;
  font-weight: 700;
  flex-shrink: 0;
  margin-top: 2px;
  letter-spacing: .01em;
}

.message-user .message-avatar {
  background: #3a3a3c;
  color: #aeaeb2;
}

.message-assistant .message-avatar {
  background: #1c1c1e;
  color: #e5e5ea;
  font-size: 10px;
}

.message-content {
  flex: 1;
  min-width: 0;
  font-size: 14px;
  line-height: 1.7;
  padding: 9px 13px;
  border-radius: var(--radius);
}

.message-user .message-content {
  background: var(--msg-user-bg);
  color: var(--text);
  border-bottom-left-radius: 4px;
}

.message-assistant .message-content {
  background: var(--msg-ai-bg);
  color: var(--text);
  box-shadow: 0 1px 4px rgba(0,0,0,.06);
  border-bottom-left-radius: 4px;
}

/* Which model produced an assistant reply — small, muted, non-interactive.
   Indented 40px to sit under the message text (past the avatar column). */
.model-label {
  margin: 5px 0 0 40px;
  font-size: 11px;
  color: var(--text-faint);
  letter-spacing: .02em;
  user-select: none;
}

/* The message-bar model dropdown is disabled while automatic routing is on —
   dim it and show a not-allowed cursor. */
.model-select:disabled { opacity: .5; cursor: not-allowed; }

/* Markdown inside messages */
.message-content h1, .message-content h2, .message-content h3 {
  margin: 1em 0 .4em;
  font-weight: 600;
  line-height: 1.3;
  letter-spacing: -.01em;
}
.message-content h1 { font-size: 1.2em; }
.message-content h2 { font-size: 1.05em; }
.message-content h3 { font-size: 1em; }
.message-content p { margin: .55em 0; }
.message-content p:first-child { margin-top: 0; }
.message-content p:last-child { margin-bottom: 0; }
.message-content ul, .message-content ol { margin: .55em 0 .55em 1.4em; }
.message-content li { margin: .2em 0; }
.message-content code {
  font-family: 'SF Mono', 'Consolas', monospace;
  font-size: .86em;
  background: rgba(0,0,0,.06);
  padding: 1px 5px;
  border-radius: 4px;
}
.message-content pre {
  background: #1c1c1e;
  color: #e5e5ea;
  border-radius: var(--radius-sm);
  padding: 14px 16px;
  margin: .7em 0;
  overflow-x: auto;
}
.message-content pre code { background: none; padding: 0; color: inherit; font-size: .84em; }
.message-content blockquote {
  border-left: 3px solid #c7c7cc;
  padding-left: 12px;
  color: var(--text-muted);
  margin: .6em 0;
}
.message-content table { border-collapse: collapse; width: 100%; margin: .7em 0; font-size: .92em; }
.message-content th, .message-content td { border: 1px solid #e5e5ea; padding: 6px 10px; text-align: left; }
.message-content th { background: #f2f2f7; font-weight: 600; }
.message-content a { color: var(--accent); }
.message-content strong { font-weight: 600; }

/* "Thinking…" indicator (assistant working, no text yet) */
.thinking-indicator {
  color: var(--text-muted);
  font-size: 14px;
  animation: thinkingPulse 1.4s ease-in-out infinite;
}
@keyframes thinkingPulse {
  0%, 100% { opacity: .4; }
  50%      { opacity: 1; }
}

/* Streaming cursor */
.message-content.streaming > *:last-child:not(.thinking-indicator)::after {
  content: '▋';
  display: inline;
  color: var(--accent);
  animation: blink .9s step-start infinite;
}
@keyframes blink { 0%, 100% { opacity: 1; } 50% { opacity: 0; } }

/* Document attachment chip (shown inside a sent message) */
.doc-attachment {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 3px 9px;
  background: var(--chip-bg);
  border-radius: var(--radius-pill);
  font-size: 12px;
  color: var(--text-muted);
  font-weight: 500;
  margin-bottom: 6px;
}

.doc-downloadable, .doc-viewable { cursor: pointer; transition: background var(--transition); }
.doc-downloadable:hover, .doc-viewable:hover { background: var(--chip-bg-hover); }
.doc-dl { margin-left: 3px; opacity: 0; transition: opacity var(--transition); }
.doc-downloadable:hover .doc-dl, .doc-viewable:hover .doc-dl { opacity: .85; }

/* Error message */
.error-msg {
  max-width: 820px;
  margin: 6px auto;
  padding: 10px 16px;
  background: rgba(255,59,48,.08);
  border: 1px solid rgba(255,59,48,.2);
  border-radius: var(--radius-sm);
  color: #ff3b30;
  font-size: 13px;
}

/* ── Input area ───────────────────────────────────────────────────────────── */

.input-area {
  flex-shrink: 0;
  padding: 0 20px 20px;
  max-width: 820px;
  margin: 0 auto;
  width: 100%;
}

.input-shell {
  background: var(--input-bg);
  border-radius: var(--radius-lg);
  box-shadow: var(--input-shadow);
  display: flex;
  flex-direction: column;
  padding: 12px 12px 8px;
  transition: box-shadow var(--transition);
}
.input-shell:focus-within {
  box-shadow: 0 2px 20px rgba(0,0,0,.1), 0 0 0 1px rgba(0,122,255,.25);
}

.pending-files {
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
  margin-bottom: 8px;
}

.message-input {
  width: 100%;
  min-height: 24px;
  max-height: 180px;
  border: none;
  background: none;
  color: var(--text);
  resize: none;
  line-height: 1.6;
  font-size: 14px;
  outline: none;
  overflow-y: auto;
}
.message-input::placeholder { color: var(--text-faint); }

.input-shell-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-top: 8px;
  gap: 8px;
}

/* Attach button & menu */
.attach-wrapper { position: relative; }

.btn-attach {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 30px;
  height: 30px;
  border-radius: 8px;
  color: var(--text-muted);
  transition: background var(--transition), color var(--transition);
}
.btn-attach:hover { background: #f2f2f7; color: var(--text); }
.btn-attach.active { background: #f2f2f7; color: var(--accent); }

.attach-menu {
  position: absolute;
  bottom: calc(100% + 6px);
  left: 0;
  background: #ffffff;
  border: 1px solid #e5e5ea;
  border-radius: var(--radius);
  box-shadow: 0 8px 24px rgba(0,0,0,.12);
  padding: 4px;
  min-width: 170px;
  z-index: 100;
}

.attach-menu-item {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  padding: 8px 10px;
  border-radius: var(--radius-sm);
  font-size: 13px;
  color: var(--text);
  transition: background var(--transition);
  text-align: left;
}
.attach-menu-item:hover { background: #f2f2f7; }

/* Claim mapping button */
.btn-claimmap {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  height: 30px;
  padding: 0 11px;
  border-radius: var(--radius-pill);
  font-size: 12.5px;
  font-weight: 500;
  color: var(--accent);
  background: rgba(0,122,255,.08);
  transition: background var(--transition);
  white-space: nowrap;
}
.btn-claimmap:hover { background: rgba(0,122,255,.15); }

/* Right side of input footer */
.input-shell-right {
  display: flex;
  align-items: center;
  gap: 6px;
}

.model-select {
  border: none;
  background: none;
  color: var(--text-faint);
  font-size: 12px;
  cursor: pointer;
  padding: 4px 6px;
  border-radius: 6px;
  transition: color var(--transition), background var(--transition);
  outline: none;
  appearance: none;
  -webkit-appearance: none;
}
.model-select:hover { background: #f2f2f7; color: var(--text-muted); }

.btn-send {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  background: var(--text);
  color: #fff;
  border-radius: 10px;
  transition: background var(--transition), opacity var(--transition);
  flex-shrink: 0;
}
.btn-send:hover:not(:disabled) { background: #3a3a3c; }
.btn-send:disabled { opacity: .3; cursor: not-allowed; }
.btn-send.has-text { background: var(--accent); }
.btn-send.has-text:hover:not(:disabled) { background: var(--accent-h); }

/* File chips (pending attachments above the message box) */
.file-chip {
  display: flex;
  align-items: center;
  gap: 5px;
  padding: 3px 8px 3px 9px;
  background: var(--chip-bg);
  border-radius: var(--radius-pill);
  font-size: 12px;
  color: var(--text-muted);
  font-weight: 500;
}

.file-chip-del {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: var(--chip-del-bg);
  color: var(--text-muted);
  font-size: 11px;
  line-height: 1;
  transition: background var(--transition);
}
.file-chip-del:hover { background: var(--chip-del-hover); }

/* Small TXT / TEXT badge that marks a chip as prior-art or pasted text. The
   label tells you the kind; the colour is intentionally neutral. */
.file-chip-txt-badge, .doc-attachment-txt-badge,
.file-chip-paste-badge, .doc-attachment-paste-badge {
  display: inline-block;
  font-size: 8px;
  font-weight: 700;
  background: var(--chip-badge);
  color: #fff;
  border-radius: 3px;
  padding: 1px 3px;
  letter-spacing: .4px;
}

/* ── Paste-to-attachment (pasted-text chips + read-only viewer) ───────────── */
/* Chips share the neutral grey look above; the only extras here are making a
   pending pasted-text chip clickable and the read-only viewer modal. */

.file-chip-clickable { cursor: pointer; transition: background var(--transition); }
.file-chip-clickable:hover { background: var(--chip-bg-hover); }

/* Read-only viewer modal */
.modal-textviewer { width: 640px; }
.text-viewer-content {
  margin: 0;
  white-space: pre-wrap;
  word-break: break-word;
  font-family: inherit;
  font-size: 13px;
  line-height: 1.55;
  color: var(--text);
}

/* ── Modals ───────────────────────────────────────────────────────────────── */

.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.4);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  opacity: 0;
  pointer-events: none;
  transition: opacity .2s;
}
.modal-overlay.open { opacity: 1; pointer-events: all; }

.modal {
  background: #ffffff;
  border-radius: 16px;
  box-shadow: 0 20px 60px rgba(0,0,0,.2);
  width: 480px;
  max-width: calc(100vw - 32px);
  max-height: calc(100vh - 64px);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
.modal-wide { width: 680px; }

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 18px 20px 14px;
  border-bottom: 1px solid #f2f2f7;
}
.modal-header h2 { font-size: 16px; font-weight: 600; letter-spacing: -.01em; }

.modal-close {
  width: 28px;
  height: 28px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 20px;
  color: var(--text-muted);
  border-radius: 6px;
  transition: background var(--transition);
  line-height: 1;
}
.modal-close:hover { background: #f2f2f7; }

.modal-body {
  flex: 1;
  overflow-y: auto;
  padding: 18px 20px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.modal-footer {
  padding: 12px 20px 16px;
  border-top: 1px solid #f2f2f7;
  display: flex;
  justify-content: flex-end;
  gap: 8px;
}

/* Fields */
.field { display: flex; flex-direction: column; gap: 5px; }
.field label { font-size: 13px; font-weight: 500; color: var(--text); }
.optional { font-weight: 400; color: var(--text-muted); }

.field input, .field textarea, .field select {
  padding: 8px 10px;
  border: 1px solid #e5e5ea;
  border-radius: var(--radius-sm);
  color: var(--text);
  background: #f9f9fb;
  transition: border-color var(--transition), box-shadow var(--transition);
  font-size: 13.5px;
}
.field input:focus, .field textarea:focus, .field select:focus {
  outline: none;
  border-color: var(--accent);
  background: #fff;
  box-shadow: 0 0 0 3px rgba(0,122,255,.12);
}
.field textarea { resize: vertical; line-height: 1.5; }

.field-hint { font-size: 11.5px; color: var(--text-muted); line-height: 1.5; }
.field-hint code { font-family: 'SF Mono', Consolas, monospace; font-size: .88em; background: #f2f2f7; padding: 1px 4px; border-radius: 3px; }

/* Buttons */
.btn-primary {
  padding: 8px 16px;
  background: var(--accent);
  color: #fff;
  border-radius: var(--radius-sm);
  font-size: 13px;
  font-weight: 500;
  transition: background var(--transition);
}
.btn-primary:hover { background: var(--accent-h); }
.btn-primary:disabled { opacity: .4; cursor: not-allowed; }

.btn-secondary {
  padding: 8px 16px;
  background: #f2f2f7;
  color: var(--text);
  border-radius: var(--radius-sm);
  font-size: 13px;
  font-weight: 500;
  transition: background var(--transition);
}
.btn-secondary:hover { background: #e5e5ea; }

.btn-sm { padding: 5px 10px !important; font-size: 12px !important; }

/* Settings-specific */
.settings-divider { border: none; border-top: 1px solid #f2f2f7; margin: 2px 0; }

.settings-section-label {
  font-size: 11px;
  font-weight: 600;
  letter-spacing: .07em;
  text-transform: uppercase;
  color: var(--text-muted);
  padding-bottom: 2px;
}

/* Section label with a trailing "see details" link (API usage) */
.usage-label-row { display: flex; align-items: center; justify-content: space-between; }
.settings-link-btn {
  font-size: 11px;
  font-weight: 500;
  letter-spacing: 0;
  text-transform: none;
  color: var(--accent);
  cursor: pointer;
}
.settings-link-btn:hover { text-decoration: underline; }

/* Login overlay */
.login-overlay {
  position: fixed; inset: 0; z-index: 3000;
  display: flex; align-items: center; justify-content: center;
  background: var(--main-bg);
}
.login-card {
  display: flex; flex-direction: column; gap: 12px;
  width: 320px; max-width: calc(100vw - 32px);
  padding: 28px 26px;
  background: #fff;
  border: 1px solid #e5e5ea;
  border-radius: 16px;
  box-shadow: 0 12px 40px rgba(0,0,0,.1);
}
.login-brand {
  display: flex; align-items: center; gap: 9px;
  font-size: 16px; font-weight: 600; letter-spacing: -.01em;
  color: var(--text); margin-bottom: 6px; justify-content: center;
}
.login-brand svg { opacity: .7; }
.login-input {
  padding: 10px 12px;
  border: 1px solid #d1d1d6; border-radius: var(--radius-sm);
  font-size: 14px; background: #f9f9fb; color: var(--text);
  outline: none; transition: border-color var(--transition), box-shadow var(--transition);
}
.login-input:focus { border-color: var(--accent); background: #fff; box-shadow: 0 0 0 3px rgba(0,122,255,.12); }
.login-submit { margin-top: 4px; padding: 10px; font-size: 14px; }
.login-error {
  font-size: 12.5px; color: var(--danger);
  background: rgba(255,59,48,.06); border: 1px solid rgba(255,59,48,.2);
  border-radius: var(--radius-sm); padding: 7px 10px;
}

/* Usage panel */
.usage-panel { display: flex; flex-direction: column; gap: 8px; font-size: 13px; }
.usage-uval.warn { color: #b45309; }
.usage-uval.over { color: var(--danger); font-weight: 600; }

.usage-headline { display: flex; align-items: baseline; gap: 8px; }
.usage-total { font-size: 22px; font-weight: 600; letter-spacing: -.02em; }
.usage-sub { font-size: 12px; color: var(--text-muted); }

.usage-bar {
  height: 7px;
  background: #e5e5ea;
  border-radius: 4px;
  overflow: hidden;
}
.usage-bar-fill {
  height: 100%;
  background: var(--accent);
  border-radius: 4px;
}
.usage-bar-fill.warn { background: #f59e0b; }
.usage-bar-fill.over { background: var(--danger); }

.usage-flag {
  font-size: 12px;
  font-weight: 500;
  color: #92400e;
  background: #fffbeb;
  border: 1px solid #fde68a;
  border-radius: var(--radius-sm);
  padding: 6px 9px;
}
.usage-flag.over { color: var(--danger); background: rgba(255,59,48,.06); border-color: rgba(255,59,48,.25); }

.usage-break { display: flex; flex-direction: column; gap: 2px; margin-top: 2px; }
.usage-break-title {
  font-size: 10px; font-weight: 600; text-transform: uppercase; letter-spacing: .06em;
  color: var(--text-faint); margin-bottom: 2px;
}
.usage-row {
  display: flex; justify-content: space-between; gap: 10px;
  font-size: 12.5px; color: var(--text); padding: 2px 0;
  border-bottom: 1px solid #f2f2f7;
}
.usage-row:last-child { border-bottom: none; }
.usage-row span:last-child { color: var(--text-muted); font-variant-numeric: tabular-nums; white-space: nowrap; }
.usage-empty { font-size: 12px; color: var(--text-faint); }

/* Settings drill-down rows */
.settings-nav-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: 100%;
  padding: 11px 12px;
  border-radius: var(--radius-sm);
  font-size: 14px;
  font-weight: 500;
  color: var(--text);
  background: #f9f9fb;
  transition: background var(--transition);
}
.settings-nav-row:hover { background: #f2f2f7; }
.settings-nav-row svg { color: var(--text-faint); }

.settings-back-row {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 8px 4px 4px;
  margin-bottom: 12px;
  font-size: 13px;
  font-weight: 500;
  color: var(--text-muted);
  border-radius: 6px;
  transition: color var(--transition);
}
.settings-back-row:hover { color: var(--text); }

/* Toggle switch */
.field-toggle {
  flex-direction: row;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
}
.toggle-label {
  display: flex;
  flex-direction: column;
  gap: 3px;
  font-size: 13px;
  font-weight: 500;
  flex: 1;
}
.toggle-desc { font-size: 11.5px; font-weight: 400; color: var(--text-muted); line-height: 1.5; }
.toggle-switch { flex-shrink: 0; position: relative; display: inline-block; width: 38px; height: 22px; margin-top: 1px; }
.toggle-switch input { opacity: 0; width: 0; height: 0; }
.toggle-track {
  position: absolute; inset: 0;
  background: #c7c7cc;
  border-radius: 22px;
  cursor: pointer;
  transition: background var(--transition);
}
.toggle-track::after {
  content: '';
  position: absolute;
  top: 3px; left: 3px;
  width: 16px; height: 16px;
  background: #fff;
  border-radius: 50%;
  transition: transform var(--transition);
  box-shadow: 0 1px 3px rgba(0,0,0,.2);
}
.toggle-switch input:checked + .toggle-track { background: var(--accent); }
.toggle-switch input:checked + .toggle-track::after { transform: translateX(16px); }

/* Template manager */
.template-manager-list { display: flex; flex-direction: column; gap: 14px; }

.template-row {
  display: flex; flex-direction: column; gap: 6px;
  padding: 12px;
  border: 1px solid #e5e5ea;
  border-radius: var(--radius);
  background: #f9f9fb;
}
.template-row-header { display: flex; align-items: center; gap: 8px; }

.template-name-input {
  flex: 1; padding: 6px 9px;
  border: 1px solid #e5e5ea; border-radius: var(--radius-sm);
  font-size: 13px; font-weight: 600;
  background: #fff; color: var(--text);
  transition: border-color var(--transition);
}
.template-name-input:focus { outline: none; border-color: var(--accent); }

.template-text-input {
  padding: 7px 9px;
  border: 1px solid #e5e5ea; border-radius: var(--radius-sm);
  font-size: 12.5px; background: #fff; color: var(--text);
  resize: vertical; min-height: 80px; line-height: 1.5;
  transition: border-color var(--transition);
}
.template-text-input:focus { outline: none; border-color: var(--accent); }

.btn-del-template {
  padding: 5px 10px;
  background: rgba(255,59,48,.08);
  color: var(--danger);
  border: 1px solid rgba(255,59,48,.2);
  border-radius: var(--radius-sm);
  font-size: 12px; font-weight: 500;
  transition: background var(--transition);
}
.btn-del-template:hover { background: rgba(255,59,48,.15); }

.btn-add-template {
  display: inline-flex; align-items: center; gap: 6px;
  margin-top: 4px; font-size: 13px; color: var(--text-muted);
}
.btn-add-template:hover { color: var(--text); }

/* ── Toolkit (Templates) modal ───────────────────────────────────────────── */

.modal-toolkit {
  width: 540px;
  max-height: calc(100vh - 80px);
}

.toolkit-body {
  display: flex;
  flex-direction: column;
  overflow: hidden;
  flex: 1;
}

.toolkit-list {
  flex: 1;
  overflow-y: auto;
  padding: 8px 0;
  min-height: 60px;
  max-height: 340px;
}
.toolkit-list::-webkit-scrollbar { width: 4px; }
.toolkit-list::-webkit-scrollbar-thumb { background: #e5e5ea; border-radius: 4px; }

.toolkit-empty {
  font-size: 13px;
  color: var(--text-faint);
  padding: 16px 20px;
  text-align: center;
}

.toolkit-item {
  display: flex;
  align-items: center;
  padding: 2px 20px;
  gap: 8px;
  transition: background var(--transition);
}
.toolkit-item:hover { background: #f9f9fb; }

.toolkit-item-info {
  flex: 1;
  min-width: 0;
  cursor: pointer;
  padding: 8px 0;
}
.toolkit-item-name {
  font-size: 13.5px;
  font-weight: 500;
  color: var(--text);
  margin-bottom: 2px;
}
.toolkit-item-preview {
  font-size: 12px;
  color: var(--text-faint);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.toolkit-item-del {
  flex-shrink: 0;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 14px;
  color: var(--text-faint);
  opacity: 0;
  transition: opacity var(--transition), color var(--transition), background var(--transition);
}
.toolkit-item:hover .toolkit-item-del { opacity: 1; }
.toolkit-item-del:hover { color: var(--danger); background: rgba(255,59,48,.08); }

/* Add template form */
.toolkit-add {
  border-top: 1px solid #f2f2f7;
  padding: 16px 20px 20px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.toolkit-add-label {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .07em;
  color: var(--text-faint);
  margin-bottom: 2px;
}

.toolkit-input {
  padding: 8px 10px;
  border: 1px solid #e5e5ea;
  border-radius: var(--radius-sm);
  font-size: 13.5px;
  color: var(--text);
  background: #f9f9fb;
  transition: border-color var(--transition), box-shadow var(--transition);
  outline: none;
}
.toolkit-input:focus {
  border-color: var(--accent);
  background: #fff;
  box-shadow: 0 0 0 3px rgba(0,122,255,.1);
}

.toolkit-textarea {
  padding: 8px 10px;
  border: 1px solid #e5e5ea;
  border-radius: var(--radius-sm);
  font-size: 13px;
  color: var(--text);
  background: #f9f9fb;
  resize: vertical;
  line-height: 1.55;
  min-height: 90px;
  outline: none;
  font-family: inherit;
  transition: border-color var(--transition), box-shadow var(--transition);
}
.toolkit-textarea:focus {
  border-color: var(--accent);
  background: #fff;
  box-shadow: 0 0 0 3px rgba(0,122,255,.1);
}

.toolkit-add-footer {
  display: flex;
  justify-content: flex-end;
}

/* ── EP Wrapper modal ─────────────────────────────────────────────────────── */

.modal-fw { width: 640px; max-height: calc(100vh - 48px); }

.fw-header-left { display: flex; align-items: center; gap: 16px; }

.fw-step-indicator { display: flex; align-items: center; }

.fw-step-dot {
  width: 22px; height: 22px; border-radius: 50%;
  border: 2px solid #e5e5ea;
  background: #fff; color: var(--text-muted);
  font-size: 10px; font-weight: 700;
  display: flex; align-items: center; justify-content: center;
  transition: background .2s, border-color .2s, color .2s;
}
.fw-step-dot.active { border-color: var(--accent); background: var(--accent); color: #fff; }
.fw-step-dot.done  { border-color: #34c759; background: #34c759; color: #fff; }
.fw-step-line { width: 20px; height: 2px; background: #e5e5ea; }

.fw-step-panel { display: flex; flex-direction: column; gap: 12px; }
.fw-step-panel.modal-body { padding: 18px 20px; overflow-y: auto; }

#fwStep3 { display: flex; flex-direction: column; overflow: hidden; max-height: calc(100vh - 220px); }

.fw-step-heading { font-size: 14px; font-weight: 600; color: var(--text); }

.fw-app-row { display: flex; gap: 8px; }
.fw-app-input {
  flex: 1; padding: 8px 10px;
  border: 1px solid #e5e5ea; border-radius: var(--radius-sm);
  font-size: 14px; color: var(--text); background: #f9f9fb;
  transition: border-color var(--transition);
}
.fw-app-input:focus { outline: none; border-color: var(--accent); background: #fff; }

.fw-biblio-card {
  background: #f9f9fb; border: 1px solid #e5e5ea;
  border-radius: var(--radius); padding: 12px 14px; font-size: 13px;
}
.fw-biblio-grid { display: flex; flex-direction: column; gap: 6px; }
.fw-biblio-row { display: flex; gap: 10px; }
.fw-biblio-label {
  width: 80px; flex-shrink: 0;
  font-size: 11px; font-weight: 600; text-transform: uppercase; letter-spacing: .05em;
  color: var(--text-muted); padding-top: 1px;
}
.fw-biblio-val { color: var(--text); line-height: 1.5; }
.fw-appnum { font-weight: 700; color: var(--accent); font-size: 14px; }
.fw-ipc { font-family: 'SF Mono', Consolas, monospace; font-size: .85em; background: #f2f2f7; padding: 1px 5px; border-radius: 4px; }
.fw-register-link { color: var(--accent); font-weight: 600; text-decoration: none; font-size: 13px; }
.fw-register-link:hover { text-decoration: underline; }
.fw-link-btn { color: var(--accent); font-size: inherit; text-decoration: underline; cursor: pointer; }

.fw-drop-zone {
  border: 2px dashed #d1d1d6; border-radius: var(--radius);
  padding: 32px 20px; text-align: center; cursor: pointer;
  transition: border-color var(--transition), background var(--transition);
  display: flex; flex-direction: column; align-items: center; gap: 10px;
  color: var(--text-muted);
}
.fw-drop-zone:hover, .fw-drop-zone.drag-over { border-color: var(--accent); background: rgba(0,122,255,.04); color: var(--accent); }
.fw-drop-zone.has-file { border-color: #34c759; background: rgba(52,199,89,.04); color: #1a7f37; }
.fw-drop-label { font-size: 13px; }
.fw-drop-link { color: var(--accent); text-decoration: underline; }

.fw-parse-status { padding: 8px 12px; border-radius: var(--radius-sm); font-size: 13px; }
.fw-parse-status.fw-loading { background: rgba(0,122,255,.08); color: var(--accent); }
.fw-parse-status.fw-ok      { background: rgba(52,199,89,.08); color: #1a7f37; }
.fw-parse-status.fw-error   { background: rgba(255,59,48,.08); color: var(--danger); }

.fw-doc-toolbar {
  display: flex; align-items: center; gap: 6px;
  padding: 10px 14px; border-bottom: 1px solid #f2f2f7;
  flex-shrink: 0; flex-wrap: wrap;
}
.fw-sel-count { font-size: 12px; color: var(--text-muted); margin-left: auto; }

.fw-doc-list { overflow-y: auto; flex: 1; padding: 8px 0; }
.fw-doc-list::-webkit-scrollbar { width: 4px; }
.fw-doc-list::-webkit-scrollbar-thumb { background: #e5e5ea; border-radius: 4px; }

.fw-cat-section { margin-bottom: 4px; }
.fw-cat-header {
  display: flex; align-items: center; gap: 7px; padding: 6px 14px;
  font-size: 10px; font-weight: 700; text-transform: uppercase; letter-spacing: .07em;
  color: var(--text-muted); background: #f9f9fb; position: sticky; top: 0; z-index: 1;
}
.fw-cat-dot { width: 7px; height: 7px; border-radius: 50%; flex-shrink: 0; }
.fw-cat-count { margin-left: auto; background: #e5e5ea; color: var(--text-muted); border-radius: 10px; padding: 1px 7px; font-size: 10px; }

.fw-doc-row {
  display: flex; align-items: center; gap: 10px; padding: 6px 14px;
  cursor: pointer; transition: background var(--transition); font-size: 13px; line-height: 1.4;
}
.fw-doc-row:hover { background: #f9f9fb; }
.fw-doc-row input[type=checkbox] { width: 15px; height: 15px; flex-shrink: 0; cursor: pointer; accent-color: var(--accent); }
.fw-doc-date { width: 76px; flex-shrink: 0; font-size: 11.5px; color: var(--text-muted); font-variant-numeric: tabular-nums; }
.fw-doc-title { flex: 1; color: var(--text); }
.fw-doc-pages { font-size: 11px; color: var(--text-faint); flex-shrink: 0; }

.fw-loading { font-size: 13px; color: var(--text-muted); }
.fw-error   { font-size: 13px; color: var(--danger); background: rgba(255,59,48,.08); padding: 8px 10px; border-radius: 6px; }

.fw-cit-label { font-size: 11px; font-weight: 700; color: #f97316; letter-spacing: .3px; white-space: nowrap; }
.fw-cit-statuswrap { display: flex; align-items: center; gap: 4px; min-width: 90px; justify-content: flex-end; }
.fw-cit-status { font-size: 11px; white-space: nowrap; }
.fw-cit-link { font-size: 11px; color: var(--accent); text-decoration: none; white-space: nowrap; }
.fw-cit-link:hover { text-decoration: underline; }
.fw-cit-scan-status { font-size: 12px; color: var(--text-muted); padding: 10px 6px; font-style: italic; }
.fw-fetch-all-btn { margin-left: auto; font-size: 11px !important; padding: 2px 8px !important; }

/* ── File wrapper summary card ────────────────────────────────────────────── */

.fw-summary-card {
  max-width: 820px; margin: 0 auto 4px; width: 100%; padding: 0 24px;
}
.fw-summary-card > div {
  background: rgba(0,122,255,.06); border: 1px solid rgba(0,122,255,.15);
  border-radius: var(--radius); padding: 12px 16px;
}
.fw-summary-head { display: flex; gap: 10px; align-items: flex-start; }
.fw-summary-icon { font-size: 18px; line-height: 1.4; flex-shrink: 0; }
.fw-summary-title { font-size: 13.5px; font-weight: 600; color: #0056cc; margin-bottom: 3px; }
.fw-summary-meta { display: flex; flex-wrap: wrap; gap: 8px; font-size: 12px; color: var(--accent); }
.fw-summary-meta span::before { content: '·'; margin-right: 8px; }
.fw-summary-meta span:first-child::before { content: ''; margin: 0; }
.fw-summary-docs { margin-top: 8px; font-size: 12px; color: var(--accent); display: flex; flex-wrap: wrap; gap: 4px; align-items: center; }
.fw-summary-docs strong { color: #0056cc; margin-right: 4px; }
.fw-summary-doc-chip {
  display: inline-flex; align-items: center; gap: 4px;
  padding: 2px 8px; border-radius: 12px; border: 1px solid currentColor;
  font-size: 11.5px; opacity: .85;
}
.fw-summary-doc-chip em { font-style: normal; opacity: .7; }

/* ── Guidelines / Case Law panel ─────────────────────────────────────────── */

.gl-panel {
  margin-top: 6px;
  margin-left: 40px;
  max-width: calc(100% - 40px);
}

.gl-panel-header {
  display: flex; align-items: center; gap: 6px;
  padding: 5px 10px;
  border: 1px solid #e5e5ea; border-radius: var(--radius-sm);
  background: #f9f9fb; font-size: 12px; color: var(--text-muted);
  width: 100%; text-align: left;
  transition: background var(--transition), border-color var(--transition);
}
.gl-panel-header:hover { background: #f2f2f7; border-color: #c7c7cc; }
.gl-panel-header.gl-open { border-bottom-left-radius: 0; border-bottom-right-radius: 0; border-color: #c7c7cc; background: #f2f2f7; }

.gl-icon { opacity: .5; flex-shrink: 0; }
.gl-panel-label { flex: 1; font-weight: 500; }
.gl-chevron { flex-shrink: 0; opacity: .4; transition: transform .2s; }
.gl-panel-header.gl-open .gl-chevron { transform: rotate(180deg); }

.gl-warn-badge {
  font-size: 11px; font-weight: 600; color: #92400e;
  background: #fef3c7; border: 1px solid #fde68a;
  border-radius: 10px; padding: 1px 7px; white-space: nowrap;
}

.gl-panel-body {
  border: 1px solid #c7c7cc; border-top: none;
  border-bottom-left-radius: var(--radius-sm); border-bottom-right-radius: var(--radius-sm);
  background: #fff; padding: 8px 10px;
  display: flex; flex-direction: column; gap: 4px;
}

.gl-section-row {
  display: flex; align-items: baseline; gap: 8px;
  padding: 3px 0; font-size: 12px;
  border-bottom: 1px solid #f2f2f7;
}
.gl-section-row:last-child { border-bottom: none; }

.gl-citation {
  font-family: 'SF Mono', Consolas, monospace;
  font-size: 11px; font-weight: 700; color: var(--accent);
  white-space: nowrap; flex-shrink: 0; min-width: 80px;
}

.gl-heading { color: var(--text); flex: 1; }

.gl-unverified-list {
  margin-top: 6px; padding: 6px 8px;
  background: #fffbeb; border: 1px solid #fde68a; border-radius: var(--radius-sm);
  font-size: 11.5px; color: #92400e; display: flex; flex-wrap: wrap; gap: 6px; align-items: center;
}
.gl-unverified-label { font-weight: 600; }
.gl-unverified-cit {
  font-family: 'SF Mono', Consolas, monospace; font-size: 11px;
  background: #fef3c7; border: 1px solid #fde68a; border-radius: 4px; padding: 1px 5px;
}

/* ── Toast ────────────────────────────────────────────────────────────────── */

.notification {
  position: fixed; bottom: 24px; left: 50%;
  transform: translateX(-50%) translateY(10px);
  background: #1c1c1e; color: #e5e5ea;
  padding: 9px 18px; border-radius: var(--radius-pill);
  font-size: 13px; font-weight: 500;
  opacity: 0; pointer-events: none;
  transition: opacity .2s, transform .2s;
  z-index: 2000; white-space: nowrap;
}
.notification.show { opacity: 1; transform: translateX(-50%) translateY(0); }

/* ── Dark theme ───────────────────────────────────────────────────────────── */

:root.dark {
  --main-bg:       #18181a;
  --msg-user-bg:   #2c2c2e;
  --msg-ai-bg:     #242426;
  --input-bg:      #242426;
  --input-border:  #3a3a3c;
  --text:          #e8e8ea;
  --text-muted:    #9a9aa0;
  --text-faint:    #6a6a70;
  --input-shadow:  0 2px 16px rgba(0,0,0,.45), 0 0 0 1px rgba(255,255,255,.06);

  /* Chip greys, lightened so they read on the dark surfaces. */
  --chip-bg:        rgba(255,255,255,.07);
  --chip-bg-hover:  rgba(255,255,255,.12);
  --chip-badge:     #67676d;
  --chip-del-bg:    rgba(255,255,255,.1);
  --chip-del-hover: rgba(255,255,255,.18);
}

.dark .messages::-webkit-scrollbar-thumb { background: #3a3a3c; }

/* Message bubbles + markdown */
.dark .message-content code { background: rgba(255,255,255,.09); }
.dark .message-content th { background: #2a2a2c; }
.dark .message-content th, .dark .message-content td { border-color: #3a3a3c; }
.dark .message-content blockquote { border-left-color: #4a4a4e; }

/* Modals */
.dark .modal { background: #232325; box-shadow: 0 20px 60px rgba(0,0,0,.6); }
.dark .modal-header, .dark .modal-footer { border-color: #2f2f31; }
.dark .modal-close:hover { background: #2c2c2e; }
.dark .settings-divider { border-color: #2f2f31; }

/* Form fields */
.dark .field input, .dark .field textarea, .dark .field select,
.dark .toolkit-input, .dark .toolkit-textarea,
.dark .fw-app-input {
  background: #1c1c1e;
  border-color: #3a3a3c;
  color: var(--text);
}
.dark .field input:focus, .dark .field textarea:focus, .dark .field select:focus,
.dark .toolkit-input:focus, .dark .toolkit-textarea:focus {
  background: #242426;
}
.dark .field-hint code, .dark .toggle-desc code { background: rgba(255,255,255,.09); }
.dark .settings-nav-row { background: #2a2a2c; }
.dark .settings-nav-row:hover { background: #313133; }
.dark .toggle-track { background: #48484a; }

/* Buttons */
.dark .btn-secondary { background: #2c2c2e; color: var(--text); }
.dark .btn-secondary:hover { background: #38383a; }
.dark .btn-send { background: #3a3a3c; color: #e8e8ea; }
.dark .btn-send:hover:not(:disabled) { background: #48484a; }
.dark .btn-send.has-text { background: var(--accent); color: #fff; }
.dark .btn-attach:hover, .dark .btn-attach.active, .dark .model-select:hover { background: #2c2c2e; }

/* Attach menu */
.dark .attach-menu { background: #2a2a2c; border-color: #3a3a3c; }
.dark .attach-menu-item { color: var(--text); }
.dark .attach-menu-item:hover { background: #333335; }

/* Usage panel */
.dark .usage-bar { background: #3a3a3c; }
.dark .usage-row { border-color: #2f2f31; }

/* Guidelines / case-law panel */
.dark .gl-panel-header { background: #2a2a2c; border-color: #3a3a3c; }
.dark .gl-panel-header:hover, .dark .gl-panel-header.gl-open { background: #313133; border-color: #48484a; }
.dark .gl-panel-body { background: #242426; border-color: #48484a; }
.dark .gl-section-row { border-color: #2f2f31; }

/* Toolkit */
.dark .toolkit-item:hover { background: #2a2a2c; }
.dark .toolkit-add { border-color: #2f2f31; }
.dark .toolkit-row, .dark .template-row { background: #1c1c1e; border-color: #3a3a3c; }

/* Drop overlay + empty state */
.dark .drop-overlay { background: rgba(0,122,255,.12); }
.dark .drop-overlay-inner { background: #242426; }

/* File wrapper modal */
.dark .fw-biblio-card, .dark .fw-drop-zone, .dark .fw-parse-status { background: #1c1c1e; border-color: #3a3a3c; }
.dark .fw-cat-header { background: #242426; }
.dark .fw-doc-row:hover { background: #242426; }
.dark .fw-cat-count { background: #3a3a3c; color: var(--text-muted); }
.dark .fw-step-dot { background: #2a2a2c; border-color: #3a3a3c; }
.dark .fw-step-line { background: #3a3a3c; }
.dark .fw-summary-card > div { /* keep accent tints */ }
