/* ============================================================================
   Meteo Online — каркас и общие компоненты
   Мобильная раскладка — база; планшет (≥768) и десктоп (≥1024) — наращиваются.
   ========================================================================== */

/* --- Каркас --------------------------------------------------------------- */
.app-header {
  position: sticky;
  top: 0;
  z-index: var(--z-header);
  isolation: isolate;
}

/* Размытие вынесено на псевдоэлемент: сам header не становится
   containing block для fixed-потомков (панели поиска и избранного). */
.app-header::before {
  content: "";
  position: absolute;
  inset: 0;
  z-index: -1;
  background: var(--bg-translucent);
  -webkit-backdrop-filter: saturate(1.5) blur(14px);
  backdrop-filter: saturate(1.5) blur(14px);
  border-bottom: 1px solid var(--line);
}

@supports not ((backdrop-filter: blur(1px)) or (-webkit-backdrop-filter: blur(1px))) {
  .app-header::before {
    background: var(--bg);
  }
}

.header-inner {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  align-items: center;
  gap: var(--sp-2);
  height: var(--header-h);
  padding-inline: var(--gutter);
  max-width: var(--shell-max);
  margin-inline: auto;
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: var(--sp-3);
  height: 40px;
  border-radius: var(--r-md);
  text-decoration: none;
}

.brand-mark {
  width: 36px;
  height: 36px;
  flex: none;
}

.brand-name {
  display: none;
  font-size: var(--text-lg);
  font-weight: var(--weight-bold);
  letter-spacing: -0.02em;
  white-space: nowrap;
}

.brand-name b {
  font-weight: var(--weight-regular);
  color: var(--ink-3);
}

.main-nav {
  display: none;
}

.header-actions {
  display: flex;
  align-items: center;
  gap: var(--sp-1);
}

.saved-anchor,
.theme-anchor,
.search {
  position: relative;
}

/* На телефоне вход в избранное — вкладка снизу, в шапке кнопки нет */
.saved-anchor {
  display: none;
}

.app-main {
  min-width: 0;
}

/* На телефоне карта и избранное — отдельные экраны: фон не прокручивается */
body.is-locked {
  overflow: hidden;
}

/* --- Погодный вид (телефон) ----------------------------------------------- */
.weather-view {
  display: flex;
  flex-direction: column;
  gap: var(--section-gap);
  min-width: 0;
  padding: var(--sp-3) var(--gutter) calc(var(--tabbar-h) + var(--sp-5) + env(safe-area-inset-bottom, 0px));
}

/* --- Кнопки --------------------------------------------------------------- */
.icon-btn {
  display: inline-grid;
  place-items: center;
  flex: none;
  width: 40px;
  height: 40px;
  border-radius: var(--r-md);
  color: var(--ink-2);
  background: transparent;
  transition: background-color var(--dur-fast) var(--ease-out), color var(--dur-fast) var(--ease-out),
    transform var(--dur-fast) var(--ease-out);
  -webkit-tap-highlight-color: transparent;
}

.icon-btn:hover {
  background: var(--surface-3);
  color: var(--ink);
}

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

.icon-btn[aria-expanded="true"] {
  background: var(--accent-soft);
  color: var(--accent);
}

.icon {
  width: 20px;
  height: 20px;
  flex: none;
}

.icon--sm {
  width: 16px;
  height: 16px;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--sp-2);
  min-height: 44px;
  padding: 0 var(--sp-5);
  border-radius: var(--r-pill);
  font-weight: var(--weight-bold);
  white-space: nowrap;
  transition: background-color var(--dur-fast) var(--ease-out), transform var(--dur-fast) var(--ease-out),
    box-shadow var(--dur-fast) var(--ease-out);
  -webkit-tap-highlight-color: transparent;
}

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

.btn-primary {
  background: var(--accent);
  color: var(--ink-on-accent);
  box-shadow: 0 6px 16px -6px rgba(42, 99, 240, 0.6);
}

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

.btn-ghost {
  min-height: 36px;
  padding: 0 var(--sp-4);
  background: var(--surface-3);
  color: var(--ink-2);
  font-size: var(--text-sm);
}

.btn-ghost:hover {
  background: var(--accent-soft);
  color: var(--accent);
}

.btn-ghost.is-danger {
  color: var(--danger);
}

/* --- Поиск ---------------------------------------------------------------- */
.search-field {
  display: flex;
  align-items: center;
  gap: var(--sp-2);
  height: 40px;
  padding-left: var(--sp-3);
  border-radius: var(--r-pill);
  background: var(--surface);
  box-shadow: inset 0 0 0 1px var(--line-strong), var(--shadow-1);
  transition: box-shadow var(--dur) var(--ease-out);
}

.search-field:focus-within {
  box-shadow: inset 0 0 0 2px var(--accent), var(--shadow-2);
}

.search-icon {
  color: var(--ink-3);
}

.search-input {
  flex: 1;
  min-width: 0;
  height: 100%;
  border: 0;
  background: transparent;
  color: var(--ink);
  font-size: var(--text-base);
  outline: none;
  -webkit-appearance: none;
  appearance: none;
}

.search-input::-webkit-search-cancel-button,
.search-input::-webkit-search-decoration {
  -webkit-appearance: none;
}

.search-input::placeholder {
  color: var(--ink-3);
  opacity: 1;
}

/* Визуально кнопки компактнее, но зона нажатия — не меньше 40×40 за счёт
   невидимого псевдоэлемента. */
.search-clear,
.search-locate {
  position: relative;
  border-radius: 50%;
}

.search-clear::before,
.search-locate::before {
  content: "";
  position: absolute;
  inset: -4px;
  border-radius: 50%;
}

.search-clear {
  width: 32px;
  height: 32px;
  margin-left: -4px;
}

.search-clear[hidden]::before {
  display: none;
}

.search-locate {
  width: 36px;
  height: 36px;
  margin-right: -2px;
  color: var(--accent);
  background: var(--accent-soft);
}

.search-locate:hover {
  background: var(--accent-soft-strong);
  color: var(--accent-hover);
}

.search-locate[aria-busy="true"] .icon {
  animation: locate-pulse 900ms var(--ease-in-out) infinite alternate;
}

@keyframes locate-pulse {
  from {
    opacity: 0.35;
    transform: scale(0.86);
  }
  to {
    opacity: 1;
    transform: scale(1.08);
  }
}

/* Панель результатов: на телефоне — лист на весь экран под шапкой */
.search-panel {
  position: fixed;
  inset: var(--header-h) 0 0 0;
  z-index: var(--z-popover);
  display: flex;
  flex-direction: column;
  background: var(--bg);
  animation: panel-in var(--dur) var(--ease-out);
}

.search-status {
  padding: var(--sp-4) var(--sp-5) var(--sp-2);
  color: var(--ink-2);
  font-size: var(--text-sm);
}

.search-status:empty {
  display: none;
}

.search-list {
  flex: 1;
  min-height: 0;
  padding: var(--sp-1) var(--gutter) var(--sp-4);
  overflow-y: auto;
  overscroll-behavior: contain;
}

.search-opt {
  display: flex;
  align-items: center;
  gap: var(--sp-3);
  width: 100%;
  min-height: 52px;
  padding: var(--sp-2) var(--sp-4);
  border-radius: var(--r-md);
  text-align: left;
  color: inherit;
}

.search-opt:hover,
.search-opt[aria-selected="true"] {
  background: var(--accent-soft);
}

.search-opt-icon {
  color: var(--ink-3);
}

.search-opt-text {
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.search-opt-name {
  font-weight: var(--weight-bold);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.search-opt-meta {
  color: var(--ink-3);
  font-size: var(--text-sm);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.search-group {
  padding: var(--sp-4) var(--sp-4) var(--sp-2);
  color: var(--ink-3);
  font-size: var(--text-xs);
  font-weight: var(--weight-bold);
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

.search-empty {
  display: grid;
  justify-items: center;
  gap: var(--sp-2);
  padding: var(--sp-8) var(--sp-5);
  text-align: center;
  color: var(--ink-2);
}

.search-empty strong {
  color: var(--ink);
  font-size: var(--text-lg);
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

@keyframes panel-in {
  from {
    opacity: 0;
    transform: translateY(-6px);
  }
  to {
    opacity: 1;
    transform: none;
  }
}

/* --- Меню темы ------------------------------------------------------------ */
.menu {
  position: absolute;
  top: calc(100% + var(--sp-2));
  right: 0;
  z-index: var(--z-popover);
  min-width: 176px;
  padding: var(--sp-1);
  border-radius: var(--r-md);
  background: var(--surface);
  box-shadow: var(--shadow-3);
  border: 1px solid var(--line);
  animation: menu-in var(--dur-fast) var(--ease-out) both;
}

@keyframes menu-in {
  from {
    opacity: 0;
    transform: translateY(-4px) scale(0.98);
  }
  to {
    opacity: 1;
    transform: none;
  }
}

.menu-item {
  display: flex;
  align-items: center;
  gap: var(--sp-2);
  width: 100%;
  min-height: 40px;
  padding: 0 var(--sp-3);
  border-radius: var(--r-sm);
  text-align: left;
  font-weight: var(--weight-medium);
  color: var(--ink-2);
}

.menu-item:hover {
  background: var(--surface-2);
  color: var(--ink);
}

.menu-item[aria-checked="true"] {
  background: var(--accent-soft);
  color: var(--accent);
}

.menu-check {
  width: 16px;
  height: 16px;
  margin-left: auto;
  opacity: 0;
}

.menu-item[aria-checked="true"] .menu-check {
  opacity: 1;
}

/* Плавный переход темы только в момент переключения (класс ставит theme.js) */
html.theme-transition,
html.theme-transition *,
html.theme-transition *::before,
html.theme-transition *::after {
  transition: background-color var(--dur-slow) var(--ease-in-out), color var(--dur-slow) var(--ease-in-out),
    border-color var(--dur-slow) var(--ease-in-out), fill var(--dur-slow) var(--ease-in-out),
    box-shadow var(--dur-slow) var(--ease-in-out) !important;
}

/* --- Избранное ------------------------------------------------------------ */
.saved-view {
  position: fixed;
  inset: var(--header-h) 0 0 0;
  z-index: calc(var(--z-view) + 1);
  display: flex;
  flex-direction: column;
  background: var(--bg);
}

.saved-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--sp-3);
  padding: var(--sp-4) var(--gutter) var(--sp-3);
}

.saved-head h2 {
  font-size: var(--text-xl);
}

.saved-head-actions {
  display: flex;
  align-items: center;
  gap: var(--sp-1);
}

.saved-close {
  display: none;
}

.saved-body {
  flex: 1;
  min-height: 0;
  padding: 0 var(--gutter) calc(var(--tabbar-h) + var(--sp-4));
  overflow-y: auto;
  overscroll-behavior: contain;
}

/* minmax(0, …): длинные названия мест обрезаются многоточием,
   а не распирают список за край экрана */
.saved-list {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: var(--sp-2);
}

.saved-item {
  display: flex;
  align-items: center;
  gap: var(--sp-1);
  padding-right: var(--sp-1);
  border-radius: var(--r-lg);
  background: var(--surface);
  box-shadow: var(--shadow-1);
}

.saved-pick {
  display: flex;
  align-items: center;
  gap: var(--sp-3);
  flex: 1;
  min-width: 0;
  min-height: 60px;
  padding: var(--sp-2) 0 var(--sp-2) var(--sp-4);
  text-align: left;
  color: inherit;
  border-radius: var(--r-lg);
}

.saved-text {
  display: flex;
  flex-direction: column;
  flex: 1;
  min-width: 0;
}

.saved-name {
  font-weight: var(--weight-bold);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.saved-meta {
  color: var(--ink-3);
  font-size: var(--text-sm);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.saved-temp {
  font-size: var(--text-lg);
  font-weight: var(--weight-bold);
  color: var(--ink-2);
}

.saved-icon {
  width: 32px;
  height: 32px;
}

.search-group-list {
  display: contents;
}

.saved-temp.is-loading {
  color: transparent;
  background: var(--surface-3);
  border-radius: var(--r-sm);
  animation: shimmer 1200ms var(--ease-in-out) infinite alternate;
}

.empty-state {
  display: grid;
  justify-items: center;
  gap: var(--sp-2);
  padding: var(--sp-8) var(--sp-5);
  text-align: center;
  color: var(--ink-3);
}

.empty-state strong {
  color: var(--ink);
  font-size: var(--text-lg);
}

@keyframes shimmer {
  from {
    opacity: 0.5;
  }
  to {
    opacity: 1;
  }
}

/* --- Нижняя панель вкладок ------------------------------------------------ */
.tabbar {
  position: fixed;
  inset: auto 0 0 0;
  z-index: var(--z-tabbar);
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  height: calc(var(--tabbar-h) + env(safe-area-inset-bottom, 0px));
  padding-bottom: env(safe-area-inset-bottom, 0px);
  background: var(--bg-translucent);
  -webkit-backdrop-filter: saturate(1.5) blur(14px);
  backdrop-filter: saturate(1.5) blur(14px);
  border-top: 1px solid var(--line);
}

@supports not ((backdrop-filter: blur(1px)) or (-webkit-backdrop-filter: blur(1px))) {
  .tabbar {
    background: var(--bg);
  }
}

.tab-btn {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  color: var(--ink-3);
  font-size: var(--text-xs);
  font-weight: var(--weight-bold);
  -webkit-tap-highlight-color: transparent;
}

.tab-btn .icon {
  width: 22px;
  height: 22px;
  transition: transform var(--dur) var(--ease-spring);
}

.tab-btn[aria-current="page"] {
  color: var(--accent);
}

.tab-btn[aria-current="page"] .icon {
  transform: translateY(-1px);
}

/* --- Уведомления ---------------------------------------------------------- */
.notice {
  display: flex;
  align-items: flex-start;
  gap: var(--sp-3);
  padding: var(--sp-4);
  border-radius: var(--r-lg);
  background: var(--surface);
  box-shadow: var(--shadow-2);
}

.notice-icon {
  margin-top: 2px;
  color: var(--danger);
}

.notice-body {
  flex: 1;
  min-width: 0;
}

.notice-title {
  font-weight: var(--weight-bold);
}

.notice-text {
  margin-top: 2px;
  color: var(--ink-2);
  font-size: var(--text-sm);
}

.notice .btn {
  margin-top: var(--sp-2);
}

.notice--slim {
  align-items: center;
  padding: var(--sp-3) var(--sp-4);
  background: var(--warn-soft);
  box-shadow: none;
}

.toast-region {
  position: fixed;
  left: 50%;
  bottom: calc(var(--tabbar-h) + env(safe-area-inset-bottom, 0px) + var(--sp-4));
  z-index: var(--z-toast);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--sp-2);
  width: min(92vw, 420px);
  transform: translateX(-50%);
  pointer-events: none;
}

.toast {
  max-width: 100%;
  padding: var(--sp-3) var(--sp-5);
  border-radius: var(--r-pill);
  background: var(--surface-inverse);
  color: var(--ink-inverse);
  font-size: var(--text-sm);
  font-weight: var(--weight-medium);
  text-align: center;
  box-shadow: var(--shadow-3);
  animation: toast-in var(--dur-slow) var(--ease-spring) both;
}

.toast.is-leaving {
  animation: toast-out var(--dur) var(--ease-in-out) both;
}

@keyframes toast-in {
  from {
    opacity: 0;
    transform: translateY(12px) scale(0.96);
  }
  to {
    opacity: 1;
    transform: none;
  }
}

@keyframes toast-out {
  to {
    opacity: 0;
    transform: translateY(8px);
  }
}

/* --- Вводные анимации ----------------------------------------------------- */
@keyframes rise-in {
  from {
    opacity: 0;
    transform: translateY(10px);
  }
  to {
    opacity: 1;
    transform: none;
  }
}

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: -1px;
  padding: 0;
  overflow: hidden;
  clip: rect(0 0 0 0);
  clip-path: inset(50%);
  white-space: nowrap;
  border: 0;
}

/* ============================================================================
   Планшет (≥768): одна колонка по центру, карта — секция внутри потока
   ========================================================================== */
@media (min-width: 768px) {
  :root {
    --gutter: 24px;
    --section-gap: 16px;
    --header-h: 60px;
  }

  .header-inner {
    grid-template-columns: auto minmax(160px, 1fr) auto auto;
    gap: var(--sp-3);
  }

  .brand-name {
    display: inline;
  }

  .main-nav {
    display: flex;
    gap: 2px;
    padding: 2px;
    border-radius: var(--r-pill);
    background: var(--surface-3);
  }

  .nav-btn {
    min-height: 40px;
    padding: 0 var(--sp-4);
    border-radius: var(--r-pill);
    color: var(--ink-2);
    font-weight: var(--weight-bold);
    font-size: var(--text-sm);
    transition: background-color var(--dur-fast) var(--ease-out), color var(--dur-fast) var(--ease-out);
  }

  .nav-btn:hover {
    color: var(--ink);
  }

  .nav-btn[aria-current="page"] {
    background: var(--surface);
    color: var(--ink);
    box-shadow: var(--shadow-1);
  }

  .search {
    max-width: 440px;
    justify-self: center;
    width: 100%;
  }

  .search-field {
    height: 42px;
  }

  /* На планшете и десктопе — выпадающий список под полем (position: fixed
     остался бы от телефонной раскладки и уехал бы за край экрана). */
  .search-panel {
    position: absolute;
    inset: calc(100% + var(--sp-2)) auto auto 0;
    width: min(420px, calc(100vw - var(--gutter) * 2));
    max-height: min(70vh, 520px);
    border-radius: var(--r-lg);
    background: var(--surface);
    box-shadow: var(--shadow-3);
    border: 1px solid var(--line);
    animation: menu-in var(--dur-fast) var(--ease-out) both;
  }

  .search-list {
    padding: var(--sp-1);
  }

  .search-empty {
    padding: var(--sp-5) var(--sp-4);
  }

  .saved-anchor {
    display: block;
  }

  .badge {
    position: absolute;
    top: 2px;
    right: 2px;
    min-width: 18px;
    height: 18px;
    padding: 0 5px;
    border-radius: var(--r-pill);
    background: var(--accent);
    color: var(--ink-on-accent);
    font-size: 11px;
    font-weight: var(--weight-bold);
    line-height: 18px;
    text-align: center;
  }

  .saved-view {
    inset: calc(var(--header-h) - 6px) var(--gutter) auto auto;
    width: min(400px, calc(100vw - var(--gutter) * 2));
    max-height: min(70vh, 560px);
    border-radius: var(--r-lg);
    background: var(--surface);
    box-shadow: var(--shadow-3);
    border: 1px solid var(--line);
    animation: menu-in var(--dur-fast) var(--ease-out) both;
  }

  .saved-head {
    padding: var(--sp-3) var(--sp-3) var(--sp-2) var(--sp-5);
  }

  .saved-head h2 {
    font-size: var(--text-lg);
    white-space: nowrap;
  }

  .saved-close {
    display: inline-grid;
  }

  .saved-body {
    padding: 0 var(--sp-3) var(--sp-3);
  }

  .saved-item {
    background: var(--surface-2);
    box-shadow: none;
  }

  .tabbar {
    display: none;
  }

  .weather-view {
    display: contents;
  }

  .app-main {
    display: grid;
    grid-template-columns: minmax(0, 760px);
    justify-content: center;
    gap: var(--section-gap);
    padding: var(--sp-4) var(--gutter) var(--sp-8);
  }

  /* Порядок секций в одном столбце: карта идёт сразу после почасового */
  .notice {
    order: 0;
  }

  .hero {
    order: 1;
  }

  #hourly {
    order: 2;
  }

  .map-host {
    order: 3;
  }

  #daily {
    order: 4;
  }

  #details {
    order: 5;
  }

  .charts {
    order: 6;
  }

  .page-foot {
    order: 7;
  }

  .toast-region {
    bottom: var(--sp-5);
  }
}

/* ============================================================================
   Десктоп (≥1024): две колонки — погода и липкая карта
   ========================================================================== */
@media (min-width: 1024px) {
  .app-main {
    grid-template-columns: minmax(0, 1fr) var(--map-col);
    align-items: start;
    gap: var(--sp-4);
    max-width: var(--shell-max);
    margin-inline: auto;
  }

  .weather-view {
    display: flex;
    max-width: var(--content-max);
    container-type: inline-size;
    container-name: weather;
  }

  .map-host {
    order: 0;
  }
}

@media (min-width: 1440px) {
  :root {
    --gutter: 32px;
    --section-gap: 16px;
  }
}

/* Группы в панели поиска */
.search-group {
  padding-top: var(--sp-3);
}

.search-group:first-child > .search-group {
  padding-top: var(--sp-2);
}

.search-opt .icon {
  width: 18px;
  height: 18px;
}

.search-opt .btn {
  margin-top: var(--sp-2);
}
