:root {
  color-scheme: light;
  --background: #ffffff;
  --foreground: #09090b;
  --card: #ffffff;
  --card-foreground: #09090b;
  --muted: #f4f4f5;
  --muted-foreground: #71717a;
  --border: #e4e4e7;
  --input: #e4e4e7;
  --primary: #18181b;
  --primary-foreground: #fafafa;
  --secondary: #f4f4f5;
  --secondary-foreground: #18181b;
  --destructive: #dc2626;
  --success: #16a34a;
  --ring: rgba(24, 24, 27, .18);
  --radius: 8px;
  --font: "Inter", "Segoe UI", "PingFang SC", "Microsoft YaHei", system-ui, sans-serif;
}

* { box-sizing: border-box; }
html { overflow-x: hidden; background: var(--background); }
body { min-width: 320px; margin: 0; overflow-x: hidden; background: var(--background); color: var(--foreground); font-family: var(--font); font-size: 16px; line-height: 1.45; }
button, input, textarea, summary { font: inherit; }
button { cursor: pointer; }
button:disabled { cursor: not-allowed; opacity: .5; }
svg { display: block; fill: none; stroke: currentColor; stroke-linecap: round; stroke-linejoin: round; stroke-width: 2; }
[hidden] { display: none !important; }
.svg-defs { position: absolute; width: 0; height: 0; overflow: hidden; }

.skip-link { position: fixed; z-index: 100; top: 12px; left: 12px; padding: 8px 12px; border-radius: var(--radius); background: var(--primary); color: var(--primary-foreground); transform: translateY(-160%); }
.skip-link:focus { transform: translateY(0); }
:focus-visible { outline: 2px solid var(--ring); outline-offset: 2px; }

.app-shell { width: min(100% - 32px, 1280px); margin: 0 auto; padding: 24px 0 40px; }
.app-header { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; padding-bottom: 16px; }
.app-header h1 { margin: 0; font-size: 25.63px; line-height: 1.15; letter-spacing: -.02em; }
.app-header p, .panel-header p { margin: 4px 0 0; color: var(--muted-foreground); }
.toolbar { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: 8px; }
.tooltip-wrap { position: relative; display: inline-flex; }
.tooltip { position: absolute; top: calc(100% + 8px); left: 50%; width: max-content; max-width: 220px; padding: 6px 10px; border-radius: var(--radius); background: var(--primary); color: var(--primary-foreground); opacity: 0; pointer-events: none; transform: translate(-50%, -3px); transition: opacity .14s ease, transform .14s ease; }
.tooltip-wrap:hover .tooltip, .tooltip-wrap:focus-within .tooltip { opacity: 1; transform: translate(-50%, 0); }

.button, .icon-button, .mini-button, .segment, .tab, .target-chip, .sticker-option {
  border: 1px solid transparent;
  border-radius: var(--radius);
  font-weight: 500;
  transition: background-color .14s ease, border-color .14s ease, color .14s ease;
}
.button { display: inline-flex; min-height: 36px; align-items: center; justify-content: center; gap: 8px; padding: 7px 12px; white-space: nowrap; }
.button-primary { border-color: var(--primary); background: var(--primary); color: var(--primary-foreground); }
.button-primary:hover { background: #27272a; }
.button-outline { border-color: var(--border); background: var(--background); color: var(--foreground); }
.button-outline:hover, .icon-button:hover, .mini-button:hover:not(:disabled) { background: var(--muted); }
.complete-action-icon { display: none; }
.icon-button, .mini-button { display: grid; width: 36px; height: 36px; flex: 0 0 36px; place-items: center; border-color: var(--border); background: var(--background); color: var(--foreground); }
.mini-button.danger:hover:not(:disabled) { border-color: rgba(220, 38, 38, .28); color: var(--destructive); background: #fef2f2; }

.import-panel { display: grid; gap: 8px; margin-top: 16px; padding: 12px; border-radius: var(--radius); background: var(--card); }
.import-row { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 8px; align-items: start; }

.editor-grid { display: grid; grid-template-columns: minmax(260px, .8fr) minmax(360px, 1.2fr) minmax(280px, .75fr); gap: 16px; margin-top: 16px; align-items: start; }
.side-stack { display: grid; gap: 16px; }
.panel { display: grid; gap: 14px; min-width: 0; padding: 14px; border: 1px solid var(--border); border-radius: var(--radius); background: var(--card); color: var(--card-foreground); box-shadow: 0 1px 2px rgba(0, 0, 0, .03); }
.panel-status.is-validation-highlighted { animation: validation-attention .24s ease-in-out 3; }
.panel-header { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; }
.panel-header h2 { margin: 0; font-size: 20.25px; line-height: 1.3; }

label, legend { color: var(--foreground); font-weight: 500; }
label { display: grid; gap: 6px; min-width: 0; }
fieldset { min-width: 0; margin: 0; padding: 0; border: 0; }
legend { margin-bottom: 8px; padding: 0; }
input, textarea { width: 100%; border: 1px solid var(--input); border-radius: calc(var(--radius) - 2px); background: var(--background); color: var(--foreground); }
input { height: 36px; padding: 6px 10px; }
textarea { display: block; min-height: 96px; padding: 8px 10px; resize: vertical; line-height: 1.45; }
input::placeholder, textarea::placeholder { color: var(--muted-foreground); opacity: 1; }
input:focus-visible, textarea:focus-visible { border-color: var(--primary); outline: 2px solid var(--ring); outline-offset: 0; }

.field-group, .compose-panel { display: grid; gap: 10px; min-width: 0; }
.add-row { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 8px; align-items: center; }
.segmented, .tabs { display: inline-flex; align-items: center; gap: 2px; padding: 3px; border-radius: var(--radius); background: var(--muted); }
.segment, .tab { min-height: 30px; padding: 5px 10px; background: transparent; color: var(--muted-foreground); }
.segment.is-active, .tab.is-active { border-color: var(--border); background: var(--background); color: var(--foreground); box-shadow: 0 1px 1px rgba(0, 0, 0, .04); }

.friend-list { display: grid; gap: 8px; }
.friend-item { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 8px; align-items: center; padding: 8px; border: 1px solid var(--border); border-radius: var(--radius); background: var(--background); }
.friend-item.is-active { border-color: var(--primary); background: var(--muted); }
.friend-select { display: flex; min-width: 0; min-height: 34px; align-items: center; border: 0; background: transparent; color: var(--foreground); text-align: left; }
.friend-select span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.target-actions, .message-actions { display: flex; gap: 6px; }

.sticker-grid { display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 8px; max-height: 310px; overflow: auto; }
.sticker-option { display: grid; min-height: 94px; place-items: center; align-content: center; gap: 6px; padding: 8px; border-color: var(--border); background: var(--background); }
.sticker-option:hover { background: var(--muted); }
.sticker-option img { width: 44px; height: 44px; object-fit: contain; }
.sticker-option strong { font-weight: 500; }

.message-list { display: grid; gap: 8px; max-height: 420px; overflow: auto; padding-right: 2px; }
.message-item { display: grid; grid-template-columns: auto minmax(0, 1fr) auto; gap: 8px; align-items: center; padding: 10px; border: 1px solid var(--border); border-radius: var(--radius); background: var(--background); animation: item-in .14s ease both; transition: transform .18s ease, opacity .14s ease, background-color .14s ease; }
.message-item.is-dragging { opacity: .45; background: var(--muted); }
.drag-handle { display: grid; width: 32px; height: 32px; place-items: center; border: 0; border-radius: var(--radius); background: transparent; color: var(--muted-foreground); cursor: grab; }
.drag-handle:active { cursor: grabbing; }
.message-copy { min-width: 0; }
.message-copy strong { display: inline-flex; align-items: center; min-height: 22px; padding: 1px 8px; border-radius: 999px; background: var(--secondary); color: var(--secondary-foreground); font-size: 16px; font-weight: 500; }
.message-copy p { margin: 6px 0 0; overflow-wrap: anywhere; color: var(--muted-foreground); }

.settings-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.range-readout { display: flex; justify-content: space-between; color: var(--muted-foreground); font-variant-numeric: tabular-nums; }
.range-slider { position: relative; height: 34px; }
.range-track { position: absolute; top: calc(50% - 2px); right: 0; left: 0; height: 4px; border-radius: 999px; background: var(--muted); }
.range-track span { position: absolute; top: 0; bottom: 0; border-radius: inherit; background: var(--primary); }
.range-slider input[type="range"] { position: absolute; inset: 0; width: 100%; height: 34px; padding: 0; border: 0; background: transparent; pointer-events: none; appearance: none; }
.range-slider input[type="range"]::-webkit-slider-thumb { width: 18px; height: 18px; margin-top: -7px; border: 2px solid var(--primary); border-radius: 999px; background: var(--background); pointer-events: auto; appearance: none; }
.range-slider input[type="range"]::-moz-range-thumb { width: 18px; height: 18px; border: 2px solid var(--primary); border-radius: 999px; background: var(--background); pointer-events: auto; }
.range-slider input[type="range"]::-webkit-slider-runnable-track { height: 4px; background: transparent; }
.range-slider input[type="range"]::-moz-range-track { height: 4px; background: transparent; }
.switch-list { display: grid; gap: 8px; }
.switch-row { display: flex; min-height: 38px; align-items: center; justify-content: space-between; gap: 10px; padding: 6px 10px; border: 1px solid var(--border); border-radius: var(--radius); cursor: pointer; }
.switch-row input { position: absolute; width: 1px; height: 1px; opacity: 0; }
.switch-row i { position: relative; width: 38px; height: 22px; flex: 0 0 auto; border-radius: 999px; background: #d4d4d8; transition: background-color .14s ease; }
.switch-row i::after { position: absolute; top: 3px; left: 3px; width: 16px; height: 16px; border-radius: 50%; background: white; content: ""; transition: transform .14s ease; box-shadow: 0 1px 2px rgba(0, 0, 0, .2); }
.switch-row input:checked + i { background: var(--primary); }
.switch-row input:checked + i::after { transform: translateX(16px); }

#generateHint { display: flex; align-items: center; gap: 6px; color: var(--success); }
#generateHint.is-error { color: var(--destructive); }
.validation-list { display: grid; gap: 6px; }
.validation-item { display: grid; gap: 2px; padding: 8px; border: 1px solid var(--border); border-radius: var(--radius); background: var(--muted); }
.validation-item strong { font-size: 16px; }
.validation-item span { color: var(--muted-foreground); }
.validation-item.is-error { border-color: rgba(220, 38, 38, .28); background: #fef2f2; color: var(--destructive); }
.validation-item.is-error span { color: var(--destructive); }
.validation-empty { padding: 8px; border: 1px solid var(--border); border-radius: var(--radius); color: var(--muted-foreground); background: var(--muted); }
.field-error { min-height: 20px; margin: 0; color: var(--destructive); overflow-wrap: anywhere; }
.empty-state { width: 100%; padding: 12px; border-radius: var(--radius); color: var(--muted-foreground); background: var(--muted); }
.empty-inline { color: var(--muted-foreground); }

.btn-icon-loading { display: none; }
.is-generating .btn-icon-static { display: none; }
.is-generating .btn-icon-loading { display: block; animation: spin .8s linear infinite; }

.modal { width: min(100% - 32px, 520px); max-height: calc(100vh - 32px); padding: 0; border: 1px solid var(--border); border-radius: var(--radius); background: var(--card); box-shadow: 0 20px 50px rgba(0, 0, 0, .16); }
.modal::backdrop { background: rgba(0, 0, 0, .42); }
.modal-content { display: grid; gap: 12px; max-height: calc(100vh - 32px); overflow-y: auto; padding: 16px; }
.modal-content header, .modal-actions { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.modal-content h2 { margin: 0; font-size: 20.25px; }
.modal-actions { justify-content: flex-start; }
.dialog-note { margin: 0; color: var(--muted-foreground); }
.dialog-note code { padding: 2px 6px; border-radius: calc(var(--radius) - 2px); background: var(--muted); color: var(--foreground); font-family: ui-monospace, SFMono-Regular, Consolas, "Liberation Mono", monospace; }
.cron-output { padding: 10px 12px; border-radius: var(--radius); background: var(--muted); color: var(--foreground); font-family: ui-monospace, SFMono-Regular, Consolas, "Liberation Mono", monospace; }
.drop-overlay { position: fixed; z-index: 90; inset: 0; display: grid; place-items: center; background: rgba(0, 0, 0, .58); color: white; }
.drop-overlay > div { display: grid; min-width: 260px; min-height: 140px; place-items: center; align-content: center; gap: 10px; border-radius: var(--radius); }
.toast-region { position: fixed; z-index: 100; right: 16px; bottom: 16px; display: grid; width: min(100% - 32px, 360px); gap: 8px; }
.toast { display: flex; align-items: center; gap: 8px; padding: 10px 12px; border: 1px solid var(--border); border-radius: var(--radius); background: var(--card); box-shadow: 0 12px 30px rgba(0, 0, 0, .12); animation: toast-in .14s ease both; }
.toast svg { flex: 0 0 auto; color: var(--success); }
.toast.is-error { border-color: rgba(220, 38, 38, .28); color: var(--destructive); }
.toast.is-error svg { color: var(--destructive); }
.is-removing { animation: item-out .14s ease both !important; }

@keyframes item-in { from { opacity: 0; transform: translateY(4px); } }
@keyframes item-out { to { opacity: 0; transform: translateX(6px); } }
@keyframes toast-in { from { opacity: 0; transform: translateY(6px); } }
@keyframes spin { to { transform: rotate(360deg); } }
@keyframes validation-attention {
  50% { border-color: rgba(220, 38, 38, .55); background: #fef2f2; box-shadow: 0 0 0 4px rgba(220, 38, 38, .14); }
}

@media (max-width: 1040px) {
  .editor-grid { grid-template-columns: 1fr 1fr; }
  .side-stack { grid-column: 1 / -1; grid-template-columns: 1fr 1fr; }
}

@media (max-width: 720px) {
  .app-shell { width: min(100% - 24px, 1280px); padding-top: 16px; padding-bottom: 96px; }
  .app-header, .panel-header { display: grid; }
  .toolbar { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); justify-content: stretch; gap: 6px; width: 100%; }
  .toolbar .button, .tooltip-wrap .button { width: 100%; min-width: 0; min-height: 44px; padding: 4px 2px; line-height: 1.1; white-space: normal; overflow-wrap: anywhere; }
  .tooltip-wrap { min-width: 0; }
  .editor-grid, .side-stack { grid-template-columns: 1fr; }
  .side-stack { grid-column: auto; }
  .import-row, .add-row, .settings-grid { grid-template-columns: 1fr; }
  .sticker-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .message-actions, .target-actions { justify-content: flex-start; }
  .complete-action { position: fixed; z-index: 80; right: 16px; bottom: 16px; display: inline-flex; width: auto !important; min-height: 52px !important; padding: 0 18px !important; border-radius: 999px; box-shadow: 0 16px 36px rgba(0, 0, 0, .18); white-space: nowrap !important; }
  .complete-action-icon { display: block; width: 22px; height: 22px; }
  .toast-region { right: 16px; bottom: 80px; }
  .message-item { grid-template-columns: auto minmax(0, 1fr) auto; align-items: start; }
  .message-copy { display: contents; }
  .message-copy strong { grid-column: 2; grid-row: 1; align-self: center; width: max-content; max-width: 100%; }
  .message-copy p { grid-column: 1 / -1; grid-row: 2; margin: 0; }
  .drag-handle { grid-column: 1; grid-row: 1; cursor: default; opacity: .65; }
  .message-item > .mini-button { grid-column: 3; grid-row: 1; }
}

@media (min-width: 430px) and (max-width: 720px) {
  .sticker-grid { grid-template-columns: repeat(4, minmax(0, 1fr)); }
}

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