/* 儒言工具整合 — 前台 */

.rth-hub {
    --rth-primary: #4f46e5;
    --rth-primary-soft: #eef2ff;
    --rth-text: #1f2937;
    --rth-muted: #6b7280;
    --rth-border: #e8ecf3;
    --rth-surface: #ffffff;
    --rth-shadow: 0 10px 30px rgba(15, 23, 42, 0.06);
    --rth-radius: 16px;
    margin: 0 0 24px;
}

.rth-hub__shell {
    padding: 24px 24px 28px;
    border: 1px solid var(--rth-border);
}

.rth-hub__header {
    display: flex;
    flex-wrap: wrap;
    align-items: flex-end;
    justify-content: space-between;
    gap: 16px 24px;
    margin-bottom: 20px;
}

.rth-hub__title {
    margin: 0;
    font-size: 28px;
    line-height: 1.2;
    font-weight: 700;
    color: var(--rth-text);
}

.rth-hub__subtitle {
    margin: 8px 0 0;
    font-size: 14px;
    color: var(--rth-muted);
}

.rth-hub__search-wrap {
    position: relative;
    flex: 1;
    min-width: 240px;
    max-width: 420px;
}

.rth-hub__search-icon {
    position: absolute;
    left: 14px;
    top: 50%;
    transform: translateY(-50%);
    color: var(--rth-muted);
    font-size: 16px;
    pointer-events: none;
}

.rth-hub__search {
    width: 100%;
    padding: 12px 14px 12px 40px;
    border: 1px solid var(--rth-border);
    border-radius: 12px;
    font-size: 14px;
    background: #f8fafc;
    color: var(--rth-text);
    transition: border-color 0.15s, box-shadow 0.15s, background 0.15s;
}

.rth-hub__search:focus {
    outline: none;
    border-color: var(--rth-primary);
    background: #fff;
    box-shadow: 0 0 0 3px rgba(79, 70, 229, 0.12);
}

.rth-hub__tabs {
    display: flex;
    flex-wrap: nowrap;
    gap: 8px;
    overflow-x: auto;
    padding-bottom: 4px;
    margin-bottom: 14px;
    scrollbar-width: thin;
}

.rth-hub__tab {
    flex: 0 0 auto;
    appearance: none;
    border: 1px solid var(--rth-border);
    background: #fff;
    color: var(--rth-muted);
    border-radius: 999px;
    padding: 8px 16px;
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.15s ease;
    white-space: nowrap;
}

.rth-hub__tab:hover {
    color: var(--rth-primary);
    border-color: #c7d2fe;
    background: #f8fafc;
}

.rth-hub__tab.is-active {
    color: var(--rth-primary);
    border-color: #c7d2fe;
    background: var(--rth-primary-soft);
    box-shadow: inset 0 0 0 1px rgba(79, 70, 229, 0.08);
}

.rth-hub__meta {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    margin-bottom: 16px;
    font-size: 13px;
    color: var(--rth-muted);
}

.rth-hub__grid {
    display: grid;
    grid-template-columns: repeat(var(--rth-cols, 4), minmax(0, 1fr));
    gap: 14px;
}

.rth-hub__card {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    gap: 12px;
    padding: 16px;
    border: 1px solid var(--rth-border);
    border-radius: 14px;
    background: #fff;
    text-decoration: none;
    color: inherit;
    cursor: pointer;
    transition: transform 0.15s ease, box-shadow 0.15s ease, border-color 0.15s ease;
    min-height: 132px;
}

.rth-hub__card:hover {
    transform: translateY(-2px);
    border-color: #c7d2fe;
    box-shadow: 0 12px 28px rgba(79, 70, 229, 0.1);
}

.rth-hub__card-head {
    display: flex;
    align-items: center;
    gap: 12px;
    width: 100%;
}

.rth-hub__icon {
    width: 44px;
    height: 44px;
    border-radius: 12px;
    object-fit: cover;
    background: #f3f4f6;
    border: 1px solid var(--rth-border);
    flex-shrink: 0;
}

.rth-hub__icon--empty {
    display: flex;
    align-items: center;
    justify-content: center;
    color: #a5b4fc;
    font-size: 18px;
    background: linear-gradient(135deg, #eef2ff, #f8fafc);
}

.rth-hub__card-title {
    font-size: 15px;
    font-weight: 700;
    line-height: 1.35;
    color: var(--rth-text);
}

.rth-hub__card-desc {
    font-size: 13px;
    line-height: 1.5;
    color: var(--rth-muted);
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

.rth-hub__card-foot {
    display: flex;
    align-items: center;
    justify-content: space-between;
    width: 100%;
    gap: 8px;
}

.rth-hub__badge {
    display: inline-flex;
    align-items: center;
    padding: 3px 8px;
    border-radius: 999px;
    font-size: 11px;
    font-weight: 700;
    line-height: 1.2;
}

.rth-hub__badge--featured {
    background: var(--rth-primary-soft);
    color: var(--rth-primary);
}

.rth-hub__badge--mode {
    background: #f3f4f6;
    color: var(--rth-muted);
}

.rth-hub__loading,
.rth-hub__empty,
.rth-hub__error {
    grid-column: 1 / -1;
    padding: 48px 20px;
    text-align: center;
    color: var(--rth-muted);
    border: 1px dashed var(--rth-border);
    border-radius: 14px;
    background: #f8fafc;
}

.rth-hub__error {
    color: #dc2626;
    background: #fef2f2;
    border-color: #fecaca;
}

/* Modal */
.rth-hub-modal {
    position: fixed;
    inset: 0;
    z-index: 100000;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
}

.rth-hub-modal[hidden] {
    display: none !important;
}

.rth-hub-modal__backdrop {
    position: absolute;
    inset: 0;
    background: rgba(15, 23, 42, 0.5);
    backdrop-filter: blur(4px);
}

.rth-hub-modal__panel {
    position: relative;
    width: min(1080px, 100%);
    max-height: 90vh;
    background: #fff;
    border-radius: 16px;
    overflow: hidden;
    display: flex;
    flex-direction: column;
    box-shadow: 0 24px 48px rgba(15, 23, 42, 0.2);
}

.rth-hub-modal__panel.is-fullscreen {
    width: 100%;
    max-height: 100vh;
    height: 100vh;
    border-radius: 0;
}

.rth-hub-modal__header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 14px 16px;
    border-bottom: 1px solid var(--rth-border);
    background: #fafbff;
}

.rth-hub-modal__title-wrap {
    display: flex;
    align-items: center;
    gap: 12px;
    min-width: 0;
}

.rth-hub__icon-svg {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 6px;
    box-sizing: border-box;
    background: linear-gradient(135deg, #eef2ff, #f8fafc);
    overflow: hidden;
}

.rth-hub__icon-svg svg {
    width: 100% !important;
    height: 100% !important;
    max-width: 100%;
    max-height: 100%;
    display: block !important;
    overflow: visible !important;
    vertical-align: initial !important;
    fill: unset;
}

.rth-hub-modal__icon {
    width: 36px;
    height: 36px;
    border-radius: 10px;
    border: 1px solid var(--rth-border);
    flex-shrink: 0;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
    background: #f8fafc;
}

.rth-hub-modal__icon img,
.rth-hub-modal__icon svg {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
}

.rth-hub-modal__title {
    margin: 0;
    font-size: 16px;
    font-weight: 700;
    color: var(--rth-text);
}

.rth-hub-modal__url {
    margin: 2px 0 0;
    font-size: 12px;
    color: var(--rth-muted);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 420px;
}

.rth-hub-modal__actions {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    flex-shrink: 0;
}

.rth-hub-modal__body {
    flex: 1;
    min-height: 420px;
    background: #f8fafc;
}

.rth-hub-modal__iframe {
    width: 100%;
    height: 100%;
    min-height: 420px;
    border: 0;
    background: #fff;
}

.rth-hub-btn {
    appearance: none;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 8px 12px;
    border-radius: 10px;
    border: 1px solid var(--rth-border);
    background: #fff;
    color: var(--rth-text);
    font-size: 13px;
    font-weight: 600;
    text-decoration: none;
    cursor: pointer;
    transition: background 0.15s, border-color 0.15s;
}

.rth-hub-btn--ghost:hover {
    background: #f3f4f6;
    border-color: #d1d5db;
}

@media (max-width: 1100px) {
    .rth-hub__grid {
        grid-template-columns: repeat(3, minmax(0, 1fr));
    }
}

.rth-hub-api-modal {
    position: fixed;
    inset: 0;
    z-index: 100001;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
}

.rth-hub-api-modal[hidden] {
    display: none !important;
}

.rth-hub-api-modal__panel {
    position: relative;
    width: min(960px, 100%);
    max-height: 92vh;
    background: #fff;
    border-radius: 16px;
    overflow: hidden;
    display: flex;
    flex-direction: column;
    box-shadow: 0 24px 48px rgba(15, 23, 42, 0.2);
}

.rth-hub-api-modal__panel.is-fullscreen {
    width: 100%;
    max-height: 100vh;
    height: 100vh;
    border-radius: 0;
}

.rth-hub-api-modal__header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 14px 16px;
    border-bottom: 1px solid var(--rth-border);
    background: #fafbff;
}

.rth-hub-api-modal .rth-hub-modal__url {
    white-space: normal;
    overflow: visible;
    text-overflow: initial;
    max-width: none;
    line-height: 1.5;
}

.rth-hub-api-modal__body {
    padding: 16px;
    overflow: auto;
}

.rth-hub-tool-panel {
    display: flex;
    flex-direction: column;
    gap: 16px;
}

.rth-hub-tool-actions {
    display: flex;
    justify-content: flex-end;
}

.rth-hub-btn--run {
    min-width: 132px;
    padding: 10px 20px;
    font-size: 14px;
    font-weight: 600;
}

.rth-hub-btn--primary {
    background: var(--rth-primary);
    border-color: var(--rth-primary);
    color: #fff;
}

.rth-hub-btn--primary:hover {
    filter: brightness(1.05);
}

.rth-hub-btn--primary:disabled {
    opacity: 0.7;
    cursor: not-allowed;
}

.rth-hub-api-fields {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 12px;
    margin-bottom: 14px;
}

.rth-hub-api-field {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.rth-hub-api-field--full {
    grid-column: 1 / -1;
}

.rth-hub-api-field__label {
    font-size: 13px;
    font-weight: 600;
    color: var(--rth-text);
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 6px;
}

.rth-hub-api-required {
    color: #dc2626;
}

.rth-hub-api-field__input,
.rth-hub-api-field__textarea,
.rth-hub-api-field__input--select {
    width: 100%;
    padding: 10px 12px;
    border: 1px solid var(--rth-border);
    border-radius: 10px;
    font-size: 13px;
    background: #fff;
}

.rth-hub-upload {
    position: relative;
    display: block;
    width: 100%;
}

/* Bootstrap 会强制 input[type=file] 为 display:block，必须显式隐藏 */
.rth-hub .rth-hub-upload__input {
    position: absolute !important;
    width: 1px !important;
    height: 1px !important;
    padding: 0 !important;
    margin: -1px !important;
    overflow: hidden !important;
    clip: rect(0, 0, 0, 0) !important;
    clip-path: inset(50%) !important;
    white-space: nowrap !important;
    border: 0 !important;
    opacity: 0 !important;
    pointer-events: none !important;
    display: block !important;
}

.rth-hub-api-field--file {
    gap: 8px;
}

.rth-hub-upload__zone {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 8px;
    width: 100%;
    box-sizing: border-box;
    min-height: 128px;
    padding: 20px 16px;
    border: 1.5px dashed #cbd5e1;
    border-radius: 14px;
    background: linear-gradient(180deg, #fafbff 0%, #f8fafc 100%);
    cursor: pointer;
    user-select: none;
    transition: border-color 0.22s ease, background 0.22s ease, box-shadow 0.22s ease, transform 0.18s ease;
    text-align: center;
}

.rth-hub-upload__zone:hover,
.rth-hub-upload__zone:focus-visible {
    outline: none;
    border-color: var(--rth-primary, #2563eb);
    background: #f5f8ff;
    box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.08);
}

.rth-hub-upload__zone:active {
    transform: scale(0.995);
}

.rth-hub-upload.is-dragover .rth-hub-upload__zone {
    border-color: var(--rth-primary, #2563eb);
    border-style: solid;
    background: #eef4ff;
    box-shadow: inset 0 0 0 1px rgba(37, 99, 235, 0.12), 0 0 0 3px rgba(37, 99, 235, 0.1);
    transform: scale(1.01);
}

.rth-hub-upload.is-disabled .rth-hub-upload__zone {
    cursor: not-allowed;
    opacity: 0.7;
}

.rth-hub-upload__icon {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 44px;
    height: 44px;
    border-radius: 12px;
    background: var(--rth-primary-soft, #eff6ff);
    color: var(--rth-primary, #2563eb);
}

.rth-hub-upload__icon svg {
    display: block;
}

.rth-hub-upload__title {
    margin: 0;
    font-size: 14px;
    font-weight: 600;
    color: var(--rth-text);
}

.rth-hub-upload__hint {
    margin: 0;
    font-size: 12px;
    color: var(--rth-muted);
}

.rth-hub-upload__preview {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    width: 100%;
    box-sizing: border-box;
    padding: 12px 14px;
    border: 1px solid var(--rth-border);
    border-radius: 12px;
    background: #f8fafc;
}

.rth-hub-upload__preview[hidden] {
    display: none !important;
}

.rth-hub-upload__file {
    display: flex;
    flex-direction: column;
    gap: 2px;
    min-width: 0;
}

.rth-hub-upload__name {
    font-size: 13px;
    font-weight: 600;
    color: var(--rth-text);
    word-break: break-all;
}

.rth-hub-upload__size {
    font-size: 12px;
    color: var(--rth-muted);
}

.rth-hub-upload__clear {
    flex-shrink: 0;
    border: 0;
    background: transparent;
    color: #dc2626;
    font-size: 12px;
    font-weight: 600;
    cursor: pointer;
    padding: 6px 10px;
    border-radius: 8px;
    transition: background 0.2s ease, transform 0.15s ease;
}

.rth-hub-upload__clear:hover {
    background: #fef2f2;
}

.rth-hub-upload__clear:active {
    transform: scale(0.97);
}

.rth-hub-api-bool {
    display: inline-flex;
    align-items: center;
    min-height: 42px;
}

.rth-hub-api-bool input {
    width: 18px;
    height: 18px;
    accent-color: var(--rth-primary, #2563eb);
}

.rth-hub-api-field--file .rth-hub-api-field__label,
.rth-hub-api-field--json .rth-hub-api-field__label,
.rth-hub-api-field--text .rth-hub-api-field__label {
    width: 100%;
}

.rth-hub-api-field__input[readonly],
.rth-hub-api-field__textarea[readonly] {
    background: #f8fafc;
    color: var(--rth-muted);
}

.rth-hub-api-field__textarea {
    min-height: 140px;
    font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
    resize: vertical;
}

.rth-hub-api-empty {
    margin: 0 0 14px;
    color: var(--rth-muted);
    font-size: 13px;
}

.rth-hub-tool-result {
    border: 1px solid var(--rth-border);
    border-radius: 14px;
    background: #fafbff;
    padding: 14px;
}

.rth-hub-tool-result[hidden] {
    display: none !important;
}

.rth-hub-tool-result__head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    margin-bottom: 10px;
}

.rth-hub-tool-result__title {
    margin: 0;
    font-size: 14px;
    font-weight: 700;
    color: var(--rth-text);
}

.rth-hub-tool-result__meta {
    font-size: 12px;
    color: var(--rth-muted);
}

.rth-hub-tool-result__body {
    margin: 0;
    min-height: 140px;
    max-height: 360px;
    overflow: auto;
    padding: 0;
    border-radius: 10px;
    background: #fff;
    border: 1px solid var(--rth-border);
    color: var(--rth-text);
    font-size: 13px;
    line-height: 1.6;
}

.rth-hub-tool-result__body--raw {
    padding: 12px;
    font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
    white-space: pre-wrap;
    word-break: break-word;
}

.rth-hub-tool-result__body--formatted {
    padding: 12px;
}

.rth-result-view {
    display: flex;
    flex-direction: column;
    gap: 14px;
}

.rth-result-banner {
    padding: 10px 14px;
    border-radius: 10px;
    font-size: 14px;
    font-weight: 600;
}

.rth-result-banner--ok {
    background: #ecfdf5;
    color: #047857;
    border: 1px solid #a7f3d0;
}

.rth-result-banner--err {
    background: #fef2f2;
    color: #b91c1c;
    border: 1px solid #fecaca;
}

.rth-result-section__title {
    margin: 0 0 10px;
    font-size: 13px;
    font-weight: 700;
    color: var(--rth-text);
}

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

.rth-result-item {
    margin: 0;
    min-width: 0;
}

.rth-result-item dt {
    margin: 0 0 4px;
    font-size: 12px;
    color: var(--rth-muted);
    font-weight: 500;
}

.rth-result-item dd {
    margin: 0;
    font-size: 13px;
    color: var(--rth-text);
    word-break: break-word;
}

.rth-result-empty {
    color: var(--rth-muted);
}

.rth-result-bool.is-yes {
    color: #047857;
    font-weight: 600;
}

.rth-result-bool.is-no {
    color: #b45309;
    font-weight: 600;
}

.rth-result-badge {
    display: inline-flex;
    padding: 2px 10px;
    border-radius: 999px;
    font-size: 12px;
    font-weight: 600;
}

.rth-result-badge--ok {
    background: #ecfdf5;
    color: #047857;
}

.rth-result-badge--bad {
    background: #fef2f2;
    color: #b91c1c;
}

.rth-result-badge--neutral {
    background: #f1f5f9;
    color: #475569;
}

.rth-result-list {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
}

.rth-result-tag {
    display: inline-flex;
    padding: 2px 8px;
    border-radius: 8px;
    background: #f1f5f9;
    font-size: 12px;
}

.rth-result-perms {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}

.rth-result-perm {
    display: inline-flex;
    padding: 4px 10px;
    border-radius: 999px;
    font-size: 12px;
    font-weight: 500;
}

.rth-result-perm.is-on {
    background: #ecfdf5;
    color: #047857;
    border: 1px solid #a7f3d0;
}

.rth-result-perm.is-off {
    background: #f8fafc;
    color: #94a3b8;
    border: 1px solid #e2e8f0;
}

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

@media (max-width: 900px) {
    .rth-hub-api-fields {
        grid-template-columns: 1fr;
    }

    .rth-hub-tool-actions {
        justify-content: stretch;
    }

    .rth-hub-btn--run {
        width: 100%;
    }

    .rth-hub__shell {
        padding: 18px 16px 22px;
    }

    .rth-hub__title {
        font-size: 24px;
    }

    .rth-hub__grid {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }

    .rth-hub-modal__header {
        flex-direction: column;
        align-items: stretch;
    }

    .rth-hub-modal__actions {
        justify-content: flex-end;
    }
}

@media (max-width: 520px) {
    .rth-hub__grid {
        grid-template-columns: 1fr;
    }

    .rth-hub__search-wrap {
        max-width: none;
    }
}
