:root {
  color-scheme: light;
  --background: #f5f7f8;
  --surface: #ffffff;
  --text: #172028;
  --muted: #64717d;
  --border: #d8dee3;
  --primary: #176b4d;
  --primary-hover: #10563d;
  --danger: #a13232;
  --danger-soft: #fff1f0;
  --warning: #8a5a00;
  --warning-soft: #fff7df;
  --success-soft: #eaf7ef;
  --radius: 6px;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--background);
  color: var(--text);
  font-family: Inter, "Segoe UI", "Microsoft YaHei", sans-serif;
  font-size: 14px;
  letter-spacing: 0;
}

a { color: var(--primary); }
code, pre { font-family: "Cascadia Mono", Consolas, monospace; }

.topbar {
  min-height: 56px;
  padding: 0 28px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}

.brand {
  color: var(--text);
  font-size: 17px;
  font-weight: 700;
  text-decoration: none;
}

.topnav, .action-row, .title-row, .form-actions {
  display: flex;
  align-items: center;
  gap: 10px;
}

.topnav a { color: var(--text); text-decoration: none; }
.topnav form, .action-row form, td form { margin: 0; }
.account { color: var(--muted); padding-left: 12px; border-left: 1px solid var(--border); }

.page-shell { width: min(1180px, calc(100% - 40px)); margin: 30px auto 60px; }
.page-heading { display: flex; justify-content: space-between; gap: 24px; align-items: flex-end; margin-bottom: 24px; }
.page-heading h1 { margin: 5px 0 0; font-size: 25px; line-height: 1.2; }
.page-heading p { margin: 5px 0 0; color: var(--muted); }
.compact-heading { align-items: flex-start; }
.back-link { color: var(--muted); font-size: 13px; text-decoration: none; }

.button {
  min-height: 36px;
  padding: 8px 14px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: 1px solid transparent;
  border-radius: var(--radius);
  font: inherit;
  font-weight: 600;
  text-decoration: none;
  cursor: pointer;
  white-space: nowrap;
}

.button-primary { background: var(--primary); color: white; }
.button-primary:hover { background: var(--primary-hover); }
.button-secondary { background: var(--surface); border-color: var(--border); color: var(--text); }
.button-danger { background: var(--surface); border-color: #e2b8b5; color: var(--danger); }
.button-quiet { min-height: 30px; padding: 5px 8px; background: transparent; color: var(--muted); }
.button:disabled { opacity: 0.48; cursor: not-allowed; }

.table-wrap { overflow-x: auto; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); }
table { width: 100%; border-collapse: collapse; }
th, td { padding: 13px 15px; text-align: left; border-bottom: 1px solid var(--border); vertical-align: middle; }
th { color: var(--muted); font-size: 12px; font-weight: 700; background: #fafbfb; }
tr:last-child td { border-bottom: 0; }
.project-link { color: var(--text); font-weight: 700; text-decoration: none; }
.output-cell { min-width: 160px; max-width: 520px; color: var(--muted); }
.output-cell summary { color: var(--primary); cursor: pointer; }
.output-cell pre { max-height: 320px; margin: 10px 0 0; padding: 10px; overflow: auto; white-space: pre-wrap; background: #f3f5f6; color: var(--text); }

.status {
  display: inline-flex;
  min-width: 62px;
  min-height: 26px;
  padding: 4px 8px;
  align-items: center;
  justify-content: center;
  border-radius: 999px;
  background: #edf0f2;
  color: #48545e;
  font-size: 12px;
  font-weight: 700;
}
.status-running, .status-success { background: var(--success-soft); color: #21643f; }
.status-ready { background: var(--success-soft); color: #21643f; }
.status-retry_ready { background: var(--success-soft); color: #21643f; }
.status-resolved { background: var(--success-soft); color: #21643f; }
.status-unreviewed, .status-investigating { background: var(--warning-soft); color: var(--warning); }
.status-ignored { background: #edf0f2; color: #48545e; }
.status-failed, .status-error { background: var(--danger-soft); color: var(--danger); }
.status-pending, .status-provisioning, .status-processing, .status-queued, .status-deploying, .status-stopping, .status-restarting, .status-blocked, .status-waiting_image { background: var(--warning-soft); color: var(--warning); }
.status-stopped { background: #edf0f2; color: #48545e; }

.notice { margin: 0 0 20px; padding: 12px 14px; border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface); }
.notice-success { border-color: #a9d8ba; background: var(--success-soft); }
.notice-warning { border-color: #ead08a; background: var(--warning-soft); }
.notice-error { border-color: #e2b8b5; background: var(--danger-soft); color: #7d2525; }
.notice pre { margin: 0; white-space: pre-wrap; }

.failure-metrics {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  margin: 0 0 24px;
  border-top: 1px solid var(--border);
  border-bottom: 1px solid var(--border);
}
.failure-metrics div { padding: 18px 20px; border-right: 1px solid var(--border); }
.failure-metrics div:last-child { border-right: 0; }
.failure-metrics strong { display: block; font-size: 24px; }
.failure-metrics span, .muted { color: var(--muted); }
.filter-bar { display: flex; align-items: end; gap: 12px; margin-bottom: 18px; flex-wrap: wrap; }
.filter-bar label { min-width: 170px; }
.filter-bar label span, .failure-review-form label span { display: block; margin-bottom: 6px; font-weight: 700; }
.filter-bar select, .failure-review-form select { width: 100%; }
.failure-summary { min-width: 280px; max-width: 520px; white-space: normal; }
.duplicate-count { display: inline-block; margin-left: 8px; color: var(--warning); font-weight: 700; }
.failure-detail-grid { display: grid; grid-template-columns: minmax(0, 1.25fr) minmax(320px, .75fr); gap: 24px; }
.detail-list { margin: 0 0 24px; }
.detail-list div { display: grid; grid-template-columns: 110px minmax(0, 1fr); gap: 16px; padding: 9px 0; border-bottom: 1px solid var(--border); }
.detail-list dt { color: var(--muted); }
.detail-list dd { margin: 0; font-weight: 600; }
.failure-review-form { display: flex; flex-direction: column; gap: 16px; }
.failure-log { max-height: 620px; overflow: auto; padding: 16px; background: #f5f7f8; border: 1px solid var(--border); white-space: pre-wrap; word-break: break-word; }

@media (max-width: 900px) {
  .failure-metrics { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .failure-metrics div { border-bottom: 1px solid var(--border); }
  .failure-detail-grid { grid-template-columns: 1fr; }
}

.login-panel, .form-panel {
  width: min(460px, 100%);
  margin: 72px auto 0;
  padding: 24px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}
.login-panel h1 { margin: 0 0 22px; font-size: 22px; }
.wide-panel { width: min(660px, 100%); }
.panel-footer { margin: 20px 0 0; text-align: center; color: var(--muted); }
.form-panel { width: min(700px, 100%); margin: 0; }
.form-stack { display: grid; gap: 18px; }
.form-stack label, .form-grid label { display: grid; gap: 7px; font-weight: 600; }
.mode-fieldset { min-width: 0; margin: 0; padding: 0; border: 0; }
.mode-fieldset legend { margin-bottom: 7px; font-weight: 600; }
.segmented-control { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); padding: 3px; border: 1px solid var(--border); border-radius: var(--radius); background: #eef1f2; }
.segmented-control label { display: block; }
.segmented-control input { position: absolute; opacity: 0; pointer-events: none; }
.segmented-control span { min-height: 34px; padding: 7px 10px; display: flex; align-items: center; justify-content: center; border-radius: 4px; color: var(--muted); cursor: pointer; font-weight: 600; }
.segmented-control input:checked + span { background: var(--surface); color: var(--text); box-shadow: 0 1px 2px rgba(23, 32, 40, 0.12); }
.form-grid { width: 100%; display: grid; grid-template-columns: minmax(180px, 1fr) minmax(220px, 1fr) auto; gap: 14px; align-items: end; }
.inline-form { display: grid; grid-template-columns: minmax(160px, 1fr) auto; gap: 8px; }
input, select, textarea {
  width: 100%;
  min-height: 40px;
  padding: 8px 10px;
  border: 1px solid #bfc8cf;
  border-radius: 4px;
  background: white;
  color: var(--text);
  font: inherit;
}
textarea { resize: vertical; line-height: 1.5; }
label small { color: var(--muted); font-weight: 400; }
input:focus, select:focus, textarea:focus { outline: 2px solid #8bbca9; outline-offset: 1px; border-color: var(--primary); }
.form-actions { justify-content: flex-end; padding-top: 6px; }
.project-create-layout { display: grid; grid-template-columns: minmax(0, 0.95fr) minmax(0, 1.15fr); gap: 20px; align-items: start; }
.project-create-form { width: 100%; }
.workflow-steps { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; margin: 0 0 22px; }
.workflow-step { display: grid; grid-template-columns: 36px minmax(0, 1fr); gap: 12px; padding: 18px; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); }
.workflow-step h2 { margin: 0 0 6px; font-size: 17px; }
.workflow-step p { margin: 0 0 12px; color: var(--muted); line-height: 1.55; }
.workflow-step form { margin: 0; }
.workflow-number { display: grid; place-items: center; width: 32px; height: 32px; border-radius: 50%; background: var(--primary); color: white; font-weight: 700; }
.deployment-guide-panel { min-width: 0; overflow: hidden; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); }
.deployment-guide-header { padding: 18px; display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; border-bottom: 1px solid var(--border); }
.deployment-guide-header h2 { margin: 0 0 5px; font-size: 18px; }
.deployment-guide-header p { margin: 0; color: var(--muted); font-size: 13px; }
.guide-copy-actions { min-width: 108px; display: grid; justify-items: end; gap: 5px; }
.deployment-guide-output { width: 100%; min-height: 540px; max-height: 620px; margin: 0; padding: 18px; overflow: auto; resize: none; border: 0; border-radius: 0; background: #f8faf9; white-space: pre-wrap; overflow-wrap: anywhere; font-family: "Cascadia Mono", Consolas, monospace; font-size: 12px; line-height: 1.58; }
.copy-status { min-height: 16px; color: var(--muted); font-size: 11px; font-weight: 400; white-space: nowrap; }
.copy-status-success { color: #21643f; }
.copy-status-error { color: var(--danger); }
.application-form { width: min(820px, 100%); }
.form-pair { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; align-items: start; }
.application-form .form-pair > label { align-content: start; }
.application-form .form-pair input { height: 40px; min-height: 40px; }
.credential-box { display: grid; gap: 10px; margin: 20px 0; padding: 16px; border: 1px solid var(--border); background: #fafbfb; }
.credential-box > div { display: grid; grid-template-columns: 100px minmax(0, 1fr); gap: 12px; }
.credential-box span { color: var(--muted); }
.credential-box code { overflow-wrap: anywhere; }
.table-actions { display: flex; align-items: center; gap: 12px; white-space: nowrap; }
.table-actions a { text-decoration: none; }
.danger-link { color: var(--danger); }
.pre-wrap { white-space: pre-wrap; }
.danger-panel { margin: 0; }
.guide-sections { display: grid; gap: 24px; }
.guide-sections section { padding-bottom: 22px; border-bottom: 1px solid var(--border); }
.guide-sections section:last-child { border-bottom: 0; }
.guide-sections h2 { margin: 0 0 10px; font-size: 17px; }
.guide-sections p { margin: 8px 0; line-height: 1.65; }
.guide-sections pre { margin: 10px 0; padding: 14px; overflow-x: auto; border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface); line-height: 1.55; }
.guide-sections li { margin: 7px 0; line-height: 1.55; }

.empty-state { padding: 54px 20px; text-align: center; background: var(--surface); border: 1px dashed #bcc5cb; border-radius: var(--radius); }
.empty-state p { margin: 0 0 8px; color: var(--muted); }
.detail-grid { background: var(--surface); border-top: 1px solid var(--border); border-bottom: 1px solid var(--border); }
.detail-grid dl { margin: 0; }
.detail-grid dl > div { display: grid; grid-template-columns: 150px minmax(0, 1fr); padding: 13px 8px; border-bottom: 1px solid var(--border); }
.detail-grid dl > div:last-child { border-bottom: 0; }
.detail-grid dt { color: var(--muted); }
.detail-grid dd { margin: 0; min-width: 0; overflow-wrap: anywhere; }
.section-block { margin-top: 30px; }
.section-first { margin-top: 0; }
.section-block h2 { margin: 0 0 14px; font-size: 17px; }
.version-note { margin: 10px 0 0; font-size: 12px; }
.access-address-row { display: flex; align-items: center; justify-content: space-between; gap: 18px; padding: 16px; border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface); }
.access-addresses { min-width: 0; display: grid; gap: 7px; overflow-wrap: anywhere; }
.access-address-item { display: grid; grid-template-columns: 72px minmax(0, 1fr); gap: 10px; align-items: baseline; }
.access-address-item > span { color: var(--muted); font-size: 12px; font-weight: 700; }
.access-addresses .primary-address { font-size: 16px; font-weight: 700; }
.domain-control { display: flex; align-items: center; gap: 8px; flex: 0 0 auto; }
.domain-control form { margin: 0; }
.domain-note { margin: 9px 0 0; font-size: 12px; }
.domain-error { margin: 12px 0 0; }
.muted { color: var(--muted); }
.application-list { display: grid; gap: 16px; }
.application-row { padding: 18px; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); }
.application-summary { display: flex; justify-content: space-between; gap: 20px; align-items: flex-start; }
.application-summary h2 { margin: 0 0 5px; font-size: 18px; }
.application-summary p, .application-description { margin: 0; color: var(--muted); }
.application-description { margin-top: 14px; color: var(--text); white-space: pre-wrap; }
.application-meta { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 12px; margin: 16px 0; }
.application-meta div { min-width: 0; }
.application-meta dt { margin-bottom: 4px; color: var(--muted); font-size: 12px; }
.application-meta dd { margin: 0; overflow-wrap: anywhere; }
.review-form { display: grid; grid-template-columns: minmax(220px, 1fr) auto; gap: 12px; align-items: end; padding-top: 14px; border-top: 1px solid var(--border); }
.review-form label { display: grid; gap: 6px; font-weight: 600; }
.image-form { max-width: none; }
.image-request-list { display: grid; gap: 16px; }
.image-request { padding: 18px; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); }
.image-request h3 { margin: 0 0 6px; font-size: 17px; }
.command-box { display: grid; gap: 7px; font-weight: 600; }
.command-box textarea { min-height: 190px; resize: vertical; font-family: "Cascadia Mono", Consolas, monospace; font-size: 12px; }

@media (max-width: 720px) {
  .topbar { min-height: auto; padding: 12px 16px; align-items: flex-start; flex-direction: column; gap: 10px; }
  .brand { flex: 0 0 auto; }
  .topnav { width: 100%; gap: 12px; overflow-x: auto; padding-bottom: 2px; }
  .topnav a, .topnav button { flex: 0 0 auto; }
  .page-shell { width: min(100% - 24px, 1180px); margin-top: 20px; }
  .page-heading { align-items: stretch; flex-direction: column; }
  .action-row { display: grid; grid-template-columns: repeat(2, 1fr); }
  .action-row .button { width: 100%; }
  .detail-grid dl > div { grid-template-columns: 1fr; gap: 5px; }
  .account { display: none; }
  .form-grid { grid-template-columns: 1fr; }
  .form-pair { grid-template-columns: 1fr; }
  .image-form { grid-template-columns: 1fr; }
  .image-request { padding: 14px; }
  .command-box textarea { min-height: 250px; }
  .application-summary { align-items: stretch; flex-direction: column; }
  .application-meta, .review-form { grid-template-columns: 1fr; }
  .workflow-steps { grid-template-columns: 1fr; }
  .access-address-row { align-items: stretch; flex-direction: column; }
  .access-address-item { grid-template-columns: 1fr; gap: 3px; }
  .domain-control { align-items: stretch; flex-wrap: wrap; }
}

@media (max-width: 980px) {
  .project-create-layout { grid-template-columns: 1fr; }
  .deployment-guide-output { min-height: 420px; max-height: 520px; }
}
