/* ==========================================================================
   wg 资产平台 · 组件层
   顶栏、导航、按钮、表单、筛选条、面板、表格、标签、提示、
   对话框与登录视图。页面样式只做布局编排，不再重复定义组件外观。
   ========================================================================== */

/* ---------- 品牌与顶栏 ---------- */
.brand {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  flex: 0 0 auto;
  min-width: 0;
  color: var(--text-primary);
  text-decoration: none;
}

.brand-mark {
  display: grid;
  place-items: center;
  inline-size: 32px;
  block-size: 32px;
  border-radius: var(--radius-sm);
  background: var(--brand-mark-bg);
  color: var(--text-inverse);
  font-size: var(--text-meta);
  font-weight: var(--weight-heavy);
  letter-spacing: 0.02em;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: var(--z-topbar);
  display: block;
  min-height: var(--topbar-height);
  border-bottom: 1px solid var(--border);
  background: var(--surface);
}

.topbar .workspace {
  flex: 0 0 auto;
  padding-inline-start: 14px;
  color: var(--text-secondary);
  font-size: var(--text-meta);
}

.topbar .workspace strong {
  color: var(--text-primary);
  font-weight: var(--weight-semibold);
}

.topbar-inner {
  position: relative;
  display: flex;
  align-items: center;
  gap: var(--space-5);
  inline-size: 100%;
  max-inline-size: var(--container-max);
  min-height: var(--topbar-height);
  margin-inline: auto;
  padding-inline: var(--gutter);
}

.desktop-nav {
  display: flex;
  flex: 1 1 auto;
  gap: 3px;
  align-self: stretch;
  justify-content: center;
}

.nav-item {
  position: relative;
  display: inline-flex;
  align-items: center;
  min-height: var(--touch-target);
  padding: 0 var(--space-2);
  border: 0;
  background: transparent;
  color: var(--text-secondary);
  font-size: var(--text-body-sm);
  font-weight: var(--weight-semibold);
  white-space: nowrap;
}

.nav-item:hover {
  color: var(--accent);
}

.desktop-nav-slot .nav-item[aria-current="page"] {
  color: var(--accent-hover);
  font-weight: var(--weight-heavy);
}

.desktop-nav-slot .nav-item[aria-current="page"]::after {
  content: "";
  position: absolute;
  inset-inline: var(--space-2);
  inset-block-end: 0;
  block-size: 3px;
  border-radius: var(--radius-pill) var(--radius-pill) 0 0;
  background: var(--accent);
}

.user {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  flex: 0 0 auto;
}

.user-meta {
  display: block;
  color: var(--text-tertiary);
  max-inline-size: 112px;
  font-size: var(--text-caption);
  line-height: var(--leading-tight);
  text-align: end;
}

.user-meta strong {
  display: block;
  overflow: hidden;
  color: var(--text-primary);
  font-size: var(--text-meta);
  text-overflow: ellipsis;
  white-space: nowrap;
}

.icon-btn {
  display: inline-grid;
  place-items: center;
  min-width: var(--touch-target);
  min-height: var(--touch-target);
  padding: 0 var(--space-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--text-secondary);
  font-size: var(--text-body-sm);
  font-weight: var(--weight-semibold);
  transition: border-color var(--motion-fast) var(--ease-standard),
    color var(--motion-fast) var(--ease-standard);
}

.icon-btn:hover {
  border-color: var(--accent);
  color: var(--accent);
}

/* ---------- 布局骨架 ---------- */
.container {
  inline-size: min(100% - (var(--gutter) * 2), var(--container-max));
  margin-inline: auto;
}

.breadcrumb {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  margin: var(--space-4) 0 var(--space-2);
  color: var(--text-tertiary);
  font-size: var(--text-caption);
}

/* ---------- 页头 ---------- */
.page-heading {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: var(--space-5);
  margin-bottom: var(--space-6);
}

.page-title {
  font-size: var(--text-display);
  letter-spacing: var(--tracking-snug);
  line-height: var(--leading-tight);
}

.page-description {
  max-inline-size: 760px;
  margin-top: var(--space-2);
  color: var(--text-secondary);
  font-size: var(--text-body-sm);
}

.page-actions {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-2);
  justify-content: flex-end;
}

/* ---------- 按钮与链接 ---------- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-2);
  min-width: var(--touch-target);
  min-height: var(--control-height);
  padding: 0 var(--space-4);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--text-primary);
  font-weight: var(--weight-bold);
  text-align: center;
  text-decoration: none;
  transition: background-color var(--motion-fast) var(--ease-standard),
    border-color var(--motion-fast) var(--ease-standard),
    color var(--motion-fast) var(--ease-standard);
}

.btn:hover {
  border-color: var(--accent);
  background: var(--accent-soft);
  color: var(--accent-hover);
}

.btn:active {
  background: var(--accent-soft-hover);
}

.btn.primary {
  border-color: var(--accent);
  background: var(--accent);
  color: var(--text-on-accent);
}

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

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

.btn:disabled {
  opacity: 0.5;
}

.link-button {
  padding: 0;
  border: 0;
  background: transparent;
  color: var(--accent);
  font: inherit;
  text-decoration: underline;
  text-underline-offset: 3px;
}

.link-button:hover {
  color: var(--accent-hover);
}

.link-button:disabled {
  color: var(--text-tertiary);
  opacity: 0.8;
}

.text-link,
.table-link {
  display: inline-flex;
  align-items: center;
  gap: var(--space-1);
  min-height: var(--touch-target);
  padding: var(--space-2) 0;
  border: 0;
  background: none;
  color: var(--accent);
  font-weight: var(--weight-bold);
  text-decoration: none;
}

.text-link:hover,
.table-link:hover {
  color: var(--accent-hover);
  text-decoration: underline;
  text-underline-offset: 3px;
}

a.text-link:not(.btn):visited,
a.table-link:not(.btn):visited {
  color: var(--text-tertiary);
}

/* ---------- 表单 ---------- */
.field {
  display: block;
  min-inline-size: 0;
}

.field label {
  display: block;
  margin-bottom: 6px;
  color: var(--text-primary);
  font-size: var(--text-meta);
  font-weight: var(--weight-bold);
}

.field input,
.field select,
.field textarea,
.filterbar select {
  inline-size: 100%;
  min-height: var(--control-height);
  padding: 0 var(--space-3);
  border: 1px solid var(--border-input);
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--text-primary);
}

.field textarea {
  min-height: 88px;
  padding-block: var(--space-2);
  line-height: var(--leading-body);
  resize: vertical;
}

.field input:focus,
.field select:focus,
.field textarea:focus,
.filterbar select:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: var(--focus-ring);
}

.field input:disabled,
.field select:disabled,
.field textarea:disabled {
  background: var(--surface-sunken);
  color: var(--text-secondary);
}

.field input[aria-invalid="true"],
.field select[aria-invalid="true"],
.field textarea[aria-invalid="true"] {
  border-color: var(--danger);
}

.field-error,
.form-error {
  display: block;
  margin-top: 5px;
  color: var(--danger);
  font-size: var(--text-meta);
}

.check-field {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  min-height: var(--control-height);
  color: var(--text-secondary);
  font-size: var(--text-meta);
}

.check-field input {
  inline-size: 16px;
  block-size: 16px;
  accent-color: var(--accent);
}

.form-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: var(--space-4);
}

.form-grid.single {
  grid-template-columns: 1fr;
}

.form-grid.triple {
  grid-template-columns: repeat(3, minmax(0, 1fr));
}

.form-grid.pair {
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
}

.form-actions {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-2);
  justify-content: flex-end;
  grid-column: 1 / -1;
}

.form-grid > * {
  min-width: 0;
}

.actions,
.compact-toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: end;
  gap: var(--space-2);
}

.compact-toolbar > .field {
  flex: 1 1 148px;
}

.field.small label,
.subtle {
  color: var(--text-secondary);
  font-size: var(--text-meta);
}

.muted {
  color: var(--text-secondary);
}

/* ---------- 筛选条 ---------- */
.filterbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--space-3);
  margin-bottom: var(--space-5);
  padding: var(--space-3) var(--space-4);
  border: 1px solid var(--border-soft);
  border-radius: var(--radius-sm);
  background: var(--surface-muted);
}

.filterbar select {
  inline-size: auto;
  min-width: 150px;
  background: var(--surface);
}

.filter-note,
.filterbar .filter-label {
  color: var(--text-secondary);
  font-size: var(--text-meta);
  font-weight: var(--weight-bold);
}

.filterbar .filter-note {
  margin-inline-start: auto;
}

/* ---------- 面板 ---------- */
.panel {
  min-width: 0;
  padding: 0;
  overflow: hidden;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  background: var(--surface);
  box-shadow: var(--shadow-sm);
}

.panel-head {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-start;
  justify-content: space-between;
  gap: var(--space-3);
  padding: var(--space-5) var(--space-6) 0;
}

.panel-head h2 {
  font-size: var(--text-body-lg);
  line-height: var(--leading-normal);
}

.panel-head p,
.panel-head small {
  color: var(--text-secondary);
  font-size: var(--text-meta);
}

.panel-head p {
  max-inline-size: 640px;
  margin-top: var(--space-1);
}

.panel-head small {
  font-weight: var(--weight-bold);
}

.panel-body {
  padding: var(--space-4) var(--space-6) var(--space-6);
}

.panel-body > :first-child {
  margin-top: 0;
}

.panel-body > :last-child {
  margin-bottom: 0;
}

/* ---------- 标签与状态 ---------- */
.tag {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 3px 8px;
  border: 1px solid transparent;
  border-radius: var(--radius-xs);
  background: var(--surface-hover);
  color: var(--text-secondary);
  font-size: var(--text-caption);
  line-height: var(--leading-normal);
  white-space: nowrap;
}

.tag.red,
.tag.bad {
  background: var(--danger-soft);
  color: var(--danger-strong);
}

.tag.amber,
.tag.warn {
  background: var(--warning-soft);
  color: var(--warning-strong);
}

.tag.green,
.tag.ok {
  background: var(--success-soft);
  color: var(--success-strong);
}

.tag.blue {
  background: var(--accent-soft);
  color: var(--accent-hover);
}

/* ---------- 表格 ---------- */
.table-wrap,
.table-scroll {
  max-inline-size: 100%;
  overflow-x: auto;
  overscroll-behavior-inline: contain;
}

.table-scroll {
  min-height: 320px;
  max-height: 420px;
  overflow-y: auto;
}

.data-table {
  inline-size: 100%;
  min-inline-size: 0;
  border-collapse: collapse;
  text-align: start;
  font-size: var(--text-body-sm);
  overflow-wrap: anywhere;
}

.data-table th {
  padding: var(--space-3) var(--space-4);
  border-bottom: 1px solid var(--border-soft);
  background: var(--surface-sunken);
  color: var(--text-secondary);
  font-size: var(--text-caption);
  font-weight: var(--weight-semibold);
  text-align: start;
  white-space: normal;
  vertical-align: bottom;
}

.data-table td {
  padding: var(--space-3) var(--space-4);
  border-bottom: 1px solid var(--border-soft);
  text-align: start;
  white-space: normal;
  vertical-align: top;
}

.data-table tbody th {
  color: var(--text-primary);
  font-size: var(--text-body-sm);
  font-weight: var(--weight-bold);
}

.data-table tbody th small,
.data-table td small {
  display: block;
  margin-top: 3px;
  color: var(--text-secondary);
  font-weight: var(--weight-regular);
}

.data-table tbody tr:hover > * {
  background: var(--surface-sunken);
}

.data-table tbody tr.active-row > *,
.data-table .active-row > * {
  background: var(--accent-soft);
}

.data-table tbody th,
.data-table tbody td {
  font-variant-numeric: tabular-nums;
}

.data-table tr:last-child td,
.data-table tr:last-child th {
  border-bottom: 0;
}

.data-table .num {
  text-align: end;
  font-variant-numeric: tabular-nums;
}

/* ---------- 提示 / 空态 / 加载 ---------- */
.notice {
  margin-bottom: var(--space-4);
  padding: var(--space-3) var(--space-4);
  border: 1px solid var(--accent-muted);
  border-radius: var(--radius-sm);
  background: var(--accent-soft);
  color: var(--accent-hover);
  font-size: var(--text-meta);
}

.notice.error {
  border-color: var(--danger-line);
  background: var(--danger-soft);
  color: var(--danger-strong);
}

.notice.success {
  border-color: var(--success-line);
  background: var(--success-soft);
  color: var(--success-strong);
}

.notice.warning,
.notice.amber {
  border-color: var(--warning-line);
  background: var(--warning-soft);
  color: var(--warning-strong);
}

.empty {
  padding: var(--space-10) var(--space-5);
  color: var(--text-secondary);
  font-size: var(--text-body-sm);
  text-align: center;
}

.workspace-loading {
  min-height: 126px;
  margin-block-start: var(--space-4);
}

@media (prefers-reduced-motion: no-preference) {
  .workspace-loading {
    animation: workspace-pulse 1.6s var(--ease-standard) infinite;
  }
}

@keyframes workspace-pulse {
  0%,
  100% {
    opacity: 1;
  }
  50% {
    opacity: 0.65;
  }
}

/* ---------- 工作区布局 ---------- */
.tree {
  display: grid;
  gap: 2px;
  padding: var(--space-3);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  background: var(--surface);
}

.tree button {
  padding: var(--space-2) var(--space-3);
  border: 0;
  border-radius: var(--radius-xs);
  background: transparent;
  color: var(--text-primary);
  text-align: start;
}

.tree button:hover {
  background: var(--surface-hover);
}

/* ---------- 对话框 ---------- */
.dialog,
.form-dialog {
  inline-size: min(520px, calc(100% - 32px));
  max-height: calc(100svh - 32px);
  padding: 0;
  overflow: auto;
  border: 1px solid var(--border);
  border-radius: var(--radius-xl);
  background: var(--surface);
  color: var(--text-primary);
  box-shadow: var(--shadow-lg);
}

.dialog::backdrop,
.form-dialog::backdrop {
  background: var(--overlay);
}

.dialog-content,
.form-dialog > form {
  padding: var(--space-6);
}

.dialog h2,
.dialog h1,
.form-dialog h2 {
  font-size: var(--text-title);
  letter-spacing: var(--tracking-snug);
}

.dialog p,
.form-dialog p {
  margin-top: var(--space-2);
  color: var(--text-secondary);
  font-size: var(--text-body-sm);
}

.dialog-actions,
.form-actions {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-2);
  justify-content: flex-end;
  margin-top: var(--space-6);
}

.form-dialog .field {
  margin-bottom: var(--space-4);
}

.dialog-error {
  margin-top: var(--space-3);
  color: var(--danger);
  font-size: var(--text-meta);
}

/* ---------- 登录视图 ---------- */
.login-shell {
  display: grid;
  grid-template-columns: 1fr 1fr;
  min-height: 100svh;
  max-inline-size: var(--container-max);
  margin-inline: auto;
}

.login-intro {
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  min-width: 0;
  padding: var(--space-12) 10%;
  border-inline-end: 1px solid var(--border);
}

.login-context .demo {
  align-self: flex-start;
  margin-bottom: var(--space-3);
}

.login-intro h1 {
  margin: var(--space-3) 0 var(--space-4);
  font-size: var(--text-hero);
  letter-spacing: var(--tracking-tighter);
  line-height: 1.15;
}

.login-intro p {
  max-inline-size: 410px;
  color: var(--text-secondary);
  font-size: var(--text-body);
}

.login-caption {
  color: var(--text-tertiary);
  font-size: var(--text-meta);
}

.login-main {
  display: grid;
  place-items: center;
  padding: var(--space-10) var(--space-6);
}

.login-box {
  inline-size: min(100%, 400px);
}

.demo {
  display: inline-block;
  padding: 5px 8px;
  border: 1px solid var(--border);
  border-radius: var(--radius-xs);
  background: var(--surface);
  color: var(--text-secondary);
  font-size: var(--text-micro);
  font-weight: var(--weight-bold);
  letter-spacing: 0.04em;
}

.login-box h2 {
  margin: var(--space-2) 0;
  font-size: var(--text-heading-sm);
  letter-spacing: var(--tracking-snug);
}

.login-box > p {
  margin: 0 0 var(--space-7);
  color: var(--text-secondary);
  font-size: var(--text-body);
}

.login-box .field {
  margin-bottom: var(--space-4);
}

.password-wrap {
  display: flex;
}

.password-wrap input {
  border-start-end-radius: 0;
  border-end-end-radius: 0;
}

.password-wrap button {
  min-width: 60px;
  min-height: var(--control-height);
  padding-inline: var(--space-3);
  border: 1px solid var(--border-input);
  border-inline-start: 0;
  border-start-end-radius: var(--radius-sm);
  border-end-end-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--text-secondary);
  font-size: var(--text-body-sm);
}

.password-wrap button:hover {
  color: var(--accent);
}

.login-box .primary {
  inline-size: 100%;
}

.roles {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-2);
  margin-top: var(--space-3);
}

.roles .btn {
  font-size: var(--text-meta);
}

.login-box .roles .btn {
  flex: 1 1 0;
  min-width: 76px;
}

.login-box .login-foot {
  margin-block: var(--space-5) 0;
  font-weight: var(--weight-bold);
}

.login-error {
  margin: 0 0 var(--space-3);
  padding: var(--space-3);
  border-radius: var(--radius-xs);
  background: var(--danger-soft);
  color: var(--danger-strong);
  font-size: var(--text-meta);
}

@media (max-width: 768px) {
  .login-shell {
    grid-template-columns: 1fr;
  }

  .login-intro {
    min-height: 208px;
    padding: var(--space-6) var(--space-6) var(--space-4);
    border-inline-end: 0;
    border-bottom: 1px solid var(--border);
  }

  .login-intro h1 {
    margin-top: var(--space-2);
    font-size: var(--text-heading);
  }

  .login-caption {
    display: none;
  }

  .login-context {
    margin-top: var(--space-5);
  }

  .login-main {
    padding: var(--space-6) var(--space-5) var(--space-10);
  }
}

/* ---------- 页脚 ---------- */
.footer {
  display: flex;
  justify-content: space-between;
  gap: var(--space-4);
  flex-wrap: wrap;
  max-inline-size: var(--container-max);
  margin: var(--space-7) auto 0;
  padding: 0 var(--gutter) var(--space-7);
  color: var(--text-tertiary);
  font-size: var(--text-caption);
}
