/* ── Tokens ── */
:root {
  --bg:          #faf9f6;
  --surface:     #ffffff;
  --border:      #ddd9d0;
  --border-light:#ede9e0;
  --text:        #1c1a17;
  --text-muted:  #6b6560;
  --accent:      #5a3e28;
  --accent-light:#7a5a3e;
  --link:        #3b5a8a;
  --link-hover:  #2a4270;
  --tag-bg:      #ede9e0;
  --tag-text:    #4a4038;
  --row-hover:   #f5f3ee;
  --radius:      4px;
  --radius-lg:   8px;
  --shadow:      0 1px 4px rgba(0,0,0,.08);
  --shadow-lg:   0 4px 24px rgba(0,0,0,.15);
  --font-body:   'Georgia', 'Times New Roman', serif;
  --font-ui:     system-ui, -apple-system, sans-serif;
}

/* ── Reset ── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
img { display: block; max-width: 100%; }
button, input, select { font: inherit; }

/* ── Base ── */
html { font-size: 16px; scroll-behavior: smooth; }
body {
  font-family: var(--font-body);
  background: var(--bg);
  color: var(--text);
  line-height: 1.6;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

/* ── Skip link ── */
.skip-link {
  position: absolute;
  top: -100%;
  left: 1rem;
  padding: .4rem .8rem;
  background: var(--accent);
  color: #fff;
  border-radius: var(--radius);
  font-family: var(--font-ui);
  font-size: .875rem;
  text-decoration: none;
  z-index: 9999;
}
.skip-link:focus { top: 1rem; }

/* Screen-reader only */
.sr-only {
  position: absolute; width: 1px; height: 1px;
  padding: 0; margin: -1px; overflow: hidden;
  clip: rect(0,0,0,0); white-space: nowrap; border: 0;
}

/* ── Header ── */
header {
  background: var(--accent);
  color: #fff;
  padding: 2.5rem 2rem 2rem;
  border-bottom: 3px solid rgba(255,255,255,.1);
}
.header-inner { max-width: 1100px; margin: 0 auto; }
header h1 {
  font-size: clamp(1.4rem, 3vw, 2rem);
  font-weight: normal;
  letter-spacing: .01em;
}
.subtitle {
  font-family: var(--font-ui);
  font-size: .875rem;
  opacity: .75;
  margin-top: .25rem;
  letter-spacing: .08em;
  text-transform: uppercase;
}

/* ── Main ── */
main {
  max-width: 1100px;
  width: 100%;
  margin: 0 auto;
  padding: 2rem 1.5rem;
  flex: 1;
}

/* ── Controls ── */
.controls {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 1.25rem 1.5rem;
  margin-bottom: 1.25rem;
  box-shadow: var(--shadow);
}

.search-wrap { margin-bottom: 1rem; }

#search {
  width: 100%;
  padding: .6rem .85rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-family: var(--font-ui);
  font-size: 1rem;
  background: var(--bg);
  color: var(--text);
  transition: border-color .15s, box-shadow .15s;
}
#search:focus {
  outline: none;
  border-color: var(--accent-light);
  box-shadow: 0 0 0 3px rgba(90,62,40,.15);
}

.filter-row {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  gap: 1rem;
}

.filter-group {
  display: flex;
  flex-direction: column;
  gap: .3rem;
}
.filter-group label {
  font-family: var(--font-ui);
  font-size: .75rem;
  text-transform: uppercase;
  letter-spacing: .06em;
  color: var(--text-muted);
}

select {
  padding: .5rem .75rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-ui);
  font-size: .9rem;
  cursor: pointer;
}
select:focus {
  outline: none;
  border-color: var(--accent-light);
  box-shadow: 0 0 0 3px rgba(90,62,40,.15);
}


.btn-ghost {
  padding: .5rem .9rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: transparent;
  color: var(--text-muted);
  font-family: var(--font-ui);
  font-size: .85rem;
  cursor: pointer;
  transition: border-color .15s, color .15s;
}
.btn-ghost:hover { border-color: var(--accent-light); color: var(--accent); }

/* ── Results header ── */
.results-header {
  font-family: var(--font-ui);
  font-size: .8rem;
  color: var(--text-muted);
  margin-bottom: .6rem;
  padding-left: .1rem;
  text-transform: uppercase;
  letter-spacing: .05em;
}

/* ── Table ── */
.table-wrap {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  overflow: auto;
  box-shadow: var(--shadow);
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: .95rem;
}

thead th {
  background: #f2efe8;
  font-family: var(--font-ui);
  font-size: .75rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .07em;
  color: var(--text-muted);
  padding: .75rem 1rem;
  border-bottom: 2px solid var(--border);
  white-space: nowrap;
  user-select: none;
}

th.sortable {
  cursor: pointer;
  transition: background .15s, color .15s;
}
th.sortable:hover { background: #e8e3d8; color: var(--accent); }
th[aria-sort="ascending"]  { color: var(--accent); }
th[aria-sort="descending"] { color: var(--accent); }

.sort-icon::after { content: ' ⇕'; font-size: .65rem; opacity: .5; }
th[aria-sort="ascending"]  .sort-icon::after { content: ' ↑'; opacity: 1; }
th[aria-sort="descending"] .sort-icon::after { content: ' ↓'; opacity: 1; }

td {
  padding: .85rem 1rem;
  border-bottom: 1px solid var(--border-light);
  vertical-align: top;
}
tr:last-child td { border-bottom: none; }
tr:hover td { background: var(--row-hover); }

.col-title  { width: 46%; }
.col-author { width: 20%; }
.col-action { width: 8%;  text-align: center; }

.doc-title {
  font-size: 1rem;
  margin-bottom: .2rem;
  color: var(--text);
}
.doc-tags {
  display: flex;
  flex-wrap: wrap;
  gap: .25rem;
  margin-top: .35rem;
}
.tag {
  display: inline-block;
  padding: .1rem .45rem;
  background: var(--tag-bg);
  color: var(--tag-text);
  border-radius: 3px;
  font-family: var(--font-ui);
  font-size: .7rem;
  letter-spacing: .02em;
}


.category-cell {
  font-family: var(--font-ui);
  font-size: .85rem;
  color: var(--text-muted);
}

.btn-view {
  display: inline-block;
  padding: .35rem .7rem;
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: var(--radius);
  font-family: var(--font-ui);
  font-size: .8rem;
  cursor: pointer;
  text-decoration: none;
  transition: background .15s;
  white-space: nowrap;
}
.btn-view:hover { background: var(--accent-light); }
.btn-view:focus {
  outline: none;
  box-shadow: 0 0 0 3px rgba(90,62,40,.3);
}

/* ── Empty state ── */
.empty-state {
  text-align: center;
  padding: 3rem 1rem;
  font-family: var(--font-ui);
  color: var(--text-muted);
}

/* ── Modal ── */
dialog {
  position: fixed;
  inset: 0;
  width: 100%;
  max-width: 100%;
  height: 100%;
  max-height: 100%;
  margin: 0;
  padding: 0;
  border: none;
  background: var(--surface);
  display: flex;
  flex-direction: column;
  z-index: 1000;
}
dialog:not([open]) { display: none; }
dialog::backdrop {
  background: rgba(0,0,0,.55);
  backdrop-filter: blur(2px);
}

.modal-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 1rem;
  padding: 1.25rem 1.5rem 1rem;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
  background: #f9f7f3;
}
.modal-meta h2 {
  font-size: 1.1rem;
  font-weight: normal;
  color: var(--text);
}
.modal-meta p {
  font-family: var(--font-ui);
  font-size: .8rem;
  color: var(--text-muted);
  margin-top: .2rem;
}
.modal-actions {
  display: flex;
  align-items: center;
  gap: .5rem;
  flex-shrink: 0;
}
.btn-secondary {
  padding: .4rem .8rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: transparent;
  color: var(--accent);
  font-family: var(--font-ui);
  font-size: .8rem;
  cursor: pointer;
  text-decoration: none;
  transition: background .15s;
  white-space: nowrap;
}
.btn-secondary:hover { background: var(--tag-bg); }
.btn-icon {
  width: 2rem;
  height: 2rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: transparent;
  color: var(--text-muted);
  cursor: pointer;
  font-size: 1rem;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background .15s;
}
.btn-icon:hover { background: var(--tag-bg); color: var(--text); }

.modal-body {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  padding: 0;
}
#modal-description {
  font-size: .9rem;
  color: var(--text-muted);
  padding: .75rem 1.5rem;
  border-bottom: 1px solid var(--border-light);
  flex-shrink: 0;
}
#modal-description:empty { display: none; }

.pdf-frame-wrap {
  flex: 1;
  overflow: hidden;
}
#pdf-frame {
  width: 100%;
  height: 100%;
  border: none;
  display: block;
}

/* ── Footer ── */
footer {
  text-align: center;
  padding: 1.5rem 1rem;
  font-family: var(--font-ui);
  font-size: .78rem;
  color: var(--text-muted);
  border-top: 1px solid var(--border);
  margin-top: auto;
}

/* ── Responsive ── */
@media (max-width: 700px) {
  header { padding: 1.5rem 1rem 1.25rem; }
  main   { padding: 1.25rem 1rem; }

  .filter-row { flex-direction: column; align-items: stretch; }
  .filter-group { width: 100%; }
  select { width: 100%; }

.col-author, .col-category { display: none; }
  td, th { padding: .7rem .75rem; }

  .modal-header { flex-wrap: wrap; }
  .modal-actions { width: 100%; justify-content: flex-end; }
}
