/* Drawing Review portal - plain, readable styling.
   Every colour is a custom property in :root below and nowhere else: no
   other rule in this file may contain a colour literal. The test
   tests/portal/test_routing.py reads the :root values from this file and
   measures each text/background pair against WCAG AA (4.5:1 for text,
   3:1 for borders and focus rings), so the pairs it checks are the pairs
   the page uses. Light mode only. No fonts, images or URLs are loaded. */

:root {
  --bg: #ffffff;
  --text: #1a2027;
  --muted: #48525c;
  --card-bg: #f4f6f8;
  --border: #c7ced5;
  --input-border: #66727d;
  --accent: #0a4fb0;
  --accent-text: #ffffff;
  --focus: #0a4fb0;
  --ok-bg: #e3f3e6;
  --ok-text: #1c6b31;
  --warn-bg: #fdf0dc;
  --warn-text: #8a4b00;
  --corrected-bg: #e4ecfb;
  --corrected-text: #1a3f8f;
  --danger-bg: #fbe9e7;
  --danger-text: #a3241d;

  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial,
          sans-serif;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 16px;
  line-height: 1.5;
}

a { color: var(--accent); }

/* -- keyboard focus: one clear ring on everything that can take focus -- */
a:focus-visible,
button:focus-visible,
input:focus-visible,
select:focus-visible,
textarea:focus-visible,
summary:focus-visible,
[tabindex]:focus-visible {
  outline: 3px solid var(--focus);
  outline-offset: 2px;
}
/* The main landmark takes focus from the skip link; no ring needed there. */
main:focus { outline: none; }

/* -- skip link: off screen until it has focus -- */
.skip-link {
  position: absolute;
  left: 8px;
  top: -100px;
  background: var(--bg);
  color: var(--accent);
  border: 2px solid var(--accent);
  border-radius: 6px;
  padding: 8px 14px;
  z-index: 10;
}
.skip-link:focus { top: 8px; }

/* -- page shell -- */
.site-header {
  background: var(--card-bg);
  border-bottom: 1px solid var(--border);
  padding: 12px 16px;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 8px 16px;
}
.brand {
  font-weight: 600;
  text-decoration: none;
  color: var(--text);
  font-size: 1.05rem;
}
.header-user {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px 12px;
  color: var(--text);
  font-size: 0.95rem;
}
.header-user form { margin: 0; }
.page {
  max-width: 1200px;
  margin: 0 auto;
  padding: 16px;
}
.narrow { max-width: 34rem; }

h1 { font-size: 1.5rem; margin: 0 0 8px; }
h2 { font-size: 1.2rem; margin: 16px 0 8px; }
h3 { font-size: 1rem; margin: 0 0 8px; }
.lede, .crumb { color: var(--muted); }
.crumb { font-size: 0.9rem; }
.meta, .meta-inline { color: var(--muted); font-size: 0.85rem; }
.muted { color: var(--muted); }

.card {
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 16px;
  margin: 12px 0;
}

/* -- forms -- */
label { display: block; font-weight: 600; margin: 12px 0 4px; }
input[type="text"], input[type="password"], input[type="search"],
input[type="email"], select, textarea {
  font-family: inherit;
  font-size: 1rem;
  color: var(--text);
  background: var(--bg);
  border: 1px solid var(--input-border);
  border-radius: 4px;
  padding: 8px 10px;
  width: 100%;
  max-width: 24rem;
}
.hint { color: var(--muted); font-size: 0.9rem; margin: 4px 0 0; }

/* -- buttons -- */
button, .btn, .btn-small {
  font-family: inherit;
  font-size: 0.95rem;
  border: 1px solid var(--accent);
  background: var(--accent);
  color: var(--accent-text);
  border-radius: 6px;
  padding: 8px 14px;
  cursor: pointer;
  text-decoration: none;
  display: inline-block;
}
button:hover:not(:disabled), .btn:hover { opacity: 0.9; }
button:disabled {
  background: var(--card-bg);
  color: var(--muted);
  border-color: var(--border);
  cursor: not-allowed;
}
.btn-secondary {
  background: var(--bg);
  color: var(--accent);
}
.btn-small { padding: 5px 10px; font-size: 0.85rem; }
.inline-form { display: inline-block; margin: 4px 8px 4px 0; }
.correct-form { display: inline-flex; gap: 6px; align-items: center; }
input.correct-input {
  font-family: inherit;
  font-size: 0.85rem;
  border: 1px solid var(--input-border);
  border-radius: 4px;
  padding: 4px 6px;
  width: 9rem;
  max-width: 100%;
  min-width: 0;
}

/* -- messages -- */
.alert {
  border: 1px solid var(--warn-text);
  background: var(--warn-bg);
  color: var(--warn-text);
  border-radius: 6px;
  padding: 10px 14px;
  margin: 12px 0;
  font-weight: 600;
}
.alert-error {
  border-color: var(--danger-text);
  background: var(--danger-bg);
  color: var(--danger-text);
}
.alert-ok {
  border-color: var(--ok-text);
  background: var(--ok-bg);
  color: var(--ok-text);
}
.error-banner {
  background: var(--warn-bg);
  color: var(--warn-text);
  border: 1px solid var(--warn-text);
  border-radius: 6px;
  padding: 10px 14px;
  margin: 12px 0;
  font-weight: 600;
}
.inline-error {
  color: var(--danger-text);
  font-size: 0.85rem;
  margin: 4px 0 0;
}

/* -- status / badges -- */
.status, .badge {
  display: inline-block;
  font-size: 0.8rem;
  font-weight: 600;
  border-radius: 999px;
  padding: 3px 10px;
}
.status-not_started { background: var(--card-bg); color: var(--muted); border: 1px solid var(--border); }
.status-in_review { background: var(--warn-bg); color: var(--warn-text); }
.status-approved { background: var(--corrected-bg); color: var(--corrected-text); }
.status-released { background: var(--ok-bg); color: var(--ok-text); }
.badge-ok { background: var(--ok-bg); color: var(--ok-text); }
.badge-warn { background: var(--warn-bg); color: var(--warn-text); }
.badge-corrected { background: var(--corrected-bg); color: var(--corrected-text); }
.badge-error { background: var(--danger-bg); color: var(--danger-text); }
.conf { color: var(--muted); font-size: 0.8rem; margin-left: 4px; }

/* -- progress bars (a real progress element with a text label) -- */
progress {
  width: 100%;
  max-width: 24rem;
  height: 1rem;
  accent-color: var(--accent);
}

/* -- tables -- */
table.data-table, table.drawing-list, table.field-table {
  width: 100%;
  border-collapse: collapse;
}
table.data-table th, table.data-table td,
table.drawing-list th, table.drawing-list td {
  text-align: left;
  padding: 10px 8px;
  border-bottom: 1px solid var(--border);
}
table.field-table th, table.field-table td {
  text-align: left;
  padding: 8px 6px;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}
table.field-table th { font-size: 0.8rem; color: var(--muted); font-weight: 600; }
caption { text-align: left; font-weight: 600; padding: 4px 0 8px; }
/* A long name with no spaces (such as a batch name) wraps inside its cell instead of widening the page. */
table.data-table td a { overflow-wrap: anywhere; min-width: 0; }
.flag-row { background: var(--card-bg); }
.actions { white-space: nowrap; }
/* The overview Actions cell holds several buttons and a note, so it may wrap at any width. */
table.data-table td.actions { white-space: normal; }

/* -- review screen (phase 1 look, kept) -- */
.review-head { display: flex; align-items: center; gap: 12px; }
.review-summary {
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 12px 16px;
  margin: 12px 0 20px;
}
.feeder-row {
  border: 1px solid var(--border);
  border-radius: 8px;
  margin-bottom: 20px;
  padding: 14px;
  background: var(--bg);
}
.feeder-row-inner {
  display: grid;
  grid-template-columns: 320px 1fr;
  gap: 16px;
  align-items: start;
}
.feeder-row-inner > * { min-width: 0; }
/* Error text in the nowrap Action cell wraps in a narrow block so it cannot widen the page. */
td.actions .inline-error { white-space: normal; max-width: 16rem; }
.feeder-crop { position: sticky; top: 12px; }
.crop-img {
  max-width: 100%;
  border: 1px solid var(--border);
  border-radius: 4px;
  background: var(--card-bg);
}
.crop-thumb {
  max-width: 160px;
  max-height: 60px;
  border: 1px solid var(--border);
  border-radius: 4px;
  background: var(--card-bg);
}
.why { font-size: 0.85rem; margin-top: 8px; }
.why summary { cursor: pointer; color: var(--accent); }
.why ul { margin: 6px 0 0; padding-left: 18px; color: var(--muted); }

/* Text for screen readers only (live-region announcements, hidden labels). */
.sr-only {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0;
}

/* -- responsive: works down to 390px width -- */
@media (max-width: 900px) {
  .feeder-row-inner { grid-template-columns: 1fr; }
  .feeder-crop { position: static; }
  /* The review Action cell holds Confirm, a correction box and error text, so it wraps on tablets. */
  table.field-table td.actions { white-space: normal; }
  .correct-form { flex-wrap: wrap; }
}

@media (max-width: 640px) {
  .page { padding: 12px; }

  table.data-table thead, table.drawing-list thead, table.field-table thead {
    display: none;
  }
  table.data-table, table.data-table tbody, table.data-table tr, table.data-table td,
  table.drawing-list, table.drawing-list tbody, table.drawing-list tr, table.drawing-list td,
  table.field-table, table.field-table tbody, table.field-table tr, table.field-table td {
    display: block;
    width: 100%;
  }
  table.data-table tr, table.drawing-list tr, table.field-table tr {
    border: 1px solid var(--border);
    border-radius: 6px;
    margin-bottom: 10px;
    padding: 6px 10px;
  }
  table.data-table td, table.drawing-list td, table.field-table td {
    border-bottom: none;
    padding: 6px 0;
    display: flex;
    justify-content: space-between;
    gap: 10px;
    align-items: center;
  }
  table.field-table td.actions { flex-direction: column; align-items: stretch; }
  table.data-table td::before, table.drawing-list td::before, table.field-table td::before {
    content: attr(data-label);
    font-weight: 600;
    color: var(--muted);
    font-size: 0.8rem;
    flex: 0 0 auto;
  }
  input.correct-input { width: 100%; }
  .correct-form { flex-wrap: wrap; }
  /* Narrow screens: let actions and their error text wrap instead of widening the page. */
  .actions { white-space: normal; }
  table.data-table td.actions, table.drawing-list td.actions { flex-wrap: wrap; justify-content: flex-start; }
  table.data-table td, table.drawing-list td, table.field-table td { min-width: 0; }
  td.actions .inline-form, td.actions .inline-error { max-width: 100%; overflow-wrap: anywhere; }
}
