/* AGE QMS Workflow, styled to the AMS visual design language:
   brand blue #3F51B5, accent orange #FF9800, Inter, Tailwind's gray / blue / red / green / yellow scales. */

* { box-sizing: border-box; }
body { margin: 0; font-family: var(--font); font-size: 15px; line-height: 1.5; color: var(--ink); background: var(--page); }
a { color: var(--link); text-underline-offset: 2px; }
a:hover { color: var(--blue-800); }
h1, h2 { line-height: 1.2; }
h1 { font-size: 1.5rem; font-weight: 700; color: var(--primary); margin: 0; }
h1 small { color: var(--muted); font-weight: 400; font-size: .9rem; margin-left: .4rem; }
main { padding: 16px var(--gutter); max-width: 1400px; margin: 0 auto; }
:focus-visible { outline: 2px solid var(--blue-500); outline-offset: 2px; }

/* Waiting on you */
.work-list { list-style: none; margin: 0; padding: 0; display: grid; grid-template-columns: repeat(auto-fill, minmax(min(100%, 440px), 1fr)); gap: 12px; }
.work-item { display: flex; flex-direction: column; gap: 6px; height: 100%; padding: 16px 18px; background: var(--paper); border-radius: var(--radius); box-shadow: var(--shadow-md); border-left: 4px solid var(--blue-600); color: var(--ink); text-decoration: none; transition: all .15s var(--ease); }
.work-item:hover { color: var(--ink); box-shadow: var(--shadow-lg); transform: translateY(-1px); }
.work-item.overdue { border-left-color: var(--red-500); background: var(--red-50); }
.work-item.info { border-left-color: var(--gray-300); }
.work-item.mrb-unsigned { border-left-color: var(--red-500); }
.work-sign { color: var(--red-700); }
.work-head { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }
.work-number { font-size: 1.1rem; font-weight: 700; color: var(--link); margin-right: auto; }
.work-item:hover .work-number { text-decoration: underline; }
.work-summary { font-weight: 500; color: var(--gray-800); }
.work-step { color: var(--gray-600); font-size: .9rem; }
.work-meta { display: flex; flex-wrap: wrap; gap: 6px 16px; margin-top: 4px; font-size: .8rem; color: var(--gray-500); }
.work-age { font-weight: 600; }
.work-age.age-fresh { color: var(--gray-600); }
.work-age.age-aging { color: var(--yellow-800); }
.work-age.age-old { color: var(--red-700); }
.work-due-late { color: var(--red-700); font-weight: 600; }
.work-empty { max-width: 560px; margin: 24px auto; padding: 32px; text-align: center; background: var(--paper); border-radius: var(--radius-xl); box-shadow: var(--shadow-md); }
.work-empty h2 { margin: 0 0 8px; color: var(--primary); font-size: 1.25rem; }
.work-empty p { margin: 0 0 20px; color: var(--gray-600); }
.work-empty-actions { display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; }
/* on desktop New NCMR is already in the top bar */
@media screen and (min-width: 1024px) { .home-actions { display: none; } }

/* photos */
.visually-hidden { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.photo-form { display: contents; }
.photo-button { cursor: pointer; }
.photo-button:focus-within { outline: 2px solid var(--blue-500); outline-offset: 2px; }
.photo-grid { list-style: none; margin: 0 0 14px; padding: 0; display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 10px; }
.attachments .photo-grid { padding-left: 0; }
.photo-grid li { display: flex; flex-direction: column; gap: 4px; margin: 0; }
.photo-grid .meta { margin: 0; font-size: .75rem; }
.photo-thumb { display: block; width: 100%; aspect-ratio: 4 / 3; object-fit: cover; border-radius: var(--radius); background: var(--gray-100); box-shadow: var(--shadow-sm); }
.photo-grid a:hover .photo-thumb { box-shadow: var(--shadow-md); }
.photo-section { max-width: 1000px; margin: 16px auto 0; padding: 16px 20px; background: var(--paper); border-radius: var(--radius); box-shadow: var(--shadow-md); }
.photo-section h2 { margin: 0 0 4px; font-size: 1.125rem; font-weight: 600; color: var(--primary); }
.photo-section .hint { margin: 0 0 12px; font-size: .85rem; }
.photo-section .photo-status { margin: 10px 0 0; }
.photo-previews { display: grid; grid-template-columns: repeat(auto-fill, minmax(110px, 1fr)); gap: 8px; margin-top: 10px; }
.photo-previews:empty { display: none; }

/* attachments dropped or chosen while filling in a CCR (static/js/dropzone.js) */
.dropzone { display: flex; flex-direction: column; align-items: center; gap: 4px; padding: 24px 16px; border: 2px dashed var(--gray-300); border-radius: var(--radius); background: var(--gray-50); text-align: center; cursor: pointer; transition: all .15s var(--ease); }
.dropzone:hover, .dropzone.dragging { border-color: var(--blue-500); background: var(--blue-50); }
.dropzone:focus-within { outline: 2px solid var(--blue-500); outline-offset: 2px; }
.dropzone-icon { display: inline-flex; color: var(--primary); }
.dropzone-icon .icon { width: 28px; height: 28px; }
.dropzone-text { color: var(--gray-700); }
.photo-section .dropzone .hint { margin: 0; }
.photo-section .dropzone-status { margin: 10px 0 0; }
.dropzone-status.error { color: var(--red-700); }
.dropzone-files { list-style: none; margin: 10px 0 0; padding: 0; display: grid; gap: 8px; }
.dropzone-files:empty { display: none; }
.dropzone-files li { display: flex; align-items: center; gap: 12px; padding: 6px 8px; border: 1px solid var(--gray-200); border-radius: var(--radius); }
.dropzone-thumb { flex: none; width: 56px; height: 42px; object-fit: cover; border-radius: 6px; background: var(--gray-100); display: inline-flex; align-items: center; justify-content: center; font-size: .7rem; font-weight: 700; color: var(--gray-600); }
.dropzone-name { flex: 1; min-width: 0; overflow-wrap: anywhere; font-size: .875rem; }
.dropzone-remove { padding: 4px 10px; font-size: .8rem; }

/* delete (void) a record, at the bottom of its edit page */
.delete-zone { max-width: 1000px; margin: 32px auto 0; padding: 16px 20px; display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 12px 24px; border: 1px solid var(--red-200); border-radius: var(--radius); background: var(--paper); }
.delete-zone h2 { margin: 0 0 4px; font-size: 1rem; color: var(--red-700); }
.delete-zone .hint { margin: 0; max-width: 640px; }
.delete-dialog { width: min(480px, calc(100vw - 32px)); padding: 20px 22px; border: 0; border-top: 4px solid var(--red-500); border-radius: var(--radius-xl); box-shadow: var(--shadow-xl); }
.delete-dialog::backdrop { background: rgb(17 24 39 / .45); }
/* it and its backdrop fade and grow in, and leave a little faster; browsers without @starting-style just show it */
.delete-dialog, .delete-dialog::backdrop { opacity: 0; transition: opacity .15s cubic-bezier(.4, 0, 1, 1), transform .15s cubic-bezier(.4, 0, 1, 1), overlay .15s allow-discrete, display .15s allow-discrete; }
.delete-dialog { transform: scale(.96); }
.delete-dialog[open], .delete-dialog[open]::backdrop { opacity: 1; transform: none; transition-duration: .2s; transition-timing-function: cubic-bezier(0, 0, .2, 1); }
@starting-style {
  .delete-dialog[open], .delete-dialog[open]::backdrop { opacity: 0; }
  .delete-dialog[open] { transform: scale(.96); }
}
.delete-dialog h2 { margin: 0 0 8px; font-size: 1.15rem; color: var(--red-700); }
.delete-dialog p { margin: 0 0 14px; color: var(--gray-600); font-size: .9rem; }
.delete-dialog label { display: block; font-weight: 600; font-size: .875rem; margin-bottom: 4px; }
.delete-dialog textarea { width: 100%; font: inherit; padding: 8px 10px; border: 1px solid var(--gray-300); border-radius: var(--radius); }
.delete-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 14px; }

/* voice-fill (static/js/voice.js): a Speak button above the form; blocks it fills are highlighted to check */
.voice { max-width: 1000px; margin: 0 auto 16px; display: grid; grid-template-columns: auto 1fr; gap: 6px 16px; align-items: center; padding: 14px 18px; background: var(--paper); border-left: 4px solid var(--primary); border-radius: var(--radius); box-shadow: var(--shadow-md); }
.voice-button { min-width: 140px; font-size: 1rem; }
.voice.recording .voice-button { background: var(--red-600); border-color: var(--red-600); color: #fff; animation: voice-pulse 1.4s ease-in-out infinite; }
.voice.working .voice-button { opacity: .6; }
@keyframes voice-pulse { 50% { box-shadow: 0 0 0 6px rgb(220 38 38 / .2); } }
.voice-text p { margin: 0; }
.voice-hint { color: var(--gray-600); font-size: .875rem; }
.voice-status { font-size: .875rem; font-weight: 500; color: var(--primary); }
.voice-status:empty { display: none; }
.voice-status.error { color: var(--red-700); }
.voice-transcript { grid-column: 1 / -1; padding: 10px 12px; border-radius: var(--radius); background: var(--gray-50); }
.voice-transcript h2 { margin: 0 0 4px; font-size: .8rem; font-weight: 600; color: var(--gray-600); }
.voice-transcript h2 small { font-weight: 400; }
.voice-transcript p { margin: 0; font-size: .9rem; color: var(--gray-700); font-style: italic; }
.voice-transcript.live p::after { content: "▍"; margin-left: 2px; color: var(--blue-500); animation: voice-caret 1s steps(1) infinite; }
@keyframes voice-caret { 50% { opacity: 0; } }
.cell.voice-filled { background: #e0f2fe; box-shadow: inset 3px 0 0 var(--blue-500); }
@media screen and (max-width: 639px) {
  .voice { grid-template-columns: 1fr; }
  .voice-button { width: 100%; min-height: 52px; }
}

/* tags: toggle buttons on the form, coloured labels elsewhere; eight colours (Tag.COLORS) */
.tag-picker { display: grid; gap: 10px; }
.tag-options { display: flex; flex-wrap: wrap; gap: 6px; }
.tag-toggle { position: relative; display: inline-flex; cursor: pointer; }
.tag-toggle input { position: absolute; opacity: 0; width: 1px; height: 1px; }
.tag-toggle span, .tag { display: inline-flex; align-items: center; padding: 4px 12px; border-radius: 9999px; border: 2px solid var(--tag-line); background: var(--paper); color: var(--tag-ink); font-size: .85rem; font-weight: 500; line-height: 1.3; transition: all .15s var(--ease); }
.tag-toggle input:checked + span { background: var(--tag-fill); }
.tag-toggle input:checked + span::before { content: "✓"; margin-right: 5px; font-weight: 700; }
.tag-toggle input:focus-visible + span { outline: 2px solid var(--blue-500); outline-offset: 2px; }
.tag { border-width: 1px; background: var(--tag-fill); padding: 2px 10px; }
.tag-list { display: flex; flex-wrap: wrap; gap: 6px; }
.tag-new { display: flex; gap: 8px; max-width: 420px; }
.tag-new input { flex: 1; min-width: 0; font: inherit; padding: 7px 10px; border: 1px solid var(--gray-300); border-radius: var(--radius); }
.tag-blue { --tag-ink: #1e40af; --tag-line: #93c5fd; --tag-fill: #dbeafe; }
.tag-green { --tag-ink: #166534; --tag-line: #86efac; --tag-fill: #dcfce7; }
.tag-amber { --tag-ink: #92400e; --tag-line: #fcd34d; --tag-fill: #fef3c7; }
.tag-red { --tag-ink: #991b1b; --tag-line: #fca5a5; --tag-fill: #fee2e2; }
.tag-purple { --tag-ink: #6b21a8; --tag-line: #d8b4fe; --tag-fill: #f3e8ff; }
.tag-teal { --tag-ink: #115e59; --tag-line: #5eead4; --tag-fill: #ccfbf1; }
.tag-pink { --tag-ink: #9d174d; --tag-line: #f9a8d4; --tag-fill: #fce7f3; }
.tag-slate { --tag-ink: #334155; --tag-line: #cbd5e1; --tag-fill: #f1f5f9; }
@media print { .tag { border-color: #999; background: none; color: #000; } }

/* form editor */
.editor-intro { max-width: 760px; margin: -4px 0 16px; color: var(--gray-600); }
.editor { display: grid; gap: 16px; align-items: start; }
.editor.editing, .editor:has(.editor-panel) { grid-template-columns: minmax(0, 1fr) 340px; }
.editor .paper { max-width: none; margin: 0; }
.edit-cell { display: block; color: var(--ink); text-decoration: none; cursor: pointer; transition: background-color .15s var(--ease), box-shadow .15s var(--ease); }
.edit-cell:hover { background: var(--blue-50); color: var(--ink); }
.edit-cell.selected { background: var(--blue-50); box-shadow: inset 0 0 0 3px var(--accent); }
.edit-cell.protected .cell-label { color: var(--gray-800); }
.cell-meta { display: flex; flex-wrap: wrap; gap: 4px 8px; align-items: center; margin-top: 4px; font-size: .72rem; color: var(--gray-500); }
.type-tag { padding: 0 6px; border-radius: 4px; background: var(--gray-100); color: var(--gray-600); }
.lock { display: inline-flex; color: var(--gray-400); }
.lock .icon { width: 13px; height: 13px; }
.edit-bar { display: flex; align-items: center; gap: 6px; text-decoration: none; cursor: pointer; }
.edit-bar:hover, .edit-bar.selected { box-shadow: inset 0 0 0 3px var(--accent); color: var(--bar-ink); }
.edit-hint { margin-left: auto; display: inline-flex; opacity: .6; }
.edit-hint .icon { width: 14px; height: 14px; }
.empty-section { color: var(--gray-500); font-style: italic; font-size: .85rem; }
.add-block { margin: 8px 0 16px; }
.add-block .button { padding: 6px 12px; font-size: .85rem; border-style: dashed; }
.editor-panel { position: sticky; top: 72px; display: grid; gap: 12px; max-height: calc(100vh - 88px); overflow-y: auto; }
.panel-card { display: grid; gap: 10px; padding: 16px; background: var(--paper); border-radius: var(--radius); box-shadow: var(--shadow-md); }
.panel-card h2 { margin: 0; font-size: 1.05rem; color: var(--primary); }
.panel-card p { margin: 0; color: var(--gray-600); font-size: .88rem; }
.panel-card label { display: grid; gap: 4px; font-size: .82rem; font-weight: 500; color: var(--gray-700); }
.panel-card label.check { display: flex; align-items: center; gap: 8px; font-weight: 400; font-size: .88rem; }
.panel-card input[type=text], .panel-card select, .panel-card textarea { font: inherit; font-size: .9rem; padding: 7px 10px; border: 1px solid var(--gray-300); border-radius: var(--radius); background: #fff; color: var(--ink); width: 100%; }
.panel-card fieldset { margin: 0; padding: 10px 12px; border: 1px solid var(--gray-200); border-radius: var(--radius); display: grid; gap: 6px; }
.panel-card legend { padding: 0 4px; font-size: .82rem; font-weight: 500; color: var(--gray-700); }
.panel-row { display: grid; grid-template-columns: 90px 1fr; gap: 8px; }
.panel-note { display: flex; gap: 6px; padding: 8px 10px; background: var(--gray-50); border-radius: var(--radius); font-size: .8rem !important; }
.panel-note .icon { flex: none; width: 14px; height: 14px; margin-top: 2px; }
.move-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; }
.move-grid form:last-child:nth-child(odd) { grid-column: 1 / -1; }
.move-grid .button, .panel-card .button.danger { width: 100%; padding: 6px 10px; font-size: .85rem; }
.release-card { border-top: 4px solid var(--accent); }
.panel-problems { margin: 0; padding-left: 18px; color: var(--red-700); font-size: .82rem; }
.panel-actions { display: flex; gap: 8px; justify-content: flex-end; }
.history-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 10px; }
.history-list li { font-size: .88rem; }
.history-list p { margin: 4px 0 0; }
@media screen and (max-width: 1023px) {
  .editor.editing, .editor:has(.editor-panel) { grid-template-columns: 1fr; }
  .editor-panel { position: static; max-height: none; }
}

/* quality dashboard */
.dash-tiles { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(150px, 45%), 1fr)); gap: 12px; margin-bottom: 16px; }
.tile { display: flex; flex-direction: column; gap: 2px; padding: 16px 18px; background: var(--paper); border-radius: var(--radius); box-shadow: var(--shadow-md); border-top: 4px solid var(--primary); color: var(--ink); text-decoration: none; }
a.tile { transition: all .15s var(--ease); }
a.tile:hover { color: var(--ink); box-shadow: var(--shadow-lg); }
.tile-n { font-size: 2rem; font-weight: 700; line-height: 1.1; color: var(--primary); }
.tile-label { color: var(--gray-600); font-weight: 500; font-size: .9rem; }
.tile-note { color: var(--red-700); font-size: .8rem; font-weight: 600; }
.tile-alert { border-top-color: var(--red-500); background: var(--red-50); }
.tile-alert .tile-n { color: var(--red-700); }
.tile-warn { border-top-color: var(--accent); }
.tile-warn .tile-n { color: var(--orange-800); }
.dash-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 420px), 1fr)); gap: 12px; margin-bottom: 16px; }
.dash-card { padding: 16px 18px; background: var(--paper); border-radius: var(--radius); box-shadow: var(--shadow-md); min-width: 0; }
.dash-card h2 { margin: 0 0 10px; font-size: 1.05rem; font-weight: 600; color: var(--primary); }
.dash-card h3 { margin: 0 0 6px; font-size: .9rem; font-weight: 600; color: var(--gray-700); }
/* wide screens: three columns, with the monthly chart taking two beside SCAR timing */
@media screen and (min-width: 1280px) {
  .dash-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .dash-span-2 { grid-column: span 2; }
}
.dash-heading { margin: 24px 0 12px; font-size: 1.25rem; color: var(--primary); }
.dash-heading small { color: var(--muted); font-weight: 400; font-size: .85rem; margin-left: .4rem; }
.dash-note { margin: -4px 0 12px; color: var(--gray-500); font-size: .82rem; }
.dash-empty { margin: 0; color: var(--gray-500); font-style: italic; font-size: .9rem; }
.hbars { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; }
.hbars li, .hbar-link { display: grid; grid-template-columns: minmax(120px, 38%) 1fr 36px auto; align-items: center; gap: 10px; font-size: .88rem; }
.hbars li.linked { display: block; }
.hbar-link { color: var(--ink); text-decoration: none; border-radius: 6px; }
.hbar-link:hover { color: var(--ink); background: var(--gray-50); }
.hbar-label { min-width: 0; overflow-wrap: anywhere; }
.hbar { height: 10px; background: var(--gray-100); border-radius: 9999px; overflow: hidden; }
.hbar > span { display: block; height: 100%; background: var(--primary); border-radius: 9999px; }
.hbar-n { font-weight: 600; text-align: right; font-variant-numeric: tabular-nums; }
.hbar-extra { color: var(--gray-500); font-size: .78rem; white-space: nowrap; }
.dash-table { width: 100%; border-collapse: collapse; font-size: .88rem; }
.dash-table th, .dash-table td { padding: 6px 8px; border-bottom: 1px solid var(--gray-200); text-align: right; font-variant-numeric: tabular-nums; }
.dash-table th:first-child { text-align: left; font-weight: 500; color: var(--gray-700); }
.dash-table thead th { color: var(--gray-500); font-weight: 600; font-size: .78rem; }
.dash-table .age-row-2 td { color: var(--yellow-800); font-weight: 600; }
.dash-table .age-row-3 td { color: var(--red-700); font-weight: 600; }
.dash-counts { margin: 0; display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.dash-counts div { padding: 10px 12px; border-radius: var(--radius); background: var(--gray-50); border-left: 4px solid var(--blue-600); }
.dash-counts div.dash-alert { border-left-color: var(--accent); background: #fffbeb; }
.dash-counts dt { color: var(--gray-600); font-size: .85rem; }
.dash-counts dd { margin: 0; font-size: 1.6rem; font-weight: 700; color: var(--primary); line-height: 1.2; }
.dash-counts dd a { color: inherit; text-decoration: none; }
.dash-counts dd a:hover { text-decoration: underline; }
.dash-stats { margin: 0; display: grid; gap: 10px; }
.dash-stats div { display: grid; grid-template-columns: minmax(150px, 42%) 1fr; gap: 10px; align-items: baseline; padding-bottom: 8px; border-bottom: 1px solid var(--gray-200); }
.dash-stats div:last-child { border-bottom: 0; padding-bottom: 0; }
.dash-stats dt { color: var(--gray-600); font-size: .88rem; }
.dash-stats dd { margin: 0; font-size: .88rem; }
.dash-stats dd strong { font-size: 1.25rem; color: var(--primary); }
.dash-stats dd span { color: var(--gray-500); }
.trend-pair { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 380px), 1fr)); gap: 24px; }
.trend { display: grid; grid-template-columns: repeat(12, 1fr); gap: 4px; align-items: end; height: 150px; padding-top: 4px; border-bottom: 1px solid var(--gray-300); }
.trend-month { display: flex; flex-direction: column; align-items: center; height: 100%; }
.trend-bars { flex: 1; width: 100%; display: flex; align-items: flex-end; justify-content: center; gap: 2px; }
.trend-bars span { width: 40%; max-width: 14px; min-height: 0; border-radius: 3px 3px 0 0; }
.bar-opened, .key-opened { background: var(--primary); }
.bar-closed, .key-closed { background: var(--accent); }
.trend-label { margin-top: 4px; font-size: .7rem; color: var(--gray-500); transform: translateY(18px); height: 0; }
.trend-pair > div { padding-bottom: 22px; }
.key { display: inline-block; width: 10px; height: 10px; border-radius: 2px; margin: 0 4px 0 10px; vertical-align: -1px; }
.dash-numbers { margin-top: 8px; }
.dash-numbers summary { cursor: pointer; color: var(--link); font-size: .85rem; font-weight: 500; }
.dash-numbers table { margin-top: 8px; }
@media screen and (max-width: 639px) {
  .hbars li, .hbar-link { grid-template-columns: 1fr 36px; }
  .hbar { grid-column: 1 / -1; grid-row: 2; }
  .hbar-extra { grid-column: 1 / -1; }
  .dash-stats div { grid-template-columns: 1fr; gap: 2px; }
}
@media print {
  .dash-card, .tile { box-shadow: none; border: 1px solid var(--gray-300); break-inside: avoid; }
  .hbar > span, .trend-bars span, .key { -webkit-print-color-adjust: exact; print-color-adjust: exact; }
  .dash-numbers[open] summary, .dash-numbers summary { display: none; }
}

/* management review pack */
.review-period { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 12px; margin-bottom: 12px; }
.review-period label { display: inline-flex; align-items: center; gap: 6px; font-weight: 500; color: var(--gray-700); }
.review-period input[type=date] { font: inherit; padding: 6px 8px; border: 1px solid var(--gray-300); border-radius: var(--radius); background: #fff; color: var(--ink); }
.review-presets { display: inline-flex; flex-wrap: wrap; gap: 4px 12px; font-size: .88rem; }
.review-presets a[aria-current] { font-weight: 600; color: var(--ink); text-decoration: none; }
.review-intro { margin: 0 0 16px; color: var(--gray-600); font-size: .88rem; }
.review-tiles .tile-note { color: var(--gray-600); font-weight: 500; }
.review-tiles .tile-alert .tile-note { color: var(--red-700); font-weight: 600; }
.review-section { margin-bottom: 16px; }
.dash-card h2 small { color: var(--muted); font-weight: 400; font-size: .8rem; margin-left: .3rem; }
.review-table td, .review-table th { white-space: nowrap; }
.review-actions .review-table td:nth-child(3), .review-actions .review-table td:nth-child(4) { white-space: normal; text-align: left; }
.review-actions .review-table td:nth-child(5) { text-align: left; }
.review-actions .review-table thead th { text-align: left; }
.review-table tr.overdue th, .review-table tr.overdue td { background: var(--red-50); }
.review-table tfoot th, .review-table tfoot td { font-weight: 700; border-bottom: 0; }
.review-notes { display: none; }
.review-lines span { display: block; height: 28px; border-bottom: 1px solid var(--gray-300); }
@media print {
  .review-page .review-notes { display: block; break-inside: avoid; }
  .review-page .review-section { break-inside: auto; }
  .review-table tr { break-inside: avoid; }
  .review-table tr.overdue th, .review-table tr.overdue td { -webkit-print-color-adjust: exact; print-color-adjust: exact; }
}

/* install popup: a card at the bottom right, a bottom sheet on phones */
.install-sheet { position: fixed; z-index: 30; right: 24px; bottom: 24px; width: 380px; display: flex; gap: 14px; align-items: flex-start; padding: 18px 18px 16px; background: var(--paper); border-top: 4px solid var(--accent); border-radius: var(--radius-xl); box-shadow: var(--shadow-xl), 0 0 0 1px rgb(0 0 0 / .04); animation: sheet-in .25s var(--ease); }
.install-icon { flex: none; border-radius: 12px; box-shadow: var(--shadow-sm); }
.install-body { min-width: 0; flex: 1; }
.install-body h2 { margin: 2px 0 4px; font-size: 1.05rem; font-weight: 700; color: var(--primary); }
.install-body p { margin: 0 0 12px; color: var(--gray-600); font-size: .9rem; }
.install-steps { margin: 0 0 14px; padding-left: 20px; color: var(--gray-700); font-size: .9rem; }
.install-steps li { margin: 4px 0; }
.step-icon { display: inline-flex; color: var(--blue-600); vertical-align: -2px; }
.install-actions { display: flex; gap: 8px; }
.install-actions .button { padding: 8px 14px; }
@keyframes sheet-in { from { opacity: 0; transform: translateY(12px); } }

@media screen and (max-width: 639px) {
  .install-sheet { left: 8px; right: 8px; bottom: 8px; width: auto; padding-bottom: calc(16px + env(safe-area-inset-bottom)); }
  .install-actions .button { flex: 1; }
}
button.link { background: none; border: 0; color: var(--link); cursor: pointer; font: inherit; padding: 0; text-decoration: underline; }

/* toolbar and buttons */
.toolbar { display: flex; align-items: center; gap: 12px 16px; margin: 4px 0 16px; flex-wrap: wrap; }
.toolbar .actions { margin-left: auto; display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.toolbar h1.record-title { flex-basis: auto; }
/* a form's buttons while it submits (site.js); the one pressed keeps its colour and shows a spinner */
.button.busy[disabled] { opacity: .85; cursor: progress; }
.button.busy .spinner + .icon { display: none; }
.button:not(.primary):not(.success):not(.danger) .spinner { border-color: var(--gray-300); border-top-color: var(--gray-600); }
.back { display: inline-flex; align-items: center; gap: 6px; text-decoration: none; font-weight: 500; }
.status-select { font-weight: 500; color: var(--gray-700); }
.status-select select { margin-left: 6px; }
select, input[type=search], .attach-form input[type=text] { font: inherit; padding: 7px 10px; border: 1px solid var(--gray-300); border-radius: var(--radius); background: #fff; color: var(--ink); transition: all .15s var(--ease); }
select:focus, input:focus, textarea:focus { outline: none; border-color: transparent; box-shadow: 0 0 0 2px var(--blue-500); }
input[type=file] { font: inherit; font-size: .875rem; max-width: 100%; }
input[type=file]::file-selector-button { font: inherit; font-weight: 500; margin-right: 10px; padding: 6px 12px; border: 2px solid var(--gray-300); border-radius: var(--radius); background: var(--paper); color: var(--gray-700); cursor: pointer; transition: all .15s var(--ease); }
input[type=file]::file-selector-button:hover { background: var(--gray-50); border-color: var(--gray-400); }

/* alerts */
.messages { list-style: none; padding: 0; margin: 0 0 16px; }
.messages li, .messages p { padding: 12px 16px; border: 1px solid var(--blue-200); border-radius: var(--radius); background: var(--blue-50); color: var(--blue-800); margin: 0 0 8px; font-size: .9rem; }
.messages .success { background: var(--green-500); border-color: var(--green-500); color: #fff; box-shadow: var(--shadow-md); }
.messages .warning { background: var(--yellow-100); border-color: #fde68a; color: var(--yellow-800); }
.messages .error, .messages p.error { background: var(--red-50); border-color: var(--red-200); color: var(--red-700); }

/* status badges: gray = not started, yellow/orange = waiting, blue = in progress, red = problem, green = done */
.status { display: inline-block; padding: 2px 10px; border-radius: var(--radius); font-size: .8rem; font-weight: 600; line-height: 1.5; background: var(--gray-100); color: var(--gray-700); white-space: nowrap; }
.status-draft { background: var(--gray-100); color: var(--gray-700); }
.status-open { background: var(--yellow-100); color: var(--yellow-800); }
.status-mrb_review { background: var(--orange-100); color: var(--orange-800); }
.status-qm_review { background: var(--blue-50); color: var(--blue-700); }
.status-dispositioned { background: var(--blue-100); color: var(--blue-800); }
.status-scar_issued { background: var(--red-50); color: var(--red-700); }
.status-response_received { background: var(--blue-50); color: var(--blue-700); }
.status-rejected { background: var(--red-50); color: var(--red-700); }
.status-escalated { background: var(--red-600); color: #fff; }
.status-verification { background: var(--blue-100); color: var(--blue-800); }
.status-resolved { background: var(--green-50); color: var(--green-800); box-shadow: inset 0 0 0 1px var(--green-200); }
.status-closed { background: var(--green-100); color: var(--green-800); }
.status-deleted { background: var(--gray-700); color: #fff; }
.deleted-banner { max-width: 1000px; margin: 0 auto 16px; padding: 12px 16px; border-left: 4px solid var(--gray-700); border-radius: var(--radius); background: var(--gray-100); color: var(--gray-800); font-size: .9rem; }
.status-reopened { background: var(--gray-100); color: var(--gray-500); text-decoration: line-through; }

/* workflow panel: the one place the accent colour leads */
.workflow { max-width: 1000px; margin: 0 auto 16px; padding: 16px 20px; background: var(--paper); border-left: 4px solid var(--accent); border-radius: var(--radius); box-shadow: var(--shadow-md); }
.workflow-next { margin: 0 0 8px; font-weight: 600; font-size: 1.05rem; color: var(--gray-800); }
.workflow .waiting { margin: 0; padding-left: 20px; color: var(--gray-700); }
.workflow .waiting li { margin: 2px 0; }
.workflow .waiting li.me { color: var(--gray-800); }
.workflow .you { display: inline-block; margin-left: 6px; padding: 0 8px; border-radius: var(--radius); background: var(--accent); color: var(--gray-800); font-size: .75rem; font-weight: 600; }
.workflow-actions { margin-top: 12px; padding-top: 12px; border-top: 1px solid var(--gray-200); }
.workflow-actions .hint { margin: 0 0 8px; }
.workflow-actions.upload { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 12px; }
.workflow-actions.upload .hint { flex-basis: 100%; margin: 0; }
.paper-origin { max-width: 1000px; margin: 0 auto 16px; padding: 12px 20px; background: var(--paper); border-left: 4px solid var(--primary); border-radius: var(--radius); box-shadow: var(--shadow-md); color: var(--gray-700); }
.paper-origin p { margin: 0; }
.paper-origin a { display: inline-flex; align-items: center; gap: 4px; }
.paper-origin .icon { width: 16px; height: 16px; }
.paper-origin .paper-note { margin-top: 6px; font-size: .9rem; }
.paper .paper-origin { margin: 12px 0 0; box-shadow: none; border-radius: 0; padding: 8px 12px; }
.workflow-actions.upload label { font-weight: 500; color: var(--gray-700); }
.docs-links { display: flex; flex-wrap: wrap; align-items: center; gap: 4px 8px; margin: 0 0 12px; font-size: .8125rem; color: var(--muted); }
.docs-links.on-record { max-width: 1000px; margin: 0 auto 12px; }
.docs-links .docs-label { display: inline-flex; align-items: center; gap: 4px; font-weight: 600; color: var(--gray-700); }
.docs-links .docs-label svg { width: 15px; height: 15px; }
.docs-links a { color: var(--primary); }
.send-message { display: block; margin: 0 0 8px; font-weight: 500; color: var(--gray-700); }
.send-message textarea { display: block; width: 100%; margin-top: 4px; font: inherit; padding: 7px 10px; border: 1px solid var(--gray-300); border-radius: var(--radius); resize: vertical; }
.inline-form { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 12px; margin-top: 8px; }
.inline-form label { font-weight: 500; color: var(--gray-700); }
.inline-form select { margin-left: 6px; font: inherit; padding: 4px 6px; }
.linked-records { width: 100%; border-collapse: collapse; font-size: .85rem; margin-top: 4px; }
.linked-records th, .linked-records td { border: 1px solid var(--gray-200); padding: 3px 6px; text-align: left; }
.linked-records th { font-weight: 600; color: var(--gray-700); background: var(--gray-50, #f8f9fa); }
.workflow > .hint { margin: 8px 0 0; font-size: .85rem; }

.attachments { max-width: 1000px; margin: 16px auto; padding: 16px 20px; background: var(--paper); border-radius: var(--radius); box-shadow: var(--shadow-md); }
.attachments h2 { margin: 0 0 8px; font-size: 1.125rem; font-weight: 600; color: var(--primary); }
.attachments ul { margin: 0 0 12px; padding-left: 20px; }
.attachments li { margin: 4px 0; }
.attachments .meta { margin: 0; }
.attachments h2 small { font-size: .8125rem; font-weight: 500; color: var(--muted); }
.comments { list-style: none; margin: 0 0 12px; padding: 0; }
.comments .comment { margin: 0 0 10px; padding: 8px 12px; border-left: 3px solid var(--gray-300); background: var(--gray-50); border-radius: 0 var(--radius) var(--radius) 0; }
.comments .comment.mine { border-left-color: var(--primary); }
.comment-who { margin: 0 0 4px; }
.comment-text { overflow-wrap: anywhere; }
.comment-form { display: flex; flex-wrap: wrap; gap: 8px; align-items: flex-end; }
.comment-form textarea { flex: 1 1 320px; font: inherit; padding: 7px 10px; border: 1px solid var(--gray-300); border-radius: var(--radius); resize: vertical; }
.attach-form { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.attach-form input[type=text] { flex: 1 1 220px; }

/* paper form: a reproduction of the controlled document, so it stays square and ruled */
.paper { background: var(--paper); border: 1px solid var(--gray-300); box-shadow: var(--shadow-md); padding: 24px; max-width: 1000px; margin: 0 auto; }
.form-header { width: 100%; border-collapse: collapse; margin-bottom: 14px; font-size: .9rem; }
.form-header td { border: 1px solid var(--gray-800); padding: 6px 10px; }
.form-header .logo { width: 25%; }
.form-header .logo img { max-width: 170px; height: auto; display: block; }
.form-header .title { text-align: center; font-weight: 700; font-size: 1rem; }
.form-header .code { text-align: center; font-weight: 700; width: 20%; }
.form-header .center { text-align: center; font-weight: 600; }

.sheet-section { margin-bottom: 0; }
.bar { background: var(--bar); color: var(--bar-ink); font-size: .85rem; font-weight: 700; margin: 0; padding: 5px 8px; border: 1px solid var(--line); border-bottom: 0; letter-spacing: .02em; }
.bar small { font-weight: 400; text-transform: none; letter-spacing: 0; }
.sheet-row { display: grid; grid-template-columns: repeat(12, 1fr); border-left: 1px solid var(--line); }
.sheet-section .sheet-row:last-child { border-bottom: 1px solid var(--line); }
.cell { border-right: 1px solid var(--line); border-top: 1px solid var(--line); padding: 4px 6px 6px; min-height: 48px; min-width: 0; }
.cell.long { min-height: 110px; }
.cell.editable { background: var(--edit); }
.cell-label { font-size: .7rem; font-weight: 600; color: var(--gray-700); line-height: 1.3; }
.cell-value { font-size: .9rem; padding-top: 3px; overflow-wrap: anywhere; }
.placeholder { color: var(--muted); font-style: italic; font-size: .85rem; }
.req { color: var(--red-600); }
.hint { font-size: .75rem; color: var(--muted); margin-top: 2px; }
.hint.locked { font-style: italic; }
.error { color: var(--red-700); font-size: .8rem; margin-top: 2px; }
.cell-input input[type=text], .cell-input input[type=number], .cell-input input[type=date], .cell-input input[type=email], .cell-input input[type=tel], .cell-input textarea,
.cell-input input:not([type]) { width: 100%; font: inherit; font-size: .9rem; padding: 5px 8px; border: 1px solid var(--gray-300); border-radius: 6px; background: #fff; color: var(--ink); transition: all .15s var(--ease); }
.cell-input textarea { resize: vertical; }
.cell-input input[type=checkbox], .cell-input input[type=radio] { accent-color: var(--blue-600); }
.cell-input.type-choice > div, .cell-input.type-multichoice > div { display: flex; flex-wrap: wrap; gap: 4px 18px; margin-top: 4px; }
.cell-input.type-choice label, .cell-input.type-multichoice label { white-space: nowrap; }
.cell-input label { font-size: .875rem; }
.cell-input.type-signoff label { font-size: .85rem; display: flex; gap: 6px; align-items: center; margin-top: 4px; }
.meta { color: var(--muted); font-size: .8rem; margin: 12px 0 0; }
.form-footer { max-width: 1000px; margin: 16px auto; display: flex; justify-content: flex-end; gap: 8px; }

.span-1 { grid-column: span 1; } .span-2 { grid-column: span 2; } .span-3 { grid-column: span 3; }
.span-4 { grid-column: span 4; } .span-5 { grid-column: span 5; } .span-6 { grid-column: span 6; }
.span-7 { grid-column: span 7; } .span-8 { grid-column: span 8; } .span-9 { grid-column: span 9; }
.span-10 { grid-column: span 10; } .span-11 { grid-column: span 11; } .span-12 { grid-column: span 12; }

/* tables */
.filters { display: flex; gap: 8px; margin-bottom: 12px; flex-wrap: wrap; }
.filters input[type=search] { min-width: min(320px, 100%); }
.table-wrap { overflow-x: auto; background: var(--paper); border-radius: var(--radius); box-shadow: var(--shadow-md); }
table.log { border-collapse: collapse; width: 100%; font-size: .85rem; }
table.log th { background: var(--gray-50); color: var(--gray-700); font-weight: 600; text-align: left; padding: 10px 10px; border-bottom: 2px solid var(--gray-200); white-space: nowrap; position: sticky; top: 0; }
/* Date Opened and the record number sort the log; the arrow shows which way */
table.log th.sortable { padding: 0; }
table.log th.sortable a { display: flex; align-items: center; gap: 6px; padding: 10px 10px; color: inherit; text-decoration: none; }
table.log th.sortable a:hover { background: var(--gray-100); color: var(--primary); }
.sort-arrow { display: inline-flex; color: var(--gray-400); }
.sort-arrow .icon { width: 14px; height: 14px; }
table.log th.sortable a:hover .sort-arrow, .sort-arrow.active { color: var(--primary); }
table.log th[aria-sort="ascending"], table.log th[aria-sort="descending"] { color: var(--primary); }
table.log td { padding: 8px 10px; border-bottom: 1px solid var(--gray-200); vertical-align: top; white-space: nowrap; }
table.log tbody tr { transition: background-color .15s var(--ease); }
table.log tbody tr:hover td { background: var(--gray-50); }
table.log td.wrap { white-space: normal; min-width: 200px; }
table.log td.empty { text-align: center; color: var(--muted); padding: 32px; }
table.log tr.overdue td, table.log tbody tr.overdue:hover td { background: var(--red-50); }
table.log tr.overdue td:first-child { box-shadow: inset 4px 0 0 var(--red-500); }
table.log td small { color: var(--muted); }
table.audit td.old { color: var(--red-700); }
table.audit td.new { color: var(--green-800); }
.nowrap { white-space: nowrap; }

/* sign-in and notices */
.signin-page { background: linear-gradient(to bottom right, var(--gray-50), var(--gray-100)); min-height: 100vh; }
.signin, .notice { max-width: 448px; margin: 48px auto; background: var(--paper); border-radius: var(--radius-xl); box-shadow: var(--shadow-xl); padding: 32px; text-align: center; }
.signin img { max-width: 220px; margin-bottom: 16px; }
.signin h1, .notice h1 { margin-bottom: 8px; }
.signin p, .notice p { color: var(--gray-600); }
.signin .button { width: 100%; }

.print-footer { display: none; }

@media (min-width: 640px) {
  main { padding: 24px var(--gutter); }
}

@media (min-width: 768px) {
  main { padding: 32px var(--gutter); }
  h1 { font-size: 1.875rem; }
}

/* phones and tablets: menu button, cards instead of wide tables, larger touch targets */
@media screen and (max-width: 1023px) {

  /* 16px inputs stop iPhones zooming in when a field is tapped */
  .cell-input input, .cell-input textarea, .cell-input select, select, input[type=search], .attach-form input[type=text] { font-size: 16px; }
  .cell-input input[type=checkbox], .cell-input input[type=radio] { width: 20px; height: 20px; margin: 0; }
  .cell-input.type-choice label, .cell-input.type-multichoice label, .cell-input.type-signoff label { display: inline-flex; align-items: center; gap: 8px; min-height: 40px; }
  .button { min-height: 44px; }

  /* the edit form's save button stays in reach at the bottom of the screen, so the top one is not needed */
  .record-form .toolbar .actions .button.primary, .record-form .toolbar .actions .button.success,
  .record-form .toolbar .actions [data-clear-form], .record-form .toolbar .actions [data-cancel-edit] { display: none; }
  .form-footer { position: sticky; bottom: 0; z-index: 5; max-width: none; margin: 16px calc(-1 * var(--gutter)) -16px; padding: 12px var(--gutter); background: rgb(255 255 255 / .96); box-shadow: 0 -4px 6px -1px rgb(0 0 0 / .1); }

  /* logs and audit trail as cards */
  .table-wrap { background: none; box-shadow: none; overflow: visible; border-radius: 0; }
  table.log, table.log tbody, table.log td { display: block; }
  table.log thead { display: none; }
  table.log tbody { display: grid; grid-template-columns: repeat(auto-fill, minmax(min(100%, 340px), 1fr)); gap: 12px; }
  table.log tr { display: grid; grid-template-columns: 1fr 1fr; align-content: start; gap: 10px 16px; padding: 14px 16px; background: var(--paper); border-radius: var(--radius); box-shadow: var(--shadow-md); }
  table.log td, table.log tbody tr:hover td, table.log tr.overdue td { padding: 0; border: 0; white-space: normal; min-width: 0; background: none; overflow-wrap: anywhere; }
  table.log td::before { content: attr(data-label); display: block; font-size: .72rem; font-weight: 500; color: var(--gray-500); }
  table.log td:empty { display: none; }
  table.log td.wrap { grid-column: 1 / -1; min-width: 0; }
  table.log td.kind-number, table.log td.col-record { order: -2; font-size: 1.05rem; font-weight: 600; }
  table.log td.kind-status { order: -1; justify-self: end; align-self: start; }
  table.log td.kind-number::before, table.log td.kind-status::before, table.log td.col-record::before, table.log td.empty::before { display: none; }
  table.log tr.overdue { background: var(--red-50); box-shadow: inset 4px 0 0 var(--red-500), var(--shadow-md); }
  table.log tr.overdue td:first-child { box-shadow: none; }
  table.log td.empty { grid-column: 1 / -1; padding: 24px; }
}

@media screen and (max-width: 639px) {
  h1 { font-size: 1.375rem; }
  .toolbar { gap: 10px; margin-bottom: 12px; }
  .toolbar h1 { flex-basis: 100%; }
  .toolbar .actions { margin-left: 0; width: 100%; display: grid; grid-template-columns: 1fr 1fr; }
  .toolbar .actions .button { width: 100%; }
  /* with an odd number of buttons the first, main action takes the full row */
  .toolbar .actions > :first-child:nth-last-child(odd), .toolbar .status-select { grid-column: 1 / -1; }
  .toolbar .status-select { display: flex; align-items: center; }
  .toolbar .status-select select { flex: 1; }
  .filters input[type=search] { flex: 1 1 200px; min-width: 0; }
  .filters:has(select) input[type=search] { flex-basis: 100%; }
  .filters select { flex: 1; min-width: 0; }
  .workflow, .attachments { padding: 14px 16px; }
  .workflow-actions .button, .attach-form .button { width: 100%; }
  .workflow-actions.upload label, .attach-form input { flex-basis: 100%; }
  .attachments li .meta { display: block; }
  .form-footer .button { width: 100%; }
  /* the paper form runs edge to edge to give the fields the full width */
  .paper { margin: 0 calc(-1 * var(--gutter)); border-left: 0; border-right: 0; }
}

@media screen and (max-width: 760px) {
  .sheet-row { grid-template-columns: 1fr; }
  .sheet-row .cell { grid-column: span 1; }
  .paper { padding: 12px; }
  .form-header { font-size: .8rem; }
  .form-header td { padding: 4px 6px; }
  .form-header .logo img { max-width: 100%; }
  .bar small { display: block; }
  .cell-input.type-choice label, .cell-input.type-multichoice label { white-space: normal; }
}

/* Page transitions are in shell.css. Opening a record from the Inbox, its number moves from the card into the
   record's heading (and back). */
.record-number { view-transition-class: record-number; }
::view-transition-group(*.record-number) { animation-duration: .28s; animation-timing-function: cubic-bezier(.4, 0, .2, 1); }

/* Messages such as "Saved" drop in once the page has faded in. */
main > .messages li { animation: message-in .3s var(--ease) .2s both; }
@keyframes message-in { from { opacity: 0; transform: translateY(-8px); } }

/* Dashboard and management review bars grow to their length (on screen; printed at full length). */
@media screen { .hbar > span { animation: bar-grow .7s cubic-bezier(.22, 1, .36, 1) .15s both; } }
@keyframes bar-grow { from { width: 0; } }

/* A comment just posted: the page lands on it (below the sticky top bar) and it flashes yellow. */
#discussion, .comments .comment { scroll-margin-top: 80px; }
.comments .comment:target { animation: comment-flash 2.2s var(--ease) .3s both; }
@keyframes comment-flash { from { background: var(--yellow-100); } }

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; animation: none !important; }
  .delete-dialog::backdrop { transition: none !important; }
  ::view-transition-group(*.record-number), ::view-transition-new(*.record-number) { animation: none !important; }
  ::view-transition-old(*.record-number) { display: none; }
}

@media print {
  @page { size: letter; margin: 0.5in; }
  body { background: #fff; font-size: 11pt; }
  .no-print, .topbar, .messages { display: none !important; }
  main { padding: 0; max-width: none; }
  h1 { color: #000; }
  .paper { border: 0; box-shadow: none; padding: 0; max-width: none; }
  .cell.editable { background: none; }
  .sheet-row { break-inside: avoid; }
  .cell-value, .cell-value a, .linked-records td, .linked-records a { color: #000; }
  .bar { -webkit-print-color-adjust: exact; print-color-adjust: exact; break-after: avoid; page-break-after: avoid; }
  .status { -webkit-print-color-adjust: exact; print-color-adjust: exact; }
  table.log th { -webkit-print-color-adjust: exact; print-color-adjust: exact; position: static; border: 1px solid var(--gray-300); }
  table.log td { border: 1px solid var(--gray-300); }
  table.log { font-size: 8pt; }
  table.log th, table.log td { white-space: normal; padding: 4px 5px; }
  table.log th.sortable a { padding: 0; }
  .sort-arrow { display: none; }
  table.log td.kind-number, table.log td.kind-ref, table.log td.col-record { white-space: nowrap; }
  table.log tr.overdue td:first-child { box-shadow: none; }
  .table-wrap { box-shadow: none; overflow: visible; border-radius: 0; }
  .print-footer { display: flex; justify-content: space-between; font-size: 8pt; margin-top: 10px; color: #333; }
}
