:root {
  --bg: #f5f7fb;
  --card: #ffffff;
  --text: #172033;
  --muted: #6b7280;
  --border: #e5eaf2;
  --primary: #2563eb;
  --accent: #4f46e5;
  --accent-soft: #eef2ff;
  --danger: #dc2626;
  --success: #059669;
  --warning: #d97706;
  --danger-soft: #fef2f2;
  --success-soft: #f0fdf4;
  --warning-soft: #fff7ed;
  --shadow: 0 10px 30px rgba(15, 23, 42, 0.08);
  --radius: 16px;
}

* { box-sizing: border-box; }
html,
body {
  height: 100%;
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Noto Sans SC", sans-serif;
  background: var(--bg);
  color: var(--text);
}

a {
  color: inherit;
  text-decoration: none;
}

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

button {
  cursor: pointer;
}

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

.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 20px 28px;
  background: var(--card);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 20;
}

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

.brand h1 {
  margin: 0;
  font-size: 1.2rem;
}

.brand h1 span {
  color: var(--accent);
}

.brand-subtitle {
  color: var(--muted);
  font-size: 0.84rem;
}

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

.header-balance-card {
  min-width: 156px;
  width: fit-content;
  max-width: 100%;
  padding: 8px 12px;
  border-radius: 12px;
  background: var(--bg);
  border: 1px solid var(--border);
  display: flex;
  align-items: center;
  flex: 0 0 auto;
  gap: 10px;
}

.header-balance-block {
  min-width: max-content;
  flex: 0 0 auto;
}

.header-balance-divider {
  width: 1px;
  align-self: stretch;
  background: var(--border);
}

.header-balance-label {
  color: var(--muted);
  font-size: 0.74rem;
  line-height: 1.2;
  white-space: nowrap;
}

.header-balance-value {
  margin-top: 4px;
  font-size: 0.96rem;
  font-weight: 700;
  line-height: 1.3;
  white-space: nowrap;
}

.container {
  width: min(1200px, calc(100vw - 32px));
  margin: 0 auto;
  padding: 24px 0 48px;
}

.page {
  flex: 1 1 auto;
  min-height: 0;
  padding: 24px 28px 28px;
}

.page-scroll {
  overflow: auto;
}

.page-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 20px;
  flex-wrap: wrap;
}

.page-title {
  margin: 0 0 8px;
  font-size: 28px;
}

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

.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  box-shadow: var(--shadow);
}

.card-bd {
  padding: 18px 20px;
}

.grid {
  display: grid;
  gap: 16px;
}

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

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

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

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

.field {
  display: grid;
  gap: 8px;
  margin-bottom: 14px;
}

label {
  font-weight: 600;
}

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

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

.btn {
  border: 0;
  border-radius: 10px;
  padding: 10px 14px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  transition: transform 0.15s ease, box-shadow 0.15s ease, border-color 0.15s ease, background 0.15s ease;
}

.btn:hover {
  transform: translateY(-1px);
}

.btn-primary {
  background: var(--accent);
  color: #fff;
  box-shadow: 0 8px 18px rgba(79, 70, 229, 0.22);
}

.btn-danger {
  background: var(--danger-soft);
  color: var(--danger);
  border: 1px solid rgba(220, 38, 38, 0.08);
}

.btn-outline {
  background: transparent;
  color: var(--muted);
  border: 1px solid var(--border);
}

.btn-success {
  background: var(--success);
  color: #fff;
}

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

.btn.is-loading::before {
  content: "";
  width: 14px;
  height: 14px;
  border-radius: 50%;
  border: 2px solid currentColor;
  border-right-color: transparent;
  animation: btn-spin 0.7s linear infinite;
}

@keyframes btn-spin {
  from {
    transform: rotate(0deg);
  }

  to {
    transform: rotate(360deg);
  }
}

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

.hero-grid,
.workbench-grid {
  display: grid;
  gap: 16px;
}

.hero-grid {
  grid-template-columns: 1.4fr 1fr;
  margin-bottom: 16px;
}

.metrics-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 12px;
}

.metric-item {
  padding: 14px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: #f8fbff;
}

.metric-item strong {
  display: block;
  font-size: 20px;
  margin-top: 8px;
}

.metric-label {
  color: var(--muted);
  font-size: 13px;
}

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

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

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

.project-card p {
  margin: 0 0 8px;
}

.run-card, .platform-card {
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 14px;
  background: #fff;
}

.status-chip,
.pill {
  display: inline-flex;
  align-items: center;
  padding: 5px 10px;
  border-radius: 999px;
  background: var(--accent-soft);
  color: var(--accent);
  font-size: 0.74rem;
  font-weight: 700;
  white-space: nowrap;
}

.pill.success {
  background: var(--success-soft);
  color: var(--success);
}

.pill.warning {
  background: var(--warning-soft);
  color: var(--warning);
}

.pill.danger {
  background: var(--danger-soft);
  color: var(--danger);
}

.pill.subtle {
  background: var(--bg);
  color: var(--muted);
  border: 1px solid var(--border);
  font-weight: 600;
  font-size: 0.68rem;
  padding: 4px 8px;
}

.field-group {
  border: 1px solid var(--border);
  border-radius: 14px;
  background: var(--bg);
  padding: 14px 16px;
}

.field-group + .field-group {
  margin-top: 18px;
}

.field-group h4 {
  margin: 0 0 12px;
  font-size: 1.08rem;
  line-height: 1.4;
}

.platform-card {
  border: 0;
  border-radius: 0;
  background: transparent;
  padding: 0;
}

.platform-card-top {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 14px;
}

.platform-card-title {
  font-weight: 700;
  line-height: 1.4;
}

.platform-card-subtitle {
  margin-top: 4px;
  color: var(--muted);
  font-size: 0.78rem;
  line-height: 1.6;
}

.platform-segment {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.platform-segment-btn {
  border: 1px solid var(--border);
  background: #fff;
  color: var(--muted);
  border-radius: 999px;
  padding: 7px 12px;
  font-size: 0.78rem;
  font-weight: 700;
}

.platform-segment-btn.active {
  background: var(--accent-soft);
  border-color: rgba(79, 70, 229, 0.2);
  color: var(--accent);
}

.platform-note {
  color: var(--muted);
  font-size: 0.78rem;
  line-height: 1.6;
  margin-bottom: 12px;
}

.choice-group {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}

.choice-chip {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 8px 12px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: #fff;
  color: var(--text);
  font-size: 0.82rem;
  cursor: pointer;
}

.choice-chip input {
  width: 14px;
  height: 14px;
  margin: 0;
}

.run-items {
  display: grid;
  gap: 12px;
}

.platform-item {
  border-top: 1px dashed var(--border);
  padding-top: 12px;
  margin-top: 12px;
}

.platform-item:first-child {
  border-top: 0;
  margin-top: 0;
  padding-top: 0;
}

.tag {
  display: inline-block;
  padding: 4px 8px;
  border-radius: 999px;
  background: #eff6ff;
  color: var(--primary);
  margin-right: 6px;
  margin-bottom: 6px;
  font-size: 12px;
}

.section-title {
  margin: 0 0 12px;
  font-size: 18px;
}

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

.empty-state {
  padding: 36px 20px;
  text-align: center;
  color: var(--muted);
  line-height: 1.8;
}

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

.app-toast {
  position: fixed;
  right: 20px;
  bottom: 20px;
  z-index: 9999;
  min-width: 220px;
  max-width: 360px;
  padding: 12px 14px;
  border-radius: 12px;
  background: #111827;
  color: #fff;
  opacity: 0;
  transform: translateY(8px);
  transition: opacity 0.2s ease, transform 0.2s ease;
  pointer-events: none;
}

.app-toast[data-type="success"] {
  background: var(--success);
}

.app-toast[data-type="error"] {
  background: var(--danger);
}

.app-toast[data-type="warning"] {
  background: var(--warning);
}

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

.drawer-mask,
.modal-mask {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.42);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.18s ease;
  z-index: 90;
}

.drawer-mask.show,
.modal-mask.show {
  opacity: 1;
  pointer-events: auto;
}

.drawer {
  position: fixed;
  top: 0;
  right: 0;
  width: min(560px, calc(100vw - 20px));
  height: 100vh;
  background: var(--card);
  box-shadow: -10px 0 30px rgba(15, 23, 42, 0.18);
  transform: translateX(100%);
  transition: transform 0.22s ease;
  z-index: 100;
  display: flex;
  flex-direction: column;
}

.drawer.show {
  transform: translateX(0);
}

.drawer-hd,
.modal-hd {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 18px 20px;
  border-bottom: 1px solid var(--border);
}

.drawer-hd h3,
.modal-hd h3 {
  margin: 0;
  font-size: 1rem;
}

.drawer-bd,
.modal-bd {
  flex: 1 1 auto;
  min-height: 0;
  overflow: auto;
  padding: 18px 20px;
}

.drawer-ft,
.modal-ft {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  padding: 16px 20px 20px;
  border-top: 1px solid var(--border);
}

.modal {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  pointer-events: none;
  z-index: 100;
}

.modal.show {
  pointer-events: auto;
}

.modal-content {
  width: min(680px, calc(100vw - 24px));
  background: var(--card);
  border-radius: 18px;
  border: 1px solid var(--border);
  box-shadow: 0 24px 80px rgba(15, 23, 42, 0.2);
  transform: translateY(20px) scale(0.98);
  opacity: 0;
  transition: opacity 0.18s ease, transform 0.18s ease;
}

.modal.show .modal-content {
  opacity: 1;
  transform: translateY(0) scale(1);
}

.login-page {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
}

.login-shell {
  width: min(480px, 100%);
}

.login-card {
  padding: 28px;
}

.login-card .actions {
  justify-content: center;
  width: 100%;
}

.login-card #loginBtn {
  width: 100%;
}

@media (max-width: 900px) {
  .app-header {
    padding: 16px;
    align-items: flex-start;
  }

  .header-actions {
    width: 100%;
    justify-content: flex-start;
  }

  .header-balance-card {
    width: 100%;
  }

  .header-balance-divider {
    display: none;
  }

  .page {
    padding: 16px;
  }

  .grid-2 { grid-template-columns: 1fr; }
  .grid-3 { grid-template-columns: 1fr; }
  .hero-grid { grid-template-columns: 1fr; }
  .metrics-grid { grid-template-columns: 1fr; }

  .platform-card {
    padding: 12px;
  }

  .platform-card-top {
    flex-direction: column;
    align-items: flex-start;
  }

  .platform-segment {
    overflow-x: auto;
    flex-wrap: nowrap;
    padding-bottom: 4px;
  }

  .platform-segment::-webkit-scrollbar {
    height: 0;
  }

  .platform-segment-btn {
    white-space: nowrap;
    flex: 0 0 auto;
  }
}
