/* ========== 移动端点击优化 ========== */
html {
    -webkit-tap-highlight-color: rgba(0, 0, 0, 0);
    -webkit-tap-highlight-color: transparent;
}

a, button, input, textarea, select, label, [role="button"] {
    -webkit-tap-highlight-color: rgba(0, 0, 0, 0);
    -webkit-tap-highlight-color: transparent;
    -webkit-touch-callout: none;
}

a:focus:not(:focus-visible),
button:focus:not(:focus-visible),
input:focus:not(:focus-visible),
textarea:focus:not(:focus-visible),
select:focus:not(:focus-visible) {
    outline: none;
}

/* 点按时轻微缩放（可选，不想用就删掉） */
.btn:active,
.header-icon:active,
.pkg-btn:active {
    transform: scale(0.97);
}
* { box-sizing: border-box; margin: 0; padding: 0; }
html { -webkit-text-size-adjust: 100%; }
body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
    background: #f9fafb;
    color: #111827;
    line-height: 1.5;
    min-height: 100vh;
}
a { color: inherit; text-decoration: none; }
button, input, textarea, select { font: inherit; }

.hidden { display: none !important; }
.muted { color: #9ca3af; }
.container { max-width: 720px; margin: 0 auto; padding: 0 16px; }

/* Header */
.header { background: #fff; border-bottom: 1px solid #e5e7eb; position: sticky; top: 0; z-index: 10; }
.header-inner { display: flex; align-items: center; justify-content: space-between; padding: 12px 16px; }
.logo { display: flex; align-items: center; gap: 8px; color: #111827; font-weight: 600; }
.logo svg { color: #fff; background: #10b981; padding: 6px; border-radius: 8px; }
.header-right { display: flex; align-items: center; gap: 12px; font-size: 14px; }
.balance-badge { background: #ecfdf5; color: #059669; padding: 4px 10px; border-radius: 999px; font-weight: 500; }
.user-link { color: #4b5563; }
.user-link:hover { color: #111827; }

/* Buttons */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; padding: 10px 16px; border-radius: 8px; border: 1px solid transparent; font-weight: 500; font-size: 14px; cursor: pointer; transition: 0.15s; }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn-sm { padding: 6px 12px; font-size: 13px; }
.btn-primary { background: #10b981; color: #fff; }
.btn-primary:hover:not(:disabled) { background: #059669; }
.btn-secondary { background: #fff; color: #374151; border-color: #d1d5db; }
.btn-secondary:hover:not(:disabled) { background: #f9fafb; }
.btn-danger { background: #ef4444; color: #fff; }
.btn-danger:hover:not(:disabled) { background: #dc2626; }
.btn-block { width: 100%; }

/* Card */
.card { background: #fff; border: 1px solid #f3f4f6; border-radius: 16px; padding: 20px; box-shadow: 0 1px 2px rgba(0,0,0,0.03); }
.card + .card { margin-top: 16px; }
.card-title { font-size: 15px; font-weight: 600; margin-bottom: 12px; display: flex; align-items: center; gap: 8px; }
.card-title svg { color: #10b981; }

/* Form */
.form-group { margin-bottom: 14px; }
.form-label { display: block; font-size: 13px; font-weight: 500; color: #374151; margin-bottom: 6px; }
.form-input, .form-select, .form-textarea {
    width: 100%; padding: 10px 12px; border: 1px solid #d1d5db; border-radius: 8px; font-size: 14px; outline: none; transition: 0.15s;
}
.form-input:focus, .form-select:focus, .form-textarea:focus { border-color: #10b981; box-shadow: 0 0 0 3px rgba(16,185,129,0.1); }
.form-textarea { min-height: 100px; resize: vertical; }

/* Alerts */
.alert { padding: 12px 14px; border-radius: 8px; font-size: 14px; margin-bottom: 14px; }
.alert-error { background: #fef2f2; color: #991b1b; border: 1px solid #fecaca; }
.alert-success { background: #f0fdf4; color: #166534; border: 1px solid #bbf7d0; }
.alert-info { background: #eff6ff; color: #1e40af; border: 1px solid #bfdbfe; }
.alert-warn { background: #fffbeb; color: #92400e; border: 1px solid #fde68a; }

/* Notice */
.notice { padding: 14px; border-radius: 12px; border: 1px solid; margin-bottom: 10px; }
.notice-info { background: #eff6ff; border-color: #bfdbfe; }
.notice-warning { background: #fffbeb; border-color: #fde68a; }
.notice-success { background: #f0fdf4; border-color: #bbf7d0; }
.notice-danger { background: #fef2f2; border-color: #fecaca; }
.notice-title { font-weight: 600; font-size: 14px; }
.notice-head { display: flex; justify-content: space-between; align-items: center; gap: 8px; margin-bottom: 6px; }
.notice-time { font-size: 12px; color: #9ca3af; flex-shrink: 0; }
.notice-content { display: block; font-size: 13px; color: #374151; line-height: 1.6; white-space: pre-wrap; word-break: break-word; }

/* Package grid */
.pkg-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 8px;
    margin-top: 18px;
    padding-top: 8px;
}
.pkg-btn {
    position: relative;
    padding: 12px 8px;
    text-align: center;
    border: 1px solid #e5e7eb;
    border-radius: 12px;
    background: #fff;
    cursor: pointer;
    transition: 0.15s;
    min-width: 0;
}
.pkg-btn:hover { border-color: #10b981; background: #f0fdf4; }
.pkg-btn.recommend { background: #10b981; color: #fff; border-color: #10b981; }
.pkg-btn.recommend:hover { background: #059669; }
.pkg-btn .pkg-name {
    font-size: 12px;
    opacity: 0.85;
    margin-bottom: 4px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.pkg-btn .pkg-price {
    font-weight: 600;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    font-variant-numeric: tabular-nums;
}
.pkg-btn .pkg-badge {
    position: absolute;
    top: -8px;
    left: 50%;
    transform: translateX(-50%);
    background: #fbbf24;
    color: #78350f;
    font-size: 11px;
    padding: 2px 8px;
    border-radius: 999px;
    white-space: nowrap;
    z-index: 1;
}

/* Modal */
.modal { position: fixed; inset: 0; background: rgba(0,0,0,0.5); z-index: 50; display: none; align-items: flex-end; justify-content: center; padding: 0; }
.modal.open { display: flex; }
@media (min-width: 640px) { .modal { align-items: center; padding: 16px; } }
.modal-box { background: #fff; width: 100%; max-width: 460px; border-radius: 16px 16px 0 0; max-height: 90vh; overflow-y: auto; }
@media (min-width: 640px) { .modal-box { border-radius: 16px; } }
.modal-head { padding: 16px 20px; border-bottom: 1px solid #f3f4f6; display: flex; justify-content: space-between; align-items: center; position: sticky; top: 0; background: #fff; z-index: 1; }
.modal-head h3 { font-size: 15px; font-weight: 600; }
.modal-close { background: none; border: 0; color: #9ca3af; cursor: pointer; padding: 4px; }
.modal-body { padding: 20px; }

/* Loading */
.loading-overlay { position: fixed; inset: 0; background: rgba(255,255,255,0.7); display: flex; align-items: center; justify-content: center; z-index: 100; }
.spinner { width: 36px; height: 36px; border: 3px solid #e5e7eb; border-top-color: #10b981; border-radius: 50%; animation: spin 0.7s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ========== Table：自己横向滚动，无需改 HTML ========== */
.table {
    width: 100%;
    border-collapse: collapse;
    font-size: 13px;
    min-width: 560px;
    white-space: nowrap;
}
.table th, .table td {
    padding: 10px 12px;
    text-align: left;
    border-bottom: 1px solid #f3f4f6;
}
.table th {
    font-weight: 500;
    color: #6b7280;
    font-size: 12px;
}
.table tr:last-child td { border-bottom: none; }

/* 长文本单元格省略 */
.table td code {
    display: inline-block;
    max-width: 220px;
    overflow: hidden;
    text-overflow: ellipsis;
    vertical-align: middle;
}

/* 关键：用外层容器包住 table 实现滚动。
   不依赖页面 HTML，给 .card 里所有直接/间接 table 的父级自动加滚动。
   用 :has() 精准命中，不会误伤 .card 里的其它内容。 */
@supports (selector(:has(*))) {
    /* table 是 .card 的直接子元素 */
    .card:has(> table) {
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
    }
    /* table 被一层 div 包着 */
    .card:has(> div > table) > div {
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
    }
    /* table 被两层 div 包着（后台常见结构） */
    .card:has(> div > div > table) > div > div {
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
    }
    /* 兜底：任何 .card 里出现 table，就让 .card 本身可横向滚动 */
    .card:has(table) {
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
    }
}

/* 不支持 :has() 的老浏览器：让 .card 自己横向滚动 */
.card {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
}

@media (max-width: 640px) {
    .table {
        min-width: 480px;
        font-size: 12px;
    }
    .table th, .table td {
        padding: 8px 10px;
    }
}

/* Utility */
.mt-4 { margin-top: 16px; }
.mb-4 { margin-bottom: 16px; }
.flex { display: flex; }
.flex-between { display: flex; justify-content: space-between; align-items: center; }
.gap-2 { gap: 8px; }
.text-right { text-align: right; }
.text-sm { font-size: 13px; }
.text-xs { font-size: 12px; }
.text-muted { color: #6b7280; }
.text-success { color: #10b981; }
.text-danger { color: #ef4444; }

/* Footer */
.footer { text-align: center; color: #9ca3af; font-size: 12px; padding: 24px 0; margin-top: 24px; }

/* Auth page (centered) */
.auth-page { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 20px; }
.auth-box { width: 100%; max-width: 380px; }
.auth-logo { text-align: center; margin-bottom: 24px; }
.auth-logo .logo-icon { display: inline-flex; align-items: center; justify-content: center; width: 56px; height: 56px; background: #10b981; border-radius: 16px; color: #fff; margin-bottom: 12px; }
.auth-logo h1 { font-size: 22px; font-weight: 600; }
.auth-logo p { font-size: 13px; color: #6b7280; margin-top: 4px; }
.auth-footer { text-align: center; margin-top: 20px; font-size: 13px; color: #6b7280; }
.auth-footer a { color: #10b981; font-weight: 500; }

/* Admin */
.admin-layout { display: flex; min-height: 100vh; }
.admin-sidebar { width: 220px; background: #1f2937; color: #e5e7eb; padding: 20px 0; flex-shrink: 0; }
.admin-sidebar .admin-logo { padding: 0 20px 20px; border-bottom: 1px solid #374151; margin-bottom: 12px; font-weight: 600; }
.admin-sidebar a { display: block; padding: 10px 20px; color: #d1d5db; font-size: 14px; transition: 0.15s; }
.admin-sidebar a:hover { background: #374151; color: #fff; }
.admin-sidebar a.active { background: #10b981; color: #fff; }
.admin-main { flex: 1; padding: 24px; overflow-x: auto; }
.admin-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 24px; }
.admin-header h1 { font-size: 22px; font-weight: 600; }

/* Stats grid */
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 16px; margin-bottom: 24px; }
.stat { background: #fff; border-radius: 12px; padding: 20px; border: 1px solid #f3f4f6; }
.stat .stat-label { font-size: 12px; color: #6b7280; margin-bottom: 6px; }
.stat .stat-value { font-size: 24px; font-weight: 600; }

/* 手机小屏时字小一点 */
@media (max-width: 480px) {
    .pkg-btn .pkg-price { font-size: 14px; }
    .pkg-btn .pkg-name { font-size: 11px; }
}

/* 所有卡片内容防撑破 */
.card * {
    min-width: 0;
}

/* 顶部徽章超长省略 */
.balance-badge {
    display: inline-block;
    max-width: 130px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    vertical-align: middle;
}

/* 余额卡大数字：可变字号 */
.balance-amount {
    font-size: 32px;
    font-weight: 600;
    margin: 8px 0;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    font-variant-numeric: tabular-nums;
}
@media (max-width: 480px) {
    .balance-amount { font-size: 22px; }
}
@media (max-width: 360px) {
    .balance-amount { font-size: 18px; }
}
/* ========== 顶部导航 ========== */
.header-inner {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    flex-wrap: nowrap;
    padding: 12px 16px;
}
.logo {
    display: flex;
    align-items: center;
    gap: 8px;
    color: #111827;
    font-weight: 600;
    flex-shrink: 0;
}
.logo span { white-space: nowrap; }
.logo svg {
    color: #fff;
    background: #10b981;
    padding: 6px;
    border-radius: 8px;
    flex-shrink: 0;
}

.header-right {
    display: flex;
    align-items: center;
    gap: 6px;
    min-width: 0;
    flex-shrink: 1;
}

/* 余额徽章 */
.balance-badge {
    display: inline-block;
    background: #ecfdf5;
    color: #059669;
    padding: 4px 10px;
    border-radius: 999px;
    font-weight: 500;
    font-size: 14px;
    white-space: nowrap;
    max-width: 120px;
    overflow: hidden;
    text-overflow: ellipsis;
    vertical-align: middle;
    flex-shrink: 0;
}
.balance-badge:hover { background: #d1fae5; }

/* 图标按钮 */
.header-icon {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 36px;
    height: 36px;
    border-radius: 10px;
    color: #4b5563;
    position: relative;
    flex-shrink: 0;
    transition: background 0.15s, color 0.15s;
}
.header-icon:hover {
    background: #f3f4f6;
    color: #111827;
}
.header-icon .badge-dot {
    position: absolute;
    top: -2px;
    right: -2px;
    background: #ef4444;
    color: #fff;
    font-size: 10px;
    padding: 1px 5px;
    border-radius: 999px;
    min-width: 16px;
    text-align: center;
    line-height: 14px;
    font-weight: 600;
}

/* 手机端压缩 */
@media (max-width: 480px) {
    .header-inner { padding: 10px 12px; gap: 6px; }
    .logo span { font-size: 15px; }
    .balance-badge { font-size: 13px; padding: 3px 8px; max-width: 90px; }
    .header-icon { width: 34px; height: 34px; }
}

@media (max-width: 380px) {
    .logo span { display: none; }
    .balance-badge { font-size: 12px; padding: 2px 6px; max-width: 70px; }
}

@media (max-width: 340px) {
    .header-icon { width: 30px; height: 30px; }
}
/* ========== 搜索栏 ========== */
.search-bar {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
    align-items: center;
    margin-bottom: 12px;
}
.search-bar .form-input,
.search-bar .form-select {
    flex: 1;
    min-width: 140px;
}
.search-bar .btn {
    flex-shrink: 0;
}
@media (max-width: 480px) {
    .search-bar .form-input,
    .search-bar .form-select {
        flex-basis: 100%;
    }
}

/* 服务链接按钮组 */
.svc-links {
    margin-top: 8px;
    display: flex;
    gap: 6px;
    flex-wrap: wrap;
}