:root {
  color-scheme: light dark;
  font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  color: light-dark(#1c2a38, #edf5fd);
  background: light-dark(#eef3f8, #0c141d);
  line-height: 1.5;
}

* {
  box-sizing: border-box;
}

*:focus-visible {
  outline-width: 3px;
}

body {
  margin: 0;
  padding: 24px;
  line-height: 1.6;
  overflow-x: hidden;
}

[hidden] {
  display: none !important;
}

.login {
  max-width: 420px;
  margin: 12vh auto 0;
}

.login-panel {
  padding: 28px;
  border: 1px solid light-dark(#cfdae6, #34495f);
  border-radius: 16px;
  background: light-dark(#f3f7fb, #101923);
  box-shadow: light-dark(0 8px 25px rgba(24, 53, 78, 0.12), 0 8px 25px rgba(0, 0, 0, 0.3));
}

.login-panel .brand {
  margin-bottom: 28px;
}

.login-panel h2 {
  font-size: 22px;
  margin-bottom: 18px;
}

.login-form {
  display: grid;
  gap: 8px;
}

.login-form label {
  font-size: 13px;
  font-weight: 500;
}

.login-form input[type="text"],
.login-form input[type="password"] {
  width: 100%;
  min-height: 44px;
  padding: 10px;
  color: inherit;
  font: inherit;
  appearance: none;
  border: 1px solid light-dark(#bdcbd8, #4d667d);
  border-radius: 8px;
  background: light-dark(#ffffff, #101a25);
  margin-bottom: 8px;
}

.login-form input[type="text"]:focus,
.login-form input[type="password"]:focus {
  outline: 2px solid light-dark(#2e73b8, #5da8f1);
  outline-offset: 2px;
}

.login-form button {
  grid-column: 1 / -1;
  width: 100%;
  margin-top: 8px;
}

.login-form .secondary-button {
  justify-self: start;
  width: auto;
  min-height: 34px;
  padding: 8px 12px;
  color: light-dark(#1c4f76, #d4ebff);
  font-size: 13px;
  background: light-dark(#dceaf4, #243b4e);
}

.login-form .secondary-button:hover:not(:disabled) {
  background: light-dark(#cbdfea, #315269);
}

.login-message {
  min-height: 24px;
  margin: 8px 0 0;
  color: #c84b4b;
  font-size: 13px;
}

.dashboard {
  width: 100%;
  max-width: 1100px;
  margin: 0 auto;
  overflow: hidden;
  background: light-dark(#f3f7fb, #101923);
  border: 1px solid light-dark(#cfdae6, #34495f);
  border-radius: 16px;
}

.settings-page {
  max-width: 700px;
  margin: 12vh auto 0;
}

.settings-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 16px;
}

.settings-header h1 {
  margin: 0;
  font-size: 20px;
  font-weight: 500;
}

.back-link {
  color: light-dark(#1e609c, #8dccff);
  font-size: 13px;
}

.settings-panel h2 {
  margin-bottom: 8px;
}

.settings-panel .helper-text {
  margin: 0;
}

.settings-form {
  display: grid;
  gap: 8px;
}

.settings-form label {
  font-size: 13px;
  font-weight: 500;
}

.settings-form input {
  width: 100%;
  min-height: 44px;
  padding: 10px;
  color: inherit;
  font: inherit;
  border: 1px solid light-dark(#bdcbd8, #4d667d);
  border-radius: 8px;
  background: light-dark(#ffffff, #101a25);
}

.settings-form input:focus {
  outline: 2px solid light-dark(#2e73b8, #5da8f1);
  outline-offset: 2px;
}

.settings-form button {
  width: 100%;
  margin-top: 8px;
}

.settings-message {
  min-height: 24px;
  margin: 8px 0 0;
  color: light-dark(#2f7b57, #83d1a7);
  font-size: 13px;
}

.token-section {
  margin-top: 28px;
  padding-top: 20px;
  border-top: 1px solid light-dark(#d7e1eb, #354a60);
}

.token-section h2 {
  margin-bottom: 8px;
}

.guest-token-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
}

.guest-token-actions button {
  width: auto;
}

.guest-token-actions .secondary-button {
  margin-left: auto;
  color: light-dark(#1c4f76, #d4ebff);
  background: light-dark(#dceaf4, #243b4e);
}

.guest-token-actions .secondary-button:hover:not(:disabled) {
  background: light-dark(#cbdfea, #315269);
}

.new-token {
  display: block;
  min-height: 44px;
  margin-top: 12px;
  padding: 10px;
  overflow-wrap: anywhere;
  color: light-dark(#1c2a38, #edf5fd);
  border: 1px solid light-dark(#bdcbd8, #4d667d);
  border-radius: 8px;
  background: light-dark(#f3f7fa, #132130);
  font-family: monospace;
}

.token-section > label {
  font-size: 13px;
  font-weight: 500;
}

.token-section > input[type="email"] {
  width: 100%;
  min-height: 44px;
  padding: 10px;
  color: inherit;
  font: inherit;
  border: 1px solid light-dark(#bdcbd8, #4d667d);
  border-radius: 8px;
  background: light-dark(#ffffff, #101a25);
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 14px 18px;
  background: light-dark(#e7eff7, #172534);
  border-bottom: 1px solid light-dark(#cfdae6, #34495f);
}

.brand,
.online,
.section-heading,
.toggle-label {
  display: flex;
  align-items: center;
}

.brand {
  gap: 10px;
}

.brand-copy {
  display: grid;
  gap: 1px;
}

.brand h1 {
  font-size: 18px;
  font-weight: 500;
  margin: 0;
}

.current-user {
  color: light-dark(#5d7082, #aac0d2);
  font-size: 12px;
}

.brand-mark {
  display: grid;
  width: 29px;
  height: 29px;
  place-items: center;
  border-radius: 50%;
  background: light-dark(#2d71b6, #61abf4);
  color: white;
  font-size: 12px;
  font-weight: 500;
}

.online {
  gap: 7px;
  font-size: 13px;
}

.guest-expiry {
  margin-left: auto;
  color: light-dark(#8a5a18, #f2c46d);
  font-size: 12px;
}

.logout-button {
  width: auto;
  padding: 7px 10px;
  font-size: 12px;
}

.settings-button {
  display: grid;
  width: 36px;
  height: 36px;
  place-items: center;
  color: inherit;
  border: 1px solid light-dark(#bdcbd8, #4d667d);
  border-radius: 8px;
  font-size: 22px;
  line-height: 1;
  text-decoration: none;
  transition: background-color 150ms ease, transform 100ms ease;
}

.settings-button:hover {
  background: light-dark(#d7e5f1, #243b4e);
}

.settings-button:active {
  transform: scale(0.98);
}

.settings-button:focus-visible {
  outline: 2px solid light-dark(#1c2a38, #edf5fd);
  outline-offset: 2px;
}

@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.6; }
}

.status-dot {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: #2f9c68;
  animation: pulse 2s cubic-bezier(0.4, 0, 0.6, 1) infinite;
}

.status-dot[data-status="offline"] {
  background: #c84b4b;
  animation: none;
}

.last-updated {
  color: light-dark(#5d7082, #aac0d2);
  font-size: 11px;
}

.layout {
  display: grid;
  grid-template-columns: minmax(0, 1.45fr) minmax(240px, 0.8fr);
  gap: 16px;
  padding: 16px;
  width: 100%;
  max-width: 100%;
  min-width: 0;
}

.primary-column,
.side-column {
  display: grid;
  align-content: start;
  gap: 16px;
  min-width: 0;
}

.panel {
  width: 100%;
  max-width: 100%;
  min-width: 0;
  overflow: hidden;
  padding: 15px;
  border: 1px solid light-dark(#d7e1eb, #354a60);
  border-radius: 11px;
  background: light-dark(#ffffff, #192736);
  box-shadow: light-dark(0 1px 3px rgba(0,0,0,0.05), 0 1px 3px rgba(0,0,0,0.2));
}

h2 {
  margin: 0 0 12px;
  font-size: 15px;
  font-weight: 500;
}

.section-heading {
  justify-content: space-between;
  gap: 10px;
}

.section-heading h2 {
  margin: 0;
}

.toggle-label {
  gap: 6px;
  font-size: 12px;
  white-space: nowrap;
  cursor: pointer;
  user-select: none;
}

.camera-off {
  display: grid;
  min-height: 205px;
  place-content: center;
  text-align: center;
  border-radius: 8px;
  background: light-dark(#e9eef3, #101a25);
  color: light-dark(#5d7082, #aec2d4);
}

.camera-off p {
  margin: 0 0 6px;
  font-size: 14px;
}

.map {
  position: relative;
  min-height: 190px;
  overflow: hidden;
  border-radius: 8px;
  background: light-dark(#edf3f7, #152230);
}

.wall {
  position: absolute;
  border-radius: 5px;
  background: light-dark(#a5bbc9, #496378);
}

.wall-top { top: 17%; left: 9%; width: 60%; height: 8px; }
.wall-left { top: 17%; bottom: 20%; left: 9%; width: 8px; }
.wall-right { top: 17%; bottom: 20%; right: 10%; width: 8px; }
.wall-bottom { bottom: 20%; left: 9%; width: 82%; height: 8px; }
.wall-divider { top: 17%; left: 55%; height: 43%; width: 8px; }

.room {
  position: absolute;
  color: light-dark(#557084, #afc1d0);
  font-size: 12px;
}

.room-living { top: 35%; left: 24%; }
.room-kitchen { top: 35%; left: 67%; }
.room-hall { bottom: 7%; left: 35%; }

.r2-position {
  position: absolute;
  top: 59%;
  left: 42%;
  width: 15px;
  height: 15px;
  border-radius: 50%;
  background: light-dark(#2873bb, #64b0fa);
  box-shadow: 0 0 0 4px light-dark(#d6e6f4, #27455f);
}

.command-row {
  display: flex;
  gap: 8px;
  align-items: center;
  min-height: 44px;
}

input[type="text"] {
  min-width: 0;
  flex: 1;
  padding: 10px;
  color: inherit;
  font: inherit;
  border: 1px solid light-dark(#bdcbd8, #4d667d);
  border-radius: 8px;
  background: light-dark(#ffffff, #101a25);
  transition: border-color 150ms ease, outline 150ms ease;
}

input[type="text"]:focus {
  outline: 2px solid light-dark(#2e73b8, #5da8f1);
  outline-offset: 2px;
}

input[type="text"]:disabled {
  opacity: 0.6;
  cursor: not-allowed;
  background: light-dark(#f5f5f5, #0a0f18);
}

input[type="checkbox"] {
  width: 16px;
  height: 16px;
  cursor: pointer;
  accent-color: light-dark(#2e73b8, #5da8f1);
}

input.toggle-input {
  appearance: none;
  -webkit-appearance: none;
  flex: 0 0 16px;
  width: 16px;
  height: 16px;
  min-width: 16px;
  min-height: 16px;
  margin: 0;
  border: 1px solid light-dark(#6c8498, #86a6bf);
  border-radius: 3px;
  background: light-dark(#ffffff, #101a25);
  cursor: pointer;
}

.toggle-input:checked {
  background: light-dark(#2e73b8, #5da8f1);
  box-shadow: inset 0 0 0 3px light-dark(#ffffff, #101a25);
}

input[type="checkbox"]:disabled {
  cursor: not-allowed;
  opacity: 0.6;
}

button {
  padding: 10px 13px;
  border: 0;
  border-radius: 8px;
  color: white;
  font: inherit;
  background: light-dark(#2e73b8, #5da8f1);
  cursor: pointer;
  transition: background-color 150ms ease, transform 100ms ease;
}

button:hover:not(:disabled) {
  background: light-dark(#1e5aa5, #4a96d9);
}

button:active:not(:disabled) {
  transform: scale(0.98);
}

button:disabled {
  opacity: 0.6;
  cursor: not-allowed;
}

button:focus-visible {
  outline: 2px solid light-dark(#1c2a38, #edf5fd);
  outline-offset: 2px;
}

.helper-text {
  min-height: 20px;
  margin: 10px 0 0;
  color: light-dark(#4d687e, #bbd0e4);
  font-size: 13px;
}

.status-grid {
  display: grid;
  grid-template-columns: minmax(60px, auto) 1fr;
  gap: 8px 12px;
  margin: 0;
  padding: 9px;
  background: light-dark(#f3f7fa, #132130);
  border-radius: 8px;
}

.status-grid dt {
  margin: 0;
  color: light-dark(#5d7082, #aac0d2);
  font-size: 12px;
  font-weight: 500;
}

.status-grid dd {
  margin: 0;
  font-size: 14px;
  font-weight: 500;
  text-align: right;
}

.status-grid dd.warning {
  color: #c84b4b;
}

.status-message {
  min-height: 20px;
  margin: 10px 0 0;
  color: #c84b4b;
  font-size: 13px;
}

.indicators {
  display: flex;
  flex-wrap: wrap;
  gap: 7px;
}

.indicators li {
  list-style: none;
}

.indicator {
  padding: 6px 8px;
  border-radius: 7px;
  background: light-dark(#edf2f6, #243546);
  font-size: 12px;
  transition: opacity 150ms ease;
}

.indicator.active {
  color: light-dark(#185a94, #d5edff);
  background: light-dark(#dbeafa, #244b6c);
}

.command-log {
  display: grid;
  gap: 9px;
  margin: 0;
  padding: 0;
  list-style: none;
}

.command-log li {
  padding-left: 9px;
  border-left: 3px solid light-dark(#91b2cf, #547a9c);
  font-size: 13px;
  transition: background-color 150ms ease, padding 150ms ease, border-radius 150ms ease, margin-left 150ms ease;
  border-radius: 0;
}

time {
  margin-right: 6px;
  color: light-dark(#5d7082, #aac0d2);
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
  border-width: 0;
}

.sr-only:focus {
  clip-path: none;
  position: static;
  width: auto;
  height: auto;
  margin: 0;
  overflow: visible;
  padding: 4px;
  background: light-dark(#2e73b8, #5da8f1);
  color: white;
  border-radius: 4px;
}

.skip-link {
  position: absolute;
  top: -40px;
  left: 0;
  background: light-dark(#2e73b8, #5da8f1);
  color: white;
  padding: 8px 12px;
  border-radius: 0 0 8px 0;
  z-index: 100;
  font-size: 14px;
  text-decoration: none;
}

.skip-link:focus {
  top: 0;
  outline: 2px solid light-dark(#1c2a38, #edf5fd);
  outline-offset: 2px;
}

.indicator:hover {
  opacity: 0.8;
}

.command-log li:hover {
  background: light-dark(#f8fafb, #1f3442);
  border-radius: 6px;
  margin-left: -9px;
  padding-left: 18px;
}

@media (prefers-reduced-motion: reduce) {
  * {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
  
  .status-dot {
    animation: none;
  }
}

@media (prefers-contrast: more) {
  .panel {
    border-width: 2px;
  }
  
  button {
    border: 1px solid currentColor;
  }
  
  input[type="text"] {
    border-width: 2px;
  }
}

@media (max-width: 700px) {
  body { 
    padding: 12px; 
  }
  
  .layout { 
    grid-template-columns: minmax(0, 1fr);
  }

  .topbar {
    flex-wrap: wrap;
  }

  .topbar .online {
    margin-left: auto;
  }

  .topbar .settings-button {
    flex: 0 0 36px;
  }
  
  button,
  input[type="checkbox"],
  input[type="text"],
  .indicator {
    min-height: 44px;
    min-width: 44px;
  }
  
  input[type="text"] {
    padding: 12px;
    font-size: 16px;
  }

  input.toggle-input {
    width: 16px;
    height: 16px;
    min-width: 16px;
    min-height: 16px;
  }
}

@media print {
  body {
    background: white;
    color: black;
    padding: 0;
  }
  
  .skip-link,
  .dashboard {
    border: none;
    box-shadow: none;
  }
  
  .topbar {
    border-bottom: 1px solid #ccc;
  }
  
  .layout {
    padding: 0;
  }
  
  button,
  .toggle-label {
    display: none;
  }
}
