:root {
  --bg: #f4f7fb;
  --panel: #ffffff;
  --muted-panel: #f8fafc;
  --text: #172033;
  --muted: #66758a;
  --border: #d3dbe8;
  --primary: #0f766e;
  --primary-hover: #0b5f59;
  --secondary: #eef4fb;
  --danger: #b91c1c;
  --danger-hover: #991b1b;
  --shadow: 0 16px 38px rgba(15, 23, 42, 0.08);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: "PingFang SC", "Microsoft YaHei", system-ui, sans-serif;
}

button,
input,
textarea {
  font: inherit;
}

button {
  border: 0;
  border-radius: 8px;
  padding: 10px 14px;
  font-weight: 700;
  cursor: pointer;
}

button.primary {
  background: var(--primary);
  color: #fff;
}

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

button.secondary {
  background: var(--secondary);
  color: #1f2a3d;
  border: 1px solid var(--border);
}

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

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

button:disabled {
  cursor: not-allowed;
  opacity: 0.55;
}

input,
textarea {
  width: 100%;
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text);
  background: #fff;
  outline: none;
  padding: 9px 10px;
}

textarea {
  min-height: 80px;
  resize: vertical;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  line-height: 1.45;
}

input:focus,
textarea:focus {
  border-color: #74b7ac;
  box-shadow: 0 0 0 3px rgba(15, 118, 110, 0.12);
}

label {
  display: block;
  font-size: 14px;
  font-weight: 800;
  margin-bottom: 7px;
}

h1,
h2,
p {
  margin: 0;
}

h1 {
  font-size: 24px;
  line-height: 1.25;
}

h2 {
  font-size: 17px;
}

p,
.muted {
  color: var(--muted);
  line-height: 1.55;
}

.hidden {
  display: none !important;
}

.login-view {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
}

.login-panel {
  width: min(440px, 100%);
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 12px;
  box-shadow: var(--shadow);
  padding: 22px;
}

.login-panel p {
  margin: 8px 0 18px;
}

.login-panel input {
  margin-bottom: 13px;
}

.login-panel button {
  width: 100%;
}

.admin-view {
  min-height: 100vh;
  padding: 18px;
}

.topbar,
.workspace,
.sidebar {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 12px;
  box-shadow: var(--shadow);
}

.topbar {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 16px;
  padding: 16px 18px;
  margin-bottom: 14px;
}

.topbar-actions,
.btn-row,
.section-title {
  display: flex;
  align-items: center;
  gap: 10px;
}

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

.sidebar,
.workspace {
  padding: 14px;
}

.section-title {
  justify-content: space-between;
  margin-bottom: 12px;
}

.upload-box {
  border: 1px solid var(--border);
  background: var(--muted-panel);
  border-radius: 10px;
  padding: 10px;
  margin-bottom: 12px;
}

.file-input-hidden {
  display: none;
}

.upload-box button {
  width: 100%;
}

.save-state {
  display: inline-flex;
  align-items: center;
  min-height: 38px;
  border-radius: 999px;
  padding: 0 12px;
  border: 1px solid var(--border);
  background: var(--secondary);
  color: var(--muted);
  font-size: 13px;
  font-weight: 800;
  white-space: nowrap;
}

.save-state.dirty,
.save-state.saving {
  border-color: #f59e0b;
  background: #fffbeb;
  color: #92400e;
}

.save-state.saved {
  border-color: #5bbf95;
  background: #ecfdf5;
  color: #047857;
}

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

.package-list {
  display: grid;
  gap: 8px;
}

.package-item {
  width: 100%;
  border: 1px solid var(--border);
  background: #fff;
  border-radius: 9px;
  padding: 10px;
  text-align: left;
}

.package-item.active {
  border-color: #74b7ac;
  box-shadow: 0 0 0 3px rgba(15, 118, 110, 0.12);
}

.package-item strong {
  display: block;
  margin-bottom: 4px;
}

.package-item span {
  display: block;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.45;
}

.fields-empty {
  border: 1px dashed var(--border);
  border-radius: 10px;
  padding: 40px 16px;
  text-align: center;
  color: var(--muted);
  background: var(--muted-panel);
}

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

.field {
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--muted-panel);
  padding: 10px;
}

.field.invalid {
  border-color: #ef4444;
  background: #fef2f2;
}

.field.wide {
  grid-column: 1 / -1;
}

.field code {
  display: block;
  font-weight: 800;
  margin-bottom: 7px;
}

.field-note {
  min-height: 0;
  margin-bottom: 7px;
  font-size: 12px;
}

.field.invalid .field-note {
  color: var(--danger);
  font-weight: 800;
}

.invalid-control {
  border-color: #ef4444;
  background: #fffafa;
}

.invalid-control:focus {
  border-color: #ef4444;
  box-shadow: 0 0 0 3px rgba(239, 68, 68, 0.12);
}

.phone-json {
  white-space: nowrap;
  overflow-x: auto;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}

.data-panel {
  margin-top: 14px;
  border-top: 1px solid var(--border);
  padding-top: 14px;
}

.data-panel-top {
  margin-top: 0;
  margin-bottom: 14px;
}

.data-grid {
  display: grid;
  grid-template-columns: minmax(160px, 0.7fr) minmax(360px, 1.6fr) minmax(110px, 0.4fr);
  gap: 12px;
}

.inline-error {
  min-height: 20px;
  margin-top: 6px;
  color: var(--danger);
  font-size: 12px;
  font-weight: 800;
  line-height: 1.35;
}

.status {
  margin-top: 12px;
  margin-bottom: 12px;
  color: #0f766e;
  white-space: pre-wrap;
  line-height: 1.55;
}

.status.error {
  color: var(--danger);
}

@media (max-width: 900px) {
  .topbar,
  .section-title {
    flex-direction: column;
    align-items: stretch;
  }

  .layout,
  .field-list,
  .data-grid {
    grid-template-columns: 1fr;
  }
}
