/* =========================================================================
   MyGPT — Phase 18 UI. Warm, friendly, comfortable. Frameworkless.
   Every value here resolves to a token from css/tokens.css. Components are
   plain classes; theming happens entirely through the token swap.
   ========================================================================= */

/* ---------------- base / reset ---------------- */
*,
*::before,
*::after {
  box-sizing: border-box;
}
html,
body {
  margin: 0;
  height: 100%;
}
body {
  background: var(--bg);
  color: var(--fg);
  font-family: var(--font-sans);
  font-size: var(--text-base);
  line-height: var(--leading-normal);
  font-feature-settings: "liga" 1, "calt" 1;
  font-optical-sizing: auto;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-rendering: optimizeLegibility;
}
h1,
h2,
h3,
h4,
p {
  margin: 0;
}
button {
  font-family: inherit;
}
.hidden {
  display: none !important;
}
.muted {
  color: var(--muted);
  font-size: var(--text-sm);
}

/* screen-reader-only (skip link, live region, hidden labels) */
.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

/* visible focus ring for keyboard users everywhere (mouse clicks stay clean) */
:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
  border-radius: var(--radius-sm);
}
*::selection {
  background: var(--accent-soft);
}

/* skip-to-content link, revealed on focus */
.skip-link {
  position: fixed;
  top: var(--space-2);
  left: var(--space-2);
  z-index: var(--z-toast);
  background: var(--surface);
  color: var(--fg);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: var(--space-2) var(--space-3);
  box-shadow: var(--shadow-md);
  transform: translateY(-150%);
  transition: transform var(--dur-base) var(--ease-out);
}
.skip-link:focus {
  transform: translateY(0);
}

/* ---------------- controls ---------------- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-2);
  background: var(--accent);
  color: var(--accent-fg);
  border: 1px solid transparent;
  border-radius: var(--radius-md);
  padding: 0.6rem 1.05rem;
  font-size: var(--text-base);
  font-weight: var(--weight-medium);
  cursor: pointer;
  transition: background var(--dur-fast) var(--ease-out),
    filter var(--dur-fast), border-color var(--dur-fast),
    transform var(--dur-fast), box-shadow var(--dur-fast);
}
.btn:hover {
  background: var(--accent-hover);
}
.btn:active {
  transform: translateY(1px);
}
.btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}
.btn.full {
  width: 100%;
}
.btn.ghost {
  background: transparent;
  border-color: var(--border-strong);
  color: var(--fg);
}
.btn.ghost:hover {
  background: var(--surface-3);
  border-color: var(--border-strong);
}
.btn.danger {
  background: var(--danger);
  color: var(--danger-fg);
}
.btn.danger:hover {
  filter: brightness(1.05);
  background: var(--danger);
}

.chip {
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
  background: transparent;
  border: 1px solid var(--border-strong);
  color: var(--muted);
  border-radius: var(--radius-full);
  padding: 0.35rem 0.75rem;
  font-size: var(--text-sm);
  font-weight: var(--weight-medium);
  cursor: pointer;
  transition: background var(--dur-fast), color var(--dur-fast),
    border-color var(--dur-fast);
}
.chip:hover {
  background: var(--surface-3);
  color: var(--fg);
}
.chip input[type="checkbox"] {
  accent-color: var(--accent);
}

.icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: transparent;
  border: 0;
  color: var(--muted);
  cursor: pointer;
  padding: 0.3rem;
  border-radius: var(--radius-sm);
  transition: background var(--dur-fast), color var(--dur-fast);
}
.icon-btn:hover {
  color: var(--fg);
  background: var(--surface-3);
}

input[type="text"],
input[type="search"],
textarea,
select {
  background: var(--surface);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-md);
  color: var(--fg);
  padding: 0.6rem 0.75rem;
  font: inherit;
  font-size: var(--text-base);
  transition: border-color var(--dur-fast), box-shadow var(--dur-fast);
}
input::placeholder,
textarea::placeholder {
  color: var(--subtle);
}
input[type="text"]:focus,
input[type="search"]:focus,
textarea:focus,
select:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--focus-ring);
}
input[type="range"] {
  accent-color: var(--accent);
}

/* ---------------- signed-out landing ---------------- */
.signed-out {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 100%;
  padding: var(--space-4);
}
.signed-out-card {
  text-align: center;
  display: flex;
  flex-direction: column;
  gap: var(--space-5);
  align-items: center;
  max-width: 360px;
  padding: var(--space-10) var(--space-8);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-xl);
  box-shadow: var(--shadow-lg);
}
.brand-lg {
  font-size: var(--text-3xl);
  font-weight: var(--weight-bold);
  letter-spacing: -0.02em;
  color: var(--accent);
}

/* ---------------- app shell ---------------- */
.app {
  display: grid;
  grid-template-columns: var(--rail-w) var(--list-w) 1fr;
  height: 100vh;
  height: 100dvh;
}

/* icon rail */
.rail {
  background: var(--surface-2);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  align-items: stretch;
  padding: var(--space-3) var(--space-2);
  gap: var(--space-1);
}
.rail-brand {
  width: 42px;
  height: 42px;
  margin: var(--space-1) auto var(--space-4);
  border-radius: var(--radius-md);
  background: var(--accent);
  color: var(--accent-fg);
  font-weight: var(--weight-bold);
  font-size: var(--text-base);
  letter-spacing: 0.5px;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: var(--shadow-sm);
}
.rail-btn {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
  background: transparent;
  border: 0;
  color: var(--muted);
  cursor: pointer;
  padding: 0.55rem 0.2rem;
  border-radius: var(--radius-md);
  transition: background var(--dur-fast), color var(--dur-fast);
}
.rail-btn:hover {
  background: var(--surface-3);
  color: var(--fg);
}
.rail-btn.active {
  background: var(--accent-soft);
  color: var(--accent);
}
.rail-label {
  font-size: 0.625rem;
  font-weight: var(--weight-medium);
}
.rail-spacer {
  flex: 1;
}

/* list pane */
.listpane {
  background: var(--surface);
  border-right: 1px solid var(--border);
  overflow: hidden;
  display: flex;
  flex-direction: column;
}
.list-section {
  display: flex;
  flex-direction: column;
  gap: var(--space-3);
  padding: var(--space-4) var(--space-3);
  min-height: 0;
  flex: 1;
}
.list-head {
  font-size: var(--text-xs);
  letter-spacing: 0.07em;
  text-transform: uppercase;
  font-weight: var(--weight-semibold);
  color: var(--subtle);
  padding: var(--space-1) var(--space-2) 0;
}
.list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 2px;
  overflow-y: auto;
  min-height: 0;
}
.row {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  padding: 0.55rem 0.65rem;
  border-radius: var(--radius-md);
  cursor: pointer;
  font-size: var(--text-base);
  color: var(--fg);
  transition: background var(--dur-fast);
}
.row:hover {
  background: var(--surface-2);
}
.row.active {
  background: var(--accent-soft);
  color: var(--accent);
  font-weight: var(--weight-medium);
}
.row-title {
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.row-actions {
  display: none;
  gap: 1px;
}
.row:hover .row-actions,
.row.active .row-actions,
.row:focus-within .row-actions {
  display: flex;
}
.list-empty,
.list-loading {
  color: var(--muted);
  font-size: var(--text-sm);
  padding: var(--space-2) var(--space-2);
}

/* status chips (documents + research) */
.status {
  font-size: var(--text-xs);
  font-weight: var(--weight-medium);
  padding: 0.1rem 0.5rem;
  border-radius: var(--radius-full);
  flex-shrink: 0;
  text-transform: capitalize;
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
}
.status::before {
  content: "";
  width: 6px;
  height: 6px;
  border-radius: var(--radius-full);
  background: currentColor;
}
.status.amber,
.status.uploaded,
.status.processing,
.status.running {
  background: var(--warn-bg);
  color: var(--warn-fg);
}
.status.green,
.status.ready,
.status.done {
  background: var(--ok-bg);
  color: var(--ok-fg);
}
.status.red,
.status.error,
.status.failed {
  background: var(--danger-bg);
  color: var(--danger-text);
}

/* skeleton loaders */
.skeleton {
  border-radius: var(--radius-sm);
  background: linear-gradient(
    90deg,
    var(--surface-2) 25%,
    var(--surface-3) 50%,
    var(--surface-2) 75%
  );
  background-size: 200% 100%;
  animation: shimmer 1.3s infinite linear;
}
.skel-row {
  height: 34px;
  margin: 2px 0;
}
@keyframes shimmer {
  to {
    background-position: -200% 0;
  }
}

/* ---------------- main pane ---------------- */
.mainpane {
  min-width: 0;
  display: flex;
  flex-direction: column;
}
.view {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
}
.viewbar {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-3);
  padding: 0.85rem 1.25rem;
  border-bottom: 1px solid var(--border);
  background: var(--bg); /* fallback for no color-mix support */
  background: color-mix(in srgb, var(--bg) 72%, transparent);
  backdrop-filter: blur(8px);
}
.viewtitle {
  font-weight: var(--weight-semibold);
  font-size: var(--text-lg);
  letter-spacing: -0.01em;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.viewbar-actions {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  flex-shrink: 0;
}

/* settings popover */
.popover {
  position: absolute;
  top: 3.4rem;
  right: 1.25rem;
  z-index: var(--z-dropdown);
  width: min(380px, calc(100vw - 2rem));
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  padding: var(--space-4);
  display: flex;
  flex-direction: column;
  gap: var(--space-4);
}
.field {
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
  font-size: var(--text-sm);
  font-weight: var(--weight-medium);
  color: var(--muted);
}
.field select,
.field textarea,
.field input[type="range"],
.field input[type="text"] {
  width: 100%;
}
.field textarea {
  resize: vertical;
  min-height: 64px;
}
.field-actions {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: var(--space-3);
}

/* segmented control (replaces the learning <select>s in Advanced) */
.segmented {
  display: flex;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 3px;
  gap: 3px;
}
.segmented button {
  flex: 1;
  background: transparent;
  border: 0;
  color: var(--muted);
  font-size: var(--text-sm);
  font-weight: var(--weight-medium);
  padding: 0.4rem 0.5rem;
  border-radius: calc(var(--radius-md) - 4px);
  cursor: pointer;
  transition: background var(--dur-fast), color var(--dur-fast);
}
.segmented button:hover {
  color: var(--fg);
}
.segmented button.active {
  background: var(--surface);
  color: var(--fg);
  box-shadow: var(--shadow-sm);
}

/* ---------------- chat feed ---------------- */
.messages {
  flex: 1;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
  padding: var(--space-6) var(--space-4) var(--space-8);
  width: 100%;
  scroll-behavior: smooth;
}
.feed-inner,
.messages > .msg,
.messages > .empty-state,
.messages > .citations,
.messages > .timeline,
.messages > .report,
.messages > .spinner {
  width: min(var(--content-max), 100%);
  margin-inline: auto;
}

/* one message row: avatar · (label + content + actions) */
.msg {
  display: flex;
  gap: var(--space-3);
  padding: var(--space-3) 0;
}
.msg-avatar {
  flex-shrink: 0;
  width: 30px;
  height: 30px;
  border-radius: var(--radius-md);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: var(--text-sm);
  font-weight: var(--weight-bold);
  margin-top: 2px;
}
.msg-user .msg-avatar {
  background: var(--surface-3);
  color: var(--fg);
}
.msg-assistant .msg-avatar {
  background: var(--accent);
  color: var(--accent-fg);
}
.msg-body {
  min-width: 0;
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: var(--space-1);
}
.msg-role {
  font-size: var(--text-sm);
  font-weight: var(--weight-semibold);
  color: var(--muted);
}
.msg-content {
  line-height: var(--leading-normal);
  word-wrap: break-word;
  overflow-wrap: anywhere;
}
.msg-user .msg-content {
  white-space: pre-wrap;
}
/* per-message actions appear on hover/focus */
.msg-actions {
  display: flex;
  gap: var(--space-1);
  margin-top: var(--space-1);
  opacity: 0;
  transition: opacity var(--dur-fast);
}
.msg:hover .msg-actions,
.msg:focus-within .msg-actions {
  opacity: 1;
}
.msg-act {
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
  background: transparent;
  border: 1px solid var(--border);
  color: var(--muted);
  border-radius: var(--radius-sm);
  padding: 0.2rem 0.5rem;
  font-size: var(--text-xs);
  font-weight: var(--weight-medium);
  cursor: pointer;
  transition: background var(--dur-fast), color var(--dur-fast),
    border-color var(--dur-fast);
}
.msg-act:hover {
  color: var(--fg);
  background: var(--surface-3);
  border-color: var(--border-strong);
}

/* streaming caret */
.msg-content.streaming::after {
  content: "";
  display: inline-block;
  width: 0.5em;
  height: 1em;
  margin-left: 1px;
  vertical-align: text-bottom;
  background: var(--accent);
  border-radius: 1px;
  animation: caret-blink 1s steps(2) infinite;
}
@keyframes caret-blink {
  50% {
    opacity: 0;
  }
}

/* citations under an assistant reply */
.citations {
  font-size: var(--text-xs);
  color: var(--muted);
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-2);
  align-items: center;
  padding: 0 0 var(--space-3) calc(30px + var(--space-3));
}
.citation-chip {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-full);
  padding: 0.12rem 0.6rem;
}

/* typing indicator (dots) */
.typing {
  display: inline-flex;
  gap: 4px;
  padding: 4px 0;
}
.typing i {
  width: 6px;
  height: 6px;
  border-radius: var(--radius-full);
  background: var(--subtle);
  animation: blink 1.2s infinite ease-in-out both;
}
.typing i:nth-child(2) {
  animation-delay: 0.18s;
}
.typing i:nth-child(3) {
  animation-delay: 0.36s;
}
@keyframes blink {
  0%,
  80%,
  100% {
    opacity: 0.25;
    transform: translateY(0);
  }
  40% {
    opacity: 1;
    transform: translateY(-2px);
  }
}

/* scroll-to-bottom button */
.scroll-bottom {
  position: absolute;
  left: 50%;
  bottom: calc(100% + var(--space-1));
  transform: translateX(-50%) translateY(6px);
  z-index: var(--z-sticky);
  width: 38px;
  height: 38px;
  border-radius: var(--radius-full);
  background: var(--surface);
  border: 1px solid var(--border-strong);
  color: var(--fg);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  box-shadow: var(--shadow-md);
  opacity: 0;
  pointer-events: none;
  transition: opacity var(--dur-base), transform var(--dur-base);
}
.scroll-bottom.show {
  opacity: 1;
  pointer-events: auto;
  transform: translateX(-50%) translateY(0);
}

/* ---------------- composer ---------------- */
.composer-wrap {
  position: relative;
  padding: var(--space-2) var(--space-4) var(--space-4);
}
.composer {
  display: flex;
  align-items: flex-end;
  gap: var(--space-2);
  width: min(var(--content-max), 100%);
  margin: 0 auto;
  background: var(--surface);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-xl);
  padding: var(--space-2) var(--space-2) var(--space-2) var(--space-4);
  box-shadow: var(--shadow-sm);
  transition: border-color var(--dur-fast), box-shadow var(--dur-fast);
}
.composer:focus-within {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--focus-ring);
}
.composer textarea {
  flex: 1;
  border: 0;
  background: transparent;
  padding: 0.4rem 0;
  resize: none;
  max-height: 200px;
  line-height: var(--leading-snug);
}
.composer textarea:focus {
  outline: none;
  box-shadow: none;
}
.composer .btn {
  border-radius: var(--radius-lg);
  padding: 0.5rem 1rem;
  flex-shrink: 0;
}
.send-btn {
  width: 40px;
  height: 40px;
  padding: 0 !important;
  border-radius: var(--radius-full) !important;
}
.composer-hint {
  width: min(var(--content-max), 100%);
  margin: var(--space-2) auto 0;
  text-align: center;
  color: var(--subtle);
  font-size: var(--text-xs);
}

/* ---------------- research ---------------- */
.research-compose {
  display: flex;
  gap: var(--space-2);
  padding: var(--space-4);
  border-bottom: 1px solid var(--border);
  width: min(var(--content-max), 100%);
  margin: 0 auto;
  align-items: center;
}
.research-compose #research-input {
  flex: 1;
}
/* inline follow-up composer, appended after a finished report in the thread */
.followup-compose {
  border-bottom: none;
  border-top: 1px solid var(--border);
  margin-top: var(--space-4);
}
.followup-compose .followup-input {
  flex: 1;
}

/* activity-feed timeline */
.timeline {
  list-style: none;
  margin: 0;
  padding: var(--space-2) 0 0;
  position: relative;
}
.timeline::before {
  content: "";
  position: absolute;
  left: 7px;
  top: 12px;
  bottom: 12px;
  width: 2px;
  background: var(--border);
}
.tl-item {
  position: relative;
  padding: 0.4rem 0 0.4rem var(--space-6);
  font-size: var(--text-sm);
  color: var(--fg);
}
.tl-item::before {
  content: "";
  position: absolute;
  left: 2px;
  top: 0.7rem;
  width: 12px;
  height: 12px;
  border-radius: var(--radius-full);
  background: var(--surface);
  border: 2px solid var(--border-strong);
}
.tl-item.active::before {
  border-color: var(--accent);
  background: var(--accent);
  box-shadow: 0 0 0 4px var(--accent-soft);
}
.tl-item.done::before {
  border-color: var(--accent);
  background: var(--accent);
}
.tl-time {
  color: var(--subtle);
  font-size: var(--text-xs);
  margin-left: var(--space-2);
}
.report {
  padding: var(--space-4) 0;
}

/* ---------------- documents ---------------- */
.docpane {
  flex: 1;
  overflow-y: auto;
  padding: var(--space-8) var(--space-4);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--space-6);
}
.dropzone {
  width: min(560px, 100%);
  border: 2px dashed var(--border-strong);
  border-radius: var(--radius-lg);
  padding: var(--space-10) var(--space-6);
  text-align: center;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
  align-items: center;
  color: var(--fg);
  background: var(--surface);
  transition: border-color var(--dur-fast), background var(--dur-fast);
}
.dropzone:hover,
.dropzone.dragover {
  border-color: var(--accent);
  background: var(--accent-soft);
}
.dropzone-big {
  color: var(--muted);
}
.doc-cards {
  width: min(560px, 100%);
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
}

/* ---------------- modal + dialog ---------------- */
.modal {
  position: fixed;
  inset: 0;
  background: rgba(20, 16, 10, 0.5);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: var(--z-modal);
  padding: var(--space-4);
  animation: fade-in var(--dur-base) var(--ease-out);
}
.modal-card {
  width: min(460px, 100%);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-xl);
  padding: var(--space-6);
  display: flex;
  flex-direction: column;
  gap: var(--space-4);
  box-shadow: var(--shadow-xl);
  animation: pop-in var(--dur-base) var(--ease-out);
}
.modal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-3);
}
.modal-head h3 {
  margin: 0;
  font-size: var(--text-lg);
  font-weight: var(--weight-semibold);
}
.dialog-actions {
  display: flex;
  justify-content: flex-end;
  gap: var(--space-2);
}
@keyframes fade-in {
  from {
    opacity: 0;
  }
}
@keyframes pop-in {
  from {
    opacity: 0;
    transform: translateY(8px) scale(0.98);
  }
}

/* ---------------- toast ---------------- */
.toast {
  position: fixed;
  top: 18px;
  left: 50%;
  transform: translateX(-50%) translateY(-8px);
  z-index: var(--z-toast);
  max-width: min(440px, 92vw);
  padding: 0.7rem 1.05rem;
  border-radius: var(--radius-md);
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--fg);
  box-shadow: var(--shadow-lg);
  font-size: var(--text-base);
  opacity: 0;
  transition: opacity var(--dur-base), transform var(--dur-base);
  pointer-events: none;
}
.toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}
.toast.error {
  border-color: var(--danger);
}
.toast.success {
  border-color: var(--accent);
}

/* ---------------- empty / welcome states ---------------- */
.empty-state {
  margin: auto;
  text-align: center;
  color: var(--muted);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--space-3);
  max-width: 480px;
  padding: var(--space-8) var(--space-4);
}
.empty-state .empty-title {
  font-size: var(--text-2xl);
  font-weight: var(--weight-semibold);
  letter-spacing: -0.01em;
  color: var(--fg);
}
.empty-state svg {
  width: 44px;
  height: 44px;
  color: var(--accent);
}
.prompt-chips {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-2);
  justify-content: center;
  margin-top: var(--space-4);
}
.prompt-chip {
  background: var(--surface);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-md);
  padding: 0.6rem 0.85rem;
  font-size: var(--text-sm);
  color: var(--fg);
  cursor: pointer;
  text-align: left;
  max-width: 220px;
  transition: background var(--dur-fast), border-color var(--dur-fast),
    transform var(--dur-fast);
}
.prompt-chip:hover {
  background: var(--accent-soft);
  border-color: var(--accent);
  transform: translateY(-1px);
}

/* spinner */
.spinner {
  width: 24px;
  height: 24px;
  border: 2.5px solid var(--border);
  border-top-color: var(--accent);
  border-radius: var(--radius-full);
  animation: spin 0.7s linear infinite;
  margin: var(--space-6) auto;
}
@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

/* ---------------- inline SVG icons ---------------- */
.ico,
.ico-sm,
.dropzone-big,
.empty-state svg {
  fill: none;
  stroke: currentColor;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
}
.empty-state svg {
  stroke-width: 1.6;
}
.rail-btn .ico,
.menu-btn .ico {
  width: 22px;
  height: 22px;
}
.ico-sm {
  width: 16px;
  height: 16px;
  flex-shrink: 0;
}
.dropzone-big {
  width: 46px;
  height: 46px;
}

/* ---------------- markdown (assistant + report) ---------------- */
.md > *:first-child {
  margin-top: 0;
}
.md > *:last-child {
  margin-bottom: 0;
}
.md h1,
.md h2,
.md h3,
.md h4 {
  margin: 0.8em 0 0.4em;
  line-height: var(--leading-tight);
  font-weight: var(--weight-semibold);
}
.md h1 {
  font-size: var(--text-xl);
}
.md h2 {
  font-size: var(--text-lg);
}
.md h3 {
  font-size: var(--text-md);
}
.md p {
  margin: 0.5em 0;
}
.md ul,
.md ol {
  margin: 0.5em 0;
  padding-left: 1.4em;
}
.md li {
  margin: 0.2em 0;
}
.md a {
  color: var(--accent);
  text-underline-offset: 2px;
}
.md blockquote {
  margin: 0.6em 0;
  padding: 0.3em 0.9em;
  border-left: 3px solid var(--border-strong);
  color: var(--muted);
}
.md hr {
  border: 0;
  border-top: 1px solid var(--border);
  margin: 1em 0;
}
.md code {
  background: var(--code-inline-bg);
  padding: 0.12em 0.4em;
  border-radius: var(--radius-sm);
  font-family: var(--font-mono);
  font-size: 0.875em;
}
.codeblock {
  margin: 0.7em 0;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  overflow: hidden;
  background: var(--code-block-bg);
}
.codebar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.35rem 0.7rem;
  background: var(--surface-2);
  font-size: var(--text-xs);
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}
.copy-btn {
  background: transparent;
  border: 1px solid var(--border-strong);
  color: var(--muted);
  border-radius: var(--radius-sm);
  padding: 0.12rem 0.55rem;
  font-size: var(--text-xs);
  font-weight: var(--weight-medium);
  cursor: pointer;
  transition: background var(--dur-fast), color var(--dur-fast);
}
.copy-btn:hover {
  color: var(--fg);
  background: var(--surface-3);
}
.codeblock pre {
  margin: 0;
  padding: 0.75rem 0.85rem;
  overflow-x: auto;
}
.codeblock code {
  background: none;
  padding: 0;
  font-family: var(--font-mono);
  font-size: 0.85rem;
  line-height: var(--leading-snug);
}

/* mobile menu button + scrim (hidden on desktop) */
.menu-btn,
.scrim {
  display: none;
}

/* =========================== responsive =========================== */
@media (max-width: 860px) {
  .app {
    grid-template-columns: var(--rail-w) 1fr;
  }
  .listpane {
    position: fixed;
    left: var(--rail-w);
    top: 0;
    bottom: 0;
    width: min(300px, 80vw);
    z-index: var(--z-slideover);
    transform: translateX(-110%);
    transition: transform var(--dur-base) var(--ease-out);
    box-shadow: var(--shadow-xl);
  }
  .app.show-list .listpane {
    transform: translateX(0);
  }
  .scrim {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.45);
    z-index: var(--z-scrim);
    animation: fade-in var(--dur-base);
  }
  .app.show-list .scrim {
    display: block;
  }
  .menu-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    position: fixed;
    top: 9px;
    left: calc(var(--rail-w) + 8px);
    z-index: var(--z-dropdown);
    width: 40px;
    height: 40px;
    border-radius: var(--radius-md);
    background: var(--surface);
    border: 1px solid var(--border-strong);
    color: var(--fg);
    cursor: pointer;
    box-shadow: var(--shadow-sm);
  }
  .viewbar {
    padding-left: 3.8rem;
  }
}
@media (max-width: 560px) {
  .rail {
    padding: var(--space-2) var(--space-1);
  }
  .rail-label {
    display: none;
  }
}

/* =========================== reduced motion =========================== */
@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.001ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.001ms !important;
    scroll-behavior: auto !important;
  }
}
