:root {
  --bg: #f7f4ea;
  --surface: #ffffff;
  --surface-muted: #f2ecda;
  --ink: #151421;
  --muted: #6f6b61;
  --line: #ddd4bd;
  --primary: #ffd200;
  --primary-strong: #d7ae00;
  --accent: #151421;
  --danger: #b42318;
  --danger-bg: #fff1f0;
  --success: #166534;
  --success-bg: #ecfdf3;
  --shadow: 0 18px 45px rgba(23, 33, 29, 0.11);
}

* {
  box-sizing: border-box;
}

body {
  min-height: 100vh;
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family:
    Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  line-height: 1.5;
}

a {
  color: inherit;
  text-decoration: none;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
  clip-path: inset(50%);
}

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

label {
  display: grid;
  gap: 8px;
  color: var(--ink);
  font-weight: 700;
}

label span,
.field-label {
  font-size: 0.92rem;
}

input,
select,
textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fffefa;
  color: var(--ink);
  padding: 12px 13px;
  outline: none;
}

.select-shell {
  position: relative;
  display: block;
}

.select-shell::after {
  position: absolute;
  top: 50%;
  right: 14px;
  width: 9px;
  height: 9px;
  border-right: 2px solid #7a6500;
  border-bottom: 2px solid #7a6500;
  content: "";
  pointer-events: none;
  transform: translateY(-65%) rotate(45deg);
}

.select-shell select {
  appearance: none;
  min-height: 48px;
  border-color: #d8c481;
  background: linear-gradient(180deg, #fffdf5 0%, #fbf3cf 100%);
  cursor: pointer;
  font-weight: 800;
  padding-right: 42px;
}

input:focus,
select:focus,
textarea:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(255, 210, 0, 0.28);
}

.field {
  display: grid;
  gap: 8px;
  color: var(--ink);
  font-weight: 700;
}

.file-input {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
  clip-path: inset(50%);
}

.file-picker {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  align-items: center;
  min-height: 54px;
  gap: 12px;
  border: 1px dashed #c8b35f;
  border-radius: 8px;
  background: #fffdf5;
  color: var(--ink);
  cursor: pointer;
  padding: 8px;
  transition:
    background 0.15s ease,
    border-color 0.15s ease,
    box-shadow 0.15s ease;
}

.file-picker:hover {
  border-color: var(--primary-strong);
  background: #fff8d7;
}

.file-input:focus + .file-picker,
.file-input:focus-visible + .file-picker {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(255, 210, 0, 0.28);
}

.file-button {
  display: inline-flex;
  min-height: 38px;
  align-items: center;
  justify-content: center;
  border-radius: 7px;
  background: var(--ink);
  color: var(--primary);
  font-size: 0.9rem;
  font-weight: 900;
  padding: 8px 12px;
}

.file-summary {
  overflow: hidden;
  color: var(--muted);
  font-size: 0.9rem;
  font-weight: 800;
  text-overflow: ellipsis;
  white-space: nowrap;
}

table {
  width: 100%;
  border-collapse: collapse;
}

th,
td {
  padding: 16px;
  border-bottom: 1px solid var(--line);
  text-align: left;
  vertical-align: middle;
}

th {
  color: var(--muted);
  font-size: 0.78rem;
  letter-spacing: 0;
  text-transform: uppercase;
}

td strong,
.document-row strong {
  display: block;
  font-size: 0.98rem;
}

td span,
td small,
.document-row span {
  display: block;
  color: var(--muted);
  font-size: 0.9rem;
}

.login-shell {
  display: grid;
  min-height: 100vh;
  place-items: center;
  padding: 24px;
}

.login-panel,
.panel {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: var(--shadow);
}

.login-panel {
  display: grid;
  width: min(100%, 420px);
  gap: 24px;
  padding: 32px;
}

.login-brand {
  text-align: center;
}

.brand-logo,
.login-logo {
  display: block;
  max-width: 100%;
  object-fit: cover;
}

.brand-logo {
  flex: 0 0 auto;
  width: 40px;
  height: 40px;
  border-radius: 8px;
}

.login-logo {
  width: 132px;
  height: 132px;
  border-radius: 8px;
  margin: 0 auto 18px;
}

.eyebrow {
  margin: 0 0 8px;
  color: #8a6d00;
  font-size: 0.78rem;
  font-weight: 800;
  letter-spacing: 0;
  text-transform: uppercase;
}

h1,
h2,
p {
  margin-top: 0;
}

h1 {
  margin-bottom: 0;
  font-size: clamp(2rem, 5vw, 3.4rem);
  line-height: 1.04;
}

h2 {
  margin-bottom: 12px;
  font-size: 1.1rem;
}

.stack {
  display: grid;
  gap: 18px;
}

.button {
  display: inline-flex;
  min-height: 42px;
  align-items: center;
  justify-content: center;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  color: var(--ink);
  cursor: pointer;
  font-weight: 800;
  padding: 10px 14px;
  transition:
    background 0.15s ease,
    border-color 0.15s ease,
    transform 0.15s ease;
}

.button:hover {
  transform: translateY(-1px);
}

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

.button.primary:hover {
  background: var(--primary-strong);
}

.button.ghost {
  background: transparent;
}

.button.danger {
  border-color: #ffd0cc;
  background: var(--danger-bg);
  color: var(--danger);
}

.button.compact {
  min-height: 36px;
  padding: 8px 11px;
  white-space: nowrap;
}

.button.full {
  width: 100%;
}

.topbar {
  display: grid;
  grid-template-columns: minmax(180px, 1fr) auto minmax(220px, 1fr);
  align-items: center;
  gap: 18px;
  border-bottom: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.88);
  padding: 14px 28px;
}

.brand,
.session,
.nav {
  display: flex;
  align-items: center;
}

.brand {
  gap: 10px;
  font-weight: 900;
  min-width: 0;
}

.brand span {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.nav {
  gap: 6px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface-muted);
  padding: 4px;
}

.nav a {
  border-radius: 6px;
  color: var(--muted);
  font-weight: 800;
  padding: 8px 12px;
}

.nav a.active {
  background: white;
  color: var(--ink);
}

.session {
  justify-content: flex-end;
  gap: 10px;
  color: var(--muted);
  font-weight: 700;
}

.session .role {
  border-radius: 999px;
  background: var(--surface-muted);
  color: #6d5600;
  font-size: 0.78rem;
  padding: 4px 9px;
}

.tag {
  display: inline-flex;
  align-items: center;
  border: 1px solid rgba(255, 210, 0, 0.45);
  border-radius: 999px;
  background: #fff6bf;
  color: #4e4100;
  font-size: 0.78rem;
  font-weight: 900;
  line-height: 1;
  margin: 0 8px 4px 0;
  padding: 5px 8px;
  white-space: nowrap;
}

.page {
  width: min(1180px, calc(100% - 40px));
  margin: 0 auto;
  padding: 42px 0;
}

.page-heading {
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 20px;
  margin-bottom: 26px;
}

.page-heading h1 {
  font-size: clamp(2rem, 4vw, 3rem);
}

.flash {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface-muted);
  padding: 12px 14px;
  font-weight: 750;
}

.flash.success {
  border-color: #bbf7d0;
  background: var(--success-bg);
  color: var(--success);
}

.flash.error {
  border-color: #ffd0cc;
  background: var(--danger-bg);
  color: var(--danger);
}

.search-bar {
  display: grid;
  grid-template-columns: minmax(220px, 1fr) auto;
  gap: 10px;
  align-items: center;
  margin-bottom: 22px;
}

.search-field {
  min-width: 0;
}

.search-field input {
  min-height: 46px;
}

.empty-state,
.table-wrap,
.tag-panel {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: var(--shadow);
}

.empty-state {
  display: grid;
  min-height: 260px;
  align-content: center;
  justify-items: center;
  padding: 36px;
  text-align: center;
}

.empty-state p {
  max-width: 520px;
  color: var(--muted);
}

.table-wrap {
  overflow-x: auto;
}

.tag-groups {
  display: grid;
  gap: 16px;
}

.tag-panel {
  overflow: hidden;
}

.tag-panel-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  border-bottom: 1px solid var(--line);
  background: #fffdf5;
  padding: 16px 18px;
}

.tag-panel-heading h2 {
  margin: 6px 0 0;
  font-size: 1rem;
}

.tag-document-list {
  display: grid;
}

.tag-document-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(150px, 210px) auto 34px;
  gap: 16px;
  align-items: center;
  padding: 16px 18px;
}

.tag-document-row + .tag-document-row {
  border-top: 1px solid var(--line);
}

.document-main {
  min-width: 0;
}

.document-main strong,
.document-main span,
.document-main small,
.document-stats span {
  display: block;
}

.document-main strong {
  font-size: 1rem;
}

.document-main span,
.document-main small,
.document-stats span {
  color: var(--muted);
  font-size: 0.9rem;
}

.document-main span,
.document-main small {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.document-stats {
  display: grid;
  gap: 3px;
}

.download-state {
  display: flex;
  justify-content: flex-end;
}

.download-check {
  display: inline-flex;
  width: 28px;
  height: 28px;
  align-items: center;
  justify-content: center;
  border: 1px solid #86efac;
  border-radius: 999px;
  background: #dcfce7;
  color: #15803d;
  font-size: 1rem;
  font-weight: 1000;
  line-height: 1;
}

.pagination {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 10px;
  margin-top: 18px;
}

.pagination-status {
  color: var(--muted);
  font-size: 0.9rem;
  font-weight: 800;
}

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

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

.admin-grid {
  display: grid;
  grid-template-columns: minmax(280px, 380px) 1fr;
  gap: 22px;
  align-items: start;
}

.admin-documents {
  min-width: 0;
}

.edit-layout {
  width: min(100%, 620px);
}

.readonly-file {
  display: grid;
  gap: 5px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fffdf5;
  padding: 14px;
}

.readonly-file span {
  color: #8a6d00;
  font-size: 0.78rem;
  font-weight: 900;
  text-transform: uppercase;
}

.readonly-file strong,
.readonly-file small {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.readonly-file small {
  color: var(--muted);
  font-size: 0.9rem;
}

.form-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}

.panel {
  padding: 22px;
}

.section-title {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 14px;
}

.section-title h2 {
  margin-bottom: 0;
}

.section-title span {
  border-radius: 999px;
  background: var(--surface-muted);
  color: #6d5600;
  font-weight: 900;
  min-width: 32px;
  padding: 4px 10px;
  text-align: center;
}

.document-list {
  display: grid;
  gap: 10px;
}

.document-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 14px;
}

.empty-inline {
  border: 1px dashed var(--line);
  border-radius: 8px;
  color: var(--muted);
  padding: 22px;
  text-align: center;
}

.error-page {
  min-height: calc(100vh - 88px);
  display: grid;
  place-items: center;
}

@media (max-width: 850px) {
  .topbar {
    grid-template-columns: 1fr;
    padding: 14px 18px;
  }

  .nav,
  .session {
    justify-content: flex-start;
  }

  .nav {
    width: 100%;
    overflow-x: auto;
  }

  .session {
    flex-wrap: wrap;
  }

  .page {
    width: min(100% - 28px, 1180px);
    padding: 28px 0;
  }

  .page-heading,
  .document-row {
    align-items: stretch;
    flex-direction: column;
  }

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

  .search-bar {
    grid-template-columns: 1fr;
  }

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

  .download-state {
    justify-content: flex-start;
  }

  .pagination {
    justify-content: flex-start;
    flex-wrap: wrap;
  }

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

@media (max-width: 560px) {
  th:nth-child(3),
  th:nth-child(4),
  td:nth-child(3),
  td:nth-child(4) {
    display: none;
  }

  .login-panel {
    padding: 24px;
  }

  .login-logo {
    width: 108px;
    height: 108px;
  }
}
