/* ════════════════════════════════════════════════════════════════════════
   阀门检验系统 · PC 门户外壳
   与各看板共用同一套设计令牌（#2563eb 主色 / slate 中性色 / 8px 间距）
   ════════════════════════════════════════════════════════════════════════ */

:root {
  /* 色彩 */
  --bg: #f4f6f9;
  --surface: #ffffff;
  --surface-soft: #f8fafc;
  --surface-muted: #f1f5f9;
  --border: #e2e8f0;
  --border-strong: #d5dde8;
  --text: #1e293b;
  --text-soft: #475569;
  --muted: #64748b;
  --muted-2: #94a3b8;

  --accent: #2563eb;
  --accent-hover: #1d4ed8;
  --accent-soft: #eff6ff;
  --accent-ring: rgba(37, 99, 235, 0.18);

  --success: #15803d;
  --success-soft: #ecfdf3;
  --danger: #dc2626;
  --danger-hover: #b91c1c;
  --danger-soft: #fef2f2;

  /* 尺寸 */
  --topbar-h: 64px;
  --sidebar-w: 240px;
  --sp-1: 8px;
  --sp-2: 16px;
  --sp-3: 24px;

  /* 圆角 / 阴影 */
  --radius-sm: 6px;
  --radius: 8px;
  --radius-lg: 12px;
  --radius-xl: 16px;
  --shadow-sm: 0 1px 2px rgba(15, 23, 42, 0.05);
  --shadow-md: 0 10px 30px rgba(15, 23, 42, 0.09);
  --shadow-lg: 0 24px 60px rgba(15, 23, 42, 0.22);

  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC",
    "Hiragino Sans GB", "Microsoft YaHei", "Helvetica Neue", Arial, sans-serif;
  --ease: 0.16s ease;
}

* {
  box-sizing: border-box;
}

html,
body {
  height: 100%;
}

body {
  margin: 0;
  font-family: var(--font);
  font-size: 14px;
  color: var(--text);
  background: var(--bg);
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
}

body.portal-nav-open {
  overflow: hidden;
}

button,
input {
  font-family: inherit;
}

svg {
  display: block;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

/* ── 顶部栏 ─────────────────────────────────────────────────────────────── */
.topbar {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  z-index: 50;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--sp-2);
  height: var(--topbar-h);
  padding: 0 20px 0 16px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  box-shadow: var(--shadow-sm);
}

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

.topbar__left {
  flex: 1 1 auto;
}

.topbar__right {
  flex: 0 0 auto;
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  padding: 4px 6px;
  color: var(--text);
  text-decoration: none;
  border-radius: var(--radius);
  transition: background-color var(--ease);
}

.brand:hover {
  background: var(--surface-muted);
}

.brand:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}

.brand__mark {
  width: 34px;
  height: 34px;
  flex: 0 0 auto;
  font-size: 17px;
  font-weight: 700;
  line-height: 34px;
  text-align: center;
  color: #fff;
  background: linear-gradient(135deg, var(--accent), #4f9bff);
  border-radius: 9px;
  user-select: none;
}

.brand__name {
  font-size: 16.5px;
  font-weight: 700;
  letter-spacing: 0.4px;
  white-space: nowrap;
}

.topbar__divider {
  width: 1px;
  height: 22px;
  flex: 0 0 auto;
  background: var(--border);
}

.topbar__page {
  min-width: 0;
  overflow: hidden;
  font-size: 14.5px;
  font-weight: 600;
  color: var(--text-soft);
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* 顶部栏右侧操作 */
.apk-link {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  height: 32px;
  padding: 0 11px;
  font-size: 12.5px;
  font-weight: 600;
  color: var(--accent);
  text-decoration: none;
  white-space: nowrap;
  background: var(--accent-soft);
  border: 1px solid #bfdbfe;
  border-radius: var(--radius);
  transition: background-color var(--ease), border-color var(--ease);
}

.apk-link:hover {
  background: #dbeafe;
  border-color: #93c5fd;
}

.apk-link:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.admin-chip {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
  padding: 3px 4px 3px 3px;
}

.admin-chip__avatar {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 27px;
  height: 27px;
  flex: 0 0 auto;
  font-size: 12px;
  font-weight: 700;
  color: var(--accent);
  background: var(--accent-soft);
  border: 1px solid #dbeafe;
  border-radius: 50%;
}

.admin-chip__name {
  max-width: 150px;
  overflow: hidden;
  font-size: 13.5px;
  font-weight: 600;
  color: var(--text-soft);
  text-overflow: ellipsis;
  white-space: nowrap;
}

.topbar__btn {
  height: 32px;
  padding: 0 10px;
  font-size: 13px;
  font-weight: 600;
  color: var(--text-soft);
  white-space: nowrap;
  background: transparent;
  border: 1px solid transparent;
  border-radius: var(--radius);
  cursor: pointer;
  transition: background-color var(--ease), color var(--ease),
    border-color var(--ease);
}

.topbar__btn:hover {
  color: var(--text);
  background: var(--surface-muted);
}

.topbar__btn--danger:hover {
  color: var(--danger-hover);
  background: var(--danger-soft);
}

.topbar__btn:focus-visible,
.hamburger:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

/* ── 汉堡按钮（仅移动端） ───────────────────────────────────────────────── */
.hamburger {
  display: none;
  align-items: center;
  justify-content: center;
  width: 38px;
  height: 38px;
  flex: 0 0 auto;
  padding: 0;
  color: var(--text-soft);
  background: transparent;
  border: 1px solid transparent;
  border-radius: var(--radius);
  cursor: pointer;
  transition: background-color var(--ease), color var(--ease);
}

.hamburger:hover {
  color: var(--text);
  background: var(--surface-muted);
}

.hamburger[aria-expanded="true"] {
  color: var(--accent);
  background: var(--accent-soft);
}

/* ── 左侧导航 ───────────────────────────────────────────────────────────── */
.sidebar {
  position: fixed;
  top: var(--topbar-h);
  left: 0;
  bottom: 0;
  z-index: 40;
  width: var(--sidebar-w);
  padding: 12px 0;
  background: var(--surface);
  border-right: 1px solid var(--border);
  overflow-y: auto;
  overscroll-behavior: contain;
  transition: transform 0.2s ease, box-shadow 0.2s ease;
}

.nav {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.nav__item {
  position: relative;
  display: flex;
  align-items: center;
  gap: 11px;
  height: 44px;
  margin: 0 10px;
  padding: 0 12px 0 15px;
  font-size: 14px;
  font-weight: 500;
  color: var(--text-soft);
  text-decoration: none;
  border-radius: var(--radius);
  transition: background-color var(--ease), color var(--ease);
}

.nav__item::before {
  content: "";
  position: absolute;
  top: 50%;
  left: 0;
  width: 3px;
  height: 0;
  background: var(--accent);
  border-radius: 0 3px 3px 0;
  transform: translateY(-50%);
  transition: height var(--ease);
}

.nav__item:hover {
  color: var(--text);
  background: var(--surface-muted);
}

.nav__item:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: -2px;
}

.nav__item.is-active {
  font-weight: 600;
  color: var(--accent);
  background: var(--accent-soft);
}

.nav__item.is-active::before {
  height: 22px;
}

.nav__item.is-active .nav__icon {
  color: var(--accent);
}

.nav__icon {
  width: 19px;
  height: 19px;
  flex: 0 0 auto;
  color: var(--muted);
  transition: color var(--ease);
}

.nav__item:hover .nav__icon {
  color: var(--text-soft);
}

.nav__label {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* ── 内容区（iframe 占满剩余视口） ──────────────────────────────────────── */
.content {
  position: fixed;
  top: var(--topbar-h);
  left: var(--sidebar-w);
  right: 0;
  bottom: 0;
  background: var(--surface);
}

#contentFrame {
  display: block;
  width: 100%;
  height: calc(100dvh - var(--topbar-h));
  border: 0;
  background: var(--surface);
}

/* 遮罩（移动端抽屉） */
.scrim {
  display: none;
  position: fixed;
  top: var(--topbar-h);
  right: 0;
  bottom: 0;
  left: 0;
  z-index: 35;
  background: rgba(15, 23, 42, 0.46);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.18s ease;
}

.scrim.is-open {
  opacity: 1;
  pointer-events: auto;
}

/* ── 弹窗（native dialog） ─────────────────────────────────────────────── */
.modal {
  width: min(440px, calc(100vw - 32px));
  max-height: calc(100dvh - 64px);
  margin: auto;
  padding: 0;
  color: var(--text);
  background: var(--surface);
  border: 0;
  border-radius: var(--radius-xl);
  box-shadow: var(--shadow-lg);
  overflow: hidden;
}

.modal--sm {
  width: min(400px, calc(100vw - 32px));
}

.modal::backdrop {
  background: rgba(15, 23, 42, 0.46);
  backdrop-filter: blur(1px);
}

.modal[open] {
  animation: modal-in 0.16s ease-out;
}

@keyframes modal-in {
  from {
    opacity: 0;
    transform: translateY(8px) scale(0.99);
  }
  to {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

.modal__form {
  display: flex;
  flex-direction: column;
  max-height: calc(100dvh - 64px);
}

.modal__head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--sp-2);
  padding: 18px 24px;
  border-bottom: 1px solid var(--border);
}

.modal__title {
  margin: 0;
  font-size: 17px;
  font-weight: 700;
  letter-spacing: 0.2px;
}

.modal__close {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 30px;
  height: 30px;
  font-size: 20px;
  line-height: 1;
  color: var(--muted);
  background: transparent;
  border: 0;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: background-color var(--ease), color var(--ease);
}

.modal__close:hover {
  color: var(--text);
  background: var(--surface-muted);
}

.modal__close:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}

.modal__body {
  padding: 20px 24px 18px;
  overflow-y: auto;
}

.modal__foot {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: var(--sp-1);
  padding: 14px 24px;
  background: var(--surface-soft);
  border-top: 1px solid var(--border);
}

.confirm-text {
  margin: 0;
  font-size: 14px;
  line-height: 1.7;
  color: var(--text-soft);
}

/* 表单 */
.field {
  display: flex;
  flex-direction: column;
  gap: 7px;
}

.field + .field {
  margin-top: 14px;
}

.field label {
  font-size: 13px;
  font-weight: 600;
  color: #445566;
}

.field input {
  width: 100%;
  height: 40px;
  padding: 0 12px;
  font-size: 14.5px;
  color: var(--text);
  background: #fbfcfe;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  outline: none;
  transition: border-color var(--ease), box-shadow var(--ease),
    background-color var(--ease);
}

.field input:focus {
  background: #fff;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-ring);
}

.field input.is-invalid {
  border-color: var(--danger);
  box-shadow: 0 0 0 3px rgba(220, 38, 38, 0.14);
}

.form-error {
  min-height: 18px;
  margin: 12px 0 0;
  font-size: 13px;
  line-height: 18px;
  color: var(--danger);
}

.form-error:empty {
  display: none;
}

/* 按钮 */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  height: 36px;
  padding: 0 16px;
  font-size: 13.5px;
  font-weight: 600;
  line-height: 1;
  white-space: nowrap;
  color: var(--text-soft);
  background: var(--surface);
  border: 1px solid transparent;
  border-radius: var(--radius);
  cursor: pointer;
  user-select: none;
  transition: background-color var(--ease), border-color var(--ease),
    color var(--ease), box-shadow var(--ease), transform 0.06s ease;
}

.btn:active:not(:disabled) {
  transform: translateY(1px);
}

.btn:disabled {
  opacity: 0.55;
  cursor: not-allowed;
}

.btn:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.btn--primary {
  color: #fff;
  background: var(--accent);
  border-color: var(--accent);
}

.btn--primary:hover:not(:disabled) {
  background: var(--accent-hover);
  border-color: var(--accent-hover);
}

.btn--ghost {
  color: var(--text-soft);
  background: var(--surface);
  border-color: var(--border-strong);
}

.btn--ghost:hover:not(:disabled) {
  background: var(--surface-soft);
  border-color: #bcc9da;
}

.btn--danger {
  color: #fff;
  background: var(--danger);
  border-color: var(--danger);
}

.btn--danger:hover:not(:disabled) {
  background: var(--danger-hover);
  border-color: var(--danger-hover);
}

/* ── Toast ─────────────────────────────────────────────────────────────── */
.toast-wrap {
  position: fixed;
  right: var(--sp-3);
  bottom: var(--sp-3);
  z-index: 1000;
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: var(--sp-1);
  pointer-events: none;
}

.toast {
  max-width: 360px;
  padding: 11px 14px;
  font-size: 13px;
  line-height: 1.45;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--border);
  border-left: 3px solid var(--accent);
  border-radius: var(--radius);
  box-shadow: var(--shadow-md);
  opacity: 0;
  transform: translateY(8px);
  transition: opacity 0.18s ease, transform 0.18s ease;
}

.toast.is-in {
  opacity: 1;
  transform: translateY(0);
}

.toast--success {
  border-left-color: var(--success);
}

.toast--error {
  border-left-color: var(--danger);
}

/* ── 响应式：900px 以下抽屉侧栏 ────────────────────────────────────────── */
@media (max-width: 900px) {
  .hamburger {
    display: inline-flex;
  }

  .sidebar {
    transform: translateX(-100%);
    box-shadow: none;
  }

  .sidebar.is-open {
    transform: translateX(0);
    box-shadow: var(--shadow-lg);
  }

  .scrim {
    display: block;
  }

  .content {
    left: 0;
  }

  .topbar {
    padding: 0 12px 0 8px;
  }

  .topbar__page {
    font-size: 14px;
  }

  .topbar__divider--right {
    display: none;
  }
}

@media (max-width: 720px) {
  .apk-link span {
    display: none;
  }

  .apk-link {
    width: 32px;
    padding: 0;
    justify-content: center;
  }

  .admin-chip__name {
    display: none;
  }

  .brand__name {
    font-size: 15.5px;
  }

  .topbar__left,
  .topbar__right {
    gap: 8px;
  }

  .topbar__btn {
    padding: 0 8px;
  }
}

@media (max-width: 520px) {
  .brand__name {
    display: none;
  }

  .topbar__divider {
    display: none;
  }

  .topbar__page {
    padding-left: 2px;
  }
}

/* 减少动效偏好 */
@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    transition-duration: 0.01ms !important;
  }
}
