:root {
  --bg: #f4f5f7;
  --surface: #ffffff;
  --ink: #111827;
  --muted: #6b7280;
  --line: #e5e7eb;
  --accent: #111827;
  --accent-hover: #374151;
  --green: #059669;
  --green-bg: #ecfdf5;
  --shadow: 0 1px 2px rgba(15, 23, 42, 0.06), 0 8px 24px rgba(15, 23, 42, 0.06);
  --radius: 12px;
  color-scheme: light;
}

* {
  box-sizing: border-box;
}

html,
body {
  height: 100%;
}

body {
  margin: 0;
  font-family:
    Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
    "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
  color: var(--ink);
  background: var(--bg);
}

button {
  font: inherit;
  cursor: pointer;
  border: 0;
}

.portal {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

.portal-header {
  background: var(--surface);
  border-bottom: 1px solid var(--line);
  padding: 0 28px;
  height: 64px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

.portal-header[hidden] {
  display: none !important;
}

.portal-brand {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
}

.portal-mark {
  width: 36px;
  height: 36px;
  border-radius: 10px;
  background: var(--accent);
  color: #fff;
  display: grid;
  place-items: center;
  font-size: 13px;
  font-weight: 700;
  letter-spacing: 0.04em;
  flex-shrink: 0;
}

.portal-brand-text {
  min-width: 0;
}

.portal-brand-label {
  font-size: 12px;
  color: var(--muted);
  line-height: 1.2;
}

.portal-brand-name {
  font-size: 16px;
  font-weight: 650;
  line-height: 1.3;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.portal-user {
  display: flex;
  align-items: center;
  gap: 12px;
}

.portal-avatar {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: #f3f4f6;
  border: 1px solid var(--line);
  display: grid;
  place-items: center;
  font-weight: 600;
  font-size: 15px;
  color: var(--accent);
  overflow: hidden;
}

.portal-avatar img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.portal-user-meta {
  text-align: right;
}

.portal-user-name {
  font-size: 14px;
  font-weight: 600;
  line-height: 1.3;
}

.portal-user-role {
  font-size: 12px;
  color: var(--muted);
  margin-top: 2px;
}

.btn-ghost {
  padding: 8px 14px;
  border-radius: 8px;
  background: transparent;
  color: var(--muted);
  border: 1px solid var(--line);
}

.btn-ghost:hover {
  color: var(--ink);
  border-color: #d1d5db;
  background: #fafafa;
}

.portal-manage-link {
  text-decoration: none;
  font-size: 13px;
  white-space: nowrap;
}

.profile-prompt-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(17, 24, 39, 0.45);
  display: grid;
  place-items: center;
  z-index: 120;
  padding: 20px;
}

.profile-prompt-card {
  width: min(400px, 100%);
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 22px 20px;
  box-shadow: var(--shadow);
}

.profile-prompt-card h3 {
  margin: 0 0 8px;
  font-size: 18px;
}

.profile-prompt-card p {
  margin: 0 0 14px;
  color: var(--muted);
  font-size: 14px;
  line-height: 1.5;
}

.profile-prompt-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  margin-top: 14px;
}

.btn-primary {
  padding: 11px 22px;
  border-radius: 10px;
  background: var(--accent);
  color: #fff;
  font-weight: 600;
  font-size: 14px;
}

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

.btn-secondary {
  width: 100%;
  padding: 11px 22px;
  border-radius: 10px;
  background: #fff;
  color: var(--accent);
  font-weight: 600;
  font-size: 14px;
  border: 1px solid var(--line);
}

.btn-secondary:hover {
  background: #fafafa;
  border-color: #d1d5db;
}

.portal-login-form {
  margin-top: 20px;
  text-align: left;
  display: grid;
  gap: 12px;
}

.portal-field {
  display: grid;
  gap: 6px;
  font-size: 13px;
  color: var(--muted);
}

.portal-field input {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  font: inherit;
  color: var(--ink);
  background: #fff;
}

.portal-field input:focus {
  outline: none;
  border-color: #9ca3af;
  box-shadow: 0 0 0 3px rgba(17, 24, 39, 0.06);
}

.portal-login-form .btn-primary {
  width: 100%;
  margin-top: 4px;
}

.portal-login-divider {
  display: flex;
  align-items: center;
  gap: 12px;
  margin: 18px 0 16px;
  color: var(--muted);
  font-size: 12px;
}

.portal-login-divider::before,
.portal-login-divider::after {
  content: "";
  flex: 1;
  height: 1px;
  background: var(--line);
}

.portal-main {
  flex: 1;
  width: min(1080px, 100%);
  margin: 0 auto;
  padding: 32px 24px 48px;
}

.portal-login {
  max-width: 440px;
  margin: 48px auto 0;
  padding: 40px 36px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 16px;
  box-shadow: var(--shadow);
  text-align: center;
}

.portal-login[hidden],
.portal-home[hidden] {
  display: none !important;
}

.portal-login h1 {
  margin: 16px 0 10px;
  font-size: 24px;
  font-weight: 700;
}

.portal-login p {
  margin: 0 0 28px;
  color: var(--muted);
  font-size: 14px;
  line-height: 1.65;
}

.portal-welcome {
  margin-bottom: 28px;
  padding: 24px 28px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.portal-welcome h2 {
  margin: 0 0 6px;
  font-size: 22px;
  font-weight: 700;
}

.portal-welcome p {
  margin: 0;
  color: var(--muted);
  font-size: 14px;
}

.portal-section-title {
  margin: 0 0 16px;
  font-size: 13px;
  font-weight: 600;
  color: var(--muted);
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.product-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 16px;
}

.product-card {
  display: flex;
  flex-direction: column;
  padding: 0;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 14px;
  box-shadow: var(--shadow);
  cursor: pointer;
  overflow: hidden;
  transition: border-color 0.15s, box-shadow 0.15s, transform 0.15s;
  text-align: left;
  min-height: 220px;
}

.product-card:hover {
  border-color: #cbd5e1;
  box-shadow: 0 8px 24px rgba(15, 23, 42, 0.08);
  transform: translateY(-1px);
}

.product-card:focus-visible {
  outline: 2px solid #93c5fd;
  outline-offset: 2px;
}

.product-cover {
  position: relative;
  display: grid;
  place-items: center;
  height: 120px;
  background: linear-gradient(180deg, #f8fafc 0%, #f1f5f9 100%);
  border-bottom: 1px solid var(--line);
}

.product-mark {
  width: 72px;
  height: 72px;
  border-radius: 18px;
  background: #fff;
  border: 1px solid #e2e8f0;
  box-shadow: 0 2px 8px rgba(15, 23, 42, 0.06);
  display: grid;
  place-items: center;
  overflow: hidden;
}

.product-mark img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.product-mark-label {
  padding: 0 8px;
  font-size: 13px;
  font-weight: 700;
  line-height: 1.25;
  text-align: center;
  color: #1e293b;
  word-break: break-word;
}

.product-body {
  flex: 1;
  display: flex;
  flex-direction: column;
  padding: 18px 20px 20px;
}

.product-body h3 {
  margin: 0 0 8px;
  font-size: 18px;
  font-weight: 700;
  line-height: 1.3;
}

.product-desc {
  margin: 0;
  flex: 1;
  font-size: 14px;
  color: var(--muted);
  line-height: 1.55;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.product-badge {
  position: absolute;
  top: 12px;
  right: 12px;
  font-size: 12px;
  font-weight: 600;
  padding: 4px 10px;
  border-radius: 999px;
  background: var(--green-bg);
  color: var(--green);
}

.product-enter {
  display: inline-block;
  margin-top: 14px;
  font-size: 14px;
  font-weight: 600;
  color: #2563eb;
}

.product-card:hover .product-enter {
  color: #1d4ed8;
}

.portal-empty {
  grid-column: 1 / -1;
  padding: 48px 24px;
  text-align: center;
  color: var(--muted);
  background: var(--surface);
  border: 1px dashed var(--line);
  border-radius: var(--radius);
  font-size: 14px;
}

.err-banner {
  margin-bottom: 20px;
  padding: 12px 16px;
  border-radius: 10px;
  background: #fef2f2;
  border: 1px solid #fecaca;
  color: #b91c1c;
  font-size: 13px;
}

.err-banner[hidden] {
  display: none !important;
}

.toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%);
  padding: 10px 18px;
  background: var(--ink);
  color: #fff;
  border-radius: 10px;
  font-size: 13px;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s;
  z-index: 50;
}

.toast.show {
  opacity: 1;
}

.launch-loading {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: grid;
  place-items: center;
  background: rgba(255, 255, 255, 0.82);
  backdrop-filter: blur(6px);
}

.launch-loading[hidden] {
  display: none !important;
}

.launch-loading-card {
  text-align: center;
  padding: 32px 36px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 16px;
  box-shadow: var(--shadow);
  min-width: 260px;
}

.launch-spinner {
  width: 32px;
  height: 32px;
  margin: 0 auto 16px;
  border: 3px solid #e5e7eb;
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: portal-spin 0.7s linear infinite;
}

@keyframes portal-spin {
  to { transform: rotate(360deg); }
}

.launch-loading-title {
  margin: 0;
  font-size: 15px;
  font-weight: 600;
}

.launch-loading-sub {
  margin: 8px 0 0;
  font-size: 13px;
  color: var(--muted);
}

@media (max-width: 640px) {
  .portal-header {
    padding: 0 16px;
    height: auto;
    min-height: 64px;
    flex-wrap: wrap;
    padding-top: 12px;
    padding-bottom: 12px;
  }

  .portal-user-meta {
    display: none;
  }

  .portal-main {
    padding: 20px 16px 32px;
  }

  .portal-login {
    margin-top: 24px;
    padding: 32px 24px;
  }
}
