:root {
  --view-bg: var(--bg);
  --view-surface: var(--surface);
  --view-surface-raised: var(--surface-raised);
  --view-border: var(--line);
  --view-border-strong: var(--line-strong);
  --view-text: var(--text);
  --view-muted: var(--muted);
  --view-accent: var(--accent);
  --view-accent-ink: var(--accent-contrast);
  --view-focus: var(--focus);
  --view-warning: var(--warning-text);
  background: var(--view-bg);
  color: var(--view-text);
  font-family: var(--font-sans);
  line-height: 1.45;
}

* {
  box-sizing: border-box;
}

body {
  min-width: 320px;
  min-height: 100vh;
  margin: 0;
  background: var(--view-bg);
}

a {
  color: var(--view-accent);
  text-underline-offset: 3px;
}

:where(a, button, input, select, textarea, summary):focus-visible {
  outline: 3px solid var(--view-focus);
  outline-offset: 3px;
}

button,
input,
select,
textarea {
  font: inherit;
}

.view-header {
  position: sticky;
  z-index: 20;
  top: 0;
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 12px 24px;
  align-items: end;
  padding: 18px clamp(18px, 3vw, 42px);
  border-bottom: 1px solid var(--view-border);
  background: var(--view-surface-raised);
  box-shadow: var(--shadow-soft);
}

.view-heading {
  min-width: 0;
}

.view-brand {
  display: inline-flex;
  gap: 8px;
  align-items: center;
  margin-bottom: 5px;
  color: var(--view-muted);
  font-size: 12px;
  font-weight: 800;
  letter-spacing: .12em;
  text-decoration: none;
  text-transform: uppercase;
}

.view-brand::before {
  width: 9px;
  height: 9px;
  border-radius: 999px;
  background: var(--view-accent);
  content: "";
}

.view-brand[data-brand-lockup]::before { content: none; }

.view-header h1 {
  margin: 0;
  overflow-wrap: anywhere;
  font-size: clamp(21px, 2.2vw, 31px);
  line-height: 1.1;
  letter-spacing: -.025em;
}

.view-meta {
  grid-column: 1 / -1;
  margin: 0;
  color: var(--view-muted);
  font-size: 13px;
}

.view-meta strong {
  color: var(--view-text);
}

.view-exports {
  display: flex;
  gap: 6px;
  align-items: center;
  flex-wrap: wrap;
  justify-content: flex-end;
  color: var(--view-muted);
  font-size: 13px;
}

.view-exports a,
.view-back {
  display: inline-flex;
  min-height: 36px;
  padding: 7px 10px;
  align-items: center;
  border: 1px solid var(--view-border);
  border-radius: 9px;
  background: var(--view-surface);
  color: var(--view-text);
  font-weight: 700;
  text-decoration: none;
}

.view-exports a:hover,
.view-back:hover {
  border-color: var(--view-accent);
  color: var(--view-accent);
}

.table-wrap {
  max-width: 100%;
  padding: 22px clamp(12px, 2.5vw, 36px) 30px;
  overflow: auto;
}

table {
  width: max-content;
  min-width: 100%;
  border: 1px solid var(--view-border);
  border-radius: 14px;
  border-spacing: 0;
  background: var(--view-surface);
  box-shadow: var(--shadow);
}

th,
td {
  padding: 12px 14px;
  border-right: 1px solid var(--view-border);
  border-bottom: 1px solid var(--view-border);
  text-align: left;
  vertical-align: top;
}

th {
  position: sticky;
  z-index: 2;
  top: 0;
  background: var(--view-surface-raised);
  color: var(--view-muted);
  font-size: 12px;
  font-weight: 800;
  letter-spacing: .055em;
  text-transform: uppercase;
}

th.is-pinned-field,
td.is-pinned-field {
  position: sticky;
  z-index: 3;
  left: var(--pinned-left);
  background: var(--view-surface);
  box-shadow: var(--shadow-soft);
}

th.is-pinned-field {
  z-index: 4;
  background: var(--view-surface-raised);
}

tbody tr:hover td.is-pinned-field {
  background: var(--surface-subtle);
}

td {
  max-width: 480px;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

tbody tr:hover td {
  background: var(--surface-subtle);
}

tr:last-child td {
  border-bottom: 0;
}

th:last-child,
td:last-child {
  border-right: 0;
}

.acks,
.member-acks,
.comments,
.member-comments {
  white-space: normal;
}

.acks,
.member-acks {
  display: flex;
  min-width: 282px;
  gap: 6px;
  align-items: flex-start;
  flex-wrap: wrap;
}

.acks form,
.member-acks form {
  display: contents;
}

.acks button,
.member-acks button,
.comment-form button,
.member-comment-form button,
.cell-form button {
  min-height: 40px;
  padding: 8px 11px;
  border: 1px solid var(--view-border-strong);
  border-radius: 9px;
  background: var(--view-surface-raised);
  color: var(--view-text);
  cursor: pointer;
  font-weight: 750;
}

.acks button:hover,
.member-acks button:hover,
.comment-form button:hover,
.member-comment-form button:hover,
.cell-form button:hover {
  border-color: var(--view-accent);
}

.acks button.marked,
.member-acks button.marked {
  border-color: var(--view-accent);
  background: var(--view-accent);
  color: var(--view-accent-ink);
}

.member-acks button:disabled,
.member-comment-form button:disabled,
.cell-form button:disabled {
  cursor: not-allowed;
  opacity: .55;
}

.comments,
.member-comments {
  min-width: 250px;
  max-width: 420px;
}

.view-comments summary {
  display: flex;
  min-height: 40px;
  padding: 8px 11px;
  align-items: center;
  justify-content: space-between;
  border: 1px solid var(--view-border-strong);
  border-radius: 9px;
  background: var(--view-surface-raised);
  color: var(--view-text);
  cursor: pointer;
  font-weight: 750;
  list-style: none;
}

.view-comments summary::-webkit-details-marker {
  display: none;
}

.view-comments summary::after {
  color: var(--view-accent);
  content: "+";
  font-size: 20px;
  line-height: 1;
}

.view-comments[open] summary::after {
  content: "−";
}

.view-comment-content {
  display: grid;
  gap: 10px;
  margin-top: 10px;
}

.view-comments:not([open]) > .view-comment-content {
  display: none;
}

.comment,
.member-comment {
  padding: 10px;
  border-left: 3px solid var(--view-border-strong);
  border-radius: 0 10px 10px 0;
  background: var(--view-surface-raised);
}

.comment.reply,
.member-comment.reply {
  margin-left: 16px;
}

.comment-meta,
.member-comment-meta {
  color: var(--view-muted);
  font-size: 12px;
}

.comment-body,
.member-comment-body {
  margin: 5px 0 8px;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.comment-form,
.member-comment-form,
.cell-form {
  display: grid;
  min-width: 180px;
  gap: 7px;
  margin-top: 8px;
}

.comment-form textarea,
.member-comment-form textarea,
.cell-form input,
.cell-form select,
.cell-form textarea,
.view-conflict input,
.view-conflict select,
.view-conflict textarea {
  width: 100%;
  min-height: 42px;
  padding: 9px 10px;
  border: 1px solid var(--view-border-strong);
  border-radius: 8px;
  background: var(--surface-subtle);
  color: var(--view-text);
}

.comment-form textarea,
.member-comment-form textarea,
.cell-form textarea {
  min-height: 72px;
  resize: vertical;
}

.comment-form button,
.member-comment-form button,
.cell-form button {
  justify-self: start;
}

.clear-form {
  margin-top: 7px;
}

.empty,
.access-notice,
.refresh-notice {
  margin: 18px clamp(12px, 2.5vw, 36px) 0;
  padding: 14px 16px;
  border: 1px solid var(--view-border);
  border-radius: 12px;
  background: var(--view-surface);
}

.empty {
  padding-block: 38px;
  color: var(--view-muted);
  text-align: center;
}

.access-notice {
  border-color: var(--info);
  background: var(--surface-info);
  color: var(--info-text);
}

.refresh-notice {
  border-color: var(--warning);
  background: var(--surface-warning);
  color: var(--view-warning);
}

.refresh-notice[hidden] {
  display: none;
}

.refresh-notice button {
  min-height: 36px;
  margin-left: 8px;
}

.view-footer {
  padding: 8px 18px 28px;
  color: var(--view-muted);
  font-size: 12px;
  text-align: center;
}

.view-footer a {
  color: inherit;
}

.view-conflict-page {
  display: grid;
  min-height: 100vh;
  padding: 24px 16px;
  place-items: center;
}

.view-conflict-shell {
  width: min(100%, 46rem);
}

.view-conflict {
  padding: clamp(18px, 4vw, 34px);
  border: 1px solid var(--view-border);
  border-radius: 16px;
  background: var(--view-surface);
  box-shadow: var(--shadow);
}

.view-conflict h1 {
  margin-top: 0;
  font-size: clamp(24px, 5vw, 34px);
}

.view-conflict dl,
.view-conflict form {
  display: grid;
  gap: 10px;
}

.view-conflict dt {
  color: var(--view-muted);
}

.view-conflict dd {
  margin: 0 0 12px;
  white-space: pre-wrap;
}

.view-conflict button {
  width: fit-content;
  min-height: 44px;
}

@media (max-width: 720px) {
  .view-header {
    position: relative;
    display: grid;
    padding: 16px;
  }

  .view-heading,
  .view-exports,
  .view-meta {
    grid-column: 1 / -1;
  }

  .view-exports {
    justify-content: flex-start;
  }

  .view-exports a,
  .view-back {
    min-height: 44px;
  }

  .table-wrap {
    padding: 12px;
    overflow: visible;
  }

  table,
  tbody,
  tr,
  td {
    display: block;
    width: 100%;
    min-width: 0;
    max-width: none;
  }

  table {
    overflow: visible;
    border: 0;
    border-radius: 0;
    background: transparent;
    box-shadow: none;
  }

  thead {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
  }

  tbody {
    display: grid;
    gap: 12px;
  }

  tr {
    display: flex;
    overflow: hidden;
    border: 1px solid var(--view-border);
    border-radius: 14px;
    background: var(--view-surface);
    box-shadow: var(--shadow-soft);
    flex-direction: column;
  }

  td {
    position: relative;
    order: 10;
    padding: 11px 14px;
    border-right: 0;
    border-bottom: 1px solid var(--view-border);
  }

  td.is-pinned-field {
    position: relative;
    left: auto;
    box-shadow: none;
  }

  td::before {
    display: block;
    margin-bottom: 5px;
    color: var(--view-muted);
    content: attr(data-label);
    font-size: 11px;
    font-weight: 800;
    letter-spacing: .06em;
    text-transform: uppercase;
  }

  td[data-field-key="system:plan"] {
    order: -30;
    padding-bottom: 5px;
    border-bottom: 0;
    color: var(--view-accent);
    font-size: 15px;
    font-variant-numeric: tabular-nums;
    font-weight: 800;
  }

  td[data-field-key="system:title"] {
    order: -29;
    padding-top: 3px;
    font-size: 20px;
    font-weight: 800;
    line-height: 1.2;
  }

  td[data-field-key="system:plan"]::before,
  td[data-field-key="system:title"]::before {
    display: none;
  }

  .acks,
  .member-acks {
    order: -20;
    min-width: 0;
    gap: 7px;
  }

  .acks::before,
  .member-acks::before {
    width: 100%;
  }

  .acks button,
  .member-acks button {
    min-height: 44px;
  }

  .comments,
  .member-comments {
    order: 50;
    min-width: 0;
    max-width: none;
    border-bottom: 0;
  }

  .view-comments summary,
  .view-attachment-download,
  .comment-form button,
  .member-comment-form button,
  .cell-form button,
  .cell-form input,
  .cell-form select,
  .cell-form textarea {
    min-height: 44px;
  }

  .view-attachment-download {
    display: inline-flex;
    align-items: center;
    padding-block: 8px;
  }

  .cell-form {
    min-width: 0;
  }

  .refresh-notice button {
    display: block;
    min-height: 44px;
    margin: 10px 0 0;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    scroll-behavior: auto !important;
    transition-duration: .01ms !important;
  }
}

@media print {
  :root {
    background: var(--bg);
    color: var(--text);
  }

  body {
    background: var(--bg);
  }

  .view-header {
    position: static;
    border-color: var(--line-strong);
    background: var(--surface);
    box-shadow: none;
  }

  th.is-pinned-field,
  td.is-pinned-field {
    position: static;
    left: auto;
    box-shadow: none;
  }

  .view-exports,
  .view-back,
  .acks,
  .member-acks,
  .comments,
  .member-comments,
  .refresh-notice {
    display: none !important;
  }
}
