/* Markdown to HTML Converter — settings, a Markdown editor, a sandboxed preview and the HTML source.
   Colours come from the shared tokens, so the panel follows the light and dark themes. */
.mdh {
  container: mdh / inline-size;
  display: grid;
  gap: 1.1rem;
  padding: clamp(16px, 2.4vw, 28px);
  text-align: left;
  color: var(--ink);
  background: var(--bg-2);
  border: 2px solid var(--line);
  border-radius: 12px;
  box-shadow: 4px 4px 0 var(--shade);
}
.mdh *, .mdh *::before, .mdh *::after { box-sizing: border-box; }
.mdh [hidden] { display: none !important; }
.mdh h2 { margin: 0 0 .35rem; font-size: 1.45rem; letter-spacing: -.02em; }
.mdh p { margin: 0; color: var(--ink-soft); }
.mdh :is(input, textarea, select, button, iframe):focus-visible { outline: 3px solid var(--primary); outline-offset: 2px; }

.mdh-head { display: flex; flex-wrap: wrap; align-items: flex-end; justify-content: space-between; gap: .9rem 1.5rem; }
.mdh-intro { min-width: 0; flex: 1 1 22rem; }
.mdh-intro p { max-width: 68ch; }
.mdh-buttons { display: flex; flex-wrap: wrap; gap: .55rem; }

.mdh .mdh-button {
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 42px;
  padding: .5rem .95rem;
  font: inherit;
  font-size: .95rem;
  font-weight: 650;
  color: var(--ink);
  background: var(--bg-2);
  border: 2px solid var(--line);
  border-radius: 8px;
  cursor: pointer;
}
.mdh .mdh-button:hover:not(:disabled) { background: var(--paper-3); }
.mdh .mdh-button:disabled { opacity: .5; cursor: default; }
.mdh .mdh-primary { color: var(--on-action); background: var(--action); box-shadow: 3px 3px 0 var(--shade); }
.mdh .mdh-primary:hover:not(:disabled) { background: var(--primary-dark); }
.mdh-file-button input { position: absolute; inset: 0; width: 100%; height: 100%; opacity: 0; cursor: pointer; }
.mdh-file-button:focus-within { outline: 3px solid var(--primary); outline-offset: 2px; }
.mdh-link { min-height: 42px; padding: 0 .1rem; font: inherit; font-size: .88rem; font-weight: 650; color: var(--action-text); background: none; border: 0; text-decoration: underline; text-underline-offset: 3px; cursor: pointer; }

/* Settings */
.mdh-settings { display: grid; gap: .85rem; padding: 1rem; background: var(--blue-tint); border: 2px solid var(--line); border-radius: 10px; }
.mdh label { display: grid; gap: .3rem; min-width: 0; font-size: .85rem; font-weight: 650; }
.mdh select, .mdh input[type="text"] {
  width: 100%;
  min-width: 0;
  min-height: 42px;
  padding: .5rem .6rem;
  font: inherit;
  font-weight: 400;
  color: var(--ink);
  background: var(--field);
  border: 1.5px solid var(--border-soft);
  border-radius: 6px;
}
.mdh input[aria-invalid="true"] { border: 2px solid var(--error); }
.mdh-row { display: flex; flex-wrap: wrap; align-items: end; gap: .75rem 1.1rem; }
.mdh-row > label { flex: 1 1 15rem; }
.mdh-checks { display: flex; flex-wrap: wrap; gap: 0 1.5rem; min-width: 0; margin: 0; padding: 0; border: 0; }
.mdh-checks legend, .mdh-pills legend { width: 100%; margin-bottom: .4rem; padding: 0; font-weight: 700; }
.mdh .mdh-check { display: flex; align-items: center; gap: .55rem; min-height: 42px; font-size: .95rem; font-weight: 500; }
.mdh .mdh-check input { flex: none; width: 1.2rem; height: 1.2rem; margin: 0; accent-color: var(--action); }
.mdh-doc { display: grid; grid-template-columns: minmax(0, 2fr) minmax(0, 1fr) auto; align-items: end; gap: .75rem 1.1rem; padding-top: .85rem; border-top: 1.5px dashed var(--border-soft); }
.mdh-field-error { grid-column: 1 / -1; padding: .45rem .7rem; font-size: .88rem; font-weight: 600; color: var(--ink) !important; background: var(--error-soft); border-left: 4px solid var(--error); border-radius: 6px; }
.mdh-reset { margin-top: -.35rem !important; }

/* Pill switches: a visually hidden radio inside each label */
.mdh-pills { display: flex; flex-wrap: wrap; gap: .5rem; min-width: 0; margin: 0; padding: 0; border: 0; }
.mdh .mdh-pills label { position: relative; display: inline-flex; align-items: center; min-height: 42px; padding: .45rem .9rem; font-size: .95rem; background: var(--bg-2); border: 2px solid var(--line); border-radius: 999px; cursor: pointer; }
.mdh-pills input { position: absolute; opacity: 0; pointer-events: none; }
.mdh .mdh-pills label:has(input:checked) { color: var(--on-action); background: var(--action); box-shadow: 2px 2px 0 var(--shade); }
.mdh .mdh-pills label:has(input:focus-visible) { outline: 3px solid var(--primary); outline-offset: 2px; }

.mdh-bar { display: flex; flex-wrap: wrap; align-items: end; justify-content: space-between; gap: .75rem 1rem; }

/* Editor, preview and HTML panes */
.mdh-work { display: grid; grid-template-columns: minmax(0, 1fr); gap: 1rem; min-width: 0; }
.mdh-pane { position: relative; display: flex; flex-direction: column; min-width: 0; overflow: hidden; background: var(--field); border: 2px solid var(--line); border-radius: 10px; }
.mdh .mdh-pane-head { display: flex; align-items: center; justify-content: space-between; gap: .75rem; margin: 0; padding: .55rem .85rem; font-size: .92rem; font-weight: 700; background: var(--paper-3); border-bottom: 1.5px solid var(--border-soft); }
.mdh .mdh-pane-head label { display: inline; font-size: inherit; }
.mdh-pane-head span { font-size: .78rem; font-weight: 500; color: var(--ink-soft); text-align: right; }
.mdh-pane textarea {
  display: block;
  width: 100%;
  min-width: 0;
  margin: 0;
  padding: .85rem 1rem;
  font: .88rem/1.6 var(--font-mono);
  color: var(--ink);
  background: var(--field);
  border: 0;
  border-radius: 0;
  resize: vertical;
  tab-size: 2;
}
.mdh-pane textarea:focus-visible, .mdh-pane iframe:focus-visible { outline-offset: -3px; }
.mdh-source textarea { height: 18rem; min-height: 10rem; }
.mdh-code textarea { height: 18rem; min-height: 8rem; white-space: pre; overflow: auto; }
.mdh-frames { position: relative; height: 22rem; background: var(--field); }
.mdh-frames iframe { position: absolute; inset: 0; display: block; width: 100%; height: 100%; border: 0; background: var(--field); }
.mdh-frames iframe.is-loading { visibility: hidden; }
.mdh .mdh-pane-foot { margin: 0; padding: .45rem .85rem; font-size: .8rem; color: var(--ink-soft); background: var(--paper-3); border-top: 1.5px solid var(--border-soft); overflow-wrap: anywhere; }
.mdh .mdh-preview-foot { display: grid; gap: .1rem; }
.mdh .mdh-preview-foot .mdh-check { font-size: .88rem; font-weight: 600; }
.mdh .mdh-preview-foot p { font-size: .78rem; }
.mdh-drop { position: absolute; inset: 0; display: none; place-items: center; padding: 1rem; font-weight: 700; text-align: center; color: var(--ink); background: var(--veil); border: 3px dashed var(--action); border-radius: 8px; pointer-events: none; }
.mdh.is-dragging .mdh-drop { display: grid; }
.mdh.is-dragging iframe { pointer-events: none; }

.mdh-status { font-weight: 600; color: var(--ink) !important; overflow-wrap: anywhere; }
.mdh-status:empty { margin-top: -1.1rem; } /* No gap while there is nothing to say; the live region stays in place. */
.mdh-status[data-error="true"] { padding: .5rem .75rem; background: var(--error-soft); border-left: 4px solid var(--error); border-radius: 6px; }
.mdh-foot { font-size: .85rem; }

@container mdh (max-width: 560px) {
  .mdh-doc { grid-template-columns: minmax(0, 1fr); }
  .mdh-buttons { width: 100%; }
  .mdh-buttons .mdh-button { flex: 1 1 auto; }
}

/* Side by side once the panel is wide enough: Markdown on the left, preview and HTML on the right. */
@container mdh (min-width: 860px) {
  .mdh-work { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); }
  .mdh-work[data-view="both"] .mdh-source { grid-row: 1 / span 2; }
  .mdh-source textarea { flex: 1 1 0; height: auto; min-height: 30rem; }
  .mdh-work[data-view="both"] .mdh-frames { height: 17rem; }
  .mdh-work[data-view="both"] .mdh-code textarea { flex: 1 1 0; height: auto; min-height: 14rem; }
  .mdh-work:not([data-view="both"]) .mdh-frames { height: 34rem; }
  .mdh-work:not([data-view="both"]) .mdh-code textarea { flex: 1 1 0; height: auto; }
}

/* Space the page holds for this view until it mounts (see .tool-view-placeholder in _workspace.css).
   Each height is a little under the space the view takes at that width, measured as how far the
   content below moves when the view replaces the placeholder, so nothing below it moves. Re-measure
   after changing the view's layout: node scripts/measure-tool-views.js --apply markdown-to-html. */
.tool-view-placeholder[data-tool="markdown-to-html"] { min-height: 1394px; }
@media (max-width: 1400px) { .tool-view-placeholder[data-tool="markdown-to-html"] { min-height: 1414px; } }
@media (max-width: 956px) { .tool-view-placeholder[data-tool="markdown-to-html"] { min-height: 1946px; } }
@media (max-width: 544px) { .tool-view-placeholder[data-tool="markdown-to-html"] { min-height: 2243px; } }
