/* The document editor.
 *
 * A page of text you type into, with a toolbar. Deliberately plain: the
 * thing being edited is a document, and the chrome should stay out of its
 * way.
 */

/* The document, and a rail beside it. The rail holds the way back and
 * where the work is: the same two controls the File Processor keeps on
 * its right, in the same place, because they should not move between
 * two screens of one tool. */
.ed {
  display: grid;
  flex: 1 0 auto;
  gap: 24px;
  grid-template-columns: minmax(0, 1fr) 248px;
  margin: 0 auto;
  max-width: 1180px;
  padding: 28px 20px 48px;
  width: 100%;
}

/* The processing overlay covers the document, not the rail: cancelling
 * a job is not a reason to lose sight of the way out of the screen.
 * `inset: 0` needs a positioned ancestor to mean anything. */
.ed-main {
  min-width: 0;
  position: relative;
}

.ed-side {
  align-content: start;
  /* Without this the rail is a grid item stretched to the height of the
     document beside it, which was 1943px on a long letter, and sticky
     has nothing to do because the element already spans the scroll. */
  align-self: start;
  background: var(--pf-card);
  border: 1px solid var(--pf-line);
  border-radius: 12px;
  display: grid;
  gap: 10px;
  padding: 14px;
  position: sticky;
  top: 80px;
}

.ed-side .secondary-btn {
  justify-content: flex-start;
  width: 100%;
}

/* Under the rail's breakpoint it goes back above the document, where a
 * single column can only put it, but stays one row rather than two
 * full-width buttons. */
@media (max-width: 900px) {
  .ed {
    grid-template-columns: minmax(0, 1fr);
  }

  .ed-side {
    align-items: center;
    display: flex;
    flex-wrap: wrap;
    order: -1;
    position: static;
  }

  .ed-side .secondary-btn {
    width: auto;
  }
}

.ed-head {
  align-items: flex-start;
  display: flex;
  flex-wrap: wrap;
  gap: 14px;
  justify-content: space-between;
  margin-bottom: 22px;
}

.ed-head h1 {
  font-size: clamp(25px, 4vw, 32px);
  letter-spacing: -0.02em;
  margin-bottom: 4px;
  overflow-wrap: anywhere;
}

.ed-sub {
  color: var(--pf-muted);
  font-size: 15px;
  margin: 0;
}

.ed-head-end {
  align-items: center;
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}

/* Where the work is, in words. Reads "Keeping...", then "Draft kept",
   then "Saved as PDF". Quiet by design: it is reassurance, not a
   notification, and it is on screen the whole time. */
.ed-draft-state {
  color: var(--pf-muted);
  font-size: 13px;
  font-weight: 600;
  white-space: nowrap;
}

/* The AI row needs its explanation under the label, not beside it. */
#aiRow span small {
  color: var(--pf-muted);
  display: block;
  font-size: 12.5px;
  line-height: 1.45;
  margin-top: 2px;
}

#aiRow.is-unavailable {
  opacity: 0.55;
}

/* ---- Toolbar ------------------------------------------------------------ */

.ed-bar {
  align-items: center;
  background: var(--pf-card);
  border: 1px solid var(--pf-line);
  border-radius: 12px 12px 0 0;
  border-bottom: 0;
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  padding: 8px 10px;
  position: sticky;
  top: 0;
  z-index: 5;
}

.ed-group {
  align-items: center;
  display: flex;
  gap: 4px;
}

.ed-right {
  margin-left: auto;
}

.ed-btn {
  align-items: center;
  background: var(--pf-card);
  border: 1px solid var(--pf-line);
  border-radius: 7px;
  color: var(--pf-ink);
  cursor: pointer;
  display: inline-flex;
  font-size: 14px;
  height: 36px;
  justify-content: center;
  min-width: 36px;
  padding: 0 8px;
}

.ed-btn:hover {
  background: var(--pf-tint);
  border-color: var(--pf-primary);
}

.ed-btn.is-on {
  background: var(--pf-ok-soft);
  border-color: var(--pf-primary);
}

.ed-btn svg {
  height: 17px;
  width: 17px;
}

.ed-bar select {
  border: 1px solid var(--pf-line);
  border-radius: 7px;
  height: 36px;
  padding: 0 8px;
}

.ed-count {
  color: var(--pf-muted);
  font-size: 12.5px;
  white-space: nowrap;
}

/* ---- The page ----------------------------------------------------------- */

/* The workspace and the page are NEUTRAL, not green.
 *
 * Green is PhoneForge's colour for chrome: bars, headers, the things
 * that frame the work. It is not a colour to put behind a document.
 * Paper is white, and a document editor that tints the page green is
 * showing you something you will never print, which makes judging the
 * result impossible. In dark mode it goes to a neutral near-black for
 * the same reason, rather than to dark green.
 *
 * Local tokens so this one surface can be neutral without disturbing
 * the rest of the app's palette. */
.ed-paper-wrap {
  --ed-desk: #e9edeb;
  --ed-paper: #ffffff;
  --ed-ink: #14181a;

  background: var(--ed-desk);
  border: 1px solid var(--pf-line);
  border-radius: 0 0 12px 12px;
  padding: 22px;
}

/* Both selectors, because the suite supports an explicit choice as well
   as following the system. */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .ed-paper-wrap {
    --ed-desk: #15171a;
    --ed-paper: #1c1f22;
    --ed-ink: #e8eaec;
  }
}

:root[data-theme="dark"] .ed-paper-wrap {
  --ed-desk: #15171a;
  --ed-paper: #1c1f22;
  --ed-ink: #e8eaec;
}

/* A page the size of a page.
 *
 * A4 is 210 x 297mm, which at the 96dpi the browser assumes is
 * 794 x 1123px, and Word's default margin is one inch, which is 96px.
 * Using those exact numbers means the line breaks you see here are the
 * line breaks you get in the saved file, and the thing on screen is
 * recognisably a document rather than a web page.
 *
 * It shrinks on a narrow screen instead of forcing a sideways scroll;
 * the margins come in proportionally so the proportions still read as a
 * page. */
.ed-paper {
  background: var(--ed-paper);
  color: var(--ed-ink);
  border-radius: 2px;
  box-shadow: 0 2px 14px rgba(16, 43, 23, 0.14);
  margin: 0 auto;
  min-height: 1123px;
  padding: 96px;
  width: min(794px, 100%);
}

.ed-paper:focus {
  outline: 2px solid var(--pf-green-600);
  outline-offset: 3px;
}

/* Document typography, deliberately close to what a word processor shows,
   so what you edit resembles what gets written out. */
.ed-paper h1 {
  font-size: 25px;
  margin: 0 0 14px;
}

.ed-paper h2 {
  font-size: 20px;
  margin: 26px 0 10px;
}

.ed-paper h3 {
  font-size: 16.5px;
  margin: 22px 0 8px;
  text-transform: none;
}

.ed-paper p {
  font-size: 15px;
  line-height: 1.65;
  margin: 0 0 12px;
}

.ed-paper ul,
.ed-paper ol {
  margin: 0 0 14px;
  padding-left: 26px;
}

.ed-paper li {
  font-size: 15px;
  line-height: 1.6;
  margin-bottom: 6px;
}

.ed-paper strong {
  font-weight: 700;
}

@media (max-width: 860px) {
  .ed-paper {
    min-height: 70vh;
    padding: 7% 7%;
  }

  .ed-paper-wrap {
    padding: 12px;
  }

  .ed-right {
    margin-left: 0;
    width: 100%;
  }

  .ed-right #saveBtn {
    flex: 1;
    justify-content: center;
  }
}

/* ---- Pictures ----------------------------------------------------------
 *
 * A document editor that can show a picture but not move or resize one
 * is a document editor somebody has to leave to finish the job. These
 * are the four things a letterhead actually needs: bigger, smaller,
 * where on the line, and gone.
 */

.ed-paper img {
  cursor: pointer;
  display: block;
  height: auto;
  /* Never wider than the text column, whatever the source said. A scan
     can report a picture wider than the page, and one of those pushes
     the whole document sideways. */
  max-width: 100%;
}

.ed-paper img.is-selected {
  outline: 2px solid var(--pf-green-600);
  outline-offset: 2px;
}

/* Centring an image inside a contenteditable is done on the paragraph
   that holds it, because the image is a block and margin:auto is what
   actually moves it. */
.ed-paper p[data-img-align="center"] img { margin-left: auto; margin-right: auto; }
.ed-paper p[data-img-align="right"] img { margin-left: auto; margin-right: 0; }

/* The picture toolbar. Sits above the selected image rather than in the
   main bar: the main bar is for the document, and these four buttons
   apply to one thing and are meaningless without it. */
.ed-img-tools {
  background: var(--pf-card);
  border: 1px solid var(--pf-line);
  border-radius: 10px;
  box-shadow: 0 10px 28px rgba(0, 0, 0, 0.22);
  display: flex;
  gap: 2px;
  padding: 4px;
  position: absolute;
  z-index: 40;
}

.ed-img-tools button {
  background: none;
  border: 0;
  border-radius: 7px;
  color: var(--pf-ink);
  cursor: pointer;
  font: inherit;
  font-size: 13px;
  min-height: 34px;
  padding: 0 10px;
}

.ed-img-tools button:hover {
  background: var(--pf-tint);
}

.ed-img-tools button.is-danger {
  color: var(--pf-danger);
}
