/* Project Dynasty PWA shell — additive chrome replacement.
   Loaded after the legacy page styles so it can retire the old header and
   footer without editing them. Owner Desk is untouched. */

:root {
  --pd-shell-h: 54px;
  --pd-shell-bg: rgba(255, 255, 255, 0.86);
  --pd-shell-ink: #102944;
  --pd-shell-dim: #5f7288;
  --pd-shell-line: rgba(16, 41, 68, 0.12);
  --pd-shell-panel: #ffffff;
  --pd-shell-accent: #a87b16;
  --pd-shell-accent-ink: #ffffff;
  --pd-shell-shadow: 0 18px 40px rgba(11, 31, 52, 0.16);
}

html[data-theme="dark"] {
  --pd-shell-bg: rgba(7, 17, 31, 0.84);
  --pd-shell-ink: #f2f5f9;
  --pd-shell-dim: #a7b6c9;
  --pd-shell-line: rgba(255, 255, 255, 0.14);
  --pd-shell-panel: #0d1c30;
  --pd-shell-accent: #f1c95b;
  --pd-shell-accent-ink: #102944;
  --pd-shell-shadow: 0 18px 40px rgba(0, 0, 0, 0.42);
}

/* Retire the legacy chrome at runtime; the markup stays for compatibility. */
body.pd-shell > .app-header,
body.pd-shell > .site-footer,
body.pd-shell > .site-dock,
body.pd-shell > #nav-backdrop {
  display: none !important;
}

body.pd-shell {
  padding-top: calc(var(--pd-shell-h) + env(safe-area-inset-top));
  padding-bottom: calc(70px + env(safe-area-inset-bottom));
}

@media (min-width: 861px) {
  body.pd-shell {
    --pd-shell-h: 58px;
    padding-bottom: 0;
  }
}

/* ---------- Top command bar ---------- */

.pd-topbar {
  position: fixed;
  inset: 0 0 auto 0;
  z-index: 2147482000;
  display: flex;
  align-items: center;
  gap: 16px;
  height: calc(var(--pd-shell-h) + env(safe-area-inset-top));
  padding: env(safe-area-inset-top) 14px 0;
  background: var(--pd-shell-bg);
  color: var(--pd-shell-ink);
  border-bottom: 1px solid var(--pd-shell-line);
  backdrop-filter: saturate(1.4) blur(14px);
  -webkit-backdrop-filter: saturate(1.4) blur(14px);
}

.pd-brand {
  display: inline-flex;
  align-items: center;
  gap: 9px;
  color: inherit;
  text-decoration: none;
  min-width: 0;
}

.pd-brand img {
  width: 30px;
  height: 30px;
  border-radius: 9px;
  display: block;
}

.pd-brand strong {
  font: 1000 15px/1 var(--pd-font-display, inherit);
  letter-spacing: -0.01em;
  white-space: nowrap;
}

.pd-brand small {
  display: block;
  margin-top: 2px;
  color: var(--pd-shell-dim);
  font-size: 9px;
  font-weight: 800;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  white-space: nowrap;
}

.pd-links {
  display: none;
  align-items: center;
  gap: 2px;
  margin-left: 8px;
}

@media (max-width: 520px) {
  .pd-brand small { display: none; }
  .pd-brand strong { font-size: 14px; }
}

.pd-links a,
.pd-links button {
  appearance: none;
  border: 0;
  background: none;
  color: var(--pd-shell-dim);
  font: 800 13px/1 inherit;
  padding: 9px 11px;
  border-radius: 10px;
  cursor: pointer;
  text-decoration: none;
}

.pd-links a:hover,
.pd-links button:hover {
  color: var(--pd-shell-ink);
  background: color-mix(in srgb, var(--pd-shell-ink) 8%, transparent);
}

.pd-links .is-active {
  color: var(--pd-shell-ink);
  background: color-mix(in srgb, var(--pd-shell-ink) 10%, transparent);
}

.pd-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-left: auto;
}

.pd-theme {
  display: inline-flex;
  border: 1px solid var(--pd-shell-line);
  border-radius: 999px;
  overflow: hidden;
}

.pd-theme button {
  appearance: none;
  border: 0;
  background: transparent;
  color: var(--pd-shell-dim);
  font: 900 12px/1 inherit;
  padding: 7px 9px;
  cursor: pointer;
}

.pd-theme button[aria-pressed="true"] {
  background: var(--pd-shell-ink);
  color: var(--pd-shell-panel);
}

.pd-cta {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 9px 14px;
  border-radius: 999px;
  background: var(--pd-shell-accent);
  color: var(--pd-shell-accent-ink);
  font: 1000 12.5px/1 inherit;
  letter-spacing: 0.01em;
  text-decoration: none;
  white-space: nowrap;
}

.pd-cta.is-ghost {
  background: transparent;
  color: var(--pd-shell-ink);
  border: 1px solid var(--pd-shell-line);
}

.pd-owner-link {
  display: none;
}

@media (min-width: 861px) {
  .pd-links { display: inline-flex; }
  .pd-owner-link { display: inline-flex; }
}

/* ---------- Mobile bottom tab bar ---------- */
.pd-tabbar {
  position: fixed;
  inset: auto 0 0 0;
  z-index: 2147482000;
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 2px;
  padding: 6px 6px calc(6px + env(safe-area-inset-bottom));
  background: var(--pd-shell-bg);
  border-top: 1px solid var(--pd-shell-line);
  backdrop-filter: saturate(1.4) blur(16px);
  -webkit-backdrop-filter: saturate(1.4) blur(16px);
}

@media (min-width: 861px) {
  .pd-tabbar { display: none; }
}

.pd-tab {
  appearance: none;
  border: 0;
  background: none;
  display: grid;
  justify-items: center;
  gap: 3px;
  padding: 7px 2px 5px;
  border-radius: 12px;
  color: var(--pd-shell-dim);
  font: 800 10px/1 inherit;
  letter-spacing: 0.02em;
  cursor: pointer;
}

.pd-tab svg { width: 21px; height: 21px; display: block; }
.pd-tab.is-active { color: var(--pd-shell-ink); }
.pd-tab.is-active svg { color: var(--pd-shell-accent); }

/* ---------- More sheet ---------- */

.pd-more-backdrop {
  position: fixed;
  inset: 0;
  z-index: 2147482100;
  background: rgba(4, 10, 19, 0.52);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.18s ease;
}

.pd-more-sheet {
  position: fixed;
  inset: auto 0 0 0;
  z-index: 2147482101;
  transform: translateY(102%);
  transition: transform 0.22s cubic-bezier(0.2, 0.9, 0.25, 1);
  background: var(--pd-shell-panel);
  color: var(--pd-shell-ink);
  border-radius: 22px 22px 0 0;
  border-top: 1px solid var(--pd-shell-line);
  box-shadow: var(--pd-shell-shadow);
  padding: 14px 16px calc(74px + env(safe-area-inset-bottom));
  max-height: 78vh;
  overflow: auto;
}

.pd-shell.is-more-open .pd-more-backdrop { opacity: 1; pointer-events: auto; }
.pd-shell.is-more-open .pd-more-sheet { transform: translateY(0); }

.pd-more-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 12px;
}

.pd-more-head strong { font: 1000 15px/1 inherit; }

.pd-more-head button {
  appearance: none;
  border: 1px solid var(--pd-shell-line);
  background: transparent;
  color: var(--pd-shell-dim);
  border-radius: 999px;
  padding: 6px 11px;
  font: 900 11px/1 inherit;
  cursor: pointer;
}

.pd-more-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
}

.pd-more-grid a,
.pd-more-grid button {
  appearance: none;
  border: 1px solid var(--pd-shell-line);
  background: color-mix(in srgb, var(--pd-shell-ink) 4%, transparent);
  border-radius: 14px;
  padding: 13px 10px;
  display: grid;
  gap: 6px;
  justify-items: start;
  color: var(--pd-shell-ink);
  text-decoration: none;
  font: 900 12px/1.15 inherit;
  cursor: pointer;
  text-align: left;
}

.pd-more-grid a small,
.pd-more-grid button small {
  color: var(--pd-shell-dim);
  font: 700 10px/1.2 inherit;
}

.pd-more-grid a > span,
.pd-more-grid button > span {
  display: grid;
  gap: 4px;
}

.pd-more-grid svg { width: 19px; height: 19px; color: var(--pd-shell-accent); }

/* ---------- Status pills (offline / update) ---------- */

.pd-status {
  position: fixed;
  left: 50%;
  bottom: calc(78px + env(safe-area-inset-bottom));
  transform: translateX(-50%);
  z-index: 2147482050;
  display: none;
  align-items: center;
  gap: 8px;
  padding: 9px 14px;
  border-radius: 999px;
  background: var(--pd-shell-panel);
  border: 1px solid var(--pd-shell-line);
  color: var(--pd-shell-ink);
  box-shadow: var(--pd-shell-shadow);
  font: 800 12px/1 inherit;
}

@media (min-width: 861px) {
  .pd-status { bottom: 18px; }
}

body.pd-shell.is-offline .pd-offline { display: inline-flex; }
body.pd-shell.has-update .pd-update { display: inline-flex; }

.pd-status button {
  appearance: none;
  border: 0;
  border-radius: 999px;
  background: var(--pd-shell-accent);
  color: var(--pd-shell-accent-ink);
  font: 1000 11px/1 inherit;
  padding: 6px 10px;
  cursor: pointer;
}

/* ---------- Owner Desk: hide the public tab bar for the private surface ---------- */

body.pd-shell.is-owner-surface { padding-bottom: 0; }
body.pd-shell.is-owner-surface .pd-tabbar,
body.pd-shell.is-owner-surface .pd-status,
body.pd-shell.is-owner-surface .pd-cta.is-join {
  display: none;
}
