:root {
  --bg: #f4f6f9;
  --surface: #fff;
  --border: #e2e8f0;
  --text: #1e293b;
  --muted: #64748b;
  --primary: #2563eb;
  --primary-dark: #1d4ed8;
  --danger: #dc2626;
  --success: #16a34a;
  --sidebar: #0f172a;
  --sidebar-text: #cbd5e1;
  --radius: 10px;
  --shadow: 0 1px 3px rgba(15, 23, 42, 0.08);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'PingFang SC', 'Microsoft YaHei', sans-serif;
  color: var(--text);
  background: var(--bg);
  line-height: 1.5;
}

a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }

.admin-layout {
  display: flex;
  min-height: 100vh;
}

.sidebar {
  width: 240px;
  background: var(--sidebar);
  color: var(--sidebar-text);
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
}

.sidebar-brand {
  padding: 1.5rem 1.25rem;
  border-bottom: 1px solid rgba(255,255,255,0.08);
}

.sidebar-logo {
  display: block;
  font-weight: 700;
  font-size: 1.1rem;
  color: #fff;
}

.sidebar-sub {
  font-size: 0.8rem;
  opacity: 0.7;
}

.sidebar-nav {
  padding: 1rem 0;
  flex: 1;
}

.sidebar-link {
  display: block;
  padding: 0.65rem 1.25rem;
  color: var(--sidebar-text);
  text-decoration: none;
  border: none;
  background: none;
  width: 100%;
  text-align: left;
  font-size: 0.95rem;
  cursor: pointer;
}

.sidebar-link:hover,
.sidebar-nav a.sidebar-link:hover {
  background: rgba(255,255,255,0.06);
  color: #fff;
  text-decoration: none;
}

.sidebar-link-label {
  position: relative;
  display: inline-block;
  padding-right: 4px;
}

.sidebar-badge {
  position: absolute;
  top: -8px;
  right: -14px;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: #ef4444;
  color: #fff;
  font-size: 11px;
  font-weight: 700;
  line-height: 18px;
  text-align: center;
  box-shadow: 0 0 0 2px var(--sidebar);
  pointer-events: none;
  box-sizing: border-box;
}

.sidebar-badge[data-wide="true"] {
  width: auto;
  min-width: 18px;
  height: 18px;
  padding: 0 5px;
  border-radius: 9px;
}

.sidebar-badge[hidden] {
  display: none !important;
}

.sidebar-footer {
  padding: 1rem 0;
  border-top: 1px solid rgba(255,255,255,0.08);
}

.sidebar-logout { color: #f87171; }

.admin-main {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 1rem 1.5rem;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  min-height: 56px;
}

.topbar h1 {
  margin: 0;
  font-size: 1.35rem;
}

.topbar-user {
  color: var(--muted);
  font-size: 0.9rem;
}

.admin-content {
  padding: 1.5rem;
  flex: 1;
}

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.25rem;
  margin-bottom: 1rem;
  box-shadow: var(--shadow);
}

.card h2 {
  margin: 0 0 1rem;
  font-size: 1.05rem;
}

.card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 1rem;
}

.card-header h2 { margin: 0; }

.stats-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 1rem;
  margin-bottom: 1.5rem;
}

.stat-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.25rem;
  box-shadow: var(--shadow);
}

.stat-highlight {
  border-color: var(--primary);
  background: #eff6ff;
}

.stat-label {
  display: block;
  font-size: 0.85rem;
  color: var(--muted);
}

.stat-value {
  display: block;
  font-size: 2rem;
  font-weight: 700;
  line-height: 1.2;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0.55rem 1rem;
  border-radius: 8px;
  border: 1px solid transparent;
  font-size: 0.9rem;
  font-weight: 500;
  cursor: pointer;
  text-decoration: none;
  background: transparent;
}

.btn:hover { text-decoration: none; }

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

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

.btn-outline {
  border-color: var(--border);
  color: var(--text);
  background: #fff;
}

.btn-outline:hover {
  background: var(--bg);
  color: var(--text);
}

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

.btn-sm { padding: 0.35rem 0.75rem; font-size: 0.82rem; }
.btn-block { width: 100%; }
.btn-lg { padding: 0.75rem 1.25rem; }

.alert {
  padding: 0.75rem 1rem;
  border-radius: 8px;
  margin-bottom: 1rem;
  font-size: 0.9rem;
}

.alert-success {
  background: #dcfce7;
  color: #166534;
  border: 1px solid #bbf7d0;
}

.alert-error {
  background: #fee2e2;
  color: #991b1b;
  border: 1px solid #fecaca;
}

.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.9rem;
}

.data-table th,
.data-table td {
  padding: 0.75rem;
  text-align: left;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}

.data-table th {
  font-weight: 600;
  color: var(--muted);
  font-size: 0.8rem;
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

.data-table tr:hover td { background: #f8fafc; }

.row-unread td { background: #eff6ff; }

.thumb {
  width: 48px;
  height: 48px;
  object-fit: cover;
  border-radius: 6px;
  border: 1px solid var(--border);
}

.badge {
  display: inline-block;
  padding: 0.2rem 0.55rem;
  border-radius: 999px;
  font-size: 0.75rem;
  font-weight: 600;
}

.badge-unread { background: #dbeafe; color: #1d4ed8; }
.badge-read { background: #f1f5f9; color: var(--muted); }
.badge-featured { background: #fef3c7; color: #92400e; }

.muted { color: var(--muted); font-size: 0.85rem; }

.page-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  margin-bottom: 1rem;
  flex-wrap: wrap;
}

.page-toolbar-actions {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  flex-shrink: 0;
}

.search-bar {
  display: flex;
  gap: 0.5rem;
}

.search-bar input {
  padding: 0.5rem 0.75rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  min-width: 220px;
}

.filter-tabs {
  display: flex;
  gap: 0.5rem;
}

.filter-tabs a {
  padding: 0.4rem 0.85rem;
  border-radius: 999px;
  border: 1px solid var(--border);
  color: var(--text);
  text-decoration: none;
  font-size: 0.85rem;
}

.filter-tabs a.active {
  background: var(--primary);
  color: #fff;
  border-color: var(--primary);
}

.toolbar-right {
  display: flex;
  gap: 0.5rem;
}

.inline-form { display: inline; }

.actions-cell {
  display: flex;
  gap: 0.4rem;
  align-items: center;
}

.empty-state {
  text-align: center;
  color: var(--muted);
  padding: 2rem;
}

.quick-actions {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 1rem;
}

.action-card {
  display: block;
  padding: 1.25rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  text-decoration: none;
  color: var(--text);
  box-shadow: var(--shadow);
}

.action-card:hover {
  border-color: var(--primary);
  text-decoration: none;
}

.action-card strong { display: block; margin-bottom: 0.25rem; }
.action-card span { color: var(--muted); font-size: 0.85rem; }

.form-grid {
  display: grid;
  grid-template-columns: 1fr 320px;
  gap: 1rem;
  align-items: start;
}

.form-main .card:last-child { margin-bottom: 0; }

label {
  display: block;
  margin-bottom: 1rem;
  font-size: 0.85rem;
  font-weight: 500;
}

label:last-child { margin-bottom: 0; }

input[type="text"],
input[type="email"],
input[type="password"],
input[type="search"],
select,
textarea {
  display: block;
  width: 100%;
  margin-top: 0.35rem;
  padding: 0.55rem 0.75rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  font: inherit;
  background: #fff;
}

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

.field-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1rem;
}

.field-row-3 { grid-template-columns: 1fr 1fr 1fr; }
.field-row-2 { grid-template-columns: 1fr 1fr; }

.checkbox-label {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding-top: 1.5rem;
}

.checkbox-label input { width: auto; margin: 0; }

.image-upload {
  margin-bottom: 1rem;
}

.image-preview {
  width: 100%;
  min-height: 120px;
  border: 1px dashed var(--border);
  border-radius: 8px;
  margin: 0.5rem 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: #f8fafc;
  overflow: hidden;
}

.image-preview-wide { min-height: 160px; }

.image-preview img {
  max-width: 100%;
  max-height: 200px;
  object-fit: contain;
}

.settings-images {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1rem;
}

.settings-images .image-upload:last-child {
  grid-column: 1 / -1;
}

.form-actions-sticky {
  display: flex;
  gap: 0.5rem;
  flex-direction: column;
}

.hint {
  color: var(--muted);
  font-size: 0.85rem;
  margin: -0.5rem 0 1rem;
}

.password-card .password-form {
  max-width: 420px;
}

.password-card .password-form label {
  display: block;
  margin-bottom: 1rem;
}

.password-card .password-form label input {
  display: block;
  width: 100%;
  margin-top: 0.35rem;
  padding: 0.55rem 0.75rem;
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 0.95rem;
}

.password-card .field-hint {
  display: block;
  margin-top: 0.25rem;
  font-size: 0.8rem;
  color: var(--muted);
}

.field-hint {
  margin: 0 0 0.5rem;
  font-size: 0.8rem;
  color: var(--muted);
  line-height: 1.5;
}

.image-spec-list {
  margin: 0 0 0.75rem;
  padding-left: 1.15rem;
  font-size: 0.8rem;
  color: var(--muted);
  line-height: 1.6;
}

.image-spec-list li + li {
  margin-top: 0.15rem;
}

.password-card .form-actions {
  display: flex;
  gap: 0.75rem;
  margin-top: 1.25rem;
  flex-wrap: wrap;
}

.password-card code {
  font-size: 0.85em;
  background: var(--bg);
  padding: 0.1rem 0.35rem;
  border-radius: 4px;
}

.sync-card .sync-meta {
  margin: 0 0 1rem;
  padding: 0;
  list-style: none;
  font-size: 0.9rem;
}

.sync-card .sync-meta li {
  margin-bottom: 0.35rem;
}

.sync-card .sync-meta code {
  font-size: 0.85em;
  background: var(--bg);
  padding: 0.1rem 0.35rem;
  border-radius: 4px;
}

.sync-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem;
}

.sync-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  margin-bottom: 1rem;
  padding: 1rem 1.25rem;
}

.sync-toolbar-text {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
  font-size: 0.9rem;
  color: var(--muted);
}

.sync-toolbar-text strong {
  color: var(--text);
  font-size: 1rem;
}

.sync-toolbar-text code {
  font-size: 0.85em;
  background: var(--bg);
  padding: 0.1rem 0.35rem;
  border-radius: 4px;
}

.sync-toolbar-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  flex-shrink: 0;
}

.sync-toolbar-alert {
  margin-bottom: 1rem;
}

.settings-page .form-actions-sticky {
  padding: 1rem;
}

.settings-page .form-actions-sticky .hint {
  margin: 0 0 0.75rem;
}

.page-intro {
  color: var(--muted);
  font-size: 0.9rem;
  margin: 0 0 1rem;
}

.category-list {
  display: flex;
  flex-direction: column;
  gap: 1rem;
  margin-bottom: 1rem;
}

.category-editor-head {
  display: flex;
  align-items: flex-end;
  gap: 1rem;
  margin-bottom: 0.5rem;
}

.category-editor-head label {
  flex: 1;
  margin-bottom: 0;
}

.categories-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem;
  align-items: center;
}

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

@media (max-width: 768px) {
  .sync-toolbar {
    flex-direction: column;
    align-items: stretch;
  }

  .category-editor-head {
    flex-direction: column;
    align-items: stretch;
  }
}

.detail-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1.5rem;
}

.detail-list {
  margin: 0;
}

.detail-list dt {
  font-size: 0.8rem;
  color: var(--muted);
  margin-top: 0.75rem;
}

.detail-list dt:first-child { margin-top: 0; }

.detail-list dd {
  margin: 0.15rem 0 0;
  font-weight: 500;
}

.inquiry-meta {
  display: flex;
  align-items: center;
  gap: 1rem;
  margin-bottom: 1.5rem;
}

.inquiry-message {
  margin-top: 1.5rem;
  padding-top: 1.5rem;
  border-top: 1px solid var(--border);
}

.inquiry-message p {
  background: #f8fafc;
  padding: 1rem;
  border-radius: 8px;
  white-space: pre-wrap;
}

.batch-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1rem;
}

.excel-sample-card {
  margin-bottom: 1rem;
}

.excel-sample-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 1rem;
  flex-wrap: wrap;
  margin-bottom: 1rem;
}

.excel-sample-header h2 {
  margin: 0 0 0.35rem;
}

.template-downloads {
  display: flex;
  gap: 0.5rem;
  flex-wrap: wrap;
}

.template-preview-wrap {
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 1rem;
  background: #f8fafc;
}

.template-preview-title {
  margin: 0 0 0.75rem;
  font-size: 0.88rem;
  font-weight: 600;
  color: var(--muted);
}

.template-table-scroll {
  overflow-x: auto;
  max-width: 100%;
}

.template-preview-table {
  font-size: 0.78rem;
}

.template-preview-table th,
.template-preview-table td {
  white-space: nowrap;
  max-width: 200px;
  overflow: hidden;
  text-overflow: ellipsis;
}

.template-note {
  margin: 0.75rem 0 0;
}

.batch-form label {
  margin-bottom: 1rem;
}

.import-result {
  margin-bottom: 1rem;
}

.import-stats {
  display: flex;
  gap: 1.5rem;
  margin-bottom: 1rem;
  font-size: 0.95rem;
}

.import-stats strong {
  color: var(--primary);
  font-size: 1.25rem;
}

.import-errors h3 {
  margin: 0 0 0.5rem;
  font-size: 0.95rem;
}

.import-errors ul {
  margin: 0;
  padding-left: 1.25rem;
  color: var(--muted);
  font-size: 0.88rem;
}

.import-errors li {
  margin-bottom: 0.35rem;
}

.hint code {
  background: #f1f5f9;
  padding: 0.1rem 0.35rem;
  border-radius: 4px;
  font-size: 0.85em;
}

@media (max-width: 1024px) {
  .batch-grid { grid-template-columns: 1fr; }
}

.login-page {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  background: linear-gradient(135deg, #0f172a 0%, #1e3a5f 100%);
}

.login-card {
  background: #fff;
  padding: 2rem;
  border-radius: 12px;
  width: 100%;
  max-width: 380px;
  box-shadow: 0 20px 50px rgba(0,0,0,0.2);
}

.login-brand {
  text-align: center;
  margin-bottom: 1.5rem;
}

.login-brand h1 {
  margin: 0;
  font-size: 1.5rem;
}

.login-brand p {
  margin: 0.25rem 0 0;
  color: var(--muted);
}

.login-form label { margin-bottom: 1rem; }

.topbar-heading {
  margin: 0;
  font-size: 1.35rem;
  display: flex;
  align-items: center;
  gap: 0.5rem;
  line-height: 1.4;
  overflow: visible;
}

.btn-icon-help {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  padding: 0;
  border: 1px solid var(--border);
  border-radius: 50%;
  background: var(--bg);
  color: var(--muted);
  cursor: pointer;
  flex-shrink: 0;
  text-decoration: none;
  line-height: 1;
  overflow: visible;
  transition: color 0.15s, border-color 0.15s, background 0.15s;
}

.btn-icon-help svg {
  display: block;
  flex-shrink: 0;
}

.btn-icon-help:hover {
  color: var(--primary);
  border-color: var(--primary);
  background: #eff6ff;
  text-decoration: none;
}

.field-help-page-title {
  margin: 0 0 1rem;
  font-size: 1.15rem;
}

.field-help-intro {
  margin: 0 0 1.25rem;
  color: var(--muted);
  font-size: 0.9rem;
  line-height: 1.6;
}

.field-help-intro code {
  font-size: 0.85em;
  background: var(--bg);
  padding: 0.1em 0.35em;
  border-radius: 4px;
}

.field-help-section {
  margin-bottom: 1.5rem;
}

.field-help-section:last-child {
  margin-bottom: 0;
}

.field-help-section h3 {
  margin: 0 0 0.75rem;
  font-size: 1rem;
  color: var(--text);
}

.field-help-table th:first-child {
  width: 28%;
  min-width: 140px;
}

.field-help-table td code {
  font-size: 0.85em;
  background: var(--bg);
  padding: 0.1em 0.35em;
  border-radius: 4px;
}

@media (max-width: 1024px) {
  .stats-grid { grid-template-columns: repeat(2, 1fr); }
  .form-grid { grid-template-columns: 1fr; }
  .quick-actions { grid-template-columns: 1fr; }
}

@media (max-width: 768px) {
  .admin-layout { flex-direction: column; }
  .sidebar { width: 100%; }
  .field-row,
  .field-row-3,
  .field-row-2,
  .detail-grid,
  .settings-images { grid-template-columns: 1fr; }
}
