:root {
  --primary: #2f6df6;
  --primary-weak: rgba(47, 109, 246, 0.12);
  --bg: #f4f6fb;
  --surface: #ffffff;
  --surface-2: #eef2f9;
  --text: #1b2333;
  --muted: #6b7689;
  --line: #e2e8f3;
  --accent: rgba(47, 109, 246, 0.08);
  --ok: #1faa6a;
  --warn: #e08a00;
  --err: #e0464b;
  --shadow: 0 10px 30px rgba(20, 30, 60, 0.08);
  --radius: 16px;
}
[data-theme="dark"] {
  --primary: #5b8dff;
  --primary-weak: rgba(91, 141, 255, 0.16);
  --bg: #0e1117;
  --surface: #161b24;
  --surface-2: #1d2430;
  --text: #e8edf6;
  --muted: #93a0b5;
  --line: #283042;
  --accent: rgba(91, 141, 255, 0.12);
  --shadow: 0 10px 30px rgba(0, 0, 0, 0.45);
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
  background: var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
  transition: background .3s, color .3s;
}
.muted { color: var(--muted); }
.hidden { display: none !important; }
.block { display: block; width: 100%; }

/* Glass */
.glass {
  background: color-mix(in srgb, var(--surface) 70%, transparent);
  backdrop-filter: blur(18px) saturate(160%);
  -webkit-backdrop-filter: blur(18px) saturate(160%);
  border: 1px solid var(--line);
}

/* Login cards base */
.brand { display: flex; align-items: center; gap: 12px; margin-bottom: 18px; }
.brand h1 { font-size: 20px; margin: 0; }
.brand small { color: var(--muted); }
.brand-mark-img {
  width: 30px; height: 30px; border-radius: 9px; object-fit: cover;
  border: 1px solid var(--line); background: #fff; flex-shrink: 0;
}
.brand-mark {
  width: 40px; height: 40px; display: grid; place-items: center; border-radius: 12px;
  background: linear-gradient(135deg, var(--primary), #7aa6ff); color: #fff; font-size: 20px;
}
.brand.small .brand-mark { width: 30px; height: 30px; font-size: 15px; border-radius: 9px; }
.brand-name { font-weight: 700; letter-spacing: .3px; }
.login-form label { display: block; font-size: 13px; color: var(--muted); margin: 12px 0 6px; }
.login-form input {
  width: 100%; padding: 11px 12px; border-radius: 10px; border: 1px solid var(--line);
  background: var(--surface); color: var(--text); font-size: 14px;
}
.login-form input:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px var(--primary-weak); }

/* Buttons */
.btn {
  border: 1px solid var(--line); background: var(--surface); color: var(--text);
  padding: 9px 14px; border-radius: 10px; cursor: pointer; font-size: 14px;
  transition: transform .12s ease, background .2s, border-color .2s;
}
.btn:hover { transform: translateY(-1px); }
.btn.primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn.ghost { background: transparent; }
.btn.small { padding: 6px 10px; font-size: 13px; }
.btn.danger { color: var(--err); border-color: color-mix(in srgb, var(--err) 40%, var(--line)); }
.icon-btn {
  border: 1px solid var(--line); background: var(--surface); color: var(--text);
  width: 38px; height: 38px; border-radius: 10px; cursor: pointer; font-size: 16px;
}
.icon-btn:hover { background: var(--surface-2); }

/* App shell */
.app { height: 100%; display: flex; flex-direction: column; }
.topbar {
  height: 60px; display: flex; align-items: center; gap: 12px; padding: 0 16px;
  border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 30;
}
.topbar-spacer { flex: 1; }
.user-chip { display: flex; align-items: center; gap: 8px; }
.avatar {
  width: 32px; height: 32px; border-radius: 50%; display: grid; place-items: center;
  background: var(--primary-weak); color: var(--primary); font-weight: 700; font-size: 14px;
}
.user-name { font-size: 14px; }

.layout { flex: 1; display: flex; min-height: 0; position: relative; }
.sidebar {
  width: 248px; flex-shrink: 0; padding: 14px 10px; overflow-y: auto;
  border-right: 1px solid var(--line); transition: transform .25s ease;
}
.nav { display: flex; flex-direction: column; gap: 4px; }
.nav-group { font-size: 11px; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); padding: 14px 10px 6px; }
.nav-item {
  display: flex; align-items: center; gap: 10px; padding: 10px 12px; border-radius: 10px;
  cursor: pointer; font-size: 14px; color: var(--text); border: 1px solid transparent;
}
.nav-item:hover { background: var(--surface-2); }
.nav-item.active { background: var(--primary-weak); color: var(--primary); border-color: color-mix(in srgb, var(--primary) 25%, transparent); }
.nav-item .ic { font-size: 16px; }
.content { flex: 1; overflow-y: auto; padding: 22px; min-width: 0; }

/* Scrim for mobile drawer */
.scrim { position: absolute; inset: 0; background: rgba(0,0,0,.35); opacity: 0; pointer-events: none; transition: opacity .25s; z-index: 20; }
.sidebar.open { transform: translateX(0); }
.sidebar.open ~ .scrim, .scrim.show { opacity: 1; pointer-events: auto; }

/* Cards / grid */
.page-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 18px; flex-wrap: wrap; }
.page-title { font-size: 22px; margin: 0; }
.grid { display: grid; gap: 16px; }
.grid.cols-3 { grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); }
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px; box-shadow: var(--shadow); }
.card h3 { margin: 0 0 6px; font-size: 15px; }
.kpi { font-size: 28px; font-weight: 700; }
.kpi.small { font-size: 18px; }

/* Tables */
table { width: 100%; border-collapse: collapse; font-size: 14px; }
th, td { text-align: left; padding: 10px 12px; border-bottom: 1px solid var(--line); }
th { color: var(--muted); font-weight: 600; font-size: 12px; text-transform: uppercase; letter-spacing: .04em; }
tr:hover td { background: var(--surface-2); }
td.num, th.num { text-align: right; }

/* Badges */
.badge { display: inline-flex; align-items: center; padding: 3px 9px; border-radius: 999px; font-size: 12px; font-weight: 600; }
.badge.ok { background: color-mix(in srgb, var(--ok) 18%, transparent); color: var(--ok); }
.badge.warn { background: color-mix(in srgb, var(--warn) 18%, transparent); color: var(--warn); }
.badge.err { background: color-mix(in srgb, var(--err) 18%, transparent); color: var(--err); }
.badge.info { background: var(--primary-weak); color: var(--primary); }
.badge.off { background: var(--surface-2); color: var(--muted); }

/* Forms inside content */
.field { margin: 10px 0; }
.field label { display: block; font-size: 13px; color: var(--muted); margin-bottom: 5px; }
.field input, .field select, .field textarea {
  width: 100%; padding: 9px 11px; border-radius: 9px; border: 1px solid var(--line);
  background: var(--surface); color: var(--text); font-size: 14px; font-family: inherit;
}
.field input:focus, .field select:focus, .field textarea:focus {
  outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px var(--primary-weak);
}
.row { display: flex; gap: 10px; flex-wrap: wrap; align-items: flex-end; }
.row > * { flex: 1; min-width: 160px; }

.form-msg { font-size: 13px; margin-top: 8px; padding: 8px 10px; border-radius: 8px; }
.form-msg.err { background: color-mix(in srgb, var(--err) 12%, transparent); color: var(--err); }
.form-msg.ok { background: color-mix(in srgb, var(--ok) 12%, transparent); color: var(--ok); }
.hint { font-size: 12px; color: var(--muted); margin-top: 8px; }
.toolbar { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 14px; }

/* Modal */
.modal-back {
  position: fixed; inset: 0; background: rgba(0,0,0,.4); display: grid; place-items: center; padding: 20px; z-index: 50;
}
.modal { width: min(520px, 100%); max-height: calc(100vh - 40px); overflow-y: auto; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 20px; box-shadow: var(--shadow); }

/* Role editor (wider, grouped/collapsible) */
.modal--role { width: min(760px, 100%); }
.modal--role h3 { margin: 0 0 14px; font-size: 17px; }
.re-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.re-grid .field { margin: 0 0 4px; }
.re-preset { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; margin: 12px 0 4px; padding: 10px 12px; background: var(--surface-2); border: 1px solid var(--line); border-radius: 12px; }
.re-preset label { font-size: 13px; color: var(--muted); font-weight: 600; }
.re-preset select { flex: 0 0 auto; width: auto; min-width: 220px; padding: 8px 10px; border-radius: 9px; border: 1px solid var(--line); background: var(--surface); color: var(--text); font-size: 14px; font-family: inherit; }
.re-preset select:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px var(--primary-weak); }
.re-preset .hint { flex: 1 1 100%; margin: 0; }
.re-section { margin-top: 16px; }
.re-section-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 8px; }
.re-section-head > span:first-child { font-size: 14px; font-weight: 700; }
.re-count { font-size: 12px; color: var(--muted); }

/* Collapsible group panels (native <details>) */
.perm-group { border: 1px solid var(--line); border-radius: 12px; margin-bottom: 10px; background: var(--surface); overflow: hidden; }
.perm-group > summary {
  list-style: none; cursor: pointer; display: flex; align-items: center; gap: 10px;
  padding: 11px 14px; font-size: 14px; user-select: none; background: var(--surface-2);
}
.perm-group > summary::-webkit-details-marker { display: none; }
.perm-group > summary::before { content: "▸"; color: var(--muted); font-size: 12px; transition: transform .15s ease; }
.perm-group[open] > summary::before { transform: rotate(90deg); }
.perm-group > summary:focus-visible { outline: 2px solid var(--primary); outline-offset: -2px; border-radius: 12px; }
.pg-check { display: inline-flex; }
.pg-check .pg-all { width: 16px; height: 16px; accent-color: var(--primary); }
.pg-icon { font-size: 15px; }
.pg-title { font-weight: 600; flex: 1; }
.pg-meta { font-size: 12px; color: var(--muted); margin-left: auto; }
.perm-list { padding: 10px 14px 12px; display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 6px 16px; }

/* Checkbox chip */
.chk { display: flex; align-items: center; gap: 8px; padding: 7px 10px; border: 1px solid transparent; border-radius: 9px; font-size: 13.5px; cursor: pointer; transition: background .15s, border-color .15s; }
.chk:hover { background: var(--surface-2); }
.chk:focus-within { border-color: var(--primary); background: var(--primary-weak); }
.chk input[type="checkbox"] { width: 16px; height: 16px; accent-color: var(--primary); flex-shrink: 0; }
.chk span { line-height: 1.25; }
.chk-key { margin-left: auto; font-size: 11px; color: var(--muted); background: var(--surface-2); padding: 2px 6px; border-radius: 6px; font-family: ui-monospace, Menlo, Consolas, monospace; }

@media (max-width: 620px) {
  .re-grid { grid-template-columns: 1fr; }
  .modal--role { width: 100%; }
}

/* Tasks */
.task { display: flex; align-items: center; gap: 12px; padding: 12px; border: 1px solid var(--line); border-radius: 12px; background: var(--surface); margin-bottom: 8px; }
.task.done .task-title { text-decoration: line-through; color: var(--muted); }
.task-title { flex: 1; }

/* Responsive */
@media (max-width: 760px) {
  .sidebar {
    position: absolute; top: 0; bottom: 0; left: 0; z-index: 25;
    transform: translateX(-100%); box-shadow: var(--shadow);
  }
  #menuBtn { display: inline-flex; }
  .content { padding: 16px; }
}
@media (min-width: 761px) {
  #menuBtn { display: none; }
}

/* ===== Login page (single screen, no scroll, no registration) ===== */
.login-overlay {
  position: fixed; inset: 0; display: grid; place-items: center;
  padding: clamp(16px, 4vh, 40px) clamp(16px, 4vw, 40px);
  background:
    radial-gradient(1200px 600px at 80% -10%, rgba(42,143,159,0.10), transparent),
    radial-gradient(1000px 500px at 10% 110%, rgba(200,74,88,0.08), transparent),
    linear-gradient(135deg, #faf8f5 0%, #eef6f9 55%, #e8f0f8 100%);
  overflow: hidden; /* 禁止页面上下滑动 */
}
[data-theme="dark"] .login-overlay {
  background:
    radial-gradient(1200px 600px at 80% -10%, rgba(42,143,159,0.12), transparent),
    radial-gradient(1000px 500px at 10% 110%, rgba(200,74,88,0.10), transparent),
    linear-gradient(135deg, #14171d 0%, #111621 55%, #151b26 100%);
}

.login-deco {
  position: absolute; inset: 0; pointer-events: none; overflow: hidden;
}
.deco-tree {
  position: absolute; width: min(420px, 55vw); height: min(420px, 55vw);
  opacity: .85; animation: treeFloat 8s ease-in-out infinite;
}
.deco-tree--tl { left: -80px; top: -80px; animation-delay: -2s; }
.deco-tree--br { right: -80px; bottom: -80px; animation-delay: -5s; }
@keyframes treeFloat {
  0%, 100% { transform: translateY(0) rotate(0deg); }
  50% { transform: translateY(-10px) rotate(1.5deg); }
}

.login-panel {
  position: relative; z-index: 1;
  width: min(880px, 100%);
  max-height: calc(100vh - 92px); /* 预留 footer 空间 */
  display: grid;
  grid-template-columns: 1.05fr 0.95fr;
  border-radius: 28px;
  box-shadow: var(--shadow);
  overflow: hidden;
}

.login-brand {
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  text-align: center; padding: clamp(28px, 5vh, 52px) clamp(24px, 4vw, 44px);
  background:
    linear-gradient(160deg, rgba(42,143,159,0.10) 0%, rgba(200,74,88,0.08) 55%, rgba(47,109,246,0.08) 100%),
    color-mix(in srgb, var(--surface) 86%, transparent);
  border-right: 1px solid var(--line);
}
.login-logo {
  width: clamp(72px, 12vw, 110px); height: clamp(72px, 12vw, 110px);
  border-radius: 50%; object-fit: cover;
  border: 3px solid rgba(255,255,255,0.6);
  box-shadow: 0 8px 28px rgba(30,58,95,0.12);
  margin-bottom: clamp(14px, 2.5vh, 22px);
  background: #fff;
}
.login-brand h1 {
  font-size: clamp(22px, 3.2vw, 30px); margin: 0 0 8px;
  color: #1e3a5f; font-weight: 800; letter-spacing: .3px;
}
[data-theme="dark"] .login-brand h1 { color: #e8edf6; }
.login-brand h1 span { color: var(--primary); font-weight: 700; }
.login-slogan {
  font-size: clamp(16px, 2.2vw, 20px); font-weight: 600;
  color: #c84a58; margin: 0 0 6px; letter-spacing: 1px;
}
[data-theme="dark"] .login-slogan { color: #e8707d; }
.login-desc {
  font-size: clamp(12px, 1.5vw, 14px); color: var(--muted);
  max-width: 280px; line-height: 1.6; margin: 0;
}

.login-form-wrap {
  display: flex; flex-direction: column; justify-content: center;
  padding: clamp(28px, 5vh, 48px) clamp(24px, 4vw, 44px);
  background: color-mix(in srgb, var(--surface) 78%, transparent);
}
.login-form-wrap h2 {
  font-size: clamp(18px, 2.4vw, 22px); margin: 0 0 18px;
  color: var(--text); font-weight: 700;
}
.login-form label { display: block; font-size: 13px; color: var(--muted); margin: 12px 0 6px; font-weight: 500; }
.login-form input {
  width: 100%; padding: 12px 14px; border-radius: 12px; border: 1px solid var(--line);
  background: var(--surface); color: var(--text); font-size: 15px;
  transition: border-color .2s, box-shadow .2s;
}
.login-form input:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px var(--primary-weak); }
.login-form .btn.block {
  margin-top: 20px; padding: 12px; font-size: 15px; border-radius: 12px;
  background: linear-gradient(135deg, var(--primary), #4a8af7);
  box-shadow: 0 6px 18px rgba(47,109,246,0.25);
}
.login-form .btn.block:hover { transform: translateY(-2px); box-shadow: 0 10px 24px rgba(47,109,246,0.32); }
.login-hint {
  font-size: 12px; color: var(--muted); text-align: center;
  margin: 14px 0 0; line-height: 1.5;
}

.login-foot {
  position: absolute; bottom: clamp(10px, 2vh, 18px);
  left: 0; right: 0; text-align: center; font-size: 12px;
}

@media (max-width: 760px) {
  .login-overlay { padding: 16px; }
  .login-panel {
    grid-template-columns: 1fr;
    max-height: calc(100vh - 72px);
    border-radius: 22px;
  }
  .login-brand {
    border-right: none; border-bottom: 1px solid var(--line);
    padding: 22px 24px 18px;
  }
  .login-logo { width: 64px; height: 64px; margin-bottom: 12px; }
  .login-brand h1 { font-size: 22px; margin-bottom: 4px; }
  .login-slogan { font-size: 15px; margin-bottom: 4px; }
  .login-desc { font-size: 12px; }
  .login-form-wrap { padding: 22px 24px 24px; }
  .login-form-wrap h2 { margin-bottom: 12px; font-size: 17px; }
  .login-form label { margin-top: 10px; }
  .login-form .btn.block { margin-top: 16px; }
  .deco-tree { width: 70vw; height: 70vw; opacity: .55; }
  .deco-tree--tl { left: -40vw; top: -30vw; }
  .deco-tree--br { right: -40vw; bottom: -30vw; }
  .login-foot { font-size: 11px; bottom: 8px; }
}

/* Backwards-compat: hide legacy landing/card selectors if referenced */
.landing, .login-card, .register-card { display: none !important; }

/* ===== Content module ===== */
textarea { resize: vertical; }

/* ===== Business modules / dashboard embed (iframe) ===== */
.biz-wrap { height: calc(100vh - 104px); min-height: 480px; }
.biz-frame {
  width: 100%; height: 100%; border: 0; border-radius: 12px;
  background: var(--bg); box-shadow: var(--shadow);
}

/* ===== Dashboard hero / workspace home ===== */
.dash-hero {
  display: grid; grid-template-columns: 1.6fr 1fr; gap: 16px; margin-bottom: 22px; align-items: stretch;
}
.dash-banner {
  width: 100%; height: 100%; min-height: 160px; max-height: 220px; object-fit: cover; object-position: center;
  border-radius: var(--radius); border: 1px solid var(--line); box-shadow: var(--shadow);
  background: var(--surface);
}
.dash-welcome {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 22px; box-shadow: var(--shadow); display: flex; flex-direction: column; justify-content: center;
}
.dash-welcome h3 { margin: 0 0 10px; font-size: 20px; }
.dash-welcome p { margin: 0; line-height: 1.6; }

@media (max-width: 760px) {
  .dash-hero { grid-template-columns: 1fr; }
  .dash-banner { max-height: 180px; }
}


/* 工作台首页移动端补充 */
@media (max-width: 760px) {
  .content { padding: 14px; }
  .page-head { flex-direction: column; align-items: flex-start; gap: 10px; }
  .page-head .btn { width: 100%; }
  .kpi { font-size: 22px; }
  .card { padding: 14px; }
}

/* ===== Mobile-only helper + compact header + module launcher grid ===== */
.mobile-only { display: none !important; }
@media (max-width: 760px) {
  .mobile-only { display: block !important; }
  .desktop-only { display: none !important; }

  /* Header: keep only logo, short title, theme, avatar, exit icon — lightly polished */
  .topbar {
    height: 56px; padding: 0 14px; gap: 10px;
    border-bottom: 1px solid var(--line);
    box-shadow: 0 6px 20px rgba(15, 23, 42, .06);
  }
  .brand.small { gap: 9px; }
  .brand-name { display: none; }
  .brand-name-mobile {
    display: inline; font-weight: 800; font-size: 17px; letter-spacing: .2px;
    background: linear-gradient(90deg, #2f6df6, #1e8f9f);
    -webkit-background-clip: text; background-clip: text;
    -webkit-text-fill-color: transparent;
  }
  .brand-mark-img {
    width: 32px; height: 32px; border-radius: 9px;
    border: 1px solid rgba(255, 255, 255, .25);
    box-shadow: 0 4px 12px rgba(47, 109, 246, .32);
  }
  #menuBtn { display: none !important; }
  .user-chip { gap: 0; }
  .user-name { display: none; }
  #logoutBtn { display: none; }
  #logoutBtnMobile { display: inline-flex !important; }
  .topbar .icon-btn, #logoutBtnMobile { min-width: 40px; min-height: 40px; }

  /* Module launcher grid on dashboard */
  .mobile-module-section { margin-top: 18px; }
  .mobile-section-title { font-size: 18px; margin: 0 0 12px; }
  .mobile-mod-group-title { font-size: 12px; color: var(--muted); margin: 16px 0 8px; text-transform: uppercase; letter-spacing: .05em; }
  .mobile-mod-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 12px; }
  .mobile-mod-card {
    background: var(--surface); border: 1px solid var(--line); border-radius: 14px;
    padding: 18px 10px; display: flex; flex-direction: column; align-items: center; gap: 8px;
    text-decoration: none; color: var(--text); box-shadow: var(--shadow); cursor: pointer;
    transition: transform .12s ease, background .2s;
  }
  .mobile-mod-card:active { transform: scale(0.98); }
  .mobile-mod-icon { font-size: 28px; line-height: 1; }
  .mobile-mod-label { font-size: 14px; font-weight: 600; text-align: center; }
}
