/* ============================================================
   CSS 变量定义
   ============================================================ */
:root {
    --primary: #2563eb;
    --primary-dark: #1d4ed8;
    --primary-light: #dbeafe;
    --secondary: #64748b;
    --secondary-light: #f1f5f9;
    --success: #16a34a;
    --success-light: #dcfce7;
    --danger: #dc2626;
    --danger-light: #fee2e2;
    --warning: #d97706;
    --warning-light: #fef3c7;
    --info: #0891b2;
    --info-light: #cffafe;

    --bg-body: #f8fafc;
    --bg-card: #ffffff;
    --text-primary: #1e293b;
    --text-secondary: #64748b;
    --text-muted: #94a3b8;
    --border: #e2e8f0;

    --radius: 10px;
    --radius-sm: 6px;
    --shadow: 0 1px 3px rgba(0,0,0,0.08), 0 1px 2px rgba(0,0,0,0.04);
    --shadow-lg: 0 4px 6px rgba(0,0,0,0.05), 0 2px 4px rgba(0,0,0,0.04);
    --transition: all 0.2s ease;
}

/* ============================================================
   基础重置
   ============================================================ */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'PingFang SC',
                 'Noto Sans CJK SC', 'Microsoft YaHei', sans-serif;
    background: var(--bg-body);
    color: var(--text-primary);
    line-height: 1.6;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

/* ============================================================
   导航栏
   ============================================================ */
.navbar {
    background: var(--bg-card);
    border-bottom: 1px solid var(--border);
    box-shadow: var(--shadow);
    position: sticky;
    top: 0;
    z-index: 100;
}

.nav-container {
    max-width: 98vw;
    width: 98vw;
    margin: 0 auto;
    padding: 0 20px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    height: 60px;
}

.nav-logo {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 18px;
    font-weight: 700;
    color: var(--primary);
    text-decoration: none;
}

.logo-icon {
    font-size: 24px;
}

.nav-links {
    display: flex;
    align-items: center;
    gap: 20px;
}

.nav-links a {
    color: var(--text-secondary);
    text-decoration: none;
    font-size: 14px;
    transition: var(--transition);
    padding: 8px 12px;
    border-radius: var(--radius-sm);
}

.nav-links a:hover {
    color: var(--primary);
    background: var(--primary-light);
}

.nav-links .btn-logout {
    color: var(--danger);
}

.nav-links .btn-logout:hover {
    background: var(--danger-light);
}

/* ============================================================
   布局容器
   ============================================================ */
.container {
    max-width: 1200px;
    margin: 0 auto;
    padding: 30px 20px;
    flex: 1;
}

.admin-page .container {
    max-width: 98vw;
    width: 98vw;
}

/* ============================================================
   Flash 消息
   ============================================================ */
.flash-messages {
    margin-bottom: 20px;
}

.alert {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 12px 16px;
    border-radius: var(--radius-sm);
    margin-bottom: 10px;
    font-size: 14px;
}

.alert-success { background: var(--success-light); color: var(--success); border-left: 4px solid var(--success); }
.alert-error   { background: var(--danger-light); color: var(--danger); border-left: 4px solid var(--danger); }
.alert-warning { background: var(--warning-light); color: var(--warning); border-left: 4px solid var(--warning); }
.alert-info    { background: var(--info-light); color: var(--info); border-left: 4px solid var(--info); }

.alert-close {
    cursor: pointer;
    font-size: 20px;
    line-height: 1;
    padding: 0 4px;
    opacity: 0.6;
}

.alert-close:hover {
    opacity: 1;
}

/* ============================================================
   首页 Hero
   ============================================================ */
.hero {
    text-align: center;
    padding: 60px 20px 40px;
}

.hero h1 {
    font-size: 36px;
    color: var(--text-primary);
    margin-bottom: 12px;
}

.hero-subtitle {
    font-size: 18px;
    color: var(--text-secondary);
    margin-bottom: 30px;
}

.hero-actions {
    display: flex;
    gap: 16px;
    justify-content: center;
}

/* ============================================================
   特性卡片
   ============================================================ */
.features {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
    gap: 20px;
    margin-top: 40px;
}

.feature-card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 30px;
    text-align: center;
    box-shadow: var(--shadow);
    transition: var(--transition);
}

.feature-card:hover {
    box-shadow: var(--shadow-lg);
    transform: translateY(-2px);
}

.feature-icon {
    font-size: 40px;
    margin-bottom: 16px;
}

.feature-card h3 {
    font-size: 18px;
    margin-bottom: 10px;
    color: var(--text-primary);
}

.feature-card p {
    font-size: 14px;
    color: var(--text-secondary);
}

/* ============================================================
   按钮
   ============================================================ */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 10px 20px;
    border: none;
    border-radius: var(--radius-sm);
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    text-decoration: none;
    transition: var(--transition);
    white-space: nowrap;
}

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

.btn-secondary { background: var(--secondary); color: #fff; }
.btn-secondary:hover { background: var(--text-secondary); }

.btn-danger { background: var(--danger); color: #fff; }
.btn-danger:hover { background: #b91c1c; }

.btn-warning { background: var(--warning); color: #fff; }
.btn-warning:hover { background: #b45309; }

.btn-success { background: var(--success); color: #fff; }
.btn-success:hover { background: #15803d; }

.btn-lg { padding: 12px 32px; font-size: 16px; }
.btn-sm { padding: 6px 14px; font-size: 13px; }
.btn-block { width: 100%; }

.btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.btn.disabled {
    opacity: 0.5;
    pointer-events: none;
    cursor: not-allowed;
}

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

.form-group label {
    display: block;
    margin-bottom: 6px;
    font-size: 14px;
    font-weight: 500;
    color: var(--text-primary);
}

.required { color: var(--danger); }

.form-group input[type="text"],
.form-group input[type="email"],
.form-group input[type="password"],
.form-group input[type="date"],
.form-group input[type="file"] {
    width: 100%;
    padding: 10px 12px;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    font-size: 14px;
    transition: var(--transition);
    background: #fff;
}

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

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

.form-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
    gap: 16px;
    margin-bottom: 20px;
}

/* ============================================================
   认证表单
   ============================================================ */
.auth-form-wrapper {
    display: flex;
    justify-content: center;
    width: 100%;
    padding: 40px 0;
}

.auth-form-card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 40px;
    width: 520px;
    max-width: calc(100vw - 80px);
    box-shadow: var(--shadow-lg);
}

#machine_code {
    font-family: 'Courier New', 'Consolas', monospace;
}

.auth-form-card h2 {
    text-align: center;
    margin-bottom: 24px;
    color: var(--text-primary);
}

.auth-form-hint {
    margin-top: 20px;
    padding-top: 20px;
    border-top: 1px solid var(--border);
    text-align: center;
    font-size: 13px;
    color: var(--text-muted);
}

.auth-form-hint strong {
    color: var(--text-secondary);
}

.text-warning {
    color: var(--warning);
}

.auth-switch-link {
    display: block;
    text-align: center;
    margin-top: 16px;
    font-size: 14px;
    color: var(--primary);
    text-decoration: none;
    transition: var(--transition);
}

.auth-switch-link:hover {
    text-decoration: underline;
}

/* ============================================================
   卡片组件
   ============================================================ */
.card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    margin-bottom: 24px;
    overflow: hidden;
    box-shadow: var(--shadow);
}

.card-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 16px 24px;
    border-bottom: 1px solid var(--border);
    background: var(--secondary-light);
}

.card-header h2 {
    font-size: 18px;
    color: var(--text-primary);
}

.card-body {
    padding: 24px;
}

.badge {
    display: inline-block;
    padding: 4px 12px;
    background: var(--primary-light);
    color: var(--primary);
    border-radius: 20px;
    font-size: 13px;
    font-weight: 500;
}

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

.stat-card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 24px;
    text-align: center;
    box-shadow: var(--shadow);
    border-left: 4px solid var(--primary);
}

.stat-card.stat-active { border-left-color: var(--success); }
.stat-card.stat-expired { border-left-color: var(--danger); }
.stat-card.stat-customers { border-left-color: var(--warning); }

.stat-label {
    font-size: 13px;
    color: var(--text-secondary);
    margin-bottom: 8px;
}

.stat-value {
    font-size: 32px;
    font-weight: 700;
    color: var(--text-primary);
}

/* ============================================================
   数据表格
   ============================================================ */
.table-wrapper {
    overflow-x: auto;
}

.data-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 14px;
}

.data-table th,
.data-table td {
    padding: 12px 16px;
    text-align: left;
    border-bottom: 1px solid var(--border);
}

.data-table th {
    background: var(--secondary-light);
    font-weight: 600;
    color: var(--text-secondary);
    font-size: 13px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.data-table tbody tr:hover {
    background: var(--secondary-light);
}

.admin-page .data-table th,
.admin-page .data-table td {
    white-space: nowrap;
}

.admin-page .card-header,
.admin-page .stat-card,
.admin-page .form-group,
.admin-page .file-info-row {
    white-space: nowrap;
}

.action-inline {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    flex-wrap: nowrap;
}

.action-inline form {
    display: inline-flex;
    margin: 0;
}

.search-form {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-bottom: 16px;
    flex-wrap: nowrap;
}

.search-form input[type="text"] {
    min-width: 360px;
    flex: 1;
    padding: 8px 12px;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    font-size: 14px;
}

.pagination-bar {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 10px;
    margin-top: 16px;
    flex-wrap: nowrap;
    white-space: nowrap;
}

.page-info {
    color: var(--text-secondary);
    font-size: 13px;
}

.pagination-jump {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    margin: 0;
}

.pagination-jump input[type="number"] {
    width: 72px;
    padding: 6px 8px;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
}

.mono {
    font-family: 'Courier New', monospace;
    font-size: 13px;
}

/* ============================================================
   状态徽章
   ============================================================ */
.status-badge {
    display: inline-block;
    padding: 4px 12px;
    border-radius: 20px;
    font-size: 12px;
    font-weight: 600;
}

.status-active {
    background: var(--success-light);
    color: var(--success);
}

.status-expired {
    background: var(--danger-light);
    color: var(--danger);
}

/* ============================================================
   客户端文件卡片
   ============================================================ */
.dashboard-header {
    margin-bottom: 24px;
}

.page-title {
    font-size: 28px;
    color: var(--text-primary);
    margin-bottom: 4px;
}

.page-subtitle {
    color: var(--text-secondary);
    font-size: 15px;
}

.file-cards {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(340px, 1fr));
    gap: 20px;
}

.file-card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    overflow: hidden;
    box-shadow: var(--shadow);
    transition: var(--transition);
}

.file-card:hover {
    box-shadow: var(--shadow-lg);
}

.file-card.file-active {
    border-top: 4px solid var(--success);
}

.file-card.file-expired {
    border-top: 4px solid var(--danger);
    opacity: 0.85;
}

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

.file-machine-code {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.file-machine-code .label {
    font-size: 12px;
    color: var(--text-muted);
}

.file-machine-code .value {
    font-size: 18px;
    font-weight: 700;
    color: var(--text-primary);
}

.file-card-body {
    padding: 16px 20px;
}

.file-info-row {
    display: flex;
    justify-content: space-between;
    padding: 8px 0;
    font-size: 14px;
    border-bottom: 1px solid var(--border);
}

.file-info-row:last-child {
    border-bottom: none;
}

.info-label {
    color: var(--text-muted);
}

.info-value {
    color: var(--text-primary);
    font-weight: 500;
}

.file-card-footer {
    padding: 16px 20px;
    border-top: 1px solid var(--border);
}

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

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

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

.empty-state-card p {
    font-size: 14px;
}

/* ============================================================
   新账号提示横幅
   ============================================================ */
.new-account-banner {
    margin-bottom: 24px;
    padding: 20px;
    border-radius: var(--radius);
    background: var(--success-light);
    border: 1px solid var(--success);
}

.account-info {
    display: flex;
    gap: 30px;
    margin: 12px 0 8px;
    font-size: 15px;
}

.password-highlight {
    color: var(--danger);
    font-size: 17px;
    letter-spacing: 1px;
}

.new-account-banner .hint {
    font-size: 13px;
    color: var(--text-secondary);
}

/* ============================================================
   错误页
   ============================================================ */
.error-page {
    text-align: center;
    padding: 80px 20px;
}

.error-code {
    font-size: 72px;
    color: var(--primary);
    margin-bottom: 16px;
}

.error-message {
    font-size: 20px;
    color: var(--text-secondary);
    margin-bottom: 24px;
}

/* ============================================================
   页脚
   ============================================================ */
.footer {
    text-align: center;
    padding: 20px;
    border-top: 1px solid var(--border);
    color: var(--text-muted);
    font-size: 13px;
}

/* ============================================================
   响应式
   ============================================================ */
@media (max-width: 768px) {
    .nav-container {
        padding: 0 12px;
    }

    .nav-logo span:last-child {
        display: none;
    }

    .nav-links {
        gap: 8px;
    }

    .nav-links a {
        padding: 6px 8px;
        font-size: 13px;
    }

    .container {
        width: 100%;
        max-width: 100vw;
        padding: 12px 6px;
    }

    .hero h1 {
        font-size: 26px;
    }

    .hero-actions {
        flex-direction: column;
    }

    .form-grid {
        grid-template-columns: 1fr;
    }

    .stats-grid {
        grid-template-columns: repeat(2, 1fr);
    }

    .stat-value {
        font-size: 24px;
    }

    .auth-form-wrapper {
        width: 100%;
        padding: 12px 0;
    }

    .auth-form-card {
        width: 100%;
        max-width: none;
        padding: 24px 12px;
    }

    .search-form,
    .pagination-bar {
        align-items: stretch;
        flex-direction: column;
    }

    .search-form input[type="text"] {
        min-width: 0;
        width: 100%;
    }

    .card-header,
    .card-body {
        padding: 16px;
    }

    .account-info {
        flex-direction: column;
        gap: 8px;
    }
}
