@font-face {
  font-family: 'YS Text regular';
  src: url(/ui/assets/fonts/ys-text-regular.woff2) format('woff2');
  font-weight: 400;
  font-style: normal;
  font-display: swap;
}

@font-face {
  font-family: 'YS Text medium';
  src: url(/ui/assets/fonts/ys-text-medium.woff2) format('woff2');
  font-weight: 500;
  font-style: normal;
  font-display: swap;
}

@font-face {
  font-family: 'YS Text bold';
  src: url(/ui/assets/fonts/ys-text-bold.woff2) format('woff2');
  font-weight: 700;
  font-style: normal;
  font-display: swap;
}

:root {
  --horizontal-wrapper-padding: 16px;
  --color-accent: #6839cf;
  --color-text: rgba(0, 0, 0, 0.8);
  --color-muted: #919cb5;
  --color-bg: #f2f3f5;
  --color-card: #fff;
  --color-toggle-off: #c7ccd9;
  --color-toggle-on: #58c46a;
  --color-separator: #e2e4eb;
  --color-ok: #1e3a2f;
  --color-ok-text: #2e7d4a;
  --color-bad: #fdecea;
  --color-bad-text: #c5221f;
  --shadow-card: 0 2px 8px rgba(0, 32, 128, 0.06);
  --shadow-card-pressed: 0 1px 3px rgba(0, 32, 128, 0.05);
  --safe-area-bottom: env(safe-area-inset-bottom, 0px);
  --ease-out: cubic-bezier(0.2, 0, 0, 1);
  --ease-spring: cubic-bezier(0.34, 1.4, 0.64, 1);
}

*, *::before, *::after { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  background: var(--color-bg);
  color: var(--color-text);
}

body {
  font-family: Arial, sans-serif;
  font-weight: 400;
  -webkit-font-smoothing: antialiased;
}

body.fonts-loaded {
  font-family: 'YS Text regular', Arial, sans-serif;
}

.font_ys-text-medium { font-family: Arial, sans-serif; font-weight: 500; }
.fonts-loaded .font_ys-text-medium { font-family: 'YS Text medium', Arial, sans-serif; }
.font_ys-text-bold { font-family: Arial, sans-serif; font-weight: 700; }
.fonts-loaded .font_ys-text-bold { font-family: 'YS Text bold', Arial, sans-serif; }

.app {
  width: 100%;
  min-height: 100%;
  background: var(--color-bg);
}

.app__wrapper {
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
}

.horizontal-wrapper_both {
  padding-left: var(--horizontal-wrapper-padding);
  padding-right: var(--horizontal-wrapper-padding);
}

/* Sticky chrome */
.app-chrome {
  position: sticky;
  top: 0;
  z-index: 10;
  background: var(--color-card);
  border-bottom: 1px solid var(--color-separator);
}

.app-topbar {
  display: flex;
  justify-content: flex-end;
  align-items: center;
  padding-top: max(12px, env(safe-area-inset-top));
  padding-bottom: 8px;
  background: var(--color-card);
}

.header-badges {
  display: flex;
  gap: 6px;
  flex-shrink: 0;
}

.status-pill {
  padding: 4px 8px;
  border-radius: 999px;
  font-size: 10px;
  line-height: 14px;
  white-space: nowrap;
}

.status-pill_ok {
  background: #e6f4ea;
  color: var(--color-ok-text);
}

.status-pill_bad {
  background: var(--color-bad);
  color: var(--color-bad-text);
}

/* Devices toolbar (household tabs under main nav) */
.devices-toolbar {
  margin-bottom: 12px;
}

.devices-toolbar:has(.household-tabs:empty) .panel-hint {
  margin-top: 0;
}

.household-tabs {
  display: flex;
  flex-wrap: nowrap;
  gap: 8px;
  min-width: 0;
  margin-bottom: 8px;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
}

.household-tabs::-webkit-scrollbar {
  display: none;
}

.household-tabs:empty {
  display: none;
  margin-bottom: 0;
}

.household-tab {
  padding: 6px 14px;
  border: 0;
  border-radius: 999px;
  background: #eef0f5;
  color: var(--color-text);
  font-size: 14px;
  line-height: 20px;
  cursor: pointer;
  white-space: nowrap;
  flex-shrink: 0;
  transition: background 0.2s var(--ease-out), color 0.2s var(--ease-out), transform 0.15s var(--ease-spring);
}

.household-tab:hover {
  background: #e4e7ed;
}

.household-tab:active {
  transform: scale(0.96);
}

.household-tab_active {
  background: var(--color-accent);
  color: #fff;
}

.household-tab_active:hover {
  background: var(--color-accent);
}

/* Tabs */
.tabs_theme_header {
  background: var(--color-card);
  border-bottom: none;
}

.tabs__scroll-container {
  display: flex;
  padding: 0 var(--horizontal-wrapper-padding);
}

.tab_theme_header {
  position: relative;
  margin-right: 16px;
  padding: 12px 0;
  min-height: 44px;
  display: flex;
  align-items: center;
}

.tab_theme_header::after {
  content: '';
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  height: 2px;
  background: var(--color-accent);
  border-radius: 1px 1px 0 0;
  transform: scaleX(0);
  transition: transform 0.25s var(--ease-out);
}

.tab_theme_header.tab_active::after {
  transform: scaleX(1);
}

.tab_theme_header:last-child { margin-right: 0; }

.tab__button {
  padding: 0;
  margin: 0;
  border: 0;
  background: none;
  cursor: pointer;
  font-size: 16px;
  line-height: 20px;
  color: var(--color-muted);
  transition: color 0.2s var(--ease-out);
}

.tab_active .tab__button { color: var(--color-accent); }

@keyframes panel-enter {
  from { opacity: 0; transform: translateY(10px); }
  to { opacity: 1; transform: translateY(0); }
}

@keyframes list-item-enter {
  from { opacity: 0; transform: translateY(6px); }
  to { opacity: 1; transform: translateY(0); }
}

@keyframes hint-pulse {
  0%, 100% { opacity: 0.45; }
  50% { opacity: 1; }
}

@keyframes toggle-pending {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.55; }
}

/* Panels */
.iot-home__content { flex: 1; }

.panel {
  display: none;
  padding: 12px var(--horizontal-wrapper-padding) calc(16px + var(--safe-area-bottom));
  background: var(--color-bg);
}

.panel_active {
  display: block;
  animation: panel-enter 0.22s var(--ease-out);
}

.panel-hint {
  margin: 0;
  font-size: 12px;
  line-height: 16px;
  color: var(--color-muted);
}

.panel-hint_loading {
  animation: hint-pulse 1.2s ease-in-out infinite;
}

/* Card surfaces */
.rooms-card {
  background: var(--color-card);
  border-radius: 16px;
  box-shadow: var(--shadow-card);
  overflow: hidden;
}

.content-card {
  background: transparent;
  border-radius: 0;
  box-shadow: none;
  overflow: visible;
  margin-bottom: 4px;
}

.content-card:empty {
  display: none;
}

.rooms-card .empty-hint {
  padding: 24px 16px;
}

.content-card .empty-hint {
  padding: 24px 0;
}

.content-card .list-item {
  margin-bottom: 8px;
  border-radius: 16px;
  box-shadow: var(--shadow-card);
  animation: list-item-enter 0.28s var(--ease-out) both;
}

.content-card .list-item + .list-item {
  border-top: none;
}

/* Rooms */
.iot-room { margin-bottom: 0; }

.iot-room + .iot-room {
  border-top: 1px solid var(--color-separator);
}

.iot-room:not(.iot-room_collapsed) {
  background: var(--color-bg);
}

.iot-room:not(.iot-room_collapsed) .iot-room__header {
  background: var(--color-card);
  border-bottom: 1px solid var(--color-separator);
}

.iot-room:not(.iot-room_collapsed) .iot-room__name {
  color: var(--color-text);
}

.iot-room__header {
  display: flex;
  align-items: center;
  width: 100%;
  min-height: 48px;
  padding: 12px 16px;
  margin: 0;
  border: 0;
  background: none;
  cursor: pointer;
  text-align: left;
  color: inherit;
  -webkit-tap-highlight-color: transparent;
}

.iot-room__header:active .iot-room__name {
  opacity: 0.7;
}

.iot-room__chevron {
  flex-shrink: 0;
  width: 16px;
  height: 16px;
  margin-right: 6px;
  background: currentColor;
  mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath d='M7 10l5 5 5-5z'/%3E%3C/svg%3E") center / contain no-repeat;
  -webkit-mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath d='M7 10l5 5 5-5z'/%3E%3C/svg%3E") center / contain no-repeat;
  color: var(--color-muted);
  transition: transform 0.2s var(--ease-out);
}

.iot-room_collapsed .iot-room__chevron {
  transform: rotate(-90deg);
}

.iot-room__name {
  flex: 1;
  min-width: 0;
  font-size: 14px;
  line-height: 18px;
  color: var(--color-muted);
  transition: opacity 0.15s var(--ease-out);
}

.iot-room__count {
  flex-shrink: 0;
  margin-left: 8px;
  font-size: 12px;
  line-height: 16px;
  color: var(--color-muted);
  opacity: 0.65;
}

.iot-room__devices {
  margin-top: 0;
  padding: 10px 12px 12px;
  background: var(--color-bg);
}

.iot-room__devices .list-item {
  background: var(--color-card);
  box-shadow: var(--shadow-card);
  border-radius: 14px;
}

.iot-room__devices .list-item:active {
  box-shadow: var(--shadow-card-pressed);
}

.iot-room__devices .list-item:last-child {
  margin-bottom: 0;
}

.iot-room_collapsed .iot-room__devices {
  display: none;
}

.iot-room_collapsed .iot-room__header {
  margin-bottom: 0;
}

/* List items */
.list-item {
  position: relative;
  display: flex;
  align-items: center;
  min-height: 56px;
  padding: 12px;
  margin-bottom: 8px;
  font-size: 14px;
  line-height: 18px;
  color: var(--color-text);
  background: var(--color-card);
  border-radius: 16px;
  box-shadow: var(--shadow-card);
  transition: transform 0.15s var(--ease-out), box-shadow 0.15s var(--ease-out);
  animation: list-item-enter 0.28s var(--ease-out) both;
}

.list-item:active {
  transform: scale(0.985);
  box-shadow: var(--shadow-card-pressed);
}

.list-item_with-composition { flex-wrap: nowrap; }

.list-item__main-area {
  display: flex;
  align-items: center;
  flex: 1;
  min-width: 0;
}

.list-item__icon {
  flex-shrink: 0;
  margin-right: 12px;
}

.list-item__content-wrapper { flex: 1; min-width: 0; }

.list-item__name {
  font-size: 16px;
  line-height: 20px;
  color: var(--color-text);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.list-item__description {
  margin-top: 2px;
  font-size: 13px;
  line-height: 16px;
  color: var(--color-muted);
}

.list-item__side-control-area {
  flex-shrink: 0;
  margin-left: 8px;
}

/* Device icon */
.iot-device-icon {
  --size: 40px;
  display: block;
  position: relative;
  width: var(--size);
  height: var(--size);
  flex-shrink: 0;
}

.iot-device-icon__icon {
  width: var(--size);
  height: var(--size);
  background-size: contain;
  background-repeat: no-repeat;
  background-position: center;
}

.iot-device-icon_on .iot-device-icon__icon {
  filter: none;
  transition: filter 0.2s var(--ease-out);
}

/* Toggle switch */
.toggle-switch {
  position: relative;
  width: 32px;
  height: 32px;
  cursor: pointer;
  flex-shrink: 0;
}

.toggle-switch::before {
  content: '';
  position: absolute;
  top: 50%;
  right: 0;
  width: 100%;
  height: 12px;
  transform: translateY(-50%);
  border-radius: 7px;
  background: var(--color-toggle-off);
  transition: background 0.2s var(--ease-out);
}

.toggle-switch_active::before { background: var(--color-toggle-on); }

.toggle-switch::after {
  content: '';
  position: absolute;
  top: 50%;
  left: 0;
  width: 18px;
  height: 18px;
  transform: translateY(-50%);
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 1px 5px rgba(0, 0, 0, 0.2);
  transition: left 0.2s var(--ease-spring), transform 0.15s var(--ease-spring);
}

.toggle-switch:active::after {
  transform: translateY(-50%) scale(0.92);
}

.toggle-switch_active::after { left: 14px; }

.toggle-switch_pending {
  pointer-events: none;
  animation: toggle-pending 0.8s ease-in-out infinite;
}

.toggle-switch_disabled {
  opacity: 0.4;
  cursor: default;
  pointer-events: none;
}

.toggle-switch_disabled::after { background: var(--color-separator); }

.iot-device-list-item_clickable {
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}

.iot-device-list-item_clickable .toggle-switch {
  pointer-events: none;
}

/* Scenario */
.iot-scenario-item .list-item__main-area { cursor: default; }

.iot-scenario-icon {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: #eef0f5 center/24px no-repeat;
}

.iot-scenario-icon_type_home {
  background-image: url(/ui/assets/icons/scenario-home.svg);
}

.iot-scenario-icon_type_work {
  background-image: url(/ui/assets/icons/scenario-work.svg);
}

.iot-scenario-icon_type_attention {
  background-image: url(/ui/assets/icons/scenario-attention.svg);
}

.iot-scenario-start-button {
  width: 32px;
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 0;
  background: none;
  cursor: pointer;
  padding: 0;
  transition: transform 0.15s var(--ease-spring);
}

.iot-scenario-start-button:active {
  transform: scale(0.88);
}

.iot-scenario-start-button svg {
  width: 24px;
  height: 24px;
}

.iot-scenario-start-button path {
  fill: #afb9cc;
  transition: fill 0.15s var(--ease-out);
}

.iot-scenario-start-button:hover path { fill: var(--color-accent); }

.section-title {
  margin: 20px 0 10px;
  font-size: 14px;
  line-height: 18px;
  color: var(--color-muted);
  font-weight: 500;
}

.section-title:first-child { margin-top: 0; }

/* Settings / debug */
.settings-card {
  background: var(--color-card);
  border-radius: 16px;
  box-shadow: var(--shadow-card);
  padding: 12px;
  margin-bottom: 12px;
}

.settings-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
  margin-bottom: 8px;
}

.settings-row_wrap {
  margin-bottom: 0;
}

.panel-hint_mono {
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
  font-size: 12px;
  word-break: break-all;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  text-decoration: none;
  padding: 8px 14px;
  border: 0;
  border-radius: 8px;
  background: var(--color-accent);
  color: #fff;
  font-size: 14px;
  cursor: pointer;
  transition: transform 0.12s var(--ease-out), opacity 0.12s var(--ease-out);
}

.btn_primary {
  background: var(--color-accent);
  color: #fff;
}

.btn_disabled {
  pointer-events: none;
  opacity: 0.5;
}

.btn:active {
  transform: scale(0.97);
}

.btn_secondary {
  background: #eef0f5;
  color: var(--color-text);
}

.btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.oauth-label {
  display: block;
  font-size: 13px;
  color: var(--color-muted);
  margin: 12px 0 6px;
}

.oauth-input {
  width: 100%;
  box-sizing: border-box;
  padding: 10px 12px;
  border-radius: 8px;
  border: 1px solid var(--color-separator);
  background: var(--color-card);
  color: var(--color-text);
  font-size: 15px;
  margin-bottom: 10px;
}

.oauth-input:focus {
  outline: none;
  border-color: var(--color-accent);
}

.yandex-activate-btn {
  width: 100%;
}

.oauth-result {
  min-height: 20px;
  margin: 0 0 10px;
  font-size: 14px;
  line-height: 20px;
}

.oauth-result_ok {
  color: #137333;
}

.oauth-result_err {
  color: #c5221f;
}

.oauth-result_loading {
  color: var(--color-muted);
}

.btn-grid {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

#log {
  list-style: none;
  padding: 0;
  margin: 0;
  max-height: 280px;
  overflow: auto;
}

#log li {
  padding: 8px 0;
  border-bottom: 1px solid var(--color-separator);
  font-size: 13px;
  line-height: 18px;
}

#log li .t {
  color: var(--color-muted);
  font-size: 11px;
  margin-right: 6px;
}

#log li .k { color: var(--color-text); }

.logout-form { margin-top: 16px; }

.logout-form .btn { width: 100%; }

.empty-hint {
  padding: 24px 0;
  text-align: center;
  color: var(--color-muted);
  font-size: 14px;
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}

@media screen and (max-width: 359px) {
  :root { --horizontal-wrapper-padding: 12px; }

  .status-pill {
    width: 10px;
    height: 10px;
    padding: 0;
    font-size: 0;
    line-height: 0;
    overflow: hidden;
  }
}

@media screen and (min-width: 641px) {
  body {
    padding: 16px 0;
  }

  .app {
    max-width: 640px;
    margin: 0 auto;
    border-radius: 16px;
    box-shadow: 0 4px 24px rgba(0, 32, 128, 0.08);
    overflow: hidden;
  }

  .app-chrome {
    border-radius: 16px 16px 0 0;
  }
}
