/* =========================================================================
 * 开发者工具箱 全局样式
 * 设计原则:简洁工具风、无外部依赖、深浅色主题、跨平台兼容
 * 兼容性说明:仅使用 Flex/Grid/自定义属性等广泛支持的特性,不使用 :has() 等
 * ========================================================================= */

/* ---------- 主题变量 ---------- */
:root {
    color-scheme: light;
    --bg: #f5f6f8;
    --card: #ffffff;
    --fg: #1f2328;
    --muted: #6a737d;
    --border: #d8dee4;
    --border-soft: #e7ebef;
    --accent: #0969da;
    --accent-weak: rgba(9, 105, 218, 0.1);
    --ok: #1a7f37;
    --err: #cf222e;
    --warn: #9a6700;
    --add-bg: #e6ffec;
    --add-fg: #116329;
    --del-bg: #ffebe9;
    --del-fg: #82071e;
    --shadow: 0 1px 2px rgba(31, 35, 40, 0.06);
    --radius: 10px;
    --mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, "Liberation Mono", monospace;
    --sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue",
        "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "Noto Sans CJK SC", sans-serif;
}

/* 显式深色模式 */
:root[data-theme="dark"] {
    color-scheme: dark;
    --bg: #0d1117;
    --card: #161b22;
    --fg: #e6edf3;
    --muted: #8b949e;
    --border: #30363d;
    --border-soft: #21262d;
    --accent: #4493f8;
    --accent-weak: rgba(68, 147, 248, 0.16);
    --ok: #3fb950;
    --err: #f85149;
    --warn: #d29922;
    --add-bg: rgba(46, 160, 67, 0.18);
    --add-fg: #7ee787;
    --del-bg: rgba(248, 81, 73, 0.16);
    --del-fg: #ff7b72;
    --shadow: 0 1px 3px rgba(0, 0, 0, 0.4);
}

/* 跟随系统深色(未手动选择浅色时生效) */
@media (prefers-color-scheme: dark) {
    :root:not([data-theme="light"]) {
        color-scheme: dark;
        --bg: #0d1117;
        --card: #161b22;
        --fg: #e6edf3;
        --muted: #8b949e;
        --border: #30363d;
        --border-soft: #21262d;
        --accent: #4493f8;
        --accent-weak: rgba(68, 147, 248, 0.16);
        --ok: #3fb950;
        --err: #f85149;
        --warn: #d29922;
        --add-bg: rgba(46, 160, 67, 0.18);
        --add-fg: #7ee787;
        --del-bg: rgba(248, 81, 73, 0.16);
        --del-fg: #ff7b72;
        --shadow: 0 1px 3px rgba(0, 0, 0, 0.4);
    }
}

/* ---------- 基础 ---------- */
* { box-sizing: border-box; }

html {
    -webkit-text-size-adjust: 100%;
    text-size-adjust: 100%;
}

body {
    margin: 0;
    background: var(--bg);
    color: var(--fg);
    font: 14px/1.6 var(--sans);
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

h1, h2, h3 { line-height: 1.3; }

::selection { background: var(--accent-weak); }

:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: 1px;
}

/* ---------- 顶栏 ---------- */
.topbar {
    position: sticky;
    top: 0;
    z-index: 20;
    display: flex;
    align-items: center;
    gap: 10px;
    height: 48px;
    padding: 0 16px;
    background: var(--card);
    border-bottom: 1px solid var(--border);
}

.topbar .brand {
    display: flex;
    align-items: center;
    gap: 8px;
    font-weight: 600;
    color: var(--fg);
    white-space: nowrap;
}

.topbar .brand:hover { text-decoration: none; }

.topbar .brand svg { flex: none; }

.topbar .crumb {
    color: var(--muted);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.topbar .spacer { flex: 1; }

.topbar .icon-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 32px;
    height: 32px;
    border: 1px solid var(--border);
    border-radius: 8px;
    background: transparent;
    color: var(--muted);
    cursor: pointer;
    flex: none;
}

.topbar .icon-btn:hover {
    color: var(--accent);
    border-color: var(--accent);
}

/* ---------- 主体容器 ---------- */
.container {
    width: 100%;
    max-width: 1080px;
    margin: 0 auto;
    padding: 20px 16px 40px;
    flex: 1;
}

.page-title {
    margin: 0 0 4px;
    font-size: 20px;
    font-weight: 700;
}

.page-desc {
    margin: 0 0 18px;
    color: var(--muted);
    font-size: 13px;
}

/* ---------- 首页宫格 ---------- */
.search-wrap {
    position: relative;
    margin-bottom: 18px;
}

.search-wrap svg {
    position: absolute;
    left: 12px;
    top: 50%;
    transform: translateY(-50%);
    color: var(--muted);
    pointer-events: none;
}

#toolSearch {
    width: 100%;
    height: 40px;
    padding: 0 12px 0 38px;
    font-size: 14px;
    color: var(--fg);
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: 10px;
}

#toolSearch:focus {
    outline: none;
    border-color: var(--accent);
    box-shadow: 0 0 0 3px var(--accent-weak);
}

.tool-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(168px, 1fr));
    gap: 12px;
}

.tool-card {
    display: flex;
    flex-direction: column;
    gap: 6px;
    padding: 14px;
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    color: var(--fg);
    box-shadow: var(--shadow);
    transition: border-color 0.15s, transform 0.15s;
}

.tool-card:hover {
    text-decoration: none;
    border-color: var(--accent);
    transform: translateY(-2px);
}

.tool-card .t-icon {
    width: 34px;
    height: 34px;
    padding: 7px;
    border-radius: 8px;
    background: var(--accent-weak);
    color: var(--accent);
}

.tool-card .t-name {
    font-weight: 600;
    font-size: 14px;
}

.tool-card .t-desc {
    color: var(--muted);
    font-size: 12px;
    line-height: 1.5;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

.cat-title {
    margin: 22px 0 10px;
    font-size: 13px;
    font-weight: 600;
    color: var(--muted);
    text-transform: none;
    letter-spacing: 0.02em;
}

.cat-title:first-child { margin-top: 0; }

.no-result {
    padding: 40px 0;
    text-align: center;
    color: var(--muted);
}

/* ---------- 表单控件 ---------- */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    height: 32px;
    padding: 0 14px;
    font-size: 13px;
    font-weight: 500;
    font-family: inherit;
    color: var(--fg);
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: 8px;
    cursor: pointer;
    white-space: nowrap;
    transition: background 0.15s, border-color 0.15s, color 0.15s;
}

.btn:hover { border-color: var(--accent); color: var(--accent); }
.btn:active { transform: translateY(1px); }

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

.btn-primary:hover {
    color: #fff;
    background: var(--accent);
    opacity: 0.88;
}

.btn-danger { color: var(--err); }
.btn-danger:hover { border-color: var(--err); color: var(--err); }

.btn-sm { height: 28px; padding: 0 10px; font-size: 12px; }

select.btn,
input.field,
textarea.ta {
    font-family: inherit;
    font-size: 13px;
    color: var(--fg);
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: 8px;
}

input.field {
    height: 32px;
    padding: 0 10px;
}

select.btn { padding: 0 8px; }

textarea.ta {
    width: 100%;
    min-height: 150px;
    padding: 10px 12px;
    font-family: var(--mono);
    font-size: 13px;
    line-height: 1.6;
    resize: vertical;
    white-space: pre;
    overflow-wrap: normal;
    overflow-x: auto;
    tab-size: 4;
}

textarea.ta:focus,
input.field:focus,
select.btn:focus {
    outline: none;
    border-color: var(--accent);
    box-shadow: 0 0 0 3px var(--accent-weak);
}

textarea.ta.err-state { border-color: var(--err); }

input[type="color"].field {
    padding: 2px;
    width: 46px;
    height: 32px;
    cursor: pointer;
}

label.inline {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    font-size: 13px;
    color: var(--muted);
    cursor: pointer;
    white-space: nowrap;
}

label.inline input[type="checkbox"] { accent-color: var(--accent); }

/* ---------- 布局辅助 ---------- */
.row {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 8px;
}

.row.tight { gap: 5px; }

.grid2 {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 12px;
    align-items: start;
}

.grid2 > .col { min-width: 0; }

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

.col-label {
    margin: 0 0 6px;
    font-size: 12px;
    font-weight: 600;
    color: var(--muted);
}

/* ---------- 输出区 ---------- */
.out {
    margin: 0;
    padding: 10px 12px;
    font-family: var(--mono);
    font-size: 13px;
    line-height: 1.6;
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: 8px;
    white-space: pre-wrap;
    word-break: break-all;
    max-height: 420px;
    overflow: auto;
}

.out.err { color: var(--err); }
.out.ok { color: var(--ok); }

/* 键值结果行(哈希、时间戳等) */
.kv {
    display: flex;
    align-items: flex-start;
    gap: 8px;
    padding: 8px 0;
    border-bottom: 1px dashed var(--border-soft);
}

.kv:last-child { border-bottom: none; }

.kv .k {
    flex: none;
    width: 110px;
    color: var(--muted);
    font-size: 12px;
    padding-top: 1px;
}

.kv .v {
    flex: 1;
    min-width: 0;
    font-family: var(--mono);
    font-size: 13px;
    word-break: break-all;
}

.kv .copy-link {
    flex: none;
    font-size: 12px;
    color: var(--accent);
    background: none;
    border: none;
    cursor: pointer;
    padding: 0 2px;
}

@media (max-width: 560px) {
    .kv { flex-direction: column; gap: 2px; }
    .kv .k { width: auto; }
    .kv .copy-link { order: -1; align-self: flex-start; }
}

/* ---------- 标签与徽标 ---------- */
.tag {
    display: inline-block;
    padding: 1px 8px;
    font-size: 11px;
    font-weight: 500;
    border-radius: 999px;
    background: var(--accent-weak);
    color: var(--accent);
    white-space: nowrap;
}

.tag.ok { background: transparent; color: var(--ok); border: 1px solid var(--ok); }
.tag.err { background: transparent; color: var(--err); border: 1px solid var(--err); }
.tag.warn { background: transparent; color: var(--warn); border: 1px solid var(--warn); }

/* ---------- 正则高亮 ---------- */
.hl-match {
    background: var(--accent-weak);
    border-radius: 3px;
    box-shadow: 0 0 0 1px var(--accent);
}

.hl-g1 { background: rgba(63, 185, 80, 0.25); border-radius: 3px; }
.hl-g2 { background: rgba(210, 153, 34, 0.25); border-radius: 3px; }
.hl-g3 { background: rgba(248, 81, 73, 0.25); border-radius: 3px; }

/* ---------- 文本对比 ---------- */
.diff {
    font-family: var(--mono);
    font-size: 13px;
    line-height: 1.7;
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: 8px;
    overflow: auto;
    max-height: 480px;
}

.diff-line {
    padding: 0 10px;
    white-space: pre-wrap;
    word-break: break-all;
}

.diff-line.add { background: var(--add-bg); color: var(--add-fg); }
.diff-line.del { background: var(--del-bg); color: var(--del-fg); }
.diff-line.same { color: var(--muted); }
.diff-line .sign { user-select: none; margin-right: 8px; opacity: 0.8; }

/* ---------- 表格 ---------- */
.table-wrap {
    overflow-x: auto;
    border: 1px solid var(--border);
    border-radius: 8px;
    background: var(--card);
    max-height: 480px;
    overflow-y: auto;
}

table.tb {
    width: 100%;
    border-collapse: collapse;
    font-size: 13px;
}

table.tb th,
table.tb td {
    padding: 7px 10px;
    border-bottom: 1px solid var(--border-soft);
    text-align: left;
    white-space: nowrap;
}

table.tb td.wrap { white-space: normal; word-break: break-all; }

table.tb th {
    position: sticky;
    top: 0;
    background: var(--card);
    color: var(--muted);
    font-weight: 600;
    box-shadow: inset 0 -1px 0 var(--border);
}

table.tb tr:last-child td { border-bottom: none; }

/* ---------- 二维码 ---------- */
.qr-box {
    display: inline-block;
    padding: 14px;
    background: #fff;
    border: 1px solid var(--border);
    border-radius: 8px;
    line-height: 0;
}

.qr-box svg { display: block; }

/* ---------- 图片工具 ---------- */
.img-preview {
    max-width: 100%;
    max-height: 300px;
    border: 1px solid var(--border);
    border-radius: 8px;
    background:
        conic-gradient(var(--border-soft) 0 25%, transparent 0 50%, var(--border-soft) 0 75%, transparent 0) 0 0/16px 16px;
}

.drop-zone {
    padding: 26px 16px;
    text-align: center;
    color: var(--muted);
    background: var(--card);
    border: 1.5px dashed var(--border);
    border-radius: var(--radius);
    cursor: pointer;
    transition: border-color 0.15s, background 0.15s;
}

.drop-zone:hover,
.drop-zone.dragover {
    border-color: var(--accent);
    background: var(--accent-weak);
}

.result-item {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 10px;
    padding: 10px;
    border: 1px solid var(--border);
    border-radius: 8px;
    background: var(--card);
}

.result-item img {
    max-width: 120px;
    max-height: 90px;
    border-radius: 4px;
    background:
        conic-gradient(var(--border-soft) 0 25%, transparent 0 50%, var(--border-soft) 0 75%, transparent 0) 0 0/12px 12px;
}

.result-item .info {
    flex: 1;
    min-width: 160px;
    font-size: 12px;
    color: var(--muted);
    line-height: 1.7;
}

/* ---------- 提示条 ---------- */
.toast {
    position: fixed;
    left: 50%;
    bottom: 28px;
    transform: translateX(-50%) translateY(8px);
    z-index: 100;
    padding: 8px 18px;
    background: var(--fg);
    color: var(--bg);
    font-size: 13px;
    border-radius: 999px;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.2s, transform 0.2s;
}

.toast.show {
    opacity: 1;
    transform: translateX(-50%) translateY(0);
}

/* ---------- 页脚 ---------- */
.site-footer {
    padding: 14px 16px;
    text-align: center;
    color: var(--muted);
    font-size: 12px;
    border-top: 1px solid var(--border);
}

/* ---------- 小屏适配 ---------- */
@media (max-width: 480px) {
    .tool-grid { grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); }
    .container { padding: 14px 12px 32px; }
    .page-title { font-size: 18px; }
}

/* ---------- 打印 ---------- */
@media print {
    .topbar, .site-footer, .toast { display: none !important; }
    body { background: #fff; color: #000; }
}
