:root {
    --primary: #4f6ef7;
    --primary-dark: #3b5de7;
    --primary-light: #e8edff;
    --success: #22c55e;
    --warning: #f59e0b;
    --danger: #ef4444;
    --gray-50: #f9fafb;
    --gray-100: #f3f4f6;
    --gray-200: #e5e7eb;
    --gray-300: #d1d5db;
    --gray-400: #9ca3af;
    --gray-500: #6b7280;
    --gray-600: #4b5563;
    --gray-700: #374151;
    --gray-800: #1f2937;
    --gray-900: #111827;
    --radius: 8px;
    --shadow: 0 1px 3px rgba(0,0,0,.08), 0 1px 2px rgba(0,0,0,.06);
    --shadow-lg: 0 10px 25px rgba(0,0,0,.1);
}

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

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'PingFang SC', 'Hiragino Sans GB', 'Microsoft YaHei', sans-serif;
    background: var(--gray-50);
    color: var(--gray-800);
    line-height: 1.6;
}

/* Login */
.login-body {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
}

.login-container { width: 100%; max-width: 400px; padding: 20px; }

.login-card {
    background: #fff;
    border-radius: 16px;
    padding: 40px;
    box-shadow: 0 20px 60px rgba(0,0,0,.15);
}

.login-header { text-align: center; margin-bottom: 32px; }
.login-header h1 {
    font-size: 28px;
    font-weight: 700;
    color: var(--primary);
    letter-spacing: 2px;
}
.login-header p { color: var(--gray-500); margin-top: 4px; font-size: 14px; }

/* Alert */
.alert {
    padding: 10px 16px;
    border-radius: var(--radius);
    margin-bottom: 16px;
    font-size: 14px;
}
.alert-error { background: #fef2f2; color: var(--danger); border: 1px solid #fecaca; }
.alert-success { background: #f0fdf4; color: var(--success); border: 1px solid #bbf7d0; }

/* Form */
.form-group { margin-bottom: 16px; }
.form-group label {
    display: block;
    font-size: 13px;
    font-weight: 600;
    color: var(--gray-700);
    margin-bottom: 6px;
}
.form-group input,
.form-group select {
    width: 100%;
    padding: 10px 14px;
    border: 1px solid var(--gray-300);
    border-radius: var(--radius);
    font-size: 14px;
    transition: border-color .2s, box-shadow .2s;
    outline: none;
    background: #fff;
}
.form-group input:focus,
.form-group select:focus {
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(79,110,247,.15);
}

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

/* Buttons */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 10px 20px;
    border: none;
    border-radius: var(--radius);
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    transition: all .2s;
    text-decoration: none;
    gap: 6px;
}
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-dark); }
.btn-secondary { background: var(--gray-200); color: var(--gray-700); }
.btn-secondary:hover { background: var(--gray-300); }
.btn-danger { background: var(--danger); color: #fff; }
.btn-danger:hover { background: #dc2626; }
.btn-sm { padding: 6px 12px; font-size: 12px; }
.btn-block { width: 100%; }
.btn-success { background: var(--success); color: #fff; }
.btn-warning { background: var(--warning); color: #fff; }

/* Layout */
.app-layout { display: flex; min-height: 100vh; }

.sidebar {
    width: 240px;
    background: var(--gray-900);
    color: #fff;
    display: flex;
    flex-direction: column;
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    z-index: 100;
}

.sidebar-header {
    padding: 24px 20px;
    border-bottom: 1px solid var(--gray-700);
}
.sidebar-header h2 {
    font-size: 22px;
    font-weight: 700;
    letter-spacing: 2px;
    color: var(--primary);
}
.sidebar-subtitle { font-size: 12px; color: var(--gray-400); }

.sidebar-menu {
    list-style: none;
    padding: 12px 0;
    flex: 1;
}
.sidebar-menu li {
    padding: 12px 20px;
    cursor: pointer;
    font-size: 14px;
    color: var(--gray-400);
    transition: all .2s;
    display: flex;
    align-items: center;
    gap: 10px;
}
.sidebar-menu li:hover { background: var(--gray-800); color: #fff; }
.sidebar-menu li.active { background: var(--primary); color: #fff; border-radius: 0; }
.menu-icon { font-size: 12px; }

.sidebar-footer {
    padding: 16px 20px;
    border-top: 1px solid var(--gray-700);
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-size: 13px;
    color: var(--gray-400);
}
.logout-link { color: var(--danger); text-decoration: none; font-size: 13px; }
.logout-link:hover { text-decoration: underline; }

.main-content {
    flex: 1;
    margin-left: 240px;
    padding: 32px;
}

.page { display: none; }
.page.active { display: block; }

.page-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 24px;
    flex-wrap: wrap;
    gap: 12px;
}
.page-header h1 { font-size: 24px; font-weight: 700; color: var(--gray-900); }
.page-actions { display: flex; gap: 12px; align-items: center; }

.search-input {
    padding: 8px 14px;
    border: 1px solid var(--gray-300);
    border-radius: var(--radius);
    font-size: 14px;
    width: 240px;
    outline: none;
    transition: border-color .2s;
}
.search-input:focus { border-color: var(--primary); }

/* Stats */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
    gap: 16px;
    margin-bottom: 24px;
}
.stat-card {
    background: #fff;
    border-radius: 12px;
    padding: 24px;
    box-shadow: var(--shadow);
    text-align: center;
    border: 1px solid var(--gray-200);
}
.stat-number {
    font-size: 32px;
    font-weight: 700;
    color: var(--gray-800);
    line-height: 1.2;
}
.stat-label { font-size: 13px; color: var(--gray-500); margin-top: 4px; }
.stat-active .stat-number { color: var(--success); }
.stat-expired .stat-number { color: var(--warning); }
.stat-disabled .stat-number { color: var(--danger); }
.stat-devices .stat-number { color: var(--primary); }

/* Table */
.table-container {
    background: #fff;
    border-radius: 12px;
    box-shadow: var(--shadow);
    overflow-x: auto;
    border: 1px solid var(--gray-200);
}
.data-table { width: 100%; border-collapse: collapse; }
.data-table th {
    padding: 12px 16px;
    text-align: left;
    font-size: 12px;
    font-weight: 600;
    color: var(--gray-500);
    text-transform: uppercase;
    letter-spacing: .5px;
    background: var(--gray-50);
    border-bottom: 1px solid var(--gray-200);
    white-space: nowrap;
}
.data-table td {
    padding: 12px 16px;
    font-size: 13px;
    border-bottom: 1px solid var(--gray-100);
    color: var(--gray-700);
}
.data-table tr:hover td { background: var(--gray-50); }
.data-table tr:last-child td { border-bottom: none; }

.key-cell {
    font-family: 'SF Mono', 'Fira Code', monospace;
    font-size: 12px;
    max-width: 200px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    cursor: pointer;
    color: var(--primary);
}
.key-cell:hover { text-decoration: underline; }

.badge {
    display: inline-block;
    padding: 3px 10px;
    border-radius: 20px;
    font-size: 11px;
    font-weight: 600;
}
.badge-active { background: #dcfce7; color: #166534; }
.badge-expired { background: #fef3c7; color: #92400e; }
.badge-disabled { background: #fee2e2; color: #991b1b; }

.action-btns { display: flex; gap: 6px; white-space: nowrap; }

/* Pagination */
.pagination {
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 8px;
    margin-top: 16px;
    padding: 12px;
}
.pagination button {
    padding: 6px 12px;
    border: 1px solid var(--gray-300);
    background: #fff;
    border-radius: 6px;
    cursor: pointer;
    font-size: 13px;
    transition: all .2s;
}
.pagination button:hover { border-color: var(--primary); color: var(--primary); }
.pagination button.active { background: var(--primary); color: #fff; border-color: var(--primary); }
.pagination button:disabled { opacity: .5; cursor: not-allowed; }
.pagination .page-info { font-size: 13px; color: var(--gray-500); }

/* Modal */
.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,.5);
    display: none;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    backdrop-filter: blur(4px);
}
.modal-overlay.show { display: flex; }

.modal {
    background: #fff;
    border-radius: 16px;
    width: 90%;
    max-width: 500px;
    box-shadow: var(--shadow-lg);
    max-height: 90vh;
    overflow-y: auto;
}
.modal-wide { max-width: 700px; }

.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 20px 24px;
    border-bottom: 1px solid var(--gray-200);
}
.modal-header h3 { font-size: 18px; font-weight: 700; }
.modal-close {
    background: none;
    border: none;
    font-size: 24px;
    cursor: pointer;
    color: var(--gray-400);
    line-height: 1;
}
.modal-close:hover { color: var(--gray-700); }

.modal form,
.modal .detail-body { padding: 24px; }

.form-actions {
    display: flex;
    justify-content: flex-end;
    gap: 12px;
    margin-top: 24px;
}

/* Detail */
.detail-body { padding: 24px; }
.detail-section { margin-bottom: 24px; }
.detail-section h4 {
    font-size: 14px;
    font-weight: 600;
    color: var(--gray-500);
    text-transform: uppercase;
    letter-spacing: .5px;
    margin-bottom: 12px;
    padding-bottom: 8px;
    border-bottom: 1px solid var(--gray-200);
}
.detail-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 12px;
}
.detail-item label {
    font-size: 12px;
    color: var(--gray-500);
    display: block;
}
.detail-item .value {
    font-size: 14px;
    font-weight: 600;
    color: var(--gray-800);
    word-break: break-all;
}
.detail-key {
    font-family: 'SF Mono', 'Fira Code', monospace;
    font-size: 13px;
    background: var(--gray-100);
    padding: 10px 14px;
    border-radius: var(--radius);
    word-break: break-all;
    margin-bottom: 16px;
    border: 1px solid var(--gray-200);
    position: relative;
    cursor: pointer;
}
.detail-key:hover { background: var(--gray-200); }
.detail-key::after {
    content: '点击复制';
    position: absolute;
    right: 10px;
    top: 50%;
    transform: translateY(-50%);
    font-size: 11px;
    color: var(--gray-400);
    font-family: -apple-system, sans-serif;
}

.device-list { list-style: none; }
.device-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 8px 12px;
    background: var(--gray-50);
    border-radius: 6px;
    margin-bottom: 6px;
    font-size: 13px;
    font-family: 'SF Mono', 'Fira Code', monospace;
}
.no-devices {
    font-size: 13px;
    color: var(--gray-400);
    font-style: italic;
    padding: 8px 0;
}

/* Settings */
.settings-card {
    background: #fff;
    border-radius: 12px;
    padding: 32px;
    box-shadow: var(--shadow);
    max-width: 500px;
    border: 1px solid var(--gray-200);
}
.settings-card h3 {
    font-size: 18px;
    font-weight: 700;
    margin-bottom: 24px;
    color: var(--gray-900);
}

/* Toast */
.toast-container {
    position: fixed;
    top: 20px;
    right: 20px;
    z-index: 9999;
    display: flex;
    flex-direction: column;
    gap: 8px;
}
.toast {
    padding: 12px 20px;
    border-radius: var(--radius);
    font-size: 14px;
    box-shadow: var(--shadow-lg);
    animation: toastIn .3s ease;
    min-width: 200px;
}
.toast-success { background: var(--success); color: #fff; }
.toast-error { background: var(--danger); color: #fff; }
@keyframes toastIn {
    from { opacity: 0; transform: translateX(40px); }
    to { opacity: 1; transform: translateX(0); }
}

/* Responsive */
@media (max-width: 768px) {
    .sidebar { display: none; }
    .main-content { margin-left: 0; padding: 16px; }
    .page-header { flex-direction: column; align-items: stretch; }
    .page-actions { flex-direction: column; }
    .search-input { width: 100%; }
    .form-row { flex-direction: column; gap: 0; }
    .detail-grid { grid-template-columns: 1fr; }
    .stats-grid { grid-template-columns: repeat(2, 1fr); }
}
