/*
 * The companion pane (§6, option 4c).
 *
 * Written entirely in the tokens: there is not a literal colour in this file,
 * and there should never be one -- the ink theme redefines the variables and
 * nothing here needs to know it happened.
 *
 * The geometry is fixed on purpose. `--companion-w` beside, `--companion-h`
 * below, and no percentages: the manuscript measure steps between two values
 * (see `measureFor` in src/companion/companion.ts) rather than being whatever
 * is left over, so opening the pane cannot reflow the sentence under the caret.
 */

.novely-companion {
  display: flex;
  flex-direction: column;
  flex: none;
  min-height: 0;
  background: var(--companion);
  font-family: var(--font-ui);
  color: var(--text);
}

/* Beside: a fixed column, with the hairline on whichever side faces the text. */
.novely-companion-beside {
  width: var(--companion-w);
}

.novely-companion-beside.novely-companion-right {
  border-left: 1px solid var(--hairline);
}

.novely-companion-beside.novely-companion-left {
  border-right: 1px solid var(--hairline);
  order: -1;
}

/* Below: the measure is untouched, so the pane takes height and nothing else. */
.novely-companion-below {
  width: 100%;
  height: var(--companion-h);
  border-top: 1px solid var(--hairline);
}

.novely-companion-slot {
  display: flex;
  flex-direction: column;
  min-height: 0;
  flex: 1;
}

.novely-companion-split .novely-companion-slot + .novely-companion-slot {
  border-top: 1px solid var(--hairline);
}

/* ---------------------------------------------------------------------- */
/* Header                                                                  */
/* ---------------------------------------------------------------------- */

.novely-companion-head {
  height: 38px;
  flex: none;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 0 12px 0 16px;
  border-bottom: 1px solid var(--hairline);
}

.novely-companion-title,
.novely-companion-tab {
  font-family: var(--font-mono);
  font-size: var(--size-10-5);
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.novely-companion-title {
  font-weight: 500;
  color: var(--text);
}

.novely-companion-tab {
  font-weight: 400;
  color: var(--muted-5);
  background: transparent;
  border: 0;
  padding: 4px 0;
  cursor: pointer;
}

.novely-companion-tab:hover {
  color: var(--text);
}

.novely-companion-spacer {
  flex: 1;
}

.novely-companion-icon {
  font-family: var(--font-mono);
  font-size: var(--size-11);
  color: var(--muted-4);
  background: transparent;
  border: 0;
  padding: 4px;
  cursor: pointer;
}

.novely-companion-icon:hover {
  color: var(--text);
}

.novely-companion-placement {
  display: flex;
  gap: 2px;
  margin-left: 8px;
}

.novely-companion-placement-button {
  border: 0;
  background: transparent;
  color: var(--muted-3);
  font: inherit;
  font-size: 10px;
  padding: 3px 4px;
  cursor: pointer;
}

.novely-companion-placement-button.is-on,
.novely-companion-placement-button:hover {
  color: var(--text);
  background: var(--panel);
}

/* ---------------------------------------------------------------------- */
/* Body                                                                    */
/* ---------------------------------------------------------------------- */

.novely-companion-body {
  flex: 1;
  min-height: 0;
  overflow: auto;
  padding: 16px 18px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

/* Below the manuscript the pane is wide and short, so its rows read in two
   columns rather than as one long scroll of a list. */
.novely-companion-below .novely-companion-body {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  align-content: start;
}

.novely-companion-group {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.novely-companion-group-label {
  font-family: var(--font-mono);
  font-size: var(--size-10);
  color: var(--muted-4);
}

.novely-companion-rows {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.novely-companion-row {
  display: flex;
  align-items: baseline;
  gap: 10px;
  padding: 8px 10px;
  background: var(--panel);
  border: 1px solid var(--hairline);
  border-radius: var(--r-row);
}

/*
 * A row the manuscript disagrees with. The violated hue, at half strength: it
 * is a report that the sheet and the text differ, not a defect and not a task.
 */
.novely-companion-row-conflict {
  border-color: color-mix(in oklch, var(--kind-violated) 50%, transparent);
}

.novely-companion-term {
  flex: 1;
  font-family: var(--font-mono);
  font-size: var(--size-12-5);
  font-weight: 500;
  color: var(--text);
}

.novely-companion-note {
  font-family: var(--font-mono);
  font-size: var(--size-10);
  color: var(--muted-5);
}

.novely-companion-count {
  font-family: var(--font-mono);
  font-size: var(--size-10);
  color: var(--muted-2);
  background: transparent;
  border: 1px solid var(--border-strong);
  border-radius: var(--r-popover);
  padding: 3px 7px;
  cursor: pointer;
}

.novely-companion-count:hover {
  border-color: var(--border-hover);
}

.novely-companion-empty {
  margin: 0;
  font-size: var(--size-12);
  line-height: var(--leading-ui-prose);
  color: var(--muted-3);
}

.novely-companion-foot {
  flex: none;
  padding: 0 18px 16px;
  font-family: var(--font-mono);
  font-size: var(--size-10);
  line-height: 1.5;
  color: var(--muted-6);
}

/*
 * A reference document, open for editing.
 *
 * Plain: it is the author's own Markdown, exactly as it sits on disk, and
 * anything cleverer here would be a second editor to keep in step with the one
 * the manuscript uses.
 */
.novely-companion-doc {
  width: 100%;
  min-height: 12rem;
  height: 100%;
  box-sizing: border-box;
  padding: 0.75rem;
  border: 0;
  background: transparent;
  color: var(--prose);
  font: 400 var(--size-13) / 1.6 var(--font-mono);
  resize: none;
}

.novely-companion-doc:focus-visible {
  outline: none;
  background: var(--row-hover);
}
