*,
*::before,
*::after {
  box-sizing: border-box;
}

html {
  font-size: 16px;
}

body {
  margin: 0;
  font-family: system-ui, sans-serif;
  line-height: 1.4;
  color: #111;
  background: #f7f7f7;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

body > .wrap,
body > .login-wrap {
  flex: 1 0 auto;
}

#site-footer {
  flex-shrink: 0;
  margin-top: auto;
}

a {
  color: inherit;
}

.wrap {
  width: min(1100px, 100% - 2rem);
  margin: 0 auto;
  padding: 1.25rem 0 2rem;
}

h1 {
  font-size: clamp(1.25rem, 2.5vw, 1.75rem);
  margin: 0 0 1rem;
  font-weight: 650;
}

.card {
  background: #fff;
  border: 1px solid #ddd;
  padding: 1rem;
}

.stack {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

label {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
  font-size: 0.9rem;
}

input[type="text"],
input[type="password"],
select {
  width: 100%;
  padding: 0.5rem 0.6rem;
  border: 1px solid #bbb;
  font: inherit;
  background: #fff;
}

:root {
  --ui-border: #888;
}

.muted {
  color: #666;
  font-size: 0.95rem;
}

.site-header {
  border-bottom: 1px solid var(--ui-border);
  background: #fff;
}

.site-header-inner {
  width: min(1100px, 100% - 2rem);
  margin: 0 auto;
  padding: 0.65rem 0;
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem 1rem;
  align-items: center;
}

.site-brand {
  font-weight: 650;
  text-decoration: none;
  margin-right: 0.5rem;
}

.site-nav {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
  flex: 1;
}

.site-footer {
  border-top: 1px solid var(--ui-border);
  margin-top: 2rem;
  background: #fff;
}

.site-footer-inner {
  width: min(1100px, 100% - 2rem);
  margin: 0 auto;
  padding: 0.75rem 0 1.25rem;
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem 0.5rem;
  align-items: center;
  font-size: 0.8rem;
  color: #666;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}

.site-footer-sep {
  color: #bbb;
}

.home-sections {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  margin-top: 1rem;
}

.home-section-link {
  display: block;
  padding: 0.85rem 0;
  border-bottom: 1px solid var(--ui-border);
  text-decoration: none;
  color: inherit;
}

.home-section-link:hover .home-section-title {
  text-decoration: underline;
}

.home-section-title {
  display: block;
  font-weight: 650;
  font-size: 1.05rem;
}

.home-section-desc {
  display: block;
  margin-top: 0.25rem;
}

.site-nav-link {
  display: inline-block;
  padding: 0.35rem 0.65rem;
  border: 1px solid transparent;
  text-decoration: none;
  font-size: 0.95rem;
}

.site-nav-link:hover {
  background: #f0f0f0;
}

.site-nav-link.is-active {
  border-color: var(--ui-border);
  background: #eee;
}

.site-header-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  align-items: center;
}

.site-user {
  font-size: 0.9rem;
  color: #444;
}

.feature-toggle {
  display: inline-flex;
  flex-direction: row;
  align-items: center;
  gap: 0.4rem;
  white-space: nowrap;
}

.feature-toggle input {
  width: auto;
}

#features-section,
#config-section {
  margin-bottom: 1.25rem;
}

.alerts-list {
  display: flex;
  flex-direction: column;
  gap: 1.5rem;
}

.alerts-day-title {
  font-size: 1.1rem;
  font-weight: 650;
  margin: 0 0 0.65rem;
}

.alerts-grid {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 0.75rem;
  align-items: start;
}

.alert-box {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  min-width: 0;
}

.alert-box-media {
  position: relative;
  width: 100%;
  aspect-ratio: 16 / 9;
  background: #c8c8c8;
  overflow: hidden;
}

.alert-box-media .alert-thumb {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.alert-spinner {
  position: absolute;
  inset: 0;
  margin: auto;
  width: 1.75rem;
  height: 1.75rem;
  border: 3px solid #eee;
  border-top-color: #555;
  border-radius: 50%;
  animation: alert-spin 0.8s linear infinite;
}

@keyframes alert-spin {
  to {
    transform: rotate(360deg);
  }
}

.alert-thumb-error {
  position: absolute;
  inset: 0;
  display: none;
  align-items: center;
  justify-content: center;
  margin: 0;
  padding: 0.5rem;
  text-align: center;
  font-size: 0.85rem;
  color: #5a0000;
  background: #d0d0d0;
}

/* class display must not override [hidden]; show only when not hidden */
.alert-box.is-error .alert-thumb-error:not([hidden]) {
  display: flex;
}

.alert-play {
  position: absolute;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  width: 2.75rem;
  height: 2.75rem;
  border-radius: 50%;
  border: 1px solid #333;
  background: rgba(255, 255, 255, 0.85);
  cursor: pointer;
  padding: 0;
}

.alert-play::before {
  content: "";
  display: block;
  margin: 0 auto;
  width: 0;
  height: 0;
  border-style: solid;
  border-width: 0.55rem 0 0.55rem 0.9rem;
  border-color: transparent transparent transparent #222;
  margin-left: 0.85rem;
}

.alert-box-meta {
  font-size: 0.75rem;
  color: #555;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.alert-video-overlay {
  position: fixed;
  inset: 0;
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(0, 0, 0, 0.65);
  padding: 1rem;
}

.alert-video-dialog {
  position: relative;
  width: min(960px, 100%);
  background: #111;
  border: 1px solid #444;
  padding: 0.5rem;
}

.alert-video-dialog video {
  display: block;
  width: 100%;
  max-height: min(80vh, 540px);
  background: #000;
}

.alert-video-close {
  position: absolute;
  top: 0.35rem;
  right: 0.35rem;
  z-index: 1;
}

.alert-video-error {
  color: #fcc;
  text-align: center;
  padding: 2rem 1rem;
  margin: 0;
}

@media (max-width: 1100px) {
  .alerts-grid {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }
}

@media (max-width: 700px) {
  .alerts-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@media (max-width: 420px) {
  .alerts-grid {
    grid-template-columns: 1fr;
  }
}

button,
.btn {
  font: inherit;
  padding: 0.4rem 0.75rem;
  border: 1px solid var(--ui-border);
  background: #eee;
  cursor: pointer;
}

button:hover,
.btn:hover {
  background: #e2e2e2;
}

button:disabled,
.btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.error {
  color: #a10000;
  font-size: 0.9rem;
}

.error:empty,
.ok:empty {
  display: none;
}

.topbar {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 1rem;
}

.topbar .actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
}

.table-wrap {
  overflow-x: auto;
  border: 1px solid #ddd;
  background: #fff;
}

table.config {
  width: 100%;
  border-collapse: collapse;
  min-width: 20rem;
}

#users-table-wrap table.config {
  min-width: 0;
}

table.config th,
table.config td {
  border-bottom: 1px solid #e5e5e5;
  padding: 0.55rem 0.65rem;
  text-align: left;
  vertical-align: middle;
}

table.config th {
  background: #f0f0f0;
  font-weight: 600;
  font-size: 0.85rem;
}

table.config td.actions {
  white-space: nowrap;
  width: 1%;
}

table.config td.actions button {
  margin-left: 0.35rem;
}

table.config td.actions button:first-child {
  margin-left: 0;
}

table.config input.cell {
  width: 100%;
  min-width: 8rem;
  padding: 0.35rem 0.45rem;
  border: 1px solid #bbb;
  font: inherit;
}

.login-wrap {
  width: min(24rem, 100% - 2rem);
  margin: 10vh auto 0;
}

.section-box {
  border: 1px solid var(--ui-border);
  background: #fff;
  padding: 1rem;
}

.section-box > h2 {
  font-size: 1.1rem;
  margin: 0 0 0.75rem;
  font-weight: 650;
}

.section-box > h3,
.panel h3 {
  font-size: 1rem;
  margin: 0;
  font-weight: 600;
}

.section-box .table-wrap {
  border-color: #ddd;
}

.panels-row {
  display: grid;
  grid-template-columns: minmax(16rem, 20rem) minmax(0, 1fr);
  gap: 1.25rem 1.5rem;
  align-items: start;
  margin-top: 1.5rem;
}

.panels-row .panel {
  margin-top: 0;
  min-width: 0;
}

.panels-row #admin-panel[hidden] {
  display: none;
}

.panels-row:has(#admin-panel[hidden]) {
  grid-template-columns: minmax(16rem, 20rem);
}

.panels-row .card.narrow {
  max-width: none;
  width: 100%;
  margin-bottom: 1rem;
}

.ok {
  color: #0a5a0a;
  font-size: 0.9rem;
}

.inline-pwd {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
  align-items: center;
}

.inline-pwd input {
  width: auto;
  min-width: 8rem;
  flex: 1;
  padding: 0.35rem 0.45rem;
  border: 1px solid #bbb;
  font: inherit;
}

@media (max-width: 720px) {
  .panels-row {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 600px) {
  .wrap {
    width: calc(100% - 1rem);
  }

  table.config td.actions {
    white-space: normal;
  }

  table.config td.actions button {
    margin: 0.15rem 0.15rem 0.15rem 0;
  }
}
