/* ============================================================
   角色卡市场（character.html）样式
   ------------------------------------------------------------
   配色与主站一致（深底 #1a1c23 / 面板 #262933 / 金 #e6c78a），
   沿用站内已有的 .icon-btn / body.light-theme 规则，不重复定义。
   ============================================================ */

:root {
    --mk-bg: #1a1c23;
    --mk-panel: #262933;
    --mk-panel2: #2d303a;
    --mk-line: #3b3f4b;
    --mk-text: #eee;
    --mk-muted: #a9acb5;
    --mk-gold: var(--accent-gold, #e6c78a);
}

body.market-page {
    margin: 0;
    background: var(--mk-bg);
    color: var(--mk-text);
    font-family: Arial, "Microsoft Yahei", sans-serif;
    -webkit-text-size-adjust: 100%;
    /* 主站 style.css 把 body 定成「满屏 flex 居中 + overflow:hidden」，
       那是为单屏聊天界面服务的。市场页是长列表，必须把这几项改回来，
       否则整个页面既滚不动、连滚动条都不会出现。 */
    display: block;
    align-items: initial;
    justify-content: initial;
    min-height: 100dvh;
    overflow-x: hidden;
    overflow-y: auto;
    padding: 0;
}

/* html 也要解除主站的固定高度限制，让文档高度随内容增长 */
html:has(body.market-page) {
    height: auto;
    overflow-y: auto;
    overflow-x: hidden;
}

/* 顶栏是 sticky，父级不能再有 overflow:hidden —— 主站的 .app-container
   规则不作用于市场页，但市场页自己的 .market-main 也不能裁剪。 */
.market-main { overflow: visible; }

/* ---------- 顶栏 ---------- */
.market-topbar {
    position: sticky;
    top: 0;
    z-index: 20;
    display: flex;
    align-items: center;
    gap: 14px;
    padding: 12px 18px;
    background: rgba(38, 41, 51, .94);
    backdrop-filter: blur(10px);
    border-bottom: 1px solid var(--mk-line);
}
.market-brand {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    color: var(--mk-gold);
    font-size: 1.15rem;
    font-weight: bold;
    text-decoration: none;
    white-space: nowrap;
}
.market-brand span {
    font-size: .72em;
    font-weight: 500;
    color: var(--mk-muted);
    border-left: 1px solid var(--mk-line);
    padding-left: 8px;
}
.market-nav {
    display: flex;
    gap: 6px;
    flex-wrap: wrap;
}
.market-nav a {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 5px 10px;
    border: 1px solid rgba(230, 199, 138, .35);
    border-radius: 999px;
    color: var(--mk-muted);
    font-size: .78rem;
    text-decoration: none;
}
.market-nav a:hover { color: var(--mk-gold); border-color: var(--mk-gold); }
.market-topbar .icon-btn { margin-left: auto; }

/* ---------- 主体 ---------- */
.market-main {
    max-width: 1220px;
    margin: 0 auto;
    padding: 18px 18px 60px;
}
.market-tabs {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
    margin-bottom: 14px;
}
.market-tab {
    display: inline-flex;
    align-items: center;
    gap: 7px;
    padding: 9px 16px;
    border: 1px solid var(--mk-line);
    border-radius: 999px;
    background: var(--mk-panel);
    color: var(--mk-muted);
    font: inherit;
    font-size: .88rem;
    cursor: pointer;
}
.market-tab:hover { color: var(--mk-text); border-color: #565b69; }
.market-tab.active { background: rgba(230, 199, 138, .14); border-color: var(--mk-gold); color: var(--mk-gold); }
.market-tab em {
    font-style: normal;
    font-size: .74rem;
    background: var(--mk-panel2);
    border-radius: 999px;
    padding: 1px 7px;
}
.market-tip {
    display: flex;
    align-items: flex-start;
    gap: 8px;
    margin: 0 0 16px;
    padding: 10px 13px;
    border: 1px dashed #4d5361;
    border-radius: 10px;
    background: #232733;
    color: var(--mk-muted);
    font-size: .8rem;
    line-height: 1.7;
}
.market-tip i { color: var(--mk-gold); font-size: 1rem; line-height: 1.5; }

/* ---------- 工具栏 ---------- */
.market-toolbar {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-wrap: wrap;
    margin-bottom: 14px;
}
.market-search {
    position: relative;
    flex: 1 1 240px;
    min-width: 180px;
    display: flex;
    align-items: center;
}
.market-search i { position: absolute; left: 11px; color: var(--mk-muted); pointer-events: none; font-size: .95rem; }
.market-search input {
    width: 100%;
    padding: 9px 11px 9px 34px;
    border-radius: 999px;
    background: #20232c;
    border: 1px solid #494e5c;
    color: var(--mk-text);
    font: inherit;
    font-size: .86rem;
    outline: none;
}
.market-search input:focus { border-color: var(--mk-gold); }
.market-toolbar select {
    padding: 9px 11px;
    border-radius: 9px;
    background: #20232c;
    border: 1px solid #494e5c;
    color: var(--mk-text);
    font: inherit;
    font-size: .84rem;
    outline: none;
    cursor: pointer;
}
.market-toolbar select:focus { border-color: var(--mk-gold); }
.market-ghost {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 9px 13px;
    border-radius: 9px;
    border: 1px solid #4a4f5d;
    background: #252934;
    color: #d8dae2;
    font: inherit;
    font-size: .83rem;
    cursor: pointer;
    white-space: nowrap;
}
.market-ghost:hover { border-color: var(--mk-gold); color: var(--mk-gold); }
.market-ghost.danger:hover { border-color: #f0706f; color: #f0706f; }
.market-ghost[disabled] { opacity: .45; cursor: not-allowed; }
.market-hint { color: var(--mk-muted); font-size: .78rem; }

/* ---------- 批量操作栏 ---------- */
.market-batchbar {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-wrap: wrap;
    margin: 0 0 14px;
    padding: 10px 12px;
    border: 1px solid rgba(230, 199, 138, .4);
    border-radius: 10px;
    background: rgba(230, 199, 138, .07);
}
.market-batchbar[hidden] { display: none; }
.market-batch-count { font-size: .84rem; color: var(--mk-muted); }
.market-batch-count b { color: var(--mk-gold); }

/* ---------- 卡片网格 ---------- */
.market-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(228px, 1fr));
    gap: 14px;
}
.market-card {
    position: relative;
    display: flex;
    gap: 12px;
    padding: 13px;
    min-height: 104px;
    background: var(--mk-panel);
    border: 1px solid var(--mk-line);
    border-radius: 13px;
    cursor: pointer;
    transition: border-color .15s ease, transform .15s ease, background .15s ease;
}
.market-card:hover { border-color: #5a6070; transform: translateY(-2px); }
.market-card.selected { border-color: var(--mk-gold); background: rgba(230, 199, 138, .09); }
.market-card.installed { cursor: default; }
.market-card img.mk-avatar {
    width: 54px;
    height: 54px;
    flex: 0 0 auto;
    border-radius: 50%;
    object-fit: cover;
    background: #3a3d47;
}
.market-card .mk-body { min-width: 0; flex: 1; display: flex; flex-direction: column; gap: 5px; }
.market-card .mk-name {
    font-size: .95rem;
    font-weight: bold;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.market-card .mk-sub {
    color: var(--mk-muted);
    font-size: .74rem;
    line-height: 1.5;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
    min-height: 2.2em;
}
.market-tags { display: flex; flex-wrap: wrap; gap: 4px; }
.market-tag {
    font-size: .68rem;
    padding: 1px 7px;
    border-radius: 999px;
    border: 1px solid #4b5060;
    color: var(--mk-muted);
    white-space: nowrap;
    max-width: 100%;
    overflow: hidden;
    text-overflow: ellipsis;
}
.market-tag.gold { border-color: rgba(230, 199, 138, .5); color: var(--mk-gold); }
.market-tag.warn { border-color: rgba(240, 168, 120, .5); color: #f0a878; }
.market-card .mk-actions { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 2px; }
.market-card .mk-actions button {
    border: 1px solid #4a4f5d;
    background: #2b2f3a;
    color: #d8dae2;
    border-radius: 8px;
    padding: 5px 9px;
    font: inherit;
    font-size: .76rem;
    cursor: pointer;
}
.market-card .mk-actions button:hover { border-color: var(--mk-gold); color: var(--mk-gold); }
.market-card .mk-actions button.primary { border-color: rgba(230, 199, 138, .55); color: var(--mk-gold); }
.market-card .mk-actions button.danger:hover { border-color: #f0706f; color: #f0706f; }
.market-card .mk-check {
    position: absolute;
    right: 10px;
    top: 10px;
    width: 22px;
    height: 22px;
    border-radius: 6px;
    border: 1px solid #5a6070;
    background: #20232c;
    display: grid;
    place-items: center;
    font-size: .8rem;
    color: transparent;
    /* 平时不显示：每张卡右上角都挂一个空方块，看起来像「控件坏了」。
       鼠标悬停 / 键盘聚焦 / 已选中 / 当前有选中项时才露出来。 */
    opacity: 0;
    transition: opacity .14s ease, background .14s ease, border-color .14s ease;
}
.market-card:hover .mk-check,
.market-card:focus-within .mk-check,
.market-card.selected .mk-check,
body.mk-has-selection .market-card .mk-check { opacity: 1; }
.market-card.selected .mk-check { background: var(--mk-gold); border-color: var(--mk-gold); color: #24262f; }

.market-empty, .market-loading {
    grid-column: 1 / -1;
    padding: 46px 10px;
    text-align: center;
    color: var(--mk-muted);
    font-size: .88rem;
    line-height: 1.9;
}
.market-section-title {
    grid-column: 1 / -1;
    margin: 10px 0 0;
    padding-bottom: 6px;
    border-bottom: 1px solid var(--mk-line);
    color: var(--mk-gold);
    font-size: .92rem;
    font-weight: bold;
    display: flex;
    align-items: center;
    gap: 7px;
}
.market-section-title small { color: var(--mk-muted); font-weight: normal; font-size: .74rem; }

/* ---------- 分组管理 ---------- */
.market-group-list { display: flex; flex-direction: column; gap: 9px; }
.market-group-row {
    display: flex;
    align-items: center;
    gap: 10px;
    flex-wrap: wrap;
    padding: 12px 14px;
    background: var(--mk-panel);
    border: 1px solid var(--mk-line);
    border-radius: 11px;
}
.market-group-row .mk-group-name { flex: 1; min-width: 140px; display: flex; align-items: center; gap: 8px; font-size: .92rem; }
.market-group-row .mk-group-name i { color: var(--mk-gold); }
.market-group-row .mk-group-count { color: var(--mk-muted); font-size: .76rem; }
.market-group-row .mk-group-acts { display: flex; gap: 6px; flex-wrap: wrap; }

/* ---------- 弹窗 ---------- */
.market-modal {
    position: fixed;
    inset: 0;
    z-index: 90;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 16px;
    background: rgba(0, 0, 0, .64);
}
.market-modal[hidden] { display: none; }
.market-dialog {
    position: relative;
    width: min(680px, 100%);
    max-height: 88vh;
    overflow: auto;
    padding: 22px;
    background: #292d38;
    border: 1px solid #515664;
    border-radius: 14px;
}
.market-dialog h2 { margin: 0 30px 16px 0; color: var(--mk-gold); font-size: 1.1rem; }
.market-dialog-close {
    position: absolute;
    right: 12px;
    top: 12px;
    width: 32px;
    height: 32px;
    border: 0;
    border-radius: 8px;
    background: transparent;
    color: #ddd;
    font-size: 1.2rem;
    cursor: pointer;
}
.market-dialog-close:hover { background: #363b47; color: var(--mk-gold); }
.market-dialog-body { font-size: .86rem; line-height: 1.8; color: #e3e4e8; }
.market-field { margin-bottom: 14px; }
.market-field label { display: block; margin-bottom: 6px; color: var(--mk-muted); font-size: .8rem; }
.market-field input, .market-field select, .market-field textarea {
    width: 100%;
    padding: 9px 11px;
    background: #20232c;
    border: 1px solid #565b68;
    border-radius: 8px;
    color: var(--mk-text);
    font: inherit;
    font-size: .86rem;
}
.market-field textarea { min-height: 150px; resize: vertical; line-height: 1.7; }
.market-dialog-actions { display: flex; justify-content: flex-end; gap: 10px; flex-wrap: wrap; margin-top: 16px; }
.market-dialog-actions .market-ghost.primary { background: var(--mk-gold); border-color: var(--mk-gold); color: #26272f; font-weight: bold; }
.market-kv { display: grid; grid-template-columns: 88px 1fr; gap: 6px 10px; margin: 12px 0; }
.market-kv dt { color: var(--mk-muted); font-size: .8rem; }
.market-kv dd { margin: 0; font-size: .84rem; word-break: break-word; }
.market-preview {
    max-height: 240px;
    overflow: auto;
    padding: 12px;
    background: #20232c;
    border: 1px solid #454a57;
    border-radius: 9px;
    white-space: pre-wrap;
    font-size: .8rem;
    line-height: 1.75;
    color: #d9dbe2;
}

/* ---------- 轻提示 ---------- */
#market-toast {
    position: fixed;
    left: 50%;
    bottom: 26px;
    transform: translateX(-50%) translateY(10px);
    z-index: 120;
    max-width: min(520px, calc(100vw - 32px));
    padding: 10px 18px;
    background: #3a3f4b;
    border: 1px solid var(--mk-gold);
    border-radius: 999px;
    color: #fff;
    font-size: .84rem;
    opacity: 0;
    pointer-events: none;
    transition: opacity .2s ease, transform .2s ease;
}
#market-toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

/* ---------- 手机 / 平板 ---------- */
@media (max-width: 620px) {
    .market-topbar { padding: 10px 12px; gap: 8px; }
    .market-brand span { display: none; }
    .market-main { padding: 14px 12px 50px; }
    .market-grid { grid-template-columns: repeat(auto-fill, minmax(100%, 1fr)); gap: 10px; }
    .market-toolbar select { flex: 1 1 auto; }
    .market-tab { padding: 8px 12px; font-size: .82rem; }
    .market-kv { grid-template-columns: 1fr; gap: 2px 0; }
    .market-dialog { padding: 18px 15px; }
}

/* ---------- 浅色主题（跟随主站的 body.light-theme） ---------- */
body.light-theme.market-page { background: #f3f1ec; color: #2b2f3a; }
body.light-theme .market-topbar { background: rgba(255, 253, 249, .95); border-color: #ddd4c4; }
body.light-theme .market-card,
body.light-theme .market-tab,
body.light-theme .market-group-row { background: #fffdf9; border-color: #ddd4c4; color: #2b2f3a; }
body.light-theme .market-search input,
body.light-theme .market-toolbar select,
body.light-theme .market-field input,
body.light-theme .market-field select,
body.light-theme .market-preview { background: #fff; border-color: #d3c6b1; color: #2b2f3a; }
body.light-theme .market-ghost { background: #fffdf9; border-color: #d3c6b1; color: #4a4e59; }
body.light-theme .market-tip { background: #fff9ee; border-color: #e0d6c4; color: #6b6a68; }
body.light-theme .market-dialog { background: #fffdf9; border-color: #ddd4c4; }
