/* AI Chat — same visual language as the converter */
:root {
  --bg: #ffffff;
  --fg: #1a1a1a;
  --muted: #6b7280;
  --line: #e5e7eb;
  --primary: #1F3864;
  --primary-hover: #2E75B6;
  --accent: #f4f6fa;
  --user-bg: #eef4fb;
  --assistant-bg: #ffffff;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font: 16px/1.55 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  color: var(--fg);
  background: var(--bg);
}
.wrap { max-width: 920px; margin: 0 auto; padding: 0 16px; }

header {
  border-bottom: 1px solid var(--line);
  position: sticky; top: 0; background: var(--bg); z-index: 10;
}
header .wrap {
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 16px;
}
header h1 { margin: 0; font-size: 18px; font-weight: 600; }
header h1 a { color: var(--fg); text-decoration: none; }
header nav { display: flex; gap: 14px; }
header nav a { color: var(--muted); font-size: 14px; text-decoration: none; }
header nav a:hover { color: var(--fg); }

main { padding: 18px 0 280px; }

.muted { color: var(--muted); }

.flash {
  padding: 10px 14px; border-radius: 6px; margin-bottom: 16px;
  border: 1px solid;
}
.flash-error { background: #fef2f2; border-color: #fecaca; color: #7f1d1d; }
.flash-ok { background: #ecfdf5; border-color: #a7f3d0; color: #065f46; }

/* Login */
.login-card {
  max-width: 340px; margin: 48px auto;
  border: 1px solid var(--line); border-radius: 10px;
  padding: 24px; background: var(--bg);
}
.login-card h2 { margin-top: 0; }
.login-card label { display: block; font-weight: 500; margin-bottom: 6px; }
.login-card input[type="password"] {
  width: 100%; padding: 10px 12px; font-size: 16px;
  border: 1px solid var(--line); border-radius: 6px; margin-bottom: 14px;
}
.login-card button {
  width: 100%; padding: 10px 14px; font-size: 16px; font-weight: 500;
  background: var(--primary); color: white; border: 0; border-radius: 6px;
  cursor: pointer;
}
.login-card button:hover { background: var(--primary-hover); }

/* Chat controls */
.chat-controls {
  display: flex; align-items: center; gap: 12px; flex-wrap: wrap;
  margin-bottom: 14px;
}
.model-picker {
  display: inline-flex; align-items: center; gap: 6px;
  font-size: 14px;
}
.model-picker span { color: var(--muted); }
#model-select {
  font-size: 14px; padding: 6px 8px;
  border: 1px solid var(--line); border-radius: 6px;
  background: var(--bg); color: var(--fg);
  min-width: 240px; max-width: 100%;
}
#status { font-size: 13px; }

.button-small {
  display: inline-block; padding: 5px 10px; font-size: 13px;
  background: var(--primary); color: white; text-decoration: none;
  border: 0; border-radius: 4px; cursor: pointer; font-family: inherit;
}
.button-small:hover { background: var(--primary-hover); }
.button-ghost {
  background: transparent; color: var(--muted);
  border: 1px solid var(--line);
}
.button-ghost:hover { background: #f3f4f6; color: var(--fg); }

/* Messages */
.messages {
  display: flex; flex-direction: column; gap: 12px;
  margin-bottom: 16px;
}
.msg {
  position: relative;
  border: 1px solid var(--line); border-radius: 10px;
  padding: 12px 14px 14px;
  scroll-margin-bottom: 260px;   /* keep auto-scroll above the sticky composer */
}
.msg header {
  position: static; background: transparent; border: 0;
  font-size: 12px; color: var(--muted); margin-bottom: 6px;
  padding: 0; font-weight: 500; letter-spacing: 0.04em; text-transform: uppercase;
}
.msg-body {
  font-size: 15px; line-height: 1.55;
  white-space: pre-wrap; word-wrap: break-word;
}
.msg-user { background: var(--user-bg); }
.msg-assistant { background: var(--assistant-bg); }
.msg-copy {
  position: absolute; top: 8px; right: 8px;
  font-size: 11px; padding: 3px 8px;
  background: transparent; color: var(--muted);
  border: 1px solid var(--line); border-radius: 4px;
  cursor: pointer;
  opacity: 0; transition: opacity .15s;
}
.msg:hover .msg-copy { opacity: 1; }
.msg-copy:hover { background: #f3f4f6; color: var(--fg); }
.msg-body.streaming::after {
  content: "▊";
  display: inline-block;
  margin-left: 2px;
  animation: blink 1s steps(2) infinite;
  color: var(--primary);
}
@keyframes blink { 50% { opacity: 0; } }

/* Composer (fixed at bottom on mobile, in-flow on desktop) */
.composer {
  position: sticky; bottom: 0;
  background: var(--bg);
  border-top: 1px solid var(--line);
  margin: 0 -16px;
  padding: 12px 16px;
  display: flex; gap: 8px; align-items: flex-end;
}
#input {
  flex: 1;
  font: inherit; font-size: 15px;
  padding: 10px 12px;
  border: 1px solid var(--line); border-radius: 8px;
  resize: none;
  min-height: 44px;
  max-height: 260px;
  background: var(--bg); color: var(--fg);
}
#input:focus { outline: 2px solid var(--primary); outline-offset: -1px; }

.composer-actions {
  display: flex; flex-direction: column; gap: 6px;
}
button.primary {
  background: var(--primary); color: white; border: 0; border-radius: 6px;
  padding: 10px 18px; font-size: 15px; font-weight: 500; cursor: pointer;
}
button.primary:hover { background: var(--primary-hover); }
button.primary:disabled { background: var(--muted); cursor: progress; }

code { background: var(--accent); padding: 0 4px; border-radius: 3px; font-size: 0.9em; }

/* Mobile tweaks */
@media (max-width: 600px) {
  header h1 { font-size: 16px; }
  header nav { gap: 10px; }
  header nav a { font-size: 13px; }
  #model-select { min-width: 0; flex: 1; }
  .msg-copy { opacity: 1; }
}

/* Documents panel */
#docs-panel {
  margin-bottom: 16px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--bg);
}
#docs-panel > summary {
  cursor: pointer;
  list-style: none;
  padding: 10px 14px;
  font-weight: 500;
  display: flex; justify-content: space-between; align-items: center;
}
#docs-panel > summary::-webkit-details-marker { display: none; }
#docs-panel > summary::before {
  content: "▸"; margin-right: 8px; color: var(--muted); transition: transform .15s;
  display: inline-block;
}
#docs-panel[open] > summary::before { transform: rotate(90deg); }
#docs-summary { font-weight: 400; font-size: 13px; }
.docs-upload { padding: 0 14px 12px; }

.drop-zone {
  display: block;
  border: 2px dashed var(--line);
  border-radius: 8px;
  padding: 16px 14px;
  text-align: center;
  cursor: pointer;
  background: var(--accent);
  transition: border-color .15s, background-color .15s;
}
.drop-zone.dragging { border-color: var(--primary); background: #eef4fb; }
.drop-zone input[type="file"] { display: none; }
.drop-zone-text strong { display: block; font-size: 15px; margin-bottom: 4px; }
.drop-zone-text small { display: block; color: var(--muted); font-size: 12px; }

#upload-progress { margin-top: 10px; }
.progress-row {
  display: flex; justify-content: space-between; align-items: baseline;
  margin-bottom: 4px; font-size: 13px; color: var(--muted);
}
#upload-pct { color: var(--fg); font-weight: 500; font-variant-numeric: tabular-nums; }
.progress-bar {
  width: 100%; height: 8px;
  background: var(--accent); border-radius: 999px; overflow: hidden;
}
.progress-bar-fill {
  width: 0%; height: 100%; background: var(--primary);
  transition: width 120ms linear;
}

.docs-list { padding: 0 14px 14px; display: flex; flex-direction: column; gap: 8px; }
.doc {
  display: flex; align-items: stretch; gap: 8px;
  border: 1px solid var(--line); border-radius: 8px;
  padding: 8px 10px;
}
.doc-attached { background: var(--user-bg); border-color: var(--primary-hover); }
.doc-row {
  display: flex; align-items: flex-start; gap: 10px;
  flex: 1; cursor: pointer; user-select: none;
}
.doc-info { flex: 1; min-width: 0; }
.doc-name { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.doc-name strong { word-break: break-all; }
.doc-meta { font-size: 12px; margin-top: 2px; }

.badge {
  display: inline-block; padding: 1px 7px; border-radius: 999px;
  font-size: 11px; font-weight: 500; color: white;
  letter-spacing: 0.03em; text-transform: lowercase;
}
.badge-queued { background: #6b7280; }
.badge-running { background: #b45309; }
.badge-done { background: #047857; }
.badge-failed { background: #b91c1c; }

.doc-delete {
  font-size: 18px; line-height: 1;
  padding: 4px 10px; align-self: center;
}
