:root {
    --bg-1: #f6f7fb;
    --bg-2: #f6f7fb;
    --bg-3: #f6f7fb;
    --card: rgba(255, 255, 255, 1);
    --ink: #171c2e;
    --muted: #6b7488;
    --accent: #4f46e5;
    --accent-strong: #4338ca;
    --accent-soft: #6366f1;
    --accent-warm: #f59e0b;
    --border: #e8eaf1;
    --surface: #fbfbfe;
    --shadow: 0 10px 30px rgba(23, 28, 46, 0.06);
}

* {
    box-sizing: border-box;
}

html,
body {
    margin: 0;
    min-height: 100%;
}

body {
    font-family: "PingFang SC", "Microsoft YaHei", "Segoe UI Variable Display", "Helvetica Neue", sans-serif;
    color: var(--ink);
    background: #f6f7fb;
    position: relative;
    display: flex;
    justify-content: center;
    align-items: stretch;
    padding: 12px;
}

body::before {
    content: none;
}

#toastContainer {
    position: fixed;
    top: 20px;
    right: 20px;
    z-index: 9999;
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.toast {
    display: flex;
    align-items: center;
    gap: 12px;
    min-width: 240px;
    max-width: 430px;
    padding: 14px 18px;
    border-radius: 14px;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.18);
    font-size: 14px;
    font-weight: 600;
    opacity: 0;
    transform: translateX(360px);
    transition: all 0.28s ease;
}

.toast.show {
    opacity: 1;
    transform: translateX(0);
}

.toast-success {
    background: linear-gradient(135deg, #2e9d58 0%, #228347 100%);
    color: #fff;
}

.toast-error {
    background: linear-gradient(135deg, #d74e4e 0%, #bc2e2e 100%);
    color: #fff;
}

.toast-warning {
    background: linear-gradient(135deg, #db8a33 0%, #bf6a14 100%);
    color: #fff;
}

.toast-icon {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 3px 8px;
    border-radius: 999px;
    background: rgba(255, 255, 255, 0.3);
    font-size: 12px;
    font-weight: 800;
    letter-spacing: 0.5px;
    flex-shrink: 0;
}

.toast-message {
    flex: 1;
    word-break: break-word;
}

.shell {
    width: min(1120px, 100%);
    min-height: calc(100vh - 24px);
    max-height: calc(100vh - 24px);
    overflow: auto;
    background: var(--card);
    border-radius: 22px;
    padding: 18px 14px 20px;
    box-shadow: var(--shadow);
    border: 1px solid rgba(255, 255, 255, 0.55);
    backdrop-filter: blur(8px);
    animation: floatIn 0.5s ease;
    margin: 0 auto;
    display: flex;
    flex-direction: column;
}

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

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

.badge {
    background: linear-gradient(135deg, var(--accent) 0%, var(--accent-soft) 100%);
    color: #fff;
    font-weight: 800;
    font-size: 12px;
    padding: 8px 12px;
    border-radius: 999px;
    letter-spacing: 1px;
    box-shadow: 0 8px 18px rgba(79, 70, 229, 0.3);
}

h1 {
    margin: 0;
    font-size: clamp(22px, 3.8vw, 30px);
    letter-spacing: 0.2px;
}

.tabs {
    display: inline-flex;
    flex-wrap: wrap;
    gap: 8px;
    background: rgba(255, 255, 255, 0.75);
    border-radius: 999px;
    padding: 6px;
    margin-bottom: 12px;
    width: fit-content;
    border: 1px solid var(--border);
}

.tab {
    border: none;
    background: transparent;
    padding: 9px 18px;
    border-radius: 999px;
    font-weight: 700;
    color: var(--muted);
    cursor: pointer;
    transition: all 0.2s ease;
}

.tab.active {
    background: linear-gradient(135deg, #ffffff 0%, #f5fbff 100%);
    color: var(--accent-strong);
    box-shadow: 0 8px 18px rgba(79, 70, 229, 0.16);
}

.panel {
    display: none;
    background: linear-gradient(165deg, rgba(255, 255, 255, 0.94) 0%, rgba(246, 252, 255, 0.93) 100%);
    border-radius: 18px;
    padding: 20px;
    border: 1px solid rgba(199, 218, 229, 0.8);
}

.panel.active {
    display: block;
}

.panel.stretch.active {
    display: flex;
    flex-direction: column;
    flex: 1;
    min-height: 0;
}

.field {
    margin-bottom: 14px;
}

.panel.stretch .field {
    flex: 1;
    display: flex;
    flex-direction: column;
}

label {
    display: block;
    font-weight: 700;
    margin-bottom: 8px;
    color: var(--ink);
}

textarea {
    width: 100%;
    border: 1px solid #bfd3df;
    border-radius: 13px;
    padding: 12px 14px;
    font-size: 15px;
    font-family: inherit;
    resize: vertical;
    background: #fefefe;
    transition: border-color 0.18s ease, box-shadow 0.18s ease, background 0.18s ease;
}

.panel.stretch textarea {
    flex: 1;
    resize: none;
    min-height: 180px;
}

textarea:focus {
    outline: none;
    border-color: var(--accent-soft);
    box-shadow: 0 0 0 4px rgba(15, 116, 150, 0.14);
    background: #fff;
}

input[type="file"] {
    width: 100%;
    padding: 12px;
    border-radius: 12px;
    border: 1px dashed #b8ccd8;
    background: #fbfdff;
    font-size: 14px;
    color: var(--muted);
}

.actions {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    align-items: center;
    margin-bottom: 10px;
}

.actions-left {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
}

.actions-right {
    margin-left: auto;
    display: flex;
    gap: 10px;
}

.btn {
    border: 1px solid #dde5ec;
    border-radius: 11px;
    padding: 10px 18px;
    font-weight: 600;
    cursor: pointer;
    background: #f2f5f9;
    color: var(--ink);
    transition: background 0.16s ease, border-color 0.16s ease, color 0.16s ease;
    text-decoration: none;
    display: inline-flex;
    align-items: center;
    justify-content: center;
}

.btn:hover {
    background: #e8edf4;
    border-color: #cdd8e2;
}

.btn.primary {
    background: #eef0ff;
    color: var(--accent);
    border-color: #dfe3ff;
}

.btn.primary:hover {
    background: #e2e6ff;
    border-color: #ccd2ff;
}

.btn.ghost {
    background: transparent;
    border: 1px solid #dde5ec;
    color: var(--muted);
}

.btn.ghost:hover {
    background: #f2f5f9;
}

.btn.copy {
    background: #e8f8ee;
    color: #15803d;
    border-color: #c9ecd4;
}

.btn.copy:hover {
    background: #d9f2e2;
    border-color: #b5e3c3;
}

.qr-tabs,
.json-tabs {
    display: inline-flex;
    gap: 8px;
    background: rgba(255, 255, 255, 0.72);
    border-radius: 999px;
    padding: 6px;
    margin-bottom: 8px;
    width: fit-content;
    border: 1px solid var(--border);
}

.qr-tab,
.json-tab {
    border: none;
    background: transparent;
    padding: 8px 18px;
    border-radius: 999px;
    font-weight: 700;
    color: var(--muted);
    cursor: pointer;
    transition: all 0.2s ease;
}

.qr-tab.active,
.json-tab.active {
    background: #fff;
    color: var(--accent-strong);
    box-shadow: 0 8px 18px rgba(79, 70, 229, 0.16);
}

.qr-grid {
    display: grid;
    gap: 16px;
    grid-template-columns: 1fr;
}

.qr-card,
.json-card {
    display: none;
    border: 1px solid var(--border);
    border-radius: 14px;
    padding: 12px;
    background: var(--surface);
}

.qr-card.active,
.json-card.active {
    display: block;
}

.qr-card h3 {
    margin: 0 0 8px;
    font-size: 16px;
}

.qr-preview {
    height: 160px;
    border-radius: 12px;
    border: 1px dashed #bdd1dc;
    background: linear-gradient(135deg, #ffffff 0%, #f2f9fe 100%);
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
}

.qr-preview img {
    max-width: 100%;
    max-height: 100%;
    display: block;
}

.qr-placeholder {
    color: var(--muted);
    font-size: 13px;
}

.panel[data-panel="json"] textarea {
    min-height: 160px;
}

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

.json-diff-result {
    border: 1px solid #bfd3df;
    border-radius: 12px;
    overflow: hidden;
    background: #fbfdff;
}

.json-diff-empty {
    color: var(--muted);
    font-size: 13px;
    padding: 14px;
}

.json-diff-header {
    display: flex;
    gap: 12px;
    padding: 10px 12px;
    background: #edf5fa;
    border-bottom: 1px solid #d5e3eb;
    font-size: 13px;
    color: #274050;
    font-weight: 700;
}

.json-diff-body {
    overflow: auto;
    max-height: 420px;
}

.json-diff-row {
    display: grid;
    grid-template-columns: 52px minmax(280px, 1fr) 52px minmax(280px, 1fr);
}

.json-diff-row + .json-diff-row {
    border-top: 1px solid #e8f1f6;
}

.json-diff-line-no {
    font-family: "Cascadia Code", "Consolas", "JetBrains Mono", "Courier New", monospace;
    font-size: 12px;
    color: #5d7280;
    background: #f3f8fb;
    text-align: right;
    padding: 8px 8px 8px 4px;
    border-right: 1px solid #e8f1f6;
}

.json-diff-line {
    font-family: "Cascadia Code", "Consolas", "JetBrains Mono", "Courier New", monospace;
    font-size: 13px;
    line-height: 1.45;
    white-space: pre;
    overflow-x: auto;
    padding: 8px 10px;
}

.json-diff-equal {
    background: #fff;
}

.json-diff-added {
    background: #e8f7ec;
    color: #0f5b29;
}

.json-diff-removed {
    background: #feecec;
    color: #7b1c1c;
}

.json-diff-changed {
    background: #fff4df;
    color: #78420f;
}

.json-diff-blank {
    background: #f5f9fc;
}

.json-diff-text-copy {
    position: absolute;
    left: -9999px;
    width: 1px;
    height: 1px;
    opacity: 0;
    pointer-events: none;
}

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

    .json-diff-row {
        grid-template-columns: 44px minmax(220px, 1fr) 44px minmax(220px, 1fr);
    }
}

@media (max-width: 720px) {
    body {
        padding: 8px;
    }

    .shell {
        padding: 14px;
        min-height: calc(100vh - 16px);
        max-height: calc(100vh - 16px);
        border-radius: 18px;
    }

    .header {
        flex-direction: column;
        align-items: flex-start;
    }

    .actions {
        align-items: stretch;
    }

    .actions-right {
        margin-left: 0;
        width: 100%;
    }

    .actions-right .btn,
    .actions-right a {
        width: 100%;
        justify-content: center;
    }

    .qr-preview {
        height: 180px;
    }
}

@keyframes floatIn {
    from {
        opacity: 0;
        transform: translateY(12px) scale(0.99);
    }

    to {
        opacity: 1;
        transform: translateY(0) scale(1);
    }
}
