* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

body {
  font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  min-height: 100vh;
  padding: 20px;
}

body.logged-out .container {
  display: none;
}

body.logged-out .login-gate {
  display: grid;
}

body:not(.logged-out) .login-gate {
  display: none;
}

.login-gate {
  min-height: calc(100vh - 40px);
  display: none;
  place-items: center;
  padding: 20px;
}

.login-gate-card {
  background: rgba(255, 255, 255, 0.95);
  border-radius: 16px;
  padding: 32px 28px;
  text-align: center;
  box-shadow: 0 12px 30px rgba(0, 0, 0, 0.25);
  max-width: 520px;
  width: 100%;
}

.login-gate-card h1 {
  color: #2d2f77;
  margin-bottom: 8px;
  font-size: 2rem;
}

.login-gate-card .subtitle {
  color: #333;
  margin-bottom: 20px;
  opacity: 0.85;
}

.login-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 12px;
  margin-bottom: 16px;
  text-align: left;
}

.login-grid label {
  font-size: 0.9em;
  color: #333;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.login-grid input {
  padding: 10px 12px;
  border-radius: 8px;
  border: 1px solid #ccc;
}

.login-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 14px 21px;
  border-radius: 999px;
  background: #0d47a1;
  color: #fff;
  font-weight: 700;
  font-size: 1.05em;
  border: none;
  text-decoration: none;
  box-shadow: 0 8px 18px rgba(13, 71, 161, 0.35);
  cursor: pointer;
}

.login-button:hover {
  background: #0b3d91;
}

.login-status {
  margin-top: 10px;
  font-size: 0.9em;
  color: #b00020;
  font-weight: 600;
}

.login-links {
  margin-top: 8px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.login-links.split {
  margin-top: 14px;
  flex-direction: row;
  justify-content: space-between;
  gap: 12px;
}

.login-secondary {
  background: #ffffff;
  color: #0d47a1;
  border: 2px solid #0d47a1;
  padding: 10px 15px;
  font-size: 0.9em;
}

.login-secondary:hover {
  background: rgba(13, 71, 161, 0.1);
}

.modal {
  position: fixed;
  inset: 0;
  background: rgba(20, 20, 35, 0.55);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
}

.modal.hidden {
  display: none;
}

.modal-content {
  background: #ffffff;
  border-radius: 14px;
  padding: 24px;
  max-width: 420px;
  width: calc(100% - 40px);
  text-align: center;
  box-shadow: 0 16px 40px rgba(0, 0, 0, 0.35);
}

.modal-content h2 {
  color: #2d2f77;
  margin-bottom: 10px;
}

.modal-content p {
  margin: 8px 0;
  color: #333;
}

.container {
  max-width: 1200px;
  margin: 0 auto;
}

main {
  display: flex;
  flex-direction: column;
  gap: 30px;
}

.container {
  width: 100%;
  max-width: 1200px;
}

header {
  text-align: center;
  color: white;
  margin-bottom: 40px;
}

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

header .header-row > div {
  text-align: left;
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.nav-buttons {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

header h1 {
  font-size: 2.5em;
  margin-bottom: 10px;
}

.subtitle {
  font-size: 1.2em;
  opacity: 0.9;
}

main {
  min-height: 300px;
}

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

.refresh-button {
  background: #0d47a1;
  color: #fff;
  border: none;
  border-radius: 8px;
  padding: 10px 16px;
  font-weight: 700;
  cursor: pointer;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.2);
}

.refresh-button:hover {
  background: #0b3d91;
}

.logout-button {
  background: rgba(255, 255, 255, 0.2);
  color: #fff;
  border: 1px solid rgba(255, 255, 255, 0.5);
  border-radius: 999px;
  padding: 10px 16px;
  font-weight: 700;
  cursor: pointer;
}

.logout-button:hover {
  background: rgba(255, 255, 255, 0.3);
}

.nav-button {
  background: rgba(255, 255, 255, 0.2);
  color: #fff;
  border: 1px solid rgba(255, 255, 255, 0.5);
  border-radius: 999px;
  padding: 10px 16px;
  font-weight: 700;
  text-decoration: none;
}

.nav-button:hover {
  background: rgba(255, 255, 255, 0.3);
}

.refresh-status {
  color: rgba(255, 255, 255, 0.9);
  font-size: 0.9em;
}

.loading {
  text-align: center;
  color: white;
  font-size: 1.2em;
  padding: 40px;
}

.loading.hidden {
  display: none;
}

.weather-container {
  transition: opacity 0.3s ease-in-out;
}

.weather-container.hidden {
  display: none;
}

.error {
  background-color: rgba(220, 53, 69, 0.9);
  color: white;
  padding: 20px;
  border-radius: 8px;
  text-align: center;
  font-size: 1.1em;
  transition: opacity 0.3s ease-in-out;
  width: 100%;
}

.error.hidden {
  display: none;
}

.weather-table-wrap {
  background: rgba(255, 255, 255, 0.95);
  border-radius: 12px;
  padding: 18px;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.3);
  overflow-x: auto;
}

.weather-table {
  width: 100%;
  border-collapse: collapse;
  min-width: 100%;
  table-layout: fixed;
}

.weather-table thead {
  background: #2d2f77;
  color: #fff;
}

.weather-table th,
.weather-table td {
  padding: 12px 10px;
  text-align: left;
  border-bottom: 1px solid #e0e0e0;
  font-size: 0.95em;
  white-space: nowrap;
}

.weather-table th:last-child,
.weather-table td:last-child {
  padding-right: 18px;
}

.weather-table tbody tr:nth-child(even) {
  background: rgba(0, 0, 0, 0.03);
}

.trend-up {
  color: #2e7d32;
  font-weight: 700;
}

.trend-down {
  color: #c62828;
  font-weight: 700;
}

.trend-flat {
  color: #616161;
  font-weight: 700;
}

.last-update {
  text-align: center;
  color: rgba(255, 255, 255, 0.8);
  font-size: 0.9em;
  margin-top: 20px;
  padding-top: 20px;
  border-top: 1px solid rgba(255, 255, 255, 0.3);
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  flex-wrap: wrap;
}

footer {
  text-align: center;
  color: rgba(255, 255, 255, 0.7);
  margin-top: 40px;
  font-size: 0.9em;
}

@media (max-width: 720px) {
  header .header-row {
    flex-direction: column;
    align-items: center;
    text-align: center;
  }

  header .header-row > div {
    text-align: center;
  }

  .header-actions {
    justify-content: center;
  }
}

.thermostat-section {
  margin-top: 40px;
}

.thermostat-section h2 {
  color: white;
  text-align: center;
  margin-bottom: 20px;
  font-size: 1.8em;
}

.thermostat-group {
  margin-bottom: 28px;
}

.thermostat-group h3 {
  color: #f5f7ff;
  margin: 0 0 12px;
  font-size: 1.2em;
  letter-spacing: 0.02em;
}

.thermostats-table {
  width: 100%;
  max-width: none;
  margin: 0;
  border-collapse: collapse;
  background: rgba(255, 255, 255, 0.95);
  border-radius: 10px;
  overflow: hidden;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.3);
  table-layout: fixed;
}

.thermostat-section {
  overflow-x: auto;
}

.thermostats-table thead {
  background: #2196F3;
  color: white;
  font-weight: 600;
}

.thermostats-table th {
  padding: 12px;
  text-align: left;
  border-bottom: 2px solid #1976D2;
  font-size: 0.95em;
}

.thermostats-table td {
  padding: 12px;
  border-bottom: 1px solid #e0e0e0;
  font-size: 0.9em;
}

.thermo-alert {
  color: #b00020;
  font-weight: 700;
}

.thermo-ok {
  color: #1b5e20;
  font-weight: 700;
}

.thermo-error {
  font-weight: 800;
  animation: thermoFlash 1.2s infinite;
}

@keyframes thermoFlash {
  0% { color: #b00020; background: transparent; }
  33% { color: #ffeb3b; background: transparent; }
  66% { color: #000000; background: transparent; }
  100% { color: #b00020; background: transparent; }
}

.thermostats-table tbody tr:hover {
  background: #f5f5f5;
}

.thermostats-table tbody tr:last-child td {
  border-bottom: none;
}

.temp-cold {
  color: #1976D2;
  font-weight: 600;
}

.temp-warm {
  color: #D32F2F;
  font-weight: 600;
}

.temp-offline {
  color: #999;
  font-style: italic;
}

.mode-heat {
  background: #FFEBEE;
  color: #C62828;
}

.mode-cool {
  background: #E3F2FD;
  color: #1565C0;
}

.mode-auto {
  background: #F3E5F5;
  color: #7B1FA2;
}

.mode-off {
  background: #F5F5F5;
  color: #666;
}

.mode-badge {
  padding: 4px 8px;
  border-radius: 4px;
  font-weight: 600;
  font-size: 0.85em;
  display: inline-block;
}

.occupancy-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 4px 8px;
  border-radius: 999px;
  font-weight: 700;
  font-size: 0.75em;
  letter-spacing: 0.03em;
}

.occupancy-yes {
  background: #e8f5e9;
  color: #1b5e20;
}

.occupancy-no {
  background: #f5f5f5;
  color: #616161;
}

.source-badge {
  display: inline-block;
  padding: 4px 8px;
  border-radius: 999px;
  font-size: 0.75em;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  background: rgba(255, 255, 255, 0.2);
  color: rgba(255, 255, 255, 0.95);
}

.source-badge.live {
  background: rgba(76, 175, 80, 0.9);
  color: #fff;
}

.source-badge.mock {
  background: rgba(255, 193, 7, 0.9);
  color: #2f2f2f;
}

@media (max-width: 600px) {
  header h1 {
    font-size: 1.8em;
  }
}
