/* ==========================================================================
   应用外壳：启动页、登录页、侧边栏、顶栏、通知、弹窗、命令面板
   ========================================================================== */

/* ---------- 启动页 ---------- */
.boot {
  position: fixed; inset: 0; z-index: 150;
  display: grid; place-content: center; justify-items: center; gap: 14px;
  background: var(--bg);
}
body:not([data-state="boot"]) .boot { display: none; }
.boot-mark { border-radius: 12px; animation: boot-pulse 1.6s var(--ease) infinite; }
.boot-text { color: var(--text-3); font-size: var(--fs-sm); }
@keyframes boot-pulse { 0%, 100% { transform: scale(1); opacity: 1; } 50% { transform: scale(.92); opacity: .72; } }

/* ---------- 登录页 ---------- */
.login {
  min-height: 100vh; min-height: 100dvh;
  display: grid; grid-template-columns: minmax(0, 1.05fr) minmax(0, 1fr);
}
.login-hero {
  position: relative; overflow: hidden;
  display: flex; align-items: center;
  padding: 56px;
  color: #fff;
  background:
    radial-gradient(900px 520px at 12% 8%, rgba(255, 255, 255, .22), transparent 60%),
    radial-gradient(700px 520px at 100% 100%, rgba(236, 72, 153, .55), transparent 60%),
    var(--brand-gradient);
}
.login-hero::before {
  content: ""; position: absolute; inset: auto -120px -160px auto;
  width: 520px; height: 520px;
  background: conic-gradient(from 210deg, rgba(255,255,255,.0), rgba(255,255,255,.28), rgba(255,255,255,.0) 40%);
  border-radius: 50%; filter: blur(2px);
}
.login-hero-inner { position: relative; max-width: 460px; }
.login-brand { display: flex; align-items: center; gap: 12px; margin-bottom: 56px; font-size: var(--fs-lg); font-weight: 650; letter-spacing: .02em; }
.login-brand img { border-radius: 10px; box-shadow: 0 6px 18px rgba(0,0,0,.25); }
.login-hero h2 { font-size: clamp(30px, 3.2vw, 42px); line-height: 1.2; letter-spacing: -.02em; font-weight: 700; }
.login-hero p { margin-top: 18px; font-size: var(--fs-lg); line-height: 1.7; opacity: .9; }
.login-points { margin-top: 34px; display: grid; gap: 12px; }
.login-points li { position: relative; padding-left: 28px; font-size: var(--fs-md); opacity: .95; }
.login-points li::before {
  content: ""; position: absolute; left: 0; top: .32em; width: 16px; height: 16px; border-radius: 50%;
  background: rgba(255,255,255,.22) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16'%3E%3Cpath d='m4.5 8.4 2.3 2.3 4.7-5' fill='none' stroke='white' stroke-width='1.8' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E") center / 16px no-repeat;
}
.login-panel { display: grid; place-items: center; padding: 32px 20px; background: var(--bg); }
.login-card {
  width: min(400px, 100%);
  padding: 36px 32px 28px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius-xl);
  box-shadow: var(--shadow-md);
  display: grid; gap: 16px;
}
.login-card-brand img { border-radius: 12px; box-shadow: var(--shadow-sm); }
.login-card h1 { font-size: var(--fs-2xl); }
.login-sub { margin-top: -8px; color: var(--text-2); }
.login-foot { font-size: var(--fs-xs); color: var(--text-3); line-height: 1.6; }
.form-error { min-height: 1.4em; margin: -6px 0 -4px; color: var(--bad); font-size: var(--fs-sm); }
.btn-block { width: 100%; }
body[data-state="login"] .app { display: none; }

@media (max-width: 860px) {
  .login { grid-template-columns: 1fr; }
  .login-hero { display: none; }
  .login-panel { background: linear-gradient(180deg, var(--accent-soft), var(--bg) 40%); }
}

/* ---------- 应用骨架 ---------- */
.app {
  display: grid;
  grid-template-columns: var(--sidebar-w) minmax(0, 1fr);
  min-height: 100vh; min-height: 100dvh;
  transition: grid-template-columns .22s var(--ease);
}
html[data-collapsed="1"] .app { --sidebar-w: 72px; }
.main-col { min-width: 0; display: flex; flex-direction: column; }
.main { flex: 1; min-width: 0; outline: none; }

/* ---------- 侧边栏 ---------- */
.sidebar {
  position: sticky; top: 0; z-index: 50;
  height: 100vh; height: 100dvh;
  display: flex; flex-direction: column;
  background: var(--surface);
  border-right: 1px solid var(--line);
  min-width: 0;
}
.sidebar-head { height: var(--topbar-h); display: flex; align-items: center; padding: 0 18px; border-bottom: 1px solid var(--line); }
.brand { display: flex; align-items: center; gap: 11px; color: var(--text); min-width: 0; }
.brand:hover { text-decoration: none; }
.brand-mark { border-radius: 9px; box-shadow: 0 2px 8px rgba(91, 95, 247, .35); flex: none; }
.brand-text { display: grid; line-height: 1.15; min-width: 0; }
.brand-text strong { font-size: 15px; letter-spacing: .01em; }
.brand-text small { font-size: 14px; color: var(--text-3); letter-spacing: .08em; text-transform: uppercase; }

.nav { flex: 1; overflow-y: auto; overflow-x: hidden; padding: 14px 12px; display: grid; align-content: start; gap: 2px; }
.nav-group-title { padding: 16px 12px 6px; font-size: 14px; font-weight: 600; letter-spacing: .08em; color: var(--text-3); text-transform: uppercase; white-space: nowrap; }
.nav-group-title:first-child { padding-top: 4px; }
.nav-item {
  position: relative;
  display: flex; align-items: center; gap: 12px;
  height: 38px; padding: 0 12px;
  border-radius: 10px;
  color: var(--text-2);
  font-weight: 500; font-size: var(--fs-md);
  white-space: nowrap;
  transition: background .15s, color .15s;
}
.nav-item:hover { background: var(--surface-2); color: var(--text); text-decoration: none; }
.nav-item[aria-current="page"] { background: var(--accent-soft); color: var(--accent-text); font-weight: 600; }
.nav-item[aria-current="page"]::before {
  content: ""; position: absolute; left: -12px; top: 9px; bottom: 9px; width: 3px; border-radius: 0 3px 3px 0; background: var(--accent);
}
.nav-item svg { width: 19px; height: 19px; }
.nav-label { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; }
.nav-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--warn); box-shadow: 0 0 0 3px var(--warn-soft); flex: none; }
.nav-dot.bad { background: var(--bad); box-shadow: 0 0 0 3px var(--bad-soft); }

.sidebar-foot { padding: 12px; border-top: 1px solid var(--line); display: grid; gap: 8px; }
.side-status { display: flex; align-items: center; gap: 10px; padding: 10px 12px; border-radius: 12px; background: var(--surface-2); border: 1px solid var(--line); min-width: 0; }
.side-status-dot { width: 9px; height: 9px; border-radius: 50%; background: var(--ok); box-shadow: 0 0 0 4px var(--ok-soft); flex: none; }
.side-status-dot.warn { background: var(--warn); box-shadow: 0 0 0 4px var(--warn-soft); }
.side-status-text { display: grid; line-height: 1.3; min-width: 0; }
.side-status-text strong { font-size: var(--fs-sm); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.side-status-text small { font-size: 14px; color: var(--text-3); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.side-collapse {
  display: flex; align-items: center; gap: 10px; height: 34px; padding: 0 12px; border: 0; border-radius: 10px;
  background: transparent; color: var(--text-3); font-size: var(--fs-sm);
}
.side-collapse:hover { background: var(--surface-2); color: var(--text); }
.side-collapse svg { width: 18px; height: 18px; }

/* 折叠态（仅桌面） */
@media (min-width: 961px) {
  html[data-collapsed="1"] .brand-text,
  html[data-collapsed="1"] .nav-label,
  html[data-collapsed="1"] .side-status-text,
  html[data-collapsed="1"] .side-collapse .label { display: none; }
  html[data-collapsed="1"] .sidebar-head { padding: 0; justify-content: center; }
  html[data-collapsed="1"] .nav { padding: 14px 10px; }
  html[data-collapsed="1"] .nav-item { justify-content: center; padding: 0; }
  html[data-collapsed="1"] .nav-item[aria-current="page"]::before { left: -10px; }
  html[data-collapsed="1"] .nav-group-title { height: 1px; padding: 0; margin: 12px 8px; background: var(--line); font-size: 0; }
  html[data-collapsed="1"] .nav-dot { position: absolute; right: 8px; top: 8px; }
  html[data-collapsed="1"] .side-status { justify-content: center; padding: 10px 0; }
  html[data-collapsed="1"] .side-collapse { justify-content: center; padding: 0; }
  html[data-collapsed="1"] .side-collapse svg { transform: scaleX(-1); }
}

/* ---------- 顶栏 ---------- */
.topbar {
  position: sticky; top: 0; z-index: 30;
  height: var(--topbar-h);
  display: flex; align-items: center; gap: 8px;
  padding: 0 24px;
  background: color-mix(in srgb, var(--bg) 84%, transparent);
  -webkit-backdrop-filter: saturate(1.4) blur(14px);
  backdrop-filter: saturate(1.4) blur(14px);
  border-bottom: 1px solid var(--line);
}
.topbar-menu { display: none; }
.topbar-spacer { flex: 1; }
.crumbs { display: flex; align-items: center; gap: 8px; font-size: var(--fs-sm); min-width: 0; }
.crumb-root { color: var(--text-3); }
.crumb-sep { color: var(--line-strong); }
.crumb-current { font-weight: 600; color: var(--text); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.palette-trigger {
  display: inline-flex; align-items: center; gap: 10px;
  height: 34px; min-width: 210px; padding: 0 8px 0 12px;
  border: 1px solid var(--line-strong); border-radius: 10px;
  background: var(--surface); color: var(--text-3); font-size: var(--fs-sm);
  transition: border-color .15s, box-shadow .15s;
}
.palette-trigger:hover { border-color: var(--text-3); color: var(--text-2); }
.palette-trigger svg { width: 16px; height: 16px; }
.palette-trigger .palette-hint { margin-left: auto; display: inline-flex; gap: 3px; }

.scrim { position: fixed; inset: 0; z-index: 45; background: var(--scrim); animation: fade-in .18s var(--ease); }

/* 移动端抽屉 */
@media (max-width: 960px) {
  .app { grid-template-columns: minmax(0, 1fr); }
  .sidebar {
    position: fixed; left: 0; top: 0; bottom: 0; width: min(300px, 86vw);
    transform: translateX(-102%);
    transition: transform .26s var(--ease), box-shadow .26s;
  }
  .app[data-nav-open="true"] .sidebar { transform: none; box-shadow: var(--shadow-lg); }
  .topbar { padding: 0 14px; }
  .topbar-menu { display: inline-flex; }
  .crumb-root, .crumb-sep { display: none; }
  .palette-trigger { min-width: 0; width: 34px; padding: 0; justify-content: center; }
  .palette-trigger .palette-label, .palette-trigger .palette-hint { display: none; }
  .side-collapse { display: none; }
}
@media (max-width: 560px) {
  #modeBadge { display: none; }
}

/* ---------- 通知 ---------- */
.toasts {
  position: fixed; right: 20px; bottom: 20px; z-index: 120;
  display: flex; flex-direction: column; align-items: flex-end; gap: 10px;
  pointer-events: none; max-width: calc(100vw - 32px);
}
.toast {
  pointer-events: auto;
  display: flex; align-items: flex-start; gap: 10px;
  min-width: 260px; max-width: 440px;
  padding: 12px 14px;
  background: var(--surface); color: var(--text);
  border: 1px solid var(--line-strong); border-left-width: 4px; border-radius: 12px;
  box-shadow: var(--shadow-md);
  font-size: var(--fs-sm); line-height: 1.5;
  animation: toast-in .28s var(--ease);
}
.toast[data-leaving="true"] { animation: toast-out .2s ease forwards; }
.toast svg { width: 18px; height: 18px; margin-top: 1px; }
.toast-ok { border-left-color: var(--ok); } .toast-ok > svg { color: var(--ok); }
.toast-bad { border-left-color: var(--bad); } .toast-bad > svg { color: var(--bad); }
.toast-warn { border-left-color: var(--warn); } .toast-warn > svg { color: var(--warn); }
.toast-info { border-left-color: var(--info); } .toast-info > svg { color: var(--info); }
.toast-text { flex: 1; min-width: 0; }
.toast-action { border: 0; background: transparent; color: var(--accent-text); font-weight: 600; font-size: var(--fs-sm); padding: 0 4px; }
.toast-action:hover { text-decoration: underline; }
.toast-close { border: 0; background: transparent; color: var(--text-3); padding: 0; width: 20px; height: 20px; display: grid; place-items: center; border-radius: 6px; }
.toast-close:hover { background: var(--surface-3); color: var(--text); }
.toast-close svg { width: 14px; height: 14px; margin: 0; color: inherit; }
@keyframes toast-in { from { opacity: 0; transform: translateY(12px) scale(.98); } to { opacity: 1; transform: none; } }
@keyframes toast-out { to { opacity: 0; transform: translateY(8px) scale(.98); } }
@keyframes fade-in { from { opacity: 0; } to { opacity: 1; } }
@media (max-width: 560px) {
  .toasts { right: 12px; left: 12px; bottom: calc(12px + env(safe-area-inset-bottom)); align-items: stretch; }
  .toast { max-width: none; }
}

/* ---------- 弹窗 ---------- */
dialog.modal {
  border: 0; padding: 0; margin: auto;
  width: min(560px, calc(100vw - 24px));
  max-height: min(90vh, 900px);
  border-radius: var(--radius-xl);
  background: var(--surface); color: var(--text);
  box-shadow: var(--shadow-lg);
  overflow: hidden;
}
dialog.modal[open] { display: flex; flex-direction: column; animation: modal-in .22s var(--ease); }
dialog.modal.wide { width: min(760px, calc(100vw - 24px)); }
dialog.modal.narrow { width: min(440px, calc(100vw - 24px)); }
dialog.modal::backdrop { background: var(--scrim); -webkit-backdrop-filter: blur(3px); backdrop-filter: blur(3px); animation: fade-in .2s var(--ease); }
@keyframes modal-in { from { opacity: 0; transform: translateY(14px) scale(.97); } to { opacity: 1; transform: none; } }
.modal-head { display: flex; align-items: flex-start; gap: 12px; padding: 22px 24px 4px; }
.modal-title { flex: 1; min-width: 0; }
.modal-title h2 { font-size: var(--fs-xl); }
.modal-title p { margin-top: 4px; color: var(--text-2); font-size: var(--fs-sm); }
.modal-body { padding: 16px 24px 8px; overflow: auto; display: grid; gap: 16px; align-content: start; }
.modal-foot { display: flex; justify-content: flex-end; flex-wrap: wrap; gap: 10px; padding: 16px 24px 22px; }
.modal-icon { width: 40px; height: 40px; border-radius: 12px; display: grid; place-items: center; background: var(--accent-soft); color: var(--accent-text); flex: none; }
.modal-icon.bad { background: var(--bad-soft); color: var(--bad); }
.modal-icon.warn { background: var(--warn-soft); color: var(--warn); }
.modal-icon.ok { background: var(--ok-soft); color: var(--ok); }
.modal-icon svg { width: 20px; height: 20px; }
@media (max-width: 560px) {
  dialog.modal { width: calc(100vw - 16px); max-height: 92vh; }
  dialog.modal[open] { margin-bottom: 8px; }
  .modal-head { padding: 18px 18px 2px; }
  .modal-body { padding: 14px 18px 6px; }
  .modal-foot { padding: 14px 18px 18px; }
  .modal-foot .btn { flex: 1; }
}

/* ---------- 命令面板 ---------- */
dialog.palette { width: min(620px, calc(100vw - 24px)); margin: 12vh auto auto; padding: 0; border: 0; border-radius: var(--radius-xl); background: var(--surface); color: var(--text); box-shadow: var(--shadow-lg); overflow: hidden; }
dialog.palette[open] { display: flex; flex-direction: column; max-height: min(520px, 76vh); animation: modal-in .18s var(--ease); }
dialog.palette::backdrop { background: var(--scrim); -webkit-backdrop-filter: blur(3px); backdrop-filter: blur(3px); }
.palette-search { display: flex; align-items: center; gap: 12px; padding: 14px 18px; border-bottom: 1px solid var(--line); }
.palette-search svg { width: 18px; height: 18px; color: var(--text-3); }
.palette-input { flex: 1; min-width: 0; border: 0; background: transparent; font-size: var(--fs-lg); outline: none; }
.palette-input::placeholder { color: var(--text-3); }
.palette-list { overflow: auto; padding: 8px; display: grid; gap: 2px; align-content: start; }
.palette-group { padding: 10px 12px 4px; font-size: 14px; font-weight: 600; letter-spacing: .08em; color: var(--text-3); }
.palette-item { display: flex; align-items: center; gap: 12px; width: 100%; padding: 9px 12px; border: 0; border-radius: 10px; background: transparent; text-align: left; color: var(--text); }
.palette-item[aria-selected="true"] { background: var(--accent-soft); color: var(--accent-text); }
.palette-item svg { width: 18px; height: 18px; color: var(--text-3); }
.palette-item[aria-selected="true"] svg { color: inherit; }
.palette-item-text { flex: 1; min-width: 0; display: grid; line-height: 1.35; }
.palette-item-text small { color: var(--text-3); font-size: var(--fs-xs); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.palette-empty { padding: 28px; text-align: center; color: var(--text-3); }
.palette-foot { display: flex; gap: 16px; padding: 10px 18px; border-top: 1px solid var(--line); color: var(--text-3); font-size: var(--fs-xs); }
.palette-foot span { display: inline-flex; gap: 6px; align-items: center; }
