/* ============================================================
   PDF-redigerare — fullscreen document editor
   Ribbon (tabs + tool groups) over a paged WYSIWYG canvas.
   ============================================================ */

.ed-root {
  position: fixed;
  inset: 0;
  display: flex;
  flex-direction: column;
  background: var(--color-surface-alt);
  z-index: 500;
}

/* --- Title bar --------------------------------------------- */
.ed-titlebar {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  padding: var(--space-2) var(--space-4);
  background: var(--color-pine);
  color: #fff;
  flex-shrink: 0;
}

.ed-titlebar__back {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  background: rgba(255,255,255,0.12);
  border: none;
  color: #fff;
  padding: var(--space-2) var(--space-3);
  border-radius: var(--radius);
  cursor: pointer;
  font-size: var(--text-sm);
  transition: background var(--transition-fast);
}
.ed-titlebar__back:hover { background: rgba(255,255,255,0.22); }

.ed-titlebar__name {
  font-size: var(--text-base);
  font-weight: var(--weight-semibold);
  background: transparent;
  border: 1px solid transparent;
  color: #fff;
  padding: var(--space-1) var(--space-2);
  border-radius: var(--radius-sm);
  min-width: 200px;
  flex: 1;
  max-width: 420px;
}
.ed-titlebar__name:hover  { border-color: rgba(255,255,255,0.3); }
.ed-titlebar__name:focus  { outline: none; background: rgba(255,255,255,0.15); border-color: rgba(255,255,255,0.5); }
.ed-titlebar__name::placeholder { color: rgba(255,255,255,0.6); }

.ed-titlebar__status {
  font-size: var(--text-xs);
  color: rgba(255,255,255,0.75);
  white-space: nowrap;
}

.ed-titlebar__actions { display: flex; align-items: center; gap: var(--space-2); margin-left: auto; }

.ed-btn {
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
  padding: var(--space-2) var(--space-3);
  border-radius: var(--radius);
  border: 1px solid rgba(255,255,255,0.25);
  background: transparent;
  color: #fff;
  font-size: var(--text-sm);
  font-weight: var(--weight-medium);
  cursor: pointer;
  white-space: nowrap;
  transition: background var(--transition-fast);
}
.ed-btn:hover:not(:disabled) { background: rgba(255,255,255,0.15); }
.ed-btn:disabled { opacity: 0.45; cursor: not-allowed; }
.ed-btn--solid { background: #fff; color: var(--color-pine); border-color: #fff; }
.ed-btn--solid:hover:not(:disabled) { background: rgba(255,255,255,0.88); }

/* --- Ribbon tabs ------------------------------------------- */
.ed-tabs {
  display: flex;
  gap: 2px;
  padding: 0 var(--space-3);
  background: var(--color-pine-mid);
  flex-shrink: 0;
  overflow-x: auto;
  scrollbar-width: none;
}
.ed-tabs::-webkit-scrollbar { display: none; }

.ed-tab {
  padding: var(--space-2) var(--space-4);
  border: none;
  background: transparent;
  color: rgba(255,255,255,0.8);
  font-size: var(--text-sm);
  font-weight: var(--weight-medium);
  cursor: pointer;
  border-radius: var(--radius) var(--radius) 0 0;
  white-space: nowrap;
  transition: background var(--transition-fast), color var(--transition-fast);
}
.ed-tab:hover { background: rgba(255,255,255,0.12); color: #fff; }
.ed-tab.is-active { background: var(--color-surface); color: var(--color-pine); }

/* --- Ribbon body ------------------------------------------- */
.ed-ribbon {
  background: var(--color-surface);
  border-bottom: 1px solid var(--color-border);
  padding: var(--space-2) var(--space-3);
  flex-shrink: 0;
  overflow-x: auto;
  scrollbar-width: thin;
}

.ed-panel { display: none; align-items: stretch; gap: var(--space-2); min-height: 56px; }
.ed-panel.is-active { display: flex; }

.ed-group {
  display: flex;
  flex-direction: column;
  gap: var(--space-1);
  padding: 0 var(--space-3);
  border-right: 1px solid var(--color-border-light);
}
.ed-group:last-child { border-right: none; }

.ed-group__row { display: flex; align-items: center; gap: var(--space-1); flex-wrap: nowrap; }

.ed-group__label {
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--color-subtle);
  text-align: center;
  margin-top: 2px;
}

/* --- Tool buttons ------------------------------------------ */
.tb {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-2);
  min-width: 32px;
  height: 32px;
  padding: 0 var(--space-2);
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--color-ink);
  font-size: var(--text-sm);
  cursor: pointer;
  white-space: nowrap;
  transition: background var(--transition-fast), border-color var(--transition-fast);
}
.tb:hover:not(:disabled) { background: var(--color-pine-light); border-color: var(--color-border); }
.tb.is-active { background: var(--color-pine-light); border-color: var(--color-pine); color: var(--color-pine); }
.tb:disabled {
  opacity: 0.35;
  cursor: not-allowed;
  background: transparent;
  border-color: transparent;
}
.tb--wide { min-width: auto; padding: 0 var(--space-3); }
.tb svg { flex-shrink: 0; }

.ed-select {
  height: 32px;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
  background: var(--color-surface);
  color: var(--color-ink);
  font-size: var(--text-sm);
  padding: 0 var(--space-2);
  cursor: pointer;
  max-width: 160px;
}
.ed-select:focus { outline: none; border-color: var(--color-pine); }
.ed-select--font { min-width: 130px; }
.ed-select--size { width: 68px; }

.ed-color {
  width: 32px;
  height: 32px;
  padding: 2px;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
  background: var(--color-surface);
  cursor: pointer;
}

/* --- Canvas / pages ---------------------------------------- */
.ed-canvas {
  flex: 1;
  overflow: auto;
  padding: var(--space-8) var(--space-4) var(--space-20);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--space-6);
}

.ed-page {
  background: #fff;
  box-shadow: var(--shadow-md);
  border-radius: 2px;
  position: relative;
  /* width/padding are set inline from the page-setup state */
}

.ed-page__body {
  outline: none;
  min-height: 100%;
  font-family: Calibri, Carlito, var(--font-sans);
  font-size: 11pt;
  line-height: 1.5;
  color: #111;
}

.ed-page__body:focus { outline: none; }

/* Keep the selection painted even while focus is on a ribbon control.
   Without this the browser dims the highlight the moment a select or
   colour picker takes focus, so it looks as if the selection was lost. */
.ed-page__body::selection,
.ed-page__body *::selection {
  background: #b4d5fe;
  color: inherit;
}

.ed-page__num {
  position: absolute;
  bottom: -22px;
  right: 4px;
  font-size: var(--text-xs);
  color: var(--color-subtle);
}

/* Content styles inside the editable body */
.ed-page__body h1 { font-size: 20pt; font-weight: 700; margin: 0 0 8pt; line-height: 1.25; }
.ed-page__body h2 { font-size: 16pt; font-weight: 700; margin: 12pt 0 6pt; line-height: 1.3; }
.ed-page__body h3 { font-size: 13pt; font-weight: 700; margin: 10pt 0 4pt; line-height: 1.3; }
.ed-page__body p  { margin: 0 0 8pt; }
.ed-page__body ul,
.ed-page__body ol { margin: 0 0 8pt; padding-left: 24pt; }
.ed-page__body li { margin-bottom: 2pt; }
.ed-page__body blockquote {
  margin: 8pt 0;
  padding-left: 12pt;
  border-left: 3px solid var(--color-border);
  color: #444;
}
.ed-page__body img {
  max-width: 100%;
  height: auto;
  vertical-align: baseline;
}
.ed-page__body img.is-selected { outline: 2px solid var(--color-pine); outline-offset: 2px; }
.ed-page__body hr { border: none; border-top: 1px solid #999; margin: 10pt 0; }

/* Tables. These rules have to out-specify the site-wide table styling in
   global.css, which sets only `border-bottom` on cells and then removes it
   again on `tr:last-child td` — correct for data listings, but it made the
   editor's tables read as invisible. Every edge is stated explicitly. */
.ed-page__body table {
  border-collapse: collapse;
  margin: 8pt 0;
  width: 100%;
  table-layout: fixed;
  font-size: inherit;
}

.ed-page__body table tr td,
.ed-page__body table tr th {
  border: 1px solid #555;
  padding: 4pt 6pt;
  vertical-align: top;
  word-wrap: break-word;
  font-size: inherit;
  text-transform: none;
  letter-spacing: normal;
  color: inherit;
  /* An empty cell would otherwise collapse to zero height, making a fresh
     table look like a thin strip rather than a grid. */
  min-width: 24px;
  height: 1.6em;
}

.ed-page__body table tr:last-child td,
.ed-page__body table tr:last-child th {
  border-bottom: 1px solid #555;
}

.ed-page__body table tr th {
  background: #f0ede6;
  font-weight: 700;
  text-align: left;
}

/* The site style tints rows on hover; inside a document that reads as a
   selection artefact, so it is switched off. */
.ed-page__body table tr:hover td {
  background: transparent;
}

/* "Växla kantlinjer" hides the printed border but keeps a faint guide on
   screen, so the table stays findable while editing. It is not exported. */
.ed-page__body table.no-borders tr td,
.ed-page__body table.no-borders tr th {
  border: 1px dashed var(--color-border);
}

.ed-page__body a { color: #1155cc; text-decoration: underline; }

/* Attachment chip */
.ed-attach {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 3px 8px;
  margin: 2px 0;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
  background: var(--color-surface-alt);
  font-size: 10pt;
  text-decoration: none;
  color: var(--color-ink);
}
.ed-attach__icon { font-size: 12pt; }

/* Page-break marker shown while editing (not exported) */
.ed-pagebreak {
  border-top: 2px dashed var(--color-accent);
  margin: 10pt 0;
  position: relative;
  height: 0;
}
.ed-pagebreak::after {
  content: 'Sidbrytning';
  position: absolute;
  right: 0;
  top: -8px;
  font-size: 8pt;
  color: var(--color-accent);
  background: #fff;
  padding: 0 4px;
}

/* --- Status / toast ---------------------------------------- */
.ed-toast {
  position: fixed;
  bottom: var(--space-6);
  left: 50%;
  transform: translateX(-50%) translateY(10px);
  background: var(--color-ink);
  color: #fff;
  padding: var(--space-3) var(--space-5);
  border-radius: var(--radius-full);
  font-size: var(--text-sm);
  box-shadow: var(--shadow-lg);
  opacity: 0;
  pointer-events: none;
  transition: opacity var(--transition), transform var(--transition);
  z-index: 900;
}
.ed-toast.is-visible { opacity: 1; transform: translateX(-50%) translateY(0); }
.ed-toast--danger  { background: var(--color-danger); }
.ed-toast--success { background: var(--color-success); }

/* --- Locked banner ----------------------------------------- */
.ed-locked {
  display: none;
  align-items: center;
  gap: var(--space-2);
  padding: var(--space-2) var(--space-4);
  background: var(--color-warning-light);
  color: #7c4a03;
  border-bottom: 1px solid #fde68a;
  font-size: var(--text-sm);
  flex-shrink: 0;
}
.ed-locked.is-visible { display: flex; }

/* --- Document library (start screen) ------------------------ */
.ed-library { max-width: var(--container-max); margin: 0 auto; width: 100%; }

.ed-lib-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(230px, 1fr));
  gap: var(--space-4);
}

.ed-doc-card {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  padding: var(--space-4);
  cursor: pointer;
  transition: border-color var(--transition-fast), box-shadow var(--transition-fast), transform var(--transition-fast);
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
}
.ed-doc-card:hover {
  border-color: var(--color-pine);
  box-shadow: var(--shadow);
  transform: translateY(-2px);
}

.ed-doc-card__title {
  font-weight: var(--weight-semibold);
  font-size: var(--text-base);
  color: var(--color-ink);
  display: flex;
  align-items: center;
  gap: var(--space-2);
  word-break: break-word;
}
.ed-doc-card__meta { font-size: var(--text-xs); color: var(--color-muted); }
.ed-doc-card__actions { display: flex; gap: var(--space-2); margin-top: auto; padding-top: var(--space-2); flex-wrap: wrap; }

.ed-newdoc-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(190px, 1fr));
  gap: var(--space-4);
  margin-bottom: var(--space-8);
}

.ed-newdoc {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  padding: var(--space-5) var(--space-4);
  cursor: pointer;
  text-align: left;
  transition: border-color var(--transition-fast), box-shadow var(--transition-fast), transform var(--transition-fast);
}
.ed-newdoc:hover { border-color: var(--color-pine); box-shadow: var(--shadow); transform: translateY(-2px); }
.ed-newdoc__icon { font-size: 1.75rem; margin-bottom: var(--space-2); display: block; }
.ed-newdoc__title { font-weight: var(--weight-semibold); font-size: var(--text-sm); margin-bottom: 2px; }
.ed-newdoc__desc  { font-size: var(--text-xs); color: var(--color-muted); line-height: var(--leading-snug); }

/* --- Find & replace bar ------------------------------------ */
.ed-find {
  display: none;
  align-items: center;
  gap: var(--space-2);
  padding: var(--space-2) var(--space-4);
  background: var(--color-info-light);
  border-bottom: 1px solid #bfdbfe;
  flex-shrink: 0;
  flex-wrap: wrap;
}
.ed-find.is-visible { display: flex; }
.ed-find input {
  height: 30px;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
  padding: 0 var(--space-2);
  font-size: var(--text-sm);
  min-width: 140px;
}
.ed-find input:focus { outline: none; border-color: var(--color-pine); }
mark.ed-hit { background: #fde68a; }
mark.ed-hit--current { background: var(--color-warning); color: #fff; }

/* --- Import progress --------------------------------------- */
.ed-import {
  position: fixed;
  inset: 0;
  background: rgba(26,26,24,0.55);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 950;
}
.ed-import.is-visible { display: flex; }
.ed-import__box {
  background: var(--color-surface);
  border-radius: var(--radius-md);
  padding: var(--space-8);
  text-align: center;
  min-width: 280px;
  box-shadow: var(--shadow-lg);
}
.ed-import__spin {
  width: 32px; height: 32px;
  border: 3px solid var(--color-border);
  border-top-color: var(--color-pine);
  border-radius: 50%;
  margin: 0 auto var(--space-4);
  animation: ed-spin 0.8s linear infinite;
}
@keyframes ed-spin { to { transform: rotate(360deg); } }

/* --- Mobile ------------------------------------------------- */
@media (max-width: 720px) {
  .ed-titlebar { flex-wrap: wrap; padding: var(--space-2); }
  .ed-titlebar__name { min-width: 120px; order: 3; flex-basis: 100%; max-width: none; }
  .ed-titlebar__status { display: none; }
  .ed-group { padding: 0 var(--space-2); }
  .ed-canvas { padding: var(--space-4) var(--space-2) var(--space-16); }
  .ed-page { transform-origin: top center; }
  .tb--wide span { display: none; }
}
