:root {
  --green: #0a7d3c;
  --green-dark: #086230;
  --green-soft: #e6f3eb;
  --ink: #1d2327;
  --muted: #667077;
  --line: #dfe3e6;
  --surface: #ffffff;
  --canvas: #f4f5f6;
  --red: #b3261e;
  --amber: #8a5a00;
  --amber-soft: #fff4d6;
}

* { box-sizing: border-box; }

/* Elements with display set in this file would otherwise ignore the hidden attribute. */
[hidden] { display: none !important; }

body {
  margin: 0;
  font: 14px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  color: var(--ink);
  background: var(--canvas);
}

a { color: var(--green-dark); }
code { font-size: 12px; }
h1, h2 { font-weight: 600; }
h2 { font-size: 15px; margin: 0 0 8px; }
.muted { color: var(--muted); }

/* --- top bar ------------------------------------------------------------------------ */
.topbar {
  display: flex;
  align-items: center;
  gap: 16px;
  height: 50px;
  padding: 0 16px;
  background: var(--surface);
  border-bottom: 1px solid var(--line);
}
.brand { display: inline-flex; align-items: center; gap: 8px; font-weight: 600; text-decoration: none; color: var(--ink); }
.brand-logo { display: block; height: 24px; width: auto; }
.project-menu { position: relative; }
.project-menu summary, .user-menu summary { cursor: pointer; list-style: none; padding: 6px 10px; border-radius: 4px; font-weight: 500; }
.project-menu summary::-webkit-details-marker, .user-menu summary::-webkit-details-marker { display: none; }
.project-menu summary:hover, .project-menu[open] summary, .user-menu summary:hover, .user-menu[open] summary { background: var(--canvas); }
.project-menu .menu { left: 0; right: auto; width: 340px; padding: 10px; }
.project-menu input[type="search"] { width: 100%; font: inherit; padding: 7px 9px; border: 1px solid #c4cace; border-radius: 4px; }
.menu-list { list-style: none; margin: 8px 0 0; padding: 0; max-height: 50vh; overflow-y: auto; }
.menu-list a { display: block; padding: 7px 9px; border-radius: 4px; color: var(--ink); text-decoration: none; overflow-wrap: anywhere; }
.menu-list a:hover, .menu-list a:focus { background: var(--canvas); }
.menu-list a[aria-current="true"] { background: var(--green-soft); color: var(--green-dark); font-weight: 600; }
.menu-foot { margin: 8px 0 0; padding: 8px 9px 0; border-top: 1px solid var(--line); }
.menu .empty { padding: 7px 9px; }
.user-menu { margin-left: auto; position: relative; }
.menu {
  position: absolute;
  right: 0;
  top: 100%;
  z-index: 10;
  min-width: 280px;
  padding: 12px 16px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 6px;
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.12);
}
.menu p { margin: 0 0 8px; }

/* --- frame: left rail and page -------------------------------------------------------- */
.frame { display: flex; min-height: calc(100vh - 50px); }
.rail {
  flex: 0 0 96px;
  display: flex;
  flex-direction: column;
  padding: 8px 0;
  background: var(--surface);
  border-right: 1px solid var(--line);
}
.rail a {
  padding: 12px 6px;
  font-size: 12px;
  text-align: center;
  text-decoration: none;
  color: var(--ink);
  border-left: 3px solid transparent;
}
.rail a:hover { background: var(--canvas); }
.rail a[aria-current="page"] { color: var(--green-dark); background: var(--green-soft); border-left-color: var(--green); font-weight: 600; }
.page { flex: 1; min-width: 0; }
.page-title { margin: 0; padding: 14px 24px; font-size: 20px; background: var(--surface); border-bottom: 1px solid var(--line); }
.page-body { padding: 20px 24px; }

/* --- panels, tables, forms ------------------------------------------------------------ */
.panel { background: var(--surface); border: 1px solid var(--line); border-radius: 6px; padding: 16px; margin-bottom: 16px; }
.empty { color: var(--muted); margin: 4px 0; }
table.list { width: 100%; border-collapse: collapse; }
table.list th { text-align: left; font-weight: 600; font-size: 12px; color: var(--muted); padding: 8px 10px; border-bottom: 1px solid var(--line); }
table.list td { padding: 10px; border-bottom: 1px solid var(--line); vertical-align: top; }
table.list tr:last-child td { border-bottom: 0; }
td.actions { text-align: right; white-space: nowrap; }

.button {
  display: inline-block;
  padding: 7px 14px;
  font: inherit;
  color: var(--ink);
  text-decoration: none;
  background: var(--surface);
  border: 1px solid #c4cace;
  border-radius: 4px;
  cursor: pointer;
}
.button:hover { background: var(--canvas); }
.button-primary { color: #fff; background: var(--green); border-color: var(--green); }
.button-primary:hover { background: var(--green-dark); }
.button-danger { color: #fff; background: var(--red); border-color: var(--red); }
select, input[type="text"] { font: inherit; padding: 6px 8px; border: 1px solid #c4cace; border-radius: 4px; background: var(--surface); max-width: 100%; }
.inline-form { display: flex; flex-wrap: wrap; align-items: center; gap: 10px; }
.form-actions { margin: 16px 0 0; }
.confirm { display: inline-block; text-align: left; }
.confirm summary { cursor: pointer; color: var(--muted); }
.confirm form { margin-top: 8px; max-width: 360px; white-space: normal; }

.notice { padding: 10px 14px; border-radius: 4px; margin: 0 0 16px; }
.notice-ok { background: var(--green-soft); color: var(--green-dark); }
.notice-error { background: #fdecea; color: var(--red); }

/* --- pages without the frame (login, errors) -------------------------------------------- */
body.bare { display: flex; justify-content: center; padding: 10vh 16px; }
.card { width: 100%; max-width: 440px; background: var(--surface); border: 1px solid var(--line); border-radius: 8px; padding: 28px; }
.card h1 { font-size: 20px; margin: 16px 0 12px; }
.card .brand { gap: 12px; }

@media (max-width: 700px) {
  .frame { flex-direction: column; }
  .rail { flex-direction: row; flex: none; border-right: 0; border-bottom: 1px solid var(--line); padding: 0; }
  .rail a { border-left: 0; border-bottom: 3px solid transparent; padding: 10px 14px; }
  .rail a[aria-current="page"] { border-bottom-color: var(--green); }
  .page-body { padding: 12px; }
  table.list { display: block; overflow-x: auto; }
}

/* --- document page: filter panel and tree ----------------------------------------------- */
.page-body:has(.documents) { padding: 0; }
.documents { display: flex; align-items: stretch; min-height: calc(100vh - 110px); }
.filters {
  flex: 0 0 250px;
  padding: 16px;
  background: var(--surface);
  border-right: 1px solid var(--line);
}
.filters fieldset { border: 0; border-top: 1px solid var(--line); margin: 14px 0 0; padding: 12px 0 0; }
.filters legend { padding: 0; font-weight: 600; font-size: 13px; }
.filters input[type="text"] { width: 100%; }
.filter-options { max-height: 220px; overflow-y: auto; }
.check { display: block; padding: 3px 0; font-size: 13px; }
.filter-actions { display: flex; align-items: center; gap: 12px; margin: 14px 0 0; }
.filters a[aria-current="page"] { font-weight: 600; }
.listing { flex: 1; min-width: 0; padding: 16px 24px; }
.listing-head { display: flex; justify-content: space-between; gap: 16px; margin-bottom: 10px; }
.section-title { margin-top: 24px; }

.tree { background: var(--surface); border: 1px solid var(--line); border-radius: 6px; }
.row {
  display: grid;
  grid-template-columns: 20px minmax(0, 1fr) 70px 100px 170px 120px 116px;
  gap: 12px;
  align-items: center;
  padding: 8px 12px;
  border-bottom: 1px solid var(--line);
}
.row-head { font-size: 12px; font-weight: 600; color: var(--muted); }
.row-folder { grid-template-columns: 20px minmax(0, 1fr) auto; cursor: pointer; list-style: none; background: #fafbfb; }
.row-folder::-webkit-details-marker { display: none; }
.row-folder:hover { background: var(--canvas); }
.folder-name { font-weight: 600; }
.folder-name::before {
  content: "";
  display: inline-block;
  width: 0;
  height: 0;
  margin-right: 8px;
  border-left: 6px solid var(--muted);
  border-top: 4px solid transparent;
  border-bottom: 4px solid transparent;
  transition: transform 0.1s;
}
.folder[open] > summary .folder-name::before { transform: rotate(90deg); }
.children { padding-left: 22px; }
.tree > .folder:last-child > summary, .children > :last-child { border-bottom: 0; }
.folder[open] > summary { border-bottom: 1px solid var(--line); }
.cell-name { min-width: 0; overflow-wrap: anywhere; }
.cell-rev, .cell-date, .cell-by { color: var(--muted); font-size: 13px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.counts { display: inline-flex; align-items: center; gap: 8px; font-size: 12px; }

.badge { display: inline-block; padding: 2px 8px; border-radius: 10px; font-size: 12px; white-space: nowrap; }
.badge-new { background: #e3effc; color: #0b4a8f; }
.badge-changed { background: var(--amber-soft); color: var(--amber); }
.badge-downloaded { background: var(--green-soft); color: var(--green-dark); }
.tag { display: inline-block; margin-left: 6px; padding: 1px 6px; border: 1px solid var(--line); border-radius: 3px; font-size: 11px; color: var(--muted); white-space: nowrap; }
.tag-warn { border-color: #e6c66a; background: var(--amber-soft); color: var(--amber); }
.notice-info { background: #e3effc; color: #0b4a8f; }
.visually-hidden { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }

@media (max-width: 900px) {
  .documents { flex-direction: column; }
  .filters { flex: none; border-right: 0; border-bottom: 1px solid var(--line); }
  .listing { padding: 12px; }
  .row { grid-template-columns: 20px minmax(0, 1fr) auto auto; }
  .row-folder { grid-template-columns: 20px minmax(0, 1fr); }
  .row-folder .counts { grid-column: 2; }
  .row-head, .cell-rev, .cell-date, .cell-by { display: none; }
}

.toolbar { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 10px; }
.button-small { padding: 3px 9px; font-size: 12px; }
.cell-check input { margin: 0; }
.cell-action { display: flex; align-items: center; justify-content: flex-end; gap: 4px; }
.row-file:hover { background: #fafbfb; }
.confirm-list { margin: 8px 0 16px; padding-left: 20px; }

/* --- front page: intro, project cards, add project ------------------------------------------ */
.small { font-size: 12px; }
.intro p { margin: 0 0 10px; max-width: 80ch; }
.intro p:last-child { margin-bottom: 0; }
.legend { list-style: none; margin: 0 0 10px; padding: 0; display: grid; gap: 6px; }
.legend .badge { margin-right: 6px; }
.panel-flush { padding: 0; overflow-x: auto; }
.project-name a { font-weight: 600; color: var(--ink); text-decoration: none; }
.project-name a:hover { color: var(--green-dark); text-decoration: underline; }
.num { text-align: right; }
.badge-missing { background: #f1f2f3; color: var(--muted); }
.add-project input[type="search"] { width: 100%; max-width: 480px; font: inherit; padding: 7px 9px; border: 1px solid #c4cace; border-radius: 4px; }
.pick-list { list-style: none; margin: 8px 0 0; padding: 4px 8px; max-width: 480px; max-height: 260px; overflow-y: auto; border: 1px solid var(--line); border-radius: 4px; }

/* --- filename builder --------------------------------------------------------------------- */
.builder { max-width: 980px; }
.blocks { display: flex; flex-wrap: wrap; align-items: stretch; gap: 6px; min-height: 44px; padding: 8px; border: 1px dashed #c4cace; border-radius: 6px; background: #fafbfb; }
.block { display: inline-flex; align-items: center; gap: 4px; padding: 4px 6px; border: 1px solid var(--line); border-radius: 4px; background: var(--surface); cursor: grab; }
.block-variable { border-color: #9fcfb2; background: var(--green-soft); color: var(--green-dark); font-weight: 600; }
.block.dragging { opacity: 0.4; }
.block.drop-before { box-shadow: -3px 0 0 var(--green); }
.block input { font: inherit; font-weight: 400; padding: 2px 4px; border: 1px solid #c4cace; border-radius: 3px; }
.block-text input { width: 6ch; text-align: center; font-family: ui-monospace, monospace; }
.block-sep { width: 4ch; text-align: center; font-family: ui-monospace, monospace; }
.block-sep-label { font-size: 11px; font-weight: 400; color: var(--muted); }
.block button { font: inherit; font-size: 12px; line-height: 1; padding: 2px 4px; border: 0; border-radius: 3px; background: transparent; color: var(--muted); cursor: pointer; }
.block button:hover { background: rgba(0, 0, 0, 0.08); color: var(--ink); }
.builder-add { display: flex; flex-wrap: wrap; gap: 8px; margin: 10px 0; }
.rule-field { display: flex; align-items: center; gap: 10px; margin: 10px 0; }
.rule-field span { font-size: 12px; color: var(--muted); }
.rule-field input { flex: 1; font-family: ui-monospace, monospace; font-size: 13px; }
.preview h3 { font-size: 13px; margin: 14px 0 6px; }
.preview ul { list-style: none; margin: 0; padding: 8px 12px; border: 1px solid var(--line); border-radius: 6px; font-family: ui-monospace, monospace; font-size: 13px; overflow-wrap: anywhere; }
.preview li { padding: 2px 0; }
.preview .tag { font-family: system-ui, sans-serif; }

/* --- log page ------------------------------------------------------------------------------- */
.tabs { display: flex; gap: 4px; margin-bottom: 16px; border-bottom: 1px solid var(--line); }
.tabs a { padding: 8px 14px; color: var(--ink); text-decoration: none; border-bottom: 3px solid transparent; margin-bottom: -1px; }
.tabs a:hover { background: var(--surface); }
.tabs a[aria-current="page"] { border-bottom-color: var(--green); color: var(--green-dark); font-weight: 600; }
.log-filter label { display: inline-flex; align-items: center; gap: 6px; }
.log-filter input[type="date"] { font: inherit; padding: 5px 8px; border: 1px solid #c4cace; border-radius: 4px; }
.log-list td { font-size: 13px; }
.nowrap { white-space: nowrap; }
.wrap { overflow-wrap: anywhere; }
.padded { padding: 16px; }


/* --- toggle switch, and the list of files missing labels ------------------------------------ */
.toggle { display: flex; align-items: center; gap: 8px; padding: 3px 0; font-size: 13px; cursor: pointer; }
.toggle input {
  appearance: none;
  position: relative;
  flex: none;
  width: 32px;
  height: 18px;
  margin: 0;
  border-radius: 9px;
  background: #c4cace;
  cursor: pointer;
  transition: background 0.15s;
}
.toggle input::after {
  content: "";
  position: absolute;
  top: 2px;
  left: 2px;
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: #fff;
  transition: transform 0.15s;
}
.toggle input:checked { background: var(--green); }
.toggle input:checked::after { transform: translateX(14px); }
.toggle input:focus-visible { outline: 2px solid var(--green-dark); outline-offset: 2px; }
.incomplete { margin-top: 24px; }
.incomplete .section-title { margin-top: 0; }

/* --- search and filter above a table --------------------------------------------------------- */
.table-filter { display: flex; flex-wrap: wrap; align-items: center; gap: 10px 16px; margin: 0 0 12px; }
.table-filter input[type="search"] { flex: 0 1 340px; font: inherit; padding: 7px 9px; border: 1px solid #c4cace; border-radius: 4px; }
.table-filter label { display: inline-flex; align-items: center; gap: 6px; }
.bulk-bar { display: flex; flex-wrap: wrap; align-items: center; gap: 10px 16px; margin: 0 0 12px; padding: 8px 12px; border: 1px solid var(--line); border-radius: 6px; background: #fafbfb; }
.bulk-bar label { display: inline-flex; align-items: center; gap: 6px; }
.bulk-bar [data-bulk-count] { font-weight: 600; min-width: 9ch; }
.button:disabled { opacity: 0.5; cursor: default; }
.cell-select { width: 32px; }
table.list tr.changed td { background: var(--amber-soft); }
.unsaved { margin-left: 12px; color: var(--amber); font-weight: 600; }

/* --- project list on the front page: rows laid out with grid --------------------------------- */
.project-list { padding: 0; }
.project-row {
  display: grid;
  /* Fixed tracks after the name, so every row (each its own grid) lines up with the header. */
  grid-template-columns: minmax(180px, 1fr) repeat(4, 104px) 104px 290px;
  gap: 12px;
  align-items: center;
  padding: 10px 16px;
  border-bottom: 1px solid var(--line);
}
.project-row:last-child { border-bottom: 0; }
.project-head { font-size: 12px; font-weight: 600; color: var(--muted); align-items: end; }
.project-head .badge { white-space: normal; text-align: center; }
.project-name { min-width: 0; overflow-wrap: anywhere; }
.project-row .num { font-variant-numeric: tabular-nums; }
.project-row .num:not([role="columnheader"]) { font-size: 15px; }
.project-row .num a { display: inline-block; min-width: 2ch; padding: 2px 6px; margin: -2px -6px; border-radius: 4px; color: var(--ink); text-decoration: none; }
.project-row .num a:hover { background: var(--canvas); text-decoration: underline; }
.project-row .last { color: var(--muted); white-space: nowrap; }
.project-row .actions { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: 6px; }
.status-error { grid-column: span 4; }
.button-quiet { border-color: transparent; color: var(--muted); }
.button-quiet:hover { border-color: #c4cace; color: var(--red); }
.remove-panel { max-width: 640px; }
.remove-panel label { display: block; margin: 16px 0 6px; font-weight: 600; }
.remove-panel input[type="text"] { width: 100%; }
.remove-panel .form-actions { display: flex; gap: 8px; }

@media (max-width: 1340px) {
  .project-head { display: none; }
  .project-row { grid-template-columns: repeat(auto-fill, minmax(120px, 1fr)); row-gap: 8px; }
  .project-row .project-name, .project-row .actions, .status-error { grid-column: 1 / -1; }
  .project-row .actions { justify-content: flex-start; }
  .project-row [data-label]::before { content: attr(data-label); display: block; font-size: 11px; color: var(--muted); }
  .project-row .num { text-align: left; }
}

/* --- dialog --------------------------------------------------------------------------------- */
.dialog {
  width: min(520px, calc(100vw - 32px));
  padding: 0;
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--ink);
  background: var(--surface);
  box-shadow: 0 20px 50px rgba(0, 0, 0, 0.25);
}
.dialog::backdrop { background: rgba(29, 35, 39, 0.45); }
.dialog form { padding: 20px 24px; }
.dialog h2 { font-size: 17px; margin: 0 0 12px; overflow-wrap: anywhere; }
.dialog p { margin: 0 0 10px; }
.dialog label { display: block; margin: 16px 0 6px; font-weight: 600; }
.dialog input[type="text"] { width: 100%; }
.dialog .form-actions { display: flex; gap: 8px; margin-top: 16px; }

/* --- link out to Catenda ------------------------------------------------------------------- */
.icon-link { display: inline-flex; align-items: center; justify-content: center; width: 26px; height: 26px; border-radius: 4px; color: var(--muted); }
.icon-link:hover, .icon-link:focus-visible { background: var(--canvas); color: var(--green-dark); }
.name-with-link { display: inline-flex; align-items: center; gap: 4px; }
.cell-name .tag { max-width: 100%; white-space: normal; }
.link-more { margin-left: 4px; font-weight: 600; white-space: nowrap; }

/* --- when the data was read from Catenda, and the button to read it again ------------------- */
.fetched { display: inline-flex; align-items: center; gap: 8px; font-size: 13px; }
.sync-button { display: inline-flex; align-items: center; justify-content: center; padding: 4px 7px; }
.sync-button.busy svg { animation: spin 0.9s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) { .sync-button.busy svg { animation: none; } }

/* --- view switch at the top of the side panel ---------------------------------------------- */
.view-switch { margin-bottom: 16px; padding-bottom: 14px; border-bottom: 1px solid var(--line); }
.view-switch h2 { margin-bottom: 8px; }
.segmented { display: flex; border: 1px solid #c4cace; border-radius: 4px; overflow: hidden; }
.segmented a { flex: 1; padding: 6px 10px; text-align: center; color: var(--ink); text-decoration: none; background: var(--surface); }
.segmented a + a { border-left: 1px solid #c4cace; }
.segmented a:hover { background: var(--canvas); }
.segmented a[aria-current="page"] { background: var(--green); color: #fff; font-weight: 600; }

/* --- search in the list of people in the filter panel --------------------------------------- */
.plain-list { list-style: none; margin: 0; padding: 0; }
.people-search { width: 100%; margin: 4px 0 6px; font: inherit; font-size: 13px; padding: 5px 8px; border: 1px solid #c4cace; border-radius: 4px; }
