:root {
  --bg: #f4efe5;
  --bg-panel: rgba(255, 251, 244, 0.92);
  --ink: #15231d;
  --muted: #6b746c;
  --line: rgba(21, 35, 29, 0.12);
  --accent: #0f6c5c;
  --accent-strong: #0a4d42;
  --warn: #b3522a;
  --shadow: 0 20px 50px rgba(21, 35, 29, 0.1);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: Georgia, "Noto Serif SC", "Songti SC", serif;
  color: var(--ink);
  background:
    radial-gradient(circle at top left, rgba(15, 108, 92, 0.14), transparent 28%),
    radial-gradient(circle at bottom right, rgba(179, 82, 42, 0.14), transparent 30%),
    linear-gradient(180deg, #f7f2e9, var(--bg));
}

.shell {
  width: min(1240px, calc(100vw - 32px));
  margin: 0 auto;
  padding: 28px 0 44px;
}

.hero {
  display: flex;
  justify-content: space-between;
  gap: 24px;
  align-items: end;
  margin-bottom: 24px;
}

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

.instance-badge {
  display: inline-flex;
  align-items: center;
  max-width: 380px;
  padding: 8px 12px;
  border-radius: 999px;
  border: 1px solid rgba(21, 35, 29, 0.12);
  background: rgba(255, 255, 255, 0.74);
  color: var(--muted);
  font-size: 12px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.eyebrow {
  margin: 0 0 8px;
  text-transform: uppercase;
  letter-spacing: 0.18em;
  font-size: 12px;
  color: var(--accent);
}

h1, h2 {
  margin: 0;
  font-weight: 600;
}

h1 {
  font-size: clamp(32px, 5vw, 54px);
  line-height: 0.95;
}

.lede {
  max-width: 720px;
  margin: 14px 0 0;
  color: var(--muted);
  font-size: 16px;
}

.grid {
  display: grid;
  grid-template-columns: repeat(12, 1fr);
  gap: 18px;
}

.tabbar {
  display: flex;
  gap: 10px;
  margin-bottom: 18px;
  flex-wrap: wrap;
}

.tab {
  position: relative;
  background: rgba(255, 255, 255, 0.72);
  color: var(--ink);
  border: 1px solid rgba(21, 35, 29, 0.08);
}

.tab.is-active {
  background: var(--accent);
  color: #f8f3ec;
}

.tab-tip {
  position: absolute;
  left: 50%;
  bottom: calc(100% + 10px);
  transform: translateX(-50%);
  width: 260px;
  padding: 10px 12px;
  border-radius: 12px;
  background: rgba(18, 32, 24, 0.96);
  color: #f7f2e9;
  box-shadow: var(--shadow);
  opacity: 0;
  pointer-events: none;
  transition: opacity 120ms ease, transform 120ms ease;
  font-size: 12px;
  line-height: 1.45;
  font-weight: 400;
  text-transform: none;
}

.tab:hover .tab-tip,
.tab:focus .tab-tip {
  opacity: 1;
  transform: translateX(-50%) translateY(-2px);
}

.panel-view {
  display: none;
}

.panel-view.is-active {
  display: block;
}

.card {
  grid-column: span 6;
  padding: 18px;
  border: 1px solid var(--line);
  border-radius: 22px;
  background: var(--bg-panel);
  box-shadow: var(--shadow);
  backdrop-filter: blur(10px);
}

.status-card,
.log-card {
  grid-column: span 12;
}

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

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

.pill {
  padding: 6px 10px;
  border-radius: 999px;
  background: rgba(15, 108, 92, 0.1);
  color: var(--accent-strong);
  font-size: 12px;
}

.stats {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 12px;
  margin-bottom: 14px;
}

.stat {
  padding: 14px;
  border-radius: 16px;
  background: rgba(255, 255, 255, 0.55);
  border: 1px solid rgba(21, 35, 29, 0.06);
}

.stat strong {
  display: block;
  font-size: 12px;
  color: var(--muted);
  margin-bottom: 8px;
}

.stat span {
  font-size: 22px;
  word-break: break-word;
}

.actions,
.inline-actions,
.submit-row,
.profile-link-row {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
}

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

button {
  border: 0;
  border-radius: 14px;
  padding: 12px 16px;
  background: var(--accent);
  color: #f8f3ec;
  cursor: pointer;
  transition: transform 120ms ease, background 120ms ease;
}

button:hover {
  transform: translateY(-1px);
  background: var(--accent-strong);
}

button:disabled {
  opacity: 0.72;
  cursor: wait;
  transform: none;
}

button.ghost {
  background: transparent;
  color: var(--ink);
  border: 1px solid var(--line);
}

button.ghost.danger {
  color: var(--warn);
  border-color: rgba(179, 82, 42, 0.28);
}

button.ghost.danger:hover {
  background: rgba(179, 82, 42, 0.08);
}

.button-busy {
  position: relative;
  padding-left: 42px;
}

.button-busy::before {
  content: "";
  position: absolute;
  left: 16px;
  top: 50%;
  width: 14px;
  height: 14px;
  margin-top: -7px;
  border-radius: 999px;
  border: 2px solid rgba(248, 243, 236, 0.35);
  border-top-color: rgba(248, 243, 236, 0.95);
  animation: spin 0.7s linear infinite;
}

button.ghost.button-busy::before {
  border: 2px solid rgba(21, 35, 29, 0.18);
  border-top-color: rgba(21, 35, 29, 0.9);
}

.form-grid,
.stack {
  display: grid;
  gap: 14px;
}

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

.subgrid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 14px;
}

label {
  display: grid;
  gap: 8px;
}

label span {
  font-size: 12px;
  color: var(--muted);
  letter-spacing: 0.02em;
}

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

.hint {
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 18px;
  height: 18px;
  border-radius: 999px;
  background: rgba(15, 108, 92, 0.12);
  color: var(--accent-strong);
  cursor: help;
  font-size: 11px;
  font-weight: 700;
  line-height: 1;
}

.tooltip {
  position: absolute;
  left: 50%;
  bottom: calc(100% + 10px);
  transform: translateX(-50%);
  width: 220px;
  padding: 10px 12px;
  border-radius: 12px;
  background: rgba(18, 32, 24, 0.96);
  color: #f7f2e9;
  box-shadow: var(--shadow);
  opacity: 0;
  pointer-events: none;
  transition: opacity 120ms ease, transform 120ms ease;
  font-size: 12px;
  line-height: 1.45;
  font-weight: 400;
}

.hint:hover .tooltip,
.hint:focus .tooltip {
  opacity: 1;
  transform: translateX(-50%) translateY(-2px);
}

input,
select,
textarea {
  width: 100%;
  padding: 12px 14px;
  border-radius: 14px;
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.85);
  color: var(--ink);
}

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

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

.profile-link-row {
  align-items: center;
  justify-content: space-between;
  padding: 14px 16px;
  border-radius: 16px;
  background: rgba(255, 255, 255, 0.6);
  border: 1px solid rgba(21, 35, 29, 0.08);
}

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

.profile-link {
  color: var(--accent-strong);
  text-decoration: none;
  font-size: 14px;
  word-break: break-all;
}

.profile-link:hover {
  text-decoration: underline;
}

.profile-link.disabled {
  color: var(--muted);
  pointer-events: none;
  text-decoration: none;
}

.advanced-box {
  border: 1px solid rgba(21, 35, 29, 0.08);
  border-radius: 18px;
  background: rgba(255, 255, 255, 0.55);
  overflow: hidden;
}

.advanced-box summary {
  list-style: none;
  cursor: pointer;
  padding: 14px 16px;
  font-size: 14px;
  color: var(--ink);
  font-weight: 600;
}

.advanced-box summary::-webkit-details-marker {
  display: none;
}

.advanced-box[open] summary {
  border-bottom: 1px solid rgba(21, 35, 29, 0.08);
}

.advanced-grid {
  display: grid;
  gap: 14px;
  padding: 14px 16px 16px;
}

.advanced-note {
  margin: 0;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.5;
}

.log-viewer {
  min-height: 360px;
  margin: 0;
  padding: 16px;
  border-radius: 16px;
  background: #122018;
  color: #dce7dd;
  overflow: auto;
  white-space: pre-wrap;
  word-break: break-word;
  font-family: Consolas, "SFMono-Regular", monospace;
  font-size: 12px;
  line-height: 1.45;
}

.toast {
  position: fixed;
  right: 18px;
  bottom: 18px;
  padding: 12px 14px;
  max-width: min(360px, calc(100vw - 24px));
  border-radius: 14px;
  background: rgba(18, 32, 24, 0.95);
  color: #f7f2e9;
  box-shadow: var(--shadow);
}

.hidden {
  display: none;
}

.auth-gate {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: grid;
  place-items: center;
  background:
    radial-gradient(circle at top left, rgba(15, 108, 92, 0.22), transparent 38%),
    radial-gradient(circle at bottom right, rgba(179, 82, 42, 0.2), transparent 40%),
    rgba(17, 25, 20, 0.58);
  backdrop-filter: blur(8px);
}

.auth-gate.hidden {
  display: none;
}

.auth-card {
  width: min(420px, calc(100vw - 24px));
  padding: 24px;
  border-radius: 20px;
  border: 1px solid rgba(21, 35, 29, 0.12);
  background: rgba(255, 251, 244, 0.96);
  box-shadow: var(--shadow);
  display: grid;
  gap: 12px;
}

.auth-note {
  margin: 0;
  color: var(--muted);
  font-size: 14px;
}

.auth-actions {
  display: flex;
  justify-content: end;
}

.auth-error {
  margin: 0;
  padding: 10px 12px;
  border-radius: 12px;
  color: #912f20;
  background: rgba(179, 82, 42, 0.12);
  border: 1px solid rgba(179, 82, 42, 0.24);
  font-size: 13px;
}

@keyframes spin {
  from {
    transform: rotate(0deg);
  }
  to {
    transform: rotate(360deg);
  }
}

@media (max-width: 920px) {
  .card,
  .status-card,
  .log-card {
    grid-column: span 12;
  }

  .form-grid,
  .subgrid {
    grid-template-columns: 1fr;
  }

  .hero {
    flex-direction: column;
    align-items: start;
  }

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

  .instance-badge {
    max-width: 100%;
  }

  .tab-tip,
  .tooltip {
    width: min(240px, calc(100vw - 48px));
    left: 0;
    transform: translateX(0);
  }
}

@media (max-width: 640px) {
  .shell {
    width: calc(100vw - 20px);
    padding: 18px 0 24px;
  }

  .card {
    padding: 14px;
    border-radius: 18px;
  }

  button {
    width: 100%;
  }

  .actions button,
  .inline-actions button,
  .submit-row button {
    width: 100%;
  }

  .profile-link-row {
    align-items: start;
    flex-direction: column;
  }

  .log-viewer {
    min-height: 240px;
  }
}
