:root {
  color-scheme: light;
  --ink: #17211b;
  --muted: #66736c;
  --line: #d9e2dd;
  --soft: #f5f7f4;
  --bg: #fbfcfa;
  --panel: #fff;
  --panel-2: #fbfcfa;
  --input: #fff;
  --shadow: rgba(23, 33, 27, 0.14);
  --modal-shadow: rgba(17, 19, 17, 0.28);
  --overlay: rgba(17, 19, 17, 0.55);
  --brand-soft: #eef6f1;
  --brand-link-bg: #f5fbf8;
  --gold-soft: #f6f1e8;
  --brand: #297a58;
  --gold: #ad7b2c;
  --red: #b64b4b;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --ink: #edf4ef;
    --muted: #aebbb3;
    --line: #304238;
    --soft: #18221d;
    --bg: #0f1512;
    --panel: #151d19;
    --panel-2: #101713;
    --input: #111915;
    --shadow: rgba(0, 0, 0, 0.34);
    --modal-shadow: rgba(0, 0, 0, 0.5);
    --overlay: rgba(0, 0, 0, 0.7);
    --brand-soft: #163327;
    --brand-link-bg: #12241d;
    --gold-soft: #2f281b;
    --brand: #45a977;
    --gold: #c99743;
    --red: #cc6262;
  }
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --ink: #edf4ef;
  --muted: #aebbb3;
  --line: #304238;
  --soft: #18221d;
  --bg: #0f1512;
  --panel: #151d19;
  --panel-2: #101713;
  --input: #111915;
  --shadow: rgba(0, 0, 0, 0.34);
  --modal-shadow: rgba(0, 0, 0, 0.5);
  --overlay: rgba(0, 0, 0, 0.7);
  --brand-soft: #163327;
  --brand-link-bg: #12241d;
  --gold-soft: #2f281b;
  --brand: #45a977;
  --gold: #c99743;
  --red: #cc6262;
}

:root[data-theme="light"] {
  color-scheme: light;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: Tahoma, Arial, sans-serif;
  background: var(--bg);
  color: var(--ink);
}

.authGate {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 20px;
}

.authGate[hidden] {
  display: none;
}

.authCard {
  width: min(430px, 100%);
  display: grid;
  gap: 14px;
  padding: 18px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: 0 14px 36px var(--shadow);
}

.authCard h1 {
  margin: 0;
  font-size: 24px;
}

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

.authTabs button {
  background: var(--panel-2);
  color: var(--ink);
}

.authTabs button.active {
  background: var(--brand);
  color: #fff;
}

.authForm {
  display: grid;
  gap: 10px;
}

.authForm[hidden] {
  display: none;
}

#authMessage {
  margin: 0;
  min-height: 22px;
  color: var(--muted);
}

.shell {
  width: min(1440px, calc(100% - 32px));
  margin: 0 auto;
  padding: 24px 0;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding-bottom: 18px;
}

h1,
h2,
p {
  margin: 0;
}

h1 {
  font-size: 28px;
}

h2 {
  font-size: 16px;
  margin-bottom: 8px;
}

p,
small {
  color: var(--muted);
}

.actions,
.filters {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.actionsPanel {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  flex-wrap: wrap;
  justify-content: flex-start;
}

.operations {
  position: relative;
}

.operations summary {
  min-height: 42px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0 14px;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  cursor: pointer;
  background: var(--panel);
  color: var(--ink);
  list-style: none;
}

.operations summary::-webkit-details-marker {
  display: none;
}

.operations summary::before {
  content: "▾";
  font-size: 12px;
  color: var(--muted);
}

.operations[open] summary::before {
  transform: rotate(180deg);
}

.operations .actions {
  position: absolute;
  top: calc(100% + 8px);
  left: 0;
  z-index: 20;
  width: min(430px, calc(100vw - 32px));
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: 0 14px 36px var(--shadow);
}

.themeControl {
  min-height: 42px;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0 10px;
  background: var(--panel);
  color: var(--muted);
  font-size: 12px;
}

.themeControl select {
  min-height: 30px;
  border: 0;
  padding: 0 4px;
  background: transparent;
}

.autoSyncStatus {
  margin-top: 4px;
  font-size: 12px;
}

button,
.export,
input,
select {
  min-height: 42px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0 14px;
  font: inherit;
  background: var(--input);
  color: var(--ink);
}

button,
.export {
  background: var(--brand);
  color: #fff;
  cursor: pointer;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
}

button.secondary {
  background: var(--panel);
  color: var(--ink);
}

button:disabled {
  opacity: 0.55;
  cursor: wait;
}

.loadingOverlay {
  position: fixed;
  inset: 0;
  z-index: 1000;
  display: grid;
  place-items: center;
  background: rgba(5, 14, 11, 0.58);
  backdrop-filter: blur(2px);
}

.loadingOverlay[hidden] {
  display: none;
}

.loadingBox {
  min-width: 220px;
  min-height: 88px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  color: var(--ink);
  box-shadow: 0 18px 50px var(--shadow);
}

.spinner {
  width: 26px;
  height: 26px;
  border: 3px solid var(--line);
  border-top-color: var(--brand);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

.metrics {
  display: grid;
  grid-template-columns: repeat(6, minmax(120px, 1fr));
  gap: 10px;
  margin: 8px 0 16px;
}

.metrics article {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  padding: 14px;
}

.metrics span,
.district small,
td small {
  display: block;
  font-size: 12px;
  color: var(--muted);
  margin-top: 4px;
}

.metrics strong {
  font-size: 24px;
}

.filters {
  margin-bottom: 14px;
}

.viewTabs {
  display: flex;
  gap: 8px;
  margin: 0 0 12px;
  flex-wrap: wrap;
}

.viewTab {
  min-height: 36px;
  background: var(--panel);
  color: var(--ink);
  border: 1px solid var(--line);
  gap: 8px;
}

.viewTab.active {
  background: var(--brand);
  color: #fff;
  border-color: var(--brand);
}

.viewTab span {
  min-width: 26px;
  min-height: 22px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0 7px;
  border-radius: 999px;
  background: var(--soft);
  color: var(--ink);
  font-size: 12px;
}

.viewTab.active span {
  background: rgba(255, 255, 255, 0.18);
  color: #fff;
}

.paginationBar {
  position: sticky;
  top: 0;
  z-index: 8;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  flex-wrap: wrap;
  padding: 10px;
  border-bottom: 1px solid var(--line);
  background: var(--panel);
}

.paginationBar > span,
.pagerGroup span {
  color: var(--muted);
  font-size: 12px;
}

.pagerGroup {
  display: inline-flex;
  align-items: center;
  gap: 8px;
}

.pagerGroup button {
  min-height: 34px;
  padding: 0 10px;
}

.filters input:first-child {
  flex: 1 1 360px;
}

.content {
  display: grid;
  grid-template-columns: 1fr 230px;
  gap: 14px;
  align-items: start;
}

.tableWrap,
aside {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  overflow: hidden;
}

.tableWrap {
  overflow-x: auto;
  overflow-y: hidden;
  scrollbar-gutter: stable;
}

aside {
  padding: 10px;
  position: sticky;
  top: 12px;
}

table {
  width: 100%;
  border-collapse: collapse;
  min-width: 1580px;
  font-size: 13px;
  table-layout: fixed;
}

th,
td {
  text-align: right;
  padding: 9px 10px;
  border-bottom: 1px solid var(--line);
  vertical-align: top;
  white-space: nowrap;
}

th {
  color: var(--muted);
  background: var(--soft);
  font-weight: 600;
  font-size: 12px;
}

.columnFilters th {
  padding: 6px;
  background: var(--panel);
}

.columnFilters select {
  width: 100%;
  min-height: 34px;
  padding: 0 8px;
  border-radius: 6px;
  font-size: 12px;
  color: var(--ink);
  background: var(--input);
}

.columnFilters input {
  width: 100%;
  min-height: 34px;
  padding: 0 8px;
  border-radius: 6px;
  font-size: 12px;
  color: var(--ink);
  background: var(--input);
}

th:nth-child(1),
td:nth-child(1) {
  width: 76px;
}

th:nth-child(2),
td:nth-child(2) {
  width: 74px;
}

th:nth-child(3),
td:nth-child(3) {
  width: 92px;
}

th:nth-child(4),
td:nth-child(4) {
  width: 112px;
}

th:nth-child(5),
td:nth-child(5) {
  width: 96px;
}

th:nth-child(6),
td:nth-child(6) {
  width: 210px;
}

th:nth-child(7),
td:nth-child(7),
th:nth-child(8),
td:nth-child(8) {
  width: 120px;
}

th:nth-child(9),
td:nth-child(9) {
  width: 112px;
}

.favoriteButton {
  width: 36px;
  min-width: 36px;
  height: 32px;
  min-height: 32px;
  padding: 0;
  justify-content: center;
  border-radius: 6px;
  background: var(--panel);
  color: var(--muted);
  border: 1px solid var(--line);
  font-size: 17px;
  line-height: 1;
}

.favoriteButton.active,
.favoriteModalActive {
  background: var(--gold-soft);
  color: var(--gold);
  border-color: var(--gold);
}

.purchaseButton {
  min-width: 58px;
  min-height: 32px;
  padding: 0 10px;
  border-radius: 6px;
  background: var(--panel);
  color: var(--brand);
  border: 1px solid var(--brand);
  font-size: 13px;
}

.purchaseButton.active {
  background: var(--brand-soft);
  color: var(--brand);
}

.purchaseInline {
  color: var(--brand);
  font-weight: 700;
}

.auctionCell {
  white-space: normal;
}

.auctionTitleLink {
  display: -webkit-box;
  max-width: 190px;
  line-height: 1.35;
  overflow: hidden;
  white-space: normal;
  overflow-wrap: anywhere;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
}

.auctionCell small {
  display: -webkit-box;
  max-width: 190px;
  line-height: 1.35;
  overflow: hidden;
  white-space: normal;
  -webkit-line-clamp: 1;
  -webkit-box-orient: vertical;
}

td a {
  font-size: 14px;
}

.mapLink {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 28px;
  padding: 0 10px;
  border: 1px solid var(--line);
  border-radius: 6px;
  color: var(--brand);
  background: var(--brand-link-bg);
  font-weight: 700;
}

td a {
  color: var(--ink);
  font-weight: 700;
  text-decoration: none;
}

.badge {
  border-radius: 999px;
  padding: 5px 10px;
  font-size: 12px;
  color: #fff;
}

.badge.current {
  background: var(--brand);
}

.badge.new {
  background: var(--gold);
}

.badge.end {
  background: var(--red);
}

.resultBadge {
  display: inline-flex;
  align-items: center;
  min-height: 26px;
  padding: 0 8px;
  border-radius: 6px;
  background: var(--soft);
  color: var(--ink);
  font-size: 12px;
  font-weight: 700;
}

.typeBadge {
  display: inline-flex;
  align-items: center;
  min-height: 26px;
  padding: 0 8px;
  border-radius: 6px;
  background: var(--brand-soft);
  color: var(--brand);
  font-size: 12px;
  font-weight: 700;
}

.typeBadge.other {
  background: var(--gold-soft);
  color: var(--gold);
}

.thumbButton {
  width: 54px;
  height: 42px;
  padding: 0;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--panel);
  overflow: hidden;
  cursor: zoom-in;
}

.thumbButton img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.modal[hidden] {
  display: none;
}

.modal {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: grid;
  place-items: center;
  padding: 20px;
}

.modalBackdrop {
  position: absolute;
  inset: 0;
  background: var(--overlay);
}

.modalPanel {
  position: relative;
  width: min(1120px, 96vw);
  max-height: 92vh;
  display: grid;
  grid-template-rows: auto 1fr auto;
  background: var(--panel);
  border-radius: 8px;
  overflow: hidden;
  box-shadow: 0 18px 60px var(--modal-shadow);
}

.modalHeader,
.modalFooter {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 12px 14px;
  border-bottom: 1px solid var(--line);
}

.modalFooter {
  border-top: 1px solid var(--line);
  border-bottom: 0;
  justify-content: flex-start;
}

.modalBody {
  display: grid;
  grid-template-columns: minmax(320px, 1.1fr) minmax(320px, 0.9fr);
  gap: 14px;
  padding: 14px;
  overflow: auto;
}

.modalImageWrap {
  min-height: 360px;
  background: var(--soft);
  border: 1px solid var(--line);
  border-radius: 8px;
  overflow: hidden;
}

.modalImageWrap img {
  width: 100%;
  height: 100%;
  max-height: 68vh;
  object-fit: contain;
  display: block;
}

.modalDetails {
  display: grid;
  gap: 10px;
  align-content: start;
}

.purchasePanel {
  width: min(720px, 94vw);
}

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

.purchaseForm label {
  display: grid;
  gap: 6px;
  color: var(--muted);
  font-size: 13px;
}

.purchaseForm .full,
.purchaseForm .modalFooter {
  grid-column: 1 / -1;
}

.purchaseForm textarea {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px;
  font: inherit;
  background: var(--input);
  color: var(--ink);
  resize: vertical;
}

.usersPanel {
  width: min(760px, 94vw);
}

.passwordPanel {
  width: min(520px, 94vw);
}

.passwordForm {
  display: grid;
  gap: 12px;
  padding: 14px;
}

.passwordForm label {
  display: grid;
  gap: 6px;
  color: var(--muted);
  font-size: 13px;
}

.passwordForm input {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
  font: inherit;
  background: var(--input);
  color: var(--ink);
}

#passwordMessage {
  margin: 0;
  color: var(--muted);
}

.usersList {
  display: grid;
  gap: 10px;
  padding: 14px;
  overflow: auto;
}

.userRow {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px;
  background: var(--panel-2);
}

.userRow small {
  display: block;
  color: var(--muted);
  margin-top: 4px;
}

.userActions {
  display: flex;
  gap: 8px;
}

.danger {
  border-color: var(--red);
  color: var(--red);
}

.detailSection {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px;
  background: var(--panel);
}

.detailSection h3 {
  margin: 0 0 8px;
  font-size: 14px;
}

.detailSection p {
  color: var(--ink);
  font-size: 13px;
  line-height: 1.8;
}

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

.detailItem {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 8px;
  background: var(--panel-2);
  min-width: 0;
}

.detailItem span {
  display: block;
  color: var(--muted);
  font-size: 12px;
  margin-bottom: 4px;
}

.detailItem strong {
  font-size: 13px;
  line-height: 1.35;
  white-space: normal;
  overflow-wrap: anywhere;
}

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

.detailImages img {
  width: 100%;
  aspect-ratio: 16 / 9;
  object-fit: cover;
  border: 1px solid var(--line);
  border-radius: 6px;
}

.iconButton,
.secondaryLink {
  min-height: 36px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0 12px;
  background: var(--panel);
  color: var(--ink);
  text-decoration: none;
  display: inline-flex;
  align-items: center;
}

.district {
  display: grid;
  gap: 3px;
  padding: 8px 0;
  border-bottom: 1px solid var(--line);
}

.district span {
  font-size: 13px;
  line-height: 1.35;
}

.district strong {
  font-size: 15px;
}

.district:last-child,
tr:last-child td {
  border-bottom: 0;
}

@media (max-width: 980px) {
  .topbar,
  .content {
    grid-template-columns: 1fr;
    display: grid;
  }

  .actionsPanel {
    justify-content: flex-start;
  }

  .operations .actions {
    position: static;
    width: 100%;
    margin-top: 8px;
    box-shadow: none;
  }

  .metrics {
    grid-template-columns: repeat(2, 1fr);
  }

  .tableWrap {
    overflow-x: auto;
  }

  aside {
    position: static;
  }

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

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

  .detailGrid,
  .detailImages {
    grid-template-columns: 1fr;
  }
}
