:root {
  --bg: #f5f2ea;
  --card: #fffdf8;
  --line: #ddd3c2;
  --text: #2b2620;
  --muted: #6f6558;
  --accent: #7a5c3e;
  --success: #2f855a;
  --warning: #b7791f;
}
* { box-sizing: border-box; }
body {
  margin: 0;
  font-family: "Trebuchet MS", Verdana, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
}
a { color: #5a3f23; text-decoration: none; }
a:hover { text-decoration: underline; }
.wrap { max-width: 1180px; margin: 0 auto; padding: 1rem; }
.site-header {
  position: relative;
  background: #efe7d8;
  border-bottom: 1px solid var(--line);
}
.site-header .wrap {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 2rem;
  position: relative;
}
.site-header h1 { margin: 0; font-size: 1.7rem; }
.subtitle { margin: .2rem 0 0 0; color: var(--muted); max-width: 52rem; }
.header-brand { min-width: 0; }
.main-nav { margin-top: .6rem; padding-right: 11rem; justify-content: flex-end; }
header nav { display: flex; gap: 1rem; flex-wrap: wrap; }
nav { display: flex; gap: 1rem; flex-wrap: wrap; }
nav a { padding: .35rem .55rem; border-radius: .35rem; }
nav a:hover { background: rgba(122, 92, 62, .09); }
nav a.active {
  font-weight: bold;
  border: 1px solid rgba(122, 92, 62, .45);
  background: rgba(122, 92, 62, .08);
}
.user-nav {
  display: flex;
  gap: .75rem;
  align-items: center;
  justify-content: flex-end;
  flex-wrap: wrap;
}
.header-corner {
  position: absolute;
  top: .9rem;
  right: 1rem;
  z-index: 40;
  padding: .35rem .45rem;
  border: 1px solid var(--line);
  border-radius: .6rem;
  background: rgba(245, 242, 234, .96);
  box-shadow: 0 1px 2px rgba(0, 0, 0, .05);
}
.user-nav form { margin: 0; }
.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: .6rem;
  padding: 1rem 1.1rem;
  margin-bottom: 1rem;
  box-shadow: 0 1px 2px rgba(0,0,0,.03);
}
.hero { padding: 1.2rem 1.25rem; }
.stats-grid, .two-col, .parallel-grid { display: grid; gap: 1rem; }
.stats-grid { grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); }
.two-col, .parallel-grid { grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); }
.stat { text-align: center; }
.stat strong { display: block; font-size: 2rem; }
.muted { color: var(--muted); }
.toolbar .filters { display: flex; gap: .6rem; flex-wrap: wrap; align-items: flex-start; }
.filter-search-wide { flex: 1 1 24rem; min-width: 18rem; }
.filter-search-stack {
  display: flex;
  flex: 1 1 24rem;
  min-width: 18rem;
  flex-direction: column;
  align-items: flex-start;
  gap: .2rem;
}
.filter-search-stack .filter-search-wide {
  width: 100%;
  flex: 0 1 auto;
}
.filter-toggle {
  padding: 0;
  border: 0;
  background: transparent;
  color: var(--accent);
  cursor: pointer;
  font: inherit;
  text-decoration: underline;
  font-size: .88rem;
}
.date-filter-panel {
  width: 100%;
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: .8rem 1rem;
  padding-top: .25rem;
}
input[type="search"], input[type="text"], input[type="password"], textarea, select, button, .button {
  padding: .55rem .7rem;
  border: 1px solid #bfb29f;
  border-radius: .4rem;
  font: inherit;
  background: white;
}
input[type="color"] {
  padding: .2rem;
  border: 1px solid #bfb29f;
  border-radius: .4rem;
  background: white;
  width: 4rem;
  min-width: 4rem;
  height: 2.65rem;
}
textarea { width: 100%; min-height: 7rem; resize: vertical; }
button, .button { background: #6f5336; color: #fff; cursor: pointer; }
.button.secondary { background: #8f7b63; }
.button.ghost {
  background: transparent;
  color: var(--accent);
  border-color: var(--line);
}
.hidden { display: none !important; }
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: .7rem; border-bottom: 1px solid #e5dccd; vertical-align: top; }
th { background: #faf5ee; }
.sort-link {
  display: inline-flex;
  align-items: center;
  gap: .3rem;
  color: inherit;
  text-decoration: none;
  padding: .18rem .45rem;
  border-radius: .35rem;
}
.sort-link:hover { text-decoration: none; }
.sort-link.active {
  font-weight: bold;
  border: 1px solid rgba(122, 92, 62, .45);
  background: rgba(122, 92, 62, .08);
}
.sort-arrow {
  color: var(--accent);
  font-size: .95em;
}
.link-list { list-style: none; padding: 0; margin: 0; }
.link-list li { padding: .45rem 0; border-bottom: 1px solid #eee3d5; }
.link-list li:last-child { border-bottom: none; }
.meta-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: .75rem 1rem; }
.meta-grid dt { font-weight: bold; color: var(--muted); }
.meta-grid dd { margin: .15rem 0 0 0; }
.full-width-meta {
  grid-column: 1 / -1;
}
.entry-block { padding: .65rem 0; border-bottom: 1px solid #eee3d5; }
.entry-block:last-child { border-bottom: none; }
.entry-head, .section-head { display: flex; justify-content: space-between; gap: 1rem; align-items: start; flex-wrap: wrap; }
.title-row { display: flex; justify-content: space-between; align-items: start; gap: 1rem; }
.title-actions { display: flex; gap: .75rem; align-items: center; flex-wrap: wrap; justify-content: end; }
.tab-nav {
  display: flex;
  gap: .65rem;
  flex-wrap: wrap;
  margin-bottom: 1rem;
}
.tab-button {
  background: #f7f1e6;
  color: var(--muted);
  border-color: var(--line);
}
.tab-button.active {
  background: #6f5336;
  color: #fff;
}
.person-tab-panel { display: none; }
.person-tab-panel.active { display: block; }
.person-tab-section:last-child { margin-bottom: 0; }
.card-section-head {
  margin: -1rem -1.1rem 1rem -1.1rem;
  padding: .85rem 1rem;
  background: #faf5ee;
  border-bottom: 1px solid #e5dccd;
  border-radius: .6rem .6rem 0 0;
}
.card-section-head h3 {
  margin: 0;
}
.long-text-block {
  white-space: pre-wrap;
  line-height: 1.7;
}
.source-text-block,
.source-text-input {
  font-family: Georgia, "Times New Roman", serif;
}
.annotatable-text {
  cursor: text;
  user-select: text;
}
.selection-actions {
  display: flex;
  gap: .6rem;
  margin-top: .75rem;
  flex-wrap: wrap;
}
.text-annotation-highlight {
  border-radius: .18rem;
  padding: 0 .04em;
}
.annotation-fragment {
  margin-top: .35rem;
  padding: .5rem .6rem;
  background: rgba(255, 255, 255, .6);
  border-radius: .35rem;
  font-style: italic;
  white-space: pre-wrap;
}
.badge { display: inline-block; padding: .2rem .5rem; border-radius: 999px; font-size: .86rem; border: 1px solid transparent; }
.badge-success { background: #e8f7ee; color: #256d4a; border-color: #c4e8d1; }
.badge-warning { background: #fff6e5; color: #946200; border-color: #f2dfa9; }
.badge-neutral { background: #f2f2f2; color: #555; border-color: #ddd; }
.segment-block { padding: .8rem 0; border-bottom: 1px solid #eee3d5; }
.segment-head { font-weight: bold; margin-bottom: .35rem; color: var(--muted); }
.annotation-chip {
  margin-top: .5rem;
  padding: .45rem .6rem;
  background: #faf8f4;
  border-left: 4px solid #666;
  font-size: .95rem;
}
.annotation-chip-head {
  display: flex;
  justify-content: space-between;
  gap: .75rem;
  align-items: start;
}
.aligned-paragraph-list {
  display: grid;
  gap: 1rem;
}
.aligned-paragraph-row {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 1rem;
  align-items: start;
}
.paragraph-panel {
  min-width: 0;
  padding: .95rem 1rem;
  border: 1px solid #eee3d5;
  border-radius: .6rem;
  background: #fff;
}
.long-text-card {
  min-height: 9rem;
  padding: .9rem 1rem;
  border: 1px solid #e5dccd;
  border-radius: .5rem;
  background: #faf7f1;
}
.theme-list { display: grid; grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); gap: .8rem; }
.theme-card { display: block; background: #fff; padding: .85rem; border: 1px solid #e5dccd; border-left: 6px solid #666; border-radius: .5rem; }
.theme-card span, .theme-card small { display: block; color: var(--muted); margin-top: .3rem; }
.theme-card-admin {
  position: relative;
  min-height: 9.5rem;
  padding-right: 8rem;
}
.theme-card-actions {
  position: absolute;
  top: 1rem;
  right: 1rem;
}
.annotation-item-head {
  display: flex;
  justify-content: space-between;
  gap: 1rem;
  align-items: start;
}
.annotation-item-head .annotation-meta {
  flex: 1 1 auto;
  min-width: 0;
}
.annotation-item blockquote { margin: 1rem 0 0 0; padding: 1rem; background: #faf7f1; border-left: 4px solid var(--accent); }
.annotation-note { margin-top: .65rem; }
.annotation-meta { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: .75rem; }
.flash-stack { margin: 1rem 0; display: grid; gap: .6rem; }
.flash { padding: .8rem 1rem; border-radius: .5rem; border: 1px solid var(--line); background: #fffdf8; }
.flash-success { background: #edf8f1; border-color: #bfe0c8; color: #256d4a; }
.flash-error { background: #fff1ef; border-color: #f2c0b8; color: #9b2c2c; }
.flash-warning { background: #fff7e6; border-color: #ead39d; color: #8b6a1f; }
.form-card { max-width: 980px; margin: 0 auto 1rem auto; }
.login-card { max-width: 520px; margin-top: 2rem; }
.form-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: 1rem; }
.embassy-form-top-row {
  grid-column: 1 / -1;
  display: grid;
  grid-template-columns: minmax(0, 1.5fr) minmax(180px, .7fr);
  gap: 1rem;
  align-items: start;
}
.embassy-year-field {
  justify-self: stretch;
}
.field { display: grid; gap: .35rem; }
.field label { font-weight: bold; color: var(--muted); }
.field.full { grid-column: 1 / -1; }
.inline-date-field { display: flex; gap: .5rem; align-items: stretch; flex-wrap: wrap; }
.inline-select-action { display: flex; gap: .5rem; align-items: stretch; }
.inline-select-action input { flex: 1 1 auto; min-width: 0; }
.inline-select-action select { flex: 1 1 auto; min-width: 0; }
.biography-reference-row {
  flex-wrap: nowrap;
}
.biography-reference-row input,
.biography-reference-row .button {
  min-height: 2.45rem;
}
.biography-reference-row .button {
  white-space: nowrap;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}
.inline-copy-field {
  display: flex;
  gap: .5rem;
  align-items: stretch;
  flex-wrap: wrap;
}
.inline-copy-field input {
  flex: 1 1 12rem;
  min-width: 0;
}
.date-pill {
  min-width: 180px;
  min-height: 2.45rem;
  padding: .55rem .7rem;
  border: 1px solid #bfb29f;
  border-radius: .4rem;
  background: #fff;
  display: flex;
  align-items: center;
}
.iso-date-mask-input {
  font-family: "Courier New", Consolas, monospace;
  font-variant-numeric: tabular-nums;
  letter-spacing: .08em;
}
.iso-date-mask-input::placeholder {
  color: #8b8174;
  opacity: 1;
}
.color-picker-row {
  display: flex;
  gap: .6rem;
  align-items: center;
  flex-wrap: wrap;
}
.color-code-preview {
  min-width: 7.5rem;
}
.icon-action {
  min-width: 2.35rem;
  width: 2.35rem;
  min-height: 2.45rem;
  height: auto;
  padding: 0;
  display: inline-grid;
  place-items: center;
  font-size: 1rem;
  line-height: 1;
}
.checkbox-field { align-content: center; }
.checkbox-field label { display: flex; gap: .55rem; align-items: center; color: var(--text); font-weight: normal; }
.form-actions { display: flex; gap: .75rem; flex-wrap: wrap; margin-top: 1rem; }
.table-action { display: inline-block; margin-left: .4rem; font-size: .92rem; }
.add-action {
  display: inline-flex;
  align-items: center;
  gap: .45rem;
}
.text-action {
  padding-left: .7rem;
  padding-right: .7rem;
}
.icon-only-action {
  justify-content: center;
  min-width: 2.2rem;
  width: 2.2rem;
  min-height: 2.2rem;
  padding: 0;
  font-size: 1.35rem;
  line-height: 1;
}
.icon-link {
  display: inline-grid;
  place-items: center;
  min-width: 2rem;
  width: 2rem;
  min-height: 2rem;
  padding: 0;
  border: 1px solid var(--line);
  border-radius: .4rem;
  background: #faf5ee;
  color: var(--accent);
  text-decoration: none;
  line-height: 1;
}
.icon-link:hover {
  background: #f1e8da;
  text-decoration: none;
}
.icon-button {
  appearance: none;
  cursor: pointer;
  font: inherit;
}
.table-icon-actions {
  display: flex;
  justify-content: end;
  gap: .4rem;
}
.inline-icon-form {
  margin: 0;
}
.inline-icon-link {
  margin-left: .4rem;
  vertical-align: middle;
}
.modal-shell {
  position: fixed;
  inset: 0;
  z-index: 1000;
  display: grid;
  place-items: center;
}
.modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(43, 38, 32, .45);
}
.modal-card {
  position: relative;
  z-index: 1;
  width: min(760px, calc(100vw - 2rem));
  max-height: calc(100vh - 2rem);
  overflow: auto;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: .8rem;
  padding: 1rem 1.1rem;
  box-shadow: 0 20px 50px rgba(0,0,0,.18);
}
.modal-card-wide {
  width: min(960px, calc(100vw - 2rem));
}
.large-textarea {
  min-height: 20rem;
}
@media (max-width: 700px) {
  .site-header .wrap {
    display: block;
  }
  .main-nav {
    margin-top: .85rem;
    padding-right: 0;
  }
  .header-corner {
    position: static;
    margin: 0 auto 1rem auto;
    width: min(1180px, calc(100vw - 2rem));
    padding: 0;
    border: 0;
    border-radius: 0;
    background: transparent;
    box-shadow: none;
    justify-content: flex-start;
  }
  th:nth-child(n+4), td:nth-child(n+4) { display: none; }
  .aligned-paragraph-row { grid-template-columns: 1fr; }
}
