/**
 * Gemini-inspired app shell: fixed header, drawer nav, settings panel.
 * Palette: safex_prices/css/design-tokens.css
 */

html,
body {
  font-family: var(--font-ui);
}

body {
  margin: 0;
  background: var(--bg-main);
  color: var(--text-primary);
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
}

.app-header {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  z-index: 200;
  box-sizing: border-box;
  min-height: calc(var(--app-header-height) + env(safe-area-inset-top, 0px));
  padding-top: env(safe-area-inset-top, 0px);
  background: var(--bg-main);
  border-bottom: 1px solid var(--border-color);
  transition: transform 0.25s ease-in-out;
}

.app-header__inner {
  display: flex;
  align-items: center;
  gap: 4px;
  height: var(--app-header-height);
  padding: 0 max(12px, env(safe-area-inset-right, 0px)) 0 max(8px, env(safe-area-inset-left, 0px));
  max-width: 100%;
}

.app-header__menu-btn {
  display: inline-flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 5px;
  width: 44px;
  height: 44px;
  padding: 10px;
  margin: 0;
  border: none;
  border-radius: 50%;
  background: transparent;
  color: var(--text-primary);
  cursor: pointer;
  flex-shrink: 0;
  touch-action: manipulation;
  transition:
    background 0.15s ease,
    opacity 0.08s ease,
    transform 0.08s ease;
}

.app-header__menu-btn:hover {
  background: var(--header-hover-bg);
}

.app-header__menu-btn:focus-visible {
  outline: 2px solid var(--input-focus-border);
  outline-offset: 2px;
}

@media (pointer: coarse) {
  .app-header__menu-btn:active {
    transform: scale(0.97);
    opacity: 0.92;
  }
}

.app-header__menu-line {
  display: block;
  width: 18px;
  height: 2px;
  border-radius: 1px;
  background: currentColor;
}

.app-header__brand {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-size: 18px;
  font-weight: 500;
  letter-spacing: -0.02em;
  line-height: 1.2;
  color: var(--text-primary);
  user-select: none;
  white-space: nowrap;
  margin-right: auto;
  min-width: 0;
  text-decoration: none;
  flex-shrink: 0;
  touch-action: manipulation;
}

.app-header__brand:hover {
  color: var(--text-primary);
}

.app-header__brand:focus-visible {
  outline: 2px solid var(--input-focus-border);
  outline-offset: 3px;
  border-radius: 10px;
}

.app-brand-mark {
  display: block;
  width: 28px;
  height: 28px;
  flex-shrink: 0;
  object-fit: contain;
}

.app-header__brand-text {
  min-width: 0;
}

.app-header__alerts {
  display: flex;
  align-items: center;
  flex-shrink: 0;
}

.app-header__alerts-btn {
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 44px;
  height: 44px;
  border-radius: 50%;
  color: var(--text-primary);
  text-decoration: none;
  touch-action: manipulation;
  transition:
    background 0.15s ease,
    opacity 0.08s ease,
    transform 0.08s ease;
}

.app-header__alerts-btn:hover {
  background: var(--header-hover-bg);
}

.app-header__alerts-icon {
  font-size: 1.2rem;
  line-height: 1;
}

.app-header__alerts-badge {
  position: absolute;
  top: 6px;
  right: 6px;
  min-width: 1.1rem;
  height: 1.1rem;
  padding: 0 4px;
  border-radius: 999px;
  background: var(--brand-farm);
  color: var(--btn-brand-text);
  font-size: 0.65rem;
  font-weight: 700;
  line-height: 1.1rem;
  text-align: center;
  box-sizing: border-box;
}

.app-header__settings {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-shrink: 0;
}

.app-header__settings-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 44px;
  height: 44px;
  padding: 10px;
  margin: 0;
  border: none;
  border-radius: 50%;
  background: transparent;
  color: var(--text-primary);
  cursor: pointer;
  touch-action: manipulation;
  transition:
    background 0.15s ease,
    opacity 0.08s ease,
    transform 0.08s ease;
}

.app-header__settings-btn:hover {
  background: var(--header-hover-bg);
}

@media (pointer: coarse) {
  .app-header__settings-btn:active {
    transform: scale(0.97);
    opacity: 0.92;
  }
}

.app-header__settings-icon {
  font-size: 1.25rem;
  line-height: 1;
  display: block;
}

/* —— Global settings drawer (right panel) —— */
.app-settings-backdrop {
  position: fixed;
  inset: 0;
  top: calc(var(--app-header-height) + env(safe-area-inset-top, 0px));
  z-index: 170;
  border: none;
  padding: 0;
  margin: 0;
  background: var(--backdrop-bg);
  cursor: pointer;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}

.app-settings-backdrop[hidden] {
  display: none !important;
}

.app-settings-drawer {
  position: fixed;
  top: calc(var(--app-header-height) + env(safe-area-inset-top, 0px));
  right: 0;
  bottom: 0;
  z-index: 180;
  width: min(100vw, 360px);
  max-width: 100%;
  display: flex;
  flex-direction: column;
  background-color: var(--bg-main);
  color: var(--text-primary);
  border-left: 1px solid var(--border-color);
  box-shadow: var(--shadow-sidebar);
  transform: translateX(100%);
  transition: transform 0.28s cubic-bezier(0.4, 0, 0.2, 1);
  will-change: transform;
}

html.app-settings-open .app-settings-drawer {
  transform: translateX(0);
}

body.has-verification-banner .app-settings-backdrop {
  top: calc(
    var(--app-header-height) + env(safe-area-inset-top, 0px) + var(--site-banner-height, 50px)
  );
}

body.has-verification-banner .app-settings-drawer {
  top: calc(
    var(--app-header-height) + env(safe-area-inset-top, 0px) + var(--site-banner-height, 50px)
  );
}

.app-settings-drawer__header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-shrink: 0;
  padding: 16px 16px 12px;
  border-bottom: 1px solid var(--border-color);
}

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

.app-settings-drawer__close {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 40px;
  height: 40px;
  margin: 0;
  padding: 0;
  border: none;
  border-radius: 50%;
  background: transparent;
  color: var(--text-primary);
  font-size: 1.5rem;
  line-height: 1;
  cursor: pointer;
  touch-action: manipulation;
  transition:
    background 0.12s ease,
    opacity 0.08s ease,
    transform 0.08s ease;
}

.app-settings-drawer__close:hover {
  background: var(--btn-icon-hover);
}

.app-settings-drawer__body {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: 16px 16px calc(20px + env(safe-area-inset-bottom, 0px));
}

.settings-drawer__section + .settings-drawer__section {
  margin-top: 20px;
  padding-top: 20px;
  border-top: 1px solid var(--border-color);
}

.settings-drawer__section-title {
  margin: 0 0 12px;
  font-size: 0.75rem;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--text-secondary);
}

.settings-drawer__options {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.settings-drawer__account-email {
  margin: 0 0 12px;
  font-size: 0.875rem;
  color: var(--text-secondary);
  word-break: break-word;
}

.settings-drawer__links {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.settings-drawer__logout-form {
  margin: 0;
}

.settings-drawer__link {
  display: flex;
  flex-direction: column;
  gap: 4px;
  width: 100%;
  padding: 12px 14px;
  border-radius: 12px;
  border: 1px solid var(--border-color);
  background-color: var(--bg-main);
  color: var(--text-primary);
  text-decoration: none;
  text-align: left;
  font: inherit;
  cursor: pointer;
  touch-action: manipulation;
  transition:
    background-color 0.12s ease,
    border-color 0.12s ease,
    opacity 0.08s ease,
    transform 0.08s ease;
}

.settings-drawer__link:hover {
  background-color: var(--table-row-hover);
  border-color: var(--text-secondary);
  color: var(--text-primary);
}

.settings-drawer__link.is-active {
  background-color: var(--btn-icon-hover);
  border-color: var(--accent-solid);
  box-shadow: inset 3px 0 0 var(--accent-solid);
}

.settings-drawer__link--button {
  appearance: none;
}

.settings-drawer__link-label {
  font-size: 0.9375rem;
  font-weight: 600;
  color: var(--text-primary);
}

.settings-drawer__link-hint {
  font-size: 0.8125rem;
  color: var(--text-secondary);
  line-height: 1.35;
}

@media (pointer: coarse) {
  .app-settings-drawer__close:active,
  .settings-drawer__link:active {
    transform: scale(0.99);
    opacity: 0.94;
  }
}

@media (prefers-reduced-motion: reduce) {
  .app-settings-drawer {
    transition: none;
  }

  .app-settings-drawer__close:active,
  .settings-drawer__link:active {
    transform: none;
    opacity: 1;
  }
}

.app-settings-option {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 14px;
  border-radius: 12px;
  border: 1px solid transparent;
  background: transparent;
  color: var(--text-primary);
  font: inherit;
  font-size: 0.9375rem;
  font-weight: 500;
  text-align: left;
  cursor: pointer;
  width: 100%;
  touch-action: manipulation;
  transition:
    background 0.12s ease,
    border-color 0.12s ease,
    opacity 0.08s ease,
    transform 0.08s ease;
}

.app-settings-option:hover {
  background: var(--header-hover-bg);
}

.app-settings-option[aria-pressed='true'] {
  border-color: var(--state-selected-border);
  background: var(--header-hover-bg);
}

@media (pointer: coarse) {
  .app-settings-option:active {
    transform: scale(0.99);
    opacity: 0.94;
  }
}

.app-settings-option__swatch {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  flex-shrink: 0;
}

.app-settings-option__swatch--dark {
  background: var(--swatch-dark-fill);
  border: 1px solid var(--swatch-dark-ring);
}

.app-settings-option__swatch--light {
  background: var(--swatch-light-fill);
  border: 1px solid var(--swatch-light-ring);
}

/* —— Backdrop —— */
.app-sidebar-backdrop {
  position: fixed;
  inset: 0;
  top: calc(var(--app-header-height) + env(safe-area-inset-top, 0px));
  z-index: 150;
  background: var(--backdrop-bg);
  border: none;
  padding: 0;
  cursor: pointer;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}

.app-sidebar-backdrop[hidden] {
  display: none !important;
}

/* —— Sidebar drawer —— */
.app-sidebar {
  position: fixed;
  top: calc(var(--app-header-height) + env(safe-area-inset-top, 0px));
  left: 0;
  bottom: 0;
  width: min(var(--sidebar-width), 100vw - 48px);
  max-width: var(--sidebar-width);
  z-index: 160;
  display: flex;
  flex-direction: column;
  background: var(--bg-main);
  color: var(--text-primary);
  border-right: 1px solid var(--border-color);
  box-shadow: var(--shadow-sidebar);
  transform: translateX(-100%);
  transition: transform 0.28s cubic-bezier(0.4, 0, 0.2, 1);
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: 20px 16px calc(20px + env(safe-area-inset-bottom, 0px));
}

html.app-sidebar-open .app-sidebar {
  transform: translateX(0);
}

@media (prefers-reduced-motion: reduce) {
  .app-sidebar {
    transition: none;
  }
}

.app-sidebar .sidebar-menu {
  gap: 4px;
}

.app-sidebar .nav-link {
  color: var(--text-primary);
  border-radius: 12px;
  padding: 12px 14px;
}

.app-sidebar .nav-link:hover {
  background: var(--header-hover-bg);
  transform: none;
  color: var(--text-primary);
}

.app-sidebar .active-highlight {
  background: var(--header-hover-bg);
  border-left: 3px solid var(--accent-solid);
  font-weight: 600;
  color: var(--text-primary);
}

.app-sidebar .nav-daily-update-cta {
  background: var(--bg-main);
  border-color: var(--border-color);
  color: var(--text-primary);
  margin-top: auto;
}

.app-sidebar .nav-daily-update-cta:hover {
  background: var(--header-hover-bg);
  border-color: var(--text-secondary);
  color: var(--text-primary);
}

/* —— Main column —— */
.app-main-offset {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 0;
  background-color: var(--bg-main);
  padding-top: calc(var(--app-header-height) + env(safe-area-inset-top, 0px));
}

.content-wrapper {
  margin-left: 0;
  padding-top: 0;
  padding-bottom: 0;
  background-color: var(--bg-main);
  transition: margin-left 0.28s cubic-bezier(0.4, 0, 0.2, 1);
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 0;
}

@media (min-width: 1024px) {
  html.app-sidebar-open .content-wrapper {
    margin-left: calc(var(--sidebar-width) + 16px);
  }
}

#app-content > .container {
  flex: 1;
}

#app-content > .footer.app-zone-footer {
  margin-top: auto;
  flex-shrink: 0;
}

.container {
  background: var(--bg-main);
  color: var(--text-primary);
  border: none;
  box-shadow: none;
}

/* —— Verification banner below header —— */
body.has-verification-banner {
  --site-banner-height: 50px;
}

body.has-verification-banner .site-verification-banner {
  top: calc(var(--app-header-height) + env(safe-area-inset-top, 0px));
  padding-left: max(16px, env(safe-area-inset-left, 0px));
  padding-right: max(16px, env(safe-area-inset-right, 0px));
  z-index: 190;
}

body.has-verification-banner .app-main-offset {
  padding-top: calc(
    var(--app-header-height) + env(safe-area-inset-top, 0px) + var(--site-banner-height, 50px)
  );
}

body.has-verification-banner .app-sidebar {
  top: calc(
    var(--app-header-height) + env(safe-area-inset-top, 0px) + var(--site-banner-height, 50px)
  );
}

body.has-verification-banner .app-sidebar-backdrop {
  top: calc(
    var(--app-header-height) + env(safe-area-inset-top, 0px) + var(--site-banner-height, 50px)
  );
}

/* —— Legacy: hide old floating toggle / orange mobile bar (replaced by app-header) —— */
.sidebar-toggle,
.mobile-topbar {
  display: none !important;
}

/* —— Scroll to top over shell —— */
.scroll-to-top {
  z-index: 210;
}

@media (prefers-reduced-motion: reduce) {
  .app-header__menu-btn,
  .app-header__alerts-btn,
  .app-header__settings-btn {
    transition: background 0.15s ease;
  }

  .app-header__menu-btn:active,
  .app-header__alerts-btn:active,
  .app-header__settings-btn:active {
    transform: none;
    opacity: 1;
  }

  .app-settings-option {
    transition: background 0.12s ease, border-color 0.12s ease;
  }

  .app-settings-option:active {
    transform: none;
    opacity: 1;
  }
}
