/*
 * Application styles. Plain CSS served by Propshaft.
 */

:root {
  --bg: #0f1115;
  --panel: #171a21;
  --panel-2: #1f232c;
  --border: #2a2f3a;
  --text: #e6e8eb;
  --muted: #9aa3b2;
  --accent: #6d5efc;
  --accent-hover: #5a4af0;
  --user-bubble: #2b3140;
  --assistant-bubble: #1f232c;
  --error: #4a2326;
  --error-text: #ff9aa2;
  --radius: 14px;
}

* { box-sizing: border-box; }

/* The `hidden` attribute must win over any component's `display` rule
   (e.g. .btn-primary, .composer-stop), which would otherwise show the element. */
[hidden] { display: none !important; }

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

.btn-primary {
  display: inline-block;
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: 10px;
  padding: 0.7rem 1.2rem;
  font-size: 0.95rem;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s ease;
}
.btn-primary:hover { background: var(--accent-hover); }

/* ---------- Home / conversation list ---------- */
.home {
  max-width: 640px;
  margin: 0 auto;
  padding: 4rem 1.5rem;
}
.home-header { text-align: center; margin-bottom: 2.5rem; }
.home-header h1 { font-size: 2rem; margin: 0 0 0.25rem; }
.subtitle { color: var(--muted); margin: 0 0 1.5rem; }

.conversation-list { list-style: none; padding: 0; margin: 0; }
.conversation-list li {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 1rem;
  padding: 0.9rem 1.1rem;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  margin-bottom: 0.6rem;
}
.conversation-link { color: var(--text); text-decoration: none; font-weight: 500; }
.conversation-link:hover { color: var(--accent); }
.conversation-date { color: var(--muted); font-size: 0.8rem; white-space: nowrap; }
.empty { text-align: center; color: var(--muted); }

/* ---------- Chat ---------- */
.chat {
  display: flex;
  flex-direction: column;
  height: 100vh;
  width: min(1200px, 95vw);   /* roomier default; was capped at 820px */
  min-width: 480px;
  max-width: 95vw;
  margin: 0 auto;
  overflow: hidden;            /* required for the native resize handle */
  resize: horizontal;          /* drag the bottom-right corner to widen */
}
.chat-header {
  padding: 1rem 1.5rem;
  border-bottom: 1px solid var(--border);
  background: var(--panel);
}
.back-link { color: var(--muted); text-decoration: none; font-size: 0.85rem; }
.back-link:hover { color: var(--accent); }
.chat-header h1 { font-size: 1.05rem; margin: 0.35rem 0 0; font-weight: 600; }

.messages {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden; /* long words/URLs wrap (below) instead of scrolling sideways */
  padding: 1.5rem;
  display: flex;
  flex-direction: column;
  gap: 1rem;
  /* Thin, themed scrollbar instead of the chunky native one on the dark panel. */
  scrollbar-width: thin;
  scrollbar-color: var(--border) transparent;
}
.messages::-webkit-scrollbar { width: 8px; }
.messages::-webkit-scrollbar-track { background: transparent; }
.messages::-webkit-scrollbar-thumb {
  background: var(--border);
  border-radius: 4px;
}
.messages::-webkit-scrollbar-thumb:hover { background: var(--muted); }

.message {
  max-width: 80%;
  padding: 0.8rem 1rem;
  border-radius: var(--radius);
  /* Break long unbreakable strings (URLs, tokens) so they never overflow. */
  overflow-wrap: anywhere;
  word-break: break-word;
}
.message-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  margin-bottom: 0.3rem;
}
.message-role {
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--muted);
}
/* Copy button: faint, sharpens on bubble hover, stays usable on touch. */
.message-copy {
  border: none;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  font-size: 0.85rem;
  line-height: 1;
  padding: 0.15rem 0.35rem;
  border-radius: 6px;
  opacity: 0.45;
  transition: opacity 0.12s ease, background 0.12s ease;
}
.message:hover .message-copy,
.message-copy:focus-visible { opacity: 0.8; }
.message-copy:hover { opacity: 1; background: var(--panel-2); }
.message-content p { margin: 0 0 0.5rem; }
.message-content p:last-child { margin-bottom: 0; }
.message-image {
  display: block;
  max-width: 100%;
  max-height: 320px;
  border-radius: 10px;
  margin-bottom: 0.4rem;
}

.message--user {
  align-self: flex-end;
  background: var(--user-bubble);
  border-bottom-right-radius: 4px;
}
.message--assistant {
  align-self: flex-start;
  background: var(--assistant-bubble);
  border: 1px solid var(--border);
  border-bottom-left-radius: 4px;
}
.message--error {
  align-self: flex-start;
  background: var(--error);
  color: var(--error-text);
}

.message--pending .message-content { color: var(--muted); }
.dots {
  display: inline-block;
  animation: blink 1.2s infinite steps(1);
}
@keyframes blink { 50% { opacity: 0.2; } }

/* Blinking caret on the bubble while tokens are still streaming in. */
.message--streaming .message-content::after {
  content: "▍";
  margin-left: 1px;
  color: var(--muted);
  animation: blink 1s steps(1) infinite;
}

/* ---------- Composer ---------- */
.composer {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  padding: 1rem 1.5rem;
  border-top: 1px solid var(--border);
  background: var(--panel);
}
.composer-row { display: flex; gap: 0.6rem; }

/* Hidden file input that the 📎 label triggers. */
.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;
}
.composer-attach {
  align-self: flex-end;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 44px;
  min-height: 44px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--panel-2);
  font-size: 1.1rem;
  cursor: pointer;
}
.composer-attach:hover { border-color: var(--accent); }

/* Thumbnail of the picked image, above the input row. */
.composer-attachment {
  position: relative;
  align-self: flex-start;
  display: inline-block;
}
.composer-attachment img {
  max-height: 120px;
  max-width: 220px;
  border-radius: 10px;
  border: 1px solid var(--border);
  display: block;
}
.composer-attachment-remove {
  position: absolute;
  top: -8px; right: -8px;
  width: 22px; height: 22px;
  border-radius: 50%;
  border: 1px solid var(--border);
  background: var(--panel);
  color: var(--text);
  font-size: 0.8rem;
  line-height: 1;
  cursor: pointer;
}
.composer-attachment-remove:hover { background: var(--error); color: var(--error-text); border-color: var(--error); }
.composer-input {
  flex: 1;
  resize: vertical;     /* drag the bottom edge to grow the input */
  background: var(--panel-2);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 0.7rem 0.9rem;
  font: inherit;
  line-height: 1.45;
  min-height: 64px;
  max-height: 50vh;     /* let it grow up to half the viewport */
}
.composer-input:focus {
  outline: none;
  border-color: var(--accent);
}
.composer-send { align-self: flex-end; }
.composer-stop {
  align-self: flex-end;
  display: inline-flex;
  align-items: center;
  gap: 0.45rem;
  background: var(--panel-2);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.55rem 0.9rem;
  font: inherit;
  font-weight: 500;
  cursor: pointer;
}
.composer-stop:hover { background: var(--error); color: var(--error-text); border-color: var(--error); }
.composer-stop:disabled { opacity: 0.6; cursor: default; }
.stop-icon {
  width: 0.7rem;
  height: 0.7rem;
  background: currentColor;
  border-radius: 2px;
}
.model-select {
  align-self: flex-start;
  background: var(--panel-2);
  color: var(--muted);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.3rem 0.5rem;
  font-size: 0.8rem;
}

/* ---------- Buttons / badges ---------- */
.btn-primary.small { padding: 0.45rem 0.8rem; font-size: 0.85rem; }
.btn-ghost {
  display: inline-block;
  background: transparent;
  color: var(--muted);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.45rem 0.8rem;
  font-size: 0.85rem;
  font-weight: 500;
  cursor: pointer;
  text-decoration: none;
}
.btn-ghost:hover { color: var(--text); border-color: var(--accent); }
.btn-ghost.small { padding: 0.3rem 0.6rem; font-size: 0.78rem; }
.btn-ghost.danger:hover { color: var(--error-text); border-color: var(--error-text); }
.badge {
  display: inline-block;
  background: var(--accent);
  color: #fff;
  font-size: 0.62rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  padding: 0.1rem 0.4rem;
  border-radius: 5px;
  vertical-align: middle;
}

/* ---------- Generic page + cards ---------- */
.page { max-width: 760px; margin: 0 auto; padding: 2.5rem 1.5rem; }
.page-header { margin-bottom: 2rem; }
.page-header h1 { font-size: 1.6rem; margin: 0.4rem 0 0; }
.page-title-row { display: flex; align-items: center; justify-content: space-between; gap: 1rem; }
.page-title-actions { display: flex; gap: 0.5rem; }

.card-list { list-style: none; padding: 0; margin: 0; }
.card-list li {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 1rem;
  padding: 0.9rem 1.1rem;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  margin-bottom: 0.6rem;
}
.card-link { color: var(--text); text-decoration: none; font-weight: 600; }
.card-link:hover { color: var(--accent); }
.card-meta { color: var(--muted); font-size: 0.8rem; white-space: nowrap; }

/* ---------- Conversation title (rename + delete, shared list/chat) ---------- */
.conv-title { min-width: 0; flex: 1; }
.conv-title-display {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  min-width: 0;
}
/* Reveal the action icons on hover/focus to keep the rows calm. */
.icon-btn {
  opacity: 0;
  background: transparent;
  border: none;
  color: var(--muted);
  cursor: pointer;
  font-size: 0.95rem;
  line-height: 1;
  padding: 0.25rem 0.4rem;
  border-radius: 6px;
}
.conv-title:hover .icon-btn,
.conv-title:focus-within .icon-btn { opacity: 1; }
.icon-btn:hover { background: var(--panel-2); color: var(--text); }
.icon-btn--danger:hover { color: var(--error-text); }
/* button_to wraps its button in a form; keep it inline in the row. */
.conv-title-display form { display: inline; margin: 0; }

.chat-title { font-size: 1.05rem; margin: 0.35rem 0 0; font-weight: 600; }
.conv-title--chat .conv-title-display { margin-top: 0.35rem; }
.conv-title--chat .chat-title { margin: 0; }

.conv-rename { display: flex; gap: 0.5rem; align-items: center; }
.conv-rename-input {
  flex: 1;
  min-width: 0;
  background: var(--panel-2);
  color: var(--text);
  border: 1px solid var(--accent);
  border-radius: 8px;
  padding: 0.35rem 0.6rem;
  font: inherit;
}
.conv-rename-input:focus { outline: none; }

/* ---------- Sections (project hub) ---------- */
.section { margin-top: 2.5rem; }
.section-head { display: flex; align-items: center; justify-content: space-between; gap: 1rem; }
.section-head h2 { font-size: 1.1rem; margin: 0; }
.section-head-actions { display: flex; align-items: center; gap: .5rem; }
.section-note { font-weight: 400; font-size: 0.8rem; color: var(--muted); }
.section-hint { color: var(--muted); font-size: 0.85rem; margin: 0.3rem 0 1rem; }

/* ---------- Instructions ---------- */
.instructions { display: flex; flex-direction: column; gap: 0.8rem; }
.instruction {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem 1.1rem;
}
.instruction-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 1rem; }
.instruction-title { font-size: 1rem; margin: 0; display: flex; align-items: center; gap: 0.5rem; }
.instruction-toggle {
  display: inline-flex; align-items: center; gap: 0.45rem;
  background: none; border: 0; padding: 0; margin: 0;
  font: inherit; color: inherit; cursor: pointer; text-align: left;
}
.instruction-toggle .caret { color: var(--muted); transition: transform 0.15s ease; }
.instruction-toggle[aria-expanded="true"] .caret { transform: rotate(90deg); }
.instruction-actions { display: flex; gap: 0.4rem; flex-shrink: 0; }
.instruction-body {
  margin: 0.8rem 0 0;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.8rem;
  font-family: ui-monospace, "SF Mono", Menlo, monospace;
  font-size: 0.82rem;
  color: var(--muted);
  white-space: pre-wrap;
  word-break: break-word;
  max-height: 300px;
  overflow-y: auto;
}

.api-link {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.5rem 0.7rem;
  margin-bottom: 1rem;
}
.api-link-url {
  flex: 1;
  font-family: ui-monospace, "SF Mono", Menlo, monospace;
  font-size: 0.8rem;
  color: var(--muted);
  overflow-x: auto;
  white-space: nowrap;
}

/* ---------- RepoZone (drag & drop) ---------- */
.dropzone {
  border: 2px dashed var(--border);
  border-radius: var(--radius);
  padding: 1.8rem 1rem;
  text-align: center;
  margin-bottom: 1rem;
  transition: border-color 0.15s ease, background 0.15s ease;
}
.dropzone.is-active { border-color: var(--accent); background: var(--panel-2); }
.dropzone.is-busy { opacity: 0.7; pointer-events: none; }
.dropzone-title { margin: 0 0 0.3rem; font-weight: 600; font-size: 0.95rem; }
.dropzone-hint { margin: 0; color: var(--muted); font-size: 0.85rem; }
.dropzone-pick { color: var(--accent); cursor: pointer; text-decoration: underline; }

.repo-file-list {
  list-style: none;
  margin: 0;
  padding: 0;
  border: 1px solid var(--border);
  border-radius: 10px;
  max-height: 320px;
  overflow-y: auto;
}
.repo-file {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  padding: 0.45rem 0.7rem;
  border-bottom: 1px solid var(--border);
  font-size: 0.82rem;
}
.repo-file:last-child { border-bottom: none; }
.repo-file-path {
  flex: 1;
  font-family: ui-monospace, "SF Mono", Menlo, monospace;
  overflow-x: auto;
  white-space: nowrap;
}
.repo-file-dir { color: var(--muted); }
.repo-file-size { color: var(--muted); white-space: nowrap; font-variant-numeric: tabular-nums; }
.repo-file-delete {
  background: none;
  border: none;
  color: var(--muted);
  cursor: pointer;
  font-size: 0.9rem;
  padding: 0 0.2rem;
  line-height: 1;
}
.repo-file-delete:hover { color: var(--error-text); }

/* ---------- Forms ---------- */
.stacked-form { display: flex; flex-direction: column; gap: 1.2rem; max-width: 620px; }
.stacked-form label { display: flex; flex-direction: column; gap: 0.4rem; font-weight: 600; font-size: 0.9rem; }
.stacked-form label.checkbox { flex-direction: row; align-items: center; gap: 0.5rem; font-weight: 500; }
.stacked-form input[type="text"],
.stacked-form select,
.stacked-form textarea {
  background: var(--panel-2);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 0.65rem 0.8rem;
  font: inherit;
}
.stacked-form textarea { resize: vertical; font-family: ui-monospace, "SF Mono", Menlo, monospace; font-size: 0.85rem; }
.stacked-form input:focus, .stacked-form select:focus, .stacked-form textarea:focus {
  outline: none; border-color: var(--accent);
}
.form-actions { display: flex; gap: 0.6rem; align-items: center; }
.form-errors {
  background: var(--error); color: var(--error-text);
  border-radius: 10px; padding: 0.8rem 1rem; font-size: 0.88rem;
}
.form-errors ul { margin: 0.4rem 0 0; padding-left: 1.1rem; }

/* ---------- Auth / login ---------- */
.auth {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1.5rem;
}
.auth-card {
  width: 100%;
  max-width: 360px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 2rem;
  text-align: center;
}
.auth-card h1 { font-size: 1.5rem; margin: 0 0 0.25rem; }
.auth-form { display: flex; flex-direction: column; gap: 0.7rem; margin-top: 1.5rem; }
.auth-input {
  background: var(--panel-2);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 0.7rem 0.9rem;
  font: inherit;
  text-align: center;
}
.auth-input:focus { outline: none; border-color: var(--accent); }
.auth-error { color: var(--error-text); font-size: 0.9rem; margin: 0; }

/* ---------- Flash ---------- */
.flash {
  position: fixed; top: 1rem; left: 50%; transform: translateX(-50%);
  background: var(--accent); color: #fff;
  padding: 0.6rem 1.2rem; border-radius: 10px; font-size: 0.9rem;
  z-index: 50; box-shadow: 0 6px 20px rgba(0,0,0,0.3);
}

/* ---------- Confirm dialog (replaces native confirm popup) ---------- */
.confirm-dialog {
  background: var(--panel);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.5rem;
  max-width: 400px;
  width: 90%;
}
.confirm-dialog::backdrop { background: rgba(0, 0, 0, 0.6); }
.confirm-text { margin: 0 0 1.3rem; font-size: 0.95rem; line-height: 1.5; }
.confirm-actions { display: flex; gap: 0.6rem; justify-content: flex-end; margin: 0; }
.btn-primary.danger { background: #c0392b; }
.btn-primary.danger:hover { background: #a93226; }
