@import url("https://fonts.googleapis.com/css2?family=Manrope:wght@400;600;700;800&family=IBM+Plex+Mono:wght@400;500&display=swap");

:root {
  --bg: #f5f7f0;
  --bg-strong: #dce7ca;
  --panel: #ffffff;
  --text: #1e2816;
  --muted: #526048;
  --accent: #1a8f6e;
  --accent-2: #2f63b8;
  --danger: #bf2d2d;
  --warning: #f59e0b;
  --success: #10b981;
  --border: #d8dfcc;
  --shadow: 0 20px 45px rgba(26, 53, 40, 0.1);

  /* Spacing System */
  --space-1: 4px;
  --space-2: 8px;
  --space-3: 12px;
  --space-4: 16px;
  --space-6: 24px;
  --space-8: 32px;
}

/* Utility Classes */
.mt-1 { margin-top: var(--space-1); }
.mt-2 { margin-top: var(--space-2); }
.mt-3 { margin-top: var(--space-3); }
.mt-4 { margin-top: var(--space-4); }
.mt-6 { margin-top: var(--space-6); }

.mb-1 { margin-bottom: var(--space-1); }
.mb-2 { margin-bottom: var(--space-2); }
.mb-3 { margin-bottom: var(--space-3); }
.mb-4 { margin-bottom: var(--space-4); }

.gap-2 { gap: var(--space-2); }
.gap-3 { gap: var(--space-3); }
.gap-4 { gap: var(--space-4); }

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: "Manrope", sans-serif;
  color: var(--text);
  background: radial-gradient(circle at 10% -20%, #f6fbd6, transparent 30%),
    radial-gradient(circle at 95% 20%, #d6eceb, transparent 35%),
    linear-gradient(135deg, var(--bg), var(--bg-strong));
  min-height: 100vh;
}

a {
  color: var(--accent-2);
  text-decoration: none;
}

a:hover {
  text-decoration: underline;
}

.shell {
  max-width: 1120px;
  margin: 0 auto;
  padding: 24px 16px 48px;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 16px;
  padding: 10px 14px;
  background: rgba(255, 255, 255, 0.75);
  border: 1px solid var(--border);
  border-radius: 14px;
  backdrop-filter: blur(6px);
}

.topbar h1 {
  margin: 0;
  font-size: 18px;
  letter-spacing: 0.02em;
}

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

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

.card + .card {
  margin-top: 16px;
}

.form-hero {
  border: 1px solid #cfdcb9;
  background: linear-gradient(135deg, #f8fff0, #eef5ff);
}

.form-kicker {
  display: inline-block;
  padding: 4px 10px;
  border-radius: 999px;
  background: #e3efcd;
  color: #2b5031;
  font-size: 12px;
  font-weight: 700;
  margin-bottom: 8px;
}

.heading {
  margin: 0 0 8px;
  font-size: 24px;
  font-weight: 800;
}

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

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

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

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

.basic-info-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(220px, 280px));
  gap: 14px;
  justify-content: start;
}

label {
  display: block;
  margin-bottom: 4px;
  font-size: 13px;
  font-weight: 700;
}

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

input[type="checkbox"],
input[type="radio"] {
  width: auto;
  border: 0;
  padding: 0;
  background: transparent;
  accent-color: var(--accent);
}

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

.pill-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.pill {
  border-radius: 999px;
  border: 1px solid var(--border);
  background: #f8faf4;
  padding: 4px 10px;
  font-size: 12px;
}

.btn-row {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

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

.form-section {
  border: 1px solid var(--border);
  border-radius: 14px;
  background: #fbfdf8;
  padding: 14px;
}

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

.req {
  color: var(--danger);
  font-weight: 800;
}

.choice-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
  gap: 8px;
}

.city-grid {
  max-height: 260px;
  overflow: auto;
  padding: 4px;
  border: 1px dashed var(--border);
  border-radius: 12px;
  background: #fff;
}

.choice-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 10px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: #fff;
}

.choice-chip span {
  font-size: 13px;
}

.building-choice-chip {
  align-items: flex-start;
}

.building-choice-chip input[type="checkbox"] {
  margin-top: 2px;
}

.building-options-grid {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: stretch;
}

.building-chip-content {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
  width: auto;
}

.building-options-grid .building-choice-chip {
  flex: 0 1 auto;
  width: auto;
  max-width: 100%;
  min-width: 260px;
}

.building-chip-name {
  font-size: 12px;
  font-weight: 700;
  color: var(--text);
  line-height: 1.3;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.building-chip-address {
  font-size: 12px;
  color: var(--muted);
  line-height: 1.3;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.choice-inline {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-bottom: 8px;
}

.choice-inline label {
  margin: 0;
  font-size: 14px;
  font-weight: 600;
  display: inline-flex;
  align-items: center;
  gap: 4px;
}

.agree-row {
  display: inline-flex;
  align-items: flex-start;
  gap: 8px;
  margin-top: 12px;
  font-size: 14px;
}

button,
.btn {
  border: 0;
  border-radius: 10px;
  padding: 10px 14px;
  font: inherit;
  font-weight: 700;
  cursor: pointer;
  background: var(--accent);
  color: #fff;
}

button.secondary,
.btn.secondary {
  background: #f2f5ee;
  color: var(--text);
  border: 1px solid var(--border);
}

button.danger {
  background: var(--danger);
}

.flash-error {
  background: #ffeaea;
  color: #812222;
  border: 1px solid #f3c3c3;
  border-radius: 10px;
  padding: 10px 12px;
}

.flash-ok {
  background: #eaf8f1;
  color: #1d6d45;
  border: 1px solid #badfc7;
  border-radius: 10px;
  padding: 10px 12px;
}

table {
  width: 100%;
  border-collapse: collapse;
}

th,
td {
  text-align: left;
  border-bottom: 1px solid var(--border);
  padding: 10px 8px;
  font-size: 14px;
}

th {
  color: var(--muted);
  font-weight: 700;
}

.th-sort-link {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  color: inherit;
  text-decoration: none;
}

.th-sort-link:hover {
  text-decoration: underline;
}

.mono {
  font-family: "IBM Plex Mono", monospace;
  font-size: 12px;
}

.status {
  display: inline-block;
  padding: 3px 9px;
  border-radius: 999px;
  font-size: 12px;
  border: 1px solid var(--border);
  background: #f7faf3;
}

.stat-card {
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 10px 12px;
  background: #f8fbf4;
}

.stat-num {
  font-size: 26px;
  font-weight: 800;
}

.btn-inline {
  margin-left: 8px;
  padding: 4px 8px;
  font-size: 12px;
}

.pager {
  display: flex;
  gap: 8px;
  align-items: center;
}

.disabled {
  opacity: 0.6;
  pointer-events: none;
}

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

.materials-box {
  max-height: 58vh;
  overflow: auto;
  border: 1px dashed var(--border);
  border-radius: 12px;
  background: #fff;
  padding: 12px;
}

.materials-pre {
  margin: 0;
  white-space: pre-wrap;
  line-height: 1.65;
  font: inherit;
}

.password-toggle {
  border: 1px solid var(--border);
  background: #fff;
  color: var(--text);
  border-radius: 8px;
  padding: 4px 8px;
  font-size: 12px;
  margin-left: 8px;
}

/* Status Colors */
.status-pending { background: #fff7ed; color: #9a3412; border-color: #fdba74; }
.status-approved { background: #f0fdf4; color: #166534; border-color: #86efac; }
.status-rejected { background: #fef2f2; color: #991b1b; border-color: #fecaca; }
.status-snatching { background: #eff6ff; color: #1e40af; border-color: #93c5fd; }

/* Spinner */
@keyframes spin {
  to { transform: rotate(360deg); }
}

.spinner {
  display: inline-block;
  width: 16px;
  height: 16px;
  border: 2px solid rgba(255,255,255,0.3);
  border-radius: 50%;
  border-top-color: #fff;
  animation: spin 0.8s linear infinite;
  margin-right: 8px;
  vertical-align: middle;
}

/* Empty State */
.empty-state {
  padding: 48px 20px;
  text-align: center;
  color: var(--muted);
}

.empty-state-icon {
  font-size: 48px;
  margin-bottom: 16px;
  display: block;
  opacity: 0.5;
}

/* Responsive Table */
@media (max-width: 820px) {
  .grid-2,
  .grid-3,
  .grid-4,
  .basic-info-grid {
    grid-template-columns: 1fr;
  }

  .topbar {
    flex-direction: column;
    align-items: flex-start;
    gap: 8px;
  }

  .table-responsive thead {
    display: none;
  }

  .table-responsive tr {
    display: block;
    border: 1px solid var(--border);
    border-radius: 12px;
    margin-bottom: 16px;
    padding: 12px;
    background: #fff;
  }

  .table-responsive td {
    display: flex;
    justify-content: space-between;
    border: 0;
    padding: 6px 0;
    font-size: 14px;
  }

  .table-responsive td::before {
    content: attr(data-label);
    font-weight: 700;
    color: var(--muted);
    margin-right: 16px;
  }
}

/* Form Grouping Improvements */
.sub-section-box {
  background: rgba(255, 255, 255, 0.6);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 16px;
  margin-top: 20px;
}

.sub-section-title {
  margin: 0 0 16px;
  font-size: 15px;
  font-weight: 700;
  color: var(--text);
  display: flex;
  align-items: center;
  gap: 8px;
}

.sub-section-title::before {
  content: '';
  display: block;
  width: 4px;
  height: 16px;
  background: var(--accent);
  border-radius: 2px;
}

.advanced-options {
  border: 1px solid var(--border);
  border-radius: 12px;
  background: #fafafa;
  margin-top: 24px;
}

.advanced-options summary {
  padding: 14px 16px;
  cursor: pointer;
  font-weight: 600;
  font-size: 14px;
  color: var(--text);
  display: flex;
  align-items: center;
  justify-content: space-between;
  user-select: none;
  outline: none;
}

.advanced-options summary:hover {
  background: #f0f0f0;
}
.advanced-options:not([open]) summary:hover {
  border-radius: 12px;
}
.advanced-options[open] summary:hover {
  border-radius: 12px 12px 0 0;
}

.advanced-options summary::after {
  content: '展开';
  font-size: 12px;
  background: #fff;
  padding: 2px 8px;
  border-radius: 6px;
  border: 1px solid var(--border);
  color: var(--muted);
}

.advanced-options[open] summary::after {
  content: '收起';
}

.advanced-options[open] summary {
  border-bottom: 1px solid var(--border);
  border-radius: 12px 12px 0 0;
}

.advanced-options-content {
  padding: 16px;
  background: #fff;
  border-radius: 0 0 12px 12px;
}
