/* Intaverna application shell: global controls, campaign navigation, and table tools. */

body.app-shell-active {
  --app-shell-bg: rgba(16, 15, 13, 0.92);
  --app-shell-panel: rgba(25, 23, 20, 0.78);
  --app-shell-panel-strong: rgba(36, 31, 25, 0.92);
  --app-shell-line: rgba(232, 214, 170, 0.18);
  --app-shell-line-strong: rgba(232, 214, 170, 0.34);
  --app-shell-text: #f1e4c8;
  --app-shell-muted: #bda879;
  --app-shell-accent: #ecc56b;
  --app-shell-danger: #d9a38e;
  --app-control-height: 32px;
  --app-control-radius: 5px;
  --app-banner-height: clamp(132px, 15vw, 225px);
  --app-header-height: calc(var(--app-banner-height) + 51px);
  --site-shell-width: min(1920px, calc(100vw - clamp(16px, 2vw, 32px)));
  --site-shell-max-width: none;
}

body.app-shell-active #wrapper {
  padding: 12px 0 24px;
}

body.app-shell-active #inner-wrapper {
  background: rgba(18, 16, 13, 0.88);
  border: 1px solid rgba(232, 214, 170, 0.12);
}

body[data-campaign-role="Player"][data-layout-mode="default"].app-shell-active {
  --site-shell-width: min(75vw, calc(100% - 32px));
  --site-shell-max-width: none;
}

.app-shell-header {
  position: sticky;
  top: 0;
  z-index: 60;
  isolation: isolate;
  overflow: hidden;
  border-bottom: 1px solid var(--app-shell-line);
  background: rgba(8, 7, 6, 0.96);
  backdrop-filter: blur(8px);
}

.app-brand-banner {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: var(--app-banner-height);
  padding: 0;
  background: #050403;
  text-decoration: none;
}

.app-brand-banner picture,
.app-brand-banner img {
  display: block;
  max-width: 100%;
}

.app-brand-banner img {
  width: auto;
  height: auto;
  max-height: var(--app-banner-height);
}

.app-topbar {
  display: grid;
  grid-template-columns: minmax(260px, 460px) auto minmax(0, 1fr);
  gap: 12px;
  align-items: center;
  min-height: 50px;
  padding: 7px 14px;
  border-top: 1px solid rgba(232, 214, 170, 0.12);
  background: rgba(10, 9, 8, 0.9);
}

.app-topbar-guest {
  grid-template-columns: minmax(0, 1fr);
}

.app-campaign-switcher {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  gap: 8px;
  align-items: center;
}

.app-shell-toggles {
  display: flex;
  gap: 6px;
  align-items: center;
}

.app-campaign-switcher label,
.app-panel-heading,
.app-widget-heading {
  color: var(--app-shell-muted);
  font-size: 0.75rem;
  font-weight: 800;
  letter-spacing: 0;
  text-transform: uppercase;
}

.app-campaign-switcher select {
  width: 100%;
  min-height: var(--app-control-height);
  border-radius: var(--app-control-radius);
  border: 1px solid var(--app-shell-line-strong);
  background: rgba(8, 8, 7, 0.86);
  color: var(--app-shell-text);
}

.app-icon-button,
.app-tool-action,
.app-widget-pin,
.app-nav-search button,
.app-tool-search button {
  min-height: var(--app-control-height);
  border-radius: var(--app-control-radius);
  border: 1px solid var(--app-shell-line);
  background: rgba(232, 214, 170, 0.08);
  color: var(--app-shell-text);
  cursor: pointer;
  font: inherit;
}

.app-icon-button:hover,
.app-tool-action:hover,
.app-widget-pin:hover,
.app-nav-search button:hover,
.app-tool-search button:hover {
  border-color: var(--app-shell-line-strong);
  background: rgba(232, 214, 170, 0.14);
  color: #fff8df;
}

.app-global-nav {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  justify-content: flex-end;
  align-items: center;
  min-width: 0;
}

.app-global-nav a {
  display: inline-flex;
  gap: 5px;
  align-items: center;
  min-height: 30px;
  padding: 0 9px;
  border-radius: var(--app-control-radius);
  border: 1px solid transparent;
  color: var(--app-shell-text);
  font-size: 0.84rem;
  line-height: 1;
  text-decoration: none;
  white-space: nowrap;
}

.app-global-nav a:hover {
  border-color: var(--app-shell-line);
  background: rgba(232, 214, 170, 0.08);
}

.app-global-nav .app-leave-link {
  color: var(--app-shell-danger);
}

.app-shell-grid {
  display: grid;
  grid-template-columns: clamp(280px, 18vw, 360px) minmax(0, 1fr) clamp(330px, 22vw, 420px);
  gap: 0;
  align-items: stretch;
}

.app-campaign-nav,
.app-tool-rail {
  position: sticky;
  top: var(--app-header-height, 60px);
  align-self: start;
  max-height: calc(100vh - var(--app-header-height, 60px));
  overflow: auto;
  padding: 14px;
  background: var(--app-shell-panel);
}

.app-campaign-nav {
  border-right: 1px solid var(--app-shell-line);
}

.app-tool-rail {
  border-left: 1px solid var(--app-shell-line);
}

.app-panel-heading,
.app-widget-heading {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
  margin-bottom: 10px;
}

.app-panel-heading .app-icon-button {
  display: none;
  min-width: 30px;
  min-height: 28px;
}

.app-current-campaign {
  display: grid;
  gap: 5px;
  margin-bottom: 12px;
  padding: 10px;
  border-radius: 6px;
  border: 1px solid var(--app-shell-line);
  background: var(--app-shell-panel-strong);
  color: var(--app-shell-text);
  text-decoration: none;
}

.app-current-campaign-art {
  display: block;
  width: 100%;
  aspect-ratio: 16 / 5;
  margin-bottom: 4px;
  border: 1px solid rgba(232, 214, 170, 0.16);
  background-position: center;
  background-size: cover;
}

.app-current-campaign strong {
  color: #fff1c2;
  font-family: 'Vollkorn', serif;
  font-size: 1.08rem;
  line-height: 1.15;
}

.app-current-campaign span,
.app-muted-text {
  color: var(--app-shell-muted);
  font-size: 0.82rem;
  line-height: 1.35;
}

.app-nav-search,
.app-tool-search {
  display: grid;
  grid-template-columns: minmax(0, 1fr) max-content;
  gap: 6px;
  align-items: stretch;
  margin: 0 0 12px;
}

.app-nav-search input,
.app-tool-search input {
  width: 100%;
  min-width: 0;
  height: var(--app-control-height);
  min-height: 0;
  padding: 0 9px;
  border-radius: var(--app-control-radius);
  border: 1px solid var(--app-shell-line);
  background: rgba(8, 8, 7, 0.72);
  color: var(--app-shell-text);
  box-sizing: border-box;
  font: inherit;
}

.app-nav-search button,
.app-tool-search button,
.app-chat-form button {
  height: var(--app-control-height);
  min-height: 0;
  padding: 0 10px;
  font-size: 0.78rem;
  font-weight: 800;
}

.app-semantic-nav {
  display: grid;
  gap: 4px;
}

.app-nav-tree,
.app-nav-tree ul {
  display: grid;
  gap: 2px;
  margin: 0;
  padding: 0;
  list-style: none;
}

.app-nav-tree ul {
  display: none;
  margin-left: 17px;
  padding-left: 8px;
  border-left: 1px solid rgba(232, 214, 170, 0.13);
}

.app-nav-node.is-expanded > ul {
  display: grid;
}

.app-nav-row {
  display: grid;
  grid-template-columns: 34px minmax(0, 1fr);
  gap: 2px;
  align-items: center;
}

.app-nav-expand,
.app-nav-spacer {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 34px;
  min-height: 34px;
}

.app-nav-expand {
  border: 0;
  background: transparent;
  color: var(--app-shell-muted);
  cursor: pointer;
  font-size: 0.78rem;
  line-height: 1;
}

.app-nav-expand:hover {
  color: #fff1c2;
}

.app-nav-node.is-expanded > .app-nav-row .app-nav-expand {
  color: #fff1c2;
}

.app-nav-item {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 8px;
  align-items: center;
  min-height: 34px;
  padding: 7px 8px;
  color: var(--app-shell-text);
  line-height: 1.2;
  text-decoration: none;
}

.app-nav-item span {
  overflow-wrap: anywhere;
}

.app-nav-item small {
  color: var(--app-shell-muted);
  font-size: 0.72rem;
}

.app-nav-item:hover,
.app-nav-item.is-current {
  background: rgba(232, 214, 170, 0.1);
  color: #fff8df;
}

.app-nav-node.is-ancestor > .app-nav-row .app-nav-item {
  background: rgba(232, 214, 170, 0.06);
}

.app-left-tools {
  margin-top: 14px;
  padding-top: 12px;
  border-top: 1px solid var(--app-shell-line);
}

.app-panel-subheading {
  margin-bottom: 7px;
  color: var(--app-shell-muted);
  font-size: 0.72rem;
  font-weight: 800;
  text-transform: uppercase;
}

.app-left-tool-grid {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.app-left-tool-grid a,
.app-left-tool-grid button {
  min-height: 28px;
  padding: 4px 8px;
  border-radius: var(--app-control-radius);
  border: 1px solid var(--app-shell-line);
  background: rgba(232, 214, 170, 0.07);
  color: #e6cf9a;
  cursor: pointer;
  font-size: 0.78rem;
  text-decoration: none;
}

.app-left-tool-grid a:hover,
.app-left-tool-grid button:hover {
  border-color: var(--app-shell-line-strong);
  color: #fff8df;
}

.app-nav-utility,
.app-tool-links {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 12px;
}

.app-nav-utility a,
.app-tool-links a {
  padding: 5px 7px;
  border-radius: var(--app-control-radius);
  border: 1px solid var(--app-shell-line);
  color: #d8c08b;
  font-size: 0.78rem;
  text-decoration: none;
}

.app-workspace {
  min-width: 0;
}

body.app-shell-active .app-workspace {
  width: auto;
  padding: clamp(18px, 1.6vw, 28px);
}

body.app-shell-active .site-search {
  display: none;
}

body.app-shell-active .vault-workspace-shell {
  grid-template-columns: minmax(0, 1fr);
}

body.app-shell-active .vault-workspace-shell > .vault-tree-panel {
  display: none;
}

body.app-shell-active .campaign-section-grid--index {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 8px;
  margin: 12px 0 22px;
}

body.app-shell-active .campaign-section-grid--index .campaign-section-card {
  border: 1px solid rgba(232, 214, 170, 0.12);
  background: rgba(10, 9, 8, 0.25);
}

body.app-shell-active .campaign-section-grid--index .campaign-section-card-main {
  min-height: 0;
  padding: 10px 12px;
}

body.app-shell-active .campaign-section-grid--index .campaign-section-title {
  font-size: 0.96rem;
}

body.app-shell-active .campaign-section-grid--index .campaign-section-summary {
  font-size: 0.78rem;
  line-height: 1.25;
}

body.app-shell-active .campaign-hero.player-campaign-hero {
  display: none;
}

.campaign-current-play {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 14px;
  align-items: center;
  margin: 0 0 16px;
  padding: 16px 18px;
  border: 1px solid rgba(236, 197, 107, 0.24);
  border-radius: 6px;
  background:
    linear-gradient(90deg, rgba(42, 34, 21, 0.6), rgba(10, 9, 8, 0.34)),
    rgba(10, 9, 8, 0.4);
}

.campaign-current-play h3 {
  margin: 0;
  border: 0;
  color: #f7e8c3;
  font-size: 1.12rem;
  text-align: left;
}

.campaign-current-play p:not(.eyebrow) {
  margin: 4px 0 0;
  color: #d9c79d;
  line-height: 1.35;
}

.campaign-current-play-actions {
  display: flex;
  justify-content: flex-end;
}

.campaign-current-play .campaign-active-map-link {
  position: static;
  min-height: 34px;
  padding: 6px 12px;
}

.app-tool-widget {
  display: flex;
  flex-direction: column;
  margin-bottom: 10px;
  padding: 10px;
  border-radius: 6px;
  border: 1px solid var(--app-shell-line);
  background: rgba(10, 9, 8, 0.46);
}

.app-tool-widget.is-unpinned {
  opacity: 0.62;
}

.app-tool-widget.is-unpinned > :not(.app-widget-heading) {
  display: none;
}

.app-tool-widget.is-collapsed > :not(.app-widget-heading):not(.app-widget-status) {
  display: none;
}

.app-widget-heading span {
  min-width: 0;
}

.app-widget-heading small {
  display: block;
  margin-top: 2px;
  color: var(--app-shell-muted);
  font-size: 0.68rem;
  font-weight: 700;
  text-transform: none;
}

.app-widget-controls {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 3px;
  align-items: center;
}

.app-tool-action {
  width: 100%;
}

.app-chat-widget:not(.is-unpinned):not(.is-collapsed) {
  min-height: clamp(390px, 46vh, 660px);
}

.app-chat-log {
  display: grid;
  align-content: start;
  gap: 6px;
  flex: 1 1 auto;
  min-height: 240px;
  max-height: min(54vh, 560px);
  overflow: auto;
  margin-bottom: 8px;
  padding: 8px 4px 8px 0;
  border-top: 1px solid rgba(232, 214, 170, 0.08);
  border-bottom: 1px solid rgba(232, 214, 170, 0.08);
}

.app-chat-message {
  display: grid;
  gap: 3px;
  padding: 7px;
  border: 1px solid rgba(232, 214, 170, 0.12);
  background: rgba(8, 8, 7, 0.34);
}

.app-chat-meta {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  color: var(--app-shell-muted);
  font-size: 0.7rem;
  line-height: 1.15;
}

.app-chat-meta strong {
  color: #fff1c2;
  overflow-wrap: anywhere;
}

.app-chat-message p {
  margin: 0;
  color: var(--app-shell-text);
  font-size: 0.82rem;
  line-height: 1.3;
  overflow-wrap: anywhere;
}

.app-chat-form {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 6px;
  align-items: stretch;
  margin-top: auto;
}

.app-chat-form input {
  min-width: 0;
  height: var(--app-control-height);
  min-height: 0;
  padding: 0 9px;
  border-radius: var(--app-control-radius);
  border: 1px solid var(--app-shell-line);
  background: rgba(8, 8, 7, 0.72);
  color: var(--app-shell-text);
  box-sizing: border-box;
  font: inherit;
}

.app-chat-clear {
  width: 100%;
  min-height: 26px;
  margin-top: 7px;
  border-radius: var(--app-control-radius);
  border: 1px solid rgba(217, 163, 142, 0.22);
  background: rgba(217, 163, 142, 0.08);
  color: var(--app-shell-danger);
  cursor: pointer;
}

.app-chat-clear:hover {
  border-color: rgba(217, 163, 142, 0.44);
  background: rgba(217, 163, 142, 0.14);
}

.app-widget-pin {
  min-height: 22px;
  padding: 0 5px;
  font-size: 0.68rem;
  line-height: 1;
}

body[data-layout-mode="dm-wide"].app-shell-active .app-shell-grid,
body[data-layout-mode="campaign-prep"].app-shell-active .app-shell-grid,
body[data-campaign-role="Player"][data-layout-mode="default"].app-shell-active .app-shell-grid {
  grid-template-columns: minmax(0, 1fr);
}

body[data-layout-mode="dm-wide"].app-shell-active,
body[data-layout-mode="campaign-prep"].app-shell-active {
  --app-banner-height: 81px;
  --app-header-height: calc(var(--app-banner-height) + 49px);
}

body[data-layout-mode="dm-wide"].app-shell-active .app-brand-banner,
body[data-layout-mode="campaign-prep"].app-shell-active .app-brand-banner {
  padding-top: 4px;
  padding-bottom: 4px;
}

body[data-layout-mode="dm-wide"].app-shell-active .app-brand-banner img,
body[data-layout-mode="campaign-prep"].app-shell-active .app-brand-banner img {
  width: auto;
  max-height: var(--app-banner-height);
}

body[data-layout-mode="dm-wide"].app-shell-active .app-topbar,
body[data-layout-mode="campaign-prep"].app-shell-active .app-topbar {
  min-height: 48px;
  padding-top: 6px;
  padding-bottom: 6px;
}

body[data-layout-mode="dm-wide"].app-shell-active .app-campaign-nav,
body[data-layout-mode="dm-wide"].app-shell-active .app-tool-rail,
body[data-layout-mode="campaign-prep"].app-shell-active .app-campaign-nav,
body[data-layout-mode="campaign-prep"].app-shell-active .app-tool-rail,
body[data-campaign-role="Player"][data-layout-mode="default"].app-shell-active .app-campaign-nav,
body[data-campaign-role="Player"][data-layout-mode="default"].app-shell-active .app-tool-rail {
  position: fixed;
  top: var(--app-header-height, 96px);
  bottom: 0;
  z-index: 70;
  width: min(360px, calc(100vw - 34px));
  max-height: none;
  transform: translateX(-105%);
  transition: transform 160ms ease;
}

body[data-layout-mode="dm-wide"].app-shell-active .app-tool-rail,
body[data-layout-mode="campaign-prep"].app-shell-active .app-tool-rail,
body[data-campaign-role="Player"][data-layout-mode="default"].app-shell-active .app-tool-rail {
  right: 0;
  width: min(420px, calc(100vw - 34px));
  transform: translateX(105%);
}

body[data-layout-mode="dm-wide"].app-shell-active.shell-nav-open .app-campaign-nav,
body[data-layout-mode="campaign-prep"].app-shell-active.shell-nav-open .app-campaign-nav,
body[data-campaign-role="Player"][data-layout-mode="default"].app-shell-active.shell-nav-open .app-campaign-nav,
body[data-layout-mode="dm-wide"].app-shell-active.shell-tools-open .app-tool-rail,
body[data-layout-mode="campaign-prep"].app-shell-active.shell-tools-open .app-tool-rail,
body[data-campaign-role="Player"][data-layout-mode="default"].app-shell-active.shell-tools-open .app-tool-rail {
  transform: translateX(0);
}

body[data-layout-mode="dm-wide"].app-shell-active .app-panel-heading .app-icon-button,
body[data-layout-mode="campaign-prep"].app-shell-active .app-panel-heading .app-icon-button,
body[data-campaign-role="Player"][data-layout-mode="default"].app-shell-active .app-panel-heading .app-icon-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

body[data-layout-mode="dm-wide"].app-shell-active .app-workspace,
body[data-layout-mode="campaign-prep"].app-shell-active .app-workspace,
body[data-campaign-role="Player"][data-layout-mode="default"].app-shell-active .app-workspace {
  grid-column: 1;
}

@media screen and (max-width: 1120px) {
  body.app-shell-active {
    --app-banner-height: clamp(114px, 18vw, 177px);
    --app-header-height: calc(var(--app-banner-height) + 92px);
  }

  .app-topbar {
    grid-template-columns: minmax(220px, 1fr) auto;
  }

  .app-global-nav {
    grid-column: 1 / -1;
    justify-content: flex-start;
  }

  .app-shell-grid {
    grid-template-columns: minmax(260px, 32vw) minmax(0, 1fr);
  }

  .app-tool-rail {
    position: fixed;
    top: var(--app-header-height, 160px);
    right: 0;
    bottom: 0;
    z-index: 70;
    width: min(400px, calc(100vw - 34px));
    max-height: none;
    transform: translateX(105%);
    transition: transform 160ms ease;
  }

  body.shell-tools-open .app-tool-rail {
    transform: translateX(0);
  }
}

@media screen and (max-width: 760px) {
  body.app-shell-active {
    --site-shell-width: calc(100% - 12px);
    --app-banner-height: clamp(90px, 27vw, 144px);
    --app-header-height: calc(var(--app-banner-height) + 146px);
  }

  .app-brand-banner {
    padding: 0;
  }

  .app-topbar {
    grid-template-columns: minmax(0, 1fr) auto auto;
    gap: 8px;
  }

  .app-campaign-switcher,
  .app-shell-toggles,
  .app-global-nav {
    grid-column: 1 / -1;
  }

  .app-shell-toggles {
    justify-content: flex-start;
  }

  .app-global-nav {
    overflow-x: auto;
    flex-wrap: nowrap;
    padding-bottom: 2px;
  }

  .app-shell-grid {
    grid-template-columns: minmax(0, 1fr);
  }

  .app-campaign-nav {
    position: fixed;
    top: var(--app-header-height, 174px);
    bottom: 0;
    left: 0;
    z-index: 70;
    width: min(340px, calc(100vw - 34px));
    max-height: none;
    transform: translateX(-105%);
    transition: transform 160ms ease;
  }

  body.shell-nav-open .app-campaign-nav {
    transform: translateX(0);
  }

  .app-panel-heading .app-icon-button {
    display: inline-flex;
    align-items: center;
    justify-content: center;
  }

  body.app-shell-active .app-workspace {
    padding: 14px 10px;
  }
}
