/* ==========================================================================
   支付网关 · 共享组件库（ui.css）
   --------------------------------------------------------------------------
   所有页面（后台 / 收银台 / 安装向导 / 演示页 / 查单页）共用这一份，
   保证按钮、输入框、卡片、标签、提示的外观完全一致。
   自托管、无 CDN、无构建步骤。
   ========================================================================== */

/* ================= 设计令牌 ================= */
:root {
    color-scheme: light;

    --bg:        #f7f8fa;
    --surface:   #ffffff;
    --surface-2: #f4f4f5;
    --surface-3: #ebebee;
    --border:    #e4e4e7;
    --border-2:  #f1f1f3;
    --ring:      rgba(37, 99, 235, .16);

    --text:      #18181b;
    --text-2:    #52525b;
    --text-3:    #a1a1aa;
    --text-inv:  #ffffff;

    --accent:      #2563eb;
    --accent-2:    #1d4ed8;
    --accent-soft: #eff6ff;

    --ok: #16a34a;   --ok-soft: #f0fdf4;
    --warn: #d97706; --warn-soft: #fffbeb;
    --err: #dc2626;  --err-soft: #fef2f2;
    --info: #0891b2; --info-soft: #ecfeff;
    --violet: #7c3aed; --violet-soft: #f5f3ff;

    --radius-xs: 6px;
    --radius-sm: 8px;
    --radius: 10px;
    --radius-lg: 14px;
    --radius-full: 999px;

    --shadow-xs: 0 1px 2px rgba(24, 24, 27, .05);
    --shadow-sm: 0 1px 3px rgba(24, 24, 27, .06), 0 1px 2px rgba(24, 24, 27, .04);
    --shadow-md: 0 4px 14px rgba(24, 24, 27, .07);
    --shadow-lg: 0 12px 32px rgba(24, 24, 27, .10);

    --control-h: 38px;
    --mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, "Liberation Mono", monospace;
}

@media (prefers-color-scheme: dark) {
    :root {
        color-scheme: dark;
        --bg:        #09090b;
        --surface:   #131316;
        --surface-2: #1c1c21;
        --surface-3: #26262c;
        --border:    #27272a;
        --border-2:  #1f1f23;
        --ring:      rgba(59, 130, 246, .22);

        --text:      #fafafa;
        --text-2:    #a1a1aa;
        --text-3:    #71717a;

        --accent:      #3b82f6;
        --accent-2:    #2563eb;
        --accent-soft: #14213d;

        --ok: #22c55e;   --ok-soft: #0d1f14;
        --warn: #f59e0b; --warn-soft: #241a08;
        --err: #ef4444;  --err-soft: #2a1113;
        --info: #22d3ee; --info-soft: #0a2126;
        --violet: #a78bfa; --violet-soft: #1e1830;

        --shadow-xs: 0 1px 2px rgba(0, 0, 0, .5);
        --shadow-sm: 0 1px 3px rgba(0, 0, 0, .6);
        --shadow-md: 0 4px 14px rgba(0, 0, 0, .5);
        --shadow-lg: 0 12px 32px rgba(0, 0, 0, .55);
    }
}

/* ================= 基础 ================= */
* { box-sizing: border-box; margin: 0; padding: 0; }
html { -webkit-text-size-adjust: 100%; }

body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Noto Sans", "PingFang SC",
                 "Hiragino Sans GB", "Microsoft YaHei", Helvetica, Arial, sans-serif;
    font-size: 14px; line-height: 1.55;
    color: var(--text); background: var(--bg);
    -webkit-font-smoothing: antialiased; text-rendering: optimizeLegibility;
}
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
img, canvas, svg { max-width: 100%; }
svg { display: block; }
code, kbd {
    font-family: var(--mono); font-size: .88em;
    background: var(--surface-2); padding: 1px 5px; border-radius: var(--radius-xs);
    word-break: break-all;
}
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: var(--radius-xs); }
.muted { color: var(--text-3); font-size: 12.5px; }
.text-ok { color: var(--ok); } .text-err { color: var(--err); } .text-warn { color: var(--warn); }

/* ================= 卡片 ================= */
.card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 18px;
    margin-bottom: 16px;
    box-shadow: var(--shadow-xs);
}
.card > h3 {
    font-size: 15px; font-weight: 650; margin-bottom: 14px;
    display: flex; align-items: center; gap: 8px; flex-wrap: wrap;
}
.card > h3 .muted { font-weight: 400; }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; margin-bottom: 14px; }
.card-head h3 { margin-bottom: 0; }
.card form { margin: 0; }

/* ================= 按钮 ================= */
.btn {
    display: inline-flex; align-items: center; justify-content: center; gap: 6px;
    min-height: var(--control-h); padding: 0 15px;
    border: 1px solid var(--border); border-radius: var(--radius-sm);
    background: var(--surface); color: var(--text);
    font: inherit; font-size: 13.5px; font-weight: 600; line-height: 1;
    cursor: pointer; white-space: nowrap; text-decoration: none;
    box-shadow: var(--shadow-xs);
    transition: background .13s, border-color .13s, color .13s, box-shadow .13s, transform .08s;
}
.btn:hover { background: var(--surface-2); text-decoration: none; }
.btn:active { transform: translateY(1px); box-shadow: none; }
.btn svg { width: 15px; height: 15px; flex: 0 0 auto; }

.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--text-inv);
    box-shadow: 0 1px 2px rgba(37, 99, 235, .28); }
.btn.primary:hover { background: var(--accent-2); border-color: var(--accent-2); }

.btn.ghost { background: transparent; border-color: transparent; box-shadow: none; color: var(--text-2); }
.btn.ghost:hover { background: var(--surface-2); color: var(--text); }

.btn.danger { color: var(--err); border-color: color-mix(in srgb, var(--err) 30%, var(--border)); }
.btn.danger:hover { background: var(--err); border-color: var(--err); color: #fff; }

.btn.sm, .btn.small { min-height: 30px; padding: 0 10px; font-size: 12.5px; font-weight: 550; }
.btn.lg { min-height: 46px; padding: 0 22px; font-size: 15.5px; }
.btn.block { width: 100%; }
.btn[disabled], .btn.disabled { opacity: .55; pointer-events: none; }
.btn-row { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.btn-row form { display: inline; }

/* ================= 表单控件 ================= */
/* 统一所有原生控件外观：即使页面没写 .field 结构也能受益 */
input[type=text], input[type=password], input[type=email], input[type=number],
input[type=date], input[type=search], input[type=tel], input[type=url],
select, textarea, .input {
    width: 100%;
    min-height: var(--control-h);
    padding: 8px 12px;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    background: var(--surface);
    color: var(--text);
    font: inherit; font-size: 14px; line-height: 1.4;
    box-shadow: var(--shadow-xs);
    transition: border-color .15s, box-shadow .15s, background .15s;
    -webkit-appearance: none; appearance: none;
}
input[type=text]:hover:not(:focus):not(:disabled),
input[type=password]:hover:not(:focus):not(:disabled),
input[type=number]:hover:not(:focus):not(:disabled),
input[type=date]:hover:not(:focus):not(:disabled),
input[type=search]:hover:not(:focus):not(:disabled),
select:hover:not(:focus):not(:disabled),
textarea:hover:not(:focus):not(:disabled) { border-color: var(--text-3); }

input:focus, select:focus, textarea:focus {
    outline: none;
    border-color: var(--accent);
    box-shadow: 0 0 0 3px var(--ring);
}
input::placeholder, textarea::placeholder { color: var(--text-3); }
input:disabled, select:disabled, textarea:disabled,
input[readonly], textarea[readonly] {
    background: var(--surface-2); color: var(--text-3); cursor: not-allowed; box-shadow: none;
}
input[aria-invalid=true], textarea[aria-invalid=true], select[aria-invalid=true] { border-color: var(--err); }

select {
    padding-right: 34px; cursor: pointer;
    background-image: url("data:image/svg+xml;charset=utf-8,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' fill='none' stroke='%23a1a1aa' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M4 6l4 4 4-4'/%3E%3C/svg%3E");
    background-repeat: no-repeat; background-position: right 11px center;
}
textarea, textarea.input {
    min-height: 96px; padding: 10px 12px; resize: vertical;
    font-family: var(--mono); font-size: 12.5px; line-height: 1.65;
}
input[type=checkbox], input[type=radio] {
    width: 16px; height: 16px; min-height: 0; padding: 0;
    accent-color: var(--accent); cursor: pointer; box-shadow: none;
    vertical-align: -2px;
}

/* ---- 字段容器 ---- */
.field { margin-bottom: 16px; }
.field:last-child { margin-bottom: 0; }
.field-label {
    display: block; font-size: 13px; font-weight: 600;
    color: var(--text); margin-bottom: 6px;
}
.field-label .req { color: var(--err); margin-left: 2px; }
.field-hint { margin-top: 6px; font-size: 12px; color: var(--text-3); line-height: 1.6; }
.field-error { margin-top: 6px; font-size: 12px; color: var(--err); }
.field-inline { display: flex; align-items: center; gap: 8px; font-size: 13.5px; }
.field-inline label { margin: 0; font-weight: 500; color: var(--text-2); cursor: pointer; }

/* ---- 带图标的输入框 ---- */
.control { position: relative; display: flex; align-items: center; }
.control > svg {
    position: absolute; left: 11px; width: 16px; height: 16px;
    color: var(--text-3); pointer-events: none;
}
.control.has-icon > input, .control.has-icon > select { padding-left: 35px; }
.control .control-btn {
    position: absolute; right: 6px; display: grid; place-items: center;
    width: 28px; height: 28px; border: 0; border-radius: var(--radius-xs);
    background: transparent; color: var(--text-3); cursor: pointer;
}
.control .control-btn:hover { background: var(--surface-2); color: var(--text); }

/* ---- 前后缀（单位 / 说明） ---- */
.input-group { display: flex; align-items: stretch; }
.input-group > input, .input-group > select, .input-group > textarea {
    border-radius: var(--radius-sm) 0 0 var(--radius-sm);
}
.input-group > .addon {
    display: flex; align-items: center; padding: 0 12px;
    border: 1px solid var(--border); border-left: 0;
    background: var(--surface-2); color: var(--text-2);
    font-size: 13px; white-space: nowrap; border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
}
.input-group > .addon.left {
    border: 1px solid var(--border); border-right: 0;
    border-radius: var(--radius-sm) 0 0 var(--radius-sm);
}
.input-group > .addon.left + input, .input-group > .addon.left + select { border-radius: 0 var(--radius-sm) var(--radius-sm) 0; }

/* ---- 文件上传（原生控件太不显眼，做成明显的按钮） ---- */
.file-input { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.file-input input[type=file] {
    position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
    overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0; opacity: 0;
}
.file-input .file-btn {
    display: inline-flex; align-items: center; gap: 6px;
    min-height: var(--control-h); padding: 0 15px;
    border: 1px solid var(--border); border-radius: var(--radius-sm);
    background: var(--surface); color: var(--text);
    font-size: 13.5px; font-weight: 600; cursor: pointer;
    box-shadow: var(--shadow-xs);
    transition: background .13s, border-color .13s;
}
.file-input .file-btn:hover { background: var(--surface-2); }
.file-input .file-btn svg { width: 15px; height: 15px; }
.file-input .file-name {
    font-size: 12.5px; color: var(--text-3);
    max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.file-input .file-name.has-file { color: var(--ok); font-weight: 600; }

/* ---- 表单栅格 ---- */
.form-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); gap: 0 20px; }
.form-grid.wide { grid-template-columns: 1fr; }
.form-actions {
    display: flex; gap: 10px; flex-wrap: wrap; align-items: center;
    margin-top: 20px; padding-top: 16px; border-top: 1px solid var(--border-2);
}

/* ---- 筛选条 ---- */
.filters { display: flex; gap: 12px; flex-wrap: wrap; align-items: flex-end; }
.filters .field { margin-bottom: 0; flex: 0 0 auto; }
.filters .btn { flex: 0 0 auto; }

/* ================= 标签 ================= */
.tag {
    display: inline-flex; align-items: center; gap: 4px;
    padding: 2px 9px; border-radius: var(--radius-full);
    font-size: 12px; font-weight: 550; line-height: 1.7;
    background: var(--surface-2); color: var(--text-2); border: 1px solid var(--border);
    white-space: nowrap;
}
.tag.ok   { background: var(--ok-soft);   color: var(--ok);   border-color: color-mix(in srgb, var(--ok) 24%, transparent); }
.tag.wait { background: var(--warn-soft); color: var(--warn); border-color: color-mix(in srgb, var(--warn) 24%, transparent); }
.tag.err  { background: var(--err-soft);  color: var(--err);  border-color: color-mix(in srgb, var(--err) 24%, transparent); }
.tag.info { background: var(--info-soft); color: var(--info); border-color: color-mix(in srgb, var(--info) 24%, transparent); }
.tag.gray { background: var(--surface-2); color: var(--text-2); }

/* ================= 提示与状态 ================= */
.msg { padding: 12px 14px; border-radius: var(--radius); font-size: 13.5px; line-height: 1.7; }
.msg.ok   { background: var(--ok-soft);   color: var(--ok); }
.msg.err  { background: var(--err-soft);  color: var(--err); }
.msg.warn { background: var(--warn-soft); color: var(--warn); }

.flash {
    display: flex; align-items: flex-start; gap: 9px;
    padding: 12px 14px; border-radius: var(--radius); margin-bottom: 16px;
    font-size: 13.5px; border: 1px solid transparent;
}
.flash::before { content: '●'; font-size: 10px; line-height: 1.9; opacity: .7; }
.flash.ok   { background: var(--ok-soft);   color: var(--ok);   border-color: color-mix(in srgb, var(--ok) 28%, transparent); }
.flash.err  { background: var(--err-soft);  color: var(--err);  border-color: color-mix(in srgb, var(--err) 28%, transparent); }
.flash.warn { background: var(--warn-soft); color: var(--warn); border-color: color-mix(in srgb, var(--warn) 28%, transparent); }

.state { text-align: center; padding: 6px 0 2px; }
.state .ico {
    width: 68px; height: 68px; border-radius: 50%; margin: 0 auto 14px;
    display: flex; align-items: center; justify-content: center; font-size: 32px;
    animation: ui-pop .34s cubic-bezier(.3, 1.5, .6, 1);
}
@keyframes ui-pop { from { transform: scale(.4); opacity: 0; } to { transform: scale(1); opacity: 1; } }
.state .ico.ok   { background: var(--ok-soft);   color: var(--ok); }
.state .ico.err  { background: var(--err-soft);  color: var(--err); }
.state .ico.wait { background: var(--accent-soft); color: var(--accent); }
.state h3 { font-size: 19px; font-weight: 650; margin-bottom: 8px; }
.state p { color: var(--text-2); font-size: 14px; word-break: break-word; }
.state .acts { margin-top: 20px; display: flex; gap: 10px; justify-content: center; flex-wrap: wrap; }
.state .acts a {
    display: inline-flex; align-items: center; min-height: var(--control-h); padding: 0 18px;
    border-radius: var(--radius-sm); font-size: 14px;
    border: 1px solid var(--border); color: var(--text-2); background: var(--surface);
}
.state .acts a:hover { background: var(--surface-2); text-decoration: none; }
.state .acts a.primary { background: var(--accent); border-color: var(--accent); color: #fff; font-weight: 600; }

/* ================= 键值行 ================= */
.rows { font-size: 13px; }
.row {
    display: flex; justify-content: space-between; gap: 14px;
    padding: 8px 0; border-bottom: 1px solid var(--border-2);
}
.row:last-child { border-bottom: 0; }
.row > span:first-child { color: var(--text-2); white-space: nowrap; }
.row > span:last-child { text-align: right; word-break: break-all; min-width: 0; }
.row .copy { cursor: pointer; color: var(--accent); font-size: 12px; margin-left: 6px; }

/* ================= 键值行（详情页 / 安装向导大量使用） ================= */
.row-line {
    display: flex; justify-content: space-between; gap: 14px;
    padding: 8px 0; font-size: 13px;
    border-bottom: 1px solid var(--border-2);
}
.row-line:last-child { border-bottom: 0; }
.row-line > span:first-child { color: var(--text-2); white-space: nowrap; }
.row-line > span:last-child { text-align: right; word-break: break-all; }

/* .grid 为 .form-grid 的兼容别名（历史页面在用） */
.grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); gap: 0 22px; }

/* ================= 表格 ================= */
.table-wrap {
    overflow-x: auto; border: 1px solid var(--border);
    border-radius: var(--radius); background: var(--surface);
}
table { width: 100%; border-collapse: collapse; font-size: 13px; }
th, td { padding: 10px 12px; text-align: left; white-space: nowrap; }
thead th {
    background: var(--surface-2); color: var(--text-2);
    font-weight: 600; font-size: 12px; border-bottom: 1px solid var(--border);
    position: sticky; top: 0; z-index: 1;
}
tbody tr + tr td { border-top: 1px solid var(--border-2); }
tbody tr:hover td { background: var(--surface-2); }
td.num { font-variant-numeric: tabular-nums; font-weight: 600; }
.empty { text-align: center; color: var(--text-3); padding: 34px 10px !important; font-size: 13px; }

/* ================= 分页 ================= */
.pager { display: flex; gap: 6px; justify-content: center; margin-top: 16px; flex-wrap: wrap; }
.pager a, .pager span {
    display: inline-flex; align-items: center; justify-content: center;
    min-width: 34px; min-height: 34px; padding: 0 10px;
    border: 1px solid var(--border); border-radius: var(--radius-sm);
    background: var(--surface); color: var(--text); font-size: 13px; box-shadow: var(--shadow-xs);
}
.pager a:hover { background: var(--surface-2); text-decoration: none; }
.pager span.on { background: var(--accent); border-color: var(--accent); color: #fff; font-weight: 650; }

/* ================= 代码块 ================= */
pre {
    background: var(--surface-2); border: 1px solid var(--border);
    border-radius: var(--radius); padding: 13px 15px; overflow: auto;
    font-family: var(--mono); font-size: 12px; line-height: 1.75;
    color: var(--text); white-space: pre-wrap; word-break: break-all;
}

/* ================= 移动端 ================= */
@media (max-width: 900px) {
    .filters { flex-direction: column; align-items: stretch; }
    .filters .field { width: 100%; }
    .filters .btn { width: 100%; }
    input, select, textarea { font-size: 16px; }   /* 防 iOS 聚焦时页面放大 */
    .card { padding: 15px; border-radius: var(--radius); }
    .form-grid { grid-template-columns: 1fr; }
    .form-actions .btn { flex: 1; }
}
