:root {
  color-scheme: dark;
  --bg: #0b0b0a;
  --panel: #151514;
  --panel-2: #1d1c1a;
  --text: #f3f0e8;
  --muted: #aaa59a;
  --line: rgba(243, 240, 232, 0.14);
  --line-strong: rgba(243, 240, 232, 0.24);
  --accent: #c7a764;
  --accent-soft: rgba(199, 167, 100, 0.16);
}

* { box-sizing: border-box; }

html {
  min-height: 100%;
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--text);
  font-family: "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "Noto Sans CJK SC",
    system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

body:not(.auth-locked) {
  height: 100vh;
  overflow: hidden;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
}

button, input, select, textarea { font: inherit; }

button, a {
  border: 1px solid var(--line-strong);
  background: transparent;
  color: var(--text);
  text-decoration: none;
  cursor: pointer;
}

button:hover, a:hover { border-color: var(--accent); }

body.auth-locked {
  overflow: hidden;
}

body.auth-locked .admin-header,
body.auth-locked .admin-layout {
  display: none;
}

.auth-gate {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
  background:
    radial-gradient(circle at 50% 20%, rgba(199, 167, 100, 0.13), transparent 28rem),
    var(--bg);
}

.auth-card {
  width: min(420px, 100%);
  border: 1px solid var(--line);
  background: linear-gradient(180deg, #151514, #10100f);
  padding: 32px;
}

.auth-card p {
  margin: 0 0 10px;
  color: var(--accent);
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.16em;
  text-transform: uppercase;
}

.auth-card h1 {
  margin: 0 0 24px;
}

.auth-card label {
  display: grid;
  gap: 8px;
}

.auth-card span,
.auth-card small {
  color: var(--muted);
  font-size: 13px;
}

.auth-card input {
  width: 100%;
  border: 1px solid var(--line);
  background: var(--bg);
  color: var(--text);
  padding: 13px 14px;
  outline: none;
}

.auth-card input:focus {
  border-color: var(--accent);
}

.auth-card button {
  width: 100%;
  min-height: 44px;
  margin-top: 16px;
}

.auth-card button.primary {
  background: var(--text);
  color: var(--bg);
  border-color: var(--text);
  font-weight: 700;
}

body:not(.auth-locked) .auth-gate {
  display: none;
}

/* ===== Header ===== */
.admin-header {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  justify-content: space-between;
  gap: 20px;
  align-items: center;
  border-bottom: 1px solid var(--line);
  background: rgba(11, 11, 10, 0.88);
  padding: 20px 28px;
  backdrop-filter: blur(18px);
}

.admin-header p, .editor-title p, #previewType {
  margin: 0 0 8px;
  color: var(--accent);
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.16em;
  text-transform: uppercase;
}

.admin-header h1, .editor-title h2 { margin: 0; }

.admin-header nav {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
  justify-content: flex-end;
}

.sync-status {
  grid-column: 1 / -1;
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 10px;
  color: var(--muted);
  font-size: 12px;
}

.sync-status span {
  border: 1px solid rgba(243, 240, 232, 0.12);
  border-radius: 999px;
  padding: 6px 10px;
  background: rgba(255, 255, 255, 0.03);
}

.admin-header a, .admin-header button,
.sidebar-head button, .action-bar button {
  min-height: 42px;
  padding: 0 14px;
}

.admin-header a,
.admin-header button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 36px;
  padding: 0 16px;
  border-radius: 999px;
  border-color: rgba(243, 240, 232, 0.16);
  background: rgba(255, 255, 255, 0.035);
  color: var(--text);
  font-size: 14px;
  font-weight: 650;
  line-height: 1;
  white-space: nowrap;
  transition: border-color 140ms ease, background 140ms ease, color 140ms ease, transform 140ms ease;
}

.admin-header a:hover,
.admin-header button:hover {
  border-color: rgba(199, 167, 100, 0.7);
  background: rgba(199, 167, 100, 0.12);
  color: var(--accent);
  transform: translateY(-1px);
}

/* ===== Layout ===== */
.admin-layout {
  display: grid;
  grid-template-columns: 240px 1fr;
  min-height: 0;
  height: 100%;
  overflow: hidden;
}

/* ===== Module Nav (Sidebar) ===== */
.module-nav {
  border-right: 1px solid var(--line);
  background: #10100f;
  padding: 10px 0;
  height: 100%;
  min-height: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
}

.module-nav button {
  display: block;
  width: 100%;
  border: 0;
  border-bottom: 1px solid var(--line);
  padding: 16px 22px;
  text-align: left;
  font-size: 15px;
  font-weight: 600;
  color: var(--muted);
  background: transparent;
  transition: background 140ms ease, color 140ms ease;
}

.module-nav button:last-child { border-bottom: 0; }

.module-nav button.active {
  background: var(--accent-soft);
  color: var(--text);
  border-left: 3px solid var(--accent);
}

.module-nav button:hover:not(.active) {
  color: var(--text);
  background: rgba(255,255,255,0.04);
}

/* ===== Editor Panel ===== */
.editor-panel {
  padding: 28px;
  height: 100%;
  min-height: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
}

.editor-title {
  display: flex;
  justify-content: space-between;
  gap: 18px;
  align-items: flex-start;
  margin-bottom: 24px;
}

#saveState {
  border: 1px solid var(--line);
  padding: 8px 10px;
  color: var(--muted);
  font-size: 12px;
  white-space: nowrap;
}

#saveState.saved {
  border-color: var(--accent);
  color: var(--accent);
}

/* ===== Work Form ===== */
.work-form {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 14px;
}

.work-form label {
  display: grid;
  gap: 8px;
}

.work-form label.span-2 { grid-column: span 2; }

.work-form label.span-3 { grid-column: span 3; }

.featured-editor-section {
  grid-column: 1 / -1;
  padding: 22px;
  border: 1px solid rgba(199, 167, 100, 0.42);
  background: linear-gradient(135deg, rgba(199, 167, 100, 0.11), rgba(255, 255, 255, 0.018) 58%);
}

.featured-editor-heading {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 20px;
  margin-bottom: 20px;
}

.featured-editor-heading p {
  margin: 0 0 5px;
  color: var(--accent);
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.12em;
}

.featured-editor-heading h3 {
  margin: 0;
  color: var(--text);
  font-size: 23px;
}

.featured-editor-heading > span {
  color: var(--muted);
  font-size: 12px;
}

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

.featured-editor-grid label {
  display: grid;
  gap: 8px;
}

.featured-editor-grid .span-2 {
  grid-column: 1 / -1;
}

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

.work-form input,
.work-form select,
.work-form textarea {
  width: 100%;
  border: 1px solid var(--line);
  background: var(--panel);
  color: var(--text);
  padding: 12px;
  outline: none;
}

.work-form input:focus,
.work-form select:focus,
.work-form textarea:focus {
  border-color: var(--accent);
}

/* ===== Preview ===== */
.preview-panel {
  display: grid;
  grid-template-columns: 230px 1fr;
  gap: 18px;
  margin-top: 24px;
  border: 1px solid var(--line);
  background: var(--panel);
  padding: 16px;
}

.preview-cover {
  aspect-ratio: 16 / 10;
  background: #050505;
  overflow: hidden;
}

.preview-cover img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

#previewTitle { margin: 0; font-size: 24px; line-height: 1.25; }
#previewMeta { display: block; margin-top: 12px; color: var(--muted); }
#previewStats { display: block; margin-top: 14px; color: var(--accent); }

/* ===== Action Bar ===== */
.action-bar {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-top: 22px;
}

.action-bar .primary {
  background: var(--text);
  color: var(--bg);
  border-color: var(--text);
  font-weight: 700;
}

.note {
  max-width: 760px;
  color: var(--muted);
  line-height: 1.75;
}

.module-hint {
  margin: 0 0 16px;
  color: var(--muted);
  line-height: 1.7;
}

.editable-map {
  margin-top: 20px;
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.03);
  padding: 16px;
}

.editable-map h3 {
  margin: 0 0 10px;
  color: var(--accent);
  font-size: 16px;
}

.editable-map p {
  margin: 8px 0 0;
  color: var(--muted);
  line-height: 1.7;
}

.editable-map .list-editor {
  margin-top: 14px;
}

.sortable-card {
  cursor: grab;
  transition: border-color 140ms ease, background 140ms ease, opacity 140ms ease, transform 140ms ease;
}

.sortable-card:active {
  cursor: grabbing;
}

.sortable-card.dragging {
  opacity: 0.5;
  background: rgba(199, 167, 100, 0.08);
}

.sortable-card.drag-over {
  border-color: rgba(199, 167, 100, 0.8);
  box-shadow: inset 3px 0 0 var(--accent);
}

.drag-handle {
  display: inline-block;
  margin-right: 8px;
  color: var(--accent);
  letter-spacing: -0.2em;
  opacity: 0.72;
}

.image-picker {
  margin-top: 6px;
  color: var(--muted);
  font-size: 13px;
}

.field-note {
  display: block;
  margin-top: 6px;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.5;
}

.work-media-group {
  grid-column: 1 / -1;
  padding: 18px;
  border: 1px solid rgba(243, 240, 232, 0.14);
  background: rgba(255, 255, 255, 0.018);
}

.work-media-heading {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 18px;
  padding-bottom: 14px;
  margin-bottom: 16px;
  border-bottom: 1px solid rgba(243, 240, 232, 0.1);
}

.work-media-heading p {
  margin: 0 0 4px;
  color: var(--accent);
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.12em;
}

.work-media-heading h3 {
  margin: 0;
  color: var(--text);
  font-size: 18px;
}

.work-media-heading > span {
  color: var(--muted);
  font-size: 12px;
}

.work-media-grid {
  display: grid;
  grid-template-columns: minmax(0, 1.35fr) minmax(260px, 0.65fr);
  gap: 18px;
  align-items: start;
}

.playback-settings-grid {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.media-file-picker {
  min-height: 42px;
  margin-top: 0;
  color: var(--muted);
  font-size: 13px;
}

.video-upload-control {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-top: 2px;
}

.video-upload-control button {
  flex: 0 0 auto;
  min-height: 38px;
  border-color: rgba(199, 167, 100, 0.55);
  color: var(--accent);
}

.video-upload-control button:disabled {
  cursor: wait;
  opacity: 0.55;
}

.video-upload-control span {
  min-width: 0;
  overflow: hidden;
  color: var(--muted);
  font-size: 12px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.video-upload-progress {
  height: 4px;
  overflow: hidden;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.08);
}

.video-upload-progress i {
  display: block;
  width: 0;
  height: 100%;
  border-radius: inherit;
  background: linear-gradient(90deg, #8f6f35, var(--accent));
  transition: width 160ms ease;
}

/* ===== Skills Editor ===== */
.skills-editor {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-top: 12px;
}

.skill-chip {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 8px 14px;
  font-size: 14px;
  background: var(--panel);
  cursor: default;
  transition: border-color 140ms ease;
}

.skill-chip .remove-skill {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 18px;
  height: 18px;
  border: 0;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.1);
  color: var(--muted);
  font-size: 14px;
  line-height: 1;
  padding: 0;
  cursor: pointer;
  transition: background 140ms ease, color 140ms ease;
}

.skill-chip .remove-skill:hover {
  background: #c0392b;
  color: #fff;
}

.add-skill-row {
  display: flex;
  gap: 10px;
  margin-top: 16px;
  align-items: center;
}

.add-skill-row input {
  flex: 1;
  max-width: 300px;
  border: 1px solid var(--line);
  background: var(--panel);
  color: var(--text);
  padding: 10px 14px;
  outline: none;
}

.add-skill-row input:focus { border-color: var(--accent); }

/* ===== List Editor (Profile / Experience / Growth Path) ===== */
.list-editor {
  display: grid;
  gap: 14px;
}

.list-item-card {
  border: 1px solid var(--line);
  background: var(--panel);
  padding: 18px;
}

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

.list-item-card .item-header strong {
  font-size: 16px;
}

.list-item-card .item-header button {
  min-height: 32px;
  padding: 0 12px;
  font-size: 12px;
  background: rgba(192, 57, 43, 0.15);
  border-color: rgba(192, 57, 43, 0.3);
  color: #e74c3c;
}

.list-item-card .item-header button:hover {
  background: rgba(192, 57, 43, 0.3);
}

.list-item-card .item-fields {
  display: grid;
  gap: 10px;
}

.list-item-card .item-fields.two-cols {
  grid-template-columns: minmax(160px, 0.45fr) minmax(220px, 1fr);
}

.metric-image-editor {
  display: grid;
  grid-template-columns: 180px minmax(0, 1fr);
  gap: 14px;
  align-items: stretch;
  margin-top: 12px;
}

.metric-image-editor > label {
  display: grid;
  align-content: start;
  gap: 5px;
}

.metric-image-editor > label > span {
  color: var(--muted);
  font-size: 12px;
}

.metric-image-preview {
  display: grid;
  min-height: 112px;
  place-items: center;
  overflow: hidden;
  border: 1px solid var(--line);
  background: var(--bg);
}

.metric-image-preview img {
  width: 100%;
  height: 112px;
  object-fit: cover;
}

.metric-image-preview i {
  color: var(--muted);
  font-size: 12px;
  font-style: normal;
}

.list-item-card .item-fields label {
  display: grid;
  gap: 4px;
}

.list-item-card .item-fields span {
  color: var(--muted);
  font-size: 12px;
}

.list-item-card .item-fields input,
.list-item-card .item-fields select,
.list-item-card .item-fields textarea {
  width: 100%;
  border: 1px solid var(--line);
  background: var(--bg);
  color: var(--text);
  padding: 10px;
  outline: none;
}

.list-item-card .item-fields input:focus,
.list-item-card .item-fields select:focus,
.list-item-card .item-fields textarea:focus {
  border-color: var(--accent);
}

.list-item-card .array-field {
  display: grid;
  gap: 6px;
}

.list-item-card .array-field .array-row {
  display: flex;
  gap: 6px;
  align-items: center;
}

.list-item-card .array-field .array-row input {
  flex: 1;
}

.list-item-card .array-field .array-row button {
  min-height: 34px;
  width: 34px;
  padding: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.add-item-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-height: 40px;
  padding: 0 16px;
  border: 1px dashed var(--line-strong);
  background: transparent;
  color: var(--accent);
  cursor: pointer;
}

.add-item-btn:hover {
  border-color: var(--accent);
  background: var(--accent-soft);
}

/* ===== Work List (kept for edit/sidebar compat) ===== */
.works-editor-layout {
  display: grid;
  grid-template-columns: 320px minmax(0, 1fr);
  gap: 22px;
  align-items: start;
  min-height: 0;
}

.work-list-panel {
  position: sticky;
  top: 12px;
  display: flex;
  flex-direction: column;
  max-height: calc(100vh - 190px);
  min-height: 0;
  overflow: hidden;
}

.work-list-actions {
  display: flex;
  gap: 10px;
  margin-bottom: 12px;
  flex-shrink: 0;
}

.work-detail-panel {
  min-width: 0;
}

.work-list {
  display: grid;
  min-height: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
  padding-right: 4px;
}

.work-list button {
  display: grid;
  grid-template-columns: 22px 1fr;
  gap: 10px;
  width: 100%;
  align-items: center;
  border: 0; border-bottom: 1px solid var(--line);
  padding: 16px 22px; text-align: left;
  cursor: grab;
  transition: background 140ms ease, opacity 140ms ease, box-shadow 140ms ease;
}
.work-list button:active { cursor: grabbing; }
.work-list button.active { background: var(--accent-soft); }
.work-list button.dragging {
  opacity: 0.48;
  background: rgba(199, 167, 100, 0.12);
}
.work-list button.drag-over {
  box-shadow: inset 3px 0 0 var(--accent), inset 0 1px 0 rgba(199, 167, 100, 0.45);
  background: rgba(199, 167, 100, 0.09);
}
.work-drag-handle {
  color: var(--accent);
  font-size: 15px;
  letter-spacing: -0.2em;
  opacity: 0.72;
  pointer-events: none;
}
.work-list-text {
  display: grid;
  gap: 7px;
  min-width: 0;
}
.work-list strong { font-size: 15px; line-height: 1.35; }
.work-list span { color: var(--muted); font-size: 12px; }
.work-list-text strong {
  color: var(--text);
}

/* ===== Responsive ===== */
@media (max-width: 880px) {
  .metric-image-editor {
    grid-template-columns: 1fr;
  }

  body:not(.auth-locked) {
    height: auto;
    min-height: 100vh;
    overflow: auto;
    display: block;
  }
  .admin-layout { grid-template-columns: 1fr; }
  .works-editor-layout {
    grid-template-columns: 1fr;
  }
  .work-list-panel {
    position: static;
    max-height: none;
  }
  .module-nav {
    position: sticky;
    top: 0;
    z-index: 8;
    display: flex;
    overflow-x: auto;
    overflow-y: hidden;
    border-right: 0;
    border-bottom: 1px solid var(--line);
    padding: 0;
  }
  .module-nav button {
    width: auto;
    min-width: max-content;
    border-bottom: 0;
    border-right: 1px solid var(--line);
  }
  .work-form { grid-template-columns: 1fr; }
  .featured-editor-section { grid-column: auto; padding: 18px; }
  .featured-editor-heading { align-items: flex-start; flex-direction: column; gap: 8px; }
  .featured-editor-grid { grid-template-columns: 1fr; }
  .featured-editor-grid .span-2 { grid-column: auto; }
  .work-media-group { grid-column: auto; padding: 16px; }
  .work-media-heading { align-items: flex-start; flex-direction: column; gap: 6px; }
  .work-media-grid,
  .playback-settings-grid { grid-template-columns: 1fr; }
  .list-item-card .item-fields.two-cols { grid-template-columns: 1fr; }
  .preview-panel { grid-template-columns: 1fr; }
  .work-form label.span-2 { grid-column: auto; }
  .admin-header { display: grid; }
}
