:root {
  --bg: #f5f5f7;
  --surface: #ffffff;
  --text: #1d1d1f;
  --muted: #86868b;
  --line: #e5e5ea;
  --line-soft: #f2f2f4;
  --accent: #14532d;
  --accent-hover: #0f4226;
  --accent-soft: #e8f3ec;
  --accent-muted: #2d6a4f;
  --sidebar-w: 220px;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font: 14px/1.6 -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
  color: var(--text);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
}

body:has(.layout) {
  height: 100vh;
  overflow: hidden;
}

a { color: var(--text); text-decoration: none; opacity: .85; }
a:hover { opacity: 1; }

.layout {
  display: flex;
  height: 100vh;
  min-height: 0;
  overflow: hidden;
}

/* ---- sidebar ---- */
.sidebar {
  width: var(--sidebar-w);
  flex-shrink: 0;
  height: 100vh;
  background: var(--surface);
  border-right: 1px solid var(--line);
  display: flex;
  flex-direction: column;
  padding: 28px 0 20px;
  overflow-y: auto;
  overscroll-behavior: contain;
}

.sidebar-title {
  padding: 0 24px 6px;
  font-size: 15px;
  font-weight: 600;
  letter-spacing: -.01em;
  color: var(--accent);
}

.sidebar-sub {
  padding: 0 24px 24px;
  font-size: 12px;
  color: var(--muted);
  border-bottom: 1px solid var(--line-soft);
}

.nav {
  flex: 1;
  padding: 16px 12px;
}

.nav a {
  display: block;
  padding: 9px 12px;
  margin-bottom: 2px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 500;
  transition: color .15s, background .15s;
}

.nav a:hover {
  color: var(--accent);
  background: var(--accent-soft);
}

.nav a.active {
  color: var(--accent);
  background: var(--accent-soft);
  font-weight: 600;
}

.nav-group {
  margin-bottom: 8px;
}

.nav-group-toggle {
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: 100%;
  padding: 9px 12px;
  border: none;
  background: transparent;
  color: var(--muted);
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  text-align: left;
}

.nav-group-toggle:hover,
.nav-group.open > .nav-group-toggle,
.nav-group-toggle.active {
  color: var(--accent);
  background: var(--accent-soft);
}

.nav-group-toggle::after {
  content: '▸';
  font-size: 12px;
  transition: transform .15s;
}

.nav-group.open > .nav-group-toggle::after {
  transform: rotate(90deg);
}

.nav-sub {
  display: none;
  padding: 4px 0 4px 10px;
}

.nav-group.open .nav-sub {
  display: block;
}

.nav-sub a {
  padding: 8px 12px 8px 18px;
  font-size: 12px;
}

.nav-sub-empty {
  display: block;
  padding: 8px 12px 8px 18px;
  font-size: 12px;
  color: var(--muted);
}

.panel-head-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
}

.panel-head-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.admin-modal-box-domain {
  max-width: 420px;
}

.admin-modal-head-green {
  background: var(--accent);
  border-bottom: none;
}

.admin-modal-head-green h3 {
  color: #fff;
}

.admin-modal-close-light {
  color: rgba(255, 255, 255, 0.85);
}

.admin-modal-close-light:hover {
  color: #fff;
}

.btn-block {
  width: 100%;
  justify-content: center;
}

.panel-head-row .panel-title {
  margin: 0;
}

tr.row-active td {
  background: var(--accent-soft);
}

.sidebar-foot {
  padding: 16px 24px 0;
  border-top: 1px solid var(--line-soft);
  margin-top: 8px;
}

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

.sidebar-foot a:hover { color: var(--text); }

/* ---- main ---- */
.content {
  flex: 1;
  min-width: 0;
  min-height: 0;
  height: 100vh;
  display: flex;
  flex-direction: column;
  overflow-y: auto;
  overflow-x: hidden;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
}

.page-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 32px 40px 0;
}

.page-head h1 {
  margin: 0;
  font-size: 22px;
  font-weight: 600;
  letter-spacing: -.02em;
  color: var(--text);
}

.page-body {
  padding: 24px 40px 48px;
  max-width: 1080px;
}

.alert {
  margin: 16px 40px 0;
  max-width: 1000px;
  padding: 10px 14px;
  font-size: 13px;
  background: var(--surface);
  border: 1px solid var(--line);
  color: var(--text);
}

.alert-success { border-left: 3px solid #34c759; }
.alert-info { border-left: 3px solid #ff9500; }
.alert-error { border-left: 3px solid #dc2626; background: #fef2f2; color: #991b1b; }

/* ---- stats ---- */
.stats {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 16px;
  margin-bottom: 24px;
}

.stat-item {
  background: var(--surface);
  border: 1px solid var(--line);
  padding: 20px 22px;
}

.stat-item .label {
  font-size: 12px;
  color: var(--muted);
  font-weight: 500;
  letter-spacing: .02em;
}

.stat-item .value {
  margin-top: 8px;
  font-size: 26px;
  font-weight: 600;
  letter-spacing: -.03em;
  color: var(--text);
  line-height: 1.2;
}

/* ---- panels ---- */
.panel {
  background: var(--surface);
  border: 1px solid var(--line);
  padding: 28px 32px;
  margin-bottom: 20px;
}

.panel:last-child { margin-bottom: 0; }

.panel-title {
  margin: 0 0 20px;
  font-size: 13px;
  font-weight: 600;
  color: var(--text);
  letter-spacing: -.01em;
}

.section-title {
  margin: 28px 0 16px;
  padding-top: 28px;
  border-top: 1px solid var(--line-soft);
  font-size: 12px;
  font-weight: 600;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: .06em;
}

.section-title:first-child {
  margin-top: 0;
  padding-top: 0;
  border-top: none;
}

.grid-2 {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0 24px;
}

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

/* ---- form ---- */
.field { margin-bottom: 18px; }

.field label {
  display: block;
  margin-bottom: 6px;
  font-size: 13px;
  font-weight: 500;
  color: var(--text);
}

.field input,
.field textarea,
.field select {
  width: 100%;
  border: 1px solid var(--line);
  padding: 10px 12px;
  font-size: 14px;
  background: var(--surface);
  color: var(--text);
  transition: border-color .15s;
}

.field input::placeholder,
.field textarea::placeholder {
  color: #aeaeb2;
}

.field input:focus,
.field textarea:focus,
.field select:focus {
  outline: none;
  border-color: var(--text);
}

.field input[readonly] {
  background: var(--line-soft);
  color: var(--muted);
}

.field textarea { min-height: 100px; resize: vertical; }

.hint {
  margin-top: 6px;
  font-size: 12px;
  color: var(--muted);
  line-height: 1.5;
}

.copy-row {
  display: flex;
  gap: 10px;
}

.copy-row input {
  flex: 1;
  min-width: 0;
  border: 1px solid var(--line);
  padding: 10px 12px;
  font-size: 14px;
  background: var(--surface);
}

.pkg-block {
  border: 1px solid var(--line);
  padding: 20px;
  background: var(--surface);
}

.pkg-block h4 {
  margin: 0 0 16px;
  font-size: 13px;
  font-weight: 600;
  color: var(--text);
}

.switch-row {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  margin-right: 20px;
  margin-top: 8px;
  font-size: 13px;
  color: var(--text);
}

/* ---- buttons ---- */
.btn {
  display: inline-block;
  padding: 9px 20px;
  font-size: 13px;
  font-weight: 500;
  border: 1px solid transparent;
  cursor: pointer;
  background: none;
  line-height: 1.4;
  text-align: center;
  transition: background .15s, border-color .15s, color .15s;
}

.btn-primary {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
}

.btn-primary:hover {
  background: var(--accent-hover);
  border-color: var(--accent-hover);
  color: #fff;
}

.btn-default {
  background: var(--surface);
  border-color: var(--line);
  color: var(--text);
}

.btn-default:hover {
  border-color: #c7c7cc;
  color: var(--text);
}

.btn-danger {
  background: #fff;
  border-color: #dc2626;
  color: #dc2626;
}

.btn-danger:hover {
  background: #fef2f2;
  border-color: #b91c1c;
  color: #b91c1c;
}

.btn-sm { padding: 7px 14px; font-size: 12px; }

.inline-form {
  display: inline-block;
  margin-top: 8px;
}

.action-row {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.action-row .inline-form {
  margin-top: 0;
}

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

.project-card {
  border: 1px solid var(--line);
  background: var(--surface);
  padding: 16px 18px;
}

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

.project-card-head code {
  font-size: 11px;
  color: var(--muted);
}

.back-link {
  display: inline-block;
  margin-right: 12px;
  font-size: 13px;
  font-weight: normal;
  color: var(--muted);
}

.back-link:hover {
  color: var(--accent);
}

.form-bar {
  margin-top: 28px;
  padding-top: 24px;
  border-top: 1px solid var(--line-soft);
}

/* ---- table ---- */
table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}

th, td {
  padding: 12px 0;
  text-align: left;
  border-bottom: 1px solid var(--line-soft);
}

th {
  font-weight: 500;
  font-size: 12px;
  color: var(--muted);
  border-bottom-color: var(--line);
}

td { color: var(--text); }

tbody tr:last-child td { border-bottom: none; }

.tag {
  display: inline-block;
  padding: 2px 8px;
  font-size: 11px;
  font-weight: 500;
  letter-spacing: .02em;
}

.tag.ok { color: #248a3d; background: #f0faf3; }
.tag.wait { color: #b45309; background: #fff8f0; }

code {
  font-size: 12px;
  color: var(--muted);
  background: var(--line-soft);
  padding: 2px 6px;
}

.preview-img {
  max-width: 100%;
  max-height: 240px;
  width: auto;
  height: auto;
  margin-top: 0;
  display: block;
  border: 1px solid var(--line);
  border-radius: 8px;
  object-fit: contain;
  background: var(--line-soft);
}

.upload-field {
  margin-top: 8px;
}

.upload-btn {
  display: block;
  width: 100%;
  box-sizing: border-box;
  min-height: 40px;
  padding: 10px 20px;
  font-size: 14px;
  font-weight: 500;
  line-height: 1.4;
  color: #fff;
  text-align: center;
  background: var(--accent);
  border: none;
  border-radius: 0;
  cursor: pointer;
  transition: background .15s;
}

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

.upload-btn-text {
  display: block;
  pointer-events: none;
}

.upload-input-native,
.upload-field input[type="file"] {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
  opacity: 0;
}

.upload-preview-box {
  display: none;
  margin-top: 12px;
}

.upload-preview-box.has-image {
  display: block;
}

/* ---- login ---- */
.login-page {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background: var(--bg);
}

.login-box {
  width: 100%;
  max-width: 360px;
  background: var(--surface);
  border: 1px solid var(--line);
  padding: 40px 36px;
}

.login-box h2 {
  margin: 0 0 6px;
  font-size: 20px;
  font-weight: 600;
  letter-spacing: -.02em;
}

.login-box p {
  margin: 0 0 28px;
  font-size: 13px;
  color: var(--muted);
}

.login-box .btn-primary {
  width: 100%;
  margin-top: 8px;
  padding: 11px 20px;
}

details summary {
  cursor: pointer;
  font-size: 13px;
  color: var(--muted);
}

details summary:hover { color: var(--text); }

details form {
  margin-top: 12px;
  padding: 16px;
  background: var(--line-soft);
  border: 1px solid var(--line);
}

body.modal-open {
  overflow: hidden;
}

.admin-modal {
  position: fixed;
  inset: 0;
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}

.admin-modal[hidden] {
  display: none !important;
}

.admin-modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(15, 23, 42, 0.45);
}

.admin-modal-box {
  position: relative;
  width: 100%;
  max-width: 480px;
  max-height: calc(100vh - 40px);
  overflow: auto;
  background: var(--surface);
  border: 1px solid var(--line);
  box-shadow: 0 20px 50px rgba(15, 23, 42, 0.18);
}

.admin-modal-box-sm {
  max-width: 400px;
}

.admin-modal-box-tpl {
  max-width: 520px;
  max-height: min(92vh, 860px);
  display: flex;
  flex-direction: column;
}

.admin-modal-box-tpl form {
  display: flex;
  flex-direction: column;
  min-height: 0;
  flex: 1;
}

.admin-modal-box-tpl .admin-modal-body {
  overflow-y: auto;
  flex: 1;
  min-height: 0;
  -webkit-overflow-scrolling: touch;
}

.tpl-modal-section {
  padding-bottom: 20px;
  margin-bottom: 20px;
  border-bottom: 1px solid var(--line-soft);
}

.tpl-modal-section:last-child {
  border-bottom: none;
  margin-bottom: 0;
  padding-bottom: 0;
}

.tpl-modal-section h4 {
  margin: 0 0 12px;
  font-size: 14px;
  font-weight: 600;
}

.tpl-modal-save-bar {
  margin-top: 4px;
  padding-top: 16px;
  border-top: 1px solid var(--line-soft);
}

.admin-modal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 16px 20px;
  border-bottom: 1px solid var(--line);
}

.admin-modal-head h3 {
  margin: 0;
  font-size: 16px;
  font-weight: 600;
}

.admin-modal-close {
  border: none;
  background: transparent;
  font-size: 22px;
  line-height: 1;
  cursor: pointer;
  color: var(--muted);
  padding: 0 4px;
}

.admin-modal-close:hover {
  color: var(--text);
}

.admin-modal-body {
  padding: 20px;
}

.admin-modal-foot {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 20px;
  padding-top: 16px;
  border-top: 1px solid var(--line);
}

.bind-list {
  list-style: none;
  margin: 0 0 16px;
  padding: 0;
}

.bind-list li {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 0;
  border-bottom: 1px solid var(--line-soft);
}

.bind-list li:last-child {
  border-bottom: none;
}

@media (max-width: 960px) {
  body:has(.layout) {
    height: auto;
    overflow: auto;
  }
  .layout {
    flex-direction: column;
    height: auto;
    overflow: visible;
  }
  .sidebar {
    width: 100%;
    height: auto;
    padding: 16px 0;
    overflow: visible;
  }
  .content {
    height: auto;
    overflow: visible;
  }
  .nav {
    display: flex;
    flex-wrap: wrap;
    gap: 4px;
    padding: 12px;
  }
  .nav a { margin-bottom: 0; }
  .page-head { padding: 20px 20px 0; }
  .page-body { padding: 16px 20px 32px; }
  .alert { margin: 12px 20px 0; }
  .stats { grid-template-columns: repeat(2, 1fr); }
  .grid-2, .grid-3 { grid-template-columns: 1fr; }
}
