/* 鲸选RPA 管理后台 · 外壳布局：侧栏、顶栏、页面容器、登录页 */

/* ---------- 侧栏 ---------- */

.app-shell { min-height: 100dvh; }

.sidebar {
  position: fixed;
  inset: 0 auto 0 0;
  z-index: 40;
  display: flex;
  flex-direction: column;
  width: var(--sidebar-width);
  background: var(--sidebar);
  color: var(--sidebar-foreground);
}

.sidebar .brand {
  display: flex;
  flex: none;
  align-items: center;
  gap: 12px;
  height: 64px;
  padding: 0 24px;
}
.sidebar .brand img { width: 46px; height: auto; }
.sidebar .brand strong { display: block; font-size: 18px; font-weight: 600; line-height: 1.25; letter-spacing: -0.01em; }
.sidebar .brand small { display: block; color: rgb(255 255 255 / 0.8); font-size: 12px; }

#navigation {
  position: relative;
  flex: 1;
  min-height: 0;
  padding: 8px 0;
  overflow-y: auto;
  overscroll-behavior: contain;
  scrollbar-width: none;
}
#navigation::-webkit-scrollbar { display: none; }

/* 隐藏滚动条是为了让选中页签贴住画布；放不下时用底部渐隐提示还能往下滚。 */
#navigation::after {
  content: "";
  position: sticky;
  bottom: -8px;
  display: block;
  height: 48px;
  margin-top: -48px;
  background: linear-gradient(to top, var(--sidebar), rgb(25 93 155 / 0));
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.3s;
}
#navigation.has-more-below::after { opacity: 1; }

#customer-navigation, #platform-navigation { display: flex; flex-direction: column; gap: 6px; }

.nav-group { display: flex; flex-direction: column; padding-left: 12px; }
.nav-group-label {
  padding: 8px 12px 4px;
  color: rgb(255 255 255 / 0.8);
  font-size: 12px;
  font-weight: 500;
  line-height: 1.5;
}

#navigation button {
  position: relative;
  justify-content: flex-start;
  gap: 12px;
  width: calc(100% - 12px);
  height: 36px;
  margin-right: 12px;
  padding: 0 12px;
  border: 0;
  border-radius: 12px;
  background: transparent;
  color: rgb(255 255 255 / 0.9);
  font-weight: 500;
  text-align: left;
  transition: background-color 0.15s, color 0.15s;
}
#navigation button span { overflow: hidden; text-overflow: ellipsis; }
#navigation button .icon { width: 18px; height: 18px; color: rgb(255 255 255 / 0.75); transition: color 0.15s; }
#navigation button:hover:not(.active):not(:disabled) { background: rgb(255 255 255 / 0.1); color: #ffffff; }
#navigation button:hover:not(.active) .icon { color: #ffffff; }
#navigation button:focus-visible { outline: 2px solid rgb(255 255 255 / 0.75); outline-offset: -2px; }
#navigation button:disabled { opacity: 1; }

/* 选中项：与右侧画布同色相连，上下用反向圆角过渡，像鲸鱼从深海蓝中浮出。 */
#navigation button.active {
  width: 100%;
  margin-right: 0;
  border-radius: var(--tab-radius) 0 0 var(--tab-radius);
  background: var(--background);
  color: var(--primary);
}
#navigation button.active .icon { color: var(--primary); }
#navigation button.active::before,
#navigation button.active::after {
  content: "";
  position: absolute;
  right: 0;
  width: var(--tab-radius);
  height: var(--tab-radius);
  pointer-events: none;
}
#navigation button.active::before {
  bottom: 100%;
  background: radial-gradient(circle at 0 0, transparent calc(var(--tab-radius) - 0.5px), var(--background) var(--tab-radius));
}
#navigation button.active::after {
  top: 100%;
  background: radial-gradient(circle at 0 100%, transparent calc(var(--tab-radius) - 0.5px), var(--background) var(--tab-radius));
}

.sidebar .company {
  flex: none;
  padding: 12px 12px 14px;
  border-top: 1px solid rgb(255 255 255 / 0.14);
}
.golden-version { display: flex; align-items: center; gap: 8px; padding: 4px 12px 2px; }
.golden-version b { font-size: 14px; font-weight: 500; }
.online-pill {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  height: 20px;
  padding: 0 6px;
  border-radius: 999px;
  background: rgb(255 255 255 / 0.1);
  color: rgb(255 255 255 / 0.9);
  font-size: 12px;
  font-weight: 500;
}
.online-pill::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: #5fe3a1; }
.sidebar .company p { padding: 0 12px; color: rgb(255 255 255 / 0.8); font-size: 12px; }

/* 矮屏（如 1366×768 笔记本）：收紧行高，13 个菜单仍能一屏放下。 */
@media (min-width: 768px) and (max-height: 800px) {
  .sidebar .brand { height: 56px; }
  #navigation button { height: 32px; }
  .nav-group-label { padding: 6px 12px 2px; }
  #customer-navigation, #platform-navigation { gap: 4px; }
}

/* ---------- 主区域与顶栏 ---------- */

.app-shell > main {
  display: flex;
  flex-direction: column;
  min-width: 0;
  min-height: 100dvh;
  margin-left: var(--sidebar-width);
}

/* 顶栏与页面内容共用同一套左右留白，宽屏下两者左右对齐。 */
.app-header, main > .page {
  padding-inline: max(var(--page-gutter), calc((100% - var(--content-max)) / 2 + var(--page-gutter)));
}

.app-header {
  position: sticky;
  top: 0;
  z-index: 30;
  display: flex;
  flex: none;
  align-items: center;
  gap: 12px;
  height: var(--header-height);
  border-bottom: 1px solid rgb(225 232 240 / 0.7);
  background: rgb(243 246 250 / 0.86);
  backdrop-filter: saturate(1.4) blur(12px);
  -webkit-backdrop-filter: saturate(1.4) blur(12px);
}

.nav-toggle { display: none; margin-left: -8px; color: var(--foreground); }

.page-heading { display: flex; flex: 1; align-items: baseline; gap: 12px; min-width: 0; }
.page-heading h1 { flex: none; font-size: 20px; font-weight: 600; letter-spacing: -0.01em; white-space: nowrap; }
.page-heading p {
  min-width: 0;
  overflow: hidden;
  color: var(--muted-foreground);
  font-size: 14px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.header-actions { display: flex; flex: none; align-items: center; gap: 8px; }

#tenant-state {
  height: 28px;
  padding: 0 12px;
  border-radius: 999px;
  background: var(--secondary);
  color: var(--foreground);
  font-size: 12px;
}
#tenant-state::before { display: none; }
#tenant-state.warn { background: rgb(180 83 9 / 0.1); color: var(--warning); }

#api-state {
  height: 28px;
  padding: 0 6px;
  background: transparent;
  color: var(--muted-foreground);
  font-size: 13px;
  font-weight: 400;
}
/* 未带状态类时是"服务器检查中"（改密前不发起健康检查，会一直停留在此状态）。 */
#api-state::before { width: 8px; height: 8px; background: var(--input-hover); }
#api-state.ok::before { background: var(--success); }
#api-state.warn::before { background: var(--warning); }
#api-state.error::before { background: var(--destructive); }

.golden-account-menu { position: relative; }
.account-label { max-width: 132px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.golden-account-menu > summary {
  display: flex;
  align-items: center;
  gap: 8px;
  height: 40px;
  padding: 0 10px 0 4px;
  border-radius: 999px;
  color: var(--foreground);
  font-size: 14px;
  font-weight: 500;
  list-style: none;
  cursor: pointer;
  user-select: none;
  transition: background-color 0.15s;
}
.golden-account-menu > summary::-webkit-details-marker { display: none; }
.golden-account-menu > summary:hover, .golden-account-menu[open] > summary { background: var(--muted); }
.golden-account-menu > summary:focus-visible { outline: 2px solid var(--primary); outline-offset: 0; }
.golden-avatar {
  display: grid;
  place-items: center;
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: var(--primary);
  color: var(--primary-foreground);
  font-size: 14px;
  font-weight: 600;
}
.account-chevron { width: 16px; height: 16px; color: var(--muted-foreground); transition: transform 0.15s; }
.golden-account-menu[open] .account-chevron { transform: rotate(180deg); }

.golden-account-options {
  position: absolute;
  top: calc(100% + 8px);
  right: 0;
  z-index: 50;
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 200px;
  padding: 6px;
  border-radius: 12px;
  background: var(--card);
  box-shadow: var(--shadow-popover);
  animation: pop-in 0.12s ease-out;
}
.golden-account-options button {
  justify-content: flex-start;
  gap: 10px;
  width: 100%;
  height: 36px;
  padding: 0 10px;
  border: 0;
  border-radius: var(--radius-md);
  background: transparent;
  color: var(--foreground);
  font-weight: 400;
}
.golden-account-options button:hover:not(:disabled) { background: var(--muted); }
.golden-account-options button::before {
  content: "";
  width: 16px;
  height: 16px;
  background: var(--muted-foreground);
  -webkit-mask: var(--icon-refresh) center / contain no-repeat;
  mask: var(--icon-refresh) center / contain no-repeat;
}
.golden-account-options #admin-auth::before {
  -webkit-mask-image: var(--icon-logout);
  mask-image: var(--icon-logout);
}

/* ---------- 页面容器 ---------- */

main > .page {
  display: none;
  width: 100%;
  padding-top: 24px;
  padding-bottom: 96px;
}
main > .page.active { display: flex; flex-direction: column; gap: 20px; animation: fade-in 0.18s ease-out; }

@media (min-width: 768px) {
  main > .page { padding-top: 28px; }
  main > .page.active { gap: 24px; }
}

.section-heading { padding: 0 4px; font-size: 16px; font-weight: 600; }

/* ---------- 手机与平板：侧栏改为抽屉 ---------- */

.nav-backdrop {
  position: fixed;
  inset: 0;
  z-index: 39;
  background: rgb(15 32 48 / 0.45);
  animation: fade-in 0.2s ease-out;
}

@media (max-width: 1023px) {
  .page-heading p { display: none; }
  #tenant-state { display: none; }
}

@media (max-width: 767px) {
  .sidebar {
    width: 280px;
    max-width: 86vw;
    box-shadow: 0 0 48px rgb(15 32 48 / 0.3);
    transform: translateX(-100%);
    visibility: hidden;
    transition: transform 0.25s ease, visibility 0s linear 0.25s;
  }
  body.nav-open .sidebar { transform: none; visibility: visible; transition: transform 0.25s ease; }
  body.nav-open { overflow: hidden; }

  /* 抽屉里没有相邻画布，选中项改为整块浅色按钮。 */
  #navigation button.active { width: calc(100% - 12px); margin-right: 12px; border-radius: 12px; }
  #navigation button.active::before, #navigation button.active::after { display: none; }

  .app-shell > main { margin-left: 0; }
  .nav-toggle { display: inline-flex; }
  .app-header { gap: 8px; height: 56px; }
  .page-heading h1 { font-size: 18px; }
  #api-state { display: none; }
  .account-label { display: none; }
  .golden-account-menu > summary { padding-right: 6px; }
  main > .page { padding-top: 16px; padding-bottom: 64px; }
  main > .page.active { gap: 16px; }
}

/* ---------- 登录与找回 ---------- */

.auth-shell {
  display: grid;
  place-items: center;
  min-height: 100dvh;
  padding: 40px 16px;
  background: var(--background);
}

.auth-card {
  display: flex;
  flex-direction: column;
  gap: 24px;
  width: 100%;
  max-width: 420px;
  padding: 32px;
  border-radius: 16px;
  background: var(--card);
  box-shadow: var(--shadow-surface), 0 20px 48px -24px rgb(20 41 60 / 0.22);
  animation: pop-in 0.2s ease-out;
}
@media (max-width: 479px) {
  .auth-card { padding: 24px 20px; border-radius: 14px; }
}

.auth-brand { display: flex; align-items: center; gap: 12px; }
.auth-brand img { width: 44px; height: 44px; border-radius: 12px; }
.auth-brand strong { display: block; font-size: 17px; font-weight: 600; line-height: 1.3; }
.auth-brand small { display: block; color: var(--muted-foreground); font-size: 13px; }

.auth-card form { display: flex; flex-direction: column; gap: 16px; }
.auth-heading h1 { font-size: 22px; font-weight: 600; letter-spacing: -0.01em; }
.auth-heading p { margin-top: 6px; color: var(--muted-foreground); font-size: 14px; line-height: 1.6; text-wrap: pretty; }

.auth-card form > button[type="submit"] { width: 100%; height: 40px; margin-top: 4px; font-size: 15px; }
/* 退出登录、注册成功等确认消息与错误共用同一行提示，由 shell.js 标记为 success。 */
.auth-card .error-text[data-tone="success"] { color: var(--success); }

.auth-links { display: flex; flex-wrap: wrap; align-items: center; justify-content: center; gap: 4px 14px; }
.auth-links-divider { width: 1px; height: 12px; background: var(--border); }
.auth-link { font-size: 14px; }
.auth-back-login, #recovery-back { align-self: center; }

.auth-recovery-entry { padding-top: 16px; border-top: 1px solid var(--border); text-align: center; }
.auth-recovery-entry .auth-link { color: var(--muted-foreground); font-size: 13px; font-weight: 400; }
.auth-recovery-entry .auth-link:hover:not(:disabled) { color: var(--foreground); }

.otp-row { display: flex; align-items: flex-end; gap: 8px; }
.otp-row label { flex: 1; }
.otp-row button { flex: none; min-width: 108px; }

.secure-link-status {
  padding: 10px 12px;
  border-radius: var(--radius-md);
  background: var(--muted);
  color: var(--muted-foreground);
  font-size: 13px;
  line-height: 1.5;
}
/* app.js renderRecoveryValidation() sets data-status to VALID / INVALID. */
.secure-link-status[data-status="VALID"] { background: rgb(19 120 74 / 0.08); color: var(--success); }
.secure-link-status[data-status="INVALID"] { background: rgb(191 58 58 / 0.08); color: var(--destructive); }

.loading-state { display: flex; align-items: center; gap: 14px; }
.loading-state h1 { font-size: 16px; }
.loading-state p { margin-top: 2px; color: var(--muted-foreground); font-size: 14px; }

.auth-failure-card { align-items: center; text-align: center; }
.auth-failure-card h1 { font-size: 18px; }
.auth-failure-card p { margin-top: -12px; color: var(--muted-foreground); }

.state-illustration {
  display: grid;
  place-items: center;
  width: 48px;
  height: 48px;
  border-radius: 14px;
  background: var(--muted);
  color: var(--muted-foreground);
}
.state-illustration .icon { width: 24px; height: 24px; }
.state-illustration.error { background: var(--destructive-soft); color: var(--destructive); }
