/* Single root size on all breakpoints (matches typical mobile scale on desktop too) */
html {
  font-size: 14px;
}

.btn:focus, .btn:active:focus, .btn-link.nav-link:focus, .form-control:focus, .form-check-input:focus {
  box-shadow: 0 0 0 0.1rem white, 0 0 0 0.25rem #258cfb;
}

html {
  position: relative;
  min-height: 100%;
}

body {
  margin-bottom: 0;
  padding-bottom: env(safe-area-inset-bottom, 0);
}

.page-shell {
  padding-left: max(0.75rem, env(safe-area-inset-left, 0px));
  padding-right: max(0.75rem, env(safe-area-inset-right, 0px));
}

/* Mobile: left flag rail + room for content (Index only sets body class). */
@media (max-width: 991.98px) {
  body.page-with-mobile-rail .page-shell {
    padding-left: calc(3.125rem + max(0.75rem, env(safe-area-inset-left, 0px)));
  }

  /* Fill dynamic viewport; on the home rail layout the feed card grows and the list scrolls inside. */
  html {
    min-height: 100dvh;
  }

  body.page-with-mobile-rail {
    min-height: 100dvh;
    display: flex;
    flex-direction: column;
  }

  body.page-with-mobile-rail .page-shell {
    flex: 1 1 auto;
    display: flex;
    flex-direction: column;
    min-height: 0;
    width: 100%;
    padding-bottom: calc(3.75rem + env(safe-area-inset-bottom, 0px));
  }

  body.page-with-mobile-rail main[role="main"] {
    flex: 1 1 auto;
    display: flex;
    flex-direction: column;
    min-height: 0;
  }

  body.page-with-mobile-rail main > .news-page-header,
  body.page-with-mobile-rail main > .alert,
  body.page-with-mobile-rail main > .collapse {
    flex-shrink: 0;
  }

  body.page-with-mobile-rail .news-columns {
    flex: 1 1 auto;
    min-height: 0;
    display: flex;
    flex-direction: column;
  }

  body.page-with-mobile-rail .news-columns .news-column-host {
    flex: 1 1 auto;
    min-height: 0;
    display: flex;
    flex-direction: column;
  }

  body.page-with-mobile-rail .news-column-host .news-column {
    flex: 1 1 auto;
    min-height: 0;
    display: flex;
    flex-direction: column;
    height: auto;
  }

  body.page-with-mobile-rail .news-column .card-body {
    flex: 1 1 auto;
    min-height: 0;
    display: flex;
    flex-direction: column;
    overflow: hidden;
  }

  body.page-with-mobile-rail .news-column .news-column-list {
    flex: 1 1 auto;
    min-height: 0;
    max-height: none;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
  }

  /* Fixed bar: category + regions (clears left flag rail + home indicator). */
  .mobile-news-footer {
    position: fixed;
    z-index: 1015;
    left: calc(3rem + max(0px, env(safe-area-inset-left, 0px)));
    right: max(0px, env(safe-area-inset-right, 0px));
    bottom: 0;
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.4rem 0.65rem;
    padding-bottom: max(0.4rem, env(safe-area-inset-bottom, 0px));
    background: rgba(255, 255, 255, 0.97);
    border-top: 1px solid rgba(0, 0, 0, 0.08);
    box-shadow: 0 -0.25rem 1rem rgba(0, 0, 0, 0.06);
  }

  .mobile-news-footer__topic {
    flex: 1 1 auto;
    min-width: 0;
  }

  .mobile-news-footer__topic .form-select {
    min-height: 2.5rem;
    width: 100%;
    max-width: 100%;
  }

  .mobile-news-footer__regions {
    min-height: 2.5rem;
    white-space: nowrap;
  }
}

.mobile-flag-rail {
  position: fixed;
  z-index: 1020;
  left: env(safe-area-inset-left, 0px);
  top: env(safe-area-inset-top, 0px);
  bottom: env(safe-area-inset-bottom, 0px);
  width: 3rem;
  display: flex;
  flex-direction: column;
  justify-content: flex-start;
  gap: 0.35rem;
  padding: 0.5rem 0.25rem 0.35rem;
  background: rgba(255, 255, 255, 0.96);
  border-right: 1px solid rgba(0, 0, 0, 0.08);
  box-shadow: 0 0 1rem rgba(0, 0, 0, 0.04);
  overflow-y: auto;
  overscroll-behavior: contain;
}

/* One country feed at a time on phones; flags on the left switch the panel on the right */
@media (max-width: 991.98px) {
  body.page-with-mobile-rail .news-columns .news-column-host {
    display: none;
  }

  body.page-with-mobile-rail[data-mobile-active-col="0"] .news-columns .news-column-host[data-mobile-col="0"],
  body.page-with-mobile-rail[data-mobile-active-col="1"] .news-columns .news-column-host[data-mobile-col="1"],
  body.page-with-mobile-rail[data-mobile-active-col="2"] .news-columns .news-column-host[data-mobile-col="2"],
  body.page-with-mobile-rail[data-mobile-active-col="3"] .news-columns .news-column-host[data-mobile-col="3"],
  body.page-with-mobile-rail[data-mobile-active-col="4"] .news-columns .news-column-host[data-mobile-col="4"],
  body.page-with-mobile-rail[data-mobile-active-col="5"] .news-columns .news-column-host[data-mobile-col="5"] {
    display: block;
    width: 100%;
  }
}

.mobile-flag-rail--compact .mobile-flag-rail__btn {
  min-height: 2.85rem;
  gap: 0.1rem;
}

.mobile-flag-rail--compact .mobile-flag-rail__emoji {
  font-size: 1.15rem;
}

.mobile-flag-rail__btn {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.15rem;
  width: 100%;
  min-height: 3.25rem;
  padding: 0.25rem 0.1rem;
  border: none;
  border-radius: 0.5rem;
  background: #f1f3f5;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}

.mobile-flag-rail__btn:active {
  background: #e7ebef;
}

.mobile-flag-rail__btn--active {
  background: #cfe2ff;
  box-shadow: inset 0 0 0 2px #0d6efd;
}

.mobile-flag-rail__edit {
  margin-top: auto;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  min-height: 2.5rem;
  padding: 0.2rem;
  border: 1px solid #dee2e6;
  border-radius: 0.5rem;
  background: #fff;
  font-size: 1rem;
  line-height: 1;
  color: #0d6efd;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}

.mobile-flag-rail__edit:active {
  background: #f1f3f5;
}

.mobile-flag-rail__emoji {
  font-size: 1.35rem;
  line-height: 1;
}

.mobile-flag-rail__badge {
  font-size: 0.65rem;
  font-weight: 700;
  color: #6c757d;
  line-height: 1;
}

/* Hint: only for large screens with real hover (not most phones) */
.desktop-hover-hint {
  display: none;
}

@media (min-width: 992px) and (hover: hover) and (pointer: fine) {
  .desktop-hover-hint {
    display: inline;
  }
}

/* Home header: compact on mobile (title + topic | Regions), relaxed on lg+ */
.news-page-header__top {
  display: grid;
  grid-template-columns: 1fr auto;
  align-items: stretch;
  column-gap: 0.5rem;
  row-gap: 0.35rem;
}

/* Mobile: hide “Business news” / “General news” to save vertical space */
.news-page-title {
  display: none;
}

.news-page-header .topic-form {
  grid-column: 1;
  display: flex;
  flex-direction: column;
  gap: 0.15rem;
  min-width: 0;
}

.news-page-header .news-page-topic-label {
  display: none;
}

.news-page-header .region-settings-btn {
  grid-column: 2;
  align-self: stretch;
  white-space: nowrap;
  padding-left: 0.5rem;
  padding-right: 0.5rem;
}

.news-page-tagline {
  font-size: 0.8125rem;
  line-height: 1.35;
}

@media (max-width: 991.98px) {
  .news-page-header__top {
    justify-items: start;
  }

  .news-page-header .topic-form {
    width: fit-content;
    max-width: calc(100% - 5rem);
  }

  .news-page-header .topic-select {
    width: auto;
    min-width: 6.75rem;
    max-width: 9rem;
    min-height: 2.5rem;
  }

  .news-page-header .region-settings-btn {
    min-height: 2.5rem;
    justify-self: end;
  }
}

@media (min-width: 992px) {
  .news-page-header__top {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 0.65rem 1rem;
    row-gap: 0.5rem;
  }

  .news-page-title {
    display: block;
    flex: 0 0 auto;
    font-size: 1.05rem;
    font-weight: 600;
    line-height: 1.25;
    max-width: 100%;
  }

  .news-page-header .topic-form {
    grid-column: auto;
    flex: 0 1 auto;
    flex-direction: row;
    align-items: center;
    gap: 0.5rem;
    min-width: 12rem;
  }

  .news-page-header .news-page-topic-label {
    display: inline;
    margin-bottom: 0 !important;
  }

  .news-page-header .region-settings-btn {
    grid-column: auto;
    flex: 0 0 auto;
    margin-left: auto;
    align-self: center;
    min-height: unset;
  }

  .news-page-tagline {
    font-size: 0.8125rem;
    width: 100%;
    flex-basis: 100%;
  }
}

/* Topic control defaults (desktop collapse / other pages) */
.topic-select {
  min-width: 11rem;
}

@media (max-width: 991.98px) {
  #regionSettings .form-select {
    min-height: 2.75rem;
  }

  #regionSettings .btn-primary {
    min-height: 2.75rem;
  }
}

/* Three columns: stacked on small screens; row from lg */
.news-columns {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

@media (min-width: 992px) {
  .news-columns {
    flex-direction: row;
    align-items: stretch;
    gap: 0.75rem;
  }

  .news-column-host {
    flex: 1 1 0;
    min-width: 0;
    transition: flex 0.38s cubic-bezier(0.4, 0, 0.2, 1);
  }
}

/* Hover-to-expand: mouse / trackpad only — avoids broken behavior on touch */
@media (min-width: 992px) and (hover: hover) and (pointer: fine) {
  .news-columns:has(.news-column-host:hover) .news-column-host:not(:hover) {
    flex: 0 0 3.5rem;
    min-width: 3.5rem;
  }

  .news-columns:has(.news-column-host:hover) .news-column-host:hover {
    flex: 1 1 0;
    min-width: 0;
    z-index: 2;
  }

  .news-column-host:hover .news-column {
    box-shadow: 0 0.5rem 2.5rem rgba(0, 0, 0, 0.12);
  }

  .news-columns:has(.news-column-host:hover) .news-column-host:not(:hover) .country-label-full,
  .news-columns:has(.news-column-host:hover) .news-column-host:not(:hover) .country-meta {
    display: none !important;
  }

  .news-columns:has(.news-column-host:hover) .news-column-host:not(:hover) .country-heading {
    flex-direction: column;
    align-items: center;
    gap: 0.35rem;
  }

  .news-columns:has(.news-column-host:hover) .news-column-host:not(:hover) .country-flag {
    font-size: 1.5rem;
    line-height: 1;
  }

  .news-columns:has(.news-column-host:hover) .news-column-host:not(:hover) .country-label-short {
    display: block !important;
    font-size: 1rem;
    font-weight: 700;
    letter-spacing: 0.02em;
    writing-mode: vertical-rl;
    transform: rotate(180deg);
    margin: 0 auto;
    max-height: 14rem;
    overflow: hidden;
    text-overflow: ellipsis;
  }

  .news-columns:has(.news-column-host:hover) .news-column-host:not(:hover) .news-column-list,
  .news-columns:has(.news-column-host:hover) .news-column-host:not(:hover) .card-body > p {
    display: none !important;
  }

  .news-columns:has(.news-column-host:hover) .news-column-host:not(:hover) .card-header {
    padding: 0.75rem 0.35rem;
    text-align: center;
    border-bottom: none;
  }

  .news-columns:has(.news-column-host:hover) .news-column-host:not(:hover) .news-column {
    min-height: 12rem;
  }

  .news-column-host:hover .news-column-list {
    max-height: min(88vh, 52rem);
  }

  .news-column-host:hover .news-item-row .news-link {
    line-height: 1.45;
  }

  .news-column-host:hover .news-item-row {
    padding-top: 0.65rem !important;
    padding-bottom: 0.65rem !important;
  }

  .news-column-host:hover .news-item-row .small {
    font-size: 0.875rem;
  }
}

.country-flag {
  font-size: 1.35rem;
  line-height: 1;
  user-select: none;
  flex-shrink: 0;
}

.country-heading-labels {
  min-width: 0;
}

.country-label-short {
  display: none;
}

@media (prefers-reduced-motion: reduce) {
  .news-column-host {
    transition: none !important;
  }

  .news-item-row {
    transition: none !important;
  }
}

.news-column .news-column-list {
  max-height: min(70vh, 42rem);
  overflow-y: auto;
}

.news-item-row {
  transition: background-color 0.12s ease;
}

.news-item-row:hover {
  background-color: rgba(13, 110, 253, 0.06);
}

.news-item-row .news-link {
  color: #0d6efd;
}

.news-item-row:hover .news-link {
  color: #0a58ca;
}

.news-thumb-wrap {
  border-radius: 0.375rem;
  overflow: hidden;
  background: #f1f3f5;
}

.news-thumb-wrap--photo {
  width: 96px;
  height: 72px;
}

.news-thumb-wrap--icon {
  width: 40px;
  height: 40px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.news-thumb-wrap--placeholder {
  width: 40px;
  height: 40px;
  background: linear-gradient(135deg, #e9ecef 0%, #dee2e6 100%);
}

.news-thumb {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.news-thumb--icon {
  object-fit: contain;
  padding: 4px;
  background: #fff;
}

.min-width-0 {
  min-width: 0;
}

/* Mobile / coarse touch: roomier rows, smaller thumbs, shorter scroll panes */
@media (max-width: 991.98px) {
  .news-item-row {
    min-height: 2.875rem;
    padding-top: 0.65rem !important;
    padding-bottom: 0.65rem !important;
  }

  .news-item-row .news-link {
    line-height: 1.4;
  }

  .news-thumb-wrap--photo {
    width: 72px;
    height: 54px;
  }

  .news-thumb-wrap--icon,
  .news-thumb-wrap--placeholder {
    width: 36px;
    height: 36px;
  }

  .news-column .news-column-list {
    max-height: min(62vh, 32rem);
  }

  .news-column .card-header {
    padding-top: 0.85rem;
    padding-bottom: 0.85rem;
  }
}

@media (max-width: 991.98px) and (hover: none) {
  .news-item-row:active {
    background-color: rgba(13, 110, 253, 0.09);
  }
}
