:root {
  color-scheme: light;
  --vellum: #e2e8dd;
  --vellum-deep: #c7d5c3;
  --paper: #fff8e7;
  --ink: #181510;
  --muted: #5c574f;
  --line: rgba(24, 21, 16, 0.24);
  --line-strong: rgba(24, 21, 16, 0.58);
  --moss: #20463b;
  --moss-soft: #d6e5d1;
  --cobalt: #254e70;
  --oxide: #943f32;
  --amber: #c58b31;
  --violet: #6c5685;
  --shadow: rgba(29, 44, 39, 0.2);
  --sans: ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  --serif: "Iowan Old Style", "Baskerville", "Palatino Linotype", Georgia, serif;
}

* {
  box-sizing: border-box;
}

html,
body {
  min-height: 100%;
}

body {
  margin: 0;
  background:
    linear-gradient(90deg, rgba(37, 78, 112, 0.12) 1px, transparent 1px),
    linear-gradient(0deg, rgba(148, 63, 50, 0.08) 1px, transparent 1px),
    radial-gradient(circle at 88% 8%, rgba(108, 86, 133, 0.18), transparent 26rem),
    var(--vellum);
  background-size: 34px 34px, 34px 34px, auto, auto;
  color: var(--ink);
  font-family: var(--sans);
  line-height: 1.45;
}

body::before {
  content: "";
  position: fixed;
  inset: 0;
  pointer-events: none;
  background:
    repeating-linear-gradient(102deg, rgba(24, 21, 16, 0.025) 0 1px, transparent 1px 8px),
    linear-gradient(90deg, rgba(226, 232, 221, 0.72), transparent 40%, rgba(223, 231, 234, 0.52));
  mix-blend-mode: multiply;
}

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

button,
label.file-button {
  cursor: pointer;
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.48;
}

[hidden] {
  display: none !important;
}

img {
  display: block;
  max-width: 100%;
}

.app-shell {
  position: relative;
  z-index: 1;
  width: min(100%, 1560px);
  min-height: 100vh;
  margin: 0 auto;
  border-right: 1px solid var(--line-strong);
  border-left: 1px solid var(--line-strong);
  background: rgba(247, 241, 223, 0.9);
  box-shadow: 0 24px 90px var(--shadow);
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  min-height: 70px;
  padding: 12px clamp(16px, 3vw, 34px);
  border-bottom: 4px double var(--line-strong);
  background: rgba(32, 70, 59, 0.96);
  color: var(--paper);
  backdrop-filter: blur(12px);
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 12px;
  color: inherit;
  text-decoration: none;
}

.brand-mark {
  width: 42px;
  height: 42px;
  display: grid;
  place-items: center;
  background: var(--paper);
  color: var(--ink);
  border: 1px solid rgba(255, 248, 231, 0.4);
  font-family: var(--serif);
  font-size: 1rem;
}

.brand strong {
  display: block;
  font-family: var(--serif);
  font-size: clamp(1.3rem, 2.5vw, 2rem);
  font-weight: 500;
  line-height: 1;
}

.brand small,
.eyebrow,
.field-label,
.field span,
.metric span,
.entry-kind,
.entry-row small,
.relation-item span,
.relation-item small,
.mini-button,
.text-button,
.primary-button,
.status-tab,
.filter-chip {
  font-family: var(--sans);
}

.brand small {
  color: var(--moss-soft);
  font-size: 0.74rem;
  font-weight: 800;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.top-actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 8px;
}

#import-file {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  opacity: 0;
  pointer-events: none;
}

.text-button,
.primary-button,
.icon-button,
.mini-button,
.filter-chip,
.status-tab {
  min-height: 38px;
  border: 1px solid var(--line-strong);
  background: rgba(255, 248, 231, 0.82);
  color: var(--ink);
}

.topbar .text-button,
.topbar .icon-button,
.topbar .file-button {
  background: rgba(255, 248, 231, 0.94);
  color: var(--ink);
  border-color: rgba(255, 248, 231, 0.58);
}

.text-button,
.primary-button {
  padding: 8px 12px;
  font-weight: 800;
}

.icon-button {
  width: 42px;
  padding: 0;
  font-size: 1.45rem;
  line-height: 1;
}

.primary-button {
  background: var(--moss);
  color: var(--paper);
  border-color: var(--moss);
}

.danger {
  color: var(--oxide);
}

.workspace {
  display: grid;
  grid-template-columns: minmax(250px, 0.78fr) minmax(480px, 1.5fr) minmax(280px, 0.88fr);
  gap: 0;
  min-height: calc(100vh - 70px);
}

.library-panel,
.detail-panel,
.context-panel {
  min-width: 0;
}

.library-panel {
  border-right: 1px solid var(--line-strong);
  background:
    linear-gradient(180deg, rgba(32, 70, 59, 0.16), transparent 22rem),
    #dce8d7;
}

.context-panel {
  border-left: 1px solid var(--line-strong);
  background:
    linear-gradient(180deg, rgba(37, 78, 112, 0.14), transparent 20rem),
    #dfe7ea;
}

.search-block,
.filter-block,
.status-tabs,
.plate-panel,
.metrics-panel,
.relations-panel,
.validation-panel {
  padding: 18px;
  border-bottom: 1px solid var(--line);
}

.panel-heading,
.editor-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
}

.eyebrow,
.field-label,
.field span {
  margin: 0;
  color: var(--oxide);
  font-size: 0.72rem;
  font-weight: 900;
  letter-spacing: 0.12em;
  text-transform: uppercase;
}

#entry-total {
  color: var(--muted);
  font-size: 0.82rem;
  font-weight: 800;
}

.field-label {
  display: block;
  margin: 14px 0 6px;
}

input,
select,
textarea {
  width: 100%;
  border: 1px solid var(--line-strong);
  background: rgba(255, 248, 231, 0.92);
  color: var(--ink);
  padding: 10px 11px;
}

textarea {
  resize: vertical;
}

input:focus,
select:focus,
textarea:focus,
button:focus-visible,
label.file-button:focus-visible {
  outline: 3px solid rgba(197, 139, 49, 0.38);
  outline-offset: 2px;
}

.filter-block,
.status-tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.filter-chip,
.status-tab,
.mini-button {
  padding: 7px 10px;
  font-size: 0.78rem;
  font-weight: 900;
}

.filter-chip.active,
.status-tab.active {
  background: var(--ink);
  color: var(--paper);
}

.entry-list {
  display: grid;
  max-height: calc(100vh - 285px);
  overflow: auto;
}

.entry-row {
  display: grid;
  grid-template-columns: 84px minmax(0, 1fr);
  gap: 5px 12px;
  width: 100%;
  border: 0;
  border-bottom: 1px solid var(--line);
  background: transparent;
  color: inherit;
  padding: 14px 18px;
  text-align: left;
}

.entry-row:hover,
.entry-row[aria-selected="true"] {
  background: rgba(32, 70, 59, 0.13);
}

.entry-kind {
  grid-row: span 2;
  align-self: start;
  color: var(--cobalt);
  font-size: 0.66rem;
  font-weight: 900;
  letter-spacing: 0.1em;
  text-transform: uppercase;
}

.entry-row strong {
  min-width: 0;
  overflow-wrap: anywhere;
  font-family: var(--serif);
  font-size: 1.05rem;
  font-weight: 700;
  line-height: 1.1;
}

.entry-row small {
  color: var(--muted);
  font-size: 0.78rem;
  overflow-wrap: anywhere;
}

.empty-state {
  margin: 0;
  padding: 14px 18px;
  color: var(--muted);
}

.detail-panel {
  padding: clamp(18px, 3vw, 34px);
}

.editor-toolbar {
  align-items: start;
  margin-bottom: 22px;
  padding-bottom: 18px;
  border-bottom: 4px double var(--line-strong);
}

.editor-toolbar h1 {
  margin: 4px 0 0;
  font-family: var(--serif);
  font-size: clamp(2rem, 5vw, 4.4rem);
  font-weight: 500;
  line-height: 0.94;
  overflow-wrap: anywhere;
}

.record-actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 8px;
}

.form-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 14px;
}

.field {
  display: grid;
  gap: 6px;
}

.field.wide {
  grid-column: 1 / -1;
}

.field textarea {
  min-height: 104px;
}

#body-input {
  min-height: 218px;
}

.plate-panel figure {
  margin: 0;
  padding: 12px;
  border: 1px solid var(--line-strong);
  background: var(--paper);
}

.plate-panel img {
  width: 100%;
  aspect-ratio: 4 / 3;
  object-fit: contain;
  border: 1px solid var(--line);
  background:
    radial-gradient(circle at 50% 42%, rgba(214, 229, 209, 0.85), transparent 62%),
    var(--vellum);
}

figcaption {
  margin-top: 10px;
  border-top: 1px solid var(--line);
  padding-top: 9px;
  color: var(--muted);
  font-family: var(--serif);
  font-size: 0.95rem;
  font-style: italic;
}

.metric-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
  margin-top: 12px;
}

.metric {
  border-left: 4px solid var(--cobalt);
  background: rgba(255, 248, 231, 0.72);
  padding: 8px 10px;
}

.metric:nth-child(2n) {
  border-left-color: var(--amber);
}

.metric strong {
  display: block;
  font-family: var(--serif);
  font-size: 1.7rem;
  line-height: 1;
}

.metric span {
  color: var(--muted);
  font-size: 0.72rem;
  font-weight: 900;
  text-transform: uppercase;
}

.relation-adder {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 8px;
  margin-top: 12px;
}

.relation-list {
  display: grid;
  gap: 10px;
  margin-top: 12px;
}

.relation-item {
  position: relative;
  display: grid;
  gap: 3px;
  padding: 10px 38px 10px 12px;
  border: 1px solid var(--line);
  background: rgba(255, 248, 231, 0.7);
}

.relation-title {
  border: 0;
  background: transparent;
  color: var(--ink);
  padding: 0;
  text-align: left;
  font-family: var(--serif);
  font-size: 1rem;
  font-weight: 700;
  text-decoration: underline;
  text-decoration-thickness: 1px;
  text-underline-offset: 0.18em;
}

.relation-item span {
  color: var(--violet);
  font-size: 0.72rem;
  font-weight: 900;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.relation-item small {
  color: var(--muted);
}

.remove-relation {
  position: absolute;
  top: 7px;
  right: 7px;
  width: 26px;
  height: 26px;
  border: 1px solid var(--line);
  background: rgba(255, 248, 231, 0.9);
  color: var(--oxide);
}

.validation-panel ul {
  display: grid;
  gap: 8px;
  margin: 12px 0 0;
  padding: 0;
  list-style: none;
}

.validation-panel li {
  padding-left: 18px;
  color: var(--muted);
  position: relative;
}

.validation-panel li::before {
  content: "";
  position: absolute;
  top: 0.6em;
  left: 0;
  width: 8px;
  height: 8px;
  background: var(--amber);
}

.validation-panel li.passes::before {
  background: var(--moss);
}

.validation-panel li.needs-work::before {
  background: var(--oxide);
}

.fatal-error {
  max-width: 720px;
  margin: 12vh auto;
  padding: 28px;
  background: var(--paper);
  border: 1px solid var(--line-strong);
}

@media (max-width: 1180px) {
  .workspace {
    grid-template-columns: minmax(240px, 0.8fr) minmax(420px, 1.3fr);
  }

  .context-panel {
    grid-column: 1 / -1;
    display: grid;
    grid-template-columns: minmax(260px, 0.8fr) repeat(3, minmax(0, 1fr));
    border-top: 1px solid var(--line-strong);
    border-left: 0;
  }

  .plate-panel,
  .metrics-panel,
  .relations-panel,
  .validation-panel {
    border-right: 1px solid var(--line);
  }
}

@media (max-width: 840px) {
  .topbar {
    position: static;
    align-items: flex-start;
    flex-direction: column;
  }

  .top-actions {
    justify-content: flex-start;
  }

  .workspace,
  .context-panel {
    display: block;
  }

  .library-panel,
  .context-panel {
    border: 0;
  }

  .entry-list {
    max-height: 360px;
    border-bottom: 1px solid var(--line-strong);
  }

  .editor-toolbar {
    display: grid;
  }

  .record-actions {
    justify-content: start;
  }

  .form-grid {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 520px) {
  .brand {
    align-items: flex-start;
  }

  .brand-mark {
    width: 36px;
    height: 36px;
  }

  .top-actions,
  .record-actions {
    width: 100%;
  }

  .text-button,
  .primary-button,
  .file-button {
    flex: 1 1 auto;
    text-align: center;
  }

  .entry-row {
    grid-template-columns: 1fr;
  }

  .entry-kind {
    grid-row: auto;
  }
}
