:root {
  --bg: #f2f4f7;
  --panel: #ffffff;
  --border: #d7dee7;
  --text: #111827;
  --muted: #5f6b7a;
  --accent: #1c6b68;
  --accent-strong: #114b49;
  --accent-soft: #e2f0ee;
  --table-head: #f3f5f8;
  --danger: #b91c1c;
  --shadow: 0 12px 30px rgba(15, 23, 42, 0.08);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: "Source Han Sans SC", "HarmonyOS Sans SC", "Noto Sans SC", "PingFang SC", "Microsoft YaHei", sans-serif;
  color: var(--text);
  background-color: var(--bg);
  background-image: radial-gradient(rgba(197, 207, 219, 0.4) 1px, transparent 1px),
    linear-gradient(180deg, #f8fafc 0%, #eef2f6 100%);
  background-size: 22px 22px, 100% 100%;
}

a { color: inherit; text-decoration: none; }

.app {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

.topbar {
  background: rgba(244, 246, 248, 0.88);
  color: #111827;
  padding: 16px 28px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-bottom: 1px solid rgba(148, 163, 184, 0.28);
  box-shadow: 0 8px 18px rgba(15, 23, 42, 0.08);
  backdrop-filter: blur(6px);
}

.topbar .title {
  font-size: 18px;
  letter-spacing: 2px;
  font-weight: 600;
}

.topbar .user {
  font-size: 13px;
  opacity: 0.9;
}

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

.topbar .topbar-logout {
  border: 1px solid rgba(148, 163, 184, 0.42);
  background: rgba(255, 255, 255, 0.75);
  color: #1f2937;
  border-radius: 999px;
  padding: 6px 12px;
  font-size: 12px;
  cursor: pointer;
}

.topbar .topbar-logout:hover {
  background: rgba(255, 255, 255, 0.95);
}

.topbar .topbar-logout:disabled {
  cursor: not-allowed;
  opacity: 0.6;
}

.nav {
  display: flex;
  gap: 10px;
  padding: 10px 24px;
  background: rgba(248, 250, 252, 0.78);
  border-bottom: 1px solid rgba(148, 163, 184, 0.24);
  backdrop-filter: blur(6px);
}

.nav a {
  padding: 8px 14px;
  border-radius: 999px;
  font-size: 14px;
  color: #1f2937;
  border: 1px solid transparent;
}

.nav a.active {
  background: rgba(148, 163, 184, 0.14);
  border-color: rgba(148, 163, 184, 0.38);
  color: #0f172a;
  font-weight: 600;
}

.page {
  width: min(1200px, 100%);
  margin: 20px auto 40px;
  padding: 0 20px;
  display: grid;
  gap: 16px;
}

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

.panel h2 {
  margin: 0 0 14px 0;
  font-size: 18px;
  letter-spacing: 1px;
}

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

.form-row {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

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

.form-row input,
.form-row select,
.form-row textarea {
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 9px 12px;
  font-size: 14px;
  background: #fff;
  transition: border 0.2s ease, box-shadow 0.2s ease;
}

.form-row input:focus,
.form-row select:focus,
.form-row textarea:focus {
  outline: none;
  border-color: rgba(28, 107, 104, 0.6);
  box-shadow: 0 0 0 3px rgba(28, 107, 104, 0.12);
}

.form-row textarea { resize: vertical; min-height: 64px; }

.search-select {
  position: relative;
}

.search-select-native {
  display: none !important;
}

.search-select-input {
  width: 100%;
  padding-right: 32px !important;
}

.search-select::after {
  content: "▾";
  position: absolute;
  right: 12px;
  top: 50%;
  transform: translateY(-50%);
  color: #6b7280;
  pointer-events: none;
  transition: transform 0.15s ease;
}

.search-select.open::after {
  transform: translateY(-50%) rotate(180deg);
}

.search-select-menu {
  display: none;
  position: absolute;
  top: calc(100% + 6px);
  left: 0;
  width: 100%;
  max-height: 260px;
  overflow-y: auto;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: #fff;
  box-shadow: 0 12px 24px rgba(15, 23, 42, 0.14);
  z-index: 35;
}

.search-select.open .search-select-menu {
  display: block;
}

.search-select-option {
  display: block;
  width: 100%;
  border: none;
  background: #fff;
  text-align: left;
  padding: 9px 12px;
  font-size: 14px;
  cursor: pointer;
  color: #0f172a;
}

.search-select-option:hover,
.search-select-option.active {
  background: #eef6f5;
}

.search-select-option.selected {
  background: #e2f0ee;
  color: #0f4d49;
  font-weight: 600;
}

.search-select-empty {
  padding: 10px 12px;
  color: #64748b;
  font-size: 13px;
}

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

.btn {
  padding: 8px 16px;
  border: 1px solid var(--border);
  background: #fff;
  border-radius: 8px;
  cursor: pointer;
  font-size: 14px;
  transition: transform 0.12s ease, box-shadow 0.2s ease, border 0.2s ease;
}

.btn:hover { transform: translateY(-1px); box-shadow: 0 6px 12px rgba(15, 23, 42, 0.12); }

.btn.primary {
  background: linear-gradient(120deg, var(--accent) 0%, #2b8a7d 100%);
  color: #fff;
  border-color: transparent;
}

.btn.secondary {
  background: #f8fafc;
}

.btn.danger {
  background: #fef2f2;
  border-color: #fecaca;
  color: var(--danger);
}

.table {
  width: 100%;
  border-collapse: collapse;
  font-size: 14px;
  background: #fff;
}

.table th,
.table td {
  border: 1px solid var(--border);
  padding: 8px 10px;
  text-align: left;
  position: relative;
  overflow: visible;
}

.table th {
  background: var(--table-head);
  font-weight: 600;
}

.table tbody tr:nth-child(odd) {
  background: #fafbfc;
}

.table input {
  width: 100%;
  border: none;
  outline: none;
  font-size: 14px;
  background: transparent;
}

.typeahead-wrap {
  position: relative;
  width: 100%;
}

.typeahead-menu {
  display: none;
  position: absolute;
  left: 0;
  top: calc(100% + 4px);
  width: max(100%, 220px);
  max-height: 220px;
  overflow-y: auto;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: #fff;
  box-shadow: 0 10px 22px rgba(15, 23, 42, 0.14);
  z-index: 40;
}

.typeahead-wrap.open .typeahead-menu {
  display: block;
}

.typeahead-option {
  display: block;
  width: 100%;
  border: none;
  background: #fff;
  text-align: left;
  padding: 8px 10px;
  font-size: 13px;
  color: #0f172a;
  cursor: pointer;
}

.typeahead-option:hover,
.typeahead-option.active {
  background: #eef6f5;
}

.table .number { text-align: right; }

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

.message {
  color: var(--muted);
  font-size: 13px;
  white-space: pre-line;
  padding: 4px 0;
}

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

.custom-fields .form-row {
  margin: 0;
}

.tabs {
  display: flex;
  gap: 12px;
  border-bottom: 1px solid var(--border);
  padding-bottom: 6px;
  margin-bottom: 12px;
}

.tabs button {
  background: none;
  border: none;
  font-size: 14px;
  padding: 6px 10px;
  cursor: pointer;
  color: var(--muted);
}

.tabs button.active {
  color: var(--text);
  border-bottom: 2px solid var(--accent);
}

.notice {
  border: 1px dashed var(--border);
  padding: 10px 12px;
  border-radius: 8px;
  background: #f8fafc;
  font-size: 13px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
}

.search-bar {
  display: grid;
  grid-template-columns: 1.5fr 1fr 1fr auto;
  gap: 8px;
  align-items: center;
}

.search-bar input {
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 8px 12px;
}

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

.stat-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 12px;
}

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

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

.stat-value {
  font-size: 22px;
  font-weight: 600;
  margin-top: 6px;
}

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

.filter-bar {
  display: flex;
  gap: 8px;
  align-items: center;
  flex-wrap: wrap;
}

.filter-bar input {
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 8px 12px;
  min-width: 240px;
}

.badge {
  display: inline-block;
  padding: 3px 8px;
  background: #e2e8f0;
  border-radius: 999px;
  font-size: 12px;
  color: #374151;
}

.editor-layout {
  display: grid;
  grid-template-columns: 2fr 1fr;
  gap: 16px;
}

.editor-toolbar {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  margin-bottom: 10px;
}

.editor-table td {
  min-width: 80px;
  height: 36px;
  cursor: pointer;
}

.editor-table td.selected {
  outline: 2px solid var(--accent);
  background: var(--accent-soft);
}

.editor-table-wrap {
  overflow-x: auto;
}

@media (max-width: 900px) {
  .editor-layout {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 1200px) {
  .form-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .search-bar { grid-template-columns: 1fr; }
}

@media (max-width: 720px) {
  .nav { flex-wrap: wrap; }
  .page { padding: 0 14px; }
  .form-grid { grid-template-columns: 1fr; }
}

.login-wrap {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(160deg, #f6f8fb 0%, #e8eef4 100%);
}

.login-card {
  width: 360px;
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 26px;
  box-shadow: var(--shadow);
}

.login-card h1 { margin: 0 0 16px; font-size: 20px; letter-spacing: 1px; }
