:root {
  --cell-gap: 1px;
  --color-available: #bbf7d0;
  --color-reserved: #ffd24d;
  --color-sold: #fecaca;
  --color-bg: #fff;
  --color-header: #f5f5f5;
  --color-border: #ddd;
  --color-text: #222;
  --color-muted: #666;
  --color-error: #c0392b;
  --font-stack: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
}

* { box-sizing: border-box; }

.banner {
  width: 100%;
  background: var(--color-bg);
  border-bottom: 1px solid var(--color-border);
  display: grid;
  grid-template-columns: 1fr;
  align-items: center;
  justify-items: center;
  column-gap: 24px;
}
.banner-main {
  width: 100%;
  max-width: 1200px;
  height: auto;
  display: block;
  min-width: 0;
}
.banner-side {
  display: none;
  flex-direction: column;
  align-items: center;
  align-self: stretch;
  height: auto;
}
.banner-side .logo {
  width: 200px;
  height: auto;
  display: block;
}
.ring-text {
  width: 100%;
  max-width: 320px;
  height: auto;
  display: block;
}
.ring-text text {
  font-size: 14px;
  font-weight: 600;
  fill: #333;
  font-family: var(--font-stack);
}
.contacts {
  list-style: none;
  margin: 24px 0 0;
  padding: 0;
  text-align: center;
  font-size: 24px;
  font-weight: 700;
  color: var(--color-text);
  line-height: 1.6;
}
.contacts li { margin: 0; }
.contacts a {
  color: inherit;
  text-decoration: none;
}
.malder-line {
  margin-top: auto;
  margin-bottom: auto;
  padding: 16px 0;
  font-size: 22px;
  font-weight: 700;
  color: var(--color-text);
  text-align: center;
  line-height: 1.3;
}
@media (min-width: 900px) {
  .banner {
    grid-template-columns: minmax(320px, 1fr) minmax(0, 1200px) minmax(320px, 1fr);
  }
  .banner-side {
    display: flex;
  }
}

html, body {
  margin: 0;
  padding: 0;
  background: var(--color-bg);
  color: var(--color-text);
  font-family: var(--font-stack);
  font-size: 14px;
  line-height: 1.4;
}

header {
  background: var(--color-header);
  border-bottom: 1px solid var(--color-border);
  padding: 10px 20px;
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  gap: 16px;
}

header h1 {
  margin: 0;
  font-size: 18px;
  font-weight: 600;
}

.header-center {
  text-align: center;
}

.legend-left  { justify-self: start; }
.legend-right { justify-self: end; }

.mobile-extra { display: none; }

.legend {
  margin: 0;
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  align-items: center;
  font-size: 13px;
  color: var(--color-muted);
}

.swatch {
  display: inline-block;
  width: 14px;
  height: 14px;
  vertical-align: middle;
  margin-right: 4px;
  border: 1px solid rgba(0, 0, 0, 0.1);
}
.swatch-available { background: var(--color-available); }
.swatch-reserved  { background: var(--color-reserved); }
.swatch-sold      { background: var(--color-sold); }

.updated {
  display: block;
  margin: 4px 0 0;
  font-size: 12px;
  color: var(--color-muted);
}

.user-email {
  font-size: 13px;
  color: var(--color-muted);
}

main {
  padding: 16px 20px;
}

.grid-wrap {
  display: grid;
  grid-template-columns: 1fr;
  align-items: start;
  justify-items: center;
  column-gap: 32px;
  width: 100%;
}
.grid-side {
  display: none;
  width: 100%;
  max-width: 420px;
  height: auto;
}
.grid-side-left  { justify-self: end; }
.grid-side-right { justify-self: start; }
@media (min-width: 1100px) {
  .grid-wrap {
    grid-template-columns: minmax(0, 1fr) minmax(0, 900px) minmax(0, 1fr);
  }
  .grid-side {
    display: block;
  }
}

.grid-below-mobile {
  display: none;
  width: 100%;
  max-width: 600px;
  height: auto;
  margin: 16px auto 0;
}
@media (max-width: 600px) {
  .grid-below-mobile {
    display: block;
  }
}

#grid {
  display: grid;
  grid-template-columns: auto repeat(25, minmax(0, 1fr));
  gap: var(--cell-gap);
  width: 100%;
  max-width: 900px;
  margin: 0 auto;
  padding-bottom: 8px;
}

.grid-corner {
  background: transparent;
}

.grid-col-label,
.grid-row-label {
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: clamp(6px, 0.7vw, 11px);
  font-variant-numeric: tabular-nums;
  color: var(--color-muted);
  font-weight: 500;
  line-height: 1;
  user-select: none;
}

.grid-col-label { padding-bottom: 2px; }
.grid-row-label { padding-right: 4px; }

.cell {
  aspect-ratio: 1 / 1;
  background: var(--color-available);
  border: 1px solid rgba(0, 0, 0, 0.05);
  user-select: none;
}
.cell-available { background: var(--color-available); }
.cell-reserved  { background: var(--color-reserved); }
.cell-sold      { background: var(--color-sold); }

.cell.admin {
  cursor: pointer;
}
.cell.admin:hover {
  outline: 2px solid #333;
  outline-offset: 1px;
  position: relative;
  z-index: 1;
}
.cell.selected {
  outline: 3px solid #2563eb;
  outline-offset: -3px;
  position: relative;
  z-index: 2;
}
.cell.selected:hover {
  outline: 3px solid #2563eb;
}

.status {
  margin-top: 12px;
  color: var(--color-error);
  min-height: 1em;
  font-size: 13px;
}

.login-form {
  max-width: 340px;
  margin: 60px auto;
  padding: 24px;
  border: 1px solid var(--color-border);
  border-radius: 6px;
  background: #fafafa;
}

.login-form h2 {
  margin: 0 0 16px;
  font-size: 16px;
}

.login-form label {
  display: block;
  font-size: 13px;
  margin-bottom: 4px;
  color: var(--color-muted);
}

.login-form input {
  width: 100%;
  padding: 8px 10px;
  margin-bottom: 12px;
  border: 1px solid var(--color-border);
  border-radius: 4px;
  font-size: 14px;
  font-family: inherit;
}

.login-form button {
  width: 100%;
  padding: 10px;
  border: 0;
  border-radius: 4px;
  background: #333;
  color: #fff;
  font-size: 14px;
  cursor: pointer;
}

.login-form button:hover {
  background: #000;
}

.login-error {
  color: var(--color-error);
  font-size: 13px;
  margin-bottom: 8px;
  min-height: 1em;
}

.logout-btn {
  margin-left: 8px;
  padding: 4px 10px;
  border: 1px solid var(--color-border);
  background: #fff;
  border-radius: 4px;
  font-size: 12px;
  cursor: pointer;
  font-family: inherit;
}

.toast {
  position: fixed;
  bottom: 20px;
  right: 20px;
  padding: 10px 14px;
  border-radius: 4px;
  font-size: 13px;
  background: #333;
  color: #fff;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.15);
  z-index: 100;
}
.toast-ok    { background: #2c7a3f; }
.toast-error { background: var(--color-error); }

.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.45);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 200;
}
.modal-box {
  background: #fff;
  border-radius: 6px;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.25);
  padding: 24px;
  max-width: 90vw;
  width: 360px;
  text-align: center;
}
.modal-message {
  margin: 0 0 20px;
  font-size: 16px;
  color: var(--color-text);
}
.modal-actions {
  display: flex;
  justify-content: center;
}
.modal-ok {
  padding: 8px 24px;
  border: 0;
  border-radius: 4px;
  background: #333;
  color: #fff;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  font-family: inherit;
}
.modal-ok:hover { background: #000; }
.modal-actions-pair {
  gap: 12px;
}
.modal-cancel {
  padding: 8px 24px;
  border: 1px solid var(--color-border);
  border-radius: 4px;
  background: #fff;
  color: var(--color-text);
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  font-family: inherit;
}
.modal-cancel:hover { background: #f0f0f0; }

#assign-panel {
  position: sticky;
  bottom: 0;
  background: var(--color-header);
  border-top: 1px solid var(--color-border);
  padding: 12px 20px;
  display: grid;
  grid-template-columns: 1fr;
  gap: 10px;
  align-items: end;
  box-shadow: 0 -4px 12px rgba(0, 0, 0, 0.06);
  z-index: 50;
}
#assign-panel[hidden] { display: none; }
.selection-summary {
  margin: 0;
  font-size: 14px;
  font-weight: 600;
}
.assign-field {
  display: flex;
  flex-direction: column;
  font-size: 12px;
  color: var(--color-muted);
  gap: 4px;
}
.assign-field select,
.assign-field input {
  padding: 6px 8px;
  border: 1px solid var(--color-border);
  border-radius: 4px;
  font-size: 14px;
  font-family: inherit;
  background: #fff;
}
.assign-hint {
  margin: 0;
  font-size: 12px;
  color: var(--color-muted);
  min-height: 1em;
}
.assign-actions {
  display: flex;
  gap: 8px;
  justify-content: flex-end;
}
.assign-actions button {
  padding: 8px 16px;
  border: 1px solid var(--color-border);
  background: #fff;
  border-radius: 4px;
  cursor: pointer;
  font-family: inherit;
  font-size: 14px;
}
#assign-save {
  background: #333;
  color: #fff;
  border-color: #333;
  font-weight: 600;
}
#assign-save:hover { background: #000; }

.sold-toolbar {
  width: 100%;
  max-width: 900px;
  margin: 0 auto 12px;
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  align-items: center;
}
.sold-toolbar input[type='search'] {
  flex: 1 1 240px;
  min-width: 0;
  padding: 8px 10px;
  border: 1px solid var(--color-border);
  border-radius: 4px;
  font-size: 14px;
  font-family: inherit;
  background: #fff;
}

.sold-table-wrap {
  width: 100%;
  max-width: 900px;
  margin: 0 auto;
  overflow-x: auto;
}
.sold-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 14px;
  background: #fff;
}
.sold-table th,
.sold-table td {
  padding: 8px 12px;
  text-align: left;
  border-bottom: 1px solid var(--color-border);
}
.sold-table th {
  background: var(--color-header);
  font-weight: 600;
  color: var(--color-text);
  position: sticky;
  top: 0;
  z-index: 1;
}
.sold-table th.sortable {
  cursor: pointer;
  user-select: none;
}
.sold-table th.sortable:hover {
  background: #ebebeb;
}
.sold-table th.sortable::after {
  content: '';
  display: inline-block;
  width: 0;
  height: 0;
  margin-left: 6px;
  vertical-align: middle;
  opacity: 0.4;
  border-left: 4px solid transparent;
  border-right: 4px solid transparent;
  border-bottom: 5px solid currentColor;
}
.sold-table th.sortable[aria-sort='ascending']::after {
  opacity: 1;
}
.sold-table th.sortable[aria-sort='descending']::after {
  opacity: 1;
  border-bottom: 0;
  border-top: 5px solid currentColor;
}
.sold-table tbody tr:hover {
  background: #fafafa;
}
.sold-table th.sold-check-cell,
.sold-table td.sold-check-cell {
  width: 32px;
  padding-left: 12px;
  padding-right: 4px;
  text-align: center;
}
.sold-table input[type='checkbox'] {
  cursor: pointer;
  width: 16px;
  height: 16px;
  margin: 0;
}
.sold-bulk {
  display: flex;
  gap: 10px;
  align-items: center;
  flex-wrap: wrap;
}
.sold-bulk button {
  padding: 8px 16px;
  border: 1px solid #333;
  background: #333;
  color: #fff;
  border-radius: 4px;
  cursor: pointer;
  font-family: inherit;
  font-size: 14px;
  font-weight: 600;
}
.sold-bulk button:hover { background: #000; }
.sold-bulk button:disabled {
  opacity: 0.6;
  cursor: not-allowed;
  background: #666;
}

@media (min-width: 700px) {
  #assign-panel {
    grid-template-columns: auto 180px 1fr 200px 1fr auto;
    align-items: end;
  }
  .selection-summary { align-self: center; }
  .assign-hint { align-self: center; grid-column: span 1; }
  .assign-actions { align-self: end; }
}

@media (max-width: 600px) {
  header {
    grid-template-columns: 1fr;
    padding: 8px 12px;
    gap: 8px;
    text-align: center;
  }
  .legend-left, .legend-right { justify-self: center; }
  .legend-right { display: none; }
  .legend-left  { order: 99; }
  main { padding: 10px 12px; }

  .mobile-extra {
    display: block;
    margin: 6px 0 0;
    text-align: center;
  }
  .mobile-ring {
    font-size: 14px;
    font-weight: 700;
  }
  .mobile-contacts {
    font-size: 13px;
    font-weight: 700;
    color: var(--color-muted);
    line-height: 1.5;
  }
  .mobile-contacts a {
    color: inherit;
    text-decoration: none;
  }
  .mobile-malder {
    font-size: 14px;
    font-weight: 700;
  }
}
