:root {
  --bg: oklch(1 0 0);
  --bg-subtle: oklch(0.975 0.004 250);
  --surface: oklch(0.992 0.002 250);
  --ink: oklch(0.205 0.025 255);
  --ink-soft: oklch(0.37 0.027 255);
  --muted: oklch(0.48 0.025 255);
  --muted-light: oklch(0.64 0.018 255);
  --border: oklch(0.9 0.01 250);
  --border-strong: oklch(0.82 0.016 250);
  --primary: oklch(0.68 0.15 88);
  --primary-hover: oklch(0.61 0.145 88);
  --primary-pale: oklch(0.96 0.045 91);
  --success: oklch(0.64 0.16 150);
  --success-pale: oklch(0.96 0.04 150);
  --danger: oklch(0.61 0.2 28);
  --danger-hover: oklch(0.54 0.19 28);
  --danger-pale: oklch(0.96 0.045 28);
  --focus: oklch(0.72 0.15 88 / 0.34);
  --font: Inter, "PingFang SC", "Microsoft YaHei", system-ui, -apple-system, sans-serif;
  --radius-sm: 8px;
  --radius: 12px;
  --radius-lg: 14px;
  --z-dropdown: 20;
  --z-dialog: 40;
  --z-toast: 50;
}

* {
  box-sizing: border-box;
}

html {
  min-width: 320px;
  color: var(--ink);
  background: var(--bg-subtle);
  font-family: var(--font);
  text-rendering: optimizeLegibility;
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg-subtle);
  font-size: 14px;
  line-height: 1.55;
}

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

button,
select {
  cursor: pointer;
}

button:disabled,
select:disabled,
input:disabled {
  cursor: not-allowed;
}

[hidden] {
  display: none !important;
}

h1,
h2,
h3,
p {
  margin-top: 0;
}

h1,
h2,
h3 {
  color: var(--ink);
  line-height: 1.25;
  text-wrap: balance;
}

p {
  text-wrap: pretty;
}

code {
  padding: 2px 5px;
  border-radius: 5px;
  background: var(--bg-subtle);
  color: var(--ink-soft);
  font-size: 12px;
}

.button {
  min-height: 38px;
  padding: 0 15px;
  border: 0;
  border-radius: var(--radius-sm);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  font-weight: 650;
  transition: background-color 180ms ease-out, color 180ms ease-out, border-color 180ms ease-out,
    transform 120ms ease-out;
}

.button:active:not(:disabled) {
  transform: translateY(1px);
}

.button:focus-visible,
input:focus-visible,
select:focus-visible,
textarea:focus-visible,
.member-option:focus-visible,
.selected-member button:focus-visible,
.selection-summary button:focus-visible,
.dialog-close:focus-visible {
  outline: 3px solid var(--focus);
  outline-offset: 2px;
}

.button-primary {
  background: var(--ink);
  color: var(--bg);
}

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

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

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

.button-secondary,
.button-quiet {
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--ink-soft);
}

.button-secondary:hover:not(:disabled),
.button-quiet:hover:not(:disabled) {
  border-color: var(--border-strong);
  background: var(--bg-subtle);
  color: var(--ink);
}

.button-block {
  width: 100%;
}

.button:disabled {
  opacity: 0.55;
}

.login-view {
  min-height: 100vh;
  padding: 32px 20px;
  display: grid;
  place-items: center;
  background: var(--bg-subtle);
}

.login-panel {
  width: min(100%, 410px);
  padding: 34px;
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  background: var(--bg);
}

.brand-mark {
  width: 42px;
  height: 42px;
  border-radius: 10px;
  display: grid;
  place-items: center;
  background: var(--primary);
  color: var(--ink);
  font-size: 19px;
  font-weight: 800;
}

.brand-name {
  margin: 18px 0 2px;
  color: var(--ink-soft);
  font-weight: 650;
}

.login-panel h1 {
  margin-bottom: 10px;
  font-size: 25px;
  letter-spacing: -0.02em;
}

.login-help,
.login-footnote {
  color: var(--muted);
}

.login-help {
  margin-bottom: 26px;
}

.login-panel label {
  display: block;
  margin-bottom: 8px;
  font-weight: 650;
}

.login-panel input {
  width: 100%;
  height: 44px;
  margin-bottom: 8px;
  padding: 0 12px;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  background: var(--bg);
  color: var(--ink);
}

.form-error {
  min-height: 22px;
  margin-bottom: 10px;
  color: var(--danger);
  font-size: 13px;
}

.login-footnote {
  margin: 20px 0 0;
  padding-top: 18px;
  border-top: 1px solid var(--border);
  font-size: 12px;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  background: var(--bg);
}

.topbar-inner,
.nav-inner,
.page-shell {
  width: min(calc(100% - 48px), 1280px);
  margin: 0 auto;
}

.topbar-inner {
  height: 58px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.brand-lockup {
  display: flex;
  align-items: baseline;
  gap: 8px;
}

.brand-lockup strong {
  font-size: 20px;
  letter-spacing: -0.02em;
}

.brand-lockup span,
.online-state {
  color: var(--muted);
}

.account-actions {
  display: flex;
  align-items: center;
  gap: 16px;
}

.online-state {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  font-size: 13px;
}

.status-dot {
  width: 8px;
  height: 8px;
  flex: 0 0 auto;
  border-radius: 50%;
  background: var(--success);
}

.nav {
  border-top: 1px solid var(--border);
  border-bottom: 1px solid var(--border);
}

.nav-inner {
  min-height: 48px;
  display: flex;
  align-items: stretch;
}

.nav-item {
  min-width: 132px;
  padding: 0 18px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  border-bottom: 2px solid transparent;
  color: var(--muted);
  text-decoration: none;
  font-weight: 650;
}

.nav-item.active {
  border-bottom-color: var(--ink);
  color: var(--ink);
}

.page-shell {
  padding: 34px 0 56px;
}

.page-heading,
.section-heading,
.panel-heading,
.form-actions,
.dialog-heading,
.dialog-actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
}

.page-heading {
  margin-bottom: 26px;
}

.page-heading h1 {
  margin-bottom: 6px;
  font-size: 26px;
  letter-spacing: -0.02em;
}

.page-heading p,
.panel-heading p,
.section-heading p,
.dialog-heading p {
  margin-bottom: 0;
  color: var(--muted);
}

.service-state {
  padding: 8px 12px;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--bg);
  color: var(--ink-soft);
  font-size: 13px;
}

.workspace {
  display: grid;
  grid-template-columns: minmax(0, 3fr) minmax(330px, 2fr);
  align-items: start;
  gap: 18px;
}

.editor-panel,
.preview-panel,
.history-section {
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  background: var(--bg);
}

.editor-panel {
  padding: 24px;
}

.preview-panel {
  position: sticky;
  top: 132px;
  padding: 22px;
}

.panel-heading {
  margin-bottom: 24px;
}

.panel-heading.compact {
  margin-bottom: 18px;
}

.panel-heading h2,
.section-heading h2,
.dialog-heading h2 {
  margin-bottom: 4px;
  font-size: 18px;
}

.step-badge,
.live-label {
  padding: 5px 9px;
  border-radius: 999px;
  background: var(--bg-subtle);
  color: var(--muted);
  font-size: 12px;
  font-weight: 650;
}

.live-label {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.live-label span {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--success);
}

fieldset {
  min-width: 0;
  margin: 0;
  padding: 22px 0;
  border: 0;
  border-top: 1px solid var(--border);
}

legend {
  padding: 0 12px 0 0;
  color: var(--ink);
  font-size: 14px;
  font-weight: 700;
}

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

.field {
  min-width: 0;
  margin-bottom: 18px;
}

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

.field label,
.label-row label {
  display: block;
  margin-bottom: 7px;
  color: var(--ink-soft);
  font-size: 13px;
  font-weight: 650;
}

.label-row {
  display: flex;
  justify-content: space-between;
  gap: 12px;
}

.label-row span {
  color: var(--muted-light);
  font-size: 12px;
}

.field select,
.field input,
.field textarea {
  width: 100%;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  background: var(--bg);
  color: var(--ink);
  transition: border-color 160ms ease-out, background-color 160ms ease-out;
}

.field select,
.field input {
  height: 43px;
  padding: 0 12px;
}

.field textarea {
  min-height: 104px;
  padding: 10px 12px;
  resize: vertical;
  line-height: 1.55;
}

.field select:hover:not(:disabled),
.field input:hover:not(:disabled),
.field textarea:hover:not(:disabled) {
  border-color: var(--muted-light);
}

.field select:disabled,
.field input:disabled {
  background: var(--bg-subtle);
  color: var(--muted-light);
}

.field input::placeholder,
.field textarea::placeholder {
  color: var(--muted);
  opacity: 1;
}

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

.member-combobox {
  position: relative;
}

.member-options {
  position: absolute;
  top: calc(100% + 6px);
  left: 0;
  right: 0;
  z-index: var(--z-dropdown);
  max-height: 280px;
  overflow-y: auto;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  background: var(--bg);
}

.member-option {
  width: 100%;
  padding: 10px 12px;
  border: 0;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: 10px;
  background: var(--bg);
  color: var(--ink);
  text-align: left;
}

.member-option:last-child {
  border-bottom: 0;
}

.member-option:hover,
.member-option.active {
  background: var(--bg-subtle);
}

.member-option span:nth-child(2) {
  min-width: 0;
  display: flex;
  flex: 1;
  flex-direction: column;
}

.member-option strong {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.member-option small,
.selected-member small {
  color: var(--muted);
}

.avatar-fallback {
  width: 32px;
  height: 32px;
  flex: 0 0 auto;
  border-radius: 50%;
  display: grid;
  place-items: center;
  background: var(--primary-pale);
  color: var(--primary-hover);
  font-size: 12px;
  font-weight: 750;
}

.selected-members {
  margin-top: 9px;
  overflow: hidden;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg-subtle);
}

.selection-summary {
  min-height: 38px;
  padding: 6px 10px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  border-bottom: 1px solid var(--border);
  color: var(--ink-soft);
  font-size: 12px;
}

.selection-summary button {
  padding: 4px 6px;
  border: 0;
  border-radius: 6px;
  background: transparent;
  color: var(--danger);
  font-size: 12px;
  font-weight: 650;
}

.selection-summary button:hover {
  background: var(--danger-pale);
}

.selected-member-list {
  max-height: 240px;
  overflow-y: auto;
}

.selected-member {
  min-height: 48px;
  padding: 7px 10px;
  display: flex;
  align-items: center;
  gap: 10px;
  border-bottom: 1px solid var(--border);
}

.selected-member:last-child {
  border-bottom: 0;
}

.selected-member > span:nth-child(2) {
  min-width: 0;
  display: flex;
  flex: 1;
  flex-direction: column;
}

.selected-member button,
.dialog-close {
  width: 32px;
  height: 32px;
  border: 0;
  border-radius: 7px;
  background: transparent;
  color: var(--muted);
  font-size: 20px;
}

.selected-member button:hover,
.dialog-close:hover {
  background: var(--border);
  color: var(--ink);
}

.form-actions {
  padding-top: 20px;
  border-top: 1px solid var(--border);
}

.form-actions p {
  margin: 0;
  color: var(--muted);
  font-size: 12px;
}

.target-summary {
  margin-bottom: 14px;
  padding: 10px 12px;
  display: flex;
  justify-content: space-between;
  gap: 12px;
  border-radius: var(--radius-sm);
  background: var(--bg-subtle);
  color: var(--muted);
  font-size: 12px;
}

.target-summary strong {
  overflow: hidden;
  color: var(--ink-soft);
  text-overflow: ellipsis;
  white-space: nowrap;
}

.kook-card-preview {
  display: grid;
  grid-template-columns: 5px minmax(0, 1fr);
  overflow: hidden;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
}

.kook-card-accent {
  background: var(--primary);
}

.kook-card-body {
  min-width: 0;
  padding: 18px;
}

.kook-card-body h3 {
  margin-bottom: 0;
  font-size: 15px;
}

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

.kook-card-body dl {
  margin: 0;
}

.kook-card-body dl div {
  margin-bottom: 13px;
}

.kook-card-body dl div:last-child {
  margin-bottom: 0;
}

.kook-card-body dt {
  margin-bottom: 2px;
  color: var(--muted);
  font-size: 12px;
}

.kook-card-body dd {
  margin: 0;
  overflow-wrap: anywhere;
  color: var(--ink-soft);
}

.kook-card-body footer {
  display: flex;
  flex-direction: column;
  gap: 2px;
  color: var(--muted);
  font-size: 11px;
}

.preview-note {
  margin-top: 14px;
  padding: 12px;
  border-radius: var(--radius-sm);
  background: var(--primary-pale);
  color: var(--ink-soft);
}

.preview-note strong {
  display: block;
  margin-bottom: 3px;
  font-size: 12px;
}

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

.history-section {
  margin-top: 18px;
}

.section-heading {
  padding: 20px 22px;
  border-bottom: 1px solid var(--border);
}

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

table {
  width: 100%;
  border-collapse: collapse;
  text-align: left;
}

th,
td {
  padding: 13px 16px;
  border-bottom: 1px solid var(--border);
  vertical-align: top;
}

th {
  background: var(--bg-subtle);
  color: var(--muted);
  font-size: 12px;
  font-weight: 650;
  white-space: nowrap;
}

td {
  max-width: 260px;
  color: var(--ink-soft);
  overflow-wrap: anywhere;
}

tbody tr:last-child td {
  border-bottom: 0;
}

.empty-row td {
  padding: 36px 16px;
  color: var(--muted);
  text-align: center;
}

.confirm-dialog {
  width: min(calc(100% - 32px), 620px);
  max-height: min(760px, calc(100vh - 32px));
  padding: 0;
  border: 0;
  border-radius: var(--radius-lg);
  background: var(--bg);
  color: var(--ink);
}

.confirm-dialog::backdrop {
  background: oklch(0.12 0.015 255 / 0.58);
}

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

.dialog-heading {
  align-items: flex-start;
}

.confirm-list {
  margin: 22px 0;
  border-top: 1px solid var(--border);
}

.confirm-list div {
  padding: 11px 0;
  display: grid;
  grid-template-columns: 110px minmax(0, 1fr);
  gap: 14px;
  border-bottom: 1px solid var(--border);
}

.confirm-list dt {
  color: var(--muted);
}

.confirm-list dd {
  margin: 0;
  overflow-wrap: anywhere;
  color: var(--ink-soft);
  font-weight: 550;
}

.dialog-actions {
  justify-content: flex-end;
}

.toast-region {
  position: fixed;
  top: 18px;
  right: 18px;
  z-index: var(--z-toast);
  width: min(380px, calc(100% - 36px));
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.toast {
  padding: 12px 14px;
  border-radius: var(--radius-sm);
  background: var(--ink);
  color: var(--bg);
}

.toast.success {
  background: oklch(0.36 0.11 150);
}

.toast.error {
  background: oklch(0.4 0.16 28);
}

.toast strong {
  display: block;
  margin-bottom: 2px;
}

.toast p {
  margin: 0;
  color: oklch(0.92 0.01 250);
  font-size: 12px;
}

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

  .preview-panel {
    position: static;
  }
}

@media (max-width: 640px) {
  .topbar-inner,
  .nav-inner,
  .page-shell {
    width: min(calc(100% - 28px), 1280px);
  }

  .account-actions {
    margin-left: auto;
  }

  .account-actions .button-quiet {
    display: inline-flex;
  }

  .brand-lockup span,
  .online-state {
    display: none;
  }

  .nav-item {
    min-width: auto;
    padding: 0 10px;
  }

  .page-shell {
    padding-top: 24px;
  }

  .page-heading,
  .section-heading,
  .form-actions {
    align-items: stretch;
    flex-direction: column;
  }

  .service-state {
    align-self: flex-start;
  }

  .field-grid {
    grid-template-columns: 1fr;
    gap: 0;
  }

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

  .form-actions .button,
  .dialog-actions .button {
    width: 100%;
  }

  .dialog-actions {
    flex-direction: column-reverse;
  }

  .confirm-list div {
    grid-template-columns: 1fr;
    gap: 3px;
  }

  .login-panel {
    padding: 26px 22px;
  }
}

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