/* 页面返回、尾部入口与弹窗导航；在原有样式之后加载。 */
:root {
  --context-navigation-height: 52px;
}

html {
  overflow-anchor: none;
  scroll-padding-top: calc(var(--app-header-height, 66px) + var(--context-nav-height, 0px) + 12px);
}

.context-navigation {
  position: sticky;
  top: var(--app-header-height, 66px);
  z-index: 6;
  display: flex;
  align-items: center;
  gap: 12px;
  min-height: var(--context-navigation-height);
  min-width: 0;
  max-width: 100%;
  padding: 4px 26px;
  background: var(--surface, #fff);
  border-bottom: 1px solid var(--line, #e7e1db);
  box-shadow: 0 3px 9px #40201008;
}

.nav-back {
  flex: 0 0 auto;
  min-width: 44px;
  min-height: 44px;
  padding: 8px 12px;
  border-radius: var(--radius-control, 8px);
  background: var(--brand-red-soft, #fff0e9);
  color: var(--brand-red, #c9341b);
  font-weight: 700;
  white-space: nowrap;
}

.context-title {
  flex: 1 1 0;
  min-width: 0;
  overflow: hidden;
  color: var(--ink-strong, #263238);
  font-size: 14px;
  font-weight: 700;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.context-title > * {
  display: block;
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.context-title small {
  color: var(--ink-muted, #788497);
  font-size: 11px;
  font-weight: 400;
}

.sidebar {
  top: calc(var(--app-header-height, 66px) + var(--context-nav-height, 0px));
  height: calc(100vh - var(--app-header-height, 66px) - var(--context-nav-height, 0px));
  height: calc(100dvh - var(--app-header-height, 66px) - var(--context-nav-height, 0px));
  min-height: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
}

.footer-navigation {
  min-width: 0;
  max-width: 100%;
  margin-top: 24px;
  padding: 18px 0 calc(18px + env(safe-area-inset-bottom, 0px));
  border-top: 1px solid var(--line, #e7e1db);
}

.footer-navigation nav {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 8px;
  min-width: 0;
}

.footer-navigation nav button {
  min-width: 0;
  min-height: 44px;
  padding: 10px 12px;
  border: 1px solid var(--line, #e7e1db);
  border-radius: var(--radius-control, 8px);
  background: var(--surface, #fff);
  color: var(--ink, #405066);
  overflow-wrap: anywhere;
}

.footer-navigation nav button.active {
  border-color: var(--brand-red, #c9341b);
  background: var(--brand-red-soft, #fff0e9);
  color: var(--brand-red, #c9341b);
  font-weight: 700;
}

.footer-return {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 8px;
  min-width: 0;
  margin-bottom: 12px;
}

.footer-return button {
  min-width: 44px;
  min-height: 44px;
  max-width: 100%;
  overflow-wrap: anywhere;
}

.scroll-top-control {
  position: fixed;
  right: calc(20px + env(safe-area-inset-right, 0px));
  bottom: max(var(--modal-top-control-bottom, 20px), calc(20px + env(safe-area-inset-bottom, 0px)));
  z-index: 300;
  min-width: 44px;
  min-height: 44px;
  max-width: calc(100vw - 40px);
  padding: 10px 12px;
  border: 1px solid var(--brand-red, #c9341b);
  border-radius: var(--radius-control, 8px);
  background: var(--surface, #fff);
  color: var(--brand-red, #c9341b);
  font-size: 12px;
  font-weight: 700;
  line-height: 1.3;
  white-space: nowrap;
  box-shadow: 0 4px 18px #40201022;
}

.scroll-top-control:hover,
.nav-back:hover {
  background: var(--brand-red-soft, #fff0e9);
  color: var(--brand-red-dark, #a92b16);
}

.scroll-top-control:focus-visible,
.nav-back:focus-visible,
.footer-navigation button:focus-visible {
  outline: 2px solid var(--brand-red, #c9341b);
  outline-offset: 2px;
}

body:has(.upload-progress-panel) .scroll-top-control {
  bottom: max(var(--modal-top-control-bottom, 20px), calc(min(45vh, 300px) + 36px + env(safe-area-inset-bottom, 0px)));
}

body:has(.modal-backdrop) .scroll-top-control {
  bottom: max(var(--modal-top-control-bottom, 20px), calc(20px + env(safe-area-inset-bottom, 0px)));
}

body:has(.modal-backdrop):has(.upload-progress-panel) .scroll-top-control {
  bottom: max(var(--modal-top-control-bottom, 20px), calc(min(45vh, 300px) + 36px + env(safe-area-inset-bottom, 0px)));
}

.upload-progress-panel {
  max-height: min(45vh, 300px);
  bottom: calc(20px + env(safe-area-inset-bottom, 0px));
}

/* 标题和尾部操作留在弹窗中；正文仍沿用现有滚动区域。 */
.modal {
  --navigation-modal-padding: 22px;
  padding: var(--navigation-modal-padding);
}

.modal > .panel-head {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  position: sticky;
  top: calc(-1 * var(--navigation-modal-padding));
  z-index: 4;
  align-items: center;
  margin: calc(-1 * var(--navigation-modal-padding)) calc(-1 * var(--navigation-modal-padding)) 14px;
  padding: 12px var(--navigation-modal-padding);
  background: var(--surface, #fff);
  border-bottom: 1px solid var(--line, #e7e1db);
}

.modal > .panel-head h2 {
  min-width: 0;
  margin: 0;
  font-size: 18px;
  line-height: 1.4;
  overflow-wrap: anywhere;
}

.file-preview-modal > .panel-head h2 {
  display: -webkit-box;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 2;
  overflow: hidden;
}

.modal > .panel-head > .plain {
  flex: 0 0 auto;
  min-width: 64px;
  min-height: 44px;
  padding: 8px 10px;
  font-size: 14px;
  line-height: 1.3;
}

.modal .modal-actions,
.publication-modal > .row-actions,
.file-preview-modal .preview-navigation {
  position: sticky;
  bottom: calc(-1 * var(--navigation-modal-padding));
  z-index: 4;
  display: flex;
  justify-content: flex-end;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px;
  margin: 18px calc(-1 * var(--navigation-modal-padding)) calc(-1 * var(--navigation-modal-padding));
  padding: 12px var(--navigation-modal-padding) var(--navigation-modal-padding);
  background: var(--surface, #fff);
  border-top: 1px solid var(--line, #e7e1db);
}

.modal .modal-actions > button,
.publication-modal > .row-actions > button,
.file-preview-modal .preview-navigation > button {
  min-height: 44px;
  max-width: 100%;
  overflow-wrap: anywhere;
}

.file-preview-overlay { z-index: 200; }
.ask-overlay { z-index: 220; }

/* 员工窗口上打开文件或确认时，保留新窗口的合法入口。 */
body:has(.employee-overlay) .modal-backdrop.file-preview-overlay,
body:has(.employee-overlay) .modal-backdrop.ask-overlay {
  display: grid;
}

@media (max-width: 680px) {
  :root { --context-navigation-height: 48px; }

  .context-navigation {
    gap: 8px;
    padding: 2px 12px;
  }

  .context-title { font-size: 13px; }
  .nav-back { padding: 8px 10px; font-size: 12px; }

  .sidebar {
    position: static;
    top: auto;
    height: auto;
    min-height: 0;
    overflow: visible;
  }

  .footer-navigation {
    margin-top: 18px;
    padding-top: 14px;
  }

  .footer-navigation nav { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .footer-navigation nav button { font-size: 12px; padding: 8px; }

  .scroll-top-control {
    right: calc(12px + env(safe-area-inset-right, 0px));
    bottom: max(var(--modal-top-control-bottom, 12px), calc(12px + env(safe-area-inset-bottom, 0px)));
    max-width: calc(100vw - 24px);
  }

  .upload-progress-panel { bottom: calc(12px + env(safe-area-inset-bottom, 0px)); }

  .modal {
    --navigation-modal-padding: 15px;
    padding: var(--navigation-modal-padding);
  }

  .modal > .panel-head { margin-bottom: 12px; padding-top: 8px; padding-bottom: 8px; }

  .modal .modal-actions,
  .publication-modal > .row-actions,
  .file-preview-modal .preview-navigation {
    margin-top: 14px;
    padding-bottom: calc(var(--navigation-modal-padding) + env(safe-area-inset-bottom, 0px));
  }
}

@media print {
  .context-navigation,
  .sidebar,
  .scroll-top-control,
  .footer-navigation { display: none !important; }

  .workspace { display: block; }

  .modal > .panel-head,
  .modal .modal-actions,
  .publication-modal > .row-actions,
  .file-preview-modal .preview-navigation {
    position: static;
    top: auto;
    bottom: auto;
    margin-left: 0;
    margin-right: 0;
    margin-bottom: 0;
    padding-left: 0;
    padding-right: 0;
    box-shadow: none;
  }
}
