/* Shared rhancasa portal: gradient canvas, header, and main content shell. */
:root {
  --bg: #0f172a;
  --panel: rgba(30, 41, 59, 0.85);
  --border: rgba(148, 163, 184, 0.15);
  --text: #e2e8f0;
  --muted: #94a3b8;
  --accent: #38bdf8;
  --accent2: #a78bfa;
  /* One column width for all authenticated portal pages + login shell */
  --portal-max-width: 1400px;
  /* Tight horizontal padding on phones; safe-area applied on .portal-page below */
  --portal-page-padding: clamp(0.4rem, 2.6vw, 1.25rem);
  /* Portal bar height — nav tap targets + logo row */
  --portal-header-hit: 3.45rem;
  --header-nav-icon-size: calc(var(--portal-header-hit) * 0.51);
  --header-nav-radius: calc(var(--portal-header-hit) * 0.283);
  /* Profile circle: between nav icon glyph and full tap cell */
  --portal-profile-size: calc(var(--portal-header-hit) * 0.68);
  --profile-avatar-font: calc(var(--portal-profile-size) * 0.42);
}
/* Avoid header/nav shifting when scrollbar appears (short vs tall pages). */
html {
  scrollbar-gutter: stable;
  /* Same base as body so overscroll / rubber-band does not flash white past the gradient canvas. */
  background-color: var(--bg);
}
* {
  box-sizing: border-box;
}
body {
  margin: 0;
  min-height: 100vh;
  min-height: 100dvh;
  font-family: "Segoe UI", system-ui, sans-serif;
  color: var(--text);
  background: linear-gradient(165deg, #0c1222 0%, var(--bg) 40%, #1e1b4b 100%);
}
header {
  --header-logo-h: clamp(2.75rem, 7vw, 4.5rem);
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 0.45rem 1.25rem;
  min-height: calc(var(--header-logo-h) + 0.95rem);
  border-bottom: 1px solid var(--border);
  background: rgba(15, 23, 42, 0.6);
  backdrop-filter: blur(8px);
}
.site-brand {
  display: flex;
  align-items: center;
  gap: 0.85rem;
  min-width: 0;
}
.site-logo {
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  padding: 0;
  border-radius: 0.35rem;
  background: transparent;
  border: none;
  line-height: 0;
  text-decoration: none;
  transition: opacity 0.15s ease;
}
.site-logo:hover {
  opacity: 0.88;
}
.site-logo:focus-visible {
  outline: 2px solid rgba(56, 189, 248, 0.7);
  outline-offset: 3px;
}
.site-logo img {
  display: block;
  height: var(--header-logo-h);
  width: auto;
  max-width: min(18rem, 52vw);
  object-fit: contain;
  object-position: left center;
}
.site-brand-text {
  min-width: 0;
}
header h1 {
  margin: 0;
  font-size: 1.15rem;
  font-weight: 700;
  background: linear-gradient(90deg, var(--accent), var(--accent2));
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}
.meta {
  font-size: 0.85rem;
  color: var(--muted);
}
.actions {
  display: flex;
  gap: 0.5rem;
  flex-wrap: wrap;
}
button,
a.link {
  font: inherit;
  cursor: pointer;
  border-radius: 0.5rem;
  padding: 0.45rem 0.85rem;
  border: 1px solid var(--border);
  background: rgba(51, 65, 85, 0.5);
  color: var(--text);
  text-decoration: none;
  font-size: 0.85rem;
}
button:hover,
a.link:hover {
  background: rgba(71, 85, 105, 0.6);
}
a.link.link-current,
button.link-current {
  border-color: rgba(56, 189, 248, 0.35);
  background: rgba(56, 189, 248, 0.12);
  color: var(--accent);
  cursor: default;
  pointer-events: none;
}

/* Content sits in one column on the gradient; dashboard adds .dash-grid for multi-column. */
.portal-page {
  display: grid;
  gap: clamp(0.5rem, 1.8vw, 1rem);
  padding: var(--portal-page-padding);
  padding-left: max(var(--portal-page-padding), env(safe-area-inset-left, 0px));
  padding-right: max(var(--portal-page-padding), env(safe-area-inset-right, 0px));
  padding-bottom: max(var(--portal-page-padding), env(safe-area-inset-bottom, 0px));
  max-width: min(var(--portal-max-width), 100%);
  margin: 0 auto;
  align-items: start;
  box-sizing: border-box;
  width: 100%;
  min-width: 0;
}

/* Large grey content panels (dashboard, weather, netmon, optional div.panel) */
.panel,
section.panel {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 1rem;
  padding: clamp(0.5rem, 2vw, 0.95rem) clamp(0.52rem, 2.4vw, 1.05rem);
  min-width: 0;
}
.panel h2,
section.panel h2 {
  margin: 0 0 0.75rem;
  font-size: 0.78rem;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--muted);
}

/* --- Modern top bar (icon nav + profile menu) --- */
header.portal-header {
  --header-logo-h: var(--portal-header-hit);
  position: sticky;
  top: 0;
  /* Profile dropdown and frosted bar stay on top while content scrolls underneath */
  z-index: 500;
  display: grid;
  grid-template-columns: auto 1fr auto;
  grid-template-rows: var(--portal-header-hit);
  align-items: stretch;
  gap: 0.35rem 0.85rem;
  /* No vertical padding: row height is exactly --portal-header-hit */
  padding: 0 clamp(0.42rem, 2.2vw, 1.1rem);
  min-height: 0;
  border-bottom: 1px solid var(--border);
  background: rgba(15, 23, 42, 0.92);
  backdrop-filter: blur(12px);
  box-shadow: 0 1px 0 var(--border), 0 8px 28px rgba(0, 0, 0, 0.22);
}
header.portal-header .portal-header-left {
  display: flex;
  align-items: stretch;
  min-width: 0;
  min-height: 0;
  height: 100%;
}
header.portal-header .site-logo {
  line-height: 0;
  display: flex;
  align-items: center;
  height: 100%;
  max-height: var(--portal-header-hit);
  overflow: hidden;
  /* Inset from header edges so the mark does not read flush / clipped */
  padding: 0.18rem 0.32rem;
}
header.portal-header .site-logo img {
  display: block;
  width: auto;
  height: 100%;
  max-height: 100%;
  max-width: min(42rem, 92vw);
  object-fit: contain;
  object-position: left center;
  flex-shrink: 0;
}
.portal-header-left {
  display: flex;
  align-items: center;
  min-width: 0;
}
.header-nav {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: calc(var(--portal-header-hit) * 0.055);
  flex-wrap: nowrap;
  min-width: 0;
  height: 100%;
}
.header-nav-item {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  width: var(--portal-header-hit);
  height: var(--portal-header-hit);
  border-radius: var(--header-nav-radius, 0.85rem);
  color: var(--muted);
  background: transparent;
  border: none;
  text-decoration: none;
  cursor: pointer;
  transition: color 0.12s ease;
}
.header-nav-item:hover {
  color: var(--accent);
  background: transparent;
}
.header-nav-item:focus-visible {
  outline: 2px solid rgba(56, 189, 248, 0.65);
  outline-offset: 2px;
}
.header-nav-item.is-active {
  color: var(--accent);
  background: transparent;
  cursor: default;
  pointer-events: none;
}
/* Underline indicator (hover + current page) — no filled background */
.header-nav-item:hover::after,
.header-nav-item.is-active::after {
  content: "";
  position: absolute;
  bottom: calc(var(--portal-header-hit) * 0.1);
  left: 50%;
  transform: translateX(-50%);
  width: min(1.85rem, 55%);
  height: 2px;
  border-radius: 1px;
  background: var(--accent);
}
.header-nav-icon {
  width: var(--header-nav-icon-size, 1.6rem);
  height: var(--header-nav-icon-size, 1.6rem);
  display: block;
  flex-shrink: 0;
  stroke: currentColor;
  fill: none;
}
.header-nav-item--external {
  pointer-events: auto;
}
.portal-header-right {
  display: flex;
  align-items: center;
  justify-content: flex-end;
}
.profile-menu {
  position: relative;
}
.profile-trigger {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  width: var(--portal-profile-size);
  height: var(--portal-profile-size);
  border: 1px solid transparent;
  border-radius: 50%;
  background: transparent;
  cursor: pointer;
  color: var(--text);
  transition: border-color 0.12s ease, color 0.12s ease;
  flex-shrink: 0;
  box-sizing: border-box;
}
.profile-trigger:hover,
.profile-menu.is-open .profile-trigger {
  background: transparent;
  box-shadow: none;
  border-color: rgba(56, 189, 248, 0.65);
}
.profile-trigger:focus-visible {
  outline: 2px solid rgba(56, 189, 248, 0.65);
  outline-offset: 2px;
}
.profile-avatar {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  height: 100%;
  border-radius: 50%;
  font-size: var(--profile-avatar-font, 1.05rem);
  font-weight: 700;
  background: linear-gradient(145deg, rgba(56, 189, 248, 0.35), rgba(167, 139, 250, 0.4));
  color: var(--text);
}
.profile-chevron {
  display: none;
}
header.portal-header .profile-chevron svg {
  display: none;
}
.profile-dropdown {
  position: absolute;
  top: calc(100% + 10px);
  right: 0;
  min-width: 15.5rem;
  padding: 0.45rem 0;
  background: rgba(30, 41, 59, 0.98);
  border: 1px solid rgba(148, 163, 184, 0.22);
  border-radius: 0.75rem;
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.45);
  opacity: 0;
  visibility: hidden;
  transform: translateY(-6px);
  transition: opacity 0.16s ease, transform 0.16s ease, visibility 0.16s;
  z-index: 2;
}
.profile-dropdown--stacked {
  min-width: min(18.5rem, calc(100vw - 1.5rem));
}
.profile-dropdown-pane--prefs {
  padding-bottom: 0.35rem;
}
.profile-menu-row--prefs {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
}
.profile-prefs-row-text {
  flex: 1;
  text-align: left;
}
.profile-prefs-chevron-r {
  font-size: 1.15rem;
  font-weight: 300;
  color: var(--muted);
  line-height: 1;
}
.profile-menu-row--back {
  display: flex;
  align-items: center;
  gap: 0.35rem;
  border-bottom: 1px solid var(--border);
  margin-bottom: 0.25rem;
  font-weight: 600;
  color: var(--accent);
}
.profile-prefs-chevron-l {
  font-size: 1.2rem;
  font-weight: 400;
  line-height: 1;
}
.profile-prefs-body {
  padding: 0.35rem 0.65rem 0.55rem;
  max-height: min(70vh, 22rem);
  overflow-y: auto;
}
.profile-prefs-section {
  margin-bottom: 0.85rem;
}
.profile-prefs-section-label {
  font-size: 0.68rem;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  color: var(--muted);
  margin-bottom: 0.45rem;
}
.profile-wx-bubbles {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
}
.profile-wx-bubble {
  font: inherit;
  font-size: 0.72rem;
  padding: 0.38rem 0.55rem;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: rgba(15, 23, 42, 0.55);
  color: var(--text);
  cursor: pointer;
  line-height: 1.2;
  transition: background 0.12s ease, border-color 0.12s ease, color 0.12s ease;
}
.profile-wx-bubble:hover {
  border-color: rgba(56, 189, 248, 0.45);
  background: rgba(56, 189, 248, 0.08);
}
.profile-wx-bubble.is-selected,
.profile-wx-bubble[aria-checked="true"] {
  border-color: rgba(56, 189, 248, 0.55);
  background: rgba(56, 189, 248, 0.18);
  color: var(--text);
  font-weight: 600;
}
html[data-portal-theme="pink"] .profile-wx-bubble.is-selected,
html[data-portal-theme="pink"] .profile-wx-bubble[aria-checked="true"] {
  border-color: rgba(255, 79, 216, 0.55);
  background: rgba(255, 79, 216, 0.15);
}
.profile-prefs-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  padding: 0.45rem 0;
  border-top: 1px solid rgba(148, 163, 184, 0.12);
}
.profile-prefs-row:first-of-type {
  border-top: none;
  padding-top: 0.15rem;
}
.profile-prefs-row-label {
  font-size: 0.82rem;
  color: var(--text);
  line-height: 1.35;
  flex: 1;
  min-width: 0;
}
.portal-ios-switch {
  width: 2.75rem;
  height: 1.55rem;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: rgba(51, 65, 85, 0.85);
  position: relative;
  flex-shrink: 0;
  cursor: pointer;
  padding: 0;
  transition: background 0.2s ease, border-color 0.2s ease;
}
.portal-ios-switch::after {
  content: "";
  position: absolute;
  width: 1.18rem;
  height: 1.18rem;
  border-radius: 50%;
  background: #f8fafc;
  top: 0.15rem;
  left: 0.15rem;
  transition: transform 0.22s ease;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.35);
}
.portal-ios-switch[aria-checked="true"] {
  background: rgba(34, 197, 94, 0.5);
  border-color: rgba(34, 197, 94, 0.65);
}
.portal-ios-switch[aria-checked="true"]::after {
  transform: translateX(1.12rem);
}
.portal-ios-switch:focus-visible {
  outline: 2px solid rgba(56, 189, 248, 0.65);
  outline-offset: 2px;
}
.profile-sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}
.profile-menu.is-open .profile-dropdown {
  opacity: 1;
  visibility: visible;
  transform: translateY(0);
}
.profile-dropdown-head {
  padding: 0.55rem 1rem 0.65rem;
  border-bottom: 1px solid var(--border);
  margin-bottom: 0.25rem;
}
.profile-menu-name {
  font-weight: 600;
  font-size: 0.92rem;
  color: var(--text);
  word-break: break-word;
}
.profile-menu-email {
  font-size: 0.78rem;
  color: var(--muted);
  margin-top: 0.2rem;
  word-break: break-all;
}
.profile-menu-row {
  display: block;
  width: 100%;
  text-align: left;
  padding: 0.5rem 1rem;
  border: none;
  background: transparent;
  color: var(--text);
  font: inherit;
  font-size: 0.88rem;
  text-decoration: none;
  cursor: pointer;
  transition: background 0.12s ease;
  box-sizing: border-box;
}
a.profile-menu-row {
  color: var(--text);
}
.profile-menu-row:hover:not(:disabled) {
  background: rgba(56, 189, 248, 0.1);
}
.profile-menu-row:disabled {
  opacity: 0.55;
  cursor: not-allowed;
}
.profile-soon {
  font-size: 0.72rem;
  color: var(--muted);
  margin-left: 0.35rem;
}
.profile-menu-row--danger {
  color: #f87171;
}
.profile-menu-row--danger:hover:not(:disabled) {
  background: rgba(248, 113, 113, 0.12);
}

.portal-page-title {
  margin: 0 0 0.35rem;
  font-size: clamp(1.1rem, 4vw, 1.35rem);
  font-weight: 700;
  line-height: 1.2;
  background: linear-gradient(90deg, var(--accent), var(--accent2));
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}
.dash-grid > .portal-page-title {
  grid-column: 1 / -1;
}

/* Weather location (dashboard + full weather page + profile) */
.wx-forecast-head-actions {
  display: flex;
  align-items: center;
  gap: 0.35rem;
  margin-left: auto;
  flex-shrink: 0;
}
.wx-loc-select {
  font: inherit;
  font-size: 0.72rem;
  color: var(--text);
  background: rgba(15, 23, 42, 0.65);
  border: 1px solid var(--border);
  border-radius: 0.45rem;
  padding: 0.28rem 0.42rem;
  min-width: 0;
  max-width: min(13rem, 56vw);
  cursor: pointer;
  line-height: 1.2;
}
.wx-loc-select:disabled {
  opacity: 0.55;
  cursor: not-allowed;
}
.profile-weather-picker {
  padding: 0.42rem 0.65rem 0.48rem;
  border-bottom: 1px solid var(--border);
}
.profile-weather-picker-inner {
  display: flex;
  align-items: center;
  gap: 0.45rem;
  flex-wrap: nowrap;
}
.profile-weather-picker-label {
  font-size: 0.68rem;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  color: var(--muted);
  flex-shrink: 0;
}
.profile-weather-picker .wx-loc-select {
  flex: 1;
  min-width: 0;
  max-width: none;
}

/* Public pages (landing, login): same 3-column bar as the portal; logo | icon nav | actions */
header.portal-header.portal-header--guest {
  grid-template-columns: auto 1fr auto;
}
.portal-header-guest-actions {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 0.5rem;
  flex-wrap: wrap;
}

/* Keep logo + nav + profile on one bar; nav scrolls horizontally if needed (no second row). */
@media (max-width: 720px) {
  header.portal-header {
    grid-template-columns: auto minmax(0, 1fr) auto;
    grid-template-rows: var(--portal-header-hit);
    align-items: center;
  }
  header.portal-header .site-logo img {
    max-width: min(9.5rem, 42vw);
  }
  header.portal-header .header-nav {
    justify-content: center;
    overflow-x: auto;
    overflow-y: hidden;
    min-width: 0;
    padding-bottom: 0;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: thin;
  }
}

/* Narrow phones: slightly reduce sticky header horizontal squeeze from safe areas */
@media (max-width: 420px) {
  header.portal-header {
    padding-left: max(0.45rem, env(safe-area-inset-left, 0px));
    padding-right: max(0.45rem, env(safe-area-inset-right, 0px));
  }
}

/* Generic loading / empty-state text (portal pages). */
.loading {
  color: var(--muted);
  font-size: 0.9rem;
}

/* Soft pulsing dots — “thinking” / agent-activity style (used with .portal-thinking). */
.portal-thinking {
  display: flex;
  flex-direction: row;
  align-items: center;
  gap: 0.65rem;
  min-height: 2rem;
  color: var(--muted);
  font-size: 0.9rem;
}
.portal-thinking-label {
  flex: 1;
  min-width: 0;
  line-height: 1.4;
}
.portal-thinking-dots {
  display: inline-flex;
  flex-direction: row;
  align-items: center;
  gap: 0.2rem;
  flex-shrink: 0;
}
.portal-thinking-dots > span {
  display: block;
  width: 0.3rem;
  height: 0.3rem;
  border-radius: 50%;
  background: currentColor;
  opacity: 0.3;
  transform: scale(0.88);
  animation: portal-thinking-pulse 1.2s ease-in-out infinite;
}
/* Staggered delays for an organic, non-metronome feel */
.portal-thinking-dots > span:nth-child(1) {
  animation-delay: 0ms;
}
.portal-thinking-dots > span:nth-child(2) {
  animation-delay: 130ms;
}
.portal-thinking-dots > span:nth-child(3) {
  animation-delay: 270ms;
}
.portal-thinking-dots > span:nth-child(4) {
  animation-delay: 70ms;
}
.portal-thinking-dots > span:nth-child(5) {
  animation-delay: 200ms;
}
.portal-thinking-dots > span:nth-child(6) {
  animation-delay: 340ms;
}
@keyframes portal-thinking-pulse {
  0%,
  100% {
    opacity: 0.28;
    transform: scale(0.85) translateY(0);
  }
  45% {
    opacity: 1;
    transform: scale(1.14) translateY(-0.05rem);
  }
}

/* SVG wordmark when /images/rhancasalogo-best.png fails to load (see portal-header.js). */
.logo-fallback {
  display: none;
  line-height: 0;
}
.logo-fallback svg {
  height: var(--header-logo-h);
  width: auto;
  max-width: min(18rem, 52vw);
}
.site-logo.has-fallback .logo-fallback {
  display: block;
}
.site-logo.has-fallback img {
  display: none;
}
