:root {
  color-scheme: light;
  --bg: #f5f7fb;
  --panel: #ffffff;
  --text: #172033;
  --muted: #617089;
  --line: #dce3ee;
  --accent: #0b6bcb;
  --accent-dark: #074f96;
  --soft: #edf5ff;
  --danger: #b42318;
  --success: #17854f;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  min-height: 100vh;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", "Microsoft YaHei", sans-serif;
  background: var(--bg);
  color: var(--text);
}

button, input, select, textarea { font: inherit; }

.login-shell, .portal-shell {
  width: min(1040px, calc(100vw - 32px));
  margin: 0 auto;
}

.login-shell {
  min-height: 100vh;
  display: grid;
  align-items: center;
  justify-items: start;
  position: relative;
  isolation: isolate;
  padding: 32px 0;
}

.login-background {
  position: fixed;
  inset: 0;
  z-index: 0;
  background-image:
    linear-gradient(120deg, rgba(7, 28, 52, 0.96) 0%, rgba(7, 79, 150, 0.72) 42%, rgba(245, 247, 251, 0.18) 100%),
    radial-gradient(circle at 18% 24%, rgba(255, 255, 255, 0.18), transparent 20%),
    radial-gradient(circle at 82% 26%, rgba(255, 255, 255, 0.12), transparent 18%),
    repeating-linear-gradient(110deg, rgba(255, 255, 255, 0.06) 0 2px, transparent 2px 54px),
    repeating-linear-gradient(70deg, rgba(255, 255, 255, 0.04) 0 2px, transparent 2px 92px),
    linear-gradient(180deg, rgba(245, 247, 251, 0.05), rgba(7, 28, 52, 0.08));
  background-size: cover;
  background-position: center;
}

.login-background::after {
  content: "";
  position: absolute;
  inset: 0;
  background:
    linear-gradient(180deg, rgba(245, 247, 251, 0.06), rgba(7, 28, 52, 0.16)),
    linear-gradient(90deg, rgba(255, 255, 255, 0.04), rgba(255, 255, 255, 0.01));
  backdrop-filter: blur(0.5px);
}

.login-panel {
  position: relative;
  z-index: 1;
  width: min(440px, 100%);
  background: rgba(255, 255, 255, 0.94);
  border: 1px solid rgba(220, 227, 238, 0.82);
  border-top: 4px solid var(--accent);
  border-radius: 8px;
  padding: 32px;
  box-shadow: 0 26px 72px rgba(7, 28, 52, 0.32);
  backdrop-filter: blur(10px);
}

.login-panel-head,
.header-actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.language-switcher {
  display: inline-flex;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff;
}

.language-switcher button {
  min-width: 64px;
  padding: 7px 10px;
  border-radius: 0;
  background: transparent;
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

.language-switcher button + button {
  border-left: 1px solid var(--line);
}

.language-switcher button:hover {
  background: var(--soft);
  color: var(--accent-dark);
}

.language-switcher button.active {
  background: var(--accent);
  color: #fff;
}

.login-subtitle {
  margin: 12px 0 0;
  color: var(--muted);
  line-height: 1.6;
}

.eyebrow {
  margin: 0 0 8px;
  color: var(--accent);
  font-size: 13px;
  font-weight: 700;
  text-transform: uppercase;
}

h1 { margin: 0; font-size: 32px; line-height: 1.1; }

.login-form { display: grid; gap: 12px; margin-top: 28px; }

label { font-size: 14px; color: var(--muted); }

input, select, textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 12px;
  background: #fff;
  color: var(--text);
}

input:focus, select:focus, textarea:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(11, 107, 203, 0.14);
  outline: none;
}

textarea {
  min-height: 140px;
  resize: vertical;
}

button {
  border: 0;
  border-radius: 6px;
  padding: 12px 16px;
  background: var(--accent);
  color: #fff;
  font-weight: 700;
  cursor: pointer;
}

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

button.secondary {
  background: #edf2f7;
  color: var(--text);
}

.error { color: var(--danger); margin: 16px 0 0; }

.notice-backdrop {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: grid;
  place-items: start center;
  padding-top: 28px;
  background: rgba(23, 32, 38, 0.18);
}

.notice-dialog {
  width: min(420px, calc(100vw - 32px));
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 18px;
  padding: 16px;
  border: 1px solid var(--line);
  border-left: 5px solid var(--success);
  border-radius: 8px;
  background: #fff;
  box-shadow: 0 18px 45px rgba(23, 32, 38, 0.18);
}

.notice-dialog.error { border-left-color: var(--danger); }
.notice-dialog h2 { margin: 0; font-size: 18px; }
.notice-dialog p { margin: 6px 0 0; color: var(--muted); }
.notice-dialog button { white-space: nowrap; }

.portal-shell { padding: 40px 0; }

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

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

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

.portal-tabs a {
  display: inline-flex;
  padding: 10px 12px;
  color: var(--muted);
  text-decoration: none;
  border-bottom: 3px solid transparent;
}

.portal-tabs a.active {
  color: var(--text);
  border-color: var(--accent);
  font-weight: 700;
}

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

.project-card {
  display: grid;
  gap: 10px;
  min-height: 150px;
  padding: 18px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  color: inherit;
  text-decoration: none;
}

.project-card:hover {
  border-color: var(--accent);
  box-shadow: 0 16px 36px rgba(23, 32, 51, 0.08);
  transform: translateY(-1px);
}

.project-meta {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.project-id { color: var(--muted); font-size: 13px; }
.health-badge {
  display: inline-flex;
  align-items: center;
  min-height: 24px;
  padding: 3px 8px;
  border: 1px solid var(--line);
  border-radius: 999px;
  font-size: 12px;
  font-weight: 700;
  white-space: nowrap;
}
.health-ok { background: #eef7f2; color: #166534; border-color: #b7e1c5; }
.health-error { background: #fff4f2; color: #b42318; border-color: #f2bbb3; }
.health-unknown { background: #f3f5f6; color: var(--muted); }
.project-card strong { font-size: 21px; }
.project-card span:last-child { color: var(--muted); line-height: 1.45; }

.panel {
  display: grid;
  gap: 18px;
  padding: 18px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
}

.section-head h2, .form-grid h3 { margin: 0; }
.section-head p { margin: 8px 0 0; color: var(--muted); }

.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; min-width: 720px; }
th, td { padding: 10px; border-top: 1px solid var(--line); text-align: left; vertical-align: middle; }
th { color: var(--muted); font-size: 13px; }

.inline-form {
  display: flex;
  gap: 8px;
  align-items: center;
}

.inline-form input { min-width: 160px; padding: 9px; }
.inline-form button { padding: 9px 12px; white-space: nowrap; }

.permission-form {
  display: grid;
  gap: 8px;
}

.project-permissions {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 6px 10px;
  min-width: 280px;
}

.check-row {
  display: flex;
  align-items: center;
  gap: 6px;
  color: var(--text);
  font-size: 13px;
}

.check-row input {
  width: auto;
  margin: 0;
}

.form-fieldset {
  grid-column: 1 / -1;
  display: grid;
  gap: 8px;
  margin: 0;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 6px;
}

.form-fieldset legend {
  padding: 0 6px;
  color: var(--muted);
  font-size: 14px;
}

.form-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 12px;
  align-items: end;
}

.form-grid h3 {
  grid-column: 1 / -1;
}

.form-grid label {
  display: grid;
  gap: 6px;
}

.form-grid .form-full {
  grid-column: 1 / -1;
}

.docs-panel {
  align-items: start;
}

.docs-layout {
  display: grid;
  grid-template-columns: minmax(260px, 360px) 1fr;
  gap: 16px;
  align-items: start;
}

.docs-index {
  display: grid;
  gap: 12px;
}

.doc-tools {
  display: grid;
  grid-template-columns: minmax(240px, 520px) minmax(160px, 220px);
  gap: 12px;
  align-items: end;
}

.doc-quick-links {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.doc-quick-links a {
  display: inline-flex;
  align-items: center;
  min-height: 34px;
  padding: 6px 10px;
  border: 1px solid var(--line);
  border-radius: 6px;
  color: var(--text);
  font-size: 13px;
  font-weight: 700;
  text-decoration: none;
  background: #fff;
}

.doc-quick-links a:hover {
  border-color: var(--accent);
  color: var(--accent);
}

.doc-search,
.doc-filter {
  display: grid;
  gap: 6px;
}

.doc-search input,
.doc-filter select {
  min-height: 42px;
}

.doc-project {
  display: grid;
  gap: 8px;
  padding: 0;
  border-bottom: 1px solid var(--line);
}

.doc-project-toggle {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  min-height: 52px;
  padding: 10px 0;
  cursor: pointer;
  list-style: none;
}

.doc-project-toggle::-webkit-details-marker {
  display: none;
}

.doc-project-toggle::before {
  content: "›";
  display: inline-grid;
  place-items: center;
  width: 18px;
  height: 18px;
  border: 1px solid var(--line);
  border-radius: 50%;
  color: var(--muted);
  transform: rotate(0deg);
}

.doc-project[open] .doc-project-toggle::before {
  transform: rotate(90deg);
}

.doc-project-toggle > span:first-child {
  display: grid;
  flex: 1;
  gap: 2px;
}

.doc-project-toggle strong {
  font-size: 15px;
}

.doc-project-toggle small {
  color: var(--muted);
  font-size: 12px;
}

.doc-project-body {
  display: grid;
  gap: 10px;
  padding: 0 0 12px 28px;
}

.doc-section-label {
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

.doc-status {
  display: inline-flex;
  align-items: center;
  min-height: 24px;
  padding: 3px 8px;
  border: 1px solid var(--line);
  border-radius: 999px;
  font-size: 12px;
  font-weight: 700;
  white-space: nowrap;
}

.doc-status.ok {
  color: #166534;
  background: #eef7f2;
  border-color: #b7e1c5;
}

.doc-status.missing {
  color: #8a5a00;
  background: #fff8e8;
  border-color: #edd28f;
}

.doc-status.risk {
  color: var(--danger);
  background: #fff4f2;
  border-color: #f2bbb3;
}

.doc-status.unknown {
  color: var(--muted);
  background: #f3f5f6;
}

.doc-list {
  display: grid;
  gap: 6px;
}

.doc-link {
  display: grid;
  gap: 4px;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 6px;
  color: inherit;
  text-decoration: none;
  background: #fff;
}

.doc-link:hover { border-color: var(--accent); }
.doc-link strong { font-size: 14px; }
.doc-link span,
.doc-link time {
  color: var(--muted);
  font-size: 12px;
  line-height: 1.45;
  overflow-wrap: anywhere;
}

.doc-core-list .doc-link {
  border-color: #d8e4df;
  background: #fbfffd;
}

.doc-more-docs {
  display: grid;
  gap: 8px;
}

.doc-more-docs > summary {
  width: fit-content;
  cursor: pointer;
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

.doc-more-docs[open] > summary {
  color: var(--text);
}

.doc-more-docs .doc-list {
  margin-top: 8px;
}

.doc-viewer {
  min-width: 0;
  display: grid;
  gap: 12px;
  padding: 16px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfcfc;
}

.markdown-body {
  max-height: 68vh;
  overflow: auto;
  overflow-wrap: anywhere;
  font-family: "Microsoft YaHei", ui-sans-serif, system-ui, sans-serif;
  font-size: 14px;
  line-height: 1.7;
}

.markdown-body h1,
.markdown-body h2,
.markdown-body h3,
.markdown-body h4 {
  margin: 20px 0 8px;
  line-height: 1.3;
}

.markdown-body h1:first-child,
.markdown-body h2:first-child,
.markdown-body h3:first-child {
  margin-top: 0;
}

.markdown-body h1 { font-size: 24px; }
.markdown-body h2 { font-size: 20px; }
.markdown-body h3 { font-size: 17px; }
.markdown-body p { margin: 0 0 12px; }
.markdown-body ul { margin: 0 0 12px 20px; padding: 0; }
.markdown-body pre {
  margin: 0 0 14px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #f3f5f6;
  overflow: auto;
}

.markdown-body code {
  font-family: Consolas, "SFMono-Regular", monospace;
}

.doc-viewer.empty {
  min-height: 220px;
  align-content: center;
}

@media (max-width: 640px) {
  .portal-header,
  .notice-dialog {
    align-items: stretch;
    flex-direction: column;
  }

  .header-actions {
    align-items: stretch;
    flex-direction: column;
  }

  .header-actions > form,
  .header-actions > form button {
    width: 100%;
  }

  .language-switcher {
    width: 100%;
  }

  .language-switcher button {
    flex: 1;
  }

  h1 { font-size: 28px; }

  .docs-layout {
    grid-template-columns: 1fr;
  }

  .doc-tools {
    grid-template-columns: 1fr;
  }

  .doc-project-body {
    padding-left: 0;
  }

  .doc-project-toggle::before {
    display: none;
  }
}
