/* Document workspace: Word-like page with findings highlighted in the text,
   a findings panel with one-click decisions and a minimap. Pure CSS/vanilla JS. */

.sa-main--workspace {
  padding: 0;
}

.sa-ws {
  display: flex;
  flex-direction: column;
  height: calc(100vh - var(--sa-topbar-height));
  min-height: 520px;
}

/* Toolbar -------------------------------------------------------------- */
.sa-ws-toolbar {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 0.6rem 1rem;
  padding: 0.55rem 1rem;
  background: var(--sa-surface);
  border-bottom: 1px solid var(--sa-border);
  flex-shrink: 0;
}

.sa-ws-toolbar__title {
  display: flex;
  align-items: center;
  gap: 0.65rem;
  min-width: 0;
  max-width: 420px;
}

.sa-ws-back {
  width: 32px;
  height: 32px;
  border-radius: var(--sa-radius-sm);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: var(--sa-text-secondary);
  background: var(--sa-surface-secondary);
  flex-shrink: 0;
}

.sa-ws-back:hover {
  background: var(--sa-primary-light);
  color: var(--sa-primary);
}

.sa-ws-toolbar__name {
  font-weight: 600;
  font-size: 0.95rem;
  line-height: 1.2;
}

.sa-ws-toolbar__sub {
  font-size: 0.75rem;
  color: var(--sa-text-muted);
}

.sa-ws-toolbar__filters,
.sa-ws-toolbar__tools,
.sa-ws-toolbar__progress {
  display: flex;
  align-items: center;
  gap: 0.4rem;
}

.sa-ws-toolbar__tools {
  gap: 0.5rem;
  flex-wrap: wrap;
}

.min-w-0 { min-width: 0; }

.sa-chip {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  border: 1px solid var(--sa-border);
  background: var(--sa-surface);
  color: var(--sa-text-secondary);
  border-radius: 999px;
  padding: 0.2rem 0.65rem;
  font-size: 0.78rem;
  font-weight: 500;
  cursor: pointer;
  transition: all .15s ease;
}

.sa-chip b { color: var(--sa-text); }

.sa-chip__dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--sev, var(--sa-text-muted));
}

.sa-chip--critical { --sev: var(--sa-severity-critical); }
.sa-chip--high { --sev: var(--sa-severity-high); }
.sa-chip--medium { --sev: var(--sa-severity-medium); }
.sa-chip--low { --sev: var(--sa-severity-low); }
.sa-chip--info { --sev: var(--sa-severity-info); }

.sa-chip:not(.is-on) {
  opacity: 0.55;
  background: var(--sa-surface-secondary);
}

.sa-chip.is-on {
  border-color: var(--sev);
  background: color-mix(in srgb, var(--sev) 9%, white);
}

.sa-ws-progress {
  width: 110px;
  height: 6px;
  border-radius: 999px;
  background: var(--sa-border-light);
  overflow: hidden;
}

.sa-ws-progress__bar {
  height: 100%;
  background: var(--sa-gradient);
  transition: width .3s ease;
}

/* Body ------------------------------------------------------------------ */
.sa-ws-body {
  flex: 1;
  min-height: 0;
  display: grid;
  grid-template-columns: 220px minmax(0, 1fr) 14px 400px;
  background: var(--sa-bg);
}

.sa-ws-pane-title {
  font-size: 0.7rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--sa-text-muted);
  padding: 0.25rem 0.5rem 0.6rem;
}

.sa-ws-outline,
.sa-ws-panel {
  background: var(--sa-surface);
  overflow-y: auto;
  padding: 1rem 0.75rem;
}

.sa-ws-outline { border-right: 1px solid var(--sa-border); }
.sa-ws-panel { border-left: 1px solid var(--sa-border); background: var(--sa-surface-secondary); }

.sa-ws-outline__link {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 0.5rem;
  padding: 0.4rem 0.6rem;
  border-radius: var(--sa-radius-sm);
  font-size: 0.85rem;
  color: var(--sa-text-secondary);
}

.sa-ws-outline__link:hover { background: var(--sa-surface-secondary); color: var(--sa-text); }
.sa-ws-outline__link.is-current { background: var(--sa-primary-light); color: var(--sa-primary-dark); font-weight: 600; }

.sa-ws-outline__count {
  font-size: 0.7rem;
  font-weight: 700;
  min-width: 20px;
  text-align: center;
  padding: 0.05rem 0.4rem;
  border-radius: 999px;
  background: rgba(234, 88, 12, .14);
  color: var(--sa-severity-high);
}

/* The page ---------------------------------------------------------------- */
.sa-ws-canvas {
  overflow-y: auto;
  padding: 2rem 1.5rem 4rem;
  scroll-behavior: smooth;
  position: relative;
}

.sa-paper {
  --sa-paper-size: 17px;
  max-width: 820px;
  margin: 0 auto;
  background: #fff;
  padding: 3.25rem 4rem;
  border-radius: 4px;
  border: 1px solid var(--sa-border);
  box-shadow: 0 1px 2px rgba(15, 23, 42, .06), 0 12px 40px rgba(15, 23, 42, .08);
  font-family: var(--sa-font-serif);
  font-size: var(--sa-paper-size);
  line-height: 1.8;
  color: #1e293b;
  min-height: 100%;
}

.sa-paper h3 {
  font-family: var(--sa-font-sans);
  font-size: 1.25em;
  margin: 1.8em 0 0.6em;
  color: var(--sa-text);
}

.sa-paper .sa-paper__section:first-child h3 { margin-top: 0; }

.sa-paper .sa-fragment {
  margin: 0 -0.75rem 0.6rem;
  padding: 0.2rem 0.75rem;
  border-radius: 6px;
  border-left: 3px solid transparent;
  background: transparent;
  scroll-margin-top: 90px;
  transition: background .2s ease, border-color .2s ease, opacity .2s ease;
}

.sa-paper .sa-fragment--table {
  font-family: var(--sa-font-sans);
  font-size: 0.85em;
  background: var(--sa-surface-secondary);
}

.sa-paper .sa-fragment[data-severity="critical"] { border-left-color: var(--sa-severity-critical); }
.sa-paper .sa-fragment[data-severity="high"] { border-left-color: var(--sa-severity-high); }
.sa-paper .sa-fragment[data-severity="medium"] { border-left-color: var(--sa-severity-medium); }
.sa-paper .sa-fragment[data-severity="low"] { border-left-color: var(--sa-severity-low); }
.sa-paper .sa-fragment[data-severity="info"] { border-left-color: var(--sa-severity-info); }

.sa-paper .sa-fragment.is-selected {
  outline: none;
  background: rgba(79, 70, 229, .05);
}

.sa-paper.only-flagged .sa-fragment:not([data-severity]) { display: none; }
.sa-paper.only-flagged .sa-paper__section:not(:has([data-severity])) { display: none; }

/* Highlights ------------------------------------------------------------- */
.sa-hl {
  --hl: var(--sa-severity-info);
  background: color-mix(in srgb, var(--hl) 16%, transparent);
  border-bottom: 2px solid var(--hl);
  border-radius: 3px;
  padding: 0.05em 0.1em;
  color: inherit;
  cursor: pointer;
  transition: background .15s ease, box-shadow .15s ease;
}

.sa-hl--critical { --hl: var(--sa-severity-critical); }
.sa-hl--high { --hl: var(--sa-severity-high); }
.sa-hl--medium { --hl: var(--sa-severity-medium); }
.sa-hl--low { --hl: var(--sa-severity-low); }

.sa-hl:hover { background: color-mix(in srgb, var(--hl) 28%, transparent); }

.sa-hl.is-active {
  background: color-mix(in srgb, var(--hl) 34%, transparent);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--hl) 30%, transparent);
  outline: none;
}

.sa-hl__num,
.sa-marker {
  font-family: var(--sa-font-sans);
  font-size: 0.62em;
  font-weight: 700;
  color: #fff;
  background: var(--hl, var(--sa-severity-info));
  border-radius: 999px;
  min-width: 1.5em;
  height: 1.5em;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  margin-left: 0.2em;
  vertical-align: super;
  line-height: 1;
  padding: 0 0.3em;
}

.sa-marker {
  border: 0;
  cursor: pointer;
  vertical-align: baseline;
  font-size: 0.7em;
}

.sa-marker--critical { --hl: var(--sa-severity-critical); }
.sa-marker--high { --hl: var(--sa-severity-high); }
.sa-marker--medium { --hl: var(--sa-severity-medium); }
.sa-marker--low { --hl: var(--sa-severity-low); }

.sa-marker.is-active { box-shadow: 0 0 0 3px color-mix(in srgb, var(--hl) 35%, transparent); }

/* Decided findings fade out of the way, like resolved comments in Word. */
.sa-hl[data-status="accepted"] { border-bottom-style: dashed; }
.sa-hl[data-status="resolved"] {
  --hl: var(--sa-success);
  background: rgba(22, 163, 74, .08);
}
.sa-hl[data-status="rejected"] {
  background: transparent;
  border-bottom: 1px dotted var(--sa-text-muted);
  opacity: .6;
}
.sa-hl[data-status="rejected"] .sa-hl__num,
.sa-marker[data-status="rejected"] { background: var(--sa-text-muted); }

.sa-hl.is-dim, .sa-marker.is-dim {
  background: transparent;
  border-bottom-color: transparent;
}
.sa-hl.is-dim .sa-hl__num, .sa-marker.is-dim { display: none; }

/* Minimap ------------------------------------------------------------------ */
.sa-ws-map {
  position: relative;
  background: var(--sa-surface);
  border-left: 1px solid var(--sa-border);
  cursor: pointer;
}

.sa-ws-map__tick {
  position: absolute;
  left: 2px;
  right: 2px;
  height: 4px;
  border-radius: 2px;
  background: var(--tick, var(--sa-severity-info));
  opacity: .85;
}

.sa-ws-map__tick.is-active { box-shadow: 0 0 0 2px color-mix(in srgb, var(--tick) 40%, transparent); opacity: 1; }
.sa-ws-map__tick[data-severity="critical"] { --tick: var(--sa-severity-critical); }
.sa-ws-map__tick[data-severity="high"] { --tick: var(--sa-severity-high); }
.sa-ws-map__tick[data-severity="medium"] { --tick: var(--sa-severity-medium); }
.sa-ws-map__tick[data-severity="low"] { --tick: var(--sa-severity-low); }

.sa-ws-map__view {
  position: absolute;
  left: 0;
  right: 0;
  background: rgba(79, 70, 229, .12);
  border-top: 1px solid rgba(79, 70, 229, .4);
  border-bottom: 1px solid rgba(79, 70, 229, .4);
  pointer-events: none;
}

/* Finding cards ---------------------------------------------------------------- */
.sa-fc {
  --sev: var(--sa-severity-info);
  background: var(--sa-surface);
  border: 1px solid var(--sa-border);
  border-left: 4px solid var(--sev);
  border-radius: var(--sa-radius-md);
  padding: 0.85rem 0.95rem;
  margin-bottom: 0.7rem;
  box-shadow: var(--sa-shadow-sm);
  cursor: pointer;
  transition: box-shadow .15s ease, border-color .15s ease, opacity .2s ease, transform .15s ease;
}

.sa-fc--critical { --sev: var(--sa-severity-critical); }
.sa-fc--high { --sev: var(--sa-severity-high); }
.sa-fc--medium { --sev: var(--sa-severity-medium); }
.sa-fc--low { --sev: var(--sa-severity-low); }

.sa-fc:hover { box-shadow: var(--sa-shadow-md); }

.sa-fc.is-active {
  border-color: var(--sev);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--sev) 22%, transparent), var(--sa-shadow-md);
}

.sa-fc[data-status="rejected"] { opacity: .55; }
.sa-fc[data-status="resolved"] { --sev: var(--sa-success); opacity: .75; }

.sa-fc__head { display: flex; align-items: center; gap: 0.5rem; margin-bottom: 0.4rem; }

.sa-fc__num {
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: var(--sev);
  color: #fff;
  font-size: 0.72rem;
  font-weight: 700;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.sa-fc__badges { display: flex; flex-wrap: wrap; gap: 0.3rem; min-width: 0; }
.badge-cat { background: var(--sa-surface-secondary); color: var(--sa-text-secondary); border: 1px solid var(--sa-border); }

.sa-fc__state {
  margin-left: auto;
  font-size: 0.7rem;
  color: var(--sa-text-muted);
  white-space: nowrap;
}

.sa-fc[data-status="accepted"] .sa-fc__state { color: var(--sa-success); }
.sa-fc[data-status="resolved"] .sa-fc__state { color: var(--sa-success); }

.sa-fc__title { font-weight: 600; font-size: 0.92rem; margin-bottom: 0.25rem; }
.sa-fc__text { font-size: 0.84rem; color: var(--sa-text-secondary); }

.sa-fc__rec {
  font-size: 0.82rem;
  margin-top: 0.5rem;
  padding: 0.45rem 0.6rem;
  background: var(--sa-primary-light);
  border-radius: var(--sa-radius-sm);
  color: var(--sa-primary-dark);
}

.sa-fc__actions { display: flex; flex-wrap: wrap; gap: 0.35rem; margin-top: 0.7rem; }
.sa-fc__actions form { display: contents; }

.sa-act {
  border: 1px solid var(--sa-border);
  background: var(--sa-surface);
  color: var(--sa-text-secondary);
  border-radius: 999px;
  padding: 0.25rem 0.7rem;
  font-size: 0.78rem;
  font-weight: 500;
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
  transition: all .15s ease;
}

.sa-act:hover { border-color: var(--sa-primary); color: var(--sa-primary); }

.sa-act--accepted[aria-pressed="true"],
.sa-act--resolved[aria-pressed="true"] { background: var(--sa-success); border-color: var(--sa-success); color: #fff; }
.sa-act--rejected[aria-pressed="true"] { background: var(--sa-text-secondary); border-color: var(--sa-text-secondary); color: #fff; }
.sa-act--more { margin-left: auto; padding: 0.25rem 0.55rem; }

.sa-fc__more { margin-top: 0.75rem; padding-top: 0.75rem; border-top: 1px solid var(--sa-border-light); cursor: default; }
.sa-fc__label { font-size: 0.7rem; font-weight: 600; text-transform: uppercase; letter-spacing: .05em; color: var(--sa-text-muted); }
.sa-fc__meta { font-size: 0.75rem; color: var(--sa-text-muted); }

.sa-fc.is-hidden { display: none; }

kbd {
  background: var(--sa-surface-secondary);
  color: var(--sa-text);
  border: 1px solid var(--sa-border);
  border-radius: 4px;
  padding: 0 0.3rem;
  font-size: 0.75rem;
}

/* Responsive ----------------------------------------------------------------- */
@media (max-width: 1399.98px) {
  .sa-ws-body { grid-template-columns: 0 minmax(0, 1fr) 14px 360px; }
  .sa-ws-outline { display: none; }
}

@media (max-width: 991.98px) {
  .sa-ws { height: auto; }
  .sa-ws-body { display: block; }
  .sa-ws-map { display: none; }
  .sa-ws-canvas { overflow: visible; padding: 1rem 0.5rem; }
  .sa-paper { padding: 1.5rem 1.25rem; }
  .sa-ws-panel { border-left: 0; border-top: 1px solid var(--sa-border); }
}

.sa-ws-outline { grid-column: 1; }
.sa-ws-canvas { grid-column: 2; }
.sa-ws-map { grid-column: 3; }
.sa-ws-panel { grid-column: 4; }
@media (max-width: 991.98px) {
  .sa-ws-outline, .sa-ws-canvas, .sa-ws-map, .sa-ws-panel { grid-column: auto; }
}

/* Live status banner ------------------------------------------------------------ */
.sa-ws-banner {
  display: flex;
  align-items: center;
  gap: .85rem;
  padding: .7rem 1rem;
  background: var(--sa-primary-light);
  border-bottom: 1px solid rgba(79, 70, 229, .2);
  flex-shrink: 0;
}
.sa-ws-banner--error { background: rgba(220, 38, 38, .08); border-bottom-color: rgba(220, 38, 38, .25); color: var(--sa-danger); }
.sa-ws-banner__title { font-weight: 600; font-size: .9rem; color: var(--sa-text); }
.sa-ws-banner__sub { font-size: .78rem; color: var(--sa-text-secondary); }
.sa-ws-progress--wide { width: 180px; background: rgba(79, 70, 229, .15); }

/* Completion card ------------------------------------------------------------------ */
.sa-done {
  text-align: center;
  padding: 1.25rem 1rem 1rem;
  margin-bottom: .9rem;
  border-radius: var(--sa-radius-md);
  background: linear-gradient(135deg, #ecfdf5 0%, #f0fdf4 100%);
  border: 1px solid rgba(22, 163, 74, .3);
}
.sa-done__icon { font-size: 2.2rem; color: var(--sa-success); line-height: 1; }
.sa-done__title { font-weight: 600; margin: .4rem 0 .6rem; }
.sa-done__stats { display: flex; justify-content: center; gap: 1rem; font-size: .82rem; color: var(--sa-text-secondary); margin-bottom: .85rem; }
.sa-done__stats b { color: var(--sa-text); font-size: 1.05rem; }

/* First-run tour ---------------------------------------------------------------------- */
.sa-tour-backdrop { position: fixed; inset: 0; background: rgba(15, 23, 42, .35); z-index: 1999; }
.sa-tour-focus { position: relative; z-index: 2001; box-shadow: 0 0 0 4px #fff, 0 0 0 7px var(--sa-primary) !important; border-radius: 8px; }
.sa-tour-card {
  position: fixed;
  z-index: 2002;
  width: 300px;
  max-width: calc(100vw - 24px);
  background: #fff;
  border-radius: var(--sa-radius-md);
  box-shadow: var(--sa-shadow-lg);
  padding: 1rem 1.1rem;
  font-size: .9rem;
}
.sa-tour-card__step { font-size: .7rem; text-transform: uppercase; letter-spacing: .06em; color: var(--sa-primary); font-weight: 700; }
.sa-tour-card__title { font-weight: 600; margin: .15rem 0 .3rem; }
.sa-tour-card__actions { display: flex; align-items: center; gap: .5rem; margin-top: .8rem; }

/* Discussion thread, compare banner ------------------------------------------------------ */
.sa-thread { font-size: .82rem; margin-bottom: 0; }
.sa-thread li { padding: .4rem .55rem; background: var(--sa-surface-secondary); border-radius: var(--sa-radius-sm); margin-bottom: .35rem; }
.sa-ws-banner--compare { background: #f5f3ff; }
