:root {
  color-scheme: dark;
  --bg: #0e151c;
  --panel: #151f28;
  --panel-soft: #1b2731;
  --text: #f4f7f8;
  --muted: #a9b7c2;
  --line: rgba(255,255,255,.12);
  --green: #237f44;
  --green-2: #1a6537;
  --blue: #2167b8;
  --blue-2: #174f91;
  --yellow: #d8a729;
  --red: #cf3d47;
}
* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; background: radial-gradient(circle at top left, #1a2630 0, #0e151c 38rem); color: var(--text); font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif; letter-spacing: 0; }
body { display: flex; flex-direction: column; }
a { color: inherit; }
.topbar { height: 64px; display: flex; align-items: center; justify-content: space-between; padding: 0 18px; background: rgba(8, 13, 18, .88); border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 10; backdrop-filter: blur(14px); }
.brand { display: inline-flex; gap: 10px; align-items: center; text-decoration: none; font-weight: 800; }
.brand-logo { width: 34px; height: 34px; }
.topnav { display: flex; gap: 10px; align-items: center; }
.user-chip { max-width: 38vw; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--muted); }
.logout-form { margin: 0; }
.icon-button { width: 40px; height: 40px; border-radius: 8px; border: 1px solid var(--line); background: var(--panel); color: var(--text); cursor: pointer; }
.page { width: min(1180px, 100%); margin: 0 auto; padding: 24px 16px 42px; flex: 1; }
.footer { display: flex; justify-content: space-between; gap: 16px; color: var(--muted); padding: 14px 18px; border-top: 1px solid var(--line); font-size: 13px; }
.hero, .section-block, .camera-view, .form-panel, .logs-panel, .guest-panel { margin-bottom: 28px; }
h1, h2 { margin: 0 0 10px; line-height: 1.15; }
h1 { font-size: clamp(28px, 4vw, 42px); }
h2 { font-size: 20px; color: #e9f0f4; }
p { color: var(--muted); margin: 0 0 14px; }
.admin-actions { display: flex; gap: 10px; flex-wrap: wrap; margin: 0 0 26px; }
.admin-actions a, .back-link, .secondary-button { border: 1px solid var(--line); background: var(--panel-soft); color: var(--text); padding: 10px 14px; border-radius: 8px; text-decoration: none; display: inline-flex; align-items: center; justify-content: center; min-height: 42px; }
.tile-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(174px, 1fr)); gap: 14px; }
.tile { min-height: 178px; border-radius: 8px; border: 1px solid rgba(255,255,255,.10); overflow: hidden; text-decoration: none; box-shadow: 0 16px 40px rgba(0,0,0,.18); }
.tile button, .tile.camera-tile { width: 100%; height: 100%; min-height: 178px; border: 0; color: #fff; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 8px; padding: 18px; cursor: pointer; text-align: center; }
.gate-tile button { background: linear-gradient(160deg, var(--green), var(--green-2)); }
.camera-tile { background: linear-gradient(160deg, var(--blue), var(--blue-2)); }
.tile img { width: 58px; height: 58px; object-fit: contain; }
.tile strong { font-size: 18px; line-height: 1.2; overflow-wrap: anywhere; }
.tile span { color: rgba(255,255,255,.82); font-size: 14px; }
.tile em { font-style: normal; font-weight: 800; font-size: 13px; padding: 6px 10px; border-radius: 8px; background: rgba(0,0,0,.18); }
.tile button:disabled { opacity: .72; cursor: progress; }
.messages { display: grid; gap: 10px; margin-bottom: 18px; }
.message { padding: 12px 14px; border-radius: 8px; border: 1px solid var(--line); background: var(--panel); }
.message.success { border-color: rgba(39, 183, 93, .55); }
.message.error { border-color: rgba(207, 61, 71, .65); }
.empty { padding: 18px; border: 1px dashed var(--line); border-radius: 8px; }
.auth-panel { min-height: calc(100vh - 190px); display: grid; place-items: center; }
.auth-card, .form-panel, .logs-panel, .guest-panel { background: rgba(21, 31, 40, .86); border: 1px solid var(--line); border-radius: 8px; padding: 22px; box-shadow: 0 24px 60px rgba(0,0,0,.24); }
.auth-card { width: min(430px, 100%); }
.stack-form { display: grid; gap: 14px; }
.stack-form p, .stack-form label { display: grid; gap: 7px; margin: 0; color: var(--muted); }
input, select, textarea { width: 100%; border: 1px solid var(--line); border-radius: 8px; background: #0b1117; color: var(--text); padding: 11px 12px; min-height: 42px; }
input[type="checkbox"] { width: auto; min-height: 0; }
.primary-button { border: 0; border-radius: 8px; min-height: 46px; padding: 12px 16px; color: white; background: linear-gradient(160deg, #2878d0, #1d5ba0); font-weight: 800; cursor: pointer; }
.back-link { margin-bottom: 18px; }
.camera-view { text-align: center; }
.snapshot { width: 100%; max-height: 72vh; object-fit: contain; border-radius: 8px; border: 1px solid var(--line); background: #070b10; display: block; margin: 16px auto; }
.created-link { display: grid; gap: 8px; padding: 14px; border-radius: 8px; border: 1px solid rgba(39, 183, 93, .55); margin-bottom: 16px; }
.notice { margin-top: 18px; border: 1px solid rgba(33,103,184,.6); background: rgba(33,103,184,.12); padding: 14px; border-radius: 8px; color: #cfe5ff; }
.filter-bar { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 10px; margin: 14px 0 18px; }
.table-wrap { overflow-x: auto; border: 1px solid var(--line); border-radius: 8px; }
.log-table { width: 100%; border-collapse: collapse; min-width: 820px; }
.log-table th, .log-table td { padding: 11px 12px; text-align: left; border-bottom: 1px solid var(--line); color: #dce5ea; }
.log-table th { background: #101923; color: var(--muted); font-size: 13px; }
.log-success td:last-child, .log-success td:nth-child(6) { color: #62d98b; }
.log-error td:last-child, .log-error td:nth-child(6) { color: #ff8d96; }
.log-denied td:last-child, .log-denied td:nth-child(6) { color: #f3cd66; }
@media (max-width: 680px) {
  .topbar { padding: 0 12px; }
  .page { padding: 20px 12px 34px; }
  .tile-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .tile, .tile button, .tile.camera-tile { min-height: 150px; }
  .tile strong { font-size: 15px; }
  .tile img { width: 48px; height: 48px; }
  .footer { flex-direction: column; }
}

/* Albrecht branding overrides */
html, body { background: #0b1117; }
body { position: relative; isolation: isolate; }
body::before {
  content: "";
  position: fixed;
  inset: 0;
  z-index: -2;
  background:
    linear-gradient(90deg, rgba(7, 11, 16, .90), rgba(7, 11, 16, .70) 46%, rgba(7, 11, 16, .84)),
    linear-gradient(0deg, rgba(7, 11, 16, .78), rgba(7, 11, 16, .18) 54%, rgba(7, 11, 16, .62)),
    url("/static/img/albrecht-background.jpg") center center / cover no-repeat;
}
body::after {
  content: "";
  position: fixed;
  inset: 0;
  z-index: -1;
  pointer-events: none;
  background: rgba(8, 12, 16, .18);
}
.topbar {
  background: rgba(7, 11, 16, .82);
  box-shadow: 0 12px 34px rgba(0, 0, 0, .28);
}
.brand { min-width: 0; gap: 0; }
.brand-mark {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  max-width: min(48vw, 292px);
  height: 46px;
  padding: 4px 10px;
  border-radius: 8px;
  background: rgba(255, 255, 255, .96);
  border: 1px solid rgba(255, 255, 255, .18);
  box-shadow: 0 10px 26px rgba(0, 0, 0, .28);
}
.brand-logo.company-logo {
  width: auto;
  max-width: 270px;
  height: auto;
  max-height: 38px;
  object-fit: contain;
  display: block;
}
.brand-app-name {
  font-size: 14px;
  text-transform: uppercase;
  letter-spacing: 0;
  color: #f6f8f9;
}
.auth-card, .form-panel, .logs-panel, .guest-panel {
  background: rgba(14, 21, 28, .90);
  backdrop-filter: blur(14px);
}
.message, .admin-actions a, .back-link, .secondary-button, input, select, textarea {
  backdrop-filter: blur(12px);
}
.tile {
  box-shadow: 0 18px 44px rgba(0,0,0,.34);
}
.footer {
  background: rgba(7, 11, 16, .72);
  backdrop-filter: blur(12px);
}
.snapshot {
  box-shadow: 0 20px 52px rgba(0, 0, 0, .36);
}
@media (max-width: 680px) {
  .brand { gap: 0; }
  .brand-mark { max-width: 58vw; height: 42px; padding: 4px 7px; }
  .brand-logo.company-logo { max-width: 185px; max-height: 33px; }
  .brand-app-name { font-size: 12px; }
  body::before { background-position: center top; }
}


/* Mobile guest links and setup */
.share-sheet {
  display: grid;
  gap: 14px;
  margin-bottom: 20px;
  padding: 16px;
  border: 1px solid rgba(39, 183, 93, .55);
  border-radius: 8px;
  background: rgba(35, 127, 68, .12);
}
.share-sheet p,
.qr-card p,
.setup-hero p { margin: 0; }
.share-url-label {
  display: grid;
  gap: 7px;
  color: var(--muted);
}
.share-url-input {
  font-size: 15px;
}
.share-actions {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(132px, 1fr));
  gap: 10px;
}
.share-actions a,
.share-actions button {
  width: 100%;
}
.qr-card {
  display: grid;
  justify-items: center;
  gap: 10px;
  padding: 14px;
  border-radius: 8px;
  background: rgba(255, 255, 255, .94);
  color: #121820;
}
.qr-code {
  width: min(100%, 310px);
}
.qr-code svg {
  width: 100%;
  height: auto;
  display: block;
}
.setup-hero {
  margin-bottom: 18px;
}
.setup-panel {
  margin-bottom: 22px;
}
.setup-form {
  display: grid;
  gap: 16px;
}
.setup-list {
  display: grid;
  gap: 14px;
}
.setup-item {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 14px;
  background: rgba(7, 11, 16, .28);
}
.setup-item h3 {
  margin: 0 0 12px;
  font-size: 18px;
}
.setup-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(210px, 1fr));
  gap: 12px;
}
.setup-grid label {
  display: grid;
  gap: 6px;
  color: var(--muted);
}
.setup-grid label em {
  color: #ff9aa2;
  font-style: normal;
  font-size: 13px;
}
.toggle-row {
  display: flex !important;
  align-items: center;
  justify-content: space-between;
  min-height: 42px;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255,255,255,.04);
}
.toggle-row input {
  width: 22px;
  height: 22px;
}
@media (max-width: 680px) {
  .share-actions {
    grid-template-columns: 1fr 1fr;
  }
  .share-actions .primary-button,
  .share-actions .secondary-button {
    min-height: 48px;
    padding-left: 10px;
    padding-right: 10px;
  }
  .setup-grid {
    grid-template-columns: 1fr;
  }
}

/* Dashboard camera live previews */
.camera-live-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
  gap: 14px;
}
.camera-live-tile {
  min-height: 0;
  background: rgba(10, 16, 22, .88);
}
.camera-live-link {
  display: grid;
  color: #fff;
  text-decoration: none;
  min-height: 100%;
}
.camera-live-frame {
  position: relative;
  aspect-ratio: 16 / 9;
  overflow: hidden;
  background: #05080d;
}
.camera-live-tile .camera-live-img {
  width: 100%;
  height: 100%;
  max-width: none;
  max-height: none;
  object-fit: cover;
  display: block;
}
.camera-live-badge,
.camera-live-error {
  position: absolute;
  left: 10px;
  bottom: 10px;
  padding: 5px 8px;
  border-radius: 8px;
  font-size: 12px;
  font-weight: 800;
  background: rgba(35, 127, 68, .88);
  color: #fff;
}
.camera-live-error {
  display: none;
  background: rgba(207, 61, 71, .92);
}
.camera-live-tile[data-camera-state="error"] .camera-live-badge { display: none; }
.camera-live-tile[data-camera-state="error"] .camera-live-error { display: inline-flex; }
.camera-live-tile[data-camera-state="error"] .camera-live-img { opacity: .45; }
.camera-live-meta {
  display: grid;
  gap: 5px;
  padding: 13px 14px 15px;
}
.camera-live-meta strong {
  font-size: 18px;
  line-height: 1.2;
  overflow-wrap: anywhere;
}
.camera-live-meta span {
  color: rgba(255,255,255,.78);
  font-size: 14px;
}
.camera-live-meta em {
  width: max-content;
  max-width: 100%;
  font-style: normal;
  font-weight: 800;
  font-size: 13px;
  padding: 6px 10px;
  border-radius: 8px;
  background: rgba(33, 103, 184, .7);
}
@media (max-width: 680px) {
  .camera-live-grid { grid-template-columns: 1fr; }
  .camera-live-meta strong { font-size: 17px; }
}
