/* =========================================================
   PayGate Pro v5 - Stripe风格后台样式
   ========================================================= */

:root {
    --primary: #635bff;
    --primary-hover: #5851ea;
    --primary-light: #e8e5ff;
    --success: #30b566;
    --success-light: #e6f9ef;
    --warning: #f5a623;
    --warning-light: #fef6e6;
    --danger: #e74c3c;
    --danger-light: #fde8e8;
    --info: #3498db;
    --info-light: #e8f4fd;

    --gray-50: #f7f8f9;
    --gray-100: #f0f1f3;
    --gray-200: #e4e6ea;
    --gray-300: #c8ccd4;
    --gray-400: #9da5b4;
    --gray-500: #697386;
    --gray-600: #4b5669;
    --gray-700: #3c4657;
    --gray-800: #2c3440;
    --gray-900: #1a1f36;

    --bg: #f7f8f9;
    --surface: #ffffff;
    --border: #e4e6ea;
    --text: #1a1f36;
    --text-secondary: #697386;
    --text-muted: #9da5b4;

    --radius: 8px;
    --radius-lg: 12px;
    --shadow-sm: 0 1px 2px rgba(0,0,0,0.04);
    --shadow: 0 2px 8px rgba(0,0,0,0.08);
    --shadow-lg: 0 8px 24px rgba(0,0,0,0.12);

    --sidebar-width: 260px;
    --header-height: 64px;
}

* { margin: 0; padding: 0; box-sizing: border-box; }

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
    font-size: 14px;
    line-height: 1.6;
    color: var(--text);
    background: var(--bg);
    -webkit-font-smoothing: antialiased;
}

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

/* ========== 登录页 ========== */
.login-page {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    background: linear-gradient(135deg, #635bff 0%, #7c3aed 100%);
    padding: 20px;
}

.login-card {
    background: var(--surface);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-lg);
    padding: 48px 40px;
    width: 100%;
    max-width: 420px;
}

.login-card .logo {
    text-align: center;
    margin-bottom: 32px;
}

.login-card .logo h1 {
    font-size: 28px;
    font-weight: 700;
    color: var(--primary);
    letter-spacing: -0.5px;
}

.login-card .logo p {
    color: var(--text-secondary);
    font-size: 14px;
    margin-top: 4px;
}

/* ========== 表单 ========== */
.form-group {
    margin-bottom: 20px;
}

.form-group label {
    display: block;
    font-size: 13px;
    font-weight: 600;
    color: var(--gray-700);
    margin-bottom: 6px;
}

.form-control {
    width: 100%;
    padding: 10px 14px;
    font-size: 14px;
    line-height: 1.5;
    border: 1.5px solid var(--border);
    border-radius: var(--radius);
    background: var(--surface);
    color: var(--text);
    transition: border-color 0.2s, box-shadow 0.2s;
    outline: none;
}

.form-control:focus {
    border-color: var(--primary);
    box-shadow: 0 0 0 3px var(--primary-light);
}

.form-control::placeholder {
    color: var(--text-muted);
}

select.form-control {
    appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath fill='%23697386' d='M6 8L1 3h10z'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 12px center;
    padding-right: 36px;
}

textarea.form-control {
    resize: vertical;
    min-height: 80px;
}

.form-row {
    display: flex;
    gap: 16px;
}

.form-row .form-group {
    flex: 1;
}

.form-hint {
    font-size: 12px;
    color: var(--text-muted);
    margin-top: 4px;
}

/* ========== 按钮 ========== */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 10px 20px;
    font-size: 14px;
    font-weight: 600;
    border-radius: var(--radius);
    border: none;
    cursor: pointer;
    transition: all 0.2s;
    text-decoration: none;
    line-height: 1.4;
    white-space: nowrap;
}

.btn:hover { text-decoration: none; }

.btn-primary {
    background: var(--primary);
    color: white;
}
.btn-primary:hover {
    background: var(--primary-hover);
    box-shadow: 0 2px 8px rgba(99,91,255,0.4);
}

.btn-success {
    background: var(--success);
    color: white;
}
.btn-success:hover { background: #28a45a; }

.btn-danger {
    background: var(--danger);
    color: white;
}
.btn-danger:hover { background: #d63a2c; }

.btn-warning {
    background: var(--warning);
    color: white;
}
.btn-warning:hover { background: #e09520; }

.btn-outline {
    background: transparent;
    color: var(--text);
    border: 1.5px solid var(--border);
}
.btn-outline:hover {
    background: var(--gray-50);
    border-color: var(--gray-300);
}

.btn-sm {
    padding: 6px 12px;
    font-size: 13px;
}

.btn-lg {
    padding: 14px 28px;
    font-size: 16px;
}

.btn-block {
    width: 100%;
}

.btn-group {
    display: flex;
    gap: 8px;
}

/* ========== 布局 ========== */
.layout {
    display: flex;
    min-height: 100vh;
}

/* 侧边栏 */
.sidebar {
    width: var(--sidebar-width);
    background: var(--gray-900);
    color: white;
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    overflow-y: auto;
    z-index: 100;
}

.sidebar-brand {
    padding: 20px 24px;
    border-bottom: 1px solid rgba(255,255,255,0.1);
}

.sidebar-brand h2 {
    font-size: 20px;
    font-weight: 700;
    color: white;
}

.sidebar-brand span {
    font-size: 12px;
    color: var(--gray-400);
}

.sidebar-nav {
    padding: 16px 0;
}

.nav-section {
    padding: 0 16px;
    margin-bottom: 8px;
}

.nav-section-title {
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.8px;
    color: var(--gray-400);
    padding: 8px;
    margin-bottom: 4px;
}

.nav-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 16px;
    color: var(--gray-300);
    font-size: 14px;
    border-radius: var(--radius);
    margin: 2px 8px;
    transition: all 0.15s;
    text-decoration: none;
}

.nav-item:hover {
    background: rgba(255,255,255,0.08);
    color: white;
    text-decoration: none;
}

.nav-item.active {
    background: rgba(99,91,255,0.25);
    color: white;
    font-weight: 500;
}

.nav-item .icon {
    width: 20px;
    height: 20px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 16px;
}

.nav-sub-item {
    padding-left: 46px;
    font-size: 13px;
}

.nav-item .new-badge {
    background: var(--danger);
    color: white;
    font-size: 10px;
    padding: 1px 6px;
    border-radius: 10px;
    font-weight: 600;
    margin-left: auto;
}

/* 主内容区 */
.main-content {
    margin-left: var(--sidebar-width);
    flex: 1;
    min-height: 100vh;
}

.content-header {
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    padding: 16px 32px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    position: sticky;
    top: 0;
    z-index: 50;
}

.content-header h1 {
    font-size: 20px;
    font-weight: 600;
    color: var(--text);
}

.content-body {
    padding: 24px 32px;
}

/* ========== 统计卡片 ========== */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
    gap: 16px;
    margin-bottom: 24px;
}

.stat-card {
    background: var(--surface);
    border-radius: var(--radius-lg);
    padding: 24px;
    box-shadow: var(--shadow-sm);
    border: 1px solid var(--border);
}

.stat-card .stat-label {
    font-size: 12px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: var(--text-secondary);
    margin-bottom: 8px;
}

.stat-card .stat-value {
    font-size: 28px;
    font-weight: 700;
    color: var(--text);
    line-height: 1.2;
}

.stat-card .stat-change {
    font-size: 13px;
    margin-top: 8px;
}

.stat-card .stat-change.positive { color: var(--success); }
.stat-card .stat-change.negative { color: var(--danger); }

.stat-card.primary { border-left: 4px solid var(--primary); }
.stat-card.success { border-left: 4px solid var(--success); }
.stat-card.warning { border-left: 4px solid var(--warning); }
.stat-card.danger { border-left: 4px solid var(--danger); }
.stat-card.info { border-left: 4px solid var(--info); }

/* ========== 表格 ========== */
.table-card {
    background: var(--surface);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-sm);
    border: 1px solid var(--border);
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
}

.table-card .data-table {
    min-width: 700px;
}

.table-header {
    padding: 20px 24px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    border-bottom: 1px solid var(--border);
}

.table-header h3 {
    font-size: 16px;
    font-weight: 600;
}

.table-filters {
    display: flex;
    gap: 12px;
    align-items: center;
    padding: 16px 24px;
    border-bottom: 1px solid var(--border);
    background: var(--gray-50);
    flex-wrap: wrap;
}

.table-filters .form-control {
    max-width: 200px;
    padding: 8px 12px;
    font-size: 13px;
}

.data-table {
    width: 100%;
    border-collapse: collapse;
}

.data-table th {
    padding: 12px 16px;
    font-size: 12px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: var(--text-secondary);
    text-align: left;
    background: var(--gray-50);
    border-bottom: 1px solid var(--border);
    white-space: nowrap;
}

.data-table td {
    padding: 14px 16px;
    font-size: 14px;
    border-bottom: 1px solid var(--border);
    color: var(--text);
}

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

.data-table tr:hover td {
    background: var(--gray-50);
}

.data-table tr.eaten-row td {
    background: var(--danger-light);
}

.table-footer {
    padding: 16px 24px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    border-top: 1px solid var(--border);
    font-size: 13px;
    color: var(--text-secondary);
}

/* ========== 徽章 ========== */
.badge {
    display: inline-flex;
    align-items: center;
    padding: 3px 10px;
    font-size: 12px;
    font-weight: 600;
    border-radius: 20px;
    white-space: nowrap;
}

.badge-success { background: var(--success-light); color: var(--success); }
.badge-warning { background: var(--warning-light); color: var(--warning); }
.badge-danger  { background: var(--danger-light);  color: var(--danger); }
.badge-info    { background: var(--info-light);     color: var(--info); }
.badge-primary { background: var(--primary-light);  color: var(--primary); }
.badge-neutral { background: var(--gray-100);       color: var(--gray-600); }

.badge-dot::before {
    content: '';
    display: inline-block;
    width: 6px;
    height: 6px;
    border-radius: 50%;
    margin-right: 6px;
}

.badge-dot.badge-success::before { background: var(--success); }
.badge-dot.badge-warning::before { background: var(--warning); }
.badge-dot.badge-danger::before  { background: var(--danger); }
.badge-dot.badge-info::before    { background: var(--info); }
.badge-dot.badge-neutral::before { background: var(--gray-400); }

/* ========== 筛选标签 ========== */
.filter-tabs {
    display: flex;
    gap: 0;
    border-bottom: 2px solid var(--border);
    margin-bottom: 20px;
}

.filter-tab {
    padding: 10px 20px;
    font-size: 14px;
    font-weight: 500;
    color: var(--text-secondary);
    cursor: pointer;
    border-bottom: 2px solid transparent;
    margin-bottom: -2px;
    transition: all 0.15s;
    text-decoration: none;
    display: inline-block;
}

.filter-tab:hover {
    color: var(--text);
    text-decoration: none;
}

.filter-tab.active {
    color: var(--primary);
    border-bottom-color: var(--primary);
    font-weight: 600;
}

/* ========== 分页 ========== */
.pagination {
    display: flex;
    gap: 4px;
}

.pagination a, .pagination span {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 36px;
    height: 36px;
    padding: 0 12px;
    border-radius: var(--radius);
    font-size: 14px;
    font-weight: 500;
    color: var(--text-secondary);
    border: 1px solid var(--border);
    background: var(--surface);
    text-decoration: none;
    transition: all 0.15s;
}

.pagination a:hover {
    background: var(--gray-50);
    border-color: var(--gray-300);
    text-decoration: none;
}

.pagination .active {
    background: var(--primary);
    color: white;
    border-color: var(--primary);
}

/* ========== 卡片 ========== */
.card {
    background: var(--surface);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-sm);
    border: 1px solid var(--border);
}

.card-header {
    padding: 20px 24px;
    border-bottom: 1px solid var(--border);
}

.card-header h3 {
    font-size: 16px;
    font-weight: 600;
}

.card-body {
    padding: 24px;
}

.card-footer {
    padding: 16px 24px;
    border-top: 1px solid var(--border);
    background: var(--gray-50);
    border-radius: 0 0 var(--radius-lg) var(--radius-lg);
}

/* ========== 弹窗/模态框 ========== */
.modal-overlay {
    position: fixed;
    top: 0; left: 0; right: 0; bottom: 0;
    background: rgba(0,0,0,0.5);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    opacity: 0;
    visibility: hidden;
    transition: all 0.2s;
}

.modal-overlay.active {
    opacity: 1;
    visibility: visible;
}

.modal {
    background: var(--surface);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-lg);
    width: 100%;
    max-width: 520px;
    max-height: 90vh;
    overflow-y: auto;
    transform: scale(0.95);
    transition: transform 0.2s;
}

.modal-overlay.active .modal {
    transform: scale(1);
}

.modal-header {
    padding: 20px 24px;
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.modal-header h3 {
    font-size: 18px;
    font-weight: 600;
}

.modal-close {
    width: 32px; height: 32px;
    border: none; background: none;
    font-size: 20px; color: var(--text-muted);
    cursor: pointer; border-radius: var(--radius);
    display: flex; align-items: center; justify-content: center;
}
.modal-close:hover { background: var(--gray-100); }

.modal-body { padding: 24px; }

.modal-footer {
    padding: 16px 24px;
    border-top: 1px solid var(--border);
    display: flex;
    justify-content: flex-end;
    gap: 8px;
}

/* ========== Toast 通知 ========== */
.toast-container {
    position: fixed;
    top: 20px;
    right: 20px;
    z-index: 2000;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.toast {
    background: var(--surface);
    border-radius: var(--radius);
    box-shadow: var(--shadow-lg);
    padding: 14px 20px;
    display: flex;
    align-items: center;
    gap: 12px;
    min-width: 300px;
    max-width: 480px;
    animation: slideIn 0.3s ease;
    border-left: 4px solid var(--primary);
}

.toast.success { border-left-color: var(--success); }
.toast.error   { border-left-color: var(--danger); }
.toast.warning { border-left-color: var(--warning); }

@keyframes slideIn {
    from { transform: translateX(100%); opacity: 0; }
    to   { transform: translateX(0);    opacity: 1; }
}

/* ========== API Key 展示 ========== */
.api-key-box {
    background: var(--gray-50);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 12px 16px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    font-family: 'SF Mono', 'Fira Code', monospace;
    font-size: 13px;
    color: var(--gray-700);
    word-break: break-all;
}

.api-key-box .btn-copy {
    flex-shrink: 0;
    padding: 4px 10px;
    font-size: 12px;
}

/* ========== 空状态 ========== */
.empty-state {
    text-align: center;
    padding: 60px 20px;
    color: var(--text-muted);
}

.empty-state .icon {
    font-size: 48px;
    margin-bottom: 16px;
}

.empty-state h3 {
    font-size: 18px;
    color: var(--text-secondary);
    margin-bottom: 8px;
}

/* ========== 侧边栏遮罩 ========== */
.sidebar-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.5);
    z-index: 90;
    opacity: 0;
    visibility: hidden;
    transition: all 0.3s;
}
.sidebar-overlay.active {
    opacity: 1;
    visibility: visible;
}

/* ========== 菜单按钮 ========== */
.menu-toggle {
    display: inline-flex;
    width: 40px;
    height: 40px;
    border: 1.5px solid var(--border);
    border-radius: var(--radius);
    background: var(--surface);
    cursor: pointer;
    align-items: center;
    justify-content: center;
    font-size: 20px;
    color: var(--text);
    flex-shrink: 0;
    margin-right: 12px;
    transition: background 0.2s;
}
.menu-toggle:hover {
    background: var(--gray-50);
}

/* ========== CSS柱状图 ========== */
.bar-chart {
    display: flex;
    align-items: flex-end;
    gap: 4px;
    height: 200px;
    padding: 10px 0;
}

.bar-chart .bar-col {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 4px;
}

.bar-chart .bar-label {
    font-size: 11px;
    color: var(--text-muted);
}

.bar-chart .bar-value {
    font-size: 11px;
    color: var(--text-muted);
}

.bar-chart .bar {
    width: 100%;
    border-radius: 4px 4px 0 0;
    opacity: 0.8;
    transition: opacity 0.2s;
}

.bar-chart .bar:hover {
    opacity: 1;
}

/* ========== Checkbox ========== */
.checkbox-group {
    display: flex;
    align-items: center;
    gap: 8px;
}

.checkbox-group input[type="checkbox"] {
    width: 18px;
    height: 18px;
    accent-color: var(--primary);
    cursor: pointer;
}

.checkbox-group label {
    font-size: 14px;
    cursor: pointer;
    color: var(--text);
    margin-bottom: 0;
}

/* ========== 响应式 ========== */
.sidebar {
    transition: transform 0.3s ease;
}
.sidebar.collapsed {
    transform: translateX(-100%);
}
.main-content.sidebar-collapsed {
    margin-left: 0;
}
@media (max-width: 1024px) {
    .sidebar:not(.collapsed) {
        /* default open on desktop */
    }
    .sidebar.collapsed { transform: translateX(-100%); }
    .sidebar.open { transform: translateX(0); }
    .main-content { margin-left: 0; }
    .stats-grid { grid-template-columns: repeat(2, 1fr); }
    .menu-toggle { display: inline-flex; }
    .content-header { padding: 12px 16px; }
    .content-body { padding: 16px; }
    .content-header h1 { font-size: 17px; }
}

@media (max-width: 768px) {
    .stats-grid { grid-template-columns: repeat(2, 1fr); gap: 12px; }
    .stat-card { padding: 16px; }
    .stat-card .stat-value { font-size: 22px; }
    .card-header { padding: 16px; }
    .card-body { padding: 16px; }
    .table-header { padding: 16px; flex-wrap: wrap; gap: 8px; }
    .table-header h3 { font-size: 14px; }
    .table-footer { padding: 12px 16px; flex-wrap: wrap; gap: 8px; justify-content: center; }
    .login-card { padding: 32px 24px; }
    .login-card .logo h1 { font-size: 24px; }
    .modal { margin: 16px; max-width: calc(100% - 32px); }
    .api-key-box { flex-direction: column; align-items: flex-start; }
    .api-key-box .btn-copy { align-self: flex-end; }
}

@media (max-width: 640px) {
    .stats-grid { grid-template-columns: 1fr; }
    .content-body { padding: 12px; }
    .content-header { padding: 10px 12px; }
    .content-header h1 { font-size: 16px; }
    .form-row { flex-direction: column; gap: 0; }
    .table-filters {
        flex-wrap: wrap;
        padding: 12px;
        gap: 8px;
    }
    .table-filters .form-control {
        max-width: 100%;
        width: 100%;
    }
    .table-filters .btn {
        width: 100%;
    }
    .btn-group { flex-wrap: wrap; }
    .btn-group .btn { flex: 1; min-width: 0; text-align: center; }
    .pagination { flex-wrap: wrap; justify-content: center; }
    .toast-container {
        left: 12px;
        right: 12px;
        top: 12px;
    }
    .toast {
        min-width: unset;
        max-width: 100%;
        width: 100%;
        font-size: 13px;
        padding: 12px 16px;
    }
    .modal { margin: 12px; max-width: calc(100% - 24px); border-radius: var(--radius); }
    .modal-header { padding: 16px; }
    .modal-body { padding: 16px; }
    .modal-footer { padding: 12px 16px; }
    .login-card { padding: 28px 20px; }
    .card-body { padding: 12px; }
    .data-table th, .data-table td { padding: 10px 12px; font-size: 13px; }
    .flex.justify-between.items-center.mb-6 {
        flex-direction: column;
        align-items: flex-start;
        gap: 12px;
    }
    .filter-tabs { overflow-x: auto; }
    .filter-tab { padding: 8px 14px; font-size: 13px; white-space: nowrap; }
}

/* ========== 辅助 ========== */
.text-muted { color: var(--text-muted) !important; }
.text-secondary { color: var(--text-secondary) !important; }
.text-success { color: var(--success) !important; }
.text-danger  { color: var(--danger) !important; }
.text-primary { color: var(--primary) !important; }
.text-warning { color: var(--warning) !important; }
.text-center { text-align: center; }
.text-right  { text-align: right; }
.font-mono   { font-family: 'SF Mono', 'Fira Code', monospace; }
.mt-4  { margin-top: 16px; }
.mt-6  { margin-top: 24px; }
.mb-4  { margin-bottom: 16px; }
.mb-6  { margin-bottom: 24px; }
.flex  { display: flex; }
.gap-2 { gap: 8px; }
.gap-4 { gap: 16px; }
.items-center { align-items: center; }
.justify-between { justify-content: space-between; }
