* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: "Segoe UI", Arial, sans-serif;
  background: #f4f7fb;
  color: #1f2937;
}

/* ── Login page ─────────────────────────────────────── */
.login-body {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
}

.login-card {
  background: #fff;
  border: 1px solid #d9e2ec;
  border-radius: 16px;
  padding: 40px 36px;
  width: 100%;
  max-width: 400px;
  box-shadow: 0 8px 24px rgba(15,23,42,0.08);
}

.login-title {
  margin: 0 0 28px;
  font-size: 1.4rem;
  text-align: center;
  color: #1e3a5f;
}

.login-form {
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.login-label {
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-size: 0.88rem;
  font-weight: 600;
  color: #374151;
}

.login-input {
  padding: 9px 12px;
  border: 1px solid #d1d5db;
  border-radius: 8px;
  font-size: 1rem;
  font-family: inherit;
  outline: none;
  transition: border-color 0.15s;
}
.login-input:focus { border-color: #2563eb; }

.login-btn {
  display: block;
  width: 100%;
  padding: 11px;
  border-radius: 8px;
  font-size: 1rem;
  font-family: inherit;
  font-weight: 600;
  cursor: pointer;
  text-align: center;
  text-decoration: none;
  border: none;
  margin-top: 4px;
}

.login-btn--primary {
  background: #1e3a5f;
  color: #fff;
}
.login-btn--primary:hover { background: #16305a; }

.login-btn--oidc {
  background: #fff;
  color: #1e3a5f;
  border: 2px solid #1e3a5f;
  margin-top: 0;
}
.login-btn--oidc:hover { background: #eef2f7; }

.login-divider {
  display: flex;
  align-items: center;
  gap: 10px;
  margin: 18px 0 14px;
  color: #9ca3af;
  font-size: 0.85rem;
}
.login-divider::before,
.login-divider::after {
  content: "";
  flex: 1;
  height: 1px;
  background: #e5e7eb;
}

.login-msg {
  padding: 10px 14px;
  border-radius: 8px;
  font-size: 0.9rem;
  margin: 0 0 16px;
}
.login-msg--error { background: #fef2f2; color: #dc2626; border: 1px solid #fecaca; }
.login-msg--info  { background: #f0fdf4; color: #16a34a; border: 1px solid #bbf7d0; }

.page {
  max-width: 1100px;
  margin: 0 auto;
  padding: 24px 16px 40px;
}

.page-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 20px;
}

.page-header h1 {
  margin: 0;
  font-size: 2rem;
}

.admin-link {
  text-decoration: none;
  color: #4a5568;
  border: 1px solid #cbd5e0;
  border-radius: 8px;
  padding: 6px 8px;
  line-height: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}
.admin-link:hover { background: #f1f5f9; color: #1a202c; }

.header-actions {
  display: flex;
  align-items: center;
  gap: 12px;
}

.logout-btn { background: none; 
  border: 1px solid #cbd5e0; 
  border-radius: 8px; 
  cursor: pointer; 
  color: #4a5568; 
  padding: 6px 8px; 
  line-height: 0; 
  display: inline-flex; 
  align-items: center; 
  justify-content: center; 
} 
  
.logout-btn:hover { 
  background: #f1f5f9; 
  color: #1a202c; 
}

.back-link {
  font-size: 1rem;
  text-decoration: none;
  color: #4a5568;
  padding: 6px 14px;
  border: 1px solid #cbd5e0;
  border-radius: 6px;
}
.back-link:hover { background: #edf2f7; }

/* Tab navigation */
.tab-nav {
  display: flex;
  gap: 4px;
  margin-bottom: 20px;
  border-bottom: 2px solid #d9e2ec;
}
.tab-btn {
  padding: 8px 20px;
  font-size: 1rem;
  border: none;
  background: none;
  cursor: pointer;
  color: #4a5568;
  border-bottom: 3px solid transparent;
  margin-bottom: -2px;
  font-family: inherit;
}
.tab-btn:hover { color: #1a202c; }
.tab-btn.active { color: #2563eb; border-bottom-color: #2563eb; font-weight: 600; }

.tab-panel.hidden { display: none; }

/* Admin table */
.admin-panel { max-width: 900px; }
.admin-section { margin-bottom: 36px; }
.admin-section h2 { font-size: 1.1rem; margin: 0 0 10px; color: #1f2937; }
.log-count { font-size: 0.85rem; color: #6b7280; font-weight: 400; }
.admin-table {
  width: 100%;
  border-collapse: collapse;
  margin-top: 12px;
}
.admin-table th, .admin-table td {
  padding: 8px 12px;
  text-align: left;
  border-bottom: 1px solid #e2e8f0;
}
.admin-table th { background: #f8fafc; font-weight: 600; }
.log-table { font-size: 0.85rem; }
.log-ts { white-space: nowrap; color: #6b7280; }
.log-type { white-space: nowrap; font-weight: 600; min-width: 80px; }
.status-online  { color: #16a34a; }
.status-offline { color: #dc2626; }
.action-btn {
  display: inline-block;
  padding: 8px 18px;
  background: #2563eb;
  color: #fff;
  border-radius: 8px;
  text-decoration: none;
  font-size: 0.95rem;
}
.action-btn:hover { background: #1d4ed8; }

.empty-tab { color: #6b7280; }

.page-footer {
  margin-top: 24px;
  text-align: center;
}

.build-meta {
  color: #9ca3af;
  font-size: 0.75rem;
}

.areas {
  display: grid;
  gap: 16px;
}

.area-card {
  background: #ffffff;
  border: 1px solid #d9e2ec;
  border-left: 6px solid var(--area-color);
  border-radius: 14px;
  padding: 14px;
  box-shadow: 0 4px 12px rgba(15, 23, 42, 0.06);
}

.area-card h2 {
  margin: 0 0 12px;
  font-size: 1.2rem;
}

/* Area header with inline toggle */
.area-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 12px;
}
.area-header h2 { margin: 0; }

/* Global switch row at top of heating tab */
.global-switch-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: #1e3a5f;
  color: #fff;
  border-radius: 12px;
  padding: 14px 18px;
  margin-bottom: 18px;
}
.global-switch-label {
  font-size: 1.05rem;
  font-weight: 600;
}

.global-switch-row--disabled {
  background: #9ca3af;
  color: #eef2f7;
}

/* Larger toggle for area/global controls */
.toggle--large .slider,
.toggle--area .slider {
  width: 52px;
  height: 28px;
}
.toggle--large .slider::before,
.toggle--area .slider::before {
  width: 22px;
  height: 22px;
  bottom: 3px;
  left: 3px;
}
.toggle--large input:checked + .slider::before,
.toggle--area input:checked + .slider::before {
  transform: translateX(24px);
}

.house-card {
  background: #f8fafc;
  border: 1px solid #e5e7eb;
  border-radius: 12px;
  padding: 12px 14px;
}

.house-card + .house-card {
  margin-top: 10px;
}

.house-card h3 {
  margin: 0 0 10px;
  font-size: 1rem;
  color: #374151;
  letter-spacing: 0.01em;
}

.room-card--alert {
  background: #fff5f5;
  border-radius: 8px;
  padding-left: 8px;
  padding-right: 8px;
  border-top-color: #fecaca;
}

.temp--alert {
  color: #dc2626;
  font-weight: 700;
}

.alert-threshold {
  font-size: 0.78rem;
  color: #6b7280;
  font-style: italic;
}

.room-card {
  display: grid;
  grid-template-columns: 1fr auto;
  align-items: center;
  gap: 12px;
  padding: 12px 10px;
  background: #ffffff;
  border: 1px solid #e5e7eb;
  border-radius: 10px;
  margin-top: 8px;
}

.room-card--overheat {
  border-color: #f97316;
  background: #fff7ed;
}

.room-meta {
  display: flex;
  flex-direction: column;
  gap: 5px;
  min-width: 0;
}

.room-name {
  font-weight: 700;
  font-size: 1rem;
}

.room-readings {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  align-items: center;
}

.room-reading {
  display: flex;
  align-items: center;
  gap: 4px;
  font-size: 0.88rem;
  color: #374151;
  white-space: nowrap;
}

.room-reading .icon {
  font-size: 1rem;
  line-height: 1;
}

.room-reading--temp-hot {
  color: #dc2626;
  font-weight: 700;
}

.room-reading--overheat {
  color: #ea580c;
  font-weight: 700;
}

.room-reading--muted {
  color: #9ca3af;
}

.room-controls {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-shrink: 0;
}

.wifi {
  display: flex;
  align-items: center;
  min-width: 24px;
  justify-content: flex-end;
}

.wifi-bars {
  display: inline-flex;
  align-items: flex-end;
  gap: 2px;
  height: 14px;
}

.wifi-bars span {
  width: 3px;
  background: #d1d5db;
  border-radius: 2px;
}

.wifi-bars span:nth-child(1) { height: 4px; }
.wifi-bars span:nth-child(2) { height: 7px; }
.wifi-bars span:nth-child(3) { height: 10px; }
.wifi-bars span:nth-child(4) { height: 13px; }

.wifi-bars.level-1 span:nth-child(1),
.wifi-bars.level-2 span:nth-child(-n+2),
.wifi-bars.level-3 span:nth-child(-n+3),
.wifi-bars.level-4 span {
  background: #22c55e;
}

.wifi.offline .wifi-bars span {
  background: #d1d5db !important;
}

.toggle {
  position: relative;
  width: 46px;
  height: 26px;
  display: inline-block;
}

.toggle input {
  opacity: 0;
  width: 0;
  height: 0;
}

.slider {
  position: absolute;
  inset: 0;
  background: #cbd5e1;
  border-radius: 999px;
  transition: background 0.2s ease;
}

.slider:before {
  content: "";
  position: absolute;
  left: 3px;
  top: 3px;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: #ffffff;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.25);
  transition: transform 0.2s ease;
}

.toggle input:checked + .slider {
  background: #22c55e;
}

.toggle input:checked + .slider:before {
  transform: translateX(20px);
}

.toggle input:disabled + .slider {
  background: #e5e7eb;
  cursor: not-allowed;
}

@media (max-width: 640px) {
  .room-card {
    grid-template-columns: 1fr;
  }

  .room-controls {
    width: 100%;
    justify-content: space-between;
  }

  .room-readings {
    gap: 8px;
  }
}
