/* SkyCoach review tool — base styles (no framework). */
:root {
  --bg: #f4f5f7;
  --surface: #ffffff;
  --text: #1c2330;
  --muted: #5d6778;
  --border: #d5dae2;
  --accent: #1f5fae;
  --accent-text: #ffffff;
  --approved: #1e7a3c;
  --rejected: #b3261e;
  --commented: #6a4a9c;
  --error-bg: #fdecea;
  --radius: 8px;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  font-size: 16px;
  line-height: 1.45;
  color: var(--text);
  background: var(--bg);
}

* { box-sizing: border-box; }
body { margin: 0; min-height: 100vh; background: var(--bg); }
main { padding: 16px; }
h1 { font-size: 1.4rem; margin: 0 0 12px; }

.topbar {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 10px 16px; background: var(--surface); border-bottom: 1px solid var(--border);
}
.brand { font-weight: 600; color: var(--text); text-decoration: none; }
.session { display: flex; align-items: center; gap: 12px; color: var(--muted); }
.session form { margin: 0; }

.card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 20px; max-width: 960px; margin: 0 auto;
}
.card.narrow { max-width: 380px; margin-top: 8vh; }

.stack { display: flex; flex-direction: column; gap: 14px; }
label { display: flex; flex-direction: column; gap: 4px; font-weight: 500; }
input, textarea {
  font: inherit; padding: 10px 12px; border: 1px solid var(--border); border-radius: 6px;
  background: var(--surface); color: var(--text);
}
input:focus, textarea:focus, button:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }

button { font: inherit; cursor: pointer; border-radius: 6px; padding: 10px 16px; border: 1px solid var(--border);
         background: var(--surface); color: var(--text); min-height: 44px; }
button.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-text); font-weight: 600; }
button.link { border: none; background: none; padding: 0; min-height: 0; color: var(--accent); text-decoration: underline; }
button:disabled { opacity: .5; cursor: not-allowed; }

.error { background: var(--error-bg); color: var(--rejected); padding: 10px 12px; border-radius: 6px; margin: 0 0 12px; }

h2 { font-size: 1.1rem; margin: 0 0 10px; }
a.button {
  display: inline-flex; align-items: center; justify-content: center; min-height: 44px; padding: 10px 16px;
  border-radius: 6px; border: 1px solid var(--border); background: var(--surface); color: var(--text);
  text-decoration: none; white-space: nowrap;
}
a.button.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-text); font-weight: 600; }

.dashboard { display: flex; flex-direction: column; gap: 16px; max-width: 760px; margin: 0 auto; }
.dashboard .card { width: 100%; }
.status { background: #eef3fb; border-left: 4px solid var(--accent); padding: 12px 14px; margin: 0 0 16px; border-radius: 4px; }
.status.done { background: #e9f5ec; border-left-color: var(--approved); }
.unit {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 12px 14px; border: 1px solid var(--border); border-radius: var(--radius);
}
.unit > div { display: flex; flex-direction: column; min-width: 0; }
.unit.current { border-color: var(--accent); margin-bottom: 16px; }
.unit-title { overflow-wrap: anywhere; }
.label { font-size: .8rem; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); }
.progress, .hint { color: var(--muted); font-size: .9rem; }
.hint { margin: 8px 0 0; }
.unit-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 8px; }

.session > span, .session button { white-space: nowrap; }
@media (max-width: 520px) {
  .brand-sub { display: none; }
}

/* Review screen: viewer + assertions. Wide screens: two columns, independent scrolling. */
.review-page main { padding: 0; }
.review { display: grid; gap: 0; grid-template-columns: 1fr; }
.review-header {
  grid-column: 1 / -1; display: flex; align-items: center; gap: 16px; flex-wrap: wrap;
  padding: 10px 16px; background: var(--surface); border-bottom: 1px solid var(--border);
}
.review-header h1 { margin: 0; font-size: 1.15rem; overflow-wrap: anywhere; }
.review-heading { flex: 1; min-width: 0; }
.review-header .meta { margin: 2px 0 0; color: var(--muted); font-size: .85rem; overflow-wrap: anywhere; }
.back { color: var(--accent); text-decoration: none; white-space: nowrap; }

.viewer-pane { background: #525659; min-width: 0; display: flex; flex-direction: column; }
.pdf-viewer { display: flex; flex-direction: column; flex: 1; min-height: 0; }
.pdf-tabs { display: flex; gap: 4px; padding: 6px 8px 0; background: #3b3e41; overflow-x: auto; }
.pdf-tab { background: #6b6f73; color: #fff; border: none; border-radius: 6px 6px 0 0; min-height: 36px; padding: 6px 12px; }
.pdf-tab[aria-selected="true"] { background: #f4f5f7; color: var(--text); font-weight: 600; }
.pdf-toolbar {
  display: flex; align-items: center; gap: 6px; padding: 6px 8px; background: #f4f5f7; border-bottom: 1px solid var(--border);
}
.pdf-toolbar button { min-height: 36px; padding: 4px 10px; }
.pdf-toolbar .spacer { flex: 1; }
.page-indicator { font-variant-numeric: tabular-nums; font-size: .9rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.pdf-scroll { overflow: auto; flex: 1; min-height: 60vh; padding: 0; -webkit-overflow-scrolling: touch; }
.pdf-scroll canvas { display: block; margin: 0 auto; background: #fff; box-shadow: 0 1px 4px rgba(0,0,0,.4); }

.assertions-pane { padding: 12px 16px 24px; min-width: 0; }
.instructions {
  margin: 0 0 12px; padding: 10px 12px; background: #fff8e1; border: 1px solid #f0d58c; border-radius: 6px; font-size: .9rem;
}
.cards { display: flex; flex-direction: column; gap: 10px; }
.assertion-card {
  background: var(--surface); border: 1px solid var(--border); border-left: 4px solid var(--accent);
  border-radius: var(--radius); padding: 12px 14px; cursor: pointer;
}
.assertion-card.selected { box-shadow: 0 0 0 2px var(--accent); }
.card-head { display: flex; justify-content: space-between; gap: 8px; align-items: baseline; }
.assertion-id { font-weight: 700; }
.page-badge { font-size: .8rem; background: #e7eef8; color: var(--accent); border-radius: 999px; padding: 2px 8px; white-space: nowrap; }
.region { margin: 4px 0 0; color: var(--muted); font-size: .8rem; }
.packaging-note {
  margin: 8px 0 0; padding: 8px 10px; background: #fff3cd; border-left: 4px solid #d99a00; border-radius: 4px; font-size: .9rem;
}
.assertion-text { margin-top: 8px; white-space: pre-wrap; overflow-wrap: anywhere; font-size: 1rem; line-height: 1.5; }

@media (min-width: 1024px) {
  .review { grid-template-columns: minmax(0, 65fr) minmax(0, 35fr); height: calc(100vh - 45px); grid-template-rows: auto minmax(0, 1fr); }
  .viewer-pane { min-height: 0; }
  .pdf-scroll { min-height: 0; }
  .assertions-pane { overflow-y: auto; border-left: 1px solid var(--border); }
}

/* Decisions on cards */
.card-actions { margin-top: 10px; }
.decision-buttons { display: flex; gap: 8px; flex-wrap: wrap; }
.decide { flex: 1 1 140px; font-weight: 600; }
.decide.approved { border-color: var(--approved); color: var(--approved); }
.decide.rejected { border-color: var(--rejected); color: var(--rejected); }
.decide.approved.chosen { background: var(--approved); color: #fff; }
.decide.rejected.chosen { background: var(--rejected); color: #fff; }
.decide.commented { border-color: var(--commented); color: var(--commented); }
.decide.commented.chosen { background: var(--commented); color: #fff; }
.comment-area { margin-top: 10px; display: flex; flex-direction: column; gap: 6px; }
.comment-area label { font-weight: 500; font-size: .9rem; }
.comment-area textarea { resize: vertical; min-height: 72px; }
.comment-footer { display: flex; justify-content: space-between; align-items: center; }
.comment-count { color: var(--muted); font-size: .85rem; font-variant-numeric: tabular-nums; }
.card-error { margin: 4px 0 0; }

.assertion-card[data-state="done"] { background: #eef0f3; border-left-color: #9aa3af; color: #4a5260; }
.assertion-card[data-state="done"] .packaging-note { background: #f3f0e6; border-left-color: #b9a46a; }
.done-row { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.decision-badge { font-weight: 700; padding: 2px 10px; border-radius: 999px; color: #fff; }
.decision-badge.approved { background: var(--approved); }
.decision-badge.rejected { background: var(--rejected); }
.decision-badge.commented { background: var(--commented); }
.author { color: var(--muted); font-size: .85rem; }
.done-tools { margin-left: auto; display: flex; gap: 6px; }
button.icon { min-height: 36px; min-width: 40px; padding: 4px 8px; }
.done-comment { margin: 8px 0 0; white-space: pre-wrap; overflow-wrap: anywhere; font-size: .9rem; }

.unit-complete {
  margin-top: 16px; padding: 14px; background: #e9f5ec; border: 1px solid #a8d5b5; border-radius: var(--radius);
  display: flex; flex-direction: column; gap: 8px; align-items: flex-start;
}
.unit-complete[hidden] { display: none; }
/* Classified cards are collapsed: two lines of text, no zone/note, until unfolded. */
.assertion-card[data-state="done"]:not(.unfolded) .region,
.assertion-card[data-state="done"]:not(.unfolded) .packaging-note { display: none; }
.assertion-card[data-state="done"]:not(.unfolded) .assertion-text {
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; font-size: .9rem;
}

/* Responsive review screen (spec §6.5). Tabs and "back" button exist only on phones. */
.mobile-tabs, .back-to-assertions { display: none; }
.pdf-scroll { touch-action: pan-x pan-y; }          /* pinch is handled by the viewer, not the page */
.pdf-scroll canvas { transform-origin: 0 0; }
.label-short { display: none; }

/* iPad portrait / tablet: chart on top (fixed height, own scrolling), assertions below. */
@media (min-width: 700px) and (max-width: 1023px) {
  .viewer-pane { height: 58vh; }
  .pdf-scroll { min-height: 0; }
}

/* Phone: two tabs, one pane at a time. */
@media (max-width: 699px) {
  .topbar { padding: 8px 12px; }
  .review-header { padding: 8px 12px; gap: 8px; }
  .review-header h1 { font-size: 1rem; }
  .review-header .meta { font-size: .75rem; }
  .mobile-tabs {
    display: flex; position: sticky; top: 0; z-index: 5; background: var(--surface); border-bottom: 1px solid var(--border);
  }
  .mobile-tabs button {
    flex: 1; border: none; border-radius: 0; background: none; border-bottom: 3px solid transparent; font-weight: 600;
    color: var(--muted);
  }
  .mobile-tabs button[aria-selected="true"] { color: var(--accent); border-bottom-color: var(--accent); }
  .review[data-mobile-tab="assertions"] .viewer-pane { display: none; }
  .review[data-mobile-tab="chart"] .assertions-pane { display: none; }
  .viewer-pane { height: calc(100dvh - 104px); min-height: 360px; }
  .pdf-scroll { min-height: 0; }
  .back-to-assertions {
    display: block; width: 100%; border: none; border-radius: 0; background: #3b3e41; color: #fff; text-align: left;
  }
  .pdf-toolbar { gap: 4px; padding: 4px 6px; }
  .pdf-toolbar button { padding: 4px 8px; min-width: 40px; }
  .label-long { display: none; }
  .label-short { display: inline; }
  .assertions-pane { padding: 10px 12px 20px; }
  .decide { flex-basis: 120px; }
}
.pdf-scroll { position: relative; }
.pdf-loading {
  position: sticky; top: 8px; left: 0; z-index: 2; width: max-content; margin: 8px auto -36px; padding: 6px 12px;
  background: rgba(28, 35, 48, .85); color: #fff; border-radius: 999px; font-size: .85rem; pointer-events: none;
}
.pdf-loading[hidden] { display: none; }

/* Coordinator pages */
.coord { display: flex; flex-direction: column; gap: 16px; max-width: 1280px; margin: 0 auto; }
.coord .card { width: 100%; max-width: none; }
.coord-nav { display: flex; gap: 4px; flex-wrap: wrap; }
.coord-nav a { padding: 8px 14px; border-radius: 6px; color: var(--accent); text-decoration: none; font-weight: 500; }
.coord-nav a[aria-current="page"] { background: var(--accent); color: var(--accent-text); }
.muted { color: var(--muted); font-size: .9rem; }
.figures { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 10px; margin-bottom: 10px; }
.figure { border: 1px solid var(--border); border-radius: 6px; padding: 10px 12px; display: flex; flex-direction: column; gap: 2px; }
.figure strong { font-size: 1.4rem; font-variant-numeric: tabular-nums; }
.approved { color: var(--approved); }
.rejected { color: var(--rejected); }
.commented { color: var(--commented); }
.table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
table.units, table.events { border-collapse: collapse; width: 100%; font-size: .9rem; }
table.units th, table.units td, table.events th, table.events td {
  text-align: left; padding: 8px; border-bottom: 1px solid var(--border); vertical-align: top; }
table.units th, table.events th { color: var(--muted); font-weight: 600; font-size: .8rem; white-space: nowrap; }
table.units td:first-child { min-width: 14ch; }
td.num { font-variant-numeric: tabular-nums; white-space: nowrap; }
td.date { white-space: nowrap; color: var(--muted); }
td.actions { white-space: nowrap; }
.inline-form { display: inline-flex; gap: 4px; margin: 0 4px 4px 0; }
.inline-form button, .inline-form select { min-height: 34px; padding: 4px 10px; }
select { font: inherit; padding: 8px; border: 1px solid var(--border); border-radius: 6px; background: var(--surface); color: var(--text); }
.state { display: inline-block; border-radius: 999px; padding: 2px 8px; font-size: .8rem; white-space: nowrap; background: #eceff3; }
.state-en-cours { background: #e7eef8; color: var(--accent); }
.state-terminée { background: #e9f5ec; color: var(--approved); }
.filters { display: flex; flex-wrap: wrap; gap: 12px; align-items: flex-end; margin-bottom: 12px; }
label.checkbox { flex-direction: row; align-items: center; gap: 6px; min-height: 40px; }
label.checkbox input { width: auto; }
.decision-list, .history { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 10px; }
.decision-item { border: 1px solid var(--border); border-radius: 6px; padding: 10px 12px; }
.decision-head { display: flex; flex-wrap: wrap; gap: 4px 12px; align-items: baseline; }
.decision-head a { color: var(--accent); }
.verdict { font-weight: 700; font-size: .85rem; }
.verdict.approved { color: var(--approved); }
.verdict.rejected { color: var(--rejected); }
.verdict.commented { color: var(--commented); }
.comment { margin: 6px 0 0; padding: 6px 10px; background: #f6f7f9; border-left: 3px solid var(--border); white-space: pre-wrap; overflow-wrap: anywhere; }
.history li { border-left: 3px solid var(--border); padding: 4px 0 4px 12px; }
.history li.current { border-left-color: var(--accent); }
.coord-title { display: flex; flex-wrap: wrap; justify-content: space-between; align-items: baseline; gap: 8px 16px; }
.exports { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; color: var(--muted); font-size: .9rem; }
.exports a.button { padding: 6px 12px; min-height: 0; }
.import-summary { margin: 0 0 16px; padding-left: 20px; display: flex; flex-direction: column; gap: 4px; }
.import-actions { display: flex; gap: 8px; align-items: center; margin-bottom: 16px; }
.import-actions form { margin: 0; }
.import-form { max-width: 560px; }
.error ul { margin: 6px 0 0; padding-left: 20px; }
.error p { margin: 0; }

/* Chart descriptions: Markdown blocks and the (not voted) context panel. */
.markdown { white-space: normal; }
.markdown h3 { font-size: .95rem; margin: 12px 0 4px; }
.markdown h3:first-child { margin-top: 0; }
.markdown p { margin: 6px 0; }
.markdown ul, .markdown ol { margin: 6px 0; padding-left: 20px; }
.markdown code { font-size: .9em; background: rgba(0, 0, 0, .06); padding: 0 3px; border-radius: 3px; }
.markdown table { border-collapse: collapse; margin: 8px 0; font-size: .85rem; display: block; overflow-x: auto; }
.markdown th, .markdown td { border: 1px solid #ccc; padding: 3px 6px; text-align: left; vertical-align: top; }
.markdown th { background: rgba(0, 0, 0, .04); }
.markdown a { color: inherit; }
.description-context { margin: 0 0 10px; padding: 6px 10px; border: 1px solid #d6d6d6; border-radius: 8px; background: #fafafa; }
.description-context summary { cursor: pointer; font-weight: 600; }
.description-context .markdown { font-size: .92rem; line-height: 1.45; }
.assertion-card .markdown h3[id] { scroll-margin-top: 8px; }
