:root {
  --shell-bg: #f5f7fb;
  --sidebar-bg: linear-gradient(180deg, #0f172a 0%, #16233d 48%, #15243a 100%);
  --sidebar-line: rgba(148, 163, 184, 0.16);
  --sidebar-text: #e5eefc;
  --sidebar-sub: rgba(203, 213, 225, 0.72);
  --sidebar-active: linear-gradient(135deg, #3b82f6 0%, #5b8dff 100%);
  --panel-bg: #ffffff;
  --panel-line: #e8edf6;
  --panel-shadow: 0 10px 30px rgba(15, 23, 42, 0.06);
  --text: #1f2937;
  --sub: #6b7280;
  --primary: #3b82f6;
}

* {
  box-sizing: border-box;
}

html,
body {
  height: 100%;
  overflow: hidden;
}

body {
  margin: 0;
  background: var(--shell-bg);
  color: var(--text);
  font-family: "PingFang SC", "Noto Sans SC", "Microsoft YaHei", sans-serif;
  overscroll-behavior: none;
  /* Disables double-tap-to-zoom; pinch zoom is capped by the viewport meta,
     which iOS honors in standalone (apple-mobile-web-app-capable) mode. */
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}

body.auth-locked .app-shell {
  visibility: hidden;
  pointer-events: none;
}

body.auth-pending .login-overlay {
  visibility: hidden;
  opacity: 0;
}

body.auth-pending .menu,
body.auth-pending .sidebar-footer {
  visibility: hidden;
}

.menu[aria-busy="true"] {
  visibility: hidden;
}

.app-shell {
  display: grid;
  grid-template-columns: 248px minmax(0, 1fr);
  height: 100vh;
  overflow: hidden;
  transition: grid-template-columns 0.22s ease;
}

body.sidebar-collapsed .app-shell {
  grid-template-columns: 88px minmax(0, 1fr);
}

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

body.clean-access-view .sidebar,
body.clean-access-view .mobile-sidebar-backdrop,
body.clean-access-view .content-toolbar,
body.clean-access-view .login-overlay,
body.clean-access-view .confirm-overlay {
  display: none !important;
}

body.clean-access-view .content-shell {
  grid-template-rows: 1fr;
  gap: 0;
  padding: 0;
  overflow: hidden;
  background: #fff;
}

body.clean-access-view .content-frame-wrap {
  border: 0;
  border-radius: 0;
  box-shadow: none;
}

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

body.content-fullscreen .sidebar,
body.content-fullscreen .mobile-sidebar-backdrop,
body.content-fullscreen .content-toolbar {
  display: none !important;
}

body.content-fullscreen .content-shell {
  grid-template-rows: 1fr;
  gap: 0;
  height: 100vh;
  padding: 0;
  overflow: hidden;
  background: #fff;
}

body.content-fullscreen .content-frame-wrap {
  border: 0;
  border-radius: 0;
  box-shadow: none;
}

.sidebar {
  display: grid;
  grid-template-rows: auto 1fr auto;
  gap: 20px;
  padding: 22px 14px 14px;
  background: var(--sidebar-bg);
  color: var(--sidebar-text);
  min-height: 0;
  overflow: hidden;
  overflow-x: hidden;
  border-right: 1px solid rgba(148, 163, 184, 0.12);
}

.mobile-sidebar-backdrop {
  display: none;
}

.sidebar-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
}

.brand-mark {
  display: grid;
  place-items: center;
  width: 40px;
  height: 40px;
  border-radius: 14px;
  background: linear-gradient(135deg, rgba(56, 189, 248, 0.24) 0%, rgba(59, 130, 246, 0.28) 100%);
  border: 1px solid rgba(125, 211, 252, 0.24);
  font-size: 22px;
  box-shadow: 0 10px 26px rgba(10, 16, 32, 0.24);
  overflow: hidden;
}

.brand-mark img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.brand-mark span {
  font-size: 22px;
}

.brand-text {
  display: grid;
  gap: 2px;
  min-width: 0;
}

.brand-text strong {
  font-size: 16px;
  letter-spacing: 0.2px;
}

.brand-text span {
  color: var(--sidebar-sub);
  font-size: 12px;
}

.menu {
  display: grid;
  align-content: start;
  gap: 10px;
  min-height: 0;
  overflow-y: auto;
  overflow-x: hidden;
  padding-right: 2px;
  scrollbar-width: thin;
  scrollbar-color: rgba(148, 163, 184, 0.35) transparent;
}

.menu::-webkit-scrollbar {
  width: 6px;
}

.menu::-webkit-scrollbar-thumb {
  border-radius: 999px;
  background: rgba(148, 163, 184, 0.28);
}

.menu::-webkit-scrollbar-track {
  background: transparent;
}

.menu-group {
  display: grid;
  gap: 10px;
}

.menu-group-toggle {
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: 100%;
  border: 0;
  padding: 10px 12px;
  background: transparent;
  color: #f8fbff;
  font: inherit;
  font-size: 16px;
  font-weight: 500;
  text-align: left;
  cursor: pointer;
}

.menu-group-arrow {
  display: grid;
  place-items: center;
  width: 24px;
  height: 24px;
  margin-left: auto;
  color: var(--sidebar-sub);
  font-size: 0;
  line-height: 1;
}

.menu-group-arrow::before {
  content: "›";
  font-size: 18px;
  transform: translateY(-1px);
}

.menu-group-toggle.expanded .menu-group-arrow::before {
  content: "⌄";
  transform: translateY(-2px);
}

.submenu {
  display: grid;
  gap: 8px;
  padding-left: 10px;
}

.submenu.collapsed {
  display: none;
}

.menu-group.is-hidden,
.menu-item.is-hidden {
  display: none !important;
}

.menu-item {
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  border: 0;
  border-radius: 14px;
  padding: 14px 16px;
  background: transparent;
  color: #dbe6f7;
  font: inherit;
  text-align: left;
  cursor: pointer;
  transition: background 0.2s ease, transform 0.2s ease;
}

.submenu .menu-item {
  padding-left: 18px;
  font-size: 15px;
  font-weight: 400;
}

.menu-item:hover {
  background: rgba(148, 163, 184, 0.1);
}

.menu-item.active {
  background: var(--sidebar-active);
  color: #ffffff;
  box-shadow:
    inset 0 0 0 1px rgba(255, 255, 255, 0.08),
    0 10px 24px rgba(59, 130, 246, 0.28);
}

.menu-section-label {
  padding: 4px 12px 0;
  color: var(--sidebar-sub);
  font-size: 12px;
}

.menu-dot {
  width: 6px;
  height: 6px;
  border-radius: 999px;
  background: currentColor;
  opacity: 0.85;
  flex: none;
}

.shell-main {
  display: grid;
  grid-template-rows: 1fr;
  min-width: 0;
  min-height: 0;
  overflow: hidden;
}

.sidebar-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex: none;
  padding-top: 14px;
  border-top: 1px solid var(--sidebar-line);
}

.user-panel {
  display: grid;
  gap: 4px;
  align-content: center;
}

.user-name {
  color: #f8fbff;
  font-size: 14px;
  font-weight: 600;
}

.user-role {
  color: var(--sidebar-sub);
  font-size: 12px;
}

.sidebar-btn {
  margin-left: auto;
  border: 0;
  border-radius: 999px;
  padding: 6px 12px;
  background: rgba(148, 163, 184, 0.1);
  color: #cdd8ea;
  font: inherit;
  font-size: 13px;
  cursor: pointer;
  transition: background 0.2s ease, color 0.2s ease;
}

.sidebar-btn:hover {
  background: rgba(148, 163, 184, 0.18);
  color: #ffffff;
}

body.sidebar-collapsed .sidebar {
  padding-left: 10px;
  padding-right: 10px;
}

body.sidebar-collapsed .brand-text,
body.sidebar-collapsed .menu-group-toggle > span:first-child,
body.sidebar-collapsed .submenu .menu-item > span:last-child,
body.sidebar-collapsed .user-panel {
  display: none;
}

body.sidebar-collapsed .brand {
  justify-content: center;
  width: 100%;
}

body.sidebar-collapsed .sidebar-header {
  display: grid;
  grid-template-columns: 1fr;
  justify-items: center;
  align-items: center;
  gap: 12px;
  width: 100%;
}

body.sidebar-collapsed .brand-mark {
  justify-self: center;
}

body.sidebar-collapsed .menu {
  gap: 14px;
}

body.sidebar-collapsed .menu-group {
  justify-items: center;
}

body.sidebar-collapsed .menu-group-toggle {
  justify-content: center;
  width: 48px;
  padding: 8px 0 4px;
}

body.sidebar-collapsed .menu-group-arrow {
  margin-left: 0;
}

body.sidebar-collapsed .submenu {
  padding-left: 0;
  justify-items: center;
}

body.sidebar-collapsed .menu-item {
  justify-content: center;
  width: 48px;
  min-height: 48px;
  padding: 0;
  border-radius: 16px;
}

body.sidebar-collapsed .menu-dot {
  width: 6px;
  height: 6px;
}

body.sidebar-collapsed .sidebar-footer {
  justify-content: center;
  padding-top: 12px;
}

body.sidebar-collapsed .sidebar-btn {
  margin-left: 0;
  width: 48px;
  height: 48px;
  padding: 0;
  border-radius: 16px;
  font-size: 0;
  position: relative;
}

body.sidebar-collapsed .sidebar-btn::before {
  content: "⎋";
  font-size: 18px;
}

.content-shell {
  display: grid;
  grid-template-rows: auto 1fr;
  gap: 8px;
  padding: 8px 10px 10px;
  min-height: 0;
  overflow-y: auto;
  overflow-x: hidden;
  overscroll-behavior: none;
  background:
    linear-gradient(180deg, rgba(234, 241, 255, 0.8) 0%, rgba(245, 248, 255, 0.85) 220px, #f7f9fd 100%);
}

.content-toolbar {
  display: flex;
  align-items: center;
  justify-content: flex-start;
  padding: 6px 8px;
  border: 1px solid #edf2fb;
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.98);
  box-shadow: 0 10px 24px rgba(29, 60, 114, 0.06);
}

.toolbar-actions {
  display: flex;
  gap: 6px;
}

.content-fullscreen-btn {
  margin-left: auto;
}

.icon-btn {
  min-width: 34px;
  height: 34px;
  border: 1px solid #dbe4f3;
  border-radius: 10px;
  background: #fff;
  color: #475569;
  font-size: 17px;
  line-height: 1;
  cursor: pointer;
  box-shadow: 0 4px 12px rgba(39, 61, 109, 0.05);
}

.content-frame-wrap {
  min-height: 0;
  border: 1px solid #e7eef9;
  border-radius: 8px;
  overflow: hidden;
  background: #fff;
  box-shadow: 0 20px 44px rgba(25, 58, 119, 0.08);
}

.content-frame {
  width: 100%;
  height: 100%;
  border: 0;
  background: #fff;
  display: block;
}

.fullscreen-exit-btn {
  position: fixed;
  top: max(15px, env(safe-area-inset-top));
  right: max(19px, env(safe-area-inset-right));
  z-index: 50;
  display: none;
  align-items: center;
  justify-content: center;
  width: 34px;
  height: 34px;
  border: 1px solid rgba(148, 163, 184, 0.16);
  border-radius: 8px;
  padding: 0;
  background: rgba(255, 255, 255, 0.3);
  color: rgba(71, 85, 105, 0.42);
  font: inherit;
  font-size: 17px;
  line-height: 1;
  cursor: pointer;
  backdrop-filter: blur(8px);
}

body.content-fullscreen .fullscreen-exit-btn {
  visibility: hidden !important;
  opacity: 0 !important;
  pointer-events: none !important;
  display: none;
  transition: opacity 0.16s ease, background 0.16s ease, color 0.16s ease, border-color 0.16s ease;
}

body.content-fullscreen .content-fullscreen-btn {
  visibility: hidden !important;
  opacity: 0 !important;
  pointer-events: none !important;
  display: none !important;
}

@media (hover: hover) and (pointer: fine) {
  body.content-fullscreen .shell-main:hover .fullscreen-exit-btn {
    visibility: visible !important;
    display: inline-flex !important;
    opacity: 1 !important;
    pointer-events: auto !important;
  }
}

body.content-fullscreen .fullscreen-exit-btn:hover,
body.content-fullscreen .fullscreen-exit-btn:focus-visible {
  opacity: 1;
  pointer-events: auto;
}

.hidden {
  display: none !important;
}

.login-overlay {
  position: fixed;
  inset: 0;
  z-index: 80;
  display: grid;
  place-items: center;
  padding: 24px;
  background:
    linear-gradient(135deg, rgba(11, 18, 32, 0.96) 0%, rgba(15, 23, 42, 0.94) 48%, rgba(17, 34, 64, 0.95) 100%),
    radial-gradient(circle at 20% 20%, rgba(56, 189, 248, 0.18) 0, transparent 28%),
    radial-gradient(circle at 82% 24%, rgba(59, 130, 246, 0.18) 0, transparent 24%),
    radial-gradient(circle at 78% 82%, rgba(139, 92, 246, 0.16) 0, transparent 26%);
  overflow: hidden;
}

.login-overlay::before {
  content: "";
  position: absolute;
  inset: 0;
  background-image:
    linear-gradient(rgba(148, 163, 184, 0.08) 1px, transparent 1px),
    linear-gradient(90deg, rgba(148, 163, 184, 0.08) 1px, transparent 1px);
  background-size: 34px 34px;
  mask-image: linear-gradient(180deg, rgba(255,255,255,0.8), rgba(255,255,255,0.18));
}

.login-card {
  position: relative;
  width: min(440px, 100%);
  display: grid;
  gap: 16px;
  padding: 28px;
  border-radius: 24px;
  border: 1px solid rgba(191, 219, 254, 0.28);
  background: rgba(255, 255, 255, 0.96);
  box-shadow:
    0 30px 80px rgba(15, 23, 42, 0.4),
    inset 0 1px 0 rgba(255, 255, 255, 0.7);
}

.login-close-btn {
  position: absolute;
  top: 16px;
  right: 16px;
  display: grid;
  place-items: center;
  width: 34px;
  height: 34px;
  border: 1px solid rgba(148, 163, 184, 0.22);
  border-radius: 12px;
  background: rgba(241, 245, 249, 0.82);
  color: #64748b;
  font-size: 22px;
  line-height: 1;
  cursor: pointer;
}

.login-close-btn:hover {
  background: #eaf1fb;
  color: #1e3a8a;
}

.login-card h1 {
  margin: 0;
  font-size: 32px;
  letter-spacing: 1px;
}

.login-field {
  display: grid;
  gap: 8px;
  font-size: 14px;
  color: #334155;
  font-weight: 600;
}

.login-field input {
  width: 100%;
  min-height: 54px;
  border: 1px solid #dbe7f5;
  border-radius: 16px;
  padding: 0 16px;
  background: rgba(248, 250, 255, 0.96);
  font: inherit;
}

.login-message {
  min-height: 20px;
  color: #dc2626;
  font-size: 13px;
}

.login-submit {
  border: 0;
  border-radius: 16px;
  min-height: 52px;
  padding: 0 16px;
  background: linear-gradient(135deg, #3b82f6 0%, #4f83ff 100%);
  color: #fff;
  font: inherit;
  font-size: 16px;
  font-weight: 700;
  cursor: pointer;
  box-shadow: 0 16px 30px rgba(59, 130, 246, 0.28);
}

.confirm-overlay {
  position: fixed;
  inset: 0;
  z-index: 85;
  display: grid;
  place-items: center;
  padding: 20px;
  background: rgba(15, 23, 42, 0.38);
}

.confirm-card {
  width: min(360px, 100%);
  display: grid;
  gap: 12px;
  padding: 22px;
  border-radius: 20px;
  background: rgba(255, 255, 255, 0.98);
  box-shadow: 0 22px 60px rgba(15, 23, 42, 0.22);
}

.confirm-card h2 {
  margin: 0;
  font-size: 20px;
}

.confirm-card p {
  margin: 0;
  color: var(--sub);
  line-height: 1.6;
}

.confirm-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  padding-top: 6px;
}

.confirm-btn {
  border: 0;
  border-radius: 12px;
  min-height: 40px;
  padding: 0 16px;
  font: inherit;
  font-weight: 700;
  cursor: pointer;
}

.confirm-btn-light {
  background: #eef2f8;
  color: #475569;
}

.confirm-btn-primary {
  background: #ef4444;
  color: #fff;
}

@media (max-width: 1100px) {
  .app-shell {
    grid-template-columns: 220px minmax(0, 1fr);
  }

  body.sidebar-collapsed .app-shell {
    grid-template-columns: 84px minmax(0, 1fr);
  }
}

@media (max-width: 860px) {
  html,
  body {
    height: 100dvh;
    overflow: hidden;
  }

  .app-shell {
    grid-template-columns: 1fr;
    height: 100dvh;
  }

  body.sidebar-collapsed .app-shell {
    grid-template-columns: 1fr;
  }

  .sidebar {
    position: fixed;
    inset: 0 auto 0 0;
    z-index: 40;
    width: min(82vw, 320px);
    height: 100dvh;
    grid-template-rows: auto 1fr auto;
    min-height: 0;
    padding: 18px 12px 12px;
    overflow: hidden;
    transform: translateX(-105%);
    transition: transform 0.22s ease;
    box-shadow: 28px 0 70px rgba(15, 23, 42, 0.28);
  }

  body.sidebar-collapsed .sidebar {
    padding: 18px 12px 12px;
  }

  body.sidebar-collapsed .brand-text,
  body.sidebar-collapsed .menu-group-toggle > span:first-child,
  body.sidebar-collapsed .submenu .menu-item > span:last-child,
  body.sidebar-collapsed .user-panel {
    display: grid;
  }

  body.sidebar-collapsed .menu-group-toggle > span:first-child,
  body.sidebar-collapsed .submenu .menu-item > span:last-child {
    display: inline;
  }

  body.sidebar-collapsed .brand {
    justify-content: flex-start;
    width: auto;
  }

  body.sidebar-collapsed .sidebar-header {
    display: flex;
    grid-template-columns: none;
    justify-items: initial;
    align-items: center;
    gap: 10px;
    width: auto;
  }

  body.sidebar-collapsed .brand-mark {
    justify-self: auto;
  }

  body.sidebar-collapsed .menu {
    gap: 10px;
  }

  body.sidebar-collapsed .menu-group {
    justify-items: stretch;
  }

  body.sidebar-collapsed .menu-group-toggle {
    justify-content: space-between;
    width: 100%;
    padding: 10px 12px;
  }

  body.sidebar-collapsed .menu-group-arrow {
    margin-left: auto;
  }

  body.sidebar-collapsed .submenu {
    padding-left: 10px;
    justify-items: stretch;
  }

  body.sidebar-collapsed .menu-item {
    justify-content: flex-start;
    width: 100%;
    min-height: auto;
    padding: 14px 16px;
    border-radius: 14px;
  }

  body.sidebar-collapsed .sidebar-footer {
    justify-content: space-between;
    padding-top: 14px;
  }

  body.sidebar-collapsed .sidebar-btn {
    margin-left: auto;
    width: auto;
    height: auto;
    padding: 6px 12px;
    border-radius: 999px;
    font-size: 13px;
  }

  body.sidebar-collapsed .sidebar-btn::before {
    content: none;
  }

  body.mobile-sidebar-open .sidebar {
    transform: translateX(0);
  }

  .mobile-sidebar-backdrop {
    position: fixed;
    inset: 0;
    z-index: 35;
    background: rgba(15, 23, 42, 0.38);
    backdrop-filter: blur(2px);
  }

  body.mobile-sidebar-open .mobile-sidebar-backdrop {
    display: block;
  }

  .shell-main {
    min-height: 0;
    height: 100dvh;
  }

  .content-shell {
    grid-template-rows: auto 1fr;
    gap: 6px;
    height: 100dvh;
    padding: 6px;
    overflow: hidden;
  }

  body.content-fullscreen .content-shell {
    height: 100dvh;
  }

  .fullscreen-exit-btn {
    top: max(11px, env(safe-area-inset-top));
    right: max(13px, env(safe-area-inset-right));
    width: 32px;
    height: 32px;
    font-size: 16px;
  }

  .fullscreen-exit-btn:active {
    opacity: 0.88;
  }

  .content-toolbar {
    display: flex;
    min-height: 42px;
    padding: 4px 6px;
    border-radius: 8px;
  }

  .icon-btn {
    min-width: 32px;
    height: 32px;
    border-radius: 10px;
    font-size: 16px;
  }

  .content-frame-wrap {
    height: auto;
    min-height: 0;
    border-radius: 8px;
  }

  .content-frame {
    height: 100%;
  }
}
