/* ── Colours ───────────────────────────────────────────────────────────────
   Shared with every jsal.io app: the palette, light/dark switching and the top
   bar live in /shell.css. These names map the shared colours onto this app's
   components. */

:root {
  --bg: var(--jsal-bg);
  --surface: var(--jsal-bg);          /* the app sits flat on the page */
  --surface-2: var(--jsal-surface);   /* fields, rows and cards */
  --surface-3: var(--jsal-sunk);      /* hover */

  --border: var(--jsal-line);
  --border-mid: var(--jsal-line);
  --border-hi: var(--jsal-line-hi);

  --text: var(--jsal-ink);
  --text-2: var(--jsal-ink-2);
  --text-3: var(--jsal-muted);

  --gradient: var(--jsal-fill);       /* main button */
  --gradient-dim: var(--jsal-accent-soft);
  --accent-glow: none;
  --on-accent: var(--jsal-on-fill);

  --accent: var(--jsal-accent);
  --accent-dim: var(--jsal-accent-soft);
  --accent-ring: var(--jsal-accent-ring);
  --ok: var(--jsal-ok);
  --ok-dim: var(--jsal-ok-soft);
  --warn: var(--jsal-warn);
  --warn-dim: var(--jsal-warn-soft);
  --bad: var(--jsal-bad);
  --bad-dim: var(--jsal-bad-soft);

  --shadow-card: var(--jsal-shadow);

  --radius-sm: var(--jsal-radius);
  --radius-xs: 4px;
  --font: var(--jsal-font);
  --mono: ui-monospace, "Cascadia Code", Consolas, "SF Mono", monospace;
}

/* ── Base ──────────────────────────────────────────────────────────────── */

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
[hidden] { display: none !important; }

/* Elements marked data-needs-content only appear once something is pasted; the paste zone only before */
.app:not(.has-content) [data-needs-content] { display: none !important; }
.app.has-content .paste-zone, .app.has-content [data-no-content] { display: none; }

.sr-only {
  position: absolute; width: 1px; height: 1px; margin: -1px;
  overflow: hidden; clip-path: inset(50%); white-space: nowrap;
}

button { font: inherit; color: inherit; cursor: pointer; background: none; border: none; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

body {
  min-height: 100vh;
  color: var(--text);
  font-family: var(--font);
  font-size: 13px;
  -webkit-font-smoothing: antialiased;
  display: flex;
  justify-content: center;
}

.ico { display: inline-grid; place-items: center; flex-shrink: 0; }

/* ── Page + header ─────────────────────────────────────────────────────── */

.app {
  width: 100%;
  max-width: 880px;   /* same as IC Defaults: lines up with the jsal.io home page column */
  display: flex;
  flex-direction: column;
  padding: 0 max(20px, env(safe-area-inset-left, 0px)) 18px;   /* same sides as the home page */
}

/* The top bar itself (.jsal-top) is styled by /shell.css */
.app-header { margin-bottom: 24px; }

.section-label {
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.5px;
  text-transform: uppercase;
  color: var(--text-3);
}
.section-label { margin-bottom: 8px; }

/* ── Sidebar ───────────────────────────────────────────────────────────── */

.side { display: flex; flex-direction: column; gap: 6px; }
.side-empty { color: var(--text-3); line-height: 1.5; }

.option-track {
  display: flex;
  gap: 2px;
  padding: 3px;
  border-radius: var(--radius-sm);
  background: var(--surface-3);
}
.option-track button {
  flex: 1;
  padding: 4px 10px;
  border-radius: var(--radius-xs);
  color: var(--text-3);
  font-weight: 600;
  white-space: nowrap;
  transition: background 0.12s, color 0.12s;
}
.option-track button:hover { color: var(--text); }
.option-track button[aria-selected="true"] { background: var(--surface-2); color: var(--text); box-shadow: var(--shadow-card); }

/* ── Checks ────────────────────────────────────────────────────────────── */

.results { min-height: 0; }
.stats { display: flex; flex-wrap: wrap; gap: 5px; margin-bottom: 8px; }
.stat {
  padding: 3px 10px;
  border-radius: 20px;
  border: 1px solid var(--border-mid);
  background: var(--surface-2);
  color: var(--text-2);
  font-size: 12px;
  font-variant-numeric: tabular-nums;
}
.stat b { color: var(--text); font-weight: 600; }
.stat.good b { color: var(--ok); }

.checks { list-style: none; display: grid; gap: 5px; }
.check {
  display: flex;
  gap: 9px;
  align-items: flex-start;
  padding: 8px 10px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text-2);
  line-height: 1.45;
}
.check > span:nth-child(2) { flex: 1; min-width: 0; overflow-wrap: anywhere; }   /* long URLs wrap instead of running off */
/* Checks about particular lines are buttons: click to show the line in the text */
button.check { width: 100%; font: inherit; text-align: left; transition: border-color 0.12s, background 0.12s; }
button.check:hover { border-color: var(--accent-ring); background: var(--surface-3); }
button.check:focus-visible { outline-offset: -2px; }
.check-show { flex-shrink: 0; align-self: center; font-size: 11.5px; font-weight: 600; color: var(--text-3); }
button.check:hover .check-show, button.check:focus-visible .check-show { color: var(--accent); }
.check .ico { margin-top: 1px; width: 16px; height: 16px; border-radius: 50%; }
.check.ok .ico { color: var(--ok); background: var(--ok-dim); }
.check.warn { border-color: var(--warn-dim); }
.check.warn .ico { color: var(--warn); background: var(--warn-dim); }
.check.info .ico { color: var(--text-3); background: var(--surface-3); }

/* ── Actions ───────────────────────────────────────────────────────────── */

.actions { display: grid; gap: 6px; margin-top: 12px; }
.actions-row { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; }
.actions-foot { display: flex; align-items: center; justify-content: space-between; gap: 10px; min-height: 28px; }

.btn-primary {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  padding: 0 14px;
  height: 40px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-mid);
  background: var(--surface-2);
  color: var(--text);
  font-weight: 500;
  white-space: nowrap;
  box-shadow: var(--shadow-card);
  transition: background 0.12s, border-color 0.12s, filter 0.12s;
}
.btn-primary:hover { background: var(--surface-3); border-color: var(--border-hi); }
.btn-primary:active { transform: scale(0.98); }
.btn-accent {
  background: var(--gradient);
  border-color: transparent;
  color: var(--on-accent);
  font-weight: 600;
  box-shadow: var(--accent-glow);
}
.btn-accent:hover { background: var(--gradient); border-color: transparent; filter: brightness(1.08); }
.btn-primary.done { border-color: var(--ok); }
.btn-accent.done { background: var(--ok-dim); color: var(--ok); }

.toolbar-hint { font-size: 12px; color: var(--text-3); }
.btn-clear { display: inline-flex; align-items: center; gap: 5px; padding: 4px 6px; color: var(--bad); font-weight: 500; border-radius: var(--radius-xs); }
.btn-clear:hover { background: var(--bad-dim); }
.btn-link { color: var(--accent); font-weight: 600; text-decoration: underline; text-underline-offset: 3px; }

/* ── Workspace ─────────────────────────────────────────────────────────── */

.work { display: grid; gap: 12px; margin-top: 12px; min-height: 0; }

.paste-zone {
  min-height: 320px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 32px 20px;
  text-align: center;
  border: 1.5px dashed var(--border-hi);
  border-radius: 8px;
  background: var(--surface-2);
  cursor: text;
  transition: border-color 0.12s, background 0.12s;
}
.paste-zone:hover, .paste-zone:focus-visible { border-color: var(--accent); background: var(--accent-dim); outline: none; }
.paste-icon { width: 44px; height: 44px; border-radius: 12px; display: grid; place-items: center; background: var(--gradient-dim); color: var(--accent); border: 1px solid var(--accent-ring); margin-bottom: 4px; }
.paste-title { font-size: 15px; font-weight: 600; }
.paste-sub { max-width: 34em; color: var(--text-2); line-height: 1.5; }
.paste-links { display: flex; gap: 10px; align-items: center; color: var(--text-3); }
.paste-privacy { margin-top: 10px; font-size: 12px; color: var(--text-3); }
kbd { font: 600 11.5px var(--font); padding: 1px 6px; border-radius: 4px; border: 1px solid var(--border-hi); border-bottom-width: 2px; background: var(--surface); }

.pane {
  display: flex;
  flex-direction: column;
  min-height: 0;
  height: 70vh;
  border: 1px solid var(--border-mid);
  border-radius: 8px;
  background: var(--surface-2);
  overflow: hidden;
}
.pane-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 7px 8px 7px 12px;
  border-bottom: 1px solid var(--border);
}
.pane-title { font-weight: 600; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.pane-meta { font-weight: 400; color: var(--text-3); margin-left: 4px; font-variant-numeric: tabular-nums; }
.pane-body { flex: 1; min-height: 0; overflow: auto; background: var(--surface-2); }

.code {
  margin: 0;
  padding: 14px 16px;
  font: 12.5px/1.65 var(--mono);
  white-space: pre-wrap;
  word-break: break-word;
  color: var(--text-2);
  tab-size: 4;
}

/* Formatting toolbar (only on the Text tab) */
.toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 2px;
  padding: 5px 8px;
  border-bottom: 1px solid var(--border);
  background: var(--surface-2);
}
.toolbar[hidden] { display: none; }
.toolbar button {
  min-width: 30px;
  height: 28px;
  padding: 0 7px;
  display: inline-grid;
  place-items: center;
  border-radius: var(--radius-xs);
  color: var(--text-2);
  font-weight: 600;
  font-size: 12.5px;
  transition: background 0.12s, color 0.12s;
}
.toolbar button:hover { background: var(--surface-3); color: var(--text); }
.toolbar button.on { background: var(--accent-dim); color: var(--accent); }
.toolbar button b { font-weight: 800; } .toolbar button i { font-family: Georgia, serif; font-size: 14px; }
.toolbar .tb-wide { padding: 0 10px; font-weight: 500; border: 1px solid var(--border-mid); display: inline-flex; gap: 2px; }
.toolbar .toolbar-hint { margin-left: 8px; }
.tb-sep { width: 1px; height: 18px; margin: 0 4px; background: var(--border-mid); }
.tb-grow { flex: 1; }

.preview[contenteditable] { outline: none; min-height: 100%; cursor: text; caret-color: var(--accent); }
.preview:empty::before { content: "Start typing or paste here…"; color: var(--text-3); }

textarea.code {
  display: block;
  width: 100%;
  height: 100%;
  resize: none;
  border: 0;
  outline: none;
  background: transparent;
}
textarea.code[hidden] { display: none; }

/* Clean preview: plain article typography */
.preview { padding: 20px 26px 40px; font-size: 15px; line-height: 1.7; color: var(--text); max-width: 760px; }
.preview > * + * { margin-top: 0.9em; }
.preview h1, .preview h2, .preview h3, .preview h4, .preview h5, .preview h6 { line-height: 1.3; letter-spacing: -0.01em; margin-top: 1.4em; }
.preview > :first-child { margin-top: 0; }
.preview h1 { font-size: 26px; } .preview h2 { font-size: 21px; } .preview h3 { font-size: 18px; } .preview h4, .preview h5, .preview h6 { font-size: 15.5px; }
/* Small tag before each heading so the level is visible at a glance */
.preview :is(h1, h2, h3, h4, h5, h6)::before {
  content: "H1";
  display: inline-block;
  margin-right: 8px;
  padding: 1px 5px;
  border-radius: 4px;
  vertical-align: 3px;
  font: 700 10px/1.4 var(--font);
  color: var(--accent);
  background: var(--accent-dim);
}
.preview h2::before { content: "H2"; } .preview h3::before { content: "H3"; } .preview h4::before { content: "H4"; }
.preview h5::before { content: "H5"; } .preview h6::before { content: "H6"; }
.preview a { color: var(--accent); text-underline-offset: 2px; }
.preview ul, .preview ol { padding-left: 1.5em; }
.preview li + li, .preview li > ul, .preview li > ol { margin-top: 0.3em; }
.preview table { border-collapse: collapse; width: 100%; font-size: 14px; }
.preview td, .preview th { border: 1px solid var(--border-hi); padding: 6px 10px; text-align: left; vertical-align: top; }
.preview blockquote { border-left: 3px solid var(--accent-ring); padding-left: 14px; color: var(--text-2); }
.preview [data-image] { display: inline-block; padding: 4px 10px; border-radius: 6px; border: 1px dashed var(--warn); color: var(--warn); background: var(--warn-dim); font-size: 13px; font-weight: 600; }
/* Bold-only lines: a gold bar in the margin (see the "only bold text" check) */
.preview > p[data-bold] { position: relative; }
.preview > p[data-bold]::before { content: ""; position: absolute; left: -14px; top: 0.2em; bottom: 0.2em; width: 3px; border-radius: 2px; background: var(--accent); opacity: 0.55; }
/* A check's line, just shown: a short gold flash (stays lit briefly, without motion, if animations are off) */
.preview .locate { background: var(--accent-dim); border-radius: 4px; animation: locate 1.2s ease-out forwards; }
@keyframes locate { 0%, 30% { background: var(--accent-dim); box-shadow: 0 0 0 4px var(--accent-dim); } 100% { background: transparent; box-shadow: 0 0 0 4px transparent; } }
.preview .flag { text-decoration-color: var(--warn); text-decoration-style: wavy; text-decoration-line: underline; }

/* ── Layout ────────────────────────────────────────────────────────────── */

@media (min-width: 900px) {
  body { height: 100vh; overflow: hidden; }
  .app {
    height: 100%;
    display: grid;
    grid-template-columns: minmax(260px, 300px) minmax(0, 1fr);
    grid-template-rows: auto minmax(0, 1fr);
    column-gap: 28px;
  }
  .app-header { grid-column: 1 / -1; }
  /* Copy buttons pinned at the bottom, checks scroll above them */
  .side { min-height: 0; }
  .results { flex: 1 1 auto; min-height: 60px; overflow-y: auto; padding-right: 4px; scrollbar-width: thin; }
  .actions { padding-top: 10px; border-top: 1px solid var(--border); }
  .work { margin-top: 0; grid-template-rows: minmax(0, 1fr); }
  .pane { height: auto; }
}
@media (max-width: 899px) {
  .app { min-height: 100vh; }
  .option-track button { padding: 5px 8px; }
  .pane { height: 75vh; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}

/* Same width as IC Defaults on very large screens */
@media (min-width: 1800px) {
  .app { max-width: 1000px; }
}
