:root {
  color-scheme: light;
  --bg: #f5f7f6;
  --surface: #ffffff;
  --surface-soft: #eef4f1;
  --ink: #17211f;
  --muted: #65716d;
  --line: #d9e1de;
  --primary: #147a73;
  --primary-dark: #0e5f59;
  --accent: #c56b35;
  --danger: #ba3349;
  --good: #168054;
  --warn: #b87712;
  --shadow: 0 18px 45px rgba(20, 38, 35, 0.1);
  font-family: Inter, "PingFang SC", "Microsoft YaHei", system-ui, sans-serif;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--ink);
}

button,
input,
select {
  font: inherit;
}

button {
  cursor: pointer;
}

.app-shell {
  display: none;
  grid-template-columns: 280px minmax(0, 1fr);
  height: 100vh;
  overflow: hidden;
}

body.authenticated .app-shell {
  display: grid;
}

body.authenticated .login-screen {
  display: none;
}

.login-screen {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
  background:
    linear-gradient(135deg, rgba(20, 122, 115, 0.1), rgba(197, 107, 53, 0.08)),
    var(--bg);
}

.login-card {
  width: min(420px, 100%);
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
  padding: 28px;
  display: grid;
  gap: 16px;
}

.login-card h1 {
  margin: 0;
  font-size: 30px;
}

.login-subtitle {
  margin: 8px 0 0;
  color: var(--muted);
}

.form-error {
  min-height: 20px;
  margin: 0;
  color: var(--danger);
  font-size: 13px;
  font-weight: 700;
}

.sidebar {
  background: #152522;
  color: #f3f8f6;
  padding: 24px;
  display: flex;
  flex-direction: column;
  gap: 28px;
  overflow-y: auto;
  overscroll-behavior: contain;
}

.brand {
  display: flex;
  align-items: center;
  gap: 14px;
}

.brand h1,
.brand p,
.topbar h2,
.panel h3 {
  margin: 0;
}

.brand h1 {
  font-size: 20px;
}

.brand p {
  color: #b6c7c2;
  margin-top: 4px;
  font-size: 13px;
}

.nav {
  display: grid;
  gap: 8px;
}

.nav-item {
  border: 0;
  width: 100%;
  text-align: left;
  background: transparent;
  color: #d8e5e1;
  padding: 12px 14px;
  border-radius: 8px;
  text-decoration: none;
  display: block;
}

.nav-item:hover,
.nav-item.active {
  background: rgba(255, 255, 255, 0.11);
  color: #ffffff;
}

.side-panel {
  margin-top: auto;
  display: grid;
  gap: 12px;
  padding: 16px;
  border: 1px solid rgba(255, 255, 255, 0.14);
  border-radius: 8px;
}

.side-panel select {
  background: #f9fbfa;
}

.workspace {
  padding: 28px;
  height: 100vh;
  overflow-y: auto;
  overflow-x: hidden;
  overscroll-behavior: contain;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 24px;
}

.topbar h2 {
  font-size: 30px;
  letter-spacing: 0;
}

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

.eyebrow {
  margin: 0 0 7px;
  color: var(--accent);
  font-size: 12px;
  font-weight: 800;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.stats-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 16px;
  margin-bottom: 18px;
}

.stat,
.panel {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.stat {
  padding: 18px;
}

.stat span {
  color: var(--muted);
  display: block;
  margin-bottom: 10px;
}

.stat strong {
  font-size: 34px;
}

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

.panel {
  padding: 20px;
  min-width: 0;
}

.panel-head {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 16px;
  margin-bottom: 18px;
}

.table-head {
  align-items: center;
}

.table-tools {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 10px;
  flex-wrap: wrap;
}

.badge {
  display: inline-flex;
  align-items: center;
  min-height: 28px;
  padding: 4px 10px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 700;
  background: #eef1f0;
  color: var(--muted);
  white-space: nowrap;
}

.badge.good {
  background: #e5f5ee;
  color: var(--good);
}

.badge.warn {
  background: #fff2d9;
  color: var(--warn);
}

.badge.bad {
  background: #fae4e8;
  color: var(--danger);
}

.detail-list {
  display: grid;
  gap: 12px;
  margin: 0 0 18px;
}

.detail-list div {
  display: grid;
  gap: 5px;
}

.detail-list dt {
  color: var(--muted);
  font-size: 13px;
}

.detail-list dd {
  margin: 0;
  overflow-wrap: anywhere;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}

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

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

label {
  display: grid;
  gap: 7px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

input,
select {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--ink);
  min-height: 42px;
  padding: 9px 11px;
  outline: none;
}

input:focus,
select:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(20, 122, 115, 0.12);
}

.primary-button,
.secondary-button,
.ghost-button {
  border: 1px solid transparent;
  min-height: 42px;
  border-radius: 8px;
  padding: 9px 14px;
  font-weight: 800;
}

.primary-button {
  background: var(--primary);
  color: white;
}

.primary-button:hover {
  background: var(--primary-dark);
}

.secondary-button {
  background: var(--surface-soft);
  color: var(--ink);
  border-color: var(--line);
}

.ghost-button {
  background: transparent;
  color: #f5fbf9;
  border-color: rgba(255, 255, 255, 0.22);
}

.ghost-button.subtle {
  min-height: 34px;
  padding: 6px 10px;
  font-size: 12px;
}

.account-line {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  color: #cfe0dc;
  font-size: 13px;
}

.search {
  max-width: 320px;
}

.table-wrap {
  overflow: auto;
}

table {
  width: 100%;
  min-width: 850px;
  border-collapse: collapse;
}

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

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

td code {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  overflow-wrap: anywhere;
}

.row-actions {
  display: flex;
  gap: 8px;
}

.mini-button {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  min-height: 34px;
  padding: 5px 9px;
  font-size: 12px;
  font-weight: 800;
}

.mini-button.bad {
  color: var(--danger);
}

pre {
  margin: 0 0 18px;
  padding: 15px;
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.08);
  overflow: auto;
  line-height: 1.55;
}

.result-panel pre {
  background: #f5f7f6;
  color: var(--ink);
  min-height: 250px;
}

dialog {
  border: 0;
  border-radius: 16px;
  padding: 0;
  background: var(--surface);
  color: var(--ink);
  max-width: 92vw;
  max-height: 90vh;
  overflow: auto;
  box-shadow: 0 32px 90px rgba(10, 25, 22, 0.32);
}

dialog::backdrop {
  background: rgba(12, 23, 21, 0.52);
  backdrop-filter: blur(4px);
}

dialog[open] {
  animation: dialog-pop 0.18s ease-out;
}

@keyframes dialog-pop {
  from {
    opacity: 0;
    transform: translateY(12px) scale(0.97);
  }
  to {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

.dialog-card {
  width: min(460px, 92vw);
  padding: 26px;
  display: grid;
  gap: 18px;
}

.dialog-card h3 {
  margin: 0;
  font-size: 19px;
}

.dialog-head {
  display: flex;
  align-items: center;
  gap: 14px;
}

.dialog-head h3 {
  margin: 0 0 3px;
}

.dialog-sub {
  margin: 0;
  color: var(--muted);
  font-size: 12px;
}

.dialog-icon {
  flex-shrink: 0;
  width: 44px;
  height: 44px;
  border-radius: 13px;
  display: grid;
  place-items: center;
  font-size: 21px;
  font-weight: 900;
  background: rgba(20, 122, 115, 0.12);
  color: var(--primary);
}

.dialog-icon.danger {
  background: rgba(186, 51, 73, 0.12);
  color: var(--danger);
}

.dialog-help {
  margin: 0;
  line-height: 1.7;
}

.dialog-warn {
  margin: 0;
  padding: 11px 13px;
  border-radius: 9px;
  background: rgba(186, 51, 73, 0.07);
  border: 1px solid rgba(186, 51, 73, 0.2);
  color: #8d2436;
  font-size: 13px;
  line-height: 1.65;
}

.dialog-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
}

.danger-button {
  border: 1px solid transparent;
  min-height: 42px;
  border-radius: 8px;
  padding: 9px 16px;
  font-weight: 800;
  background: var(--danger);
  color: #ffffff;
}

.danger-button:hover {
  background: #9e2b3e;
}

.danger-button[disabled] {
  opacity: 0.6;
  cursor: not-allowed;
}

.toast {
  position: fixed;
  right: 24px;
  bottom: 24px;
  max-width: min(420px, calc(100vw - 48px));
  background: #142421;
  color: white;
  border-radius: 8px;
  padding: 13px 15px;
  box-shadow: var(--shadow);
  opacity: 0;
  transform: translateY(8px);
  pointer-events: none;
  transition: 0.18s ease;
}

.toast.show {
  opacity: 1;
  transform: translateY(0);
}

@media (max-width: 1000px) {
  /* 窄屏改为上下堆叠，交还文档流滚动，避免侧栏被裁剪 */
  .app-shell {
    grid-template-columns: 1fr;
    height: auto;
    overflow: visible;
  }

  .sidebar {
    min-height: auto;
    overflow-y: visible;
  }

  .workspace {
    height: auto;
    overflow: visible;
  }

  .nav {
    grid-template-columns: repeat(5, minmax(0, 1fr));
  }

  .side-panel {
    margin-top: 0;
  }

  .stats-grid,
  .main-grid {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 640px) {
  .workspace,
  .sidebar {
    padding: 18px;
  }

  .nav {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .topbar,
  .panel-head {
    align-items: stretch;
    flex-direction: column;
  }

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

  .search {
    max-width: none;
  }

  .table-tools {
    align-items: stretch;
    justify-content: stretch;
  }
}

/* 项目页 */
.view-header {
  display: flex;
  justify-content: flex-end;
  margin-bottom: 18px;
}

.projects-list {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(min(288px, 100%), 1fr));
  gap: 16px;
}

/* 正方形项目卡片 */
.project-card {
  aspect-ratio: 1 / 1;
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 16px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 14px;
  box-shadow: 0 2px 10px rgba(20, 38, 35, 0.05);
  overflow: hidden;
  transition: transform 0.18s ease, box-shadow 0.18s ease, border-color 0.18s ease;
}

.project-card:hover {
  transform: translateY(-2px);
  border-color: #c6d5d1;
  box-shadow: var(--shadow);
}

.project-card-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 10px;
}

.project-card-head h3 {
  margin: 0;
  font-size: 16px;
  line-height: 1.35;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.project-card .badge {
  min-height: 22px;
  padding: 2px 9px;
  font-size: 11px;
}

.project-card .detail-list {
  gap: 7px;
  margin: 0;
  min-width: 0;
}

.project-card .detail-list dt {
  font-size: 11px;
  letter-spacing: 0.03em;
}

/* 单行省略，保证内容高度可预测、不会把底部按钮挤出去 */
.project-card .detail-list dd {
  font-size: 12px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.project-card-actions {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 6px;
  margin-top: auto;
}

.mini-action {
  border: 1px solid var(--line);
  background: var(--surface-soft);
  color: var(--ink);
  border-radius: 8px;
  padding: 7px 4px;
  font-size: 12px;
  font-weight: 800;
  white-space: nowrap;
  transition: background 0.15s ease;
}

.mini-action:hover {
  background: #e1ebe7;
}

.mini-action.primary {
  background: var(--primary);
  border-color: transparent;
  color: #ffffff;
}

.mini-action.primary:hover {
  background: var(--primary-dark);
}

.mini-action.danger {
  color: var(--danger);
  border-color: rgba(186, 51, 73, 0.28);
  background: rgba(186, 51, 73, 0.06);
}

.mini-action.danger:hover {
  background: rgba(186, 51, 73, 0.14);
}

/* 表格链接 */
.table-link {
  color: var(--primary);
  text-decoration: none;
  font-weight: 700;
}

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

/* 空状态 */
.empty-hint {
  color: var(--muted);
  text-align: center;
  padding: 32px 16px;
  margin: 0;
}

/* 授权码筛选下拉 */
#licenseProjectFilter {
  max-width: 200px;
  min-width: 140px;
}
