/* ==========================================================================
   hookmebysam app shell.
   One definition of: page frame, top bar, tab bar / desktop rail, screen stack,
   connectivity banner, pull-to-refresh and toasts. (Replaces ~25 overlapping
   legacy rules in style.css and premium.css.)

   Phone  (<900px): top bar, screen, bottom tab bar.
   Wide  (>=900px): left navigation rail + one centred content column.
   ========================================================================== */

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

/* ---------- Frame ---------- */
.app-shell {
  position: relative;
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  grid-template-rows: auto auto auto minmax(0, 1fr) auto;
  width: 100%;
  max-width: var(--content-max);
  height: 100dvh;
  margin: 0 auto;
  overflow: hidden;
  background: var(--bg);
  color: var(--text);
}
.app-shell > .app-header { grid-row: 1; grid-column: 1; }
.app-shell > .network-status-banner { grid-row: 2; grid-column: 1; }
.app-shell > .shell-notices { grid-row: 3; grid-column: 1; }
.app-shell > .screens-container { grid-row: 4; grid-column: 1; }
.app-shell > .bottom-nav { grid-row: 5; grid-column: 1; }

.screens-container {
  position: relative;
  min-height: 0;
  overflow: hidden;
}
.screen {
  position: absolute;
  inset: 0;
  display: none;
  flex-direction: column;
  width: 100%;
  background: var(--bg);
  color: var(--text);
}
.screen.active { display: flex; }

.is-hidden { display: none !important; }

/* ---------- Top bar ---------- */
.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--s-2);
  min-height: calc(var(--bar-h) + var(--safe-top));
  padding: var(--safe-top) var(--s-3) 0 var(--s-4);
  background: var(--bg);
  border-bottom: 1px solid var(--border);
  box-sizing: border-box;
}
.header-left { display: flex; align-items: center; gap: var(--s-1); min-width: 0; }
.header-title-wrap { display: flex; align-items: center; gap: var(--s-2); min-width: 0; }
.header-right { display: flex; align-items: center; gap: var(--s-1); }

.main-header-logo,
.screen-header-title {
  display: inline-flex; align-items: center; gap: var(--s-2);
  margin: 0; min-width: 0;
  font-family: var(--font-ui);
  font-size: var(--fs-lg);
  font-weight: 800;
  letter-spacing: -0.02em;
  line-height: 1.1;
  color: var(--text);
  background: none;
  -webkit-text-fill-color: currentColor;
  text-shadow: none;
}
.brand-lockup { display: inline-flex; align-items: center; gap: var(--s-2); }
.main-header-logo .i-logo { width: 28px; height: 28px; color: var(--primary-text); }
.header-title-alt { display: none; }
.main-header-logo .brand-word { font-size: var(--fs-lg); }
.screen-header-title { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.header-btn {
  position: relative;
  display: inline-flex; align-items: center; justify-content: center; gap: var(--s-2);
  min-width: var(--tap); height: var(--tap);
  padding: 0;
  border: 0; border-radius: var(--r-sm);
  background: transparent;
  color: var(--text-2);
  transition: background var(--dur-1), color var(--dur-1);
}
.header-btn:hover { background: var(--surface-raised); color: var(--text); }
.header-btn:active { background: var(--primary-soft); }
.header-btn-gold { color: var(--gold-text); }
.header-btn-gold:hover { color: var(--gold-text); }

.header-btn-label { font-size: var(--fs-sm); font-weight: 700; }
.filter-active-dot {
  position: absolute; top: 9px; right: 9px;
  width: 8px; height: 8px; border-radius: 50%;
  background: var(--primary); border: 2px solid var(--bg); box-sizing: content-box;
}
.header-vip-badge { flex: none; }

/* ---------- Connectivity banner (in flow: never covers content) ---------- */
.network-status-banner {
  display: flex; align-items: center; gap: var(--s-3);
  padding: var(--s-2) var(--s-4);
  font-size: var(--fs-sm); font-weight: 600;
  border-bottom: 1px solid var(--border);
}
.network-status-banner .net-status-text { flex: 1; min-width: 0; }
.network-status-banner.offline { background: var(--warning-soft); color: var(--warning); border-color: transparent; }
.network-status-banner.online { background: var(--success-soft); color: var(--success); border-color: transparent; }
.net-status-retry-btn { min-height: 32px; }

/* ---------- Inline notices ---------- */
.shell-notices { display: flex; flex-direction: column; }
.shell-notices:empty,
.shell-notices > [style*="display: none"],
.shell-notices > [style*="display:none"] { display: none; }
.shell-notices .notice { border-radius: 0; border-width: 0 0 1px; background: var(--surface); }
.notice-body { flex: 1; min-width: 0; }
.notice-compact { align-items: center; padding-top: var(--s-2); padding-bottom: var(--s-2); }
.notice-compact > .i { margin-top: 0; }
.notice-line { flex: 1; min-width: 0; }
.notice-actions { display: flex; flex-wrap: wrap; gap: var(--s-2); margin-top: var(--s-2); }

/* ---------- Pull to refresh ---------- */
.ptr-indicator {
  position: absolute; top: calc(var(--bar-h) + var(--safe-top) + var(--s-2)); left: 50%;
  z-index: var(--z-sticky);
  width: 40px; height: 40px;
  display: grid; place-items: center;
  border-radius: 50%;
  background: var(--surface-raised); color: var(--text-2);
  border: 1px solid var(--border-strong);
  box-shadow: var(--shadow-2);
  transform: translate(-50%, -80px);
  opacity: 0; pointer-events: none;
  transition: transform var(--dur-2) var(--ease-out), opacity var(--dur-2);
}
.ptr-indicator.ptr-pulling,
.ptr-indicator.ptr-refreshing { opacity: 1; }
.ptr-icon { display: grid; place-items: center; }
.ptr-indicator.ptr-refreshing .ptr-icon { animation: hm-spin 0.8s linear infinite; }

/* ---------- Navigation: bottom tab bar (phones) ---------- */
.bottom-nav {
  display: flex;
  align-items: stretch;
  min-height: calc(var(--nav-h) + var(--safe-bottom));
  padding: 0 var(--s-1) var(--safe-bottom);
  background: var(--bg);
  border-top: 1px solid var(--border);
  box-sizing: border-box;
  z-index: var(--z-nav);
}
.rail-brand { display: none; }
.nav-tab {
  position: relative;
  flex: 1; min-width: 0;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px;
  padding: var(--s-2) 0;
  border: 0; background: transparent;
  color: var(--text-3);
  font-size: var(--fs-xs); font-weight: 600; line-height: 1;
  transition: color var(--dur-1);
}
.nav-tab:hover { color: var(--text); }
.nav-tab.active { color: var(--primary-text); }
.nav-tab.active::before {
  content: ""; position: absolute; top: -1px; left: 28%; right: 28%;
  height: 2px; border-radius: 0 0 2px 2px; background: var(--primary-text);
}
.nav-tab .nav-icon-wrap { position: relative; display: inline-flex; }
.nav-tab .i { width: 24px; height: 24px; }
.nav-tab.active .i { stroke-width: 2.1; }
.nav-count-badge {
  position: absolute; top: -6px; left: calc(100% - 8px);
  box-shadow: 0 0 0 2px var(--bg);
}

/* Keyboard open on a phone: tab bar gives its space back to the screen */
body.keyboard-visible .bottom-nav,
body.keyboard-open .bottom-nav,
.app-shell.keyboard-visible .bottom-nav,
.app-shell.keyboard-open .bottom-nav { display: none !important; }

/* ---------- Toasts ---------- */
.toast-notification {
  position: fixed;
  top: calc(var(--safe-top) + var(--s-3)); left: 50%;
  z-index: var(--z-toast);
  width: max-content; max-width: min(92vw, 420px);
  padding: var(--s-3) var(--s-4);
  border-radius: var(--r-sm);
  background: var(--surface-raised);
  color: var(--text);
  border: 1px solid var(--border-strong);
  border-left-width: 4px;
  box-shadow: var(--shadow-2);
  font-size: var(--fs-base); font-weight: 600; line-height: var(--lh-snug);
  text-align: left;
  opacity: 0; pointer-events: none;
  transform: translate(-50%, -16px);
  transition: opacity var(--dur-2), transform var(--dur-2) var(--ease-out);
}
.toast-notification.visible { opacity: 1; transform: translate(-50%, 0); }
.toast-neutral,
.toast-success { border-left-color: var(--success); }
.toast-info { border-left-color: var(--info); }
.toast-warning { border-left-color: var(--warning); }
.toast-error { border-left-color: var(--danger); }

/* ==========================================================================
   Wide screens: navigation rail + content column
   ========================================================================== */
@media (min-width: 900px) {

  :root { --content-max: 640px; }
  .app-shell {
    max-width: none;
    grid-template-columns: 240px minmax(0, var(--content-max));
    grid-template-rows: auto auto auto minmax(0, 1fr);
    justify-content: center;
  }
  .app-shell > .app-header { grid-column: 2; grid-row: 1; }
  .app-shell > .network-status-banner { grid-column: 2; grid-row: 2; }
  .app-shell > .shell-notices { grid-column: 2; grid-row: 3; border-right: 1px solid var(--border); }
  .app-shell > .screens-container { grid-column: 2; grid-row: 4; border-right: 1px solid var(--border); }
  .app-shell > .app-header { border-right: 1px solid var(--border); }

  .app-shell > .bottom-nav {
    grid-column: 1; grid-row: 1 / -1;
    flex-direction: column; align-items: stretch; gap: var(--s-1);
    min-height: 0;
    padding: var(--s-5) var(--s-3);
    border-top: 0;
    border-left: 1px solid var(--border);
    border-right: 1px solid var(--border);
    overflow-y: auto;
  }
  .rail-brand { display: inline-flex; padding: var(--s-1) var(--s-3) var(--s-5); }
  .rail-brand .i-logo { width: 32px; height: 32px; }
  .nav-tab {
    flex: none;
    flex-direction: row; justify-content: flex-start; gap: var(--s-3);
    min-height: var(--tap);
    padding: 0 var(--s-3);
    border-radius: var(--r-sm);
    font-size: var(--fs-base); font-weight: 600;
  }
  .nav-tab:hover { background: var(--surface-raised); }
  .nav-tab.active { background: var(--primary-soft); }
  .nav-tab.active::before { display: none; }
  .nav-count-badge { position: static; margin-left: auto; box-shadow: none; }
  .nav-tab .nav-icon-wrap { order: 0; }
  .nav-tab .nav-label { order: 1; }
  /* the rail already carries the brand; the bar names the screen instead */
  .main-header-logo .brand-lockup { display: none; }
  .main-header-logo .header-title-alt { display: inline; }
  .toast-notification { left: calc(50% + 120px); }

}

@media (max-width: 380px) {

  .app-header { padding-left: var(--s-3); padding-right: var(--s-2); }
  .header-btn { min-width: 40px; }

}
