/* P63 Climate Knowledge — shared styles.
   Constraints taken from the wireframe accessibility notes:
   - must work down to 320px width
   - no reliance on hover for anything functional
   - colour is never the only signal
   - tap targets on mobile no smaller than ~44px                              */

:root {
  --ink: #1c1c1a;
  --ink-soft: #5c5c56;
  --line: #d6d3cc;
  --line-strong: #b3aea4;
  --paper: #fbfaf7;
  --panel: #ffffff;
  --accent: #7a4b1e;
  --accent-soft: #f3e9df;
  --ok: #2f6d3f;
  --ok-soft: #e6f0e6;
  --warn: #8a5a00;
  --warn-soft: #fbf0d8;
  --bad: #8f2f2f;
  --bad-soft: #f7e6e4;
  --radius: 10px;
  --font-scale: 1;
  --base: calc(16px * var(--font-scale));
}

* { box-sizing: border-box; }

/* The text-size control has to change the root, not the body.
   
   `rem` resolves against the root element, so with the scale applied to `body`
   every size written in rem — which is most of this stylesheet — carried on
   using the browser's 16px and ignored the setting entirely. The result was a
   control where some text grew and some did not, which is worse than one that
   does nothing: it looks broken rather than absent, and the people it exists
   for are the ones least likely to shrug it off. */
html {
  -webkit-text-size-adjust: 100%;
  font-size: var(--base);
}

body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font: 1rem/1.55 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto,
    "Helvetica Neue", Arial, sans-serif;
}

h1, h2, h3 { line-height: 1.25; margin: 0 0 .4em; font-weight: 650; }
h1 { font-size: 1.5rem; }
h2 { font-size: 1.2rem; }
h3 { font-size: 1rem; }
p  { margin: 0 0 .8em; }

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

.muted { color: var(--ink-soft); }
.small { font-size: .875rem; }
.tiny  { font-size: .8rem; }
.mono  { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; }
.nowrap { white-space: nowrap; }
.hidden { display: none !important; }
.spacer { flex: 1; }

/* --- controls ------------------------------------------------------------ */

button, .btn {
  font: inherit;
  min-height: 44px;
  padding: 10px 16px;
  border: 1px solid var(--line-strong);
  border-radius: var(--radius);
  background: var(--panel);
  color: var(--ink);
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  text-decoration: none;
}
button:hover, .btn:hover { border-color: var(--ink-soft); }
button:focus-visible, a:focus-visible, input:focus-visible, select:focus-visible,
textarea:focus-visible {
  outline: 3px solid var(--accent);
  outline-offset: 2px;
}
button:disabled { opacity: .5; cursor: not-allowed; }

.btn-primary {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
  font-weight: 600;
}
.btn-primary:hover { background: #683f19; }
.btn-approve { background: var(--ok-soft); border-color: var(--ok); color: var(--ok); font-weight: 600; }
.btn-reject  { background: var(--bad-soft); border-color: var(--bad); color: var(--bad); font-weight: 600; }
.btn-sm { min-height: 36px; padding: 6px 12px; font-size: .875rem; }
.btn-block { width: 100%; }

label { display: block; font-size: .8rem; letter-spacing: .04em;
        text-transform: uppercase; color: var(--ink-soft); margin-bottom: 6px; }

input[type=text], input[type=password], input[type=search], select, textarea {
  font: inherit;
  width: 100%;
  min-height: 44px;
  padding: 10px 12px;
  border: 1px solid var(--line-strong);
  border-radius: var(--radius);
  background: var(--panel);
  color: var(--ink);
}
textarea { min-height: 90px; resize: vertical; }

.field { margin-bottom: 16px; }

/* --- feedback ------------------------------------------------------------ */

.notice {
  border: 1px solid var(--line-strong);
  border-left-width: 4px;
  border-radius: var(--radius);
  padding: 12px 14px;
  margin-bottom: 16px;
  background: var(--panel);
}
.notice-error { border-color: var(--bad); background: var(--bad-soft); }
.notice-ok    { border-color: var(--ok);  background: var(--ok-soft); }
.notice-warn  { border-color: var(--warn); background: var(--warn-soft); }

.pill {
  display: inline-block;
  padding: 2px 9px;
  border-radius: 999px;
  border: 1px solid var(--line-strong);
  font-size: .78rem;
  background: var(--panel);
}
.pill-ok   { border-color: var(--ok);   background: var(--ok-soft);   color: var(--ok); }
.pill-warn { border-color: var(--warn); background: var(--warn-soft); color: var(--warn); }
.pill-bad  { border-color: var(--bad);  background: var(--bad-soft);  color: var(--bad); }

.empty {
  border: 1px dashed var(--line-strong);
  border-radius: var(--radius);
  padding: 32px 20px;
  text-align: center;
  color: var(--ink-soft);
  background: var(--panel);
}

/* --- admin shell (D3-D7) ------------------------------------------------- */

.shell { display: flex; min-height: 100vh; }

.sidebar {
  width: 250px;
  flex: none;
  background: var(--panel);
  border-right: 1px solid var(--line);
  padding: 20px 14px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.brand { font-weight: 700; padding: 0 8px 4px; }
.brand small { display: block; font-weight: 400; color: var(--ink-soft); font-size: .78rem; }

.navitem {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 11px 10px;
  border-radius: var(--radius);
  color: var(--ink);
  text-decoration: none;
  min-height: 44px;
}
.navitem:hover { background: var(--paper); }
.navitem[aria-current="page"] {
  background: var(--accent-soft);
  font-weight: 650;
  box-shadow: inset 3px 0 0 var(--accent);
}
.navitem .count {
  margin-left: auto;
  font-size: .78rem;
  background: var(--accent);
  color: #fff;
  border-radius: 999px;
  padding: 1px 8px;
}
.navitem .count.zero { background: var(--line-strong); color: var(--ink); }
.nav-sep { border-top: 1px solid var(--line); margin: 10px 4px; }

.main { flex: 1; min-width: 0; padding: 26px 30px 60px; }
.main-head { display: flex; align-items: flex-start; gap: 16px; flex-wrap: wrap; margin-bottom: 20px; }
.main-head h1 { margin: 0; }

.panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 20px;
  margin-bottom: 20px;
}

.toolbar { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; margin-bottom: 16px; }
.toolbar > * { flex: 0 0 auto; }
.toolbar .grow { flex: 1 1 200px; }

/* --- tables -------------------------------------------------------------- */

table.data { width: 100%; border-collapse: collapse; font-size: .92rem; }
table.data th, table.data td {
  text-align: left;
  padding: 11px 12px;
  border-bottom: 1px solid var(--line);
  vertical-align: top;
}
table.data th {
  font-size: .74rem;
  text-transform: uppercase;
  letter-spacing: .05em;
  color: var(--ink-soft);
  border-bottom: 1px solid var(--line-strong);
}
table.data tr:last-child td { border-bottom: none; }
.table-wrap { overflow-x: auto; }

/* Below this a table stops being a table.

   The fallback was overflow-x, which technically works and is miserable in
   practice: reading one row means swiping sideways and losing the column you
   started from. Each row becomes a card instead, with the column name beside
   each value — admin.js copies the headings onto the cells so nothing has to
   be repeated in the markup.

   Applied at 720px rather than 480px because these tables carry five and six
   columns; they are already cramped on a small tablet. */
@media (max-width: 720px) {
  .table-wrap { overflow-x: visible; }
  table.data thead { position: absolute; width: 1px; height: 1px;
                     overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
  table.data, table.data tbody, table.data tr, table.data td { display: block; width: 100%; }
  table.data tr {
    border: 1px solid var(--line-strong); border-radius: var(--radius);
    padding: 6px 12px; margin-bottom: 12px; background: var(--panel);
  }
  table.data tr:last-child { margin-bottom: 0; }
  table.data td {
    border-bottom: 1px solid var(--line); padding: 9px 0;
    display: flex; gap: 12px; align-items: baseline;
  }
  table.data tr td:last-child { border-bottom: none; }
  table.data td[data-label]::before {
    content: attr(data-label);
    flex: 0 0 38%; min-width: 0;
    font-size: .72rem; text-transform: uppercase; letter-spacing: .05em;
    color: var(--ink-soft);
  }
  /* A cell holding only buttons reads better full width with the label gone:
     the actions are obvious and the word "Actions" earns nothing. */
  table.data td:empty { display: none; }
}

/* --- side-by-side review (D4, D6) ---------------------------------------- */

.compare { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.compare > div {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 14px;
  background: var(--paper);
}
.compare h4 {
  margin: 0 0 8px;
  font-size: .74rem;
  text-transform: uppercase;
  letter-spacing: .05em;
  color: var(--ink-soft);
}
.compare .raw { max-height: 260px; overflow: auto; white-space: pre-wrap;
                font-size: .86rem; color: var(--ink-soft); }
@media (max-width: 860px) { .compare { grid-template-columns: 1fr; } }

.entry-card { border: 1px solid var(--line); border-radius: var(--radius);
              padding: 18px; margin-bottom: 16px; background: var(--panel); }
.entry-card.is-selected { border-color: var(--accent); box-shadow: 0 0 0 2px var(--accent-soft); }
.entry-head { display: flex; gap: 12px; align-items: flex-start; flex-wrap: wrap; margin-bottom: 12px; }
.entry-head h3 { margin: 0; flex: 1 1 260px; }
.entry-actions { display: flex; gap: 8px; flex-wrap: wrap; }

/* Approve, Reject and Save edit side by side do not fit a phone, and this is
   the screen an admin spends the most time in. Full width and stacked, with
   room to hit them: rejecting knowledge because the buttons were 4px apart is
   not a mistake worth allowing. */
@media (max-width: 560px) {
  .entry-actions { width: 100%; }
  .entry-actions button { flex: 1 1 100%; min-height: 44px; }
}

/* --- progress ------------------------------------------------------------ */

.progress { height: 10px; border: 1px solid var(--line-strong); border-radius: 999px;
            background: var(--paper); overflow: hidden; }
.progress > span { display: block; height: 100%; background: var(--accent); width: 0; transition: width .3s; }

/* --- dropzone (D3) ------------------------------------------------------- */

.dropzone {
  border: 2px dashed var(--line-strong);
  border-radius: var(--radius);
  padding: 34px 20px;
  text-align: center;
  background: var(--paper);
  cursor: pointer;
}
.dropzone.is-over { border-color: var(--accent); background: var(--accent-soft); }
.radio-row { display: flex; gap: 10px; flex-wrap: wrap; }
.radio-row label {
  flex: 1 1 200px;
  display: flex; align-items: center; gap: 10px;
  border: 1px solid var(--line-strong);
  border-radius: var(--radius);
  padding: 12px 14px;
  text-transform: none; letter-spacing: 0; font-size: 1rem;
  color: var(--ink); margin: 0; cursor: pointer; min-height: 44px;
}
.radio-row label:has(input:checked) { border-color: var(--accent); background: var(--accent-soft); }
.radio-row input { width: auto; min-height: 0; }

/* --- topbar (chat) ------------------------------------------------------- */

.topbar {
  display: flex; align-items: center; gap: 12px;
  padding: 10px 16px;
  background: var(--panel);
  border-bottom: 1px solid var(--line);
  position: sticky; top: 0; z-index: 20;
}
.topbar .title { font-weight: 650; }

/* On a 375px phone this row carries a title, two language buttons, three text
   sizes, a username, Change password and Sign out, and on an admin account an
   Admin link as well. That does not fit, and with no wrapping the title was
   crushed to a couple of characters.

   Wrapping onto a second line is the honest answer: everything stays, nothing
   is squeezed, and the bar grows by one row. The controls that are only
   occasionally wanted give up their labels first. */
@media (max-width: 720px) {
  .topbar { flex-wrap: wrap; gap: 8px 10px; padding: 8px 12px; }
  .topbar .title { font-size: .95rem; width: 100%; order: -1; }
  .topbar .spacer { display: none; }
  .topbar .pill { font-size: .78rem; }
}

/* Narrower still, and the least-used label becomes an icon. Sign out keeps its
   word: it is the one with a consequence, and a door icon alone leaves somebody
   guessing. The username stays too — this may be a shared device, and who you
   are signed in as is not a detail to drop for space. */
@media (max-width: 420px) {
  #change-password { font-size: 0; padding: 6px 10px; }
  #change-password::before { content: "🔑"; font-size: .95rem; }
}
.langtoggle { display: inline-flex; border: 1px solid var(--line-strong); border-radius: 999px; overflow: hidden; }
.langtoggle button { min-height: 36px; border: none; border-radius: 0; padding: 6px 14px; background: var(--panel); }
.langtoggle button[aria-pressed="true"] { background: var(--accent); color: #fff; font-weight: 600; }

/* --- modal / sheet ------------------------------------------------------- */

.backdrop {
  position: fixed; inset: 0; background: rgba(28, 28, 26, .45);
  display: flex; align-items: center; justify-content: center; padding: 16px; z-index: 60;
}
.modal {
  background: var(--panel); border-radius: var(--radius); border: 1px solid var(--line);
  width: min(640px, 100%); max-height: 88vh; overflow: auto; padding: 22px;
}
.modal-wide { width: min(900px, 100%); }
@media (max-width: 640px) {
  .backdrop { align-items: flex-end; padding: 0; }
  .modal { width: 100%; border-radius: var(--radius) var(--radius) 0 0; max-height: 92vh; }
}

.choice-list { display: flex; flex-direction: column; gap: 10px; margin-bottom: 16px; }
.choice-list button { justify-content: flex-start; text-align: left; min-height: 52px; }
.choice-list button[aria-pressed="true"] { border-color: var(--accent); background: var(--accent-soft); font-weight: 600; }

.toast {
  position: fixed; left: 50%; bottom: 22px; transform: translateX(-50%);
  background: var(--ink); color: #fff; padding: 12px 18px; border-radius: var(--radius);
  z-index: 90; max-width: 90vw; box-shadow: 0 6px 24px rgba(0,0,0,.25);
}
.toast.err { background: var(--bad); }

/* --- responsive ---------------------------------------------------------- */

/* --- drawer (shared by the chat rail and the admin sidebar) --------------- */

.drawer-scrim { position: fixed; inset: 0; background: rgba(28,28,26,.45); z-index: 65; }
.drawer-toggle, .admin-bar { display: none; }

@media (max-width: 900px) {
  .toolbar { flex-wrap: wrap; }
  .toolbar > select, .toolbar > input { flex: 1 1 100%; max-width: none; }
  .shell { flex-direction: column; }

  /* The sidebar used to become a strip that scrolled sideways. Seven
     destinations, about one and a half visible on a phone, and nothing to
     suggest the rest were there. It slides in now, the same way the chat rail
     does, and the bar above says which screen you are on. */
  .admin-bar {
    display: flex; align-items: center; gap: 12px;
    padding: 10px 14px; background: var(--panel);
    border-bottom: 1px solid var(--line);
    position: sticky; top: 0; z-index: 20;
  }
  .admin-bar-title { font-weight: 650; }
  .drawer-toggle { display: inline-flex; }

  .sidebar {
    position: fixed; inset: 0 auto 0 0; width: min(280px, 84vw);
    z-index: 70; transform: translateX(-100%);
    transition: transform .18s ease-out;
    box-shadow: 4px 0 24px rgba(0,0,0,.18);
    border-right: 1px solid var(--line); overflow-y: auto;
  }
  .sidebar.is-open { transform: translateX(0); }
  .main { padding: 18px 16px 60px; }
}

@media (prefers-reduced-motion: reduce) {
  .sidebar, .chat-rail { transition: none; }
}
@media (max-width: 380px) {
  .main { padding: 14px 12px 60px; }
  .panel { padding: 14px; }
}

/* A rating the reader has given. Marked by weight and a border rather than
   colour alone, so it still reads on a phone in sunlight and to anyone who
   cannot distinguish the two. */
.msg-tools .is-chosen {
  background: var(--accent-soft);
  border-color: var(--accent);
  font-weight: 600;
}
