/* ============================================================
   roxy-gw-v2 前端共享样式
   响应式：桌面宽表格 / 窄屏(≤720px)自动转卡片；深浅色自适应
   ============================================================ */

:root {
    --bg: #f5f6f8;
    --surface: #ffffff;
    --surface-2: #f0f2f5;
    --border: #e2e5ea;
    --text: #1c1e21;
    --text-2: #65676b;
    --primary: #2563eb;
    --primary-hover: #1d4ed8;
    --danger: #dc2626;
    --danger-hover: #b91c1c;
    --ok: #16a34a;
    --warn: #d97706;
    --info: #2563eb;
    --shadow: 0 1px 3px rgba(0, 0, 0, .08);
    --radius: 10px;
    --tap: 44px; /* 触摸目标最小尺寸 */
}
:root[data-theme="dark"] {
    --bg: #17181c;
    --surface: #212328;
    --surface-2: #2a2d34;
    --border: #34373f;
    --text: #e6e8eb;
    --text-2: #9aa0a8;
    --primary: #3b82f6;
    --primary-hover: #60a5fa;
    --danger: #ef4444;
    --danger-hover: #f87171;
    --ok: #22c55e;
    --warn: #f59e0b;
    --shadow: 0 1px 3px rgba(0, 0, 0, .4);
}
@media (prefers-color-scheme: dark) {
    :root:not([data-theme="light"]) {
        --bg: #17181c; --surface: #212328; --surface-2: #2a2d34; --border: #34373f;
        --text: #e6e8eb; --text-2: #9aa0a8; --primary: #3b82f6; --primary-hover: #60a5fa;
        --danger: #ef4444; --danger-hover: #f87171; --ok: #22c55e; --warn: #f59e0b;
        --shadow: 0 1px 3px rgba(0, 0, 0, .4);
    }
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC",
        "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
    background: var(--bg);
    color: var(--text);
    font-size: 15px;
    line-height: 1.5;
    -webkit-text-size-adjust: 100%;
}
a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ── 顶栏 ── */
.topbar {
    position: sticky; top: 0; z-index: 30;
    display: flex; align-items: center; gap: 12px;
    padding: 10px 16px;
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    box-shadow: var(--shadow);
}
.topbar h1 { font-size: 17px; margin: 0; font-weight: 700; white-space: nowrap; }
.topbar .spacer { flex: 1; }
.topbar .who { color: var(--text-2); font-size: 13px; max-width: 40vw; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ── 导航 tab（桌面顶部横排 / 手机底部固定栏）── */
.tabs {
    display: flex; gap: 4px;
    background: var(--surface); border-bottom: 1px solid var(--border);
    padding: 0 8px; overflow-x: auto; position: sticky; top: 55px; z-index: 20;
}
.tabs button {
    flex: 0 0 auto;
    background: none; border: none; border-bottom: 2px solid transparent;
    color: var(--text-2); padding: 12px 14px; font-size: 14px; cursor: pointer;
    min-height: var(--tap); white-space: nowrap;
}
.tabs button.active { color: var(--primary); border-bottom-color: var(--primary); font-weight: 600; }

/* ── 主体 ── */
.wrap { max-width: 1200px; margin: 0 auto; padding: 16px; }
.page { display: none; }
.page.active { display: block; }

/* ── 统计卡 ── */
.stats { display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 10px; margin-bottom: 16px; }
.stat { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 12px 14px; box-shadow: var(--shadow); }
.stat .k { color: var(--text-2); font-size: 12px; }
.stat .v { font-size: 22px; font-weight: 700; margin-top: 2px; }

/* ── 余额芯片 ── */
.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip { background: var(--surface-2); border: 1px solid var(--border); border-radius: 999px; padding: 6px 12px; font-size: 13px; display: inline-flex; gap: 6px; align-items: center; }
.chip b { color: var(--primary); }

/* ── 卡片/面板 ── */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px; box-shadow: var(--shadow); margin-bottom: 16px; }
.card h2 { margin: 0 0 12px; font-size: 16px; }

/* ── 表单 ── */
.field { margin-bottom: 12px; }
.field > label { display: block; font-size: 13px; color: var(--text-2); margin-bottom: 5px; }
input, select, textarea, button { font: inherit; }
input[type=text], input[type=password], input[type=number], input[type=search], select, textarea {
    width: 100%; padding: 10px 12px; min-height: var(--tap);
    background: var(--surface); color: var(--text);
    border: 1px solid var(--border); border-radius: 8px;
}
textarea { min-height: 88px; resize: vertical; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--primary); outline-offset: -1px; border-color: var(--primary); }
.row { display: flex; flex-wrap: wrap; gap: 12px; }
.row > .field { flex: 1 1 180px; }
.hint { font-size: 12px; color: var(--warn); margin-top: 4px; }
.muted { color: var(--text-2); }

/* ── 按钮 ── */
.btn {
    display: inline-flex; align-items: center; justify-content: center; gap: 6px;
    min-height: var(--tap); padding: 10px 16px;
    background: var(--primary); color: #fff; border: none; border-radius: 8px;
    cursor: pointer; font-size: 14px; font-weight: 600;
}
.btn:hover { background: var(--primary-hover); }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn.secondary { background: var(--surface-2); color: var(--text); border: 1px solid var(--border); }
.btn.danger { background: var(--danger); }
.btn.danger:hover { background: var(--danger-hover); }
.btn.sm { min-height: 34px; padding: 6px 10px; font-size: 13px; font-weight: 500; }
.btn.icon { background: none; color: var(--text); border: 1px solid var(--border); min-height: 38px; padding: 8px 10px; }

/* ── 表格（桌面）── */
.table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; border-radius: var(--radius); }
table { width: 100%; border-collapse: collapse; background: var(--surface); }
thead th { text-align: left; font-size: 12px; color: var(--text-2); font-weight: 600; padding: 10px 12px; border-bottom: 2px solid var(--border); white-space: nowrap; }
tbody td { padding: 10px 12px; border-bottom: 1px solid var(--border); font-size: 13px; vertical-align: middle; }
tbody tr:hover { background: var(--surface-2); }
tbody tr.clickable { cursor: pointer; }

/* ── 开关（代理启用等）── */
.switch { position: relative; display: inline-block; width: 46px; height: 26px; vertical-align: middle; }
.switch input { position: absolute; inset: 0; width: 100%; height: 100%; margin: 0; opacity: 0; cursor: pointer; z-index: 1; }
.switch .slider { position: absolute; inset: 0; background: var(--surface-2); border: 1px solid var(--border); border-radius: 999px; transition: background .2s, border-color .2s; }
.switch .slider::before { content: ""; position: absolute; width: 20px; height: 20px; left: 2px; top: 2px; background: #fff; border-radius: 50%; box-shadow: 0 1px 2px rgba(0,0,0,.3); transition: transform .2s; }
.switch input:checked + .slider { background: var(--primary); border-color: var(--primary); }
.switch input:checked + .slider::before { transform: translateX(20px); }

/* 代理表：下拉按内容自适应，行内保存高亮 */
[data-page="proxy"] td select { width: auto; min-width: 120px; max-width: 100%; }
@keyframes savedFlash { from { background: rgba(22,163,74,.20); } to { background: transparent; } }
tbody tr.saved-flash { animation: savedFlash .8s ease-out; }

/* ── 状态徽章 ── */
.badge { display: inline-block; padding: 2px 8px; border-radius: 999px; font-size: 12px; font-weight: 600; }
.badge.ok { background: rgba(22,163,74,.15); color: var(--ok); }
.badge.err { background: rgba(220,38,38,.15); color: var(--danger); }
.badge.info { background: rgba(37,99,235,.15); color: var(--info); }
.badge.warn { background: rgba(217,119,6,.15); color: var(--warn); }

/* ── 分页 ── */
.pager { display: flex; flex-wrap: wrap; gap: 6px; justify-content: center; margin-top: 14px; }
.pager button { min-width: 40px; min-height: 40px; background: var(--surface); border: 1px solid var(--border); color: var(--text); border-radius: 8px; cursor: pointer; }
.pager button.active { background: var(--primary); color: #fff; border-color: var(--primary); }
.pager button:disabled { opacity: .4; cursor: not-allowed; }

/* ── 上传拖拽区 ── */
.drop { border: 2px dashed var(--border); border-radius: 8px; padding: 14px; text-align: center; color: var(--text-2); cursor: pointer; font-size: 13px; }
.drop.over { border-color: var(--primary); background: var(--surface-2); }
.thumbs { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 8px; }
.thumb { position: relative; width: 64px; height: 64px; border-radius: 6px; overflow: hidden; border: 1px solid var(--border); background: var(--surface-2); display: flex; align-items: center; justify-content: center; font-size: 11px; }
.thumb img { width: 100%; height: 100%; object-fit: cover; }
.thumb .x { position: absolute; top: 1px; right: 1px; width: 18px; height: 18px; line-height: 16px; text-align: center; background: rgba(0,0,0,.6); color: #fff; border-radius: 50%; cursor: pointer; font-size: 12px; }

/* ── 登录页 ── */
.login { max-width: 360px; margin: 12vh auto; }

/* ── 模态框 ── */
.modal-bg { position: fixed; inset: 0; background: rgba(0,0,0,.5); display: none; align-items: flex-start; justify-content: center; z-index: 50; padding: 16px; overflow-y: auto; }
.modal-bg.open { display: flex; }
.modal { background: var(--surface); border-radius: var(--radius); width: 100%; max-width: 560px; margin: 6vh 0; box-shadow: 0 10px 40px rgba(0,0,0,.3); }
.modal header { display: flex; align-items: center; padding: 14px 16px; border-bottom: 1px solid var(--border); }
.modal header h3 { margin: 0; font-size: 16px; flex: 1; }
.modal .body { padding: 16px; }
.modal .foot { padding: 12px 16px; border-top: 1px solid var(--border); display: flex; gap: 8px; justify-content: flex-end; }
.close-x { background: none; border: none; font-size: 22px; cursor: pointer; color: var(--text-2); line-height: 1; }

/* ── 详情网格 ── */
.kv { display: grid; grid-template-columns: max-content 1fr; gap: 6px 14px; font-size: 13px; }
.kv dt { color: var(--text-2); }
.kv dd { margin: 0; word-break: break-word; }
.media-grid { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 8px; }
.media-grid img, .media-grid video, .media-grid audio { max-width: 140px; max-height: 140px; border-radius: 6px; border: 1px solid var(--border); }
/* 参考图可点开看原图 */
.media-grid img { cursor: zoom-in; object-fit: cover; transition: transform .15s ease, box-shadow .15s ease; }
.media-grid img:hover { transform: scale(1.03); box-shadow: 0 4px 16px rgba(0,0,0,.28); }

/* ── lightbox（点参考图放大看原图）── */
#lightbox { position: fixed; inset: 0; background: rgba(0,0,0,.86); z-index: 200; display: none;
    align-items: center; justify-content: center; padding: 24px; cursor: zoom-out;
    opacity: 0; transition: opacity .18s ease; }
#lightbox.open { display: flex; opacity: 1; }
#lightbox img { max-width: 100%; max-height: 100%; object-fit: contain; border-radius: 4px;
    box-shadow: 0 8px 40px rgba(0,0,0,.5); transform: scale(.97); transition: transform .18s ease; }
#lightbox.open img { transform: scale(1); }
#lightbox .lb-close { position: absolute; top: 14px; right: 18px; width: 40px; height: 40px;
    border: 0; border-radius: 50%; background: rgba(255,255,255,.14); color: #fff; font-size: 22px;
    line-height: 1; cursor: pointer; display: flex; align-items: center; justify-content: center; }
#lightbox .lb-close:hover { background: rgba(255,255,255,.26); }
#lightbox .lb-tip { position: absolute; bottom: 16px; left: 50%; transform: translateX(-50%);
    color: rgba(255,255,255,.66); font-size: 12px; pointer-events: none; max-width: 90vw;
    overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
@media (max-width: 600px) { #lightbox { padding: 10px; } #lightbox .lb-tip { display: none; } }
@media (prefers-reduced-motion: reduce) {
    #lightbox, #lightbox img, .media-grid img { transition: none; }
    .media-grid img:hover { transform: none; }
}

/* ── toast ── */
#toast { position: fixed; bottom: 78px; left: 50%; transform: translateX(-50%); background: var(--text); color: var(--bg); padding: 10px 18px; border-radius: 999px; font-size: 14px; z-index: 100; opacity: 0; transition: opacity .2s; pointer-events: none; max-width: 90vw; }
#toast.show { opacity: .95; }

.hidden { display: none !important; }
.grow { flex: 1; }
.right { text-align: right; }
.nowrap { white-space: nowrap; }
.mono { font-family: ui-monospace, "SF Mono", Menlo, monospace; font-size: 12px; }
.linklike { color: var(--primary); cursor: pointer; }

/* 结果预览 */
.result-box { margin-top: 12px; }
.result-box video, .result-box img { max-width: 100%; border-radius: 8px; }
.progress { height: 8px; background: var(--surface-2); border-radius: 999px; overflow: hidden; margin: 8px 0; }
.progress > i { display: block; height: 100%; background: var(--primary); width: 0; transition: width .3s; }

/* 工具条 */
.toolbar { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin-bottom: 12px; }
.toolbar > * { margin: 0; }
.toolbar select, .toolbar input { width: auto; min-width: 130px; flex: 0 1 auto; }

/* ============================================================
   响应式断点：≤720px 表格转卡片、tab 移到底部
   ============================================================ */
@media (max-width: 720px) {
    body { padding-bottom: 64px; } /* 给底部 tab 让位 */
    .wrap { padding: 12px; }
    .topbar h1 { font-size: 15px; }
    .topbar .who { max-width: 30vw; }

    /* tab 固定到底部 */
    .tabs {
        position: fixed; bottom: 0; top: auto; left: 0; right: 0;
        border-top: 1px solid var(--border); border-bottom: none;
        justify-content: space-around; padding: 0;
        box-shadow: 0 -1px 3px rgba(0,0,0,.1);
    }
    .tabs button { flex: 1; font-size: 11px; padding: 8px 2px; border-bottom: none; border-top: 2px solid transparent; }
    .tabs button.active { border-top-color: var(--primary); border-bottom-color: transparent; }

    /* 表格 → 卡片 */
    .table-wrap { overflow: visible; }
    table, thead, tbody, tr, td { display: block; width: 100%; }
    thead { position: absolute; left: -9999px; } /* 隐藏表头 */
    tbody tr {
        background: var(--surface); border: 1px solid var(--border);
        border-radius: var(--radius); margin-bottom: 10px; padding: 6px 0; box-shadow: var(--shadow);
    }
    tbody td {
        display: flex; justify-content: space-between; align-items: center; gap: 12px;
        padding: 8px 14px; border-bottom: 1px solid var(--border); text-align: right;
    }
    tbody tr td:last-child { border-bottom: none; }
    tbody td::before {
        content: attr(data-label); color: var(--text-2); font-size: 12px;
        font-weight: 600; text-align: left; flex: 0 0 auto;
    }
    tbody td.actions { justify-content: flex-end; flex-wrap: wrap; }

    .toolbar select, .toolbar input { flex: 1 1 100%; min-width: 0; width: 100%; }
    .stats { grid-template-columns: repeat(2, 1fr); }
    .modal { margin: 2vh 0; }
}

@media (max-width: 420px) {
    .stats { grid-template-columns: 1fr; }
}
