:root {
    --bg: #f5f7fb;
    --panel: #ffffff;
    --panel-soft: #f9fbff;
    --line: #e6ebf3;
    --line-strong: #d6deeb;
    --muted: #7c879a;
    --text: #101828;
    --blue: #2468f2;
    --blue-strong: #1557d6;
    --blue-soft: #edf4ff;
    --green: #0f9f6e;
    --amber: #c27803;
    --danger: #c2410c;
    --shadow: 0 16px 38px rgba(31, 56, 94, .09);
    --shadow-soft: 0 8px 20px rgba(31, 56, 94, .06);
}

* {
    box-sizing: border-box;
}

[hidden] {
    display: none !important;
}

html,
body {
    min-height: 100%;
}

body {
    margin: 0;
    background:
        linear-gradient(180deg, rgba(255, 255, 255, .86), rgba(245, 247, 251, .92) 180px),
        radial-gradient(circle at 18% 8%, rgba(36, 104, 242, .08), transparent 30%),
        var(--bg);
    color: var(--text);
    font-family: "Segoe UI", "Microsoft YaHei", Arial, sans-serif;
    font-size: 14px;
    letter-spacing: 0;
}

button,
select,
input {
    font: inherit;
}

button {
    cursor: pointer;
}

.app {
    height: 100vh;
    display: grid;
    grid-template-rows: 58px 1fr;
    overflow: hidden;
}

.topbar {
    display: flex;
    align-items: center;
    gap: 16px;
    padding: 0 22px;
    background: rgba(255, 255, 255, .96);
    border-bottom: 1px solid var(--line);
    box-shadow: 0 1px 0 rgba(255, 255, 255, .9);
}

.brand {
    display: flex;
    align-items: center;
    gap: 10px;
    min-width: 0;
}

.brand-mark {
    display: grid;
    place-items: center;
    width: 32px;
    height: 32px;
    color: #fff;
    background: linear-gradient(145deg, #1f6eff, #154ec7);
    border-radius: 9px;
    font-weight: 700;
    box-shadow: 0 9px 18px rgba(36, 104, 242, .24);
}

.brand strong {
    color: #1757d2;
    font-size: 18px;
}

.brand span {
    color: #6b7280;
    font-size: 16px;
}

.license-actions {
    margin-left: auto;
    display: flex;
    align-items: center;
    gap: 8px;
    min-width: 0;
    padding: 0;
    background: transparent;
    border: 0;
    box-shadow: none;
}

.topbar-button {
    display: inline-flex;
    align-items: center;
    gap: 7px;
    min-height: 34px;
    padding: 0 12px 0 9px;
    border: 1px solid var(--line);
    border-radius: 999px;
    color: #24314f;
    background: #fff;
    font-size: 13px;
    font-weight: 600;
    white-space: nowrap;
    box-shadow: 0 1px 2px rgba(30, 48, 80, .05);
    transition: background .16s ease, border-color .16s ease, box-shadow .16s ease, transform .16s ease;
}

.topbar-button::before {
    content: attr(data-icon);
    display: grid;
    place-items: center;
    width: 20px;
    height: 20px;
    border-radius: 999px;
    color: #fff;
    font-size: 12px;
    font-weight: 800;
    line-height: 1;
}

.topbar-button:hover {
    transform: translateY(-1px);
    border-color: #cfd9ea;
    box-shadow: 0 8px 18px rgba(39, 70, 125, .10);
}

.topbar-button:focus-visible {
    outline: 2px solid rgba(61, 99, 255, .32);
    outline-offset: 2px;
}

.topbar-button[data-tone="code"] {
    border-color: #d8e3ff;
    background: #f3f7ff;
}

.topbar-button[data-tone="code"]::before {
    background: #3d63ff;
}

.topbar-button[data-tone="status"] {
    border-color: #ccebdc;
    background: #f0fbf6;
}

.topbar-button[data-tone="status"]::before {
    background: #0f9f6e;
}

.topbar-button[data-tone="upload"] {
    border-color: #f2ddb6;
    background: #fff8ea;
}

.topbar-button[data-tone="upload"]::before {
    background: #c27803;
}

.status-pill {
    display: inline-flex;
    align-items: center;
    gap: 7px;
    min-height: 30px;
    padding: 4px 13px;
    color: #26538f;
    background: #f5f8ff;
    border: 1px solid #dfe8f8;
    border-radius: 999px;
    white-space: nowrap;
    font-weight: 600;
}

.workspace {
    display: grid;
    grid-template-columns: 232px minmax(420px, 1fr) minmax(420px, 42vw);
    height: calc(100vh - 58px);
    min-height: 0;
    gap: 12px;
    padding: 12px;
    overflow: hidden;
}

.sidebar,
.preview-pane,
.result-pane {
    min-width: 0;
    min-height: 0;
}

.sidebar {
    display: flex;
    flex-direction: column;
    gap: 14px;
    padding: 14px;
    background: rgba(255, 255, 255, .88);
    border: 1px solid var(--line);
    border-radius: 12px;
    box-shadow: var(--shadow-soft);
}

.side-actions {
    display: grid;
    gap: 10px;
}

.new-button,
.api-button {
    width: 100%;
    min-height: 40px;
    border: 1px solid var(--line-strong);
    border-radius: 9px;
    color: #1e2b43;
    background: #fff;
    font-weight: 700;
    transition: border-color .16s ease, box-shadow .16s ease, transform .16s ease, background .16s ease;
}

.new-button {
    color: #fff;
    background: linear-gradient(180deg, #2b75ff, #1557d6);
    border-color: #1557d6;
    box-shadow: 0 10px 20px rgba(36, 104, 242, .20);
}

.new-button:hover,
.api-button:hover {
    transform: translateY(-1px);
    box-shadow: var(--shadow-soft);
}

.api-button:hover {
    border-color: #b9c8e0;
    background: #f9fbff;
}

.api-button {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    text-decoration: none;
}

.settings-button {
    display: flex;
    align-items: center;
    gap: 8px;
    width: 100%;
    min-height: 36px;
    padding: 0 12px;
    border: 0;
    background: transparent;
    color: #29364f;
    text-align: left;
}

.side-section {
    display: flex;
    min-height: 0;
    flex: 1;
    flex-direction: column;
    border-top: 1px solid var(--line);
    padding-top: 12px;
}

.side-title {
    display: flex;
    align-items: center;
    justify-content: space-between;
    color: #2b364b;
    font-weight: 700;
    margin: 0 0 12px;
}

.side-tabs {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 4px;
    margin-bottom: 10px;
    padding: 3px;
    background: #f2f5fa;
    border: 1px solid #e2e8f2;
    border-radius: 999px;
}

.side-tab {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-height: 28px;
    color: #66748a;
    border-radius: 999px;
    font-size: 12px;
    font-weight: 700;
}

.side-tab.active {
    color: #1557d6;
    background: #fff;
    box-shadow: 0 4px 10px rgba(31, 56, 94, .08);
}

.file-list {
    display: flex;
    flex-direction: column;
    gap: 8px;
    min-height: 120px;
    overflow: auto;
}

.file-item {
    display: grid;
    grid-template-columns: 28px 1fr;
    gap: 8px;
    align-items: center;
    padding: 10px;
    border: 1px solid #dce6f7;
    border-radius: 10px;
    background: #f5f8ff;
    color: #20304f;
}

.file-icon {
    display: grid;
    place-items: center;
    width: 28px;
    height: 34px;
    border-radius: 8px;
    background: #2468f2;
    color: #fff;
    font-size: 13px;
    font-weight: 700;
}

.file-name {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    font-weight: 600;
}

.file-meta {
    margin-top: 3px;
    color: var(--muted);
    font-size: 12px;
}

.empty-list {
    display: grid;
    place-items: center;
    min-height: 128px;
    padding: 18px 12px;
    color: #9aa6bd;
    text-align: center;
    font-size: 13px;
    border: 1px dashed #d8e0ec;
    border-radius: 10px;
    background: #fafcff;
}

.preview-pane {
    display: grid;
    grid-template-rows: auto minmax(0, 1fr);
    background: #f2f5fb;
    border: 1px solid var(--line);
    border-radius: 12px;
    overflow: hidden;
    box-shadow: var(--shadow-soft);
}

.upload-strip {
    background: #fff;
}

.dropzone {
    position: relative;
    display: grid;
    place-items: center;
    min-height: 118px;
    margin: 14px;
    border: 1.5px dashed #b8c9e8;
    border-radius: 8px;
    background: #f8fbff;
    transition: border-color .16s ease, background .16s ease, box-shadow .16s ease;
}

.dropzone:hover {
    border-color: #6a95ef;
    box-shadow: inset 0 0 0 1px rgba(36, 104, 242, .10);
}

.dropzone.dragging {
    border-color: var(--green);
    background: #edfdf7;
}

.dropzone input {
    position: absolute;
    inset: 0;
    opacity: 0;
    cursor: pointer;
}

.drop-content {
    display: grid;
    justify-items: center;
    gap: 8px;
    padding: 18px;
    text-align: center;
    pointer-events: none;
}

.upload-icon {
    display: grid;
    place-items: center;
    width: 46px;
    height: 40px;
    border-radius: 12px;
    background: linear-gradient(180deg, #2b75ff, #1557d6);
    color: #fff;
    font-size: 20px;
    font-weight: 700;
}

.drop-title {
    color: #1f2a44;
    font-weight: 700;
    font-size: 16px;
}

.drop-note {
    max-width: 480px;
    color: #7e91bd;
    line-height: 1.55;
    font-size: 13px;
}

.source-bar {
    display: grid;
    grid-template-rows: 58px 52px;
    background: #fff;
}

.source-tab {
    display: flex;
    align-items: center;
    padding: 0 16px;
    color: var(--blue);
    background: #fff;
    border-bottom: 1px solid var(--line);
    font-size: 13px;
    font-weight: 700;
}

.source-meta {
    display: flex;
    align-items: center;
    gap: 8px;
    min-width: 0;
    height: 52px;
    padding: 0 16px;
    background: #fbfcff;
    border-bottom: 1px solid var(--line);
}

.source-file-icon {
    position: relative;
    display: block;
    flex: 0 0 auto;
    width: 18px;
    height: 22px;
    border: 1.5px solid #4f73c8;
    border-radius: 3px;
    background: #f5f8ff;
    color: transparent;
    font-size: 0;
}

.source-file-icon::before {
    content: "";
    position: absolute;
    top: -1.5px;
    right: -1.5px;
    width: 7px;
    height: 7px;
    background: linear-gradient(225deg, #fff 48%, #4f73c8 49%, #4f73c8 57%, #e7efff 58%);
    border-radius: 0 3px 0 0;
}

.source-file-icon::after {
    content: "";
    position: absolute;
    left: 4px;
    bottom: 5px;
    width: 8px;
    height: 1.5px;
    background: #8da4d8;
    box-shadow: 0 -4px 0 #8da4d8;
}

.source-file {
    flex: 1 1 auto;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    font-weight: 600;
}

.source-size {
    color: #91a0bb;
    white-space: nowrap;
}

.source-tools {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    color: #1f2a44;
    font-size: 13px;
    white-space: nowrap;
}

.preview-stage {
    position: relative;
    display: grid;
    min-height: 0;
    padding: 0;
    overflow: hidden;
    background: #f2f5fb;
}

.image-shell {
    position: relative;
    display: grid;
    place-items: start center;
    min-height: 0;
    padding: 30px 24px 76px;
    overflow: auto;
    background: #f7f9fd;
    border: 0;
    border-radius: 0;
    box-shadow: none;
    scrollbar-gutter: stable;
}

.image-wrap {
    position: relative;
    width: min(100%, 560px);
    background: #fff;
    border: 1px solid #dfe5f0;
    box-shadow: 0 8px 22px rgba(31, 49, 83, .08);
}

.image-wrap img {
    display: block;
    width: 100%;
    height: auto;
}

.overlay {
    position: absolute;
    inset: 0;
    pointer-events: none;
}

.box {
    position: absolute;
    border: 1.5px solid rgba(61, 99, 255, .34);
    background: rgba(61, 99, 255, .035);
    opacity: .42;
    pointer-events: auto;
    transition: opacity .14s ease, border-color .14s ease, background .14s ease, box-shadow .14s ease;
}

.box.active {
    z-index: 5;
    border-color: rgba(61, 99, 255, .95);
    background: rgba(61, 99, 255, .10);
    box-shadow: 0 0 0 2px rgba(61, 99, 255, .14);
    opacity: 1;
}

.box-label {
    position: absolute;
    top: -22px;
    left: -2px;
    max-width: 180px;
    padding: 2px 6px;
    color: #fff;
    background: var(--blue);
    font-size: 12px;
    line-height: 1.35;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    opacity: 0;
    transition: opacity .14s ease;
}

.box.active .box-label {
    opacity: 1;
}

.placeholder {
    display: grid;
    justify-items: center;
    gap: 12px;
    color: #8896b1;
    text-align: center;
    font-weight: 600;
}

.placeholder-mark {
    display: grid;
    place-items: center;
    width: 74px;
    height: 92px;
    border: 1px solid #d7e1f0;
    border-radius: 12px;
    background: #f6f9fe;
    color: #70809b;
    font-weight: 700;
    box-shadow: inset 0 -18px 0 rgba(36, 104, 242, .04);
}

.pager {
    position: absolute;
    left: 50%;
    bottom: 12px;
    z-index: 20;
    display: inline-flex;
    align-items: center;
    gap: 8px;
    min-height: 44px;
    width: max-content;
    max-width: calc(100% - 24px);
    padding: 0 13px;
    transform: translateX(-50%);
    background: #fff;
    border: 1px solid #e3eaf7;
    border-radius: 999px;
    box-shadow: 0 10px 22px rgba(52, 85, 145, .12);
    color: #34405a;
}

.pager button {
    width: 28px;
    height: 28px;
    border: 0;
    background: transparent;
    color: #8390a8;
}

.pager button:disabled {
    cursor: not-allowed;
    opacity: .4;
}

.page-input {
    width: 48px;
    height: 28px;
    border: 1px solid #d8e1f0;
    border-radius: 5px;
    text-align: center;
    color: #25304a;
}

.pager-divider {
    width: 1px;
    height: 22px;
    background: #dfe6f2;
}

.pager .preview-tool {
    color: #2b344f;
}

.result-pane {
    display: grid;
    grid-template-rows: 58px 52px minmax(0, 1fr);
    max-height: calc(100vh - 82px);
    overflow: hidden;
    background: #fff;
    border: 1px solid var(--line);
    border-radius: 12px;
    box-shadow: var(--shadow-soft);
}

.model-row {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 0 16px;
    background: #fff;
    border-bottom: 1px solid var(--line);
}

.model-label {
    color: #4d5b73;
    font-size: 13px;
    font-weight: 700;
    white-space: nowrap;
}

.model-field {
    position: relative;
    display: inline-flex;
    align-items: center;
    min-width: 260px;
}

.model-select {
    width: 100%;
    min-width: 260px;
    height: 36px;
    padding: 0 58px 0 12px;
    color: #174ea6;
    background: #f4f8ff;
    border: 1px solid #cbdaf5;
    border-radius: 9px;
    font-weight: 700;
}

.model-badge {
    position: absolute;
    right: 34px;
    top: 50%;
    transform: translateY(-50%);
    padding: 2px 6px;
    color: #0f7a55;
    background: #e9fbf2;
    border: 1px solid #c9f0dc;
    border-radius: 999px;
    font-size: 11px;
    font-weight: 800;
    line-height: 1.2;
    pointer-events: none;
}

.tabbar {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 0 16px;
    border-bottom: 1px solid var(--line);
    background: #fbfcff;
}

.tab {
    display: inline-flex;
    align-items: center;
    gap: 7px;
    height: 34px;
    padding: 0 13px;
    border: 1px solid transparent;
    border-radius: 999px;
    background: transparent;
    color: #24314f;
}

.tab.active {
    color: #1557d6;
    background: var(--blue-soft);
    border-color: #d8e5ff;
    font-weight: 700;
}

.toolbar {
    margin-left: auto;
    display: flex;
    align-items: center;
    gap: 4px;
}

.icon-button {
    display: grid;
    place-items: center;
    width: 32px;
    height: 32px;
    border: 1px solid transparent;
    border-radius: 8px;
    color: #2d3650;
    background: transparent;
}

.icon-button:hover {
    background: #fff;
    border-color: #dbe4f2;
}

.icon-button[hidden] {
    display: none;
}

.origin-image-toggle.inactive {
    color: #4658ff;
}

.result-body {
    min-height: 0;
    overflow: auto;
    padding: 20px 24px 34px;
    background: #fff;
}

.result-content {
    font-size: 15px;
    line-height: 1.86;
    word-break: break-word;
}

.result-content.plain-text {
    white-space: pre-wrap;
}

.result-content.coordinate-view {
    width: 100%;
    min-width: 0;
    line-height: normal;
}

.coordinate-stage {
    position: relative;
    margin: 10px auto 0;
    background: #fff;
    border: 1px solid #d9e0ea;
    box-shadow: 0 8px 24px rgba(22, 34, 51, .12);
    overflow: hidden;
}

.coordinate-canvas {
    position: absolute;
    top: 0;
    left: 0;
    transform-origin: 0 0;
    color: #101828;
    background: #fff;
    overflow: hidden;
    transform-origin: 0 0;
    user-select: text;
}

.parse-render-right .origin-image {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    opacity: .3;
    filter: grayscale(100%);
    pointer-events: none;
    user-select: none;
}

.parse-render-right img {
    vertical-align: middle;
    border-style: none;
}

.coordinate-text {
    position: absolute;
    overflow: hidden;
    transform-origin: 0 0;
    color: #101010;
    cursor: text;
    transition: background-color .12s ease, outline-color .12s ease;
}

.coordinate-text:hover,
.coordinate-text.active {
    background: rgba(61, 99, 255, .08);
    outline: 1px solid rgba(61, 99, 255, .45);
}

.coordinate-text-content {
    display: block;
    width: max-content;
    min-width: 100%;
    white-space: nowrap;
    transform-origin: 0 50%;
}

.coordinate-text-block .coordinate-text-content {
    width: 100%;
    min-width: 0;
    white-space: pre-wrap;
    overflow-wrap: anywhere;
}

.coordinate-text-vertical .coordinate-text-content {
    position: absolute;
    top: 0;
    left: 50%;
    width: max-content;
    height: 100%;
    min-width: 0;
    max-width: 100%;
    white-space: pre-wrap;
    overflow-wrap: normal;
    writing-mode: vertical-rl;
    text-orientation: upright;
    transform: translateX(-50%);
    transform-origin: 50% 50%;
}

.coordinate-text-table .coordinate-text-content {
    height: 100%;
    white-space: normal;
    overflow-wrap: anywhere;
}

.coordinate-text-table table {
    width: 100%;
    border-collapse: collapse;
    table-layout: fixed;
    font-size: inherit;
    line-height: 1.15;
}

.coordinate-text-table th,
.coordinate-text-table td {
    padding: 2px 3px;
    border: 1px solid #667085;
    vertical-align: top;
}

.coordinate-text-table th {
    font-weight: 700;
    background: #f2f4f7;
}

.markdown-body {
    color: #172033;
    line-height: 1.75;
}

.markdown-body h1,
.markdown-body h2,
.markdown-body h3,
.markdown-body h4 {
    margin: 1.1em 0 .55em;
    color: #111827;
    line-height: 1.35;
}

.markdown-body h1 {
    font-size: 24px;
}

.markdown-body h2 {
    font-size: 21px;
}

.markdown-body h3 {
    font-size: 18px;
}

.markdown-body p {
    margin: .65em 0;
}

.markdown-block {
    position: relative;
    display: block;
    margin: .25em -8px;
    padding: .25em 8px;
    border: 1px solid transparent;
    border-radius: 4px;
    transition: background .14s ease, border-color .14s ease;
}

.markdown-block:hover,
.markdown-block.active {
    border-color: rgba(61, 99, 255, .55);
    background: rgba(61, 99, 255, .055);
}

.markdown-block::before {
    content: attr(data-block-label);
    position: absolute;
    top: -18px;
    left: 6px;
    display: none;
    padding: 1px 6px;
    border-radius: 3px;
    color: #fff;
    background: var(--blue);
    font-size: 11px;
    line-height: 1.4;
    z-index: 1;
}

.markdown-block:hover::before,
.markdown-block.active::before {
    display: block;
}

.markdown-body ul,
.markdown-body ol {
    margin: .7em 0 .7em 1.4em;
    padding: 0;
}

.markdown-body blockquote {
    margin: .85em 0;
    padding: .2em 1em;
    color: #526071;
    border-left: 3px solid #cfd9ec;
    background: #f8fafc;
}

.markdown-body code {
    padding: 2px 5px;
    border-radius: 4px;
    background: #f1f5f9;
    font-family: Consolas, "Cascadia Mono", monospace;
    font-size: .92em;
}

.markdown-body pre {
    overflow: auto;
    margin: .9em 0;
    padding: 14px;
    border: 1px solid #e4ebf5;
    border-radius: 6px;
    background: #f8fafc;
}

.markdown-body pre code {
    padding: 0;
    background: transparent;
}

.markdown-body table {
    width: 100%;
    margin: .9em 0;
    border-collapse: collapse;
    font-size: 14px;
}

.markdown-body th,
.markdown-body td {
    padding: 8px 10px;
    border: 1px solid #dbe4f0;
    vertical-align: top;
}

.markdown-body th {
    background: #f1f5fb;
    font-weight: 700;
}

.markdown-body .MathJax_Display,
.markdown-body mjx-container[display="true"] {
    max-width: 100%;
    overflow-x: auto;
    overflow-y: hidden;
}

.markdown-body mjx-container {
    max-width: 100%;
}

.json-view {
    display: none;
    min-height: 100%;
    margin: 0;
    padding: 16px;
    color: #152033;
    background: #f8fafc;
    border: 1px solid #e4ebf5;
    border-radius: 6px;
    overflow: auto;
    white-space: pre-wrap;
    word-break: break-word;
    font-family: Consolas, "Cascadia Mono", monospace;
    font-size: 13px;
    line-height: 1.6;
}

.toast {
    position: fixed;
    right: 20px;
    bottom: 20px;
    max-width: min(420px, calc(100vw - 40px));
    padding: 12px 14px;
    color: #fff;
    background: #182235;
    border-radius: 6px;
    box-shadow: var(--shadow);
    opacity: 0;
    transform: translateY(10px);
    pointer-events: none;
    transition: opacity .18s ease, transform .18s ease;
    z-index: 20;
}

.toast.show {
    opacity: 1;
    transform: translateY(0);
}

.busy .dropzone,
.busy .model-select,
.busy .new-button {
    opacity: .72;
}

@media (max-width: 1180px) {
    .workspace {
        grid-template-columns: 220px 1fr;
        grid-template-rows: minmax(480px, 55vh) minmax(420px, auto);
    }

    .result-pane {
        grid-column: 1 / -1;
        border-top: 1px solid var(--line);
    }
}

@media (max-width: 760px) {
    .topbar {
        padding: 0 14px;
    }

    .brand span,
    .status-pill {
        display: none;
    }

    .license-actions {
        margin-left: auto;
        gap: 4px;
        padding: 3px;
    }

    .topbar-button {
        width: 32px;
        min-height: 30px;
        padding: 0;
        justify-content: center;
        overflow: hidden;
        color: transparent;
    }

    .topbar-button::before {
        flex: 0 0 auto;
    }

    .workspace {
        display: block;
    }

    .sidebar {
        min-height: auto;
        border-right: 0;
        border-bottom: 1px solid var(--line);
    }

    .preview-pane,
    .result-pane {
        min-height: 520px;
    }

    .model-row {
        align-items: flex-start;
        flex-direction: column;
        height: auto;
        padding: 10px 14px;
    }

    .model-select {
        min-width: 0;
        width: 100%;
    }

    .model-field {
        min-width: 0;
        width: 100%;
    }

    .result-pane {
        grid-template-rows: auto 50px minmax(0, 1fr);
    }
}
