/*
 * Letter Desk (owner only). Palette and type come from /css/tokens.css and the base
 * controls from /css/site.css. The four level colours below are local to the desk:
 * every level also carries a word and a symbol, so colour is never the only signal.
 * Contrast of the words on their fills: red 7.3:1, amber 6.5:1, green 9.6:1, note 5.0:1.
 */
.page.desk {
  max-width: 920px;
  --lvl-red-fg: var(--danger);
  --lvl-red-bg: var(--danger-bg);
  --lvl-red-edge: var(--danger);
  --lvl-red-line: var(--danger-line);
  --lvl-amber-fg: #6b5316;
  --lvl-amber-bg: var(--gold-tint);
  --lvl-amber-edge: #b08d2e;
  --lvl-amber-line: var(--gold-line);
  --lvl-green-fg: var(--ink);
  --lvl-green-bg: var(--tint);
  --lvl-green-edge: var(--delta);
  --lvl-green-line: #cbd8c7;
  --lvl-info-fg: var(--muted);
  --lvl-info-bg: var(--card);
  --lvl-info-edge: var(--field-border);
  --lvl-info-line: var(--hairline);
}
.desk [hidden] { display: none !important; }

/* Header */
.desk-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; margin-bottom: 40px; }
.desk-nav { display: flex; align-items: center; gap: 16px; font-size: 14px; flex-wrap: wrap; }
.desk-nav nav { display: flex; gap: 14px; flex-wrap: wrap; }
.desk-nav nav a[aria-current="page"] { font-weight: 500; text-decoration: none; }
.who { margin: 0; color: var(--muted); font-size: 13px; overflow-wrap: anywhere; }

/* Type */
.desk h1 { font-family: var(--serif); font-weight: 500; font-size: clamp(28px, 5vw, 36px); line-height: 1.2; color: var(--ink); margin: 0 0 12px; }
.desk h2 { font-family: var(--serif); font-weight: 500; font-size: 24px; line-height: 1.3; color: var(--ink); margin: 40px 0 8px; }
.desk h3 { font-size: 16px; font-weight: 600; margin: 28px 0 10px; }
.desk .eyebrow { margin-bottom: 8px; }
.lead { font-size: 16px; margin: 0 0 20px; max-width: 70ch; }
.desk code { font-size: 0.92em; background: var(--tint); padding: 0 4px; border-radius: 3px; }

.notice { margin: 0 0 24px; padding: 12px 16px; font-size: 14.5px; line-height: 1.55; background: var(--card); border: 1px solid var(--hairline); border-left: 3px solid var(--gold); border-radius: 6px; }
.notice[data-tone="warn"] { background: var(--lvl-amber-bg); border-color: var(--lvl-amber-line); border-left-color: var(--lvl-amber-edge); color: var(--text); }

/* Form */
@media (max-width: 719px) { .field-row.three { flex-direction: column; gap: 0; } }
.hint { margin: 5px 0 0; font-size: 13px; color: var(--muted); line-height: 1.45; }

.desk input[type="date"], .desk textarea {
  display: block; width: 100%;
  font-family: var(--sans); font-size: 16px; color: var(--text);
  background-color: var(--card); border: 1px solid var(--field-border); border-radius: 8px;
  transition: border-color 0.2s ease;
}
.desk input[type="date"] { height: 48px; padding: 0 14px; }
.desk textarea { min-height: 240px; padding: 12px 14px; line-height: 1.5; resize: vertical; font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; }
.desk textarea.code { min-height: 0; margin-top: 8px; background-color: var(--paper); }
@media (min-width: 720px) { .desk textarea { font-size: 14px; } .desk textarea.code { font-size: 13px; } }
.desk input[type="date"]:hover, .desk textarea:hover { border-color: var(--ink); }
.desk input[type="date"]:focus-visible, .desk textarea:focus-visible { outline: 2px solid var(--ink); outline-offset: 1px; border-color: var(--ink); }
.desk input[aria-invalid="true"], .desk textarea[aria-invalid="true"] { border-color: var(--danger); }

.check-row { display: flex; align-items: flex-start; gap: 10px; margin: 10px 0 14px; font-size: 14.5px; line-height: 1.5; }
.check-row input { width: 20px; height: 20px; margin: 1px 0 0; flex: 0 0 auto; accent-color: var(--ink); }
.check-row input:focus-visible { outline: 2px solid var(--ink); outline-offset: 2px; }

.actions { display: flex; gap: 10px; flex-wrap: wrap; }
.actions .btn { width: auto; min-width: 200px; padding: 0 24px; }
@media (max-width: 480px) { .actions .btn { width: 100%; } }
.desk .btn.small { width: auto; height: 40px; margin: 0; padding: 0 16px; font-size: 14.5px; }
.desk .btn.secondary:disabled { opacity: 0.55; }
.desk .btn[data-copied] { background: var(--lvl-green-bg); border-color: var(--lvl-green-edge); }

/* Progress */
.progress { margin: 24px 0; }
.progress p { margin: 0 0 6px; font-size: 14.5px; }
.progress progress { display: block; width: 100%; height: 8px; border: none; border-radius: 4px; background: var(--tint); overflow: hidden; appearance: none; -webkit-appearance: none; }
.progress progress::-webkit-progress-bar { background: var(--tint); border-radius: 4px; }
.progress progress::-webkit-progress-value { background: var(--delta); border-radius: 4px; transition: width 0.3s ease; }
.progress progress::-moz-progress-bar { background: var(--delta); border-radius: 4px; }

/* Results */
.results { margin-top: 32px; }
#results-title:focus { outline: none; }
#results-title:focus-visible { outline: 2px solid var(--ink); outline-offset: 4px; border-radius: 3px; }
.summary-chips { list-style: none; margin: 4px 0 10px; padding: 0; display: flex; flex-wrap: wrap; gap: 8px; }
.summary-chips .badge { font-size: 15px; padding: 3px 12px; }
.summary-chips .badge .icon { font-size: 13px; }
.summary { font-size: 15px; margin: 0 0 6px; }
#tagged-summary { font-size: 15px; margin: 0 0 6px; }

.legend { list-style: none; margin: 16px 0; padding: 0; display: flex; flex-wrap: wrap; gap: 8px 18px; font-size: 13.5px; color: var(--muted); }
.legend li { display: flex; align-items: center; gap: 6px; }

.badge {
  display: inline-flex; align-items: center; gap: 5px; margin: 0; padding: 1px 9px;
  font-size: 12.5px; font-weight: 600; line-height: 1.7; white-space: nowrap;
  color: var(--lvl-info-fg); background: var(--lvl-info-bg); border: 1px solid var(--lvl-info-line); border-radius: 999px;
}
.badge .icon { font-size: 11px; }
[data-level="red"] .badge { color: var(--lvl-red-fg); background: var(--lvl-red-bg); border-color: var(--lvl-red-line); }
[data-level="amber"] .badge { color: var(--lvl-amber-fg); background: var(--lvl-amber-bg); border-color: var(--lvl-amber-line); }
[data-level="green"] .badge { color: var(--lvl-green-fg); background: var(--lvl-green-bg); border-color: var(--lvl-green-line); }

.group h3 .count { font-weight: 400; color: var(--muted); }
.items { list-style: none; margin: 0; padding: 0; display: grid; gap: 10px; }
.item {
  display: grid; grid-template-columns: 8em minmax(0, 1fr); gap: 12px; align-items: start;
  padding: 12px 14px; background: var(--card);
  border: 1px solid var(--hairline); border-left: 4px solid var(--lvl-info-edge); border-radius: 8px;
}
.item[data-level="red"] { border-left-color: var(--lvl-red-edge); }
.item[data-level="amber"] { border-left-color: var(--lvl-amber-edge); }
.item[data-level="green"] { border-left-color: var(--lvl-green-edge); }
.item[data-level="pending"] { border-left-style: dashed; }
.item > .badge { justify-self: start; }
@media (max-width: 560px) { .item { grid-template-columns: minmax(0, 1fr); gap: 6px; } }
.item-body { min-width: 0; }
.item-title { margin: 0; font-weight: 500; line-height: 1.45; overflow-wrap: anywhere; }
.item-title .src { display: inline-block; margin-left: 4px; padding: 0 6px; font-size: 12.5px; font-weight: 500; color: var(--ink); background: var(--tint); border-radius: 4px; white-space: nowrap; }
.item-meta { margin: 2px 0 0; font-size: 13px; color: var(--muted); line-height: 1.5; overflow-wrap: anywhere; }
.item-notes { margin: 6px 0 0; padding-left: 18px; font-size: 14px; line-height: 1.55; }
.item-context { margin: 6px 0 0; font-size: 13px; color: var(--muted); font-style: italic; line-height: 1.5; overflow-wrap: anywhere; }
.item-open { margin: 6px 0 0; font-size: 13.5px; }
.results.only-problems .item[data-level="green"],
.results.only-problems .item[data-level="info"] { display: none; }
.empty { margin: 0; font-size: 14px; color: var(--muted); }

/* Outputs */
.output { margin: 0 0 16px; padding: 18px 20px; background: var(--card); border: 1px solid var(--hairline); border-radius: 12px; }
.output h3 { margin-top: 0; }
.copy-row { display: flex; flex-wrap: wrap; gap: 8px; margin: 12px 0 4px; }
.sources-preview { margin: 10px 0; padding-left: 26px; font-size: 14px; line-height: 1.55; overflow-wrap: anywhere; }
.sources-preview li { margin: 0 0 4px; }
.tagged-changes { margin: 8px 0; padding-left: 18px; font-size: 13px; line-height: 1.55; overflow-wrap: anywhere; }
.tagged-changes .arrow, .tagged-changes .replaced { color: var(--muted); }
.output details summary { margin-top: 10px; font-size: 14px; color: var(--ink); cursor: pointer; }

.offscreen { position: fixed; left: -9999px; top: 0; width: 1px; height: 1px; opacity: 0; }

@media (prefers-reduced-motion: reduce) {
  .progress progress::-webkit-progress-value { transition: none; }
  .desk input[type="date"], .desk textarea { transition: none; }
}
