:root {
  --bg: #f6f7f9; --surface: #ffffff; --text: #1b1f27; --muted: #5d6675; --line: #dde1e8;
  --accent: #1d4ed8; --accent-text: #ffffff; --danger: #b42318; --ok: #1a7f37; --warn: #9a6700;
  --b-draft: #e8eaee; --b-review: #fff1c2; --b-approved: #d5f2dc; --b-obsolete: #ececec;
  --b-conf: #fde0dd; --b-pais: #e3ecff; --b-part: #d5f2dc;
  --radius: 8px; --shadow: 0 1px 2px rgba(0,0,0,.06);
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #12151b; --surface: #1b2029; --text: #e6e9ef; --muted: #9aa3b2; --line: #2d3442;
    --accent: #6b95ff; --accent-text: #0b1020; --danger: #ff8a80; --ok: #6fdc8c; --warn: #f0c050;
    --b-draft: #2a303c; --b-review: #4a3d12; --b-approved: #17402a; --b-obsolete: #2a2a2a;
    --b-conf: #4d2320; --b-pais: #1f3160; --b-part: #17402a;
  }
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html { font-size: 16px; }
body { margin: 0; background: var(--bg); color: var(--text); font: 15px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
.boot { padding: 2rem 16px; color: var(--muted); }

header.top { background: var(--surface); border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 5; }
header.top .in { max-width: 1200px; margin: 0 auto; padding: 0 16px; display: flex; align-items: center; gap: 1rem; flex-wrap: wrap; min-height: 52px; }
.brand { font-weight: 700; letter-spacing: .2px; }
nav.main { display: flex; gap: .25rem; flex: 1; flex-wrap: wrap; }
nav.main a { padding: .45rem .75rem; border-radius: 6px; color: var(--text); }
nav.main a:hover { background: var(--bg); text-decoration: none; }
nav.main a.on { background: var(--bg); font-weight: 600; box-shadow: inset 0 -2px 0 var(--accent); border-radius: 6px 6px 0 0; }
.who { color: var(--muted); font-size: 13px; display: flex; gap: .6rem; align-items: center; }
main { max-width: 1200px; margin: 0 auto; padding: 20px 16px 60px; }
h1 { font-size: 1.35rem; margin: 0 0 .25rem; }
h2 { font-size: 1.05rem; margin: 1.4rem 0 .5rem; }
.sub { color: var(--muted); margin: 0 0 1rem; }
.bar { display: flex; gap: .6rem; flex-wrap: wrap; align-items: end; margin: .75rem 0 1rem; }
.bar .grow { flex: 1; }
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); padding: 16px; margin-bottom: 14px; }

label.f { display: flex; flex-direction: column; gap: 3px; font-size: 12.5px; color: var(--muted); }
input, select, textarea { font: inherit; color: var(--text); background: var(--surface); border: 1px solid var(--line); border-radius: 6px; padding: .45rem .55rem; min-width: 0; }
textarea { width: 100%; min-height: 8rem; resize: vertical; }
input:focus, select:focus, textarea:focus, button:focus-visible, a:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
input[type=checkbox] { width: 1.1rem; height: 1.1rem; padding: 0; }
.chk { display: flex; align-items: center; gap: .4rem; font-size: 14px; color: var(--text); }

button, .btn { font: inherit; cursor: pointer; border: 1px solid var(--line); background: var(--surface); color: var(--text); border-radius: 6px; padding: .45rem .85rem; display: inline-block; }
button:hover:not(:disabled), .btn:hover { border-color: var(--accent); text-decoration: none; }
button:disabled { opacity: .5; cursor: not-allowed; }
button.primary { background: var(--accent); color: var(--accent-text); border-color: var(--accent); font-weight: 600; }
button.danger { color: var(--danger); border-color: var(--danger); }
button.link { border: 0; background: none; color: var(--accent); padding: 0; }

table { width: 100%; border-collapse: collapse; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; }
th, td { text-align: left; padding: .55rem .7rem; border-bottom: 1px solid var(--line); vertical-align: top; }
th { font-size: 12px; text-transform: uppercase; letter-spacing: .4px; color: var(--muted); background: var(--bg); white-space: nowrap; }
tr:last-child td { border-bottom: 0; }
tbody tr:hover { background: color-mix(in srgb, var(--accent) 5%, transparent); }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
td.path { word-break: break-all; font-size: 13px; max-width: 420px; }
.scroll { overflow-x: auto; }
.empty { padding: 2rem; text-align: center; color: var(--muted); background: var(--surface); border: 1px dashed var(--line); border-radius: var(--radius); }

.badge { display: inline-block; font-size: 12px; font-weight: 600; padding: 1px 8px; border-radius: 999px; background: var(--b-draft); white-space: nowrap; }
.s-draft { background: var(--b-draft); } .s-review { background: var(--b-review); } .s-approved { background: var(--b-approved); } .s-obsolete { background: var(--b-obsolete); }
.z-confidencial { background: var(--b-conf); } .z-so_pais { background: var(--b-pais); } .z-partilhavel { background: var(--b-part); }
.z-none { background: var(--b-draft); color: var(--muted); }

dl.meta { display: grid; grid-template-columns: max-content 1fr; gap: 4px 16px; margin: 0; }
dl.meta dt { color: var(--muted); } dl.meta dd { margin: 0; }
.body-text { white-space: pre-wrap; word-break: break-word; background: var(--bg); border: 1px solid var(--line); border-radius: 6px; padding: 12px; font: 14px/1.55 ui-monospace, Consolas, monospace; max-height: 560px; overflow: auto; }
.actions { display: flex; gap: .5rem; flex-wrap: wrap; align-items: center; }
.note { font-size: 13px; color: var(--muted); }
.timeline { list-style: none; margin: 0; padding: 0 0 0 14px; border-left: 2px solid var(--line); }
.timeline > li { position: relative; padding: 0 0 16px 14px; }
.timeline > li::before { content: ""; position: absolute; left: -22px; top: 6px; width: 10px; height: 10px; border-radius: 50%; background: var(--accent); border: 2px solid var(--bg); }
.timeline .ev { font-weight: 600; }
.timeline .when { color: var(--muted); font-size: 13px; }
.timeline details { margin-top: 6px; }
.timeline summary { cursor: pointer; color: var(--accent); font-size: 13px; }
.diff { font: 13px/1.5 ui-monospace, Consolas, monospace; background: var(--bg); border: 1px solid var(--line); border-radius: 6px; margin: 6px 0; max-height: 360px; overflow: auto; }
.diff div { white-space: pre-wrap; word-break: break-word; padding: 0 8px; }
.diff .add { background: var(--b-approved); }
.diff .del { background: var(--b-conf); }
.diff .skip { color: var(--muted); text-align: center; }
.chg { margin: 4px 0; font-size: 13.5px; }
.chg .old { text-decoration: line-through; color: var(--muted); }
fieldset.card { margin: 0 0 14px; }
fieldset.card legend { font-weight: 600; padding: 0 6px; }
label.check { display: block; padding: 4px 0; cursor: pointer; }
.countries { display: flex; flex-wrap: wrap; gap: 4px 18px; margin: 2px 0 6px 22px; }
ul.access { list-style: none; margin: 0; padding: 0; }
ul.access li { padding: 3px 0; }
ul.access li.no { color: var(--muted); }
.warn { background: var(--b-review); border-radius: 6px; padding: 8px 12px; margin: .5rem 0; }
.err { color: var(--danger); } .ok { color: var(--ok); }
.grid2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 12px; }
.pager { display: flex; gap: .5rem; align-items: center; margin-top: .8rem; color: var(--muted); }
.crumbs { font-size: 13px; margin-bottom: .6rem; }

#toasts { position: fixed; right: 16px; bottom: 16px; display: flex; flex-direction: column; gap: 8px; z-index: 20; max-width: min(420px, calc(100vw - 32px)); }
.toast { background: var(--text); color: var(--bg); padding: 10px 14px; border-radius: 6px; box-shadow: 0 4px 14px rgba(0,0,0,.25); }
.toast.bad { background: var(--danger); color: #fff; }
dialog { border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface); color: var(--text); max-width: min(560px, calc(100vw - 32px)); padding: 18px; }
dialog::backdrop { background: rgba(0,0,0,.45); }

.login { max-width: 420px; margin: 12vh auto; text-align: center; }
.login .langs { margin: 1.25rem 0 0; display: flex; gap: 1rem; justify-content: center; }
.login .langs button.on { color: var(--text, inherit); font-weight: 600; text-decoration: none; cursor: default; }
@media (max-width: 640px) {
  dl.meta { grid-template-columns: 1fr; } dl.meta dt { margin-top: .4rem; }
  th, td { padding: .45rem .5rem; }
}

/* chat */
.thread { display: flex; flex-direction: column; gap: 12px; margin-bottom: 14px; }
.msg { border: 1px solid var(--line); border-radius: var(--radius); padding: 12px 14px; background: var(--surface); max-width: 920px; }
.msg.user { align-self: flex-end; background: color-mix(in srgb, var(--accent) 10%, var(--surface)); white-space: pre-wrap; word-break: break-word; }
.msg.bot { align-self: flex-start; width: 100%; }
.who-label { font-size: 12px; color: var(--muted); margin-bottom: 2px; }
.answer { white-space: pre-wrap; word-break: break-word; }
.msg h2 { margin-top: 1rem; }
.src { border-top: 1px solid var(--line); padding: 8px 0; }
.src.flash { background: var(--b-review); }
.src .excerpt { margin: 4px 0 0; color: var(--muted); font-size: 13.5px; white-space: pre-wrap; word-break: break-word; }
.warns { margin: 4px 0 0; padding-left: 1.2rem; color: var(--warn); font-size: 13.5px; }
.cite { font-size: inherit; vertical-align: baseline; }
.chatbar { position: sticky; bottom: 0; background: var(--bg); padding: 10px 0 4px; border-top: 1px solid var(--line); }
.chatbar .actions { margin-top: 8px; align-items: end; }
