: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);
  min-height: 100vh;
}

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;
}

.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;
  overflow: hidden;
}

.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;
}

.view {
  display: none;
}

.view.active {
  display: block;
}

.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,
.docs-layout {
  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);
}

.wide {
  grid-column: 1 / -1;
}

.primary-button,
.secondary-button,
.ghost-button,
.icon-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;
}

.icon-button {
  width: 42px;
  padding: 0;
  background: var(--surface);
  border-color: var(--line);
  font-size: 20px;
}

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

.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);
}

.api-stack {
  display: grid;
  gap: 18px;
}

.doc-panel {
  align-self: start;
}

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

.doc-grid article {
  background: #f6f8f7;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 14px;
}

.doc-grid h4 {
  margin: 0 0 8px;
}

.doc-grid p,
.code-note {
  margin: 0;
  color: var(--muted);
  line-height: 1.7;
}

.steps {
  padding-left: 20px;
  margin: 12px 0 0;
  color: var(--muted);
  line-height: 1.8;
}

.code-panel {
  background: #101917;
  color: #ecf7f4;
}

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

.endpoint span {
  background: #dff5ef;
  color: #0d635b;
  border-radius: 6px;
  padding: 4px 8px;
  font-weight: 900;
  font-size: 12px;
}

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

.code-note {
  color: #b9c9c5;
  margin-bottom: 10px;
}

.error-list {
  display: grid;
  gap: 10px;
}

.error-list div {
  display: grid;
  grid-template-columns: minmax(220px, 0.32fr) minmax(0, 1fr);
  gap: 12px;
  align-items: center;
  padding: 12px 0;
  border-bottom: 1px solid var(--line);
}

.error-list div:last-child {
  border-bottom: 0;
}

.error-list span {
  color: var(--muted);
}

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

dialog {
  border: 0;
  border-radius: 8px;
  padding: 0;
  box-shadow: 0 30px 80px rgba(0, 0, 0, 0.25);
}

dialog::backdrop {
  background: rgba(12, 23, 21, 0.45);
}

.dialog-card {
  width: min(440px, 92vw);
  padding: 22px;
  display: grid;
  gap: 16px;
}

.dialog-card h3 {
  margin: 0;
}

.dialog-help {
  margin: 0;
  color: var(--muted);
  line-height: 1.7;
}

.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;
  }

  .sidebar {
    min-height: auto;
  }

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

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

  .stats-grid,
  .main-grid,
  .docs-layout,
  .doc-grid,
  .error-list div {
    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;
  gap: 18px;
}

.project-card {
  padding: 20px;
}

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

.project-card-head h3 {
  margin: 0 0 6px;
}

.project-actions {
  display: flex;
  gap: 8px;
  flex-shrink: 0;
}

/* 总览页：到期预警 */
.expire-list {
  display: grid;
  gap: 12px;
}

.expire-item {
  padding: 12px;
  background: var(--surface-soft);
  border: 1px solid var(--line);
  border-radius: 8px;
}

.expire-main {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 6px;
}

.expire-main code {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  overflow-wrap: anywhere;
  font-size: 13px;
}

.expire-meta {
  display: flex;
  gap: 16px;
  color: var(--muted);
  font-size: 13px;
}

/* 表格链接 */
.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;
}

/* Secret Key 隐藏字段 */
.secret-field {
  display: flex;
  align-items: center;
  gap: 8px;
}

.secret-masked {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}
