:root {
    --bg: #f7f8fa;
    --surface: #ffffff;
    --surface-soft: #f9fafb;
    --surface-muted: #f3f4f6;
    --text: #111827;
    --muted: #4b5563;
    --subtle: #6b7280;
    --line: #e5e7eb;
    --line-strong: #d1d5db;
    --accent: #2f5fd0;
    --accent-hover: #1d4ed8;
    --accent-soft: rgba(47, 95, 208, 0.09);
    --ok: #15803d;
    --ok-soft: #edf7f0;
    --warn: #b45309;
    --warn-soft: #fff7ed;
    --error: #dc2626;
    --error-soft: #fef2f2;
    --pending: #64748b;
    --shadow: 0 1px 2px rgba(16, 24, 40, 0.04), 0 1px 3px rgba(16, 24, 40, 0.06);
}

* {
    box-sizing: border-box;
}

body {
    margin: 0;
    min-width: 320px;
    color: var(--text);
    background: var(--bg);
    font-family: Inter, "PingFang SC", "Noto Sans SC", "Microsoft YaHei", sans-serif;
    font-size: 14px;
    line-height: 1.6;
}

button,
textarea,
input {
    font: inherit;
}

button {
    border: 0;
}

.shell {
    min-height: 100vh;
}

.topbar {
    position: sticky;
    top: 0;
    z-index: 20;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 24px;
    min-height: 78px;
    padding: 16px 32px;
    border-bottom: 1px solid var(--line);
    background: rgba(255, 255, 255, 0.94);
    backdrop-filter: blur(14px);
}

.brand {
    display: flex;
    align-items: center;
    min-width: 0;
    gap: 14px;
}

.mark {
    display: grid;
    flex: 0 0 42px;
    width: 42px;
    height: 42px;
    place-items: center;
    border-radius: 10px;
    color: #fff;
    background: #111827;
    font-weight: 700;
    letter-spacing: 0;
}

.brand h1 {
    margin: 0;
    font-size: 22px;
    font-weight: 650;
    line-height: 1.3;
}

.brand p {
    margin: 4px 0 0;
    color: var(--subtle);
    font-size: 13px;
}

.badge {
    flex: 0 0 auto;
    min-height: 34px;
    padding: 7px 12px;
    border: 1px solid rgba(47, 95, 208, 0.16);
    border-radius: 999px;
    color: var(--accent);
    background: var(--accent-soft);
    font-size: 12px;
    font-weight: 650;
}

.workspace {
    width: min(1280px, 100%);
    margin: 0 auto;
    padding: 24px 28px 40px;
}

.stepper {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 0;
    margin-bottom: 24px;
    padding: 16px 18px;
    border: 1px solid var(--line);
    border-radius: 12px;
    background: var(--surface);
    box-shadow: var(--shadow);
}

.step {
    position: relative;
    display: flex;
    align-items: center;
    min-width: 0;
    gap: 10px;
    color: var(--pending);
}

.step:not(:last-child)::after {
    content: "";
    flex: 1 1 auto;
    height: 1px;
    min-width: 18px;
    margin: 0 18px;
    background: var(--line);
}

.index {
    display: grid;
    flex: 0 0 26px;
    width: 26px;
    height: 26px;
    place-items: center;
    border: 1px solid var(--line-strong);
    border-radius: 999px;
    color: var(--pending);
    background: #fff;
    font-size: 12px;
    font-weight: 700;
}

.step.active {
    color: var(--text);
}

.step.active .index {
    color: #fff;
    border-color: var(--accent);
    background: var(--accent);
}

.step.done .index {
    color: #fff;
    border-color: var(--text);
    background: var(--text);
}

.step strong {
    overflow: hidden;
    font-size: 13px;
    font-weight: 650;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.app-layout {
    display: grid;
    grid-template-columns: minmax(0, 1fr) 320px;
    gap: 24px;
    align-items: start;
}

.work-column {
    display: grid;
    gap: 20px;
}

.panel,
.side-card {
    border: 1px solid rgba(229, 231, 235, 0.9);
    border-radius: 12px;
    background: var(--surface);
    box-shadow: var(--shadow);
}

.primary-panel {
    padding: 22px;
}

.rules-panel {
    border-color: rgba(47, 95, 208, 0.18);
}

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

.panel-header h2,
.side-card h2 {
    margin: 0;
    color: var(--text);
    font-size: 18px;
    font-weight: 650;
    line-height: 1.3;
}

.side-card h2 {
    font-size: 15px;
}

.eyebrow {
    display: block;
    margin-bottom: 5px;
    color: var(--accent);
    font-size: 12px;
    font-weight: 700;
}

.subtle {
    max-width: 680px;
    margin: 5px 0 0;
    color: var(--subtle);
    font-size: 13px;
}

.field-label {
    display: block;
    margin-bottom: 8px;
    color: var(--text);
    font-size: 13px;
    font-weight: 650;
}

.status-badge {
    flex: 0 0 auto;
    min-height: 28px;
    padding: 5px 10px;
    border-radius: 999px;
    color: var(--ok);
    background: var(--ok-soft);
    font-size: 12px;
    font-weight: 650;
    white-space: nowrap;
}

.status-badge.neutral {
    color: var(--pending);
    background: var(--surface-muted);
}

.status-badge.warning {
    color: var(--warn);
    background: var(--warn-soft);
}

.status-badge.error {
    color: var(--error);
    background: var(--error-soft);
}

textarea {
    width: 100%;
    min-height: 148px;
    padding: 14px 15px;
    resize: vertical;
    border: 1px solid var(--line-strong);
    border-radius: 10px;
    color: var(--text);
    background: #fff;
    outline: none;
    transition: border-color 180ms ease, box-shadow 180ms ease, background-color 180ms ease;
}

textarea::placeholder {
    color: #9ca3af;
}

textarea:focus,
textarea:focus-visible {
    border-color: rgba(47, 95, 208, 0.78);
    box-shadow: 0 0 0 3px rgba(47, 95, 208, 0.12);
}

button:focus-visible,
.upload-dropzone:focus-within {
    outline: 3px solid rgba(47, 95, 208, 0.22);
    outline-offset: 2px;
}

.example-box {
    margin-top: 14px;
    padding: 14px 16px;
    border-radius: 10px;
    background: var(--surface-soft);
}

.example-box strong {
    display: block;
    margin-bottom: 8px;
    font-size: 13px;
    font-weight: 650;
}

.example-box ul {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 6px 18px;
    margin: 0;
    padding-left: 18px;
    color: var(--muted);
    font-size: 13px;
}

.hidden {
    display: none !important;
}

.actions {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    margin-top: 16px;
}

button,
.upload-dropzone {
    cursor: pointer;
}

button {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-height: 40px;
    padding: 9px 16px;
    border-radius: 10px;
    font-weight: 650;
    transition: background-color 180ms ease, border-color 180ms ease, box-shadow 180ms ease, color 180ms ease, opacity 180ms ease;
}

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

.primary:hover:not(:disabled) {
    background: var(--accent-hover);
    box-shadow: 0 6px 16px rgba(47, 95, 208, 0.18);
}

.secondary {
    color: var(--text);
    border: 1px solid var(--line-strong);
    background: #fff;
}

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

button:disabled,
.upload-dropzone.disabled {
    opacity: 0.56;
    cursor: not-allowed;
}

.message,
.delivery-note {
    margin: 14px 0 0;
    padding: 11px 13px;
    border-radius: 10px;
    color: var(--muted);
    background: var(--surface-soft);
    font-size: 13px;
}

.message.success,
.delivery-note.success {
    color: var(--ok);
    background: var(--ok-soft);
}

.message.warning,
.delivery-note.warning {
    color: var(--warn);
    background: var(--warn-soft);
}

.message.error,
.delivery-note.error {
    color: var(--error);
    background: var(--error-soft);
}

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

.rule-card {
    display: grid;
    gap: 12px;
    padding: 15px;
    border: 1px solid var(--line);
    border-radius: 10px;
    background: var(--surface-soft);
}

.rule-card-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
}

.rule-card h3 {
    margin: 0;
    font-size: 15px;
    font-weight: 650;
}

.rule-state {
    flex: 0 0 auto;
    padding: 3px 8px;
    border-radius: 999px;
    color: var(--pending);
    background: #eef2f7;
    font-size: 12px;
    font-weight: 650;
}

.rule-state.ready {
    color: var(--ok);
    background: var(--ok-soft);
}

.rule-edit-row,
.rule-fields {
    display: grid;
    gap: 8px;
}

.rule-edit-row {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    align-items: end;
}

.rule-fields {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    padding-top: 4px;
}

.rule-field,
.rule-edit-field {
    min-width: 0;
}

.rule-edit-field {
    display: grid;
    gap: 4px;
}

.rule-custom-font {
    grid-column: 1 / -1;
}

.rule-field span,
.rule-edit-field span {
    display: block;
    color: var(--subtle);
    font-size: 12px;
}

.rule-field strong {
    display: block;
    overflow: hidden;
    margin-top: 2px;
    color: var(--text);
    font-size: 13px;
    font-weight: 600;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.rule-edit-field select,
.rule-edit-field input {
    width: 100%;
    min-width: 0;
    min-height: 34px;
    padding: 7px 9px;
    border: 1px solid var(--line-strong);
    border-radius: 8px;
    box-sizing: border-box;
    color: var(--text);
    background: #fff;
    font-size: 13px;
}

.rule-edit-field select:focus,
.rule-edit-field input:focus {
    border-color: var(--accent);
    outline: 2px solid rgba(47, 95, 208, 0.12);
}

.clarification-list,
.unsupported-list {
    margin: 12px 0 0;
    padding-left: 18px;
    color: var(--muted);
    font-size: 13px;
}

.clarification-list:empty {
    display: none;
}

.upload-dropzone {
    position: relative;
    display: grid;
    place-items: center;
    min-height: 156px;
    padding: 22px;
    border: 1px dashed #cbd5e1;
    border-radius: 12px;
    color: var(--text);
    background: #fbfcfe;
    text-align: center;
    transition: border-color 180ms ease, background-color 180ms ease, box-shadow 180ms ease, opacity 180ms ease;
}

.upload-dropzone:not(.disabled):hover,
.upload-dropzone.drag-over {
    border-color: rgba(47, 95, 208, 0.7);
    background: rgba(47, 95, 208, 0.04);
}

.upload-icon {
    display: grid;
    width: 40px;
    height: 40px;
    margin-bottom: 10px;
    place-items: center;
    border-radius: 12px;
    color: var(--accent);
    background: var(--accent-soft);
}

.upload-icon svg {
    width: 22px;
    height: 22px;
    fill: none;
    stroke: currentColor;
    stroke-width: 1.8;
    stroke-linecap: round;
    stroke-linejoin: round;
}

.upload-dropzone strong {
    font-size: 15px;
    font-weight: 650;
}

.upload-dropzone small {
    margin-top: 4px;
    color: var(--subtle);
    font-size: 13px;
}

.file-input {
    position: absolute;
    width: 1px;
    height: 1px;
    overflow: hidden;
    clip: rect(0 0 0 0);
    clip-path: inset(50%);
    white-space: nowrap;
}

.queue {
    display: grid;
    gap: 10px;
    margin-top: 14px;
}

.queue-item,
.empty-state {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto auto;
    gap: 12px;
    align-items: center;
    min-height: 48px;
    padding: 12px 14px;
    border: 1px solid var(--line);
    border-radius: 10px;
    background: #fff;
}

.queue-item {
    cursor: pointer;
}

.queue-item.selected {
    border-color: rgba(37, 99, 235, 0.34);
    background: #eff6ff;
}

.queue-name {
    min-width: 0;
}

.queue-name strong {
    display: block;
    overflow: hidden;
    color: var(--text);
    font-size: 14px;
    font-weight: 600;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.queue-name span {
    display: block;
    margin-top: 2px;
    color: var(--subtle);
    font-size: 12px;
}

.empty-state {
    grid-template-columns: 1fr;
    justify-items: center;
    padding: 18px;
    color: var(--subtle);
    background: var(--surface-soft);
    text-align: center;
}

.empty-state strong {
    color: var(--text);
    font-size: 14px;
}

.empty-state span {
    font-size: 13px;
}

.pill {
    padding: 4px 9px;
    border-radius: 999px;
    color: var(--pending);
    background: #eef2f7;
    font-size: 12px;
    font-weight: 650;
    white-space: nowrap;
}

.pill.error {
    color: var(--error);
    background: var(--error-soft);
}

.remove-file {
    min-height: 32px;
    padding: 5px 9px;
    color: var(--subtle);
    border: 1px solid transparent;
    background: transparent;
}

.remove-file:hover {
    color: var(--error);
    background: var(--error-soft);
}

.document-styles {
    display: grid;
    gap: 12px;
    margin-top: 16px;
    padding-top: 16px;
    border-top: 1px solid var(--line);
}

.document-styles-header {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 16px;
}

.document-styles h3 {
    margin: 0;
    color: var(--text);
    font-size: 15px;
    font-weight: 650;
}

.document-styles p {
    margin: 3px 0 0;
    color: var(--subtle);
    font-size: 13px;
}

.style-preview-list {
    display: grid;
    gap: 12px;
}

.style-preview-controls {
    display: flex;
    align-items: end;
    justify-content: space-between;
    gap: 12px;
}

.style-preview-mode {
    display: inline-flex;
    padding: 3px;
    border: 1px solid var(--line);
    border-radius: 10px;
    background: var(--surface-soft);
}

.style-preview-mode button {
    min-height: 32px;
    padding: 5px 10px;
    border: 0;
    border-radius: 8px;
    color: var(--subtle);
    background: transparent;
    font-size: 12px;
}

.style-preview-mode button.active {
    color: var(--primary);
    background: #fff;
    box-shadow: 0 1px 3px rgba(15, 23, 42, 0.08);
}

.style-preview-select {
    display: grid;
    min-width: min(280px, 100%);
    gap: 5px;
}

.style-preview-select.hidden {
    display: none;
}

.style-preview-select span {
    color: var(--subtle);
    font-size: 12px;
    font-weight: 600;
}

.style-preview-select select {
    min-height: 36px;
    max-width: 100%;
    padding: 6px 34px 6px 10px;
    border: 1px solid var(--line-strong);
    border-radius: 9px;
    color: var(--text);
    background: #fff;
    font-size: 13px;
}

.style-preview-tabs {
    display: flex;
    gap: 8px;
    overflow-x: auto;
    padding-bottom: 2px;
}

.style-preview-tab {
    display: grid;
    min-width: 150px;
    max-width: 220px;
    gap: 2px;
    padding: 8px 10px;
    border: 1px solid var(--line);
    border-radius: 8px;
    color: var(--muted);
    text-align: left;
    background: #fff;
    cursor: pointer;
}

.style-preview-tab:hover {
    border-color: var(--line-strong);
}

.style-preview-tab.active {
    border-color: rgba(37, 99, 235, 0.34);
    color: var(--primary);
    background: #eff6ff;
}

.style-preview-tab span,
.style-preview-tab strong {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.style-preview-tab span {
    font-size: 13px;
    font-weight: 650;
}

.style-preview-tab strong {
    color: var(--subtle);
    font-size: 11px;
    font-weight: 600;
}

.style-preview-file {
    display: grid;
    gap: 12px;
    padding: 14px;
    border: 1px solid var(--line);
    border-radius: 10px;
    background: #fff;
}

.style-preview-file.error {
    border-color: rgba(220, 38, 38, 0.18);
    background: var(--error-soft);
}

.style-preview-file.error p {
    margin: 0;
    color: var(--error);
    font-size: 13px;
}

.style-preview-file-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
}

.style-preview-file-header > strong {
    overflow: hidden;
    color: var(--text);
    font-size: 14px;
    font-weight: 650;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.style-preview-grid {
    display: grid;
    gap: 8px;
}

.style-preview-row {
    display: grid;
    grid-template-columns: minmax(86px, 0.85fr) repeat(3, minmax(72px, 0.7fr)) minmax(140px, 1.3fr);
    gap: 10px;
    align-items: start;
    padding: 10px 12px;
    border: 1px solid var(--line);
    border-radius: 9px;
    background: var(--surface-soft);
}

.style-preview-row span {
    display: block;
    color: var(--subtle);
    font-size: 12px;
}

.style-preview-row strong {
    display: block;
    overflow: hidden;
    margin-top: 2px;
    color: var(--text);
    font-size: 13px;
    font-weight: 600;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.style-preview-target strong {
    font-weight: 700;
}

.style-preview-sample strong {
    color: var(--muted);
}

.insight-sidebar {
    position: sticky;
    top: 102px;
    display: grid;
    gap: 16px;
}

.side-card {
    padding: 18px;
}

.status-stack,
.config-list {
    display: grid;
    gap: 12px;
    margin-top: 14px;
}

.status-stack > div,
.config-list > div {
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    gap: 16px;
    padding-bottom: 12px;
    border-bottom: 1px solid var(--line);
}

.status-stack > div:last-child,
.config-list > div:last-child {
    padding-bottom: 0;
    border-bottom: 0;
}

.status-stack span,
.config-list span {
    color: var(--subtle);
    font-size: 13px;
}

.status-stack strong,
.config-list strong {
    color: var(--text);
    font-size: 13px;
    font-weight: 650;
    text-align: right;
}

.unsupported-list li + li {
    margin-top: 6px;
}

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

@media (max-width: 1040px) {
    .app-layout {
        grid-template-columns: 1fr;
    }

    .insight-sidebar {
        position: static;
        grid-template-columns: repeat(3, minmax(0, 1fr));
    }
}

@media (max-width: 820px) {
    .topbar {
        position: static;
        align-items: flex-start;
        padding: 14px 18px;
    }

    .badge {
        display: none;
    }

    .workspace {
        padding: 16px 14px 28px;
    }

    .stepper {
        grid-template-columns: repeat(2, minmax(0, 1fr));
        gap: 10px 16px;
        padding: 14px;
    }

    .step:not(:last-child)::after {
        display: none;
    }

    .rules-list,
    .example-box ul,
    .insight-sidebar,
    .style-preview-row {
        grid-template-columns: 1fr;
    }
}

@media (max-width: 560px) {
    body {
        font-size: 15px;
    }

    .brand {
        align-items: flex-start;
    }

    .mark {
        width: 38px;
        height: 38px;
        flex-basis: 38px;
    }

    .brand h1 {
        font-size: 18px;
    }

    .brand p {
        display: -webkit-box;
        overflow: hidden;
        -webkit-box-orient: vertical;
        -webkit-line-clamp: 2;
    }

    .primary-panel,
    .side-card {
        padding: 16px;
    }

    .panel-header {
        flex-direction: column;
        gap: 10px;
    }

    .status-badge {
        align-self: flex-start;
    }

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

    textarea {
        min-height: 160px;
        font-size: 16px;
    }

    .rule-edit-row,
    .rule-fields {
        grid-template-columns: 1fr;
    }

    .queue-item {
        grid-template-columns: 1fr;
        gap: 8px;
    }

    .style-preview-tab {
        min-width: 132px;
    }

    .document-styles-header,
    .style-preview-controls,
    .style-preview-file-header {
        flex-direction: column;
        align-items: flex-start;
    }

    .style-preview-select {
        width: 100%;
    }

    .queue-name strong,
    .style-preview-file-header > strong,
    .style-preview-row strong {
        white-space: normal;
        overflow-wrap: anywhere;
    }

    .pill,
    .remove-file {
        justify-self: start;
    }

    .actions {
        display: grid;
        grid-template-columns: 1fr;
    }

    button {
        width: 100%;
        min-height: 44px;
    }
}
