:root {
  font-family: Inter, 'Segoe UI', Arial, sans-serif;
  color-scheme: dark;
  --bg: #211a16;
  --panel: #30241d;
  --input: #261c16;
  --ink: #f2e5ce;
  --muted: #c1ab8d;
  --line: #604b3b;
  --gold: #d4ad66;
  --green: #b5c997;
  --danger: #f4aaa0;
  color: var(--ink);
  background: var(--bg);
}
:root[data-theme='light'] {
  color-scheme: light;
  --bg: #f5f2e9;
  --panel: #fffdf5;
  --input: #ffffff;
  --ink: #263d38;
  --muted: #516c5d;
  --line: #bac8b2;
  --gold: #997439;
  --green: #486b45;
  --danger: #a3362a;
}
* {
  box-sizing: border-box;
}
body {
  margin: 0;
  min-height: 100vh;
  background:
    radial-gradient(circle at 90% 0, #8c633422, transparent 38%),
    radial-gradient(circle at 0 100%, #71815422, transparent 38%), var(--bg);
}
button,
input,
select {
  font: inherit;
  color: inherit;
}
button {
  cursor: pointer;
}
button:disabled {
  opacity: 0.5;
  cursor: default;
}
button:focus-visible,
a:focus-visible,
input:focus-visible,
select:focus-visible {
  outline: 2px solid var(--gold);
  outline-offset: 3px;
}
.hidden {
  display: none !important;
}
.shell {
  width: min(1280px, calc(100% - 48px));
  margin: auto;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}
.topbar {
  min-height: 94px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 20px;
  border-bottom: 1px solid var(--line);
  padding: 16px 0;
}
.brand {
  text-decoration: none;
  color: inherit;
  display: flex;
  align-items: center;
  gap: 14px;
  min-width: 0;
}
.brand strong,
.brand small {
  display: block;
}
.brand strong {
  font-family: Georgia, serif;
  font-size: 1.45rem;
  letter-spacing: 0.02em;
}
.brand small {
  font-size: 0.73rem;
  color: var(--muted);
  letter-spacing: 0.04em;
  margin-top: 4px;
}
.sigil {
  width: 48px;
  height: 48px;
  flex-shrink: 0;
  display: grid;
  place-items: center;
  border: 1px solid var(--gold);
  border-radius: 12px;
  color: var(--gold);
  background: #d4ad6610;
  font-size: 1.45rem;
}
.header-actions {
  display: flex;
  align-items: center;
  gap: 10px;
}
.ghost,
.primary,
.danger,
.tab {
  border-radius: 8px;
  padding: 12px 16px;
  border: 1px solid var(--line);
  font: inherit;
  background: transparent;
  color: var(--ink);
}
.ghost:hover {
  border-color: var(--gold);
  color: var(--gold);
}
.primary {
  border-color: #d4ad66;
  background: #d4ad66;
  color: #211a16;
  font-weight: 650;
}
.primary:hover {
  background: #edc984;
}
.danger {
  border-color: var(--danger);
  color: var(--danger);
  background: #be55441a;
  font-weight: 600;
}
.danger:hover {
  background: #be554430;
}
.compact {
  padding: 9px 13px;
  font-size: 0.85rem;
}
.theme-toggle {
  min-width: 44px;
  font-size: 1.2rem;
  line-height: 1;
}
main {
  padding: 60px 0 70px;
  flex: 1;
  min-width: 0;
}
.eyebrow,
.section-index {
  font-size: 0.7rem;
  letter-spacing: 0.19em;
  color: var(--gold);
  font-weight: 700;
}
h1,
h2 {
  font-family: Georgia, serif;
  font-weight: 500;
}
h1 {
  font-size: clamp(2.4rem, 6vw, 4.7rem);
  line-height: 1.08;
  max-width: 900px;
  margin: 20px 0;
}
h2 {
  font-size: 1.8rem;
  margin: 10px 0;
}
h3 {
  font-size: 0.95rem;
  margin: 24px 0 12px;
}
.lead {
  color: var(--muted);
  font-size: 1rem;
  line-height: 1.6;
  max-width: 670px;
  margin: 0 0 36px;
}
:root[data-authenticated='true'] main {
  padding-top: 36px;
}
:root[data-authenticated='true'] h1 {
  font-size: clamp(2rem, 4vw, 3rem);
}
.panel {
  border: 1px solid var(--line);
  background: var(--panel);
  border-radius: 16px;
  box-shadow: 0 24px 50px #140e0b22;
}
.login-panel {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 60px;
  padding: 40px;
}
.login-panel p {
  color: var(--muted);
  max-width: 330px;
  line-height: 1.6;
}
form {
  display: flex;
  flex-direction: column;
}
label {
  font-size: 0.8rem;
  margin: 0 0 8px;
}
input,
select {
  width: 100%;
  min-width: 0;
  background: var(--input);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px 13px;
}
input {
  margin-bottom: 18px;
}
input::placeholder {
  color: var(--muted);
  opacity: 0.8;
}
select {
  min-height: 45px;
}
.message {
  border: 1px solid var(--gold);
  color: var(--ink);
  background: #b08b3f18;
  padding: 14px 18px;
  border-radius: 8px;
  margin-bottom: 20px;
  line-height: 1.6;
  overflow-wrap: anywhere;
}
.section-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 16px;
  margin: 0 0 26px;
}
.dashboard-tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}
.tab {
  border-color: transparent;
  color: var(--muted);
  font-size: 0.9rem;
}
.tab.active {
  color: var(--ink);
  background: #7a8f5526;
  border-color: #82976366;
}
.metrics {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 16px;
}
.metric {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 14px;
  min-height: 160px;
  padding: 23px;
  display: flex;
  flex-direction: column;
}
.metric span {
  color: var(--muted);
  font-size: 0.88rem;
}
.metric strong {
  font-family: Georgia, serif;
  font-size: 3rem;
  font-weight: 500;
  margin: auto 0 8px;
}
.metric small {
  color: var(--green);
  font-size: 0.73rem;
  line-height: 1.5;
}
.service-status {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px;
  margin-top: 22px;
  color: var(--muted);
  font-size: 0.85rem;
}
.service-status strong {
  color: var(--green);
}
.status-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--green);
}
.updated {
  color: var(--muted);
  font-size: 0.8rem;
  margin: 0 0 0 auto;
}
.links {
  display: flex;
  gap: 15px;
  margin-top: 22px;
}
.links a {
  flex: 1;
  border: 1px solid var(--line);
  padding: 19px 22px;
  border-radius: 10px;
  color: var(--ink);
  text-decoration: none;
  display: flex;
  justify-content: space-between;
  gap: 10px;
}
.links a:hover {
  border-color: var(--gold);
  color: var(--gold);
}
.section-title {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 20px;
  margin-bottom: 24px;
}
.section-title p {
  color: var(--muted);
  font-size: 0.86rem;
  line-height: 1.6;
  margin: 0;
}
.section-title .primary {
  flex-shrink: 0;
}
.filters {
  display: grid;
  grid-template-columns: minmax(180px, 1fr) minmax(130px, 0.5fr) minmax(130px, 0.5fr) auto;
  gap: 12px;
  align-items: end;
  padding: 20px;
  border: 1px solid var(--line);
  background: var(--panel);
  border-radius: 12px;
}
.filters label {
  display: block;
}
.filters input {
  margin: 0;
}
.filter-submit {
  min-height: 45px;
}
.list-state {
  color: var(--muted);
  min-height: 22px;
  margin: 18px 0 12px;
  font-size: 0.85rem;
  line-height: 1.6;
}
.data-panel {
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--panel);
}
.data-table {
  width: 100%;
  border-collapse: collapse;
  table-layout: fixed;
  font-size: 0.78rem;
}
.data-table th {
  text-align: left;
  padding: 16px 14px;
  font-size: 0.72rem;
  font-weight: 600;
  color: var(--muted);
  border-bottom: 1px solid var(--line);
}
.data-table td {
  padding: 17px 14px;
  vertical-align: top;
  border-bottom: 1px solid var(--line);
  line-height: 1.55;
  overflow-wrap: anywhere;
}
.data-table tr:last-child td {
  border-bottom: 0;
}
.data-table th:first-child {
  width: 24%;
}
.data-table th:last-child {
  width: 12%;
}
.identity {
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.identity span {
  color: var(--muted);
  font-size: 0.74rem;
}
.identity code {
  color: var(--green);
  font-size: 0.71rem;
}
.badge {
  display: inline-block;
  padding: 4px 8px;
  border: 1px solid var(--line);
  border-radius: 5px;
  font-size: 0.69rem;
  width: fit-content;
}
.badge.verified,
.badge.info {
  color: var(--green);
  border-color: #82976366;
  background: #7a8f5518;
}
.badge.pending,
.badge.warning {
  color: var(--gold);
  border-color: #b08b3f77;
  background: #b08b3f18;
}
.badge.error {
  color: var(--danger);
  border-color: #be554455;
  background: #be554418;
}
.log-action {
  display: flex;
  flex-direction: column;
  gap: 7px;
}
.log-table th:first-child {
  width: 16%;
}
.log-table th:last-child {
  width: 24%;
}
.metadata {
  margin: 0;
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1.3fr);
  gap: 4px 8px;
  font-size: 0.71rem;
}
.metadata dt {
  color: var(--muted);
}
.metadata dd {
  margin: 0;
}
.pagination {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-top: 20px;
}
.pagination span {
  color: var(--muted);
  font-size: 0.78rem;
  text-align: center;
}
.admin-dialog {
  width: min(760px, calc(100% - 28px));
  max-height: calc(100dvh - 40px);
  border: 1px solid var(--line);
  border-radius: 16px;
  background: var(--panel);
  color: var(--ink);
  padding: 28px;
  overflow-y: auto;
  overscroll-behavior: contain;
  box-shadow: 0 32px 90px #0007;
}
.admin-dialog::backdrop {
  background: #130f0cbb;
  backdrop-filter: blur(4px);
}
.dialog-head {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 18px;
  margin-bottom: 24px;
}
.dialog-head h2 {
  margin: 0;
  font-size: 1.7rem;
}
.dialog-head button {
  flex-shrink: 0;
}
.dialog-note,
.destructive-note {
  line-height: 1.65;
  color: var(--muted);
  font-size: 0.88rem;
  margin: 0 0 24px;
}
.destructive-note {
  border-left: 3px solid var(--danger);
  padding: 12px 16px;
  background: #be554415;
  color: var(--ink);
}
.form-field {
  display: flex;
  flex-direction: column;
  gap: 9px;
  margin-bottom: 17px;
}
.form-field input {
  margin: 0;
}
.field-hint {
  font-size: 0.75rem;
  color: var(--muted);
  margin: 0 0 14px;
  line-height: 1.6;
}
.detail-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 18px 24px;
  margin: 0;
}
.detail-field dt {
  color: var(--muted);
  font-size: 0.75rem;
  margin-bottom: 6px;
}
.detail-field dd {
  margin: 0;
  font-size: 0.86rem;
  overflow-wrap: anywhere;
}
.village-summary {
  padding: 18px;
  background: #7a8f5515;
  border: 1px solid var(--line);
  border-radius: 10px;
  margin-bottom: 12px;
}
.village-summary .detail-grid {
  grid-template-columns: repeat(3, minmax(0, 1fr));
  margin-top: 18px;
  gap: 14px;
}
.session-record {
  color: var(--muted);
  font-size: 0.8rem;
  line-height: 1.7;
  border-top: 1px solid var(--line);
  padding-top: 12px;
  overflow-wrap: anywhere;
}
.delete-target {
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 18px;
  border: 1px solid var(--line);
  border-radius: 10px;
  margin-bottom: 20px;
  overflow-wrap: anywhere;
}
.delete-target span {
  color: var(--muted);
  font-size: 0.86rem;
}
.delete-target code {
  color: var(--gold);
  font-size: 1rem;
}
.dialog-actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 12px;
  border-top: 1px solid var(--line);
  padding-top: 20px;
  margin-top: 24px;
}
.muted {
  color: var(--muted);
  font-size: 0.85rem;
  line-height: 1.6;
}
footer {
  border-top: 1px solid var(--line);
  padding: 24px 0;
  color: var(--muted);
  font-size: 0.78rem;
  line-height: 1.8;
}
footer span {
  margin: 0 5px;
}
@media (max-width: 960px) {
  .filters {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
  .search-field {
    grid-column: 1 / -1;
  }
  .filter-submit {
    grid-column: 1 / -1;
  }
  .data-panel {
    background: transparent;
    border: 0;
  }
  .data-table,
  .data-table tbody {
    display: block;
  }
  .data-table thead {
    display: none;
  }
  .data-table tr {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    background: var(--panel);
    border: 1px solid var(--line);
    border-radius: 12px;
    margin-bottom: 14px;
  }
  .data-table td {
    display: flex;
    flex-direction: column;
    gap: 8px;
    padding: 14px 16px;
    border: 0;
    min-width: 0;
  }
  .data-table td::before {
    content: attr(data-label);
    font-size: 0.7rem;
    color: var(--muted);
  }
  .data-table td:first-child {
    grid-column: 1 / -1;
    border-bottom: 1px solid var(--line);
  }
  .log-table td:last-child {
    grid-column: 1 / -1;
  }
}
@media (max-width: 620px) {
  .shell {
    width: calc(100% - 28px);
  }
  .topbar {
    min-height: 78px;
    gap: 10px;
  }
  .brand {
    gap: 9px;
  }
  .brand strong {
    font-size: 1rem;
  }
  .brand small {
    display: none;
  }
  .sigil {
    width: 36px;
    height: 36px;
    font-size: 1.2rem;
  }
  .header-actions {
    gap: 6px;
  }
  .header-actions button {
    padding: 9px 10px;
    font-size: 0.8rem;
  }
  .theme-toggle {
    min-width: 36px;
  }
  main,
  :root[data-authenticated='true'] main {
    padding-top: 32px;
  }
  .lead {
    margin-bottom: 26px;
    font-size: 0.9rem;
  }
  .login-panel {
    grid-template-columns: 1fr;
    gap: 12px;
    padding: 24px;
  }
  .section-head {
    align-items: flex-start;
    flex-direction: column;
    gap: 12px;
  }
  .tab {
    padding: 10px 12px;
    font-size: 0.83rem;
  }
  .metrics {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 10px;
  }
  .metric {
    min-height: 155px;
    padding: 17px;
  }
  .metric strong {
    font-size: 2.4rem;
  }
  .metric span {
    font-size: 0.78rem;
  }
  .metric small {
    font-size: 0.68rem;
  }
  .updated {
    flex-basis: 100%;
    margin: 4px 0 0;
  }
  .links {
    flex-direction: column;
  }
  .section-title {
    align-items: flex-start;
    flex-direction: column;
    gap: 12px;
  }
  .filters {
    padding: 16px;
  }
  .pagination {
    gap: 8px;
  }
  .pagination button {
    padding: 9px 10px;
  }
  .admin-dialog {
    padding: 21px;
  }
  .detail-grid {
    gap: 18px 14px;
  }
  .dialog-head h2 {
    font-size: 1.45rem;
  }
  .dialog-actions button {
    flex: 1;
  }
}
@media (max-width: 380px) {
  .topbar {
    align-items: flex-start;
    flex-direction: column;
  }
  .header-actions {
    align-self: flex-end;
  }
  .detail-grid {
    grid-template-columns: 1fr;
  }
  .village-summary .detail-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
  .filters {
    grid-template-columns: minmax(0, 1fr);
  }
  .metrics {
    grid-template-columns: minmax(0, 1fr);
  }
}
