:root {
  --forest-950: #0f291c;
  --forest-900: #163826;
  --forest-700: #315d3a;
  --leaf-500: #5ea352;
  --leaf-100: #e8f4e5;
  --solar-gold: #e9b949;
  --ink-900: #0f172a;
  --ink-700: #334155;
  --ink-500: #64748b;
  --line-200: #e2e8f0;
  --bg-app: #f4f7f5;
  --bg-card: #ffffff;
}

*, *::before, *::after { box-sizing: border-box; }

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Inter", "PingFang SC", "Microsoft YaHei", sans-serif;
  background: var(--bg-app);
  color: var(--ink-900);
  display: flex;
  min-height: 100vh;
}

/* Sidebar */
.sidebar {
  width: 248px;
  background: var(--forest-950);
  color: #d6e6dc;
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
  position: sticky;
  top: 0;
  height: 100vh;
}

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

.sidebar-brand strong {
  display: block;
  color: #fff;
  font-size: 16px;
  letter-spacing: -0.01em;
}

.sidebar-brand span {
  font-size: 12px;
  color: #93b5a0;
}

.sidebar-nav {
  padding: 14px 12px;
  display: flex;
  flex-direction: column;
  gap: 4px;
  flex: 1;
}

.nav-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 12px;
  border-radius: 9px;
  border: none;
  background: transparent;
  color: #cfe0d6;
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  text-align: left;
  transition: all 0.16s;
}

.nav-item:hover {
  background: rgba(255, 255, 255, 0.08);
  color: #fff;
}

.nav-item.active {
  background: var(--forest-700);
  color: #fff;
  font-weight: 600;
}

.nav-badge {
  background: var(--solar-gold);
  color: var(--forest-950);
  font-size: 11px;
  font-weight: 800;
  padding: 2px 7px;
  border-radius: 999px;
}

.sidebar-footer {
  padding: 14px 16px;
  border-top: 1px solid rgba(255, 255, 255, 0.08);
  font-size: 12px;
  color: #87a694;
}

/* Main Area */
.main {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 30;
  height: 64px;
  background: rgba(255, 255, 255, 0.94);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--line-200);
  padding: 0 28px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

.topbar-title {
  font-size: 17px;
  font-weight: 700;
  color: var(--forest-950);
}

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

.dirty-dot {
  font-size: 12.5px;
  color: #b45309;
  background: #fef3c7;
  padding: 4px 10px;
  border-radius: 999px;
  font-weight: 600;
  display: none;
}

.dirty-dot.show { display: inline-block; }

.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 14px;
  border-radius: 8px;
  font-size: 13.5px;
  font-weight: 600;
  cursor: pointer;
  border: 1px solid transparent;
  text-decoration: none;
  transition: all 0.16s;
}

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

.btn-outline {
  background: #fff;
  color: var(--ink-700);
  border-color: #cbd5e1;
}
.btn-outline:hover { border-color: var(--forest-700); color: var(--forest-700); }

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

.btn-sm { padding: 5px 10px; font-size: 12.5px; }

.content {
  padding: 26px 28px 60px;
  max-width: 1180px;
  width: 100%;
}

.panel { display: none; }
.panel.active { display: block; }

/* Cards & Metrics */
.kpi-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 16px;
  margin-bottom: 24px;
}

.kpi-card {
  background: var(--bg-card);
  border: 1px solid var(--line-200);
  border-radius: 12px;
  padding: 18px 20px;
}

.kpi-card span {
  display: block;
  font-size: 12.5px;
  color: var(--ink-500);
  margin-bottom: 6px;
}

.kpi-card strong {
  font-size: 28px;
  color: var(--forest-900);
}

.card {
  background: var(--bg-card);
  border: 1px solid var(--line-200);
  border-radius: 14px;
  padding: 22px;
  margin-bottom: 20px;
}

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

.card-head h3 {
  margin: 0;
  font-size: 16px;
  color: var(--forest-950);
}

.form-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 14px;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 5px;
}

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

.field label {
  font-size: 12.5px;
  font-weight: 600;
  color: var(--ink-700);
}

.field input,
.field select,
.field textarea {
  width: 100%;
  padding: 9px 11px;
  border: 1px solid #cbd5e1;
  border-radius: 8px;
  font-size: 13.5px;
  font-family: inherit;
  color: var(--ink-900);
  background: #fff;
}

.field input:focus,
.field select:focus,
.field textarea:focus {
  outline: none;
  border-color: var(--forest-700);
  box-shadow: 0 0 0 3px rgba(49, 93, 58, 0.12);
}

/* Editable Tables */
.table-wrap { overflow-x: auto; }

table.cms-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}

table.cms-table th {
  text-align: left;
  padding: 10px 10px;
  background: #f2f7f3;
  color: var(--forest-900);
  font-size: 12px;
  border-bottom: 1px solid var(--line-200);
}

table.cms-table td {
  padding: 8px 6px;
  border-bottom: 1px solid #eef2f0;
  vertical-align: top;
}

table.cms-table input,
table.cms-table select {
  width: 100%;
  padding: 6px 8px;
  border: 1px solid #d7e0ea;
  border-radius: 6px;
  font-size: 12.5px;
  font-family: inherit;
}

/* Item Cards (Products / Articles / Inquiries) */
.item-list {
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.item-card {
  border: 1px solid var(--line-200);
  border-radius: 12px;
  padding: 16px;
  background: #fbfdfb;
}

.item-card-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 12px;
}

.thumb-row {
  display: flex;
  align-items: center;
  gap: 12px;
}

.thumb-preview {
  width: 72px;
  height: 52px;
  border-radius: 8px;
  object-fit: cover;
  border: 1px solid var(--line-200);
  background: #e2e8f0;
}

.status-pill {
  display: inline-block;
  padding: 3px 9px;
  border-radius: 999px;
  font-size: 11.5px;
  font-weight: 700;
}

.status-New { background: #fef3c7; color: #92400e; }
.status-Quoted { background: #e0f2fe; color: #0369a1; }
.status-Followed\ Up { background: #e6f6e9; color: #166534; }

/* Toast */
.toast {
  position: fixed;
  right: 24px;
  bottom: 24px;
  background: var(--forest-950);
  color: #fff;
  padding: 12px 18px;
  border-radius: 10px;
  font-size: 13.5px;
  font-weight: 600;
  box-shadow: 0 12px 30px rgba(0, 0, 0, 0.22);
  opacity: 0;
  transform: translateY(10px);
  pointer-events: none;
  transition: all 0.22s ease;
  z-index: 90;
}

.toast.show {
  opacity: 1;
  transform: translateY(0);
}

/* Auth Login Gate Overlay */
.auth-gate {
  position: fixed;
  inset: 0;
  z-index: 200;
  background: radial-gradient(circle at top right, #1f4d35 0%, #0f291c 70%);
  display: none;
  align-items: center;
  justify-content: center;
  padding: 24px;
}

.auth-gate.show {
  display: flex;
}

.auth-card {
  width: 100%;
  max-width: 410px;
  background: #ffffff;
  border-radius: 16px;
  padding: 30px 28px;
  box-shadow: 0 24px 60px rgba(0, 0, 0, 0.35);
}

.auth-card h2 {
  margin: 0 0 6px;
  font-size: 20px;
  color: var(--forest-950);
}

.auth-card p {
  margin: 0 0 20px;
  font-size: 13.5px;
  color: var(--ink-500);
}

.auth-error {
  display: none;
  background: #fef2f2;
  border: 1px solid #fecaca;
  color: #b91c1c;
  padding: 9px 12px;
  border-radius: 8px;
  font-size: 13px;
  margin-bottom: 14px;
}

.auth-error.show {
  display: block;
}

/* Runtime Mode & Status Pills */
.mode-pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 10px;
  border-radius: 999px;
  font-size: 11.5px;
  font-weight: 700;
  margin-bottom: 8px;
  background: rgba(119, 190, 104, 0.16);
  color: #a9e59d;
  border: 1px solid rgba(119, 190, 104, 0.32);
}

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

.status-chip {
  border: 1px solid var(--line-200);
  border-radius: 10px;
  padding: 12px 14px;
  background: #fbfdfb;
}

.status-chip span {
  display: block;
  font-size: 12px;
  color: var(--ink-500);
  margin-bottom: 4px;
}

.status-chip strong {
  font-size: 13.5px;
  color: var(--forest-900);
}

@media (max-width: 900px) {
  body { flex-direction: column; }
  .sidebar { width: 100%; height: auto; position: static; }
  .kpi-grid, .form-grid, .status-grid { grid-template-columns: 1fr; }
}


/* ===== Visual Drag-and-Drop Builder & Split Preview Studio ===== */
.visual-studio {
  display: grid;
  grid-template-columns: 400px 1fr;
  gap: 18px;
  align-items: start;
}
.visual-controls {
  max-height: calc(100vh - 110px);
  overflow-y: auto;
  padding-right: 4px;
}
.theme-picker-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 8px;
}
.theme-choice {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 10px 12px;
  border: 1.5px solid #e2e8f0;
  border-radius: 10px;
  background: #fff;
  cursor: pointer;
  text-align: left;
  transition: all 0.15s ease;
}
.theme-choice:hover { border-color: #315d3a; background: #f8fafc; }
.theme-choice.active {
  border-color: #163826;
  background: #ecfdf5;
  box-shadow: 0 0 0 2px rgba(22, 56, 38, 0.14);
}
.theme-swatches {
  display: flex;
  gap: 4px;
  flex-shrink: 0;
}
.theme-swatch {
  width: 14px;
  height: 14px;
  border-radius: 999px;
  border: 1px solid rgba(0,0,0,.15);
}
.drag-sections-list {
  display: grid;
  gap: 6px;
}
.drag-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 8px 10px;
  background: #f8fafc;
  border: 1px solid #e2e8f0;
  border-radius: 8px;
  cursor: grab;
  font-size: 13px;
}
.drag-row.dragging { opacity: 0.45; border-style: dashed; border-color: #315d3a; }
.drag-handle { color: #64748b; font-weight: 700; cursor: grab; padding-right: 4px; }
.drag-actions { display: flex; align-items: center; gap: 4px; }
.drag-mini-btn {
  border: 1px solid #cbd5e1;
  background: #fff;
  border-radius: 6px;
  padding: 2px 6px;
  font-size: 11.5px;
  cursor: pointer;
}
.drag-mini-btn:hover { background: #e2e8f0; }

.style-control-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}
.style-control-grid .full { grid-column: 1 / -1; }
.color-row {
  display: flex;
  align-items: center;
  gap: 6px;
}
.color-row input[type="color"] {
  width: 36px;
  height: 34px;
  padding: 2px;
  border: 1px solid #cbd5e1;
  border-radius: 6px;
  cursor: pointer;
}
.visual-preview-pane {
  background: #e2e8f0;
  border: 1px solid #cbd5e1;
  border-radius: 14px;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  height: calc(100vh - 110px);
}
.preview-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 10px 14px;
  background: #fff;
  border-bottom: 1px solid #cbd5e1;
}
.preview-stage {
  flex: 1;
  display: flex;
  justify-content: center;
  align-items: stretch;
  padding: 12px;
  overflow: auto;
}
#live-preview-frame {
  width: 100%;
  height: 100%;
  border: 1px solid #cbd5e1;
  border-radius: 10px;
  background: #fff;
  transition: width 0.25s ease;
}
.preview-stage.mobile #live-preview-frame {
  width: 390px;
  border: 8px solid #0f172a;
  border-radius: 28px;
  box-shadow: 0 20px 50px rgba(0, 0, 0, 0.25);
}

@media (max-width: 1100px) {
  .visual-studio { grid-template-columns: 1fr; }
  .visual-preview-pane { height: 640px; }
}
