:root {
  --bg: #f6f7fb;
  --panel: #ffffff;
  --panel-soft: #f1f5f9;
  --ink: #172033;
  --muted: #657086;
  --line: #dce3ee;
  --teal: #14b8a6;
  --blue: #3478f6;
  --rose: #e95f76;
  --amber: #c98316;
  --green: #1f9d63;
  --shadow: 0 16px 36px rgba(31, 41, 55, 0.08);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Microsoft YaHei", sans-serif;
  letter-spacing: 0;
}

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

button {
  cursor: pointer;
}

.shell {
  min-height: 100vh;
  display: grid;
  grid-template-columns: 220px minmax(0, 1fr);
}

.side {
  background: #121926;
  color: #eef6ff;
  padding: 22px 16px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 26px;
  font-weight: 800;
  font-size: 19px;
}

.brand-mark {
  width: 34px;
  height: 34px;
  display: grid;
  place-items: center;
  border-radius: 8px;
  background: linear-gradient(135deg, #14b8a6, #3478f6);
  color: white;
}

.nav {
  display: grid;
  gap: 8px;
}

.nav a,
.nav span {
  color: rgba(255, 255, 255, 0.78);
  text-decoration: none;
  padding: 10px 12px;
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.nav .active {
  background: rgba(255, 255, 255, 0.12);
  color: white;
}

.main {
  min-width: 0;
  padding: 24px;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  margin-bottom: 20px;
}

.eyebrow {
  color: var(--muted);
  font-size: 13px;
  margin-bottom: 4px;
}

h1,
h2,
h3 {
  margin: 0;
}

h1 {
  font-size: 25px;
}

h2 {
  font-size: 18px;
}

h3 {
  font-size: 15px;
}

.status-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-height: 30px;
  padding: 0 10px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: white;
  color: var(--muted);
  font-size: 13px;
}

.dot {
  width: 8px;
  height: 8px;
  border-radius: 999px;
  background: var(--green);
}

.grid {
  display: grid;
  grid-template-columns: minmax(0, 1.35fr) minmax(300px, 0.85fr);
  gap: 18px;
}

.panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 16px 18px;
  border-bottom: 1px solid var(--line);
}

.panel-body {
  padding: 18px;
}

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

.field {
  display: grid;
  gap: 7px;
  align-content: start;
}

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

.custom-relationship-field {
  display: none;
}

.custom-relationship-field.show {
  display: grid;
}

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

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

input:not([type="file"]),
select {
  height: 44px;
}

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

input:focus,
select:focus,
textarea:focus {
  border-color: var(--blue);
  box-shadow: 0 0 0 3px rgba(52, 120, 246, 0.12);
}

.chips {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.chip {
  border: 1px solid #cfd8e6;
  border-radius: 999px;
  background: white;
  color: var(--ink);
  padding: 8px 12px;
  line-height: 1;
}

.chip.active {
  border-color: rgba(20, 184, 166, 0.7);
  background: rgba(20, 184, 166, 0.12);
  color: #0f766e;
}

.chip.custom-tag {
  border-color: rgba(52, 120, 246, 0.45);
}

.custom-input-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 8px;
}

.custom-input-row .btn {
  min-width: 72px;
}

.actions {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 10px;
  margin-top: 16px;
}

.btn {
  min-height: 40px;
  border: 1px solid transparent;
  border-radius: 8px;
  padding: 0 14px;
  background: #e7ecf5;
  color: var(--ink);
  font-weight: 700;
}

.btn.primary {
  background: var(--blue);
  color: white;
}

.btn.danger {
  background: #fff0f3;
  border-color: #ffd1dc;
  color: #b42342;
}

.icon-btn {
  width: 38px;
  height: 38px;
  border-radius: 8px;
  border: 1px solid var(--line);
  background: #fff;
  color: var(--ink);
}

.preview-stage {
  position: relative;
  min-height: 356px;
  overflow: hidden;
  background:
    linear-gradient(160deg, rgba(20, 184, 166, 0.2), transparent 36%),
    linear-gradient(30deg, rgba(233, 95, 118, 0.16), transparent 40%),
    #182231;
  border-radius: 8px 8px 0 0;
  display: grid;
  align-items: end;
  justify-items: center;
}

.preview-stage img {
  width: min(82%, 310px);
  max-height: 340px;
  object-fit: contain;
  filter: drop-shadow(0 20px 32px rgba(0, 0, 0, 0.32));
}

.preview-meta {
  display: grid;
  gap: 10px;
}

.meta-line {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  padding-bottom: 9px;
  border-bottom: 1px solid var(--line);
  font-size: 14px;
}

.meta-line span:first-child {
  color: var(--muted);
}

.meter {
  height: 8px;
  background: #e5eaf2;
  border-radius: 999px;
  overflow: hidden;
}

.meter > span {
  display: block;
  height: 100%;
  background: linear-gradient(90deg, var(--teal), var(--blue));
}

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

.metric {
  background: white;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 14px;
  box-shadow: var(--shadow);
}

.metric b {
  display: block;
  margin-top: 8px;
  font-size: 24px;
}

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

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

table {
  width: 100%;
  border-collapse: collapse;
  min-width: 760px;
}

th,
td {
  padding: 12px 10px;
  text-align: left;
  border-bottom: 1px solid var(--line);
  font-size: 14px;
}

th {
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
  background: #f8fafc;
}

.tag {
  display: inline-flex;
  padding: 4px 8px;
  border-radius: 999px;
  background: #eef2ff;
  color: #3451a3;
  font-size: 12px;
}

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

.user-center {
  max-width: 1480px;
}

.user-layout {
  display: grid;
  grid-template-columns: minmax(0, 1.55fr) minmax(320px, 0.65fr);
  gap: 18px;
  align-items: start;
}

.role-panel .panel-body {
  display: grid;
  gap: 18px;
}

.role-grid {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 10px;
}

.role-card {
  min-width: 0;
  min-height: 292px;
  display: grid;
  grid-template-rows: 178px auto auto auto;
  gap: 7px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  padding: 10px;
  color: var(--ink);
  text-align: left;
  overflow: hidden;
  transition: border-color 160ms ease, box-shadow 160ms ease, transform 160ms ease;
}

.role-card:hover,
.role-card.active {
  border-color: rgba(20, 184, 166, 0.85);
  box-shadow: 0 14px 30px rgba(20, 184, 166, 0.14);
  transform: translateY(-1px);
}

.role-card img,
.custom-role-visual {
  width: 100%;
  height: 178px;
  border-radius: 8px;
  object-fit: cover;
  object-position: top center;
  background: #edf2f7;
}

.role-card strong {
  font-size: 15px;
}

.role-card small {
  color: var(--muted);
  font-size: 12px;
  line-height: 1.35;
}

.role-badge {
  width: max-content;
  max-width: 100%;
  display: inline-flex;
  align-items: center;
  min-height: 22px;
  padding: 0 8px;
  border-radius: 999px;
  background: #eef7ff;
  color: #266199;
  font-size: 12px;
}

.custom-role-card {
  background:
    linear-gradient(135deg, rgba(20, 184, 166, 0.08), rgba(52, 120, 246, 0.08)),
    #fff;
}

.custom-role-visual {
  display: grid;
  place-items: center;
  border: 1px dashed rgba(52, 120, 246, 0.5);
}

.custom-role-visual span {
  width: 54px;
  height: 54px;
  display: grid;
  place-items: center;
  border-radius: 999px;
  background: #fff;
  color: var(--blue);
  font-size: 34px;
  font-weight: 700;
  box-shadow: 0 10px 24px rgba(52, 120, 246, 0.16);
}

.compact-form {
  padding-top: 2px;
}

.custom-builder {
  display: none;
  border: 1px solid #dbe7f4;
  border-radius: 8px;
  background: #f8fbff;
  padding: 16px;
}

.custom-builder.show {
  display: grid;
  gap: 14px;
}

.builder-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

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

.builder-block {
  display: grid;
  gap: 12px;
  border: 1px solid #dce6f2;
  border-radius: 8px;
  background: #fff;
  padding: 14px;
}

.builder-block.full {
  grid-column: 1 / -1;
}

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

.upload-box {
  min-height: 112px;
  display: grid;
  align-content: center;
  gap: 6px;
  border: 1px dashed #b8c8dc;
  border-radius: 8px;
  background: #fbfdff;
  padding: 12px;
  color: var(--ink);
  cursor: pointer;
}

.upload-box span {
  font-weight: 800;
}

.upload-box small {
  color: var(--muted);
  line-height: 1.35;
}

.upload-box input {
  width: 1px;
  height: 1px;
  opacity: 0;
  position: absolute;
  pointer-events: none;
}

.role-preview-stage {
  min-height: 460px;
}

.role-preview-stage img {
  width: 100%;
  max-width: none;
  max-height: 430px;
  object-fit: cover;
  object-position: top center;
}

.preview-panel {
  position: sticky;
  top: 20px;
}

.user-metrics {
  margin-top: 18px;
}

.moments-admin {
  max-width: 1680px;
}

.moments-metrics {
  grid-template-columns: repeat(6, minmax(0, 1fr));
}

.moments-admin-layout {
  display: grid;
  grid-template-columns: minmax(260px, 310px) minmax(0, 1fr);
  gap: 18px;
  align-items: start;
}

.moments-users-panel {
  position: sticky;
  top: 20px;
  max-height: calc(100vh - 40px);
  overflow: hidden;
}

.user-search-box {
  padding: 12px;
  border-bottom: 1px solid var(--line);
}

.moments-user-list {
  max-height: calc(100vh - 190px);
  overflow-y: auto;
  padding: 8px;
}

.moments-user-card {
  width: 100%;
  display: grid;
  grid-template-columns: 38px minmax(0, 1fr) 10px;
  align-items: center;
  gap: 10px;
  border: 1px solid transparent;
  border-radius: 8px;
  background: transparent;
  padding: 10px;
  color: var(--ink);
  text-align: left;
}

.moments-user-card:hover,
.moments-user-card.active {
  border-color: #b9d1ff;
  background: #f2f7ff;
}

.user-avatar {
  width: 38px;
  height: 38px;
  display: inline-grid;
  place-items: center;
  border-radius: 8px;
  background: linear-gradient(135deg, #d9f5ef, #dce7ff);
  color: #28527d;
  font-weight: 800;
  flex: 0 0 auto;
}

.user-card-main {
  min-width: 0;
  display: grid;
  gap: 3px;
}

.user-card-main strong,
.user-card-main small,
.user-card-main span {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.user-card-main small,
.user-card-main span {
  color: var(--muted);
  font-size: 11px;
}

.status-dot {
  width: 9px;
  height: 9px;
  border-radius: 999px;
  background: var(--green);
}

.status-dot.paused {
  background: #aab3c2;
}

.moments-workspace {
  min-width: 0;
  display: grid;
  gap: 18px;
}

.selected-user-panel {
  box-shadow: none;
}

.selected-user-head {
  border-bottom: 0;
}

.user-key {
  max-width: 780px;
  margin-top: 5px;
  color: var(--muted);
  font-size: 12px;
  word-break: break-all;
}

.moments-control-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 18px;
  align-items: start;
}

.moments-settings-form {
  gap: 12px;
}

.toggle-field {
  min-height: 44px;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 11px;
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--ink);
}

.toggle-field input {
  width: auto;
  height: auto;
}

.settings-actions {
  grid-column: 1 / -1;
}

.manual-image-preview {
  min-height: 120px;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel-soft);
}

.manual-image-preview img {
  display: block;
  max-width: 100%;
  max-height: 220px;
  margin: auto;
  border-radius: 8px;
  object-fit: contain;
}

.feed-filters select {
  width: 135px;
}

.feed-filters input {
  width: min(240px, 32vw);
}

.moments-feed {
  display: grid;
}

.admin-moment-card {
  padding: 18px;
  border-bottom: 1px solid var(--line);
}

.admin-moment-card:last-child {
  border-bottom: 0;
}

.admin-moment-head {
  display: flex;
  align-items: center;
  gap: 11px;
}

.admin-moment-head > img {
  width: 42px;
  height: 42px;
  border-radius: 8px;
  object-fit: cover;
}

.admin-moment-head > div {
  min-width: 0;
  display: grid;
  gap: 3px;
  flex: 1;
}

.admin-moment-head small {
  color: var(--muted);
}

.admin-moment-head .btn {
  min-height: 32px;
  padding: 0 10px;
  font-size: 12px;
}

.admin-moment-content {
  margin: 13px 0;
  line-height: 1.65;
  white-space: pre-wrap;
  word-break: break-word;
}

.admin-moment-images {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(130px, 190px));
  gap: 8px;
  margin: 12px 0;
}

.admin-moment-images img {
  width: 100%;
  aspect-ratio: 1;
  border-radius: 8px;
  background: var(--panel-soft);
  object-fit: cover;
}

.image-observation {
  margin: 10px 0;
  padding: 9px 11px;
  border-left: 3px solid #9dbff7;
  background: #f4f8ff;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.5;
}

.ai-like-controls {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 6px;
  margin: 12px 0;
  color: var(--muted);
  font-size: 12px;
}

.ai-like-controls .chip {
  padding: 7px 10px;
  font-size: 12px;
}

.admin-comments {
  display: grid;
  gap: 1px;
  padding: 8px 10px;
  border-radius: 8px;
  background: #f5f7fa;
}

.admin-comment {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  padding: 5px 0;
  font-size: 13px;
  line-height: 1.45;
}

.admin-comment span {
  min-width: 0;
  word-break: break-word;
}

.text-danger {
  flex: 0 0 auto;
  border: 0;
  background: transparent;
  color: #b42342;
  font-size: 12px;
}

.ai-comment-composer {
  display: grid;
  grid-template-columns: 120px minmax(0, 1fr) auto;
  gap: 8px;
  margin-top: 10px;
}

.empty-state {
  padding: 42px 18px;
  color: var(--muted);
  text-align: center;
}

.empty-state.compact {
  padding: 18px;
}

.task-panel table {
  min-width: 680px;
}

.task-failed {
  background: #fff0f3;
  color: #b42342;
}

.task-pending,
.task-running {
  background: #fff7e7;
  color: #925b00;
}

.toast {
  position: fixed;
  right: 20px;
  bottom: 20px;
  min-width: 220px;
  max-width: calc(100vw - 40px);
  padding: 12px 14px;
  border-radius: 8px;
  background: #111827;
  color: white;
  opacity: 0;
  transform: translateY(12px);
  pointer-events: none;
  transition: opacity 160ms ease, transform 160ms ease;
}

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

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

  .side {
    position: sticky;
    top: 0;
    z-index: 10;
    padding: 14px 16px;
  }

  .brand {
    margin-bottom: 10px;
  }

  .nav {
    grid-auto-flow: column;
    overflow-x: auto;
  }

  .grid,
  .split,
  .user-layout,
  .metric-grid {
    grid-template-columns: 1fr;
  }

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

  .preview-panel {
    position: static;
  }

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

  .topbar {
    align-items: flex-start;
    flex-direction: column;
  }

  .moments-metrics {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }

  .moments-admin-layout {
    grid-template-columns: 1fr;
  }

  .moments-users-panel {
    position: static;
    max-height: none;
  }

  .moments-user-list {
    max-height: 340px;
  }
}

@media (max-width: 620px) {
  .main {
    padding: 16px;
  }

  .form-grid {
    grid-template-columns: 1fr;
  }

  .role-grid,
  .builder-grid,
  .import-grid {
    grid-template-columns: 1fr;
  }

  .role-card {
    min-height: 220px;
  }

  .panel-head {
    align-items: flex-start;
    flex-direction: column;
  }

  .moments-metrics,
  .moments-control-grid {
    grid-template-columns: 1fr;
  }

  .selected-user-head,
  .admin-moment-head {
    align-items: flex-start;
  }

  .admin-moment-head {
    flex-wrap: wrap;
  }

  .admin-moment-head > div {
    flex-basis: calc(100% - 54px);
  }

  .admin-moment-head .delete-post {
    margin-left: 53px;
  }

  .feed-filters,
  .feed-filters select,
  .feed-filters input {
    width: 100%;
  }

  .ai-comment-composer {
    grid-template-columns: 1fr;
  }
}
