/* The site editor's screens. One stylesheet, no inline styles (the CSP allows only this file). */

:root {
  color-scheme: light;
  --bg: #f4f6f8;
  --surface: #ffffff;
  --surface-2: #f8f9fb;
  --text: #1b2430;
  --muted: #55606d;
  --line: #d3d9e0;
  --line-strong: #6b7785;
  --primary: #1d5ba6;
  --primary-dark: #154680;
  --primary-soft: #e8f0fa;
  --danger: #b0261c;
  --danger-soft: #fdeceb;
  --success: #1b6e37;
  --success-soft: #e8f5ec;
  --warning: #7a4f00;
  --warning-soft: #fff4dc;
  --info-soft: #eef4fb;
  --focus: #ffbf47;
  --focus-ink: #0b0c0c;
  --radius: 6px;
  --shadow: 0 1px 2px rgba(16, 24, 40, 0.06), 0 1px 3px rgba(16, 24, 40, 0.08);
  --font: system-ui, -apple-system, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, 'Liberation Mono', monospace;
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html {
  -webkit-text-size-adjust: 100%;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.5 var(--font);
}

h1,
h2,
h3 {
  line-height: 1.25;
  margin: 0 0 0.5rem;
}
h1 {
  font-size: 1.75rem;
}
h2 {
  font-size: 1.3rem;
}
h3 {
  font-size: 1.1rem;
}
p {
  margin: 0 0 0.75rem;
}
a {
  color: var(--primary);
  text-underline-offset: 2px;
}
a:hover {
  color: var(--primary-dark);
}
code,
pre {
  font-family: var(--mono);
  font-size: 0.9em;
}

/* Focus: always visible, the same everywhere. */
:focus-visible {
  outline: 3px solid var(--focus);
  outline-offset: 0;
  box-shadow: 0 0 0 5px var(--focus-ink);
}
h1:focus,
h2:focus,
[tabindex='-1']:focus {
  outline: none;
  box-shadow: none;
}
.problem-summary:focus,
.conflict:focus,
.token-once:focus {
  outline: 3px solid var(--focus);
  box-shadow: none;
}

.sr-only {
  position: absolute !important;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
  border: 0;
}
.offscreen {
  position: fixed;
  left: -10000px;
  top: 0;
  width: 1px;
  height: 1px;
  opacity: 0;
}
[hidden] {
  display: none !important;
}

.skip-link {
  position: absolute;
  left: 0.5rem;
  top: -4rem;
  z-index: 100;
  background: var(--focus);
  color: var(--focus-ink);
  border: 0;
  padding: 0.6rem 1rem;
  font: inherit;
  font-weight: 600;
  border-radius: 0 0 var(--radius) var(--radius);
}
.skip-link:focus {
  top: 0;
}

/* ---------------------------------------------------------------- top bar */

.topbar {
  background: #16324f;
  color: #fff;
}
.topbar-inner {
  max-width: 1600px;
  margin: 0 auto;
  padding: 0.6rem 1rem;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.5rem 1.5rem;
}
.brand {
  color: #fff;
  font-weight: 700;
  font-size: 1.1rem;
  text-decoration: none;
  letter-spacing: 0.01em;
}
.brand:hover {
  color: #fff;
  text-decoration: underline;
}
.topnav ul {
  display: flex;
  flex-wrap: wrap;
  gap: 0.25rem 1rem;
  list-style: none;
  margin: 0;
  padding: 0;
}
.topnav a {
  color: #dce6f2;
  text-decoration: none;
  padding: 0.25rem 0;
  border-bottom: 3px solid transparent;
}
.topnav a:hover {
  color: #fff;
  border-bottom-color: #7ea6d6;
}
.topnav a[aria-current='page'] {
  color: #fff;
  border-bottom-color: #fff;
}
.who {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: 0.75rem;
  color: #dce6f2;
  font-size: 0.95rem;
}
.who .btn-quiet {
  color: #fff;
  border-color: #6f8fb4;
}
.who .btn-quiet:hover {
  background: #21466d;
}

main {
  max-width: 1200px;
  margin: 0 auto;
  padding: 1.25rem 1rem 4rem;
}
main:focus {
  outline: none;
}
main:has(.editor-layout.show-preview) {
  max-width: 1600px;
}
.noscript {
  padding: 2rem;
}

/* ---------------------------------------------------------------- screen heads */

.crumbs ol {
  list-style: none;
  margin: 0 0 0.5rem;
  padding: 0;
  display: flex;
  flex-wrap: wrap;
  gap: 0.25rem;
  font-size: 0.9rem;
  color: var(--muted);
}
.crumbs li + li::before {
  content: '›';
  margin-right: 0.35rem;
  color: var(--muted);
}
.crumbs span[aria-current] {
  color: var(--text);
}
.screen-head {
  margin-bottom: 1rem;
}
.screen-title {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
}
.screen-title h1 {
  margin: 0;
  overflow-wrap: anywhere;
}
.screen-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
}
.lede {
  color: var(--muted);
  margin-top: 0.5rem;
  max-width: 50rem;
}
.muted {
  color: var(--muted);
}
.small {
  font-size: 0.9rem;
}
.empty {
  color: var(--muted);
  font-style: italic;
}
.loading {
  color: var(--muted);
}

/* ---------------------------------------------------------------- buttons */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.4rem;
  min-height: 2.5rem;
  padding: 0.45rem 1rem;
  border: 1px solid var(--line-strong);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--text);
  font: inherit;
  font-weight: 600;
  line-height: 1.2;
  text-decoration: none;
  cursor: pointer;
}
.btn:hover {
  background: var(--surface-2);
  color: var(--text);
}
.btn:disabled,
.btn[aria-disabled='true'] {
  opacity: 0.55;
  cursor: not-allowed;
}
.btn-primary {
  background: var(--primary);
  border-color: var(--primary);
  color: #fff;
}
.btn-primary:hover {
  background: var(--primary-dark);
  border-color: var(--primary-dark);
  color: #fff;
}
.btn-danger {
  background: var(--danger);
  border-color: var(--danger);
  color: #fff;
}
.btn-danger:hover {
  background: #8c1d15;
  color: #fff;
}
.btn-danger-quiet {
  color: var(--danger);
  border-color: #d9a29d;
}
.btn-danger-quiet:hover {
  background: var(--danger-soft);
  color: var(--danger);
}
.btn-quiet {
  background: transparent;
  border-color: transparent;
  color: var(--primary);
}
.btn-quiet:hover {
  background: var(--primary-soft);
  color: var(--primary-dark);
}
.btn-small {
  min-height: 2.1rem;
  padding: 0.3rem 0.7rem;
  font-size: 0.9rem;
}
.btn-wide {
  width: 100%;
}
.btn-link {
  background: none;
  border: 0;
  padding: 0;
  font: inherit;
  color: var(--primary);
  text-decoration: underline;
  text-underline-offset: 2px;
  cursor: pointer;
  text-align: left;
}
.btn-link:hover {
  color: var(--primary-dark);
}
.btn-icon {
  background: none;
  border: 1px solid transparent;
  border-radius: var(--radius);
  font-size: 1.5rem;
  line-height: 1;
  width: 2.5rem;
  height: 2.5rem;
  cursor: pointer;
  color: var(--muted);
}
.btn-icon:hover {
  background: var(--surface-2);
  color: var(--text);
}
.btn-google {
  background: #fff;
  border: 1px solid var(--line-strong);
  color: var(--text);
}
.g-mark {
  display: inline-grid;
  place-items: center;
  width: 1.4rem;
  height: 1.4rem;
  border-radius: 50%;
  background: #4285f4;
  color: #fff;
  font-weight: 700;
  font-size: 0.85rem;
}
.button-row {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  align-items: center;
  margin: 0.5rem 0;
}

/* ---------------------------------------------------------------- forms */

.stack > * + * {
  margin-top: 0.25rem;
}
.narrow {
  max-width: 36rem;
}
.field {
  margin: 0 0 1rem;
}
.field > label,
.field-label {
  display: block;
  font-weight: 600;
  margin-bottom: 0.25rem;
}
.req {
  font-weight: 400;
  color: var(--muted);
  font-size: 0.9em;
}
.help {
  color: var(--muted);
  font-size: 0.9rem;
  margin: 0 0 0.35rem;
  max-width: 48rem;
}
.input {
  display: block;
  width: 100%;
  min-height: 2.5rem;
  padding: 0.45rem 0.6rem;
  border: 1px solid var(--line-strong);
  border-radius: var(--radius);
  background: #fff;
  color: var(--text);
  font: inherit;
}
textarea.input {
  resize: vertical;
  line-height: 1.45;
}
textarea.one-line {
  min-height: 2.5rem;
  overflow: hidden;
}
select.input {
  padding-right: 2rem;
}
.input:disabled {
  background: var(--surface-2);
  color: var(--muted);
}
.input-short {
  max-width: 16rem;
}
.input-row {
  display: flex;
  gap: 0.5rem;
  align-items: stretch;
}
.input-row .input {
  flex: 1;
  min-width: 0;
}
.input[aria-invalid='true'],
.has-error > .input,
.has-error > .input-row .input {
  border-color: var(--danger);
  box-shadow: inset 4px 0 0 var(--danger);
}
.field-error {
  color: var(--danger);
  font-weight: 600;
  margin: 0.35rem 0 0;
  padding-left: 0.6rem;
  border-left: 4px solid var(--danger);
}
.counter {
  font-size: 0.85rem;
  color: var(--muted);
  margin: 0.25rem 0 0;
  text-align: right;
}
.counter.over {
  color: var(--danger);
  font-weight: 600;
}
.check,
.radio {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-start;
  gap: 0.5rem;
  margin: 0 0 0.6rem;
}
.check input,
.radio input {
  width: 1.25rem;
  height: 1.25rem;
  margin: 0.15rem 0 0;
  flex: none;
  accent-color: var(--primary);
}
.check label,
.radio label {
  flex: 1;
  min-width: 0;
}
.check .help,
.check .field-error {
  flex-basis: 100%;
  margin-left: 1.75rem;
}
.radio-row {
  display: flex;
  flex-wrap: wrap;
  gap: 0.25rem 1.25rem;
}
.radio-row .radio {
  margin-bottom: 0.25rem;
}
fieldset.plain {
  border: 0;
  margin: 0 0 1rem;
  padding: 0;
  min-width: 0;
}
fieldset.plain > legend {
  font-weight: 600;
  margin-bottom: 0.35rem;
  padding: 0;
}
.field-inline-label {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin: 0;
}
.field-inline-label label {
  font-weight: 600;
  white-space: nowrap;
}

/* ---------------------------------------------------------------- notices */

.notice {
  border: 1px solid var(--line);
  border-left: 5px solid var(--primary);
  background: var(--info-soft);
  border-radius: var(--radius);
  padding: 0.75rem 1rem;
  margin: 0 0 1rem;
}
.notice > :last-child {
  margin-bottom: 0;
}
.notice h2,
.notice h3 {
  font-size: 1.1rem;
}
.notice-success {
  border-left-color: var(--success);
  background: var(--success-soft);
}
.notice-warning {
  border-left-color: #b77900;
  background: var(--warning-soft);
}
.notice-error {
  border-left-color: var(--danger);
  background: var(--danger-soft);
}
.problem-summary ul {
  margin: 0.25rem 0 0;
  padding-left: 1.25rem;
}
.problem-summary li {
  margin: 0.2rem 0;
}
.problem-summary .btn-link {
  color: var(--danger);
  font-weight: 600;
}
.problem-summary .where {
  font-weight: 400;
  color: var(--text);
}

.badge {
  display: inline-block;
  font-size: 0.75rem;
  font-weight: 700;
  letter-spacing: 0.02em;
  padding: 0.1rem 0.45rem;
  margin-left: 0.4rem;
  border-radius: 999px;
  background: var(--primary-soft);
  color: var(--primary-dark);
  vertical-align: middle;
  white-space: nowrap;
}
.badge-ok {
  background: var(--success-soft);
  color: var(--success);
  margin-left: 0;
}
.badge-warn {
  background: var(--warning-soft);
  color: var(--warning);
}
.badge-info {
  background: var(--info-soft);
  color: var(--primary-dark);
}
.badge-agent {
  background: #efe9fb;
  color: #4b2f8f;
}

/* ---------------------------------------------------------------- sign-in */

.auth-card {
  max-width: 30rem;
  margin: 2rem auto;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 1.75rem 1.5rem;
  box-shadow: var(--shadow);
}
.auth-card h1 {
  margin-bottom: 0.5rem;
}
.divider {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  color: var(--muted);
  font-size: 0.9rem;
  margin: 1.25rem 0;
}
.divider::before,
.divider::after {
  content: '';
  flex: 1;
  border-top: 1px solid var(--line);
}
.steps {
  padding-left: 1.25rem;
}
.steps > li {
  margin-bottom: 1.25rem;
}
.steps > li > strong {
  display: block;
  margin-bottom: 0.35rem;
}
.codes {
  columns: 2;
  padding-left: 2rem;
  font-size: 1.05rem;
}
.codes code {
  letter-spacing: 0.04em;
}
.qr {
  display: inline-block;
  background: #fff;
  padding: 0.75rem;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  margin-bottom: 0.75rem;
}
.qr svg {
  display: block;
  width: 200px;
  height: 200px;
}
.pw-count {
  font-size: 0.9rem;
  color: var(--muted);
  margin: 0.3rem 0 0;
}
.pw-count.ok {
  color: var(--success);
}
.pw-ok {
  color: var(--success);
  font-weight: 600;
  margin: 0.3rem 0 0;
}
.pw-problems {
  color: var(--danger);
  margin: 0.3rem 0 0;
  padding-left: 1.25rem;
}
.turnstile-box {
  min-height: 65px;
}

.copy-box {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.5rem;
  margin: 0.25rem 0 0.75rem;
}
.copy-text {
  flex: 1 1 18rem;
  min-width: 0;
  background: #fff;
  border: 1px solid var(--line-strong);
  border-radius: var(--radius);
  padding: 0.5rem 0.65rem;
  overflow-wrap: anywhere;
  word-break: break-all;
  user-select: all;
}
.copy-text.secret {
  font-size: 1.05rem;
  letter-spacing: 0.06em;
  word-break: normal;
}
.copy-wrap {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
}
.copy-status {
  font-size: 0.9rem;
  color: var(--success);
}

/* ---------------------------------------------------------------- cards and lists */

.cards {
  list-style: none;
  margin: 0 0 1.5rem;
  padding: 0;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(15rem, 1fr));
  gap: 0.75rem;
}
.card {
  position: relative;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 1rem;
  box-shadow: var(--shadow);
}
.card h2,
.card h3 {
  font-size: 1.1rem;
  margin: 0 0 0.25rem;
}
.card:hover {
  border-color: var(--primary);
}
/* The whole card is the link's click target. */
.card-link::after {
  content: '';
  position: absolute;
  inset: 0;
}
.card .ext,
.card p a {
  position: relative;
  z-index: 1;
}
.card p {
  margin: 0;
}
.home-section {
  margin-bottom: 1.75rem;
}
.section-head {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  justify-content: space-between;
  gap: 0.5rem;
}
.link-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(15rem, 1fr));
  gap: 0.5rem;
}
.link-list a {
  display: block;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 0.65rem 0.9rem;
  font-weight: 600;
  text-decoration: none;
}
.link-list a:hover {
  border-color: var(--primary);
  text-decoration: underline;
}
.ext {
  font-size: 0.85em;
}
ul.compact {
  margin: 0.25rem 0 0.5rem;
  padding-left: 1.25rem;
}

.panel {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 1.25rem;
  margin-bottom: 1.25rem;
}
.details {
  display: grid;
  grid-template-columns: max-content 1fr;
  gap: 0.35rem 1.25rem;
  margin: 0 0 0.75rem;
}
.details dt {
  font-weight: 600;
}
.details dd {
  margin: 0;
  overflow-wrap: anywhere;
}
details.add-box {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 0.75rem 1rem;
  margin: 1rem 0;
}
details.add-box > summary,
.person-manage > summary,
.used-by > summary {
  cursor: pointer;
  font-weight: 600;
  color: var(--primary);
}
details.add-box[open] > summary {
  margin-bottom: 1rem;
}

/* ---------------------------------------------------------------- entry list */

.list-tools {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem 2rem;
  align-items: flex-end;
  margin-bottom: 0.5rem;
}
.list-tools .field {
  flex: 1 1 18rem;
  max-width: 28rem;
  margin-bottom: 0.5rem;
}
.list-tools > .help {
  flex: 1 1 18rem;
}
.entries {
  list-style: none;
  margin: 0;
  padding: 0;
}
.entries.tree.sub {
  margin-left: 1.5rem;
  border-left: 2px solid var(--line);
  padding-left: 0.75rem;
}
.entries > li {
  margin: 0;
}
.entry-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 0.35rem 1rem;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 0.55rem 0.8rem;
  margin: 0.35rem 0;
}
.entry-main {
  display: flex;
  flex-direction: column;
  min-width: 0;
}
.entry-title {
  font-weight: 600;
  overflow-wrap: anywhere;
}
.entry-url {
  font-size: 0.85rem;
  color: var(--muted);
  overflow-wrap: anywhere;
}
.entry-tools {
  display: flex;
  gap: 0.35rem;
}
.kids-toggle {
  margin: 0 0 0.25rem 0.8rem;
}

/* ---------------------------------------------------------------- the editor */

.editor-bar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem 1rem;
  background: rgba(244, 246, 248, 0.96);
  border-bottom: 1px solid var(--line);
  padding: 0.6rem 0;
  margin-bottom: 0.75rem;
}
.editor-bar-main {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.5rem 0.75rem;
  min-width: 0;
}
.editor-bar .btn-primary {
  min-width: 7rem;
}
.dirty-badge {
  font-size: 0.85rem;
  font-weight: 700;
  color: var(--warning);
  background: var(--warning-soft);
  border-radius: 999px;
  padding: 0.15rem 0.6rem;
}
.save-status .notice {
  margin: 0;
}
.publish-status {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.4rem;
  font-size: 0.95rem;
}
.save-status .publish-status,
.home-section + .publish-status,
.upload-log .publish-status {
  margin: 0.25rem 0;
}
.publish-status[data-state='failed'] {
  color: var(--danger);
}
.publish-status[data-state='live'] {
  color: var(--success);
}
.dot {
  width: 0.65rem;
  height: 0.65rem;
  border-radius: 50%;
  display: inline-block;
}
.dot-live {
  background: var(--success);
}
.dot-failed {
  background: var(--danger);
}
.spinner {
  width: 0.9rem;
  height: 0.9rem;
  border: 2px solid var(--line);
  border-top-color: var(--primary);
  border-radius: 50%;
  display: inline-block;
  animation: spin 0.9s linear infinite;
}
@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}
@media (prefers-reduced-motion: reduce) {
  .spinner {
    animation: none;
  }
}
.editor-links {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.5rem 1.25rem;
  margin: -0.25rem 0 1rem;
}
.btn-danger-quiet.btn-small {
  margin-left: auto;
}

.editor-layout {
  display: block;
}
.editor-preview {
  display: none;
}
.editor-layout.show-preview .editor-preview {
  display: block;
}
@media (min-width: 1100px) {
  .editor-layout.show-preview {
    display: grid;
    grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
    gap: 1.25rem;
    align-items: start;
  }
  .editor-layout.show-preview .editor-preview {
    position: sticky;
    top: 4.25rem;
  }
}
@media (max-width: 1099.98px) {
  .editor-layout.show-preview .editor-form {
    display: none;
  }
}
.editor-form {
  min-width: 0;
}
.form-fields {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 1.25rem;
}
.id-field {
  background: var(--surface-2);
  border: 1px dashed var(--line-strong);
  border-radius: var(--radius);
  padding: 0.75rem;
}
.id-show {
  font-weight: 600;
  margin: 0.35rem 0 0;
  overflow-wrap: anywhere;
}

.preview-panel {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 0.75rem;
}
.preview-head {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.25rem 1rem;
  margin-bottom: 0.5rem;
}
.preview-head h2 {
  font-size: 1.1rem;
  margin: 0;
}
.preview-status {
  color: var(--muted);
  font-size: 0.9rem;
  margin: 0;
}
.preview-frame iframe {
  display: block;
  width: 100%;
  height: calc(100vh - 11rem);
  min-height: 24rem;
  border: 1px solid var(--line);
  border-radius: 4px;
  background: #fff;
}
.preview-problems .notice {
  font-size: 0.9rem;
}
.preview-problems ul {
  margin: 0;
  padding-left: 1.25rem;
}

/* Groups: objects, lists, blocks, pictures */
.group {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  margin: 0 0 1rem;
  padding: 0.75rem 1rem 0.5rem;
  min-width: 0;
  background: var(--surface);
}
.group > legend {
  font-weight: 700;
  padding: 0 0.35rem;
  margin-left: -0.35rem;
}
.group > .field-error {
  margin-bottom: 0.75rem;
}
.group.has-error {
  border-color: var(--danger);
}
.object-field .object-field,
.list-field .group {
  background: var(--surface-2);
}
.list-items {
  list-style: none;
  margin: 0;
  padding: 0;
}
.list-item {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  gap: 0.25rem 0.5rem;
  padding: 0.25rem 0;
  border-bottom: 1px solid var(--line);
}
.list-item:last-child {
  border-bottom: 0;
}
.list-item > .item-body {
  flex: 1 1 18rem;
  min-width: 0;
}
.list-item > .item-body > .field,
.list-item > .item-body > .group {
  margin-bottom: 0.5rem;
}
.list-item-group {
  align-items: flex-start;
  flex-direction: column;
}
.list-item-group > .item-body {
  width: 100%;
  flex-basis: auto;
}
.item-tools {
  display: flex;
  gap: 0.3rem;
  padding-bottom: 0.5rem;
}
.list-add {
  margin: 0.5rem 0;
}
.btn-tool {
  min-height: 2rem;
  padding: 0.2rem 0.55rem;
  font-weight: 500;
}
.btn-add {
  border-style: dashed;
  color: var(--primary);
}

.blocks-field {
  background: var(--surface-2);
}
.blocks-tools {
  display: flex;
  justify-content: flex-end;
  gap: 0.25rem;
}
.block-list {
  list-style: none;
  margin: 0;
  padding: 0;
}
.block-card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-left: 4px solid #8fb0d6;
  border-radius: var(--radius);
  margin: 0 0 0.75rem;
}
.block-card.has-error {
  border-color: var(--danger);
}
.block-head {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 0.25rem 0.5rem;
  padding: 0.35rem 0.5rem 0.35rem 0.25rem;
  border-bottom: 1px solid var(--line);
  background: #fbfcfd;
  border-radius: var(--radius) var(--radius) 0 0;
}
.is-folded > .block-head {
  border-bottom: 0;
}
.block-toggle {
  flex: 1 1 14rem;
  min-width: 0;
  display: flex;
  align-items: baseline;
  gap: 0.5rem;
  background: none;
  border: 0;
  border-radius: 4px;
  font: inherit;
  text-align: left;
  padding: 0.35rem 0.4rem;
  cursor: pointer;
  color: var(--text);
}
.block-toggle:hover {
  background: var(--primary-soft);
}
.fold-icon::before {
  content: '▾';
  display: inline-block;
  width: 1rem;
  color: var(--muted);
}
.is-folded .fold-icon::before {
  content: '▸';
}
.block-name {
  font-weight: 700;
  white-space: nowrap;
}
.block-snippet {
  color: var(--muted);
  font-size: 0.9rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  min-width: 0;
}
.block-tools {
  display: flex;
  flex-wrap: wrap;
  gap: 0.3rem;
  align-items: flex-start;
  position: relative;
}
.block-tools .add-wrap {
  position: static;
}
.block-card > .field-error {
  margin: 0.5rem 0.75rem 0;
}
.block-body {
  padding: 0.75rem 0.9rem 0.25rem;
}
.block-body > .field:last-child,
.block-body > .group:last-child {
  margin-bottom: 0.5rem;
}
.block-body .blocks-field {
  background: var(--surface-2);
}
.add-wrap {
  position: relative;
  margin: 0.25rem 0;
}
.add-menu {
  position: absolute;
  z-index: 30;
  right: 0;
  top: calc(100% + 0.25rem);
  width: min(24rem, calc(100vw - 2rem));
  max-height: 60vh;
  overflow: auto;
  background: var(--surface);
  border: 1px solid var(--line-strong);
  border-radius: var(--radius);
  box-shadow: 0 8px 24px rgba(16, 24, 40, 0.18);
  padding: 0.5rem;
}
.blocks-field > .add-wrap > .add-menu {
  left: 0;
  right: auto;
}
.add-menu ul {
  list-style: none;
  margin: 0 0 0.5rem;
  padding: 0;
}
.add-menu-title {
  font-weight: 600;
  margin: 0.25rem 0.25rem 0.5rem;
}
.add-menu-item {
  display: flex;
  flex-direction: column;
  width: 100%;
  text-align: left;
  background: none;
  border: 0;
  border-radius: 4px;
  padding: 0.4rem 0.5rem;
  font: inherit;
  cursor: pointer;
  color: var(--text);
}
.add-menu-item:hover {
  background: var(--primary-soft);
}
.add-menu-label {
  font-weight: 600;
}
.add-menu-hint {
  font-size: 0.85rem;
  color: var(--muted);
}

.text-tools {
  display: flex;
  gap: 0.25rem;
  margin-bottom: 0.25rem;
}
.tool {
  min-height: 2rem;
  padding: 0.15rem 0.6rem;
  border: 1px solid var(--line-strong);
  border-radius: 4px;
  background: var(--surface);
  font: inherit;
  font-size: 0.9rem;
  cursor: pointer;
  color: var(--text);
}
.tool:hover {
  background: var(--primary-soft);
}
.tool-b {
  font-weight: 800;
}
.tool-i {
  font-style: italic;
}
.tool-link {
  text-decoration: underline;
  color: var(--primary);
}
.link-desc {
  margin: 0.35rem 0 0;
  overflow-wrap: anywhere;
}
.ref-open {
  display: inline-block;
  margin-top: 0.35rem;
}

.image-current,
.file-current {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  margin-bottom: 0.25rem;
  min-width: 0;
}
.thumb {
  width: 8rem;
  height: 6rem;
  object-fit: cover;
  border: 1px solid var(--line);
  border-radius: 4px;
  background: var(--surface-2);
  flex: none;
}
.image-meta {
  display: flex;
  flex-direction: column;
  min-width: 0;
}
.media-name {
  font-weight: 600;
  overflow-wrap: anywhere;
  margin: 0;
}
.media-meta {
  font-size: 0.85rem;
  color: var(--muted);
  margin: 0;
}
.upload-status {
  font-size: 0.9rem;
  color: var(--muted);
  margin: 0 0 0.5rem;
}
.upload-status:empty {
  display: none;
}
.upload-status.bad,
li.bad {
  color: var(--danger);
  font-weight: 600;
}
.pdf-reminder {
  border-top: 1px solid var(--line);
  padding-top: 0.5rem;
}
.doc-icon {
  display: inline-grid;
  place-items: center;
  width: 2.75rem;
  height: 3.25rem;
  border: 1px solid #d9a29d;
  border-radius: 4px;
  background: var(--danger-soft);
  color: var(--danger);
  font-weight: 800;
  font-size: 0.8rem;
  flex: none;
}
.doc-icon.big {
  width: 4.5rem;
  height: 5.5rem;
  font-size: 1rem;
}
.json {
  background: #f6f8fa;
  border: 1px solid var(--line);
  border-radius: 4px;
  padding: 0.75rem;
  overflow: auto;
  max-height: 60vh;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  font-size: 0.85rem;
}
textarea.json {
  font-family: var(--mono);
  max-height: none;
  white-space: pre;
}

/* ---------------------------------------------------------------- media */

.media-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(9.5rem, 1fr));
  gap: 0.6rem;
}
.media-tile {
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: 0.25rem;
  padding: 0.4rem;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  font: inherit;
  text-align: left;
  cursor: pointer;
  color: var(--text);
  min-width: 0;
}
.media-tile:hover {
  border-color: var(--primary);
}
.media-tile.is-current {
  border: 2px solid var(--primary);
}
.media-tile img {
  width: 100%;
  aspect-ratio: 4 / 3;
  object-fit: cover;
  border-radius: 3px;
  background: var(--surface-2);
}
.media-tile .doc-icon {
  width: 100%;
  height: auto;
  aspect-ratio: 4 / 3;
}
.media-tile .media-name {
  font-size: 0.85rem;
}
.media-cards {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(14rem, 1fr));
  gap: 0.75rem;
}
.media-card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 0.6rem;
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  min-width: 0;
}
.media-thumb {
  display: grid;
  place-items: center;
  background: var(--surface-2);
  border-radius: 4px;
  aspect-ratio: 4 / 3;
  overflow: hidden;
}
.media-thumb img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}
.media-info p {
  margin: 0;
}
.used-by summary {
  font-size: 0.9rem;
}
.upload-log ul {
  margin: 0.25rem 0 0;
}

/* ---------------------------------------------------------------- history */

.history {
  list-style: none;
  margin: 0;
  padding: 0;
}
.history-row {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 0.65rem 0.9rem;
  margin-bottom: 0.5rem;
}
.history-meta {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.25rem 0.75rem;
  font-size: 0.9rem;
  color: var(--muted);
}
.history-meta time {
  color: var(--text);
  font-weight: 600;
}
.history-who {
  color: var(--text);
}
.history-what {
  margin: 0.25rem 0;
  overflow-wrap: anywhere;
}
.history-files {
  margin: 0;
  padding-left: 1.25rem;
  font-size: 0.9rem;
}
.history-row .button-row {
  margin-bottom: 0;
}

/* ---------------------------------------------------------------- admin */

.tabs ul {
  display: flex;
  flex-wrap: wrap;
  gap: 0.25rem;
  list-style: none;
  margin: 0 0 1.25rem;
  padding: 0;
  border-bottom: 1px solid var(--line);
}
.tabs a {
  display: block;
  padding: 0.5rem 0.9rem;
  text-decoration: none;
  border-bottom: 3px solid transparent;
  margin-bottom: -1px;
  font-weight: 600;
}
.tabs a[aria-current='page'] {
  border-bottom-color: var(--primary);
  color: var(--text);
}
.people-list {
  list-style: none;
  margin: 0;
  padding: 0;
}
.person-row {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 0.75rem 1rem;
  margin-bottom: 0.5rem;
}
.person-row.is-disabled {
  background: var(--surface-2);
}
.person-main p {
  margin: 0 0 0.15rem;
  overflow-wrap: anywhere;
}
.person-name {
  font-weight: 700;
}
.person-manage {
  margin-top: 0.5rem;
}
.person-manage[open] > summary {
  margin-bottom: 0.75rem;
}
.filters {
  display: flex;
  flex-wrap: wrap;
  gap: 0 1rem;
}
.filters .field {
  flex: 1 1 14rem;
  max-width: 22rem;
}

/* Tables become stacked cards on narrow screens. */
.table-wrap {
  overflow-x: auto;
  margin-bottom: 1rem;
}
table.data {
  width: 100%;
  border-collapse: collapse;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  font-size: 0.95rem;
}
table.data th,
table.data td {
  text-align: left;
  padding: 0.5rem 0.65rem;
  border-bottom: 1px solid var(--line);
  vertical-align: top;
  overflow-wrap: anywhere;
}
table.data th {
  background: var(--surface-2);
  font-weight: 700;
  white-space: nowrap;
}
@media (max-width: 760px) {
  table.data,
  table.data tbody,
  table.data tr,
  table.data td {
    display: block;
    width: 100%;
  }
  table.data thead {
    position: absolute;
    width: 1px;
    height: 1px;
    overflow: hidden;
    clip: rect(0 0 0 0);
  }
  table.data tr {
    border-bottom: 1px solid var(--line-strong);
    padding: 0.35rem 0;
  }
  table.data td {
    border: 0;
    padding: 0.2rem 0.65rem;
  }
  table.data td[data-label]:not([data-label=''])::before {
    content: attr(data-label) ': ';
    font-weight: 700;
  }
}

/* ---------------------------------------------------------------- dialogs */

dialog.dlg {
  width: min(40rem, calc(100vw - 2rem));
  max-height: calc(100vh - 2rem);
  padding: 0;
  border: 1px solid var(--line-strong);
  border-radius: 10px;
  box-shadow: 0 16px 48px rgba(16, 24, 40, 0.3);
  color: var(--text);
  background: var(--surface);
}
dialog.dlg-wide {
  width: min(64rem, calc(100vw - 2rem));
}
dialog.dlg::backdrop {
  background: rgba(16, 24, 40, 0.5);
}
.dlg-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 0.75rem 0.75rem 0.5rem 1.25rem;
  border-bottom: 1px solid var(--line);
  position: sticky;
  top: 0;
  background: var(--surface);
  z-index: 1;
}
.dlg-head h2 {
  margin: 0;
  font-size: 1.2rem;
  overflow-wrap: anywhere;
}
.dlg-body {
  padding: 1rem 1.25rem;
}
.dlg-actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 0.5rem;
  padding: 0.75rem 1.25rem 1rem;
}
.dlg-body .dlg-actions {
  padding: 0.75rem 0 0;
}
.page-list {
  min-height: 12rem;
}
.link-panel {
  margin-top: 0.5rem;
}

/* ---------------------------------------------------------------- small screens */

@media (max-width: 600px) {
  h1 {
    font-size: 1.45rem;
  }
  main {
    padding: 1rem 1rem 3rem;
  }
  .auth-card {
    margin: 0.5rem auto;
    padding: 1.25rem 1rem;
    border-radius: var(--radius);
  }
  .form-fields {
    padding: 0.85rem;
  }
  .group {
    padding: 0.6rem 0.65rem 0.35rem;
  }
  .block-body {
    padding: 0.6rem 0.6rem 0.25rem;
  }
  .who {
    margin-left: 0;
    width: 100%;
    justify-content: space-between;
  }
  .codes {
    columns: 1;
  }
  .thumb {
    width: 6rem;
    height: 4.5rem;
  }
  .btn-danger-quiet.btn-small {
    margin-left: 0;
  }
  .details {
    grid-template-columns: 1fr;
    gap: 0 0;
  }
  .details dd {
    margin-bottom: 0.5rem;
  }
}
