:root {
  --bg: #f6f4ef;
  --surface: #ffffff;
  --surface-active: #fff7ed;
  --text: #1f2937;
  --muted: #6b7280;
  --border: #e5e7eb;
  --heat: #ea580c;
  --heat-hover: #c2410c;
  --stop: #1e293b;
  --stop-hover: #0f172a;
  --danger: #dc2626;
  --success: #15803d;
  --radius: 18px;
  --shadow: 0 8px 24px rgba(15, 23, 42, 0.06);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
}

.topbar {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 10;
}

.topbar-inner {
  max-width: 1040px;
  margin: 0 auto;
  padding: 0.75rem 1rem;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 0.65rem;
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  font-weight: 800;
  font-size: 1.15rem;
  color: var(--text);
  text-decoration: none;
}

.nav-links {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.5rem;
}

.nav-link {
  color: var(--text);
  text-decoration: none;
  font-weight: 600;
  padding: 0.45rem 0.85rem;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--surface);
  cursor: pointer;
  font-size: 0.95rem;
}

.nav-link:hover {
  background: #f3f4f6;
}

.nav-btn {
  font-family: inherit;
}

.mode-badge {
  font-size: 0.8rem;
  font-weight: 700;
  padding: 0.25rem 0.65rem;
  border-radius: 999px;
}

.mode-mock {
  background: #fef3c7;
  color: #92400e;
}

.container {
  max-width: 1040px;
  margin: 0 auto;
  padding: 1.5rem 1.25rem 3rem;
}

.dashboard-header,
.settings-header {
  margin-bottom: 1.25rem;
}

h1 {
  margin: 0 0 0.25rem;
  font-size: 1.75rem;
}

.subtitle {
  margin: 0;
  color: var(--muted);
}

.valve-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(290px, 1fr));
  gap: 1.25rem;
}

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 1.35rem;
}

.valve-card {
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  gap: 1.1rem;
  transition: border-color 0.2s ease, background-color 0.2s ease;
}

.valve-card-active {
  background: var(--surface-active);
  border-color: #fb923c;
  box-shadow: 0 10px 28px rgba(234, 88, 12, 0.14);
}

.valve-card-offline {
  opacity: 0.78;
}

.valve-card-top {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 0.75rem;
}

.room-name {
  margin: 0 0 0.4rem;
  font-size: 1.35rem;
}

.status-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.45rem;
}

.pill {
  display: inline-block;
  font-size: 0.85rem;
  font-weight: 700;
  padding: 0.2rem 0.65rem;
  border-radius: 999px;
}

.pill-idle {
  background: #f3f4f6;
  color: #374151;
}

.pill-heating {
  background: #ffedd5;
  color: #c2410c;
}

.pill-offline {
  background: #fee2e2;
  color: #b91c1c;
}

.meta-chip {
  font-size: 0.82rem;
  color: var(--muted);
}

.temp-display {
  text-align: right;
  white-space: nowrap;
}

.temp-value {
  font-size: 2.15rem;
  font-weight: 800;
  letter-spacing: -0.02em;
}

.temp-unit {
  font-size: 1.05rem;
  font-weight: 700;
  color: var(--muted);
  margin-left: 0.1rem;
}

.target-hint {
  margin: 0 0 0.75rem;
  color: var(--muted);
  font-size: 0.95rem;
}

.active-timer-box {
  background: #ffffff;
  border: 1px solid #fed7aa;
  border-radius: 12px;
  padding: 0.75rem 0.9rem;
  margin-bottom: 0.85rem;
}

.timer-headline {
  font-size: 0.95rem;
}

.timer-countdown {
  font-size: 1.15rem;
  font-weight: 800;
  color: var(--heat);
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  min-height: 64px;
  padding: 0.85rem 1.2rem;
  border-radius: 14px;
  border: none;
  font-family: inherit;
  font-size: 1.15rem;
  font-weight: 800;
  cursor: pointer;
  text-decoration: none;
  transition: transform 0.08s ease, background-color 0.15s ease;
}

.btn:active:not(:disabled) {
  transform: scale(0.985);
}

.btn-heat {
  background: var(--heat);
  color: #ffffff;
}

.btn-heat:hover {
  background: var(--heat-hover);
}

.btn-stop {
  background: var(--stop);
  color: #ffffff;
}

.btn-stop:hover {
  background: var(--stop-hover);
}

.btn-disabled {
  background: #e5e7eb;
  color: #6b7280;
  cursor: not-allowed;
}

.btn-secondary {
  width: auto;
  min-height: 44px;
  font-size: 0.95rem;
  font-weight: 700;
  background: #1f2937;
  color: #ffffff;
  padding: 0.55rem 1rem;
  border-radius: 10px;
}

.btn-secondary:hover {
  background: #111827;
}

.btn-compact {
  width: auto;
  min-height: 44px;
  font-size: 0.95rem;
  padding: 0.55rem 1.1rem;
  border-radius: 10px;
}

.btn-danger-outline {
  width: auto;
  min-height: 44px;
  font-size: 0.95rem;
  padding: 0.55rem 1rem;
  border-radius: 10px;
  background: transparent;
  color: var(--danger);
  border: 1px solid #fecaca;
}

.disabled-reason {
  margin: 0.55rem 0 0;
  font-size: 0.9rem;
  color: var(--muted);
  text-align: center;
}

.alert {
  padding: 0.75rem 1rem;
  border-radius: 12px;
  font-weight: 600;
  margin-bottom: 1rem;
}

.alert-error {
  background: #fee2e2;
  color: #991b1b;
  border: 1px solid #fecaca;
}

.alert-success {
  background: #dcfce7;
  color: #166534;
  border: 1px solid #bbf7d0;
}

.settings-panel,
.settings-valve-card,
.room-selector-bar {
  margin-bottom: 1.25rem;
}

.room-selector-form {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  gap: 0.75rem;
}

.room-selector-field {
  flex: 1 1 280px;
}

.room-selector-field select {
  font-size: 1rem;
  font-weight: 600;
  padding: 0.65rem 0.85rem;
}

.panel-header {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  align-items: center;
  gap: 0.75rem;
  margin-bottom: 0.85rem;
}

.panel-header h2,
.panel-header h3 {
  margin: 0 0 0.2rem;
}

.muted {
  color: var(--muted);
  margin: 0;
}

.form-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(210px, 1fr));
  gap: 0.9rem;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  font-size: 0.9rem;
  font-weight: 600;
}

.field input,
.field select {
  font-family: inherit;
  font-size: 0.95rem;
  padding: 0.55rem 0.7rem;
  border: 1px solid #d1d5db;
  border-radius: 10px;
  background: #ffffff;
}

.field-checkbox {
  flex-direction: row;
  align-items: center;
  padding-top: 1.4rem;
}

.field-checkbox input {
  width: 1.15rem;
  height: 1.15rem;
}

.form-actions {
  margin-top: 1rem;
}

.button-row {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem;
  margin-top: 0.75rem;
}

.inline-form {
  display: inline;
}

.raw-inspector {
  margin-top: 1rem;
  border-top: 1px solid var(--border);
  padding-top: 0.75rem;
}

.raw-inspector summary {
  cursor: pointer;
  font-weight: 600;
  color: var(--muted);
}

.raw-inspector pre {
  background: #111827;
  color: #e5e7eb;
  padding: 0.85rem;
  border-radius: 10px;
  overflow-x: auto;
  font-size: 0.82rem;
}

.event-list {
  list-style: none;
  padding: 0;
  margin: 0;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.event-list li {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  font-size: 0.88rem;
  border-bottom: 1px solid var(--border);
  padding-bottom: 0.45rem;
}

.event-time {
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}

.event-type {
  font-weight: 700;
}

.login-card {
  max-width: 420px;
  margin: 2rem auto;
}

.login-form {
  display: flex;
  flex-direction: column;
  gap: 1rem;
  margin-top: 1rem;
}

.empty-state {
  text-align: center;
  padding: 2rem 1.5rem;
}

.user-badge {
  font-size: 0.85rem;
  font-weight: 700;
  padding: 0.3rem 0.7rem;
  border-radius: 999px;
  background: #e0f2fe;
  color: #0369a1;
}

.filter-bar {
  display: flex;
  flex-wrap: wrap;
  gap: 0.6rem;
  margin-bottom: 1.1rem;
}

.filter-pill {
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  font-family: inherit;
  font-size: 0.92rem;
  font-weight: 700;
  padding: 0.45rem 0.95rem;
  border-radius: 999px;
  cursor: pointer;
}

.filter-pill-active {
  background: #1f2937;
  color: #ffffff;
  border-color: #1f2937;
}

.room-title-row {
  display: flex;
  align-items: center;
  gap: 0.45rem;
}

.favorite-btn {
  border: none;
  background: transparent;
  font-size: 1.35rem;
  line-height: 1;
  padding: 0.15rem 0.3rem;
  cursor: pointer;
  color: #9ca3af;
}

.favorite-btn-active {
  color: #f59e0b;
}

.timer-actor {
  margin-top: 0.25rem;
  font-size: 0.85rem;
  color: var(--muted);
}

.user-list {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  margin-bottom: 1.25rem;
}

.user-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.6rem;
  padding: 0.75rem;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: #fafafa;
}

.user-edit-form {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.55rem;
  flex: 1 1 auto;
}

.user-edit-form input[type="text"],
.user-edit-form input[type="password"],
.user-edit-form select {
  font-family: inherit;
  font-size: 0.9rem;
  padding: 0.4rem 0.6rem;
  border: 1px solid #d1d5db;
  border-radius: 8px;
  background: #ffffff;
}

.user-identity {
  display: flex;
  align-items: center;
  gap: 0.45rem;
  min-width: 140px;
}

.inline-check {
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
  font-size: 0.85rem;
  font-weight: 600;
}

.btn-sm {
  min-height: 36px;
  padding: 0.35rem 0.75rem;
  font-size: 0.88rem;
}

.user-create-form {
  border-top: 1px solid var(--border);
  padding-top: 1rem;
}

.user-create-form h3 {
  margin: 0 0 0.75rem;
}

.event-actor {
  font-weight: 700;
  color: #0369a1;
  background: #e0f2fe;
  padding: 0.05rem 0.45rem;
  border-radius: 999px;
}

.nav-link-active {
  background: #1f2937;
  color: #ffffff;
  border-color: #1f2937;
}

.nav-link-active:hover {
  background: #111827;
}

.hub-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
  gap: 1.25rem;
}

.hub-module-card {
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  gap: 1.25rem;
  text-decoration: none;
  color: inherit;
  min-height: 170px;
  transition: transform 0.1s ease, border-color 0.15s ease, box-shadow 0.15s ease;
}

.hub-module-card:hover {
  transform: translateY(-2px);
  border-color: #9ca3af;
}

.hub-module-card-active {
  background: var(--surface-active);
  border-color: #fb923c;
}

.hub-module-card-settings {
  background: #fafaf9;
}

.hub-module-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
}

.hub-module-icon {
  font-size: 2rem;
  line-height: 1;
}

.hub-module-title {
  margin: 0 0 0.25rem;
  font-size: 1.35rem;
}

.hub-module-desc {
  margin: 0;
  color: var(--muted);
  font-size: 0.95rem;
}

.user-menu {
  position: relative;
}

.user-menu-trigger {
  list-style: none;
  cursor: pointer;
  user-select: none;
  display: inline-flex;
  align-items: center;
  gap: 0.25rem;
}

.user-menu-trigger::-webkit-details-marker {
  display: none;
}

.user-menu-dropdown {
  position: absolute;
  right: 0;
  top: calc(100% + 0.45rem);
  min-width: 190px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px;
  box-shadow: 0 12px 28px rgba(15, 23, 42, 0.14);
  padding: 0.65rem;
  z-index: 30;
  display: flex;
  flex-direction: column;
  gap: 0.55rem;
}

.user-menu-info {
  display: flex;
  flex-direction: column;
  padding: 0.2rem 0.35rem 0.45rem;
  border-bottom: 1px solid var(--border);
  font-size: 0.9rem;
}

.user-menu-form {
  margin: 0;
}

.user-menu-logout {
  width: 100%;
  text-align: left;
  font-family: inherit;
  font-size: 0.95rem;
  font-weight: 700;
  color: var(--danger);
  background: #fef2f2;
  border: 1px solid #fecaca;
  border-radius: 10px;
  padding: 0.55rem 0.75rem;
  cursor: pointer;
}

.user-menu-logout:hover {
  background: #fee2e2;
}
