:root {
  --green: #107c41;
  --green-dark: #0b5d31;
  --green-soft: #e7f3ec;
  --border: #d0d7de;
  --border-strong: #a9b2bc;
  --text: #1f2328;
  --muted: #59636e;
  --bg: #f6f8fa;
  --danger: #c43e1c;
  --font: -apple-system, BlinkMacSystemFont, "Hiragino Sans", "Yu Gothic", "YuGothic", "Segoe UI", sans-serif;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-width: 1040px;
  color: var(--text);
  background: var(--bg);
  font-family: var(--font);
  font-size: 14px;
  letter-spacing: 0;
}

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

button {
  cursor: pointer;
}

a {
  color: var(--green-dark);
  text-decoration: none;
}

a:hover {
  text-decoration: underline;
}

.admin-shell {
  min-height: 100vh;
  display: grid;
  grid-template-rows: auto auto auto 1fr;
}

.admin-header {
  min-height: 72px;
  padding: 16px 24px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  color: #ffffff;
  background: var(--green);
}

.admin-header p,
.panel-head p,
.section-head p {
  margin: 0 0 4px;
  color: inherit;
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
}

.admin-header h1,
.panel-head h2,
.section-head h2 {
  margin: 0;
  line-height: 1.2;
  letter-spacing: 0;
}

.admin-header h1 {
  font-size: 24px;
}

.admin-actions,
.form-actions,
.inline-field,
.copy-row {
  display: flex;
  align-items: center;
  gap: 8px;
}

.status-band {
  display: grid;
  grid-template-columns: 1fr 1.35fr 0.42fr 0.42fr;
  border-bottom: 1px solid var(--border);
  background: #ffffff;
}

.status-band > div {
  min-width: 0;
  padding: 12px 16px;
  border-right: 1px solid var(--border);
}

.status-band > div:last-child {
  border-right: 0;
}

.status-band span {
  display: block;
  margin-bottom: 5px;
  color: var(--muted);
  font-size: 12px;
}

.status-band strong {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 13px;
}

.saas-summary {
  display: grid;
  grid-template-columns: minmax(320px, 0.95fr) minmax(620px, 1.55fr);
  gap: 18px;
  padding: 14px 24px;
  align-items: center;
  border-bottom: 1px solid var(--border);
  background: #ffffff;
}

.saas-summary p {
  margin: 0 0 4px;
  color: var(--green-dark);
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
}

.saas-summary h2 {
  margin: 0 0 6px;
  font-size: 18px;
  line-height: 1.25;
}

.saas-summary span {
  color: var(--muted);
  line-height: 1.55;
}

.saas-summary dl {
  margin: 0;
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 8px;
}

.saas-summary dl > div {
  min-width: 0;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: #f8faf9;
}

.saas-summary dt {
  margin-bottom: 4px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

.saas-summary dd {
  margin: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-weight: 700;
}

.preflight-panel {
  margin: 14px 24px 0;
  padding: 16px;
  display: grid;
  grid-template-columns: minmax(280px, 0.8fr) minmax(520px, 1.2fr);
  gap: 16px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: #ffffff;
}

.preflight-panel p {
  margin: 0 0 4px;
  color: var(--green-dark);
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
}

.preflight-panel h2 {
  margin: 0 0 6px;
  font-size: 18px;
}

.preflight-panel span {
  color: var(--muted);
  line-height: 1.55;
}

.preflight-panel ul {
  margin: 0;
  padding: 0;
  display: grid;
  gap: 8px;
  list-style: none;
}

.preflight-panel li {
  padding: 9px 10px;
  border: 1px solid var(--border);
  border-radius: 4px;
  background: #f8faf9;
  line-height: 1.45;
}

.preflight-panel li.is-ng {
  border-color: #f0b69f;
  background: #fff4ee;
}

.preflight-panel strong {
  display: block;
  margin-bottom: 3px;
}

.file-warning {
  margin: 14px 24px 0;
  padding: 14px 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  background: #fff4e5;
  border: 1px solid #f4b860;
  border-radius: 6px;
}

.file-warning[hidden] {
  display: none;
}

.file-warning strong,
.file-warning span {
  display: block;
}

.file-warning strong {
  margin-bottom: 4px;
}

.file-warning span {
  color: var(--muted);
}

.admin-grid {
  display: grid;
  grid-template-columns: minmax(480px, 0.95fr) minmax(460px, 1.05fr);
  gap: 16px;
  padding: 16px 24px;
}

.admin-panel,
.tenant-section {
  background: #ffffff;
  border: 1px solid var(--border);
  border-radius: 6px;
}

.admin-panel {
  padding: 18px;
}

.panel-head,
.section-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 16px;
}

.panel-head p,
.section-head p {
  color: var(--green-dark);
}

.panel-head h2,
.section-head h2 {
  font-size: 20px;
}

.panel-note,
#tenantCount {
  color: var(--muted);
  font-size: 12px;
  white-space: nowrap;
}

.issue-panel {
  display: grid;
  gap: 14px;
}

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

.issue-panel label > span {
  color: var(--muted);
  font-weight: 700;
}

.issue-panel small {
  color: var(--muted);
  line-height: 1.5;
}

.checkbox-stack {
  display: grid;
  gap: 8px;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 4px;
  background: #fbfcfd;
}

.check-row {
  display: flex !important;
  grid-template-columns: none !important;
  align-items: flex-start;
  gap: 8px !important;
  color: var(--text);
  font-weight: 700;
  line-height: 1.5;
}

.check-row input {
  width: 16px !important;
  min-height: 16px !important;
  margin-top: 3px;
  padding: 0 !important;
}

.issue-panel input,
.issue-panel select,
.issue-panel textarea {
  width: 100%;
  min-height: 38px;
  padding: 8px 10px;
  color: var(--text);
  background: #ffffff;
  border: 1px solid var(--border-strong);
  border-radius: 4px;
  outline: none;
}

.issue-panel textarea {
  resize: vertical;
}

.issue-panel input:focus,
.issue-panel select:focus,
.issue-panel textarea:focus {
  border-color: var(--green);
  box-shadow: 0 0 0 2px rgba(16, 124, 65, 0.12);
}

.inline-field input {
  flex: 1;
  min-width: 300px;
}

.inline-field {
  flex-wrap: wrap;
}

.inline-field .ghost-button {
  flex: 0 0 auto;
}

.two-column {
  display: grid;
  grid-template-columns: 1fr 150px;
  gap: 12px;
}

.primary-button,
.ghost-button,
.copy-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-height: 36px;
  padding: 8px 12px;
  border-radius: 4px;
  border: 1px solid var(--border-strong);
  background: #ffffff;
  color: var(--text);
  font-weight: 700;
}

.admin-header .ghost-button {
  color: #ffffff;
  border-color: rgba(255, 255, 255, 0.38);
  background: rgba(255, 255, 255, 0.12);
}

.admin-header .ghost-button[aria-disabled="true"] {
  color: rgba(255, 255, 255, 0.62);
  border-color: rgba(255, 255, 255, 0.22);
  background: rgba(255, 255, 255, 0.06);
  pointer-events: none;
}

.primary-button {
  color: #ffffff;
  border-color: var(--green-dark);
  background: var(--green);
}

.primary-button:hover {
  background: var(--green-dark);
}

.ghost-button:hover,
.copy-button:hover {
  border-color: var(--green);
  background: var(--green-soft);
  text-decoration: none;
}

.dev-only[hidden] {
  display: none;
}

#hubspotAccountField[hidden],
#privateSetupNote[hidden],
#hubspotAccountApprovedRow[hidden],
#installerPermissionConfirmedRow[hidden] {
  display: none !important;
}

.private-setup-note {
  padding: 12px 14px;
  border: 1px solid #f0b66f;
  border-radius: 4px;
  background: #fff8ec;
}

.private-setup-note strong {
  display: block;
  margin-bottom: 8px;
  color: #7a4b00;
}

.private-setup-note ol {
  margin: 0;
  padding-left: 20px;
  color: var(--text);
  line-height: 1.6;
}

#localKeyHint {
  color: var(--green-dark);
}

.result-panel {
  min-height: 360px;
}

.empty-result {
  padding: 18px;
  color: var(--muted);
  border: 1px dashed var(--border-strong);
  border-radius: 6px;
  background: #fbfcfd;
}

.result-box dl {
  margin: 0;
  display: grid;
  gap: 12px;
}

.result-box dl > div {
  display: grid;
  grid-template-columns: 150px minmax(0, 1fr);
  align-items: start;
  gap: 12px;
  padding-bottom: 12px;
  border-bottom: 1px solid var(--border);
}

.result-box dl > div:last-child {
  border-bottom: 0;
}

.result-box dt {
  color: var(--muted);
  font-weight: 700;
}

.result-box dd {
  margin: 0;
  min-width: 0;
  display: flex;
  align-items: center;
  gap: 8px;
}

.result-box a,
.result-box code {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.result-box code {
  display: block;
  padding: 3px 6px;
  background: #f2f4f7;
  border: 1px solid var(--border);
  border-radius: 4px;
}

.customer-guide {
  margin-top: 18px;
  padding: 16px;
  background: #f7fbf8;
  border: 1px solid #b8d9c5;
  border-radius: 6px;
}

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

.customer-guide h3 {
  margin: 0 0 6px;
  color: var(--green-dark);
  font-size: 16px;
}

.customer-guide p {
  margin: 0;
  color: var(--muted);
  line-height: 1.6;
}

.customer-guide ol {
  margin: 0 0 14px;
  padding-left: 22px;
}

.customer-guide li {
  margin: 0 0 8px;
  line-height: 1.65;
}

.customer-guide textarea {
  width: 100%;
  min-height: 190px;
  padding: 10px 12px;
  color: var(--text);
  background: #ffffff;
  border: 1px solid var(--border);
  border-radius: 4px;
  resize: vertical;
  line-height: 1.6;
}

.copy-button {
  min-height: 30px;
  padding: 5px 9px;
  font-size: 12px;
  white-space: nowrap;
}

.tenant-section {
  margin: 0 24px 24px;
  min-height: 260px;
  overflow: hidden;
}

.section-head {
  margin: 0;
  padding: 16px 18px;
  border-bottom: 1px solid var(--border);
}

.table-wrap {
  overflow: auto;
}

.tenant-table {
  width: 100%;
  border-collapse: collapse;
  table-layout: fixed;
}

.tenant-table th,
.tenant-table td {
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
  text-align: left;
  vertical-align: top;
}

.tenant-table th {
  position: sticky;
  top: 0;
  z-index: 1;
  background: #f3f4f6;
  color: #3b434b;
  font-size: 12px;
}

.tenant-table th:nth-child(1) {
  width: 18%;
}

.tenant-table th:nth-child(2) {
  width: 12%;
}

.tenant-table th:nth-child(3) {
  width: 17%;
}

.tenant-table th:nth-child(4),
.tenant-table th:nth-child(5) {
  width: 12%;
}

.tenant-table th:nth-child(6) {
  width: 14%;
}

.tenant-table th:nth-child(7) {
  width: 17%;
}

.tenant-table td {
  overflow-wrap: anywhere;
}

.tenant-meta {
  display: block;
  margin-top: 4px;
  color: var(--muted);
  font-size: 12px;
}

.tenant-meta.warning {
  color: #8a4b00;
  font-weight: 700;
}

.status-pill {
  display: inline-flex;
  align-items: center;
  min-height: 24px;
  padding: 2px 8px;
  border-radius: 999px;
  background: #f2f4f7;
  border: 1px solid var(--border);
  color: #3b434b;
  font-size: 12px;
  font-weight: 700;
}

.status-pill.connected {
  color: var(--green-dark);
  background: var(--green-soft);
  border-color: #a8d5bd;
}

.status-pill.warning {
  color: #8a4b00;
  background: #fff7e8;
  border-color: #f2c783;
}

.tenant-url-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.tenant-lifecycle-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.tenant-action-button {
  min-height: 28px;
  padding: 4px 8px;
  border: 1px solid var(--border-strong);
  border-radius: 4px;
  background: #ffffff;
  color: var(--text);
  font-size: 12px;
  font-weight: 700;
}

.tenant-action-button:hover {
  border-color: var(--green);
  background: var(--green-soft);
}

.tenant-action-button.danger {
  color: var(--danger);
  border-color: #e4a08e;
}

.toast {
  position: fixed;
  right: 18px;
  bottom: 18px;
  z-index: 10;
  max-width: 420px;
  padding: 10px 12px;
  color: #ffffff;
  background: #24292f;
  border-radius: 6px;
  box-shadow: 0 8px 24px rgba(31, 35, 40, 0.2);
  opacity: 0;
  transform: translateY(8px);
  pointer-events: none;
  transition:
    opacity 0.16s ease,
    transform 0.16s ease;
}

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

.toast.error {
  background: var(--danger);
}

@media (max-width: 900px) {
  body {
    min-width: 0;
  }

  .admin-header,
  .admin-grid,
  .tenant-section {
    margin: 0;
  }

  .admin-header,
  .admin-grid {
    padding-left: 14px;
    padding-right: 14px;
  }

  .admin-grid,
  .status-band,
  .two-column {
    grid-template-columns: 1fr;
  }

  .status-band > div {
    border-right: 0;
    border-bottom: 1px solid var(--border);
  }
}
