:root {
  --bg-page: #121212;
  --bg-surface: #1c1c1e;
  --bg-subtle: #262629;
  --text-primary: #f2f2f7;
  --text-secondary: #98989f;
  --text-muted: #636366;
  --border-color: #2c2c2e;
  --accent-active: #e5e5ea;
  --accent-active-text: #121212;
  --accent-green: #34c759;
  --accent-green-soft: rgba(52, 199, 89, 0.14);
  --accent-red: #ff453a;
  --accent-red-soft: rgba(255, 69, 58, 0.14);
  --radius-lg: 14px;
  --radius-md: 10px;
  --radius-sm: 7px;
}

* {
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

body {
  margin: 0;
  padding: 0;
  background-color: var(--bg-page);
  color: var(--text-primary);
  font-family: -apple-system, BlinkMacSystemFont, "Inter", "Segoe UI", Roboto, sans-serif;
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
  overflow-x: hidden;
  touch-action: pan-y;
}

.app-shell {
  max-width: 460px;
  margin: 0 auto;
  padding: 12px 14px 28px 14px;
  min-height: calc(100vh - 24px);
}

.top-header {
  display: flex;
  justify-content: space-between;
  align-items: stretch;
  gap: 8px;
  margin-bottom: 10px;
}

.app-title {
  margin: 0;
  font-size: 1.15rem;
  font-weight: 600;
  letter-spacing: -0.02em;
  color: var(--text-primary);
}

.app-subtitle {
  margin: 1px 0 0 0;
  font-size: 0.76rem;
  color: var(--text-secondary);
}

.temp-banner {
  flex: 1;
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 6px;
  min-width: 0;
}

.temp-chip {
  background: var(--bg-surface);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  padding: 5px 4px 4px 4px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 1px;
  min-width: 0;
}

.temp-room {
  font-size: 0.64rem;
  color: var(--text-secondary);
  font-weight: 500;
  line-height: 1.2;
  text-align: center;
}

.temp-value {
  font-size: 0.92rem;
  font-weight: 600;
  color: var(--text-primary);
  letter-spacing: -0.03em;
  line-height: 1.2;
}

.scenario-summary {
  font-size: 0.76rem;
  color: var(--text-secondary);
  margin-top: 5px;
  line-height: 1.45;
}

.scenario-summary strong {
  color: var(--text-primary);
  font-weight: 600;
}

.icon-btn {
  border: 1px solid var(--border-color);
  background: var(--bg-surface);
  color: var(--text-secondary);
  height: 32px;
  padding: 0 10px;
  border-radius: var(--radius-sm);
  font-size: 0.76rem;
  font-weight: 500;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.icon-btn.header-settings {
  align-self: stretch;
  height: unset;
  width: 42px;
  min-width: 42px;
  padding: 0;
  font-size: 1.35rem;
  flex-shrink: 0;
}

.icon-btn:hover {
  background: var(--bg-subtle);
  color: var(--text-primary);
}

/* 3 Onglets : Scénarios | Prises | Chauffages */
.segmented-control {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  background: var(--bg-surface);
  border: 1px solid var(--border-color);
  padding: 3px;
  border-radius: var(--radius-md);
  margin-bottom: 12px;
}

.segment-btn {
  border: none;
  background: transparent;
  color: var(--text-secondary);
  padding: 8px 6px;
  border-radius: 8px;
  font-size: 0.8rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.15s ease;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 5px;
}

.segment-btn.active {
  background: var(--bg-subtle);
  color: var(--text-primary);
}

.segment-count {
  font-size: 0.68rem;
  padding: 1px 5px;
  border-radius: 999px;
  background: var(--bg-page);
  color: var(--text-secondary);
}

.segment-btn.active .segment-count {
  background: var(--accent-active);
  color: var(--accent-active-text);
}

/* Animation de changement d'onglet */
.tab-content.from-right {
  animation: tab-slide-right 0.22s ease;
}

.tab-content.from-left {
  animation: tab-slide-left 0.22s ease;
}

@keyframes tab-slide-right {
  from {
    opacity: 0.4;
    transform: translateX(22px);
  }
  to {
    opacity: 1;
    transform: translateX(0);
  }
}

@keyframes tab-slide-left {
  from {
    opacity: 0.4;
    transform: translateX(-22px);
  }
  to {
    opacity: 1;
    transform: translateX(0);
  }
}

/* Barre de l'onglet Scénarios */
.scenarios-toolbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 10px;
}

.scenario-grid {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.scenario-card {
  background: var(--bg-surface);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  padding: 13px 14px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  cursor: default;
  gap: 12px;
  user-select: none;
  -webkit-user-select: none;
}

.scenario-card-main {
  flex: 1;
  min-width: 0;
}

.icon-btn.tile-settings {
  width: 40px;
  min-width: 40px;
  height: 40px;
  padding: 0;
  flex-shrink: 0;
  font-size: 1.15rem;
}

.scenario-card-right {
  display: flex;
  flex-direction: row;
  align-items: center;
  gap: 18px;
  flex-shrink: 0;
}

.scenario-action-btn {
  height: 32px;
  min-width: 44px;
  padding: 0 10px;
  border-radius: 8px;
  font-size: 0.74rem;
  font-weight: 500;
  border: 1px solid var(--border-color);
  cursor: pointer;
  flex-shrink: 0;
}

.scenario-action-btn:hover {
  filter: brightness(1.08);
}

.scenario-action-btn:active {
  transform: scale(0.95);
}

.scenario-action-btn.on {
  background: var(--accent-active);
  border-color: var(--accent-active);
  color: var(--accent-active-text);
}

.scenario-action-btn.off {
  background: var(--bg-subtle);
  border-color: #3a3a3c;
  color: var(--text-primary);
}

.schedule-badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-size: 0.68rem;
  color: var(--accent-green);
  background: var(--accent-green-soft);
  border: 1px solid rgba(52, 199, 89, 0.3);
  padding: 2px 7px;
  border-radius: 999px;
  margin-top: 5px;
  font-weight: 500;
}

/* Éditeur de Scénario */
.editor-card {
  background: var(--bg-surface);
  border: 1px solid #3a3a3c;
  border-radius: var(--radius-lg);
  padding: 14px;
  margin-bottom: 12px;
}

.editor-section-title {
  font-size: 0.75rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-secondary);
  margin: 12px 0 6px 0;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.editor-input {
  width: 100%;
  background: var(--bg-page);
  border: 1px solid var(--border-color);
  color: var(--text-primary);
  padding: 8px 10px;
  border-radius: var(--radius-sm);
  font-size: 0.82rem;
  font-family: inherit;
}

.editor-row-2col {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin-top: 8px;
}

.editor-device-box {
  background: var(--bg-page);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 9px 10px;
  margin-bottom: 7px;
}

.editor-device-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 6px;
}

.editor-device-title {
  font-size: 0.84rem;
  font-weight: 600;
  color: var(--text-primary);
}

.editor-mode-grid-4 {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 5px;
}

.editor-mode-grid-3 {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 5px;
}

.days-row {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 5px;
  margin-top: 8px;
}

.day-pill {
  border: 1px solid var(--border-color);
  background: var(--bg-surface);
  color: var(--text-secondary);
  height: 32px;
  padding: 0;
  border-radius: 6px;
  font-size: 0.72rem;
  font-weight: 500;
  cursor: pointer;
  text-align: center;
}

.day-pill.active {
  background: var(--accent-active);
  border-color: var(--accent-active);
  color: var(--accent-active-text);
}

.editor-footer {
  display: flex;
  gap: 8px;
  margin-top: 14px;
}

.btn-primary,
.btn-secondary,
.btn-danger {
  height: 34px;
  padding: 0 12px;
  border-radius: var(--radius-sm);
  font-size: 0.76rem;
  font-weight: 500;
  cursor: pointer;
}

.btn-primary {
  flex: 1;
  background: var(--accent-active);
  color: var(--accent-active-text);
  border: 1px solid var(--accent-active);
}

.btn-secondary {
  background: var(--bg-page);
  color: var(--text-primary);
  border: 1px solid var(--border-color);
}

.btn-danger {
  background: rgba(255, 69, 58, 0.14);
  color: #ff453a;
  border: 1px solid rgba(255, 69, 58, 0.35);
}

/* Cartes compactes Chauffages */
.card {
  background: var(--bg-surface);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  padding: 11px 13px;
  margin-bottom: 8px;
}

.heater-top {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 8px;
}

.heater-title-group {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
  flex: 1;
}

.device-name {
  margin: 0;
  font-size: 0.94rem;
  font-weight: 600;
  color: var(--text-primary);
}

.probe-inline {
  font-size: 0.8rem;
  color: var(--text-secondary);
}

.probe-inline strong {
  color: var(--text-primary);
  font-weight: 600;
}

.heater-status-group {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
}

.relay-pill {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  font-size: 0.7rem;
  font-weight: 600;
  padding: 3px 8px;
  border-radius: 999px;
  border: 1px solid rgba(255, 69, 58, 0.35);
  background: var(--accent-red-soft);
  color: var(--accent-red);
}

.relay-pill.hs {
  border-color: rgba(255, 159, 10, 0.4);
  background: rgba(255, 159, 10, 0.14);
  color: #ffb020;
}

.relay-pill .status-dot.hs {
  background: #ffb020;
}

.device-hs {
  opacity: 0.88;
}

.mode-row.is-disabled {
  opacity: 0.45;
  pointer-events: none;
}

.relay-pill .status-dot {
  background: var(--accent-red);
}

.relay-pill.heating {
  background: var(--accent-green-soft);
  border-color: rgba(52, 199, 89, 0.35);
  color: var(--accent-green);
}

.relay-pill.heating .status-dot {
  background: var(--accent-green);
}

.mode-row {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 6px;
}

.mode-btn {
  border: 1px solid var(--border-color);
  background: var(--bg-page);
  color: var(--text-secondary);
  height: 34px;
  padding: 0 4px;
  border-radius: var(--radius-sm);
  font-size: 0.73rem;
  font-weight: 500;
  cursor: pointer;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.mode-btn.active {
  background: var(--accent-active);
  border-color: var(--accent-active);
  color: var(--accent-active-text);
}

.auto-compact-box {
  background: var(--bg-page);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 8px 10px;
  margin-top: 8px;
}

.auto-rows {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.stepper-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  min-width: 0;
}

.stepper-label {
  font-size: 0.72rem;
  color: var(--text-secondary);
  min-width: 0;
}

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

.stepper-val {
  font-size: 0.88rem;
  font-weight: 600;
  min-width: 40px;
  text-align: center;
  color: var(--text-primary);
}

.step-btn {
  width: 30px;
  height: 30px;
  border-radius: 7px;
  border: 1px solid var(--border-color);
  background: var(--bg-surface);
  color: var(--text-primary);
  font-size: 0.95rem;
  font-weight: 500;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  flex-shrink: 0;
}

.step-btn:hover {
  background: var(--bg-subtle);
}

.step-btn:active {
  transform: scale(0.92);
}

.mini-btn {
  border: 1px solid var(--border-color);
  background: var(--bg-surface);
  color: var(--text-secondary);
  height: 32px;
  padding: 0 10px;
  border-radius: var(--radius-sm);
  font-size: 0.76rem;
  font-weight: 500;
  cursor: pointer;
}

.toggle-switch {
  position: relative;
  width: 48px;
  height: 26px;
  border-radius: 999px;
  background: var(--bg-subtle);
  border: 1px solid var(--border-color);
  cursor: pointer;
  transition: background 0.15s ease, border-color 0.15s ease, transform 0.1s ease;
  padding: 0;
  flex-shrink: 0;
}

.toggle-switch:disabled {
  opacity: 0.4;
  pointer-events: none;
}

.toggle-switch:active {
  transform: scale(0.93);
}

.toggle-switch.on {
  background: var(--accent-active);
  border-color: var(--accent-active);
}

.toggle-knob {
  position: absolute;
  top: 3px;
  left: 3px;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: #8e8e93;
  transition: transform 0.15s cubic-bezier(0.22, 1, 0.36, 1), background 0.15s ease;
}

.toggle-switch.on .toggle-knob {
  transform: translateX(22px);
  background: #121212;
}

.switch-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  background: var(--bg-surface);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  padding: 13px 15px;
  margin-bottom: 8px;
  cursor: default;
  pointer-events: none;
}

.switch-row button {
  pointer-events: auto;
}

.device-room {
  font-size: 0.68rem;
  color: var(--text-secondary);
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.switch-meta {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 3px;
}

.status-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--text-muted);
  display: inline-block;
}

.status-dot.on {
  background: var(--accent-green);
}

.swipe-hint {
  text-align: center;
  font-size: 0.68rem;
  color: var(--text-muted);
  margin-top: 12px;
}

.settings-header {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 14px;
}

.icon-btn.header-back {
  width: 42px;
  min-width: 42px;
  height: 42px;
  padding: 0;
  flex-shrink: 0;
}

.icon-btn.header-back .back-arrow {
  width: 20px;
  height: 20px;
  display: block;
}

.tuya-status-on {
  color: var(--accent-green);
}

.tuya-status-off {
  color: var(--text-secondary);
}

.settings-title {
  margin: 0;
  font-size: 1.2rem;
  font-weight: 600;
  letter-spacing: -0.02em;
}

.settings-section {
  padding: 14px;
}

.settings-section-title {
  margin: 0 0 6px 0;
  font-size: 0.92rem;
  font-weight: 600;
}

.settings-hint {
  margin: 0 0 10px 0;
  font-size: 0.74rem;
  color: var(--text-secondary);
  line-height: 1.4;
}

.settings-result {
  margin: 10px 0 0 0;
  font-size: 0.76rem;
  color: var(--text-primary);
  font-weight: 500;
}

.btn-block {
  width: 100%;
  height: 42px;
  border: none;
  border-radius: var(--radius-sm);
  background: var(--accent-active);
  color: var(--accent-active-text);
  font-size: 0.86rem;
  font-weight: 600;
  cursor: pointer;
}

.btn-block:disabled {
  opacity: 0.55;
  cursor: default;
}

.settings-found-list {
  margin-top: 10px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.settings-found-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  background: var(--bg-page);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  padding: 8px 10px;
}

.settings-found-row strong {
  display: block;
  font-size: 0.8rem;
  color: var(--text-primary);
}

.settings-found-row span {
  display: block;
  margin-top: 1px;
  font-size: 0.68rem;
  color: var(--text-secondary);
}

.settings-found-status {
  font-style: normal;
  font-size: 0.68rem;
  font-weight: 600;
  color: var(--text-secondary);
  flex-shrink: 0;
}

.settings-found-status.added {
  color: var(--accent-green);
}

.settings-found-status.updated {
  color: var(--text-primary);
}

.settings-tuya-row {
  display: flex;
  gap: 8px;
  margin-bottom: 10px;
}

.settings-tuya-row input {
  flex: 1;
  min-width: 0;
  background: var(--bg-page);
  border: 1px solid var(--border-color);
  color: var(--text-primary);
  padding: 8px 10px;
  border-radius: var(--radius-sm);
  font-size: 0.82rem;
}

.settings-tuya-btn {
  background: var(--accent-active);
  color: var(--accent-active-text);
  font-weight: 600;
  height: 36px;
}

.settings-qr-wrap {
  text-align: center;
  padding: 10px;
  background: #ffffff;
  border-radius: 10px;
  width: 210px;
  margin: 0 auto 8px auto;
}

.settings-qr-wrap img {
  display: block;
}
