:root {
  color-scheme: light;
  --background: #f3f6f5;
  --surface: #ffffff;
  --surface-soft: #f7faf9;
  --foreground: #17211e;
  --muted: #63716c;
  --muted-strong: #46534e;
  --border: #dce5e1;
  --border-strong: #c7d3ce;
  --primary: #0f766e;
  --primary-hover: #0b625b;
  --primary-soft: #e8f5f2;
  --accent: #ea580c;
  --accent-hover: #c2410c;
  --accent-soft: #fff1e8;
  --info: #2563eb;
  --danger: #c2413b;
  --danger-soft: #fff0ef;
  --shadow-sm: 0 1px 2px rgba(17, 39, 32, 0.05);
  --shadow-md: 0 14px 40px rgba(17, 39, 32, 0.08);
  --radius: 8px;
}

* {
  box-sizing: border-box;
}

html {
  min-width: 320px;
  background: var(--background);
}

body {
  margin: 0;
  color: var(--foreground);
  background:
    linear-gradient(to bottom, rgba(15, 118, 110, 0.055), transparent 280px),
    var(--background);
  font-family:
    Inter, "PingFang SC", "Microsoft YaHei", "Noto Sans CJK SC", system-ui,
    sans-serif;
  font-size: 15px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

button,
input,
textarea {
  font: inherit;
}

button,
a {
  -webkit-tap-highlight-color: transparent;
}

button {
  cursor: pointer;
}

a {
  color: inherit;
}

svg {
  width: 18px;
  height: 18px;
  stroke-width: 1.9;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.app-shell {
  min-height: 100vh;
}

.topbar {
  position: sticky;
  z-index: 20;
  top: 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-height: 68px;
  padding: 12px clamp(18px, 4vw, 56px);
  border-bottom: 1px solid rgba(199, 211, 206, 0.76);
  background: rgba(255, 255, 255, 0.9);
  backdrop-filter: blur(16px);
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 11px;
  color: inherit;
  text-decoration: none;
}

.brand-icon {
  display: grid;
  width: 40px;
  height: 40px;
  place-items: center;
  color: #fff;
  border-radius: var(--radius);
  background: var(--primary);
  box-shadow: var(--shadow-sm);
}

.brand-icon svg {
  width: 21px;
  height: 21px;
}

.brand strong,
.brand small {
  display: block;
}

.brand strong {
  font-size: 15px;
  letter-spacing: 0;
}

.brand small {
  color: var(--muted);
  font-size: 11px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

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

.status-pill,
.status-count {
  display: inline-flex;
  min-height: 34px;
  align-items: center;
  gap: 7px;
  padding: 0 11px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--surface);
  color: var(--muted-strong);
  font-size: 13px;
  white-space: nowrap;
}

.status-pill.is-ready {
  color: #065f57;
  border-color: #b8ddd7;
  background: var(--primary-soft);
}

.status-pill.is-warning {
  color: #9a3412;
  border-color: #fed7aa;
  background: var(--accent-soft);
}

main {
  width: min(1380px, calc(100% - clamp(28px, 7vw, 96px)));
  margin: 0 auto;
  padding: 42px 0 72px;
}

.page-intro {
  display: grid;
  grid-template-columns: minmax(0, 1.25fr) minmax(280px, 0.75fr);
  gap: 32px;
  align-items: end;
  margin-bottom: 28px;
}

.eyebrow,
.section-index {
  color: var(--primary);
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.page-intro h1 {
  max-width: 760px;
  margin: 8px 0 0;
  font-size: clamp(31px, 4vw, 52px);
  line-height: 1.08;
  letter-spacing: -0.035em;
}

.page-intro p {
  max-width: 560px;
  margin: 0 0 4px;
  color: var(--muted-strong);
  font-size: 16px;
}

.workspace {
  display: grid;
  grid-template-columns: minmax(0, 1.14fr) minmax(360px, 0.86fr);
  gap: 20px;
  align-items: stretch;
}

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

.composer-panel,
.preview-panel {
  padding: clamp(20px, 2.5vw, 30px);
}

.section-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 20px;
  margin-bottom: 26px;
}

.section-header > div:first-child {
  display: flex;
  align-items: center;
  gap: 10px;
}

.section-header h2 {
  margin: 0;
  font-size: 19px;
  letter-spacing: -0.015em;
}

.section-index {
  display: grid;
  width: 34px;
  height: 28px;
  place-items: center;
  border-radius: 6px;
  background: var(--primary-soft);
  font-size: 11px;
}

.section-meta {
  color: var(--muted);
  font-size: 13px;
}

.field-group {
  display: grid;
  gap: 8px;
}

.field-group + .field-group {
  margin-top: 18px;
}

.field-group label,
.mode-fieldset legend {
  color: var(--foreground);
  font-size: 13px;
  font-weight: 650;
}

input,
textarea {
  width: 100%;
  color: var(--foreground);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius);
  background: var(--surface);
  outline: none;
  transition:
    border-color 160ms ease,
    box-shadow 160ms ease,
    background-color 160ms ease;
}

input {
  min-height: 46px;
  padding: 10px 12px;
}

textarea {
  min-height: 92px;
  padding: 11px 12px;
  resize: vertical;
}

input::placeholder,
textarea::placeholder {
  color: #93a09b;
}

input:focus,
textarea:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(15, 118, 110, 0.13);
}

.url-control {
  position: relative;
  display: flex;
  gap: 8px;
}

.url-control input {
  padding-left: 42px;
}

.input-with-icon {
  position: relative;
}

.input-with-icon input {
  padding-left: 42px;
}

.input-icon {
  position: absolute;
  z-index: 1;
  top: 50%;
  left: 13px;
  display: grid;
  color: var(--muted);
  transform: translateY(-50%);
  pointer-events: none;
}

.input-with-counter {
  position: relative;
}

.input-with-counter input,
.input-with-counter textarea {
  padding-right: 62px;
}

.input-with-counter span {
  position: absolute;
  right: 11px;
  bottom: 10px;
  color: var(--muted);
  font-size: 11px;
  pointer-events: none;
}

.field-help {
  margin: 0;
  color: var(--muted);
  font-size: 12px;
}

.field-help.is-error {
  color: var(--danger);
}

.form-divider {
  height: 1px;
  margin: 25px 0;
  background: var(--border);
}

.button,
.icon-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 44px;
  border: 1px solid transparent;
  border-radius: var(--radius);
  font-weight: 650;
  text-decoration: none;
  transition:
    color 160ms ease,
    border-color 160ms ease,
    background-color 160ms ease,
    transform 160ms ease,
    box-shadow 160ms ease;
}

.button:active,
.icon-button:active {
  transform: translateY(1px);
}

.button:disabled,
.icon-button:disabled {
  cursor: not-allowed;
  opacity: 0.58;
}

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

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

.button-accent {
  color: #fff;
  background: var(--accent);
  box-shadow: 0 8px 20px rgba(234, 88, 12, 0.17);
}

.button-accent:hover:not(:disabled) {
  background: var(--accent-hover);
}

.button-secondary {
  color: var(--foreground);
  border-color: var(--border-strong);
  background: var(--surface);
}

.button-secondary:hover:not(:disabled) {
  border-color: var(--muted);
  background: var(--surface-soft);
}

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

.url-control .button {
  flex: 0 0 auto;
  padding: 0 17px;
}

.metadata-fields {
  opacity: 0.6;
  transition: opacity 180ms ease;
}

.metadata-fields.is-ready {
  opacity: 1;
}

.mode-fieldset {
  padding: 0;
  margin: 24px 0 20px;
  border: 0;
}

.mode-fieldset legend {
  margin-bottom: 10px;
}

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

.segmented-control label {
  position: relative;
  display: block;
  min-width: 0;
}

.segmented-control input {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}

.segmented-control label > span {
  display: grid;
  min-height: 88px;
  grid-template-columns: 24px minmax(0, 1fr);
  gap: 4px 8px;
  align-content: center;
  padding: 13px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface-soft);
  color: var(--muted-strong);
  transition:
    border-color 160ms ease,
    background-color 160ms ease,
    color 160ms ease;
}

.segmented-control label > span > svg {
  grid-row: 1 / span 2;
  margin-top: 2px;
}

.segmented-control strong {
  color: var(--foreground);
  font-size: 13px;
}

.segmented-control small {
  color: var(--muted);
  font-size: 11px;
  line-height: 1.4;
}

.segmented-control input:checked + span {
  color: var(--primary);
  border-color: var(--primary);
  background: var(--primary-soft);
  box-shadow: inset 0 0 0 1px var(--primary);
}

.segmented-control input:focus-visible + span {
  outline: 3px solid rgba(15, 118, 110, 0.18);
  outline-offset: 2px;
}

.generate-button {
  width: 100%;
}

.generate-button.is-loading svg,
.button.is-loading svg,
.icon-button.is-loading svg {
  animation: spin 0.9s linear infinite;
}

.result-panel {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  gap: 12px;
  align-items: center;
  margin-top: 14px;
  padding: 12px;
  border: 1px solid #b8ddd7;
  border-radius: var(--radius);
  background: var(--primary-soft);
}

.result-icon {
  display: grid;
  width: 36px;
  height: 36px;
  place-items: center;
  color: var(--primary);
  border-radius: 7px;
  background: #fff;
}

.result-copy {
  min-width: 0;
}

.result-copy strong,
.result-copy a {
  display: block;
}

.result-copy strong {
  font-size: 13px;
}

.result-copy a {
  overflow: hidden;
  margin-top: 2px;
  color: var(--primary);
  font-size: 12px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.icon-button {
  width: 44px;
  padding: 0;
  color: var(--muted-strong);
  border-color: var(--border);
  background: var(--surface);
}

.icon-button:hover:not(:disabled) {
  color: var(--primary);
  border-color: var(--primary);
  background: var(--primary-soft);
}

.phone-stage {
  display: grid;
  min-height: 430px;
  place-items: center;
  padding: 22px 0;
  border-radius: var(--radius);
  background: #e9efed;
  overflow: hidden;
}

.phone-frame {
  width: min(330px, 78%);
  min-height: 540px;
  padding: 14px 12px 36px;
  border: 7px solid #26312e;
  border-radius: 34px;
  background: #f1f2f3;
  box-shadow: 0 28px 60px rgba(25, 39, 35, 0.2);
}

.phone-topbar {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  padding: 2px 6px 13px;
  color: #1d2422;
  font-size: 11px;
  font-weight: 650;
}

.phone-title {
  font-size: 12px;
}

.phone-signal {
  display: flex;
  justify-content: flex-end;
}

.phone-signal svg {
  width: 14px;
  height: 14px;
}

.chat-area {
  display: flex;
  min-height: 455px;
  flex-direction: column;
  gap: 16px;
  padding: 14px 3px;
}

.message-row {
  display: flex;
  align-items: flex-start;
  gap: 8px;
}

.message-row.is-self {
  justify-content: flex-end;
  margin-top: auto;
}

.message-avatar {
  display: grid;
  width: 36px;
  height: 36px;
  flex: 0 0 36px;
  place-items: center;
  border-radius: 6px;
  background: var(--primary);
  color: #fff;
  font-size: 13px;
  font-weight: 700;
}

.wechat-link-card {
  width: min(235px, calc(100% - 44px));
  overflow: hidden;
  border-radius: var(--radius);
  background: #fff;
  box-shadow: 0 2px 10px rgba(24, 38, 34, 0.1);
}

.card-cover {
  position: relative;
  display: grid;
  width: 100%;
  aspect-ratio: 16 / 9;
  place-items: center;
  overflow: hidden;
  background:
    linear-gradient(135deg, rgba(15, 118, 110, 0.12), rgba(37, 99, 235, 0.08)),
    #dce8e5;
}

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

.cover-placeholder {
  display: grid;
  place-items: center;
  gap: 6px;
  color: #58716b;
  font-size: 11px;
}

.cover-placeholder svg {
  width: 25px;
  height: 25px;
}

.card-content {
  padding: 12px;
}

.card-content h3 {
  display: -webkit-box;
  overflow: hidden;
  margin: 0;
  font-size: 14px;
  line-height: 1.4;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 2;
}

.card-content p {
  display: -webkit-box;
  overflow: hidden;
  margin: 6px 0 10px;
  color: #6c7673;
  font-size: 11px;
  line-height: 1.5;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 3;
}

.card-meta {
  display: flex;
  align-items: center;
  gap: 5px;
  color: #9aa39f;
  font-size: 10px;
}

.card-meta span {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.card-meta svg {
  width: 11px;
  height: 11px;
}

.self-bubble {
  max-width: 78%;
  padding: 9px 11px;
  border-radius: 7px;
  background: #95ec69;
  color: #162018;
  font-size: 12px;
}

.preview-note {
  display: flex;
  gap: 10px;
  align-items: flex-start;
  margin-top: 16px;
  color: var(--muted);
}

.preview-note svg {
  flex: 0 0 auto;
  margin-top: 2px;
  color: var(--info);
}

.preview-note p {
  margin: 0;
  font-size: 12px;
}

.library-panel {
  margin-top: 20px;
  overflow: hidden;
}

.library-header {
  align-items: center;
  padding: 22px 24px 18px;
  margin-bottom: 0;
}

.library-tools {
  display: flex;
  align-items: center;
  gap: 8px;
}

.search-control {
  position: relative;
  display: flex;
  align-items: center;
}

.search-control svg {
  position: absolute;
  left: 12px;
  color: var(--muted);
  pointer-events: none;
}

.search-control input {
  width: min(260px, 30vw);
  min-height: 40px;
  padding-left: 38px;
}

.table-wrap {
  overflow-x: auto;
  border-top: 1px solid var(--border);
}

.link-table {
  width: 100%;
  border-collapse: collapse;
  table-layout: fixed;
}

.link-table th,
.link-table td {
  padding: 14px 18px;
  text-align: left;
  vertical-align: middle;
}

.link-table th {
  color: var(--muted);
  border-bottom: 1px solid var(--border);
  background: var(--surface-soft);
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

.link-table th:first-child {
  width: 35%;
}

.link-table th:nth-child(2) {
  width: 29%;
}

.link-table th:nth-child(3),
.link-table th:nth-child(4) {
  width: 12%;
}

.link-table th:last-child {
  width: 120px;
}

.link-table tbody tr {
  border-bottom: 1px solid var(--border);
  transition: background-color 150ms ease;
}

.link-table tbody tr:last-child {
  border-bottom: 0;
}

.link-table tbody tr:hover {
  background: #fbfdfc;
}

.card-cell {
  display: flex;
  min-width: 0;
  align-items: center;
  gap: 12px;
}

.card-thumb {
  display: grid;
  width: 62px;
  height: 46px;
  flex: 0 0 62px;
  place-items: center;
  overflow: hidden;
  border-radius: 6px;
  background: var(--primary-soft);
  color: var(--primary);
}

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

.card-cell-copy {
  min-width: 0;
}

.card-cell-copy strong,
.card-cell-copy span,
.share-link {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.card-cell-copy strong {
  font-size: 13px;
}

.card-cell-copy span {
  margin-top: 3px;
  color: var(--muted);
  font-size: 11px;
}

.share-link {
  color: var(--primary);
  font-size: 12px;
}

.numeric-cell {
  color: var(--muted-strong);
  font-variant-numeric: tabular-nums;
}

.date-cell {
  color: var(--muted);
  font-size: 12px;
}

.row-actions {
  display: flex;
  justify-content: flex-end;
  gap: 6px;
}

.row-actions .icon-button {
  width: 38px;
  min-height: 38px;
}

.empty-state {
  display: grid;
  min-height: 250px;
  place-items: center;
  align-content: center;
  padding: 34px;
  text-align: center;
}

.empty-state[hidden] {
  display: none;
}

.empty-icon {
  display: grid;
  width: 54px;
  height: 54px;
  place-items: center;
  border-radius: 50%;
  background: var(--surface-soft);
  color: var(--muted);
}

.empty-icon svg {
  width: 24px;
  height: 24px;
}

.empty-state h3 {
  margin: 14px 0 4px;
  font-size: 15px;
}

.empty-state p {
  margin: 0;
  color: var(--muted);
  font-size: 13px;
}

.confirm-dialog {
  width: min(420px, calc(100% - 32px));
  padding: 0;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: var(--shadow-md);
}

.confirm-dialog::backdrop {
  background: rgba(20, 31, 28, 0.42);
  backdrop-filter: blur(3px);
}

.confirm-dialog form {
  padding: 26px;
}

.dialog-icon {
  display: grid;
  width: 44px;
  height: 44px;
  place-items: center;
  border-radius: var(--radius);
  background: var(--danger-soft);
  color: var(--danger);
}

.confirm-dialog h2 {
  margin: 16px 0 6px;
  font-size: 18px;
}

.confirm-dialog p {
  margin: 0;
  color: var(--muted);
  font-size: 13px;
}

.dialog-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 24px;
}

.dialog-actions .button {
  padding: 0 17px;
}

.toast {
  position: fixed;
  z-index: 60;
  right: 22px;
  bottom: 22px;
  display: flex;
  max-width: min(420px, calc(100% - 44px));
  align-items: center;
  gap: 9px;
  padding: 12px 15px;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius);
  background: #17211e;
  color: #fff;
  box-shadow: var(--shadow-md);
  opacity: 0;
  transform: translateY(12px);
  pointer-events: none;
  transition:
    opacity 180ms ease,
    transform 180ms ease;
}

.toast.is-visible {
  opacity: 1;
  transform: translateY(0);
}

.toast.is-error {
  background: #7f1d1d;
}

.toast svg {
  flex: 0 0 auto;
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

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

  .phone-stage {
    min-height: 390px;
  }

  .phone-frame {
    width: min(330px, 62%);
  }
}

@media (max-width: 760px) {
  .topbar {
    padding: 10px 16px;
  }

  .status-count {
    display: none;
  }

  main {
    width: min(100% - 28px, 680px);
    padding-top: 30px;
  }

  .page-intro {
    grid-template-columns: 1fr;
    gap: 14px;
  }

  .page-intro h1 {
    font-size: 34px;
  }

  .url-control {
    display: grid;
  }

  .url-control input {
    padding-left: 42px;
  }

  .url-control .button {
    width: 100%;
  }

  .segmented-control {
    grid-template-columns: 1fr;
  }

  .phone-frame {
    width: min(330px, 88%);
  }

  .library-header {
    align-items: flex-start;
    padding: 18px;
  }

  .library-tools {
    width: 100%;
  }

  .library-header {
    flex-direction: column;
  }

  .search-control {
    flex: 1;
  }

  .search-control input {
    width: 100%;
  }

  .link-table,
  .link-table tbody,
  .link-table tr,
  .link-table td {
    display: block;
    width: 100%;
  }

  .link-table thead {
    display: none;
  }

  .link-table tbody {
    padding: 0 16px 16px;
  }

  .link-table tr {
    position: relative;
    padding: 16px 0;
    border-bottom: 1px solid var(--border);
  }

  .link-table td {
    padding: 4px 0;
  }

  .link-table td::before {
    display: block;
    margin-bottom: 2px;
    color: var(--muted);
    content: attr(data-label);
    font-size: 10px;
    font-weight: 700;
    letter-spacing: 0.06em;
    text-transform: uppercase;
  }

  .link-table td:last-child::before {
    display: none;
  }

  .row-actions {
    justify-content: flex-start;
    margin-top: 8px;
  }

  .row-actions .icon-button {
    width: 44px;
    min-height: 44px;
  }
}

@media (max-width: 480px) {
  .brand small,
  .status-pill span {
    display: none;
  }

  .page-intro h1 {
    font-size: 30px;
  }

  .composer-panel,
  .preview-panel {
    padding: 18px;
  }

  .phone-stage {
    margin-inline: -18px;
    border-radius: 0;
  }

  .phone-frame {
    width: min(310px, 92%);
    min-height: 510px;
  }

  .result-panel {
    grid-template-columns: auto minmax(0, 1fr);
  }

  .result-panel .icon-button {
    grid-column: 2;
    justify-self: start;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    scroll-behavior: auto !important;
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}
