:root {
  --paper: #f7f3e8;
  --paper-2: #fffdf7;
  --ink: #22262f;
  --muted: #6b6f78;
  --line: #e2dccb;
  --indigo: #303a8f;
  --indigo-soft: #e8e9f7;
  --mint: #2f7f6b;
  --mint-soft: #e3f2ec;
  --honey: #b9791f;
  --honey-soft: #f8ecd8;
  --danger: #a33a32;
  --danger-soft: #f7e6e3;
  --shadow: 0 1px 0 rgba(34, 38, 47, 0.04), 0 8px 24px rgba(34, 38, 47, 0.06);
  --radius: 14px;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  padding: 0;
}

body {
  background: var(--paper);
  color: var(--ink);
  font-family: "Segoe UI", "PingFang SC", "Microsoft YaHei", system-ui, -apple-system, sans-serif;
  font-size: 15px;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
}

a {
  color: var(--indigo);
  text-decoration: none;
}

a:hover {
  text-decoration: underline;
}

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

.boot {
  padding: 64px;
  text-align: center;
  color: var(--muted);
}

/* ---------- 顶栏 ---------- */

.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  gap: 24px;
  padding: 12px 28px;
  background: rgba(247, 243, 232, 0.94);
  border-bottom: 1px solid var(--line);
  backdrop-filter: blur(8px);
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  color: var(--ink);
  text-decoration: none;
  min-width: 180px;
}

.brand:hover {
  text-decoration: none;
}

.brand strong {
  display: block;
  font-size: 16px;
  letter-spacing: 0.02em;
}

.brand small {
  display: block;
  color: var(--muted);
  font-size: 12px;
}

.brand-mark {
  display: inline-grid;
  place-items: center;
  width: 34px;
  height: 34px;
  border-radius: 10px;
  background: var(--indigo);
  color: #fff;
  font-weight: 700;
  font-family: Georgia, "Times New Roman", serif;
}

.nav {
  display: flex;
  gap: 4px;
  flex: 1;
  flex-wrap: wrap;
}

.nav-link {
  padding: 7px 12px;
  border-radius: 9px;
  color: var(--muted);
  font-size: 14px;
}

.nav-link:hover {
  background: var(--indigo-soft);
  color: var(--indigo);
  text-decoration: none;
}

.nav-link.active {
  background: var(--indigo);
  color: #fff;
}

.account-chip {
  display: grid;
  grid-template-columns: auto auto;
  align-items: center;
  gap: 0 14px;
  font-size: 13px;
}

.account-name {
  font-weight: 600;
}

.account-meta {
  color: var(--muted);
  font-size: 12px;
}

.role-row {
  display: flex;
  gap: 4px;
  grid-column: 1 / -1;
}

.account-chip .btn {
  grid-column: 2;
  grid-row: 1 / span 2;
}

.badge {
  display: inline-block;
  padding: 1px 8px;
  border-radius: 999px;
  background: var(--indigo-soft);
  color: var(--indigo);
  font-size: 12px;
  line-height: 1.7;
}

/* ---------- 页面 ---------- */

.page {
  max-width: 1180px;
  margin: 0 auto;
  padding: 28px 28px 56px;
}

.page-head {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 20px;
  margin-bottom: 18px;
}

.page-head h1 {
  margin: 0 0 4px;
  font-size: 28px;
  letter-spacing: 0.01em;
}

.page-head p {
  margin: 0;
}

.back {
  display: inline-block;
  margin-bottom: 8px;
  font-size: 13px;
}

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

.small {
  font-size: 13px;
}

.panel {
  background: var(--paper-2);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 20px 22px;
  margin-bottom: 18px;
}

.panel h2 {
  margin: 0 0 10px;
  font-size: 18px;
}

.panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
}

.subpanel {
  margin: 12px 0 18px;
  padding: 14px 16px;
  border: 1px dashed var(--line);
  border-radius: 12px;
  background: #fbf8ef;
}

.detail-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1.2fr);
  gap: 18px;
}

.detail-grid .panel {
  margin-bottom: 0;
}

.detail-grid + .panel {
  margin-top: 18px;
}

/* ---------- 表格 ---------- */

.table-wrap {
  overflow-x: auto;
  margin: 6px 0;
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 14px;
}

th,
td {
  padding: 10px 12px;
  border-bottom: 1px solid var(--line);
  text-align: left;
  vertical-align: top;
}

th {
  color: var(--muted);
  font-weight: 600;
  font-size: 12px;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  white-space: nowrap;
}

tbody tr:hover {
  background: #fbf8ef;
}

table.compact th,
table.compact td {
  padding: 7px 10px;
}

code {
  font-family: "Cascadia Code", Consolas, monospace;
  font-size: 12.5px;
  background: #f1ecdd;
  padding: 1px 5px;
  border-radius: 5px;
}

/* ---------- 表单 ---------- */

.form {
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.grid-form {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 14px 18px;
}

.grid-form .form-error,
.grid-form .form-actions {
  grid-column: 1 / -1;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 5px;
  font-size: 14px;
}

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

.field-hint {
  color: var(--muted);
  font-size: 12px;
}

input,
select,
textarea {
  font: inherit;
  color: var(--ink);
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 9px;
  padding: 8px 10px;
  min-width: 0;
}

input:focus,
select:focus,
textarea:focus,
button:focus-visible,
a:focus-visible {
  outline: 2px solid var(--indigo);
  outline-offset: 2px;
}

textarea {
  resize: vertical;
}

.form-actions {
  display: flex;
  gap: 10px;
  align-items: center;
  flex-wrap: wrap;
}

.form-error {
  margin: 0;
  color: var(--danger);
  background: var(--danger-soft);
  border-radius: 8px;
  padding: 8px 10px;
  font-size: 13px;
}

.form-error.small {
  display: inline-block;
  margin-top: 4px;
}

.checks {
  display: flex;
  gap: 10px 16px;
  flex-wrap: wrap;
}

.check {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 13px;
}

.inline {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  color: var(--muted);
}

/* ---------- 按钮 ---------- */

.btn {
  font: inherit;
  border: 1px solid var(--line);
  background: #fff;
  color: var(--ink);
  border-radius: 9px;
  padding: 7px 14px;
  cursor: pointer;
  transition: background 120ms ease, border-color 120ms ease, transform 80ms ease;
  white-space: nowrap;
}

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

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

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

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

.btn.primary:hover:not(:disabled) {
  background: #26307a;
  color: #fff;
}

.btn.ghost {
  background: transparent;
}

.btn.small {
  padding: 4px 10px;
  font-size: 13px;
}

.link {
  border: 0;
  background: none;
  color: var(--indigo);
  font: inherit;
  padding: 0;
  cursor: pointer;
}

.link:hover {
  text-decoration: underline;
}

/* ---------- 状态与提示 ---------- */

.flash-slot {
  max-width: 1180px;
  margin: 0 auto;
  padding: 0 28px;
}

.flash {
  margin: 12px 0 0;
  padding: 9px 14px;
  border-radius: 9px;
  font-size: 14px;
  background: var(--mint-soft);
  color: #215f50;
  border: 1px solid #c6e3d8;
}

.flash.error {
  background: var(--danger-soft);
  color: var(--danger);
  border-color: #eecfcb;
}

.flash.ok {
  background: var(--mint-soft);
}

.status {
  display: inline-block;
  padding: 2px 9px;
  border-radius: 999px;
  font-size: 12px;
  background: #eee9da;
  color: #595445;
}

.status.active {
  background: var(--mint-soft);
  color: #23624f;
}

.status.paused {
  background: var(--honey-soft);
  color: #7c5314;
}

.status.archived {
  background: #ecebea;
  color: #5f5b55;
}

.empty {
  color: var(--muted);
  padding: 18px 4px;
  text-align: center;
}

.loading {
  color: var(--muted);
  text-align: center;
  padding: 48px;
}

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

.notice-box {
  background: var(--honey-soft);
  border: 1px solid #ecd7b4;
  border-radius: 10px;
  padding: 12px 14px;
  margin: 8px 0 16px;
  font-size: 14px;
}

.context-out {
  max-height: 420px;
  overflow: auto;
  background: #1f2430;
  color: #e9e5d8;
  border-radius: 10px;
  padding: 14px;
  font-size: 12.5px;
  line-height: 1.55;
  white-space: pre-wrap;
  word-break: break-word;
}

.answer {
  margin-top: 14px;
  border-top: 1px solid var(--line);
  padding-top: 12px;
}

.answer h3 {
  margin: 0 0 4px;
  font-size: 16px;
}

.answer-text {
  white-space: pre-wrap;
  font-size: 14.5px;
  line-height: 1.7;
}

.facts {
  display: grid;
  grid-template-columns: max-content 1fr;
  gap: 6px 18px;
  margin: 8px 0 12px;
  font-size: 14px;
}

.facts dt {
  color: var(--muted);
}

.facts dd {
  margin: 0;
}

.pagination {
  display: flex;
  align-items: center;
  gap: 12px;
  justify-content: flex-end;
  padding-top: 10px;
}

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

.link-row {
  display: flex;
  gap: 18px;
  flex-wrap: wrap;
  align-items: center;
}

.toolbar {
  display: flex;
  gap: 10px;
  align-items: center;
  margin-bottom: 14px;
  flex-wrap: wrap;
}

.toolbar .grow {
  flex: 1;
  min-width: 220px;
}

.plain-list {
  margin: 8px 0;
  padding-left: 20px;
  color: #444a55;
  font-size: 14px;
}

.plain-list li {
  margin-bottom: 6px;
}

/* ---------- 登录 ---------- */

.auth-wrap {
  min-height: 100vh;
  display: grid;
  grid-template-columns: minmax(0, 0.9fr) minmax(320px, 420px);
  gap: 56px;
  align-items: center;
  justify-content: center;
  padding: 56px clamp(20px, 8vw, 120px);
  background:
    radial-gradient(circle at 18% 22%, rgba(48, 58, 143, 0.1), transparent 42%),
    radial-gradient(circle at 82% 78%, rgba(47, 127, 107, 0.1), transparent 44%),
    var(--paper);
}

.auth-brand .brand-mark {
  width: 48px;
  height: 48px;
  font-size: 22px;
  border-radius: 14px;
  margin-bottom: 18px;
}

.auth-brand strong {
  font-family: Georgia, "Songti SC", serif;
  font-size: 40px;
  line-height: 1.2;
  letter-spacing: 0.02em;
}

.auth-brand p {
  color: var(--muted);
  font-size: 15px;
  margin-top: 10px;
}

.auth-card {
  background: var(--paper-2);
  border: 1px solid var(--line);
  border-radius: 18px;
  box-shadow: var(--shadow);
  padding: 30px 28px;
}

.auth-card h1 {
  margin: 0 0 4px;
  font-size: 24px;
}

.auth-card .muted {
  margin-top: 0;
  font-size: 14px;
}

.auth-footer {
  margin-top: 18px;
  padding-top: 14px;
  border-top: 1px solid var(--line);
}

/* ---------- 页脚 ---------- */

.footer {
  max-width: 1180px;
  margin: 0 auto;
  padding: 0 28px 32px;
  color: var(--muted);
  font-size: 12.5px;
}

/* ---------- Excel 导入 ---------- */

.file-button {
  display: inline-flex;
  align-items: center;
}

.import-panel:empty {
  display: none;
}

.import-panel {
  border: 1px dashed var(--line);
  border-radius: 12px;
  background: #fbf8ef;
  padding: 14px 16px;
  margin: 12px 0;
}

.import-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
  margin-bottom: 6px;
}

/* ---------- 看板 ---------- */

.stat-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 12px;
  margin-bottom: 18px;
}

.stat {
  background: var(--paper-2);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 14px 16px;
  box-shadow: var(--shadow);
}

.stat-label {
  display: block;
  color: var(--muted);
  font-size: 12px;
}

.stat strong {
  display: block;
  margin: 4px 0 2px;
  font-size: 26px;
  line-height: 1.2;
  font-variant-numeric: tabular-nums;
}

.stat-hint {
  color: var(--muted);
  font-size: 11.5px;
}

.field-aggregates {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 12px;
}

.aggregate-card {
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #fbf8ef;
  padding: 12px 14px;
}

.aggregate-title {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 8px;
  font-weight: 600;
  margin-bottom: 6px;
}

.aggregate-title code {
  font-size: 11px;
}

.aggregate-card .plain-list {
  margin: 0;
  font-size: 13px;
}

/* ---------- 项目分区 ---------- */

.tabs {
  display: flex;
  gap: 4px;
  border-bottom: 1px solid var(--line);
  margin: 0 0 18px;
  flex-wrap: wrap;
}

.tab {
  padding: 8px 16px;
  border-radius: 10px 10px 0 0;
  color: var(--muted);
  font-size: 14px;
  border: 1px solid transparent;
  border-bottom: 0;
}

.tab:hover {
  color: var(--indigo);
  background: var(--indigo-soft);
  text-decoration: none;
}

.tab.active {
  background: var(--paper-2);
  border-color: var(--line);
  color: var(--indigo);
  font-weight: 600;
  margin-bottom: -1px;
}

.field-rows {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin: 12px 0;
}

.field-row {
  display: grid;
  grid-template-columns: 1.1fr 1.2fr 0.9fr 0.9fr auto auto 1.5fr;
  gap: 8px 10px;
  align-items: end;
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 10px 12px;
  background: #fbf8ef;
}

.field-row label {
  display: flex;
  flex-direction: column;
  gap: 3px;
  font-size: 12px;
  color: var(--muted);
}

.field-row label.check {
  flex-direction: row;
  align-items: center;
  gap: 5px;
  padding-bottom: 6px;
  white-space: nowrap;
}

.field-row input,
.field-row select {
  padding: 6px 8px;
  font-size: 13px;
}

@media (max-width: 900px) {
  .field-row {
    grid-template-columns: 1fr 1fr;
  }
}

/* ---------- 响应式 ---------- */

@media (max-width: 900px) {
  .topbar {
    flex-wrap: wrap;
    gap: 10px 16px;
    padding: 12px 18px;
  }

  .brand {
    min-width: 0;
  }

  .nav {
    order: 3;
    width: 100%;
  }

  .account-chip {
    margin-left: auto;
  }

  .page {
    padding: 20px 18px 44px;
  }

  .detail-grid {
    grid-template-columns: 1fr;
  }

  .auth-wrap {
    grid-template-columns: 1fr;
    gap: 28px;
    padding: 32px 18px;
  }

  .auth-brand strong {
    font-size: 30px;
  }

  .flash-slot,
  .footer {
    padding-left: 18px;
    padding-right: 18px;
  }
}

@media (max-width: 520px) {
  .page-head {
    flex-direction: column;
    align-items: flex-start;
  }

  .auth-card {
    padding: 22px 18px;
  }

  .account-meta {
    display: none;
  }
}
