/* Cassidy frontend — tier-1 typography + page chrome.
   See ARCHITECTURE.md §UI principles and issue #40 for the spec. */

@font-face {
  font-family: 'Inter Tight';
  font-style: normal;
  font-weight: 400;
  font-display: swap;
  src: url('/static/fonts/InterTight-Regular.woff2') format('woff2');
}

:root {
  --color-bg: #ffffff;
  --color-text: #111;
  --color-muted: #555;
  --color-border: #e5e7eb;
  --color-accent-green: #15803d;
  --color-accent-blue: #1d4ed8;
  --color-selection: #fde68a;
  --color-error: #b00;
  --color-shared-fg: #1d4ed8;
  --color-shared-bg: rgba(59, 130, 246, 0.12);
  --color-shared-bg-hover: rgba(59, 130, 246, 0.28);
  --color-private-fg: #b45309;
  --color-private-bg: rgba(234, 179, 8, 0.12);
  --color-private-bg-hover: rgba(234, 179, 8, 0.32);
  --rail-width: 280px;
  --main-max: 95ch;
  --mobile-bp: 720px;
}

html, body {
  margin: 0;
  padding: 0;
}

/* The HTML `hidden` attribute's user-agent rule is `display: none`, but any
   element-specific `display:` rule below wins on specificity. Restore
   browser-default semantics with `!important` so `el.hidden = true` from JS
   actually hides elements with explicit display rules (.banner, header#chrome,
   .popover-phase, .bulk-actions, etc.). */
[hidden] { display: none !important; }

body {
  background: var(--color-bg);
  color: var(--color-text);
  font-family: 'Inter Tight', sans-serif;
  font-size: 15px;
  line-height: 1.5;
}

::selection {
  background: var(--color-selection);
}

/* ---- Top bar (chrome) -------------------------------------------------- */

header#chrome {
  position: sticky;
  top: 0;
  z-index: 10;
  display: grid;
  grid-template-columns: 1fr 2fr 1fr;
  align-items: center;
  gap: 1rem;
  background: var(--color-bg);
  border-bottom: 1px solid var(--color-border);
  padding: 0.75rem 1.5rem;
}

.chrome-left  { justify-self: start; }
.chrome-center { justify-self: center; color: var(--color-muted); }
.chrome-right { justify-self: end; display: flex; align-items: center; gap: 1rem; }

.mark {
  font-weight: 400;
  letter-spacing: -0.01em;
}

.mark--display {
  font-size: 2rem;
  letter-spacing: -0.02em;
  margin: 0 0 0.5rem;
}

.doc-name {
  font-size: 0.9375rem;
  color: var(--color-text);
}

.doc-sha {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 0.8125rem;
  color: var(--color-muted);
  margin-left: 0.5rem;
}

.save-indicator {
  font-size: 0.8125rem;
  color: var(--color-muted);
}

.save-indicator.save--error { color: var(--color-error); }
.save-indicator.save--info { color: var(--color-shared-fg); }

.turn-indicator {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.875rem;
  color: var(--color-muted);
}

.turn-dot {
  display: inline-block;
  width: 0.5rem;
  height: 0.5rem;
  border-radius: 50%;
  background: var(--color-muted);
}

.turn--your-turn  .turn-dot { background: var(--color-accent-green); }
.turn--llm-reviewing .turn-dot { background: var(--color-accent-blue); }
.turn--your-review .turn-dot { background: var(--color-accent-blue); }

header#chrome a {
  color: var(--color-muted);
  text-decoration: none;
  font-size: 0.875rem;
}

header#chrome a:hover { text-decoration: underline; }

/* ---- Body layout: main + right rail ------------------------------------ */

.layout {
  display: flex;
  align-items: stretch;
  min-height: calc(100vh - 3rem); /* leave room for top bar */
}

main {
  flex: 1;
  min-width: 0; /* allow shrinking under flex */
}

main > section {
  max-width: var(--main-max);
  margin: 0 auto;
  padding: 2rem;
}

.lede {
  color: var(--color-muted);
  margin: 0 0 1.5rem;
}

.empty-state {
  color: var(--color-muted);
  font-size: 1.125rem;
}

.rail {
  width: var(--rail-width);
  flex-shrink: 0;
  border-left: 1px solid var(--color-border);
  padding: 2rem 1.5rem;
}

/* ---- Home / doc list -------------------------------------------------- */

.home-heading {
  font-size: 1.5rem;
  letter-spacing: -0.01em;
  margin: 0 0 1.5rem;
}

.doc-list {
  list-style: none;
  margin: 0;
  padding: 0;
}

.doc-list li {
  border-bottom: 1px solid var(--color-border);
}

.doc-list a {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  padding: 1rem 0;
  text-decoration: none;
  color: var(--color-text);
}

.doc-list a:hover { background: #fafafa; }

.doc-list .doc-meta {
  color: var(--color-muted);
  font-size: 0.8125rem;
}

/* ---- Editor ------------------------------------------------------------ */

.editor {
  white-space: pre-wrap;
  word-wrap: break-word;
  outline: none;
  min-height: 60vh;
  font-size: 15px;
  line-height: 1.6;
}

.editor:focus { outline: none; }

/* ---- Editor shell + highlight overlay --------------------------------- */

.editor-shell {
  position: relative;
}

.highlight-overlay {
  position: absolute;
  inset: 0;
  pointer-events: none; /* default; the .highlight children override */
  z-index: 0;
}

.editor {
  position: relative;
  z-index: 1; /* keep caret + text above the overlay */
}

.highlight {
  position: absolute;
  pointer-events: auto;
  cursor: pointer;
}

.highlight--shared { background: var(--color-shared-bg); }
.highlight--private { background: var(--color-private-bg); }
.highlight--shared.is-hover,
.highlight--shared.is-active { background: var(--color-shared-bg-hover); }
.highlight--private.is-hover,
.highlight--private.is-active { background: var(--color-private-bg-hover); }

/* ---- Comment rail ------------------------------------------------------ */

.rail-heading {
  font-size: 0.8125rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--color-muted);
  margin: 0 0 1rem;
}

.rail-empty {
  color: var(--color-muted);
  font-size: 0.875rem;
}

.comment-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.comment-entry {
  border: 1px solid var(--color-border);
  border-radius: 3px;
  padding: 0.625rem 0.75rem;
  font-size: 0.875rem;
  cursor: pointer;
  background: #fff;
}

.comment-entry.is-hover,
.comment-entry.is-active {
  border-color: var(--color-text);
}

.comment-entry .comment-meta {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.75rem;
  margin-bottom: 0.375rem;
}

.comment-entry .comment-badge {
  display: inline-block;
  padding: 0.0625rem 0.375rem;
  border-radius: 2px;
  font-size: 0.6875rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.comment-entry .comment-badge--shared {
  background: var(--color-shared-bg);
  color: var(--color-shared-fg);
}

.comment-entry .comment-badge--private {
  background: var(--color-private-bg);
  color: var(--color-private-fg);
}

.comment-entry .comment-time {
  color: var(--color-muted);
}

.comment-entry .comment-quote {
  display: block;
  color: var(--color-muted);
  font-style: italic;
  margin-top: 0.375rem;
  font-size: 0.75rem;
  border-left: 2px solid var(--color-border);
  padding-left: 0.5rem;
}

.comment-entry .comment-body {
  white-space: pre-wrap;
  word-wrap: break-word;
}

/* ---- Comment popover --------------------------------------------------- */

.popover {
  position: fixed;
  z-index: 100;
  background: #fff;
  border: 1px solid var(--color-text);
  border-radius: 3px;
  padding: 0.5rem;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.08); /* subtle drop only — chrome stays flat */
  min-width: 240px;
}

.popover-close {
  position: absolute;
  top: 0.25rem;
  right: 0.25rem;
  background: transparent;
  border: none;
  color: var(--color-text);
  font-size: 1rem;
  line-height: 1;
  padding: 0.125rem 0.375rem;
  cursor: pointer;
}

.popover-close:hover {
  background: #fafafa;
}

.popover-phase {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.popover-btn {
  padding: 0.375rem 0.75rem;
  font-size: 0.875rem;
  text-align: left;
}

.popover-btn--shared {
  background: var(--color-shared-fg);
  border-color: var(--color-shared-fg);
}

.popover-btn--private {
  background: var(--color-private-fg);
  border-color: var(--color-private-fg);
}

.popover-body {
  font-family: inherit;
  font-size: 0.875rem;
  padding: 0.5rem;
  border: 1px solid var(--color-border);
  border-radius: 2px;
  resize: vertical;
  width: 100%;
  box-sizing: border-box;
}

.popover-actions {
  display: flex;
  justify-content: flex-end;
  gap: 0.5rem;
  margin-top: 0.5rem;
}

.popover-cancel {
  background: #fff;
  color: var(--color-text);
  border-color: var(--color-border);
}

.popover-cancel:hover {
  background: #fafafa;
}

/* ---- Conflict banner --------------------------------------------------- */

.banner {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 1rem;
  background: #fef3c7;
  border-bottom: 1px solid #f59e0b;
  padding: 0.75rem 1.5rem;
  font-size: 0.875rem;
}

.banner button {
  padding: 0.25rem 0.75rem;
  font-size: 0.8125rem;
}

/* ---- Review banner (Track Changes) ------------------------------------ */

.banner--review {
  background: #dbeafe;
  border-bottom-color: var(--color-shared-fg);
  color: #1e3a8a;
}

/* ---- Stale-hunk banner (#96) ------------------------------------------ */
/* Surfaced when an apply_hunk 409 fires — the LLM's offsets don't bind to
   the current content. Reuses the .banner shape but in error-warm tones so
   it reads as "something to act on", not just informational. */

.banner--stale {
  background: #fee2e2;
  border-bottom-color: var(--color-error);
  color: #7f1d1d;
}

/* ---- Track Changes hunks ---------------------------------------------- */

.editor[contenteditable="false"] {
  cursor: default;
}

.hunk-del {
  color: #b91c1c;
  background: rgba(239, 68, 68, 0.10);
  text-decoration: line-through;
  text-decoration-color: rgba(185, 28, 28, 0.6);
  padding: 0 1px;
}

.hunk-ins {
  color: #166534;
  background: rgba(34, 197, 94, 0.15);
  text-decoration: none;
  padding: 0 1px;
}

.hunk-controls {
  display: inline-flex;
  gap: 0.125rem;
  margin: 0 0.25rem;
  vertical-align: middle;
  user-select: none;
}

.hunk-btn {
  font-family: inherit;
  font-size: 0.75rem;
  line-height: 1;
  padding: 0.125rem 0.375rem;
  border-radius: 2px;
  cursor: pointer;
  position: relative;
}

.hunk-btn--accept {
  background: #166534;
  border-color: #166534;
}

.hunk-btn--accept:hover { background: #14532d; }

.hunk-btn--reject {
  background: #fff;
  color: #b91c1c;
  border-color: #b91c1c;
}

.hunk-btn--reject:hover { background: #fee2e2; }

.hunk-btn[title]:hover::after {
  /* Native title is fine for tier-1 — saves a tooltip implementation. */
}

/* ---- Bulk action buttons ---------------------------------------------- */

.bulk-actions {
  display: inline-flex;
  gap: 0.375rem;
  align-items: center;
}

.bulk-btn {
  font-size: 0.8125rem;
  padding: 0.25rem 0.625rem;
}

.bulk-btn--accept {
  background: #166534;
  border-color: #166534;
}

.bulk-btn--accept:hover { background: #14532d; }

.bulk-btn--reject {
  background: #fff;
  color: #b91c1c;
  border-color: #b91c1c;
}

.bulk-btn--reject:hover { background: #fee2e2; }

/* ---- Comment "N proposals pending" line ------------------------------ */

.comment-pending {
  display: block;
  margin-top: 0.375rem;
  font-size: 0.75rem;
  color: var(--color-shared-fg);
  cursor: pointer;
}

.comment-pending:hover { text-decoration: underline; }

/* ---- Comment "LLM didn't respond" hint (#97) ------------------------- */
/* Surfaced when the post-comment poller hits its budget without seeing a
   proposal land. Muted, non-clickable — purely informational. */

.comment-no-response {
  display: block;
  margin-top: 0.375rem;
  font-size: 0.75rem;
  color: var(--color-muted);
  font-style: italic;
}

/* ---- Comment "LLM tried, gate filtered" entry (#63) ------------------- */

.comment-rejected {
  display: block;
  margin-top: 0.375rem;
  padding: 0.25rem 0;
  border-top: 1px dashed var(--color-border);
  font-size: 0.75rem;
  color: var(--color-muted, #6b7280);
  line-height: 1.5;
}

.comment-rejected-label {
  display: block;
  font-weight: 500;
  letter-spacing: 0.02em;
  text-transform: uppercase;
  color: var(--color-muted, #6b7280);
  font-size: 0.6875rem;
}

.comment-rejected-new {
  display: block;
  text-decoration: line-through;
  text-decoration-color: var(--color-muted, #9ca3af);
  color: var(--color-muted, #6b7280);
  font-style: italic;
}

.comment-rejected-reason {
  display: block;
  font-size: 0.6875rem;
  color: var(--color-muted, #9ca3af);
}

/* ---- Comment "stale" entry (#99) -------------------------------------- */
/* A previously-pending hunk that an upstream accept or save invalidated.
   Visually adjacent to .comment-rejected but warmer (it's actionable: the
   writer should reject), and carries an inline ✗ button. */

.comment-stale {
  display: flex;
  align-items: center;
  gap: 0.375rem;
  margin-top: 0.375rem;
  padding: 0.25rem 0;
  border-top: 1px dashed var(--color-error, #b91c1c);
  font-size: 0.75rem;
  color: #7f1d1d;
  line-height: 1.5;
}

.comment-stale-label {
  font-weight: 500;
  letter-spacing: 0.02em;
  text-transform: uppercase;
  font-size: 0.6875rem;
  color: #7f1d1d;
  flex-shrink: 0;
}

.comment-stale-new {
  flex: 1;
  text-decoration: line-through;
  text-decoration-color: rgba(185, 28, 28, 0.5);
  color: #7f1d1d;
  font-style: italic;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.comment-stale-reject {
  flex-shrink: 0;
}

/* ---- Buttons ----------------------------------------------------------- */

button {
  font-family: inherit;
  font-size: 0.9375rem;
  padding: 0.5rem 1rem;
  border: 1px solid var(--color-text);
  background: var(--color-text);
  color: #fff;
  cursor: pointer;
}

button:hover { background: #000; }

/* ---- Error surface ----------------------------------------------------- */

#error-view p {
  color: var(--color-error);
}

/* ---- Mobile: hide rail, stack top bar --------------------------------- */

@media (max-width: 720px) {
  header#chrome {
    grid-template-columns: 1fr 1fr;
    grid-template-rows: auto auto;
    row-gap: 0.5rem;
  }
  .chrome-left   { grid-column: 1; grid-row: 1; }
  .chrome-right  { grid-column: 2; grid-row: 1; }
  .chrome-center { grid-column: 1 / -1; grid-row: 2; justify-self: start; }

  .layout { flex-direction: column; }
  .rail { display: none; }
}

/* ---- Session-expired modal -------------------------------------------- */
/* Sits on top of the live editor DOM so a token expiry doesn't tear down
   in-flight text or open comment popovers (#100). The overlay catches
   clicks; the only action is "Sign in again", which routes through
   beginLogin() with the current pathname stashed for return. */

.modal {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.4);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
}

.modal-card {
  background: #fff;
  padding: 1.5rem;
  max-width: 28rem;
  width: calc(100% - 2rem);
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.2);
}

.modal-title {
  margin: 0 0 0.5rem 0;
  font-size: 1rem;
  font-weight: 600;
}

.modal-body {
  margin: 0 0 1rem 0;
  font-size: 0.875rem;
  color: var(--color-muted);
}

.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 0.5rem;
}

.modal-btn {
  padding: 0.5rem 1rem;
  font-size: 0.875rem;
}
